aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2012-05-21 06:45:18 -0400
committerTakashi Iwai <tiwai@suse.de>2012-05-21 06:45:18 -0400
commit775b2449bdba7c97dda9f274c92bf7a83dac4142 (patch)
treeb4bee45c13762ea93642b1e38c62de454e51cf5d
parent21363cf0ca5c9c62e34e37422fb1d13d70d3de3c (diff)
parent5fb86e5d4a951ddb0474cdfd809380c8e2a8d101 (diff)
Merge branch 'topic/asoc' into for-linus
-rw-r--r--Documentation/ABI/stable/sysfs-driver-usb-usbtmc14
-rw-r--r--Documentation/ABI/testing/sysfs-block-rssd18
-rw-r--r--Documentation/ABI/testing/sysfs-bus-hsi19
-rw-r--r--Documentation/ABI/testing/sysfs-cfq-target-latency8
-rw-r--r--Documentation/DMA-attributes.txt18
-rw-r--r--Documentation/DocBook/device-drivers.tmpl17
-rw-r--r--Documentation/DocBook/media/v4l/pixfmt-nv12m.xml2
-rw-r--r--Documentation/DocBook/media/v4l/pixfmt-yuv420m.xml2
-rw-r--r--Documentation/cgroups/cpusets.txt2
-rw-r--r--Documentation/cgroups/memory.txt5
-rw-r--r--Documentation/cpu-hotplug.txt22
-rw-r--r--Documentation/devicetree/bindings/ata/ahci-platform.txt (renamed from Documentation/devicetree/bindings/ata/calxeda-sata.txt)5
-rw-r--r--Documentation/devicetree/bindings/mtd/atmel-nand.txt10
-rw-r--r--Documentation/devicetree/bindings/regulator/anatop-regulator.txt29
-rw-r--r--Documentation/devicetree/bindings/sound/imx-audio-sgtl5000.txt49
-rw-r--r--Documentation/devicetree/bindings/sound/mxs-audio-sgtl5000.txt17
-rw-r--r--Documentation/devicetree/bindings/sound/mxs-saif.txt36
-rw-r--r--Documentation/devicetree/bindings/sound/nvidia,tegra30-ahub.txt32
-rw-r--r--Documentation/devicetree/bindings/sound/nvidia,tegra30-i2s.txt15
-rw-r--r--Documentation/devicetree/bindings/sound/tegra-audio-trimslice.txt14
-rw-r--r--Documentation/feature-removal-schedule.txt16
-rw-r--r--Documentation/filesystems/vfs.txt2
-rw-r--r--Documentation/hwmon/k10temp2
-rw-r--r--Documentation/ioctl/ioctl-number.txt1
-rw-r--r--Documentation/networking/driver.txt31
-rw-r--r--Documentation/networking/ip-sysctl.txt15
-rw-r--r--Documentation/networking/netdevices.txt25
-rw-r--r--Documentation/power/freezing-of-tasks.txt37
-rw-r--r--Documentation/security/keys.txt14
-rw-r--r--Documentation/usb/URB.txt22
-rw-r--r--Documentation/usb/usbmon.txt6
-rw-r--r--MAINTAINERS109
-rw-r--r--Makefile2
-rw-r--r--arch/alpha/Kconfig2
-rw-r--r--arch/alpha/include/asm/atomic.h68
-rw-r--r--arch/alpha/include/asm/cmpxchg.h71
-rw-r--r--arch/alpha/include/asm/dma-mapping.h18
-rw-r--r--arch/alpha/include/asm/rtc.h8
-rw-r--r--arch/alpha/include/asm/xchg.h4
-rw-r--r--arch/alpha/kernel/core_tsunami.c1
-rw-r--r--arch/alpha/kernel/pci-noop.c10
-rw-r--r--arch/alpha/kernel/pci_iommu.c10
-rw-r--r--arch/alpha/kernel/signal.c31
-rw-r--r--arch/alpha/kernel/smp.c2
-rw-r--r--arch/alpha/kernel/sys_marvel.c2
-rw-r--r--arch/arm/Kconfig10
-rw-r--r--arch/arm/boot/compressed/atags_to_fdt.c2
-rw-r--r--arch/arm/boot/compressed/head.S2
-rw-r--r--arch/arm/boot/dts/at91sam9g20.dtsi3
-rw-r--r--arch/arm/boot/dts/at91sam9g25ek.dts4
-rw-r--r--arch/arm/boot/dts/at91sam9g45.dtsi3
-rw-r--r--arch/arm/boot/dts/at91sam9m10g45ek.dts6
-rw-r--r--arch/arm/boot/dts/at91sam9x5.dtsi7
-rw-r--r--arch/arm/boot/dts/at91sam9x5cm.dtsi2
-rw-r--r--arch/arm/boot/dts/db8500.dtsi1
-rw-r--r--arch/arm/boot/dts/highbank.dts1
-rw-r--r--arch/arm/boot/dts/msm8660-surf.dts4
-rw-r--r--arch/arm/boot/dts/usb_a9g20.dts2
-rw-r--r--arch/arm/boot/dts/versatile-ab.dts2
-rw-r--r--arch/arm/boot/dts/versatile-pb.dts2
-rw-r--r--arch/arm/common/vic.c9
-rw-r--r--arch/arm/configs/imx_v4_v5_defconfig1
-rw-r--r--arch/arm/configs/mini2440_defconfig2
-rw-r--r--arch/arm/configs/u8500_defconfig9
-rw-r--r--arch/arm/include/asm/barrier.h2
-rw-r--r--arch/arm/include/asm/io.h2
-rw-r--r--arch/arm/include/asm/jump_label.h2
-rw-r--r--arch/arm/include/asm/thread_info.h7
-rw-r--r--arch/arm/include/asm/tls.h4
-rw-r--r--arch/arm/kernel/bios32.c1
-rw-r--r--arch/arm/kernel/insn.c1
-rw-r--r--arch/arm/kernel/irq.c6
-rw-r--r--arch/arm/kernel/kprobes.c2
-rw-r--r--arch/arm/kernel/ptrace.c28
-rw-r--r--arch/arm/kernel/setup.c16
-rw-r--r--arch/arm/kernel/signal.c55
-rw-r--r--arch/arm/kernel/smp.c33
-rw-r--r--arch/arm/kernel/sys_arm.c2
-rw-r--r--arch/arm/mach-at91/at91rm9200_devices.c1
-rw-r--r--arch/arm/mach-at91/at91rm9200_time.c2
-rw-r--r--arch/arm/mach-at91/at91sam9260_devices.c3
-rw-r--r--arch/arm/mach-at91/at91sam9261_devices.c3
-rw-r--r--arch/arm/mach-at91/at91sam9263_devices.c6
-rw-r--r--arch/arm/mach-at91/at91sam9g45_devices.c11
-rw-r--r--arch/arm/mach-at91/at91sam9rl_devices.c3
-rw-r--r--arch/arm/mach-at91/at91sam9x5.c2
-rw-r--r--arch/arm/mach-at91/board-rm9200ek.c2
-rw-r--r--arch/arm/mach-at91/board-sam9261ek.c5
-rw-r--r--arch/arm/mach-at91/board-sam9263ek.c1
-rw-r--r--arch/arm/mach-at91/board-sam9m10g45ek.c1
-rw-r--r--arch/arm/mach-at91/clock.c1
-rw-r--r--arch/arm/mach-at91/include/mach/at91_pmc.h2
-rw-r--r--arch/arm/mach-at91/include/mach/board.h13
-rw-r--r--arch/arm/mach-at91/include/mach/io.h27
-rw-r--r--arch/arm/mach-at91/setup.c2
-rw-r--r--arch/arm/mach-bcmring/core.c4
-rw-r--r--arch/arm/mach-exynos/Kconfig5
-rw-r--r--arch/arm/mach-exynos/clock-exynos4.c24
-rw-r--r--arch/arm/mach-exynos/clock-exynos5.c26
-rw-r--r--arch/arm/mach-exynos/common.c17
-rw-r--r--arch/arm/mach-exynos/dev-dwmci.c13
-rw-r--r--arch/arm/mach-exynos/dma.c2
-rw-r--r--arch/arm/mach-exynos/include/mach/debug-macro.S7
-rw-r--r--arch/arm/mach-exynos/include/mach/irqs.h2
-rw-r--r--arch/arm/mach-exynos/include/mach/map.h4
-rw-r--r--arch/arm/mach-exynos/include/mach/regs-clock.h6
-rw-r--r--arch/arm/mach-exynos/include/mach/uncompress.h17
-rw-r--r--arch/arm/mach-exynos/mach-exynos5-dt.c2
-rw-r--r--arch/arm/mach-exynos/mach-nuri.c47
-rw-r--r--arch/arm/mach-exynos/mach-universal_c210.c7
-rw-r--r--arch/arm/mach-imx/Kconfig2
-rw-r--r--arch/arm/mach-imx/clock-imx27.c1
-rw-r--r--arch/arm/mach-imx/clock-imx35.c2
-rw-r--r--arch/arm/mach-imx/imx27-dt.c6
-rw-r--r--arch/arm/mach-imx/mach-armadillo5x0.c9
-rw-r--r--arch/arm/mach-imx/mach-kzm_arm11_01.c9
-rw-r--r--arch/arm/mach-imx/mach-mx31_3ds.c22
-rw-r--r--arch/arm/mach-imx/mach-mx31lilly.c9
-rw-r--r--arch/arm/mach-imx/mach-mx31lite.c9
-rw-r--r--arch/arm/mach-imx/mach-mx31moboard.c20
-rw-r--r--arch/arm/mach-imx/mach-mx35_3ds.c2
-rw-r--r--arch/arm/mach-imx/mach-mx53_ard.c8
-rw-r--r--arch/arm/mach-imx/mm-imx5.c2
-rw-r--r--arch/arm/mach-kirkwood/board-dt.c1
-rw-r--r--arch/arm/mach-msm/board-halibut.c3
-rw-r--r--arch/arm/mach-msm/board-msm8x60.c25
-rw-r--r--arch/arm/mach-msm/board-trout-panel.c1
-rw-r--r--arch/arm/mach-msm/board-trout.c1
-rw-r--r--arch/arm/mach-msm/include/mach/uncompress.h1
-rw-r--r--arch/arm/mach-msm/proc_comm.c2
-rw-r--r--arch/arm/mach-msm/smd_debug.c8
-rw-r--r--arch/arm/mach-omap1/ams-delta-fiq.c2
-rw-r--r--arch/arm/mach-omap1/include/mach/io.h45
-rw-r--r--arch/arm/mach-omap1/mux.c1
-rw-r--r--arch/arm/mach-omap1/timer.c4
-rw-r--r--arch/arm/mach-omap2/board-4430sdp.c12
-rw-r--r--arch/arm/mach-omap2/board-cm-t35.c16
-rw-r--r--arch/arm/mach-omap2/board-generic.c2
-rw-r--r--arch/arm/mach-omap2/board-igep0020.c6
-rw-r--r--arch/arm/mach-omap2/board-ldp.c7
-rw-r--r--arch/arm/mach-omap2/board-omap3evm.c15
-rw-r--r--arch/arm/mach-omap2/board-omap3logic.c7
-rw-r--r--arch/arm/mach-omap2/board-omap3stalker.c16
-rw-r--r--arch/arm/mach-omap2/board-omap4panda.c13
-rw-r--r--arch/arm/mach-omap2/board-overo.c8
-rw-r--r--arch/arm/mach-omap2/board-zoom-debugboard.c9
-rw-r--r--arch/arm/mach-omap2/clkt2xxx_virt_prcm_set.c80
-rw-r--r--arch/arm/mach-omap2/clock.c5
-rw-r--r--arch/arm/mach-omap2/clock.h8
-rw-r--r--arch/arm/mach-omap2/clock3xxx_data.c18
-rw-r--r--arch/arm/mach-omap2/clock44xx_data.c5
-rw-r--r--arch/arm/mach-omap2/clockdomains44xx_data.c2
-rw-r--r--arch/arm/mach-omap2/gpmc-smsc911x.c65
-rw-r--r--arch/arm/mach-omap2/hsmmc.c7
-rw-r--r--arch/arm/mach-omap2/include/mach/barriers.h2
-rw-r--r--arch/arm/mach-omap2/include/mach/ctrl_module_pad_core_44xx.h8
-rw-r--r--arch/arm/mach-omap2/omap_hwmod.c85
-rw-r--r--arch/arm/mach-omap2/omap_hwmod_2420_data.c1
-rw-r--r--arch/arm/mach-omap2/omap_hwmod_2430_data.c1
-rw-r--r--arch/arm/mach-omap2/omap_hwmod_3xxx_data.c1
-rw-r--r--arch/arm/mach-omap2/omap_hwmod_44xx_data.c37
-rw-r--r--arch/arm/mach-omap2/opp.c4
-rw-r--r--arch/arm/mach-omap2/pm34xx.c38
-rw-r--r--arch/arm/mach-omap2/pm44xx.c10
-rw-r--r--arch/arm/mach-omap2/powerdomain.c8
-rw-r--r--arch/arm/mach-omap2/prm44xx.c21
-rw-r--r--arch/arm/mach-omap2/prm_common.c2
-rw-r--r--arch/arm/mach-omap2/serial.c124
-rw-r--r--arch/arm/mach-omap2/twl-common.c37
-rw-r--r--arch/arm/mach-omap2/twl-common.h10
-rw-r--r--arch/arm/mach-omap2/usb-host.c10
-rw-r--r--arch/arm/mach-orion5x/mpp.h4
-rw-r--r--arch/arm/mach-pxa/Kconfig1
-rw-r--r--arch/arm/mach-pxa/include/mach/io.h17
-rw-r--r--arch/arm/mach-pxa/include/mach/mfp-pxa2xx.h7
-rw-r--r--arch/arm/mach-pxa/mfp-pxa2xx.c21
-rw-r--r--arch/arm/mach-pxa/pxa27x.c6
-rw-r--r--arch/arm/mach-s3c24xx/Kconfig8
-rw-r--r--arch/arm/mach-s3c24xx/common.h18
-rw-r--r--arch/arm/mach-s5pv210/dma.c2
-rw-r--r--arch/arm/mach-s5pv210/mach-aquila.c4
-rw-r--r--arch/arm/mach-s5pv210/mach-goni.c6
-rw-r--r--arch/arm/mach-sa1100/collie.c4
-rw-r--r--arch/arm/mach-sa1100/generic.c2
-rw-r--r--arch/arm/mach-sa1100/include/mach/collie.h3
-rw-r--r--arch/arm/mach-shmobile/Kconfig2
-rw-r--r--arch/arm/mach-shmobile/board-ag5evm.c22
-rw-r--r--arch/arm/mach-shmobile/board-ap4evb.c35
-rw-r--r--arch/arm/mach-shmobile/board-mackerel.c57
-rw-r--r--arch/arm/mach-shmobile/headsmp.S56
-rw-r--r--arch/arm/mach-shmobile/include/mach/common.h2
-rw-r--r--arch/arm/mach-shmobile/setup-r8a7779.c4
-rw-r--r--arch/arm/mach-shmobile/setup-sh73a0.c4
-rw-r--r--arch/arm/mach-shmobile/smp-r8a7779.c8
-rw-r--r--arch/arm/mach-shmobile/smp-sh73a0.c7
-rw-r--r--arch/arm/mach-shmobile/timer.c9
-rw-r--r--arch/arm/mach-tegra/board-dt-tegra20.c6
-rw-r--r--arch/arm/mach-tegra/board-harmony.c1
-rw-r--r--arch/arm/mach-tegra/board-seaboard.c1
-rw-r--r--arch/arm/mach-tegra/board-trimslice.c1
-rw-r--r--arch/arm/mach-tegra/devices.c11
-rw-r--r--arch/arm/mach-tegra/devices.h1
-rw-r--r--arch/arm/mach-tegra/tegra2_clocks.c4
-rw-r--r--arch/arm/mach-u300/core.c6
-rw-r--r--arch/arm/mach-u300/i2c.c9
-rw-r--r--arch/arm/mach-u300/include/mach/irqs.h150
-rw-r--r--arch/arm/mach-ux500/Kconfig1
-rw-r--r--arch/arm/mach-ux500/mbox-db5500.c2
-rw-r--r--arch/arm/mach-ux500/platsmp.c2
-rw-r--r--arch/arm/mach-versatile/pci.c10
-rw-r--r--arch/arm/mm/Kconfig2
-rw-r--r--arch/arm/mm/abort-ev6.S17
-rw-r--r--arch/arm/mm/cache-l2x0.c25
-rw-r--r--arch/arm/mm/fault.c2
-rw-r--r--arch/arm/mm/init.c4
-rw-r--r--arch/arm/mm/mmu.c4
-rw-r--r--arch/arm/mm/nommu.c2
-rw-r--r--arch/arm/mm/proc-v7.S12
-rw-r--r--arch/arm/plat-mxc/3ds_debugboard.c2
-rw-r--r--arch/arm/plat-omap/Kconfig1
-rw-r--r--arch/arm/plat-omap/clock.c31
-rw-r--r--arch/arm/plat-omap/dma.c14
-rw-r--r--arch/arm/plat-omap/include/plat/clock.h10
-rw-r--r--arch/arm/plat-omap/include/plat/omap_hwmod.h16
-rw-r--r--arch/arm/plat-omap/sram.c12
-rw-r--r--arch/arm/plat-samsung/Kconfig1
-rw-r--r--arch/arm/plat-samsung/include/plat/sdhci.h28
-rw-r--r--arch/arm/vfp/vfpmodule.c99
-rw-r--r--arch/avr32/include/asm/barrier.h2
-rw-r--r--arch/avr32/include/asm/special_insns.h13
-rw-r--r--arch/avr32/mach-at32ap/include/mach/board.h2
-rw-r--r--arch/blackfin/Kconfig2
-rw-r--r--arch/blackfin/configs/BF527-EZKIT_defconfig1
-rw-r--r--arch/blackfin/include/asm/cmpxchg.h3
-rw-r--r--arch/blackfin/include/asm/gpio.h14
-rw-r--r--arch/blackfin/mach-bf538/boards/ezkit.c53
-rw-r--r--arch/c6x/include/asm/irq.h4
-rw-r--r--arch/c6x/kernel/irq.c13
-rw-r--r--arch/c6x/kernel/signal.c16
-rw-r--r--arch/frv/mb93090-mb00/pci-dma.c1
-rw-r--r--arch/hexagon/include/asm/dma-mapping.h18
-rw-r--r--arch/hexagon/kernel/dma.c10
-rw-r--r--arch/hexagon/kernel/process.c6
-rw-r--r--arch/hexagon/kernel/ptrace.c1
-rw-r--r--arch/hexagon/kernel/smp.c16
-rw-r--r--arch/hexagon/kernel/time.c1
-rw-r--r--arch/hexagon/kernel/vdso.c1
-rw-r--r--arch/ia64/hp/common/sba_iommu.c11
-rw-r--r--arch/ia64/include/asm/cmpxchg.h148
-rw-r--r--arch/ia64/include/asm/dma-mapping.h18
-rw-r--r--arch/ia64/include/asm/futex.h9
-rw-r--r--arch/ia64/include/asm/intrinsics.h114
-rw-r--r--arch/ia64/kernel/acpi.c2
-rw-r--r--arch/ia64/kernel/pci-swiotlb.c14
-rw-r--r--arch/ia64/kernel/perfmon.c18
-rw-r--r--arch/ia64/kvm/kvm-ia64.c2
-rw-r--r--arch/ia64/sn/pci/pci_dma.c9
-rw-r--r--arch/m68k/configs/m5275evb_defconfig1
-rw-r--r--arch/m68k/include/asm/atomic.h1
-rw-r--r--arch/m68k/mac/config.c3
-rw-r--r--arch/m68k/platform/520x/config.c6
-rw-r--r--arch/m68k/platform/523x/config.c6
-rw-r--r--arch/m68k/platform/5249/config.c6
-rw-r--r--arch/m68k/platform/527x/config.c8
-rw-r--r--arch/m68k/platform/528x/config.c6
-rw-r--r--arch/m68k/platform/532x/config.c6
-rw-r--r--arch/m68k/platform/68EZ328/Makefile6
-rw-r--r--arch/m68k/platform/68VZ328/Makefile9
-rw-r--r--arch/m68k/platform/68VZ328/bootlogo.h (renamed from arch/m68k/platform/68EZ328/bootlogo.h)2
-rw-r--r--arch/m68k/platform/coldfire/device.c8
-rw-r--r--arch/m68k/q40/config.c3
-rw-r--r--arch/microblaze/include/asm/cmpxchg.h2
-rw-r--r--arch/microblaze/include/asm/dma-mapping.h18
-rw-r--r--arch/microblaze/include/asm/futex.h2
-rw-r--r--arch/microblaze/include/asm/processor.h4
-rw-r--r--arch/microblaze/kernel/dma.c10
-rw-r--r--arch/microblaze/kernel/early_printk.c2
-rw-r--r--arch/microblaze/kernel/setup.c2
-rw-r--r--arch/microblaze/kernel/unwind.c1
-rw-r--r--arch/microblaze/lib/uaccess_old.S98
-rw-r--r--arch/mips/ath79/dev-wmac.c2
-rw-r--r--arch/mips/cavium-octeon/dma-octeon.c12
-rw-r--r--arch/mips/cavium-octeon/smp.c4
-rw-r--r--arch/mips/include/asm/dma-mapping.h18
-rw-r--r--arch/mips/include/asm/mach-jz4740/irq.h2
-rw-r--r--arch/mips/include/asm/mmu_context.h6
-rw-r--r--arch/mips/kernel/mips-mt-fpaff.c2
-rw-r--r--arch/mips/kernel/proc.c2
-rw-r--r--arch/mips/kernel/signal.c27
-rw-r--r--arch/mips/kernel/signal32.c20
-rw-r--r--arch/mips/kernel/signal_n32.c10
-rw-r--r--arch/mips/kernel/smp-bmips.c2
-rw-r--r--arch/mips/kernel/smp.c27
-rw-r--r--arch/mips/kernel/smtc.c2
-rw-r--r--arch/mips/mm/c-octeon.c6
-rw-r--r--arch/mips/mm/dma-default.c8
-rw-r--r--arch/mips/netlogic/common/smp.c6
-rw-r--r--arch/mips/pmc-sierra/yosemite/smp.c8
-rw-r--r--arch/mips/sgi-ip27/ip27-smp.c2
-rw-r--r--arch/mips/sibyte/bcm1480/smp.c7
-rw-r--r--arch/mips/sibyte/sb1250/smp.c7
-rw-r--r--arch/parisc/include/asm/atomic.h107
-rw-r--r--arch/parisc/include/asm/cmpxchg.h116
-rw-r--r--arch/parisc/include/asm/hardware.h3
-rw-r--r--arch/parisc/include/asm/page.h6
-rw-r--r--arch/parisc/include/asm/pdc.h7
-rw-r--r--arch/parisc/include/asm/pgtable.h2
-rw-r--r--arch/parisc/include/asm/spinlock.h2
-rw-r--r--arch/parisc/kernel/pdc_cons.c3
-rw-r--r--arch/parisc/kernel/time.c1
-rw-r--r--arch/powerpc/boot/dts/fsl/pq3-mpic-message-B.dtsi43
-rw-r--r--arch/powerpc/boot/dts/fsl/pq3-mpic.dtsi10
-rw-r--r--arch/powerpc/boot/dts/p1020mbg-pc.dtsi151
-rw-r--r--arch/powerpc/boot/dts/p1020mbg-pc_32b.dts89
-rw-r--r--arch/powerpc/boot/dts/p1020mbg-pc_36b.dts89
-rw-r--r--arch/powerpc/boot/dts/p1020utm-pc.dtsi140
-rw-r--r--arch/powerpc/boot/dts/p1020utm-pc_32b.dts89
-rw-r--r--arch/powerpc/boot/dts/p1020utm-pc_36b.dts89
-rw-r--r--arch/powerpc/boot/dts/p2041rdb.dts3
-rw-r--r--arch/powerpc/boot/dts/p3041ds.dts4
-rw-r--r--arch/powerpc/boot/dts/p3060qds.dts2
-rw-r--r--arch/powerpc/boot/dts/p4080ds.dts3
-rw-r--r--arch/powerpc/boot/dts/p5020ds.dts4
-rw-r--r--arch/powerpc/configs/86xx/mpc8610_hpcd_defconfig1
-rw-r--r--arch/powerpc/configs/corenet32_smp_defconfig1
-rw-r--r--arch/powerpc/configs/corenet64_smp_defconfig2
-rw-r--r--arch/powerpc/configs/mpc85xx_defconfig2
-rw-r--r--arch/powerpc/configs/mpc85xx_smp_defconfig2
-rw-r--r--arch/powerpc/include/asm/dma-mapping.h24
-rw-r--r--arch/powerpc/include/asm/epapr_hcalls.h7
-rw-r--r--arch/powerpc/include/asm/exception-64s.h7
-rw-r--r--arch/powerpc/include/asm/fsl_guts.h26
-rw-r--r--arch/powerpc/include/asm/irq.h6
-rw-r--r--arch/powerpc/include/asm/mpic.h18
-rw-r--r--arch/powerpc/include/asm/mpic_msgr.h1
-rw-r--r--arch/powerpc/include/asm/reg_booke.h5
-rw-r--r--arch/powerpc/kernel/dma-iommu.c10
-rw-r--r--arch/powerpc/kernel/dma-swiotlb.c4
-rw-r--r--arch/powerpc/kernel/dma.c10
-rw-r--r--arch/powerpc/kernel/entry_32.S39
-rw-r--r--arch/powerpc/kernel/entry_64.S62
-rw-r--r--arch/powerpc/kernel/exceptions-64s.S2
-rw-r--r--arch/powerpc/kernel/fadump.c2
-rw-r--r--arch/powerpc/kernel/ibmebus.c10
-rw-r--r--arch/powerpc/kernel/irq.c33
-rw-r--r--arch/powerpc/kernel/kgdb.c1
-rw-r--r--arch/powerpc/kernel/machine_kexec.c7
-rw-r--r--arch/powerpc/kernel/process.c4
-rw-r--r--arch/powerpc/kernel/setup_32.c3
-rw-r--r--arch/powerpc/kernel/traps.c10
-rw-r--r--arch/powerpc/kernel/vio.c14
-rw-r--r--arch/powerpc/kvm/book3s_64_mmu_hv.c22
-rw-r--r--arch/powerpc/kvm/book3s_emulate.c1
-rw-r--r--arch/powerpc/kvm/book3s_hv.c2
-rw-r--r--arch/powerpc/kvm/book3s_hv_builtin.c9
-rw-r--r--arch/powerpc/kvm/book3s_hv_interrupts.S8
-rw-r--r--arch/powerpc/kvm/book3s_interrupts.S7
-rw-r--r--arch/powerpc/kvm/book3s_paired_singles.c1
-rw-r--r--arch/powerpc/kvm/book3s_pr.c10
-rw-r--r--arch/powerpc/kvm/booke_interrupts.S7
-rw-r--r--arch/powerpc/net/bpf_jit.h8
-rw-r--r--arch/powerpc/net/bpf_jit_64.S108
-rw-r--r--arch/powerpc/net/bpf_jit_comp.c26
-rw-r--r--arch/powerpc/platforms/52xx/mpc52xx_pci.c2
-rw-r--r--arch/powerpc/platforms/85xx/common.c6
-rw-r--r--arch/powerpc/platforms/85xx/mpc85xx_mds.c13
-rw-r--r--arch/powerpc/platforms/85xx/mpc85xx_rdb.c2
-rw-r--r--arch/powerpc/platforms/85xx/p1022_ds.c17
-rw-r--r--arch/powerpc/platforms/86xx/mpc8610_hpcd.c2
-rw-r--r--arch/powerpc/platforms/cell/axon_msi.c8
-rw-r--r--arch/powerpc/platforms/cell/beat_interrupt.c4
-rw-r--r--arch/powerpc/platforms/cell/iommu.c16
-rw-r--r--arch/powerpc/platforms/cell/qpace_setup.c2
-rw-r--r--arch/powerpc/platforms/cell/setup.c2
-rw-r--r--arch/powerpc/platforms/powermac/low_i2c.c9
-rw-r--r--arch/powerpc/platforms/powermac/pic.c6
-rw-r--r--arch/powerpc/platforms/powermac/smp.c2
-rw-r--r--arch/powerpc/platforms/ps3/interrupt.c3
-rw-r--r--arch/powerpc/platforms/ps3/system-bus.c13
-rw-r--r--arch/powerpc/platforms/pseries/Kconfig4
-rw-r--r--arch/powerpc/platforms/pseries/eeh.c2
-rw-r--r--arch/powerpc/platforms/pseries/eeh_event.c4
-rw-r--r--arch/powerpc/sysdev/cpm2_pic.c3
-rw-r--r--arch/powerpc/sysdev/mpc8xx_pic.c61
-rw-r--r--arch/powerpc/sysdev/mpic.c54
-rw-r--r--arch/powerpc/sysdev/mpic_msgr.c12
-rw-r--r--arch/powerpc/sysdev/qe_lib/qe.c22
-rw-r--r--arch/powerpc/sysdev/scom.c1
-rw-r--r--arch/powerpc/sysdev/xics/xics-common.c7
-rw-r--r--arch/s390/Kconfig1
-rw-r--r--arch/s390/defconfig37
-rw-r--r--arch/s390/include/asm/facility.h3
-rw-r--r--arch/s390/include/asm/pgalloc.h3
-rw-r--r--arch/s390/include/asm/swab.h2
-rw-r--r--arch/s390/include/asm/tlb.h22
-rw-r--r--arch/s390/kernel/head.S2
-rw-r--r--arch/s390/kernel/irq.c9
-rw-r--r--arch/s390/kernel/perf_cpum_cf.c4
-rw-r--r--arch/s390/mm/maccess.c27
-rw-r--r--arch/s390/mm/pgtable.c63
-rw-r--r--arch/sh/Kconfig.debug1
-rw-r--r--arch/sh/boards/Kconfig2
-rw-r--r--arch/sh/boards/board-sh7785lcr.c1
-rw-r--r--arch/sh/boards/mach-ecovec24/setup.c26
-rw-r--r--arch/sh/boards/mach-hp6xx/pm.c1
-rw-r--r--arch/sh/boards/mach-se/7724/setup.c15
-rw-r--r--arch/sh/drivers/dma/dma-sysfs.c2
-rw-r--r--arch/sh/include/asm/atomic.h2
-rw-r--r--arch/sh/include/asm/dma-mapping.h28
-rw-r--r--arch/sh/kernel/cpu/fpu.c1
-rw-r--r--arch/sh/kernel/cpu/sh2a/fpu.c1
-rw-r--r--arch/sh/kernel/cpu/sh4/fpu.c1
-rw-r--r--arch/sh/kernel/cpu/sh4a/clock-sh7757.c2
-rw-r--r--arch/sh/kernel/cpu/shmobile/pm.c1
-rw-r--r--arch/sh/kernel/dma-nommu.c4
-rw-r--r--arch/sh/kernel/idle.c2
-rw-r--r--arch/sh/kernel/kgdb.c1
-rw-r--r--arch/sh/kernel/process_32.c1
-rw-r--r--arch/sh/kernel/smp.c1
-rw-r--r--arch/sh/kernel/vsyscall/vsyscall-sigreturn.S35
-rw-r--r--arch/sh/kernel/vsyscall/vsyscall-trapa.S23
-rw-r--r--arch/sh/mm/cache-sh4.c1
-rw-r--r--arch/sh/mm/consistent.c6
-rw-r--r--arch/sh/mm/fault_32.c2
-rw-r--r--arch/sh/mm/flush-sh4.c1
-rw-r--r--arch/sh/mm/sram.c1
-rw-r--r--arch/sparc/include/asm/dma-mapping.h18
-rw-r--r--arch/sparc/include/asm/pgtable_64.h4
-rw-r--r--arch/sparc/kernel/central.c2
-rw-r--r--arch/sparc/kernel/ds.c2
-rw-r--r--arch/sparc/kernel/iommu.c10
-rw-r--r--arch/sparc/kernel/ioport.c18
-rw-r--r--arch/sparc/kernel/leon_kernel.c6
-rw-r--r--arch/sparc/kernel/leon_pci.c13
-rw-r--r--arch/sparc/kernel/leon_smp.c3
-rw-r--r--arch/sparc/kernel/pci_sun4v.c9
-rw-r--r--arch/sparc/kernel/rtrap_64.S7
-rw-r--r--arch/sparc/kernel/sys_sparc_64.c7
-rw-r--r--arch/sparc/mm/fault_32.c37
-rw-r--r--arch/sparc/mm/fault_64.c37
-rw-r--r--arch/sparc/mm/ultra.S6
-rw-r--r--arch/tile/Kconfig8
-rw-r--r--arch/tile/Makefile5
-rw-r--r--arch/tile/include/arch/spr_def.h4
-rw-r--r--arch/tile/include/asm/atomic.h50
-rw-r--r--arch/tile/include/asm/atomic_32.h2
-rw-r--r--arch/tile/include/asm/bitops_64.h8
-rw-r--r--arch/tile/include/asm/cmpxchg.h73
-rw-r--r--arch/tile/include/asm/irq.h2
-rw-r--r--arch/tile/include/asm/pci.h4
-rw-r--r--arch/tile/include/asm/spinlock_64.h2
-rw-r--r--arch/tile/include/asm/stack.h1
-rw-r--r--arch/tile/include/asm/traps.h6
-rw-r--r--arch/tile/kernel/entry.S2
-rw-r--r--arch/tile/kernel/intvec_32.S24
-rw-r--r--arch/tile/kernel/intvec_64.S52
-rw-r--r--arch/tile/kernel/module.c2
-rw-r--r--arch/tile/kernel/pci.c4
-rw-r--r--arch/tile/kernel/proc.c4
-rw-r--r--arch/tile/kernel/process.c3
-rw-r--r--arch/tile/kernel/setup.c36
-rw-r--r--arch/tile/kernel/single_step.c35
-rw-r--r--arch/tile/kernel/smp.c8
-rw-r--r--arch/tile/kernel/smpboot.c2
-rw-r--r--arch/tile/kernel/stack.c232
-rw-r--r--arch/tile/kernel/traps.c15
-rw-r--r--arch/tile/lib/Makefile1
-rw-r--r--arch/tile/lib/cacheflush.c30
-rw-r--r--arch/tile/lib/memcpy_user_64.c8
-rw-r--r--arch/tile/lib/spinlock_common.h2
-rw-r--r--arch/tile/mm/fault.c22
-rw-r--r--arch/tile/mm/homecache.c1
-rw-r--r--arch/tile/mm/init.c26
-rw-r--r--arch/tile/mm/pgtable.c38
-rw-r--r--arch/um/drivers/cow.h35
-rw-r--r--arch/um/drivers/cow_user.c43
-rw-r--r--arch/um/drivers/mconsole_kern.c1
-rw-r--r--arch/um/include/asm/Kbuild3
-rw-r--r--arch/um/kernel/Makefile7
-rw-r--r--arch/um/kernel/process.c6
-rw-r--r--arch/um/kernel/skas/mmu.c1
-rw-r--r--arch/um/kernel/skas/process.c2
-rw-r--r--arch/um/kernel/smp.c9
-rw-r--r--arch/unicore32/include/asm/dma-mapping.h18
-rw-r--r--arch/unicore32/mm/dma-swiotlb.c18
-rw-r--r--arch/x86/Kconfig2
-rw-r--r--arch/x86/Makefile1
-rw-r--r--arch/x86/Makefile.um3
-rw-r--r--arch/x86/boot/compressed/head_32.S14
-rw-r--r--arch/x86/boot/compressed/head_64.S22
-rw-r--r--arch/x86/boot/compressed/relocs.c2
-rw-r--r--arch/x86/boot/tools/build.c15
-rw-r--r--arch/x86/ia32/ia32_aout.c35
-rw-r--r--arch/x86/include/asm/cmpxchg.h4
-rw-r--r--arch/x86/include/asm/dma-mapping.h26
-rw-r--r--arch/x86/include/asm/posix_types.h6
-rw-r--r--arch/x86/include/asm/processor.h10
-rw-r--r--arch/x86/include/asm/sigcontext.h2
-rw-r--r--arch/x86/include/asm/siginfo.h8
-rw-r--r--arch/x86/include/asm/uaccess.h2
-rw-r--r--arch/x86/include/asm/uaccess_32.h5
-rw-r--r--arch/x86/include/asm/uaccess_64.h4
-rw-r--r--arch/x86/include/asm/unistd.h6
-rw-r--r--arch/x86/include/asm/word-at-a-time.h79
-rw-r--r--arch/x86/include/asm/x86_init.h1
-rw-r--r--arch/x86/kernel/acpi/sleep.c4
-rw-r--r--arch/x86/kernel/acpi/sleep.h4
-rw-r--r--arch/x86/kernel/acpi/wakeup_32.S4
-rw-r--r--arch/x86/kernel/acpi/wakeup_64.S4
-rw-r--r--arch/x86/kernel/amd_gart_64.c11
-rw-r--r--arch/x86/kernel/apic/apic.c34
-rw-r--r--arch/x86/kernel/apic/apic_numachip.c7
-rw-r--r--arch/x86/kernel/apic/x2apic_phys.c6
-rw-r--r--arch/x86/kernel/cpu/amd.c29
-rw-r--r--arch/x86/kernel/cpu/common.c9
-rw-r--r--arch/x86/kernel/cpu/intel_cacheinfo.c8
-rw-r--r--arch/x86/kernel/cpu/perf_event_p4.c13
-rw-r--r--arch/x86/kernel/i387.c1
-rw-r--r--arch/x86/kernel/irq.c7
-rw-r--r--arch/x86/kernel/kdebugfs.c9
-rw-r--r--arch/x86/kernel/kgdb.c60
-rw-r--r--arch/x86/kernel/kvm.c13
-rw-r--r--arch/x86/kernel/microcode_amd.c12
-rw-r--r--arch/x86/kernel/microcode_core.c10
-rw-r--r--arch/x86/kernel/pci-calgary_64.c9
-rw-r--r--arch/x86/kernel/pci-dma.c3
-rw-r--r--arch/x86/kernel/pci-nommu.c6
-rw-r--r--arch/x86/kernel/pci-swiotlb.c17
-rw-r--r--arch/x86/kernel/process.c24
-rw-r--r--arch/x86/kernel/process_64.c1
-rw-r--r--arch/x86/kernel/setup_percpu.c14
-rw-r--r--arch/x86/kernel/vsyscall_64.c6
-rw-r--r--arch/x86/kernel/x86_init.c1
-rw-r--r--arch/x86/kvm/pmu.c20
-rw-r--r--arch/x86/kvm/vmx.c7
-rw-r--r--arch/x86/kvm/x86.c9
-rw-r--r--arch/x86/lib/insn.c53
-rw-r--r--arch/x86/lib/usercopy.c103
-rw-r--r--arch/x86/lib/usercopy_32.c87
-rw-r--r--arch/x86/lib/usercopy_64.c49
-rw-r--r--arch/x86/net/bpf_jit.S122
-rw-r--r--arch/x86/net/bpf_jit_comp.c43
-rw-r--r--arch/x86/platform/geode/net5501.c2
-rw-r--r--arch/x86/platform/mrst/mrst.c4
-rw-r--r--arch/x86/power/cpu.c2
-rw-r--r--arch/x86/um/asm/barrier.h75
-rw-r--r--arch/x86/um/asm/system.h135
-rw-r--r--arch/x86/xen/enlighten.c48
-rw-r--r--arch/x86/xen/mmu.c11
-rw-r--r--arch/x86/xen/pci-swiotlb-xen.c4
-rw-r--r--arch/x86/xen/smp.c17
-rw-r--r--arch/x86/xen/xen-asm.S2
-rw-r--r--arch/xtensa/include/asm/hardirq.h3
-rw-r--r--arch/xtensa/include/asm/io.h1
-rw-r--r--arch/xtensa/kernel/signal.c1
-rw-r--r--block/blk-core.c5
-rw-r--r--block/blk-throttle.c2
-rw-r--r--block/cfq-iosched.c10
-rw-r--r--crypto/Kconfig6
-rw-r--r--crypto/ablkcipher.c4
-rw-r--r--crypto/aead.c4
-rw-r--r--crypto/crypto_user.c80
-rw-r--r--crypto/pcrypt.c8
-rw-r--r--crypto/sha512_generic.c2
-rw-r--r--drivers/Kconfig2
-rw-r--r--drivers/Makefile1
-rw-r--r--drivers/acpi/acpica/hwxface.c3
-rw-r--r--drivers/acpi/ec_sys.c8
-rw-r--r--drivers/acpi/osl.c3
-rw-r--r--drivers/acpi/power.c2
-rw-r--r--drivers/acpi/processor_idle.c2
-rw-r--r--drivers/acpi/reboot.c3
-rw-r--r--drivers/acpi/scan.c17
-rw-r--r--drivers/acpi/sleep.c52
-rw-r--r--drivers/amba/bus.c42
-rw-r--r--drivers/ata/ahci.c2
-rw-r--r--drivers/ata/ahci_platform.c1
-rw-r--r--drivers/ata/ata_piix.c2
-rw-r--r--drivers/ata/libata-core.c4
-rw-r--r--drivers/ata/libata-eh.c3
-rw-r--r--drivers/ata/libata-scsi.c38
-rw-r--r--drivers/ata/libata-transport.c1
-rw-r--r--drivers/ata/libata.h2
-rw-r--r--drivers/ata/pata_arasan_cf.c4
-rw-r--r--drivers/ata/sata_mv.c3
-rw-r--r--drivers/base/firmware_class.c208
-rw-r--r--drivers/base/power/runtime.c3
-rw-r--r--drivers/base/regmap/Kconfig3
-rw-r--r--drivers/base/regmap/Makefile1
-rw-r--r--drivers/base/regmap/internal.h22
-rw-r--r--drivers/base/regmap/regcache-lzo.c11
-rw-r--r--drivers/base/regmap/regcache-rbtree.c52
-rw-r--r--drivers/base/regmap/regcache.c35
-rw-r--r--drivers/base/regmap/regmap-debugfs.c30
-rw-r--r--drivers/base/regmap/regmap-i2c.c13
-rw-r--r--drivers/base/regmap/regmap-irq.c37
-rw-r--r--drivers/base/regmap/regmap-mmio.c224
-rw-r--r--drivers/base/regmap/regmap-spi.c13
-rw-r--r--drivers/base/regmap/regmap.c171
-rw-r--r--drivers/base/soc.c4
-rw-r--r--drivers/bcma/Kconfig2
-rw-r--r--drivers/bcma/driver_pci_host.c1
-rw-r--r--drivers/bcma/sprom.c7
-rw-r--r--drivers/block/cciss_scsi.c3
-rw-r--r--drivers/block/drbd/drbd_nl.c2
-rw-r--r--drivers/block/floppy.c36
-rw-r--r--drivers/block/mtip32xx/Kconfig2
-rw-r--r--drivers/block/mtip32xx/mtip32xx.c860
-rw-r--r--drivers/block/mtip32xx/mtip32xx.h58
-rw-r--r--drivers/block/virtio_blk.c42
-rw-r--r--drivers/block/xen-blkback/blkback.c50
-rw-r--r--drivers/block/xen-blkback/common.h6
-rw-r--r--drivers/block/xen-blkback/xenbus.c89
-rw-r--r--drivers/block/xen-blkfront.c43
-rw-r--r--drivers/bluetooth/ath3k.c8
-rw-r--r--drivers/bluetooth/btmrvl_debugfs.c26
-rw-r--r--drivers/bluetooth/btusb.c11
-rw-r--r--drivers/bluetooth/hci_ldisc.c2
-rw-r--r--drivers/char/agp/intel-agp.h1
-rw-r--r--drivers/char/agp/intel-gtt.c3
-rw-r--r--drivers/char/apm-emulation.c2
-rw-r--r--drivers/char/hpet.c4
-rw-r--r--drivers/char/random.c11
-rw-r--r--drivers/char/tile-srom.c12
-rw-r--r--drivers/char/virtio_console.c8
-rw-r--r--drivers/clocksource/acpi_pm.c24
-rw-r--r--drivers/cpufreq/Kconfig.arm11
-rw-r--r--drivers/cpufreq/db8500-cpufreq.c2
-rw-r--r--drivers/cpuidle/cpuidle.c5
-rw-r--r--drivers/crypto/ixp4xx_crypto.c1
-rw-r--r--drivers/crypto/talitos.c20
-rw-r--r--drivers/dma/Kconfig5
-rw-r--r--drivers/dma/amba-pl08x.c1
-rw-r--r--drivers/dma/at_hdmac.c4
-rw-r--r--drivers/dma/coh901318.c9
-rw-r--r--drivers/dma/dmaengine.c14
-rw-r--r--drivers/dma/imx-dma.c9
-rw-r--r--drivers/dma/ioat/dma.c16
-rw-r--r--drivers/dma/ioat/dma.h6
-rw-r--r--drivers/dma/ioat/dma_v2.c12
-rw-r--r--drivers/dma/ioat/dma_v2.h4
-rw-r--r--drivers/dma/ioat/dma_v3.c49
-rw-r--r--drivers/dma/iop-adma.c4
-rw-r--r--drivers/dma/mxs-dma.c10
-rw-r--r--drivers/dma/pl330.c25
-rw-r--r--drivers/dma/sa11x0-dma.c2
-rw-r--r--drivers/dma/ste_dma40.c323
-rw-r--r--drivers/dma/ste_dma40_ll.h2
-rw-r--r--drivers/edac/mce_amd.c6
-rw-r--r--drivers/edac/tile_edac.c4
-rw-r--r--drivers/firmware/efivars.c196
-rw-r--r--drivers/gpio/Kconfig2
-rw-r--r--drivers/gpio/gpio-adp5588.c2
-rw-r--r--drivers/gpio/gpio-omap.c9
-rw-r--r--drivers/gpio/gpio-pch.c57
-rw-r--r--drivers/gpio/gpio-pxa.c21
-rw-r--r--drivers/gpio/gpio-samsung.c34
-rw-r--r--drivers/gpio/gpio-sodaville.c23
-rw-r--r--drivers/gpio/gpio-tegra.c59
-rw-r--r--drivers/gpu/drm/Kconfig1
-rw-r--r--drivers/gpu/drm/Makefile2
-rw-r--r--drivers/gpu/drm/drm_bufs.c12
-rw-r--r--drivers/gpu/drm/drm_crtc.c10
-rw-r--r--drivers/gpu/drm/drm_drv.c4
-rw-r--r--drivers/gpu/drm/drm_fb_helper.c8
-rw-r--r--drivers/gpu/drm/drm_fops.c13
-rw-r--r--drivers/gpu/drm/drm_gem.c9
-rw-r--r--drivers/gpu/drm/drm_prime.c304
-rw-r--r--drivers/gpu/drm/drm_usb.c6
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_buf.c47
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_core.c14
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_drv.h10
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_fimd.c20
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_gem.c79
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_gem.h2
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_hdmi.c107
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_hdmi.h23
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_plane.c4
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_vidi.c20
-rw-r--r--drivers/gpu/drm/exynos/exynos_hdmi.c42
-rw-r--r--drivers/gpu/drm/exynos/exynos_mixer.c40
-rw-r--r--drivers/gpu/drm/gma500/mdfld_dsi_output.h1
-rw-r--r--drivers/gpu/drm/i810/i810_dma.c6
-rw-r--r--drivers/gpu/drm/i915/i915_debugfs.c17
-rw-r--r--drivers/gpu/drm/i915/i915_dma.c36
-rw-r--r--drivers/gpu/drm/i915/i915_drv.c15
-rw-r--r--drivers/gpu/drm/i915/i915_drv.h23
-rw-r--r--drivers/gpu/drm/i915/i915_gem.c43
-rw-r--r--drivers/gpu/drm/i915/i915_gem_execbuffer.c10
-rw-r--r--drivers/gpu/drm/i915/i915_gem_gtt.c9
-rw-r--r--drivers/gpu/drm/i915/i915_reg.h5
-rw-r--r--drivers/gpu/drm/i915/intel_bios.c23
-rw-r--r--drivers/gpu/drm/i915/intel_crt.c29
-rw-r--r--drivers/gpu/drm/i915/intel_display.c130
-rw-r--r--drivers/gpu/drm/i915/intel_dp.c49
-rw-r--r--drivers/gpu/drm/i915/intel_drv.h4
-rw-r--r--drivers/gpu/drm/i915/intel_fb.c4
-rw-r--r--drivers/gpu/drm/i915/intel_hdmi.c2
-rw-r--r--drivers/gpu/drm/i915/intel_i2c.c2
-rw-r--r--drivers/gpu/drm/i915/intel_lvds.c18
-rw-r--r--drivers/gpu/drm/i915/intel_panel.c2
-rw-r--r--drivers/gpu/drm/i915/intel_ringbuffer.c15
-rw-r--r--drivers/gpu/drm/i915/intel_sdvo.c40
-rw-r--r--drivers/gpu/drm/i915/intel_sprite.c4
-rw-r--r--drivers/gpu/drm/nouveau/Kconfig1
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_acpi.c2
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_bios.c15
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_channel.c10
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_dma.h4
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_hdmi.c4
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_i2c.c199
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_i2c.h1
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_pm.c1
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_state.c2
-rw-r--r--drivers/gpu/drm/nouveau/nv10_gpio.c2
-rw-r--r--drivers/gpu/drm/nouveau/nv50_sor.c2
-rw-r--r--drivers/gpu/drm/nouveau/nvc0_fb.c5
-rw-r--r--drivers/gpu/drm/radeon/atom.c15
-rw-r--r--drivers/gpu/drm/radeon/atom.h1
-rw-r--r--drivers/gpu/drm/radeon/atombios_crtc.c7
-rw-r--r--drivers/gpu/drm/radeon/atombios_encoders.c4
-rw-r--r--drivers/gpu/drm/radeon/r100.c2
-rw-r--r--drivers/gpu/drm/radeon/r600.c6
-rw-r--r--drivers/gpu/drm/radeon/r600_cp.c6
-rw-r--r--drivers/gpu/drm/radeon/radeon_clocks.c24
-rw-r--r--drivers/gpu/drm/radeon/radeon_combios.c8
-rw-r--r--drivers/gpu/drm/radeon/radeon_connectors.c4
-rw-r--r--drivers/gpu/drm/radeon/radeon_device.c4
-rw-r--r--drivers/gpu/drm/radeon/radeon_display.c3
-rw-r--r--drivers/gpu/drm/radeon/radeon_i2c.c4
-rw-r--r--drivers/gpu/drm/radeon/radeon_irq_kms.c6
-rw-r--r--drivers/gpu/drm/radeon/radeon_legacy_encoders.c12
-rw-r--r--drivers/gpu/drm/radeon/radeon_object.c3
-rw-r--r--drivers/gpu/drm/radeon/rv770.c4
-rw-r--r--drivers/gpu/drm/radeon/si.c5
-rw-r--r--drivers/gpu/drm/savage/savage_state.c6
-rw-r--r--drivers/gpu/drm/udl/udl_drv.c2
-rw-r--r--drivers/gpu/drm/udl/udl_drv.h1
-rw-r--r--drivers/gpu/drm/udl/udl_gem.c14
-rw-r--r--drivers/hid/Kconfig2
-rw-r--r--drivers/hid/hid-picolcd.c16
-rw-r--r--drivers/hid/hid-tivo.c2
-rw-r--r--drivers/hid/hid-wiimote-debug.c8
-rw-r--r--drivers/hsi/Kconfig19
-rw-r--r--drivers/hsi/Makefile6
-rw-r--r--drivers/hsi/clients/Kconfig13
-rw-r--r--drivers/hsi/clients/Makefile5
-rw-r--r--drivers/hsi/clients/hsi_char.c802
-rw-r--r--drivers/hsi/hsi.c507
-rw-r--r--drivers/hsi/hsi_boardinfo.c62
-rw-r--r--drivers/hsi/hsi_core.h35
-rw-r--r--drivers/hwmon/Kconfig7
-rw-r--r--drivers/hwmon/acpi_power_meter.c3
-rw-r--r--drivers/hwmon/ad7314.c13
-rw-r--r--drivers/hwmon/adm1031.c20
-rw-r--r--drivers/hwmon/ads1015.c33
-rw-r--r--drivers/hwmon/coretemp.c6
-rw-r--r--drivers/hwmon/f75375s.c2
-rw-r--r--drivers/hwmon/fam15h_power.c42
-rw-r--r--drivers/hwmon/k10temp.c4
-rw-r--r--drivers/hwmon/max6639.c15
-rw-r--r--drivers/hwmon/pmbus/pmbus_core.c17
-rw-r--r--drivers/hwmon/smsc47b397.c14
-rw-r--r--drivers/hwmon/smsc47m1.c19
-rw-r--r--drivers/hwmon/w83627ehf.c18
-rw-r--r--drivers/i2c/busses/i2c-designware-pcidrv.c1
-rw-r--r--drivers/i2c/busses/i2c-eg20t.c4
-rw-r--r--drivers/i2c/busses/i2c-mxs.c8
-rw-r--r--drivers/i2c/busses/i2c-pnx.c3
-rw-r--r--drivers/i2c/busses/i2c-tegra.c8
-rw-r--r--drivers/idle/i7300_idle.c8
-rw-r--r--drivers/infiniband/core/mad.c8
-rw-r--r--drivers/infiniband/core/sysfs.c9
-rw-r--r--drivers/infiniband/hw/mlx4/main.c7
-rw-r--r--drivers/infiniband/ulp/srpt/ib_srpt.c1
-rw-r--r--drivers/input/misc/Kconfig3
-rw-r--r--drivers/input/misc/da9052_onkey.c3
-rw-r--r--drivers/input/misc/twl6040-vibra.c4
-rw-r--r--drivers/input/mouse/elantech.c10
-rw-r--r--drivers/input/mouse/gpio_mouse.c2
-rw-r--r--drivers/input/mouse/sentelic.c8
-rw-r--r--drivers/input/mouse/synaptics.c3
-rw-r--r--drivers/input/mouse/trackpoint.c14
-rw-r--r--drivers/input/touchscreen/tps6507x-ts.c4
-rw-r--r--drivers/iommu/amd_iommu.c10
-rw-r--r--drivers/iommu/intel-iommu.c9
-rw-r--r--drivers/iommu/omap-iommu-debug.c10
-rw-r--r--drivers/isdn/gigaset/interface.c2
-rw-r--r--drivers/isdn/hardware/mISDN/avmfritz.c2
-rw-r--r--drivers/isdn/hardware/mISDN/hfcpci.c2
-rw-r--r--drivers/isdn/hardware/mISDN/hfcsusb.c2
-rw-r--r--drivers/isdn/hardware/mISDN/mISDNipac.c2
-rw-r--r--drivers/isdn/hardware/mISDN/mISDNisar.c2
-rw-r--r--drivers/isdn/hardware/mISDN/netjet.c2
-rw-r--r--drivers/isdn/hardware/mISDN/w6692.c2
-rw-r--r--drivers/leds/leds-atmel-pwm.c2
-rw-r--r--drivers/leds/leds-netxbig.c4
-rw-r--r--drivers/leds/leds-ns2.c2
-rw-r--r--drivers/md/bitmap.c8
-rw-r--r--drivers/md/bitmap.h3
-rw-r--r--drivers/md/dm-log-userspace-transfer.c2
-rw-r--r--drivers/md/dm-mpath.c4
-rw-r--r--drivers/md/dm-raid.c4
-rw-r--r--drivers/md/dm-thin.c16
-rw-r--r--drivers/md/linear.c9
-rw-r--r--drivers/md/md.c7
-rw-r--r--drivers/md/raid0.c27
-rw-r--r--drivers/md/raid1.c16
-rw-r--r--drivers/md/raid10.c6
-rw-r--r--drivers/md/raid5.c59
-rw-r--r--drivers/media/common/tuners/xc5000.c39
-rw-r--r--drivers/media/common/tuners/xc5000.h1
-rw-r--r--drivers/media/dvb/dvb-core/dvb_frontend.c37
-rw-r--r--drivers/media/dvb/dvb-usb/it913x.c54
-rw-r--r--drivers/media/dvb/frontends/drxk_hard.c6
-rw-r--r--drivers/media/rc/winbond-cir.c1
-rw-r--r--drivers/media/video/Kconfig2
-rw-r--r--drivers/media/video/ivtv/ivtv-ioctl.c4
-rw-r--r--drivers/media/video/mt9m032.c5
-rw-r--r--drivers/media/video/uvc/uvc_video.c50
-rw-r--r--drivers/mfd/Kconfig11
-rw-r--r--drivers/mfd/aat2870-core.c9
-rw-r--r--drivers/mfd/ab3100-core.c8
-rw-r--r--drivers/mfd/asic3.c4
-rw-r--r--drivers/mfd/db8500-prcmu.c1
-rw-r--r--drivers/mfd/mc13xxx-core.c3
-rw-r--r--drivers/mfd/omap-usb-host.c45
-rw-r--r--drivers/mfd/rc5t583.c39
-rw-r--r--drivers/mfd/twl6040-core.c114
-rw-r--r--drivers/misc/ibmasm/ibmasmfs.c8
-rw-r--r--drivers/misc/kgdbts.c160
-rw-r--r--drivers/mmc/card/block.c83
-rw-r--r--drivers/mmc/card/queue.c2
-rw-r--r--drivers/mmc/core/bus.c41
-rw-r--r--drivers/mmc/core/cd-gpio.c1
-rw-r--r--drivers/mmc/core/core.c74
-rw-r--r--drivers/mmc/core/mmc.c30
-rw-r--r--drivers/mmc/core/sdio_bus.c12
-rw-r--r--drivers/mmc/host/atmel-mci-regs.h1
-rw-r--r--drivers/mmc/host/atmel-mci.c55
-rw-r--r--drivers/mmc/host/dw_mmc.c7
-rw-r--r--drivers/mmc/host/mxs-mmc.c3
-rw-r--r--drivers/mmc/host/omap_hsmmc.c187
-rw-r--r--drivers/mmc/host/sdhci-dove.c1
-rw-r--r--drivers/mmc/host/sdhci-esdhc-imx.c3
-rw-r--r--drivers/mmc/host/sdhci-pci.c6
-rw-r--r--drivers/mmc/host/sdhci-s3c.c159
-rw-r--r--drivers/mmc/host/sdhci.c7
-rw-r--r--drivers/mmc/host/sh_mmcif.c13
-rw-r--r--drivers/mtd/mtdchar.c20
-rw-r--r--drivers/mtd/nand/gpmi-nand/gpmi-nand.c1
-rw-r--r--drivers/mtd/ubi/debug.c10
-rw-r--r--drivers/net/arcnet/arc-rimi.c8
-rw-r--r--drivers/net/bonding/bond_3ad.c18
-rw-r--r--drivers/net/bonding/bond_3ad.h2
-rw-r--r--drivers/net/bonding/bond_main.c84
-rw-r--r--drivers/net/caif/caif_hsi.c9
-rw-r--r--drivers/net/caif/caif_spi.c10
-rw-r--r--drivers/net/can/usb/peak_usb/pcan_usb_pro.c2
-rw-r--r--drivers/net/dummy.c6
-rw-r--r--drivers/net/eql.c7
-rw-r--r--drivers/net/ethernet/atheros/atlx/atl1.c12
-rw-r--r--drivers/net/ethernet/atheros/atlx/atl1.h3
-rw-r--r--drivers/net/ethernet/atheros/atlx/atlx.c2
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x.h7
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c41
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h3
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_fw_defs.h110
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_hsi.h3
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_link.c160
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_link.h2
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c485
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_reg.h12
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c2
-rw-r--r--drivers/net/ethernet/broadcom/tg3.c22
-rw-r--r--drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c92
-rw-r--r--drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c9
-rw-r--r--drivers/net/ethernet/dlink/dl2k.c52
-rw-r--r--drivers/net/ethernet/dlink/dl2k.h7
-rw-r--r--drivers/net/ethernet/freescale/fsl_pq_mdio.c12
-rw-r--r--drivers/net/ethernet/freescale/ucc_geth.c12
-rw-r--r--drivers/net/ethernet/freescale/ucc_geth.h2
-rw-r--r--drivers/net/ethernet/ibm/ehea/ehea_main.c62
-rw-r--r--drivers/net/ethernet/ibm/ehea/ehea_phyp.h2
-rw-r--r--drivers/net/ethernet/intel/e1000/e1000_main.c44
-rw-r--r--drivers/net/ethernet/intel/e1000e/e1000.h6
-rw-r--r--drivers/net/ethernet/intel/e1000e/ich8lan.c15
-rw-r--r--drivers/net/ethernet/intel/e1000e/netdev.c35
-rw-r--r--drivers/net/ethernet/intel/e1000e/param.c99
-rw-r--r--drivers/net/ethernet/intel/igb/igb_main.c31
-rw-r--r--drivers/net/ethernet/intel/igbvf/netdev.c11
-rw-r--r--drivers/net/ethernet/intel/ixgb/ixgb_main.c6
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe.h5
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_dcb_nl.c195
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c2
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c1
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_lib.c10
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_main.c52
-rw-r--r--drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c7
-rw-r--r--drivers/net/ethernet/marvell/sky2.c49
-rw-r--r--drivers/net/ethernet/marvell/sky2.h1
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/mlx4_en.h5
-rw-r--r--drivers/net/ethernet/micrel/ks8851.c28
-rw-r--r--drivers/net/ethernet/micrel/ks8851_mll.c2
-rw-r--r--drivers/net/ethernet/micrel/ksz884x.c2
-rw-r--r--drivers/net/ethernet/nxp/lpc_eth.c2
-rw-r--r--drivers/net/ethernet/realtek/8139cp.c10
-rw-r--r--drivers/net/ethernet/realtek/r8169.c19
-rw-r--r--drivers/net/ethernet/renesas/Kconfig5
-rw-r--r--drivers/net/ethernet/renesas/sh_eth.c22
-rw-r--r--drivers/net/ethernet/renesas/sh_eth.h15
-rw-r--r--drivers/net/ethernet/sfc/efx.c2
-rw-r--r--drivers/net/ethernet/smsc/smsc911x.c17
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/stmmac_main.c6
-rw-r--r--drivers/net/ethernet/sun/sungem.c2
-rw-r--r--drivers/net/ethernet/ti/davinci_emac.c2
-rw-r--r--drivers/net/ethernet/ti/davinci_mdio.c5
-rw-r--r--drivers/net/ethernet/ti/tlan.c2
-rw-r--r--drivers/net/ethernet/tile/tilepro.c77
-rw-r--r--drivers/net/ethernet/via/via-rhine.c12
-rw-r--r--drivers/net/ethernet/xilinx/xilinx_axienet.h4
-rw-r--r--drivers/net/ethernet/xilinx/xilinx_axienet_main.c6
-rw-r--r--drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c6
-rw-r--r--drivers/net/hyperv/netvsc_drv.c38
-rw-r--r--drivers/net/irda/sa1100_ir.c2
-rw-r--r--drivers/net/macvlan.c2
-rw-r--r--drivers/net/macvtap.c43
-rw-r--r--drivers/net/phy/icplus.c15
-rw-r--r--drivers/net/ppp/ppp_generic.c3
-rw-r--r--drivers/net/rionet.c11
-rw-r--r--drivers/net/usb/asix.c4
-rw-r--r--drivers/net/usb/cdc-phonet.c4
-rw-r--r--drivers/net/usb/cdc_eem.c1
-rw-r--r--drivers/net/usb/cdc_ether.c14
-rw-r--r--drivers/net/usb/qmi_wwan.c30
-rw-r--r--drivers/net/usb/rtl8150.c26
-rw-r--r--drivers/net/usb/smsc75xx.c36
-rw-r--r--drivers/net/usb/smsc95xx.c3
-rw-r--r--drivers/net/usb/usbnet.c5
-rw-r--r--drivers/net/usb/zaurus.c5
-rw-r--r--drivers/net/virtio_net.c10
-rw-r--r--drivers/net/wan/farsync.c1
-rw-r--r--drivers/net/wimax/i2400m/debugfs.c15
-rw-r--r--drivers/net/wimax/i2400m/netdev.c3
-rw-r--r--drivers/net/wimax/i2400m/usb.c18
-rw-r--r--drivers/net/wireless/ath/ath5k/ahb.c8
-rw-r--r--drivers/net/wireless/ath/ath5k/debug.c23
-rw-r--r--drivers/net/wireless/ath/ath6kl/debug.c42
-rw-r--r--drivers/net/wireless/ath/ath9k/ar5008_phy.c2
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9003_paprd.c2
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9003_phy.c6
-rw-r--r--drivers/net/wireless/ath/ath9k/calib.c5
-rw-r--r--drivers/net/wireless/ath/ath9k/debug.c37
-rw-r--r--drivers/net/wireless/ath/ath9k/dfs_debug.c9
-rw-r--r--drivers/net/wireless/ath/ath9k/eeprom_9287.c2
-rw-r--r--drivers/net/wireless/ath/ath9k/htc_drv_debug.c26
-rw-r--r--drivers/net/wireless/ath/ath9k/hw.c9
-rw-r--r--drivers/net/wireless/ath/ath9k/hw.h3
-rw-r--r--drivers/net/wireless/ath/ath9k/init.c2
-rw-r--r--drivers/net/wireless/ath/ath9k/main.c21
-rw-r--r--drivers/net/wireless/ath/ath9k/rc.c8
-rw-r--r--drivers/net/wireless/ath/ath9k/recv.c4
-rw-r--r--drivers/net/wireless/ath/ath9k/xmit.c10
-rw-r--r--drivers/net/wireless/ath/carl9170/debug.c7
-rw-r--r--drivers/net/wireless/b43/debugfs.c8
-rw-r--r--drivers/net/wireless/b43/main.c10
-rw-r--r--drivers/net/wireless/b43legacy/debugfs.c8
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/bcmsdh_sdmmc.c8
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c64
-rw-r--r--drivers/net/wireless/brcm80211/brcmsmac/main.c11
-rw-r--r--drivers/net/wireless/ipw2x00/ipw2200.c17
-rw-r--r--drivers/net/wireless/iwlegacy/3945-mac.c2
-rw-r--r--drivers/net/wireless/iwlegacy/3945-rs.c8
-rw-r--r--drivers/net/wireless/iwlegacy/4965-mac.c2
-rw-r--r--drivers/net/wireless/iwlegacy/4965-rs.c12
-rw-r--r--drivers/net/wireless/iwlegacy/common.c31
-rw-r--r--drivers/net/wireless/iwlegacy/debug.c12
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-1000.c8
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-2000.c16
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-5000.c11
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-6000.c10
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-rs.c11
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-rx.c21
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn.c3
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-debugfs.c12
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-fh.h24
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-mac80211.c10
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-prph.h27
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-trans-pcie-rx.c3
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-trans-pcie.c12
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-trans.h1
-rw-r--r--drivers/net/wireless/iwmc3200wifi/debugfs.c14
-rw-r--r--drivers/net/wireless/iwmc3200wifi/sdio.c9
-rw-r--r--drivers/net/wireless/libertas/cfg.c9
-rw-r--r--drivers/net/wireless/libertas/debugfs.c10
-rw-r--r--drivers/net/wireless/mwifiex/debugfs.c18
-rw-r--r--drivers/net/wireless/mwifiex/pcie.h18
-rw-r--r--drivers/net/wireless/orinoco/main.c8
-rw-r--r--drivers/net/wireless/rt2x00/rt2800usb.c10
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00dev.c6
-rw-r--r--drivers/net/wireless/rtlwifi/base.c5
-rw-r--r--drivers/net/wireless/rtlwifi/pci.c8
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192c/phy_common.c2
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192de/phy.c2
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192de/sw.c6
-rw-r--r--drivers/net/wireless/rtlwifi/usb.c34
-rw-r--r--drivers/net/wireless/rtlwifi/wifi.h6
-rw-r--r--drivers/net/wireless/wl1251/debugfs.c14
-rw-r--r--drivers/net/wireless/wl1251/main.c1
-rw-r--r--drivers/net/wireless/wl1251/sdio.c2
-rw-r--r--drivers/net/wireless/wl12xx/debugfs.c38
-rw-r--r--drivers/net/xen-netfront.c2
-rw-r--r--drivers/of/gpio.c2
-rw-r--r--drivers/oprofile/oprofilefs.c14
-rw-r--r--drivers/parisc/sba_iommu.c1
-rw-r--r--drivers/pci/Makefile1
-rw-r--r--drivers/pci/pci-acpi.c4
-rw-r--r--drivers/pci/pci.c71
-rw-r--r--drivers/pci/xen-pcifront.c1
-rw-r--r--drivers/pinctrl/core.c25
-rw-r--r--drivers/platform/x86/acerhdf.c67
-rw-r--r--drivers/platform/x86/dell-laptop.c1
-rw-r--r--drivers/platform/x86/intel_ips.c2
-rw-r--r--drivers/platform/x86/intel_mid_powerbtn.c2
-rw-r--r--drivers/regulator/anatop-regulator.c11
-rw-r--r--drivers/regulator/core.c9
-rw-r--r--drivers/regulator/fixed-helper.c3
-rw-r--r--drivers/regulator/max8997.c2
-rw-r--r--drivers/regulator/mc13892-regulator.c10
-rw-r--r--drivers/regulator/s5m8767.c14
-rw-r--r--drivers/regulator/tps6586x-regulator.c5
-rw-r--r--drivers/regulator/wm831x-dcdc.c9
-rw-r--r--drivers/regulator/wm831x-isink.c2
-rw-r--r--drivers/regulator/wm831x-ldo.c7
-rw-r--r--drivers/regulator/wm8350-regulator.c34
-rw-r--r--drivers/remoteproc/remoteproc_debugfs.c13
-rw-r--r--drivers/rtc/rtc-88pm860x.c4
-rw-r--r--drivers/rtc/rtc-ds1307.c1
-rw-r--r--drivers/rtc/rtc-efi.c1
-rw-r--r--drivers/rtc/rtc-mpc5121.c3
-rw-r--r--drivers/rtc/rtc-pl031.c3
-rw-r--r--drivers/rtc/rtc-r9701.c22
-rw-r--r--drivers/rtc/rtc-s3c.c31
-rw-r--r--drivers/rtc/rtc-twl.c43
-rw-r--r--drivers/s390/block/dasd_eckd.c24
-rw-r--r--drivers/s390/char/vmur.c2
-rw-r--r--drivers/s390/net/qeth_core_main.c6
-rw-r--r--drivers/scsi/hosts.c3
-rw-r--r--drivers/scsi/ipr.c6
-rw-r--r--drivers/scsi/libfc/fc_lport.c12
-rw-r--r--drivers/scsi/libsas/sas_ata.c33
-rw-r--r--drivers/scsi/libsas/sas_discover.c61
-rw-r--r--drivers/scsi/libsas/sas_event.c24
-rw-r--r--drivers/scsi/libsas/sas_expander.c56
-rw-r--r--drivers/scsi/libsas/sas_init.c11
-rw-r--r--drivers/scsi/libsas/sas_internal.h6
-rw-r--r--drivers/scsi/libsas/sas_phy.c21
-rw-r--r--drivers/scsi/libsas/sas_port.c17
-rw-r--r--drivers/scsi/lpfc/lpfc_debugfs.c9
-rw-r--r--drivers/scsi/qla2xxx/qla_bsg.c3
-rw-r--r--drivers/scsi/qla2xxx/qla_dbg.c2
-rw-r--r--drivers/scsi/qla2xxx/qla_isr.c15
-rw-r--r--drivers/scsi/qla2xxx/qla_nx.c1
-rw-r--r--drivers/scsi/qla2xxx/qla_os.c18
-rw-r--r--drivers/scsi/qla2xxx/qla_sup.c3
-rw-r--r--drivers/scsi/qla2xxx/qla_version.h6
-rw-r--r--drivers/scsi/scsi_error.c2
-rw-r--r--drivers/scsi/scsi_lib.c2
-rw-r--r--drivers/scsi/virtio_scsi.c24
-rw-r--r--drivers/spi/Kconfig2
-rw-r--r--drivers/spi/Makefile2
-rw-r--r--drivers/spi/spi-bcm63xx.c163
-rw-r--r--drivers/spi/spi-bfin-sport.c21
-rw-r--r--drivers/spi/spi-bfin5xx.c14
-rw-r--r--drivers/spi/spi-davinci.c6
-rw-r--r--drivers/spi/spi-dw.c8
-rw-r--r--drivers/spi/spi-ep93xx.c24
-rw-r--r--drivers/spi/spi-fsl-spi.c4
-rw-r--r--drivers/spi/spi-imx.c12
-rw-r--r--drivers/spi/spi-pl022.c60
-rw-r--r--drivers/staging/android/Kconfig3
-rw-r--r--drivers/staging/android/lowmemorykiller.c48
-rw-r--r--drivers/staging/android/persistent_ram.c11
-rw-r--r--drivers/staging/android/timed_gpio.c27
-rw-r--r--drivers/staging/iio/inkern.c1
-rw-r--r--drivers/staging/iio/magnetometer/ak8975.c8
-rw-r--r--drivers/staging/iio/magnetometer/hmc5843.c4
-rw-r--r--drivers/staging/media/as102/as102_fw.c2
-rw-r--r--drivers/staging/octeon/ethernet-rx.c1
-rw-r--r--drivers/staging/octeon/ethernet-tx.c1
-rw-r--r--drivers/staging/octeon/ethernet.c1
-rw-r--r--drivers/staging/omapdrm/omap_drv.c7
-rw-r--r--drivers/staging/ozwpan/TODO4
-rw-r--r--drivers/staging/ozwpan/ozpd.c2
-rw-r--r--drivers/staging/ramster/Kconfig6
-rw-r--r--drivers/staging/rts_pstor/ms.c3
-rw-r--r--drivers/staging/rts_pstor/rtsx.c5
-rw-r--r--drivers/staging/rts_pstor/rtsx_transport.c11
-rw-r--r--drivers/staging/sep/sep_main.c6
-rw-r--r--drivers/staging/tidspbridge/core/tiomap3430.c20
-rw-r--r--drivers/staging/tidspbridge/core/wdt.c8
-rw-r--r--drivers/staging/vme/devices/vme_pio2_core.c4
-rw-r--r--drivers/staging/vt6655/key.c3
-rw-r--r--drivers/staging/vt6656/ioctl.c3
-rw-r--r--drivers/staging/vt6656/key.c3
-rw-r--r--drivers/staging/xgifb/vb_init.c2
-rw-r--r--drivers/staging/xgifb/vb_setmode.c7
-rw-r--r--drivers/staging/xgifb/vb_table.h11
-rw-r--r--drivers/staging/zcache/Kconfig2
-rw-r--r--drivers/staging/zsmalloc/zsmalloc-main.c30
-rw-r--r--drivers/target/target_core_tpg.c22
-rw-r--r--drivers/target/tcm_fc/tcm_fc.h1
-rw-r--r--drivers/target/tcm_fc/tfc_cmd.c10
-rw-r--r--drivers/target/tcm_fc/tfc_conf.c13
-rw-r--r--drivers/target/tcm_fc/tfc_io.c2
-rw-r--r--drivers/tty/amiserial.c4
-rw-r--r--drivers/tty/serial/8250/8250.c12
-rw-r--r--drivers/tty/serial/8250/8250_pci.c16
-rw-r--r--drivers/tty/serial/Kconfig2
-rw-r--r--drivers/tty/serial/altera_uart.c4
-rw-r--r--drivers/tty/serial/amba-pl011.c8
-rw-r--r--drivers/tty/serial/atmel_serial.c4
-rw-r--r--drivers/tty/serial/clps711x.c14
-rw-r--r--drivers/tty/serial/mfd.c9
-rw-r--r--drivers/tty/serial/omap-serial.c43
-rw-r--r--drivers/tty/serial/pch_uart.c20
-rw-r--r--drivers/tty/serial/pmac_zilog.c6
-rw-r--r--drivers/tty/serial/samsung.c1
-rw-r--r--drivers/tty/serial/sh-sci.c167
-rw-r--r--drivers/tty/serial/sh-sci.h8
-rw-r--r--drivers/tty/serial/sunzilog.c4
-rw-r--r--drivers/tty/sysrq.c2
-rw-r--r--drivers/tty/vt/keyboard.c26
-rw-r--r--drivers/tty/vt/vt.c3
-rw-r--r--drivers/usb/Kconfig16
-rw-r--r--drivers/usb/class/cdc-wdm.c7
-rw-r--r--drivers/usb/core/driver.c9
-rw-r--r--drivers/usb/core/hcd-pci.c9
-rw-r--r--drivers/usb/core/hcd.c12
-rw-r--r--drivers/usb/core/hub.c19
-rw-r--r--drivers/usb/core/inode.c10
-rw-r--r--drivers/usb/core/message.c17
-rw-r--r--drivers/usb/core/urb.c12
-rw-r--r--drivers/usb/dwc3/core.c6
-rw-r--r--drivers/usb/dwc3/ep0.c12
-rw-r--r--drivers/usb/gadget/at91_udc.c8
-rw-r--r--drivers/usb/gadget/dummy_hcd.c1
-rw-r--r--drivers/usb/gadget/f_fs.c3
-rw-r--r--drivers/usb/gadget/f_mass_storage.c2
-rw-r--r--drivers/usb/gadget/f_phonet.c2
-rw-r--r--drivers/usb/gadget/f_rndis.c1
-rw-r--r--drivers/usb/gadget/file_storage.c2
-rw-r--r--drivers/usb/gadget/fsl_udc_core.c25
-rw-r--r--drivers/usb/gadget/g_ffs.c4
-rw-r--r--drivers/usb/gadget/inode.c1
-rw-r--r--drivers/usb/gadget/s3c-hsotg.c17
-rw-r--r--drivers/usb/gadget/udc-core.c6
-rw-r--r--drivers/usb/gadget/uvc.h2
-rw-r--r--drivers/usb/gadget/uvc_queue.c4
-rw-r--r--drivers/usb/gadget/uvc_v4l2.c2
-rw-r--r--drivers/usb/host/ehci-atmel.c1
-rw-r--r--drivers/usb/host/ehci-dbg.c9
-rw-r--r--drivers/usb/host/ehci-fsl.c7
-rw-r--r--drivers/usb/host/ehci-hcd.c12
-rw-r--r--drivers/usb/host/ehci-hub.c31
-rw-r--r--drivers/usb/host/ehci-omap.c39
-rw-r--r--drivers/usb/host/ehci-pci.c8
-rw-r--r--drivers/usb/host/ehci-tegra.c379
-rw-r--r--drivers/usb/host/ehci.h2
-rw-r--r--drivers/usb/host/ohci-at91.c175
-rw-r--r--drivers/usb/host/pci-quirks.c10
-rw-r--r--drivers/usb/host/uhci-hub.c5
-rw-r--r--drivers/usb/host/xhci-dbg.c2
-rw-r--r--drivers/usb/host/xhci-ext-caps.h5
-rw-r--r--drivers/usb/host/xhci-mem.c9
-rw-r--r--drivers/usb/host/xhci-pci.c4
-rw-r--r--drivers/usb/host/xhci-ring.c6
-rw-r--r--drivers/usb/host/xhci.c12
-rw-r--r--drivers/usb/host/xhci.h4
-rw-r--r--drivers/usb/misc/usbtest.c9
-rw-r--r--drivers/usb/misc/yurex.c10
-rw-r--r--drivers/usb/musb/davinci.c3
-rw-r--r--drivers/usb/musb/musb_core.c40
-rw-r--r--drivers/usb/musb/musb_core.h2
-rw-r--r--drivers/usb/musb/musb_host.c2
-rw-r--r--drivers/usb/musb/omap2430.c31
-rw-r--r--drivers/usb/otg/gpio_vbus.c15
-rw-r--r--drivers/usb/serial/bus.c5
-rw-r--r--drivers/usb/serial/cp210x.c9
-rw-r--r--drivers/usb/serial/ftdi_sio.c36
-rw-r--r--drivers/usb/serial/metro-usb.c6
-rw-r--r--drivers/usb/serial/option.c1
-rw-r--r--drivers/usb/serial/pl2303.c2
-rw-r--r--drivers/usb/serial/sierra.c5
-rw-r--r--drivers/usb/serial/usb-serial.c31
-rw-r--r--drivers/usb/storage/usb.c30
-rw-r--r--drivers/uwb/hwa-rc.c3
-rw-r--r--drivers/uwb/neh.c12
-rw-r--r--drivers/uwb/uwb-debug.c9
-rw-r--r--drivers/vhost/net.c9
-rw-r--r--drivers/vhost/test.c2
-rw-r--r--drivers/vhost/vhost.c5
-rw-r--r--drivers/vhost/vhost.h2
-rw-r--r--drivers/video/au1100fb.c5
-rw-r--r--drivers/video/au1200fb.c2
-rw-r--r--drivers/video/backlight/Kconfig6
-rw-r--r--drivers/video/backlight/Makefile1
-rw-r--r--drivers/video/backlight/da9052_bl.c187
-rw-r--r--drivers/video/backlight/locomolcd.c9
-rw-r--r--drivers/video/bfin-lq035q1-fb.c1
-rw-r--r--drivers/video/console/sticore.c2
-rw-r--r--drivers/video/kyro/STG4000Reg.h376
-rw-r--r--drivers/video/msm/mddi.c8
-rw-r--r--drivers/video/uvesafb.c13
-rw-r--r--drivers/video/xen-fbfront.c27
-rw-r--r--drivers/virtio/virtio_balloon.c58
-rw-r--r--drivers/watchdog/hpwdt.c6
-rw-r--r--drivers/xen/Kconfig22
-rw-r--r--drivers/xen/events.c2
-rw-r--r--drivers/xen/gntdev.c2
-rw-r--r--drivers/xen/grant-table.c13
-rw-r--r--drivers/xen/manage.c1
-rw-r--r--drivers/xen/swiotlb-xen.c5
-rw-r--r--drivers/xen/xen-acpi-processor.c5
-rw-r--r--drivers/xen/xen-pciback/pciback_ops.c2
-rw-r--r--drivers/xen/xenbus/xenbus_probe_frontend.c69
-rw-r--r--fs/aio.c16
-rw-r--r--fs/autofs4/autofs_i.h12
-rw-r--r--fs/autofs4/dev-ioctl.c3
-rw-r--r--fs/autofs4/inode.c4
-rw-r--r--fs/autofs4/waitq.c22
-rw-r--r--fs/binfmt_aout.c32
-rw-r--r--fs/binfmt_elf.c23
-rw-r--r--fs/binfmt_elf_fdpic.c18
-rw-r--r--fs/binfmt_flat.c12
-rw-r--r--fs/binfmt_som.c12
-rw-r--r--fs/btrfs/backref.c27
-rw-r--r--fs/btrfs/compression.c2
-rw-r--r--fs/btrfs/ctree.c28
-rw-r--r--fs/btrfs/ctree.h4
-rw-r--r--fs/btrfs/disk-io.c40
-rw-r--r--fs/btrfs/disk-io.h3
-rw-r--r--fs/btrfs/extent-tree.c28
-rw-r--r--fs/btrfs/extent_io.c66
-rw-r--r--fs/btrfs/extent_io.h4
-rw-r--r--fs/btrfs/file.c9
-rw-r--r--fs/btrfs/free-space-cache.c9
-rw-r--r--fs/btrfs/inode.c54
-rw-r--r--fs/btrfs/ioctl.c5
-rw-r--r--fs/btrfs/ioctl.h4
-rw-r--r--fs/btrfs/reada.c48
-rw-r--r--fs/btrfs/relocation.c4
-rw-r--r--fs/btrfs/scrub.c26
-rw-r--r--fs/btrfs/super.c7
-rw-r--r--fs/btrfs/transaction.c15
-rw-r--r--fs/btrfs/tree-log.c2
-rw-r--r--fs/btrfs/volumes.c33
-rw-r--r--fs/buffer.c1
-rw-r--r--fs/cifs/cifsfs.c16
-rw-r--r--fs/cifs/cifsfs.h2
-rw-r--r--fs/cifs/cifssmb.c30
-rw-r--r--fs/cifs/connect.c132
-rw-r--r--fs/cifs/dir.c17
-rw-r--r--fs/cifs/file.c13
-rw-r--r--fs/cifs/netmisc.c3
-rw-r--r--fs/dcache.c26
-rw-r--r--fs/debugfs/file.c14
-rw-r--r--fs/dlm/debug_fs.c9
-rw-r--r--fs/dlm/lock.c12
-rw-r--r--fs/eventpoll.c4
-rw-r--r--fs/exec.c7
-rw-r--r--fs/ext4/ext4.h3
-rw-r--r--fs/ext4/extents.c6
-rw-r--r--fs/ext4/super.c50
-rw-r--r--fs/fuse/dir.c25
-rw-r--r--fs/fuse/file.c129
-rw-r--r--fs/fuse/inode.c1
-rw-r--r--fs/gfs2/Kconfig7
-rw-r--r--fs/gfs2/aops.c4
-rw-r--r--fs/gfs2/bmap.c6
-rw-r--r--fs/gfs2/dir.c4
-rw-r--r--fs/gfs2/inode.c13
-rw-r--r--fs/gfs2/lock_dlm.c10
-rw-r--r--fs/gfs2/rgrp.c8
-rw-r--r--fs/gfs2/xattr.c12
-rw-r--r--fs/hfsplus/catalog.c4
-rw-r--r--fs/hfsplus/dir.c11
-rw-r--r--fs/hugetlbfs/inode.c2
-rw-r--r--fs/jbd2/commit.c4
-rw-r--r--fs/libfs.c9
-rw-r--r--fs/lockd/clnt4xdr.c2
-rw-r--r--fs/lockd/clntxdr.c2
-rw-r--r--fs/locks.c3
-rw-r--r--fs/namei.c39
-rw-r--r--fs/nfs/blocklayout/blocklayout.c4
-rw-r--r--fs/nfs/client.c5
-rw-r--r--fs/nfs/dir.c4
-rw-r--r--fs/nfs/idmap.c4
-rw-r--r--fs/nfs/internal.h8
-rw-r--r--fs/nfs/namespace.c93
-rw-r--r--fs/nfs/nfs4_fs.h11
-rw-r--r--fs/nfs/nfs4filelayoutdev.c2
-rw-r--r--fs/nfs/nfs4namespace.c86
-rw-r--r--fs/nfs/nfs4proc.c186
-rw-r--r--fs/nfs/nfs4state.c31
-rw-r--r--fs/nfs/nfs4xdr.c53
-rw-r--r--fs/nfs/objlayout/objlayout.c2
-rw-r--r--fs/nfs/pnfs.c2
-rw-r--r--fs/nfs/read.c2
-rw-r--r--fs/nfs/super.c12
-rw-r--r--fs/nfs/write.c5
-rw-r--r--fs/nfsd/nfs3xdr.c22
-rw-r--r--fs/nfsd/nfs4proc.c15
-rw-r--r--fs/nfsd/nfs4recover.c2
-rw-r--r--fs/nfsd/nfs4state.c23
-rw-r--r--fs/nfsd/nfs4xdr.c4
-rw-r--r--fs/nfsd/vfs.c2
-rw-r--r--fs/ocfs2/alloc.c2
-rw-r--r--fs/ocfs2/refcounttree.c12
-rw-r--r--fs/ocfs2/suballoc.c4
-rw-r--r--fs/pipe.c31
-rw-r--r--fs/proc/root.c9
-rw-r--r--fs/proc/stat.c34
-rw-r--r--fs/proc/task_mmu.c15
-rw-r--r--fs/pstore/inode.c8
-rw-r--r--fs/splice.c5
-rw-r--r--fs/sysfs/dir.c5
-rw-r--r--fs/sysfs/group.c6
-rw-r--r--fs/xattr.c40
-rw-r--r--include/acpi/actypes.h7
-rw-r--r--include/asm-generic/cmpxchg.h1
-rw-r--r--include/asm-generic/siginfo.h14
-rw-r--r--include/asm-generic/statfs.h2
-rw-r--r--include/crypto/internal/aead.h2
-rw-r--r--include/crypto/internal/skcipher.h2
-rw-r--r--include/drm/drm.h14
-rw-r--r--include/drm/drmP.h62
-rw-r--r--include/drm/exynos_drm.h5
-rw-r--r--include/drm/intel-gtt.h4
-rw-r--r--include/linux/Kbuild1
-rw-r--r--include/linux/amba/bus.h7
-rw-r--r--include/linux/amba/pl022.h2
-rw-r--r--include/linux/blkdev.h18
-rw-r--r--include/linux/cpumask.h6
-rw-r--r--include/linux/cryptouser.h3
-rw-r--r--include/linux/dma-attrs.h2
-rw-r--r--include/linux/dma-mapping.h13
-rw-r--r--include/linux/dmaengine.h1
-rw-r--r--include/linux/efi.h13
-rw-r--r--include/linux/etherdevice.h11
-rw-r--r--include/linux/ethtool.h3
-rw-r--r--include/linux/firewire.h3
-rw-r--r--include/linux/fs.h6
-rw-r--r--include/linux/fuse.h2
-rw-r--r--include/linux/gpio-pxa.h4
-rw-r--r--include/linux/hsi/Kbuild1
-rw-r--r--include/linux/hsi/hsi.h413
-rw-r--r--include/linux/hsi/hsi_char.h63
-rw-r--r--include/linux/i2c/twl.h12
-rw-r--r--include/linux/if_eql.h2
-rw-r--r--include/linux/irq.h12
-rw-r--r--include/linux/irqdomain.h12
-rw-r--r--include/linux/kconfig.h22
-rw-r--r--include/linux/kgdb.h7
-rw-r--r--include/linux/kmod.h27
-rw-r--r--include/linux/kvm_host.h6
-rw-r--r--include/linux/libata.h3
-rw-r--r--include/linux/lsm_audit.h96
-rw-r--r--include/linux/mfd/db5500-prcmu.h88
-rw-r--r--include/linux/mfd/mc13xxx.h11
-rw-r--r--include/linux/mfd/rc5t583.h47
-rw-r--r--include/linux/mfd/twl6040.h27
-rw-r--r--include/linux/mm.h27
-rw-r--r--include/linux/mmc/card.h2
-rw-r--r--include/linux/netdevice.h11
-rw-r--r--include/linux/netfilter/xt_set.h4
-rw-r--r--include/linux/netfilter_bridge.h9
-rw-r--r--include/linux/netfilter_ipv6/ip6_tables.h12
-rw-r--r--include/linux/nfs_xdr.h7
-rw-r--r--include/linux/nfsd/Kbuild1
-rw-r--r--include/linux/pinctrl/machine.h4
-rw-r--r--include/linux/pipe_fs_i.h1
-rw-r--r--include/linux/platform_data/atmel.h6
-rw-r--r--include/linux/pm_qos.h4
-rw-r--r--include/linux/regmap.h28
-rw-r--r--include/linux/regulator/machine.h8
-rw-r--r--include/linux/seqlock.h23
-rw-r--r--include/linux/serial_core.h2
-rw-r--r--include/linux/skbuff.h24
-rw-r--r--include/linux/socket.h2
-rw-r--r--include/linux/spi/spi.h2
-rw-r--r--include/linux/stddef.h8
-rw-r--r--include/linux/swap.h14
-rw-r--r--include/linux/types.h6
-rw-r--r--include/linux/usb/hcd.h2
-rw-r--r--include/linux/usb/otg.h1
-rw-r--r--include/linux/usb/serial.h8
-rw-r--r--include/linux/vgaarb.h2
-rw-r--r--include/linux/vm_event_item.h5
-rw-r--r--include/net/bluetooth/hci.h3
-rw-r--r--include/net/bluetooth/hci_core.h15
-rw-r--r--include/net/bluetooth/mgmt.h2
-rw-r--r--include/net/cfg80211.h6
-rw-r--r--include/net/dst.h7
-rw-r--r--include/net/ip6_fib.h48
-rw-r--r--include/net/ip_vs.h4
-rw-r--r--include/net/mac80211.h2
-rw-r--r--include/net/netfilter/xt_log.h2
-rw-r--r--include/net/red.h6
-rw-r--r--include/net/sctp/sctp.h13
-rw-r--r--include/net/sock.h5
-rw-r--r--include/scsi/libsas.h40
-rw-r--r--include/scsi/sas_ata.h4
-rw-r--r--include/scsi/scsi_cmnd.h3
-rw-r--r--include/sound/cs42l52.h36
-rw-r--r--include/sound/max98095.h12
-rw-r--r--include/sound/sh_fsi.h12
-rw-r--r--include/sound/simple_card.h38
-rw-r--r--include/sound/soc-dai.h4
-rw-r--r--include/sound/soc-dapm.h28
-rw-r--r--include/sound/soc-dpcm.h138
-rw-r--r--include/sound/soc.h118
-rw-r--r--include/trace/events/asoc.h80
-rw-r--r--include/trace/events/sched.h2
-rw-r--r--include/xen/swiotlb-xen.h6
-rw-r--r--init/Kconfig4
-rw-r--r--init/do_mounts.c2
-rw-r--r--init/main.c25
-rw-r--r--kernel/compat.c63
-rw-r--r--kernel/cpuset.c10
-rw-r--r--kernel/cred.c2
-rw-r--r--kernel/debug/debug_core.c53
-rw-r--r--kernel/debug/kdb/kdb_io.c2
-rw-r--r--kernel/events/core.c2
-rw-r--r--kernel/fork.c3
-rw-r--r--kernel/irq/Kconfig2
-rw-r--r--kernel/irq/debug.h38
-rw-r--r--kernel/irq/irqdomain.c47
-rw-r--r--kernel/irq_work.c2
-rw-r--r--kernel/itimer.c8
-rw-r--r--kernel/kmod.c117
-rw-r--r--kernel/padata.c13
-rw-r--r--kernel/panic.c2
-rw-r--r--kernel/power/hibernate.c18
-rw-r--r--kernel/power/process.c8
-rw-r--r--kernel/power/qos.c50
-rw-r--r--kernel/power/suspend.c7
-rw-r--r--kernel/power/swap.c28
-rw-r--r--kernel/power/user.c10
-rw-r--r--kernel/rcutree.c1
-rw-r--r--kernel/sched/core.c22
-rw-r--r--kernel/sched/fair.c18
-rw-r--r--kernel/sched/features.h1
-rw-r--r--kernel/sysctl.c8
-rw-r--r--kernel/time/Kconfig4
-rw-r--r--kernel/time/tick-broadcast.c11
-rw-r--r--kernel/time/tick-sched.c4
-rw-r--r--kernel/trace/blktrace.c18
-rw-r--r--kernel/trace/trace.c8
-rw-r--r--kernel/trace/trace.h4
-rw-r--r--kernel/trace/trace_output.c5
-rw-r--r--lib/kobject.c14
-rw-r--r--lib/mpi/mpi-bit.c5
-rw-r--r--mm/hugetlb.c5
-rw-r--r--mm/memblock.c7
-rw-r--r--mm/memcontrol.c28
-rw-r--r--mm/mempolicy.c11
-rw-r--r--mm/migrate.c16
-rw-r--r--mm/mmap.c59
-rw-r--r--mm/nobootmem.c13
-rw-r--r--mm/nommu.c41
-rw-r--r--mm/page_alloc.c2
-rw-r--r--mm/percpu.c22
-rw-r--r--mm/swap_state.c2
-rw-r--r--mm/vmscan.c18
-rw-r--r--mm/vmstat.c4
-rw-r--r--net/802/garp.c22
-rw-r--r--net/8021q/vlan_dev.c2
-rw-r--r--net/ax25/af_ax25.c9
-rw-r--r--net/bluetooth/hci_core.c34
-rw-r--r--net/bluetooth/hci_event.c3
-rw-r--r--net/bluetooth/l2cap_core.c3
-rw-r--r--net/bluetooth/l2cap_sock.c5
-rw-r--r--net/bluetooth/mgmt.c15
-rw-r--r--net/bridge/br_forward.c1
-rw-r--r--net/bridge/br_multicast.c81
-rw-r--r--net/bridge/br_netfilter.c8
-rw-r--r--net/bridge/br_private.h4
-rw-r--r--net/caif/chnl_net.c9
-rw-r--r--net/core/dev.c115
-rw-r--r--net/core/dev_addr_lists.c3
-rw-r--r--net/core/drop_monitor.c89
-rw-r--r--net/core/filter.c9
-rw-r--r--net/core/net_namespace.c33
-rw-r--r--net/core/pktgen.c10
-rw-r--r--net/core/skbuff.c8
-rw-r--r--net/ieee802154/6lowpan.c40
-rw-r--r--net/ipv4/fib_trie.c2
-rw-r--r--net/ipv4/inet_diag.c2
-rw-r--r--net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c12
-rw-r--r--net/ipv4/route.c2
-rw-r--r--net/ipv4/tcp.c26
-rw-r--r--net/ipv4/tcp_input.c23
-rw-r--r--net/ipv4/tcp_ipv4.c2
-rw-r--r--net/ipv4/tcp_output.c3
-rw-r--r--net/ipv4/udp_diag.c9
-rw-r--r--net/ipv6/addrconf.c9
-rw-r--r--net/ipv6/ip6_fib.c9
-rw-r--r--net/ipv6/mcast.c2
-rw-r--r--net/ipv6/ndisc.c3
-rw-r--r--net/ipv6/netfilter/ip6_tables.c14
-rw-r--r--net/ipv6/route.c105
-rw-r--r--net/ipv6/tcp_ipv6.c6
-rw-r--r--net/key/af_key.c2
-rw-r--r--net/l2tp/l2tp_ip.c8
-rw-r--r--net/mac80211/agg-rx.c3
-rw-r--r--net/mac80211/debugfs.c12
-rw-r--r--net/mac80211/debugfs.h1
-rw-r--r--net/mac80211/debugfs_key.c4
-rw-r--r--net/mac80211/debugfs_netdev.c2
-rw-r--r--net/mac80211/debugfs_sta.c4
-rw-r--r--net/mac80211/ibss.c4
-rw-r--r--net/mac80211/ieee80211_i.h2
-rw-r--r--net/mac80211/iface.c4
-rw-r--r--net/mac80211/main.c3
-rw-r--r--net/mac80211/mlme.c5
-rw-r--r--net/mac80211/rate.c2
-rw-r--r--net/mac80211/rx.c10
-rw-r--r--net/mac80211/scan.c2
-rw-r--r--net/mac80211/tx.c3
-rw-r--r--net/netfilter/ipvs/ip_vs_core.c11
-rw-r--r--net/netfilter/ipvs/ip_vs_ctl.c56
-rw-r--r--net/netfilter/ipvs/ip_vs_ftp.c2
-rw-r--r--net/netfilter/ipvs/ip_vs_lblc.c3
-rw-r--r--net/netfilter/ipvs/ip_vs_lblcr.c3
-rw-r--r--net/netfilter/ipvs/ip_vs_proto.c38
-rw-r--r--net/netfilter/ipvs/ip_vs_proto_sctp.c5
-rw-r--r--net/netfilter/ipvs/ip_vs_proto_tcp.c5
-rw-r--r--net/netfilter/ipvs/ip_vs_proto_udp.c5
-rw-r--r--net/netfilter/nf_conntrack_core.c3
-rw-r--r--net/netfilter/nf_conntrack_proto_tcp.c4
-rw-r--r--net/netfilter/nfnetlink_acct.c2
-rw-r--r--net/netfilter/xt_CT.c30
-rw-r--r--net/netlink/af_netlink.c24
-rw-r--r--net/nfc/llcp/commands.c4
-rw-r--r--net/openvswitch/datapath.c27
-rw-r--r--net/openvswitch/flow.c3
-rw-r--r--net/phonet/pep.c3
-rw-r--r--net/phonet/pn_dev.c21
-rw-r--r--net/rose/rose_dev.c4
-rw-r--r--net/sched/sch_gred.c7
-rw-r--r--net/sched/sch_netem.c6
-rw-r--r--net/sctp/output.c4
-rw-r--r--net/sctp/socket.c5
-rw-r--r--net/sctp/transport.c17
-rw-r--r--net/socket.c6
-rw-r--r--net/sunrpc/auth_gss/gss_mech_switch.c7
-rw-r--r--net/sunrpc/clnt.c50
-rw-r--r--net/sunrpc/rpc_pipe.c3
-rw-r--r--net/sunrpc/sunrpc_syms.c17
-rw-r--r--net/wireless/debugfs.c10
-rw-r--r--net/wireless/nl80211.c60
-rw-r--r--net/wireless/util.c2
-rw-r--r--net/wireless/wext-core.c6
-rwxr-xr-xscripts/checkpatch.pl6
-rw-r--r--scripts/coccinelle/api/simple_open.cocci70
-rw-r--r--scripts/kconfig/confdata.c38
-rw-r--r--scripts/mod/file2alias.c4
-rw-r--r--scripts/mod/modpost.c7
-rw-r--r--scripts/mod/modpost.h1
-rwxr-xr-xscripts/tags.sh2
-rw-r--r--scripts/xz_wrap.sh4
-rw-r--r--security/apparmor/audit.c42
-rw-r--r--security/apparmor/capability.c6
-rw-r--r--security/apparmor/file.c54
-rw-r--r--security/apparmor/include/audit.h28
-rw-r--r--security/apparmor/ipc.c10
-rw-r--r--security/apparmor/lib.c4
-rw-r--r--security/apparmor/lsm.c8
-rw-r--r--security/apparmor/policy.c10
-rw-r--r--security/apparmor/policy_unpack.c20
-rw-r--r--security/apparmor/resource.c12
-rw-r--r--security/commoncap.c6
-rw-r--r--security/lsm_audit.c80
-rw-r--r--security/selinux/avc.c45
-rw-r--r--security/selinux/hooks.c176
-rw-r--r--security/selinux/include/avc.h25
-rw-r--r--security/smack/smack.h23
-rw-r--r--security/smack/smack_access.c14
-rw-r--r--security/smack/smack_lsm.c86
-rw-r--r--security/smack/smackfs.c14
-rw-r--r--sound/pci/Kconfig4
-rw-r--r--sound/soc/Kconfig5
-rw-r--r--sound/soc/Makefile3
-rw-r--r--sound/soc/blackfin/bf5xx-ssm2602.c37
-rw-r--r--sound/soc/codecs/Kconfig19
-rw-r--r--sound/soc/codecs/Makefile10
-rw-r--r--sound/soc/codecs/ac97.c6
-rw-r--r--sound/soc/codecs/ad1836.c4
-rw-r--r--sound/soc/codecs/ad193x.c4
-rw-r--r--sound/soc/codecs/adau1701.c3
-rw-r--r--sound/soc/codecs/ak4104.c3
-rw-r--r--sound/soc/codecs/ak4535.c3
-rw-r--r--sound/soc/codecs/ak4641.c113
-rw-r--r--sound/soc/codecs/alc5623.c23
-rw-r--r--sound/soc/codecs/alc5632.c31
-rw-r--r--sound/soc/codecs/cs4270.c11
-rw-r--r--sound/soc/codecs/cs4271.c3
-rw-r--r--sound/soc/codecs/cs42l51.c9
-rw-r--r--sound/soc/codecs/cs42l52.c1295
-rw-r--r--sound/soc/codecs/cs42l52.h274
-rw-r--r--sound/soc/codecs/cs42l73.c93
-rw-r--r--sound/soc/codecs/da7210.c379
-rw-r--r--sound/soc/codecs/jz4740.c3
-rw-r--r--sound/soc/codecs/lm49453.c1550
-rw-r--r--sound/soc/codecs/lm49453.h380
-rw-r--r--sound/soc/codecs/max98095.c158
-rw-r--r--sound/soc/codecs/max98095.h22
-rw-r--r--sound/soc/codecs/mc13783.c786
-rw-r--r--sound/soc/codecs/mc13783.h28
-rw-r--r--sound/soc/codecs/ml26124.c681
-rw-r--r--sound/soc/codecs/ml26124.h184
-rw-r--r--sound/soc/codecs/rt5631.c110
-rw-r--r--sound/soc/codecs/sgtl5000.c25
-rw-r--r--sound/soc/codecs/ssm2602.c138
-rw-r--r--sound/soc/codecs/sta32x.c3
-rw-r--r--sound/soc/codecs/tlv320aic23.c13
-rw-r--r--sound/soc/codecs/tlv320aic26.c3
-rw-r--r--sound/soc/codecs/tlv320aic3x.c21
-rw-r--r--sound/soc/codecs/tlv320dac33.c35
-rw-r--r--sound/soc/codecs/twl4030.c18
-rw-r--r--sound/soc/codecs/twl6040.c453
-rw-r--r--sound/soc/codecs/uda134x.c6
-rw-r--r--sound/soc/codecs/uda1380.c6
-rw-r--r--sound/soc/codecs/wl1273.c6
-rw-r--r--sound/soc/codecs/wm1250-ev1.c65
-rw-r--r--sound/soc/codecs/wm5100-tables.c125
-rw-r--r--sound/soc/codecs/wm5100.c47
-rw-r--r--sound/soc/codecs/wm5100.h159
-rw-r--r--sound/soc/codecs/wm8350.c187
-rw-r--r--sound/soc/codecs/wm8400.c135
-rw-r--r--sound/soc/codecs/wm8510.c3
-rw-r--r--sound/soc/codecs/wm8523.c3
-rw-r--r--sound/soc/codecs/wm8728.c3
-rw-r--r--sound/soc/codecs/wm8731.c37
-rw-r--r--sound/soc/codecs/wm8737.c3
-rw-r--r--sound/soc/codecs/wm8741.c3
-rw-r--r--sound/soc/codecs/wm8750.c3
-rw-r--r--sound/soc/codecs/wm8753.c6
-rw-r--r--sound/soc/codecs/wm8900.c3
-rw-r--r--sound/soc/codecs/wm8903.c3
-rw-r--r--sound/soc/codecs/wm8940.c3
-rw-r--r--sound/soc/codecs/wm8960.c3
-rw-r--r--sound/soc/codecs/wm8962.c18
-rw-r--r--sound/soc/codecs/wm8971.c3
-rw-r--r--sound/soc/codecs/wm8978.c3
-rw-r--r--sound/soc/codecs/wm8988.c3
-rw-r--r--sound/soc/codecs/wm8990.c3
-rw-r--r--sound/soc/codecs/wm8993.c86
-rw-r--r--sound/soc/codecs/wm8994.c290
-rw-r--r--sound/soc/codecs/wm8994.h3
-rw-r--r--sound/soc/codecs/wm8996.c12
-rw-r--r--sound/soc/codecs/wm9081.c5
-rw-r--r--sound/soc/codecs/wm9705.c6
-rw-r--r--sound/soc/codecs/wm9712.c10
-rw-r--r--sound/soc/codecs/wm_hubs.c220
-rw-r--r--sound/soc/codecs/wm_hubs.h12
-rw-r--r--sound/soc/ep93xx/ep93xx-ac97.c74
-rw-r--r--sound/soc/ep93xx/ep93xx-i2s.c49
-rw-r--r--sound/soc/fsl/Kconfig129
-rw-r--r--sound/soc/fsl/Makefile31
-rw-r--r--sound/soc/fsl/eukrea-tlv320.c (renamed from sound/soc/imx/eukrea-tlv320.c)2
-rw-r--r--sound/soc/fsl/fsl_ssi.c167
-rw-r--r--sound/soc/fsl/fsl_utils.c91
-rw-r--r--sound/soc/fsl/fsl_utils.h26
-rw-r--r--sound/soc/fsl/imx-audmux.c (renamed from sound/soc/imx/imx-audmux.c)8
-rw-r--r--sound/soc/fsl/imx-audmux.h (renamed from sound/soc/imx/imx-audmux.h)0
-rw-r--r--sound/soc/fsl/imx-mc13783.c156
-rw-r--r--sound/soc/fsl/imx-pcm-dma.c (renamed from sound/soc/imx/imx-pcm-dma-mx2.c)3
-rw-r--r--sound/soc/fsl/imx-pcm-fiq.c (renamed from sound/soc/imx/imx-pcm-fiq.c)0
-rw-r--r--sound/soc/fsl/imx-pcm.c (renamed from sound/soc/imx/imx-pcm.c)0
-rw-r--r--sound/soc/fsl/imx-pcm.h (renamed from sound/soc/imx/imx-pcm.h)1
-rw-r--r--sound/soc/fsl/imx-sgtl5000.c221
-rw-r--r--sound/soc/fsl/imx-ssi.c (renamed from sound/soc/imx/imx-ssi.c)2
-rw-r--r--sound/soc/fsl/imx-ssi.h (renamed from sound/soc/imx/imx-ssi.h)0
-rw-r--r--sound/soc/fsl/mpc8610_hpcd.c174
-rw-r--r--sound/soc/fsl/mx27vis-aic32x4.c (renamed from sound/soc/imx/mx27vis-aic32x4.c)0
-rw-r--r--sound/soc/fsl/p1022_ds.c168
-rw-r--r--sound/soc/fsl/phycore-ac97.c (renamed from sound/soc/imx/phycore-ac97.c)0
-rw-r--r--sound/soc/fsl/wm1133-ev1.c (renamed from sound/soc/imx/wm1133-ev1.c)0
-rw-r--r--sound/soc/generic/Kconfig4
-rw-r--r--sound/soc/generic/Makefile3
-rw-r--r--sound/soc/generic/simple-card.c114
-rw-r--r--sound/soc/imx/Kconfig79
-rw-r--r--sound/soc/imx/Makefile22
-rw-r--r--sound/soc/jz4740/jz4740-i2s.c4
-rw-r--r--sound/soc/mxs/mxs-pcm.c24
-rw-r--r--sound/soc/mxs/mxs-pcm.h3
-rw-r--r--sound/soc/mxs/mxs-saif.c92
-rw-r--r--sound/soc/mxs/mxs-saif.h1
-rw-r--r--sound/soc/mxs/mxs-sgtl5000.c50
-rw-r--r--sound/soc/omap/Kconfig2
-rw-r--r--sound/soc/pxa/pxa-ssp.c28
-rw-r--r--sound/soc/pxa/pxa2xx-i2s.c4
-rw-r--r--sound/soc/samsung/littlemill.c102
-rw-r--r--sound/soc/samsung/lowland.c75
-rw-r--r--sound/soc/samsung/speyside.c33
-rw-r--r--sound/soc/sh/Kconfig24
-rw-r--r--sound/soc/sh/Makefile6
-rw-r--r--sound/soc/sh/fsi-ak4642.c108
-rw-r--r--sound/soc/sh/fsi-da7210.c81
-rw-r--r--sound/soc/sh/fsi-hdmi.c118
-rw-r--r--sound/soc/soc-core.c698
-rw-r--r--sound/soc/soc-dapm.c578
-rw-r--r--sound/soc/soc-jack.c5
-rw-r--r--sound/soc/soc-pcm.c1718
-rw-r--r--sound/soc/tegra/Kconfig58
-rw-r--r--sound/soc/tegra/Makefile18
-rw-r--r--sound/soc/tegra/tegra20_das.c233
-rw-r--r--sound/soc/tegra/tegra20_das.h134
-rw-r--r--sound/soc/tegra/tegra20_i2s.c494
-rw-r--r--sound/soc/tegra/tegra20_i2s.h164
-rw-r--r--sound/soc/tegra/tegra20_spdif.c404
-rw-r--r--sound/soc/tegra/tegra20_spdif.h471
-rw-r--r--sound/soc/tegra/tegra30_ahub.c631
-rw-r--r--sound/soc/tegra/tegra30_ahub.h483
-rw-r--r--sound/soc/tegra/tegra30_i2s.c536
-rw-r--r--sound/soc/tegra/tegra30_i2s.h242
-rw-r--r--sound/soc/tegra/tegra_alc5632.c48
-rw-r--r--sound/soc/tegra/tegra_asoc_utils.c37
-rw-r--r--sound/soc/tegra/tegra_asoc_utils.h9
-rw-r--r--sound/soc/tegra/tegra_das.c261
-rw-r--r--sound/soc/tegra/tegra_das.h135
-rw-r--r--sound/soc/tegra/tegra_i2s.c459
-rw-r--r--sound/soc/tegra/tegra_i2s.h166
-rw-r--r--sound/soc/tegra/tegra_pcm.c28
-rw-r--r--sound/soc/tegra/tegra_pcm.h5
-rw-r--r--sound/soc/tegra/tegra_spdif.c364
-rw-r--r--sound/soc/tegra/tegra_spdif.h473
-rw-r--r--sound/soc/tegra/tegra_wm8903.c29
-rw-r--r--sound/soc/tegra/trimslice.c41
-rw-r--r--sound/soc/ux500/Kconfig14
-rw-r--r--sound/soc/ux500/Makefile4
-rw-r--r--sound/soc/ux500/ux500_msp_dai.c843
-rw-r--r--sound/soc/ux500/ux500_msp_dai.h79
-rw-r--r--sound/soc/ux500/ux500_msp_i2s.c742
-rw-r--r--sound/soc/ux500/ux500_msp_i2s.h553
-rw-r--r--tools/perf/.gitignore2
-rw-r--r--tools/perf/Makefile25
-rw-r--r--tools/perf/builtin-report.c17
-rw-r--r--tools/perf/builtin-sched.c1
-rw-r--r--tools/perf/builtin-test.c30
-rw-r--r--tools/perf/builtin-top.c36
-rw-r--r--tools/perf/perf-archive.sh3
-rw-r--r--tools/perf/util/annotate.c16
-rw-r--r--tools/perf/util/hist.c12
-rw-r--r--tools/perf/util/map.c1
-rw-r--r--tools/perf/util/map.h1
-rw-r--r--tools/perf/util/parse-events.l2
-rw-r--r--tools/perf/util/session.c16
-rw-r--r--tools/perf/util/symbol.c13
-rw-r--r--tools/perf/util/ui/browsers/hists.c3
-rwxr-xr-xtools/testing/ktest/ktest.pl12
-rw-r--r--virt/kvm/iommu.c30
-rw-r--r--virt/kvm/kvm_main.c5
1765 files changed, 36950 insertions, 15719 deletions
diff --git a/Documentation/ABI/stable/sysfs-driver-usb-usbtmc b/Documentation/ABI/stable/sysfs-driver-usb-usbtmc
index 2a7f9a00cb0a..e960cd027e1e 100644
--- a/Documentation/ABI/stable/sysfs-driver-usb-usbtmc
+++ b/Documentation/ABI/stable/sysfs-driver-usb-usbtmc
@@ -1,5 +1,5 @@
1What: /sys/bus/usb/drivers/usbtmc/devices/*/interface_capabilities 1What: /sys/bus/usb/drivers/usbtmc/*/interface_capabilities
2What: /sys/bus/usb/drivers/usbtmc/devices/*/device_capabilities 2What: /sys/bus/usb/drivers/usbtmc/*/device_capabilities
3Date: August 2008 3Date: August 2008
4Contact: Greg Kroah-Hartman <gregkh@linuxfoundation.org> 4Contact: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
5Description: 5Description:
@@ -12,8 +12,8 @@ Description:
12 The files are read only. 12 The files are read only.
13 13
14 14
15What: /sys/bus/usb/drivers/usbtmc/devices/*/usb488_interface_capabilities 15What: /sys/bus/usb/drivers/usbtmc/*/usb488_interface_capabilities
16What: /sys/bus/usb/drivers/usbtmc/devices/*/usb488_device_capabilities 16What: /sys/bus/usb/drivers/usbtmc/*/usb488_device_capabilities
17Date: August 2008 17Date: August 2008
18Contact: Greg Kroah-Hartman <gregkh@linuxfoundation.org> 18Contact: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
19Description: 19Description:
@@ -27,7 +27,7 @@ Description:
27 The files are read only. 27 The files are read only.
28 28
29 29
30What: /sys/bus/usb/drivers/usbtmc/devices/*/TermChar 30What: /sys/bus/usb/drivers/usbtmc/*/TermChar
31Date: August 2008 31Date: August 2008
32Contact: Greg Kroah-Hartman <gregkh@linuxfoundation.org> 32Contact: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
33Description: 33Description:
@@ -40,7 +40,7 @@ Description:
40 sent to the device or not. 40 sent to the device or not.
41 41
42 42
43What: /sys/bus/usb/drivers/usbtmc/devices/*/TermCharEnabled 43What: /sys/bus/usb/drivers/usbtmc/*/TermCharEnabled
44Date: August 2008 44Date: August 2008
45Contact: Greg Kroah-Hartman <gregkh@linuxfoundation.org> 45Contact: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
46Description: 46Description:
@@ -51,7 +51,7 @@ Description:
51 published by the USB-IF. 51 published by the USB-IF.
52 52
53 53
54What: /sys/bus/usb/drivers/usbtmc/devices/*/auto_abort 54What: /sys/bus/usb/drivers/usbtmc/*/auto_abort
55Date: August 2008 55Date: August 2008
56Contact: Greg Kroah-Hartman <gregkh@linuxfoundation.org> 56Contact: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
57Description: 57Description:
diff --git a/Documentation/ABI/testing/sysfs-block-rssd b/Documentation/ABI/testing/sysfs-block-rssd
new file mode 100644
index 000000000000..d535757799fe
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-block-rssd
@@ -0,0 +1,18 @@
1What: /sys/block/rssd*/registers
2Date: March 2012
3KernelVersion: 3.3
4Contact: Asai Thambi S P <asamymuthupa@micron.com>
5Description: This is a read-only file. Dumps below driver information and
6 hardware registers.
7 - S ACTive
8 - Command Issue
9 - Allocated
10 - Completed
11 - PORT IRQ STAT
12 - HOST IRQ STAT
13
14What: /sys/block/rssd*/status
15Date: April 2012
16KernelVersion: 3.4
17Contact: Asai Thambi S P <asamymuthupa@micron.com>
18Description: This is a read-only file. Indicates the status of the device.
diff --git a/Documentation/ABI/testing/sysfs-bus-hsi b/Documentation/ABI/testing/sysfs-bus-hsi
new file mode 100644
index 000000000000..1b1b282a99e1
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-bus-hsi
@@ -0,0 +1,19 @@
1What: /sys/bus/hsi
2Date: April 2012
3KernelVersion: 3.4
4Contact: Carlos Chinea <carlos.chinea@nokia.com>
5Description:
6 High Speed Synchronous Serial Interface (HSI) is a
7 serial interface mainly used for connecting application
8 engines (APE) with cellular modem engines (CMT) in cellular
9 handsets.
10 The bus will be populated with devices (hsi_clients) representing
11 the protocols available in the system. Bus drivers implement
12 those protocols.
13
14What: /sys/bus/hsi/devices/.../modalias
15Date: April 2012
16KernelVersion: 3.4
17Contact: Carlos Chinea <carlos.chinea@nokia.com>
18Description: Stores the same MODALIAS value emitted by uevent
19 Format: hsi:<hsi_client device name>
diff --git a/Documentation/ABI/testing/sysfs-cfq-target-latency b/Documentation/ABI/testing/sysfs-cfq-target-latency
new file mode 100644
index 000000000000..df0f7828c5e3
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-cfq-target-latency
@@ -0,0 +1,8 @@
1What: /sys/block/<device>/iosched/target_latency
2Date: March 2012
3contact: Tao Ma <boyu.mt@taobao.com>
4Description:
5 The /sys/block/<device>/iosched/target_latency only exists
6 when the user sets cfq to /sys/block/<device>/scheduler.
7 It contains an estimated latency time for the cfq. cfq will
8 use it to calculate the time slice used for every task.
diff --git a/Documentation/DMA-attributes.txt b/Documentation/DMA-attributes.txt
index b768cc0e402b..5c72eed89563 100644
--- a/Documentation/DMA-attributes.txt
+++ b/Documentation/DMA-attributes.txt
@@ -31,3 +31,21 @@ may be weakly ordered, that is that reads and writes may pass each other.
31Since it is optional for platforms to implement DMA_ATTR_WEAK_ORDERING, 31Since it is optional for platforms to implement DMA_ATTR_WEAK_ORDERING,
32those that do not will simply ignore the attribute and exhibit default 32those that do not will simply ignore the attribute and exhibit default
33behavior. 33behavior.
34
35DMA_ATTR_WRITE_COMBINE
36----------------------
37
38DMA_ATTR_WRITE_COMBINE specifies that writes to the mapping may be
39buffered to improve performance.
40
41Since it is optional for platforms to implement DMA_ATTR_WRITE_COMBINE,
42those that do not will simply ignore the attribute and exhibit default
43behavior.
44
45DMA_ATTR_NON_CONSISTENT
46-----------------------
47
48DMA_ATTR_NON_CONSISTENT lets the platform to choose to return either
49consistent or non-consistent memory as it sees fit. By using this API,
50you are guaranteeing to the platform that you have all the correct and
51necessary sync points for this memory in the driver.
diff --git a/Documentation/DocBook/device-drivers.tmpl b/Documentation/DocBook/device-drivers.tmpl
index 9c27e5125dd2..7514dbf0a679 100644
--- a/Documentation/DocBook/device-drivers.tmpl
+++ b/Documentation/DocBook/device-drivers.tmpl
@@ -446,4 +446,21 @@ X!Idrivers/video/console/fonts.c
446!Edrivers/i2c/i2c-core.c 446!Edrivers/i2c/i2c-core.c
447 </chapter> 447 </chapter>
448 448
449 <chapter id="hsi">
450 <title>High Speed Synchronous Serial Interface (HSI)</title>
451
452 <para>
453 High Speed Synchronous Serial Interface (HSI) is a
454 serial interface mainly used for connecting application
455 engines (APE) with cellular modem engines (CMT) in cellular
456 handsets.
457
458 HSI provides multiplexing for up to 16 logical channels,
459 low-latency and full duplex communication.
460 </para>
461
462!Iinclude/linux/hsi/hsi.h
463!Edrivers/hsi/hsi.c
464 </chapter>
465
449</book> 466</book>
diff --git a/Documentation/DocBook/media/v4l/pixfmt-nv12m.xml b/Documentation/DocBook/media/v4l/pixfmt-nv12m.xml
index 3fd3ce5df270..5274c24d11e0 100644
--- a/Documentation/DocBook/media/v4l/pixfmt-nv12m.xml
+++ b/Documentation/DocBook/media/v4l/pixfmt-nv12m.xml
@@ -1,6 +1,6 @@
1 <refentry id="V4L2-PIX-FMT-NV12M"> 1 <refentry id="V4L2-PIX-FMT-NV12M">
2 <refmeta> 2 <refmeta>
3 <refentrytitle>V4L2_PIX_FMT_NV12M ('NV12M')</refentrytitle> 3 <refentrytitle>V4L2_PIX_FMT_NV12M ('NM12')</refentrytitle>
4 &manvol; 4 &manvol;
5 </refmeta> 5 </refmeta>
6 <refnamediv> 6 <refnamediv>
diff --git a/Documentation/DocBook/media/v4l/pixfmt-yuv420m.xml b/Documentation/DocBook/media/v4l/pixfmt-yuv420m.xml
index 9957863daf18..60308f1eefdf 100644
--- a/Documentation/DocBook/media/v4l/pixfmt-yuv420m.xml
+++ b/Documentation/DocBook/media/v4l/pixfmt-yuv420m.xml
@@ -1,6 +1,6 @@
1 <refentry id="V4L2-PIX-FMT-YUV420M"> 1 <refentry id="V4L2-PIX-FMT-YUV420M">
2 <refmeta> 2 <refmeta>
3 <refentrytitle>V4L2_PIX_FMT_YUV420M ('YU12M')</refentrytitle> 3 <refentrytitle>V4L2_PIX_FMT_YUV420M ('YM12')</refentrytitle>
4 &manvol; 4 &manvol;
5 </refmeta> 5 </refmeta>
6 <refnamediv> 6 <refnamediv>
diff --git a/Documentation/cgroups/cpusets.txt b/Documentation/cgroups/cpusets.txt
index 5c51ed406d1d..cefd3d8bbd11 100644
--- a/Documentation/cgroups/cpusets.txt
+++ b/Documentation/cgroups/cpusets.txt
@@ -217,7 +217,7 @@ and name space for cpusets, with a minimum of additional kernel code.
217 217
218The cpus and mems files in the root (top_cpuset) cpuset are 218The cpus and mems files in the root (top_cpuset) cpuset are
219read-only. The cpus file automatically tracks the value of 219read-only. The cpus file automatically tracks the value of
220cpu_online_map using a CPU hotplug notifier, and the mems file 220cpu_online_mask using a CPU hotplug notifier, and the mems file
221automatically tracks the value of node_states[N_HIGH_MEMORY]--i.e., 221automatically tracks the value of node_states[N_HIGH_MEMORY]--i.e.,
222nodes with memory--using the cpuset_track_online_nodes() hook. 222nodes with memory--using the cpuset_track_online_nodes() hook.
223 223
diff --git a/Documentation/cgroups/memory.txt b/Documentation/cgroups/memory.txt
index 4c95c0034a4b..9b1067afb224 100644
--- a/Documentation/cgroups/memory.txt
+++ b/Documentation/cgroups/memory.txt
@@ -34,8 +34,7 @@ Current Status: linux-2.6.34-mmotm(development version of 2010/April)
34 34
35Features: 35Features:
36 - accounting anonymous pages, file caches, swap caches usage and limiting them. 36 - accounting anonymous pages, file caches, swap caches usage and limiting them.
37 - private LRU and reclaim routine. (system's global LRU and private LRU 37 - pages are linked to per-memcg LRU exclusively, and there is no global LRU.
38 work independently from each other)
39 - optionally, memory+swap usage can be accounted and limited. 38 - optionally, memory+swap usage can be accounted and limited.
40 - hierarchical accounting 39 - hierarchical accounting
41 - soft limit 40 - soft limit
@@ -154,7 +153,7 @@ updated. page_cgroup has its own LRU on cgroup.
1542.2.1 Accounting details 1532.2.1 Accounting details
155 154
156All mapped anon pages (RSS) and cache pages (Page Cache) are accounted. 155All mapped anon pages (RSS) and cache pages (Page Cache) are accounted.
157Some pages which are never reclaimable and will not be on the global LRU 156Some pages which are never reclaimable and will not be on the LRU
158are not accounted. We just account pages under usual VM management. 157are not accounted. We just account pages under usual VM management.
159 158
160RSS pages are accounted at page_fault unless they've already been accounted 159RSS pages are accounted at page_fault unless they've already been accounted
diff --git a/Documentation/cpu-hotplug.txt b/Documentation/cpu-hotplug.txt
index a20bfd415e41..66ef8f35613d 100644
--- a/Documentation/cpu-hotplug.txt
+++ b/Documentation/cpu-hotplug.txt
@@ -47,7 +47,7 @@ maxcpus=n Restrict boot time cpus to n. Say if you have 4 cpus, using
47 other cpus later online, read FAQ's for more info. 47 other cpus later online, read FAQ's for more info.
48 48
49additional_cpus=n (*) Use this to limit hotpluggable cpus. This option sets 49additional_cpus=n (*) Use this to limit hotpluggable cpus. This option sets
50 cpu_possible_map = cpu_present_map + additional_cpus 50 cpu_possible_mask = cpu_present_mask + additional_cpus
51 51
52cede_offline={"off","on"} Use this option to disable/enable putting offlined 52cede_offline={"off","on"} Use this option to disable/enable putting offlined
53 processors to an extended H_CEDE state on 53 processors to an extended H_CEDE state on
@@ -64,11 +64,11 @@ should only rely on this to count the # of cpus, but *MUST* not rely
64on the apicid values in those tables for disabled apics. In the event 64on the apicid values in those tables for disabled apics. In the event
65BIOS doesn't mark such hot-pluggable cpus as disabled entries, one could 65BIOS doesn't mark such hot-pluggable cpus as disabled entries, one could
66use this parameter "additional_cpus=x" to represent those cpus in the 66use this parameter "additional_cpus=x" to represent those cpus in the
67cpu_possible_map. 67cpu_possible_mask.
68 68
69possible_cpus=n [s390,x86_64] use this to set hotpluggable cpus. 69possible_cpus=n [s390,x86_64] use this to set hotpluggable cpus.
70 This option sets possible_cpus bits in 70 This option sets possible_cpus bits in
71 cpu_possible_map. Thus keeping the numbers of bits set 71 cpu_possible_mask. Thus keeping the numbers of bits set
72 constant even if the machine gets rebooted. 72 constant even if the machine gets rebooted.
73 73
74CPU maps and such 74CPU maps and such
@@ -76,7 +76,7 @@ CPU maps and such
76[More on cpumaps and primitive to manipulate, please check 76[More on cpumaps and primitive to manipulate, please check
77include/linux/cpumask.h that has more descriptive text.] 77include/linux/cpumask.h that has more descriptive text.]
78 78
79cpu_possible_map: Bitmap of possible CPUs that can ever be available in the 79cpu_possible_mask: Bitmap of possible CPUs that can ever be available in the
80system. This is used to allocate some boot time memory for per_cpu variables 80system. This is used to allocate some boot time memory for per_cpu variables
81that aren't designed to grow/shrink as CPUs are made available or removed. 81that aren't designed to grow/shrink as CPUs are made available or removed.
82Once set during boot time discovery phase, the map is static, i.e no bits 82Once set during boot time discovery phase, the map is static, i.e no bits
@@ -84,13 +84,13 @@ are added or removed anytime. Trimming it accurately for your system needs
84upfront can save some boot time memory. See below for how we use heuristics 84upfront can save some boot time memory. See below for how we use heuristics
85in x86_64 case to keep this under check. 85in x86_64 case to keep this under check.
86 86
87cpu_online_map: Bitmap of all CPUs currently online. Its set in __cpu_up() 87cpu_online_mask: Bitmap of all CPUs currently online. Its set in __cpu_up()
88after a cpu is available for kernel scheduling and ready to receive 88after a cpu is available for kernel scheduling and ready to receive
89interrupts from devices. Its cleared when a cpu is brought down using 89interrupts from devices. Its cleared when a cpu is brought down using
90__cpu_disable(), before which all OS services including interrupts are 90__cpu_disable(), before which all OS services including interrupts are
91migrated to another target CPU. 91migrated to another target CPU.
92 92
93cpu_present_map: Bitmap of CPUs currently present in the system. Not all 93cpu_present_mask: Bitmap of CPUs currently present in the system. Not all
94of them may be online. When physical hotplug is processed by the relevant 94of them may be online. When physical hotplug is processed by the relevant
95subsystem (e.g ACPI) can change and new bit either be added or removed 95subsystem (e.g ACPI) can change and new bit either be added or removed
96from the map depending on the event is hot-add/hot-remove. There are currently 96from the map depending on the event is hot-add/hot-remove. There are currently
@@ -99,22 +99,22 @@ at which time hotplug is disabled.
99 99
100You really dont need to manipulate any of the system cpu maps. They should 100You really dont need to manipulate any of the system cpu maps. They should
101be read-only for most use. When setting up per-cpu resources almost always use 101be read-only for most use. When setting up per-cpu resources almost always use
102cpu_possible_map/for_each_possible_cpu() to iterate. 102cpu_possible_mask/for_each_possible_cpu() to iterate.
103 103
104Never use anything other than cpumask_t to represent bitmap of CPUs. 104Never use anything other than cpumask_t to represent bitmap of CPUs.
105 105
106 #include <linux/cpumask.h> 106 #include <linux/cpumask.h>
107 107
108 for_each_possible_cpu - Iterate over cpu_possible_map 108 for_each_possible_cpu - Iterate over cpu_possible_mask
109 for_each_online_cpu - Iterate over cpu_online_map 109 for_each_online_cpu - Iterate over cpu_online_mask
110 for_each_present_cpu - Iterate over cpu_present_map 110 for_each_present_cpu - Iterate over cpu_present_mask
111 for_each_cpu_mask(x,mask) - Iterate over some random collection of cpu mask. 111 for_each_cpu_mask(x,mask) - Iterate over some random collection of cpu mask.
112 112
113 #include <linux/cpu.h> 113 #include <linux/cpu.h>
114 get_online_cpus() and put_online_cpus(): 114 get_online_cpus() and put_online_cpus():
115 115
116The above calls are used to inhibit cpu hotplug operations. While the 116The above calls are used to inhibit cpu hotplug operations. While the
117cpu_hotplug.refcount is non zero, the cpu_online_map will not change. 117cpu_hotplug.refcount is non zero, the cpu_online_mask will not change.
118If you merely need to avoid cpus going away, you could also use 118If you merely need to avoid cpus going away, you could also use
119preempt_disable() and preempt_enable() for those sections. 119preempt_disable() and preempt_enable() for those sections.
120Just remember the critical section cannot call any 120Just remember the critical section cannot call any
diff --git a/Documentation/devicetree/bindings/ata/calxeda-sata.txt b/Documentation/devicetree/bindings/ata/ahci-platform.txt
index 79caa5651f53..8bb8a76d42e8 100644
--- a/Documentation/devicetree/bindings/ata/calxeda-sata.txt
+++ b/Documentation/devicetree/bindings/ata/ahci-platform.txt
@@ -1,10 +1,10 @@
1* Calxeda SATA Controller 1* AHCI SATA Controller
2 2
3SATA nodes are defined to describe on-chip Serial ATA controllers. 3SATA nodes are defined to describe on-chip Serial ATA controllers.
4Each SATA controller should have its own node. 4Each SATA controller should have its own node.
5 5
6Required properties: 6Required properties:
7- compatible : compatible list, contains "calxeda,hb-ahci" 7- compatible : compatible list, contains "calxeda,hb-ahci" or "snps,spear-ahci"
8- interrupts : <interrupt mapping for SATA IRQ> 8- interrupts : <interrupt mapping for SATA IRQ>
9- reg : <registers mapping> 9- reg : <registers mapping>
10 10
@@ -14,4 +14,3 @@ Example:
14 reg = <0xffe08000 0x1000>; 14 reg = <0xffe08000 0x1000>;
15 interrupts = <115>; 15 interrupts = <115>;
16 }; 16 };
17
diff --git a/Documentation/devicetree/bindings/mtd/atmel-nand.txt b/Documentation/devicetree/bindings/mtd/atmel-nand.txt
index 5903ecf6e895..a20069502f5a 100644
--- a/Documentation/devicetree/bindings/mtd/atmel-nand.txt
+++ b/Documentation/devicetree/bindings/mtd/atmel-nand.txt
@@ -27,13 +27,13 @@ nand0: nand@40000000,0 {
27 reg = <0x40000000 0x10000000 27 reg = <0x40000000 0x10000000
28 0xffffe800 0x200 28 0xffffe800 0x200
29 >; 29 >;
30 atmel,nand-addr-offset = <21>; 30 atmel,nand-addr-offset = <21>; /* ale */
31 atmel,nand-cmd-offset = <22>; 31 atmel,nand-cmd-offset = <22>; /* cle */
32 nand-on-flash-bbt; 32 nand-on-flash-bbt;
33 nand-ecc-mode = "soft"; 33 nand-ecc-mode = "soft";
34 gpios = <&pioC 13 0 34 gpios = <&pioC 13 0 /* rdy */
35 &pioC 14 0 35 &pioC 14 0 /* nce */
36 0 36 0 /* cd */
37 >; 37 >;
38 partition@0 { 38 partition@0 {
39 ... 39 ...
diff --git a/Documentation/devicetree/bindings/regulator/anatop-regulator.txt b/Documentation/devicetree/bindings/regulator/anatop-regulator.txt
new file mode 100644
index 000000000000..357758cb6e92
--- /dev/null
+++ b/Documentation/devicetree/bindings/regulator/anatop-regulator.txt
@@ -0,0 +1,29 @@
1Anatop Voltage regulators
2
3Required properties:
4- compatible: Must be "fsl,anatop-regulator"
5- anatop-reg-offset: Anatop MFD register offset
6- anatop-vol-bit-shift: Bit shift for the register
7- anatop-vol-bit-width: Number of bits used in the register
8- anatop-min-bit-val: Minimum value of this register
9- anatop-min-voltage: Minimum voltage of this regulator
10- anatop-max-voltage: Maximum voltage of this regulator
11
12Any property defined as part of the core regulator
13binding, defined in regulator.txt, can also be used.
14
15Example:
16
17 regulator-vddpu {
18 compatible = "fsl,anatop-regulator";
19 regulator-name = "vddpu";
20 regulator-min-microvolt = <725000>;
21 regulator-max-microvolt = <1300000>;
22 regulator-always-on;
23 anatop-reg-offset = <0x140>;
24 anatop-vol-bit-shift = <9>;
25 anatop-vol-bit-width = <5>;
26 anatop-min-bit-val = <1>;
27 anatop-min-voltage = <725000>;
28 anatop-max-voltage = <1300000>;
29 };
diff --git a/Documentation/devicetree/bindings/sound/imx-audio-sgtl5000.txt b/Documentation/devicetree/bindings/sound/imx-audio-sgtl5000.txt
new file mode 100644
index 000000000000..e4acdd891e49
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/imx-audio-sgtl5000.txt
@@ -0,0 +1,49 @@
1Freescale i.MX audio complex with SGTL5000 codec
2
3Required properties:
4- compatible : "fsl,imx-audio-sgtl5000"
5- model : The user-visible name of this sound complex
6- ssi-controller : The phandle of the i.MX SSI controller
7- audio-codec : The phandle of the SGTL5000 audio codec
8- audio-routing : A list of the connections between audio components.
9 Each entry is a pair of strings, the first being the connection's sink,
10 the second being the connection's source. Valid names could be power
11 supplies, SGTL5000 pins, and the jacks on the board:
12
13 Power supplies:
14 * Mic Bias
15
16 SGTL5000 pins:
17 * MIC_IN
18 * LINE_IN
19 * HP_OUT
20 * LINE_OUT
21
22 Board connectors:
23 * Mic Jack
24 * Line In Jack
25 * Headphone Jack
26 * Line Out Jack
27 * Ext Spk
28
29- mux-int-port : The internal port of the i.MX audio muxer (AUDMUX)
30- mux-ext-port : The external port of the i.MX audio muxer
31
32Note: The AUDMUX port numbering should start at 1, which is consistent with
33hardware manual.
34
35Example:
36
37sound {
38 compatible = "fsl,imx51-babbage-sgtl5000",
39 "fsl,imx-audio-sgtl5000";
40 model = "imx51-babbage-sgtl5000";
41 ssi-controller = <&ssi1>;
42 audio-codec = <&sgtl5000>;
43 audio-routing =
44 "MIC_IN", "Mic Jack",
45 "Mic Jack", "Mic Bias",
46 "Headphone Jack", "HP_OUT";
47 mux-int-port = <1>;
48 mux-ext-port = <3>;
49};
diff --git a/Documentation/devicetree/bindings/sound/mxs-audio-sgtl5000.txt b/Documentation/devicetree/bindings/sound/mxs-audio-sgtl5000.txt
new file mode 100644
index 000000000000..601c518eddaa
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/mxs-audio-sgtl5000.txt
@@ -0,0 +1,17 @@
1* Freescale MXS audio complex with SGTL5000 codec
2
3Required properties:
4- compatible: "fsl,mxs-audio-sgtl5000"
5- model: The user-visible name of this sound complex
6- saif-controllers: The phandle list of the MXS SAIF controller
7- audio-codec: The phandle of the SGTL5000 audio codec
8
9Example:
10
11sound {
12 compatible = "fsl,imx28-evk-sgtl5000",
13 "fsl,mxs-audio-sgtl5000";
14 model = "imx28-evk-sgtl5000";
15 saif-controllers = <&saif0 &saif1>;
16 audio-codec = <&sgtl5000>;
17};
diff --git a/Documentation/devicetree/bindings/sound/mxs-saif.txt b/Documentation/devicetree/bindings/sound/mxs-saif.txt
new file mode 100644
index 000000000000..c37ba6143d9b
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/mxs-saif.txt
@@ -0,0 +1,36 @@
1* Freescale MXS Serial Audio Interface (SAIF)
2
3Required properties:
4- compatible: Should be "fsl,<chip>-saif"
5- reg: Should contain registers location and length
6- interrupts: Should contain ERROR and DMA interrupts
7- fsl,saif-dma-channel: APBX DMA channel for the SAIF
8
9Optional properties:
10- fsl,saif-master: phandle to the master SAIF. It's only required for
11 the slave SAIF.
12
13Note: Each SAIF controller should have an alias correctly numbered
14in "aliases" node.
15
16Example:
17
18aliases {
19 saif0 = &saif0;
20 saif1 = &saif1;
21};
22
23saif0: saif@80042000 {
24 compatible = "fsl,imx28-saif";
25 reg = <0x80042000 2000>;
26 interrupts = <59 80>;
27 fsl,saif-dma-channel = <4>;
28};
29
30saif1: saif@80046000 {
31 compatible = "fsl,imx28-saif";
32 reg = <0x80046000 2000>;
33 interrupts = <58 81>;
34 fsl,saif-dma-channel = <5>;
35 fsl,saif-master = <&saif0>;
36};
diff --git a/Documentation/devicetree/bindings/sound/nvidia,tegra30-ahub.txt b/Documentation/devicetree/bindings/sound/nvidia,tegra30-ahub.txt
new file mode 100644
index 000000000000..1ac7b1642186
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/nvidia,tegra30-ahub.txt
@@ -0,0 +1,32 @@
1NVIDIA Tegra30 AHUB (Audio Hub)
2
3Required properties:
4- compatible : "nvidia,tegra30-ahub"
5- reg : Should contain the register physical address and length for each of
6 the AHUB's APBIF registers and the AHUB's own registers.
7- interrupts : Should contain AHUB interrupt
8- nvidia,dma-request-selector : The Tegra DMA controller's phandle and
9 request selector for the first APBIF channel.
10- ranges : The bus address mapping for the configlink register bus.
11 Can be empty since the mapping is 1:1.
12- #address-cells : For the configlink bus. Should be <1>;
13- #size-cells : For the configlink bus. Should be <1>.
14
15AHUB client modules need to specify the IDs of their CIFs (Client InterFaces).
16For RX CIFs, the numbers indicate the register number within AHUB routing
17register space (APBIF 0..3 RX, I2S 0..5 RX, DAM 0..2 RX 0..1, SPDIF RX 0..1).
18For TX CIFs, the numbers indicate the bit position within the AHUB routing
19registers (APBIF 0..3 TX, I2S 0..5 TX, DAM 0..2 TX, SPDIF TX 0..1).
20
21Example:
22
23ahub@70080000 {
24 compatible = "nvidia,tegra30-ahub";
25 reg = <0x70080000 0x200 0x70080200 0x100>;
26 interrupts = < 0 103 0x04 >;
27 nvidia,dma-request-selector = <&apbdma 1>;
28
29 ranges;
30 #address-cells = <1>;
31 #size-cells = <1>;
32};
diff --git a/Documentation/devicetree/bindings/sound/nvidia,tegra30-i2s.txt b/Documentation/devicetree/bindings/sound/nvidia,tegra30-i2s.txt
new file mode 100644
index 000000000000..dfa6c037124a
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/nvidia,tegra30-i2s.txt
@@ -0,0 +1,15 @@
1NVIDIA Tegra30 I2S controller
2
3Required properties:
4- compatible : "nvidia,tegra30-i2s"
5- reg : Should contain I2S registers location and length
6- nvidia,ahub-cif-ids : The list of AHUB CIF IDs for this port, rx (playback)
7 first, tx (capture) second. See nvidia,tegra30-ahub.txt for values.
8
9Example:
10
11i2s@70002800 {
12 compatible = "nvidia,tegra30-i2s";
13 reg = <0x70080300 0x100>;
14 nvidia,ahub-cif-ids = <4 4>;
15};
diff --git a/Documentation/devicetree/bindings/sound/tegra-audio-trimslice.txt b/Documentation/devicetree/bindings/sound/tegra-audio-trimslice.txt
new file mode 100644
index 000000000000..04b14cfb1f16
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/tegra-audio-trimslice.txt
@@ -0,0 +1,14 @@
1NVIDIA Tegra audio complex for TrimSlice
2
3Required properties:
4- compatible : "nvidia,tegra-audio-trimslice"
5- nvidia,i2s-controller : The phandle of the Tegra I2S1 controller
6- nvidia,audio-codec : The phandle of the WM8903 audio codec
7
8Example:
9
10sound {
11 compatible = "nvidia,tegra-audio-trimslice";
12 nvidia,i2s-controller = <&tegra_i2s1>;
13 nvidia,audio-codec = <&codec>;
14};
diff --git a/Documentation/feature-removal-schedule.txt b/Documentation/feature-removal-schedule.txt
index c1be8066ea59..03ca210406ed 100644
--- a/Documentation/feature-removal-schedule.txt
+++ b/Documentation/feature-removal-schedule.txt
@@ -6,14 +6,6 @@ be removed from this file.
6 6
7--------------------------- 7---------------------------
8 8
9What: x86 floppy disable_hlt
10When: 2012
11Why: ancient workaround of dubious utility clutters the
12 code used by everybody else.
13Who: Len Brown <len.brown@intel.com>
14
15---------------------------
16
17What: CONFIG_APM_CPU_IDLE, and its ability to call APM BIOS in idle 9What: CONFIG_APM_CPU_IDLE, and its ability to call APM BIOS in idle
18When: 2012 10When: 2012
19Why: This optional sub-feature of APM is of dubious reliability, 11Why: This optional sub-feature of APM is of dubious reliability,
@@ -539,3 +531,11 @@ Why: There appear to be no production users of the get_robust_list syscall,
539 of ASLR. It was only ever intended for debugging, so it should be 531 of ASLR. It was only ever intended for debugging, so it should be
540 removed. 532 removed.
541Who: Kees Cook <keescook@chromium.org> 533Who: Kees Cook <keescook@chromium.org>
534
535----------------------------
536
537What: setitimer accepts user NULL pointer (value)
538When: 3.6
539Why: setitimer is not returning -EFAULT if user pointer is NULL. This
540 violates the spec.
541Who: Sasikantha Babu <sasikanth.v19@gmail.com>
diff --git a/Documentation/filesystems/vfs.txt b/Documentation/filesystems/vfs.txt
index e916e3d36488..0d0492028082 100644
--- a/Documentation/filesystems/vfs.txt
+++ b/Documentation/filesystems/vfs.txt
@@ -114,7 +114,7 @@ members are defined:
114struct file_system_type { 114struct file_system_type {
115 const char *name; 115 const char *name;
116 int fs_flags; 116 int fs_flags;
117 struct dentry (*mount) (struct file_system_type *, int, 117 struct dentry *(*mount) (struct file_system_type *, int,
118 const char *, void *); 118 const char *, void *);
119 void (*kill_sb) (struct super_block *); 119 void (*kill_sb) (struct super_block *);
120 struct module *owner; 120 struct module *owner;
diff --git a/Documentation/hwmon/k10temp b/Documentation/hwmon/k10temp
index a10f73624ad3..90956b618025 100644
--- a/Documentation/hwmon/k10temp
+++ b/Documentation/hwmon/k10temp
@@ -11,7 +11,7 @@ Supported chips:
11 Socket S1G2: Athlon (X2), Sempron (X2), Turion X2 (Ultra) 11 Socket S1G2: Athlon (X2), Sempron (X2), Turion X2 (Ultra)
12* AMD Family 12h processors: "Llano" (E2/A4/A6/A8-Series) 12* AMD Family 12h processors: "Llano" (E2/A4/A6/A8-Series)
13* AMD Family 14h processors: "Brazos" (C/E/G/Z-Series) 13* AMD Family 14h processors: "Brazos" (C/E/G/Z-Series)
14* AMD Family 15h processors: "Bulldozer" 14* AMD Family 15h processors: "Bulldozer" (FX-Series), "Trinity"
15 15
16 Prefix: 'k10temp' 16 Prefix: 'k10temp'
17 Addresses scanned: PCI space 17 Addresses scanned: PCI space
diff --git a/Documentation/ioctl/ioctl-number.txt b/Documentation/ioctl/ioctl-number.txt
index 3b7488fc3373..e34b531dc316 100644
--- a/Documentation/ioctl/ioctl-number.txt
+++ b/Documentation/ioctl/ioctl-number.txt
@@ -225,6 +225,7 @@ Code Seq#(hex) Include File Comments
225'j' 00-3F linux/joystick.h 225'j' 00-3F linux/joystick.h
226'k' 00-0F linux/spi/spidev.h conflict! 226'k' 00-0F linux/spi/spidev.h conflict!
227'k' 00-05 video/kyro.h conflict! 227'k' 00-05 video/kyro.h conflict!
228'k' 10-17 linux/hsi/hsi_char.h HSI character device
228'l' 00-3F linux/tcfs_fs.h transparent cryptographic file system 229'l' 00-3F linux/tcfs_fs.h transparent cryptographic file system
229 <http://web.archive.org/web/*/http://mikonos.dia.unisa.it/tcfs> 230 <http://web.archive.org/web/*/http://mikonos.dia.unisa.it/tcfs>
230'l' 40-7F linux/udf_fs_i.h in development: 231'l' 40-7F linux/udf_fs_i.h in development:
diff --git a/Documentation/networking/driver.txt b/Documentation/networking/driver.txt
index 03283daa64fe..da59e2884130 100644
--- a/Documentation/networking/driver.txt
+++ b/Documentation/networking/driver.txt
@@ -2,16 +2,16 @@ Document about softnet driver issues
2 2
3Transmit path guidelines: 3Transmit path guidelines:
4 4
51) The hard_start_xmit method must never return '1' under any 51) The ndo_start_xmit method must not return NETDEV_TX_BUSY under
6 normal circumstances. It is considered a hard error unless 6 any normal circumstances. It is considered a hard error unless
7 there is no way your device can tell ahead of time when it's 7 there is no way your device can tell ahead of time when it's
8 transmit function will become busy. 8 transmit function will become busy.
9 9
10 Instead it must maintain the queue properly. For example, 10 Instead it must maintain the queue properly. For example,
11 for a driver implementing scatter-gather this means: 11 for a driver implementing scatter-gather this means:
12 12
13 static int drv_hard_start_xmit(struct sk_buff *skb, 13 static netdev_tx_t drv_hard_start_xmit(struct sk_buff *skb,
14 struct net_device *dev) 14 struct net_device *dev)
15 { 15 {
16 struct drv *dp = netdev_priv(dev); 16 struct drv *dp = netdev_priv(dev);
17 17
@@ -23,7 +23,7 @@ Transmit path guidelines:
23 unlock_tx(dp); 23 unlock_tx(dp);
24 printk(KERN_ERR PFX "%s: BUG! Tx Ring full when queue awake!\n", 24 printk(KERN_ERR PFX "%s: BUG! Tx Ring full when queue awake!\n",
25 dev->name); 25 dev->name);
26 return 1; 26 return NETDEV_TX_BUSY;
27 } 27 }
28 28
29 ... queue packet to card ... 29 ... queue packet to card ...
@@ -35,6 +35,7 @@ Transmit path guidelines:
35 ... 35 ...
36 unlock_tx(dp); 36 unlock_tx(dp);
37 ... 37 ...
38 return NETDEV_TX_OK;
38 } 39 }
39 40
40 And then at the end of your TX reclamation event handling: 41 And then at the end of your TX reclamation event handling:
@@ -58,15 +59,12 @@ Transmit path guidelines:
58 TX_BUFFS_AVAIL(dp) > 0) 59 TX_BUFFS_AVAIL(dp) > 0)
59 netif_wake_queue(dp->dev); 60 netif_wake_queue(dp->dev);
60 61
612) Do not forget to update netdev->trans_start to jiffies after 622) An ndo_start_xmit method must not modify the shared parts of a
62 each new tx packet is given to the hardware.
63
643) A hard_start_xmit method must not modify the shared parts of a
65 cloned SKB. 63 cloned SKB.
66 64
674) Do not forget that once you return 0 from your hard_start_xmit 653) Do not forget that once you return NETDEV_TX_OK from your
68 method, it is your driver's responsibility to free up the SKB 66 ndo_start_xmit method, it is your driver's responsibility to free
69 and in some finite amount of time. 67 up the SKB and in some finite amount of time.
70 68
71 For example, this means that it is not allowed for your TX 69 For example, this means that it is not allowed for your TX
72 mitigation scheme to let TX packets "hang out" in the TX 70 mitigation scheme to let TX packets "hang out" in the TX
@@ -74,8 +72,9 @@ Transmit path guidelines:
74 This error can deadlock sockets waiting for send buffer room 72 This error can deadlock sockets waiting for send buffer room
75 to be freed up. 73 to be freed up.
76 74
77 If you return 1 from the hard_start_xmit method, you must not keep 75 If you return NETDEV_TX_BUSY from the ndo_start_xmit method, you
78 any reference to that SKB and you must not attempt to free it up. 76 must not keep any reference to that SKB and you must not attempt
77 to free it up.
79 78
80Probing guidelines: 79Probing guidelines:
81 80
@@ -85,10 +84,10 @@ Probing guidelines:
85 84
86Close/stop guidelines: 85Close/stop guidelines:
87 86
881) After the dev->stop routine has been called, the hardware must 871) After the ndo_stop routine has been called, the hardware must
89 not receive or transmit any data. All in flight packets must 88 not receive or transmit any data. All in flight packets must
90 be aborted. If necessary, poll or wait for completion of 89 be aborted. If necessary, poll or wait for completion of
91 any reset commands. 90 any reset commands.
92 91
932) The dev->stop routine will be called by unregister_netdevice 922) The ndo_stop routine will be called by unregister_netdevice
94 if device is still UP. 93 if device is still UP.
diff --git a/Documentation/networking/ip-sysctl.txt b/Documentation/networking/ip-sysctl.txt
index ad3e80e17b4f..1619a8c80873 100644
--- a/Documentation/networking/ip-sysctl.txt
+++ b/Documentation/networking/ip-sysctl.txt
@@ -147,7 +147,7 @@ tcp_adv_win_scale - INTEGER
147 (if tcp_adv_win_scale > 0) or bytes-bytes/2^(-tcp_adv_win_scale), 147 (if tcp_adv_win_scale > 0) or bytes-bytes/2^(-tcp_adv_win_scale),
148 if it is <= 0. 148 if it is <= 0.
149 Possible values are [-31, 31], inclusive. 149 Possible values are [-31, 31], inclusive.
150 Default: 2 150 Default: 1
151 151
152tcp_allowed_congestion_control - STRING 152tcp_allowed_congestion_control - STRING
153 Show/set the congestion control choices available to non-privileged 153 Show/set the congestion control choices available to non-privileged
@@ -410,7 +410,7 @@ tcp_rmem - vector of 3 INTEGERs: min, default, max
410 net.core.rmem_max. Calling setsockopt() with SO_RCVBUF disables 410 net.core.rmem_max. Calling setsockopt() with SO_RCVBUF disables
411 automatic tuning of that socket's receive buffer size, in which 411 automatic tuning of that socket's receive buffer size, in which
412 case this value is ignored. 412 case this value is ignored.
413 Default: between 87380B and 4MB, depending on RAM size. 413 Default: between 87380B and 6MB, depending on RAM size.
414 414
415tcp_sack - BOOLEAN 415tcp_sack - BOOLEAN
416 Enable select acknowledgments (SACKS). 416 Enable select acknowledgments (SACKS).
@@ -604,15 +604,8 @@ IP Variables:
604ip_local_port_range - 2 INTEGERS 604ip_local_port_range - 2 INTEGERS
605 Defines the local port range that is used by TCP and UDP to 605 Defines the local port range that is used by TCP and UDP to
606 choose the local port. The first number is the first, the 606 choose the local port. The first number is the first, the
607 second the last local port number. Default value depends on 607 second the last local port number. The default values are
608 amount of memory available on the system: 608 32768 and 61000 respectively.
609 > 128Mb 32768-61000
610 < 128Mb 1024-4999 or even less.
611 This number defines number of active connections, which this
612 system can issue simultaneously to systems not supporting
613 TCP extensions (timestamps). With tcp_tw_recycle enabled
614 (i.e. by default) range 1024-4999 is enough to issue up to
615 2000 connections per second to systems supporting timestamps.
616 609
617ip_local_reserved_ports - list of comma separated ranges 610ip_local_reserved_ports - list of comma separated ranges
618 Specify the ports which are reserved for known third-party 611 Specify the ports which are reserved for known third-party
diff --git a/Documentation/networking/netdevices.txt b/Documentation/networking/netdevices.txt
index 89358341682a..c7ecc7080494 100644
--- a/Documentation/networking/netdevices.txt
+++ b/Documentation/networking/netdevices.txt
@@ -47,26 +47,25 @@ packets is preferred.
47 47
48struct net_device synchronization rules 48struct net_device synchronization rules
49======================================= 49=======================================
50dev->open: 50ndo_open:
51 Synchronization: rtnl_lock() semaphore. 51 Synchronization: rtnl_lock() semaphore.
52 Context: process 52 Context: process
53 53
54dev->stop: 54ndo_stop:
55 Synchronization: rtnl_lock() semaphore. 55 Synchronization: rtnl_lock() semaphore.
56 Context: process 56 Context: process
57 Note1: netif_running() is guaranteed false 57 Note: netif_running() is guaranteed false
58 Note2: dev->poll() is guaranteed to be stopped
59 58
60dev->do_ioctl: 59ndo_do_ioctl:
61 Synchronization: rtnl_lock() semaphore. 60 Synchronization: rtnl_lock() semaphore.
62 Context: process 61 Context: process
63 62
64dev->get_stats: 63ndo_get_stats:
65 Synchronization: dev_base_lock rwlock. 64 Synchronization: dev_base_lock rwlock.
66 Context: nominally process, but don't sleep inside an rwlock 65 Context: nominally process, but don't sleep inside an rwlock
67 66
68dev->hard_start_xmit: 67ndo_start_xmit:
69 Synchronization: netif_tx_lock spinlock. 68 Synchronization: __netif_tx_lock spinlock.
70 69
71 When the driver sets NETIF_F_LLTX in dev->features this will be 70 When the driver sets NETIF_F_LLTX in dev->features this will be
72 called without holding netif_tx_lock. In this case the driver 71 called without holding netif_tx_lock. In this case the driver
@@ -87,20 +86,20 @@ dev->hard_start_xmit:
87 o NETDEV_TX_LOCKED Locking failed, please retry quickly. 86 o NETDEV_TX_LOCKED Locking failed, please retry quickly.
88 Only valid when NETIF_F_LLTX is set. 87 Only valid when NETIF_F_LLTX is set.
89 88
90dev->tx_timeout: 89ndo_tx_timeout:
91 Synchronization: netif_tx_lock spinlock. 90 Synchronization: netif_tx_lock spinlock; all TX queues frozen.
92 Context: BHs disabled 91 Context: BHs disabled
93 Notes: netif_queue_stopped() is guaranteed true 92 Notes: netif_queue_stopped() is guaranteed true
94 93
95dev->set_rx_mode: 94ndo_set_rx_mode:
96 Synchronization: netif_tx_lock spinlock. 95 Synchronization: netif_addr_lock spinlock.
97 Context: BHs disabled 96 Context: BHs disabled
98 97
99struct napi_struct synchronization rules 98struct napi_struct synchronization rules
100======================================== 99========================================
101napi->poll: 100napi->poll:
102 Synchronization: NAPI_STATE_SCHED bit in napi->state. Device 101 Synchronization: NAPI_STATE_SCHED bit in napi->state. Device
103 driver's dev->close method will invoke napi_disable() on 102 driver's ndo_stop method will invoke napi_disable() on
104 all NAPI instances which will do a sleeping poll on the 103 all NAPI instances which will do a sleeping poll on the
105 NAPI_STATE_SCHED napi->state bit, waiting for all pending 104 NAPI_STATE_SCHED napi->state bit, waiting for all pending
106 NAPI activity to cease. 105 NAPI activity to cease.
diff --git a/Documentation/power/freezing-of-tasks.txt b/Documentation/power/freezing-of-tasks.txt
index ec715cd78fbb..6ec291ea1c78 100644
--- a/Documentation/power/freezing-of-tasks.txt
+++ b/Documentation/power/freezing-of-tasks.txt
@@ -9,7 +9,7 @@ architectures).
9 9
10II. How does it work? 10II. How does it work?
11 11
12There are four per-task flags used for that, PF_NOFREEZE, PF_FROZEN, TIF_FREEZE 12There are three per-task flags used for that, PF_NOFREEZE, PF_FROZEN
13and PF_FREEZER_SKIP (the last one is auxiliary). The tasks that have 13and PF_FREEZER_SKIP (the last one is auxiliary). The tasks that have
14PF_NOFREEZE unset (all user space processes and some kernel threads) are 14PF_NOFREEZE unset (all user space processes and some kernel threads) are
15regarded as 'freezable' and treated in a special way before the system enters a 15regarded as 'freezable' and treated in a special way before the system enters a
@@ -17,30 +17,31 @@ suspend state as well as before a hibernation image is created (in what follows
17we only consider hibernation, but the description also applies to suspend). 17we only consider hibernation, but the description also applies to suspend).
18 18
19Namely, as the first step of the hibernation procedure the function 19Namely, as the first step of the hibernation procedure the function
20freeze_processes() (defined in kernel/power/process.c) is called. It executes 20freeze_processes() (defined in kernel/power/process.c) is called. A system-wide
21try_to_freeze_tasks() that sets TIF_FREEZE for all of the freezable tasks and 21variable system_freezing_cnt (as opposed to a per-task flag) is used to indicate
22either wakes them up, if they are kernel threads, or sends fake signals to them, 22whether the system is to undergo a freezing operation. And freeze_processes()
23if they are user space processes. A task that has TIF_FREEZE set, should react 23sets this variable. After this, it executes try_to_freeze_tasks() that sends a
24to it by calling the function called __refrigerator() (defined in 24fake signal to all user space processes, and wakes up all the kernel threads.
25kernel/freezer.c), which sets the task's PF_FROZEN flag, changes its state 25All freezable tasks must react to that by calling try_to_freeze(), which
26to TASK_UNINTERRUPTIBLE and makes it loop until PF_FROZEN is cleared for it. 26results in a call to __refrigerator() (defined in kernel/freezer.c), which sets
27Then, we say that the task is 'frozen' and therefore the set of functions 27the task's PF_FROZEN flag, changes its state to TASK_UNINTERRUPTIBLE and makes
28handling this mechanism is referred to as 'the freezer' (these functions are 28it loop until PF_FROZEN is cleared for it. Then, we say that the task is
29defined in kernel/power/process.c, kernel/freezer.c & include/linux/freezer.h). 29'frozen' and therefore the set of functions handling this mechanism is referred
30User space processes are generally frozen before kernel threads. 30to as 'the freezer' (these functions are defined in kernel/power/process.c,
31kernel/freezer.c & include/linux/freezer.h). User space processes are generally
32frozen before kernel threads.
31 33
32__refrigerator() must not be called directly. Instead, use the 34__refrigerator() must not be called directly. Instead, use the
33try_to_freeze() function (defined in include/linux/freezer.h), that checks 35try_to_freeze() function (defined in include/linux/freezer.h), that checks
34the task's TIF_FREEZE flag and makes the task enter __refrigerator() if the 36if the task is to be frozen and makes the task enter __refrigerator().
35flag is set.
36 37
37For user space processes try_to_freeze() is called automatically from the 38For user space processes try_to_freeze() is called automatically from the
38signal-handling code, but the freezable kernel threads need to call it 39signal-handling code, but the freezable kernel threads need to call it
39explicitly in suitable places or use the wait_event_freezable() or 40explicitly in suitable places or use the wait_event_freezable() or
40wait_event_freezable_timeout() macros (defined in include/linux/freezer.h) 41wait_event_freezable_timeout() macros (defined in include/linux/freezer.h)
41that combine interruptible sleep with checking if TIF_FREEZE is set and calling 42that combine interruptible sleep with checking if the task is to be frozen and
42try_to_freeze(). The main loop of a freezable kernel thread may look like the 43calling try_to_freeze(). The main loop of a freezable kernel thread may look
43following one: 44like the following one:
44 45
45 set_freezable(); 46 set_freezable();
46 do { 47 do {
@@ -53,7 +54,7 @@ following one:
53(from drivers/usb/core/hub.c::hub_thread()). 54(from drivers/usb/core/hub.c::hub_thread()).
54 55
55If a freezable kernel thread fails to call try_to_freeze() after the freezer has 56If a freezable kernel thread fails to call try_to_freeze() after the freezer has
56set TIF_FREEZE for it, the freezing of tasks will fail and the entire 57initiated a freezing operation, the freezing of tasks will fail and the entire
57hibernation operation will be cancelled. For this reason, freezable kernel 58hibernation operation will be cancelled. For this reason, freezable kernel
58threads must call try_to_freeze() somewhere or use one of the 59threads must call try_to_freeze() somewhere or use one of the
59wait_event_freezable() and wait_event_freezable_timeout() macros. 60wait_event_freezable() and wait_event_freezable_timeout() macros.
diff --git a/Documentation/security/keys.txt b/Documentation/security/keys.txt
index 787717091421..d389acd31e19 100644
--- a/Documentation/security/keys.txt
+++ b/Documentation/security/keys.txt
@@ -123,7 +123,7 @@ KEY SERVICE OVERVIEW
123 123
124The key service provides a number of features besides keys: 124The key service provides a number of features besides keys:
125 125
126 (*) The key service defines two special key types: 126 (*) The key service defines three special key types:
127 127
128 (+) "keyring" 128 (+) "keyring"
129 129
@@ -137,6 +137,18 @@ The key service provides a number of features besides keys:
137 blobs of data. These can be created, updated and read by userspace, 137 blobs of data. These can be created, updated and read by userspace,
138 and aren't intended for use by kernel services. 138 and aren't intended for use by kernel services.
139 139
140 (+) "logon"
141
142 Like a "user" key, a "logon" key has a payload that is an arbitrary
143 blob of data. It is intended as a place to store secrets which are
144 accessible to the kernel but not to userspace programs.
145
146 The description can be arbitrary, but must be prefixed with a non-zero
147 length string that describes the key "subclass". The subclass is
148 separated from the rest of the description by a ':'. "logon" keys can
149 be created and updated from userspace, but the payload is only
150 readable from kernel space.
151
140 (*) Each process subscribes to three keyrings: a thread-specific keyring, a 152 (*) Each process subscribes to three keyrings: a thread-specific keyring, a
141 process-specific keyring, and a session-specific keyring. 153 process-specific keyring, and a session-specific keyring.
142 154
diff --git a/Documentation/usb/URB.txt b/Documentation/usb/URB.txt
index 8ffce746d496..00d2c644068e 100644
--- a/Documentation/usb/URB.txt
+++ b/Documentation/usb/URB.txt
@@ -168,6 +168,28 @@ that if the completion handler or anyone else tries to resubmit it
168they will get a -EPERM error. Thus you can be sure that when 168they will get a -EPERM error. Thus you can be sure that when
169usb_kill_urb() returns, the URB is totally idle. 169usb_kill_urb() returns, the URB is totally idle.
170 170
171There is a lifetime issue to consider. An URB may complete at any
172time, and the completion handler may free the URB. If this happens
173while usb_unlink_urb or usb_kill_urb is running, it will cause a
174memory-access violation. The driver is responsible for avoiding this,
175which often means some sort of lock will be needed to prevent the URB
176from being deallocated while it is still in use.
177
178On the other hand, since usb_unlink_urb may end up calling the
179completion handler, the handler must not take any lock that is held
180when usb_unlink_urb is invoked. The general solution to this problem
181is to increment the URB's reference count while holding the lock, then
182drop the lock and call usb_unlink_urb or usb_kill_urb, and then
183decrement the URB's reference count. You increment the reference
184count by calling
185
186 struct urb *usb_get_urb(struct urb *urb)
187
188(ignore the return value; it is the same as the argument) and
189decrement the reference count by calling usb_free_urb. Of course,
190none of this is necessary if there's no danger of the URB being freed
191by the completion handler.
192
171 193
1721.7. What about the completion handler? 1941.7. What about the completion handler?
173 195
diff --git a/Documentation/usb/usbmon.txt b/Documentation/usb/usbmon.txt
index 5335fa8b06eb..c42bb9cd3b43 100644
--- a/Documentation/usb/usbmon.txt
+++ b/Documentation/usb/usbmon.txt
@@ -183,10 +183,10 @@ An input control transfer to get a port status.
183d5ea89a0 3575914555 S Ci:1:001:0 s a3 00 0000 0003 0004 4 < 183d5ea89a0 3575914555 S Ci:1:001:0 s a3 00 0000 0003 0004 4 <
184d5ea89a0 3575914560 C Ci:1:001:0 0 4 = 01050000 184d5ea89a0 3575914560 C Ci:1:001:0 0 4 = 01050000
185 185
186An output bulk transfer to send a SCSI command 0x5E in a 31-byte Bulk wrapper 186An output bulk transfer to send a SCSI command 0x28 (READ_10) in a 31-byte
187to a storage device at address 5: 187Bulk wrapper to a storage device at address 5:
188 188
189dd65f0e8 4128379752 S Bo:1:005:2 -115 31 = 55534243 5e000000 00000000 00000600 00000000 00000000 00000000 000000 189dd65f0e8 4128379752 S Bo:1:005:2 -115 31 = 55534243 ad000000 00800000 80010a28 20000000 20000040 00000000 000000
190dd65f0e8 4128379808 C Bo:1:005:2 0 31 > 190dd65f0e8 4128379808 C Bo:1:005:2 0 31 >
191 191
192* Raw binary format and API 192* Raw binary format and API
diff --git a/MAINTAINERS b/MAINTAINERS
index 5190cf25fd8d..fc203d019e61 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -228,7 +228,7 @@ M: Len Brown <lenb@kernel.org>
228L: linux-acpi@vger.kernel.org 228L: linux-acpi@vger.kernel.org
229W: http://www.lesswatts.org/projects/acpi/ 229W: http://www.lesswatts.org/projects/acpi/
230Q: http://patchwork.kernel.org/project/linux-acpi/list/ 230Q: http://patchwork.kernel.org/project/linux-acpi/list/
231T: git git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux-acpi-2.6.git 231T: git git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux
232S: Supported 232S: Supported
233F: drivers/acpi/ 233F: drivers/acpi/
234F: drivers/pnp/pnpacpi/ 234F: drivers/pnp/pnpacpi/
@@ -1251,7 +1251,6 @@ ATHEROS ATH5K WIRELESS DRIVER
1251M: Jiri Slaby <jirislaby@gmail.com> 1251M: Jiri Slaby <jirislaby@gmail.com>
1252M: Nick Kossifidis <mickflemm@gmail.com> 1252M: Nick Kossifidis <mickflemm@gmail.com>
1253M: "Luis R. Rodriguez" <mcgrof@qca.qualcomm.com> 1253M: "Luis R. Rodriguez" <mcgrof@qca.qualcomm.com>
1254M: Bob Copeland <me@bobcopeland.com>
1255L: linux-wireless@vger.kernel.org 1254L: linux-wireless@vger.kernel.org
1256L: ath5k-devel@lists.ath5k.org 1255L: ath5k-devel@lists.ath5k.org
1257W: http://wireless.kernel.org/en/users/Drivers/ath5k 1256W: http://wireless.kernel.org/en/users/Drivers/ath5k
@@ -1522,8 +1521,8 @@ M: Gustavo Padovan <gustavo@padovan.org>
1522M: Johan Hedberg <johan.hedberg@gmail.com> 1521M: Johan Hedberg <johan.hedberg@gmail.com>
1523L: linux-bluetooth@vger.kernel.org 1522L: linux-bluetooth@vger.kernel.org
1524W: http://www.bluez.org/ 1523W: http://www.bluez.org/
1525T: git git://git.kernel.org/pub/scm/linux/kernel/git/padovan/bluetooth.git 1524T: git git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth.git
1526T: git git://git.kernel.org/pub/scm/linux/kernel/git/jh/bluetooth.git 1525T: git git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git
1527S: Maintained 1526S: Maintained
1528F: drivers/bluetooth/ 1527F: drivers/bluetooth/
1529 1528
@@ -1533,8 +1532,8 @@ M: Gustavo Padovan <gustavo@padovan.org>
1533M: Johan Hedberg <johan.hedberg@gmail.com> 1532M: Johan Hedberg <johan.hedberg@gmail.com>
1534L: linux-bluetooth@vger.kernel.org 1533L: linux-bluetooth@vger.kernel.org
1535W: http://www.bluez.org/ 1534W: http://www.bluez.org/
1536T: git git://git.kernel.org/pub/scm/linux/kernel/git/padovan/bluetooth.git 1535T: git git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth.git
1537T: git git://git.kernel.org/pub/scm/linux/kernel/git/jh/bluetooth.git 1536T: git git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git
1538S: Maintained 1537S: Maintained
1539F: net/bluetooth/ 1538F: net/bluetooth/
1540F: include/net/bluetooth/ 1539F: include/net/bluetooth/
@@ -1969,10 +1968,9 @@ S: Maintained
1969F: drivers/net/ethernet/ti/cpmac.c 1968F: drivers/net/ethernet/ti/cpmac.c
1970 1969
1971CPU FREQUENCY DRIVERS 1970CPU FREQUENCY DRIVERS
1972M: Dave Jones <davej@redhat.com> 1971M: Rafael J. Wysocki <rjw@sisk.pl>
1973L: cpufreq@vger.kernel.org 1972L: cpufreq@vger.kernel.org
1974W: http://www.codemonkey.org.uk/projects/cpufreq/ 1973L: linux-pm@vger.kernel.org
1975T: git git://git.kernel.org/pub/scm/linux/kernel/git/davej/cpufreq.git
1976S: Maintained 1974S: Maintained
1977F: drivers/cpufreq/ 1975F: drivers/cpufreq/
1978F: include/linux/cpufreq.h 1976F: include/linux/cpufreq.h
@@ -2322,9 +2320,9 @@ S: Supported
2322F: drivers/acpi/dock.c 2320F: drivers/acpi/dock.c
2323 2321
2324DOCUMENTATION 2322DOCUMENTATION
2325M: Randy Dunlap <rdunlap@xenotime.net> 2323M: Rob Landley <rob@landley.net>
2326L: linux-doc@vger.kernel.org 2324L: linux-doc@vger.kernel.org
2327T: quilt http://xenotime.net/kernel-doc-patches/current/ 2325T: TBD
2328S: Maintained 2326S: Maintained
2329F: Documentation/ 2327F: Documentation/
2330 2328
@@ -2451,17 +2449,17 @@ F: fs/ecryptfs/
2451 2449
2452EDAC-CORE 2450EDAC-CORE
2453M: Doug Thompson <dougthompson@xmission.com> 2451M: Doug Thompson <dougthompson@xmission.com>
2454L: bluesmoke-devel@lists.sourceforge.net (moderated for non-subscribers) 2452L: linux-edac@vger.kernel.org
2455W: bluesmoke.sourceforge.net 2453W: bluesmoke.sourceforge.net
2456S: Supported 2454S: Supported
2457F: Documentation/edac.txt 2455F: Documentation/edac.txt
2458F: drivers/edac/edac_* 2456F: drivers/edac/
2459F: include/linux/edac.h 2457F: include/linux/edac.h
2460 2458
2461EDAC-AMD64 2459EDAC-AMD64
2462M: Doug Thompson <dougthompson@xmission.com> 2460M: Doug Thompson <dougthompson@xmission.com>
2463M: Borislav Petkov <borislav.petkov@amd.com> 2461M: Borislav Petkov <borislav.petkov@amd.com>
2464L: bluesmoke-devel@lists.sourceforge.net (moderated for non-subscribers) 2462L: linux-edac@vger.kernel.org
2465W: bluesmoke.sourceforge.net 2463W: bluesmoke.sourceforge.net
2466S: Supported 2464S: Supported
2467F: drivers/edac/amd64_edac* 2465F: drivers/edac/amd64_edac*
@@ -2469,35 +2467,35 @@ F: drivers/edac/amd64_edac*
2469EDAC-E752X 2467EDAC-E752X
2470M: Mark Gross <mark.gross@intel.com> 2468M: Mark Gross <mark.gross@intel.com>
2471M: Doug Thompson <dougthompson@xmission.com> 2469M: Doug Thompson <dougthompson@xmission.com>
2472L: bluesmoke-devel@lists.sourceforge.net (moderated for non-subscribers) 2470L: linux-edac@vger.kernel.org
2473W: bluesmoke.sourceforge.net 2471W: bluesmoke.sourceforge.net
2474S: Maintained 2472S: Maintained
2475F: drivers/edac/e752x_edac.c 2473F: drivers/edac/e752x_edac.c
2476 2474
2477EDAC-E7XXX 2475EDAC-E7XXX
2478M: Doug Thompson <dougthompson@xmission.com> 2476M: Doug Thompson <dougthompson@xmission.com>
2479L: bluesmoke-devel@lists.sourceforge.net (moderated for non-subscribers) 2477L: linux-edac@vger.kernel.org
2480W: bluesmoke.sourceforge.net 2478W: bluesmoke.sourceforge.net
2481S: Maintained 2479S: Maintained
2482F: drivers/edac/e7xxx_edac.c 2480F: drivers/edac/e7xxx_edac.c
2483 2481
2484EDAC-I82443BXGX 2482EDAC-I82443BXGX
2485M: Tim Small <tim@buttersideup.com> 2483M: Tim Small <tim@buttersideup.com>
2486L: bluesmoke-devel@lists.sourceforge.net (moderated for non-subscribers) 2484L: linux-edac@vger.kernel.org
2487W: bluesmoke.sourceforge.net 2485W: bluesmoke.sourceforge.net
2488S: Maintained 2486S: Maintained
2489F: drivers/edac/i82443bxgx_edac.c 2487F: drivers/edac/i82443bxgx_edac.c
2490 2488
2491EDAC-I3000 2489EDAC-I3000
2492M: Jason Uhlenkott <juhlenko@akamai.com> 2490M: Jason Uhlenkott <juhlenko@akamai.com>
2493L: bluesmoke-devel@lists.sourceforge.net (moderated for non-subscribers) 2491L: linux-edac@vger.kernel.org
2494W: bluesmoke.sourceforge.net 2492W: bluesmoke.sourceforge.net
2495S: Maintained 2493S: Maintained
2496F: drivers/edac/i3000_edac.c 2494F: drivers/edac/i3000_edac.c
2497 2495
2498EDAC-I5000 2496EDAC-I5000
2499M: Doug Thompson <dougthompson@xmission.com> 2497M: Doug Thompson <dougthompson@xmission.com>
2500L: bluesmoke-devel@lists.sourceforge.net (moderated for non-subscribers) 2498L: linux-edac@vger.kernel.org
2501W: bluesmoke.sourceforge.net 2499W: bluesmoke.sourceforge.net
2502S: Maintained 2500S: Maintained
2503F: drivers/edac/i5000_edac.c 2501F: drivers/edac/i5000_edac.c
@@ -2526,21 +2524,21 @@ F: drivers/edac/i7core_edac.c
2526EDAC-I82975X 2524EDAC-I82975X
2527M: Ranganathan Desikan <ravi@jetztechnologies.com> 2525M: Ranganathan Desikan <ravi@jetztechnologies.com>
2528M: "Arvind R." <arvino55@gmail.com> 2526M: "Arvind R." <arvino55@gmail.com>
2529L: bluesmoke-devel@lists.sourceforge.net (moderated for non-subscribers) 2527L: linux-edac@vger.kernel.org
2530W: bluesmoke.sourceforge.net 2528W: bluesmoke.sourceforge.net
2531S: Maintained 2529S: Maintained
2532F: drivers/edac/i82975x_edac.c 2530F: drivers/edac/i82975x_edac.c
2533 2531
2534EDAC-PASEMI 2532EDAC-PASEMI
2535M: Egor Martovetsky <egor@pasemi.com> 2533M: Egor Martovetsky <egor@pasemi.com>
2536L: bluesmoke-devel@lists.sourceforge.net (moderated for non-subscribers) 2534L: linux-edac@vger.kernel.org
2537W: bluesmoke.sourceforge.net 2535W: bluesmoke.sourceforge.net
2538S: Maintained 2536S: Maintained
2539F: drivers/edac/pasemi_edac.c 2537F: drivers/edac/pasemi_edac.c
2540 2538
2541EDAC-R82600 2539EDAC-R82600
2542M: Tim Small <tim@buttersideup.com> 2540M: Tim Small <tim@buttersideup.com>
2543L: bluesmoke-devel@lists.sourceforge.net (moderated for non-subscribers) 2541L: linux-edac@vger.kernel.org
2544W: bluesmoke.sourceforge.net 2542W: bluesmoke.sourceforge.net
2545S: Maintained 2543S: Maintained
2546F: drivers/edac/r82600_edac.c 2544F: drivers/edac/r82600_edac.c
@@ -3557,17 +3555,13 @@ L: linux-pm@vger.kernel.org
3557S: Supported 3555S: Supported
3558F: arch/x86/platform/mrst/pmu.* 3556F: arch/x86/platform/mrst/pmu.*
3559 3557
3560INTEL PRO/WIRELESS 2100 NETWORK CONNECTION SUPPORT 3558INTEL PRO/WIRELESS 2100, 2200BG, 2915ABG NETWORK CONNECTION SUPPORT
3559M: Stanislav Yakovlev <stas.yakovlev@gmail.com>
3561L: linux-wireless@vger.kernel.org 3560L: linux-wireless@vger.kernel.org
3562S: Orphan 3561S: Maintained
3563F: Documentation/networking/README.ipw2100 3562F: Documentation/networking/README.ipw2100
3564F: drivers/net/wireless/ipw2x00/ipw2100.*
3565
3566INTEL PRO/WIRELESS 2915ABG NETWORK CONNECTION SUPPORT
3567L: linux-wireless@vger.kernel.org
3568S: Orphan
3569F: Documentation/networking/README.ipw2200 3563F: Documentation/networking/README.ipw2200
3570F: drivers/net/wireless/ipw2x00/ipw2200.* 3564F: drivers/net/wireless/ipw2x00/
3571 3565
3572INTEL(R) TRUSTED EXECUTION TECHNOLOGY (TXT) 3566INTEL(R) TRUSTED EXECUTION TECHNOLOGY (TXT)
3573M: Joseph Cihula <joseph.cihula@intel.com> 3567M: Joseph Cihula <joseph.cihula@intel.com>
@@ -3597,6 +3591,7 @@ S: Supported
3597F: drivers/net/wireless/iwlegacy/ 3591F: drivers/net/wireless/iwlegacy/
3598 3592
3599INTEL WIRELESS WIFI LINK (iwlwifi) 3593INTEL WIRELESS WIFI LINK (iwlwifi)
3594M: Johannes Berg <johannes.berg@intel.com>
3600M: Wey-Yi Guy <wey-yi.w.guy@intel.com> 3595M: Wey-Yi Guy <wey-yi.w.guy@intel.com>
3601M: Intel Linux Wireless <ilw@linux.intel.com> 3596M: Intel Linux Wireless <ilw@linux.intel.com>
3602L: linux-wireless@vger.kernel.org 3597L: linux-wireless@vger.kernel.org
@@ -4041,6 +4036,7 @@ F: Documentation/scsi/53c700.txt
4041F: drivers/scsi/53c700* 4036F: drivers/scsi/53c700*
4042 4037
4043LED SUBSYSTEM 4038LED SUBSYSTEM
4039M: Bryan Wu <bryan.wu@canonical.com>
4044M: Richard Purdie <rpurdie@rpsys.net> 4040M: Richard Purdie <rpurdie@rpsys.net>
4045S: Maintained 4041S: Maintained
4046F: drivers/leds/ 4042F: drivers/leds/
@@ -4314,6 +4310,13 @@ W: http://www.kernel.org/doc/man-pages
4314L: linux-man@vger.kernel.org 4310L: linux-man@vger.kernel.org
4315S: Maintained 4311S: Maintained
4316 4312
4313MARVELL GIGABIT ETHERNET DRIVERS (skge/sky2)
4314M: Mirko Lindner <mlindner@marvell.com>
4315M: Stephen Hemminger <shemminger@vyatta.com>
4316L: netdev@vger.kernel.org
4317S: Maintained
4318F: drivers/net/ethernet/marvell/sk*
4319
4317MARVELL LIBERTAS WIRELESS DRIVER 4320MARVELL LIBERTAS WIRELESS DRIVER
4318M: Dan Williams <dcbw@redhat.com> 4321M: Dan Williams <dcbw@redhat.com>
4319L: libertas-dev@lists.infradead.org 4322L: libertas-dev@lists.infradead.org
@@ -4344,12 +4347,6 @@ M: Nicolas Pitre <nico@fluxnic.net>
4344S: Odd Fixes 4347S: Odd Fixes
4345F: drivers/mmc/host/mvsdio.* 4348F: drivers/mmc/host/mvsdio.*
4346 4349
4347MARVELL YUKON / SYSKONNECT DRIVER
4348M: Mirko Lindner <mlindner@syskonnect.de>
4349M: Ralph Roesler <rroesler@syskonnect.de>
4350W: http://www.syskonnect.com
4351S: Supported
4352
4353MATROX FRAMEBUFFER DRIVER 4350MATROX FRAMEBUFFER DRIVER
4354L: linux-fbdev@vger.kernel.org 4351L: linux-fbdev@vger.kernel.org
4355S: Orphan 4352S: Orphan
@@ -4537,8 +4534,7 @@ S: Supported
4537F: drivers/net/ethernet/myricom/myri10ge/ 4534F: drivers/net/ethernet/myricom/myri10ge/
4538 4535
4539NATSEMI ETHERNET DRIVER (DP8381x) 4536NATSEMI ETHERNET DRIVER (DP8381x)
4540M: Tim Hockin <thockin@hockin.org> 4537S: Orphan
4541S: Maintained
4542F: drivers/net/ethernet/natsemi/natsemi.c 4538F: drivers/net/ethernet/natsemi/natsemi.c
4543 4539
4544NATIVE INSTRUMENTS USB SOUND INTERFACE DRIVER 4540NATIVE INSTRUMENTS USB SOUND INTERFACE DRIVER
@@ -5122,6 +5118,11 @@ F: drivers/i2c/busses/i2c-pca-*
5122F: include/linux/i2c-algo-pca.h 5118F: include/linux/i2c-algo-pca.h
5123F: include/linux/i2c-pca-platform.h 5119F: include/linux/i2c-pca-platform.h
5124 5120
5121PCDP - PRIMARY CONSOLE AND DEBUG PORT
5122M: Khalid Aziz <khalid.aziz@hp.com>
5123S: Maintained
5124F: drivers/firmware/pcdp.*
5125
5125PCI ERROR RECOVERY 5126PCI ERROR RECOVERY
5126M: Linas Vepstas <linasvepstas@gmail.com> 5127M: Linas Vepstas <linasvepstas@gmail.com>
5127L: linux-pci@vger.kernel.org 5128L: linux-pci@vger.kernel.org
@@ -5643,7 +5644,7 @@ M: Ohad Ben-Cohen <ohad@wizery.com>
5643S: Maintained 5644S: Maintained
5644F: drivers/remoteproc/ 5645F: drivers/remoteproc/
5645F: Documentation/remoteproc.txt 5646F: Documentation/remoteproc.txt
5646F: include/linux/remoteproc.txt 5647F: include/linux/remoteproc.h
5647 5648
5648RFKILL 5649RFKILL
5649M: Johannes Berg <johannes@sipsolutions.net> 5650M: Johannes Berg <johannes@sipsolutions.net>
@@ -5891,11 +5892,11 @@ F: Documentation/scsi/st.txt
5891F: drivers/scsi/st* 5892F: drivers/scsi/st*
5892 5893
5893SCTP PROTOCOL 5894SCTP PROTOCOL
5894M: Vlad Yasevich <vladislav.yasevich@hp.com> 5895M: Vlad Yasevich <vyasevich@gmail.com>
5895M: Sridhar Samudrala <sri@us.ibm.com> 5896M: Sridhar Samudrala <sri@us.ibm.com>
5896L: linux-sctp@vger.kernel.org 5897L: linux-sctp@vger.kernel.org
5897W: http://lksctp.sourceforge.net 5898W: http://lksctp.sourceforge.net
5898S: Supported 5899S: Maintained
5899F: Documentation/networking/sctp.txt 5900F: Documentation/networking/sctp.txt
5900F: include/linux/sctp.h 5901F: include/linux/sctp.h
5901F: include/net/sctp/ 5902F: include/net/sctp/
@@ -6122,12 +6123,6 @@ W: http://www.winischhofer.at/linuxsisusbvga.shtml
6122S: Maintained 6123S: Maintained
6123F: drivers/usb/misc/sisusbvga/ 6124F: drivers/usb/misc/sisusbvga/
6124 6125
6125SKGE, SKY2 10/100/1000 GIGABIT ETHERNET DRIVERS
6126M: Stephen Hemminger <shemminger@vyatta.com>
6127L: netdev@vger.kernel.org
6128S: Maintained
6129F: drivers/net/ethernet/marvell/sk*
6130
6131SLAB ALLOCATOR 6126SLAB ALLOCATOR
6132M: Christoph Lameter <cl@linux-foundation.org> 6127M: Christoph Lameter <cl@linux-foundation.org>
6133M: Pekka Enberg <penberg@kernel.org> 6128M: Pekka Enberg <penberg@kernel.org>
@@ -6293,6 +6288,15 @@ F: drivers/tty/serial/sunsu.c
6293F: drivers/tty/serial/sunzilog.c 6288F: drivers/tty/serial/sunzilog.c
6294F: drivers/tty/serial/sunzilog.h 6289F: drivers/tty/serial/sunzilog.h
6295 6290
6291SPARSE CHECKER
6292M: "Christopher Li" <sparse@chrisli.org>
6293L: linux-sparse@vger.kernel.org
6294W: https://sparse.wiki.kernel.org/
6295T: git git://git.kernel.org/pub/scm/devel/sparse/sparse.git
6296T: git git://git.kernel.org/pub/scm/devel/sparse/chrisl/sparse.git
6297S: Maintained
6298F: include/linux/compiler.h
6299
6296SPEAR PLATFORM SUPPORT 6300SPEAR PLATFORM SUPPORT
6297M: Viresh Kumar <viresh.kumar@st.com> 6301M: Viresh Kumar <viresh.kumar@st.com>
6298L: spear-devel@list.st.com 6302L: spear-devel@list.st.com
@@ -6468,6 +6472,7 @@ S: Odd Fixes
6468F: drivers/staging/olpc_dcon/ 6472F: drivers/staging/olpc_dcon/
6469 6473
6470STAGING - OZMO DEVICES USB OVER WIFI DRIVER 6474STAGING - OZMO DEVICES USB OVER WIFI DRIVER
6475M: Rupesh Gujare <rgujare@ozmodevices.com>
6471M: Chris Kelly <ckelly@ozmodevices.com> 6476M: Chris Kelly <ckelly@ozmodevices.com>
6472S: Maintained 6477S: Maintained
6473F: drivers/staging/ozwpan/ 6478F: drivers/staging/ozwpan/
@@ -6665,6 +6670,12 @@ F: drivers/misc/tifm*
6665F: drivers/mmc/host/tifm_sd.c 6670F: drivers/mmc/host/tifm_sd.c
6666F: include/linux/tifm.h 6671F: include/linux/tifm.h
6667 6672
6673TI LM49xxx FAMILY ASoC CODEC DRIVERS
6674M: M R Swami Reddy <mr.swami.reddy@ti.com>
6675L: alsa-devel@alsa-project.org (moderated for non-subscribers)
6676S: Maintained
6677F: sound/soc/codecs/lm49453*
6678
6668TI TWL4030 SERIES SOC CODEC DRIVER 6679TI TWL4030 SERIES SOC CODEC DRIVER
6669M: Peter Ujfalusi <peter.ujfalusi@ti.com> 6680M: Peter Ujfalusi <peter.ujfalusi@ti.com>
6670L: alsa-devel@alsa-project.org (moderated for non-subscribers) 6681L: alsa-devel@alsa-project.org (moderated for non-subscribers)
@@ -7574,8 +7585,8 @@ F: Documentation/filesystems/xfs.txt
7574F: fs/xfs/ 7585F: fs/xfs/
7575 7586
7576XILINX AXI ETHERNET DRIVER 7587XILINX AXI ETHERNET DRIVER
7577M: Ariane Keller <ariane.keller@tik.ee.ethz.ch> 7588M: Anirudha Sarangi <anirudh@xilinx.com>
7578M: Daniel Borkmann <daniel.borkmann@tik.ee.ethz.ch> 7589M: John Linn <John.Linn@xilinx.com>
7579S: Maintained 7590S: Maintained
7580F: drivers/net/ethernet/xilinx/xilinx_axienet* 7591F: drivers/net/ethernet/xilinx/xilinx_axienet*
7581 7592
diff --git a/Makefile b/Makefile
index 5e637c23974e..48bd1f50dcc3 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
1VERSION = 3 1VERSION = 3
2PATCHLEVEL = 4 2PATCHLEVEL = 4
3SUBLEVEL = 0 3SUBLEVEL = 0
4EXTRAVERSION = -rc1 4EXTRAVERSION = -rc7
5NAME = Saber-toothed Squirrel 5NAME = Saber-toothed Squirrel
6 6
7# *DOCUMENTATION* 7# *DOCUMENTATION*
diff --git a/arch/alpha/Kconfig b/arch/alpha/Kconfig
index 56a4df952fb0..22e58a99f38b 100644
--- a/arch/alpha/Kconfig
+++ b/arch/alpha/Kconfig
@@ -477,7 +477,7 @@ config ALPHA_BROKEN_IRQ_MASK
477 477
478config VGA_HOSE 478config VGA_HOSE
479 bool 479 bool
480 depends on ALPHA_GENERIC || ALPHA_TITAN || ALPHA_MARVEL || ALPHA_TSUNAMI 480 depends on VGA_CONSOLE && (ALPHA_GENERIC || ALPHA_TITAN || ALPHA_MARVEL || ALPHA_TSUNAMI)
481 default y 481 default y
482 help 482 help
483 Support VGA on an arbitrary hose; needed for several platforms 483 Support VGA on an arbitrary hose; needed for several platforms
diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
index f62251e82ffa..3bb7ffeae3bc 100644
--- a/arch/alpha/include/asm/atomic.h
+++ b/arch/alpha/include/asm/atomic.h
@@ -3,6 +3,7 @@
3 3
4#include <linux/types.h> 4#include <linux/types.h>
5#include <asm/barrier.h> 5#include <asm/barrier.h>
6#include <asm/cmpxchg.h>
6 7
7/* 8/*
8 * Atomic operations that C can't guarantee us. Useful for 9 * Atomic operations that C can't guarantee us. Useful for
@@ -168,73 +169,6 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
168 return result; 169 return result;
169} 170}
170 171
171/*
172 * Atomic exchange routines.
173 */
174
175#define __ASM__MB
176#define ____xchg(type, args...) __xchg ## type ## _local(args)
177#define ____cmpxchg(type, args...) __cmpxchg ## type ## _local(args)
178#include <asm/xchg.h>
179
180#define xchg_local(ptr,x) \
181 ({ \
182 __typeof__(*(ptr)) _x_ = (x); \
183 (__typeof__(*(ptr))) __xchg_local((ptr), (unsigned long)_x_, \
184 sizeof(*(ptr))); \
185 })
186
187#define cmpxchg_local(ptr, o, n) \
188 ({ \
189 __typeof__(*(ptr)) _o_ = (o); \
190 __typeof__(*(ptr)) _n_ = (n); \
191 (__typeof__(*(ptr))) __cmpxchg_local((ptr), (unsigned long)_o_, \
192 (unsigned long)_n_, \
193 sizeof(*(ptr))); \
194 })
195
196#define cmpxchg64_local(ptr, o, n) \
197 ({ \
198 BUILD_BUG_ON(sizeof(*(ptr)) != 8); \
199 cmpxchg_local((ptr), (o), (n)); \
200 })
201
202#ifdef CONFIG_SMP
203#undef __ASM__MB
204#define __ASM__MB "\tmb\n"
205#endif
206#undef ____xchg
207#undef ____cmpxchg
208#define ____xchg(type, args...) __xchg ##type(args)
209#define ____cmpxchg(type, args...) __cmpxchg ##type(args)
210#include <asm/xchg.h>
211
212#define xchg(ptr,x) \
213 ({ \
214 __typeof__(*(ptr)) _x_ = (x); \
215 (__typeof__(*(ptr))) __xchg((ptr), (unsigned long)_x_, \
216 sizeof(*(ptr))); \
217 })
218
219#define cmpxchg(ptr, o, n) \
220 ({ \
221 __typeof__(*(ptr)) _o_ = (o); \
222 __typeof__(*(ptr)) _n_ = (n); \
223 (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \
224 (unsigned long)_n_, sizeof(*(ptr)));\
225 })
226
227#define cmpxchg64(ptr, o, n) \
228 ({ \
229 BUILD_BUG_ON(sizeof(*(ptr)) != 8); \
230 cmpxchg((ptr), (o), (n)); \
231 })
232
233#undef __ASM__MB
234#undef ____cmpxchg
235
236#define __HAVE_ARCH_CMPXCHG 1
237
238#define atomic64_cmpxchg(v, old, new) (cmpxchg(&((v)->counter), old, new)) 172#define atomic64_cmpxchg(v, old, new) (cmpxchg(&((v)->counter), old, new))
239#define atomic64_xchg(v, new) (xchg(&((v)->counter), new)) 173#define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
240 174
diff --git a/arch/alpha/include/asm/cmpxchg.h b/arch/alpha/include/asm/cmpxchg.h
new file mode 100644
index 000000000000..429e8cd0d78e
--- /dev/null
+++ b/arch/alpha/include/asm/cmpxchg.h
@@ -0,0 +1,71 @@
1#ifndef _ALPHA_CMPXCHG_H
2#define _ALPHA_CMPXCHG_H
3
4/*
5 * Atomic exchange routines.
6 */
7
8#define __ASM__MB
9#define ____xchg(type, args...) __xchg ## type ## _local(args)
10#define ____cmpxchg(type, args...) __cmpxchg ## type ## _local(args)
11#include <asm/xchg.h>
12
13#define xchg_local(ptr, x) \
14({ \
15 __typeof__(*(ptr)) _x_ = (x); \
16 (__typeof__(*(ptr))) __xchg_local((ptr), (unsigned long)_x_, \
17 sizeof(*(ptr))); \
18})
19
20#define cmpxchg_local(ptr, o, n) \
21({ \
22 __typeof__(*(ptr)) _o_ = (o); \
23 __typeof__(*(ptr)) _n_ = (n); \
24 (__typeof__(*(ptr))) __cmpxchg_local((ptr), (unsigned long)_o_, \
25 (unsigned long)_n_, \
26 sizeof(*(ptr))); \
27})
28
29#define cmpxchg64_local(ptr, o, n) \
30({ \
31 BUILD_BUG_ON(sizeof(*(ptr)) != 8); \
32 cmpxchg_local((ptr), (o), (n)); \
33})
34
35#ifdef CONFIG_SMP
36#undef __ASM__MB
37#define __ASM__MB "\tmb\n"
38#endif
39#undef ____xchg
40#undef ____cmpxchg
41#define ____xchg(type, args...) __xchg ##type(args)
42#define ____cmpxchg(type, args...) __cmpxchg ##type(args)
43#include <asm/xchg.h>
44
45#define xchg(ptr, x) \
46({ \
47 __typeof__(*(ptr)) _x_ = (x); \
48 (__typeof__(*(ptr))) __xchg((ptr), (unsigned long)_x_, \
49 sizeof(*(ptr))); \
50})
51
52#define cmpxchg(ptr, o, n) \
53({ \
54 __typeof__(*(ptr)) _o_ = (o); \
55 __typeof__(*(ptr)) _n_ = (n); \
56 (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \
57 (unsigned long)_n_, sizeof(*(ptr)));\
58})
59
60#define cmpxchg64(ptr, o, n) \
61({ \
62 BUILD_BUG_ON(sizeof(*(ptr)) != 8); \
63 cmpxchg((ptr), (o), (n)); \
64})
65
66#undef __ASM__MB
67#undef ____cmpxchg
68
69#define __HAVE_ARCH_CMPXCHG 1
70
71#endif /* _ALPHA_CMPXCHG_H */
diff --git a/arch/alpha/include/asm/dma-mapping.h b/arch/alpha/include/asm/dma-mapping.h
index 4567aca6fdd6..dfa32f061320 100644
--- a/arch/alpha/include/asm/dma-mapping.h
+++ b/arch/alpha/include/asm/dma-mapping.h
@@ -12,16 +12,22 @@ static inline struct dma_map_ops *get_dma_ops(struct device *dev)
12 12
13#include <asm-generic/dma-mapping-common.h> 13#include <asm-generic/dma-mapping-common.h>
14 14
15static inline void *dma_alloc_coherent(struct device *dev, size_t size, 15#define dma_alloc_coherent(d,s,h,f) dma_alloc_attrs(d,s,h,f,NULL)
16 dma_addr_t *dma_handle, gfp_t gfp) 16
17static inline void *dma_alloc_attrs(struct device *dev, size_t size,
18 dma_addr_t *dma_handle, gfp_t gfp,
19 struct dma_attrs *attrs)
17{ 20{
18 return get_dma_ops(dev)->alloc_coherent(dev, size, dma_handle, gfp); 21 return get_dma_ops(dev)->alloc(dev, size, dma_handle, gfp, attrs);
19} 22}
20 23
21static inline void dma_free_coherent(struct device *dev, size_t size, 24#define dma_free_coherent(d,s,c,h) dma_free_attrs(d,s,c,h,NULL)
22 void *vaddr, dma_addr_t dma_handle) 25
26static inline void dma_free_attrs(struct device *dev, size_t size,
27 void *vaddr, dma_addr_t dma_handle,
28 struct dma_attrs *attrs)
23{ 29{
24 get_dma_ops(dev)->free_coherent(dev, size, vaddr, dma_handle); 30 get_dma_ops(dev)->free(dev, size, vaddr, dma_handle, attrs);
25} 31}
26 32
27static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr) 33static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
diff --git a/arch/alpha/include/asm/rtc.h b/arch/alpha/include/asm/rtc.h
index 1f7fba671ae6..d70408d36677 100644
--- a/arch/alpha/include/asm/rtc.h
+++ b/arch/alpha/include/asm/rtc.h
@@ -1,14 +1,10 @@
1#ifndef _ALPHA_RTC_H 1#ifndef _ALPHA_RTC_H
2#define _ALPHA_RTC_H 2#define _ALPHA_RTC_H
3 3
4#if defined(CONFIG_ALPHA_GENERIC) 4#if defined(CONFIG_ALPHA_MARVEL) && defined(CONFIG_SMP) \
5 || defined(CONFIG_ALPHA_GENERIC)
5# define get_rtc_time alpha_mv.rtc_get_time 6# define get_rtc_time alpha_mv.rtc_get_time
6# define set_rtc_time alpha_mv.rtc_set_time 7# define set_rtc_time alpha_mv.rtc_set_time
7#else
8# if defined(CONFIG_ALPHA_MARVEL) && defined(CONFIG_SMP)
9# define get_rtc_time marvel_get_rtc_time
10# define set_rtc_time marvel_set_rtc_time
11# endif
12#endif 8#endif
13 9
14#include <asm-generic/rtc.h> 10#include <asm-generic/rtc.h>
diff --git a/arch/alpha/include/asm/xchg.h b/arch/alpha/include/asm/xchg.h
index 1d1b436fbff2..0ca9724597c1 100644
--- a/arch/alpha/include/asm/xchg.h
+++ b/arch/alpha/include/asm/xchg.h
@@ -1,10 +1,10 @@
1#ifndef _ALPHA_ATOMIC_H 1#ifndef _ALPHA_CMPXCHG_H
2#error Do not include xchg.h directly! 2#error Do not include xchg.h directly!
3#else 3#else
4/* 4/*
5 * xchg/xchg_local and cmpxchg/cmpxchg_local share the same code 5 * xchg/xchg_local and cmpxchg/cmpxchg_local share the same code
6 * except that local version do not have the expensive memory barrier. 6 * except that local version do not have the expensive memory barrier.
7 * So this file is included twice from asm/system.h. 7 * So this file is included twice from asm/cmpxchg.h.
8 */ 8 */
9 9
10/* 10/*
diff --git a/arch/alpha/kernel/core_tsunami.c b/arch/alpha/kernel/core_tsunami.c
index 5e7c28f92f19..61893d7bdda5 100644
--- a/arch/alpha/kernel/core_tsunami.c
+++ b/arch/alpha/kernel/core_tsunami.c
@@ -11,6 +11,7 @@
11#include <asm/core_tsunami.h> 11#include <asm/core_tsunami.h>
12#undef __EXTERN_INLINE 12#undef __EXTERN_INLINE
13 13
14#include <linux/module.h>
14#include <linux/types.h> 15#include <linux/types.h>
15#include <linux/pci.h> 16#include <linux/pci.h>
16#include <linux/sched.h> 17#include <linux/sched.h>
diff --git a/arch/alpha/kernel/pci-noop.c b/arch/alpha/kernel/pci-noop.c
index 04eea4894ef3..df24b76f9246 100644
--- a/arch/alpha/kernel/pci-noop.c
+++ b/arch/alpha/kernel/pci-noop.c
@@ -108,7 +108,8 @@ sys_pciconfig_write(unsigned long bus, unsigned long dfn,
108} 108}
109 109
110static void *alpha_noop_alloc_coherent(struct device *dev, size_t size, 110static void *alpha_noop_alloc_coherent(struct device *dev, size_t size,
111 dma_addr_t *dma_handle, gfp_t gfp) 111 dma_addr_t *dma_handle, gfp_t gfp,
112 struct dma_attrs *attrs)
112{ 113{
113 void *ret; 114 void *ret;
114 115
@@ -123,7 +124,8 @@ static void *alpha_noop_alloc_coherent(struct device *dev, size_t size,
123} 124}
124 125
125static void alpha_noop_free_coherent(struct device *dev, size_t size, 126static void alpha_noop_free_coherent(struct device *dev, size_t size,
126 void *cpu_addr, dma_addr_t dma_addr) 127 void *cpu_addr, dma_addr_t dma_addr,
128 struct dma_attrs *attrs)
127{ 129{
128 free_pages((unsigned long)cpu_addr, get_order(size)); 130 free_pages((unsigned long)cpu_addr, get_order(size));
129} 131}
@@ -174,8 +176,8 @@ static int alpha_noop_set_mask(struct device *dev, u64 mask)
174} 176}
175 177
176struct dma_map_ops alpha_noop_ops = { 178struct dma_map_ops alpha_noop_ops = {
177 .alloc_coherent = alpha_noop_alloc_coherent, 179 .alloc = alpha_noop_alloc_coherent,
178 .free_coherent = alpha_noop_free_coherent, 180 .free = alpha_noop_free_coherent,
179 .map_page = alpha_noop_map_page, 181 .map_page = alpha_noop_map_page,
180 .map_sg = alpha_noop_map_sg, 182 .map_sg = alpha_noop_map_sg,
181 .mapping_error = alpha_noop_mapping_error, 183 .mapping_error = alpha_noop_mapping_error,
diff --git a/arch/alpha/kernel/pci_iommu.c b/arch/alpha/kernel/pci_iommu.c
index 43610804987d..cd634795aa9c 100644
--- a/arch/alpha/kernel/pci_iommu.c
+++ b/arch/alpha/kernel/pci_iommu.c
@@ -434,7 +434,8 @@ static void alpha_pci_unmap_page(struct device *dev, dma_addr_t dma_addr,
434 else DMA_ADDRP is undefined. */ 434 else DMA_ADDRP is undefined. */
435 435
436static void *alpha_pci_alloc_coherent(struct device *dev, size_t size, 436static void *alpha_pci_alloc_coherent(struct device *dev, size_t size,
437 dma_addr_t *dma_addrp, gfp_t gfp) 437 dma_addr_t *dma_addrp, gfp_t gfp,
438 struct dma_attrs *attrs)
438{ 439{
439 struct pci_dev *pdev = alpha_gendev_to_pci(dev); 440 struct pci_dev *pdev = alpha_gendev_to_pci(dev);
440 void *cpu_addr; 441 void *cpu_addr;
@@ -478,7 +479,8 @@ try_again:
478 DMA_ADDR past this call are illegal. */ 479 DMA_ADDR past this call are illegal. */
479 480
480static void alpha_pci_free_coherent(struct device *dev, size_t size, 481static void alpha_pci_free_coherent(struct device *dev, size_t size,
481 void *cpu_addr, dma_addr_t dma_addr) 482 void *cpu_addr, dma_addr_t dma_addr,
483 struct dma_attrs *attrs)
482{ 484{
483 struct pci_dev *pdev = alpha_gendev_to_pci(dev); 485 struct pci_dev *pdev = alpha_gendev_to_pci(dev);
484 pci_unmap_single(pdev, dma_addr, size, PCI_DMA_BIDIRECTIONAL); 486 pci_unmap_single(pdev, dma_addr, size, PCI_DMA_BIDIRECTIONAL);
@@ -952,8 +954,8 @@ static int alpha_pci_set_mask(struct device *dev, u64 mask)
952} 954}
953 955
954struct dma_map_ops alpha_pci_ops = { 956struct dma_map_ops alpha_pci_ops = {
955 .alloc_coherent = alpha_pci_alloc_coherent, 957 .alloc = alpha_pci_alloc_coherent,
956 .free_coherent = alpha_pci_free_coherent, 958 .free = alpha_pci_free_coherent,
957 .map_page = alpha_pci_map_page, 959 .map_page = alpha_pci_map_page,
958 .unmap_page = alpha_pci_unmap_page, 960 .unmap_page = alpha_pci_unmap_page,
959 .map_sg = alpha_pci_map_sg, 961 .map_sg = alpha_pci_map_sg,
diff --git a/arch/alpha/kernel/signal.c b/arch/alpha/kernel/signal.c
index 6f7feb5db271..35f2ef44de12 100644
--- a/arch/alpha/kernel/signal.c
+++ b/arch/alpha/kernel/signal.c
@@ -120,12 +120,13 @@ SYSCALL_DEFINE5(rt_sigaction, int, sig, const struct sigaction __user *, act,
120 */ 120 */
121SYSCALL_DEFINE1(sigsuspend, old_sigset_t, mask) 121SYSCALL_DEFINE1(sigsuspend, old_sigset_t, mask)
122{ 122{
123 mask &= _BLOCKABLE; 123 sigset_t blocked;
124 spin_lock_irq(&current->sighand->siglock); 124
125 current->saved_sigmask = current->blocked; 125 current->saved_sigmask = current->blocked;
126 siginitset(&current->blocked, mask); 126
127 recalc_sigpending(); 127 mask &= _BLOCKABLE;
128 spin_unlock_irq(&current->sighand->siglock); 128 siginitset(&blocked, mask);
129 set_current_blocked(&blocked);
129 130
130 current->state = TASK_INTERRUPTIBLE; 131 current->state = TASK_INTERRUPTIBLE;
131 schedule(); 132 schedule();
@@ -238,10 +239,7 @@ do_sigreturn(struct sigcontext __user *sc, struct pt_regs *regs,
238 goto give_sigsegv; 239 goto give_sigsegv;
239 240
240 sigdelsetmask(&set, ~_BLOCKABLE); 241 sigdelsetmask(&set, ~_BLOCKABLE);
241 spin_lock_irq(&current->sighand->siglock); 242 set_current_blocked(&set);
242 current->blocked = set;
243 recalc_sigpending();
244 spin_unlock_irq(&current->sighand->siglock);
245 243
246 if (restore_sigcontext(sc, regs, sw)) 244 if (restore_sigcontext(sc, regs, sw))
247 goto give_sigsegv; 245 goto give_sigsegv;
@@ -276,10 +274,7 @@ do_rt_sigreturn(struct rt_sigframe __user *frame, struct pt_regs *regs,
276 goto give_sigsegv; 274 goto give_sigsegv;
277 275
278 sigdelsetmask(&set, ~_BLOCKABLE); 276 sigdelsetmask(&set, ~_BLOCKABLE);
279 spin_lock_irq(&current->sighand->siglock); 277 set_current_blocked(&set);
280 current->blocked = set;
281 recalc_sigpending();
282 spin_unlock_irq(&current->sighand->siglock);
283 278
284 if (restore_sigcontext(&frame->uc.uc_mcontext, regs, sw)) 279 if (restore_sigcontext(&frame->uc.uc_mcontext, regs, sw))
285 goto give_sigsegv; 280 goto give_sigsegv;
@@ -501,14 +496,8 @@ handle_signal(int sig, struct k_sigaction *ka, siginfo_t *info,
501 else 496 else
502 ret = setup_frame(sig, ka, oldset, regs, sw); 497 ret = setup_frame(sig, ka, oldset, regs, sw);
503 498
504 if (ret == 0) { 499 if (ret == 0)
505 spin_lock_irq(&current->sighand->siglock); 500 block_sigmask(ka, sig);
506 sigorsets(&current->blocked,&current->blocked,&ka->sa.sa_mask);
507 if (!(ka->sa.sa_flags & SA_NODEFER))
508 sigaddset(&current->blocked,sig);
509 recalc_sigpending();
510 spin_unlock_irq(&current->sighand->siglock);
511 }
512 501
513 return ret; 502 return ret;
514} 503}
diff --git a/arch/alpha/kernel/smp.c b/arch/alpha/kernel/smp.c
index 4087a569b43b..50d438db1f6b 100644
--- a/arch/alpha/kernel/smp.c
+++ b/arch/alpha/kernel/smp.c
@@ -450,7 +450,7 @@ setup_smp(void)
450 smp_num_probed = 1; 450 smp_num_probed = 1;
451 } 451 }
452 452
453 printk(KERN_INFO "SMP: %d CPUs probed -- cpu_present_map = %lx\n", 453 printk(KERN_INFO "SMP: %d CPUs probed -- cpu_present_mask = %lx\n",
454 smp_num_probed, cpumask_bits(cpu_present_mask)[0]); 454 smp_num_probed, cpumask_bits(cpu_present_mask)[0]);
455} 455}
456 456
diff --git a/arch/alpha/kernel/sys_marvel.c b/arch/alpha/kernel/sys_marvel.c
index 14a4b6a7cf59..407accc80877 100644
--- a/arch/alpha/kernel/sys_marvel.c
+++ b/arch/alpha/kernel/sys_marvel.c
@@ -317,7 +317,7 @@ marvel_init_irq(void)
317} 317}
318 318
319static int 319static int
320marvel_map_irq(const struct pci_dev *dev, u8 slot, u8 pin) 320marvel_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
321{ 321{
322 struct pci_controller *hose = dev->sysdata; 322 struct pci_controller *hose = dev->sysdata;
323 struct io7_port *io7_port = hose->sysdata; 323 struct io7_port *io7_port = hose->sysdata;
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 93180845ae16..36586dba6fa6 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -338,6 +338,7 @@ config ARCH_AT91
338 select HAVE_CLK 338 select HAVE_CLK
339 select CLKDEV_LOOKUP 339 select CLKDEV_LOOKUP
340 select IRQ_DOMAIN 340 select IRQ_DOMAIN
341 select NEED_MACH_IO_H if PCCARD
341 help 342 help
342 This enables support for systems based on the Atmel AT91RM9200, 343 This enables support for systems based on the Atmel AT91RM9200,
343 AT91SAM9 processors. 344 AT91SAM9 processors.
@@ -1185,6 +1186,15 @@ if !MMU
1185source "arch/arm/Kconfig-nommu" 1186source "arch/arm/Kconfig-nommu"
1186endif 1187endif
1187 1188
1189config ARM_ERRATA_326103
1190 bool "ARM errata: FSR write bit incorrect on a SWP to read-only memory"
1191 depends on CPU_V6
1192 help
1193 Executing a SWP instruction to read-only memory does not set bit 11
1194 of the FSR on the ARM 1136 prior to r1p0. This causes the kernel to
1195 treat the access as a read, preventing a COW from occurring and
1196 causing the faulting task to livelock.
1197
1188config ARM_ERRATA_411920 1198config ARM_ERRATA_411920
1189 bool "ARM errata: Invalidation of the Instruction Cache operation can fail" 1199 bool "ARM errata: Invalidation of the Instruction Cache operation can fail"
1190 depends on CPU_V6 || CPU_V6K 1200 depends on CPU_V6 || CPU_V6K
diff --git a/arch/arm/boot/compressed/atags_to_fdt.c b/arch/arm/boot/compressed/atags_to_fdt.c
index 6ce11c481178..797f04bedb47 100644
--- a/arch/arm/boot/compressed/atags_to_fdt.c
+++ b/arch/arm/boot/compressed/atags_to_fdt.c
@@ -77,6 +77,8 @@ int atags_to_fdt(void *atag_list, void *fdt, int total_space)
77 } else if (atag->hdr.tag == ATAG_MEM) { 77 } else if (atag->hdr.tag == ATAG_MEM) {
78 if (memcount >= sizeof(mem_reg_property)/4) 78 if (memcount >= sizeof(mem_reg_property)/4)
79 continue; 79 continue;
80 if (!atag->u.mem.size)
81 continue;
80 mem_reg_property[memcount++] = cpu_to_fdt32(atag->u.mem.start); 82 mem_reg_property[memcount++] = cpu_to_fdt32(atag->u.mem.start);
81 mem_reg_property[memcount++] = cpu_to_fdt32(atag->u.mem.size); 83 mem_reg_property[memcount++] = cpu_to_fdt32(atag->u.mem.size);
82 } else if (atag->hdr.tag == ATAG_INITRD2) { 84 } else if (atag->hdr.tag == ATAG_INITRD2) {
diff --git a/arch/arm/boot/compressed/head.S b/arch/arm/boot/compressed/head.S
index 5f6045f1766c..dc7e8ce8e6be 100644
--- a/arch/arm/boot/compressed/head.S
+++ b/arch/arm/boot/compressed/head.S
@@ -273,7 +273,7 @@ restart: adr r0, LC0
273 add r0, r0, #0x100 273 add r0, r0, #0x100
274 mov r1, r6 274 mov r1, r6
275 sub r2, sp, r6 275 sub r2, sp, r6
276 blne atags_to_fdt 276 bleq atags_to_fdt
277 277
278 ldmfd sp!, {r0-r3, ip, lr} 278 ldmfd sp!, {r0-r3, ip, lr}
279 sub sp, sp, #0x10000 279 sub sp, sp, #0x10000
diff --git a/arch/arm/boot/dts/at91sam9g20.dtsi b/arch/arm/boot/dts/at91sam9g20.dtsi
index 92f36627e7f8..773ef484037a 100644
--- a/arch/arm/boot/dts/at91sam9g20.dtsi
+++ b/arch/arm/boot/dts/at91sam9g20.dtsi
@@ -35,7 +35,7 @@
35 }; 35 };
36 }; 36 };
37 37
38 memory@20000000 { 38 memory {
39 reg = <0x20000000 0x08000000>; 39 reg = <0x20000000 0x08000000>;
40 }; 40 };
41 41
@@ -55,7 +55,6 @@
55 #interrupt-cells = <2>; 55 #interrupt-cells = <2>;
56 compatible = "atmel,at91rm9200-aic"; 56 compatible = "atmel,at91rm9200-aic";
57 interrupt-controller; 57 interrupt-controller;
58 interrupt-parent;
59 reg = <0xfffff000 0x200>; 58 reg = <0xfffff000 0x200>;
60 }; 59 };
61 60
diff --git a/arch/arm/boot/dts/at91sam9g25ek.dts b/arch/arm/boot/dts/at91sam9g25ek.dts
index ac0dc0031dda..7829a4d0cb22 100644
--- a/arch/arm/boot/dts/at91sam9g25ek.dts
+++ b/arch/arm/boot/dts/at91sam9g25ek.dts
@@ -37,8 +37,8 @@
37 usb0: ohci@00600000 { 37 usb0: ohci@00600000 {
38 status = "okay"; 38 status = "okay";
39 num-ports = <2>; 39 num-ports = <2>;
40 atmel,vbus-gpio = <&pioD 19 0 40 atmel,vbus-gpio = <&pioD 19 1
41 &pioD 20 0 41 &pioD 20 1
42 >; 42 >;
43 }; 43 };
44 44
diff --git a/arch/arm/boot/dts/at91sam9g45.dtsi b/arch/arm/boot/dts/at91sam9g45.dtsi
index 3d0c32fb218f..c8042147eaa2 100644
--- a/arch/arm/boot/dts/at91sam9g45.dtsi
+++ b/arch/arm/boot/dts/at91sam9g45.dtsi
@@ -36,7 +36,7 @@
36 }; 36 };
37 }; 37 };
38 38
39 memory@70000000 { 39 memory {
40 reg = <0x70000000 0x10000000>; 40 reg = <0x70000000 0x10000000>;
41 }; 41 };
42 42
@@ -56,7 +56,6 @@
56 #interrupt-cells = <2>; 56 #interrupt-cells = <2>;
57 compatible = "atmel,at91rm9200-aic"; 57 compatible = "atmel,at91rm9200-aic";
58 interrupt-controller; 58 interrupt-controller;
59 interrupt-parent;
60 reg = <0xfffff000 0x200>; 59 reg = <0xfffff000 0x200>;
61 }; 60 };
62 61
diff --git a/arch/arm/boot/dts/at91sam9m10g45ek.dts b/arch/arm/boot/dts/at91sam9m10g45ek.dts
index c4c8ae4123d5..a3633bd13111 100644
--- a/arch/arm/boot/dts/at91sam9m10g45ek.dts
+++ b/arch/arm/boot/dts/at91sam9m10g45ek.dts
@@ -17,7 +17,7 @@
17 bootargs = "mem=64M console=ttyS0,115200 root=/dev/mtdblock1 rw rootfstype=jffs2"; 17 bootargs = "mem=64M console=ttyS0,115200 root=/dev/mtdblock1 rw rootfstype=jffs2";
18 }; 18 };
19 19
20 memory@70000000 { 20 memory {
21 reg = <0x70000000 0x4000000>; 21 reg = <0x70000000 0x4000000>;
22 }; 22 };
23 23
@@ -73,8 +73,8 @@
73 usb0: ohci@00700000 { 73 usb0: ohci@00700000 {
74 status = "okay"; 74 status = "okay";
75 num-ports = <2>; 75 num-ports = <2>;
76 atmel,vbus-gpio = <&pioD 1 0 76 atmel,vbus-gpio = <&pioD 1 1
77 &pioD 3 0>; 77 &pioD 3 1>;
78 }; 78 };
79 79
80 usb1: ehci@00800000 { 80 usb1: ehci@00800000 {
diff --git a/arch/arm/boot/dts/at91sam9x5.dtsi b/arch/arm/boot/dts/at91sam9x5.dtsi
index c111001f254e..dd4ed748469a 100644
--- a/arch/arm/boot/dts/at91sam9x5.dtsi
+++ b/arch/arm/boot/dts/at91sam9x5.dtsi
@@ -34,7 +34,7 @@
34 }; 34 };
35 }; 35 };
36 36
37 memory@20000000 { 37 memory {
38 reg = <0x20000000 0x10000000>; 38 reg = <0x20000000 0x10000000>;
39 }; 39 };
40 40
@@ -54,7 +54,6 @@
54 #interrupt-cells = <2>; 54 #interrupt-cells = <2>;
55 compatible = "atmel,at91rm9200-aic"; 55 compatible = "atmel,at91rm9200-aic";
56 interrupt-controller; 56 interrupt-controller;
57 interrupt-parent;
58 reg = <0xfffff000 0x200>; 57 reg = <0xfffff000 0x200>;
59 }; 58 };
60 59
@@ -201,8 +200,8 @@
201 >; 200 >;
202 atmel,nand-addr-offset = <21>; 201 atmel,nand-addr-offset = <21>;
203 atmel,nand-cmd-offset = <22>; 202 atmel,nand-cmd-offset = <22>;
204 gpios = <&pioC 8 0 203 gpios = <&pioD 5 0
205 &pioC 14 0 204 &pioD 4 0
206 0 205 0
207 >; 206 >;
208 status = "disabled"; 207 status = "disabled";
diff --git a/arch/arm/boot/dts/at91sam9x5cm.dtsi b/arch/arm/boot/dts/at91sam9x5cm.dtsi
index 67936f83c694..31e7be23703d 100644
--- a/arch/arm/boot/dts/at91sam9x5cm.dtsi
+++ b/arch/arm/boot/dts/at91sam9x5cm.dtsi
@@ -8,7 +8,7 @@
8 */ 8 */
9 9
10/ { 10/ {
11 memory@20000000 { 11 memory {
12 reg = <0x20000000 0x8000000>; 12 reg = <0x20000000 0x8000000>;
13 }; 13 };
14 14
diff --git a/arch/arm/boot/dts/db8500.dtsi b/arch/arm/boot/dts/db8500.dtsi
index d73dce645667..14bc30705099 100644
--- a/arch/arm/boot/dts/db8500.dtsi
+++ b/arch/arm/boot/dts/db8500.dtsi
@@ -24,7 +24,6 @@
24 #interrupt-cells = <3>; 24 #interrupt-cells = <3>;
25 #address-cells = <1>; 25 #address-cells = <1>;
26 interrupt-controller; 26 interrupt-controller;
27 interrupt-parent;
28 reg = <0xa0411000 0x1000>, 27 reg = <0xa0411000 0x1000>,
29 <0xa0410100 0x100>; 28 <0xa0410100 0x100>;
30 }; 29 };
diff --git a/arch/arm/boot/dts/highbank.dts b/arch/arm/boot/dts/highbank.dts
index 37c0ff9c8b90..83e72294aefb 100644
--- a/arch/arm/boot/dts/highbank.dts
+++ b/arch/arm/boot/dts/highbank.dts
@@ -89,7 +89,6 @@
89 #size-cells = <0>; 89 #size-cells = <0>;
90 #address-cells = <1>; 90 #address-cells = <1>;
91 interrupt-controller; 91 interrupt-controller;
92 interrupt-parent;
93 reg = <0xfff11000 0x1000>, 92 reg = <0xfff11000 0x1000>,
94 <0xfff10100 0x100>; 93 <0xfff10100 0x100>;
95 }; 94 };
diff --git a/arch/arm/boot/dts/msm8660-surf.dts b/arch/arm/boot/dts/msm8660-surf.dts
index 15ded0deaa79..45bc4bb04e57 100644
--- a/arch/arm/boot/dts/msm8660-surf.dts
+++ b/arch/arm/boot/dts/msm8660-surf.dts
@@ -10,7 +10,7 @@
10 intc: interrupt-controller@02080000 { 10 intc: interrupt-controller@02080000 {
11 compatible = "qcom,msm-8660-qgic"; 11 compatible = "qcom,msm-8660-qgic";
12 interrupt-controller; 12 interrupt-controller;
13 #interrupt-cells = <1>; 13 #interrupt-cells = <3>;
14 reg = < 0x02080000 0x1000 >, 14 reg = < 0x02080000 0x1000 >,
15 < 0x02081000 0x1000 >; 15 < 0x02081000 0x1000 >;
16 }; 16 };
@@ -19,6 +19,6 @@
19 compatible = "qcom,msm-hsuart", "qcom,msm-uart"; 19 compatible = "qcom,msm-hsuart", "qcom,msm-uart";
20 reg = <0x19c40000 0x1000>, 20 reg = <0x19c40000 0x1000>,
21 <0x19c00000 0x1000>; 21 <0x19c00000 0x1000>;
22 interrupts = <195>; 22 interrupts = <0 195 0x0>;
23 }; 23 };
24}; 24};
diff --git a/arch/arm/boot/dts/usb_a9g20.dts b/arch/arm/boot/dts/usb_a9g20.dts
index 3b3c4e0fa79f..7c2399c532e5 100644
--- a/arch/arm/boot/dts/usb_a9g20.dts
+++ b/arch/arm/boot/dts/usb_a9g20.dts
@@ -16,7 +16,7 @@
16 bootargs = "mem=64M console=ttyS0,115200 root=/dev/mtdblock5 rw rootfstype=ubifs"; 16 bootargs = "mem=64M console=ttyS0,115200 root=/dev/mtdblock5 rw rootfstype=ubifs";
17 }; 17 };
18 18
19 memory@20000000 { 19 memory {
20 reg = <0x20000000 0x4000000>; 20 reg = <0x20000000 0x4000000>;
21 }; 21 };
22 22
diff --git a/arch/arm/boot/dts/versatile-ab.dts b/arch/arm/boot/dts/versatile-ab.dts
index 0b32925f2147..e2fe3195c0d1 100644
--- a/arch/arm/boot/dts/versatile-ab.dts
+++ b/arch/arm/boot/dts/versatile-ab.dts
@@ -173,7 +173,7 @@
173 mmc@5000 { 173 mmc@5000 {
174 compatible = "arm,primecell"; 174 compatible = "arm,primecell";
175 reg = < 0x5000 0x1000>; 175 reg = < 0x5000 0x1000>;
176 interrupts = <22>; 176 interrupts = <22 34>;
177 }; 177 };
178 kmi@6000 { 178 kmi@6000 {
179 compatible = "arm,pl050", "arm,primecell"; 179 compatible = "arm,pl050", "arm,primecell";
diff --git a/arch/arm/boot/dts/versatile-pb.dts b/arch/arm/boot/dts/versatile-pb.dts
index 166461073b78..7e8175269064 100644
--- a/arch/arm/boot/dts/versatile-pb.dts
+++ b/arch/arm/boot/dts/versatile-pb.dts
@@ -41,7 +41,7 @@
41 mmc@b000 { 41 mmc@b000 {
42 compatible = "arm,primecell"; 42 compatible = "arm,primecell";
43 reg = <0xb000 0x1000>; 43 reg = <0xb000 0x1000>;
44 interrupts = <23>; 44 interrupts = <23 34>;
45 }; 45 };
46 }; 46 };
47 }; 47 };
diff --git a/arch/arm/common/vic.c b/arch/arm/common/vic.c
index 7a66311f3066..7e288f96cedf 100644
--- a/arch/arm/common/vic.c
+++ b/arch/arm/common/vic.c
@@ -427,19 +427,18 @@ int __init vic_of_init(struct device_node *node, struct device_node *parent)
427 427
428/* 428/*
429 * Handle each interrupt in a single VIC. Returns non-zero if we've 429 * Handle each interrupt in a single VIC. Returns non-zero if we've
430 * handled at least one interrupt. This does a single read of the 430 * handled at least one interrupt. This reads the status register
431 * status register and handles all interrupts in order from LSB first. 431 * before handling each interrupt, which is necessary given that
432 * handle_IRQ may briefly re-enable interrupts for soft IRQ handling.
432 */ 433 */
433static int handle_one_vic(struct vic_device *vic, struct pt_regs *regs) 434static int handle_one_vic(struct vic_device *vic, struct pt_regs *regs)
434{ 435{
435 u32 stat, irq; 436 u32 stat, irq;
436 int handled = 0; 437 int handled = 0;
437 438
438 stat = readl_relaxed(vic->base + VIC_IRQ_STATUS); 439 while ((stat = readl_relaxed(vic->base + VIC_IRQ_STATUS))) {
439 while (stat) {
440 irq = ffs(stat) - 1; 440 irq = ffs(stat) - 1;
441 handle_IRQ(irq_find_mapping(vic->domain, irq), regs); 441 handle_IRQ(irq_find_mapping(vic->domain, irq), regs);
442 stat &= ~(1 << irq);
443 handled = 1; 442 handled = 1;
444 } 443 }
445 444
diff --git a/arch/arm/configs/imx_v4_v5_defconfig b/arch/arm/configs/imx_v4_v5_defconfig
index b5ac644e12af..6b31cb60daab 100644
--- a/arch/arm/configs/imx_v4_v5_defconfig
+++ b/arch/arm/configs/imx_v4_v5_defconfig
@@ -112,6 +112,7 @@ CONFIG_WATCHDOG=y
112CONFIG_IMX2_WDT=y 112CONFIG_IMX2_WDT=y
113CONFIG_MFD_MC13XXX=y 113CONFIG_MFD_MC13XXX=y
114CONFIG_REGULATOR=y 114CONFIG_REGULATOR=y
115CONFIG_REGULATOR_FIXED_VOLTAGE=y
115CONFIG_REGULATOR_MC13783=y 116CONFIG_REGULATOR_MC13783=y
116CONFIG_REGULATOR_MC13892=y 117CONFIG_REGULATOR_MC13892=y
117CONFIG_FB=y 118CONFIG_FB=y
diff --git a/arch/arm/configs/mini2440_defconfig b/arch/arm/configs/mini2440_defconfig
index 42da9183acc8..082175c54e7c 100644
--- a/arch/arm/configs/mini2440_defconfig
+++ b/arch/arm/configs/mini2440_defconfig
@@ -14,6 +14,8 @@ CONFIG_MODULE_FORCE_UNLOAD=y
14# CONFIG_BLK_DEV_BSG is not set 14# CONFIG_BLK_DEV_BSG is not set
15CONFIG_BLK_DEV_INTEGRITY=y 15CONFIG_BLK_DEV_INTEGRITY=y
16CONFIG_ARCH_S3C24XX=y 16CONFIG_ARCH_S3C24XX=y
17# CONFIG_CPU_S3C2410 is not set
18CONFIG_CPU_S3C2440=y
17CONFIG_S3C_ADC=y 19CONFIG_S3C_ADC=y
18CONFIG_S3C24XX_PWM=y 20CONFIG_S3C24XX_PWM=y
19CONFIG_MACH_MINI2440=y 21CONFIG_MACH_MINI2440=y
diff --git a/arch/arm/configs/u8500_defconfig b/arch/arm/configs/u8500_defconfig
index 889d73ac1ae1..7e84f453e8a6 100644
--- a/arch/arm/configs/u8500_defconfig
+++ b/arch/arm/configs/u8500_defconfig
@@ -8,8 +8,6 @@ CONFIG_MODULE_UNLOAD=y
8# CONFIG_LBDAF is not set 8# CONFIG_LBDAF is not set
9# CONFIG_BLK_DEV_BSG is not set 9# CONFIG_BLK_DEV_BSG is not set
10CONFIG_ARCH_U8500=y 10CONFIG_ARCH_U8500=y
11CONFIG_UX500_SOC_DB5500=y
12CONFIG_UX500_SOC_DB8500=y
13CONFIG_MACH_HREFV60=y 11CONFIG_MACH_HREFV60=y
14CONFIG_MACH_SNOWBALL=y 12CONFIG_MACH_SNOWBALL=y
15CONFIG_MACH_U5500=y 13CONFIG_MACH_U5500=y
@@ -39,7 +37,6 @@ CONFIG_CAIF=y
39CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug" 37CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
40CONFIG_BLK_DEV_RAM=y 38CONFIG_BLK_DEV_RAM=y
41CONFIG_BLK_DEV_RAM_SIZE=65536 39CONFIG_BLK_DEV_RAM_SIZE=65536
42CONFIG_MISC_DEVICES=y
43CONFIG_AB8500_PWM=y 40CONFIG_AB8500_PWM=y
44CONFIG_SENSORS_BH1780=y 41CONFIG_SENSORS_BH1780=y
45CONFIG_NETDEVICES=y 42CONFIG_NETDEVICES=y
@@ -65,16 +62,18 @@ CONFIG_SERIAL_AMBA_PL011=y
65CONFIG_SERIAL_AMBA_PL011_CONSOLE=y 62CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
66CONFIG_HW_RANDOM=y 63CONFIG_HW_RANDOM=y
67CONFIG_HW_RANDOM_NOMADIK=y 64CONFIG_HW_RANDOM_NOMADIK=y
68CONFIG_I2C=y
69CONFIG_I2C_NOMADIK=y
70CONFIG_SPI=y 65CONFIG_SPI=y
71CONFIG_SPI_PL022=y 66CONFIG_SPI_PL022=y
72CONFIG_GPIO_STMPE=y 67CONFIG_GPIO_STMPE=y
73CONFIG_GPIO_TC3589X=y 68CONFIG_GPIO_TC3589X=y
69CONFIG_POWER_SUPPLY=y
70CONFIG_AB8500_BM=y
71CONFIG_AB8500_BATTERY_THERM_ON_BATCTRL=y
74CONFIG_MFD_STMPE=y 72CONFIG_MFD_STMPE=y
75CONFIG_MFD_TC3589X=y 73CONFIG_MFD_TC3589X=y
76CONFIG_AB5500_CORE=y 74CONFIG_AB5500_CORE=y
77CONFIG_AB8500_CORE=y 75CONFIG_AB8500_CORE=y
76CONFIG_REGULATOR=y
78CONFIG_REGULATOR_AB8500=y 77CONFIG_REGULATOR_AB8500=y
79# CONFIG_HID_SUPPORT is not set 78# CONFIG_HID_SUPPORT is not set
80CONFIG_USB_GADGET=y 79CONFIG_USB_GADGET=y
diff --git a/arch/arm/include/asm/barrier.h b/arch/arm/include/asm/barrier.h
index 44f4a09ff37b..05112380dc53 100644
--- a/arch/arm/include/asm/barrier.h
+++ b/arch/arm/include/asm/barrier.h
@@ -2,6 +2,7 @@
2#define __ASM_BARRIER_H 2#define __ASM_BARRIER_H
3 3
4#ifndef __ASSEMBLY__ 4#ifndef __ASSEMBLY__
5#include <asm/outercache.h>
5 6
6#define nop() __asm__ __volatile__("mov\tr0,r0\t@ nop\n\t"); 7#define nop() __asm__ __volatile__("mov\tr0,r0\t@ nop\n\t");
7 8
@@ -39,7 +40,6 @@
39#ifdef CONFIG_ARCH_HAS_BARRIERS 40#ifdef CONFIG_ARCH_HAS_BARRIERS
40#include <mach/barriers.h> 41#include <mach/barriers.h>
41#elif defined(CONFIG_ARM_DMA_MEM_BUFFERABLE) || defined(CONFIG_SMP) 42#elif defined(CONFIG_ARM_DMA_MEM_BUFFERABLE) || defined(CONFIG_SMP)
42#include <asm/outercache.h>
43#define mb() do { dsb(); outer_sync(); } while (0) 43#define mb() do { dsb(); outer_sync(); } while (0)
44#define rmb() dsb() 44#define rmb() dsb()
45#define wmb() mb() 45#define wmb() mb()
diff --git a/arch/arm/include/asm/io.h b/arch/arm/include/asm/io.h
index df0ac0bb39aa..9af5563dd3eb 100644
--- a/arch/arm/include/asm/io.h
+++ b/arch/arm/include/asm/io.h
@@ -119,7 +119,7 @@ static inline void __iomem *__typesafe_io(unsigned long addr)
119#ifdef CONFIG_NEED_MACH_IO_H 119#ifdef CONFIG_NEED_MACH_IO_H
120#include <mach/io.h> 120#include <mach/io.h>
121#else 121#else
122#define __io(a) ({ (void)(a); __typesafe_io(0); }) 122#define __io(a) __typesafe_io((a) & IO_SPACE_LIMIT)
123#endif 123#endif
124 124
125/* 125/*
diff --git a/arch/arm/include/asm/jump_label.h b/arch/arm/include/asm/jump_label.h
index 5c5ca2ea62b0..bfc198c75913 100644
--- a/arch/arm/include/asm/jump_label.h
+++ b/arch/arm/include/asm/jump_label.h
@@ -14,7 +14,7 @@
14#define JUMP_LABEL_NOP "nop" 14#define JUMP_LABEL_NOP "nop"
15#endif 15#endif
16 16
17static __always_inline bool arch_static_branch(struct jump_label_key *key) 17static __always_inline bool arch_static_branch(struct static_key *key)
18{ 18{
19 asm goto("1:\n\t" 19 asm goto("1:\n\t"
20 JUMP_LABEL_NOP "\n\t" 20 JUMP_LABEL_NOP "\n\t"
diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
index d4c24d412a8d..0f04d84582e1 100644
--- a/arch/arm/include/asm/thread_info.h
+++ b/arch/arm/include/asm/thread_info.h
@@ -118,6 +118,13 @@ extern void iwmmxt_task_switch(struct thread_info *);
118extern void vfp_sync_hwstate(struct thread_info *); 118extern void vfp_sync_hwstate(struct thread_info *);
119extern void vfp_flush_hwstate(struct thread_info *); 119extern void vfp_flush_hwstate(struct thread_info *);
120 120
121struct user_vfp;
122struct user_vfp_exc;
123
124extern int vfp_preserve_user_clear_hwstate(struct user_vfp __user *,
125 struct user_vfp_exc __user *);
126extern int vfp_restore_user_hwstate(struct user_vfp __user *,
127 struct user_vfp_exc __user *);
121#endif 128#endif
122 129
123/* 130/*
diff --git a/arch/arm/include/asm/tls.h b/arch/arm/include/asm/tls.h
index 60843eb0f61c..73409e6c0251 100644
--- a/arch/arm/include/asm/tls.h
+++ b/arch/arm/include/asm/tls.h
@@ -7,6 +7,8 @@
7 7
8 .macro set_tls_v6k, tp, tmp1, tmp2 8 .macro set_tls_v6k, tp, tmp1, tmp2
9 mcr p15, 0, \tp, c13, c0, 3 @ set TLS register 9 mcr p15, 0, \tp, c13, c0, 3 @ set TLS register
10 mov \tmp1, #0
11 mcr p15, 0, \tmp1, c13, c0, 2 @ clear user r/w TLS register
10 .endm 12 .endm
11 13
12 .macro set_tls_v6, tp, tmp1, tmp2 14 .macro set_tls_v6, tp, tmp1, tmp2
@@ -15,6 +17,8 @@
15 mov \tmp2, #0xffff0fff 17 mov \tmp2, #0xffff0fff
16 tst \tmp1, #HWCAP_TLS @ hardware TLS available? 18 tst \tmp1, #HWCAP_TLS @ hardware TLS available?
17 mcrne p15, 0, \tp, c13, c0, 3 @ yes, set TLS register 19 mcrne p15, 0, \tp, c13, c0, 3 @ yes, set TLS register
20 movne \tmp1, #0
21 mcrne p15, 0, \tmp1, c13, c0, 2 @ clear user r/w TLS register
18 streq \tp, [\tmp2, #-15] @ set TLS value at 0xffff0ff0 22 streq \tp, [\tmp2, #-15] @ set TLS value at 0xffff0ff0
19 .endm 23 .endm
20 24
diff --git a/arch/arm/kernel/bios32.c b/arch/arm/kernel/bios32.c
index 632df9a66f8c..ede5f7741c42 100644
--- a/arch/arm/kernel/bios32.c
+++ b/arch/arm/kernel/bios32.c
@@ -299,7 +299,6 @@ static inline int pdev_bad_for_parity(struct pci_dev *dev)
299 */ 299 */
300void pcibios_fixup_bus(struct pci_bus *bus) 300void pcibios_fixup_bus(struct pci_bus *bus)
301{ 301{
302 struct pci_sys_data *root = bus->sysdata;
303 struct pci_dev *dev; 302 struct pci_dev *dev;
304 u16 features = PCI_COMMAND_SERR | PCI_COMMAND_PARITY | PCI_COMMAND_FAST_BACK; 303 u16 features = PCI_COMMAND_SERR | PCI_COMMAND_PARITY | PCI_COMMAND_FAST_BACK;
305 304
diff --git a/arch/arm/kernel/insn.c b/arch/arm/kernel/insn.c
index ab312e516546..b760340b7014 100644
--- a/arch/arm/kernel/insn.c
+++ b/arch/arm/kernel/insn.c
@@ -1,3 +1,4 @@
1#include <linux/bug.h>
1#include <linux/kernel.h> 2#include <linux/kernel.h>
2#include <asm/opcodes.h> 3#include <asm/opcodes.h>
3 4
diff --git a/arch/arm/kernel/irq.c b/arch/arm/kernel/irq.c
index 71ccdbfed662..8349d4e97e2b 100644
--- a/arch/arm/kernel/irq.c
+++ b/arch/arm/kernel/irq.c
@@ -155,10 +155,10 @@ static bool migrate_one_irq(struct irq_desc *desc)
155 } 155 }
156 156
157 c = irq_data_get_irq_chip(d); 157 c = irq_data_get_irq_chip(d);
158 if (c->irq_set_affinity) 158 if (!c->irq_set_affinity)
159 c->irq_set_affinity(d, affinity, true);
160 else
161 pr_debug("IRQ%u: unable to set affinity\n", d->irq); 159 pr_debug("IRQ%u: unable to set affinity\n", d->irq);
160 else if (c->irq_set_affinity(d, affinity, true) == IRQ_SET_MASK_OK && ret)
161 cpumask_copy(d->affinity, affinity);
162 162
163 return ret; 163 return ret;
164} 164}
diff --git a/arch/arm/kernel/kprobes.c b/arch/arm/kernel/kprobes.c
index ab1869dac97a..4dd41fc9e235 100644
--- a/arch/arm/kernel/kprobes.c
+++ b/arch/arm/kernel/kprobes.c
@@ -152,7 +152,7 @@ int __kprobes __arch_disarm_kprobe(void *p)
152 152
153void __kprobes arch_disarm_kprobe(struct kprobe *p) 153void __kprobes arch_disarm_kprobe(struct kprobe *p)
154{ 154{
155 stop_machine(__arch_disarm_kprobe, p, &cpu_online_map); 155 stop_machine(__arch_disarm_kprobe, p, cpu_online_mask);
156} 156}
157 157
158void __kprobes arch_remove_kprobe(struct kprobe *p) 158void __kprobes arch_remove_kprobe(struct kprobe *p)
diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
index 45956c9d0ef0..9650c143afc1 100644
--- a/arch/arm/kernel/ptrace.c
+++ b/arch/arm/kernel/ptrace.c
@@ -256,7 +256,7 @@ static int ptrace_read_user(struct task_struct *tsk, unsigned long off,
256{ 256{
257 unsigned long tmp; 257 unsigned long tmp;
258 258
259 if (off & 3 || off >= sizeof(struct user)) 259 if (off & 3)
260 return -EIO; 260 return -EIO;
261 261
262 tmp = 0; 262 tmp = 0;
@@ -268,6 +268,8 @@ static int ptrace_read_user(struct task_struct *tsk, unsigned long off,
268 tmp = tsk->mm->end_code; 268 tmp = tsk->mm->end_code;
269 else if (off < sizeof(struct pt_regs)) 269 else if (off < sizeof(struct pt_regs))
270 tmp = get_user_reg(tsk, off >> 2); 270 tmp = get_user_reg(tsk, off >> 2);
271 else if (off >= sizeof(struct user))
272 return -EIO;
271 273
272 return put_user(tmp, ret); 274 return put_user(tmp, ret);
273} 275}
@@ -904,27 +906,14 @@ long arch_ptrace(struct task_struct *child, long request,
904 return ret; 906 return ret;
905} 907}
906 908
907#ifdef __ARMEB__
908#define AUDIT_ARCH_NR AUDIT_ARCH_ARMEB
909#else
910#define AUDIT_ARCH_NR AUDIT_ARCH_ARM
911#endif
912
913asmlinkage int syscall_trace(int why, struct pt_regs *regs, int scno) 909asmlinkage int syscall_trace(int why, struct pt_regs *regs, int scno)
914{ 910{
915 unsigned long ip; 911 unsigned long ip;
916 912
917 /* 913 if (why)
918 * Save IP. IP is used to denote syscall entry/exit:
919 * IP = 0 -> entry, = 1 -> exit
920 */
921 ip = regs->ARM_ip;
922 regs->ARM_ip = why;
923
924 if (!ip)
925 audit_syscall_exit(regs); 914 audit_syscall_exit(regs);
926 else 915 else
927 audit_syscall_entry(AUDIT_ARCH_NR, scno, regs->ARM_r0, 916 audit_syscall_entry(AUDIT_ARCH_ARM, scno, regs->ARM_r0,
928 regs->ARM_r1, regs->ARM_r2, regs->ARM_r3); 917 regs->ARM_r1, regs->ARM_r2, regs->ARM_r3);
929 918
930 if (!test_thread_flag(TIF_SYSCALL_TRACE)) 919 if (!test_thread_flag(TIF_SYSCALL_TRACE))
@@ -934,6 +923,13 @@ asmlinkage int syscall_trace(int why, struct pt_regs *regs, int scno)
934 923
935 current_thread_info()->syscall = scno; 924 current_thread_info()->syscall = scno;
936 925
926 /*
927 * IP is used to denote syscall entry/exit:
928 * IP = 0 -> entry, =1 -> exit
929 */
930 ip = regs->ARM_ip;
931 regs->ARM_ip = why;
932
937 /* the 0x80 provides a way for the tracing parent to distinguish 933 /* the 0x80 provides a way for the tracing parent to distinguish
938 between a syscall stop and SIGTRAP delivery */ 934 between a syscall stop and SIGTRAP delivery */
939 ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD) 935 ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
index b91411371ae1..ebfac782593f 100644
--- a/arch/arm/kernel/setup.c
+++ b/arch/arm/kernel/setup.c
@@ -523,7 +523,21 @@ int __init arm_add_memory(phys_addr_t start, unsigned long size)
523 */ 523 */
524 size -= start & ~PAGE_MASK; 524 size -= start & ~PAGE_MASK;
525 bank->start = PAGE_ALIGN(start); 525 bank->start = PAGE_ALIGN(start);
526 bank->size = size & PAGE_MASK; 526
527#ifndef CONFIG_LPAE
528 if (bank->start + size < bank->start) {
529 printk(KERN_CRIT "Truncating memory at 0x%08llx to fit in "
530 "32-bit physical address space\n", (long long)start);
531 /*
532 * To ensure bank->start + bank->size is representable in
533 * 32 bits, we use ULONG_MAX as the upper limit rather than 4GB.
534 * This means we lose a page after masking.
535 */
536 size = ULONG_MAX - bank->start;
537 }
538#endif
539
540 bank->size = size & PAGE_MASK;
527 541
528 /* 542 /*
529 * Check whether this memory region has non-zero size or 543 * Check whether this memory region has non-zero size or
diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
index 7cb532fc8aa4..d68d1b694680 100644
--- a/arch/arm/kernel/signal.c
+++ b/arch/arm/kernel/signal.c
@@ -180,44 +180,23 @@ static int restore_iwmmxt_context(struct iwmmxt_sigframe *frame)
180 180
181static int preserve_vfp_context(struct vfp_sigframe __user *frame) 181static int preserve_vfp_context(struct vfp_sigframe __user *frame)
182{ 182{
183 struct thread_info *thread = current_thread_info();
184 struct vfp_hard_struct *h = &thread->vfpstate.hard;
185 const unsigned long magic = VFP_MAGIC; 183 const unsigned long magic = VFP_MAGIC;
186 const unsigned long size = VFP_STORAGE_SIZE; 184 const unsigned long size = VFP_STORAGE_SIZE;
187 int err = 0; 185 int err = 0;
188 186
189 vfp_sync_hwstate(thread);
190 __put_user_error(magic, &frame->magic, err); 187 __put_user_error(magic, &frame->magic, err);
191 __put_user_error(size, &frame->size, err); 188 __put_user_error(size, &frame->size, err);
192 189
193 /* 190 if (err)
194 * Copy the floating point registers. There can be unused 191 return -EFAULT;
195 * registers see asm/hwcap.h for details.
196 */
197 err |= __copy_to_user(&frame->ufp.fpregs, &h->fpregs,
198 sizeof(h->fpregs));
199 /*
200 * Copy the status and control register.
201 */
202 __put_user_error(h->fpscr, &frame->ufp.fpscr, err);
203
204 /*
205 * Copy the exception registers.
206 */
207 __put_user_error(h->fpexc, &frame->ufp_exc.fpexc, err);
208 __put_user_error(h->fpinst, &frame->ufp_exc.fpinst, err);
209 __put_user_error(h->fpinst2, &frame->ufp_exc.fpinst2, err);
210 192
211 return err ? -EFAULT : 0; 193 return vfp_preserve_user_clear_hwstate(&frame->ufp, &frame->ufp_exc);
212} 194}
213 195
214static int restore_vfp_context(struct vfp_sigframe __user *frame) 196static int restore_vfp_context(struct vfp_sigframe __user *frame)
215{ 197{
216 struct thread_info *thread = current_thread_info();
217 struct vfp_hard_struct *h = &thread->vfpstate.hard;
218 unsigned long magic; 198 unsigned long magic;
219 unsigned long size; 199 unsigned long size;
220 unsigned long fpexc;
221 int err = 0; 200 int err = 0;
222 201
223 __get_user_error(magic, &frame->magic, err); 202 __get_user_error(magic, &frame->magic, err);
@@ -228,33 +207,7 @@ static int restore_vfp_context(struct vfp_sigframe __user *frame)
228 if (magic != VFP_MAGIC || size != VFP_STORAGE_SIZE) 207 if (magic != VFP_MAGIC || size != VFP_STORAGE_SIZE)
229 return -EINVAL; 208 return -EINVAL;
230 209
231 vfp_flush_hwstate(thread); 210 return vfp_restore_user_hwstate(&frame->ufp, &frame->ufp_exc);
232
233 /*
234 * Copy the floating point registers. There can be unused
235 * registers see asm/hwcap.h for details.
236 */
237 err |= __copy_from_user(&h->fpregs, &frame->ufp.fpregs,
238 sizeof(h->fpregs));
239 /*
240 * Copy the status and control register.
241 */
242 __get_user_error(h->fpscr, &frame->ufp.fpscr, err);
243
244 /*
245 * Sanitise and restore the exception registers.
246 */
247 __get_user_error(fpexc, &frame->ufp_exc.fpexc, err);
248 /* Ensure the VFP is enabled. */
249 fpexc |= FPEXC_EN;
250 /* Ensure FPINST2 is invalid and the exception flag is cleared. */
251 fpexc &= ~(FPEXC_EX | FPEXC_FP2V);
252 h->fpexc = fpexc;
253
254 __get_user_error(h->fpinst, &frame->ufp_exc.fpinst, err);
255 __get_user_error(h->fpinst2, &frame->ufp_exc.fpinst2, err);
256
257 return err ? -EFAULT : 0;
258} 211}
259 212
260#endif 213#endif
diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
index 2cee7d1eb958..8f4644659777 100644
--- a/arch/arm/kernel/smp.c
+++ b/arch/arm/kernel/smp.c
@@ -251,8 +251,6 @@ asmlinkage void __cpuinit secondary_start_kernel(void)
251 struct mm_struct *mm = &init_mm; 251 struct mm_struct *mm = &init_mm;
252 unsigned int cpu = smp_processor_id(); 252 unsigned int cpu = smp_processor_id();
253 253
254 printk("CPU%u: Booted secondary processor\n", cpu);
255
256 /* 254 /*
257 * All kernel threads share the same mm context; grab a 255 * All kernel threads share the same mm context; grab a
258 * reference and switch to it. 256 * reference and switch to it.
@@ -264,6 +262,8 @@ asmlinkage void __cpuinit secondary_start_kernel(void)
264 enter_lazy_tlb(mm, current); 262 enter_lazy_tlb(mm, current);
265 local_flush_tlb_all(); 263 local_flush_tlb_all();
266 264
265 printk("CPU%u: Booted secondary processor\n", cpu);
266
267 cpu_init(); 267 cpu_init();
268 preempt_disable(); 268 preempt_disable();
269 trace_hardirqs_off(); 269 trace_hardirqs_off();
@@ -349,7 +349,7 @@ void __init smp_prepare_cpus(unsigned int max_cpus)
349 * re-initialize the map in platform_smp_prepare_cpus() if 349 * re-initialize the map in platform_smp_prepare_cpus() if
350 * present != possible (e.g. physical hotplug). 350 * present != possible (e.g. physical hotplug).
351 */ 351 */
352 init_cpu_present(&cpu_possible_map); 352 init_cpu_present(cpu_possible_mask);
353 353
354 /* 354 /*
355 * Initialise the SCU if there are more than one CPU 355 * Initialise the SCU if there are more than one CPU
@@ -510,10 +510,6 @@ static void ipi_cpu_stop(unsigned int cpu)
510 local_fiq_disable(); 510 local_fiq_disable();
511 local_irq_disable(); 511 local_irq_disable();
512 512
513#ifdef CONFIG_HOTPLUG_CPU
514 platform_cpu_kill(cpu);
515#endif
516
517 while (1) 513 while (1)
518 cpu_relax(); 514 cpu_relax();
519} 515}
@@ -576,16 +572,25 @@ void smp_send_reschedule(int cpu)
576 smp_cross_call(cpumask_of(cpu), IPI_RESCHEDULE); 572 smp_cross_call(cpumask_of(cpu), IPI_RESCHEDULE);
577} 573}
578 574
575#ifdef CONFIG_HOTPLUG_CPU
576static void smp_kill_cpus(cpumask_t *mask)
577{
578 unsigned int cpu;
579 for_each_cpu(cpu, mask)
580 platform_cpu_kill(cpu);
581}
582#else
583static void smp_kill_cpus(cpumask_t *mask) { }
584#endif
585
579void smp_send_stop(void) 586void smp_send_stop(void)
580{ 587{
581 unsigned long timeout; 588 unsigned long timeout;
589 struct cpumask mask;
582 590
583 if (num_online_cpus() > 1) { 591 cpumask_copy(&mask, cpu_online_mask);
584 cpumask_t mask = cpu_online_map; 592 cpumask_clear_cpu(smp_processor_id(), &mask);
585 cpu_clear(smp_processor_id(), mask); 593 smp_cross_call(&mask, IPI_CPU_STOP);
586
587 smp_cross_call(&mask, IPI_CPU_STOP);
588 }
589 594
590 /* Wait up to one second for other CPUs to stop */ 595 /* Wait up to one second for other CPUs to stop */
591 timeout = USEC_PER_SEC; 596 timeout = USEC_PER_SEC;
@@ -594,6 +599,8 @@ void smp_send_stop(void)
594 599
595 if (num_online_cpus() > 1) 600 if (num_online_cpus() > 1)
596 pr_warning("SMP: failed to stop secondary CPUs\n"); 601 pr_warning("SMP: failed to stop secondary CPUs\n");
602
603 smp_kill_cpus(&mask);
597} 604}
598 605
599/* 606/*
diff --git a/arch/arm/kernel/sys_arm.c b/arch/arm/kernel/sys_arm.c
index d2b177905cdb..76cbb055dd05 100644
--- a/arch/arm/kernel/sys_arm.c
+++ b/arch/arm/kernel/sys_arm.c
@@ -115,7 +115,7 @@ int kernel_execve(const char *filename,
115 "Ir" (THREAD_START_SP - sizeof(regs)), 115 "Ir" (THREAD_START_SP - sizeof(regs)),
116 "r" (&regs), 116 "r" (&regs),
117 "Ir" (sizeof(regs)) 117 "Ir" (sizeof(regs))
118 : "r0", "r1", "r2", "r3", "ip", "lr", "memory"); 118 : "r0", "r1", "r2", "r3", "r8", "r9", "ip", "lr", "memory");
119 119
120 out: 120 out:
121 return ret; 121 return ret;
diff --git a/arch/arm/mach-at91/at91rm9200_devices.c b/arch/arm/mach-at91/at91rm9200_devices.c
index 99ce5c955e39..05774e5b1cba 100644
--- a/arch/arm/mach-at91/at91rm9200_devices.c
+++ b/arch/arm/mach-at91/at91rm9200_devices.c
@@ -1173,7 +1173,6 @@ void __init at91_add_device_serial(void)
1173 printk(KERN_INFO "AT91: No default serial console defined.\n"); 1173 printk(KERN_INFO "AT91: No default serial console defined.\n");
1174} 1174}
1175#else 1175#else
1176void __init __deprecated at91_init_serial(struct at91_uart_config *config) {}
1177void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {} 1176void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}
1178void __init at91_set_serial_console(unsigned portnr) {} 1177void __init at91_set_serial_console(unsigned portnr) {}
1179void __init at91_add_device_serial(void) {} 1178void __init at91_add_device_serial(void) {}
diff --git a/arch/arm/mach-at91/at91rm9200_time.c b/arch/arm/mach-at91/at91rm9200_time.c
index dd7f782b0b91..104ca40d8d18 100644
--- a/arch/arm/mach-at91/at91rm9200_time.c
+++ b/arch/arm/mach-at91/at91rm9200_time.c
@@ -23,6 +23,7 @@
23#include <linux/interrupt.h> 23#include <linux/interrupt.h>
24#include <linux/irq.h> 24#include <linux/irq.h>
25#include <linux/clockchips.h> 25#include <linux/clockchips.h>
26#include <linux/export.h>
26 27
27#include <asm/mach/time.h> 28#include <asm/mach/time.h>
28 29
@@ -176,6 +177,7 @@ static struct clock_event_device clkevt = {
176}; 177};
177 178
178void __iomem *at91_st_base; 179void __iomem *at91_st_base;
180EXPORT_SYMBOL_GPL(at91_st_base);
179 181
180void __init at91rm9200_ioremap_st(u32 addr) 182void __init at91rm9200_ioremap_st(u32 addr)
181{ 183{
diff --git a/arch/arm/mach-at91/at91sam9260_devices.c b/arch/arm/mach-at91/at91sam9260_devices.c
index 7e5651ee9f85..5652dde4bbe2 100644
--- a/arch/arm/mach-at91/at91sam9260_devices.c
+++ b/arch/arm/mach-at91/at91sam9260_devices.c
@@ -598,6 +598,9 @@ void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
598 else 598 else
599 cs_pin = spi1_standard_cs[devices[i].chip_select]; 599 cs_pin = spi1_standard_cs[devices[i].chip_select];
600 600
601 if (!gpio_is_valid(cs_pin))
602 continue;
603
601 if (devices[i].bus_num == 0) 604 if (devices[i].bus_num == 0)
602 enable_spi0 = 1; 605 enable_spi0 = 1;
603 else 606 else
diff --git a/arch/arm/mach-at91/at91sam9261_devices.c b/arch/arm/mach-at91/at91sam9261_devices.c
index 096da87dc00d..4db961a93085 100644
--- a/arch/arm/mach-at91/at91sam9261_devices.c
+++ b/arch/arm/mach-at91/at91sam9261_devices.c
@@ -415,6 +415,9 @@ void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
415 else 415 else
416 cs_pin = spi1_standard_cs[devices[i].chip_select]; 416 cs_pin = spi1_standard_cs[devices[i].chip_select];
417 417
418 if (!gpio_is_valid(cs_pin))
419 continue;
420
418 if (devices[i].bus_num == 0) 421 if (devices[i].bus_num == 0)
419 enable_spi0 = 1; 422 enable_spi0 = 1;
420 else 423 else
diff --git a/arch/arm/mach-at91/at91sam9263_devices.c b/arch/arm/mach-at91/at91sam9263_devices.c
index 53688c46f956..fe99206de880 100644
--- a/arch/arm/mach-at91/at91sam9263_devices.c
+++ b/arch/arm/mach-at91/at91sam9263_devices.c
@@ -72,7 +72,8 @@ void __init at91_add_device_usbh(struct at91_usbh_data *data)
72 /* Enable VBus control for UHP ports */ 72 /* Enable VBus control for UHP ports */
73 for (i = 0; i < data->ports; i++) { 73 for (i = 0; i < data->ports; i++) {
74 if (gpio_is_valid(data->vbus_pin[i])) 74 if (gpio_is_valid(data->vbus_pin[i]))
75 at91_set_gpio_output(data->vbus_pin[i], 0); 75 at91_set_gpio_output(data->vbus_pin[i],
76 data->vbus_pin_active_low[i]);
76 } 77 }
77 78
78 /* Enable overcurrent notification */ 79 /* Enable overcurrent notification */
@@ -671,6 +672,9 @@ void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
671 else 672 else
672 cs_pin = spi1_standard_cs[devices[i].chip_select]; 673 cs_pin = spi1_standard_cs[devices[i].chip_select];
673 674
675 if (!gpio_is_valid(cs_pin))
676 continue;
677
674 if (devices[i].bus_num == 0) 678 if (devices[i].bus_num == 0)
675 enable_spi0 = 1; 679 enable_spi0 = 1;
676 else 680 else
diff --git a/arch/arm/mach-at91/at91sam9g45_devices.c b/arch/arm/mach-at91/at91sam9g45_devices.c
index 698479f1e197..6b008aee1dff 100644
--- a/arch/arm/mach-at91/at91sam9g45_devices.c
+++ b/arch/arm/mach-at91/at91sam9g45_devices.c
@@ -127,12 +127,13 @@ void __init at91_add_device_usbh_ohci(struct at91_usbh_data *data)
127 /* Enable VBus control for UHP ports */ 127 /* Enable VBus control for UHP ports */
128 for (i = 0; i < data->ports; i++) { 128 for (i = 0; i < data->ports; i++) {
129 if (gpio_is_valid(data->vbus_pin[i])) 129 if (gpio_is_valid(data->vbus_pin[i]))
130 at91_set_gpio_output(data->vbus_pin[i], 0); 130 at91_set_gpio_output(data->vbus_pin[i],
131 data->vbus_pin_active_low[i]);
131 } 132 }
132 133
133 /* Enable overcurrent notification */ 134 /* Enable overcurrent notification */
134 for (i = 0; i < data->ports; i++) { 135 for (i = 0; i < data->ports; i++) {
135 if (data->overcurrent_pin[i]) 136 if (gpio_is_valid(data->overcurrent_pin[i]))
136 at91_set_gpio_input(data->overcurrent_pin[i], 1); 137 at91_set_gpio_input(data->overcurrent_pin[i], 1);
137 } 138 }
138 139
@@ -188,7 +189,8 @@ void __init at91_add_device_usbh_ehci(struct at91_usbh_data *data)
188 /* Enable VBus control for UHP ports */ 189 /* Enable VBus control for UHP ports */
189 for (i = 0; i < data->ports; i++) { 190 for (i = 0; i < data->ports; i++) {
190 if (gpio_is_valid(data->vbus_pin[i])) 191 if (gpio_is_valid(data->vbus_pin[i]))
191 at91_set_gpio_output(data->vbus_pin[i], 0); 192 at91_set_gpio_output(data->vbus_pin[i],
193 data->vbus_pin_active_low[i]);
192 } 194 }
193 195
194 usbh_ehci_data = *data; 196 usbh_ehci_data = *data;
@@ -785,6 +787,9 @@ void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
785 else 787 else
786 cs_pin = spi1_standard_cs[devices[i].chip_select]; 788 cs_pin = spi1_standard_cs[devices[i].chip_select];
787 789
790 if (!gpio_is_valid(cs_pin))
791 continue;
792
788 if (devices[i].bus_num == 0) 793 if (devices[i].bus_num == 0)
789 enable_spi0 = 1; 794 enable_spi0 = 1;
790 else 795 else
diff --git a/arch/arm/mach-at91/at91sam9rl_devices.c b/arch/arm/mach-at91/at91sam9rl_devices.c
index eda72e83037d..fe4ae22e8561 100644
--- a/arch/arm/mach-at91/at91sam9rl_devices.c
+++ b/arch/arm/mach-at91/at91sam9rl_devices.c
@@ -419,6 +419,9 @@ void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
419 else 419 else
420 cs_pin = spi_standard_cs[devices[i].chip_select]; 420 cs_pin = spi_standard_cs[devices[i].chip_select];
421 421
422 if (!gpio_is_valid(cs_pin))
423 continue;
424
422 /* enable chip-select pin */ 425 /* enable chip-select pin */
423 at91_set_gpio_output(cs_pin, 1); 426 at91_set_gpio_output(cs_pin, 1);
424 427
diff --git a/arch/arm/mach-at91/at91sam9x5.c b/arch/arm/mach-at91/at91sam9x5.c
index b6831eeb7b76..13c8cae60462 100644
--- a/arch/arm/mach-at91/at91sam9x5.c
+++ b/arch/arm/mach-at91/at91sam9x5.c
@@ -223,6 +223,8 @@ static struct clk_lookup periph_clocks_lookups[] = {
223 CLKDEV_CON_DEV_ID("usart", "f8028000.serial", &usart3_clk), 223 CLKDEV_CON_DEV_ID("usart", "f8028000.serial", &usart3_clk),
224 CLKDEV_CON_DEV_ID("t0_clk", "f8008000.timer", &tcb0_clk), 224 CLKDEV_CON_DEV_ID("t0_clk", "f8008000.timer", &tcb0_clk),
225 CLKDEV_CON_DEV_ID("t0_clk", "f800c000.timer", &tcb0_clk), 225 CLKDEV_CON_DEV_ID("t0_clk", "f800c000.timer", &tcb0_clk),
226 CLKDEV_CON_DEV_ID("dma_clk", "ffffec00.dma-controller", &dma0_clk),
227 CLKDEV_CON_DEV_ID("dma_clk", "ffffee00.dma-controller", &dma1_clk),
226 CLKDEV_CON_ID("pioA", &pioAB_clk), 228 CLKDEV_CON_ID("pioA", &pioAB_clk),
227 CLKDEV_CON_ID("pioB", &pioAB_clk), 229 CLKDEV_CON_ID("pioB", &pioAB_clk),
228 CLKDEV_CON_ID("pioC", &pioCD_clk), 230 CLKDEV_CON_ID("pioC", &pioCD_clk),
diff --git a/arch/arm/mach-at91/board-rm9200ek.c b/arch/arm/mach-at91/board-rm9200ek.c
index 11cbaa8946fe..b2e4fe21f346 100644
--- a/arch/arm/mach-at91/board-rm9200ek.c
+++ b/arch/arm/mach-at91/board-rm9200ek.c
@@ -117,7 +117,7 @@ static struct i2c_board_info __initdata ek_i2c_devices[] = {
117}; 117};
118 118
119#define EK_FLASH_BASE AT91_CHIPSELECT_0 119#define EK_FLASH_BASE AT91_CHIPSELECT_0
120#define EK_FLASH_SIZE SZ_2M 120#define EK_FLASH_SIZE SZ_8M
121 121
122static struct physmap_flash_data ek_flash_data = { 122static struct physmap_flash_data ek_flash_data = {
123 .width = 2, 123 .width = 2,
diff --git a/arch/arm/mach-at91/board-sam9261ek.c b/arch/arm/mach-at91/board-sam9261ek.c
index c3f994462864..065fed342424 100644
--- a/arch/arm/mach-at91/board-sam9261ek.c
+++ b/arch/arm/mach-at91/board-sam9261ek.c
@@ -85,8 +85,6 @@ static struct resource dm9000_resource[] = {
85 .flags = IORESOURCE_MEM 85 .flags = IORESOURCE_MEM
86 }, 86 },
87 [2] = { 87 [2] = {
88 .start = AT91_PIN_PC11,
89 .end = AT91_PIN_PC11,
90 .flags = IORESOURCE_IRQ 88 .flags = IORESOURCE_IRQ
91 | IORESOURCE_IRQ_LOWEDGE | IORESOURCE_IRQ_HIGHEDGE, 89 | IORESOURCE_IRQ_LOWEDGE | IORESOURCE_IRQ_HIGHEDGE,
92 } 90 }
@@ -130,6 +128,8 @@ static struct sam9_smc_config __initdata dm9000_smc_config = {
130 128
131static void __init ek_add_device_dm9000(void) 129static void __init ek_add_device_dm9000(void)
132{ 130{
131 struct resource *r = &dm9000_resource[2];
132
133 /* Configure chip-select 2 (DM9000) */ 133 /* Configure chip-select 2 (DM9000) */
134 sam9_smc_configure(0, 2, &dm9000_smc_config); 134 sam9_smc_configure(0, 2, &dm9000_smc_config);
135 135
@@ -139,6 +139,7 @@ static void __init ek_add_device_dm9000(void)
139 /* Configure Interrupt pin as input, no pull-up */ 139 /* Configure Interrupt pin as input, no pull-up */
140 at91_set_gpio_input(AT91_PIN_PC11, 0); 140 at91_set_gpio_input(AT91_PIN_PC11, 0);
141 141
142 r->start = r->end = gpio_to_irq(AT91_PIN_PC11);
142 platform_device_register(&dm9000_device); 143 platform_device_register(&dm9000_device);
143} 144}
144#else 145#else
diff --git a/arch/arm/mach-at91/board-sam9263ek.c b/arch/arm/mach-at91/board-sam9263ek.c
index 66f0ddf4b2ae..2ffe50f3a9e9 100644
--- a/arch/arm/mach-at91/board-sam9263ek.c
+++ b/arch/arm/mach-at91/board-sam9263ek.c
@@ -74,6 +74,7 @@ static void __init ek_init_early(void)
74static struct at91_usbh_data __initdata ek_usbh_data = { 74static struct at91_usbh_data __initdata ek_usbh_data = {
75 .ports = 2, 75 .ports = 2,
76 .vbus_pin = { AT91_PIN_PA24, AT91_PIN_PA21 }, 76 .vbus_pin = { AT91_PIN_PA24, AT91_PIN_PA21 },
77 .vbus_pin_active_low = {1, 1},
77 .overcurrent_pin= {-EINVAL, -EINVAL}, 78 .overcurrent_pin= {-EINVAL, -EINVAL},
78}; 79};
79 80
diff --git a/arch/arm/mach-at91/board-sam9m10g45ek.c b/arch/arm/mach-at91/board-sam9m10g45ek.c
index e1bea73e6b30..c88e908ddd82 100644
--- a/arch/arm/mach-at91/board-sam9m10g45ek.c
+++ b/arch/arm/mach-at91/board-sam9m10g45ek.c
@@ -71,6 +71,7 @@ static void __init ek_init_early(void)
71static struct at91_usbh_data __initdata ek_usbh_hs_data = { 71static struct at91_usbh_data __initdata ek_usbh_hs_data = {
72 .ports = 2, 72 .ports = 2,
73 .vbus_pin = {AT91_PIN_PD1, AT91_PIN_PD3}, 73 .vbus_pin = {AT91_PIN_PD1, AT91_PIN_PD3},
74 .vbus_pin_active_low = {1, 1},
74 .overcurrent_pin= {-EINVAL, -EINVAL}, 75 .overcurrent_pin= {-EINVAL, -EINVAL},
75}; 76};
76 77
diff --git a/arch/arm/mach-at91/clock.c b/arch/arm/mach-at91/clock.c
index a0f4d7424cdc..6b692824c988 100644
--- a/arch/arm/mach-at91/clock.c
+++ b/arch/arm/mach-at91/clock.c
@@ -35,6 +35,7 @@
35#include "generic.h" 35#include "generic.h"
36 36
37void __iomem *at91_pmc_base; 37void __iomem *at91_pmc_base;
38EXPORT_SYMBOL_GPL(at91_pmc_base);
38 39
39/* 40/*
40 * There's a lot more which can be done with clocks, including cpufreq 41 * There's a lot more which can be done with clocks, including cpufreq
diff --git a/arch/arm/mach-at91/include/mach/at91_pmc.h b/arch/arm/mach-at91/include/mach/at91_pmc.h
index 36604782a78f..ea2c57a86ca6 100644
--- a/arch/arm/mach-at91/include/mach/at91_pmc.h
+++ b/arch/arm/mach-at91/include/mach/at91_pmc.h
@@ -25,7 +25,7 @@ extern void __iomem *at91_pmc_base;
25#define at91_pmc_write(field, value) \ 25#define at91_pmc_write(field, value) \
26 __raw_writel(value, at91_pmc_base + field) 26 __raw_writel(value, at91_pmc_base + field)
27#else 27#else
28.extern at91_aic_base 28.extern at91_pmc_base
29#endif 29#endif
30 30
31#define AT91_PMC_SCER 0x00 /* System Clock Enable Register */ 31#define AT91_PMC_SCER 0x00 /* System Clock Enable Register */
diff --git a/arch/arm/mach-at91/include/mach/board.h b/arch/arm/mach-at91/include/mach/board.h
index 544a5d5ce416..49a821192c65 100644
--- a/arch/arm/mach-at91/include/mach/board.h
+++ b/arch/arm/mach-at91/include/mach/board.h
@@ -86,14 +86,15 @@ extern void __init at91_add_device_mci(short mmc_id, struct mci_platform_data *d
86extern void __init at91_add_device_eth(struct macb_platform_data *data); 86extern void __init at91_add_device_eth(struct macb_platform_data *data);
87 87
88 /* USB Host */ 88 /* USB Host */
89#define AT91_MAX_USBH_PORTS 3
89struct at91_usbh_data { 90struct at91_usbh_data {
90 u8 ports; /* number of ports on root hub */ 91 int vbus_pin[AT91_MAX_USBH_PORTS]; /* port power-control pin */
91 int vbus_pin[2]; /* port power-control pin */ 92 int overcurrent_pin[AT91_MAX_USBH_PORTS];
92 u8 vbus_pin_active_low[2]; 93 u8 ports; /* number of ports on root hub */
93 u8 overcurrent_supported; 94 u8 overcurrent_supported;
94 int overcurrent_pin[2]; 95 u8 vbus_pin_active_low[AT91_MAX_USBH_PORTS];
95 u8 overcurrent_status[2]; 96 u8 overcurrent_status[AT91_MAX_USBH_PORTS];
96 u8 overcurrent_changed[2]; 97 u8 overcurrent_changed[AT91_MAX_USBH_PORTS];
97}; 98};
98extern void __init at91_add_device_usbh(struct at91_usbh_data *data); 99extern void __init at91_add_device_usbh(struct at91_usbh_data *data);
99extern void __init at91_add_device_usbh_ohci(struct at91_usbh_data *data); 100extern void __init at91_add_device_usbh_ohci(struct at91_usbh_data *data);
diff --git a/arch/arm/mach-at91/include/mach/io.h b/arch/arm/mach-at91/include/mach/io.h
new file mode 100644
index 000000000000..2d9ca0455745
--- /dev/null
+++ b/arch/arm/mach-at91/include/mach/io.h
@@ -0,0 +1,27 @@
1/*
2 * arch/arm/mach-at91/include/mach/io.h
3 *
4 * Copyright (C) 2003 SAN People
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#ifndef __ASM_ARCH_IO_H
22#define __ASM_ARCH_IO_H
23
24#define IO_SPACE_LIMIT 0xFFFFFFFF
25#define __io(a) __typesafe_io(a)
26
27#endif
diff --git a/arch/arm/mach-at91/setup.c b/arch/arm/mach-at91/setup.c
index 97cc04dc8073..f44a2e7272e3 100644
--- a/arch/arm/mach-at91/setup.c
+++ b/arch/arm/mach-at91/setup.c
@@ -54,6 +54,7 @@ void __init at91_init_interrupts(unsigned int *priority)
54} 54}
55 55
56void __iomem *at91_ramc_base[2]; 56void __iomem *at91_ramc_base[2];
57EXPORT_SYMBOL_GPL(at91_ramc_base);
57 58
58void __init at91_ioremap_ramc(int id, u32 addr, u32 size) 59void __init at91_ioremap_ramc(int id, u32 addr, u32 size)
59{ 60{
@@ -292,6 +293,7 @@ void __init at91_ioremap_rstc(u32 base_addr)
292} 293}
293 294
294void __iomem *at91_matrix_base; 295void __iomem *at91_matrix_base;
296EXPORT_SYMBOL_GPL(at91_matrix_base);
295 297
296void __init at91_ioremap_matrix(u32 base_addr) 298void __init at91_ioremap_matrix(u32 base_addr)
297{ 299{
diff --git a/arch/arm/mach-bcmring/core.c b/arch/arm/mach-bcmring/core.c
index 22e4e0a28ad1..adbfb1994582 100644
--- a/arch/arm/mach-bcmring/core.c
+++ b/arch/arm/mach-bcmring/core.c
@@ -52,8 +52,8 @@
52#include <mach/csp/chipcHw_inline.h> 52#include <mach/csp/chipcHw_inline.h>
53#include <mach/csp/tmrHw_reg.h> 53#include <mach/csp/tmrHw_reg.h>
54 54
55static AMBA_APB_DEVICE(uartA, "uarta", MM_ADDR_IO_UARTA, { IRQ_UARTA }, NULL); 55static AMBA_APB_DEVICE(uartA, "uartA", 0, MM_ADDR_IO_UARTA, {IRQ_UARTA}, NULL);
56static AMBA_APB_DEVICE(uartB, "uartb", MM_ADDR_IO_UARTB, { IRQ_UARTB }, NULL); 56static AMBA_APB_DEVICE(uartB, "uartB", 0, MM_ADDR_IO_UARTB, {IRQ_UARTB}, NULL);
57 57
58static struct clk pll1_clk = { 58static struct clk pll1_clk = {
59 .name = "PLL1", 59 .name = "PLL1",
diff --git a/arch/arm/mach-exynos/Kconfig b/arch/arm/mach-exynos/Kconfig
index 0491ceef1cda..b8df521fb68e 100644
--- a/arch/arm/mach-exynos/Kconfig
+++ b/arch/arm/mach-exynos/Kconfig
@@ -232,6 +232,9 @@ config MACH_ARMLEX4210
232config MACH_UNIVERSAL_C210 232config MACH_UNIVERSAL_C210
233 bool "Mobile UNIVERSAL_C210 Board" 233 bool "Mobile UNIVERSAL_C210 Board"
234 select CPU_EXYNOS4210 234 select CPU_EXYNOS4210
235 select S5P_HRT
236 select CLKSRC_MMIO
237 select HAVE_SCHED_CLOCK
235 select S5P_GPIO_INT 238 select S5P_GPIO_INT
236 select S5P_DEV_FIMC0 239 select S5P_DEV_FIMC0
237 select S5P_DEV_FIMC1 240 select S5P_DEV_FIMC1
@@ -368,6 +371,7 @@ comment "Flattened Device Tree based board for EXYNOS SoCs"
368 371
369config MACH_EXYNOS4_DT 372config MACH_EXYNOS4_DT
370 bool "Samsung Exynos4 Machine using device tree" 373 bool "Samsung Exynos4 Machine using device tree"
374 depends on ARCH_EXYNOS4
371 select CPU_EXYNOS4210 375 select CPU_EXYNOS4210
372 select USE_OF 376 select USE_OF
373 select ARM_AMBA 377 select ARM_AMBA
@@ -380,6 +384,7 @@ config MACH_EXYNOS4_DT
380 384
381config MACH_EXYNOS5_DT 385config MACH_EXYNOS5_DT
382 bool "SAMSUNG EXYNOS5 Machine using device tree" 386 bool "SAMSUNG EXYNOS5 Machine using device tree"
387 depends on ARCH_EXYNOS5
383 select SOC_EXYNOS5250 388 select SOC_EXYNOS5250
384 select USE_OF 389 select USE_OF
385 select ARM_AMBA 390 select ARM_AMBA
diff --git a/arch/arm/mach-exynos/clock-exynos4.c b/arch/arm/mach-exynos/clock-exynos4.c
index df54c2a92225..6efd1e5919fd 100644
--- a/arch/arm/mach-exynos/clock-exynos4.c
+++ b/arch/arm/mach-exynos/clock-exynos4.c
@@ -497,25 +497,25 @@ static struct clk exynos4_init_clocks_off[] = {
497 .ctrlbit = (1 << 3), 497 .ctrlbit = (1 << 3),
498 }, { 498 }, {
499 .name = "hsmmc", 499 .name = "hsmmc",
500 .devname = "s3c-sdhci.0", 500 .devname = "exynos4-sdhci.0",
501 .parent = &exynos4_clk_aclk_133.clk, 501 .parent = &exynos4_clk_aclk_133.clk,
502 .enable = exynos4_clk_ip_fsys_ctrl, 502 .enable = exynos4_clk_ip_fsys_ctrl,
503 .ctrlbit = (1 << 5), 503 .ctrlbit = (1 << 5),
504 }, { 504 }, {
505 .name = "hsmmc", 505 .name = "hsmmc",
506 .devname = "s3c-sdhci.1", 506 .devname = "exynos4-sdhci.1",
507 .parent = &exynos4_clk_aclk_133.clk, 507 .parent = &exynos4_clk_aclk_133.clk,
508 .enable = exynos4_clk_ip_fsys_ctrl, 508 .enable = exynos4_clk_ip_fsys_ctrl,
509 .ctrlbit = (1 << 6), 509 .ctrlbit = (1 << 6),
510 }, { 510 }, {
511 .name = "hsmmc", 511 .name = "hsmmc",
512 .devname = "s3c-sdhci.2", 512 .devname = "exynos4-sdhci.2",
513 .parent = &exynos4_clk_aclk_133.clk, 513 .parent = &exynos4_clk_aclk_133.clk,
514 .enable = exynos4_clk_ip_fsys_ctrl, 514 .enable = exynos4_clk_ip_fsys_ctrl,
515 .ctrlbit = (1 << 7), 515 .ctrlbit = (1 << 7),
516 }, { 516 }, {
517 .name = "hsmmc", 517 .name = "hsmmc",
518 .devname = "s3c-sdhci.3", 518 .devname = "exynos4-sdhci.3",
519 .parent = &exynos4_clk_aclk_133.clk, 519 .parent = &exynos4_clk_aclk_133.clk,
520 .enable = exynos4_clk_ip_fsys_ctrl, 520 .enable = exynos4_clk_ip_fsys_ctrl,
521 .ctrlbit = (1 << 8), 521 .ctrlbit = (1 << 8),
@@ -1202,7 +1202,7 @@ static struct clksrc_clk exynos4_clk_sclk_uart3 = {
1202static struct clksrc_clk exynos4_clk_sclk_mmc0 = { 1202static struct clksrc_clk exynos4_clk_sclk_mmc0 = {
1203 .clk = { 1203 .clk = {
1204 .name = "sclk_mmc", 1204 .name = "sclk_mmc",
1205 .devname = "s3c-sdhci.0", 1205 .devname = "exynos4-sdhci.0",
1206 .parent = &exynos4_clk_dout_mmc0.clk, 1206 .parent = &exynos4_clk_dout_mmc0.clk,
1207 .enable = exynos4_clksrc_mask_fsys_ctrl, 1207 .enable = exynos4_clksrc_mask_fsys_ctrl,
1208 .ctrlbit = (1 << 0), 1208 .ctrlbit = (1 << 0),
@@ -1213,7 +1213,7 @@ static struct clksrc_clk exynos4_clk_sclk_mmc0 = {
1213static struct clksrc_clk exynos4_clk_sclk_mmc1 = { 1213static struct clksrc_clk exynos4_clk_sclk_mmc1 = {
1214 .clk = { 1214 .clk = {
1215 .name = "sclk_mmc", 1215 .name = "sclk_mmc",
1216 .devname = "s3c-sdhci.1", 1216 .devname = "exynos4-sdhci.1",
1217 .parent = &exynos4_clk_dout_mmc1.clk, 1217 .parent = &exynos4_clk_dout_mmc1.clk,
1218 .enable = exynos4_clksrc_mask_fsys_ctrl, 1218 .enable = exynos4_clksrc_mask_fsys_ctrl,
1219 .ctrlbit = (1 << 4), 1219 .ctrlbit = (1 << 4),
@@ -1224,7 +1224,7 @@ static struct clksrc_clk exynos4_clk_sclk_mmc1 = {
1224static struct clksrc_clk exynos4_clk_sclk_mmc2 = { 1224static struct clksrc_clk exynos4_clk_sclk_mmc2 = {
1225 .clk = { 1225 .clk = {
1226 .name = "sclk_mmc", 1226 .name = "sclk_mmc",
1227 .devname = "s3c-sdhci.2", 1227 .devname = "exynos4-sdhci.2",
1228 .parent = &exynos4_clk_dout_mmc2.clk, 1228 .parent = &exynos4_clk_dout_mmc2.clk,
1229 .enable = exynos4_clksrc_mask_fsys_ctrl, 1229 .enable = exynos4_clksrc_mask_fsys_ctrl,
1230 .ctrlbit = (1 << 8), 1230 .ctrlbit = (1 << 8),
@@ -1235,7 +1235,7 @@ static struct clksrc_clk exynos4_clk_sclk_mmc2 = {
1235static struct clksrc_clk exynos4_clk_sclk_mmc3 = { 1235static struct clksrc_clk exynos4_clk_sclk_mmc3 = {
1236 .clk = { 1236 .clk = {
1237 .name = "sclk_mmc", 1237 .name = "sclk_mmc",
1238 .devname = "s3c-sdhci.3", 1238 .devname = "exynos4-sdhci.3",
1239 .parent = &exynos4_clk_dout_mmc3.clk, 1239 .parent = &exynos4_clk_dout_mmc3.clk,
1240 .enable = exynos4_clksrc_mask_fsys_ctrl, 1240 .enable = exynos4_clksrc_mask_fsys_ctrl,
1241 .ctrlbit = (1 << 12), 1241 .ctrlbit = (1 << 12),
@@ -1340,10 +1340,10 @@ static struct clk_lookup exynos4_clk_lookup[] = {
1340 CLKDEV_INIT("exynos4210-uart.1", "clk_uart_baud0", &exynos4_clk_sclk_uart1.clk), 1340 CLKDEV_INIT("exynos4210-uart.1", "clk_uart_baud0", &exynos4_clk_sclk_uart1.clk),
1341 CLKDEV_INIT("exynos4210-uart.2", "clk_uart_baud0", &exynos4_clk_sclk_uart2.clk), 1341 CLKDEV_INIT("exynos4210-uart.2", "clk_uart_baud0", &exynos4_clk_sclk_uart2.clk),
1342 CLKDEV_INIT("exynos4210-uart.3", "clk_uart_baud0", &exynos4_clk_sclk_uart3.clk), 1342 CLKDEV_INIT("exynos4210-uart.3", "clk_uart_baud0", &exynos4_clk_sclk_uart3.clk),
1343 CLKDEV_INIT("s3c-sdhci.0", "mmc_busclk.2", &exynos4_clk_sclk_mmc0.clk), 1343 CLKDEV_INIT("exynos4-sdhci.0", "mmc_busclk.2", &exynos4_clk_sclk_mmc0.clk),
1344 CLKDEV_INIT("s3c-sdhci.1", "mmc_busclk.2", &exynos4_clk_sclk_mmc1.clk), 1344 CLKDEV_INIT("exynos4-sdhci.1", "mmc_busclk.2", &exynos4_clk_sclk_mmc1.clk),
1345 CLKDEV_INIT("s3c-sdhci.2", "mmc_busclk.2", &exynos4_clk_sclk_mmc2.clk), 1345 CLKDEV_INIT("exynos4-sdhci.2", "mmc_busclk.2", &exynos4_clk_sclk_mmc2.clk),
1346 CLKDEV_INIT("s3c-sdhci.3", "mmc_busclk.2", &exynos4_clk_sclk_mmc3.clk), 1346 CLKDEV_INIT("exynos4-sdhci.3", "mmc_busclk.2", &exynos4_clk_sclk_mmc3.clk),
1347 CLKDEV_INIT("exynos4-fb.0", "lcd", &exynos4_clk_fimd0), 1347 CLKDEV_INIT("exynos4-fb.0", "lcd", &exynos4_clk_fimd0),
1348 CLKDEV_INIT("dma-pl330.0", "apb_pclk", &exynos4_clk_pdma0), 1348 CLKDEV_INIT("dma-pl330.0", "apb_pclk", &exynos4_clk_pdma0),
1349 CLKDEV_INIT("dma-pl330.1", "apb_pclk", &exynos4_clk_pdma1), 1349 CLKDEV_INIT("dma-pl330.1", "apb_pclk", &exynos4_clk_pdma1),
diff --git a/arch/arm/mach-exynos/clock-exynos5.c b/arch/arm/mach-exynos/clock-exynos5.c
index d013982d0f8e..7ac6ff4c46bd 100644
--- a/arch/arm/mach-exynos/clock-exynos5.c
+++ b/arch/arm/mach-exynos/clock-exynos5.c
@@ -455,25 +455,25 @@ static struct clk exynos5_init_clocks_off[] = {
455 .ctrlbit = (1 << 20), 455 .ctrlbit = (1 << 20),
456 }, { 456 }, {
457 .name = "hsmmc", 457 .name = "hsmmc",
458 .devname = "s3c-sdhci.0", 458 .devname = "exynos4-sdhci.0",
459 .parent = &exynos5_clk_aclk_200.clk, 459 .parent = &exynos5_clk_aclk_200.clk,
460 .enable = exynos5_clk_ip_fsys_ctrl, 460 .enable = exynos5_clk_ip_fsys_ctrl,
461 .ctrlbit = (1 << 12), 461 .ctrlbit = (1 << 12),
462 }, { 462 }, {
463 .name = "hsmmc", 463 .name = "hsmmc",
464 .devname = "s3c-sdhci.1", 464 .devname = "exynos4-sdhci.1",
465 .parent = &exynos5_clk_aclk_200.clk, 465 .parent = &exynos5_clk_aclk_200.clk,
466 .enable = exynos5_clk_ip_fsys_ctrl, 466 .enable = exynos5_clk_ip_fsys_ctrl,
467 .ctrlbit = (1 << 13), 467 .ctrlbit = (1 << 13),
468 }, { 468 }, {
469 .name = "hsmmc", 469 .name = "hsmmc",
470 .devname = "s3c-sdhci.2", 470 .devname = "exynos4-sdhci.2",
471 .parent = &exynos5_clk_aclk_200.clk, 471 .parent = &exynos5_clk_aclk_200.clk,
472 .enable = exynos5_clk_ip_fsys_ctrl, 472 .enable = exynos5_clk_ip_fsys_ctrl,
473 .ctrlbit = (1 << 14), 473 .ctrlbit = (1 << 14),
474 }, { 474 }, {
475 .name = "hsmmc", 475 .name = "hsmmc",
476 .devname = "s3c-sdhci.3", 476 .devname = "exynos4-sdhci.3",
477 .parent = &exynos5_clk_aclk_200.clk, 477 .parent = &exynos5_clk_aclk_200.clk,
478 .enable = exynos5_clk_ip_fsys_ctrl, 478 .enable = exynos5_clk_ip_fsys_ctrl,
479 .ctrlbit = (1 << 15), 479 .ctrlbit = (1 << 15),
@@ -678,7 +678,7 @@ static struct clk exynos5_clk_pdma1 = {
678 .name = "dma", 678 .name = "dma",
679 .devname = "dma-pl330.1", 679 .devname = "dma-pl330.1",
680 .enable = exynos5_clk_ip_fsys_ctrl, 680 .enable = exynos5_clk_ip_fsys_ctrl,
681 .ctrlbit = (1 << 1), 681 .ctrlbit = (1 << 2),
682}; 682};
683 683
684static struct clk exynos5_clk_mdma1 = { 684static struct clk exynos5_clk_mdma1 = {
@@ -813,7 +813,7 @@ static struct clksrc_clk exynos5_clk_sclk_uart3 = {
813static struct clksrc_clk exynos5_clk_sclk_mmc0 = { 813static struct clksrc_clk exynos5_clk_sclk_mmc0 = {
814 .clk = { 814 .clk = {
815 .name = "sclk_mmc", 815 .name = "sclk_mmc",
816 .devname = "s3c-sdhci.0", 816 .devname = "exynos4-sdhci.0",
817 .parent = &exynos5_clk_dout_mmc0.clk, 817 .parent = &exynos5_clk_dout_mmc0.clk,
818 .enable = exynos5_clksrc_mask_fsys_ctrl, 818 .enable = exynos5_clksrc_mask_fsys_ctrl,
819 .ctrlbit = (1 << 0), 819 .ctrlbit = (1 << 0),
@@ -824,7 +824,7 @@ static struct clksrc_clk exynos5_clk_sclk_mmc0 = {
824static struct clksrc_clk exynos5_clk_sclk_mmc1 = { 824static struct clksrc_clk exynos5_clk_sclk_mmc1 = {
825 .clk = { 825 .clk = {
826 .name = "sclk_mmc", 826 .name = "sclk_mmc",
827 .devname = "s3c-sdhci.1", 827 .devname = "exynos4-sdhci.1",
828 .parent = &exynos5_clk_dout_mmc1.clk, 828 .parent = &exynos5_clk_dout_mmc1.clk,
829 .enable = exynos5_clksrc_mask_fsys_ctrl, 829 .enable = exynos5_clksrc_mask_fsys_ctrl,
830 .ctrlbit = (1 << 4), 830 .ctrlbit = (1 << 4),
@@ -835,7 +835,7 @@ static struct clksrc_clk exynos5_clk_sclk_mmc1 = {
835static struct clksrc_clk exynos5_clk_sclk_mmc2 = { 835static struct clksrc_clk exynos5_clk_sclk_mmc2 = {
836 .clk = { 836 .clk = {
837 .name = "sclk_mmc", 837 .name = "sclk_mmc",
838 .devname = "s3c-sdhci.2", 838 .devname = "exynos4-sdhci.2",
839 .parent = &exynos5_clk_dout_mmc2.clk, 839 .parent = &exynos5_clk_dout_mmc2.clk,
840 .enable = exynos5_clksrc_mask_fsys_ctrl, 840 .enable = exynos5_clksrc_mask_fsys_ctrl,
841 .ctrlbit = (1 << 8), 841 .ctrlbit = (1 << 8),
@@ -846,7 +846,7 @@ static struct clksrc_clk exynos5_clk_sclk_mmc2 = {
846static struct clksrc_clk exynos5_clk_sclk_mmc3 = { 846static struct clksrc_clk exynos5_clk_sclk_mmc3 = {
847 .clk = { 847 .clk = {
848 .name = "sclk_mmc", 848 .name = "sclk_mmc",
849 .devname = "s3c-sdhci.3", 849 .devname = "exynos4-sdhci.3",
850 .parent = &exynos5_clk_dout_mmc3.clk, 850 .parent = &exynos5_clk_dout_mmc3.clk,
851 .enable = exynos5_clksrc_mask_fsys_ctrl, 851 .enable = exynos5_clksrc_mask_fsys_ctrl,
852 .ctrlbit = (1 << 12), 852 .ctrlbit = (1 << 12),
@@ -990,10 +990,10 @@ static struct clk_lookup exynos5_clk_lookup[] = {
990 CLKDEV_INIT("exynos4210-uart.1", "clk_uart_baud0", &exynos5_clk_sclk_uart1.clk), 990 CLKDEV_INIT("exynos4210-uart.1", "clk_uart_baud0", &exynos5_clk_sclk_uart1.clk),
991 CLKDEV_INIT("exynos4210-uart.2", "clk_uart_baud0", &exynos5_clk_sclk_uart2.clk), 991 CLKDEV_INIT("exynos4210-uart.2", "clk_uart_baud0", &exynos5_clk_sclk_uart2.clk),
992 CLKDEV_INIT("exynos4210-uart.3", "clk_uart_baud0", &exynos5_clk_sclk_uart3.clk), 992 CLKDEV_INIT("exynos4210-uart.3", "clk_uart_baud0", &exynos5_clk_sclk_uart3.clk),
993 CLKDEV_INIT("s3c-sdhci.0", "mmc_busclk.2", &exynos5_clk_sclk_mmc0.clk), 993 CLKDEV_INIT("exynos4-sdhci.0", "mmc_busclk.2", &exynos5_clk_sclk_mmc0.clk),
994 CLKDEV_INIT("s3c-sdhci.1", "mmc_busclk.2", &exynos5_clk_sclk_mmc1.clk), 994 CLKDEV_INIT("exynos4-sdhci.1", "mmc_busclk.2", &exynos5_clk_sclk_mmc1.clk),
995 CLKDEV_INIT("s3c-sdhci.2", "mmc_busclk.2", &exynos5_clk_sclk_mmc2.clk), 995 CLKDEV_INIT("exynos4-sdhci.2", "mmc_busclk.2", &exynos5_clk_sclk_mmc2.clk),
996 CLKDEV_INIT("s3c-sdhci.3", "mmc_busclk.2", &exynos5_clk_sclk_mmc3.clk), 996 CLKDEV_INIT("exynos4-sdhci.3", "mmc_busclk.2", &exynos5_clk_sclk_mmc3.clk),
997 CLKDEV_INIT("dma-pl330.0", "apb_pclk", &exynos5_clk_pdma0), 997 CLKDEV_INIT("dma-pl330.0", "apb_pclk", &exynos5_clk_pdma0),
998 CLKDEV_INIT("dma-pl330.1", "apb_pclk", &exynos5_clk_pdma1), 998 CLKDEV_INIT("dma-pl330.1", "apb_pclk", &exynos5_clk_pdma1),
999 CLKDEV_INIT("dma-pl330.2", "apb_pclk", &exynos5_clk_mdma1), 999 CLKDEV_INIT("dma-pl330.2", "apb_pclk", &exynos5_clk_mdma1),
diff --git a/arch/arm/mach-exynos/common.c b/arch/arm/mach-exynos/common.c
index e6cc50e94a58..5ccd6e80a607 100644
--- a/arch/arm/mach-exynos/common.c
+++ b/arch/arm/mach-exynos/common.c
@@ -326,6 +326,11 @@ static void __init exynos4_map_io(void)
326 s3c_fimc_setname(2, "exynos4-fimc"); 326 s3c_fimc_setname(2, "exynos4-fimc");
327 s3c_fimc_setname(3, "exynos4-fimc"); 327 s3c_fimc_setname(3, "exynos4-fimc");
328 328
329 s3c_sdhci_setname(0, "exynos4-sdhci");
330 s3c_sdhci_setname(1, "exynos4-sdhci");
331 s3c_sdhci_setname(2, "exynos4-sdhci");
332 s3c_sdhci_setname(3, "exynos4-sdhci");
333
329 /* The I2C bus controllers are directly compatible with s3c2440 */ 334 /* The I2C bus controllers are directly compatible with s3c2440 */
330 s3c_i2c0_setname("s3c2440-i2c"); 335 s3c_i2c0_setname("s3c2440-i2c");
331 s3c_i2c1_setname("s3c2440-i2c"); 336 s3c_i2c1_setname("s3c2440-i2c");
@@ -344,6 +349,11 @@ static void __init exynos5_map_io(void)
344 s3c_device_i2c0.resource[1].start = EXYNOS5_IRQ_IIC; 349 s3c_device_i2c0.resource[1].start = EXYNOS5_IRQ_IIC;
345 s3c_device_i2c0.resource[1].end = EXYNOS5_IRQ_IIC; 350 s3c_device_i2c0.resource[1].end = EXYNOS5_IRQ_IIC;
346 351
352 s3c_sdhci_setname(0, "exynos4-sdhci");
353 s3c_sdhci_setname(1, "exynos4-sdhci");
354 s3c_sdhci_setname(2, "exynos4-sdhci");
355 s3c_sdhci_setname(3, "exynos4-sdhci");
356
347 /* The I2C bus controllers are directly compatible with s3c2440 */ 357 /* The I2C bus controllers are directly compatible with s3c2440 */
348 s3c_i2c0_setname("s3c2440-i2c"); 358 s3c_i2c0_setname("s3c2440-i2c");
349 s3c_i2c1_setname("s3c2440-i2c"); 359 s3c_i2c1_setname("s3c2440-i2c");
@@ -537,7 +547,9 @@ void __init exynos5_init_irq(void)
537{ 547{
538 int irq; 548 int irq;
539 549
540 gic_init(0, IRQ_PPI(0), S5P_VA_GIC_DIST, S5P_VA_GIC_CPU); 550#ifdef CONFIG_OF
551 of_irq_init(exynos4_dt_irq_match);
552#endif
541 553
542 for (irq = 0; irq < EXYNOS5_MAX_COMBINER_NR; irq++) { 554 for (irq = 0; irq < EXYNOS5_MAX_COMBINER_NR; irq++) {
543 combiner_init(irq, (void __iomem *)S5P_VA_COMBINER(irq), 555 combiner_init(irq, (void __iomem *)S5P_VA_COMBINER(irq),
@@ -583,10 +595,11 @@ core_initcall(exynos_core_init);
583#ifdef CONFIG_CACHE_L2X0 595#ifdef CONFIG_CACHE_L2X0
584static int __init exynos4_l2x0_cache_init(void) 596static int __init exynos4_l2x0_cache_init(void)
585{ 597{
598 int ret;
599
586 if (soc_is_exynos5250()) 600 if (soc_is_exynos5250())
587 return 0; 601 return 0;
588 602
589 int ret;
590 ret = l2x0_of_init(L2_AUX_VAL, L2_AUX_MASK); 603 ret = l2x0_of_init(L2_AUX_VAL, L2_AUX_MASK);
591 if (!ret) { 604 if (!ret) {
592 l2x0_regs_phys = virt_to_phys(&l2x0_saved_regs); 605 l2x0_regs_phys = virt_to_phys(&l2x0_saved_regs);
diff --git a/arch/arm/mach-exynos/dev-dwmci.c b/arch/arm/mach-exynos/dev-dwmci.c
index b025db4bf602..79035018fb74 100644
--- a/arch/arm/mach-exynos/dev-dwmci.c
+++ b/arch/arm/mach-exynos/dev-dwmci.c
@@ -16,6 +16,7 @@
16#include <linux/dma-mapping.h> 16#include <linux/dma-mapping.h>
17#include <linux/platform_device.h> 17#include <linux/platform_device.h>
18#include <linux/interrupt.h> 18#include <linux/interrupt.h>
19#include <linux/ioport.h>
19#include <linux/mmc/dw_mmc.h> 20#include <linux/mmc/dw_mmc.h>
20 21
21#include <plat/devs.h> 22#include <plat/devs.h>
@@ -33,16 +34,8 @@ static int exynos4_dwmci_init(u32 slot_id, irq_handler_t handler, void *data)
33} 34}
34 35
35static struct resource exynos4_dwmci_resource[] = { 36static struct resource exynos4_dwmci_resource[] = {
36 [0] = { 37 [0] = DEFINE_RES_MEM(EXYNOS4_PA_DWMCI, SZ_4K),
37 .start = EXYNOS4_PA_DWMCI, 38 [1] = DEFINE_RES_IRQ(EXYNOS4_IRQ_DWMCI),
38 .end = EXYNOS4_PA_DWMCI + SZ_4K - 1,
39 .flags = IORESOURCE_MEM,
40 },
41 [1] = {
42 .start = IRQ_DWMCI,
43 .end = IRQ_DWMCI,
44 .flags = IORESOURCE_IRQ,
45 }
46}; 39};
47 40
48static struct dw_mci_board exynos4_dwci_pdata = { 41static struct dw_mci_board exynos4_dwci_pdata = {
diff --git a/arch/arm/mach-exynos/dma.c b/arch/arm/mach-exynos/dma.c
index 3983abee4264..69aaa4503205 100644
--- a/arch/arm/mach-exynos/dma.c
+++ b/arch/arm/mach-exynos/dma.c
@@ -35,8 +35,6 @@
35#include <mach/irqs.h> 35#include <mach/irqs.h>
36#include <mach/dma.h> 36#include <mach/dma.h>
37 37
38static u64 dma_dmamask = DMA_BIT_MASK(32);
39
40static u8 exynos4210_pdma0_peri[] = { 38static u8 exynos4210_pdma0_peri[] = {
41 DMACH_PCM0_RX, 39 DMACH_PCM0_RX,
42 DMACH_PCM0_TX, 40 DMACH_PCM0_TX,
diff --git a/arch/arm/mach-exynos/include/mach/debug-macro.S b/arch/arm/mach-exynos/include/mach/debug-macro.S
index 6c857ff0b5d8..e0c86ea475e7 100644
--- a/arch/arm/mach-exynos/include/mach/debug-macro.S
+++ b/arch/arm/mach-exynos/include/mach/debug-macro.S
@@ -21,10 +21,9 @@
21 */ 21 */
22 22
23 .macro addruart, rp, rv, tmp 23 .macro addruart, rp, rv, tmp
24 mov \rp, #0x10000000 24 mrc p15, 0, \tmp, c0, c0, 0
25 ldr \rp, [\rp, #0x0] 25 and \tmp, \tmp, #0xf0
26 and \rp, \rp, #0xf00000 26 teq \tmp, #0xf0 @@ A15
27 teq \rp, #0x500000 @@ EXYNOS5
28 ldreq \rp, =EXYNOS5_PA_UART 27 ldreq \rp, =EXYNOS5_PA_UART
29 movne \rp, #EXYNOS4_PA_UART @@ EXYNOS4 28 movne \rp, #EXYNOS4_PA_UART @@ EXYNOS4
30 ldr \rv, =S3C_VA_UART 29 ldr \rv, =S3C_VA_UART
diff --git a/arch/arm/mach-exynos/include/mach/irqs.h b/arch/arm/mach-exynos/include/mach/irqs.h
index 9bee8535d9e0..591e78521a9f 100644
--- a/arch/arm/mach-exynos/include/mach/irqs.h
+++ b/arch/arm/mach-exynos/include/mach/irqs.h
@@ -212,6 +212,8 @@
212#define IRQ_MFC EXYNOS4_IRQ_MFC 212#define IRQ_MFC EXYNOS4_IRQ_MFC
213#define IRQ_SDO EXYNOS4_IRQ_SDO 213#define IRQ_SDO EXYNOS4_IRQ_SDO
214 214
215#define IRQ_I2S0 EXYNOS4_IRQ_I2S0
216
215#define IRQ_ADC EXYNOS4_IRQ_ADC0 217#define IRQ_ADC EXYNOS4_IRQ_ADC0
216#define IRQ_TC EXYNOS4_IRQ_PEN0 218#define IRQ_TC EXYNOS4_IRQ_PEN0
217 219
diff --git a/arch/arm/mach-exynos/include/mach/map.h b/arch/arm/mach-exynos/include/mach/map.h
index 024d38ff1718..6e6d11ff352a 100644
--- a/arch/arm/mach-exynos/include/mach/map.h
+++ b/arch/arm/mach-exynos/include/mach/map.h
@@ -89,6 +89,10 @@
89#define EXYNOS4_PA_MDMA1 0x12840000 89#define EXYNOS4_PA_MDMA1 0x12840000
90#define EXYNOS4_PA_PDMA0 0x12680000 90#define EXYNOS4_PA_PDMA0 0x12680000
91#define EXYNOS4_PA_PDMA1 0x12690000 91#define EXYNOS4_PA_PDMA1 0x12690000
92#define EXYNOS5_PA_MDMA0 0x10800000
93#define EXYNOS5_PA_MDMA1 0x11C10000
94#define EXYNOS5_PA_PDMA0 0x121A0000
95#define EXYNOS5_PA_PDMA1 0x121B0000
92 96
93#define EXYNOS4_PA_SYSMMU_MDMA 0x10A40000 97#define EXYNOS4_PA_SYSMMU_MDMA 0x10A40000
94#define EXYNOS4_PA_SYSMMU_SSS 0x10A50000 98#define EXYNOS4_PA_SYSMMU_SSS 0x10A50000
diff --git a/arch/arm/mach-exynos/include/mach/regs-clock.h b/arch/arm/mach-exynos/include/mach/regs-clock.h
index e141c1fd68d8..d9578a58ae7f 100644
--- a/arch/arm/mach-exynos/include/mach/regs-clock.h
+++ b/arch/arm/mach-exynos/include/mach/regs-clock.h
@@ -255,9 +255,15 @@
255 255
256/* For EXYNOS5250 */ 256/* For EXYNOS5250 */
257 257
258#define EXYNOS5_APLL_LOCK EXYNOS_CLKREG(0x00000)
258#define EXYNOS5_APLL_CON0 EXYNOS_CLKREG(0x00100) 259#define EXYNOS5_APLL_CON0 EXYNOS_CLKREG(0x00100)
259#define EXYNOS5_CLKSRC_CPU EXYNOS_CLKREG(0x00200) 260#define EXYNOS5_CLKSRC_CPU EXYNOS_CLKREG(0x00200)
261#define EXYNOS5_CLKMUX_STATCPU EXYNOS_CLKREG(0x00400)
260#define EXYNOS5_CLKDIV_CPU0 EXYNOS_CLKREG(0x00500) 262#define EXYNOS5_CLKDIV_CPU0 EXYNOS_CLKREG(0x00500)
263#define EXYNOS5_CLKDIV_CPU1 EXYNOS_CLKREG(0x00504)
264#define EXYNOS5_CLKDIV_STATCPU0 EXYNOS_CLKREG(0x00600)
265#define EXYNOS5_CLKDIV_STATCPU1 EXYNOS_CLKREG(0x00604)
266
261#define EXYNOS5_MPLL_CON0 EXYNOS_CLKREG(0x04100) 267#define EXYNOS5_MPLL_CON0 EXYNOS_CLKREG(0x04100)
262#define EXYNOS5_CLKSRC_CORE1 EXYNOS_CLKREG(0x04204) 268#define EXYNOS5_CLKSRC_CORE1 EXYNOS_CLKREG(0x04204)
263 269
diff --git a/arch/arm/mach-exynos/include/mach/uncompress.h b/arch/arm/mach-exynos/include/mach/uncompress.h
index 493f4f365ddf..2979995d5a6a 100644
--- a/arch/arm/mach-exynos/include/mach/uncompress.h
+++ b/arch/arm/mach-exynos/include/mach/uncompress.h
@@ -20,9 +20,24 @@ volatile u8 *uart_base;
20 20
21#include <plat/uncompress.h> 21#include <plat/uncompress.h>
22 22
23static unsigned int __raw_readl(unsigned int ptr)
24{
25 return *((volatile unsigned int *)ptr);
26}
27
23static void arch_detect_cpu(void) 28static void arch_detect_cpu(void)
24{ 29{
25 if (machine_is_smdk5250()) 30 u32 chip_id = __raw_readl(EXYNOS_PA_CHIPID);
31
32 /*
33 * product_id is bits 31:12
34 * bits 23:20 describe the exynosX family
35 *
36 */
37 chip_id >>= 20;
38 chip_id &= 0xf;
39
40 if (chip_id == 0x5)
26 uart_base = (volatile u8 *)EXYNOS5_PA_UART + (S3C_UART_OFFSET * CONFIG_S3C_LOWLEVEL_UART_PORT); 41 uart_base = (volatile u8 *)EXYNOS5_PA_UART + (S3C_UART_OFFSET * CONFIG_S3C_LOWLEVEL_UART_PORT);
27 else 42 else
28 uart_base = (volatile u8 *)EXYNOS4_PA_UART + (S3C_UART_OFFSET * CONFIG_S3C_LOWLEVEL_UART_PORT); 43 uart_base = (volatile u8 *)EXYNOS4_PA_UART + (S3C_UART_OFFSET * CONFIG_S3C_LOWLEVEL_UART_PORT);
diff --git a/arch/arm/mach-exynos/mach-exynos5-dt.c b/arch/arm/mach-exynos/mach-exynos5-dt.c
index 0d26f50081ad..4711c8920e37 100644
--- a/arch/arm/mach-exynos/mach-exynos5-dt.c
+++ b/arch/arm/mach-exynos/mach-exynos5-dt.c
@@ -45,7 +45,7 @@ static const struct of_dev_auxdata exynos5250_auxdata_lookup[] __initconst = {
45 "exynos4210-uart.3", NULL), 45 "exynos4210-uart.3", NULL),
46 OF_DEV_AUXDATA("arm,pl330", EXYNOS5_PA_PDMA0, "dma-pl330.0", NULL), 46 OF_DEV_AUXDATA("arm,pl330", EXYNOS5_PA_PDMA0, "dma-pl330.0", NULL),
47 OF_DEV_AUXDATA("arm,pl330", EXYNOS5_PA_PDMA1, "dma-pl330.1", NULL), 47 OF_DEV_AUXDATA("arm,pl330", EXYNOS5_PA_PDMA1, "dma-pl330.1", NULL),
48 OF_DEV_AUXDATA("arm,pl330", EXYNOS5_PA_PDMA1, "dma-pl330.2", NULL), 48 OF_DEV_AUXDATA("arm,pl330", EXYNOS5_PA_MDMA1, "dma-pl330.2", NULL),
49 {}, 49 {},
50}; 50};
51 51
diff --git a/arch/arm/mach-exynos/mach-nuri.c b/arch/arm/mach-exynos/mach-nuri.c
index b3982c867c9c..ed90aef404c3 100644
--- a/arch/arm/mach-exynos/mach-nuri.c
+++ b/arch/arm/mach-exynos/mach-nuri.c
@@ -112,6 +112,7 @@ static struct s3c_sdhci_platdata nuri_hsmmc0_data __initdata = {
112 .host_caps = (MMC_CAP_8_BIT_DATA | MMC_CAP_4_BIT_DATA | 112 .host_caps = (MMC_CAP_8_BIT_DATA | MMC_CAP_4_BIT_DATA |
113 MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED | 113 MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED |
114 MMC_CAP_ERASE), 114 MMC_CAP_ERASE),
115 .host_caps2 = MMC_CAP2_BROKEN_VOLTAGE,
115 .cd_type = S3C_SDHCI_CD_PERMANENT, 116 .cd_type = S3C_SDHCI_CD_PERMANENT,
116 .clk_type = S3C_SDHCI_CLK_DIV_EXTERNAL, 117 .clk_type = S3C_SDHCI_CLK_DIV_EXTERNAL,
117}; 118};
@@ -307,49 +308,7 @@ static struct i2c_board_info i2c1_devs[] __initdata = {
307}; 308};
308 309
309/* TSP */ 310/* TSP */
310static u8 mxt_init_vals[] = {
311 /* MXT_GEN_COMMAND(6) */
312 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
313 /* MXT_GEN_POWER(7) */
314 0x20, 0xff, 0x32,
315 /* MXT_GEN_ACQUIRE(8) */
316 0x0a, 0x00, 0x05, 0x00, 0x00, 0x00, 0x09, 0x23,
317 /* MXT_TOUCH_MULTI(9) */
318 0x00, 0x00, 0x00, 0x13, 0x0b, 0x00, 0x00, 0x00, 0x02, 0x00,
319 0x00, 0x01, 0x01, 0x0e, 0x0a, 0x0a, 0x0a, 0x0a, 0x00, 0x00,
320 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
321 0x00,
322 /* MXT_TOUCH_KEYARRAY(15) */
323 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
324 0x00,
325 /* MXT_SPT_GPIOPWM(19) */
326 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
327 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
328 /* MXT_PROCI_GRIPFACE(20) */
329 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x28, 0x04,
330 0x0f, 0x0a,
331 /* MXT_PROCG_NOISE(22) */
332 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x23, 0x00,
333 0x00, 0x05, 0x0f, 0x19, 0x23, 0x2d, 0x03,
334 /* MXT_TOUCH_PROXIMITY(23) */
335 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
336 0x00, 0x00, 0x00, 0x00, 0x00,
337 /* MXT_PROCI_ONETOUCH(24) */
338 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
339 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
340 /* MXT_SPT_SELFTEST(25) */
341 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
342 0x00, 0x00, 0x00, 0x00,
343 /* MXT_PROCI_TWOTOUCH(27) */
344 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
345 /* MXT_SPT_CTECONFIG(28) */
346 0x00, 0x00, 0x02, 0x08, 0x10, 0x00,
347};
348
349static struct mxt_platform_data mxt_platform_data = { 311static struct mxt_platform_data mxt_platform_data = {
350 .config = mxt_init_vals,
351 .config_length = ARRAY_SIZE(mxt_init_vals),
352
353 .x_line = 18, 312 .x_line = 18,
354 .y_line = 11, 313 .y_line = 11,
355 .x_size = 1024, 314 .x_size = 1024,
@@ -571,7 +530,7 @@ static struct regulator_init_data __initdata max8997_ldo7_data = {
571 530
572static struct regulator_init_data __initdata max8997_ldo8_data = { 531static struct regulator_init_data __initdata max8997_ldo8_data = {
573 .constraints = { 532 .constraints = {
574 .name = "VUSB/VDAC_3.3V_C210", 533 .name = "VUSB+VDAC_3.3V_C210",
575 .min_uV = 3300000, 534 .min_uV = 3300000,
576 .max_uV = 3300000, 535 .max_uV = 3300000,
577 .valid_ops_mask = REGULATOR_CHANGE_STATUS, 536 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
@@ -1347,6 +1306,7 @@ static struct platform_device *nuri_devices[] __initdata = {
1347 1306
1348static void __init nuri_map_io(void) 1307static void __init nuri_map_io(void)
1349{ 1308{
1309 clk_xusbxti.rate = 24000000;
1350 exynos_init_io(NULL, 0); 1310 exynos_init_io(NULL, 0);
1351 s3c24xx_init_clocks(24000000); 1311 s3c24xx_init_clocks(24000000);
1352 s3c24xx_init_uarts(nuri_uartcfgs, ARRAY_SIZE(nuri_uartcfgs)); 1312 s3c24xx_init_uarts(nuri_uartcfgs, ARRAY_SIZE(nuri_uartcfgs));
@@ -1379,7 +1339,6 @@ static void __init nuri_machine_init(void)
1379 nuri_camera_init(); 1339 nuri_camera_init();
1380 1340
1381 nuri_ehci_init(); 1341 nuri_ehci_init();
1382 clk_xusbxti.rate = 24000000;
1383 1342
1384 /* Last */ 1343 /* Last */
1385 platform_add_devices(nuri_devices, ARRAY_SIZE(nuri_devices)); 1344 platform_add_devices(nuri_devices, ARRAY_SIZE(nuri_devices));
diff --git a/arch/arm/mach-exynos/mach-universal_c210.c b/arch/arm/mach-exynos/mach-universal_c210.c
index 6bb9dbdd73fd..a34036eb8ba2 100644
--- a/arch/arm/mach-exynos/mach-universal_c210.c
+++ b/arch/arm/mach-exynos/mach-universal_c210.c
@@ -29,6 +29,7 @@
29#include <asm/mach-types.h> 29#include <asm/mach-types.h>
30 30
31#include <plat/regs-serial.h> 31#include <plat/regs-serial.h>
32#include <plat/clock.h>
32#include <plat/cpu.h> 33#include <plat/cpu.h>
33#include <plat/devs.h> 34#include <plat/devs.h>
34#include <plat/iic.h> 35#include <plat/iic.h>
@@ -39,6 +40,7 @@
39#include <plat/pd.h> 40#include <plat/pd.h>
40#include <plat/regs-fb-v4.h> 41#include <plat/regs-fb-v4.h>
41#include <plat/fimc-core.h> 42#include <plat/fimc-core.h>
43#include <plat/s5p-time.h>
42#include <plat/camport.h> 44#include <plat/camport.h>
43#include <plat/mipi_csis.h> 45#include <plat/mipi_csis.h>
44 46
@@ -746,6 +748,7 @@ static struct s3c_sdhci_platdata universal_hsmmc0_data __initdata = {
746 .max_width = 8, 748 .max_width = 8,
747 .host_caps = (MMC_CAP_8_BIT_DATA | MMC_CAP_4_BIT_DATA | 749 .host_caps = (MMC_CAP_8_BIT_DATA | MMC_CAP_4_BIT_DATA |
748 MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED), 750 MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED),
751 .host_caps2 = MMC_CAP2_BROKEN_VOLTAGE,
749 .cd_type = S3C_SDHCI_CD_PERMANENT, 752 .cd_type = S3C_SDHCI_CD_PERMANENT,
750 .clk_type = S3C_SDHCI_CLK_DIV_EXTERNAL, 753 .clk_type = S3C_SDHCI_CLK_DIV_EXTERNAL,
751}; 754};
@@ -1057,9 +1060,11 @@ static struct platform_device *universal_devices[] __initdata = {
1057 1060
1058static void __init universal_map_io(void) 1061static void __init universal_map_io(void)
1059{ 1062{
1063 clk_xusbxti.rate = 24000000;
1060 exynos_init_io(NULL, 0); 1064 exynos_init_io(NULL, 0);
1061 s3c24xx_init_clocks(24000000); 1065 s3c24xx_init_clocks(24000000);
1062 s3c24xx_init_uarts(universal_uartcfgs, ARRAY_SIZE(universal_uartcfgs)); 1066 s3c24xx_init_uarts(universal_uartcfgs, ARRAY_SIZE(universal_uartcfgs));
1067 s5p_set_timer_source(S5P_PWM2, S5P_PWM4);
1063} 1068}
1064 1069
1065static void s5p_tv_setup(void) 1070static void s5p_tv_setup(void)
@@ -1110,7 +1115,7 @@ MACHINE_START(UNIVERSAL_C210, "UNIVERSAL_C210")
1110 .map_io = universal_map_io, 1115 .map_io = universal_map_io,
1111 .handle_irq = gic_handle_irq, 1116 .handle_irq = gic_handle_irq,
1112 .init_machine = universal_machine_init, 1117 .init_machine = universal_machine_init,
1113 .timer = &exynos4_timer, 1118 .timer = &s5p_timer,
1114 .reserve = &universal_reserve, 1119 .reserve = &universal_reserve,
1115 .restart = exynos4_restart, 1120 .restart = exynos4_restart,
1116MACHINE_END 1121MACHINE_END
diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig
index 7561eca131b0..472d47b50cd6 100644
--- a/arch/arm/mach-imx/Kconfig
+++ b/arch/arm/mach-imx/Kconfig
@@ -151,6 +151,7 @@ config MACH_MX25_3DS
151 select IMX_HAVE_PLATFORM_IMX2_WDT 151 select IMX_HAVE_PLATFORM_IMX2_WDT
152 select IMX_HAVE_PLATFORM_IMXDI_RTC 152 select IMX_HAVE_PLATFORM_IMXDI_RTC
153 select IMX_HAVE_PLATFORM_IMX_I2C 153 select IMX_HAVE_PLATFORM_IMX_I2C
154 select IMX_HAVE_PLATFORM_IMX_SSI
154 select IMX_HAVE_PLATFORM_IMX_FB 155 select IMX_HAVE_PLATFORM_IMX_FB
155 select IMX_HAVE_PLATFORM_IMX_KEYPAD 156 select IMX_HAVE_PLATFORM_IMX_KEYPAD
156 select IMX_HAVE_PLATFORM_IMX_UART 157 select IMX_HAVE_PLATFORM_IMX_UART
@@ -493,6 +494,7 @@ config MACH_MX31MOBOARD
493 select IMX_HAVE_PLATFORM_FSL_USB2_UDC 494 select IMX_HAVE_PLATFORM_FSL_USB2_UDC
494 select IMX_HAVE_PLATFORM_IMX2_WDT 495 select IMX_HAVE_PLATFORM_IMX2_WDT
495 select IMX_HAVE_PLATFORM_IMX_I2C 496 select IMX_HAVE_PLATFORM_IMX_I2C
497 select IMX_HAVE_PLATFORM_IMX_SSI
496 select IMX_HAVE_PLATFORM_IMX_UART 498 select IMX_HAVE_PLATFORM_IMX_UART
497 select IMX_HAVE_PLATFORM_IPU_CORE 499 select IMX_HAVE_PLATFORM_IPU_CORE
498 select IMX_HAVE_PLATFORM_MXC_EHCI 500 select IMX_HAVE_PLATFORM_MXC_EHCI
diff --git a/arch/arm/mach-imx/clock-imx27.c b/arch/arm/mach-imx/clock-imx27.c
index b9a95ed75553..98e04f5a87dd 100644
--- a/arch/arm/mach-imx/clock-imx27.c
+++ b/arch/arm/mach-imx/clock-imx27.c
@@ -662,6 +662,7 @@ static struct clk_lookup lookups[] = {
662 _REGISTER_CLOCK(NULL, "dma", dma_clk) 662 _REGISTER_CLOCK(NULL, "dma", dma_clk)
663 _REGISTER_CLOCK(NULL, "rtic", rtic_clk) 663 _REGISTER_CLOCK(NULL, "rtic", rtic_clk)
664 _REGISTER_CLOCK(NULL, "brom", brom_clk) 664 _REGISTER_CLOCK(NULL, "brom", brom_clk)
665 _REGISTER_CLOCK(NULL, "emma", emma_clk)
665 _REGISTER_CLOCK("m2m-emmaprp.0", NULL, emma_clk) 666 _REGISTER_CLOCK("m2m-emmaprp.0", NULL, emma_clk)
666 _REGISTER_CLOCK(NULL, "slcdc", slcdc_clk) 667 _REGISTER_CLOCK(NULL, "slcdc", slcdc_clk)
667 _REGISTER_CLOCK("imx27-fec.0", NULL, fec_clk) 668 _REGISTER_CLOCK("imx27-fec.0", NULL, fec_clk)
diff --git a/arch/arm/mach-imx/clock-imx35.c b/arch/arm/mach-imx/clock-imx35.c
index 1e279af656ad..e56c1a83eee3 100644
--- a/arch/arm/mach-imx/clock-imx35.c
+++ b/arch/arm/mach-imx/clock-imx35.c
@@ -483,7 +483,7 @@ static struct clk_lookup lookups[] = {
483 _REGISTER_CLOCK("imx2-wdt.0", NULL, wdog_clk) 483 _REGISTER_CLOCK("imx2-wdt.0", NULL, wdog_clk)
484 _REGISTER_CLOCK(NULL, "max", max_clk) 484 _REGISTER_CLOCK(NULL, "max", max_clk)
485 _REGISTER_CLOCK(NULL, "audmux", audmux_clk) 485 _REGISTER_CLOCK(NULL, "audmux", audmux_clk)
486 _REGISTER_CLOCK(NULL, "csi", csi_clk) 486 _REGISTER_CLOCK("mx3-camera.0", NULL, csi_clk)
487 _REGISTER_CLOCK(NULL, "iim", iim_clk) 487 _REGISTER_CLOCK(NULL, "iim", iim_clk)
488 _REGISTER_CLOCK(NULL, "gpu2d", gpu2d_clk) 488 _REGISTER_CLOCK(NULL, "gpu2d", gpu2d_clk)
489 _REGISTER_CLOCK("mxc_nand.0", NULL, nfc_clk) 489 _REGISTER_CLOCK("mxc_nand.0", NULL, nfc_clk)
diff --git a/arch/arm/mach-imx/imx27-dt.c b/arch/arm/mach-imx/imx27-dt.c
index 861ceb8232d6..ed38d03c61f2 100644
--- a/arch/arm/mach-imx/imx27-dt.c
+++ b/arch/arm/mach-imx/imx27-dt.c
@@ -35,7 +35,7 @@ static const struct of_dev_auxdata imx27_auxdata_lookup[] __initconst = {
35static int __init imx27_avic_add_irq_domain(struct device_node *np, 35static int __init imx27_avic_add_irq_domain(struct device_node *np,
36 struct device_node *interrupt_parent) 36 struct device_node *interrupt_parent)
37{ 37{
38 irq_domain_add_simple(np, 0); 38 irq_domain_add_legacy(np, 64, 0, 0, &irq_domain_simple_ops, NULL);
39 return 0; 39 return 0;
40} 40}
41 41
@@ -44,7 +44,9 @@ static int __init imx27_gpio_add_irq_domain(struct device_node *np,
44{ 44{
45 static int gpio_irq_base = MXC_GPIO_IRQ_START + ARCH_NR_GPIOS; 45 static int gpio_irq_base = MXC_GPIO_IRQ_START + ARCH_NR_GPIOS;
46 46
47 irq_domain_add_simple(np, gpio_irq_base); 47 gpio_irq_base -= 32;
48 irq_domain_add_legacy(np, 32, gpio_irq_base, 0, &irq_domain_simple_ops,
49 NULL);
48 50
49 return 0; 51 return 0;
50} 52}
diff --git a/arch/arm/mach-imx/mach-armadillo5x0.c b/arch/arm/mach-imx/mach-armadillo5x0.c
index 27bc27e6ea41..c650145d1646 100644
--- a/arch/arm/mach-imx/mach-armadillo5x0.c
+++ b/arch/arm/mach-imx/mach-armadillo5x0.c
@@ -38,6 +38,8 @@
38#include <linux/usb/otg.h> 38#include <linux/usb/otg.h>
39#include <linux/usb/ulpi.h> 39#include <linux/usb/ulpi.h>
40#include <linux/delay.h> 40#include <linux/delay.h>
41#include <linux/regulator/machine.h>
42#include <linux/regulator/fixed.h>
41 43
42#include <mach/hardware.h> 44#include <mach/hardware.h>
43#include <asm/mach-types.h> 45#include <asm/mach-types.h>
@@ -479,6 +481,11 @@ static struct platform_device *devices[] __initdata = {
479 &armadillo5x0_smc911x_device, 481 &armadillo5x0_smc911x_device,
480}; 482};
481 483
484static struct regulator_consumer_supply dummy_supplies[] = {
485 REGULATOR_SUPPLY("vdd33a", "smsc911x"),
486 REGULATOR_SUPPLY("vddvario", "smsc911x"),
487};
488
482/* 489/*
483 * Perform board specific initializations 490 * Perform board specific initializations
484 */ 491 */
@@ -489,6 +496,8 @@ static void __init armadillo5x0_init(void)
489 mxc_iomux_setup_multiple_pins(armadillo5x0_pins, 496 mxc_iomux_setup_multiple_pins(armadillo5x0_pins,
490 ARRAY_SIZE(armadillo5x0_pins), "armadillo5x0"); 497 ARRAY_SIZE(armadillo5x0_pins), "armadillo5x0");
491 498
499 regulator_register_fixed(0, dummy_supplies, ARRAY_SIZE(dummy_supplies));
500
492 platform_add_devices(devices, ARRAY_SIZE(devices)); 501 platform_add_devices(devices, ARRAY_SIZE(devices));
493 imx_add_gpio_keys(&armadillo5x0_button_data); 502 imx_add_gpio_keys(&armadillo5x0_button_data);
494 imx31_add_imx_i2c1(NULL); 503 imx31_add_imx_i2c1(NULL);
diff --git a/arch/arm/mach-imx/mach-kzm_arm11_01.c b/arch/arm/mach-imx/mach-kzm_arm11_01.c
index fc78e8071cd1..15a26e908260 100644
--- a/arch/arm/mach-imx/mach-kzm_arm11_01.c
+++ b/arch/arm/mach-imx/mach-kzm_arm11_01.c
@@ -24,6 +24,8 @@
24#include <linux/serial_8250.h> 24#include <linux/serial_8250.h>
25#include <linux/smsc911x.h> 25#include <linux/smsc911x.h>
26#include <linux/types.h> 26#include <linux/types.h>
27#include <linux/regulator/machine.h>
28#include <linux/regulator/fixed.h>
27 29
28#include <asm/irq.h> 30#include <asm/irq.h>
29#include <asm/mach-types.h> 31#include <asm/mach-types.h>
@@ -166,6 +168,11 @@ static struct platform_device kzm_smsc9118_device = {
166 }, 168 },
167}; 169};
168 170
171static struct regulator_consumer_supply dummy_supplies[] = {
172 REGULATOR_SUPPLY("vdd33a", "smsc911x"),
173 REGULATOR_SUPPLY("vddvario", "smsc911x"),
174};
175
169static int __init kzm_init_smsc9118(void) 176static int __init kzm_init_smsc9118(void)
170{ 177{
171 /* 178 /*
@@ -175,6 +182,8 @@ static int __init kzm_init_smsc9118(void)
175 gpio_request(IOMUX_TO_GPIO(MX31_PIN_GPIO1_2), "smsc9118-int"); 182 gpio_request(IOMUX_TO_GPIO(MX31_PIN_GPIO1_2), "smsc9118-int");
176 gpio_direction_input(IOMUX_TO_GPIO(MX31_PIN_GPIO1_2)); 183 gpio_direction_input(IOMUX_TO_GPIO(MX31_PIN_GPIO1_2));
177 184
185 regulator_register_fixed(0, dummy_supplies, ARRAY_SIZE(dummy_supplies));
186
178 return platform_device_register(&kzm_smsc9118_device); 187 return platform_device_register(&kzm_smsc9118_device);
179} 188}
180#else 189#else
diff --git a/arch/arm/mach-imx/mach-mx31_3ds.c b/arch/arm/mach-imx/mach-mx31_3ds.c
index 4d1aab154400..4eafdf275ea2 100644
--- a/arch/arm/mach-imx/mach-mx31_3ds.c
+++ b/arch/arm/mach-imx/mach-mx31_3ds.c
@@ -156,6 +156,11 @@ static int mx31_3ds_pins[] = {
156 MX31_PIN_CSI_VSYNC__CSI_VSYNC, 156 MX31_PIN_CSI_VSYNC__CSI_VSYNC,
157 MX31_PIN_CSI_D5__GPIO3_5, /* CMOS PWDN */ 157 MX31_PIN_CSI_D5__GPIO3_5, /* CMOS PWDN */
158 IOMUX_MODE(MX31_PIN_RI_DTE1, IOMUX_CONFIG_GPIO), /* CMOS reset */ 158 IOMUX_MODE(MX31_PIN_RI_DTE1, IOMUX_CONFIG_GPIO), /* CMOS reset */
159 /* SSI */
160 MX31_PIN_STXD4__STXD4,
161 MX31_PIN_SRXD4__SRXD4,
162 MX31_PIN_SCK4__SCK4,
163 MX31_PIN_SFS4__SFS4,
159}; 164};
160 165
161/* 166/*
@@ -488,12 +493,23 @@ static struct mc13xxx_regulator_init_data mx31_3ds_regulators[] = {
488}; 493};
489 494
490/* MC13783 */ 495/* MC13783 */
496static struct mc13xxx_codec_platform_data mx31_3ds_codec = {
497 .dac_ssi_port = MC13783_SSI1_PORT,
498 .adc_ssi_port = MC13783_SSI1_PORT,
499};
500
491static struct mc13xxx_platform_data mc13783_pdata = { 501static struct mc13xxx_platform_data mc13783_pdata = {
492 .regulators = { 502 .regulators = {
493 .regulators = mx31_3ds_regulators, 503 .regulators = mx31_3ds_regulators,
494 .num_regulators = ARRAY_SIZE(mx31_3ds_regulators), 504 .num_regulators = ARRAY_SIZE(mx31_3ds_regulators),
495 }, 505 },
496 .flags = MC13XXX_USE_TOUCHSCREEN | MC13XXX_USE_RTC, 506 .codec = &mx31_3ds_codec,
507 .flags = MC13XXX_USE_TOUCHSCREEN | MC13XXX_USE_RTC | MC13XXX_USE_CODEC,
508
509};
510
511static struct imx_ssi_platform_data mx31_3ds_ssi_pdata = {
512 .flags = IMX_SSI_DMA | IMX_SSI_NET,
497}; 513};
498 514
499/* SPI */ 515/* SPI */
@@ -741,6 +757,10 @@ static void __init mx31_3ds_init(void)
741 } 757 }
742 758
743 mx31_3ds_init_camera(); 759 mx31_3ds_init_camera();
760
761 imx31_add_imx_ssi(0, &mx31_3ds_ssi_pdata);
762
763 imx_add_platform_device("imx_mc13783", 0, NULL, 0, NULL, 0);
744} 764}
745 765
746static void __init mx31_3ds_timer_init(void) 766static void __init mx31_3ds_timer_init(void)
diff --git a/arch/arm/mach-imx/mach-mx31lilly.c b/arch/arm/mach-imx/mach-mx31lilly.c
index 02401bbd6d53..83714b0cc290 100644
--- a/arch/arm/mach-imx/mach-mx31lilly.c
+++ b/arch/arm/mach-imx/mach-mx31lilly.c
@@ -34,6 +34,8 @@
34#include <linux/mfd/mc13783.h> 34#include <linux/mfd/mc13783.h>
35#include <linux/usb/otg.h> 35#include <linux/usb/otg.h>
36#include <linux/usb/ulpi.h> 36#include <linux/usb/ulpi.h>
37#include <linux/regulator/machine.h>
38#include <linux/regulator/fixed.h>
37 39
38#include <asm/mach-types.h> 40#include <asm/mach-types.h>
39#include <asm/mach/arch.h> 41#include <asm/mach/arch.h>
@@ -242,6 +244,11 @@ static struct platform_device *devices[] __initdata = {
242static int mx31lilly_baseboard; 244static int mx31lilly_baseboard;
243core_param(mx31lilly_baseboard, mx31lilly_baseboard, int, 0444); 245core_param(mx31lilly_baseboard, mx31lilly_baseboard, int, 0444);
244 246
247static struct regulator_consumer_supply dummy_supplies[] = {
248 REGULATOR_SUPPLY("vdd33a", "smsc911x"),
249 REGULATOR_SUPPLY("vddvario", "smsc911x"),
250};
251
245static void __init mx31lilly_board_init(void) 252static void __init mx31lilly_board_init(void)
246{ 253{
247 imx31_soc_init(); 254 imx31_soc_init();
@@ -280,6 +287,8 @@ static void __init mx31lilly_board_init(void)
280 imx31_add_spi_imx1(&spi1_pdata); 287 imx31_add_spi_imx1(&spi1_pdata);
281 spi_register_board_info(&mc13783_dev, 1); 288 spi_register_board_info(&mc13783_dev, 1);
282 289
290 regulator_register_fixed(0, dummy_supplies, ARRAY_SIZE(dummy_supplies));
291
283 platform_add_devices(devices, ARRAY_SIZE(devices)); 292 platform_add_devices(devices, ARRAY_SIZE(devices));
284 293
285 /* USB */ 294 /* USB */
diff --git a/arch/arm/mach-imx/mach-mx31lite.c b/arch/arm/mach-imx/mach-mx31lite.c
index ef80751712e7..0abef5f13df5 100644
--- a/arch/arm/mach-imx/mach-mx31lite.c
+++ b/arch/arm/mach-imx/mach-mx31lite.c
@@ -29,6 +29,8 @@
29#include <linux/usb/ulpi.h> 29#include <linux/usb/ulpi.h>
30#include <linux/mtd/physmap.h> 30#include <linux/mtd/physmap.h>
31#include <linux/delay.h> 31#include <linux/delay.h>
32#include <linux/regulator/machine.h>
33#include <linux/regulator/fixed.h>
32 34
33#include <asm/mach-types.h> 35#include <asm/mach-types.h>
34#include <asm/mach/arch.h> 36#include <asm/mach/arch.h>
@@ -226,6 +228,11 @@ void __init mx31lite_map_io(void)
226static int mx31lite_baseboard; 228static int mx31lite_baseboard;
227core_param(mx31lite_baseboard, mx31lite_baseboard, int, 0444); 229core_param(mx31lite_baseboard, mx31lite_baseboard, int, 0444);
228 230
231static struct regulator_consumer_supply dummy_supplies[] = {
232 REGULATOR_SUPPLY("vdd33a", "smsc911x"),
233 REGULATOR_SUPPLY("vddvario", "smsc911x"),
234};
235
229static void __init mx31lite_init(void) 236static void __init mx31lite_init(void)
230{ 237{
231 int ret; 238 int ret;
@@ -259,6 +266,8 @@ static void __init mx31lite_init(void)
259 if (usbh2_pdata.otg) 266 if (usbh2_pdata.otg)
260 imx31_add_mxc_ehci_hs(2, &usbh2_pdata); 267 imx31_add_mxc_ehci_hs(2, &usbh2_pdata);
261 268
269 regulator_register_fixed(0, dummy_supplies, ARRAY_SIZE(dummy_supplies));
270
262 /* SMSC9117 IRQ pin */ 271 /* SMSC9117 IRQ pin */
263 ret = gpio_request(IOMUX_TO_GPIO(MX31_PIN_SFS6), "sms9117-irq"); 272 ret = gpio_request(IOMUX_TO_GPIO(MX31_PIN_SFS6), "sms9117-irq");
264 if (ret) 273 if (ret)
diff --git a/arch/arm/mach-imx/mach-mx31moboard.c b/arch/arm/mach-imx/mach-mx31moboard.c
index f17a15f28316..31e5b3d5da73 100644
--- a/arch/arm/mach-imx/mach-mx31moboard.c
+++ b/arch/arm/mach-imx/mach-mx31moboard.c
@@ -47,6 +47,7 @@
47#include <mach/hardware.h> 47#include <mach/hardware.h>
48#include <mach/iomux-mx3.h> 48#include <mach/iomux-mx3.h>
49#include <mach/ulpi.h> 49#include <mach/ulpi.h>
50#include <mach/ssi.h>
50 51
51#include "devices-imx31.h" 52#include "devices-imx31.h"
52 53
@@ -102,6 +103,9 @@ static unsigned int moboard_pins[] = {
102 MX31_PIN_CSPI3_MOSI__MOSI, MX31_PIN_CSPI3_MISO__MISO, 103 MX31_PIN_CSPI3_MOSI__MOSI, MX31_PIN_CSPI3_MISO__MISO,
103 MX31_PIN_CSPI3_SCLK__SCLK, MX31_PIN_CSPI3_SPI_RDY__SPI_RDY, 104 MX31_PIN_CSPI3_SCLK__SCLK, MX31_PIN_CSPI3_SPI_RDY__SPI_RDY,
104 MX31_PIN_CSPI2_SS1__CSPI3_SS1, 105 MX31_PIN_CSPI2_SS1__CSPI3_SS1,
106 /* SSI */
107 MX31_PIN_STXD4__STXD4, MX31_PIN_SRXD4__SRXD4,
108 MX31_PIN_SCK4__SCK4, MX31_PIN_SFS4__SFS4,
105}; 109};
106 110
107static struct physmap_flash_data mx31moboard_flash_data = { 111static struct physmap_flash_data mx31moboard_flash_data = {
@@ -276,6 +280,11 @@ static struct mc13xxx_buttons_platform_data moboard_buttons = {
276 .b1on_key = KEY_POWER, 280 .b1on_key = KEY_POWER,
277}; 281};
278 282
283static struct mc13xxx_codec_platform_data moboard_codec = {
284 .dac_ssi_port = MC13783_SSI1_PORT,
285 .adc_ssi_port = MC13783_SSI1_PORT,
286};
287
279static struct mc13xxx_platform_data moboard_pmic = { 288static struct mc13xxx_platform_data moboard_pmic = {
280 .regulators = { 289 .regulators = {
281 .regulators = moboard_regulators, 290 .regulators = moboard_regulators,
@@ -283,7 +292,12 @@ static struct mc13xxx_platform_data moboard_pmic = {
283 }, 292 },
284 .leds = &moboard_leds, 293 .leds = &moboard_leds,
285 .buttons = &moboard_buttons, 294 .buttons = &moboard_buttons,
286 .flags = MC13XXX_USE_RTC | MC13XXX_USE_ADC, 295 .codec = &moboard_codec,
296 .flags = MC13XXX_USE_RTC | MC13XXX_USE_ADC | MC13XXX_USE_CODEC,
297};
298
299static struct imx_ssi_platform_data moboard_ssi_pdata = {
300 .flags = IMX_SSI_DMA | IMX_SSI_NET,
287}; 301};
288 302
289static struct spi_board_info moboard_spi_board_info[] __initdata = { 303static struct spi_board_info moboard_spi_board_info[] __initdata = {
@@ -554,6 +568,10 @@ static void __init mx31moboard_init(void)
554 568
555 moboard_usbh2_init(); 569 moboard_usbh2_init();
556 570
571 imx31_add_imx_ssi(0, &moboard_ssi_pdata);
572
573 imx_add_platform_device("imx_mc13783", 0, NULL, 0, NULL, 0);
574
557 pm_power_off = mx31moboard_poweroff; 575 pm_power_off = mx31moboard_poweroff;
558 576
559 switch (mx31moboard_baseboard) { 577 switch (mx31moboard_baseboard) {
diff --git a/arch/arm/mach-imx/mach-mx35_3ds.c b/arch/arm/mach-imx/mach-mx35_3ds.c
index e14291d89e4f..6ae51c6b95b7 100644
--- a/arch/arm/mach-imx/mach-mx35_3ds.c
+++ b/arch/arm/mach-imx/mach-mx35_3ds.c
@@ -97,7 +97,7 @@ static struct i2c_board_info __initdata i2c_devices_3ds[] = {
97static int lcd_power_gpio = -ENXIO; 97static int lcd_power_gpio = -ENXIO;
98 98
99static int mc9s08dz60_gpiochip_match(struct gpio_chip *chip, 99static int mc9s08dz60_gpiochip_match(struct gpio_chip *chip,
100 void *data) 100 const void *data)
101{ 101{
102 return !strcmp(chip->label, data); 102 return !strcmp(chip->label, data);
103} 103}
diff --git a/arch/arm/mach-imx/mach-mx53_ard.c b/arch/arm/mach-imx/mach-mx53_ard.c
index 753f4fc9ec04..05641980dc5e 100644
--- a/arch/arm/mach-imx/mach-mx53_ard.c
+++ b/arch/arm/mach-imx/mach-mx53_ard.c
@@ -23,6 +23,8 @@
23#include <linux/delay.h> 23#include <linux/delay.h>
24#include <linux/gpio.h> 24#include <linux/gpio.h>
25#include <linux/smsc911x.h> 25#include <linux/smsc911x.h>
26#include <linux/regulator/machine.h>
27#include <linux/regulator/fixed.h>
26 28
27#include <mach/common.h> 29#include <mach/common.h>
28#include <mach/hardware.h> 30#include <mach/hardware.h>
@@ -214,6 +216,11 @@ static int weim_cs_config(void)
214 return 0; 216 return 0;
215} 217}
216 218
219static struct regulator_consumer_supply dummy_supplies[] = {
220 REGULATOR_SUPPLY("vdd33a", "smsc911x"),
221 REGULATOR_SUPPLY("vddvario", "smsc911x"),
222};
223
217void __init imx53_ard_common_init(void) 224void __init imx53_ard_common_init(void)
218{ 225{
219 mxc_iomux_v3_setup_multiple_pads(mx53_ard_pads, 226 mxc_iomux_v3_setup_multiple_pads(mx53_ard_pads,
@@ -232,6 +239,7 @@ static void __init mx53_ard_board_init(void)
232 239
233 imx53_ard_common_init(); 240 imx53_ard_common_init();
234 mx53_ard_io_init(); 241 mx53_ard_io_init();
242 regulator_register_fixed(0, dummy_supplies, ARRAY_SIZE(dummy_supplies));
235 platform_add_devices(devices, ARRAY_SIZE(devices)); 243 platform_add_devices(devices, ARRAY_SIZE(devices));
236 244
237 imx53_add_sdhci_esdhc_imx(0, &mx53_ard_sd1_data); 245 imx53_add_sdhci_esdhc_imx(0, &mx53_ard_sd1_data);
diff --git a/arch/arm/mach-imx/mm-imx5.c b/arch/arm/mach-imx/mm-imx5.c
index 05250aed61fb..e10f3914fcfe 100644
--- a/arch/arm/mach-imx/mm-imx5.c
+++ b/arch/arm/mach-imx/mm-imx5.c
@@ -35,7 +35,7 @@ static void imx5_idle(void)
35 } 35 }
36 clk_enable(gpc_dvfs_clk); 36 clk_enable(gpc_dvfs_clk);
37 mx5_cpu_lp_set(WAIT_UNCLOCKED_POWER_OFF); 37 mx5_cpu_lp_set(WAIT_UNCLOCKED_POWER_OFF);
38 if (tzic_enable_wake() != 0) 38 if (!tzic_enable_wake())
39 cpu_do_idle(); 39 cpu_do_idle();
40 clk_disable(gpc_dvfs_clk); 40 clk_disable(gpc_dvfs_clk);
41} 41}
diff --git a/arch/arm/mach-kirkwood/board-dt.c b/arch/arm/mach-kirkwood/board-dt.c
index 1c672d9e6656..f7fe1b9f3170 100644
--- a/arch/arm/mach-kirkwood/board-dt.c
+++ b/arch/arm/mach-kirkwood/board-dt.c
@@ -14,6 +14,7 @@
14#include <linux/init.h> 14#include <linux/init.h>
15#include <linux/of.h> 15#include <linux/of.h>
16#include <linux/of_platform.h> 16#include <linux/of_platform.h>
17#include <linux/kexec.h>
17#include <asm/mach/arch.h> 18#include <asm/mach/arch.h>
18#include <asm/mach/map.h> 19#include <asm/mach/map.h>
19#include <mach/bridge-regs.h> 20#include <mach/bridge-regs.h>
diff --git a/arch/arm/mach-msm/board-halibut.c b/arch/arm/mach-msm/board-halibut.c
index 3698a370d636..26aac363a064 100644
--- a/arch/arm/mach-msm/board-halibut.c
+++ b/arch/arm/mach-msm/board-halibut.c
@@ -86,9 +86,6 @@ static void __init halibut_init(void)
86static void __init halibut_fixup(struct tag *tags, char **cmdline, 86static void __init halibut_fixup(struct tag *tags, char **cmdline,
87 struct meminfo *mi) 87 struct meminfo *mi)
88{ 88{
89 mi->nr_banks=1;
90 mi->bank[0].start = PHYS_OFFSET;
91 mi->bank[0].size = (101*1024*1024);
92} 89}
93 90
94static void __init halibut_map_io(void) 91static void __init halibut_map_io(void)
diff --git a/arch/arm/mach-msm/board-msm8x60.c b/arch/arm/mach-msm/board-msm8x60.c
index 962e71169750..fb3496a52ef4 100644
--- a/arch/arm/mach-msm/board-msm8x60.c
+++ b/arch/arm/mach-msm/board-msm8x60.c
@@ -17,6 +17,7 @@
17#include <linux/irqdomain.h> 17#include <linux/irqdomain.h>
18#include <linux/of.h> 18#include <linux/of.h>
19#include <linux/of_address.h> 19#include <linux/of_address.h>
20#include <linux/of_irq.h>
20#include <linux/of_platform.h> 21#include <linux/of_platform.h>
21#include <linux/memblock.h> 22#include <linux/memblock.h>
22 23
@@ -49,10 +50,22 @@ static void __init msm8x60_map_io(void)
49 msm_map_msm8x60_io(); 50 msm_map_msm8x60_io();
50} 51}
51 52
53#ifdef CONFIG_OF
54static struct of_device_id msm_dt_gic_match[] __initdata = {
55 { .compatible = "qcom,msm-8660-qgic", .data = gic_of_init },
56 {}
57};
58#endif
59
52static void __init msm8x60_init_irq(void) 60static void __init msm8x60_init_irq(void)
53{ 61{
54 gic_init(0, GIC_PPI_START, MSM_QGIC_DIST_BASE, 62 if (!of_have_populated_dt())
55 (void *)MSM_QGIC_CPU_BASE); 63 gic_init(0, GIC_PPI_START, MSM_QGIC_DIST_BASE,
64 (void *)MSM_QGIC_CPU_BASE);
65#ifdef CONFIG_OF
66 else
67 of_irq_init(msm_dt_gic_match);
68#endif
56 69
57 /* Edge trigger PPIs except AVS_SVICINT and AVS_SVICINTSWDONE */ 70 /* Edge trigger PPIs except AVS_SVICINT and AVS_SVICINTSWDONE */
58 writel(0xFFFFD7FF, MSM_QGIC_DIST_BASE + GIC_DIST_CONFIG + 4); 71 writel(0xFFFFD7FF, MSM_QGIC_DIST_BASE + GIC_DIST_CONFIG + 4);
@@ -73,16 +86,8 @@ static struct of_dev_auxdata msm_auxdata_lookup[] __initdata = {
73 {} 86 {}
74}; 87};
75 88
76static struct of_device_id msm_dt_gic_match[] __initdata = {
77 { .compatible = "qcom,msm-8660-qgic", },
78 {}
79};
80
81static void __init msm8x60_dt_init(void) 89static void __init msm8x60_dt_init(void)
82{ 90{
83 irq_domain_generate_simple(msm_dt_gic_match, MSM8X60_QGIC_DIST_PHYS,
84 GIC_SPI_START);
85
86 if (of_machine_is_compatible("qcom,msm8660-surf")) { 91 if (of_machine_is_compatible("qcom,msm8660-surf")) {
87 printk(KERN_INFO "Init surf UART registers\n"); 92 printk(KERN_INFO "Init surf UART registers\n");
88 msm8x60_init_uart12dm(); 93 msm8x60_init_uart12dm();
diff --git a/arch/arm/mach-msm/board-trout-panel.c b/arch/arm/mach-msm/board-trout-panel.c
index 25105c1027fe..89bf6b426699 100644
--- a/arch/arm/mach-msm/board-trout-panel.c
+++ b/arch/arm/mach-msm/board-trout-panel.c
@@ -12,6 +12,7 @@
12 12
13#include <asm/io.h> 13#include <asm/io.h>
14#include <asm/mach-types.h> 14#include <asm/mach-types.h>
15#include <asm/system_info.h>
15 16
16#include <mach/msm_fb.h> 17#include <mach/msm_fb.h>
17#include <mach/vreg.h> 18#include <mach/vreg.h>
diff --git a/arch/arm/mach-msm/board-trout.c b/arch/arm/mach-msm/board-trout.c
index 5414f76ec0a9..d4060a37e23d 100644
--- a/arch/arm/mach-msm/board-trout.c
+++ b/arch/arm/mach-msm/board-trout.c
@@ -19,6 +19,7 @@
19#include <linux/platform_device.h> 19#include <linux/platform_device.h>
20#include <linux/clkdev.h> 20#include <linux/clkdev.h>
21 21
22#include <asm/system_info.h>
22#include <asm/mach-types.h> 23#include <asm/mach-types.h>
23#include <asm/mach/arch.h> 24#include <asm/mach/arch.h>
24#include <asm/mach/map.h> 25#include <asm/mach/map.h>
diff --git a/arch/arm/mach-msm/include/mach/uncompress.h b/arch/arm/mach-msm/include/mach/uncompress.h
index 169a84007456..c14011fe832d 100644
--- a/arch/arm/mach-msm/include/mach/uncompress.h
+++ b/arch/arm/mach-msm/include/mach/uncompress.h
@@ -16,6 +16,7 @@
16#ifndef __ASM_ARCH_MSM_UNCOMPRESS_H 16#ifndef __ASM_ARCH_MSM_UNCOMPRESS_H
17#define __ASM_ARCH_MSM_UNCOMPRESS_H 17#define __ASM_ARCH_MSM_UNCOMPRESS_H
18 18
19#include <asm/barrier.h>
19#include <asm/processor.h> 20#include <asm/processor.h>
20#include <mach/msm_iomap.h> 21#include <mach/msm_iomap.h>
21 22
diff --git a/arch/arm/mach-msm/proc_comm.c b/arch/arm/mach-msm/proc_comm.c
index 67e701c7f183..9980dc736e7b 100644
--- a/arch/arm/mach-msm/proc_comm.c
+++ b/arch/arm/mach-msm/proc_comm.c
@@ -121,7 +121,7 @@ int msm_proc_comm(unsigned cmd, unsigned *data1, unsigned *data2)
121 * and unknown state. This function should be called early to 121 * and unknown state. This function should be called early to
122 * wait on the ARM9. 122 * wait on the ARM9.
123 */ 123 */
124void __init proc_comm_boot_wait(void) 124void __devinit proc_comm_boot_wait(void)
125{ 125{
126 void __iomem *base = MSM_SHARED_RAM_BASE; 126 void __iomem *base = MSM_SHARED_RAM_BASE;
127 127
diff --git a/arch/arm/mach-msm/smd_debug.c b/arch/arm/mach-msm/smd_debug.c
index 0c56a5aaf588..c56df9e932ae 100644
--- a/arch/arm/mach-msm/smd_debug.c
+++ b/arch/arm/mach-msm/smd_debug.c
@@ -203,15 +203,9 @@ static ssize_t debug_read(struct file *file, char __user *buf,
203 return simple_read_from_buffer(buf, count, ppos, debug_buffer, bsize); 203 return simple_read_from_buffer(buf, count, ppos, debug_buffer, bsize);
204} 204}
205 205
206static int debug_open(struct inode *inode, struct file *file)
207{
208 file->private_data = inode->i_private;
209 return 0;
210}
211
212static const struct file_operations debug_ops = { 206static const struct file_operations debug_ops = {
213 .read = debug_read, 207 .read = debug_read,
214 .open = debug_open, 208 .open = simple_open,
215 .llseek = default_llseek, 209 .llseek = default_llseek,
216}; 210};
217 211
diff --git a/arch/arm/mach-omap1/ams-delta-fiq.c b/arch/arm/mach-omap1/ams-delta-fiq.c
index fcce7ff37630..cfd98b186fcc 100644
--- a/arch/arm/mach-omap1/ams-delta-fiq.c
+++ b/arch/arm/mach-omap1/ams-delta-fiq.c
@@ -48,7 +48,7 @@ static irqreturn_t deferred_fiq(int irq, void *dev_id)
48 struct irq_chip *irq_chip = NULL; 48 struct irq_chip *irq_chip = NULL;
49 int gpio, irq_num, fiq_count; 49 int gpio, irq_num, fiq_count;
50 50
51 irq_desc = irq_to_desc(IH_GPIO_BASE); 51 irq_desc = irq_to_desc(gpio_to_irq(AMS_DELTA_GPIO_PIN_KEYBRD_CLK));
52 if (irq_desc) 52 if (irq_desc)
53 irq_chip = irq_desc->irq_data.chip; 53 irq_chip = irq_desc->irq_data.chip;
54 54
diff --git a/arch/arm/mach-omap1/include/mach/io.h b/arch/arm/mach-omap1/include/mach/io.h
new file mode 100644
index 000000000000..ce4f8005b26f
--- /dev/null
+++ b/arch/arm/mach-omap1/include/mach/io.h
@@ -0,0 +1,45 @@
1/*
2 * arch/arm/mach-omap1/include/mach/io.h
3 *
4 * IO definitions for TI OMAP processors and boards
5 *
6 * Copied from arch/arm/mach-sa1100/include/mach/io.h
7 * Copyright (C) 1997-1999 Russell King
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
13 *
14 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
17 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
20 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
21 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 *
25 * You should have received a copy of the GNU General Public License along
26 * with this program; if not, write to the Free Software Foundation, Inc.,
27 * 675 Mass Ave, Cambridge, MA 02139, USA.
28 *
29 * Modifications:
30 * 06-12-1997 RMK Created.
31 * 07-04-1999 RMK Major cleanup
32 */
33
34#ifndef __ASM_ARM_ARCH_IO_H
35#define __ASM_ARM_ARCH_IO_H
36
37#define IO_SPACE_LIMIT 0xffffffff
38
39/*
40 * We don't actually have real ISA nor PCI buses, but there is so many
41 * drivers out there that might just work if we fake them...
42 */
43#define __io(a) __typesafe_io(a)
44
45#endif
diff --git a/arch/arm/mach-omap1/mux.c b/arch/arm/mach-omap1/mux.c
index 087dba0df47e..e9cc52d4cb28 100644
--- a/arch/arm/mach-omap1/mux.c
+++ b/arch/arm/mach-omap1/mux.c
@@ -27,6 +27,7 @@
27#include <linux/io.h> 27#include <linux/io.h>
28#include <linux/spinlock.h> 28#include <linux/spinlock.h>
29 29
30#include <mach/hardware.h>
30 31
31#include <plat/mux.h> 32#include <plat/mux.h>
32 33
diff --git a/arch/arm/mach-omap1/timer.c b/arch/arm/mach-omap1/timer.c
index 6e90665a7c47..fb202af01d0d 100644
--- a/arch/arm/mach-omap1/timer.c
+++ b/arch/arm/mach-omap1/timer.c
@@ -47,9 +47,9 @@ static int omap1_dm_timer_set_src(struct platform_device *pdev,
47 int n = (pdev->id - 1) << 1; 47 int n = (pdev->id - 1) << 1;
48 u32 l; 48 u32 l;
49 49
50 l = __raw_readl(MOD_CONF_CTRL_1) & ~(0x03 << n); 50 l = omap_readl(MOD_CONF_CTRL_1) & ~(0x03 << n);
51 l |= source << n; 51 l |= source << n;
52 __raw_writel(l, MOD_CONF_CTRL_1); 52 omap_writel(l, MOD_CONF_CTRL_1);
53 53
54 return 0; 54 return 0;
55} 55}
diff --git a/arch/arm/mach-omap2/board-4430sdp.c b/arch/arm/mach-omap2/board-4430sdp.c
index a39fc4bbd2b8..130ab00c09a2 100644
--- a/arch/arm/mach-omap2/board-4430sdp.c
+++ b/arch/arm/mach-omap2/board-4430sdp.c
@@ -20,6 +20,7 @@
20#include <linux/usb/otg.h> 20#include <linux/usb/otg.h>
21#include <linux/spi/spi.h> 21#include <linux/spi/spi.h>
22#include <linux/i2c/twl.h> 22#include <linux/i2c/twl.h>
23#include <linux/mfd/twl6040.h>
23#include <linux/gpio_keys.h> 24#include <linux/gpio_keys.h>
24#include <linux/regulator/machine.h> 25#include <linux/regulator/machine.h>
25#include <linux/regulator/fixed.h> 26#include <linux/regulator/fixed.h>
@@ -560,7 +561,7 @@ static struct regulator_init_data sdp4430_vusim = {
560 }, 561 },
561}; 562};
562 563
563static struct twl4030_codec_data twl6040_codec = { 564static struct twl6040_codec_data twl6040_codec = {
564 /* single-step ramp for headset and handsfree */ 565 /* single-step ramp for headset and handsfree */
565 .hs_left_step = 0x0f, 566 .hs_left_step = 0x0f,
566 .hs_right_step = 0x0f, 567 .hs_right_step = 0x0f,
@@ -568,7 +569,7 @@ static struct twl4030_codec_data twl6040_codec = {
568 .hf_right_step = 0x1d, 569 .hf_right_step = 0x1d,
569}; 570};
570 571
571static struct twl4030_vibra_data twl6040_vibra = { 572static struct twl6040_vibra_data twl6040_vibra = {
572 .vibldrv_res = 8, 573 .vibldrv_res = 8,
573 .vibrdrv_res = 3, 574 .vibrdrv_res = 3,
574 .viblmotor_res = 10, 575 .viblmotor_res = 10,
@@ -577,16 +578,14 @@ static struct twl4030_vibra_data twl6040_vibra = {
577 .vddvibr_uV = 0, /* fixed volt supply - VBAT */ 578 .vddvibr_uV = 0, /* fixed volt supply - VBAT */
578}; 579};
579 580
580static struct twl4030_audio_data twl6040_audio = { 581static struct twl6040_platform_data twl6040_data = {
581 .codec = &twl6040_codec, 582 .codec = &twl6040_codec,
582 .vibra = &twl6040_vibra, 583 .vibra = &twl6040_vibra,
583 .audpwron_gpio = 127, 584 .audpwron_gpio = 127,
584 .naudint_irq = OMAP44XX_IRQ_SYS_2N,
585 .irq_base = TWL6040_CODEC_IRQ_BASE, 585 .irq_base = TWL6040_CODEC_IRQ_BASE,
586}; 586};
587 587
588static struct twl4030_platform_data sdp4430_twldata = { 588static struct twl4030_platform_data sdp4430_twldata = {
589 .audio = &twl6040_audio,
590 /* Regulators */ 589 /* Regulators */
591 .vusim = &sdp4430_vusim, 590 .vusim = &sdp4430_vusim,
592 .vaux1 = &sdp4430_vaux1, 591 .vaux1 = &sdp4430_vaux1,
@@ -617,7 +616,8 @@ static int __init omap4_i2c_init(void)
617 TWL_COMMON_REGULATOR_VCXIO | 616 TWL_COMMON_REGULATOR_VCXIO |
618 TWL_COMMON_REGULATOR_VUSB | 617 TWL_COMMON_REGULATOR_VUSB |
619 TWL_COMMON_REGULATOR_CLK32KG); 618 TWL_COMMON_REGULATOR_CLK32KG);
620 omap4_pmic_init("twl6030", &sdp4430_twldata); 619 omap4_pmic_init("twl6030", &sdp4430_twldata,
620 &twl6040_data, OMAP44XX_IRQ_SYS_2N);
621 omap_register_i2c_bus(2, 400, NULL, 0); 621 omap_register_i2c_bus(2, 400, NULL, 0);
622 omap_register_i2c_bus(3, 400, sdp4430_i2c_3_boardinfo, 622 omap_register_i2c_bus(3, 400, sdp4430_i2c_3_boardinfo,
623 ARRAY_SIZE(sdp4430_i2c_3_boardinfo)); 623 ARRAY_SIZE(sdp4430_i2c_3_boardinfo));
diff --git a/arch/arm/mach-omap2/board-cm-t35.c b/arch/arm/mach-omap2/board-cm-t35.c
index 41b0a2fe0b04..909a8b91b564 100644
--- a/arch/arm/mach-omap2/board-cm-t35.c
+++ b/arch/arm/mach-omap2/board-cm-t35.c
@@ -26,6 +26,7 @@
26 26
27#include <linux/i2c/at24.h> 27#include <linux/i2c/at24.h>
28#include <linux/i2c/twl.h> 28#include <linux/i2c/twl.h>
29#include <linux/regulator/fixed.h>
29#include <linux/regulator/machine.h> 30#include <linux/regulator/machine.h>
30#include <linux/mmc/host.h> 31#include <linux/mmc/host.h>
31 32
@@ -81,8 +82,23 @@ static struct omap_smsc911x_platform_data sb_t35_smsc911x_cfg = {
81 .flags = SMSC911X_USE_32BIT | SMSC911X_SAVE_MAC_ADDRESS, 82 .flags = SMSC911X_USE_32BIT | SMSC911X_SAVE_MAC_ADDRESS,
82}; 83};
83 84
85static struct regulator_consumer_supply cm_t35_smsc911x_supplies[] = {
86 REGULATOR_SUPPLY("vddvario", "smsc911x.0"),
87 REGULATOR_SUPPLY("vdd33a", "smsc911x.0"),
88};
89
90static struct regulator_consumer_supply sb_t35_smsc911x_supplies[] = {
91 REGULATOR_SUPPLY("vddvario", "smsc911x.1"),
92 REGULATOR_SUPPLY("vdd33a", "smsc911x.1"),
93};
94
84static void __init cm_t35_init_ethernet(void) 95static void __init cm_t35_init_ethernet(void)
85{ 96{
97 regulator_register_fixed(0, cm_t35_smsc911x_supplies,
98 ARRAY_SIZE(cm_t35_smsc911x_supplies));
99 regulator_register_fixed(1, sb_t35_smsc911x_supplies,
100 ARRAY_SIZE(sb_t35_smsc911x_supplies));
101
86 gpmc_smsc911x_init(&cm_t35_smsc911x_cfg); 102 gpmc_smsc911x_init(&cm_t35_smsc911x_cfg);
87 gpmc_smsc911x_init(&sb_t35_smsc911x_cfg); 103 gpmc_smsc911x_init(&sb_t35_smsc911x_cfg);
88} 104}
diff --git a/arch/arm/mach-omap2/board-generic.c b/arch/arm/mach-omap2/board-generic.c
index 74e1687b5170..098d183a0086 100644
--- a/arch/arm/mach-omap2/board-generic.c
+++ b/arch/arm/mach-omap2/board-generic.c
@@ -137,7 +137,7 @@ static struct twl4030_platform_data sdp4430_twldata = {
137 137
138static void __init omap4_i2c_init(void) 138static void __init omap4_i2c_init(void)
139{ 139{
140 omap4_pmic_init("twl6030", &sdp4430_twldata); 140 omap4_pmic_init("twl6030", &sdp4430_twldata, NULL, 0);
141} 141}
142 142
143static void __init omap4_init(void) 143static void __init omap4_init(void)
diff --git a/arch/arm/mach-omap2/board-igep0020.c b/arch/arm/mach-omap2/board-igep0020.c
index e558800adfdf..740cee9369ba 100644
--- a/arch/arm/mach-omap2/board-igep0020.c
+++ b/arch/arm/mach-omap2/board-igep0020.c
@@ -634,8 +634,14 @@ static void __init igep_wlan_bt_init(void)
634static inline void __init igep_wlan_bt_init(void) { } 634static inline void __init igep_wlan_bt_init(void) { }
635#endif 635#endif
636 636
637static struct regulator_consumer_supply dummy_supplies[] = {
638 REGULATOR_SUPPLY("vddvario", "smsc911x.0"),
639 REGULATOR_SUPPLY("vdd33a", "smsc911x.0"),
640};
641
637static void __init igep_init(void) 642static void __init igep_init(void)
638{ 643{
644 regulator_register_fixed(1, dummy_supplies, ARRAY_SIZE(dummy_supplies));
639 omap3_mux_init(board_mux, OMAP_PACKAGE_CBB); 645 omap3_mux_init(board_mux, OMAP_PACKAGE_CBB);
640 646
641 /* Get IGEP2 hardware revision */ 647 /* Get IGEP2 hardware revision */
diff --git a/arch/arm/mach-omap2/board-ldp.c b/arch/arm/mach-omap2/board-ldp.c
index d50a562adfa0..1b6049567ab4 100644
--- a/arch/arm/mach-omap2/board-ldp.c
+++ b/arch/arm/mach-omap2/board-ldp.c
@@ -22,6 +22,7 @@
22#include <linux/err.h> 22#include <linux/err.h>
23#include <linux/clk.h> 23#include <linux/clk.h>
24#include <linux/spi/spi.h> 24#include <linux/spi/spi.h>
25#include <linux/regulator/fixed.h>
25#include <linux/regulator/machine.h> 26#include <linux/regulator/machine.h>
26#include <linux/i2c/twl.h> 27#include <linux/i2c/twl.h>
27#include <linux/io.h> 28#include <linux/io.h>
@@ -410,8 +411,14 @@ static struct mtd_partition ldp_nand_partitions[] = {
410 411
411}; 412};
412 413
414static struct regulator_consumer_supply dummy_supplies[] = {
415 REGULATOR_SUPPLY("vddvario", "smsc911x.0"),
416 REGULATOR_SUPPLY("vdd33a", "smsc911x.0"),
417};
418
413static void __init omap_ldp_init(void) 419static void __init omap_ldp_init(void)
414{ 420{
421 regulator_register_fixed(0, dummy_supplies, ARRAY_SIZE(dummy_supplies));
415 omap3_mux_init(board_mux, OMAP_PACKAGE_CBB); 422 omap3_mux_init(board_mux, OMAP_PACKAGE_CBB);
416 ldp_init_smsc911x(); 423 ldp_init_smsc911x();
417 omap_i2c_init(); 424 omap_i2c_init();
diff --git a/arch/arm/mach-omap2/board-omap3evm.c b/arch/arm/mach-omap2/board-omap3evm.c
index 4c90f078abe1..49df12735b41 100644
--- a/arch/arm/mach-omap2/board-omap3evm.c
+++ b/arch/arm/mach-omap2/board-omap3evm.c
@@ -114,15 +114,6 @@ static struct omap_smsc911x_platform_data smsc911x_cfg = {
114 114
115static inline void __init omap3evm_init_smsc911x(void) 115static inline void __init omap3evm_init_smsc911x(void)
116{ 116{
117 struct clk *l3ck;
118 unsigned int rate;
119
120 l3ck = clk_get(NULL, "l3_ck");
121 if (IS_ERR(l3ck))
122 rate = 100000000;
123 else
124 rate = clk_get_rate(l3ck);
125
126 /* Configure ethernet controller reset gpio */ 117 /* Configure ethernet controller reset gpio */
127 if (cpu_is_omap3430()) { 118 if (cpu_is_omap3430()) {
128 if (get_omap3_evm_rev() == OMAP3EVM_BOARD_GEN_1) 119 if (get_omap3_evm_rev() == OMAP3EVM_BOARD_GEN_1)
@@ -632,9 +623,15 @@ static void __init omap3_evm_wl12xx_init(void)
632#endif 623#endif
633} 624}
634 625
626static struct regulator_consumer_supply dummy_supplies[] = {
627 REGULATOR_SUPPLY("vddvario", "smsc911x.0"),
628 REGULATOR_SUPPLY("vdd33a", "smsc911x.0"),
629};
630
635static void __init omap3_evm_init(void) 631static void __init omap3_evm_init(void)
636{ 632{
637 omap3_evm_get_revision(); 633 omap3_evm_get_revision();
634 regulator_register_fixed(0, dummy_supplies, ARRAY_SIZE(dummy_supplies));
638 635
639 if (cpu_is_omap3630()) 636 if (cpu_is_omap3630())
640 omap3_mux_init(omap36x_board_mux, OMAP_PACKAGE_CBB); 637 omap3_mux_init(omap36x_board_mux, OMAP_PACKAGE_CBB);
diff --git a/arch/arm/mach-omap2/board-omap3logic.c b/arch/arm/mach-omap2/board-omap3logic.c
index 4a7d8c8a75da..9b3c141ff51b 100644
--- a/arch/arm/mach-omap2/board-omap3logic.c
+++ b/arch/arm/mach-omap2/board-omap3logic.c
@@ -23,6 +23,7 @@
23#include <linux/io.h> 23#include <linux/io.h>
24#include <linux/gpio.h> 24#include <linux/gpio.h>
25 25
26#include <linux/regulator/fixed.h>
26#include <linux/regulator/machine.h> 27#include <linux/regulator/machine.h>
27 28
28#include <linux/i2c/twl.h> 29#include <linux/i2c/twl.h>
@@ -188,8 +189,14 @@ static struct omap_board_mux board_mux[] __initdata = {
188}; 189};
189#endif 190#endif
190 191
192static struct regulator_consumer_supply dummy_supplies[] = {
193 REGULATOR_SUPPLY("vddvario", "smsc911x.0"),
194 REGULATOR_SUPPLY("vdd33a", "smsc911x.0"),
195};
196
191static void __init omap3logic_init(void) 197static void __init omap3logic_init(void)
192{ 198{
199 regulator_register_fixed(0, dummy_supplies, ARRAY_SIZE(dummy_supplies));
193 omap3_mux_init(board_mux, OMAP_PACKAGE_CBB); 200 omap3_mux_init(board_mux, OMAP_PACKAGE_CBB);
194 omap3torpedo_fix_pbias_voltage(); 201 omap3torpedo_fix_pbias_voltage();
195 omap3logic_i2c_init(); 202 omap3logic_i2c_init();
diff --git a/arch/arm/mach-omap2/board-omap3stalker.c b/arch/arm/mach-omap2/board-omap3stalker.c
index 641004380795..4dffc95bddd2 100644
--- a/arch/arm/mach-omap2/board-omap3stalker.c
+++ b/arch/arm/mach-omap2/board-omap3stalker.c
@@ -24,6 +24,7 @@
24#include <linux/input.h> 24#include <linux/input.h>
25#include <linux/gpio_keys.h> 25#include <linux/gpio_keys.h>
26 26
27#include <linux/regulator/fixed.h>
27#include <linux/regulator/machine.h> 28#include <linux/regulator/machine.h>
28#include <linux/i2c/twl.h> 29#include <linux/i2c/twl.h>
29#include <linux/mmc/host.h> 30#include <linux/mmc/host.h>
@@ -72,15 +73,6 @@ static struct omap_smsc911x_platform_data smsc911x_cfg = {
72 73
73static inline void __init omap3stalker_init_eth(void) 74static inline void __init omap3stalker_init_eth(void)
74{ 75{
75 struct clk *l3ck;
76 unsigned int rate;
77
78 l3ck = clk_get(NULL, "l3_ck");
79 if (IS_ERR(l3ck))
80 rate = 100000000;
81 else
82 rate = clk_get_rate(l3ck);
83
84 omap_mux_init_gpio(19, OMAP_PIN_INPUT_PULLUP); 76 omap_mux_init_gpio(19, OMAP_PIN_INPUT_PULLUP);
85 gpmc_smsc911x_init(&smsc911x_cfg); 77 gpmc_smsc911x_init(&smsc911x_cfg);
86} 78}
@@ -419,8 +411,14 @@ static struct omap_board_mux board_mux[] __initdata = {
419}; 411};
420#endif 412#endif
421 413
414static struct regulator_consumer_supply dummy_supplies[] = {
415 REGULATOR_SUPPLY("vddvario", "smsc911x.0"),
416 REGULATOR_SUPPLY("vdd33a", "smsc911x.0"),
417};
418
422static void __init omap3_stalker_init(void) 419static void __init omap3_stalker_init(void)
423{ 420{
421 regulator_register_fixed(0, dummy_supplies, ARRAY_SIZE(dummy_supplies));
424 omap3_mux_init(board_mux, OMAP_PACKAGE_CUS); 422 omap3_mux_init(board_mux, OMAP_PACKAGE_CUS);
425 omap_board_config = omap3_stalker_config; 423 omap_board_config = omap3_stalker_config;
426 omap_board_config_size = ARRAY_SIZE(omap3_stalker_config); 424 omap_board_config_size = ARRAY_SIZE(omap3_stalker_config);
diff --git a/arch/arm/mach-omap2/board-omap4panda.c b/arch/arm/mach-omap2/board-omap4panda.c
index d8c0e89f0126..1b782ba53433 100644
--- a/arch/arm/mach-omap2/board-omap4panda.c
+++ b/arch/arm/mach-omap2/board-omap4panda.c
@@ -25,6 +25,7 @@
25#include <linux/gpio.h> 25#include <linux/gpio.h>
26#include <linux/usb/otg.h> 26#include <linux/usb/otg.h>
27#include <linux/i2c/twl.h> 27#include <linux/i2c/twl.h>
28#include <linux/mfd/twl6040.h>
28#include <linux/regulator/machine.h> 29#include <linux/regulator/machine.h>
29#include <linux/regulator/fixed.h> 30#include <linux/regulator/fixed.h>
30#include <linux/wl12xx.h> 31#include <linux/wl12xx.h>
@@ -284,7 +285,7 @@ static int __init omap4_twl6030_hsmmc_init(struct omap2_hsmmc_info *controllers)
284 return 0; 285 return 0;
285} 286}
286 287
287static struct twl4030_codec_data twl6040_codec = { 288static struct twl6040_codec_data twl6040_codec = {
288 /* single-step ramp for headset and handsfree */ 289 /* single-step ramp for headset and handsfree */
289 .hs_left_step = 0x0f, 290 .hs_left_step = 0x0f,
290 .hs_right_step = 0x0f, 291 .hs_right_step = 0x0f,
@@ -292,17 +293,14 @@ static struct twl4030_codec_data twl6040_codec = {
292 .hf_right_step = 0x1d, 293 .hf_right_step = 0x1d,
293}; 294};
294 295
295static struct twl4030_audio_data twl6040_audio = { 296static struct twl6040_platform_data twl6040_data = {
296 .codec = &twl6040_codec, 297 .codec = &twl6040_codec,
297 .audpwron_gpio = 127, 298 .audpwron_gpio = 127,
298 .naudint_irq = OMAP44XX_IRQ_SYS_2N,
299 .irq_base = TWL6040_CODEC_IRQ_BASE, 299 .irq_base = TWL6040_CODEC_IRQ_BASE,
300}; 300};
301 301
302/* Panda board uses the common PMIC configuration */ 302/* Panda board uses the common PMIC configuration */
303static struct twl4030_platform_data omap4_panda_twldata = { 303static struct twl4030_platform_data omap4_panda_twldata;
304 .audio = &twl6040_audio,
305};
306 304
307/* 305/*
308 * Display monitor features are burnt in their EEPROM as EDID data. The EEPROM 306 * Display monitor features are burnt in their EEPROM as EDID data. The EEPROM
@@ -326,7 +324,8 @@ static int __init omap4_panda_i2c_init(void)
326 TWL_COMMON_REGULATOR_VCXIO | 324 TWL_COMMON_REGULATOR_VCXIO |
327 TWL_COMMON_REGULATOR_VUSB | 325 TWL_COMMON_REGULATOR_VUSB |
328 TWL_COMMON_REGULATOR_CLK32KG); 326 TWL_COMMON_REGULATOR_CLK32KG);
329 omap4_pmic_init("twl6030", &omap4_panda_twldata); 327 omap4_pmic_init("twl6030", &omap4_panda_twldata,
328 &twl6040_data, OMAP44XX_IRQ_SYS_2N);
330 omap_register_i2c_bus(2, 400, NULL, 0); 329 omap_register_i2c_bus(2, 400, NULL, 0);
331 /* 330 /*
332 * Bus 3 is attached to the DVI port where devices like the pico DLP 331 * Bus 3 is attached to the DVI port where devices like the pico DLP
diff --git a/arch/arm/mach-omap2/board-overo.c b/arch/arm/mach-omap2/board-overo.c
index 668533e2a379..33aa3910b09e 100644
--- a/arch/arm/mach-omap2/board-overo.c
+++ b/arch/arm/mach-omap2/board-overo.c
@@ -498,10 +498,18 @@ static struct gpio overo_bt_gpios[] __initdata = {
498 { OVERO_GPIO_BT_NRESET, GPIOF_OUT_INIT_HIGH, "lcd bl enable" }, 498 { OVERO_GPIO_BT_NRESET, GPIOF_OUT_INIT_HIGH, "lcd bl enable" },
499}; 499};
500 500
501static struct regulator_consumer_supply dummy_supplies[] = {
502 REGULATOR_SUPPLY("vddvario", "smsc911x.0"),
503 REGULATOR_SUPPLY("vdd33a", "smsc911x.0"),
504 REGULATOR_SUPPLY("vddvario", "smsc911x.1"),
505 REGULATOR_SUPPLY("vdd33a", "smsc911x.1"),
506};
507
501static void __init overo_init(void) 508static void __init overo_init(void)
502{ 509{
503 int ret; 510 int ret;
504 511
512 regulator_register_fixed(0, dummy_supplies, ARRAY_SIZE(dummy_supplies));
505 omap3_mux_init(board_mux, OMAP_PACKAGE_CBB); 513 omap3_mux_init(board_mux, OMAP_PACKAGE_CBB);
506 omap_hsmmc_init(mmc); 514 omap_hsmmc_init(mmc);
507 overo_i2c_init(); 515 overo_i2c_init();
diff --git a/arch/arm/mach-omap2/board-zoom-debugboard.c b/arch/arm/mach-omap2/board-zoom-debugboard.c
index 1e8540eabde9..f64f44173061 100644
--- a/arch/arm/mach-omap2/board-zoom-debugboard.c
+++ b/arch/arm/mach-omap2/board-zoom-debugboard.c
@@ -14,6 +14,9 @@
14#include <linux/smsc911x.h> 14#include <linux/smsc911x.h>
15#include <linux/interrupt.h> 15#include <linux/interrupt.h>
16 16
17#include <linux/regulator/fixed.h>
18#include <linux/regulator/machine.h>
19
17#include <plat/gpmc.h> 20#include <plat/gpmc.h>
18#include <plat/gpmc-smsc911x.h> 21#include <plat/gpmc-smsc911x.h>
19 22
@@ -117,11 +120,17 @@ static struct platform_device *zoom_devices[] __initdata = {
117 &zoom_debugboard_serial_device, 120 &zoom_debugboard_serial_device,
118}; 121};
119 122
123static struct regulator_consumer_supply dummy_supplies[] = {
124 REGULATOR_SUPPLY("vddvario", "smsc911x.0"),
125 REGULATOR_SUPPLY("vdd33a", "smsc911x.0"),
126};
127
120int __init zoom_debugboard_init(void) 128int __init zoom_debugboard_init(void)
121{ 129{
122 if (!omap_zoom_debugboard_detect()) 130 if (!omap_zoom_debugboard_detect())
123 return 0; 131 return 0;
124 132
133 regulator_register_fixed(0, dummy_supplies, ARRAY_SIZE(dummy_supplies));
125 zoom_init_smsc911x(); 134 zoom_init_smsc911x();
126 zoom_init_quaduart(); 135 zoom_init_quaduart();
127 return platform_add_devices(zoom_devices, ARRAY_SIZE(zoom_devices)); 136 return platform_add_devices(zoom_devices, ARRAY_SIZE(zoom_devices));
diff --git a/arch/arm/mach-omap2/clkt2xxx_virt_prcm_set.c b/arch/arm/mach-omap2/clkt2xxx_virt_prcm_set.c
index 7072e0d651b1..3d9d746b221a 100644
--- a/arch/arm/mach-omap2/clkt2xxx_virt_prcm_set.c
+++ b/arch/arm/mach-omap2/clkt2xxx_virt_prcm_set.c
@@ -165,83 +165,3 @@ int omap2_select_table_rate(struct clk *clk, unsigned long rate)
165 165
166 return 0; 166 return 0;
167} 167}
168
169#ifdef CONFIG_CPU_FREQ
170/*
171 * Walk PRCM rate table and fillout cpufreq freq_table
172 * XXX This should be replaced by an OPP layer in the near future
173 */
174static struct cpufreq_frequency_table *freq_table;
175
176void omap2_clk_init_cpufreq_table(struct cpufreq_frequency_table **table)
177{
178 const struct prcm_config *prcm;
179 int i = 0;
180 int tbl_sz = 0;
181
182 if (!cpu_is_omap24xx())
183 return;
184
185 for (prcm = rate_table; prcm->mpu_speed; prcm++) {
186 if (!(prcm->flags & cpu_mask))
187 continue;
188 if (prcm->xtal_speed != sclk->rate)
189 continue;
190
191 /* don't put bypass rates in table */
192 if (prcm->dpll_speed == prcm->xtal_speed)
193 continue;
194
195 tbl_sz++;
196 }
197
198 /*
199 * XXX Ensure that we're doing what CPUFreq expects for this error
200 * case and the following one
201 */
202 if (tbl_sz == 0) {
203 pr_warning("%s: no matching entries in rate_table\n",
204 __func__);
205 return;
206 }
207
208 /* Include the CPUFREQ_TABLE_END terminator entry */
209 tbl_sz++;
210
211 freq_table = kzalloc(sizeof(struct cpufreq_frequency_table) * tbl_sz,
212 GFP_ATOMIC);
213 if (!freq_table) {
214 pr_err("%s: could not kzalloc frequency table\n", __func__);
215 return;
216 }
217
218 for (prcm = rate_table; prcm->mpu_speed; prcm++) {
219 if (!(prcm->flags & cpu_mask))
220 continue;
221 if (prcm->xtal_speed != sclk->rate)
222 continue;
223
224 /* don't put bypass rates in table */
225 if (prcm->dpll_speed == prcm->xtal_speed)
226 continue;
227
228 freq_table[i].index = i;
229 freq_table[i].frequency = prcm->mpu_speed / 1000;
230 i++;
231 }
232
233 freq_table[i].index = i;
234 freq_table[i].frequency = CPUFREQ_TABLE_END;
235
236 *table = &freq_table[0];
237}
238
239void omap2_clk_exit_cpufreq_table(struct cpufreq_frequency_table **table)
240{
241 if (!cpu_is_omap24xx())
242 return;
243
244 kfree(freq_table);
245}
246
247#endif
diff --git a/arch/arm/mach-omap2/clock.c b/arch/arm/mach-omap2/clock.c
index f57ed5baeccf..d9f4931513f9 100644
--- a/arch/arm/mach-omap2/clock.c
+++ b/arch/arm/mach-omap2/clock.c
@@ -536,10 +536,5 @@ struct clk_functions omap2_clk_functions = {
536 .clk_set_rate = omap2_clk_set_rate, 536 .clk_set_rate = omap2_clk_set_rate,
537 .clk_set_parent = omap2_clk_set_parent, 537 .clk_set_parent = omap2_clk_set_parent,
538 .clk_disable_unused = omap2_clk_disable_unused, 538 .clk_disable_unused = omap2_clk_disable_unused,
539#ifdef CONFIG_CPU_FREQ
540 /* These will be removed when the OPP code is integrated */
541 .clk_init_cpufreq_table = omap2_clk_init_cpufreq_table,
542 .clk_exit_cpufreq_table = omap2_clk_exit_cpufreq_table,
543#endif
544}; 539};
545 540
diff --git a/arch/arm/mach-omap2/clock.h b/arch/arm/mach-omap2/clock.h
index b8c2a686481c..a1bb23a23351 100644
--- a/arch/arm/mach-omap2/clock.h
+++ b/arch/arm/mach-omap2/clock.h
@@ -146,14 +146,6 @@ extern const struct clksel_rate gpt_sys_rates[];
146extern const struct clksel_rate gfx_l3_rates[]; 146extern const struct clksel_rate gfx_l3_rates[];
147extern const struct clksel_rate dsp_ick_rates[]; 147extern const struct clksel_rate dsp_ick_rates[];
148 148
149#if defined(CONFIG_ARCH_OMAP2) && defined(CONFIG_CPU_FREQ)
150extern void omap2_clk_init_cpufreq_table(struct cpufreq_frequency_table **table);
151extern void omap2_clk_exit_cpufreq_table(struct cpufreq_frequency_table **table);
152#else
153#define omap2_clk_init_cpufreq_table 0
154#define omap2_clk_exit_cpufreq_table 0
155#endif
156
157extern const struct clkops clkops_omap2_iclk_dflt_wait; 149extern const struct clkops clkops_omap2_iclk_dflt_wait;
158extern const struct clkops clkops_omap2_iclk_dflt; 150extern const struct clkops clkops_omap2_iclk_dflt;
159extern const struct clkops clkops_omap2_iclk_idle_only; 151extern const struct clkops clkops_omap2_iclk_idle_only;
diff --git a/arch/arm/mach-omap2/clock3xxx_data.c b/arch/arm/mach-omap2/clock3xxx_data.c
index 480fb8f09aed..f4a626f7c79e 100644
--- a/arch/arm/mach-omap2/clock3xxx_data.c
+++ b/arch/arm/mach-omap2/clock3xxx_data.c
@@ -747,7 +747,7 @@ static struct clk dpll4_m3_ck = {
747 .parent = &dpll4_ck, 747 .parent = &dpll4_ck,
748 .init = &omap2_init_clksel_parent, 748 .init = &omap2_init_clksel_parent,
749 .clksel_reg = OMAP_CM_REGADDR(OMAP3430_DSS_MOD, CM_CLKSEL), 749 .clksel_reg = OMAP_CM_REGADDR(OMAP3430_DSS_MOD, CM_CLKSEL),
750 .clksel_mask = OMAP3430_CLKSEL_TV_MASK, 750 .clksel_mask = OMAP3630_CLKSEL_TV_MASK,
751 .clksel = dpll4_clksel, 751 .clksel = dpll4_clksel,
752 .clkdm_name = "dpll4_clkdm", 752 .clkdm_name = "dpll4_clkdm",
753 .recalc = &omap2_clksel_recalc, 753 .recalc = &omap2_clksel_recalc,
@@ -832,7 +832,7 @@ static struct clk dpll4_m4_ck = {
832 .parent = &dpll4_ck, 832 .parent = &dpll4_ck,
833 .init = &omap2_init_clksel_parent, 833 .init = &omap2_init_clksel_parent,
834 .clksel_reg = OMAP_CM_REGADDR(OMAP3430_DSS_MOD, CM_CLKSEL), 834 .clksel_reg = OMAP_CM_REGADDR(OMAP3430_DSS_MOD, CM_CLKSEL),
835 .clksel_mask = OMAP3430_CLKSEL_DSS1_MASK, 835 .clksel_mask = OMAP3630_CLKSEL_DSS1_MASK,
836 .clksel = dpll4_clksel, 836 .clksel = dpll4_clksel,
837 .clkdm_name = "dpll4_clkdm", 837 .clkdm_name = "dpll4_clkdm",
838 .recalc = &omap2_clksel_recalc, 838 .recalc = &omap2_clksel_recalc,
@@ -859,7 +859,7 @@ static struct clk dpll4_m5_ck = {
859 .parent = &dpll4_ck, 859 .parent = &dpll4_ck,
860 .init = &omap2_init_clksel_parent, 860 .init = &omap2_init_clksel_parent,
861 .clksel_reg = OMAP_CM_REGADDR(OMAP3430_CAM_MOD, CM_CLKSEL), 861 .clksel_reg = OMAP_CM_REGADDR(OMAP3430_CAM_MOD, CM_CLKSEL),
862 .clksel_mask = OMAP3430_CLKSEL_CAM_MASK, 862 .clksel_mask = OMAP3630_CLKSEL_CAM_MASK,
863 .clksel = dpll4_clksel, 863 .clksel = dpll4_clksel,
864 .clkdm_name = "dpll4_clkdm", 864 .clkdm_name = "dpll4_clkdm",
865 .set_rate = &omap2_clksel_set_rate, 865 .set_rate = &omap2_clksel_set_rate,
@@ -886,7 +886,7 @@ static struct clk dpll4_m6_ck = {
886 .parent = &dpll4_ck, 886 .parent = &dpll4_ck,
887 .init = &omap2_init_clksel_parent, 887 .init = &omap2_init_clksel_parent,
888 .clksel_reg = OMAP_CM_REGADDR(OMAP3430_EMU_MOD, CM_CLKSEL1), 888 .clksel_reg = OMAP_CM_REGADDR(OMAP3430_EMU_MOD, CM_CLKSEL1),
889 .clksel_mask = OMAP3430_DIV_DPLL4_MASK, 889 .clksel_mask = OMAP3630_DIV_DPLL4_MASK,
890 .clksel = dpll4_clksel, 890 .clksel = dpll4_clksel,
891 .clkdm_name = "dpll4_clkdm", 891 .clkdm_name = "dpll4_clkdm",
892 .recalc = &omap2_clksel_recalc, 892 .recalc = &omap2_clksel_recalc,
@@ -1394,6 +1394,7 @@ static struct clk cpefuse_fck = {
1394 .name = "cpefuse_fck", 1394 .name = "cpefuse_fck",
1395 .ops = &clkops_omap2_dflt, 1395 .ops = &clkops_omap2_dflt,
1396 .parent = &sys_ck, 1396 .parent = &sys_ck,
1397 .clkdm_name = "core_l4_clkdm",
1397 .enable_reg = OMAP_CM_REGADDR(CORE_MOD, OMAP3430ES2_CM_FCLKEN3), 1398 .enable_reg = OMAP_CM_REGADDR(CORE_MOD, OMAP3430ES2_CM_FCLKEN3),
1398 .enable_bit = OMAP3430ES2_EN_CPEFUSE_SHIFT, 1399 .enable_bit = OMAP3430ES2_EN_CPEFUSE_SHIFT,
1399 .recalc = &followparent_recalc, 1400 .recalc = &followparent_recalc,
@@ -1403,6 +1404,7 @@ static struct clk ts_fck = {
1403 .name = "ts_fck", 1404 .name = "ts_fck",
1404 .ops = &clkops_omap2_dflt, 1405 .ops = &clkops_omap2_dflt,
1405 .parent = &omap_32k_fck, 1406 .parent = &omap_32k_fck,
1407 .clkdm_name = "core_l4_clkdm",
1406 .enable_reg = OMAP_CM_REGADDR(CORE_MOD, OMAP3430ES2_CM_FCLKEN3), 1408 .enable_reg = OMAP_CM_REGADDR(CORE_MOD, OMAP3430ES2_CM_FCLKEN3),
1407 .enable_bit = OMAP3430ES2_EN_TS_SHIFT, 1409 .enable_bit = OMAP3430ES2_EN_TS_SHIFT,
1408 .recalc = &followparent_recalc, 1410 .recalc = &followparent_recalc,
@@ -1412,6 +1414,7 @@ static struct clk usbtll_fck = {
1412 .name = "usbtll_fck", 1414 .name = "usbtll_fck",
1413 .ops = &clkops_omap2_dflt_wait, 1415 .ops = &clkops_omap2_dflt_wait,
1414 .parent = &dpll5_m2_ck, 1416 .parent = &dpll5_m2_ck,
1417 .clkdm_name = "core_l4_clkdm",
1415 .enable_reg = OMAP_CM_REGADDR(CORE_MOD, OMAP3430ES2_CM_FCLKEN3), 1418 .enable_reg = OMAP_CM_REGADDR(CORE_MOD, OMAP3430ES2_CM_FCLKEN3),
1416 .enable_bit = OMAP3430ES2_EN_USBTLL_SHIFT, 1419 .enable_bit = OMAP3430ES2_EN_USBTLL_SHIFT,
1417 .recalc = &followparent_recalc, 1420 .recalc = &followparent_recalc,
@@ -1617,6 +1620,7 @@ static struct clk fshostusb_fck = {
1617 .name = "fshostusb_fck", 1620 .name = "fshostusb_fck",
1618 .ops = &clkops_omap2_dflt_wait, 1621 .ops = &clkops_omap2_dflt_wait,
1619 .parent = &core_48m_fck, 1622 .parent = &core_48m_fck,
1623 .clkdm_name = "core_l4_clkdm",
1620 .enable_reg = OMAP_CM_REGADDR(CORE_MOD, CM_FCLKEN1), 1624 .enable_reg = OMAP_CM_REGADDR(CORE_MOD, CM_FCLKEN1),
1621 .enable_bit = OMAP3430ES1_EN_FSHOSTUSB_SHIFT, 1625 .enable_bit = OMAP3430ES1_EN_FSHOSTUSB_SHIFT,
1622 .recalc = &followparent_recalc, 1626 .recalc = &followparent_recalc,
@@ -2043,6 +2047,7 @@ static struct clk omapctrl_ick = {
2043 .enable_reg = OMAP_CM_REGADDR(CORE_MOD, CM_ICLKEN1), 2047 .enable_reg = OMAP_CM_REGADDR(CORE_MOD, CM_ICLKEN1),
2044 .enable_bit = OMAP3430_EN_OMAPCTRL_SHIFT, 2048 .enable_bit = OMAP3430_EN_OMAPCTRL_SHIFT,
2045 .flags = ENABLE_ON_INIT, 2049 .flags = ENABLE_ON_INIT,
2050 .clkdm_name = "core_l4_clkdm",
2046 .recalc = &followparent_recalc, 2051 .recalc = &followparent_recalc,
2047}; 2052};
2048 2053
@@ -2094,6 +2099,7 @@ static struct clk usb_l4_ick = {
2094 .clksel_reg = OMAP_CM_REGADDR(CORE_MOD, CM_CLKSEL), 2099 .clksel_reg = OMAP_CM_REGADDR(CORE_MOD, CM_CLKSEL),
2095 .clksel_mask = OMAP3430ES1_CLKSEL_FSHOSTUSB_MASK, 2100 .clksel_mask = OMAP3430ES1_CLKSEL_FSHOSTUSB_MASK,
2096 .clksel = usb_l4_clksel, 2101 .clksel = usb_l4_clksel,
2102 .clkdm_name = "core_l4_clkdm",
2097 .recalc = &omap2_clksel_recalc, 2103 .recalc = &omap2_clksel_recalc,
2098}; 2104};
2099 2105
@@ -3467,8 +3473,8 @@ static struct omap_clk omap3xxx_clks[] = {
3467 CLK(NULL, "ipss_ick", &ipss_ick, CK_AM35XX), 3473 CLK(NULL, "ipss_ick", &ipss_ick, CK_AM35XX),
3468 CLK(NULL, "rmii_ck", &rmii_ck, CK_AM35XX), 3474 CLK(NULL, "rmii_ck", &rmii_ck, CK_AM35XX),
3469 CLK(NULL, "pclk_ck", &pclk_ck, CK_AM35XX), 3475 CLK(NULL, "pclk_ck", &pclk_ck, CK_AM35XX),
3470 CLK("davinci_emac", "emac_clk", &emac_ick, CK_AM35XX), 3476 CLK("davinci_emac", NULL, &emac_ick, CK_AM35XX),
3471 CLK("davinci_emac", "phy_clk", &emac_fck, CK_AM35XX), 3477 CLK("davinci_mdio.0", NULL, &emac_fck, CK_AM35XX),
3472 CLK("vpfe-capture", "master", &vpfe_ick, CK_AM35XX), 3478 CLK("vpfe-capture", "master", &vpfe_ick, CK_AM35XX),
3473 CLK("vpfe-capture", "slave", &vpfe_fck, CK_AM35XX), 3479 CLK("vpfe-capture", "slave", &vpfe_fck, CK_AM35XX),
3474 CLK("musb-am35x", "ick", &hsotgusb_ick_am35xx, CK_AM35XX), 3480 CLK("musb-am35x", "ick", &hsotgusb_ick_am35xx, CK_AM35XX),
diff --git a/arch/arm/mach-omap2/clock44xx_data.c b/arch/arm/mach-omap2/clock44xx_data.c
index c03c1108468e..fa6ea65ad44b 100644
--- a/arch/arm/mach-omap2/clock44xx_data.c
+++ b/arch/arm/mach-omap2/clock44xx_data.c
@@ -957,8 +957,8 @@ static struct dpll_data dpll_usb_dd = {
957 .modes = (1 << DPLL_LOW_POWER_BYPASS) | (1 << DPLL_LOCKED), 957 .modes = (1 << DPLL_LOW_POWER_BYPASS) | (1 << DPLL_LOCKED),
958 .autoidle_reg = OMAP4430_CM_AUTOIDLE_DPLL_USB, 958 .autoidle_reg = OMAP4430_CM_AUTOIDLE_DPLL_USB,
959 .idlest_reg = OMAP4430_CM_IDLEST_DPLL_USB, 959 .idlest_reg = OMAP4430_CM_IDLEST_DPLL_USB,
960 .mult_mask = OMAP4430_DPLL_MULT_MASK, 960 .mult_mask = OMAP4430_DPLL_MULT_USB_MASK,
961 .div1_mask = OMAP4430_DPLL_DIV_MASK, 961 .div1_mask = OMAP4430_DPLL_DIV_0_7_MASK,
962 .enable_mask = OMAP4430_DPLL_EN_MASK, 962 .enable_mask = OMAP4430_DPLL_EN_MASK,
963 .autoidle_mask = OMAP4430_AUTO_DPLL_MODE_MASK, 963 .autoidle_mask = OMAP4430_AUTO_DPLL_MODE_MASK,
964 .idlest_mask = OMAP4430_ST_DPLL_CLK_MASK, 964 .idlest_mask = OMAP4430_ST_DPLL_CLK_MASK,
@@ -978,6 +978,7 @@ static struct clk dpll_usb_ck = {
978 .recalc = &omap3_dpll_recalc, 978 .recalc = &omap3_dpll_recalc,
979 .round_rate = &omap2_dpll_round_rate, 979 .round_rate = &omap2_dpll_round_rate,
980 .set_rate = &omap3_noncore_dpll_set_rate, 980 .set_rate = &omap3_noncore_dpll_set_rate,
981 .clkdm_name = "l3_init_clkdm",
981}; 982};
982 983
983static struct clk dpll_usb_clkdcoldo_ck = { 984static struct clk dpll_usb_clkdcoldo_ck = {
diff --git a/arch/arm/mach-omap2/clockdomains44xx_data.c b/arch/arm/mach-omap2/clockdomains44xx_data.c
index 9299ac291d28..bd7ed13515cc 100644
--- a/arch/arm/mach-omap2/clockdomains44xx_data.c
+++ b/arch/arm/mach-omap2/clockdomains44xx_data.c
@@ -390,7 +390,7 @@ static struct clockdomain emu_sys_44xx_clkdm = {
390 .prcm_partition = OMAP4430_PRM_PARTITION, 390 .prcm_partition = OMAP4430_PRM_PARTITION,
391 .cm_inst = OMAP4430_PRM_EMU_CM_INST, 391 .cm_inst = OMAP4430_PRM_EMU_CM_INST,
392 .clkdm_offs = OMAP4430_PRM_EMU_CM_EMU_CDOFFS, 392 .clkdm_offs = OMAP4430_PRM_EMU_CM_EMU_CDOFFS,
393 .flags = CLKDM_CAN_HWSUP, 393 .flags = CLKDM_CAN_ENABLE_AUTO | CLKDM_CAN_FORCE_WAKEUP,
394}; 394};
395 395
396static struct clockdomain l3_dma_44xx_clkdm = { 396static struct clockdomain l3_dma_44xx_clkdm = {
diff --git a/arch/arm/mach-omap2/gpmc-smsc911x.c b/arch/arm/mach-omap2/gpmc-smsc911x.c
index 5e5880d6d099..b6c77be3e8f7 100644
--- a/arch/arm/mach-omap2/gpmc-smsc911x.c
+++ b/arch/arm/mach-omap2/gpmc-smsc911x.c
@@ -19,15 +19,11 @@
19#include <linux/interrupt.h> 19#include <linux/interrupt.h>
20#include <linux/io.h> 20#include <linux/io.h>
21#include <linux/smsc911x.h> 21#include <linux/smsc911x.h>
22#include <linux/regulator/fixed.h>
23#include <linux/regulator/machine.h>
24 22
25#include <plat/board.h> 23#include <plat/board.h>
26#include <plat/gpmc.h> 24#include <plat/gpmc.h>
27#include <plat/gpmc-smsc911x.h> 25#include <plat/gpmc-smsc911x.h>
28 26
29static struct omap_smsc911x_platform_data *gpmc_cfg;
30
31static struct resource gpmc_smsc911x_resources[] = { 27static struct resource gpmc_smsc911x_resources[] = {
32 [0] = { 28 [0] = {
33 .flags = IORESOURCE_MEM, 29 .flags = IORESOURCE_MEM,
@@ -41,51 +37,6 @@ static struct smsc911x_platform_config gpmc_smsc911x_config = {
41 .phy_interface = PHY_INTERFACE_MODE_MII, 37 .phy_interface = PHY_INTERFACE_MODE_MII,
42 .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW, 38 .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
43 .irq_type = SMSC911X_IRQ_TYPE_OPEN_DRAIN, 39 .irq_type = SMSC911X_IRQ_TYPE_OPEN_DRAIN,
44 .flags = SMSC911X_USE_16BIT,
45};
46
47static struct regulator_consumer_supply gpmc_smsc911x_supply[] = {
48 REGULATOR_SUPPLY("vddvario", "smsc911x.0"),
49 REGULATOR_SUPPLY("vdd33a", "smsc911x.0"),
50};
51
52/* Generic regulator definition to satisfy smsc911x */
53static struct regulator_init_data gpmc_smsc911x_reg_init_data = {
54 .constraints = {
55 .min_uV = 3300000,
56 .max_uV = 3300000,
57 .valid_modes_mask = REGULATOR_MODE_NORMAL
58 | REGULATOR_MODE_STANDBY,
59 .valid_ops_mask = REGULATOR_CHANGE_MODE
60 | REGULATOR_CHANGE_STATUS,
61 },
62 .num_consumer_supplies = ARRAY_SIZE(gpmc_smsc911x_supply),
63 .consumer_supplies = gpmc_smsc911x_supply,
64};
65
66static struct fixed_voltage_config gpmc_smsc911x_fixed_reg_data = {
67 .supply_name = "gpmc_smsc911x",
68 .microvolts = 3300000,
69 .gpio = -EINVAL,
70 .startup_delay = 0,
71 .enable_high = 0,
72 .enabled_at_boot = 1,
73 .init_data = &gpmc_smsc911x_reg_init_data,
74};
75
76/*
77 * Platform device id of 42 is a temporary fix to avoid conflicts
78 * with other reg-fixed-voltage devices. The real fix should
79 * involve the driver core providing a way of dynamically
80 * assigning a unique id on registration for platform devices
81 * in the same name space.
82 */
83static struct platform_device gpmc_smsc911x_regulator = {
84 .name = "reg-fixed-voltage",
85 .id = 42,
86 .dev = {
87 .platform_data = &gpmc_smsc911x_fixed_reg_data,
88 },
89}; 40};
90 41
91/* 42/*
@@ -93,23 +44,12 @@ static struct platform_device gpmc_smsc911x_regulator = {
93 * assume that pin multiplexing is done in the board-*.c file, 44 * assume that pin multiplexing is done in the board-*.c file,
94 * or in the bootloader. 45 * or in the bootloader.
95 */ 46 */
96void __init gpmc_smsc911x_init(struct omap_smsc911x_platform_data *board_data) 47void __init gpmc_smsc911x_init(struct omap_smsc911x_platform_data *gpmc_cfg)
97{ 48{
98 struct platform_device *pdev; 49 struct platform_device *pdev;
99 unsigned long cs_mem_base; 50 unsigned long cs_mem_base;
100 int ret; 51 int ret;
101 52
102 gpmc_cfg = board_data;
103
104 if (!gpmc_cfg->id) {
105 ret = platform_device_register(&gpmc_smsc911x_regulator);
106 if (ret < 0) {
107 pr_err("Unable to register smsc911x regulators: %d\n",
108 ret);
109 return;
110 }
111 }
112
113 if (gpmc_cs_request(gpmc_cfg->cs, SZ_16M, &cs_mem_base) < 0) { 53 if (gpmc_cs_request(gpmc_cfg->cs, SZ_16M, &cs_mem_base) < 0) {
114 pr_err("Failed to request GPMC mem region\n"); 54 pr_err("Failed to request GPMC mem region\n");
115 return; 55 return;
@@ -139,8 +79,7 @@ void __init gpmc_smsc911x_init(struct omap_smsc911x_platform_data *board_data)
139 gpio_set_value(gpmc_cfg->gpio_reset, 1); 79 gpio_set_value(gpmc_cfg->gpio_reset, 1);
140 } 80 }
141 81
142 if (gpmc_cfg->flags) 82 gpmc_smsc911x_config.flags = gpmc_cfg->flags ? : SMSC911X_USE_16BIT;
143 gpmc_smsc911x_config.flags = gpmc_cfg->flags;
144 83
145 pdev = platform_device_register_resndata(NULL, "smsc911x", gpmc_cfg->id, 84 pdev = platform_device_register_resndata(NULL, "smsc911x", gpmc_cfg->id,
146 gpmc_smsc911x_resources, ARRAY_SIZE(gpmc_smsc911x_resources), 85 gpmc_smsc911x_resources, ARRAY_SIZE(gpmc_smsc911x_resources),
diff --git a/arch/arm/mach-omap2/hsmmc.c b/arch/arm/mach-omap2/hsmmc.c
index 100db6217f39..b0268eaffe13 100644
--- a/arch/arm/mach-omap2/hsmmc.c
+++ b/arch/arm/mach-omap2/hsmmc.c
@@ -506,6 +506,13 @@ static void __init omap_hsmmc_init_one(struct omap2_hsmmc_info *hsmmcinfo,
506 if (oh->dev_attr != NULL) { 506 if (oh->dev_attr != NULL) {
507 mmc_dev_attr = oh->dev_attr; 507 mmc_dev_attr = oh->dev_attr;
508 mmc_data->controller_flags = mmc_dev_attr->flags; 508 mmc_data->controller_flags = mmc_dev_attr->flags;
509 /*
510 * erratum 2.1.1.128 doesn't apply if board has
511 * a transceiver is attached
512 */
513 if (hsmmcinfo->transceiver)
514 mmc_data->controller_flags &=
515 ~OMAP_HSMMC_BROKEN_MULTIBLOCK_READ;
509 } 516 }
510 517
511 pdev = platform_device_alloc(name, ctrl_nr - 1); 518 pdev = platform_device_alloc(name, ctrl_nr - 1);
diff --git a/arch/arm/mach-omap2/include/mach/barriers.h b/arch/arm/mach-omap2/include/mach/barriers.h
index 4fa72c7cc7cd..1c582a8592b9 100644
--- a/arch/arm/mach-omap2/include/mach/barriers.h
+++ b/arch/arm/mach-omap2/include/mach/barriers.h
@@ -22,6 +22,8 @@
22#ifndef __MACH_BARRIERS_H 22#ifndef __MACH_BARRIERS_H
23#define __MACH_BARRIERS_H 23#define __MACH_BARRIERS_H
24 24
25#include <asm/outercache.h>
26
25extern void omap_bus_sync(void); 27extern void omap_bus_sync(void);
26 28
27#define rmb() dsb() 29#define rmb() dsb()
diff --git a/arch/arm/mach-omap2/include/mach/ctrl_module_pad_core_44xx.h b/arch/arm/mach-omap2/include/mach/ctrl_module_pad_core_44xx.h
index 1e2d3322f33e..c88420de1151 100644
--- a/arch/arm/mach-omap2/include/mach/ctrl_module_pad_core_44xx.h
+++ b/arch/arm/mach-omap2/include/mach/ctrl_module_pad_core_44xx.h
@@ -941,10 +941,10 @@
941#define OMAP4_DSI2_LANEENABLE_MASK (0x7 << 29) 941#define OMAP4_DSI2_LANEENABLE_MASK (0x7 << 29)
942#define OMAP4_DSI1_LANEENABLE_SHIFT 24 942#define OMAP4_DSI1_LANEENABLE_SHIFT 24
943#define OMAP4_DSI1_LANEENABLE_MASK (0x1f << 24) 943#define OMAP4_DSI1_LANEENABLE_MASK (0x1f << 24)
944#define OMAP4_DSI2_PIPD_SHIFT 19 944#define OMAP4_DSI1_PIPD_SHIFT 19
945#define OMAP4_DSI2_PIPD_MASK (0x1f << 19) 945#define OMAP4_DSI1_PIPD_MASK (0x1f << 19)
946#define OMAP4_DSI1_PIPD_SHIFT 14 946#define OMAP4_DSI2_PIPD_SHIFT 14
947#define OMAP4_DSI1_PIPD_MASK (0x1f << 14) 947#define OMAP4_DSI2_PIPD_MASK (0x1f << 14)
948 948
949/* CONTROL_MCBSPLP */ 949/* CONTROL_MCBSPLP */
950#define OMAP4_ALBCTRLRX_FSX_SHIFT 31 950#define OMAP4_ALBCTRLRX_FSX_SHIFT 31
diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
index eba6cd3816f5..7144ae651d3d 100644
--- a/arch/arm/mach-omap2/omap_hwmod.c
+++ b/arch/arm/mach-omap2/omap_hwmod.c
@@ -1395,7 +1395,7 @@ static int _read_hardreset(struct omap_hwmod *oh, const char *name)
1395 */ 1395 */
1396static int _ocp_softreset(struct omap_hwmod *oh) 1396static int _ocp_softreset(struct omap_hwmod *oh)
1397{ 1397{
1398 u32 v; 1398 u32 v, softrst_mask;
1399 int c = 0; 1399 int c = 0;
1400 int ret = 0; 1400 int ret = 0;
1401 1401
@@ -1422,16 +1422,21 @@ static int _ocp_softreset(struct omap_hwmod *oh)
1422 goto dis_opt_clks; 1422 goto dis_opt_clks;
1423 _write_sysconfig(v, oh); 1423 _write_sysconfig(v, oh);
1424 1424
1425 if (oh->class->sysc->srst_udelay)
1426 udelay(oh->class->sysc->srst_udelay);
1427
1425 if (oh->class->sysc->sysc_flags & SYSS_HAS_RESET_STATUS) 1428 if (oh->class->sysc->sysc_flags & SYSS_HAS_RESET_STATUS)
1426 omap_test_timeout((omap_hwmod_read(oh, 1429 omap_test_timeout((omap_hwmod_read(oh,
1427 oh->class->sysc->syss_offs) 1430 oh->class->sysc->syss_offs)
1428 & SYSS_RESETDONE_MASK), 1431 & SYSS_RESETDONE_MASK),
1429 MAX_MODULE_SOFTRESET_WAIT, c); 1432 MAX_MODULE_SOFTRESET_WAIT, c);
1430 else if (oh->class->sysc->sysc_flags & SYSC_HAS_RESET_STATUS) 1433 else if (oh->class->sysc->sysc_flags & SYSC_HAS_RESET_STATUS) {
1434 softrst_mask = (0x1 << oh->class->sysc->sysc_fields->srst_shift);
1431 omap_test_timeout(!(omap_hwmod_read(oh, 1435 omap_test_timeout(!(omap_hwmod_read(oh,
1432 oh->class->sysc->sysc_offs) 1436 oh->class->sysc->sysc_offs)
1433 & SYSC_TYPE2_SOFTRESET_MASK), 1437 & softrst_mask),
1434 MAX_MODULE_SOFTRESET_WAIT, c); 1438 MAX_MODULE_SOFTRESET_WAIT, c);
1439 }
1435 1440
1436 if (c == MAX_MODULE_SOFTRESET_WAIT) 1441 if (c == MAX_MODULE_SOFTRESET_WAIT)
1437 pr_warning("omap_hwmod: %s: softreset failed (waited %d usec)\n", 1442 pr_warning("omap_hwmod: %s: softreset failed (waited %d usec)\n",
@@ -1477,6 +1482,11 @@ static int _reset(struct omap_hwmod *oh)
1477 1482
1478 ret = (oh->class->reset) ? oh->class->reset(oh) : _ocp_softreset(oh); 1483 ret = (oh->class->reset) ? oh->class->reset(oh) : _ocp_softreset(oh);
1479 1484
1485 if (oh->class->sysc) {
1486 _update_sysc_cache(oh);
1487 _enable_sysc(oh);
1488 }
1489
1480 return ret; 1490 return ret;
1481} 1491}
1482 1492
@@ -1786,20 +1796,9 @@ static int _setup(struct omap_hwmod *oh, void *data)
1786 return 0; 1796 return 0;
1787 } 1797 }
1788 1798
1789 if (!(oh->flags & HWMOD_INIT_NO_RESET)) { 1799 if (!(oh->flags & HWMOD_INIT_NO_RESET))
1790 _reset(oh); 1800 _reset(oh);
1791 1801
1792 /*
1793 * OCP_SYSCONFIG bits need to be reprogrammed after a softreset.
1794 * The _enable() function should be split to
1795 * avoid the rewrite of the OCP_SYSCONFIG register.
1796 */
1797 if (oh->class->sysc) {
1798 _update_sysc_cache(oh);
1799 _enable_sysc(oh);
1800 }
1801 }
1802
1803 postsetup_state = oh->_postsetup_state; 1802 postsetup_state = oh->_postsetup_state;
1804 if (postsetup_state == _HWMOD_STATE_UNKNOWN) 1803 if (postsetup_state == _HWMOD_STATE_UNKNOWN)
1805 postsetup_state = _HWMOD_STATE_ENABLED; 1804 postsetup_state = _HWMOD_STATE_ENABLED;
@@ -2463,26 +2462,28 @@ int omap_hwmod_del_initiator_dep(struct omap_hwmod *oh,
2463 * @oh: struct omap_hwmod * 2462 * @oh: struct omap_hwmod *
2464 * 2463 *
2465 * Sets the module OCP socket ENAWAKEUP bit to allow the module to 2464 * Sets the module OCP socket ENAWAKEUP bit to allow the module to
2466 * send wakeups to the PRCM. Eventually this should sets PRCM wakeup 2465 * send wakeups to the PRCM, and enable I/O ring wakeup events for
2467 * registers to cause the PRCM to receive wakeup events from the 2466 * this IP block if it has dynamic mux entries. Eventually this
2468 * module. Does not set any wakeup routing registers beyond this 2467 * should set PRCM wakeup registers to cause the PRCM to receive
2469 * point - if the module is to wake up any other module or subsystem, 2468 * wakeup events from the module. Does not set any wakeup routing
2470 * that must be set separately. Called by omap_device code. Returns 2469 * registers beyond this point - if the module is to wake up any other
2471 * -EINVAL on error or 0 upon success. 2470 * module or subsystem, that must be set separately. Called by
2471 * omap_device code. Returns -EINVAL on error or 0 upon success.
2472 */ 2472 */
2473int omap_hwmod_enable_wakeup(struct omap_hwmod *oh) 2473int omap_hwmod_enable_wakeup(struct omap_hwmod *oh)
2474{ 2474{
2475 unsigned long flags; 2475 unsigned long flags;
2476 u32 v; 2476 u32 v;
2477 2477
2478 if (!oh->class->sysc ||
2479 !(oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP))
2480 return -EINVAL;
2481
2482 spin_lock_irqsave(&oh->_lock, flags); 2478 spin_lock_irqsave(&oh->_lock, flags);
2483 v = oh->_sysc_cache; 2479
2484 _enable_wakeup(oh, &v); 2480 if (oh->class->sysc &&
2485 _write_sysconfig(v, oh); 2481 (oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)) {
2482 v = oh->_sysc_cache;
2483 _enable_wakeup(oh, &v);
2484 _write_sysconfig(v, oh);
2485 }
2486
2486 _set_idle_ioring_wakeup(oh, true); 2487 _set_idle_ioring_wakeup(oh, true);
2487 spin_unlock_irqrestore(&oh->_lock, flags); 2488 spin_unlock_irqrestore(&oh->_lock, flags);
2488 2489
@@ -2494,26 +2495,28 @@ int omap_hwmod_enable_wakeup(struct omap_hwmod *oh)
2494 * @oh: struct omap_hwmod * 2495 * @oh: struct omap_hwmod *
2495 * 2496 *
2496 * Clears the module OCP socket ENAWAKEUP bit to prevent the module 2497 * Clears the module OCP socket ENAWAKEUP bit to prevent the module
2497 * from sending wakeups to the PRCM. Eventually this should clear 2498 * from sending wakeups to the PRCM, and disable I/O ring wakeup
2498 * PRCM wakeup registers to cause the PRCM to ignore wakeup events 2499 * events for this IP block if it has dynamic mux entries. Eventually
2499 * from the module. Does not set any wakeup routing registers beyond 2500 * this should clear PRCM wakeup registers to cause the PRCM to ignore
2500 * this point - if the module is to wake up any other module or 2501 * wakeup events from the module. Does not set any wakeup routing
2501 * subsystem, that must be set separately. Called by omap_device 2502 * registers beyond this point - if the module is to wake up any other
2502 * code. Returns -EINVAL on error or 0 upon success. 2503 * module or subsystem, that must be set separately. Called by
2504 * omap_device code. Returns -EINVAL on error or 0 upon success.
2503 */ 2505 */
2504int omap_hwmod_disable_wakeup(struct omap_hwmod *oh) 2506int omap_hwmod_disable_wakeup(struct omap_hwmod *oh)
2505{ 2507{
2506 unsigned long flags; 2508 unsigned long flags;
2507 u32 v; 2509 u32 v;
2508 2510
2509 if (!oh->class->sysc ||
2510 !(oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP))
2511 return -EINVAL;
2512
2513 spin_lock_irqsave(&oh->_lock, flags); 2511 spin_lock_irqsave(&oh->_lock, flags);
2514 v = oh->_sysc_cache; 2512
2515 _disable_wakeup(oh, &v); 2513 if (oh->class->sysc &&
2516 _write_sysconfig(v, oh); 2514 (oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)) {
2515 v = oh->_sysc_cache;
2516 _disable_wakeup(oh, &v);
2517 _write_sysconfig(v, oh);
2518 }
2519
2517 _set_idle_ioring_wakeup(oh, false); 2520 _set_idle_ioring_wakeup(oh, false);
2518 spin_unlock_irqrestore(&oh->_lock, flags); 2521 spin_unlock_irqrestore(&oh->_lock, flags);
2519 2522
diff --git a/arch/arm/mach-omap2/omap_hwmod_2420_data.c b/arch/arm/mach-omap2/omap_hwmod_2420_data.c
index a5409ce3f323..a6bde34e443a 100644
--- a/arch/arm/mach-omap2/omap_hwmod_2420_data.c
+++ b/arch/arm/mach-omap2/omap_hwmod_2420_data.c
@@ -1000,7 +1000,6 @@ static struct omap_hwmod_ocp_if omap2420_l4_core__dss_venc = {
1000 .flags = OMAP_FIREWALL_L4, 1000 .flags = OMAP_FIREWALL_L4,
1001 } 1001 }
1002 }, 1002 },
1003 .flags = OCPIF_SWSUP_IDLE,
1004 .user = OCP_USER_MPU | OCP_USER_SDMA, 1003 .user = OCP_USER_MPU | OCP_USER_SDMA,
1005}; 1004};
1006 1005
diff --git a/arch/arm/mach-omap2/omap_hwmod_2430_data.c b/arch/arm/mach-omap2/omap_hwmod_2430_data.c
index c4f56cb60d7d..04a3885f4475 100644
--- a/arch/arm/mach-omap2/omap_hwmod_2430_data.c
+++ b/arch/arm/mach-omap2/omap_hwmod_2430_data.c
@@ -1049,7 +1049,6 @@ static struct omap_hwmod_ocp_if omap2430_l4_core__dss_venc = {
1049 .slave = &omap2430_dss_venc_hwmod, 1049 .slave = &omap2430_dss_venc_hwmod,
1050 .clk = "dss_ick", 1050 .clk = "dss_ick",
1051 .addr = omap2_dss_venc_addrs, 1051 .addr = omap2_dss_venc_addrs,
1052 .flags = OCPIF_SWSUP_IDLE,
1053 .user = OCP_USER_MPU | OCP_USER_SDMA, 1052 .user = OCP_USER_MPU | OCP_USER_SDMA,
1054}; 1053};
1055 1054
diff --git a/arch/arm/mach-omap2/omap_hwmod_3xxx_data.c b/arch/arm/mach-omap2/omap_hwmod_3xxx_data.c
index 34b9766d1d23..db86ce90c69f 100644
--- a/arch/arm/mach-omap2/omap_hwmod_3xxx_data.c
+++ b/arch/arm/mach-omap2/omap_hwmod_3xxx_data.c
@@ -1676,7 +1676,6 @@ static struct omap_hwmod_ocp_if omap3xxx_l4_core__dss_venc = {
1676 .flags = OMAP_FIREWALL_L4, 1676 .flags = OMAP_FIREWALL_L4,
1677 } 1677 }
1678 }, 1678 },
1679 .flags = OCPIF_SWSUP_IDLE,
1680 .user = OCP_USER_MPU | OCP_USER_SDMA, 1679 .user = OCP_USER_MPU | OCP_USER_SDMA,
1681}; 1680};
1682 1681
diff --git a/arch/arm/mach-omap2/omap_hwmod_44xx_data.c b/arch/arm/mach-omap2/omap_hwmod_44xx_data.c
index 08daa5e0eb5f..6abc75753e42 100644
--- a/arch/arm/mach-omap2/omap_hwmod_44xx_data.c
+++ b/arch/arm/mach-omap2/omap_hwmod_44xx_data.c
@@ -2594,6 +2594,15 @@ static struct omap_hwmod omap44xx_ipu_hwmod = {
2594static struct omap_hwmod_class_sysconfig omap44xx_iss_sysc = { 2594static struct omap_hwmod_class_sysconfig omap44xx_iss_sysc = {
2595 .rev_offs = 0x0000, 2595 .rev_offs = 0x0000,
2596 .sysc_offs = 0x0010, 2596 .sysc_offs = 0x0010,
2597 /*
2598 * ISS needs 100 OCP clk cycles delay after a softreset before
2599 * accessing sysconfig again.
2600 * The lowest frequency at the moment for L3 bus is 100 MHz, so
2601 * 1usec delay is needed. Add an x2 margin to be safe (2 usecs).
2602 *
2603 * TODO: Indicate errata when available.
2604 */
2605 .srst_udelay = 2,
2597 .sysc_flags = (SYSC_HAS_MIDLEMODE | SYSC_HAS_RESET_STATUS | 2606 .sysc_flags = (SYSC_HAS_MIDLEMODE | SYSC_HAS_RESET_STATUS |
2598 SYSC_HAS_SIDLEMODE | SYSC_HAS_SOFTRESET), 2607 SYSC_HAS_SIDLEMODE | SYSC_HAS_SOFTRESET),
2599 .idlemodes = (SIDLE_FORCE | SIDLE_NO | SIDLE_SMART | 2608 .idlemodes = (SIDLE_FORCE | SIDLE_NO | SIDLE_SMART |
@@ -2996,6 +3005,11 @@ static struct omap_hwmod_ocp_if *omap44xx_mcbsp1_slaves[] = {
2996 &omap44xx_l4_abe__mcbsp1_dma, 3005 &omap44xx_l4_abe__mcbsp1_dma,
2997}; 3006};
2998 3007
3008static struct omap_hwmod_opt_clk mcbsp1_opt_clks[] = {
3009 { .role = "pad_fck", .clk = "pad_clks_ck" },
3010 { .role = "prcm_clk", .clk = "mcbsp1_sync_mux_ck" },
3011};
3012
2999static struct omap_hwmod omap44xx_mcbsp1_hwmod = { 3013static struct omap_hwmod omap44xx_mcbsp1_hwmod = {
3000 .name = "mcbsp1", 3014 .name = "mcbsp1",
3001 .class = &omap44xx_mcbsp_hwmod_class, 3015 .class = &omap44xx_mcbsp_hwmod_class,
@@ -3012,6 +3026,8 @@ static struct omap_hwmod omap44xx_mcbsp1_hwmod = {
3012 }, 3026 },
3013 .slaves = omap44xx_mcbsp1_slaves, 3027 .slaves = omap44xx_mcbsp1_slaves,
3014 .slaves_cnt = ARRAY_SIZE(omap44xx_mcbsp1_slaves), 3028 .slaves_cnt = ARRAY_SIZE(omap44xx_mcbsp1_slaves),
3029 .opt_clks = mcbsp1_opt_clks,
3030 .opt_clks_cnt = ARRAY_SIZE(mcbsp1_opt_clks),
3015}; 3031};
3016 3032
3017/* mcbsp2 */ 3033/* mcbsp2 */
@@ -3071,6 +3087,11 @@ static struct omap_hwmod_ocp_if *omap44xx_mcbsp2_slaves[] = {
3071 &omap44xx_l4_abe__mcbsp2_dma, 3087 &omap44xx_l4_abe__mcbsp2_dma,
3072}; 3088};
3073 3089
3090static struct omap_hwmod_opt_clk mcbsp2_opt_clks[] = {
3091 { .role = "pad_fck", .clk = "pad_clks_ck" },
3092 { .role = "prcm_clk", .clk = "mcbsp2_sync_mux_ck" },
3093};
3094
3074static struct omap_hwmod omap44xx_mcbsp2_hwmod = { 3095static struct omap_hwmod omap44xx_mcbsp2_hwmod = {
3075 .name = "mcbsp2", 3096 .name = "mcbsp2",
3076 .class = &omap44xx_mcbsp_hwmod_class, 3097 .class = &omap44xx_mcbsp_hwmod_class,
@@ -3087,6 +3108,8 @@ static struct omap_hwmod omap44xx_mcbsp2_hwmod = {
3087 }, 3108 },
3088 .slaves = omap44xx_mcbsp2_slaves, 3109 .slaves = omap44xx_mcbsp2_slaves,
3089 .slaves_cnt = ARRAY_SIZE(omap44xx_mcbsp2_slaves), 3110 .slaves_cnt = ARRAY_SIZE(omap44xx_mcbsp2_slaves),
3111 .opt_clks = mcbsp2_opt_clks,
3112 .opt_clks_cnt = ARRAY_SIZE(mcbsp2_opt_clks),
3090}; 3113};
3091 3114
3092/* mcbsp3 */ 3115/* mcbsp3 */
@@ -3146,6 +3169,11 @@ static struct omap_hwmod_ocp_if *omap44xx_mcbsp3_slaves[] = {
3146 &omap44xx_l4_abe__mcbsp3_dma, 3169 &omap44xx_l4_abe__mcbsp3_dma,
3147}; 3170};
3148 3171
3172static struct omap_hwmod_opt_clk mcbsp3_opt_clks[] = {
3173 { .role = "pad_fck", .clk = "pad_clks_ck" },
3174 { .role = "prcm_clk", .clk = "mcbsp3_sync_mux_ck" },
3175};
3176
3149static struct omap_hwmod omap44xx_mcbsp3_hwmod = { 3177static struct omap_hwmod omap44xx_mcbsp3_hwmod = {
3150 .name = "mcbsp3", 3178 .name = "mcbsp3",
3151 .class = &omap44xx_mcbsp_hwmod_class, 3179 .class = &omap44xx_mcbsp_hwmod_class,
@@ -3162,6 +3190,8 @@ static struct omap_hwmod omap44xx_mcbsp3_hwmod = {
3162 }, 3190 },
3163 .slaves = omap44xx_mcbsp3_slaves, 3191 .slaves = omap44xx_mcbsp3_slaves,
3164 .slaves_cnt = ARRAY_SIZE(omap44xx_mcbsp3_slaves), 3192 .slaves_cnt = ARRAY_SIZE(omap44xx_mcbsp3_slaves),
3193 .opt_clks = mcbsp3_opt_clks,
3194 .opt_clks_cnt = ARRAY_SIZE(mcbsp3_opt_clks),
3165}; 3195};
3166 3196
3167/* mcbsp4 */ 3197/* mcbsp4 */
@@ -3200,6 +3230,11 @@ static struct omap_hwmod_ocp_if *omap44xx_mcbsp4_slaves[] = {
3200 &omap44xx_l4_per__mcbsp4, 3230 &omap44xx_l4_per__mcbsp4,
3201}; 3231};
3202 3232
3233static struct omap_hwmod_opt_clk mcbsp4_opt_clks[] = {
3234 { .role = "pad_fck", .clk = "pad_clks_ck" },
3235 { .role = "prcm_clk", .clk = "mcbsp4_sync_mux_ck" },
3236};
3237
3203static struct omap_hwmod omap44xx_mcbsp4_hwmod = { 3238static struct omap_hwmod omap44xx_mcbsp4_hwmod = {
3204 .name = "mcbsp4", 3239 .name = "mcbsp4",
3205 .class = &omap44xx_mcbsp_hwmod_class, 3240 .class = &omap44xx_mcbsp_hwmod_class,
@@ -3216,6 +3251,8 @@ static struct omap_hwmod omap44xx_mcbsp4_hwmod = {
3216 }, 3251 },
3217 .slaves = omap44xx_mcbsp4_slaves, 3252 .slaves = omap44xx_mcbsp4_slaves,
3218 .slaves_cnt = ARRAY_SIZE(omap44xx_mcbsp4_slaves), 3253 .slaves_cnt = ARRAY_SIZE(omap44xx_mcbsp4_slaves),
3254 .opt_clks = mcbsp4_opt_clks,
3255 .opt_clks_cnt = ARRAY_SIZE(mcbsp4_opt_clks),
3219}; 3256};
3220 3257
3221/* 3258/*
diff --git a/arch/arm/mach-omap2/opp.c b/arch/arm/mach-omap2/opp.c
index 9262a6b47702..de6d46451746 100644
--- a/arch/arm/mach-omap2/opp.c
+++ b/arch/arm/mach-omap2/opp.c
@@ -64,10 +64,10 @@ int __init omap_init_opp_table(struct omap_opp_def *opp_def,
64 } 64 }
65 oh = omap_hwmod_lookup(opp_def->hwmod_name); 65 oh = omap_hwmod_lookup(opp_def->hwmod_name);
66 if (!oh || !oh->od) { 66 if (!oh || !oh->od) {
67 pr_warn("%s: no hwmod or odev for %s, [%d] " 67 pr_debug("%s: no hwmod or odev for %s, [%d] "
68 "cannot add OPPs.\n", __func__, 68 "cannot add OPPs.\n", __func__,
69 opp_def->hwmod_name, i); 69 opp_def->hwmod_name, i);
70 return -EINVAL; 70 continue;
71 } 71 }
72 dev = &oh->od->pdev->dev; 72 dev = &oh->od->pdev->dev;
73 73
diff --git a/arch/arm/mach-omap2/pm34xx.c b/arch/arm/mach-omap2/pm34xx.c
index 238defc6f6df..703bd1099259 100644
--- a/arch/arm/mach-omap2/pm34xx.c
+++ b/arch/arm/mach-omap2/pm34xx.c
@@ -153,8 +153,7 @@ static void omap3_save_secure_ram_context(void)
153 pwrdm_set_next_pwrst(mpu_pwrdm, mpu_next_state); 153 pwrdm_set_next_pwrst(mpu_pwrdm, mpu_next_state);
154 /* Following is for error tracking, it should not happen */ 154 /* Following is for error tracking, it should not happen */
155 if (ret) { 155 if (ret) {
156 printk(KERN_ERR "save_secure_sram() returns %08x\n", 156 pr_err("save_secure_sram() returns %08x\n", ret);
157 ret);
158 while (1) 157 while (1)
159 ; 158 ;
160 } 159 }
@@ -289,7 +288,7 @@ void omap_sram_idle(void)
289 break; 288 break;
290 default: 289 default:
291 /* Invalid state */ 290 /* Invalid state */
292 printk(KERN_ERR "Invalid mpu state in sram_idle\n"); 291 pr_err("Invalid mpu state in sram_idle\n");
293 return; 292 return;
294 } 293 }
295 294
@@ -439,18 +438,17 @@ restore:
439 list_for_each_entry(pwrst, &pwrst_list, node) { 438 list_for_each_entry(pwrst, &pwrst_list, node) {
440 state = pwrdm_read_prev_pwrst(pwrst->pwrdm); 439 state = pwrdm_read_prev_pwrst(pwrst->pwrdm);
441 if (state > pwrst->next_state) { 440 if (state > pwrst->next_state) {
442 printk(KERN_INFO "Powerdomain (%s) didn't enter " 441 pr_info("Powerdomain (%s) didn't enter "
443 "target state %d\n", 442 "target state %d\n",
444 pwrst->pwrdm->name, pwrst->next_state); 443 pwrst->pwrdm->name, pwrst->next_state);
445 ret = -1; 444 ret = -1;
446 } 445 }
447 omap_set_pwrdm_state(pwrst->pwrdm, pwrst->saved_state); 446 omap_set_pwrdm_state(pwrst->pwrdm, pwrst->saved_state);
448 } 447 }
449 if (ret) 448 if (ret)
450 printk(KERN_ERR "Could not enter target state in pm_suspend\n"); 449 pr_err("Could not enter target state in pm_suspend\n");
451 else 450 else
452 printk(KERN_INFO "Successfully put all powerdomains " 451 pr_info("Successfully put all powerdomains to target state\n");
453 "to target state\n");
454 452
455 return ret; 453 return ret;
456} 454}
@@ -734,21 +732,22 @@ static int __init omap3_pm_init(void)
734 732
735 if (ret) { 733 if (ret) {
736 pr_err("pm: Failed to request pm_io irq\n"); 734 pr_err("pm: Failed to request pm_io irq\n");
737 goto err1; 735 goto err2;
738 } 736 }
739 737
740 ret = pwrdm_for_each(pwrdms_setup, NULL); 738 ret = pwrdm_for_each(pwrdms_setup, NULL);
741 if (ret) { 739 if (ret) {
742 printk(KERN_ERR "Failed to setup powerdomains\n"); 740 pr_err("Failed to setup powerdomains\n");
743 goto err2; 741 goto err3;
744 } 742 }
745 743
746 (void) clkdm_for_each(omap_pm_clkdms_setup, NULL); 744 (void) clkdm_for_each(omap_pm_clkdms_setup, NULL);
747 745
748 mpu_pwrdm = pwrdm_lookup("mpu_pwrdm"); 746 mpu_pwrdm = pwrdm_lookup("mpu_pwrdm");
749 if (mpu_pwrdm == NULL) { 747 if (mpu_pwrdm == NULL) {
750 printk(KERN_ERR "Failed to get mpu_pwrdm\n"); 748 pr_err("Failed to get mpu_pwrdm\n");
751 goto err2; 749 ret = -EINVAL;
750 goto err3;
752 } 751 }
753 752
754 neon_pwrdm = pwrdm_lookup("neon_pwrdm"); 753 neon_pwrdm = pwrdm_lookup("neon_pwrdm");
@@ -781,8 +780,8 @@ static int __init omap3_pm_init(void)
781 omap3_secure_ram_storage = 780 omap3_secure_ram_storage =
782 kmalloc(0x803F, GFP_KERNEL); 781 kmalloc(0x803F, GFP_KERNEL);
783 if (!omap3_secure_ram_storage) 782 if (!omap3_secure_ram_storage)
784 printk(KERN_ERR "Memory allocation failed when" 783 pr_err("Memory allocation failed when "
785 "allocating for secure sram context\n"); 784 "allocating for secure sram context\n");
786 785
787 local_irq_disable(); 786 local_irq_disable();
788 local_fiq_disable(); 787 local_fiq_disable();
@@ -796,14 +795,17 @@ static int __init omap3_pm_init(void)
796 } 795 }
797 796
798 omap3_save_scratchpad_contents(); 797 omap3_save_scratchpad_contents();
799err1:
800 return ret; 798 return ret;
801err2: 799
802 free_irq(INT_34XX_PRCM_MPU_IRQ, NULL); 800err3:
803 list_for_each_entry_safe(pwrst, tmp, &pwrst_list, node) { 801 list_for_each_entry_safe(pwrst, tmp, &pwrst_list, node) {
804 list_del(&pwrst->node); 802 list_del(&pwrst->node);
805 kfree(pwrst); 803 kfree(pwrst);
806 } 804 }
805 free_irq(omap_prcm_event_to_irq("io"), omap3_pm_init);
806err2:
807 free_irq(omap_prcm_event_to_irq("wkup"), NULL);
808err1:
807 return ret; 809 return ret;
808} 810}
809 811
diff --git a/arch/arm/mach-omap2/pm44xx.c b/arch/arm/mach-omap2/pm44xx.c
index 9ccaadc2cf07..885625352429 100644
--- a/arch/arm/mach-omap2/pm44xx.c
+++ b/arch/arm/mach-omap2/pm44xx.c
@@ -144,7 +144,7 @@ static void omap_default_idle(void)
144static int __init omap4_pm_init(void) 144static int __init omap4_pm_init(void)
145{ 145{
146 int ret; 146 int ret;
147 struct clockdomain *emif_clkdm, *mpuss_clkdm, *l3_1_clkdm; 147 struct clockdomain *emif_clkdm, *mpuss_clkdm, *l3_1_clkdm, *l4wkup;
148 struct clockdomain *ducati_clkdm, *l3_2_clkdm, *l4_per_clkdm; 148 struct clockdomain *ducati_clkdm, *l3_2_clkdm, *l4_per_clkdm;
149 149
150 if (!cpu_is_omap44xx()) 150 if (!cpu_is_omap44xx())
@@ -168,14 +168,19 @@ static int __init omap4_pm_init(void)
168 * MPUSS -> L4_PER/L3_* and DUCATI -> L3_* doesn't work as 168 * MPUSS -> L4_PER/L3_* and DUCATI -> L3_* doesn't work as
169 * expected. The hardware recommendation is to enable static 169 * expected. The hardware recommendation is to enable static
170 * dependencies for these to avoid system lock ups or random crashes. 170 * dependencies for these to avoid system lock ups or random crashes.
171 * The L4 wakeup depedency is added to workaround the OCP sync hardware
172 * BUG with 32K synctimer which lead to incorrect timer value read
173 * from the 32K counter. The BUG applies for GPTIMER1 and WDT2 which
174 * are part of L4 wakeup clockdomain.
171 */ 175 */
172 mpuss_clkdm = clkdm_lookup("mpuss_clkdm"); 176 mpuss_clkdm = clkdm_lookup("mpuss_clkdm");
173 emif_clkdm = clkdm_lookup("l3_emif_clkdm"); 177 emif_clkdm = clkdm_lookup("l3_emif_clkdm");
174 l3_1_clkdm = clkdm_lookup("l3_1_clkdm"); 178 l3_1_clkdm = clkdm_lookup("l3_1_clkdm");
175 l3_2_clkdm = clkdm_lookup("l3_2_clkdm"); 179 l3_2_clkdm = clkdm_lookup("l3_2_clkdm");
176 l4_per_clkdm = clkdm_lookup("l4_per_clkdm"); 180 l4_per_clkdm = clkdm_lookup("l4_per_clkdm");
181 l4wkup = clkdm_lookup("l4_wkup_clkdm");
177 ducati_clkdm = clkdm_lookup("ducati_clkdm"); 182 ducati_clkdm = clkdm_lookup("ducati_clkdm");
178 if ((!mpuss_clkdm) || (!emif_clkdm) || (!l3_1_clkdm) || 183 if ((!mpuss_clkdm) || (!emif_clkdm) || (!l3_1_clkdm) || (!l4wkup) ||
179 (!l3_2_clkdm) || (!ducati_clkdm) || (!l4_per_clkdm)) 184 (!l3_2_clkdm) || (!ducati_clkdm) || (!l4_per_clkdm))
180 goto err2; 185 goto err2;
181 186
@@ -183,6 +188,7 @@ static int __init omap4_pm_init(void)
183 ret |= clkdm_add_wkdep(mpuss_clkdm, l3_1_clkdm); 188 ret |= clkdm_add_wkdep(mpuss_clkdm, l3_1_clkdm);
184 ret |= clkdm_add_wkdep(mpuss_clkdm, l3_2_clkdm); 189 ret |= clkdm_add_wkdep(mpuss_clkdm, l3_2_clkdm);
185 ret |= clkdm_add_wkdep(mpuss_clkdm, l4_per_clkdm); 190 ret |= clkdm_add_wkdep(mpuss_clkdm, l4_per_clkdm);
191 ret |= clkdm_add_wkdep(mpuss_clkdm, l4wkup);
186 ret |= clkdm_add_wkdep(ducati_clkdm, l3_1_clkdm); 192 ret |= clkdm_add_wkdep(ducati_clkdm, l3_1_clkdm);
187 ret |= clkdm_add_wkdep(ducati_clkdm, l3_2_clkdm); 193 ret |= clkdm_add_wkdep(ducati_clkdm, l3_2_clkdm);
188 if (ret) { 194 if (ret) {
diff --git a/arch/arm/mach-omap2/powerdomain.c b/arch/arm/mach-omap2/powerdomain.c
index 8a18d1bd61c8..96ad3dbeac34 100644
--- a/arch/arm/mach-omap2/powerdomain.c
+++ b/arch/arm/mach-omap2/powerdomain.c
@@ -972,7 +972,13 @@ int pwrdm_wait_transition(struct powerdomain *pwrdm)
972 972
973int pwrdm_state_switch(struct powerdomain *pwrdm) 973int pwrdm_state_switch(struct powerdomain *pwrdm)
974{ 974{
975 return _pwrdm_state_switch(pwrdm, PWRDM_STATE_NOW); 975 int ret;
976
977 ret = pwrdm_wait_transition(pwrdm);
978 if (!ret)
979 ret = _pwrdm_state_switch(pwrdm, PWRDM_STATE_NOW);
980
981 return ret;
976} 982}
977 983
978int pwrdm_clkdm_state_switch(struct clockdomain *clkdm) 984int pwrdm_clkdm_state_switch(struct clockdomain *clkdm)
diff --git a/arch/arm/mach-omap2/prm44xx.c b/arch/arm/mach-omap2/prm44xx.c
index eac623c7c3d8..f106d21ff581 100644
--- a/arch/arm/mach-omap2/prm44xx.c
+++ b/arch/arm/mach-omap2/prm44xx.c
@@ -147,8 +147,9 @@ static inline u32 _read_pending_irq_reg(u16 irqen_offs, u16 irqst_offs)
147 u32 mask, st; 147 u32 mask, st;
148 148
149 /* XXX read mask from RAM? */ 149 /* XXX read mask from RAM? */
150 mask = omap4_prm_read_inst_reg(OMAP4430_PRM_DEVICE_INST, irqen_offs); 150 mask = omap4_prm_read_inst_reg(OMAP4430_PRM_OCP_SOCKET_INST,
151 st = omap4_prm_read_inst_reg(OMAP4430_PRM_DEVICE_INST, irqst_offs); 151 irqen_offs);
152 st = omap4_prm_read_inst_reg(OMAP4430_PRM_OCP_SOCKET_INST, irqst_offs);
152 153
153 return mask & st; 154 return mask & st;
154} 155}
@@ -180,7 +181,7 @@ void omap44xx_prm_read_pending_irqs(unsigned long *events)
180 */ 181 */
181void omap44xx_prm_ocp_barrier(void) 182void omap44xx_prm_ocp_barrier(void)
182{ 183{
183 omap4_prm_read_inst_reg(OMAP4430_PRM_DEVICE_INST, 184 omap4_prm_read_inst_reg(OMAP4430_PRM_OCP_SOCKET_INST,
184 OMAP4_REVISION_PRM_OFFSET); 185 OMAP4_REVISION_PRM_OFFSET);
185} 186}
186 187
@@ -198,19 +199,19 @@ void omap44xx_prm_ocp_barrier(void)
198void omap44xx_prm_save_and_clear_irqen(u32 *saved_mask) 199void omap44xx_prm_save_and_clear_irqen(u32 *saved_mask)
199{ 200{
200 saved_mask[0] = 201 saved_mask[0] =
201 omap4_prm_read_inst_reg(OMAP4430_PRM_DEVICE_INST, 202 omap4_prm_read_inst_reg(OMAP4430_PRM_OCP_SOCKET_INST,
202 OMAP4_PRM_IRQSTATUS_MPU_OFFSET); 203 OMAP4_PRM_IRQSTATUS_MPU_OFFSET);
203 saved_mask[1] = 204 saved_mask[1] =
204 omap4_prm_read_inst_reg(OMAP4430_PRM_DEVICE_INST, 205 omap4_prm_read_inst_reg(OMAP4430_PRM_OCP_SOCKET_INST,
205 OMAP4_PRM_IRQSTATUS_MPU_2_OFFSET); 206 OMAP4_PRM_IRQSTATUS_MPU_2_OFFSET);
206 207
207 omap4_prm_write_inst_reg(0, OMAP4430_PRM_DEVICE_INST, 208 omap4_prm_write_inst_reg(0, OMAP4430_PRM_OCP_SOCKET_INST,
208 OMAP4_PRM_IRQENABLE_MPU_OFFSET); 209 OMAP4_PRM_IRQENABLE_MPU_OFFSET);
209 omap4_prm_write_inst_reg(0, OMAP4430_PRM_DEVICE_INST, 210 omap4_prm_write_inst_reg(0, OMAP4430_PRM_OCP_SOCKET_INST,
210 OMAP4_PRM_IRQENABLE_MPU_2_OFFSET); 211 OMAP4_PRM_IRQENABLE_MPU_2_OFFSET);
211 212
212 /* OCP barrier */ 213 /* OCP barrier */
213 omap4_prm_read_inst_reg(OMAP4430_PRM_DEVICE_INST, 214 omap4_prm_read_inst_reg(OMAP4430_PRM_OCP_SOCKET_INST,
214 OMAP4_REVISION_PRM_OFFSET); 215 OMAP4_REVISION_PRM_OFFSET);
215} 216}
216 217
@@ -226,9 +227,9 @@ void omap44xx_prm_save_and_clear_irqen(u32 *saved_mask)
226 */ 227 */
227void omap44xx_prm_restore_irqen(u32 *saved_mask) 228void omap44xx_prm_restore_irqen(u32 *saved_mask)
228{ 229{
229 omap4_prm_write_inst_reg(saved_mask[0], OMAP4430_PRM_DEVICE_INST, 230 omap4_prm_write_inst_reg(saved_mask[0], OMAP4430_PRM_OCP_SOCKET_INST,
230 OMAP4_PRM_IRQENABLE_MPU_OFFSET); 231 OMAP4_PRM_IRQENABLE_MPU_OFFSET);
231 omap4_prm_write_inst_reg(saved_mask[1], OMAP4430_PRM_DEVICE_INST, 232 omap4_prm_write_inst_reg(saved_mask[1], OMAP4430_PRM_OCP_SOCKET_INST,
232 OMAP4_PRM_IRQENABLE_MPU_2_OFFSET); 233 OMAP4_PRM_IRQENABLE_MPU_2_OFFSET);
233} 234}
234 235
diff --git a/arch/arm/mach-omap2/prm_common.c b/arch/arm/mach-omap2/prm_common.c
index 873b51d494ea..d28f848897d6 100644
--- a/arch/arm/mach-omap2/prm_common.c
+++ b/arch/arm/mach-omap2/prm_common.c
@@ -290,7 +290,7 @@ int omap_prcm_register_chain_handler(struct omap_prcm_irq_setup *irq_setup)
290 goto err; 290 goto err;
291 } 291 }
292 292
293 for (i = 0; i <= irq_setup->nr_regs; i++) { 293 for (i = 0; i < irq_setup->nr_regs; i++) {
294 gc = irq_alloc_generic_chip("PRCM", 1, 294 gc = irq_alloc_generic_chip("PRCM", 1,
295 irq_setup->base_irq + i * 32, prm_base, 295 irq_setup->base_irq + i * 32, prm_base,
296 handle_level_irq); 296 handle_level_irq);
diff --git a/arch/arm/mach-omap2/serial.c b/arch/arm/mach-omap2/serial.c
index 0cdd359a128e..9fc2f44188cb 100644
--- a/arch/arm/mach-omap2/serial.c
+++ b/arch/arm/mach-omap2/serial.c
@@ -108,8 +108,14 @@ static void omap_uart_set_noidle(struct platform_device *pdev)
108static void omap_uart_set_smartidle(struct platform_device *pdev) 108static void omap_uart_set_smartidle(struct platform_device *pdev)
109{ 109{
110 struct omap_device *od = to_omap_device(pdev); 110 struct omap_device *od = to_omap_device(pdev);
111 u8 idlemode;
111 112
112 omap_hwmod_set_slave_idlemode(od->hwmods[0], HWMOD_IDLEMODE_SMART); 113 if (od->hwmods[0]->class->sysc->idlemodes & SIDLE_SMART_WKUP)
114 idlemode = HWMOD_IDLEMODE_SMART_WKUP;
115 else
116 idlemode = HWMOD_IDLEMODE_SMART;
117
118 omap_hwmod_set_slave_idlemode(od->hwmods[0], idlemode);
113} 119}
114 120
115#else 121#else
@@ -120,124 +126,8 @@ static void omap_uart_set_smartidle(struct platform_device *pdev) {}
120#endif /* CONFIG_PM */ 126#endif /* CONFIG_PM */
121 127
122#ifdef CONFIG_OMAP_MUX 128#ifdef CONFIG_OMAP_MUX
123static struct omap_device_pad default_uart1_pads[] __initdata = {
124 {
125 .name = "uart1_cts.uart1_cts",
126 .enable = OMAP_PIN_INPUT_PULLUP | OMAP_MUX_MODE0,
127 },
128 {
129 .name = "uart1_rts.uart1_rts",
130 .enable = OMAP_PIN_OUTPUT | OMAP_MUX_MODE0,
131 },
132 {
133 .name = "uart1_tx.uart1_tx",
134 .enable = OMAP_PIN_OUTPUT | OMAP_MUX_MODE0,
135 },
136 {
137 .name = "uart1_rx.uart1_rx",
138 .flags = OMAP_DEVICE_PAD_REMUX | OMAP_DEVICE_PAD_WAKEUP,
139 .enable = OMAP_PIN_INPUT_PULLUP | OMAP_MUX_MODE0,
140 .idle = OMAP_PIN_INPUT_PULLUP | OMAP_MUX_MODE0,
141 },
142};
143
144static struct omap_device_pad default_uart2_pads[] __initdata = {
145 {
146 .name = "uart2_cts.uart2_cts",
147 .enable = OMAP_PIN_INPUT_PULLUP | OMAP_MUX_MODE0,
148 },
149 {
150 .name = "uart2_rts.uart2_rts",
151 .enable = OMAP_PIN_OUTPUT | OMAP_MUX_MODE0,
152 },
153 {
154 .name = "uart2_tx.uart2_tx",
155 .enable = OMAP_PIN_OUTPUT | OMAP_MUX_MODE0,
156 },
157 {
158 .name = "uart2_rx.uart2_rx",
159 .flags = OMAP_DEVICE_PAD_REMUX | OMAP_DEVICE_PAD_WAKEUP,
160 .enable = OMAP_PIN_INPUT_PULLUP | OMAP_MUX_MODE0,
161 .idle = OMAP_PIN_INPUT_PULLUP | OMAP_MUX_MODE0,
162 },
163};
164
165static struct omap_device_pad default_uart3_pads[] __initdata = {
166 {
167 .name = "uart3_cts_rctx.uart3_cts_rctx",
168 .enable = OMAP_PIN_INPUT_PULLUP | OMAP_MUX_MODE0,
169 },
170 {
171 .name = "uart3_rts_sd.uart3_rts_sd",
172 .enable = OMAP_PIN_OUTPUT | OMAP_MUX_MODE0,
173 },
174 {
175 .name = "uart3_tx_irtx.uart3_tx_irtx",
176 .enable = OMAP_PIN_OUTPUT | OMAP_MUX_MODE0,
177 },
178 {
179 .name = "uart3_rx_irrx.uart3_rx_irrx",
180 .flags = OMAP_DEVICE_PAD_REMUX | OMAP_DEVICE_PAD_WAKEUP,
181 .enable = OMAP_PIN_INPUT | OMAP_MUX_MODE0,
182 .idle = OMAP_PIN_INPUT | OMAP_MUX_MODE0,
183 },
184};
185
186static struct omap_device_pad default_omap36xx_uart4_pads[] __initdata = {
187 {
188 .name = "gpmc_wait2.uart4_tx",
189 .enable = OMAP_PIN_OUTPUT | OMAP_MUX_MODE0,
190 },
191 {
192 .name = "gpmc_wait3.uart4_rx",
193 .flags = OMAP_DEVICE_PAD_REMUX | OMAP_DEVICE_PAD_WAKEUP,
194 .enable = OMAP_PIN_INPUT | OMAP_MUX_MODE2,
195 .idle = OMAP_PIN_INPUT | OMAP_MUX_MODE2,
196 },
197};
198
199static struct omap_device_pad default_omap4_uart4_pads[] __initdata = {
200 {
201 .name = "uart4_tx.uart4_tx",
202 .enable = OMAP_PIN_OUTPUT | OMAP_MUX_MODE0,
203 },
204 {
205 .name = "uart4_rx.uart4_rx",
206 .flags = OMAP_DEVICE_PAD_REMUX | OMAP_DEVICE_PAD_WAKEUP,
207 .enable = OMAP_PIN_INPUT | OMAP_MUX_MODE0,
208 .idle = OMAP_PIN_INPUT | OMAP_MUX_MODE0,
209 },
210};
211
212static void omap_serial_fill_default_pads(struct omap_board_data *bdata) 129static void omap_serial_fill_default_pads(struct omap_board_data *bdata)
213{ 130{
214 switch (bdata->id) {
215 case 0:
216 bdata->pads = default_uart1_pads;
217 bdata->pads_cnt = ARRAY_SIZE(default_uart1_pads);
218 break;
219 case 1:
220 bdata->pads = default_uart2_pads;
221 bdata->pads_cnt = ARRAY_SIZE(default_uart2_pads);
222 break;
223 case 2:
224 bdata->pads = default_uart3_pads;
225 bdata->pads_cnt = ARRAY_SIZE(default_uart3_pads);
226 break;
227 case 3:
228 if (cpu_is_omap44xx()) {
229 bdata->pads = default_omap4_uart4_pads;
230 bdata->pads_cnt =
231 ARRAY_SIZE(default_omap4_uart4_pads);
232 } else if (cpu_is_omap3630()) {
233 bdata->pads = default_omap36xx_uart4_pads;
234 bdata->pads_cnt =
235 ARRAY_SIZE(default_omap36xx_uart4_pads);
236 }
237 break;
238 default:
239 break;
240 }
241} 131}
242#else 132#else
243static void omap_serial_fill_default_pads(struct omap_board_data *bdata) {} 133static void omap_serial_fill_default_pads(struct omap_board_data *bdata) {}
diff --git a/arch/arm/mach-omap2/twl-common.c b/arch/arm/mach-omap2/twl-common.c
index 4b57757bf9d1..7a7b89304c48 100644
--- a/arch/arm/mach-omap2/twl-common.c
+++ b/arch/arm/mach-omap2/twl-common.c
@@ -37,6 +37,16 @@ static struct i2c_board_info __initdata pmic_i2c_board_info = {
37 .flags = I2C_CLIENT_WAKE, 37 .flags = I2C_CLIENT_WAKE,
38}; 38};
39 39
40static struct i2c_board_info __initdata omap4_i2c1_board_info[] = {
41 {
42 .addr = 0x48,
43 .flags = I2C_CLIENT_WAKE,
44 },
45 {
46 I2C_BOARD_INFO("twl6040", 0x4b),
47 },
48};
49
40void __init omap_pmic_init(int bus, u32 clkrate, 50void __init omap_pmic_init(int bus, u32 clkrate,
41 const char *pmic_type, int pmic_irq, 51 const char *pmic_type, int pmic_irq,
42 struct twl4030_platform_data *pmic_data) 52 struct twl4030_platform_data *pmic_data)
@@ -49,14 +59,31 @@ void __init omap_pmic_init(int bus, u32 clkrate,
49 omap_register_i2c_bus(bus, clkrate, &pmic_i2c_board_info, 1); 59 omap_register_i2c_bus(bus, clkrate, &pmic_i2c_board_info, 1);
50} 60}
51 61
62void __init omap4_pmic_init(const char *pmic_type,
63 struct twl4030_platform_data *pmic_data,
64 struct twl6040_platform_data *twl6040_data, int twl6040_irq)
65{
66 /* PMIC part*/
67 strncpy(omap4_i2c1_board_info[0].type, pmic_type,
68 sizeof(omap4_i2c1_board_info[0].type));
69 omap4_i2c1_board_info[0].irq = OMAP44XX_IRQ_SYS_1N;
70 omap4_i2c1_board_info[0].platform_data = pmic_data;
71
72 /* TWL6040 audio IC part */
73 omap4_i2c1_board_info[1].irq = twl6040_irq;
74 omap4_i2c1_board_info[1].platform_data = twl6040_data;
75
76 omap_register_i2c_bus(1, 400, omap4_i2c1_board_info, 2);
77
78}
79
52void __init omap_pmic_late_init(void) 80void __init omap_pmic_late_init(void)
53{ 81{
54 /* Init the OMAP TWL parameters (if PMIC has been registerd) */ 82 /* Init the OMAP TWL parameters (if PMIC has been registerd) */
55 if (!pmic_i2c_board_info.irq) 83 if (pmic_i2c_board_info.irq)
56 return; 84 omap3_twl_init();
57 85 if (omap4_i2c1_board_info[0].irq)
58 omap3_twl_init(); 86 omap4_twl_init();
59 omap4_twl_init();
60} 87}
61 88
62#if defined(CONFIG_ARCH_OMAP3) 89#if defined(CONFIG_ARCH_OMAP3)
diff --git a/arch/arm/mach-omap2/twl-common.h b/arch/arm/mach-omap2/twl-common.h
index 275dde8cb27a..09627483a57f 100644
--- a/arch/arm/mach-omap2/twl-common.h
+++ b/arch/arm/mach-omap2/twl-common.h
@@ -29,6 +29,7 @@
29 29
30 30
31struct twl4030_platform_data; 31struct twl4030_platform_data;
32struct twl6040_platform_data;
32 33
33void omap_pmic_init(int bus, u32 clkrate, const char *pmic_type, int pmic_irq, 34void omap_pmic_init(int bus, u32 clkrate, const char *pmic_type, int pmic_irq,
34 struct twl4030_platform_data *pmic_data); 35 struct twl4030_platform_data *pmic_data);
@@ -46,12 +47,9 @@ static inline void omap3_pmic_init(const char *pmic_type,
46 omap_pmic_init(1, 2600, pmic_type, INT_34XX_SYS_NIRQ, pmic_data); 47 omap_pmic_init(1, 2600, pmic_type, INT_34XX_SYS_NIRQ, pmic_data);
47} 48}
48 49
49static inline void omap4_pmic_init(const char *pmic_type, 50void omap4_pmic_init(const char *pmic_type,
50 struct twl4030_platform_data *pmic_data) 51 struct twl4030_platform_data *pmic_data,
51{ 52 struct twl6040_platform_data *audio_data, int twl6040_irq);
52 /* Phoenix Audio IC needs I2C1 to start with 400 KHz or less */
53 omap_pmic_init(1, 400, pmic_type, OMAP44XX_IRQ_SYS_1N, pmic_data);
54}
55 53
56void omap3_pmic_get_config(struct twl4030_platform_data *pmic_data, 54void omap3_pmic_get_config(struct twl4030_platform_data *pmic_data,
57 u32 pdata_flags, u32 regulators_flags); 55 u32 pdata_flags, u32 regulators_flags);
diff --git a/arch/arm/mach-omap2/usb-host.c b/arch/arm/mach-omap2/usb-host.c
index f51348dafafd..dde8a11f47d5 100644
--- a/arch/arm/mach-omap2/usb-host.c
+++ b/arch/arm/mach-omap2/usb-host.c
@@ -54,7 +54,7 @@ static struct omap_device_pm_latency omap_uhhtll_latency[] = {
54/* 54/*
55 * setup_ehci_io_mux - initialize IO pad mux for USBHOST 55 * setup_ehci_io_mux - initialize IO pad mux for USBHOST
56 */ 56 */
57static void setup_ehci_io_mux(const enum usbhs_omap_port_mode *port_mode) 57static void __init setup_ehci_io_mux(const enum usbhs_omap_port_mode *port_mode)
58{ 58{
59 switch (port_mode[0]) { 59 switch (port_mode[0]) {
60 case OMAP_EHCI_PORT_MODE_PHY: 60 case OMAP_EHCI_PORT_MODE_PHY:
@@ -197,7 +197,8 @@ static void setup_ehci_io_mux(const enum usbhs_omap_port_mode *port_mode)
197 return; 197 return;
198} 198}
199 199
200static void setup_4430ehci_io_mux(const enum usbhs_omap_port_mode *port_mode) 200static
201void __init setup_4430ehci_io_mux(const enum usbhs_omap_port_mode *port_mode)
201{ 202{
202 switch (port_mode[0]) { 203 switch (port_mode[0]) {
203 case OMAP_EHCI_PORT_MODE_PHY: 204 case OMAP_EHCI_PORT_MODE_PHY:
@@ -315,7 +316,7 @@ static void setup_4430ehci_io_mux(const enum usbhs_omap_port_mode *port_mode)
315 } 316 }
316} 317}
317 318
318static void setup_ohci_io_mux(const enum usbhs_omap_port_mode *port_mode) 319static void __init setup_ohci_io_mux(const enum usbhs_omap_port_mode *port_mode)
319{ 320{
320 switch (port_mode[0]) { 321 switch (port_mode[0]) {
321 case OMAP_OHCI_PORT_MODE_PHY_6PIN_DATSE0: 322 case OMAP_OHCI_PORT_MODE_PHY_6PIN_DATSE0:
@@ -412,7 +413,8 @@ static void setup_ohci_io_mux(const enum usbhs_omap_port_mode *port_mode)
412 } 413 }
413} 414}
414 415
415static void setup_4430ohci_io_mux(const enum usbhs_omap_port_mode *port_mode) 416static
417void __init setup_4430ohci_io_mux(const enum usbhs_omap_port_mode *port_mode)
416{ 418{
417 switch (port_mode[0]) { 419 switch (port_mode[0]) {
418 case OMAP_OHCI_PORT_MODE_PHY_6PIN_DATSE0: 420 case OMAP_OHCI_PORT_MODE_PHY_6PIN_DATSE0:
diff --git a/arch/arm/mach-orion5x/mpp.h b/arch/arm/mach-orion5x/mpp.h
index eac68978a2c2..db70e79a1198 100644
--- a/arch/arm/mach-orion5x/mpp.h
+++ b/arch/arm/mach-orion5x/mpp.h
@@ -65,8 +65,8 @@
65#define MPP8_GIGE MPP(8, 0x1, 0, 0, 1, 1, 1) 65#define MPP8_GIGE MPP(8, 0x1, 0, 0, 1, 1, 1)
66 66
67#define MPP9_UNUSED MPP(9, 0x0, 0, 0, 1, 1, 1) 67#define MPP9_UNUSED MPP(9, 0x0, 0, 0, 1, 1, 1)
68#define MPP9_GPIO MPP(9, 0x0, 0, 0, 1, 1, 1) 68#define MPP9_GPIO MPP(9, 0x0, 1, 1, 1, 1, 1)
69#define MPP9_GIGE MPP(9, 0x1, 1, 1, 1, 1, 1) 69#define MPP9_GIGE MPP(9, 0x1, 0, 0, 1, 1, 1)
70 70
71#define MPP10_UNUSED MPP(10, 0x0, 0, 0, 1, 1, 1) 71#define MPP10_UNUSED MPP(10, 0x0, 0, 0, 1, 1, 1)
72#define MPP10_GPIO MPP(10, 0x0, 1, 1, 1, 1, 1) 72#define MPP10_GPIO MPP(10, 0x0, 1, 1, 1, 1, 1)
diff --git a/arch/arm/mach-pxa/Kconfig b/arch/arm/mach-pxa/Kconfig
index 109ccd2a8885..fe2d1f80ef50 100644
--- a/arch/arm/mach-pxa/Kconfig
+++ b/arch/arm/mach-pxa/Kconfig
@@ -113,6 +113,7 @@ config MACH_ARMCORE
113 select IWMMXT 113 select IWMMXT
114 select PXA25x 114 select PXA25x
115 select MIGHT_HAVE_PCI 115 select MIGHT_HAVE_PCI
116 select NEED_MACH_IO_H if PCI
116 117
117config MACH_EM_X270 118config MACH_EM_X270
118 bool "CompuLab EM-x270 platform" 119 bool "CompuLab EM-x270 platform"
diff --git a/arch/arm/mach-pxa/include/mach/io.h b/arch/arm/mach-pxa/include/mach/io.h
new file mode 100644
index 000000000000..cd78b7fe3567
--- /dev/null
+++ b/arch/arm/mach-pxa/include/mach/io.h
@@ -0,0 +1,17 @@
1/*
2 * arch/arm/mach-pxa/include/mach/io.h
3 *
4 * Copied from asm/arch/sa1100/io.h
5 */
6#ifndef __ASM_ARM_ARCH_IO_H
7#define __ASM_ARM_ARCH_IO_H
8
9#define IO_SPACE_LIMIT 0xffffffff
10
11/*
12 * We don't actually have real ISA nor PCI buses, but there is so many
13 * drivers out there that might just work if we fake them...
14 */
15#define __io(a) __typesafe_io(a)
16
17#endif
diff --git a/arch/arm/mach-pxa/include/mach/mfp-pxa2xx.h b/arch/arm/mach-pxa/include/mach/mfp-pxa2xx.h
index c54cef25895c..cbf51ae81855 100644
--- a/arch/arm/mach-pxa/include/mach/mfp-pxa2xx.h
+++ b/arch/arm/mach-pxa/include/mach/mfp-pxa2xx.h
@@ -17,6 +17,7 @@
17 * 17 *
18 * bit 23 - Input/Output (PXA2xx specific) 18 * bit 23 - Input/Output (PXA2xx specific)
19 * bit 24 - Wakeup Enable(PXA2xx specific) 19 * bit 24 - Wakeup Enable(PXA2xx specific)
20 * bit 25 - Keep Output (PXA2xx specific)
20 */ 21 */
21 22
22#define MFP_DIR_IN (0x0 << 23) 23#define MFP_DIR_IN (0x0 << 23)
@@ -25,6 +26,12 @@
25#define MFP_DIR(x) (((x) >> 23) & 0x1) 26#define MFP_DIR(x) (((x) >> 23) & 0x1)
26 27
27#define MFP_LPM_CAN_WAKEUP (0x1 << 24) 28#define MFP_LPM_CAN_WAKEUP (0x1 << 24)
29
30/*
31 * MFP_LPM_KEEP_OUTPUT must be specified for pins that need to
32 * retain their last output level (low or high).
33 * Note: MFP_LPM_KEEP_OUTPUT has no effect on pins configured for input.
34 */
28#define MFP_LPM_KEEP_OUTPUT (0x1 << 25) 35#define MFP_LPM_KEEP_OUTPUT (0x1 << 25)
29 36
30#define WAKEUP_ON_EDGE_RISE (MFP_LPM_CAN_WAKEUP | MFP_LPM_EDGE_RISE) 37#define WAKEUP_ON_EDGE_RISE (MFP_LPM_CAN_WAKEUP | MFP_LPM_EDGE_RISE)
diff --git a/arch/arm/mach-pxa/mfp-pxa2xx.c b/arch/arm/mach-pxa/mfp-pxa2xx.c
index b0a842887780..ef0426a159d4 100644
--- a/arch/arm/mach-pxa/mfp-pxa2xx.c
+++ b/arch/arm/mach-pxa/mfp-pxa2xx.c
@@ -33,6 +33,8 @@
33#define BANK_OFF(n) (((n) < 3) ? (n) << 2 : 0x100 + (((n) - 3) << 2)) 33#define BANK_OFF(n) (((n) < 3) ? (n) << 2 : 0x100 + (((n) - 3) << 2))
34#define GPLR(x) __REG2(0x40E00000, BANK_OFF((x) >> 5)) 34#define GPLR(x) __REG2(0x40E00000, BANK_OFF((x) >> 5))
35#define GPDR(x) __REG2(0x40E00000, BANK_OFF((x) >> 5) + 0x0c) 35#define GPDR(x) __REG2(0x40E00000, BANK_OFF((x) >> 5) + 0x0c)
36#define GPSR(x) __REG2(0x40E00000, BANK_OFF((x) >> 5) + 0x18)
37#define GPCR(x) __REG2(0x40E00000, BANK_OFF((x) >> 5) + 0x24)
36 38
37#define PWER_WE35 (1 << 24) 39#define PWER_WE35 (1 << 24)
38 40
@@ -348,6 +350,7 @@ static inline void pxa27x_mfp_init(void) {}
348#ifdef CONFIG_PM 350#ifdef CONFIG_PM
349static unsigned long saved_gafr[2][4]; 351static unsigned long saved_gafr[2][4];
350static unsigned long saved_gpdr[4]; 352static unsigned long saved_gpdr[4];
353static unsigned long saved_gplr[4];
351static unsigned long saved_pgsr[4]; 354static unsigned long saved_pgsr[4];
352 355
353static int pxa2xx_mfp_suspend(void) 356static int pxa2xx_mfp_suspend(void)
@@ -366,14 +369,26 @@ static int pxa2xx_mfp_suspend(void)
366 } 369 }
367 370
368 for (i = 0; i <= gpio_to_bank(pxa_last_gpio); i++) { 371 for (i = 0; i <= gpio_to_bank(pxa_last_gpio); i++) {
369
370 saved_gafr[0][i] = GAFR_L(i); 372 saved_gafr[0][i] = GAFR_L(i);
371 saved_gafr[1][i] = GAFR_U(i); 373 saved_gafr[1][i] = GAFR_U(i);
372 saved_gpdr[i] = GPDR(i * 32); 374 saved_gpdr[i] = GPDR(i * 32);
375 saved_gplr[i] = GPLR(i * 32);
373 saved_pgsr[i] = PGSR(i); 376 saved_pgsr[i] = PGSR(i);
374 377
375 GPDR(i * 32) = gpdr_lpm[i]; 378 GPSR(i * 32) = PGSR(i);
379 GPCR(i * 32) = ~PGSR(i);
380 }
381
382 /* set GPDR bits taking into account MFP_LPM_KEEP_OUTPUT */
383 for (i = 0; i < pxa_last_gpio; i++) {
384 if ((gpdr_lpm[gpio_to_bank(i)] & GPIO_bit(i)) ||
385 ((gpio_desc[i].config & MFP_LPM_KEEP_OUTPUT) &&
386 (saved_gpdr[gpio_to_bank(i)] & GPIO_bit(i))))
387 GPDR(i) |= GPIO_bit(i);
388 else
389 GPDR(i) &= ~GPIO_bit(i);
376 } 390 }
391
377 return 0; 392 return 0;
378} 393}
379 394
@@ -384,6 +399,8 @@ static void pxa2xx_mfp_resume(void)
384 for (i = 0; i <= gpio_to_bank(pxa_last_gpio); i++) { 399 for (i = 0; i <= gpio_to_bank(pxa_last_gpio); i++) {
385 GAFR_L(i) = saved_gafr[0][i]; 400 GAFR_L(i) = saved_gafr[0][i];
386 GAFR_U(i) = saved_gafr[1][i]; 401 GAFR_U(i) = saved_gafr[1][i];
402 GPSR(i * 32) = saved_gplr[i];
403 GPCR(i * 32) = ~saved_gplr[i];
387 GPDR(i * 32) = saved_gpdr[i]; 404 GPDR(i * 32) = saved_gpdr[i];
388 PGSR(i) = saved_pgsr[i]; 405 PGSR(i) = saved_pgsr[i];
389 } 406 }
diff --git a/arch/arm/mach-pxa/pxa27x.c b/arch/arm/mach-pxa/pxa27x.c
index 6bce78edce7a..4726c246dcdc 100644
--- a/arch/arm/mach-pxa/pxa27x.c
+++ b/arch/arm/mach-pxa/pxa27x.c
@@ -421,8 +421,11 @@ void __init pxa27x_set_i2c_power_info(struct i2c_pxa_platform_data *info)
421 pxa_register_device(&pxa27x_device_i2c_power, info); 421 pxa_register_device(&pxa27x_device_i2c_power, info);
422} 422}
423 423
424static struct pxa_gpio_platform_data pxa27x_gpio_info __initdata = {
425 .gpio_set_wake = gpio_set_wake,
426};
427
424static struct platform_device *devices[] __initdata = { 428static struct platform_device *devices[] __initdata = {
425 &pxa_device_gpio,
426 &pxa27x_device_udc, 429 &pxa27x_device_udc,
427 &pxa_device_pmu, 430 &pxa_device_pmu,
428 &pxa_device_i2s, 431 &pxa_device_i2s,
@@ -458,6 +461,7 @@ static int __init pxa27x_init(void)
458 register_syscore_ops(&pxa2xx_mfp_syscore_ops); 461 register_syscore_ops(&pxa2xx_mfp_syscore_ops);
459 register_syscore_ops(&pxa2xx_clock_syscore_ops); 462 register_syscore_ops(&pxa2xx_clock_syscore_ops);
460 463
464 pxa_register_device(&pxa_device_gpio, &pxa27x_gpio_info);
461 ret = platform_add_devices(devices, ARRAY_SIZE(devices)); 465 ret = platform_add_devices(devices, ARRAY_SIZE(devices));
462 } 466 }
463 467
diff --git a/arch/arm/mach-s3c24xx/Kconfig b/arch/arm/mach-s3c24xx/Kconfig
index 0f3a327ebcaa..b34287ab5afd 100644
--- a/arch/arm/mach-s3c24xx/Kconfig
+++ b/arch/arm/mach-s3c24xx/Kconfig
@@ -111,10 +111,6 @@ config S3C24XX_SETUP_TS
111 help 111 help
112 Compile in platform device definition for Samsung TouchScreen. 112 Compile in platform device definition for Samsung TouchScreen.
113 113
114# cpu-specific sections
115
116if CPU_S3C2410
117
118config S3C2410_DMA 114config S3C2410_DMA
119 bool 115 bool
120 depends on S3C24XX_DMA && (CPU_S3C2410 || CPU_S3C2442) 116 depends on S3C24XX_DMA && (CPU_S3C2410 || CPU_S3C2442)
@@ -127,6 +123,10 @@ config S3C2410_PM
127 help 123 help
128 Power Management code common to S3C2410 and better 124 Power Management code common to S3C2410 and better
129 125
126# cpu-specific sections
127
128if CPU_S3C2410
129
130config S3C24XX_SIMTEC_NOR 130config S3C24XX_SIMTEC_NOR
131 bool 131 bool
132 help 132 help
diff --git a/arch/arm/mach-s3c24xx/common.h b/arch/arm/mach-s3c24xx/common.h
new file mode 100644
index 000000000000..c2f596e7bc2d
--- /dev/null
+++ b/arch/arm/mach-s3c24xx/common.h
@@ -0,0 +1,18 @@
1/*
2 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 * http://www.samsung.com
4 *
5 * Common Header for S3C24XX SoCs
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#ifndef __ARCH_ARM_MACH_S3C24XX_COMMON_H
13#define __ARCH_ARM_MACH_S3C24XX_COMMON_H __FILE__
14
15void s3c2410_restart(char mode, const char *cmd);
16void s3c244x_restart(char mode, const char *cmd);
17
18#endif /* __ARCH_ARM_MACH_S3C24XX_COMMON_H */
diff --git a/arch/arm/mach-s5pv210/dma.c b/arch/arm/mach-s5pv210/dma.c
index 86ce62f66190..b8337e248b09 100644
--- a/arch/arm/mach-s5pv210/dma.c
+++ b/arch/arm/mach-s5pv210/dma.c
@@ -33,8 +33,6 @@
33#include <mach/irqs.h> 33#include <mach/irqs.h>
34#include <mach/dma.h> 34#include <mach/dma.h>
35 35
36static u64 dma_dmamask = DMA_BIT_MASK(32);
37
38static u8 pdma0_peri[] = { 36static u8 pdma0_peri[] = {
39 DMACH_UART0_RX, 37 DMACH_UART0_RX,
40 DMACH_UART0_TX, 38 DMACH_UART0_TX,
diff --git a/arch/arm/mach-s5pv210/mach-aquila.c b/arch/arm/mach-s5pv210/mach-aquila.c
index a9ea64e0da0d..48d018f2332b 100644
--- a/arch/arm/mach-s5pv210/mach-aquila.c
+++ b/arch/arm/mach-s5pv210/mach-aquila.c
@@ -484,8 +484,8 @@ static struct wm8994_pdata wm8994_platform_data = {
484 .gpio_defaults[8] = 0x0100, 484 .gpio_defaults[8] = 0x0100,
485 .gpio_defaults[9] = 0x0100, 485 .gpio_defaults[9] = 0x0100,
486 .gpio_defaults[10] = 0x0100, 486 .gpio_defaults[10] = 0x0100,
487 .ldo[0] = { S5PV210_MP03(6), NULL, &wm8994_ldo1_data }, /* XM0FRNB_2 */ 487 .ldo[0] = { S5PV210_MP03(6), &wm8994_ldo1_data }, /* XM0FRNB_2 */
488 .ldo[1] = { 0, NULL, &wm8994_ldo2_data }, 488 .ldo[1] = { 0, &wm8994_ldo2_data },
489}; 489};
490 490
491/* GPIO I2C PMIC */ 491/* GPIO I2C PMIC */
diff --git a/arch/arm/mach-s5pv210/mach-goni.c b/arch/arm/mach-s5pv210/mach-goni.c
index 2cf5ed75f390..32395664e879 100644
--- a/arch/arm/mach-s5pv210/mach-goni.c
+++ b/arch/arm/mach-s5pv210/mach-goni.c
@@ -25,6 +25,7 @@
25#include <linux/gpio_keys.h> 25#include <linux/gpio_keys.h>
26#include <linux/input.h> 26#include <linux/input.h>
27#include <linux/gpio.h> 27#include <linux/gpio.h>
28#include <linux/mmc/host.h>
28#include <linux/interrupt.h> 29#include <linux/interrupt.h>
29 30
30#include <asm/hardware/vic.h> 31#include <asm/hardware/vic.h>
@@ -674,8 +675,8 @@ static struct wm8994_pdata wm8994_platform_data = {
674 .gpio_defaults[8] = 0x0100, 675 .gpio_defaults[8] = 0x0100,
675 .gpio_defaults[9] = 0x0100, 676 .gpio_defaults[9] = 0x0100,
676 .gpio_defaults[10] = 0x0100, 677 .gpio_defaults[10] = 0x0100,
677 .ldo[0] = { S5PV210_MP03(6), NULL, &wm8994_ldo1_data }, /* XM0FRNB_2 */ 678 .ldo[0] = { S5PV210_MP03(6), &wm8994_ldo1_data }, /* XM0FRNB_2 */
678 .ldo[1] = { 0, NULL, &wm8994_ldo2_data }, 679 .ldo[1] = { 0, &wm8994_ldo2_data },
679}; 680};
680 681
681/* GPIO I2C PMIC */ 682/* GPIO I2C PMIC */
@@ -765,6 +766,7 @@ static void __init goni_pmic_init(void)
765/* MoviNAND */ 766/* MoviNAND */
766static struct s3c_sdhci_platdata goni_hsmmc0_data __initdata = { 767static struct s3c_sdhci_platdata goni_hsmmc0_data __initdata = {
767 .max_width = 4, 768 .max_width = 4,
769 .host_caps2 = MMC_CAP2_BROKEN_VOLTAGE,
768 .cd_type = S3C_SDHCI_CD_PERMANENT, 770 .cd_type = S3C_SDHCI_CD_PERMANENT,
769}; 771};
770 772
diff --git a/arch/arm/mach-sa1100/collie.c b/arch/arm/mach-sa1100/collie.c
index 48885b7efd6b..c7f418b0cde9 100644
--- a/arch/arm/mach-sa1100/collie.c
+++ b/arch/arm/mach-sa1100/collie.c
@@ -313,6 +313,10 @@ static struct sa1100fb_mach_info collie_lcd_info = {
313 313
314 .lccr0 = LCCR0_Color | LCCR0_Sngl | LCCR0_Act, 314 .lccr0 = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
315 .lccr3 = LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_ACBsDiv(2), 315 .lccr3 = LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_ACBsDiv(2),
316
317#ifdef CONFIG_BACKLIGHT_LOCOMO
318 .lcd_power = locomolcd_power
319#endif
316}; 320};
317 321
318static void __init collie_init(void) 322static void __init collie_init(void)
diff --git a/arch/arm/mach-sa1100/generic.c b/arch/arm/mach-sa1100/generic.c
index 7c524b4e415d..16be4c56abe3 100644
--- a/arch/arm/mach-sa1100/generic.c
+++ b/arch/arm/mach-sa1100/generic.c
@@ -306,7 +306,7 @@ void sa11x0_register_irda(struct irda_platform_data *irda)
306} 306}
307 307
308static struct resource sa1100_rtc_resources[] = { 308static struct resource sa1100_rtc_resources[] = {
309 DEFINE_RES_MEM(0x90010000, 0x9001003f), 309 DEFINE_RES_MEM(0x90010000, 0x40),
310 DEFINE_RES_IRQ_NAMED(IRQ_RTC1Hz, "rtc 1Hz"), 310 DEFINE_RES_IRQ_NAMED(IRQ_RTC1Hz, "rtc 1Hz"),
311 DEFINE_RES_IRQ_NAMED(IRQ_RTCAlrm, "rtc alarm"), 311 DEFINE_RES_IRQ_NAMED(IRQ_RTCAlrm, "rtc alarm"),
312}; 312};
diff --git a/arch/arm/mach-sa1100/include/mach/collie.h b/arch/arm/mach-sa1100/include/mach/collie.h
index 52acda7061b7..f33679d2d3ee 100644
--- a/arch/arm/mach-sa1100/include/mach/collie.h
+++ b/arch/arm/mach-sa1100/include/mach/collie.h
@@ -1,7 +1,7 @@
1/* 1/*
2 * arch/arm/mach-sa1100/include/mach/collie.h 2 * arch/arm/mach-sa1100/include/mach/collie.h
3 * 3 *
4 * This file contains the hardware specific definitions for Assabet 4 * This file contains the hardware specific definitions for Collie
5 * Only include this file from SA1100-specific files. 5 * Only include this file from SA1100-specific files.
6 * 6 *
7 * ChangeLog: 7 * ChangeLog:
@@ -13,6 +13,7 @@
13#ifndef __ASM_ARCH_COLLIE_H 13#ifndef __ASM_ARCH_COLLIE_H
14#define __ASM_ARCH_COLLIE_H 14#define __ASM_ARCH_COLLIE_H
15 15
16extern void locomolcd_power(int on);
16 17
17#define COLLIE_SCOOP_GPIO_BASE (GPIO_MAX + 1) 18#define COLLIE_SCOOP_GPIO_BASE (GPIO_MAX + 1)
18#define COLLIE_GPIO_CHARGE_ON (COLLIE_SCOOP_GPIO_BASE + 0) 19#define COLLIE_GPIO_CHARGE_ON (COLLIE_SCOOP_GPIO_BASE + 0)
diff --git a/arch/arm/mach-shmobile/Kconfig b/arch/arm/mach-shmobile/Kconfig
index 34560cab45d9..2cda0c2af230 100644
--- a/arch/arm/mach-shmobile/Kconfig
+++ b/arch/arm/mach-shmobile/Kconfig
@@ -58,6 +58,7 @@ config MACH_AP4EVB
58 depends on ARCH_SH7372 58 depends on ARCH_SH7372
59 select ARCH_REQUIRE_GPIOLIB 59 select ARCH_REQUIRE_GPIOLIB
60 select SH_LCD_MIPI_DSI 60 select SH_LCD_MIPI_DSI
61 select SND_SOC_AK4642 if SND_SIMPLE_CARD
61 62
62choice 63choice
63 prompt "AP4EVB LCD panel selection" 64 prompt "AP4EVB LCD panel selection"
@@ -82,6 +83,7 @@ config MACH_MACKEREL
82 bool "mackerel board" 83 bool "mackerel board"
83 depends on ARCH_SH7372 84 depends on ARCH_SH7372
84 select ARCH_REQUIRE_GPIOLIB 85 select ARCH_REQUIRE_GPIOLIB
86 select SND_SOC_AK4642 if SND_SIMPLE_CARD
85 87
86config MACH_KOTA2 88config MACH_KOTA2
87 bool "KOTA2 board" 89 bool "KOTA2 board"
diff --git a/arch/arm/mach-shmobile/board-ag5evm.c b/arch/arm/mach-shmobile/board-ag5evm.c
index cb224a344af0..0891ec6e27f5 100644
--- a/arch/arm/mach-shmobile/board-ag5evm.c
+++ b/arch/arm/mach-shmobile/board-ag5evm.c
@@ -365,23 +365,13 @@ static struct platform_device mipidsi0_device = {
365}; 365};
366 366
367/* SDHI0 */ 367/* SDHI0 */
368static irqreturn_t ag5evm_sdhi0_gpio_cd(int irq, void *arg)
369{
370 struct device *dev = arg;
371 struct sh_mobile_sdhi_info *info = dev->platform_data;
372 struct tmio_mmc_data *pdata = info->pdata;
373
374 tmio_mmc_cd_wakeup(pdata);
375
376 return IRQ_HANDLED;
377}
378
379static struct sh_mobile_sdhi_info sdhi0_info = { 368static struct sh_mobile_sdhi_info sdhi0_info = {
380 .dma_slave_tx = SHDMA_SLAVE_SDHI0_TX, 369 .dma_slave_tx = SHDMA_SLAVE_SDHI0_TX,
381 .dma_slave_rx = SHDMA_SLAVE_SDHI0_RX, 370 .dma_slave_rx = SHDMA_SLAVE_SDHI0_RX,
382 .tmio_flags = TMIO_MMC_HAS_IDLE_WAIT, 371 .tmio_flags = TMIO_MMC_HAS_IDLE_WAIT | TMIO_MMC_USE_GPIO_CD,
383 .tmio_caps = MMC_CAP_SD_HIGHSPEED, 372 .tmio_caps = MMC_CAP_SD_HIGHSPEED,
384 .tmio_ocr_mask = MMC_VDD_27_28 | MMC_VDD_28_29, 373 .tmio_ocr_mask = MMC_VDD_27_28 | MMC_VDD_28_29,
374 .cd_gpio = GPIO_PORT251,
385}; 375};
386 376
387static struct resource sdhi0_resources[] = { 377static struct resource sdhi0_resources[] = {
@@ -557,7 +547,6 @@ static void __init ag5evm_init(void)
557 lcd_backlight_reset(); 547 lcd_backlight_reset();
558 548
559 /* enable SDHI0 on CN15 [SD I/F] */ 549 /* enable SDHI0 on CN15 [SD I/F] */
560 gpio_request(GPIO_FN_SDHICD0, NULL);
561 gpio_request(GPIO_FN_SDHIWP0, NULL); 550 gpio_request(GPIO_FN_SDHIWP0, NULL);
562 gpio_request(GPIO_FN_SDHICMD0, NULL); 551 gpio_request(GPIO_FN_SDHICMD0, NULL);
563 gpio_request(GPIO_FN_SDHICLK0, NULL); 552 gpio_request(GPIO_FN_SDHICLK0, NULL);
@@ -566,13 +555,6 @@ static void __init ag5evm_init(void)
566 gpio_request(GPIO_FN_SDHID0_1, NULL); 555 gpio_request(GPIO_FN_SDHID0_1, NULL);
567 gpio_request(GPIO_FN_SDHID0_0, NULL); 556 gpio_request(GPIO_FN_SDHID0_0, NULL);
568 557
569 if (!request_irq(intcs_evt2irq(0x3c0), ag5evm_sdhi0_gpio_cd,
570 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
571 "sdhi0 cd", &sdhi0_device.dev))
572 sdhi0_info.tmio_flags |= TMIO_MMC_HAS_COLD_CD;
573 else
574 pr_warn("Unable to setup SDHI0 GPIO IRQ\n");
575
576 /* enable SDHI1 on CN4 [WLAN I/F] */ 558 /* enable SDHI1 on CN4 [WLAN I/F] */
577 gpio_request(GPIO_FN_SDHICLK1, NULL); 559 gpio_request(GPIO_FN_SDHICLK1, NULL);
578 gpio_request(GPIO_FN_SDHICMD1_PU, NULL); 560 gpio_request(GPIO_FN_SDHICMD1_PU, NULL);
diff --git a/arch/arm/mach-shmobile/board-ap4evb.c b/arch/arm/mach-shmobile/board-ap4evb.c
index b56dde2732bb..8302265977a8 100644
--- a/arch/arm/mach-shmobile/board-ap4evb.c
+++ b/arch/arm/mach-shmobile/board-ap4evb.c
@@ -50,6 +50,7 @@
50#include <media/soc_camera.h> 50#include <media/soc_camera.h>
51 51
52#include <sound/sh_fsi.h> 52#include <sound/sh_fsi.h>
53#include <sound/simple_card.h>
53 54
54#include <video/sh_mobile_hdmi.h> 55#include <video/sh_mobile_hdmi.h>
55#include <video/sh_mobile_lcdc.h> 56#include <video/sh_mobile_lcdc.h>
@@ -785,17 +786,25 @@ static struct platform_device fsi_device = {
785 }, 786 },
786}; 787};
787 788
788static struct fsi_ak4642_info fsi2_ak4643_info = { 789static struct asoc_simple_dai_init_info fsi2_ak4643_init_info = {
790 .fmt = SND_SOC_DAIFMT_LEFT_J,
791 .codec_daifmt = SND_SOC_DAIFMT_CBM_CFM,
792 .cpu_daifmt = SND_SOC_DAIFMT_CBS_CFS,
793 .sysclk = 11289600,
794};
795
796static struct asoc_simple_card_info fsi2_ak4643_info = {
789 .name = "AK4643", 797 .name = "AK4643",
790 .card = "FSI2A-AK4643", 798 .card = "FSI2A-AK4643",
791 .cpu_dai = "fsia-dai", 799 .cpu_dai = "fsia-dai",
792 .codec = "ak4642-codec.0-0013", 800 .codec = "ak4642-codec.0-0013",
793 .platform = "sh_fsi2", 801 .platform = "sh_fsi2",
794 .id = FSI_PORT_A, 802 .codec_dai = "ak4642-hifi",
803 .init = &fsi2_ak4643_init_info,
795}; 804};
796 805
797static struct platform_device fsi_ak4643_device = { 806static struct platform_device fsi_ak4643_device = {
798 .name = "fsi-ak4642-audio", 807 .name = "asoc-simple-card",
799 .dev = { 808 .dev = {
800 .platform_data = &fsi2_ak4643_info, 809 .platform_data = &fsi2_ak4643_info,
801 }, 810 },
@@ -900,8 +909,26 @@ static struct platform_device lcdc1_device = {
900 }, 909 },
901}; 910};
902 911
912static struct asoc_simple_dai_init_info fsi2_hdmi_init_info = {
913 .cpu_daifmt = SND_SOC_DAIFMT_CBM_CFM,
914};
915
916static struct asoc_simple_card_info fsi2_hdmi_info = {
917 .name = "HDMI",
918 .card = "FSI2B-HDMI",
919 .cpu_dai = "fsib-dai",
920 .codec = "sh-mobile-hdmi",
921 .platform = "sh_fsi2",
922 .codec_dai = "sh_mobile_hdmi-hifi",
923 .init = &fsi2_hdmi_init_info,
924};
925
903static struct platform_device fsi_hdmi_device = { 926static struct platform_device fsi_hdmi_device = {
904 .name = "sh_fsi2_b_hdmi", 927 .name = "asoc-simple-card",
928 .id = 1,
929 .dev = {
930 .platform_data = &fsi2_hdmi_info,
931 },
905}; 932};
906 933
907static struct gpio_led ap4evb_leds[] = { 934static struct gpio_led ap4evb_leds[] = {
diff --git a/arch/arm/mach-shmobile/board-mackerel.c b/arch/arm/mach-shmobile/board-mackerel.c
index f49e28abe0ab..fb27bac4cfd1 100644
--- a/arch/arm/mach-shmobile/board-mackerel.c
+++ b/arch/arm/mach-shmobile/board-mackerel.c
@@ -53,6 +53,7 @@
53#include <media/soc_camera.h> 53#include <media/soc_camera.h>
54#include <media/soc_camera_platform.h> 54#include <media/soc_camera_platform.h>
55#include <sound/sh_fsi.h> 55#include <sound/sh_fsi.h>
56#include <sound/simple_card.h>
56 57
57#include <mach/common.h> 58#include <mach/common.h>
58#include <mach/irqs.h> 59#include <mach/irqs.h>
@@ -502,8 +503,26 @@ static struct platform_device hdmi_lcdc_device = {
502 }, 503 },
503}; 504};
504 505
506static struct asoc_simple_dai_init_info fsi2_hdmi_init_info = {
507 .cpu_daifmt = SND_SOC_DAIFMT_CBM_CFM,
508};
509
510static struct asoc_simple_card_info fsi2_hdmi_info = {
511 .name = "HDMI",
512 .card = "FSI2B-HDMI",
513 .cpu_dai = "fsib-dai",
514 .codec = "sh-mobile-hdmi",
515 .platform = "sh_fsi2",
516 .codec_dai = "sh_mobile_hdmi-hifi",
517 .init = &fsi2_hdmi_init_info,
518};
519
505static struct platform_device fsi_hdmi_device = { 520static struct platform_device fsi_hdmi_device = {
506 .name = "sh_fsi2_b_hdmi", 521 .name = "asoc-simple-card",
522 .id = 1,
523 .dev = {
524 .platform_data = &fsi2_hdmi_info,
525 },
507}; 526};
508 527
509static void __init hdmi_init_pm_clock(void) 528static void __init hdmi_init_pm_clock(void)
@@ -941,17 +960,25 @@ static struct platform_device fsi_device = {
941 }, 960 },
942}; 961};
943 962
944static struct fsi_ak4642_info fsi2_ak4643_info = { 963static struct asoc_simple_dai_init_info fsi2_ak4643_init_info = {
964 .fmt = SND_SOC_DAIFMT_LEFT_J,
965 .codec_daifmt = SND_SOC_DAIFMT_CBM_CFM,
966 .cpu_daifmt = SND_SOC_DAIFMT_CBS_CFS,
967 .sysclk = 11289600,
968};
969
970static struct asoc_simple_card_info fsi2_ak4643_info = {
945 .name = "AK4643", 971 .name = "AK4643",
946 .card = "FSI2A-AK4643", 972 .card = "FSI2A-AK4643",
947 .cpu_dai = "fsia-dai", 973 .cpu_dai = "fsia-dai",
948 .codec = "ak4642-codec.0-0013", 974 .codec = "ak4642-codec.0-0013",
949 .platform = "sh_fsi2", 975 .platform = "sh_fsi2",
950 .id = FSI_PORT_A, 976 .codec_dai = "ak4642-hifi",
977 .init = &fsi2_ak4643_init_info,
951}; 978};
952 979
953static struct platform_device fsi_ak4643_device = { 980static struct platform_device fsi_ak4643_device = {
954 .name = "fsi-ak4642-audio", 981 .name = "asoc-simple-card",
955 .dev = { 982 .dev = {
956 .platform_data = &fsi2_ak4643_info, 983 .platform_data = &fsi2_ak4643_info,
957 }, 984 },
@@ -1011,21 +1038,12 @@ static int slot_cn7_get_cd(struct platform_device *pdev)
1011} 1038}
1012 1039
1013/* SDHI0 */ 1040/* SDHI0 */
1014static irqreturn_t mackerel_sdhi0_gpio_cd(int irq, void *arg)
1015{
1016 struct device *dev = arg;
1017 struct sh_mobile_sdhi_info *info = dev->platform_data;
1018 struct tmio_mmc_data *pdata = info->pdata;
1019
1020 tmio_mmc_cd_wakeup(pdata);
1021
1022 return IRQ_HANDLED;
1023}
1024
1025static struct sh_mobile_sdhi_info sdhi0_info = { 1041static struct sh_mobile_sdhi_info sdhi0_info = {
1026 .dma_slave_tx = SHDMA_SLAVE_SDHI0_TX, 1042 .dma_slave_tx = SHDMA_SLAVE_SDHI0_TX,
1027 .dma_slave_rx = SHDMA_SLAVE_SDHI0_RX, 1043 .dma_slave_rx = SHDMA_SLAVE_SDHI0_RX,
1044 .tmio_flags = TMIO_MMC_USE_GPIO_CD,
1028 .tmio_caps = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ, 1045 .tmio_caps = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ,
1046 .cd_gpio = GPIO_PORT172,
1029}; 1047};
1030 1048
1031static struct resource sdhi0_resources[] = { 1049static struct resource sdhi0_resources[] = {
@@ -1384,7 +1402,6 @@ static void __init mackerel_init(void)
1384{ 1402{
1385 u32 srcr4; 1403 u32 srcr4;
1386 struct clk *clk; 1404 struct clk *clk;
1387 int ret;
1388 1405
1389 /* External clock source */ 1406 /* External clock source */
1390 clk_set_rate(&sh7372_dv_clki_clk, 27000000); 1407 clk_set_rate(&sh7372_dv_clki_clk, 27000000);
@@ -1481,7 +1498,6 @@ static void __init mackerel_init(void)
1481 irq_set_irq_type(IRQ21, IRQ_TYPE_LEVEL_HIGH); 1498 irq_set_irq_type(IRQ21, IRQ_TYPE_LEVEL_HIGH);
1482 1499
1483 /* enable SDHI0 */ 1500 /* enable SDHI0 */
1484 gpio_request(GPIO_FN_SDHICD0, NULL);
1485 gpio_request(GPIO_FN_SDHIWP0, NULL); 1501 gpio_request(GPIO_FN_SDHIWP0, NULL);
1486 gpio_request(GPIO_FN_SDHICMD0, NULL); 1502 gpio_request(GPIO_FN_SDHICMD0, NULL);
1487 gpio_request(GPIO_FN_SDHICLK0, NULL); 1503 gpio_request(GPIO_FN_SDHICLK0, NULL);
@@ -1490,13 +1506,6 @@ static void __init mackerel_init(void)
1490 gpio_request(GPIO_FN_SDHID0_1, NULL); 1506 gpio_request(GPIO_FN_SDHID0_1, NULL);
1491 gpio_request(GPIO_FN_SDHID0_0, NULL); 1507 gpio_request(GPIO_FN_SDHID0_0, NULL);
1492 1508
1493 ret = request_irq(evt2irq(0x3340), mackerel_sdhi0_gpio_cd,
1494 IRQF_TRIGGER_FALLING, "sdhi0 cd", &sdhi0_device.dev);
1495 if (!ret)
1496 sdhi0_info.tmio_flags |= TMIO_MMC_HAS_COLD_CD;
1497 else
1498 pr_err("Cannot get IRQ #%d: %d\n", evt2irq(0x3340), ret);
1499
1500#if !defined(CONFIG_MMC_SH_MMCIF) && !defined(CONFIG_MMC_SH_MMCIF_MODULE) 1509#if !defined(CONFIG_MMC_SH_MMCIF) && !defined(CONFIG_MMC_SH_MMCIF_MODULE)
1501 /* enable SDHI1 */ 1510 /* enable SDHI1 */
1502 gpio_request(GPIO_FN_SDHICMD1, NULL); 1511 gpio_request(GPIO_FN_SDHICMD1, NULL);
diff --git a/arch/arm/mach-shmobile/headsmp.S b/arch/arm/mach-shmobile/headsmp.S
index 6ac015c89206..b202c1272526 100644
--- a/arch/arm/mach-shmobile/headsmp.S
+++ b/arch/arm/mach-shmobile/headsmp.S
@@ -16,6 +16,59 @@
16 16
17 __CPUINIT 17 __CPUINIT
18 18
19/* Cache invalidation nicked from arch/arm/mach-imx/head-v7.S, thanks!
20 *
21 * The secondary kernel init calls v7_flush_dcache_all before it enables
22 * the L1; however, the L1 comes out of reset in an undefined state, so
23 * the clean + invalidate performed by v7_flush_dcache_all causes a bunch
24 * of cache lines with uninitialized data and uninitialized tags to get
25 * written out to memory, which does really unpleasant things to the main
26 * processor. We fix this by performing an invalidate, rather than a
27 * clean + invalidate, before jumping into the kernel.
28 *
29 * This funciton is cloned from arch/arm/mach-tegra/headsmp.S, and needs
30 * to be called for both secondary cores startup and primary core resume
31 * procedures. Ideally, it should be moved into arch/arm/mm/cache-v7.S.
32 */
33ENTRY(v7_invalidate_l1)
34 mov r0, #0
35 mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
36 mcr p15, 2, r0, c0, c0, 0
37 mrc p15, 1, r0, c0, c0, 0
38
39 ldr r1, =0x7fff
40 and r2, r1, r0, lsr #13
41
42 ldr r1, =0x3ff
43
44 and r3, r1, r0, lsr #3 @ NumWays - 1
45 add r2, r2, #1 @ NumSets
46
47 and r0, r0, #0x7
48 add r0, r0, #4 @ SetShift
49
50 clz r1, r3 @ WayShift
51 add r4, r3, #1 @ NumWays
521: sub r2, r2, #1 @ NumSets--
53 mov r3, r4 @ Temp = NumWays
542: subs r3, r3, #1 @ Temp--
55 mov r5, r3, lsl r1
56 mov r6, r2, lsl r0
57 orr r5, r5, r6 @ Reg = (Temp<<WayShift)|(NumSets<<SetShift)
58 mcr p15, 0, r5, c7, c6, 2
59 bgt 2b
60 cmp r2, #0
61 bgt 1b
62 dsb
63 isb
64 mov pc, lr
65ENDPROC(v7_invalidate_l1)
66
67ENTRY(shmobile_invalidate_start)
68 bl v7_invalidate_l1
69 b secondary_startup
70ENDPROC(shmobile_invalidate_start)
71
19/* 72/*
20 * Reset vector for secondary CPUs. 73 * Reset vector for secondary CPUs.
21 * This will be mapped at address 0 by SBAR register. 74 * This will be mapped at address 0 by SBAR register.
@@ -24,4 +77,5 @@
24 .align 12 77 .align 12
25ENTRY(shmobile_secondary_vector) 78ENTRY(shmobile_secondary_vector)
26 ldr pc, 1f 79 ldr pc, 1f
271: .long secondary_startup - PAGE_OFFSET + PLAT_PHYS_OFFSET 801: .long shmobile_invalidate_start - PAGE_OFFSET + PLAT_PHYS_OFFSET
81ENDPROC(shmobile_secondary_vector)
diff --git a/arch/arm/mach-shmobile/include/mach/common.h b/arch/arm/mach-shmobile/include/mach/common.h
index 83ad3fe0a75f..c85e6ecda606 100644
--- a/arch/arm/mach-shmobile/include/mach/common.h
+++ b/arch/arm/mach-shmobile/include/mach/common.h
@@ -4,7 +4,6 @@
4extern void shmobile_earlytimer_init(void); 4extern void shmobile_earlytimer_init(void);
5extern struct sys_timer shmobile_timer; 5extern struct sys_timer shmobile_timer;
6struct twd_local_timer; 6struct twd_local_timer;
7void shmobile_twd_init(struct twd_local_timer *twd_local_timer);
8extern void shmobile_setup_console(void); 7extern void shmobile_setup_console(void);
9extern void shmobile_secondary_vector(void); 8extern void shmobile_secondary_vector(void);
10extern int shmobile_platform_cpu_kill(unsigned int cpu); 9extern int shmobile_platform_cpu_kill(unsigned int cpu);
@@ -82,5 +81,6 @@ extern int r8a7779_platform_cpu_kill(unsigned int cpu);
82extern void r8a7779_secondary_init(unsigned int cpu); 81extern void r8a7779_secondary_init(unsigned int cpu);
83extern int r8a7779_boot_secondary(unsigned int cpu); 82extern int r8a7779_boot_secondary(unsigned int cpu);
84extern void r8a7779_smp_prepare_cpus(void); 83extern void r8a7779_smp_prepare_cpus(void);
84extern void r8a7779_register_twd(void);
85 85
86#endif /* __ARCH_MACH_COMMON_H */ 86#endif /* __ARCH_MACH_COMMON_H */
diff --git a/arch/arm/mach-shmobile/setup-r8a7779.c b/arch/arm/mach-shmobile/setup-r8a7779.c
index 12c6f529ab89..e98e46f6cf55 100644
--- a/arch/arm/mach-shmobile/setup-r8a7779.c
+++ b/arch/arm/mach-shmobile/setup-r8a7779.c
@@ -262,10 +262,14 @@ void __init r8a7779_add_standard_devices(void)
262 ARRAY_SIZE(r8a7779_late_devices)); 262 ARRAY_SIZE(r8a7779_late_devices));
263} 263}
264 264
265/* do nothing for !CONFIG_SMP or !CONFIG_HAVE_TWD */
266void __init __weak r8a7779_register_twd(void) { }
267
265static void __init r8a7779_earlytimer_init(void) 268static void __init r8a7779_earlytimer_init(void)
266{ 269{
267 r8a7779_clock_init(); 270 r8a7779_clock_init();
268 shmobile_earlytimer_init(); 271 shmobile_earlytimer_init();
272 r8a7779_register_twd();
269} 273}
270 274
271void __init r8a7779_add_early_devices(void) 275void __init r8a7779_add_early_devices(void)
diff --git a/arch/arm/mach-shmobile/setup-sh73a0.c b/arch/arm/mach-shmobile/setup-sh73a0.c
index 5bebffc10455..04a0dfe75493 100644
--- a/arch/arm/mach-shmobile/setup-sh73a0.c
+++ b/arch/arm/mach-shmobile/setup-sh73a0.c
@@ -688,10 +688,14 @@ void __init sh73a0_add_standard_devices(void)
688 ARRAY_SIZE(sh73a0_late_devices)); 688 ARRAY_SIZE(sh73a0_late_devices));
689} 689}
690 690
691/* do nothing for !CONFIG_SMP or !CONFIG_HAVE_TWD */
692void __init __weak sh73a0_register_twd(void) { }
693
691static void __init sh73a0_earlytimer_init(void) 694static void __init sh73a0_earlytimer_init(void)
692{ 695{
693 sh73a0_clock_init(); 696 sh73a0_clock_init();
694 shmobile_earlytimer_init(); 697 shmobile_earlytimer_init();
698 sh73a0_register_twd();
695} 699}
696 700
697void __init sh73a0_add_early_devices(void) 701void __init sh73a0_add_early_devices(void)
diff --git a/arch/arm/mach-shmobile/smp-r8a7779.c b/arch/arm/mach-shmobile/smp-r8a7779.c
index b62e19d4c9af..6d1d0238cbf7 100644
--- a/arch/arm/mach-shmobile/smp-r8a7779.c
+++ b/arch/arm/mach-shmobile/smp-r8a7779.c
@@ -64,8 +64,15 @@ static void __iomem *scu_base_addr(void)
64static DEFINE_SPINLOCK(scu_lock); 64static DEFINE_SPINLOCK(scu_lock);
65static unsigned long tmp; 65static unsigned long tmp;
66 66
67#ifdef CONFIG_HAVE_ARM_TWD
67static DEFINE_TWD_LOCAL_TIMER(twd_local_timer, 0xf0000600, 29); 68static DEFINE_TWD_LOCAL_TIMER(twd_local_timer, 0xf0000600, 29);
68 69
70void __init r8a7779_register_twd(void)
71{
72 twd_local_timer_register(&twd_local_timer);
73}
74#endif
75
69static void modify_scu_cpu_psr(unsigned long set, unsigned long clr) 76static void modify_scu_cpu_psr(unsigned long set, unsigned long clr)
70{ 77{
71 void __iomem *scu_base = scu_base_addr(); 78 void __iomem *scu_base = scu_base_addr();
@@ -84,7 +91,6 @@ unsigned int __init r8a7779_get_core_count(void)
84{ 91{
85 void __iomem *scu_base = scu_base_addr(); 92 void __iomem *scu_base = scu_base_addr();
86 93
87 shmobile_twd_init(&twd_local_timer);
88 return scu_get_core_count(scu_base); 94 return scu_get_core_count(scu_base);
89} 95}
90 96
diff --git a/arch/arm/mach-shmobile/smp-sh73a0.c b/arch/arm/mach-shmobile/smp-sh73a0.c
index 14ad8b052f1a..e36c41c4ab40 100644
--- a/arch/arm/mach-shmobile/smp-sh73a0.c
+++ b/arch/arm/mach-shmobile/smp-sh73a0.c
@@ -42,7 +42,13 @@ static void __iomem *scu_base_addr(void)
42static DEFINE_SPINLOCK(scu_lock); 42static DEFINE_SPINLOCK(scu_lock);
43static unsigned long tmp; 43static unsigned long tmp;
44 44
45#ifdef CONFIG_HAVE_ARM_TWD
45static DEFINE_TWD_LOCAL_TIMER(twd_local_timer, 0xf0000600, 29); 46static DEFINE_TWD_LOCAL_TIMER(twd_local_timer, 0xf0000600, 29);
47void __init sh73a0_register_twd(void)
48{
49 twd_local_timer_register(&twd_local_timer);
50}
51#endif
46 52
47static void modify_scu_cpu_psr(unsigned long set, unsigned long clr) 53static void modify_scu_cpu_psr(unsigned long set, unsigned long clr)
48{ 54{
@@ -62,7 +68,6 @@ unsigned int __init sh73a0_get_core_count(void)
62{ 68{
63 void __iomem *scu_base = scu_base_addr(); 69 void __iomem *scu_base = scu_base_addr();
64 70
65 shmobile_twd_init(&twd_local_timer);
66 return scu_get_core_count(scu_base); 71 return scu_get_core_count(scu_base);
67} 72}
68 73
diff --git a/arch/arm/mach-shmobile/timer.c b/arch/arm/mach-shmobile/timer.c
index 2fba5f3d1c8a..8b79e7917a23 100644
--- a/arch/arm/mach-shmobile/timer.c
+++ b/arch/arm/mach-shmobile/timer.c
@@ -46,15 +46,6 @@ static void __init shmobile_timer_init(void)
46{ 46{
47} 47}
48 48
49void __init shmobile_twd_init(struct twd_local_timer *twd_local_timer)
50{
51#ifdef CONFIG_HAVE_ARM_TWD
52 int err = twd_local_timer_register(twd_local_timer);
53 if (err)
54 pr_err("twd_local_timer_register failed %d\n", err);
55#endif
56}
57
58struct sys_timer shmobile_timer = { 49struct sys_timer shmobile_timer = {
59 .init = shmobile_timer_init, 50 .init = shmobile_timer_init,
60}; 51};
diff --git a/arch/arm/mach-tegra/board-dt-tegra20.c b/arch/arm/mach-tegra/board-dt-tegra20.c
index 0952494f481a..86abcf0d2be9 100644
--- a/arch/arm/mach-tegra/board-dt-tegra20.c
+++ b/arch/arm/mach-tegra/board-dt-tegra20.c
@@ -64,9 +64,9 @@ struct of_dev_auxdata tegra20_auxdata_lookup[] __initdata = {
64 OF_DEV_AUXDATA("nvidia,tegra20-i2c", TEGRA_I2C2_BASE, "tegra-i2c.1", NULL), 64 OF_DEV_AUXDATA("nvidia,tegra20-i2c", TEGRA_I2C2_BASE, "tegra-i2c.1", NULL),
65 OF_DEV_AUXDATA("nvidia,tegra20-i2c", TEGRA_I2C3_BASE, "tegra-i2c.2", NULL), 65 OF_DEV_AUXDATA("nvidia,tegra20-i2c", TEGRA_I2C3_BASE, "tegra-i2c.2", NULL),
66 OF_DEV_AUXDATA("nvidia,tegra20-i2c-dvc", TEGRA_DVC_BASE, "tegra-i2c.3", NULL), 66 OF_DEV_AUXDATA("nvidia,tegra20-i2c-dvc", TEGRA_DVC_BASE, "tegra-i2c.3", NULL),
67 OF_DEV_AUXDATA("nvidia,tegra20-i2s", TEGRA_I2S1_BASE, "tegra-i2s.0", NULL), 67 OF_DEV_AUXDATA("nvidia,tegra20-i2s", TEGRA_I2S1_BASE, "tegra20-i2s.0", NULL),
68 OF_DEV_AUXDATA("nvidia,tegra20-i2s", TEGRA_I2S2_BASE, "tegra-i2s.1", NULL), 68 OF_DEV_AUXDATA("nvidia,tegra20-i2s", TEGRA_I2S2_BASE, "tegra20-i2s.1", NULL),
69 OF_DEV_AUXDATA("nvidia,tegra20-das", TEGRA_APB_MISC_DAS_BASE, "tegra-das", NULL), 69 OF_DEV_AUXDATA("nvidia,tegra20-das", TEGRA_APB_MISC_DAS_BASE, "tegra20-das", NULL),
70 OF_DEV_AUXDATA("nvidia,tegra20-ehci", TEGRA_USB_BASE, "tegra-ehci.0", 70 OF_DEV_AUXDATA("nvidia,tegra20-ehci", TEGRA_USB_BASE, "tegra-ehci.0",
71 &tegra_ehci1_pdata), 71 &tegra_ehci1_pdata),
72 OF_DEV_AUXDATA("nvidia,tegra20-ehci", TEGRA_USB2_BASE, "tegra-ehci.1", 72 OF_DEV_AUXDATA("nvidia,tegra20-ehci", TEGRA_USB2_BASE, "tegra-ehci.1",
diff --git a/arch/arm/mach-tegra/board-harmony.c b/arch/arm/mach-tegra/board-harmony.c
index c00aadb01e09..5eb74ea98141 100644
--- a/arch/arm/mach-tegra/board-harmony.c
+++ b/arch/arm/mach-tegra/board-harmony.c
@@ -122,7 +122,6 @@ static struct platform_device *harmony_devices[] __initdata = {
122 &tegra_ehci3_device, 122 &tegra_ehci3_device,
123 &tegra_i2s_device1, 123 &tegra_i2s_device1,
124 &tegra_das_device, 124 &tegra_das_device,
125 &tegra_pcm_device,
126 &harmony_audio_device, 125 &harmony_audio_device,
127}; 126};
128 127
diff --git a/arch/arm/mach-tegra/board-seaboard.c b/arch/arm/mach-tegra/board-seaboard.c
index d669847f0485..0e2957f90201 100644
--- a/arch/arm/mach-tegra/board-seaboard.c
+++ b/arch/arm/mach-tegra/board-seaboard.c
@@ -153,7 +153,6 @@ static struct platform_device *seaboard_devices[] __initdata = {
153 &seaboard_gpio_keys_device, 153 &seaboard_gpio_keys_device,
154 &tegra_i2s_device1, 154 &tegra_i2s_device1,
155 &tegra_das_device, 155 &tegra_das_device,
156 &tegra_pcm_device,
157 &seaboard_audio_device, 156 &seaboard_audio_device,
158}; 157};
159 158
diff --git a/arch/arm/mach-tegra/board-trimslice.c b/arch/arm/mach-tegra/board-trimslice.c
index cd52820a3e37..ba2e04756c5e 100644
--- a/arch/arm/mach-tegra/board-trimslice.c
+++ b/arch/arm/mach-tegra/board-trimslice.c
@@ -86,7 +86,6 @@ static struct platform_device *trimslice_devices[] __initdata = {
86 &tegra_sdhci_device4, 86 &tegra_sdhci_device4,
87 &tegra_i2s_device1, 87 &tegra_i2s_device1,
88 &tegra_das_device, 88 &tegra_das_device,
89 &tegra_pcm_device,
90 &trimslice_audio_device, 89 &trimslice_audio_device,
91}; 90};
92 91
diff --git a/arch/arm/mach-tegra/devices.c b/arch/arm/mach-tegra/devices.c
index 5f6b867e20b4..d6c9b2624d85 100644
--- a/arch/arm/mach-tegra/devices.c
+++ b/arch/arm/mach-tegra/devices.c
@@ -671,14 +671,14 @@ static struct resource i2s_resource2[] = {
671}; 671};
672 672
673struct platform_device tegra_i2s_device1 = { 673struct platform_device tegra_i2s_device1 = {
674 .name = "tegra-i2s", 674 .name = "tegra20-i2s",
675 .id = 0, 675 .id = 0,
676 .resource = i2s_resource1, 676 .resource = i2s_resource1,
677 .num_resources = ARRAY_SIZE(i2s_resource1), 677 .num_resources = ARRAY_SIZE(i2s_resource1),
678}; 678};
679 679
680struct platform_device tegra_i2s_device2 = { 680struct platform_device tegra_i2s_device2 = {
681 .name = "tegra-i2s", 681 .name = "tegra20-i2s",
682 .id = 1, 682 .id = 1,
683 .resource = i2s_resource2, 683 .resource = i2s_resource2,
684 .num_resources = ARRAY_SIZE(i2s_resource2), 684 .num_resources = ARRAY_SIZE(i2s_resource2),
@@ -693,13 +693,8 @@ static struct resource tegra_das_resources[] = {
693}; 693};
694 694
695struct platform_device tegra_das_device = { 695struct platform_device tegra_das_device = {
696 .name = "tegra-das", 696 .name = "tegra20-das",
697 .id = -1, 697 .id = -1,
698 .num_resources = ARRAY_SIZE(tegra_das_resources), 698 .num_resources = ARRAY_SIZE(tegra_das_resources),
699 .resource = tegra_das_resources, 699 .resource = tegra_das_resources,
700}; 700};
701
702struct platform_device tegra_pcm_device = {
703 .name = "tegra-pcm-audio",
704 .id = -1,
705};
diff --git a/arch/arm/mach-tegra/devices.h b/arch/arm/mach-tegra/devices.h
index ec455679b219..138c642e59f4 100644
--- a/arch/arm/mach-tegra/devices.h
+++ b/arch/arm/mach-tegra/devices.h
@@ -52,6 +52,5 @@ extern struct platform_device tegra_pmu_device;
52extern struct platform_device tegra_i2s_device1; 52extern struct platform_device tegra_i2s_device1;
53extern struct platform_device tegra_i2s_device2; 53extern struct platform_device tegra_i2s_device2;
54extern struct platform_device tegra_das_device; 54extern struct platform_device tegra_das_device;
55extern struct platform_device tegra_pcm_device;
56 55
57#endif 56#endif
diff --git a/arch/arm/mach-tegra/tegra2_clocks.c b/arch/arm/mach-tegra/tegra2_clocks.c
index 592a4eeb5328..cf4999bcd4d8 100644
--- a/arch/arm/mach-tegra/tegra2_clocks.c
+++ b/arch/arm/mach-tegra/tegra2_clocks.c
@@ -2142,8 +2142,8 @@ static struct clk tegra_list_clks[] = {
2142 PERIPH_CLK("apbdma", "tegra-dma", NULL, 34, 0, 108000000, mux_pclk, 0), 2142 PERIPH_CLK("apbdma", "tegra-dma", NULL, 34, 0, 108000000, mux_pclk, 0),
2143 PERIPH_CLK("rtc", "rtc-tegra", NULL, 4, 0, 32768, mux_clk_32k, PERIPH_NO_RESET), 2143 PERIPH_CLK("rtc", "rtc-tegra", NULL, 4, 0, 32768, mux_clk_32k, PERIPH_NO_RESET),
2144 PERIPH_CLK("timer", "timer", NULL, 5, 0, 26000000, mux_clk_m, 0), 2144 PERIPH_CLK("timer", "timer", NULL, 5, 0, 26000000, mux_clk_m, 0),
2145 PERIPH_CLK("i2s1", "tegra-i2s.0", NULL, 11, 0x100, 26000000, mux_pllaout0_audio2x_pllp_clkm, MUX | DIV_U71), 2145 PERIPH_CLK("i2s1", "tegra20-i2s.0", NULL, 11, 0x100, 26000000, mux_pllaout0_audio2x_pllp_clkm, MUX | DIV_U71),
2146 PERIPH_CLK("i2s2", "tegra-i2s.1", NULL, 18, 0x104, 26000000, mux_pllaout0_audio2x_pllp_clkm, MUX | DIV_U71), 2146 PERIPH_CLK("i2s2", "tegra20-i2s.1", NULL, 18, 0x104, 26000000, mux_pllaout0_audio2x_pllp_clkm, MUX | DIV_U71),
2147 PERIPH_CLK("spdif_out", "spdif_out", NULL, 10, 0x108, 100000000, mux_pllaout0_audio2x_pllp_clkm, MUX | DIV_U71), 2147 PERIPH_CLK("spdif_out", "spdif_out", NULL, 10, 0x108, 100000000, mux_pllaout0_audio2x_pllp_clkm, MUX | DIV_U71),
2148 PERIPH_CLK("spdif_in", "spdif_in", NULL, 10, 0x10c, 100000000, mux_pllp_pllc_pllm, MUX | DIV_U71), 2148 PERIPH_CLK("spdif_in", "spdif_in", NULL, 10, 0x10c, 100000000, mux_pllp_pllc_pllm, MUX | DIV_U71),
2149 PERIPH_CLK("pwm", "pwm", NULL, 17, 0x110, 432000000, mux_pllp_pllc_audio_clkm_clk32, MUX | DIV_U71), 2149 PERIPH_CLK("pwm", "pwm", NULL, 17, 0x110, 432000000, mux_pllp_pllc_audio_clkm_clk32, MUX | DIV_U71),
diff --git a/arch/arm/mach-u300/core.c b/arch/arm/mach-u300/core.c
index 1621ad07d284..33339745d432 100644
--- a/arch/arm/mach-u300/core.c
+++ b/arch/arm/mach-u300/core.c
@@ -1667,8 +1667,10 @@ void __init u300_init_irq(void)
1667 1667
1668 for (i = 0; i < U300_VIC_IRQS_END; i++) 1668 for (i = 0; i < U300_VIC_IRQS_END; i++)
1669 set_bit(i, (unsigned long *) &mask[0]); 1669 set_bit(i, (unsigned long *) &mask[0]);
1670 vic_init((void __iomem *) U300_INTCON0_VBASE, 0, mask[0], mask[0]); 1670 vic_init((void __iomem *) U300_INTCON0_VBASE, IRQ_U300_INTCON0_START,
1671 vic_init((void __iomem *) U300_INTCON1_VBASE, 32, mask[1], mask[1]); 1671 mask[0], mask[0]);
1672 vic_init((void __iomem *) U300_INTCON1_VBASE, IRQ_U300_INTCON1_START,
1673 mask[1], mask[1]);
1672} 1674}
1673 1675
1674 1676
diff --git a/arch/arm/mach-u300/i2c.c b/arch/arm/mach-u300/i2c.c
index a38f80238ea9..cb04bd6ab3e7 100644
--- a/arch/arm/mach-u300/i2c.c
+++ b/arch/arm/mach-u300/i2c.c
@@ -146,9 +146,6 @@ static struct ab3100_platform_data ab3100_plf_data = {
146 .min_uV = 1800000, 146 .min_uV = 1800000,
147 .max_uV = 1800000, 147 .max_uV = 1800000,
148 .valid_modes_mask = REGULATOR_MODE_NORMAL, 148 .valid_modes_mask = REGULATOR_MODE_NORMAL,
149 .valid_ops_mask =
150 REGULATOR_CHANGE_VOLTAGE |
151 REGULATOR_CHANGE_STATUS,
152 .always_on = 1, 149 .always_on = 1,
153 .boot_on = 1, 150 .boot_on = 1,
154 }, 151 },
@@ -160,9 +157,6 @@ static struct ab3100_platform_data ab3100_plf_data = {
160 .min_uV = 2500000, 157 .min_uV = 2500000,
161 .max_uV = 2500000, 158 .max_uV = 2500000,
162 .valid_modes_mask = REGULATOR_MODE_NORMAL, 159 .valid_modes_mask = REGULATOR_MODE_NORMAL,
163 .valid_ops_mask =
164 REGULATOR_CHANGE_VOLTAGE |
165 REGULATOR_CHANGE_STATUS,
166 .always_on = 1, 160 .always_on = 1,
167 .boot_on = 1, 161 .boot_on = 1,
168 }, 162 },
@@ -230,8 +224,7 @@ static struct ab3100_platform_data ab3100_plf_data = {
230 .max_uV = 1800000, 224 .max_uV = 1800000,
231 .valid_modes_mask = REGULATOR_MODE_NORMAL, 225 .valid_modes_mask = REGULATOR_MODE_NORMAL,
232 .valid_ops_mask = 226 .valid_ops_mask =
233 REGULATOR_CHANGE_VOLTAGE | 227 REGULATOR_CHANGE_VOLTAGE,
234 REGULATOR_CHANGE_STATUS,
235 .always_on = 1, 228 .always_on = 1,
236 .boot_on = 1, 229 .boot_on = 1,
237 }, 230 },
diff --git a/arch/arm/mach-u300/include/mach/irqs.h b/arch/arm/mach-u300/include/mach/irqs.h
index ee78a26707eb..ec09c1e07b1a 100644
--- a/arch/arm/mach-u300/include/mach/irqs.h
+++ b/arch/arm/mach-u300/include/mach/irqs.h
@@ -12,101 +12,101 @@
12#ifndef __MACH_IRQS_H 12#ifndef __MACH_IRQS_H
13#define __MACH_IRQS_H 13#define __MACH_IRQS_H
14 14
15#define IRQ_U300_INTCON0_START 0 15#define IRQ_U300_INTCON0_START 1
16#define IRQ_U300_INTCON1_START 32 16#define IRQ_U300_INTCON1_START 33
17/* These are on INTCON0 - 30 lines */ 17/* These are on INTCON0 - 30 lines */
18#define IRQ_U300_IRQ0_EXT 0 18#define IRQ_U300_IRQ0_EXT 1
19#define IRQ_U300_IRQ1_EXT 1 19#define IRQ_U300_IRQ1_EXT 2
20#define IRQ_U300_DMA 2 20#define IRQ_U300_DMA 3
21#define IRQ_U300_VIDEO_ENC_0 3 21#define IRQ_U300_VIDEO_ENC_0 4
22#define IRQ_U300_VIDEO_ENC_1 4 22#define IRQ_U300_VIDEO_ENC_1 5
23#define IRQ_U300_AAIF_RX 5 23#define IRQ_U300_AAIF_RX 6
24#define IRQ_U300_AAIF_TX 6 24#define IRQ_U300_AAIF_TX 7
25#define IRQ_U300_AAIF_VGPIO 7 25#define IRQ_U300_AAIF_VGPIO 8
26#define IRQ_U300_AAIF_WAKEUP 8 26#define IRQ_U300_AAIF_WAKEUP 9
27#define IRQ_U300_PCM_I2S0_FRAME 9 27#define IRQ_U300_PCM_I2S0_FRAME 10
28#define IRQ_U300_PCM_I2S0_FIFO 10 28#define IRQ_U300_PCM_I2S0_FIFO 11
29#define IRQ_U300_PCM_I2S1_FRAME 11 29#define IRQ_U300_PCM_I2S1_FRAME 12
30#define IRQ_U300_PCM_I2S1_FIFO 12 30#define IRQ_U300_PCM_I2S1_FIFO 13
31#define IRQ_U300_XGAM_GAMCON 13 31#define IRQ_U300_XGAM_GAMCON 14
32#define IRQ_U300_XGAM_CDI 14 32#define IRQ_U300_XGAM_CDI 15
33#define IRQ_U300_XGAM_CDICON 15 33#define IRQ_U300_XGAM_CDICON 16
34#if defined(CONFIG_MACH_U300_BS2X) || defined(CONFIG_MACH_U300_BS330) 34#if defined(CONFIG_MACH_U300_BS2X) || defined(CONFIG_MACH_U300_BS330)
35/* MMIACC not used on the DB3210 or DB3350 chips */ 35/* MMIACC not used on the DB3210 or DB3350 chips */
36#define IRQ_U300_XGAM_MMIACC 16 36#define IRQ_U300_XGAM_MMIACC 17
37#endif 37#endif
38#define IRQ_U300_XGAM_PDI 17 38#define IRQ_U300_XGAM_PDI 18
39#define IRQ_U300_XGAM_PDICON 18 39#define IRQ_U300_XGAM_PDICON 19
40#define IRQ_U300_XGAM_GAMEACC 19 40#define IRQ_U300_XGAM_GAMEACC 20
41#define IRQ_U300_XGAM_MCIDCT 20 41#define IRQ_U300_XGAM_MCIDCT 21
42#define IRQ_U300_APEX 21 42#define IRQ_U300_APEX 22
43#define IRQ_U300_UART0 22 43#define IRQ_U300_UART0 23
44#define IRQ_U300_SPI 23 44#define IRQ_U300_SPI 24
45#define IRQ_U300_TIMER_APP_OS 24 45#define IRQ_U300_TIMER_APP_OS 25
46#define IRQ_U300_TIMER_APP_DD 25 46#define IRQ_U300_TIMER_APP_DD 26
47#define IRQ_U300_TIMER_APP_GP1 26 47#define IRQ_U300_TIMER_APP_GP1 27
48#define IRQ_U300_TIMER_APP_GP2 27 48#define IRQ_U300_TIMER_APP_GP2 28
49#define IRQ_U300_TIMER_OS 28 49#define IRQ_U300_TIMER_OS 29
50#define IRQ_U300_TIMER_MS 29 50#define IRQ_U300_TIMER_MS 30
51#define IRQ_U300_KEYPAD_KEYBF 30 51#define IRQ_U300_KEYPAD_KEYBF 31
52#define IRQ_U300_KEYPAD_KEYBR 31 52#define IRQ_U300_KEYPAD_KEYBR 32
53/* These are on INTCON1 - 32 lines */ 53/* These are on INTCON1 - 32 lines */
54#define IRQ_U300_GPIO_PORT0 32 54#define IRQ_U300_GPIO_PORT0 33
55#define IRQ_U300_GPIO_PORT1 33 55#define IRQ_U300_GPIO_PORT1 34
56#define IRQ_U300_GPIO_PORT2 34 56#define IRQ_U300_GPIO_PORT2 35
57 57
58#if defined(CONFIG_MACH_U300_BS2X) || defined(CONFIG_MACH_U300_BS330) || \ 58#if defined(CONFIG_MACH_U300_BS2X) || defined(CONFIG_MACH_U300_BS330) || \
59 defined(CONFIG_MACH_U300_BS335) 59 defined(CONFIG_MACH_U300_BS335)
60/* These are for DB3150, DB3200 and DB3350 */ 60/* These are for DB3150, DB3200 and DB3350 */
61#define IRQ_U300_WDOG 35 61#define IRQ_U300_WDOG 36
62#define IRQ_U300_EVHIST 36 62#define IRQ_U300_EVHIST 37
63#define IRQ_U300_MSPRO 37 63#define IRQ_U300_MSPRO 38
64#define IRQ_U300_MMCSD_MCIINTR0 38 64#define IRQ_U300_MMCSD_MCIINTR0 39
65#define IRQ_U300_MMCSD_MCIINTR1 39 65#define IRQ_U300_MMCSD_MCIINTR1 40
66#define IRQ_U300_I2C0 40 66#define IRQ_U300_I2C0 41
67#define IRQ_U300_I2C1 41 67#define IRQ_U300_I2C1 42
68#define IRQ_U300_RTC 42 68#define IRQ_U300_RTC 43
69#define IRQ_U300_NFIF 43 69#define IRQ_U300_NFIF 44
70#define IRQ_U300_NFIF2 44 70#define IRQ_U300_NFIF2 45
71#endif 71#endif
72 72
73/* DB3150 and DB3200 have only 45 IRQs */ 73/* DB3150 and DB3200 have only 45 IRQs */
74#if defined(CONFIG_MACH_U300_BS2X) || defined(CONFIG_MACH_U300_BS330) 74#if defined(CONFIG_MACH_U300_BS2X) || defined(CONFIG_MACH_U300_BS330)
75#define U300_VIC_IRQS_END 45 75#define U300_VIC_IRQS_END 46
76#endif 76#endif
77 77
78/* The DB3350-specific interrupt lines */ 78/* The DB3350-specific interrupt lines */
79#ifdef CONFIG_MACH_U300_BS335 79#ifdef CONFIG_MACH_U300_BS335
80#define IRQ_U300_ISP_F0 45 80#define IRQ_U300_ISP_F0 46
81#define IRQ_U300_ISP_F1 46 81#define IRQ_U300_ISP_F1 47
82#define IRQ_U300_ISP_F2 47 82#define IRQ_U300_ISP_F2 48
83#define IRQ_U300_ISP_F3 48 83#define IRQ_U300_ISP_F3 49
84#define IRQ_U300_ISP_F4 49 84#define IRQ_U300_ISP_F4 50
85#define IRQ_U300_GPIO_PORT3 50 85#define IRQ_U300_GPIO_PORT3 51
86#define IRQ_U300_SYSCON_PLL_LOCK 51 86#define IRQ_U300_SYSCON_PLL_LOCK 52
87#define IRQ_U300_UART1 52 87#define IRQ_U300_UART1 53
88#define IRQ_U300_GPIO_PORT4 53 88#define IRQ_U300_GPIO_PORT4 54
89#define IRQ_U300_GPIO_PORT5 54 89#define IRQ_U300_GPIO_PORT5 55
90#define IRQ_U300_GPIO_PORT6 55 90#define IRQ_U300_GPIO_PORT6 56
91#define U300_VIC_IRQS_END 56 91#define U300_VIC_IRQS_END 57
92#endif 92#endif
93 93
94/* The DB3210-specific interrupt lines */ 94/* The DB3210-specific interrupt lines */
95#ifdef CONFIG_MACH_U300_BS365 95#ifdef CONFIG_MACH_U300_BS365
96#define IRQ_U300_GPIO_PORT3 35 96#define IRQ_U300_GPIO_PORT3 36
97#define IRQ_U300_GPIO_PORT4 36 97#define IRQ_U300_GPIO_PORT4 37
98#define IRQ_U300_WDOG 37 98#define IRQ_U300_WDOG 38
99#define IRQ_U300_EVHIST 38 99#define IRQ_U300_EVHIST 39
100#define IRQ_U300_MSPRO 39 100#define IRQ_U300_MSPRO 40
101#define IRQ_U300_MMCSD_MCIINTR0 40 101#define IRQ_U300_MMCSD_MCIINTR0 41
102#define IRQ_U300_MMCSD_MCIINTR1 41 102#define IRQ_U300_MMCSD_MCIINTR1 42
103#define IRQ_U300_I2C0 42 103#define IRQ_U300_I2C0 43
104#define IRQ_U300_I2C1 43 104#define IRQ_U300_I2C1 44
105#define IRQ_U300_RTC 44 105#define IRQ_U300_RTC 45
106#define IRQ_U300_NFIF 45 106#define IRQ_U300_NFIF 46
107#define IRQ_U300_NFIF2 46 107#define IRQ_U300_NFIF2 47
108#define IRQ_U300_SYSCON_PLL_LOCK 47 108#define IRQ_U300_SYSCON_PLL_LOCK 48
109#define U300_VIC_IRQS_END 48 109#define U300_VIC_IRQS_END 49
110#endif 110#endif
111 111
112/* Maximum 8*7 GPIO lines */ 112/* Maximum 8*7 GPIO lines */
@@ -117,6 +117,6 @@
117#define IRQ_U300_GPIO_END (U300_VIC_IRQS_END) 117#define IRQ_U300_GPIO_END (U300_VIC_IRQS_END)
118#endif 118#endif
119 119
120#define NR_IRQS (IRQ_U300_GPIO_END) 120#define NR_IRQS (IRQ_U300_GPIO_END - IRQ_U300_INTCON0_START)
121 121
122#endif 122#endif
diff --git a/arch/arm/mach-ux500/Kconfig b/arch/arm/mach-ux500/Kconfig
index 880d02ec89d4..ef7099eea0f2 100644
--- a/arch/arm/mach-ux500/Kconfig
+++ b/arch/arm/mach-ux500/Kconfig
@@ -17,6 +17,7 @@ config UX500_SOC_DB5500
17config UX500_SOC_DB8500 17config UX500_SOC_DB8500
18 bool 18 bool
19 select MFD_DB8500_PRCMU 19 select MFD_DB8500_PRCMU
20 select REGULATOR
20 select REGULATOR_DB8500_PRCMU 21 select REGULATOR_DB8500_PRCMU
21 select CPU_FREQ_TABLE if CPU_FREQ 22 select CPU_FREQ_TABLE if CPU_FREQ
22 23
diff --git a/arch/arm/mach-ux500/mbox-db5500.c b/arch/arm/mach-ux500/mbox-db5500.c
index 2b2d51caf9d8..0127490218cd 100644
--- a/arch/arm/mach-ux500/mbox-db5500.c
+++ b/arch/arm/mach-ux500/mbox-db5500.c
@@ -168,7 +168,7 @@ static ssize_t mbox_read_fifo(struct device *dev,
168 return sprintf(buf, "0x%X\n", mbox_value); 168 return sprintf(buf, "0x%X\n", mbox_value);
169} 169}
170 170
171static DEVICE_ATTR(fifo, S_IWUGO | S_IRUGO, mbox_read_fifo, mbox_write_fifo); 171static DEVICE_ATTR(fifo, S_IWUSR | S_IRUGO, mbox_read_fifo, mbox_write_fifo);
172 172
173static int mbox_show(struct seq_file *s, void *data) 173static int mbox_show(struct seq_file *s, void *data)
174{ 174{
diff --git a/arch/arm/mach-ux500/platsmp.c b/arch/arm/mach-ux500/platsmp.c
index d2058ef8345f..eff5842f6232 100644
--- a/arch/arm/mach-ux500/platsmp.c
+++ b/arch/arm/mach-ux500/platsmp.c
@@ -99,7 +99,7 @@ int __cpuinit boot_secondary(unsigned int cpu, struct task_struct *idle)
99 */ 99 */
100 write_pen_release(cpu_logical_map(cpu)); 100 write_pen_release(cpu_logical_map(cpu));
101 101
102 gic_raise_softirq(cpumask_of(cpu), 1); 102 smp_send_reschedule(cpu);
103 103
104 timeout = jiffies + (1 * HZ); 104 timeout = jiffies + (1 * HZ);
105 while (time_before(jiffies, timeout)) { 105 while (time_before(jiffies, timeout)) {
diff --git a/arch/arm/mach-versatile/pci.c b/arch/arm/mach-versatile/pci.c
index a6e23f464528..d2268be8c34c 100644
--- a/arch/arm/mach-versatile/pci.c
+++ b/arch/arm/mach-versatile/pci.c
@@ -190,7 +190,7 @@ static struct resource pre_mem = {
190 .flags = IORESOURCE_MEM | IORESOURCE_PREFETCH, 190 .flags = IORESOURCE_MEM | IORESOURCE_PREFETCH,
191}; 191};
192 192
193static int __init pci_versatile_setup_resources(struct list_head *resources) 193static int __init pci_versatile_setup_resources(struct pci_sys_data *sys)
194{ 194{
195 int ret = 0; 195 int ret = 0;
196 196
@@ -218,9 +218,9 @@ static int __init pci_versatile_setup_resources(struct list_head *resources)
218 * the mem resource for this bus 218 * the mem resource for this bus
219 * the prefetch mem resource for this bus 219 * the prefetch mem resource for this bus
220 */ 220 */
221 pci_add_resource_offset(resources, &io_mem, sys->io_offset); 221 pci_add_resource_offset(&sys->resources, &io_mem, sys->io_offset);
222 pci_add_resource_offset(resources, &non_mem, sys->mem_offset); 222 pci_add_resource_offset(&sys->resources, &non_mem, sys->mem_offset);
223 pci_add_resource_offset(resources, &pre_mem, sys->mem_offset); 223 pci_add_resource_offset(&sys->resources, &pre_mem, sys->mem_offset);
224 224
225 goto out; 225 goto out;
226 226
@@ -249,7 +249,7 @@ int __init pci_versatile_setup(int nr, struct pci_sys_data *sys)
249 249
250 if (nr == 0) { 250 if (nr == 0) {
251 sys->mem_offset = 0; 251 sys->mem_offset = 0;
252 ret = pci_versatile_setup_resources(&sys->resources); 252 ret = pci_versatile_setup_resources(sys);
253 if (ret < 0) { 253 if (ret < 0) {
254 printk("pci_versatile_setup: resources... oops?\n"); 254 printk("pci_versatile_setup: resources... oops?\n");
255 goto out; 255 goto out;
diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
index 7edef9121632..7c8a7d8467bf 100644
--- a/arch/arm/mm/Kconfig
+++ b/arch/arm/mm/Kconfig
@@ -723,7 +723,7 @@ config CPU_HIGH_VECTOR
723 bool "Select the High exception vector" 723 bool "Select the High exception vector"
724 help 724 help
725 Say Y here to select high exception vector(0xFFFF0000~). 725 Say Y here to select high exception vector(0xFFFF0000~).
726 The exception vector can be vary depending on the platform 726 The exception vector can vary depending on the platform
727 design in nommu mode. If your platform needs to select 727 design in nommu mode. If your platform needs to select
728 high exception vector, say Y. 728 high exception vector, say Y.
729 Otherwise or if you are unsure, say N, and the low exception 729 Otherwise or if you are unsure, say N, and the low exception
diff --git a/arch/arm/mm/abort-ev6.S b/arch/arm/mm/abort-ev6.S
index ff1f7cc11f87..80741992a9fc 100644
--- a/arch/arm/mm/abort-ev6.S
+++ b/arch/arm/mm/abort-ev6.S
@@ -26,18 +26,23 @@ ENTRY(v6_early_abort)
26 mrc p15, 0, r1, c5, c0, 0 @ get FSR 26 mrc p15, 0, r1, c5, c0, 0 @ get FSR
27 mrc p15, 0, r0, c6, c0, 0 @ get FAR 27 mrc p15, 0, r0, c6, c0, 0 @ get FAR
28/* 28/*
29 * Faulty SWP instruction on 1136 doesn't set bit 11 in DFSR (erratum 326103). 29 * Faulty SWP instruction on 1136 doesn't set bit 11 in DFSR.
30 * The test below covers all the write situations, including Java bytecodes
31 */ 30 */
32 bic r1, r1, #1 << 11 @ clear bit 11 of FSR 31#ifdef CONFIG_ARM_ERRATA_326103
32 ldr ip, =0x4107b36
33 mrc p15, 0, r3, c0, c0, 0 @ get processor id
34 teq ip, r3, lsr #4 @ r0 ARM1136?
35 bne do_DataAbort
33 tst r5, #PSR_J_BIT @ Java? 36 tst r5, #PSR_J_BIT @ Java?
37 tsteq r5, #PSR_T_BIT @ Thumb?
34 bne do_DataAbort 38 bne do_DataAbort
35 do_thumb_abort fsr=r1, pc=r4, psr=r5, tmp=r3 39 bic r1, r1, #1 << 11 @ clear bit 11 of FSR
36 ldreq r3, [r4] @ read aborted ARM instruction 40 ldr r3, [r4] @ read aborted ARM instruction
37#ifdef CONFIG_CPU_ENDIAN_BE8 41#ifdef CONFIG_CPU_ENDIAN_BE8
38 reveq r3, r3 42 rev r3, r3
39#endif 43#endif
40 do_ldrd_abort tmp=ip, insn=r3 44 do_ldrd_abort tmp=ip, insn=r3
41 tst r3, #1 << 20 @ L = 0 -> write 45 tst r3, #1 << 20 @ L = 0 -> write
42 orreq r1, r1, #1 << 11 @ yes. 46 orreq r1, r1, #1 << 11 @ yes.
47#endif
43 b do_DataAbort 48 b do_DataAbort
diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
index a53fd2aaa2f4..2a8e380501e8 100644
--- a/arch/arm/mm/cache-l2x0.c
+++ b/arch/arm/mm/cache-l2x0.c
@@ -32,6 +32,7 @@ static void __iomem *l2x0_base;
32static DEFINE_RAW_SPINLOCK(l2x0_lock); 32static DEFINE_RAW_SPINLOCK(l2x0_lock);
33static u32 l2x0_way_mask; /* Bitmask of active ways */ 33static u32 l2x0_way_mask; /* Bitmask of active ways */
34static u32 l2x0_size; 34static u32 l2x0_size;
35static unsigned long sync_reg_offset = L2X0_CACHE_SYNC;
35 36
36struct l2x0_regs l2x0_saved_regs; 37struct l2x0_regs l2x0_saved_regs;
37 38
@@ -61,12 +62,7 @@ static inline void cache_sync(void)
61{ 62{
62 void __iomem *base = l2x0_base; 63 void __iomem *base = l2x0_base;
63 64
64#ifdef CONFIG_PL310_ERRATA_753970 65 writel_relaxed(0, base + sync_reg_offset);
65 /* write to an unmmapped register */
66 writel_relaxed(0, base + L2X0_DUMMY_REG);
67#else
68 writel_relaxed(0, base + L2X0_CACHE_SYNC);
69#endif
70 cache_wait(base + L2X0_CACHE_SYNC, 1); 66 cache_wait(base + L2X0_CACHE_SYNC, 1);
71} 67}
72 68
@@ -85,10 +81,13 @@ static inline void l2x0_inv_line(unsigned long addr)
85} 81}
86 82
87#if defined(CONFIG_PL310_ERRATA_588369) || defined(CONFIG_PL310_ERRATA_727915) 83#if defined(CONFIG_PL310_ERRATA_588369) || defined(CONFIG_PL310_ERRATA_727915)
84static inline void debug_writel(unsigned long val)
85{
86 if (outer_cache.set_debug)
87 outer_cache.set_debug(val);
88}
88 89
89#define debug_writel(val) outer_cache.set_debug(val) 90static void pl310_set_debug(unsigned long val)
90
91static void l2x0_set_debug(unsigned long val)
92{ 91{
93 writel_relaxed(val, l2x0_base + L2X0_DEBUG_CTRL); 92 writel_relaxed(val, l2x0_base + L2X0_DEBUG_CTRL);
94} 93}
@@ -98,7 +97,7 @@ static inline void debug_writel(unsigned long val)
98{ 97{
99} 98}
100 99
101#define l2x0_set_debug NULL 100#define pl310_set_debug NULL
102#endif 101#endif
103 102
104#ifdef CONFIG_PL310_ERRATA_588369 103#ifdef CONFIG_PL310_ERRATA_588369
@@ -331,6 +330,11 @@ void __init l2x0_init(void __iomem *base, u32 aux_val, u32 aux_mask)
331 else 330 else
332 ways = 8; 331 ways = 8;
333 type = "L310"; 332 type = "L310";
333#ifdef CONFIG_PL310_ERRATA_753970
334 /* Unmapped register. */
335 sync_reg_offset = L2X0_DUMMY_REG;
336#endif
337 outer_cache.set_debug = pl310_set_debug;
334 break; 338 break;
335 case L2X0_CACHE_ID_PART_L210: 339 case L2X0_CACHE_ID_PART_L210:
336 ways = (aux >> 13) & 0xf; 340 ways = (aux >> 13) & 0xf;
@@ -379,7 +383,6 @@ void __init l2x0_init(void __iomem *base, u32 aux_val, u32 aux_mask)
379 outer_cache.flush_all = l2x0_flush_all; 383 outer_cache.flush_all = l2x0_flush_all;
380 outer_cache.inv_all = l2x0_inv_all; 384 outer_cache.inv_all = l2x0_inv_all;
381 outer_cache.disable = l2x0_disable; 385 outer_cache.disable = l2x0_disable;
382 outer_cache.set_debug = l2x0_set_debug;
383 386
384 printk(KERN_INFO "%s cache controller enabled\n", type); 387 printk(KERN_INFO "%s cache controller enabled\n", type);
385 printk(KERN_INFO "l2x0: %d ways, CACHE_ID 0x%08x, AUX_CTRL 0x%08x, Cache size: %d B\n", 388 printk(KERN_INFO "l2x0: %d ways, CACHE_ID 0x%08x, AUX_CTRL 0x%08x, Cache size: %d B\n",
diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
index 9055b5a84ec5..f07467533365 100644
--- a/arch/arm/mm/fault.c
+++ b/arch/arm/mm/fault.c
@@ -320,7 +320,7 @@ retry:
320 */ 320 */
321 321
322 perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, addr); 322 perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, addr);
323 if (flags & FAULT_FLAG_ALLOW_RETRY) { 323 if (!(fault & VM_FAULT_ERROR) && flags & FAULT_FLAG_ALLOW_RETRY) {
324 if (fault & VM_FAULT_MAJOR) { 324 if (fault & VM_FAULT_MAJOR) {
325 tsk->maj_flt++; 325 tsk->maj_flt++;
326 perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MAJ, 1, 326 perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MAJ, 1,
diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
index 595079fa9d1d..8f5813bbffb5 100644
--- a/arch/arm/mm/init.c
+++ b/arch/arm/mm/init.c
@@ -293,11 +293,11 @@ EXPORT_SYMBOL(pfn_valid);
293#endif 293#endif
294 294
295#ifndef CONFIG_SPARSEMEM 295#ifndef CONFIG_SPARSEMEM
296static void arm_memory_present(void) 296static void __init arm_memory_present(void)
297{ 297{
298} 298}
299#else 299#else
300static void arm_memory_present(void) 300static void __init arm_memory_present(void)
301{ 301{
302 struct memblock_region *reg; 302 struct memblock_region *reg;
303 303
diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
index b86f8933ff91..2c7cf2f9c837 100644
--- a/arch/arm/mm/mmu.c
+++ b/arch/arm/mm/mmu.c
@@ -618,8 +618,8 @@ static void __init alloc_init_section(pud_t *pud, unsigned long addr,
618 } 618 }
619} 619}
620 620
621static void alloc_init_pud(pgd_t *pgd, unsigned long addr, unsigned long end, 621static void __init alloc_init_pud(pgd_t *pgd, unsigned long addr,
622 unsigned long phys, const struct mem_type *type) 622 unsigned long end, unsigned long phys, const struct mem_type *type)
623{ 623{
624 pud_t *pud = pud_offset(pgd, addr); 624 pud_t *pud = pud_offset(pgd, addr);
625 unsigned long next; 625 unsigned long next;
diff --git a/arch/arm/mm/nommu.c b/arch/arm/mm/nommu.c
index 6486d2f253cd..d51225f90ae2 100644
--- a/arch/arm/mm/nommu.c
+++ b/arch/arm/mm/nommu.c
@@ -13,6 +13,7 @@
13#include <asm/sections.h> 13#include <asm/sections.h>
14#include <asm/page.h> 14#include <asm/page.h>
15#include <asm/setup.h> 15#include <asm/setup.h>
16#include <asm/traps.h>
16#include <asm/mach/arch.h> 17#include <asm/mach/arch.h>
17 18
18#include "mm.h" 19#include "mm.h"
@@ -39,6 +40,7 @@ void __init sanity_check_meminfo(void)
39 */ 40 */
40void __init paging_init(struct machine_desc *mdesc) 41void __init paging_init(struct machine_desc *mdesc)
41{ 42{
43 early_trap_init((void *)CONFIG_VECTORS_BASE);
42 bootmem_init(); 44 bootmem_init();
43} 45}
44 46
diff --git a/arch/arm/mm/proc-v7.S b/arch/arm/mm/proc-v7.S
index f1c8486f7501..c2e2b66f72b5 100644
--- a/arch/arm/mm/proc-v7.S
+++ b/arch/arm/mm/proc-v7.S
@@ -255,6 +255,18 @@ __v7_setup:
255 mcr p15, 0, r5, c10, c2, 0 @ write PRRR 255 mcr p15, 0, r5, c10, c2, 0 @ write PRRR
256 mcr p15, 0, r6, c10, c2, 1 @ write NMRR 256 mcr p15, 0, r6, c10, c2, 1 @ write NMRR
257#endif 257#endif
258#ifndef CONFIG_ARM_THUMBEE
259 mrc p15, 0, r0, c0, c1, 0 @ read ID_PFR0 for ThumbEE
260 and r0, r0, #(0xf << 12) @ ThumbEE enabled field
261 teq r0, #(1 << 12) @ check if ThumbEE is present
262 bne 1f
263 mov r5, #0
264 mcr p14, 6, r5, c1, c0, 0 @ Initialize TEEHBR to 0
265 mrc p14, 6, r0, c0, c0, 0 @ load TEECR
266 orr r0, r0, #1 @ set the 1st bit in order to
267 mcr p14, 6, r0, c0, c0, 0 @ stop userspace TEEHBR access
2681:
269#endif
258 adr r5, v7_crval 270 adr r5, v7_crval
259 ldmia r5, {r5, r6} 271 ldmia r5, {r5, r6}
260#ifdef CONFIG_CPU_ENDIAN_BE8 272#ifdef CONFIG_CPU_ENDIAN_BE8
diff --git a/arch/arm/plat-mxc/3ds_debugboard.c b/arch/arm/plat-mxc/3ds_debugboard.c
index d1e31fa1b0c3..5cac2c540f4f 100644
--- a/arch/arm/plat-mxc/3ds_debugboard.c
+++ b/arch/arm/plat-mxc/3ds_debugboard.c
@@ -80,7 +80,7 @@ static struct smsc911x_platform_config smsc911x_config = {
80 80
81static struct platform_device smsc_lan9217_device = { 81static struct platform_device smsc_lan9217_device = {
82 .name = "smsc911x", 82 .name = "smsc911x",
83 .id = 0, 83 .id = -1,
84 .dev = { 84 .dev = {
85 .platform_data = &smsc911x_config, 85 .platform_data = &smsc911x_config,
86 }, 86 },
diff --git a/arch/arm/plat-omap/Kconfig b/arch/arm/plat-omap/Kconfig
index ce1e9b96ba1a..ad95c7a5d009 100644
--- a/arch/arm/plat-omap/Kconfig
+++ b/arch/arm/plat-omap/Kconfig
@@ -17,6 +17,7 @@ config ARCH_OMAP1
17 select IRQ_DOMAIN 17 select IRQ_DOMAIN
18 select HAVE_IDE 18 select HAVE_IDE
19 select NEED_MACH_MEMORY_H 19 select NEED_MACH_MEMORY_H
20 select NEED_MACH_IO_H if PCCARD
20 help 21 help
21 "Systems based on omap7xx, omap15xx or omap16xx" 22 "Systems based on omap7xx, omap15xx or omap16xx"
22 23
diff --git a/arch/arm/plat-omap/clock.c b/arch/arm/plat-omap/clock.c
index 56b6f8b7053e..62ec5c452792 100644
--- a/arch/arm/plat-omap/clock.c
+++ b/arch/arm/plat-omap/clock.c
@@ -398,32 +398,6 @@ struct clk dummy_ck = {
398 .ops = &clkops_null, 398 .ops = &clkops_null,
399}; 399};
400 400
401#ifdef CONFIG_CPU_FREQ
402void clk_init_cpufreq_table(struct cpufreq_frequency_table **table)
403{
404 unsigned long flags;
405
406 if (!arch_clock || !arch_clock->clk_init_cpufreq_table)
407 return;
408
409 spin_lock_irqsave(&clockfw_lock, flags);
410 arch_clock->clk_init_cpufreq_table(table);
411 spin_unlock_irqrestore(&clockfw_lock, flags);
412}
413
414void clk_exit_cpufreq_table(struct cpufreq_frequency_table **table)
415{
416 unsigned long flags;
417
418 if (!arch_clock || !arch_clock->clk_exit_cpufreq_table)
419 return;
420
421 spin_lock_irqsave(&clockfw_lock, flags);
422 arch_clock->clk_exit_cpufreq_table(table);
423 spin_unlock_irqrestore(&clockfw_lock, flags);
424}
425#endif
426
427/* 401/*
428 * 402 *
429 */ 403 */
@@ -441,6 +415,8 @@ static int __init clk_disable_unused(void)
441 return 0; 415 return 0;
442 416
443 pr_info("clock: disabling unused clocks to save power\n"); 417 pr_info("clock: disabling unused clocks to save power\n");
418
419 spin_lock_irqsave(&clockfw_lock, flags);
444 list_for_each_entry(ck, &clocks, node) { 420 list_for_each_entry(ck, &clocks, node) {
445 if (ck->ops == &clkops_null) 421 if (ck->ops == &clkops_null)
446 continue; 422 continue;
@@ -448,10 +424,9 @@ static int __init clk_disable_unused(void)
448 if (ck->usecount > 0 || !ck->enable_reg) 424 if (ck->usecount > 0 || !ck->enable_reg)
449 continue; 425 continue;
450 426
451 spin_lock_irqsave(&clockfw_lock, flags);
452 arch_clock->clk_disable_unused(ck); 427 arch_clock->clk_disable_unused(ck);
453 spin_unlock_irqrestore(&clockfw_lock, flags);
454 } 428 }
429 spin_unlock_irqrestore(&clockfw_lock, flags);
455 430
456 return 0; 431 return 0;
457} 432}
diff --git a/arch/arm/plat-omap/dma.c b/arch/arm/plat-omap/dma.c
index ecdb3da0dea9..c58d896cd5c3 100644
--- a/arch/arm/plat-omap/dma.c
+++ b/arch/arm/plat-omap/dma.c
@@ -916,6 +916,13 @@ void omap_start_dma(int lch)
916 l |= OMAP_DMA_CCR_BUFFERING_DISABLE; 916 l |= OMAP_DMA_CCR_BUFFERING_DISABLE;
917 l |= OMAP_DMA_CCR_EN; 917 l |= OMAP_DMA_CCR_EN;
918 918
919 /*
920 * As dma_write() uses IO accessors which are weakly ordered, there
921 * is no guarantee that data in coherent DMA memory will be visible
922 * to the DMA device. Add a memory barrier here to ensure that any
923 * such data is visible prior to enabling DMA.
924 */
925 mb();
919 p->dma_write(l, CCR, lch); 926 p->dma_write(l, CCR, lch);
920 927
921 dma_chan[lch].flags |= OMAP_DMA_ACTIVE; 928 dma_chan[lch].flags |= OMAP_DMA_ACTIVE;
@@ -965,6 +972,13 @@ void omap_stop_dma(int lch)
965 p->dma_write(l, CCR, lch); 972 p->dma_write(l, CCR, lch);
966 } 973 }
967 974
975 /*
976 * Ensure that data transferred by DMA is visible to any access
977 * after DMA has been disabled. This is important for coherent
978 * DMA regions.
979 */
980 mb();
981
968 if (!omap_dma_in_1510_mode() && dma_chan[lch].next_lch != -1) { 982 if (!omap_dma_in_1510_mode() && dma_chan[lch].next_lch != -1) {
969 int next_lch, cur_lch = lch; 983 int next_lch, cur_lch = lch;
970 char dma_chan_link_map[dma_lch_count]; 984 char dma_chan_link_map[dma_lch_count];
diff --git a/arch/arm/plat-omap/include/plat/clock.h b/arch/arm/plat-omap/include/plat/clock.h
index 240a7b9fd946..d0ef57c1d71b 100644
--- a/arch/arm/plat-omap/include/plat/clock.h
+++ b/arch/arm/plat-omap/include/plat/clock.h
@@ -272,8 +272,6 @@ struct clk {
272#endif 272#endif
273}; 273};
274 274
275struct cpufreq_frequency_table;
276
277struct clk_functions { 275struct clk_functions {
278 int (*clk_enable)(struct clk *clk); 276 int (*clk_enable)(struct clk *clk);
279 void (*clk_disable)(struct clk *clk); 277 void (*clk_disable)(struct clk *clk);
@@ -283,10 +281,6 @@ struct clk_functions {
283 void (*clk_allow_idle)(struct clk *clk); 281 void (*clk_allow_idle)(struct clk *clk);
284 void (*clk_deny_idle)(struct clk *clk); 282 void (*clk_deny_idle)(struct clk *clk);
285 void (*clk_disable_unused)(struct clk *clk); 283 void (*clk_disable_unused)(struct clk *clk);
286#ifdef CONFIG_CPU_FREQ
287 void (*clk_init_cpufreq_table)(struct cpufreq_frequency_table **);
288 void (*clk_exit_cpufreq_table)(struct cpufreq_frequency_table **);
289#endif
290}; 284};
291 285
292extern int mpurate; 286extern int mpurate;
@@ -301,10 +295,6 @@ extern void recalculate_root_clocks(void);
301extern unsigned long followparent_recalc(struct clk *clk); 295extern unsigned long followparent_recalc(struct clk *clk);
302extern void clk_enable_init_clocks(void); 296extern void clk_enable_init_clocks(void);
303unsigned long omap_fixed_divisor_recalc(struct clk *clk); 297unsigned long omap_fixed_divisor_recalc(struct clk *clk);
304#ifdef CONFIG_CPU_FREQ
305extern void clk_init_cpufreq_table(struct cpufreq_frequency_table **table);
306extern void clk_exit_cpufreq_table(struct cpufreq_frequency_table **table);
307#endif
308extern struct clk *omap_clk_get_by_name(const char *name); 298extern struct clk *omap_clk_get_by_name(const char *name);
309extern int omap_clk_enable_autoidle_all(void); 299extern int omap_clk_enable_autoidle_all(void);
310extern int omap_clk_disable_autoidle_all(void); 300extern int omap_clk_disable_autoidle_all(void);
diff --git a/arch/arm/plat-omap/include/plat/omap_hwmod.h b/arch/arm/plat-omap/include/plat/omap_hwmod.h
index 9e8e63d52aab..3f26db4ee8e6 100644
--- a/arch/arm/plat-omap/include/plat/omap_hwmod.h
+++ b/arch/arm/plat-omap/include/plat/omap_hwmod.h
@@ -47,17 +47,17 @@ extern struct omap_hwmod_sysc_fields omap_hwmod_sysc_type2;
47 * with the original PRCM protocol defined for OMAP2420 47 * with the original PRCM protocol defined for OMAP2420
48 */ 48 */
49#define SYSC_TYPE1_MIDLEMODE_SHIFT 12 49#define SYSC_TYPE1_MIDLEMODE_SHIFT 12
50#define SYSC_TYPE1_MIDLEMODE_MASK (0x3 << SYSC_MIDLEMODE_SHIFT) 50#define SYSC_TYPE1_MIDLEMODE_MASK (0x3 << SYSC_TYPE1_MIDLEMODE_SHIFT)
51#define SYSC_TYPE1_CLOCKACTIVITY_SHIFT 8 51#define SYSC_TYPE1_CLOCKACTIVITY_SHIFT 8
52#define SYSC_TYPE1_CLOCKACTIVITY_MASK (0x3 << SYSC_CLOCKACTIVITY_SHIFT) 52#define SYSC_TYPE1_CLOCKACTIVITY_MASK (0x3 << SYSC_TYPE1_CLOCKACTIVITY_SHIFT)
53#define SYSC_TYPE1_SIDLEMODE_SHIFT 3 53#define SYSC_TYPE1_SIDLEMODE_SHIFT 3
54#define SYSC_TYPE1_SIDLEMODE_MASK (0x3 << SYSC_SIDLEMODE_SHIFT) 54#define SYSC_TYPE1_SIDLEMODE_MASK (0x3 << SYSC_TYPE1_SIDLEMODE_SHIFT)
55#define SYSC_TYPE1_ENAWAKEUP_SHIFT 2 55#define SYSC_TYPE1_ENAWAKEUP_SHIFT 2
56#define SYSC_TYPE1_ENAWAKEUP_MASK (1 << SYSC_ENAWAKEUP_SHIFT) 56#define SYSC_TYPE1_ENAWAKEUP_MASK (1 << SYSC_TYPE1_ENAWAKEUP_SHIFT)
57#define SYSC_TYPE1_SOFTRESET_SHIFT 1 57#define SYSC_TYPE1_SOFTRESET_SHIFT 1
58#define SYSC_TYPE1_SOFTRESET_MASK (1 << SYSC_SOFTRESET_SHIFT) 58#define SYSC_TYPE1_SOFTRESET_MASK (1 << SYSC_TYPE1_SOFTRESET_SHIFT)
59#define SYSC_TYPE1_AUTOIDLE_SHIFT 0 59#define SYSC_TYPE1_AUTOIDLE_SHIFT 0
60#define SYSC_TYPE1_AUTOIDLE_MASK (1 << SYSC_AUTOIDLE_SHIFT) 60#define SYSC_TYPE1_AUTOIDLE_MASK (1 << SYSC_TYPE1_AUTOIDLE_SHIFT)
61 61
62/* 62/*
63 * OCP SYSCONFIG bit shifts/masks TYPE2. These are for IPs compliant 63 * OCP SYSCONFIG bit shifts/masks TYPE2. These are for IPs compliant
@@ -305,6 +305,7 @@ struct omap_hwmod_sysc_fields {
305 * @rev_offs: IP block revision register offset (from module base addr) 305 * @rev_offs: IP block revision register offset (from module base addr)
306 * @sysc_offs: OCP_SYSCONFIG register offset (from module base addr) 306 * @sysc_offs: OCP_SYSCONFIG register offset (from module base addr)
307 * @syss_offs: OCP_SYSSTATUS register offset (from module base addr) 307 * @syss_offs: OCP_SYSSTATUS register offset (from module base addr)
308 * @srst_udelay: Delay needed after doing a softreset in usecs
308 * @idlemodes: One or more of {SIDLE,MSTANDBY}_{OFF,FORCE,SMART} 309 * @idlemodes: One or more of {SIDLE,MSTANDBY}_{OFF,FORCE,SMART}
309 * @sysc_flags: SYS{C,S}_HAS* flags indicating SYSCONFIG bits supported 310 * @sysc_flags: SYS{C,S}_HAS* flags indicating SYSCONFIG bits supported
310 * @clockact: the default value of the module CLOCKACTIVITY bits 311 * @clockact: the default value of the module CLOCKACTIVITY bits
@@ -330,9 +331,10 @@ struct omap_hwmod_class_sysconfig {
330 u16 sysc_offs; 331 u16 sysc_offs;
331 u16 syss_offs; 332 u16 syss_offs;
332 u16 sysc_flags; 333 u16 sysc_flags;
334 struct omap_hwmod_sysc_fields *sysc_fields;
335 u8 srst_udelay;
333 u8 idlemodes; 336 u8 idlemodes;
334 u8 clockact; 337 u8 clockact;
335 struct omap_hwmod_sysc_fields *sysc_fields;
336}; 338};
337 339
338/** 340/**
diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
index eec98afa0f83..f9a8c5341ee9 100644
--- a/arch/arm/plat-omap/sram.c
+++ b/arch/arm/plat-omap/sram.c
@@ -348,7 +348,6 @@ u32 omap3_configure_core_dpll(u32 m2, u32 unlock_dll, u32 f, u32 inc,
348 sdrc_actim_ctrl_b_1, sdrc_mr_1); 348 sdrc_actim_ctrl_b_1, sdrc_mr_1);
349} 349}
350 350
351#ifdef CONFIG_PM
352void omap3_sram_restore_context(void) 351void omap3_sram_restore_context(void)
353{ 352{
354 omap_sram_ceil = omap_sram_base + omap_sram_size; 353 omap_sram_ceil = omap_sram_base + omap_sram_size;
@@ -358,17 +357,18 @@ void omap3_sram_restore_context(void)
358 omap3_sram_configure_core_dpll_sz); 357 omap3_sram_configure_core_dpll_sz);
359 omap_push_sram_idle(); 358 omap_push_sram_idle();
360} 359}
361#endif /* CONFIG_PM */
362
363#endif /* CONFIG_ARCH_OMAP3 */
364 360
365static inline int omap34xx_sram_init(void) 361static inline int omap34xx_sram_init(void)
366{ 362{
367#if defined(CONFIG_ARCH_OMAP3) && defined(CONFIG_PM)
368 omap3_sram_restore_context(); 363 omap3_sram_restore_context();
369#endif
370 return 0; 364 return 0;
371} 365}
366#else
367static inline int omap34xx_sram_init(void)
368{
369 return 0;
370}
371#endif /* CONFIG_ARCH_OMAP3 */
372 372
373static inline int am33xx_sram_init(void) 373static inline int am33xx_sram_init(void)
374{ 374{
diff --git a/arch/arm/plat-samsung/Kconfig b/arch/arm/plat-samsung/Kconfig
index 71553f410016..a0ffc77da809 100644
--- a/arch/arm/plat-samsung/Kconfig
+++ b/arch/arm/plat-samsung/Kconfig
@@ -302,6 +302,7 @@ comment "Power management"
302config SAMSUNG_PM_DEBUG 302config SAMSUNG_PM_DEBUG
303 bool "S3C2410 PM Suspend debug" 303 bool "S3C2410 PM Suspend debug"
304 depends on PM 304 depends on PM
305 select DEBUG_LL
305 help 306 help
306 Say Y here if you want verbose debugging from the PM Suspend and 307 Say Y here if you want verbose debugging from the PM Suspend and
307 Resume code. See <file:Documentation/arm/Samsung-S3C24XX/Suspend.txt> 308 Resume code. See <file:Documentation/arm/Samsung-S3C24XX/Suspend.txt>
diff --git a/arch/arm/plat-samsung/include/plat/sdhci.h b/arch/arm/plat-samsung/include/plat/sdhci.h
index 317e246ffc56..e834c5ef437c 100644
--- a/arch/arm/plat-samsung/include/plat/sdhci.h
+++ b/arch/arm/plat-samsung/include/plat/sdhci.h
@@ -18,6 +18,8 @@
18#ifndef __PLAT_S3C_SDHCI_H 18#ifndef __PLAT_S3C_SDHCI_H
19#define __PLAT_S3C_SDHCI_H __FILE__ 19#define __PLAT_S3C_SDHCI_H __FILE__
20 20
21#include <plat/devs.h>
22
21struct platform_device; 23struct platform_device;
22struct mmc_host; 24struct mmc_host;
23struct mmc_card; 25struct mmc_card;
@@ -356,4 +358,30 @@ static inline void exynos4_default_sdhci3(void) { }
356 358
357#endif /* CONFIG_EXYNOS4_SETUP_SDHCI */ 359#endif /* CONFIG_EXYNOS4_SETUP_SDHCI */
358 360
361static inline void s3c_sdhci_setname(int id, char *name)
362{
363 switch (id) {
364#ifdef CONFIG_S3C_DEV_HSMMC
365 case 0:
366 s3c_device_hsmmc0.name = name;
367 break;
368#endif
369#ifdef CONFIG_S3C_DEV_HSMMC1
370 case 1:
371 s3c_device_hsmmc1.name = name;
372 break;
373#endif
374#ifdef CONFIG_S3C_DEV_HSMMC2
375 case 2:
376 s3c_device_hsmmc2.name = name;
377 break;
378#endif
379#ifdef CONFIG_S3C_DEV_HSMMC3
380 case 3:
381 s3c_device_hsmmc3.name = name;
382 break;
383#endif
384 }
385}
386
359#endif /* __PLAT_S3C_SDHCI_H */ 387#endif /* __PLAT_S3C_SDHCI_H */
diff --git a/arch/arm/vfp/vfpmodule.c b/arch/arm/vfp/vfpmodule.c
index 858748eaa144..bc683b8219b5 100644
--- a/arch/arm/vfp/vfpmodule.c
+++ b/arch/arm/vfp/vfpmodule.c
@@ -17,6 +17,8 @@
17#include <linux/sched.h> 17#include <linux/sched.h>
18#include <linux/smp.h> 18#include <linux/smp.h>
19#include <linux/init.h> 19#include <linux/init.h>
20#include <linux/uaccess.h>
21#include <linux/user.h>
20 22
21#include <asm/cp15.h> 23#include <asm/cp15.h>
22#include <asm/cputype.h> 24#include <asm/cputype.h>
@@ -529,6 +531,103 @@ void vfp_flush_hwstate(struct thread_info *thread)
529} 531}
530 532
531/* 533/*
534 * Save the current VFP state into the provided structures and prepare
535 * for entry into a new function (signal handler).
536 */
537int vfp_preserve_user_clear_hwstate(struct user_vfp __user *ufp,
538 struct user_vfp_exc __user *ufp_exc)
539{
540 struct thread_info *thread = current_thread_info();
541 struct vfp_hard_struct *hwstate = &thread->vfpstate.hard;
542 int err = 0;
543
544 /* Ensure that the saved hwstate is up-to-date. */
545 vfp_sync_hwstate(thread);
546
547 /*
548 * Copy the floating point registers. There can be unused
549 * registers see asm/hwcap.h for details.
550 */
551 err |= __copy_to_user(&ufp->fpregs, &hwstate->fpregs,
552 sizeof(hwstate->fpregs));
553 /*
554 * Copy the status and control register.
555 */
556 __put_user_error(hwstate->fpscr, &ufp->fpscr, err);
557
558 /*
559 * Copy the exception registers.
560 */
561 __put_user_error(hwstate->fpexc, &ufp_exc->fpexc, err);
562 __put_user_error(hwstate->fpinst, &ufp_exc->fpinst, err);
563 __put_user_error(hwstate->fpinst2, &ufp_exc->fpinst2, err);
564
565 if (err)
566 return -EFAULT;
567
568 /* Ensure that VFP is disabled. */
569 vfp_flush_hwstate(thread);
570
571 /*
572 * As per the PCS, clear the length and stride bits for function
573 * entry.
574 */
575 hwstate->fpscr &= ~(FPSCR_LENGTH_MASK | FPSCR_STRIDE_MASK);
576
577 /*
578 * Disable VFP in the hwstate so that we can detect if it gets
579 * used.
580 */
581 hwstate->fpexc &= ~FPEXC_EN;
582 return 0;
583}
584
585/* Sanitise and restore the current VFP state from the provided structures. */
586int vfp_restore_user_hwstate(struct user_vfp __user *ufp,
587 struct user_vfp_exc __user *ufp_exc)
588{
589 struct thread_info *thread = current_thread_info();
590 struct vfp_hard_struct *hwstate = &thread->vfpstate.hard;
591 unsigned long fpexc;
592 int err = 0;
593
594 /*
595 * If VFP has been used, then disable it to avoid corrupting
596 * the new thread state.
597 */
598 if (hwstate->fpexc & FPEXC_EN)
599 vfp_flush_hwstate(thread);
600
601 /*
602 * Copy the floating point registers. There can be unused
603 * registers see asm/hwcap.h for details.
604 */
605 err |= __copy_from_user(&hwstate->fpregs, &ufp->fpregs,
606 sizeof(hwstate->fpregs));
607 /*
608 * Copy the status and control register.
609 */
610 __get_user_error(hwstate->fpscr, &ufp->fpscr, err);
611
612 /*
613 * Sanitise and restore the exception registers.
614 */
615 __get_user_error(fpexc, &ufp_exc->fpexc, err);
616
617 /* Ensure the VFP is enabled. */
618 fpexc |= FPEXC_EN;
619
620 /* Ensure FPINST2 is invalid and the exception flag is cleared. */
621 fpexc &= ~(FPEXC_EX | FPEXC_FP2V);
622 hwstate->fpexc = fpexc;
623
624 __get_user_error(hwstate->fpinst, &ufp_exc->fpinst, err);
625 __get_user_error(hwstate->fpinst2, &ufp_exc->fpinst2, err);
626
627 return err ? -EFAULT : 0;
628}
629
630/*
532 * VFP hardware can lose all context when a CPU goes offline. 631 * VFP hardware can lose all context when a CPU goes offline.
533 * As we will be running in SMP mode with CPU hotplug, we will save the 632 * As we will be running in SMP mode with CPU hotplug, we will save the
534 * hardware state at every thread switch. We clear our held state when 633 * hardware state at every thread switch. We clear our held state when
diff --git a/arch/avr32/include/asm/barrier.h b/arch/avr32/include/asm/barrier.h
index 808001c9cf8c..0961275373db 100644
--- a/arch/avr32/include/asm/barrier.h
+++ b/arch/avr32/include/asm/barrier.h
@@ -8,6 +8,8 @@
8#ifndef __ASM_AVR32_BARRIER_H 8#ifndef __ASM_AVR32_BARRIER_H
9#define __ASM_AVR32_BARRIER_H 9#define __ASM_AVR32_BARRIER_H
10 10
11#define nop() asm volatile("nop")
12
11#define mb() asm volatile("" : : : "memory") 13#define mb() asm volatile("" : : : "memory")
12#define rmb() mb() 14#define rmb() mb()
13#define wmb() asm volatile("sync 0" : : : "memory") 15#define wmb() asm volatile("sync 0" : : : "memory")
diff --git a/arch/avr32/include/asm/special_insns.h b/arch/avr32/include/asm/special_insns.h
deleted file mode 100644
index f922218dfaa5..000000000000
--- a/arch/avr32/include/asm/special_insns.h
+++ /dev/null
@@ -1,13 +0,0 @@
1/*
2 * Copyright (C) 2004-2006 Atmel Corporation
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
8#ifndef __ASM_AVR32_SPECIAL_INSNS_H
9#define __ASM_AVR32_SPECIAL_INSNS_H
10
11#define nop() asm volatile("nop")
12
13#endif /* __ASM_AVR32_SPECIAL_INSNS_H */
diff --git a/arch/avr32/mach-at32ap/include/mach/board.h b/arch/avr32/mach-at32ap/include/mach/board.h
index 71733866cb4f..70742ec997f8 100644
--- a/arch/avr32/mach-at32ap/include/mach/board.h
+++ b/arch/avr32/mach-at32ap/include/mach/board.h
@@ -7,7 +7,7 @@
7#include <linux/types.h> 7#include <linux/types.h>
8#include <linux/serial.h> 8#include <linux/serial.h>
9#include <linux/platform_data/macb.h> 9#include <linux/platform_data/macb.h>
10#include <linux/platform_data/atmel_nand.h> 10#include <linux/platform_data/atmel.h>
11 11
12#define GPIO_PIN_NONE (-1) 12#define GPIO_PIN_NONE (-1)
13 13
diff --git a/arch/blackfin/Kconfig b/arch/blackfin/Kconfig
index c1269a1085e1..373a6902d8fa 100644
--- a/arch/blackfin/Kconfig
+++ b/arch/blackfin/Kconfig
@@ -823,7 +823,7 @@ config CACHELINE_ALIGNED_L1
823 bool "Locate cacheline_aligned data to L1 Data Memory" 823 bool "Locate cacheline_aligned data to L1 Data Memory"
824 default y if !BF54x 824 default y if !BF54x
825 default n if BF54x 825 default n if BF54x
826 depends on !SMP && !BF531 826 depends on !SMP && !BF531 && !CRC32
827 help 827 help
828 If enabled, cacheline_aligned data is linked 828 If enabled, cacheline_aligned data is linked
829 into L1 data memory. (less latency) 829 into L1 data memory. (less latency)
diff --git a/arch/blackfin/configs/BF527-EZKIT_defconfig b/arch/blackfin/configs/BF527-EZKIT_defconfig
index 9ccc18a6b4df..90b175323644 100644
--- a/arch/blackfin/configs/BF527-EZKIT_defconfig
+++ b/arch/blackfin/configs/BF527-EZKIT_defconfig
@@ -147,6 +147,7 @@ CONFIG_USB_OTG_BLACKLIST_HUB=y
147CONFIG_USB_MON=y 147CONFIG_USB_MON=y
148CONFIG_USB_MUSB_HDRC=y 148CONFIG_USB_MUSB_HDRC=y
149CONFIG_USB_MUSB_BLACKFIN=y 149CONFIG_USB_MUSB_BLACKFIN=y
150CONFIG_MUSB_PIO_ONLY=y
150CONFIG_USB_STORAGE=y 151CONFIG_USB_STORAGE=y
151CONFIG_USB_GADGET=y 152CONFIG_USB_GADGET=y
152CONFIG_RTC_CLASS=y 153CONFIG_RTC_CLASS=y
diff --git a/arch/blackfin/include/asm/cmpxchg.h b/arch/blackfin/include/asm/cmpxchg.h
index ba2484f4cb2a..c05868cc61c1 100644
--- a/arch/blackfin/include/asm/cmpxchg.h
+++ b/arch/blackfin/include/asm/cmpxchg.h
@@ -122,7 +122,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr,
122 (unsigned long)(n), sizeof(*(ptr)))) 122 (unsigned long)(n), sizeof(*(ptr))))
123#define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n)) 123#define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
124 124
125#include <asm-generic/cmpxchg.h> 125#define cmpxchg(ptr, o, n) cmpxchg_local((ptr), (o), (n))
126#define cmpxchg64(ptr, o, n) cmpxchg64_local((ptr), (o), (n))
126 127
127#endif /* !CONFIG_SMP */ 128#endif /* !CONFIG_SMP */
128 129
diff --git a/arch/blackfin/include/asm/gpio.h b/arch/blackfin/include/asm/gpio.h
index 5a25856381ff..12d3571b5232 100644
--- a/arch/blackfin/include/asm/gpio.h
+++ b/arch/blackfin/include/asm/gpio.h
@@ -244,16 +244,26 @@ static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
244 return -EINVAL; 244 return -EINVAL;
245} 245}
246 246
247static inline int gpio_get_value(unsigned gpio) 247static inline int __gpio_get_value(unsigned gpio)
248{ 248{
249 return bfin_gpio_get_value(gpio); 249 return bfin_gpio_get_value(gpio);
250} 250}
251 251
252static inline void gpio_set_value(unsigned gpio, int value) 252static inline void __gpio_set_value(unsigned gpio, int value)
253{ 253{
254 return bfin_gpio_set_value(gpio, value); 254 return bfin_gpio_set_value(gpio, value);
255} 255}
256 256
257static inline int gpio_get_value(unsigned gpio)
258{
259 return __gpio_get_value(gpio);
260}
261
262static inline void gpio_set_value(unsigned gpio, int value)
263{
264 return __gpio_set_value(gpio, value);
265}
266
257static inline int gpio_to_irq(unsigned gpio) 267static inline int gpio_to_irq(unsigned gpio)
258{ 268{
259 if (likely(gpio < MAX_BLACKFIN_GPIOS)) 269 if (likely(gpio < MAX_BLACKFIN_GPIOS))
diff --git a/arch/blackfin/mach-bf538/boards/ezkit.c b/arch/blackfin/mach-bf538/boards/ezkit.c
index 1633a6f306c0..85038f54354d 100644
--- a/arch/blackfin/mach-bf538/boards/ezkit.c
+++ b/arch/blackfin/mach-bf538/boards/ezkit.c
@@ -38,7 +38,7 @@ static struct platform_device rtc_device = {
38 .name = "rtc-bfin", 38 .name = "rtc-bfin",
39 .id = -1, 39 .id = -1,
40}; 40};
41#endif 41#endif /* CONFIG_RTC_DRV_BFIN */
42 42
43#if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE) 43#if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE)
44#ifdef CONFIG_SERIAL_BFIN_UART0 44#ifdef CONFIG_SERIAL_BFIN_UART0
@@ -100,7 +100,7 @@ static struct platform_device bfin_uart0_device = {
100 .platform_data = &bfin_uart0_peripherals, /* Passed to driver */ 100 .platform_data = &bfin_uart0_peripherals, /* Passed to driver */
101 }, 101 },
102}; 102};
103#endif 103#endif /* CONFIG_SERIAL_BFIN_UART0 */
104#ifdef CONFIG_SERIAL_BFIN_UART1 104#ifdef CONFIG_SERIAL_BFIN_UART1
105static struct resource bfin_uart1_resources[] = { 105static struct resource bfin_uart1_resources[] = {
106 { 106 {
@@ -148,7 +148,7 @@ static struct platform_device bfin_uart1_device = {
148 .platform_data = &bfin_uart1_peripherals, /* Passed to driver */ 148 .platform_data = &bfin_uart1_peripherals, /* Passed to driver */
149 }, 149 },
150}; 150};
151#endif 151#endif /* CONFIG_SERIAL_BFIN_UART1 */
152#ifdef CONFIG_SERIAL_BFIN_UART2 152#ifdef CONFIG_SERIAL_BFIN_UART2
153static struct resource bfin_uart2_resources[] = { 153static struct resource bfin_uart2_resources[] = {
154 { 154 {
@@ -196,8 +196,8 @@ static struct platform_device bfin_uart2_device = {
196 .platform_data = &bfin_uart2_peripherals, /* Passed to driver */ 196 .platform_data = &bfin_uart2_peripherals, /* Passed to driver */
197 }, 197 },
198}; 198};
199#endif 199#endif /* CONFIG_SERIAL_BFIN_UART2 */
200#endif 200#endif /* CONFIG_SERIAL_BFIN */
201 201
202#if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE) 202#if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
203#ifdef CONFIG_BFIN_SIR0 203#ifdef CONFIG_BFIN_SIR0
@@ -224,7 +224,7 @@ static struct platform_device bfin_sir0_device = {
224 .num_resources = ARRAY_SIZE(bfin_sir0_resources), 224 .num_resources = ARRAY_SIZE(bfin_sir0_resources),
225 .resource = bfin_sir0_resources, 225 .resource = bfin_sir0_resources,
226}; 226};
227#endif 227#endif /* CONFIG_BFIN_SIR0 */
228#ifdef CONFIG_BFIN_SIR1 228#ifdef CONFIG_BFIN_SIR1
229static struct resource bfin_sir1_resources[] = { 229static struct resource bfin_sir1_resources[] = {
230 { 230 {
@@ -249,7 +249,7 @@ static struct platform_device bfin_sir1_device = {
249 .num_resources = ARRAY_SIZE(bfin_sir1_resources), 249 .num_resources = ARRAY_SIZE(bfin_sir1_resources),
250 .resource = bfin_sir1_resources, 250 .resource = bfin_sir1_resources,
251}; 251};
252#endif 252#endif /* CONFIG_BFIN_SIR1 */
253#ifdef CONFIG_BFIN_SIR2 253#ifdef CONFIG_BFIN_SIR2
254static struct resource bfin_sir2_resources[] = { 254static struct resource bfin_sir2_resources[] = {
255 { 255 {
@@ -274,8 +274,8 @@ static struct platform_device bfin_sir2_device = {
274 .num_resources = ARRAY_SIZE(bfin_sir2_resources), 274 .num_resources = ARRAY_SIZE(bfin_sir2_resources),
275 .resource = bfin_sir2_resources, 275 .resource = bfin_sir2_resources,
276}; 276};
277#endif 277#endif /* CONFIG_BFIN_SIR2 */
278#endif 278#endif /* CONFIG_BFIN_SIR */
279 279
280#if defined(CONFIG_SERIAL_BFIN_SPORT) || defined(CONFIG_SERIAL_BFIN_SPORT_MODULE) 280#if defined(CONFIG_SERIAL_BFIN_SPORT) || defined(CONFIG_SERIAL_BFIN_SPORT_MODULE)
281#ifdef CONFIG_SERIAL_BFIN_SPORT0_UART 281#ifdef CONFIG_SERIAL_BFIN_SPORT0_UART
@@ -311,7 +311,7 @@ static struct platform_device bfin_sport0_uart_device = {
311 .platform_data = &bfin_sport0_peripherals, /* Passed to driver */ 311 .platform_data = &bfin_sport0_peripherals, /* Passed to driver */
312 }, 312 },
313}; 313};
314#endif 314#endif /* CONFIG_SERIAL_BFIN_SPORT0_UART */
315#ifdef CONFIG_SERIAL_BFIN_SPORT1_UART 315#ifdef CONFIG_SERIAL_BFIN_SPORT1_UART
316static struct resource bfin_sport1_uart_resources[] = { 316static struct resource bfin_sport1_uart_resources[] = {
317 { 317 {
@@ -345,7 +345,7 @@ static struct platform_device bfin_sport1_uart_device = {
345 .platform_data = &bfin_sport1_peripherals, /* Passed to driver */ 345 .platform_data = &bfin_sport1_peripherals, /* Passed to driver */
346 }, 346 },
347}; 347};
348#endif 348#endif /* CONFIG_SERIAL_BFIN_SPORT1_UART */
349#ifdef CONFIG_SERIAL_BFIN_SPORT2_UART 349#ifdef CONFIG_SERIAL_BFIN_SPORT2_UART
350static struct resource bfin_sport2_uart_resources[] = { 350static struct resource bfin_sport2_uart_resources[] = {
351 { 351 {
@@ -379,7 +379,7 @@ static struct platform_device bfin_sport2_uart_device = {
379 .platform_data = &bfin_sport2_peripherals, /* Passed to driver */ 379 .platform_data = &bfin_sport2_peripherals, /* Passed to driver */
380 }, 380 },
381}; 381};
382#endif 382#endif /* CONFIG_SERIAL_BFIN_SPORT2_UART */
383#ifdef CONFIG_SERIAL_BFIN_SPORT3_UART 383#ifdef CONFIG_SERIAL_BFIN_SPORT3_UART
384static struct resource bfin_sport3_uart_resources[] = { 384static struct resource bfin_sport3_uart_resources[] = {
385 { 385 {
@@ -413,8 +413,8 @@ static struct platform_device bfin_sport3_uart_device = {
413 .platform_data = &bfin_sport3_peripherals, /* Passed to driver */ 413 .platform_data = &bfin_sport3_peripherals, /* Passed to driver */
414 }, 414 },
415}; 415};
416#endif 416#endif /* CONFIG_SERIAL_BFIN_SPORT3_UART */
417#endif 417#endif /* CONFIG_SERIAL_BFIN_SPORT */
418 418
419#if defined(CONFIG_CAN_BFIN) || defined(CONFIG_CAN_BFIN_MODULE) 419#if defined(CONFIG_CAN_BFIN) || defined(CONFIG_CAN_BFIN_MODULE)
420static unsigned short bfin_can_peripherals[] = { 420static unsigned short bfin_can_peripherals[] = {
@@ -452,7 +452,7 @@ static struct platform_device bfin_can_device = {
452 .platform_data = &bfin_can_peripherals, /* Passed to driver */ 452 .platform_data = &bfin_can_peripherals, /* Passed to driver */
453 }, 453 },
454}; 454};
455#endif 455#endif /* CONFIG_CAN_BFIN */
456 456
457/* 457/*
458 * USB-LAN EzExtender board 458 * USB-LAN EzExtender board
@@ -488,7 +488,7 @@ static struct platform_device smc91x_device = {
488 .platform_data = &smc91x_info, 488 .platform_data = &smc91x_info,
489 }, 489 },
490}; 490};
491#endif 491#endif /* CONFIG_SMC91X */
492 492
493#if defined(CONFIG_SPI_BFIN5XX) || defined(CONFIG_SPI_BFIN5XX_MODULE) 493#if defined(CONFIG_SPI_BFIN5XX) || defined(CONFIG_SPI_BFIN5XX_MODULE)
494/* all SPI peripherals info goes here */ 494/* all SPI peripherals info goes here */
@@ -518,7 +518,8 @@ static struct flash_platform_data bfin_spi_flash_data = {
518static struct bfin5xx_spi_chip spi_flash_chip_info = { 518static struct bfin5xx_spi_chip spi_flash_chip_info = {
519 .enable_dma = 0, /* use dma transfer with this chip*/ 519 .enable_dma = 0, /* use dma transfer with this chip*/
520}; 520};
521#endif 521#endif /* CONFIG_MTD_M25P80 */
522#endif /* CONFIG_SPI_BFIN5XX */
522 523
523#if defined(CONFIG_TOUCHSCREEN_AD7879) || defined(CONFIG_TOUCHSCREEN_AD7879_MODULE) 524#if defined(CONFIG_TOUCHSCREEN_AD7879) || defined(CONFIG_TOUCHSCREEN_AD7879_MODULE)
524#include <linux/spi/ad7879.h> 525#include <linux/spi/ad7879.h>
@@ -535,7 +536,7 @@ static const struct ad7879_platform_data bfin_ad7879_ts_info = {
535 .gpio_export = 1, /* Export GPIO to gpiolib */ 536 .gpio_export = 1, /* Export GPIO to gpiolib */
536 .gpio_base = -1, /* Dynamic allocation */ 537 .gpio_base = -1, /* Dynamic allocation */
537}; 538};
538#endif 539#endif /* CONFIG_TOUCHSCREEN_AD7879 */
539 540
540#if defined(CONFIG_FB_BFIN_LQ035Q1) || defined(CONFIG_FB_BFIN_LQ035Q1_MODULE) 541#if defined(CONFIG_FB_BFIN_LQ035Q1) || defined(CONFIG_FB_BFIN_LQ035Q1_MODULE)
541#include <asm/bfin-lq035q1.h> 542#include <asm/bfin-lq035q1.h>
@@ -564,7 +565,7 @@ static struct platform_device bfin_lq035q1_device = {
564 .platform_data = &bfin_lq035q1_data, 565 .platform_data = &bfin_lq035q1_data,
565 }, 566 },
566}; 567};
567#endif 568#endif /* CONFIG_FB_BFIN_LQ035Q1 */
568 569
569static struct spi_board_info bf538_spi_board_info[] __initdata = { 570static struct spi_board_info bf538_spi_board_info[] __initdata = {
570#if defined(CONFIG_MTD_M25P80) \ 571#if defined(CONFIG_MTD_M25P80) \
@@ -579,7 +580,7 @@ static struct spi_board_info bf538_spi_board_info[] __initdata = {
579 .controller_data = &spi_flash_chip_info, 580 .controller_data = &spi_flash_chip_info,
580 .mode = SPI_MODE_3, 581 .mode = SPI_MODE_3,
581 }, 582 },
582#endif 583#endif /* CONFIG_MTD_M25P80 */
583#if defined(CONFIG_TOUCHSCREEN_AD7879_SPI) || defined(CONFIG_TOUCHSCREEN_AD7879_SPI_MODULE) 584#if defined(CONFIG_TOUCHSCREEN_AD7879_SPI) || defined(CONFIG_TOUCHSCREEN_AD7879_SPI_MODULE)
584 { 585 {
585 .modalias = "ad7879", 586 .modalias = "ad7879",
@@ -590,7 +591,7 @@ static struct spi_board_info bf538_spi_board_info[] __initdata = {
590 .chip_select = 1, 591 .chip_select = 1,
591 .mode = SPI_CPHA | SPI_CPOL, 592 .mode = SPI_CPHA | SPI_CPOL,
592 }, 593 },
593#endif 594#endif /* CONFIG_TOUCHSCREEN_AD7879_SPI */
594#if defined(CONFIG_FB_BFIN_LQ035Q1) || defined(CONFIG_FB_BFIN_LQ035Q1_MODULE) 595#if defined(CONFIG_FB_BFIN_LQ035Q1) || defined(CONFIG_FB_BFIN_LQ035Q1_MODULE)
595 { 596 {
596 .modalias = "bfin-lq035q1-spi", 597 .modalias = "bfin-lq035q1-spi",
@@ -599,7 +600,7 @@ static struct spi_board_info bf538_spi_board_info[] __initdata = {
599 .chip_select = 2, 600 .chip_select = 2,
600 .mode = SPI_CPHA | SPI_CPOL, 601 .mode = SPI_CPHA | SPI_CPOL,
601 }, 602 },
602#endif 603#endif /* CONFIG_FB_BFIN_LQ035Q1 */
603#if defined(CONFIG_SPI_SPIDEV) || defined(CONFIG_SPI_SPIDEV_MODULE) 604#if defined(CONFIG_SPI_SPIDEV) || defined(CONFIG_SPI_SPIDEV_MODULE)
604 { 605 {
605 .modalias = "spidev", 606 .modalias = "spidev",
@@ -607,7 +608,7 @@ static struct spi_board_info bf538_spi_board_info[] __initdata = {
607 .bus_num = 0, 608 .bus_num = 0,
608 .chip_select = 1, 609 .chip_select = 1,
609 }, 610 },
610#endif 611#endif /* CONFIG_SPI_SPIDEV */
611}; 612};
612 613
613/* SPI (0) */ 614/* SPI (0) */
@@ -716,8 +717,6 @@ static struct platform_device bf538_spi_master2 = {
716 }, 717 },
717}; 718};
718 719
719#endif /* spi master and devices */
720
721#if defined(CONFIG_I2C_BLACKFIN_TWI) || defined(CONFIG_I2C_BLACKFIN_TWI_MODULE) 720#if defined(CONFIG_I2C_BLACKFIN_TWI) || defined(CONFIG_I2C_BLACKFIN_TWI_MODULE)
722static struct resource bfin_twi0_resource[] = { 721static struct resource bfin_twi0_resource[] = {
723 [0] = { 722 [0] = {
@@ -759,8 +758,8 @@ static struct platform_device i2c_bfin_twi1_device = {
759 .num_resources = ARRAY_SIZE(bfin_twi1_resource), 758 .num_resources = ARRAY_SIZE(bfin_twi1_resource),
760 .resource = bfin_twi1_resource, 759 .resource = bfin_twi1_resource,
761}; 760};
762#endif 761#endif /* CONFIG_BF542 */
763#endif 762#endif /* CONFIG_I2C_BLACKFIN_TWI */
764 763
765#if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE) 764#if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
766#include <linux/gpio_keys.h> 765#include <linux/gpio_keys.h>
diff --git a/arch/c6x/include/asm/irq.h b/arch/c6x/include/asm/irq.h
index f13b78d5e1ca..ab4577f93d96 100644
--- a/arch/c6x/include/asm/irq.h
+++ b/arch/c6x/include/asm/irq.h
@@ -42,10 +42,6 @@
42/* This number is used when no interrupt has been assigned */ 42/* This number is used when no interrupt has been assigned */
43#define NO_IRQ 0 43#define NO_IRQ 0
44 44
45struct irq_data;
46extern irq_hw_number_t irqd_to_hwirq(struct irq_data *d);
47extern irq_hw_number_t virq_to_hw(unsigned int virq);
48
49extern void __init init_pic_c64xplus(void); 45extern void __init init_pic_c64xplus(void);
50 46
51extern void init_IRQ(void); 47extern void init_IRQ(void);
diff --git a/arch/c6x/kernel/irq.c b/arch/c6x/kernel/irq.c
index 65b8ddf54b44..c90fb5e82ad7 100644
--- a/arch/c6x/kernel/irq.c
+++ b/arch/c6x/kernel/irq.c
@@ -130,16 +130,3 @@ int arch_show_interrupts(struct seq_file *p, int prec)
130 seq_printf(p, "%*s: %10lu\n", prec, "Err", irq_err_count); 130 seq_printf(p, "%*s: %10lu\n", prec, "Err", irq_err_count);
131 return 0; 131 return 0;
132} 132}
133
134irq_hw_number_t irqd_to_hwirq(struct irq_data *d)
135{
136 return d->hwirq;
137}
138EXPORT_SYMBOL_GPL(irqd_to_hwirq);
139
140irq_hw_number_t virq_to_hw(unsigned int virq)
141{
142 struct irq_data *irq_data = irq_get_irq_data(virq);
143 return WARN_ON(!irq_data) ? 0 : irq_data->hwirq;
144}
145EXPORT_SYMBOL_GPL(virq_to_hw);
diff --git a/arch/c6x/kernel/signal.c b/arch/c6x/kernel/signal.c
index 304f675826e9..3b5a05099989 100644
--- a/arch/c6x/kernel/signal.c
+++ b/arch/c6x/kernel/signal.c
@@ -85,10 +85,7 @@ asmlinkage int do_rt_sigreturn(struct pt_regs *regs)
85 goto badframe; 85 goto badframe;
86 86
87 sigdelsetmask(&set, ~_BLOCKABLE); 87 sigdelsetmask(&set, ~_BLOCKABLE);
88 spin_lock_irq(&current->sighand->siglock); 88 set_current_blocked(&set);
89 current->blocked = set;
90 recalc_sigpending();
91 spin_unlock_irq(&current->sighand->siglock);
92 89
93 if (restore_sigcontext(regs, &frame->uc.uc_mcontext)) 90 if (restore_sigcontext(regs, &frame->uc.uc_mcontext))
94 goto badframe; 91 goto badframe;
@@ -279,15 +276,8 @@ static int handle_signal(int sig,
279 276
280 /* Set up the stack frame */ 277 /* Set up the stack frame */
281 ret = setup_rt_frame(sig, ka, info, oldset, regs); 278 ret = setup_rt_frame(sig, ka, info, oldset, regs);
282 if (ret == 0) { 279 if (ret == 0)
283 spin_lock_irq(&current->sighand->siglock); 280 block_sigmask(ka, sig);
284 sigorsets(&current->blocked, &current->blocked,
285 &ka->sa.sa_mask);
286 if (!(ka->sa.sa_flags & SA_NODEFER))
287 sigaddset(&current->blocked, sig);
288 recalc_sigpending();
289 spin_unlock_irq(&current->sighand->siglock);
290 }
291 281
292 return ret; 282 return ret;
293} 283}
diff --git a/arch/frv/mb93090-mb00/pci-dma.c b/arch/frv/mb93090-mb00/pci-dma.c
index 41098a3803a2..4f8d8bcdc7de 100644
--- a/arch/frv/mb93090-mb00/pci-dma.c
+++ b/arch/frv/mb93090-mb00/pci-dma.c
@@ -13,6 +13,7 @@
13#include <linux/dma-mapping.h> 13#include <linux/dma-mapping.h>
14#include <linux/list.h> 14#include <linux/list.h>
15#include <linux/pci.h> 15#include <linux/pci.h>
16#include <linux/export.h>
16#include <linux/highmem.h> 17#include <linux/highmem.h>
17#include <linux/scatterlist.h> 18#include <linux/scatterlist.h>
18#include <asm/io.h> 19#include <asm/io.h>
diff --git a/arch/hexagon/include/asm/dma-mapping.h b/arch/hexagon/include/asm/dma-mapping.h
index 448b224ba4ef..233ed3d2d25e 100644
--- a/arch/hexagon/include/asm/dma-mapping.h
+++ b/arch/hexagon/include/asm/dma-mapping.h
@@ -71,29 +71,35 @@ static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
71 return (dma_addr == bad_dma_address); 71 return (dma_addr == bad_dma_address);
72} 72}
73 73
74static inline void *dma_alloc_coherent(struct device *dev, size_t size, 74#define dma_alloc_coherent(d,s,h,f) dma_alloc_attrs(d,s,h,f,NULL)
75 dma_addr_t *dma_handle, gfp_t flag) 75
76static inline void *dma_alloc_attrs(struct device *dev, size_t size,
77 dma_addr_t *dma_handle, gfp_t flag,
78 struct dma_attrs *attrs)
76{ 79{
77 void *ret; 80 void *ret;
78 struct dma_map_ops *ops = get_dma_ops(dev); 81 struct dma_map_ops *ops = get_dma_ops(dev);
79 82
80 BUG_ON(!dma_ops); 83 BUG_ON(!dma_ops);
81 84
82 ret = ops->alloc_coherent(dev, size, dma_handle, flag); 85 ret = ops->alloc(dev, size, dma_handle, flag, attrs);
83 86
84 debug_dma_alloc_coherent(dev, size, *dma_handle, ret); 87 debug_dma_alloc_coherent(dev, size, *dma_handle, ret);
85 88
86 return ret; 89 return ret;
87} 90}
88 91
89static inline void dma_free_coherent(struct device *dev, size_t size, 92#define dma_free_coherent(d,s,c,h) dma_free_attrs(d,s,c,h,NULL)
90 void *cpu_addr, dma_addr_t dma_handle) 93
94static inline void dma_free_attrs(struct device *dev, size_t size,
95 void *cpu_addr, dma_addr_t dma_handle,
96 struct dma_attrs *attrs)
91{ 97{
92 struct dma_map_ops *dma_ops = get_dma_ops(dev); 98 struct dma_map_ops *dma_ops = get_dma_ops(dev);
93 99
94 BUG_ON(!dma_ops); 100 BUG_ON(!dma_ops);
95 101
96 dma_ops->free_coherent(dev, size, cpu_addr, dma_handle); 102 dma_ops->free(dev, size, cpu_addr, dma_handle, attrs);
97 103
98 debug_dma_free_coherent(dev, size, cpu_addr, dma_handle); 104 debug_dma_free_coherent(dev, size, cpu_addr, dma_handle);
99} 105}
diff --git a/arch/hexagon/kernel/dma.c b/arch/hexagon/kernel/dma.c
index e711ace62fdf..0f2367cc5493 100644
--- a/arch/hexagon/kernel/dma.c
+++ b/arch/hexagon/kernel/dma.c
@@ -22,6 +22,7 @@
22#include <linux/bootmem.h> 22#include <linux/bootmem.h>
23#include <linux/genalloc.h> 23#include <linux/genalloc.h>
24#include <asm/dma-mapping.h> 24#include <asm/dma-mapping.h>
25#include <linux/module.h>
25 26
26struct dma_map_ops *dma_ops; 27struct dma_map_ops *dma_ops;
27EXPORT_SYMBOL(dma_ops); 28EXPORT_SYMBOL(dma_ops);
@@ -54,7 +55,8 @@ static struct gen_pool *coherent_pool;
54/* Allocates from a pool of uncached memory that was reserved at boot time */ 55/* Allocates from a pool of uncached memory that was reserved at boot time */
55 56
56void *hexagon_dma_alloc_coherent(struct device *dev, size_t size, 57void *hexagon_dma_alloc_coherent(struct device *dev, size_t size,
57 dma_addr_t *dma_addr, gfp_t flag) 58 dma_addr_t *dma_addr, gfp_t flag,
59 struct dma_attrs *attrs)
58{ 60{
59 void *ret; 61 void *ret;
60 62
@@ -81,7 +83,7 @@ void *hexagon_dma_alloc_coherent(struct device *dev, size_t size,
81} 83}
82 84
83static void hexagon_free_coherent(struct device *dev, size_t size, void *vaddr, 85static void hexagon_free_coherent(struct device *dev, size_t size, void *vaddr,
84 dma_addr_t dma_addr) 86 dma_addr_t dma_addr, struct dma_attrs *attrs)
85{ 87{
86 gen_pool_free(coherent_pool, (unsigned long) vaddr, size); 88 gen_pool_free(coherent_pool, (unsigned long) vaddr, size);
87} 89}
@@ -202,8 +204,8 @@ static void hexagon_sync_single_for_device(struct device *dev,
202} 204}
203 205
204struct dma_map_ops hexagon_dma_ops = { 206struct dma_map_ops hexagon_dma_ops = {
205 .alloc_coherent = hexagon_dma_alloc_coherent, 207 .alloc = hexagon_dma_alloc_coherent,
206 .free_coherent = hexagon_free_coherent, 208 .free = hexagon_free_coherent,
207 .map_sg = hexagon_map_sg, 209 .map_sg = hexagon_map_sg,
208 .map_page = hexagon_map_page, 210 .map_page = hexagon_map_page,
209 .sync_single_for_cpu = hexagon_sync_single_for_cpu, 211 .sync_single_for_cpu = hexagon_sync_single_for_cpu,
diff --git a/arch/hexagon/kernel/process.c b/arch/hexagon/kernel/process.c
index 18c4f0b0f4ba..ff02821bfb7e 100644
--- a/arch/hexagon/kernel/process.c
+++ b/arch/hexagon/kernel/process.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Process creation support for Hexagon 2 * Process creation support for Hexagon
3 * 3 *
4 * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved. 4 * Copyright (c) 2010-2012, Code Aurora Forum. All rights reserved.
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 and 7 * it under the terms of the GNU General Public License version 2 and
@@ -88,7 +88,7 @@ void (*idle_sleep)(void) = default_idle;
88void cpu_idle(void) 88void cpu_idle(void)
89{ 89{
90 while (1) { 90 while (1) {
91 tick_nohz_stop_sched_tick(1); 91 tick_nohz_idle_enter();
92 local_irq_disable(); 92 local_irq_disable();
93 while (!need_resched()) { 93 while (!need_resched()) {
94 idle_sleep(); 94 idle_sleep();
@@ -97,7 +97,7 @@ void cpu_idle(void)
97 local_irq_disable(); 97 local_irq_disable();
98 } 98 }
99 local_irq_enable(); 99 local_irq_enable();
100 tick_nohz_restart_sched_tick(); 100 tick_nohz_idle_exit();
101 schedule(); 101 schedule();
102 } 102 }
103} 103}
diff --git a/arch/hexagon/kernel/ptrace.c b/arch/hexagon/kernel/ptrace.c
index 32342de1a79c..96c3b2c4dbad 100644
--- a/arch/hexagon/kernel/ptrace.c
+++ b/arch/hexagon/kernel/ptrace.c
@@ -28,6 +28,7 @@
28#include <linux/ptrace.h> 28#include <linux/ptrace.h>
29#include <linux/regset.h> 29#include <linux/regset.h>
30#include <linux/user.h> 30#include <linux/user.h>
31#include <linux/elf.h>
31 32
32#include <asm/user.h> 33#include <asm/user.h>
33 34
diff --git a/arch/hexagon/kernel/smp.c b/arch/hexagon/kernel/smp.c
index 15d1fd22bbc5..1298141874a3 100644
--- a/arch/hexagon/kernel/smp.c
+++ b/arch/hexagon/kernel/smp.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * SMP support for Hexagon 2 * SMP support for Hexagon
3 * 3 *
4 * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved. 4 * Copyright (c) 2010-2012, Code Aurora Forum. All rights reserved.
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 and 7 * it under the terms of the GNU General Public License version 2 and
@@ -28,6 +28,7 @@
28#include <linux/sched.h> 28#include <linux/sched.h>
29#include <linux/smp.h> 29#include <linux/smp.h>
30#include <linux/spinlock.h> 30#include <linux/spinlock.h>
31#include <linux/cpu.h>
31 32
32#include <asm/time.h> /* timer_interrupt */ 33#include <asm/time.h> /* timer_interrupt */
33#include <asm/hexagon_vm.h> 34#include <asm/hexagon_vm.h>
@@ -35,7 +36,7 @@
35#define BASE_IPI_IRQ 26 36#define BASE_IPI_IRQ 26
36 37
37/* 38/*
38 * cpu_possible_map needs to be filled out prior to setup_per_cpu_areas 39 * cpu_possible_mask needs to be filled out prior to setup_per_cpu_areas
39 * (which is prior to any of our smp_prepare_cpu crap), in order to set 40 * (which is prior to any of our smp_prepare_cpu crap), in order to set
40 * up the... per_cpu areas. 41 * up the... per_cpu areas.
41 */ 42 */
@@ -177,7 +178,12 @@ void __cpuinit start_secondary(void)
177 178
178 printk(KERN_INFO "%s cpu %d\n", __func__, current_thread_info()->cpu); 179 printk(KERN_INFO "%s cpu %d\n", __func__, current_thread_info()->cpu);
179 180
181 notify_cpu_starting(cpu);
182
183 ipi_call_lock();
180 set_cpu_online(cpu, true); 184 set_cpu_online(cpu, true);
185 ipi_call_unlock();
186
181 local_irq_enable(); 187 local_irq_enable();
182 188
183 cpu_idle(); 189 cpu_idle();
@@ -208,7 +214,7 @@ int __cpuinit __cpu_up(unsigned int cpu)
208 stack_start = ((void *) thread) + THREAD_SIZE; 214 stack_start = ((void *) thread) + THREAD_SIZE;
209 __vmstart(start_secondary, stack_start); 215 __vmstart(start_secondary, stack_start);
210 216
211 while (!cpu_isset(cpu, cpu_online_map)) 217 while (!cpu_online(cpu))
212 barrier(); 218 barrier();
213 219
214 return 0; 220 return 0;
@@ -229,7 +235,7 @@ void __init smp_prepare_cpus(unsigned int max_cpus)
229 235
230 /* Right now, let's just fake it. */ 236 /* Right now, let's just fake it. */
231 for (i = 0; i < max_cpus; i++) 237 for (i = 0; i < max_cpus; i++)
232 cpu_set(i, cpu_present_map); 238 set_cpu_present(i, true);
233 239
234 /* Also need to register the interrupts for IPI */ 240 /* Also need to register the interrupts for IPI */
235 if (max_cpus > 1) 241 if (max_cpus > 1)
@@ -269,5 +275,5 @@ void smp_start_cpus(void)
269 int i; 275 int i;
270 276
271 for (i = 0; i < NR_CPUS; i++) 277 for (i = 0; i < NR_CPUS; i++)
272 cpu_set(i, cpu_possible_map); 278 set_cpu_possible(i, true);
273} 279}
diff --git a/arch/hexagon/kernel/time.c b/arch/hexagon/kernel/time.c
index 6bee15c9c113..5d9b33b67935 100644
--- a/arch/hexagon/kernel/time.c
+++ b/arch/hexagon/kernel/time.c
@@ -28,6 +28,7 @@
28#include <linux/of.h> 28#include <linux/of.h>
29#include <linux/of_address.h> 29#include <linux/of_address.h>
30#include <linux/of_irq.h> 30#include <linux/of_irq.h>
31#include <linux/module.h>
31 32
32#include <asm/timer-regs.h> 33#include <asm/timer-regs.h>
33#include <asm/hexagon_vm.h> 34#include <asm/hexagon_vm.h>
diff --git a/arch/hexagon/kernel/vdso.c b/arch/hexagon/kernel/vdso.c
index f212a453b527..5d39f42f7085 100644
--- a/arch/hexagon/kernel/vdso.c
+++ b/arch/hexagon/kernel/vdso.c
@@ -21,6 +21,7 @@
21#include <linux/err.h> 21#include <linux/err.h>
22#include <linux/mm.h> 22#include <linux/mm.h>
23#include <linux/vmalloc.h> 23#include <linux/vmalloc.h>
24#include <linux/binfmts.h>
24 25
25#include <asm/vdso.h> 26#include <asm/vdso.h>
26 27
diff --git a/arch/ia64/hp/common/sba_iommu.c b/arch/ia64/hp/common/sba_iommu.c
index f6ea3a3b4a84..bcda5b2d121a 100644
--- a/arch/ia64/hp/common/sba_iommu.c
+++ b/arch/ia64/hp/common/sba_iommu.c
@@ -1129,7 +1129,8 @@ void sba_unmap_single_attrs(struct device *dev, dma_addr_t iova, size_t size,
1129 * See Documentation/DMA-API-HOWTO.txt 1129 * See Documentation/DMA-API-HOWTO.txt
1130 */ 1130 */
1131static void * 1131static void *
1132sba_alloc_coherent (struct device *dev, size_t size, dma_addr_t *dma_handle, gfp_t flags) 1132sba_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
1133 gfp_t flags, struct dma_attrs *attrs)
1133{ 1134{
1134 struct ioc *ioc; 1135 struct ioc *ioc;
1135 void *addr; 1136 void *addr;
@@ -1191,8 +1192,8 @@ sba_alloc_coherent (struct device *dev, size_t size, dma_addr_t *dma_handle, gfp
1191 * 1192 *
1192 * See Documentation/DMA-API-HOWTO.txt 1193 * See Documentation/DMA-API-HOWTO.txt
1193 */ 1194 */
1194static void sba_free_coherent (struct device *dev, size_t size, void *vaddr, 1195static void sba_free_coherent(struct device *dev, size_t size, void *vaddr,
1195 dma_addr_t dma_handle) 1196 dma_addr_t dma_handle, struct dma_attrs *attrs)
1196{ 1197{
1197 sba_unmap_single_attrs(dev, dma_handle, size, 0, NULL); 1198 sba_unmap_single_attrs(dev, dma_handle, size, 0, NULL);
1198 free_pages((unsigned long) vaddr, get_order(size)); 1199 free_pages((unsigned long) vaddr, get_order(size));
@@ -2212,8 +2213,8 @@ sba_page_override(char *str)
2212__setup("sbapagesize=",sba_page_override); 2213__setup("sbapagesize=",sba_page_override);
2213 2214
2214struct dma_map_ops sba_dma_ops = { 2215struct dma_map_ops sba_dma_ops = {
2215 .alloc_coherent = sba_alloc_coherent, 2216 .alloc = sba_alloc_coherent,
2216 .free_coherent = sba_free_coherent, 2217 .free = sba_free_coherent,
2217 .map_page = sba_map_page, 2218 .map_page = sba_map_page,
2218 .unmap_page = sba_unmap_page, 2219 .unmap_page = sba_unmap_page,
2219 .map_sg = sba_map_sg_attrs, 2220 .map_sg = sba_map_sg_attrs,
diff --git a/arch/ia64/include/asm/cmpxchg.h b/arch/ia64/include/asm/cmpxchg.h
index 4c96187e2049..4f37dbbb8640 100644
--- a/arch/ia64/include/asm/cmpxchg.h
+++ b/arch/ia64/include/asm/cmpxchg.h
@@ -1 +1,147 @@
1#include <asm/intrinsics.h> 1#ifndef _ASM_IA64_CMPXCHG_H
2#define _ASM_IA64_CMPXCHG_H
3
4/*
5 * Compare/Exchange, forked from asm/intrinsics.h
6 * which was:
7 *
8 * Copyright (C) 2002-2003 Hewlett-Packard Co
9 * David Mosberger-Tang <davidm@hpl.hp.com>
10 */
11
12#ifndef __ASSEMBLY__
13
14#include <linux/types.h>
15/* include compiler specific intrinsics */
16#include <asm/ia64regs.h>
17#ifdef __INTEL_COMPILER
18# include <asm/intel_intrin.h>
19#else
20# include <asm/gcc_intrin.h>
21#endif
22
23/*
24 * This function doesn't exist, so you'll get a linker error if
25 * something tries to do an invalid xchg().
26 */
27extern void ia64_xchg_called_with_bad_pointer(void);
28
29#define __xchg(x, ptr, size) \
30({ \
31 unsigned long __xchg_result; \
32 \
33 switch (size) { \
34 case 1: \
35 __xchg_result = ia64_xchg1((__u8 *)ptr, x); \
36 break; \
37 \
38 case 2: \
39 __xchg_result = ia64_xchg2((__u16 *)ptr, x); \
40 break; \
41 \
42 case 4: \
43 __xchg_result = ia64_xchg4((__u32 *)ptr, x); \
44 break; \
45 \
46 case 8: \
47 __xchg_result = ia64_xchg8((__u64 *)ptr, x); \
48 break; \
49 default: \
50 ia64_xchg_called_with_bad_pointer(); \
51 } \
52 __xchg_result; \
53})
54
55#define xchg(ptr, x) \
56((__typeof__(*(ptr))) __xchg((unsigned long) (x), (ptr), sizeof(*(ptr))))
57
58/*
59 * Atomic compare and exchange. Compare OLD with MEM, if identical,
60 * store NEW in MEM. Return the initial value in MEM. Success is
61 * indicated by comparing RETURN with OLD.
62 */
63
64#define __HAVE_ARCH_CMPXCHG 1
65
66/*
67 * This function doesn't exist, so you'll get a linker error
68 * if something tries to do an invalid cmpxchg().
69 */
70extern long ia64_cmpxchg_called_with_bad_pointer(void);
71
72#define ia64_cmpxchg(sem, ptr, old, new, size) \
73({ \
74 __u64 _o_, _r_; \
75 \
76 switch (size) { \
77 case 1: \
78 _o_ = (__u8) (long) (old); \
79 break; \
80 case 2: \
81 _o_ = (__u16) (long) (old); \
82 break; \
83 case 4: \
84 _o_ = (__u32) (long) (old); \
85 break; \
86 case 8: \
87 _o_ = (__u64) (long) (old); \
88 break; \
89 default: \
90 break; \
91 } \
92 switch (size) { \
93 case 1: \
94 _r_ = ia64_cmpxchg1_##sem((__u8 *) ptr, new, _o_); \
95 break; \
96 \
97 case 2: \
98 _r_ = ia64_cmpxchg2_##sem((__u16 *) ptr, new, _o_); \
99 break; \
100 \
101 case 4: \
102 _r_ = ia64_cmpxchg4_##sem((__u32 *) ptr, new, _o_); \
103 break; \
104 \
105 case 8: \
106 _r_ = ia64_cmpxchg8_##sem((__u64 *) ptr, new, _o_); \
107 break; \
108 \
109 default: \
110 _r_ = ia64_cmpxchg_called_with_bad_pointer(); \
111 break; \
112 } \
113 (__typeof__(old)) _r_; \
114})
115
116#define cmpxchg_acq(ptr, o, n) \
117 ia64_cmpxchg(acq, (ptr), (o), (n), sizeof(*(ptr)))
118#define cmpxchg_rel(ptr, o, n) \
119 ia64_cmpxchg(rel, (ptr), (o), (n), sizeof(*(ptr)))
120
121/* for compatibility with other platforms: */
122#define cmpxchg(ptr, o, n) cmpxchg_acq((ptr), (o), (n))
123#define cmpxchg64(ptr, o, n) cmpxchg_acq((ptr), (o), (n))
124
125#define cmpxchg_local cmpxchg
126#define cmpxchg64_local cmpxchg64
127
128#ifdef CONFIG_IA64_DEBUG_CMPXCHG
129# define CMPXCHG_BUGCHECK_DECL int _cmpxchg_bugcheck_count = 128;
130# define CMPXCHG_BUGCHECK(v) \
131do { \
132 if (_cmpxchg_bugcheck_count-- <= 0) { \
133 void *ip; \
134 extern int printk(const char *fmt, ...); \
135 ip = (void *) ia64_getreg(_IA64_REG_IP); \
136 printk("CMPXCHG_BUGCHECK: stuck at %p on word %p\n", ip, (v));\
137 break; \
138 } \
139} while (0)
140#else /* !CONFIG_IA64_DEBUG_CMPXCHG */
141# define CMPXCHG_BUGCHECK_DECL
142# define CMPXCHG_BUGCHECK(v)
143#endif /* !CONFIG_IA64_DEBUG_CMPXCHG */
144
145#endif /* !__ASSEMBLY__ */
146
147#endif /* _ASM_IA64_CMPXCHG_H */
diff --git a/arch/ia64/include/asm/dma-mapping.h b/arch/ia64/include/asm/dma-mapping.h
index 4336d080b241..4f5e8148440d 100644
--- a/arch/ia64/include/asm/dma-mapping.h
+++ b/arch/ia64/include/asm/dma-mapping.h
@@ -23,23 +23,29 @@ extern void machvec_dma_sync_single(struct device *, dma_addr_t, size_t,
23extern void machvec_dma_sync_sg(struct device *, struct scatterlist *, int, 23extern void machvec_dma_sync_sg(struct device *, struct scatterlist *, int,
24 enum dma_data_direction); 24 enum dma_data_direction);
25 25
26static inline void *dma_alloc_coherent(struct device *dev, size_t size, 26#define dma_alloc_coherent(d,s,h,f) dma_alloc_attrs(d,s,h,f,NULL)
27 dma_addr_t *daddr, gfp_t gfp) 27
28static inline void *dma_alloc_attrs(struct device *dev, size_t size,
29 dma_addr_t *daddr, gfp_t gfp,
30 struct dma_attrs *attrs)
28{ 31{
29 struct dma_map_ops *ops = platform_dma_get_ops(dev); 32 struct dma_map_ops *ops = platform_dma_get_ops(dev);
30 void *caddr; 33 void *caddr;
31 34
32 caddr = ops->alloc_coherent(dev, size, daddr, gfp); 35 caddr = ops->alloc(dev, size, daddr, gfp, attrs);
33 debug_dma_alloc_coherent(dev, size, *daddr, caddr); 36 debug_dma_alloc_coherent(dev, size, *daddr, caddr);
34 return caddr; 37 return caddr;
35} 38}
36 39
37static inline void dma_free_coherent(struct device *dev, size_t size, 40#define dma_free_coherent(d,s,c,h) dma_free_attrs(d,s,c,h,NULL)
38 void *caddr, dma_addr_t daddr) 41
42static inline void dma_free_attrs(struct device *dev, size_t size,
43 void *caddr, dma_addr_t daddr,
44 struct dma_attrs *attrs)
39{ 45{
40 struct dma_map_ops *ops = platform_dma_get_ops(dev); 46 struct dma_map_ops *ops = platform_dma_get_ops(dev);
41 debug_dma_free_coherent(dev, size, caddr, daddr); 47 debug_dma_free_coherent(dev, size, caddr, daddr);
42 ops->free_coherent(dev, size, caddr, daddr); 48 ops->free(dev, size, caddr, daddr, attrs);
43} 49}
44 50
45#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f) 51#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
diff --git a/arch/ia64/include/asm/futex.h b/arch/ia64/include/asm/futex.h
index 0ab82cc2dc8f..d2bf1fd5e44f 100644
--- a/arch/ia64/include/asm/futex.h
+++ b/arch/ia64/include/asm/futex.h
@@ -106,15 +106,16 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
106 return -EFAULT; 106 return -EFAULT;
107 107
108 { 108 {
109 register unsigned long r8 __asm ("r8") = 0; 109 register unsigned long r8 __asm ("r8");
110 unsigned long prev; 110 unsigned long prev;
111 __asm__ __volatile__( 111 __asm__ __volatile__(
112 " mf;; \n" 112 " mf;; \n"
113 " mov ar.ccv=%3;; \n" 113 " mov %0=r0 \n"
114 "[1:] cmpxchg4.acq %0=[%1],%2,ar.ccv \n" 114 " mov ar.ccv=%4;; \n"
115 "[1:] cmpxchg4.acq %1=[%2],%3,ar.ccv \n"
115 " .xdata4 \"__ex_table\", 1b-., 2f-. \n" 116 " .xdata4 \"__ex_table\", 1b-., 2f-. \n"
116 "[2:]" 117 "[2:]"
117 : "=r" (prev) 118 : "=r" (r8), "=r" (prev)
118 : "r" (uaddr), "r" (newval), 119 : "r" (uaddr), "r" (newval),
119 "rO" ((long) (unsigned) oldval) 120 "rO" ((long) (unsigned) oldval)
120 : "memory"); 121 : "memory");
diff --git a/arch/ia64/include/asm/intrinsics.h b/arch/ia64/include/asm/intrinsics.h
index e4076b511829..d129e367e764 100644
--- a/arch/ia64/include/asm/intrinsics.h
+++ b/arch/ia64/include/asm/intrinsics.h
@@ -18,6 +18,7 @@
18#else 18#else
19# include <asm/gcc_intrin.h> 19# include <asm/gcc_intrin.h>
20#endif 20#endif
21#include <asm/cmpxchg.h>
21 22
22#define ia64_native_get_psr_i() (ia64_native_getreg(_IA64_REG_PSR) & IA64_PSR_I) 23#define ia64_native_get_psr_i() (ia64_native_getreg(_IA64_REG_PSR) & IA64_PSR_I)
23 24
@@ -81,119 +82,6 @@ extern unsigned long __bad_increment_for_ia64_fetch_and_add (void);
81 82
82#define ia64_fetch_and_add(i,v) (ia64_fetchadd(i, v, rel) + (i)) /* return new value */ 83#define ia64_fetch_and_add(i,v) (ia64_fetchadd(i, v, rel) + (i)) /* return new value */
83 84
84/*
85 * This function doesn't exist, so you'll get a linker error if
86 * something tries to do an invalid xchg().
87 */
88extern void ia64_xchg_called_with_bad_pointer (void);
89
90#define __xchg(x,ptr,size) \
91({ \
92 unsigned long __xchg_result; \
93 \
94 switch (size) { \
95 case 1: \
96 __xchg_result = ia64_xchg1((__u8 *)ptr, x); \
97 break; \
98 \
99 case 2: \
100 __xchg_result = ia64_xchg2((__u16 *)ptr, x); \
101 break; \
102 \
103 case 4: \
104 __xchg_result = ia64_xchg4((__u32 *)ptr, x); \
105 break; \
106 \
107 case 8: \
108 __xchg_result = ia64_xchg8((__u64 *)ptr, x); \
109 break; \
110 default: \
111 ia64_xchg_called_with_bad_pointer(); \
112 } \
113 __xchg_result; \
114})
115
116#define xchg(ptr,x) \
117 ((__typeof__(*(ptr))) __xchg ((unsigned long) (x), (ptr), sizeof(*(ptr))))
118
119/*
120 * Atomic compare and exchange. Compare OLD with MEM, if identical,
121 * store NEW in MEM. Return the initial value in MEM. Success is
122 * indicated by comparing RETURN with OLD.
123 */
124
125#define __HAVE_ARCH_CMPXCHG 1
126
127/*
128 * This function doesn't exist, so you'll get a linker error
129 * if something tries to do an invalid cmpxchg().
130 */
131extern long ia64_cmpxchg_called_with_bad_pointer (void);
132
133#define ia64_cmpxchg(sem,ptr,old,new,size) \
134({ \
135 __u64 _o_, _r_; \
136 \
137 switch (size) { \
138 case 1: _o_ = (__u8 ) (long) (old); break; \
139 case 2: _o_ = (__u16) (long) (old); break; \
140 case 4: _o_ = (__u32) (long) (old); break; \
141 case 8: _o_ = (__u64) (long) (old); break; \
142 default: break; \
143 } \
144 switch (size) { \
145 case 1: \
146 _r_ = ia64_cmpxchg1_##sem((__u8 *) ptr, new, _o_); \
147 break; \
148 \
149 case 2: \
150 _r_ = ia64_cmpxchg2_##sem((__u16 *) ptr, new, _o_); \
151 break; \
152 \
153 case 4: \
154 _r_ = ia64_cmpxchg4_##sem((__u32 *) ptr, new, _o_); \
155 break; \
156 \
157 case 8: \
158 _r_ = ia64_cmpxchg8_##sem((__u64 *) ptr, new, _o_); \
159 break; \
160 \
161 default: \
162 _r_ = ia64_cmpxchg_called_with_bad_pointer(); \
163 break; \
164 } \
165 (__typeof__(old)) _r_; \
166})
167
168#define cmpxchg_acq(ptr, o, n) \
169 ia64_cmpxchg(acq, (ptr), (o), (n), sizeof(*(ptr)))
170#define cmpxchg_rel(ptr, o, n) \
171 ia64_cmpxchg(rel, (ptr), (o), (n), sizeof(*(ptr)))
172
173/* for compatibility with other platforms: */
174#define cmpxchg(ptr, o, n) cmpxchg_acq((ptr), (o), (n))
175#define cmpxchg64(ptr, o, n) cmpxchg_acq((ptr), (o), (n))
176
177#define cmpxchg_local cmpxchg
178#define cmpxchg64_local cmpxchg64
179
180#ifdef CONFIG_IA64_DEBUG_CMPXCHG
181# define CMPXCHG_BUGCHECK_DECL int _cmpxchg_bugcheck_count = 128;
182# define CMPXCHG_BUGCHECK(v) \
183 do { \
184 if (_cmpxchg_bugcheck_count-- <= 0) { \
185 void *ip; \
186 extern int printk(const char *fmt, ...); \
187 ip = (void *) ia64_getreg(_IA64_REG_IP); \
188 printk("CMPXCHG_BUGCHECK: stuck at %p on word %p\n", ip, (v)); \
189 break; \
190 } \
191 } while (0)
192#else /* !CONFIG_IA64_DEBUG_CMPXCHG */
193# define CMPXCHG_BUGCHECK_DECL
194# define CMPXCHG_BUGCHECK(v)
195#endif /* !CONFIG_IA64_DEBUG_CMPXCHG */
196
197#endif 85#endif
198 86
199#ifdef __KERNEL__ 87#ifdef __KERNEL__
diff --git a/arch/ia64/kernel/acpi.c b/arch/ia64/kernel/acpi.c
index ac795d311f44..6f38b6120d96 100644
--- a/arch/ia64/kernel/acpi.c
+++ b/arch/ia64/kernel/acpi.c
@@ -839,7 +839,7 @@ static __init int setup_additional_cpus(char *s)
839early_param("additional_cpus", setup_additional_cpus); 839early_param("additional_cpus", setup_additional_cpus);
840 840
841/* 841/*
842 * cpu_possible_map should be static, it cannot change as CPUs 842 * cpu_possible_mask should be static, it cannot change as CPUs
843 * are onlined, or offlined. The reason is per-cpu data-structures 843 * are onlined, or offlined. The reason is per-cpu data-structures
844 * are allocated by some modules at init time, and dont expect to 844 * are allocated by some modules at init time, and dont expect to
845 * do this dynamically on cpu arrival/departure. 845 * do this dynamically on cpu arrival/departure.
diff --git a/arch/ia64/kernel/pci-swiotlb.c b/arch/ia64/kernel/pci-swiotlb.c
index d9485d952ed0..939260aeac98 100644
--- a/arch/ia64/kernel/pci-swiotlb.c
+++ b/arch/ia64/kernel/pci-swiotlb.c
@@ -15,16 +15,24 @@ int swiotlb __read_mostly;
15EXPORT_SYMBOL(swiotlb); 15EXPORT_SYMBOL(swiotlb);
16 16
17static void *ia64_swiotlb_alloc_coherent(struct device *dev, size_t size, 17static void *ia64_swiotlb_alloc_coherent(struct device *dev, size_t size,
18 dma_addr_t *dma_handle, gfp_t gfp) 18 dma_addr_t *dma_handle, gfp_t gfp,
19 struct dma_attrs *attrs)
19{ 20{
20 if (dev->coherent_dma_mask != DMA_BIT_MASK(64)) 21 if (dev->coherent_dma_mask != DMA_BIT_MASK(64))
21 gfp |= GFP_DMA; 22 gfp |= GFP_DMA;
22 return swiotlb_alloc_coherent(dev, size, dma_handle, gfp); 23 return swiotlb_alloc_coherent(dev, size, dma_handle, gfp);
23} 24}
24 25
26static void ia64_swiotlb_free_coherent(struct device *dev, size_t size,
27 void *vaddr, dma_addr_t dma_addr,
28 struct dma_attrs *attrs)
29{
30 swiotlb_free_coherent(dev, size, vaddr, dma_addr);
31}
32
25struct dma_map_ops swiotlb_dma_ops = { 33struct dma_map_ops swiotlb_dma_ops = {
26 .alloc_coherent = ia64_swiotlb_alloc_coherent, 34 .alloc = ia64_swiotlb_alloc_coherent,
27 .free_coherent = swiotlb_free_coherent, 35 .free = ia64_swiotlb_free_coherent,
28 .map_page = swiotlb_map_page, 36 .map_page = swiotlb_map_page,
29 .unmap_page = swiotlb_unmap_page, 37 .unmap_page = swiotlb_unmap_page,
30 .map_sg = swiotlb_map_sg_attrs, 38 .map_sg = swiotlb_map_sg_attrs,
diff --git a/arch/ia64/kernel/perfmon.c b/arch/ia64/kernel/perfmon.c
index 9d0fd7d5bb82..f00ba025375d 100644
--- a/arch/ia64/kernel/perfmon.c
+++ b/arch/ia64/kernel/perfmon.c
@@ -604,12 +604,6 @@ pfm_unprotect_ctx_ctxsw(pfm_context_t *x, unsigned long f)
604 spin_unlock(&(x)->ctx_lock); 604 spin_unlock(&(x)->ctx_lock);
605} 605}
606 606
607static inline unsigned int
608pfm_do_munmap(struct mm_struct *mm, unsigned long addr, size_t len, int acct)
609{
610 return do_munmap(mm, addr, len);
611}
612
613static inline unsigned long 607static inline unsigned long
614pfm_get_unmapped_area(struct file *file, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags, unsigned long exec) 608pfm_get_unmapped_area(struct file *file, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags, unsigned long exec)
615{ 609{
@@ -1458,8 +1452,9 @@ pfm_unreserve_session(pfm_context_t *ctx, int is_syswide, unsigned int cpu)
1458 * a PROTECT_CTX() section. 1452 * a PROTECT_CTX() section.
1459 */ 1453 */
1460static int 1454static int
1461pfm_remove_smpl_mapping(struct task_struct *task, void *vaddr, unsigned long size) 1455pfm_remove_smpl_mapping(void *vaddr, unsigned long size)
1462{ 1456{
1457 struct task_struct *task = current;
1463 int r; 1458 int r;
1464 1459
1465 /* sanity checks */ 1460 /* sanity checks */
@@ -1473,13 +1468,8 @@ pfm_remove_smpl_mapping(struct task_struct *task, void *vaddr, unsigned long siz
1473 /* 1468 /*
1474 * does the actual unmapping 1469 * does the actual unmapping
1475 */ 1470 */
1476 down_write(&task->mm->mmap_sem); 1471 r = vm_munmap((unsigned long)vaddr, size);
1477 1472
1478 DPRINT(("down_write done smpl_vaddr=%p size=%lu\n", vaddr, size));
1479
1480 r = pfm_do_munmap(task->mm, (unsigned long)vaddr, size, 0);
1481
1482 up_write(&task->mm->mmap_sem);
1483 if (r !=0) { 1473 if (r !=0) {
1484 printk(KERN_ERR "perfmon: [%d] unable to unmap sampling buffer @%p size=%lu\n", task_pid_nr(task), vaddr, size); 1474 printk(KERN_ERR "perfmon: [%d] unable to unmap sampling buffer @%p size=%lu\n", task_pid_nr(task), vaddr, size);
1485 } 1475 }
@@ -1945,7 +1935,7 @@ pfm_flush(struct file *filp, fl_owner_t id)
1945 * because some VM function reenables interrupts. 1935 * because some VM function reenables interrupts.
1946 * 1936 *
1947 */ 1937 */
1948 if (smpl_buf_vaddr) pfm_remove_smpl_mapping(current, smpl_buf_vaddr, smpl_buf_size); 1938 if (smpl_buf_vaddr) pfm_remove_smpl_mapping(smpl_buf_vaddr, smpl_buf_size);
1949 1939
1950 return 0; 1940 return 0;
1951} 1941}
diff --git a/arch/ia64/kvm/kvm-ia64.c b/arch/ia64/kvm/kvm-ia64.c
index f5104b7c52cd..463fb3bbe11e 100644
--- a/arch/ia64/kvm/kvm-ia64.c
+++ b/arch/ia64/kvm/kvm-ia64.c
@@ -1174,7 +1174,7 @@ out:
1174 1174
1175bool kvm_vcpu_compatible(struct kvm_vcpu *vcpu) 1175bool kvm_vcpu_compatible(struct kvm_vcpu *vcpu)
1176{ 1176{
1177 return irqchip_in_kernel(vcpu->kcm) == (vcpu->arch.apic != NULL); 1177 return irqchip_in_kernel(vcpu->kvm) == (vcpu->arch.apic != NULL);
1178} 1178}
1179 1179
1180int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu) 1180int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu)
diff --git a/arch/ia64/sn/pci/pci_dma.c b/arch/ia64/sn/pci/pci_dma.c
index a9d310de57da..3290d6e00c31 100644
--- a/arch/ia64/sn/pci/pci_dma.c
+++ b/arch/ia64/sn/pci/pci_dma.c
@@ -76,7 +76,8 @@ EXPORT_SYMBOL(sn_dma_set_mask);
76 * more information. 76 * more information.
77 */ 77 */
78static void *sn_dma_alloc_coherent(struct device *dev, size_t size, 78static void *sn_dma_alloc_coherent(struct device *dev, size_t size,
79 dma_addr_t * dma_handle, gfp_t flags) 79 dma_addr_t * dma_handle, gfp_t flags,
80 struct dma_attrs *attrs)
80{ 81{
81 void *cpuaddr; 82 void *cpuaddr;
82 unsigned long phys_addr; 83 unsigned long phys_addr;
@@ -137,7 +138,7 @@ static void *sn_dma_alloc_coherent(struct device *dev, size_t size,
137 * any associated IOMMU mappings. 138 * any associated IOMMU mappings.
138 */ 139 */
139static void sn_dma_free_coherent(struct device *dev, size_t size, void *cpu_addr, 140static void sn_dma_free_coherent(struct device *dev, size_t size, void *cpu_addr,
140 dma_addr_t dma_handle) 141 dma_addr_t dma_handle, struct dma_attrs *attrs)
141{ 142{
142 struct pci_dev *pdev = to_pci_dev(dev); 143 struct pci_dev *pdev = to_pci_dev(dev);
143 struct sn_pcibus_provider *provider = SN_PCIDEV_BUSPROVIDER(pdev); 144 struct sn_pcibus_provider *provider = SN_PCIDEV_BUSPROVIDER(pdev);
@@ -466,8 +467,8 @@ int sn_pci_legacy_write(struct pci_bus *bus, u16 port, u32 val, u8 size)
466} 467}
467 468
468static struct dma_map_ops sn_dma_ops = { 469static struct dma_map_ops sn_dma_ops = {
469 .alloc_coherent = sn_dma_alloc_coherent, 470 .alloc = sn_dma_alloc_coherent,
470 .free_coherent = sn_dma_free_coherent, 471 .free = sn_dma_free_coherent,
471 .map_page = sn_dma_map_page, 472 .map_page = sn_dma_map_page,
472 .unmap_page = sn_dma_unmap_page, 473 .unmap_page = sn_dma_unmap_page,
473 .map_sg = sn_dma_map_sg, 474 .map_sg = sn_dma_map_sg,
diff --git a/arch/m68k/configs/m5275evb_defconfig b/arch/m68k/configs/m5275evb_defconfig
index 33c32aeca12b..a1230e82bb1e 100644
--- a/arch/m68k/configs/m5275evb_defconfig
+++ b/arch/m68k/configs/m5275evb_defconfig
@@ -49,7 +49,6 @@ CONFIG_BLK_DEV_RAM=y
49CONFIG_NETDEVICES=y 49CONFIG_NETDEVICES=y
50CONFIG_NET_ETHERNET=y 50CONFIG_NET_ETHERNET=y
51CONFIG_FEC=y 51CONFIG_FEC=y
52CONFIG_FEC2=y
53# CONFIG_NETDEV_1000 is not set 52# CONFIG_NETDEV_1000 is not set
54# CONFIG_NETDEV_10000 is not set 53# CONFIG_NETDEV_10000 is not set
55CONFIG_PPP=y 54CONFIG_PPP=y
diff --git a/arch/m68k/include/asm/atomic.h b/arch/m68k/include/asm/atomic.h
index 336e6173794f..f4e32de263a7 100644
--- a/arch/m68k/include/asm/atomic.h
+++ b/arch/m68k/include/asm/atomic.h
@@ -3,6 +3,7 @@
3 3
4#include <linux/types.h> 4#include <linux/types.h>
5#include <linux/irqflags.h> 5#include <linux/irqflags.h>
6#include <asm/cmpxchg.h>
6 7
7/* 8/*
8 * Atomic operations that C can't guarantee us. Useful for 9 * Atomic operations that C can't guarantee us. Useful for
diff --git a/arch/m68k/mac/config.c b/arch/m68k/mac/config.c
index 96fa6ed7e799..d9f62e0f46c0 100644
--- a/arch/m68k/mac/config.c
+++ b/arch/m68k/mac/config.c
@@ -980,6 +980,9 @@ int __init mac_platform_init(void)
980{ 980{
981 u8 *swim_base; 981 u8 *swim_base;
982 982
983 if (!MACH_IS_MAC)
984 return -ENODEV;
985
983 /* 986 /*
984 * Serial devices 987 * Serial devices
985 */ 988 */
diff --git a/arch/m68k/platform/520x/config.c b/arch/m68k/platform/520x/config.c
index 235947844f27..09df4b89e8be 100644
--- a/arch/m68k/platform/520x/config.c
+++ b/arch/m68k/platform/520x/config.c
@@ -22,7 +22,7 @@
22 22
23/***************************************************************************/ 23/***************************************************************************/
24 24
25#ifdef CONFIG_SPI_COLDFIRE_QSPI 25#if IS_ENABLED(CONFIG_SPI_COLDFIRE_QSPI)
26 26
27static void __init m520x_qspi_init(void) 27static void __init m520x_qspi_init(void)
28{ 28{
@@ -35,7 +35,7 @@ static void __init m520x_qspi_init(void)
35 writew(par, MCF_GPIO_PAR_UART); 35 writew(par, MCF_GPIO_PAR_UART);
36} 36}
37 37
38#endif /* CONFIG_SPI_COLDFIRE_QSPI */ 38#endif /* IS_ENABLED(CONFIG_SPI_COLDFIRE_QSPI) */
39 39
40/***************************************************************************/ 40/***************************************************************************/
41 41
@@ -79,7 +79,7 @@ void __init config_BSP(char *commandp, int size)
79 mach_sched_init = hw_timer_init; 79 mach_sched_init = hw_timer_init;
80 m520x_uarts_init(); 80 m520x_uarts_init();
81 m520x_fec_init(); 81 m520x_fec_init();
82#ifdef CONFIG_SPI_COLDFIRE_QSPI 82#if IS_ENABLED(CONFIG_SPI_COLDFIRE_QSPI)
83 m520x_qspi_init(); 83 m520x_qspi_init();
84#endif 84#endif
85} 85}
diff --git a/arch/m68k/platform/523x/config.c b/arch/m68k/platform/523x/config.c
index c8b405d5a961..d47dfd8f50a2 100644
--- a/arch/m68k/platform/523x/config.c
+++ b/arch/m68k/platform/523x/config.c
@@ -22,7 +22,7 @@
22 22
23/***************************************************************************/ 23/***************************************************************************/
24 24
25#ifdef CONFIG_SPI_COLDFIRE_QSPI 25#if IS_ENABLED(CONFIG_SPI_COLDFIRE_QSPI)
26 26
27static void __init m523x_qspi_init(void) 27static void __init m523x_qspi_init(void)
28{ 28{
@@ -36,7 +36,7 @@ static void __init m523x_qspi_init(void)
36 writew(par, MCFGPIO_PAR_TIMER); 36 writew(par, MCFGPIO_PAR_TIMER);
37} 37}
38 38
39#endif /* CONFIG_SPI_COLDFIRE_QSPI */ 39#endif /* IS_ENABLED(CONFIG_SPI_COLDFIRE_QSPI) */
40 40
41/***************************************************************************/ 41/***************************************************************************/
42 42
@@ -58,7 +58,7 @@ void __init config_BSP(char *commandp, int size)
58{ 58{
59 mach_sched_init = hw_timer_init; 59 mach_sched_init = hw_timer_init;
60 m523x_fec_init(); 60 m523x_fec_init();
61#ifdef CONFIG_SPI_COLDFIRE_QSPI 61#if IS_ENABLED(CONFIG_SPI_COLDFIRE_QSPI)
62 m523x_qspi_init(); 62 m523x_qspi_init();
63#endif 63#endif
64} 64}
diff --git a/arch/m68k/platform/5249/config.c b/arch/m68k/platform/5249/config.c
index bbf05135bb98..300e729a58d0 100644
--- a/arch/m68k/platform/5249/config.c
+++ b/arch/m68k/platform/5249/config.c
@@ -51,7 +51,7 @@ static struct platform_device *m5249_devices[] __initdata = {
51 51
52/***************************************************************************/ 52/***************************************************************************/
53 53
54#ifdef CONFIG_SPI_COLDFIRE_QSPI 54#if IS_ENABLED(CONFIG_SPI_COLDFIRE_QSPI)
55 55
56static void __init m5249_qspi_init(void) 56static void __init m5249_qspi_init(void)
57{ 57{
@@ -61,7 +61,7 @@ static void __init m5249_qspi_init(void)
61 mcf_mapirq2imr(MCF_IRQ_QSPI, MCFINTC_QSPI); 61 mcf_mapirq2imr(MCF_IRQ_QSPI, MCFINTC_QSPI);
62} 62}
63 63
64#endif /* CONFIG_SPI_COLDFIRE_QSPI */ 64#endif /* IS_ENABLED(CONFIG_SPI_COLDFIRE_QSPI) */
65 65
66/***************************************************************************/ 66/***************************************************************************/
67 67
@@ -90,7 +90,7 @@ void __init config_BSP(char *commandp, int size)
90#ifdef CONFIG_M5249C3 90#ifdef CONFIG_M5249C3
91 m5249_smc91x_init(); 91 m5249_smc91x_init();
92#endif 92#endif
93#ifdef CONFIG_SPI_COLDFIRE_QSPI 93#if IS_ENABLED(CONFIG_SPI_COLDFIRE_QSPI)
94 m5249_qspi_init(); 94 m5249_qspi_init();
95#endif 95#endif
96} 96}
diff --git a/arch/m68k/platform/527x/config.c b/arch/m68k/platform/527x/config.c
index 7ed848c3b848..b3cb378c5e94 100644
--- a/arch/m68k/platform/527x/config.c
+++ b/arch/m68k/platform/527x/config.c
@@ -23,7 +23,7 @@
23 23
24/***************************************************************************/ 24/***************************************************************************/
25 25
26#ifdef CONFIG_SPI_COLDFIRE_QSPI 26#if IS_ENABLED(CONFIG_SPI_COLDFIRE_QSPI)
27 27
28static void __init m527x_qspi_init(void) 28static void __init m527x_qspi_init(void)
29{ 29{
@@ -42,7 +42,7 @@ static void __init m527x_qspi_init(void)
42#endif 42#endif
43} 43}
44 44
45#endif /* CONFIG_SPI_COLDFIRE_QSPI */ 45#endif /* IS_ENABLED(CONFIG_SPI_COLDFIRE_QSPI) */
46 46
47/***************************************************************************/ 47/***************************************************************************/
48 48
@@ -74,9 +74,7 @@ static void __init m527x_fec_init(void)
74 writew(par | 0xf00, MCF_IPSBAR + 0x100082); 74 writew(par | 0xf00, MCF_IPSBAR + 0x100082);
75 v = readb(MCF_IPSBAR + 0x100078); 75 v = readb(MCF_IPSBAR + 0x100078);
76 writeb(v | 0xc0, MCF_IPSBAR + 0x100078); 76 writeb(v | 0xc0, MCF_IPSBAR + 0x100078);
77#endif
78 77
79#ifdef CONFIG_FEC2
80 /* Set multi-function pins to ethernet mode for fec1 */ 78 /* Set multi-function pins to ethernet mode for fec1 */
81 par = readw(MCF_IPSBAR + 0x100082); 79 par = readw(MCF_IPSBAR + 0x100082);
82 writew(par | 0xa0, MCF_IPSBAR + 0x100082); 80 writew(par | 0xa0, MCF_IPSBAR + 0x100082);
@@ -92,7 +90,7 @@ void __init config_BSP(char *commandp, int size)
92 mach_sched_init = hw_timer_init; 90 mach_sched_init = hw_timer_init;
93 m527x_uarts_init(); 91 m527x_uarts_init();
94 m527x_fec_init(); 92 m527x_fec_init();
95#ifdef CONFIG_SPI_COLDFIRE_QSPI 93#if IS_ENABLED(CONFIG_SPI_COLDFIRE_QSPI)
96 m527x_qspi_init(); 94 m527x_qspi_init();
97#endif 95#endif
98} 96}
diff --git a/arch/m68k/platform/528x/config.c b/arch/m68k/platform/528x/config.c
index d4492926614c..c5f11ba49be5 100644
--- a/arch/m68k/platform/528x/config.c
+++ b/arch/m68k/platform/528x/config.c
@@ -24,7 +24,7 @@
24 24
25/***************************************************************************/ 25/***************************************************************************/
26 26
27#ifdef CONFIG_SPI_COLDFIRE_QSPI 27#if IS_ENABLED(CONFIG_SPI_COLDFIRE_QSPI)
28 28
29static void __init m528x_qspi_init(void) 29static void __init m528x_qspi_init(void)
30{ 30{
@@ -32,7 +32,7 @@ static void __init m528x_qspi_init(void)
32 __raw_writeb(0x07, MCFGPIO_PQSPAR); 32 __raw_writeb(0x07, MCFGPIO_PQSPAR);
33} 33}
34 34
35#endif /* CONFIG_SPI_COLDFIRE_QSPI */ 35#endif /* IS_ENABLED(CONFIG_SPI_COLDFIRE_QSPI) */
36 36
37/***************************************************************************/ 37/***************************************************************************/
38 38
@@ -98,7 +98,7 @@ void __init config_BSP(char *commandp, int size)
98 mach_sched_init = hw_timer_init; 98 mach_sched_init = hw_timer_init;
99 m528x_uarts_init(); 99 m528x_uarts_init();
100 m528x_fec_init(); 100 m528x_fec_init();
101#ifdef CONFIG_SPI_COLDFIRE_QSPI 101#if IS_ENABLED(CONFIG_SPI_COLDFIRE_QSPI)
102 m528x_qspi_init(); 102 m528x_qspi_init();
103#endif 103#endif
104} 104}
diff --git a/arch/m68k/platform/532x/config.c b/arch/m68k/platform/532x/config.c
index 2bec3477b739..37082d02f2bd 100644
--- a/arch/m68k/platform/532x/config.c
+++ b/arch/m68k/platform/532x/config.c
@@ -30,7 +30,7 @@
30 30
31/***************************************************************************/ 31/***************************************************************************/
32 32
33#ifdef CONFIG_SPI_COLDFIRE_QSPI 33#if IS_ENABLED(CONFIG_SPI_COLDFIRE_QSPI)
34 34
35static void __init m532x_qspi_init(void) 35static void __init m532x_qspi_init(void)
36{ 36{
@@ -38,7 +38,7 @@ static void __init m532x_qspi_init(void)
38 writew(0x01f0, MCF_GPIO_PAR_QSPI); 38 writew(0x01f0, MCF_GPIO_PAR_QSPI);
39} 39}
40 40
41#endif /* CONFIG_SPI_COLDFIRE_QSPI */ 41#endif /* IS_ENABLED(CONFIG_SPI_COLDFIRE_QSPI) */
42 42
43/***************************************************************************/ 43/***************************************************************************/
44 44
@@ -77,7 +77,7 @@ void __init config_BSP(char *commandp, int size)
77 mach_sched_init = hw_timer_init; 77 mach_sched_init = hw_timer_init;
78 m532x_uarts_init(); 78 m532x_uarts_init();
79 m532x_fec_init(); 79 m532x_fec_init();
80#ifdef CONFIG_SPI_COLDFIRE_QSPI 80#if IS_ENABLED(CONFIG_SPI_COLDFIRE_QSPI)
81 m532x_qspi_init(); 81 m532x_qspi_init();
82#endif 82#endif
83 83
diff --git a/arch/m68k/platform/68EZ328/Makefile b/arch/m68k/platform/68EZ328/Makefile
index ee97735a242c..b44d799b1115 100644
--- a/arch/m68k/platform/68EZ328/Makefile
+++ b/arch/m68k/platform/68EZ328/Makefile
@@ -3,9 +3,3 @@
3# 3#
4 4
5obj-y := config.o 5obj-y := config.o
6
7extra-y := bootlogo.rh
8
9$(obj)/bootlogo.rh: $(src)/bootlogo.h
10 perl $(src)/../68328/bootlogo.pl < $(src)/bootlogo.h \
11 > $(obj)/bootlogo.rh
diff --git a/arch/m68k/platform/68VZ328/Makefile b/arch/m68k/platform/68VZ328/Makefile
index 447ffa0fd7c7..a49d75e65489 100644
--- a/arch/m68k/platform/68VZ328/Makefile
+++ b/arch/m68k/platform/68VZ328/Makefile
@@ -3,14 +3,9 @@
3# 3#
4 4
5obj-y := config.o 5obj-y := config.o
6logo-$(UCDIMM) := bootlogo.rh 6extra-$(DRAGEN2):= screen.h
7logo-$(DRAGEN2) := screen.h
8extra-y := $(logo-y)
9
10$(obj)/bootlogo.rh: $(src)/../68EZ328/bootlogo.h
11 perl $(src)/bootlogo.pl < $(src)/../68328/bootlogo.h > $(obj)/bootlogo.rh
12 7
13$(obj)/screen.h: $(src)/screen.xbm $(src)/xbm2lcd.pl 8$(obj)/screen.h: $(src)/screen.xbm $(src)/xbm2lcd.pl
14 perl $(src)/xbm2lcd.pl < $(src)/screen.xbm > $(obj)/screen.h 9 perl $(src)/xbm2lcd.pl < $(src)/screen.xbm > $(obj)/screen.h
15 10
16clean-files := $(obj)/screen.h $(obj)/bootlogo.rh 11clean-files := $(obj)/screen.h
diff --git a/arch/m68k/platform/68EZ328/bootlogo.h b/arch/m68k/platform/68VZ328/bootlogo.h
index e842bdae5839..b38e2b255142 100644
--- a/arch/m68k/platform/68EZ328/bootlogo.h
+++ b/arch/m68k/platform/68VZ328/bootlogo.h
@@ -1,6 +1,6 @@
1#define splash_width 640 1#define splash_width 640
2#define splash_height 480 2#define splash_height 480
3static unsigned char splash_bits[] = { 3unsigned char __attribute__ ((aligned(16))) bootlogo_bits[] = {
4 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 4 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 5 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 6 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
diff --git a/arch/m68k/platform/coldfire/device.c b/arch/m68k/platform/coldfire/device.c
index fa50c48292ff..3aa77ddea89d 100644
--- a/arch/m68k/platform/coldfire/device.c
+++ b/arch/m68k/platform/coldfire/device.c
@@ -114,14 +114,14 @@ static struct resource mcf_fec1_resources[] = {
114 114
115static struct platform_device mcf_fec1 = { 115static struct platform_device mcf_fec1 = {
116 .name = "fec", 116 .name = "fec",
117 .id = 0, 117 .id = 1,
118 .num_resources = ARRAY_SIZE(mcf_fec1_resources), 118 .num_resources = ARRAY_SIZE(mcf_fec1_resources),
119 .resource = mcf_fec1_resources, 119 .resource = mcf_fec1_resources,
120}; 120};
121#endif /* MCFFEC_BASE1 */ 121#endif /* MCFFEC_BASE1 */
122#endif /* CONFIG_FEC */ 122#endif /* CONFIG_FEC */
123 123
124#ifdef CONFIG_SPI_COLDFIRE_QSPI 124#if IS_ENABLED(CONFIG_SPI_COLDFIRE_QSPI)
125/* 125/*
126 * The ColdFire QSPI module is an SPI protocol hardware block used 126 * The ColdFire QSPI module is an SPI protocol hardware block used
127 * on a number of different ColdFire CPUs. 127 * on a number of different ColdFire CPUs.
@@ -274,7 +274,7 @@ static struct platform_device mcf_qspi = {
274 .resource = mcf_qspi_resources, 274 .resource = mcf_qspi_resources,
275 .dev.platform_data = &mcf_qspi_data, 275 .dev.platform_data = &mcf_qspi_data,
276}; 276};
277#endif /* CONFIG_SPI_COLDFIRE_QSPI */ 277#endif /* IS_ENABLED(CONFIG_SPI_COLDFIRE_QSPI) */
278 278
279static struct platform_device *mcf_devices[] __initdata = { 279static struct platform_device *mcf_devices[] __initdata = {
280 &mcf_uart, 280 &mcf_uart,
@@ -284,7 +284,7 @@ static struct platform_device *mcf_devices[] __initdata = {
284 &mcf_fec1, 284 &mcf_fec1,
285#endif 285#endif
286#endif 286#endif
287#ifdef CONFIG_SPI_COLDFIRE_QSPI 287#if IS_ENABLED(CONFIG_SPI_COLDFIRE_QSPI)
288 &mcf_qspi, 288 &mcf_qspi,
289#endif 289#endif
290}; 290};
diff --git a/arch/m68k/q40/config.c b/arch/m68k/q40/config.c
index 512adb64f7dd..8a1ce327c963 100644
--- a/arch/m68k/q40/config.c
+++ b/arch/m68k/q40/config.c
@@ -334,6 +334,9 @@ static __init int q40_add_kbd_device(void)
334{ 334{
335 struct platform_device *pdev; 335 struct platform_device *pdev;
336 336
337 if (!MACH_IS_Q40)
338 return -ENODEV;
339
337 pdev = platform_device_register_simple("q40kbd", -1, NULL, 0); 340 pdev = platform_device_register_simple("q40kbd", -1, NULL, 0);
338 if (IS_ERR(pdev)) 341 if (IS_ERR(pdev))
339 return PTR_ERR(pdev); 342 return PTR_ERR(pdev);
diff --git a/arch/microblaze/include/asm/cmpxchg.h b/arch/microblaze/include/asm/cmpxchg.h
index 0094859abd9b..538afc0ab9f3 100644
--- a/arch/microblaze/include/asm/cmpxchg.h
+++ b/arch/microblaze/include/asm/cmpxchg.h
@@ -1,6 +1,8 @@
1#ifndef _ASM_MICROBLAZE_CMPXCHG_H 1#ifndef _ASM_MICROBLAZE_CMPXCHG_H
2#define _ASM_MICROBLAZE_CMPXCHG_H 2#define _ASM_MICROBLAZE_CMPXCHG_H
3 3
4#include <linux/irqflags.h>
5
4void __bad_xchg(volatile void *ptr, int size); 6void __bad_xchg(volatile void *ptr, int size);
5 7
6static inline unsigned long __xchg(unsigned long x, volatile void *ptr, 8static inline unsigned long __xchg(unsigned long x, volatile void *ptr,
diff --git a/arch/microblaze/include/asm/dma-mapping.h b/arch/microblaze/include/asm/dma-mapping.h
index 3a3e5b886854..01d228286cb0 100644
--- a/arch/microblaze/include/asm/dma-mapping.h
+++ b/arch/microblaze/include/asm/dma-mapping.h
@@ -123,28 +123,34 @@ static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
123#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f) 123#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
124#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h) 124#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
125 125
126static inline void *dma_alloc_coherent(struct device *dev, size_t size, 126#define dma_alloc_coherent(d, s, h, f) dma_alloc_attrs(d, s, h, f, NULL)
127 dma_addr_t *dma_handle, gfp_t flag) 127
128static inline void *dma_alloc_attrs(struct device *dev, size_t size,
129 dma_addr_t *dma_handle, gfp_t flag,
130 struct dma_attrs *attrs)
128{ 131{
129 struct dma_map_ops *ops = get_dma_ops(dev); 132 struct dma_map_ops *ops = get_dma_ops(dev);
130 void *memory; 133 void *memory;
131 134
132 BUG_ON(!ops); 135 BUG_ON(!ops);
133 136
134 memory = ops->alloc_coherent(dev, size, dma_handle, flag); 137 memory = ops->alloc(dev, size, dma_handle, flag, attrs);
135 138
136 debug_dma_alloc_coherent(dev, size, *dma_handle, memory); 139 debug_dma_alloc_coherent(dev, size, *dma_handle, memory);
137 return memory; 140 return memory;
138} 141}
139 142
140static inline void dma_free_coherent(struct device *dev, size_t size, 143#define dma_free_coherent(d,s,c,h) dma_free_attrs(d, s, c, h, NULL)
141 void *cpu_addr, dma_addr_t dma_handle) 144
145static inline void dma_free_attrs(struct device *dev, size_t size,
146 void *cpu_addr, dma_addr_t dma_handle,
147 struct dma_attrs *attrs)
142{ 148{
143 struct dma_map_ops *ops = get_dma_ops(dev); 149 struct dma_map_ops *ops = get_dma_ops(dev);
144 150
145 BUG_ON(!ops); 151 BUG_ON(!ops);
146 debug_dma_free_coherent(dev, size, cpu_addr, dma_handle); 152 debug_dma_free_coherent(dev, size, cpu_addr, dma_handle);
147 ops->free_coherent(dev, size, cpu_addr, dma_handle); 153 ops->free(dev, size, cpu_addr, dma_handle, attrs);
148} 154}
149 155
150static inline void dma_cache_sync(struct device *dev, void *vaddr, size_t size, 156static inline void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
diff --git a/arch/microblaze/include/asm/futex.h b/arch/microblaze/include/asm/futex.h
index b0526d2716fa..ff8cde159d9a 100644
--- a/arch/microblaze/include/asm/futex.h
+++ b/arch/microblaze/include/asm/futex.h
@@ -24,7 +24,7 @@
24 .word 1b,4b,2b,4b; \ 24 .word 1b,4b,2b,4b; \
25 .previous;" \ 25 .previous;" \
26 : "=&r" (oldval), "=&r" (ret) \ 26 : "=&r" (oldval), "=&r" (ret) \
27 : "b" (uaddr), "i" (-EFAULT), "r" (oparg) \ 27 : "r" (uaddr), "i" (-EFAULT), "r" (oparg) \
28 ); \ 28 ); \
29}) 29})
30 30
diff --git a/arch/microblaze/include/asm/processor.h b/arch/microblaze/include/asm/processor.h
index 510a8e1c16ba..bffb54527299 100644
--- a/arch/microblaze/include/asm/processor.h
+++ b/arch/microblaze/include/asm/processor.h
@@ -31,6 +31,8 @@ extern const struct seq_operations cpuinfo_op;
31/* Do necessary setup to start up a newly executed thread. */ 31/* Do necessary setup to start up a newly executed thread. */
32void start_thread(struct pt_regs *regs, unsigned long pc, unsigned long usp); 32void start_thread(struct pt_regs *regs, unsigned long pc, unsigned long usp);
33 33
34extern void ret_from_fork(void);
35
34# endif /* __ASSEMBLY__ */ 36# endif /* __ASSEMBLY__ */
35 37
36# ifndef CONFIG_MMU 38# ifndef CONFIG_MMU
@@ -143,8 +145,6 @@ static inline void exit_thread(void)
143 145
144unsigned long get_wchan(struct task_struct *p); 146unsigned long get_wchan(struct task_struct *p);
145 147
146extern void ret_from_fork(void);
147
148/* The size allocated for kernel stacks. This _must_ be a power of two! */ 148/* The size allocated for kernel stacks. This _must_ be a power of two! */
149# define KERNEL_STACK_SIZE 0x2000 149# define KERNEL_STACK_SIZE 0x2000
150 150
diff --git a/arch/microblaze/kernel/dma.c b/arch/microblaze/kernel/dma.c
index 65a4af4cbbbe..a2bfa2ca5730 100644
--- a/arch/microblaze/kernel/dma.c
+++ b/arch/microblaze/kernel/dma.c
@@ -33,7 +33,8 @@ static unsigned long get_dma_direct_offset(struct device *dev)
33#define NOT_COHERENT_CACHE 33#define NOT_COHERENT_CACHE
34 34
35static void *dma_direct_alloc_coherent(struct device *dev, size_t size, 35static void *dma_direct_alloc_coherent(struct device *dev, size_t size,
36 dma_addr_t *dma_handle, gfp_t flag) 36 dma_addr_t *dma_handle, gfp_t flag,
37 struct dma_attrs *attrs)
37{ 38{
38#ifdef NOT_COHERENT_CACHE 39#ifdef NOT_COHERENT_CACHE
39 return consistent_alloc(flag, size, dma_handle); 40 return consistent_alloc(flag, size, dma_handle);
@@ -57,7 +58,8 @@ static void *dma_direct_alloc_coherent(struct device *dev, size_t size,
57} 58}
58 59
59static void dma_direct_free_coherent(struct device *dev, size_t size, 60static void dma_direct_free_coherent(struct device *dev, size_t size,
60 void *vaddr, dma_addr_t dma_handle) 61 void *vaddr, dma_addr_t dma_handle,
62 struct dma_attrs *attrs)
61{ 63{
62#ifdef NOT_COHERENT_CACHE 64#ifdef NOT_COHERENT_CACHE
63 consistent_free(size, vaddr); 65 consistent_free(size, vaddr);
@@ -176,8 +178,8 @@ dma_direct_sync_sg_for_device(struct device *dev,
176} 178}
177 179
178struct dma_map_ops dma_direct_ops = { 180struct dma_map_ops dma_direct_ops = {
179 .alloc_coherent = dma_direct_alloc_coherent, 181 .alloc = dma_direct_alloc_coherent,
180 .free_coherent = dma_direct_free_coherent, 182 .free = dma_direct_free_coherent,
181 .map_sg = dma_direct_map_sg, 183 .map_sg = dma_direct_map_sg,
182 .unmap_sg = dma_direct_unmap_sg, 184 .unmap_sg = dma_direct_unmap_sg,
183 .dma_supported = dma_direct_dma_supported, 185 .dma_supported = dma_direct_dma_supported,
diff --git a/arch/microblaze/kernel/early_printk.c b/arch/microblaze/kernel/early_printk.c
index ec485876d0d0..aba1f9a97d5d 100644
--- a/arch/microblaze/kernel/early_printk.c
+++ b/arch/microblaze/kernel/early_printk.c
@@ -176,6 +176,7 @@ void __init remap_early_printk(void)
176 base_addr = (u32) ioremap(base_addr, PAGE_SIZE); 176 base_addr = (u32) ioremap(base_addr, PAGE_SIZE);
177 printk(KERN_CONT "0x%x\n", base_addr); 177 printk(KERN_CONT "0x%x\n", base_addr);
178 178
179#ifdef CONFIG_MMU
179 /* 180 /*
180 * Early console is on the top of skipped TLB entries 181 * Early console is on the top of skipped TLB entries
181 * decrease tlb_skip size ensure that hardcoded TLB entry will be 182 * decrease tlb_skip size ensure that hardcoded TLB entry will be
@@ -189,6 +190,7 @@ void __init remap_early_printk(void)
189 * cmp rX, orig_base_addr 190 * cmp rX, orig_base_addr
190 */ 191 */
191 tlb_skip -= 1; 192 tlb_skip -= 1;
193#endif
192} 194}
193 195
194void __init disable_early_printk(void) 196void __init disable_early_printk(void)
diff --git a/arch/microblaze/kernel/setup.c b/arch/microblaze/kernel/setup.c
index 71af974aa24a..16d8dfd9094b 100644
--- a/arch/microblaze/kernel/setup.c
+++ b/arch/microblaze/kernel/setup.c
@@ -206,6 +206,7 @@ static int microblaze_debugfs_init(void)
206} 206}
207arch_initcall(microblaze_debugfs_init); 207arch_initcall(microblaze_debugfs_init);
208 208
209# ifdef CONFIG_MMU
209static int __init debugfs_tlb(void) 210static int __init debugfs_tlb(void)
210{ 211{
211 struct dentry *d; 212 struct dentry *d;
@@ -218,6 +219,7 @@ static int __init debugfs_tlb(void)
218 return -ENOMEM; 219 return -ENOMEM;
219} 220}
220device_initcall(debugfs_tlb); 221device_initcall(debugfs_tlb);
222# endif
221#endif 223#endif
222 224
223static int dflt_bus_notify(struct notifier_block *nb, 225static int dflt_bus_notify(struct notifier_block *nb,
diff --git a/arch/microblaze/kernel/unwind.c b/arch/microblaze/kernel/unwind.c
index 9781a528cfc9..6be4ae3c3351 100644
--- a/arch/microblaze/kernel/unwind.c
+++ b/arch/microblaze/kernel/unwind.c
@@ -24,6 +24,7 @@
24#include <asm/sections.h> 24#include <asm/sections.h>
25#include <asm/exceptions.h> 25#include <asm/exceptions.h>
26#include <asm/unwind.h> 26#include <asm/unwind.h>
27#include <asm/switch_to.h>
27 28
28struct stack_trace; 29struct stack_trace;
29 30
diff --git a/arch/microblaze/lib/uaccess_old.S b/arch/microblaze/lib/uaccess_old.S
index f037266cdaf3..f085995ee848 100644
--- a/arch/microblaze/lib/uaccess_old.S
+++ b/arch/microblaze/lib/uaccess_old.S
@@ -122,22 +122,22 @@ __strnlen_user:
12215: swi r24, r5, 0x0018 + offset; \ 12215: swi r24, r5, 0x0018 + offset; \
12316: swi r25, r5, 0x001C + offset; \ 12316: swi r25, r5, 0x001C + offset; \
124 .section __ex_table,"a"; \ 124 .section __ex_table,"a"; \
125 .word 1b, 0f; \ 125 .word 1b, 33f; \
126 .word 2b, 0f; \ 126 .word 2b, 33f; \
127 .word 3b, 0f; \ 127 .word 3b, 33f; \
128 .word 4b, 0f; \ 128 .word 4b, 33f; \
129 .word 5b, 0f; \ 129 .word 5b, 33f; \
130 .word 6b, 0f; \ 130 .word 6b, 33f; \
131 .word 7b, 0f; \ 131 .word 7b, 33f; \
132 .word 8b, 0f; \ 132 .word 8b, 33f; \
133 .word 9b, 0f; \ 133 .word 9b, 33f; \
134 .word 10b, 0f; \ 134 .word 10b, 33f; \
135 .word 11b, 0f; \ 135 .word 11b, 33f; \
136 .word 12b, 0f; \ 136 .word 12b, 33f; \
137 .word 13b, 0f; \ 137 .word 13b, 33f; \
138 .word 14b, 0f; \ 138 .word 14b, 33f; \
139 .word 15b, 0f; \ 139 .word 15b, 33f; \
140 .word 16b, 0f; \ 140 .word 16b, 33f; \
141 .text 141 .text
142 142
143#define COPY_80(offset) \ 143#define COPY_80(offset) \
@@ -190,14 +190,17 @@ w2: sw r4, r5, r3
190 190
191.align 4 /* Alignment is important to keep icache happy */ 191.align 4 /* Alignment is important to keep icache happy */
192page: /* Create room on stack and save registers for storign values */ 192page: /* Create room on stack and save registers for storign values */
193 addik r1, r1, -32 193 addik r1, r1, -40
194 swi r19, r1, 4 194 swi r5, r1, 0
195 swi r20, r1, 8 195 swi r6, r1, 4
196 swi r21, r1, 12 196 swi r7, r1, 8
197 swi r22, r1, 16 197 swi r19, r1, 12
198 swi r23, r1, 20 198 swi r20, r1, 16
199 swi r24, r1, 24 199 swi r21, r1, 20
200 swi r25, r1, 28 200 swi r22, r1, 24
201 swi r23, r1, 28
202 swi r24, r1, 32
203 swi r25, r1, 36
201loop: /* r4, r19, r20, r21, r22, r23, r24, r25 are used for storing values */ 204loop: /* r4, r19, r20, r21, r22, r23, r24, r25 are used for storing values */
202 /* Loop unrolling to get performance boost */ 205 /* Loop unrolling to get performance boost */
203 COPY_80(0x000); 206 COPY_80(0x000);
@@ -205,21 +208,44 @@ loop: /* r4, r19, r20, r21, r22, r23, r24, r25 are used for storing values */
205 COPY_80(0x100); 208 COPY_80(0x100);
206 COPY_80(0x180); 209 COPY_80(0x180);
207 /* copy loop */ 210 /* copy loop */
208 addik r6, r6, 0x200 211 addik r6, r6, 0x200
209 addik r7, r7, -0x200 212 addik r7, r7, -0x200
210 bneid r7, loop 213 bneid r7, loop
211 addik r5, r5, 0x200 214 addik r5, r5, 0x200
215
212 /* Restore register content */ 216 /* Restore register content */
213 lwi r19, r1, 4 217 lwi r5, r1, 0
214 lwi r20, r1, 8 218 lwi r6, r1, 4
215 lwi r21, r1, 12 219 lwi r7, r1, 8
216 lwi r22, r1, 16 220 lwi r19, r1, 12
217 lwi r23, r1, 20 221 lwi r20, r1, 16
218 lwi r24, r1, 24 222 lwi r21, r1, 20
219 lwi r25, r1, 28 223 lwi r22, r1, 24
220 addik r1, r1, 32 224 lwi r23, r1, 28
225 lwi r24, r1, 32
226 lwi r25, r1, 36
227 addik r1, r1, 40
221 /* return back */ 228 /* return back */
229 addik r3, r0, 0
230 rtsd r15, 8
231 nop
232
233/* Fault case - return temp count */
23433:
222 addik r3, r7, 0 235 addik r3, r7, 0
236 /* Restore register content */
237 lwi r5, r1, 0
238 lwi r6, r1, 4
239 lwi r7, r1, 8
240 lwi r19, r1, 12
241 lwi r20, r1, 16
242 lwi r21, r1, 20
243 lwi r22, r1, 24
244 lwi r23, r1, 28
245 lwi r24, r1, 32
246 lwi r25, r1, 36
247 addik r1, r1, 40
248 /* return back */
223 rtsd r15, 8 249 rtsd r15, 8
224 nop 250 nop
225 251
diff --git a/arch/mips/ath79/dev-wmac.c b/arch/mips/ath79/dev-wmac.c
index e21507052066..9c717bf98ffe 100644
--- a/arch/mips/ath79/dev-wmac.c
+++ b/arch/mips/ath79/dev-wmac.c
@@ -58,8 +58,8 @@ static void __init ar913x_wmac_setup(void)
58 58
59static int ar933x_wmac_reset(void) 59static int ar933x_wmac_reset(void)
60{ 60{
61 ath79_device_reset_clear(AR933X_RESET_WMAC);
62 ath79_device_reset_set(AR933X_RESET_WMAC); 61 ath79_device_reset_set(AR933X_RESET_WMAC);
62 ath79_device_reset_clear(AR933X_RESET_WMAC);
63 63
64 return 0; 64 return 0;
65} 65}
diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
index b6bb92c16a47..41dd00884975 100644
--- a/arch/mips/cavium-octeon/dma-octeon.c
+++ b/arch/mips/cavium-octeon/dma-octeon.c
@@ -157,7 +157,7 @@ static void octeon_dma_sync_sg_for_device(struct device *dev,
157} 157}
158 158
159static void *octeon_dma_alloc_coherent(struct device *dev, size_t size, 159static void *octeon_dma_alloc_coherent(struct device *dev, size_t size,
160 dma_addr_t *dma_handle, gfp_t gfp) 160 dma_addr_t *dma_handle, gfp_t gfp, struct dma_attrs *attrs)
161{ 161{
162 void *ret; 162 void *ret;
163 163
@@ -192,7 +192,7 @@ static void *octeon_dma_alloc_coherent(struct device *dev, size_t size,
192} 192}
193 193
194static void octeon_dma_free_coherent(struct device *dev, size_t size, 194static void octeon_dma_free_coherent(struct device *dev, size_t size,
195 void *vaddr, dma_addr_t dma_handle) 195 void *vaddr, dma_addr_t dma_handle, struct dma_attrs *attrs)
196{ 196{
197 int order = get_order(size); 197 int order = get_order(size);
198 198
@@ -240,8 +240,8 @@ EXPORT_SYMBOL(dma_to_phys);
240 240
241static struct octeon_dma_map_ops octeon_linear_dma_map_ops = { 241static struct octeon_dma_map_ops octeon_linear_dma_map_ops = {
242 .dma_map_ops = { 242 .dma_map_ops = {
243 .alloc_coherent = octeon_dma_alloc_coherent, 243 .alloc = octeon_dma_alloc_coherent,
244 .free_coherent = octeon_dma_free_coherent, 244 .free = octeon_dma_free_coherent,
245 .map_page = octeon_dma_map_page, 245 .map_page = octeon_dma_map_page,
246 .unmap_page = swiotlb_unmap_page, 246 .unmap_page = swiotlb_unmap_page,
247 .map_sg = octeon_dma_map_sg, 247 .map_sg = octeon_dma_map_sg,
@@ -325,8 +325,8 @@ void __init plat_swiotlb_setup(void)
325#ifdef CONFIG_PCI 325#ifdef CONFIG_PCI
326static struct octeon_dma_map_ops _octeon_pci_dma_map_ops = { 326static struct octeon_dma_map_ops _octeon_pci_dma_map_ops = {
327 .dma_map_ops = { 327 .dma_map_ops = {
328 .alloc_coherent = octeon_dma_alloc_coherent, 328 .alloc = octeon_dma_alloc_coherent,
329 .free_coherent = octeon_dma_free_coherent, 329 .free = octeon_dma_free_coherent,
330 .map_page = octeon_dma_map_page, 330 .map_page = octeon_dma_map_page,
331 .unmap_page = swiotlb_unmap_page, 331 .unmap_page = swiotlb_unmap_page,
332 .map_sg = octeon_dma_map_sg, 332 .map_sg = octeon_dma_map_sg,
diff --git a/arch/mips/cavium-octeon/smp.c b/arch/mips/cavium-octeon/smp.c
index c3e2b85c3b02..97e7ce9b50ed 100644
--- a/arch/mips/cavium-octeon/smp.c
+++ b/arch/mips/cavium-octeon/smp.c
@@ -78,7 +78,7 @@ static inline void octeon_send_ipi_mask(const struct cpumask *mask,
78} 78}
79 79
80/** 80/**
81 * Detect available CPUs, populate cpu_possible_map 81 * Detect available CPUs, populate cpu_possible_mask
82 */ 82 */
83static void octeon_smp_hotplug_setup(void) 83static void octeon_smp_hotplug_setup(void)
84{ 84{
@@ -268,7 +268,7 @@ static int octeon_cpu_disable(void)
268 268
269 spin_lock(&smp_reserve_lock); 269 spin_lock(&smp_reserve_lock);
270 270
271 cpu_clear(cpu, cpu_online_map); 271 set_cpu_online(cpu, false);
272 cpu_clear(cpu, cpu_callin_map); 272 cpu_clear(cpu, cpu_callin_map);
273 local_irq_disable(); 273 local_irq_disable();
274 fixup_irqs(); 274 fixup_irqs();
diff --git a/arch/mips/include/asm/dma-mapping.h b/arch/mips/include/asm/dma-mapping.h
index 7aa37ddfca4b..be39a12901c6 100644
--- a/arch/mips/include/asm/dma-mapping.h
+++ b/arch/mips/include/asm/dma-mapping.h
@@ -57,25 +57,31 @@ dma_set_mask(struct device *dev, u64 mask)
57extern void dma_cache_sync(struct device *dev, void *vaddr, size_t size, 57extern void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
58 enum dma_data_direction direction); 58 enum dma_data_direction direction);
59 59
60static inline void *dma_alloc_coherent(struct device *dev, size_t size, 60#define dma_alloc_coherent(d,s,h,f) dma_alloc_attrs(d,s,h,f,NULL)
61 dma_addr_t *dma_handle, gfp_t gfp) 61
62static inline void *dma_alloc_attrs(struct device *dev, size_t size,
63 dma_addr_t *dma_handle, gfp_t gfp,
64 struct dma_attrs *attrs)
62{ 65{
63 void *ret; 66 void *ret;
64 struct dma_map_ops *ops = get_dma_ops(dev); 67 struct dma_map_ops *ops = get_dma_ops(dev);
65 68
66 ret = ops->alloc_coherent(dev, size, dma_handle, gfp); 69 ret = ops->alloc(dev, size, dma_handle, gfp, attrs);
67 70
68 debug_dma_alloc_coherent(dev, size, *dma_handle, ret); 71 debug_dma_alloc_coherent(dev, size, *dma_handle, ret);
69 72
70 return ret; 73 return ret;
71} 74}
72 75
73static inline void dma_free_coherent(struct device *dev, size_t size, 76#define dma_free_coherent(d,s,c,h) dma_free_attrs(d,s,c,h,NULL)
74 void *vaddr, dma_addr_t dma_handle) 77
78static inline void dma_free_attrs(struct device *dev, size_t size,
79 void *vaddr, dma_addr_t dma_handle,
80 struct dma_attrs *attrs)
75{ 81{
76 struct dma_map_ops *ops = get_dma_ops(dev); 82 struct dma_map_ops *ops = get_dma_ops(dev);
77 83
78 ops->free_coherent(dev, size, vaddr, dma_handle); 84 ops->free(dev, size, vaddr, dma_handle, attrs);
79 85
80 debug_dma_free_coherent(dev, size, vaddr, dma_handle); 86 debug_dma_free_coherent(dev, size, vaddr, dma_handle);
81} 87}
diff --git a/arch/mips/include/asm/mach-jz4740/irq.h b/arch/mips/include/asm/mach-jz4740/irq.h
index a865c983c70a..5ad1a9c113c6 100644
--- a/arch/mips/include/asm/mach-jz4740/irq.h
+++ b/arch/mips/include/asm/mach-jz4740/irq.h
@@ -45,7 +45,7 @@
45#define JZ4740_IRQ_LCD JZ4740_IRQ(30) 45#define JZ4740_IRQ_LCD JZ4740_IRQ(30)
46 46
47/* 2nd-level interrupts */ 47/* 2nd-level interrupts */
48#define JZ4740_IRQ_DMA(x) (JZ4740_IRQ(32) + (X)) 48#define JZ4740_IRQ_DMA(x) (JZ4740_IRQ(32) + (x))
49 49
50#define JZ4740_IRQ_INTC_GPIO(x) (JZ4740_IRQ_GPIO0 - (x)) 50#define JZ4740_IRQ_INTC_GPIO(x) (JZ4740_IRQ_GPIO0 - (x))
51#define JZ4740_IRQ_GPIO(x) (JZ4740_IRQ(48) + (x)) 51#define JZ4740_IRQ_GPIO(x) (JZ4740_IRQ(48) + (x))
diff --git a/arch/mips/include/asm/mmu_context.h b/arch/mips/include/asm/mmu_context.h
index 73c0d45798de..9b02cfba7449 100644
--- a/arch/mips/include/asm/mmu_context.h
+++ b/arch/mips/include/asm/mmu_context.h
@@ -37,12 +37,6 @@ extern void tlbmiss_handler_setup_pgd(unsigned long pgd);
37 write_c0_xcontext((unsigned long) smp_processor_id() << 51); \ 37 write_c0_xcontext((unsigned long) smp_processor_id() << 51); \
38 } while (0) 38 } while (0)
39 39
40
41static inline unsigned long get_current_pgd(void)
42{
43 return PHYS_TO_XKSEG_CACHED((read_c0_context() >> 11) & ~0xfffUL);
44}
45
46#else /* CONFIG_MIPS_PGD_C0_CONTEXT: using pgd_current*/ 40#else /* CONFIG_MIPS_PGD_C0_CONTEXT: using pgd_current*/
47 41
48/* 42/*
diff --git a/arch/mips/kernel/mips-mt-fpaff.c b/arch/mips/kernel/mips-mt-fpaff.c
index 802e6160f37e..33f63bab478a 100644
--- a/arch/mips/kernel/mips-mt-fpaff.c
+++ b/arch/mips/kernel/mips-mt-fpaff.c
@@ -173,7 +173,7 @@ asmlinkage long mipsmt_sys_sched_getaffinity(pid_t pid, unsigned int len,
173 if (retval) 173 if (retval)
174 goto out_unlock; 174 goto out_unlock;
175 175
176 cpus_and(mask, p->thread.user_cpus_allowed, cpu_possible_map); 176 cpumask_and(&mask, &p->thread.user_cpus_allowed, cpu_possible_mask);
177 177
178out_unlock: 178out_unlock:
179 read_unlock(&tasklist_lock); 179 read_unlock(&tasklist_lock);
diff --git a/arch/mips/kernel/proc.c b/arch/mips/kernel/proc.c
index e309665b6c81..f8b2c592514d 100644
--- a/arch/mips/kernel/proc.c
+++ b/arch/mips/kernel/proc.c
@@ -25,7 +25,7 @@ static int show_cpuinfo(struct seq_file *m, void *v)
25 int i; 25 int i;
26 26
27#ifdef CONFIG_SMP 27#ifdef CONFIG_SMP
28 if (!cpu_isset(n, cpu_online_map)) 28 if (!cpu_online(n))
29 return 0; 29 return 0;
30#endif 30#endif
31 31
diff --git a/arch/mips/kernel/signal.c b/arch/mips/kernel/signal.c
index 185ca00c4c84..d5a338a1739c 100644
--- a/arch/mips/kernel/signal.c
+++ b/arch/mips/kernel/signal.c
@@ -257,11 +257,8 @@ asmlinkage int sys_sigsuspend(nabi_no_regargs struct pt_regs regs)
257 return -EFAULT; 257 return -EFAULT;
258 sigdelsetmask(&newset, ~_BLOCKABLE); 258 sigdelsetmask(&newset, ~_BLOCKABLE);
259 259
260 spin_lock_irq(&current->sighand->siglock);
261 current->saved_sigmask = current->blocked; 260 current->saved_sigmask = current->blocked;
262 current->blocked = newset; 261 set_current_blocked(&newset);
263 recalc_sigpending();
264 spin_unlock_irq(&current->sighand->siglock);
265 262
266 current->state = TASK_INTERRUPTIBLE; 263 current->state = TASK_INTERRUPTIBLE;
267 schedule(); 264 schedule();
@@ -286,11 +283,8 @@ asmlinkage int sys_rt_sigsuspend(nabi_no_regargs struct pt_regs regs)
286 return -EFAULT; 283 return -EFAULT;
287 sigdelsetmask(&newset, ~_BLOCKABLE); 284 sigdelsetmask(&newset, ~_BLOCKABLE);
288 285
289 spin_lock_irq(&current->sighand->siglock);
290 current->saved_sigmask = current->blocked; 286 current->saved_sigmask = current->blocked;
291 current->blocked = newset; 287 set_current_blocked(&newset);
292 recalc_sigpending();
293 spin_unlock_irq(&current->sighand->siglock);
294 288
295 current->state = TASK_INTERRUPTIBLE; 289 current->state = TASK_INTERRUPTIBLE;
296 schedule(); 290 schedule();
@@ -362,10 +356,7 @@ asmlinkage void sys_sigreturn(nabi_no_regargs struct pt_regs regs)
362 goto badframe; 356 goto badframe;
363 357
364 sigdelsetmask(&blocked, ~_BLOCKABLE); 358 sigdelsetmask(&blocked, ~_BLOCKABLE);
365 spin_lock_irq(&current->sighand->siglock); 359 set_current_blocked(&blocked);
366 current->blocked = blocked;
367 recalc_sigpending();
368 spin_unlock_irq(&current->sighand->siglock);
369 360
370 sig = restore_sigcontext(&regs, &frame->sf_sc); 361 sig = restore_sigcontext(&regs, &frame->sf_sc);
371 if (sig < 0) 362 if (sig < 0)
@@ -401,10 +392,7 @@ asmlinkage void sys_rt_sigreturn(nabi_no_regargs struct pt_regs regs)
401 goto badframe; 392 goto badframe;
402 393
403 sigdelsetmask(&set, ~_BLOCKABLE); 394 sigdelsetmask(&set, ~_BLOCKABLE);
404 spin_lock_irq(&current->sighand->siglock); 395 set_current_blocked(&set);
405 current->blocked = set;
406 recalc_sigpending();
407 spin_unlock_irq(&current->sighand->siglock);
408 396
409 sig = restore_sigcontext(&regs, &frame->rs_uc.uc_mcontext); 397 sig = restore_sigcontext(&regs, &frame->rs_uc.uc_mcontext);
410 if (sig < 0) 398 if (sig < 0)
@@ -580,12 +568,7 @@ static int handle_signal(unsigned long sig, siginfo_t *info,
580 if (ret) 568 if (ret)
581 return ret; 569 return ret;
582 570
583 spin_lock_irq(&current->sighand->siglock); 571 block_sigmask(ka, sig);
584 sigorsets(&current->blocked, &current->blocked, &ka->sa.sa_mask);
585 if (!(ka->sa.sa_flags & SA_NODEFER))
586 sigaddset(&current->blocked, sig);
587 recalc_sigpending();
588 spin_unlock_irq(&current->sighand->siglock);
589 572
590 return ret; 573 return ret;
591} 574}
diff --git a/arch/mips/kernel/signal32.c b/arch/mips/kernel/signal32.c
index 06b5da392e24..ac3b8d89aae5 100644
--- a/arch/mips/kernel/signal32.c
+++ b/arch/mips/kernel/signal32.c
@@ -290,11 +290,8 @@ asmlinkage int sys32_sigsuspend(nabi_no_regargs struct pt_regs regs)
290 return -EFAULT; 290 return -EFAULT;
291 sigdelsetmask(&newset, ~_BLOCKABLE); 291 sigdelsetmask(&newset, ~_BLOCKABLE);
292 292
293 spin_lock_irq(&current->sighand->siglock);
294 current->saved_sigmask = current->blocked; 293 current->saved_sigmask = current->blocked;
295 current->blocked = newset; 294 set_current_blocked(&newset);
296 recalc_sigpending();
297 spin_unlock_irq(&current->sighand->siglock);
298 295
299 current->state = TASK_INTERRUPTIBLE; 296 current->state = TASK_INTERRUPTIBLE;
300 schedule(); 297 schedule();
@@ -318,11 +315,8 @@ asmlinkage int sys32_rt_sigsuspend(nabi_no_regargs struct pt_regs regs)
318 return -EFAULT; 315 return -EFAULT;
319 sigdelsetmask(&newset, ~_BLOCKABLE); 316 sigdelsetmask(&newset, ~_BLOCKABLE);
320 317
321 spin_lock_irq(&current->sighand->siglock);
322 current->saved_sigmask = current->blocked; 318 current->saved_sigmask = current->blocked;
323 current->blocked = newset; 319 set_current_blocked(&newset);
324 recalc_sigpending();
325 spin_unlock_irq(&current->sighand->siglock);
326 320
327 current->state = TASK_INTERRUPTIBLE; 321 current->state = TASK_INTERRUPTIBLE;
328 schedule(); 322 schedule();
@@ -488,10 +482,7 @@ asmlinkage void sys32_sigreturn(nabi_no_regargs struct pt_regs regs)
488 goto badframe; 482 goto badframe;
489 483
490 sigdelsetmask(&blocked, ~_BLOCKABLE); 484 sigdelsetmask(&blocked, ~_BLOCKABLE);
491 spin_lock_irq(&current->sighand->siglock); 485 set_current_blocked(&blocked);
492 current->blocked = blocked;
493 recalc_sigpending();
494 spin_unlock_irq(&current->sighand->siglock);
495 486
496 sig = restore_sigcontext32(&regs, &frame->sf_sc); 487 sig = restore_sigcontext32(&regs, &frame->sf_sc);
497 if (sig < 0) 488 if (sig < 0)
@@ -529,10 +520,7 @@ asmlinkage void sys32_rt_sigreturn(nabi_no_regargs struct pt_regs regs)
529 goto badframe; 520 goto badframe;
530 521
531 sigdelsetmask(&set, ~_BLOCKABLE); 522 sigdelsetmask(&set, ~_BLOCKABLE);
532 spin_lock_irq(&current->sighand->siglock); 523 set_current_blocked(&set);
533 current->blocked = set;
534 recalc_sigpending();
535 spin_unlock_irq(&current->sighand->siglock);
536 524
537 sig = restore_sigcontext32(&regs, &frame->rs_uc.uc_mcontext); 525 sig = restore_sigcontext32(&regs, &frame->rs_uc.uc_mcontext);
538 if (sig < 0) 526 if (sig < 0)
diff --git a/arch/mips/kernel/signal_n32.c b/arch/mips/kernel/signal_n32.c
index ae29e894ab8d..86eb4b04631c 100644
--- a/arch/mips/kernel/signal_n32.c
+++ b/arch/mips/kernel/signal_n32.c
@@ -93,11 +93,8 @@ asmlinkage int sysn32_rt_sigsuspend(nabi_no_regargs struct pt_regs regs)
93 sigset_from_compat(&newset, &uset); 93 sigset_from_compat(&newset, &uset);
94 sigdelsetmask(&newset, ~_BLOCKABLE); 94 sigdelsetmask(&newset, ~_BLOCKABLE);
95 95
96 spin_lock_irq(&current->sighand->siglock);
97 current->saved_sigmask = current->blocked; 96 current->saved_sigmask = current->blocked;
98 current->blocked = newset; 97 set_current_blocked(&newset);
99 recalc_sigpending();
100 spin_unlock_irq(&current->sighand->siglock);
101 98
102 current->state = TASK_INTERRUPTIBLE; 99 current->state = TASK_INTERRUPTIBLE;
103 schedule(); 100 schedule();
@@ -121,10 +118,7 @@ asmlinkage void sysn32_rt_sigreturn(nabi_no_regargs struct pt_regs regs)
121 goto badframe; 118 goto badframe;
122 119
123 sigdelsetmask(&set, ~_BLOCKABLE); 120 sigdelsetmask(&set, ~_BLOCKABLE);
124 spin_lock_irq(&current->sighand->siglock); 121 set_current_blocked(&set);
125 current->blocked = set;
126 recalc_sigpending();
127 spin_unlock_irq(&current->sighand->siglock);
128 122
129 sig = restore_sigcontext(&regs, &frame->rs_uc.uc_mcontext); 123 sig = restore_sigcontext(&regs, &frame->rs_uc.uc_mcontext);
130 if (sig < 0) 124 if (sig < 0)
diff --git a/arch/mips/kernel/smp-bmips.c b/arch/mips/kernel/smp-bmips.c
index ca673569fd24..3046e2986006 100644
--- a/arch/mips/kernel/smp-bmips.c
+++ b/arch/mips/kernel/smp-bmips.c
@@ -317,7 +317,7 @@ static int bmips_cpu_disable(void)
317 317
318 pr_info("SMP: CPU%d is offline\n", cpu); 318 pr_info("SMP: CPU%d is offline\n", cpu);
319 319
320 cpu_clear(cpu, cpu_online_map); 320 set_cpu_online(cpu, false);
321 cpu_clear(cpu, cpu_callin_map); 321 cpu_clear(cpu, cpu_callin_map);
322 322
323 local_flush_tlb_all(); 323 local_flush_tlb_all();
diff --git a/arch/mips/kernel/smp.c b/arch/mips/kernel/smp.c
index 9c1cce9de35f..ba9376bf52a1 100644
--- a/arch/mips/kernel/smp.c
+++ b/arch/mips/kernel/smp.c
@@ -148,7 +148,7 @@ static void stop_this_cpu(void *dummy)
148 /* 148 /*
149 * Remove this CPU: 149 * Remove this CPU:
150 */ 150 */
151 cpu_clear(smp_processor_id(), cpu_online_map); 151 set_cpu_online(smp_processor_id(), false);
152 for (;;) { 152 for (;;) {
153 if (cpu_wait) 153 if (cpu_wait)
154 (*cpu_wait)(); /* Wait if available. */ 154 (*cpu_wait)(); /* Wait if available. */
@@ -174,7 +174,7 @@ void __init smp_prepare_cpus(unsigned int max_cpus)
174 mp_ops->prepare_cpus(max_cpus); 174 mp_ops->prepare_cpus(max_cpus);
175 set_cpu_sibling_map(0); 175 set_cpu_sibling_map(0);
176#ifndef CONFIG_HOTPLUG_CPU 176#ifndef CONFIG_HOTPLUG_CPU
177 init_cpu_present(&cpu_possible_map); 177 init_cpu_present(cpu_possible_mask);
178#endif 178#endif
179} 179}
180 180
@@ -248,7 +248,7 @@ int __cpuinit __cpu_up(unsigned int cpu)
248 while (!cpu_isset(cpu, cpu_callin_map)) 248 while (!cpu_isset(cpu, cpu_callin_map))
249 udelay(100); 249 udelay(100);
250 250
251 cpu_set(cpu, cpu_online_map); 251 set_cpu_online(cpu, true);
252 252
253 return 0; 253 return 0;
254} 254}
@@ -320,13 +320,12 @@ void flush_tlb_mm(struct mm_struct *mm)
320 if ((atomic_read(&mm->mm_users) != 1) || (current->mm != mm)) { 320 if ((atomic_read(&mm->mm_users) != 1) || (current->mm != mm)) {
321 smp_on_other_tlbs(flush_tlb_mm_ipi, mm); 321 smp_on_other_tlbs(flush_tlb_mm_ipi, mm);
322 } else { 322 } else {
323 cpumask_t mask = cpu_online_map;
324 unsigned int cpu; 323 unsigned int cpu;
325 324
326 cpu_clear(smp_processor_id(), mask); 325 for_each_online_cpu(cpu) {
327 for_each_cpu_mask(cpu, mask) 326 if (cpu != smp_processor_id() && cpu_context(cpu, mm))
328 if (cpu_context(cpu, mm))
329 cpu_context(cpu, mm) = 0; 327 cpu_context(cpu, mm) = 0;
328 }
330 } 329 }
331 local_flush_tlb_mm(mm); 330 local_flush_tlb_mm(mm);
332 331
@@ -360,13 +359,12 @@ void flush_tlb_range(struct vm_area_struct *vma, unsigned long start, unsigned l
360 359
361 smp_on_other_tlbs(flush_tlb_range_ipi, &fd); 360 smp_on_other_tlbs(flush_tlb_range_ipi, &fd);
362 } else { 361 } else {
363 cpumask_t mask = cpu_online_map;
364 unsigned int cpu; 362 unsigned int cpu;
365 363
366 cpu_clear(smp_processor_id(), mask); 364 for_each_online_cpu(cpu) {
367 for_each_cpu_mask(cpu, mask) 365 if (cpu != smp_processor_id() && cpu_context(cpu, mm))
368 if (cpu_context(cpu, mm))
369 cpu_context(cpu, mm) = 0; 366 cpu_context(cpu, mm) = 0;
367 }
370 } 368 }
371 local_flush_tlb_range(vma, start, end); 369 local_flush_tlb_range(vma, start, end);
372 preempt_enable(); 370 preempt_enable();
@@ -407,13 +405,12 @@ void flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
407 405
408 smp_on_other_tlbs(flush_tlb_page_ipi, &fd); 406 smp_on_other_tlbs(flush_tlb_page_ipi, &fd);
409 } else { 407 } else {
410 cpumask_t mask = cpu_online_map;
411 unsigned int cpu; 408 unsigned int cpu;
412 409
413 cpu_clear(smp_processor_id(), mask); 410 for_each_online_cpu(cpu) {
414 for_each_cpu_mask(cpu, mask) 411 if (cpu != smp_processor_id() && cpu_context(cpu, vma->vm_mm))
415 if (cpu_context(cpu, vma->vm_mm))
416 cpu_context(cpu, vma->vm_mm) = 0; 412 cpu_context(cpu, vma->vm_mm) = 0;
413 }
417 } 414 }
418 local_flush_tlb_page(vma, page); 415 local_flush_tlb_page(vma, page);
419 preempt_enable(); 416 preempt_enable();
diff --git a/arch/mips/kernel/smtc.c b/arch/mips/kernel/smtc.c
index c4f75bbc0bd6..f5dd38f1d015 100644
--- a/arch/mips/kernel/smtc.c
+++ b/arch/mips/kernel/smtc.c
@@ -291,7 +291,7 @@ static void smtc_configure_tlb(void)
291 * possibly leave some TCs/VPEs as "slave" processors. 291 * possibly leave some TCs/VPEs as "slave" processors.
292 * 292 *
293 * Use c0_MVPConf0 to find out how many TCs are available, setting up 293 * Use c0_MVPConf0 to find out how many TCs are available, setting up
294 * cpu_possible_map and the logical/physical mappings. 294 * cpu_possible_mask and the logical/physical mappings.
295 */ 295 */
296 296
297int __init smtc_build_cpu_map(int start_cpu_slot) 297int __init smtc_build_cpu_map(int start_cpu_slot)
diff --git a/arch/mips/mm/c-octeon.c b/arch/mips/mm/c-octeon.c
index 1f9ca07f53c8..47037ec5589b 100644
--- a/arch/mips/mm/c-octeon.c
+++ b/arch/mips/mm/c-octeon.c
@@ -80,9 +80,9 @@ static void octeon_flush_icache_all_cores(struct vm_area_struct *vma)
80 if (vma) 80 if (vma)
81 mask = *mm_cpumask(vma->vm_mm); 81 mask = *mm_cpumask(vma->vm_mm);
82 else 82 else
83 mask = cpu_online_map; 83 mask = *cpu_online_mask;
84 cpu_clear(cpu, mask); 84 cpumask_clear_cpu(cpu, &mask);
85 for_each_cpu_mask(cpu, mask) 85 for_each_cpu(cpu, &mask)
86 octeon_send_ipi_single(cpu, SMP_ICACHE_FLUSH); 86 octeon_send_ipi_single(cpu, SMP_ICACHE_FLUSH);
87 87
88 preempt_enable(); 88 preempt_enable();
diff --git a/arch/mips/mm/dma-default.c b/arch/mips/mm/dma-default.c
index 46084912e588..3fab2046c8a4 100644
--- a/arch/mips/mm/dma-default.c
+++ b/arch/mips/mm/dma-default.c
@@ -98,7 +98,7 @@ void *dma_alloc_noncoherent(struct device *dev, size_t size,
98EXPORT_SYMBOL(dma_alloc_noncoherent); 98EXPORT_SYMBOL(dma_alloc_noncoherent);
99 99
100static void *mips_dma_alloc_coherent(struct device *dev, size_t size, 100static void *mips_dma_alloc_coherent(struct device *dev, size_t size,
101 dma_addr_t * dma_handle, gfp_t gfp) 101 dma_addr_t * dma_handle, gfp_t gfp, struct dma_attrs *attrs)
102{ 102{
103 void *ret; 103 void *ret;
104 104
@@ -132,7 +132,7 @@ void dma_free_noncoherent(struct device *dev, size_t size, void *vaddr,
132EXPORT_SYMBOL(dma_free_noncoherent); 132EXPORT_SYMBOL(dma_free_noncoherent);
133 133
134static void mips_dma_free_coherent(struct device *dev, size_t size, void *vaddr, 134static void mips_dma_free_coherent(struct device *dev, size_t size, void *vaddr,
135 dma_addr_t dma_handle) 135 dma_addr_t dma_handle, struct dma_attrs *attrs)
136{ 136{
137 unsigned long addr = (unsigned long) vaddr; 137 unsigned long addr = (unsigned long) vaddr;
138 int order = get_order(size); 138 int order = get_order(size);
@@ -323,8 +323,8 @@ void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
323EXPORT_SYMBOL(dma_cache_sync); 323EXPORT_SYMBOL(dma_cache_sync);
324 324
325static struct dma_map_ops mips_default_dma_map_ops = { 325static struct dma_map_ops mips_default_dma_map_ops = {
326 .alloc_coherent = mips_dma_alloc_coherent, 326 .alloc = mips_dma_alloc_coherent,
327 .free_coherent = mips_dma_free_coherent, 327 .free = mips_dma_free_coherent,
328 .map_page = mips_dma_map_page, 328 .map_page = mips_dma_map_page,
329 .unmap_page = mips_dma_unmap_page, 329 .unmap_page = mips_dma_unmap_page,
330 .map_sg = mips_dma_map_sg, 330 .map_sg = mips_dma_map_sg,
diff --git a/arch/mips/netlogic/common/smp.c b/arch/mips/netlogic/common/smp.c
index db17f49886c2..fab316de57e9 100644
--- a/arch/mips/netlogic/common/smp.c
+++ b/arch/mips/netlogic/common/smp.c
@@ -165,7 +165,7 @@ void __init nlm_smp_setup(void)
165 cpu_set(boot_cpu, phys_cpu_present_map); 165 cpu_set(boot_cpu, phys_cpu_present_map);
166 __cpu_number_map[boot_cpu] = 0; 166 __cpu_number_map[boot_cpu] = 0;
167 __cpu_logical_map[0] = boot_cpu; 167 __cpu_logical_map[0] = boot_cpu;
168 cpu_set(0, cpu_possible_map); 168 set_cpu_possible(0, true);
169 169
170 num_cpus = 1; 170 num_cpus = 1;
171 for (i = 0; i < NR_CPUS; i++) { 171 for (i = 0; i < NR_CPUS; i++) {
@@ -177,14 +177,14 @@ void __init nlm_smp_setup(void)
177 cpu_set(i, phys_cpu_present_map); 177 cpu_set(i, phys_cpu_present_map);
178 __cpu_number_map[i] = num_cpus; 178 __cpu_number_map[i] = num_cpus;
179 __cpu_logical_map[num_cpus] = i; 179 __cpu_logical_map[num_cpus] = i;
180 cpu_set(num_cpus, cpu_possible_map); 180 set_cpu_possible(num_cpus, true);
181 ++num_cpus; 181 ++num_cpus;
182 } 182 }
183 } 183 }
184 184
185 pr_info("Phys CPU present map: %lx, possible map %lx\n", 185 pr_info("Phys CPU present map: %lx, possible map %lx\n",
186 (unsigned long)phys_cpu_present_map.bits[0], 186 (unsigned long)phys_cpu_present_map.bits[0],
187 (unsigned long)cpu_possible_map.bits[0]); 187 (unsigned long)cpumask_bits(cpu_possible_mask)[0]);
188 188
189 pr_info("Detected %i Slave CPU(s)\n", num_cpus); 189 pr_info("Detected %i Slave CPU(s)\n", num_cpus);
190 nlm_set_nmi_handler(nlm_boot_secondary_cpus); 190 nlm_set_nmi_handler(nlm_boot_secondary_cpus);
diff --git a/arch/mips/pmc-sierra/yosemite/smp.c b/arch/mips/pmc-sierra/yosemite/smp.c
index 2608752898c0..b71fae231049 100644
--- a/arch/mips/pmc-sierra/yosemite/smp.c
+++ b/arch/mips/pmc-sierra/yosemite/smp.c
@@ -146,7 +146,7 @@ static void __cpuinit yos_boot_secondary(int cpu, struct task_struct *idle)
146} 146}
147 147
148/* 148/*
149 * Detect available CPUs, populate cpu_possible_map before smp_init 149 * Detect available CPUs, populate cpu_possible_mask before smp_init
150 * 150 *
151 * We don't want to start the secondary CPU yet nor do we have a nice probing 151 * We don't want to start the secondary CPU yet nor do we have a nice probing
152 * feature in PMON so we just assume presence of the secondary core. 152 * feature in PMON so we just assume presence of the secondary core.
@@ -155,10 +155,10 @@ static void __init yos_smp_setup(void)
155{ 155{
156 int i; 156 int i;
157 157
158 cpus_clear(cpu_possible_map); 158 init_cpu_possible(cpu_none_mask);
159 159
160 for (i = 0; i < 2; i++) { 160 for (i = 0; i < 2; i++) {
161 cpu_set(i, cpu_possible_map); 161 set_cpu_possible(i, true);
162 __cpu_number_map[i] = i; 162 __cpu_number_map[i] = i;
163 __cpu_logical_map[i] = i; 163 __cpu_logical_map[i] = i;
164 } 164 }
@@ -169,7 +169,7 @@ static void __init yos_prepare_cpus(unsigned int max_cpus)
169 /* 169 /*
170 * Be paranoid. Enable the IPI only if we're really about to go SMP. 170 * Be paranoid. Enable the IPI only if we're really about to go SMP.
171 */ 171 */
172 if (cpus_weight(cpu_possible_map)) 172 if (num_possible_cpus())
173 set_c0_status(STATUSF_IP5); 173 set_c0_status(STATUSF_IP5);
174} 174}
175 175
diff --git a/arch/mips/sgi-ip27/ip27-smp.c b/arch/mips/sgi-ip27/ip27-smp.c
index c6851df9ab74..735b43bf8f82 100644
--- a/arch/mips/sgi-ip27/ip27-smp.c
+++ b/arch/mips/sgi-ip27/ip27-smp.c
@@ -76,7 +76,7 @@ static int do_cpumask(cnodeid_t cnode, nasid_t nasid, int highest)
76 /* Only let it join in if it's marked enabled */ 76 /* Only let it join in if it's marked enabled */
77 if ((acpu->cpu_info.flags & KLINFO_ENABLE) && 77 if ((acpu->cpu_info.flags & KLINFO_ENABLE) &&
78 (tot_cpus_found != NR_CPUS)) { 78 (tot_cpus_found != NR_CPUS)) {
79 cpu_set(cpuid, cpu_possible_map); 79 set_cpu_possible(cpuid, true);
80 alloc_cpupda(cpuid, tot_cpus_found); 80 alloc_cpupda(cpuid, tot_cpus_found);
81 cpus_found++; 81 cpus_found++;
82 tot_cpus_found++; 82 tot_cpus_found++;
diff --git a/arch/mips/sibyte/bcm1480/smp.c b/arch/mips/sibyte/bcm1480/smp.c
index d667875be564..de88e22694a0 100644
--- a/arch/mips/sibyte/bcm1480/smp.c
+++ b/arch/mips/sibyte/bcm1480/smp.c
@@ -138,7 +138,7 @@ static void __cpuinit bcm1480_boot_secondary(int cpu, struct task_struct *idle)
138 138
139/* 139/*
140 * Use CFE to find out how many CPUs are available, setting up 140 * Use CFE to find out how many CPUs are available, setting up
141 * cpu_possible_map and the logical/physical mappings. 141 * cpu_possible_mask and the logical/physical mappings.
142 * XXXKW will the boot CPU ever not be physical 0? 142 * XXXKW will the boot CPU ever not be physical 0?
143 * 143 *
144 * Common setup before any secondaries are started 144 * Common setup before any secondaries are started
@@ -147,14 +147,13 @@ static void __init bcm1480_smp_setup(void)
147{ 147{
148 int i, num; 148 int i, num;
149 149
150 cpus_clear(cpu_possible_map); 150 init_cpu_possible(cpumask_of(0));
151 cpu_set(0, cpu_possible_map);
152 __cpu_number_map[0] = 0; 151 __cpu_number_map[0] = 0;
153 __cpu_logical_map[0] = 0; 152 __cpu_logical_map[0] = 0;
154 153
155 for (i = 1, num = 0; i < NR_CPUS; i++) { 154 for (i = 1, num = 0; i < NR_CPUS; i++) {
156 if (cfe_cpu_stop(i) == 0) { 155 if (cfe_cpu_stop(i) == 0) {
157 cpu_set(i, cpu_possible_map); 156 set_cpu_possible(i, true);
158 __cpu_number_map[i] = ++num; 157 __cpu_number_map[i] = ++num;
159 __cpu_logical_map[num] = i; 158 __cpu_logical_map[num] = i;
160 } 159 }
diff --git a/arch/mips/sibyte/sb1250/smp.c b/arch/mips/sibyte/sb1250/smp.c
index 38e7f6bd7922..285cfef4ebc0 100644
--- a/arch/mips/sibyte/sb1250/smp.c
+++ b/arch/mips/sibyte/sb1250/smp.c
@@ -126,7 +126,7 @@ static void __cpuinit sb1250_boot_secondary(int cpu, struct task_struct *idle)
126 126
127/* 127/*
128 * Use CFE to find out how many CPUs are available, setting up 128 * Use CFE to find out how many CPUs are available, setting up
129 * cpu_possible_map and the logical/physical mappings. 129 * cpu_possible_mask and the logical/physical mappings.
130 * XXXKW will the boot CPU ever not be physical 0? 130 * XXXKW will the boot CPU ever not be physical 0?
131 * 131 *
132 * Common setup before any secondaries are started 132 * Common setup before any secondaries are started
@@ -135,14 +135,13 @@ static void __init sb1250_smp_setup(void)
135{ 135{
136 int i, num; 136 int i, num;
137 137
138 cpus_clear(cpu_possible_map); 138 init_cpu_possible(cpumask_of(0));
139 cpu_set(0, cpu_possible_map);
140 __cpu_number_map[0] = 0; 139 __cpu_number_map[0] = 0;
141 __cpu_logical_map[0] = 0; 140 __cpu_logical_map[0] = 0;
142 141
143 for (i = 1, num = 0; i < NR_CPUS; i++) { 142 for (i = 1, num = 0; i < NR_CPUS; i++) {
144 if (cfe_cpu_stop(i) == 0) { 143 if (cfe_cpu_stop(i) == 0) {
145 cpu_set(i, cpu_possible_map); 144 set_cpu_possible(i, true);
146 __cpu_number_map[i] = ++num; 145 __cpu_number_map[i] = ++num;
147 __cpu_logical_map[num] = i; 146 __cpu_logical_map[num] = i;
148 } 147 }
diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
index 3ae56073cc3d..6c6defc24619 100644
--- a/arch/parisc/include/asm/atomic.h
+++ b/arch/parisc/include/asm/atomic.h
@@ -6,6 +6,7 @@
6#define _ASM_PARISC_ATOMIC_H_ 6#define _ASM_PARISC_ATOMIC_H_
7 7
8#include <linux/types.h> 8#include <linux/types.h>
9#include <asm/cmpxchg.h>
9 10
10/* 11/*
11 * Atomic operations that C can't guarantee us. Useful for 12 * Atomic operations that C can't guarantee us. Useful for
@@ -48,112 +49,6 @@ extern arch_spinlock_t __atomic_hash[ATOMIC_HASH_SIZE] __lock_aligned;
48# define _atomic_spin_unlock_irqrestore(l,f) do { local_irq_restore(f); } while (0) 49# define _atomic_spin_unlock_irqrestore(l,f) do { local_irq_restore(f); } while (0)
49#endif 50#endif
50 51
51/* This should get optimized out since it's never called.
52** Or get a link error if xchg is used "wrong".
53*/
54extern void __xchg_called_with_bad_pointer(void);
55
56
57/* __xchg32/64 defined in arch/parisc/lib/bitops.c */
58extern unsigned long __xchg8(char, char *);
59extern unsigned long __xchg32(int, int *);
60#ifdef CONFIG_64BIT
61extern unsigned long __xchg64(unsigned long, unsigned long *);
62#endif
63
64/* optimizer better get rid of switch since size is a constant */
65static __inline__ unsigned long
66__xchg(unsigned long x, __volatile__ void * ptr, int size)
67{
68 switch(size) {
69#ifdef CONFIG_64BIT
70 case 8: return __xchg64(x,(unsigned long *) ptr);
71#endif
72 case 4: return __xchg32((int) x, (int *) ptr);
73 case 1: return __xchg8((char) x, (char *) ptr);
74 }
75 __xchg_called_with_bad_pointer();
76 return x;
77}
78
79
80/*
81** REVISIT - Abandoned use of LDCW in xchg() for now:
82** o need to test sizeof(*ptr) to avoid clearing adjacent bytes
83** o and while we are at it, could CONFIG_64BIT code use LDCD too?
84**
85** if (__builtin_constant_p(x) && (x == NULL))
86** if (((unsigned long)p & 0xf) == 0)
87** return __ldcw(p);
88*/
89#define xchg(ptr,x) \
90 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
91
92
93#define __HAVE_ARCH_CMPXCHG 1
94
95/* bug catcher for when unsupported size is used - won't link */
96extern void __cmpxchg_called_with_bad_pointer(void);
97
98/* __cmpxchg_u32/u64 defined in arch/parisc/lib/bitops.c */
99extern unsigned long __cmpxchg_u32(volatile unsigned int *m, unsigned int old, unsigned int new_);
100extern unsigned long __cmpxchg_u64(volatile unsigned long *ptr, unsigned long old, unsigned long new_);
101
102/* don't worry...optimizer will get rid of most of this */
103static __inline__ unsigned long
104__cmpxchg(volatile void *ptr, unsigned long old, unsigned long new_, int size)
105{
106 switch(size) {
107#ifdef CONFIG_64BIT
108 case 8: return __cmpxchg_u64((unsigned long *)ptr, old, new_);
109#endif
110 case 4: return __cmpxchg_u32((unsigned int *)ptr, (unsigned int) old, (unsigned int) new_);
111 }
112 __cmpxchg_called_with_bad_pointer();
113 return old;
114}
115
116#define cmpxchg(ptr,o,n) \
117 ({ \
118 __typeof__(*(ptr)) _o_ = (o); \
119 __typeof__(*(ptr)) _n_ = (n); \
120 (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \
121 (unsigned long)_n_, sizeof(*(ptr))); \
122 })
123
124#include <asm-generic/cmpxchg-local.h>
125
126static inline unsigned long __cmpxchg_local(volatile void *ptr,
127 unsigned long old,
128 unsigned long new_, int size)
129{
130 switch (size) {
131#ifdef CONFIG_64BIT
132 case 8: return __cmpxchg_u64((unsigned long *)ptr, old, new_);
133#endif
134 case 4: return __cmpxchg_u32(ptr, old, new_);
135 default:
136 return __cmpxchg_local_generic(ptr, old, new_, size);
137 }
138}
139
140/*
141 * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
142 * them available.
143 */
144#define cmpxchg_local(ptr, o, n) \
145 ((__typeof__(*(ptr)))__cmpxchg_local((ptr), (unsigned long)(o), \
146 (unsigned long)(n), sizeof(*(ptr))))
147#ifdef CONFIG_64BIT
148#define cmpxchg64_local(ptr, o, n) \
149 ({ \
150 BUILD_BUG_ON(sizeof(*(ptr)) != 8); \
151 cmpxchg_local((ptr), (o), (n)); \
152 })
153#else
154#define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
155#endif
156
157/* 52/*
158 * Note that we need not lock read accesses - aligned word writes/reads 53 * Note that we need not lock read accesses - aligned word writes/reads
159 * are atomic, so a reader never sees inconsistent values. 54 * are atomic, so a reader never sees inconsistent values.
diff --git a/arch/parisc/include/asm/cmpxchg.h b/arch/parisc/include/asm/cmpxchg.h
new file mode 100644
index 000000000000..dbd13354ec41
--- /dev/null
+++ b/arch/parisc/include/asm/cmpxchg.h
@@ -0,0 +1,116 @@
1/*
2 * forked from parisc asm/atomic.h which was:
3 * Copyright (C) 2000 Philipp Rumpf <prumpf@tux.org>
4 * Copyright (C) 2006 Kyle McMartin <kyle@parisc-linux.org>
5 */
6
7#ifndef _ASM_PARISC_CMPXCHG_H_
8#define _ASM_PARISC_CMPXCHG_H_
9
10/* This should get optimized out since it's never called.
11** Or get a link error if xchg is used "wrong".
12*/
13extern void __xchg_called_with_bad_pointer(void);
14
15/* __xchg32/64 defined in arch/parisc/lib/bitops.c */
16extern unsigned long __xchg8(char, char *);
17extern unsigned long __xchg32(int, int *);
18#ifdef CONFIG_64BIT
19extern unsigned long __xchg64(unsigned long, unsigned long *);
20#endif
21
22/* optimizer better get rid of switch since size is a constant */
23static inline unsigned long
24__xchg(unsigned long x, __volatile__ void *ptr, int size)
25{
26 switch (size) {
27#ifdef CONFIG_64BIT
28 case 8: return __xchg64(x, (unsigned long *) ptr);
29#endif
30 case 4: return __xchg32((int) x, (int *) ptr);
31 case 1: return __xchg8((char) x, (char *) ptr);
32 }
33 __xchg_called_with_bad_pointer();
34 return x;
35}
36
37/*
38** REVISIT - Abandoned use of LDCW in xchg() for now:
39** o need to test sizeof(*ptr) to avoid clearing adjacent bytes
40** o and while we are at it, could CONFIG_64BIT code use LDCD too?
41**
42** if (__builtin_constant_p(x) && (x == NULL))
43** if (((unsigned long)p & 0xf) == 0)
44** return __ldcw(p);
45*/
46#define xchg(ptr, x) \
47 ((__typeof__(*(ptr)))__xchg((unsigned long)(x), (ptr), sizeof(*(ptr))))
48
49#define __HAVE_ARCH_CMPXCHG 1
50
51/* bug catcher for when unsupported size is used - won't link */
52extern void __cmpxchg_called_with_bad_pointer(void);
53
54/* __cmpxchg_u32/u64 defined in arch/parisc/lib/bitops.c */
55extern unsigned long __cmpxchg_u32(volatile unsigned int *m, unsigned int old,
56 unsigned int new_);
57extern unsigned long __cmpxchg_u64(volatile unsigned long *ptr,
58 unsigned long old, unsigned long new_);
59
60/* don't worry...optimizer will get rid of most of this */
61static inline unsigned long
62__cmpxchg(volatile void *ptr, unsigned long old, unsigned long new_, int size)
63{
64 switch (size) {
65#ifdef CONFIG_64BIT
66 case 8: return __cmpxchg_u64((unsigned long *)ptr, old, new_);
67#endif
68 case 4: return __cmpxchg_u32((unsigned int *)ptr,
69 (unsigned int)old, (unsigned int)new_);
70 }
71 __cmpxchg_called_with_bad_pointer();
72 return old;
73}
74
75#define cmpxchg(ptr, o, n) \
76({ \
77 __typeof__(*(ptr)) _o_ = (o); \
78 __typeof__(*(ptr)) _n_ = (n); \
79 (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \
80 (unsigned long)_n_, sizeof(*(ptr))); \
81})
82
83#include <asm-generic/cmpxchg-local.h>
84
85static inline unsigned long __cmpxchg_local(volatile void *ptr,
86 unsigned long old,
87 unsigned long new_, int size)
88{
89 switch (size) {
90#ifdef CONFIG_64BIT
91 case 8: return __cmpxchg_u64((unsigned long *)ptr, old, new_);
92#endif
93 case 4: return __cmpxchg_u32(ptr, old, new_);
94 default:
95 return __cmpxchg_local_generic(ptr, old, new_, size);
96 }
97}
98
99/*
100 * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
101 * them available.
102 */
103#define cmpxchg_local(ptr, o, n) \
104 ((__typeof__(*(ptr)))__cmpxchg_local((ptr), (unsigned long)(o), \
105 (unsigned long)(n), sizeof(*(ptr))))
106#ifdef CONFIG_64BIT
107#define cmpxchg64_local(ptr, o, n) \
108({ \
109 BUILD_BUG_ON(sizeof(*(ptr)) != 8); \
110 cmpxchg_local((ptr), (o), (n)); \
111})
112#else
113#define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
114#endif
115
116#endif /* _ASM_PARISC_CMPXCHG_H_ */
diff --git a/arch/parisc/include/asm/hardware.h b/arch/parisc/include/asm/hardware.h
index 4e9626836bab..d1d864b81bae 100644
--- a/arch/parisc/include/asm/hardware.h
+++ b/arch/parisc/include/asm/hardware.h
@@ -2,7 +2,6 @@
2#define _PARISC_HARDWARE_H 2#define _PARISC_HARDWARE_H
3 3
4#include <linux/mod_devicetable.h> 4#include <linux/mod_devicetable.h>
5#include <asm/pdc.h>
6 5
7#define HWTYPE_ANY_ID PA_HWTYPE_ANY_ID 6#define HWTYPE_ANY_ID PA_HWTYPE_ANY_ID
8#define HVERSION_ANY_ID PA_HVERSION_ANY_ID 7#define HVERSION_ANY_ID PA_HVERSION_ANY_ID
@@ -95,12 +94,14 @@ struct bc_module {
95#define HPHW_MC 15 94#define HPHW_MC 15
96#define HPHW_FAULTY 31 95#define HPHW_FAULTY 31
97 96
97struct parisc_device_id;
98 98
99/* hardware.c: */ 99/* hardware.c: */
100extern const char *parisc_hardware_description(struct parisc_device_id *id); 100extern const char *parisc_hardware_description(struct parisc_device_id *id);
101extern enum cpu_type parisc_get_cpu_type(unsigned long hversion); 101extern enum cpu_type parisc_get_cpu_type(unsigned long hversion);
102 102
103struct pci_dev; 103struct pci_dev;
104struct hardware_path;
104 105
105/* drivers.c: */ 106/* drivers.c: */
106extern struct parisc_device *alloc_pa_dev(unsigned long hpa, 107extern struct parisc_device *alloc_pa_dev(unsigned long hpa,
diff --git a/arch/parisc/include/asm/page.h b/arch/parisc/include/asm/page.h
index a84cc1f925f6..4e0e7dbf0f3f 100644
--- a/arch/parisc/include/asm/page.h
+++ b/arch/parisc/include/asm/page.h
@@ -160,5 +160,11 @@ extern int npmem_ranges;
160 160
161#include <asm-generic/memory_model.h> 161#include <asm-generic/memory_model.h>
162#include <asm-generic/getorder.h> 162#include <asm-generic/getorder.h>
163#include <asm/pdc.h>
164
165#define PAGE0 ((struct zeropage *)__PAGE_OFFSET)
166
167/* DEFINITION OF THE ZERO-PAGE (PAG0) */
168/* based on work by Jason Eckhardt (jason@equator.com) */
163 169
164#endif /* _PARISC_PAGE_H */ 170#endif /* _PARISC_PAGE_H */
diff --git a/arch/parisc/include/asm/pdc.h b/arch/parisc/include/asm/pdc.h
index 4ca510b3c6f8..7f0f2d23059d 100644
--- a/arch/parisc/include/asm/pdc.h
+++ b/arch/parisc/include/asm/pdc.h
@@ -343,8 +343,6 @@
343 343
344#ifdef __KERNEL__ 344#ifdef __KERNEL__
345 345
346#include <asm/page.h> /* for __PAGE_OFFSET */
347
348extern int pdc_type; 346extern int pdc_type;
349 347
350/* Values for pdc_type */ 348/* Values for pdc_type */
@@ -677,11 +675,6 @@ static inline char * os_id_to_string(u16 os_id) {
677 675
678#endif /* __KERNEL__ */ 676#endif /* __KERNEL__ */
679 677
680#define PAGE0 ((struct zeropage *)__PAGE_OFFSET)
681
682/* DEFINITION OF THE ZERO-PAGE (PAG0) */
683/* based on work by Jason Eckhardt (jason@equator.com) */
684
685/* flags of the device_path */ 678/* flags of the device_path */
686#define PF_AUTOBOOT 0x80 679#define PF_AUTOBOOT 0x80
687#define PF_AUTOSEARCH 0x40 680#define PF_AUTOSEARCH 0x40
diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
index 22dadeb58695..ee99f2339356 100644
--- a/arch/parisc/include/asm/pgtable.h
+++ b/arch/parisc/include/asm/pgtable.h
@@ -44,6 +44,8 @@ struct vm_area_struct;
44 44
45#endif /* !__ASSEMBLY__ */ 45#endif /* !__ASSEMBLY__ */
46 46
47#include <asm/page.h>
48
47#define pte_ERROR(e) \ 49#define pte_ERROR(e) \
48 printk("%s:%d: bad pte %08lx.\n", __FILE__, __LINE__, pte_val(e)) 50 printk("%s:%d: bad pte %08lx.\n", __FILE__, __LINE__, pte_val(e))
49#define pmd_ERROR(e) \ 51#define pmd_ERROR(e) \
diff --git a/arch/parisc/include/asm/spinlock.h b/arch/parisc/include/asm/spinlock.h
index 804aa28ab1d6..3516e0b27044 100644
--- a/arch/parisc/include/asm/spinlock.h
+++ b/arch/parisc/include/asm/spinlock.h
@@ -1,6 +1,8 @@
1#ifndef __ASM_SPINLOCK_H 1#ifndef __ASM_SPINLOCK_H
2#define __ASM_SPINLOCK_H 2#define __ASM_SPINLOCK_H
3 3
4#include <asm/barrier.h>
5#include <asm/ldcw.h>
4#include <asm/processor.h> 6#include <asm/processor.h>
5#include <asm/spinlock_types.h> 7#include <asm/spinlock_types.h>
6 8
diff --git a/arch/parisc/kernel/pdc_cons.c b/arch/parisc/kernel/pdc_cons.c
index 4f004596a6e7..47341aa208f2 100644
--- a/arch/parisc/kernel/pdc_cons.c
+++ b/arch/parisc/kernel/pdc_cons.c
@@ -50,6 +50,7 @@
50#include <linux/init.h> 50#include <linux/init.h>
51#include <linux/major.h> 51#include <linux/major.h>
52#include <linux/tty.h> 52#include <linux/tty.h>
53#include <asm/page.h> /* for PAGE0 */
53#include <asm/pdc.h> /* for iodc_call() proto and friends */ 54#include <asm/pdc.h> /* for iodc_call() proto and friends */
54 55
55static DEFINE_SPINLOCK(pdc_console_lock); 56static DEFINE_SPINLOCK(pdc_console_lock);
@@ -104,7 +105,7 @@ static int pdc_console_tty_open(struct tty_struct *tty, struct file *filp)
104 105
105static void pdc_console_tty_close(struct tty_struct *tty, struct file *filp) 106static void pdc_console_tty_close(struct tty_struct *tty, struct file *filp)
106{ 107{
107 if (!tty->count) { 108 if (tty->count == 1) {
108 del_timer_sync(&pdc_console_timer); 109 del_timer_sync(&pdc_console_timer);
109 tty_port_tty_set(&tty_port, NULL); 110 tty_port_tty_set(&tty_port, NULL);
110 } 111 }
diff --git a/arch/parisc/kernel/time.c b/arch/parisc/kernel/time.c
index 7c0774397b89..70e105d62423 100644
--- a/arch/parisc/kernel/time.c
+++ b/arch/parisc/kernel/time.c
@@ -29,6 +29,7 @@
29#include <asm/uaccess.h> 29#include <asm/uaccess.h>
30#include <asm/io.h> 30#include <asm/io.h>
31#include <asm/irq.h> 31#include <asm/irq.h>
32#include <asm/page.h>
32#include <asm/param.h> 33#include <asm/param.h>
33#include <asm/pdc.h> 34#include <asm/pdc.h>
34#include <asm/led.h> 35#include <asm/led.h>
diff --git a/arch/powerpc/boot/dts/fsl/pq3-mpic-message-B.dtsi b/arch/powerpc/boot/dts/fsl/pq3-mpic-message-B.dtsi
new file mode 100644
index 000000000000..1cf0b77b1efe
--- /dev/null
+++ b/arch/powerpc/boot/dts/fsl/pq3-mpic-message-B.dtsi
@@ -0,0 +1,43 @@
1/*
2 * PQ3 MPIC Message (Group B) device tree stub [ controller @ offset 0x42400 ]
3 *
4 * Copyright 2012 Freescale Semiconductor Inc.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of Freescale Semiconductor nor the
14 * names of its contributors may be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 *
18 * ALTERNATIVELY, this software may be distributed under the terms of the
19 * GNU General Public License ("GPL") as published by the Free Software
20 * Foundation, either version 2 of that License or (at your option) any
21 * later version.
22 *
23 * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
24 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
27 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35message@42400 {
36 compatible = "fsl,mpic-v3.1-msgr";
37 reg = <0x42400 0x200>;
38 interrupts = <
39 0xb4 2 0 0
40 0xb5 2 0 0
41 0xb6 2 0 0
42 0xb7 2 0 0>;
43};
diff --git a/arch/powerpc/boot/dts/fsl/pq3-mpic.dtsi b/arch/powerpc/boot/dts/fsl/pq3-mpic.dtsi
index fdedf7b1fe0f..71c30eb10056 100644
--- a/arch/powerpc/boot/dts/fsl/pq3-mpic.dtsi
+++ b/arch/powerpc/boot/dts/fsl/pq3-mpic.dtsi
@@ -53,6 +53,16 @@ timer@41100 {
53 3 0 3 0>; 53 3 0 3 0>;
54}; 54};
55 55
56message@41400 {
57 compatible = "fsl,mpic-v3.1-msgr";
58 reg = <0x41400 0x200>;
59 interrupts = <
60 0xb0 2 0 0
61 0xb1 2 0 0
62 0xb2 2 0 0
63 0xb3 2 0 0>;
64};
65
56msi@41600 { 66msi@41600 {
57 compatible = "fsl,mpic-msi"; 67 compatible = "fsl,mpic-msi";
58 reg = <0x41600 0x80>; 68 reg = <0x41600 0x80>;
diff --git a/arch/powerpc/boot/dts/p1020mbg-pc.dtsi b/arch/powerpc/boot/dts/p1020mbg-pc.dtsi
new file mode 100644
index 000000000000..a24699cfea9c
--- /dev/null
+++ b/arch/powerpc/boot/dts/p1020mbg-pc.dtsi
@@ -0,0 +1,151 @@
1/*
2 * P1020 MBG-PC Device Tree Source stub (no addresses or top-level ranges)
3 *
4 * Copyright 2012 Freescale Semiconductor Inc.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of Freescale Semiconductor nor the
14 * names of its contributors may be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 *
18 * ALTERNATIVELY, this software may be distributed under the terms of the
19 * GNU General Public License ("GPL") as published by the Free Software
20 * Foundation, either version 2 of that License or (at your option) any
21 * later version.
22 *
23 * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
24 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
27 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35&lbc {
36 nor@0,0 {
37 #address-cells = <1>;
38 #size-cells = <1>;
39 compatible = "cfi-flash";
40 reg = <0x0 0x0 0x4000000>;
41 bank-width = <2>;
42 device-width = <1>;
43
44 partition@0 {
45 /* 128KB for DTB Image */
46 reg = <0x0 0x00020000>;
47 label = "NOR DTB Image";
48 };
49
50 partition@20000 {
51 /* 3.875 MB for Linux Kernel Image */
52 reg = <0x00020000 0x003e0000>;
53 label = "NOR Linux Kernel Image";
54 };
55
56 partition@400000 {
57 /* 58MB for Root file System */
58 reg = <0x00400000 0x03a00000>;
59 label = "NOR Root File System";
60 };
61
62 partition@3e00000 {
63 /* This location must not be altered */
64 /* 1M for Vitesse 7385 Switch firmware */
65 reg = <0x3e00000 0x00100000>;
66 label = "NOR Vitesse-7385 Firmware";
67 read-only;
68 };
69
70 partition@3f00000 {
71 /* This location must not be altered */
72 /* 512KB for u-boot Bootloader Image */
73 /* 512KB for u-boot Environment Variables */
74 reg = <0x03f00000 0x00100000>;
75 label = "NOR U-Boot Image";
76 read-only;
77 };
78 };
79
80 L2switch@2,0 {
81 #address-cells = <1>;
82 #size-cells = <1>;
83 compatible = "vitesse-7385";
84 reg = <0x2 0x0 0x20000>;
85 };
86};
87
88&soc {
89 i2c@3000 {
90 rtc@68 {
91 compatible = "dallas,ds1339";
92 reg = <0x68>;
93 };
94 };
95
96 mdio@24000 {
97 phy0: ethernet-phy@0 {
98 interrupts = <3 1 0 0>;
99 reg = <0x0>;
100 };
101 phy1: ethernet-phy@1 {
102 interrupts = <2 1 0 0>;
103 reg = <0x1>;
104 };
105 };
106
107 mdio@25000 {
108 tbi1: tbi-phy@11 {
109 reg = <0x11>;
110 device_type = "tbi-phy";
111 };
112 };
113
114 mdio@26000 {
115 tbi2: tbi-phy@11 {
116 reg = <0x11>;
117 device_type = "tbi-phy";
118 };
119 };
120
121 enet0: ethernet@b0000 {
122 fixed-link = <1 1 1000 0 0>;
123 phy-connection-type = "rgmii-id";
124 };
125
126 enet1: ethernet@b1000 {
127 phy-handle = <&phy0>;
128 tbi-handle = <&tbi1>;
129 phy-connection-type = "sgmii";
130 };
131
132 enet2: ethernet@b2000 {
133 phy-handle = <&phy1>;
134 phy-connection-type = "rgmii-id";
135 };
136
137 usb@22000 {
138 phy_type = "ulpi";
139 };
140
141 /* USB2 is shared with localbus, so it must be disabled
142 by default. We can't put 'status = "disabled";' here
143 since U-Boot doesn't clear the status property when
144 it enables USB2. OTOH, U-Boot does create a new node
145 when there isn't any. So, just comment it out.
146 */
147 usb@23000 {
148 status = "disabled";
149 phy_type = "ulpi";
150 };
151};
diff --git a/arch/powerpc/boot/dts/p1020mbg-pc_32b.dts b/arch/powerpc/boot/dts/p1020mbg-pc_32b.dts
new file mode 100644
index 000000000000..ab8f076eae90
--- /dev/null
+++ b/arch/powerpc/boot/dts/p1020mbg-pc_32b.dts
@@ -0,0 +1,89 @@
1/*
2 * P1020 MBG-PC Device Tree Source (32-bit address map)
3 *
4 * Copyright 2012 Freescale Semiconductor Inc.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of Freescale Semiconductor nor the
14 * names of its contributors may be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 *
18 * ALTERNATIVELY, this software may be distributed under the terms of the
19 * GNU General Public License ("GPL") as published by the Free Software
20 * Foundation, either version 2 of that License or (at your option) any
21 * later version.
22 *
23 * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
24 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
27 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35/include/ "fsl/p1020si-pre.dtsi"
36/ {
37 model = "fsl,P1020MBG-PC";
38 compatible = "fsl,P1020MBG-PC";
39
40 memory {
41 device_type = "memory";
42 };
43
44 lbc: localbus@ffe05000 {
45 reg = <0x0 0xffe05000 0x0 0x1000>;
46
47 /* NOR and L2 switch */
48 ranges = <0x0 0x0 0x0 0xec000000 0x04000000
49 0x1 0x0 0x0 0xffa00000 0x00040000
50 0x2 0x0 0x0 0xffb00000 0x00020000>;
51 };
52
53 soc: soc@ffe00000 {
54 ranges = <0x0 0x0 0xffe00000 0x100000>;
55 };
56
57 pci0: pcie@ffe09000 {
58 reg = <0x0 0xffe09000 0x0 0x1000>;
59 ranges = <0x2000000 0x0 0xe0000000 0x0 0xa0000000 0x0 0x20000000
60 0x1000000 0x0 0x00000000 0x0 0xffc10000 0x0 0x10000>;
61 pcie@0 {
62 ranges = <0x2000000 0x0 0xe0000000
63 0x2000000 0x0 0xe0000000
64 0x0 0x20000000
65
66 0x1000000 0x0 0x0
67 0x1000000 0x0 0x0
68 0x0 0x100000>;
69 };
70 };
71
72 pci1: pcie@ffe0a000 {
73 reg = <0x0 0xffe0a000 0x0 0x1000>;
74 ranges = <0x2000000 0x0 0xe0000000 0x0 0x80000000 0x0 0x20000000
75 0x1000000 0x0 0x00000000 0x0 0xffc00000 0x0 0x10000>;
76 pcie@0 {
77 ranges = <0x2000000 0x0 0xe0000000
78 0x2000000 0x0 0xe0000000
79 0x0 0x20000000
80
81 0x1000000 0x0 0x0
82 0x1000000 0x0 0x0
83 0x0 0x100000>;
84 };
85 };
86};
87
88/include/ "p1020mbg-pc.dtsi"
89/include/ "fsl/p1020si-post.dtsi"
diff --git a/arch/powerpc/boot/dts/p1020mbg-pc_36b.dts b/arch/powerpc/boot/dts/p1020mbg-pc_36b.dts
new file mode 100644
index 000000000000..9e9f401419b1
--- /dev/null
+++ b/arch/powerpc/boot/dts/p1020mbg-pc_36b.dts
@@ -0,0 +1,89 @@
1/*
2 * P1020 MBG-PC Device Tree Source (36-bit address map)
3 *
4 * Copyright 2012 Freescale Semiconductor Inc.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of Freescale Semiconductor nor the
14 * names of its contributors may be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 *
18 * ALTERNATIVELY, this software may be distributed under the terms of the
19 * GNU General Public License ("GPL") as published by the Free Software
20 * Foundation, either version 2 of that License or (at your option) any
21 * later version.
22 *
23 * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
24 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
27 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35/include/ "fsl/p1020si-pre.dtsi"
36/ {
37 model = "fsl,P1020MBG-PC";
38 compatible = "fsl,P1020MBG-PC";
39
40 memory {
41 device_type = "memory";
42 };
43
44 lbc: localbus@fffe05000 {
45 reg = <0xf 0xffe05000 0x0 0x1000>;
46
47 /* NOR and L2 switch */
48 ranges = <0x0 0x0 0xf 0xec000000 0x04000000
49 0x1 0x0 0xf 0xffa00000 0x00040000
50 0x2 0x0 0xf 0xffb00000 0x00020000>;
51 };
52
53 soc: soc@fffe00000 {
54 ranges = <0x0 0xf 0xffe00000 0x100000>;
55 };
56
57 pci0: pcie@fffe09000 {
58 reg = <0xf 0xffe09000 0x0 0x1000>;
59 ranges = <0x2000000 0x0 0xe0000000 0xc 0x20000000 0x0 0x20000000
60 0x1000000 0x0 0x00000000 0xf 0xffc10000 0x0 0x10000>;
61 pcie@0 {
62 ranges = <0x2000000 0x0 0xe0000000
63 0x2000000 0x0 0xe0000000
64 0x0 0x20000000
65
66 0x1000000 0x0 0x0
67 0x1000000 0x0 0x0
68 0x0 0x100000>;
69 };
70 };
71
72 pci1: pcie@fffe0a000 {
73 reg = <0xf 0xffe0a000 0 0x1000>;
74 ranges = <0x2000000 0x0 0xe0000000 0xc 0x00000000 0x0 0x20000000
75 0x1000000 0x0 0x00000000 0xf 0xffc00000 0x0 0x10000>;
76 pcie@0 {
77 ranges = <0x2000000 0x0 0xe0000000
78 0x2000000 0x0 0xe0000000
79 0x0 0x20000000
80
81 0x1000000 0x0 0x0
82 0x1000000 0x0 0x0
83 0x0 0x100000>;
84 };
85 };
86};
87
88/include/ "p1020mbg-pc.dtsi"
89/include/ "fsl/p1020si-post.dtsi"
diff --git a/arch/powerpc/boot/dts/p1020utm-pc.dtsi b/arch/powerpc/boot/dts/p1020utm-pc.dtsi
new file mode 100644
index 000000000000..7ea85eabcc5c
--- /dev/null
+++ b/arch/powerpc/boot/dts/p1020utm-pc.dtsi
@@ -0,0 +1,140 @@
1/*
2 * P1020 UTM-PC Device Tree Source stub (no addresses or top-level ranges)
3 *
4 * Copyright 2012 Freescale Semiconductor Inc.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of Freescale Semiconductor nor the
14 * names of its contributors may be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 *
18 * ALTERNATIVELY, this software may be distributed under the terms of the
19 * GNU General Public License ("GPL") as published by the Free Software
20 * Foundation, either version 2 of that License or (at your option) any
21 * later version.
22 *
23 * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
24 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
27 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35&lbc {
36 nor@0,0 {
37 #address-cells = <1>;
38 #size-cells = <1>;
39 compatible = "cfi-flash";
40 reg = <0x0 0x0 0x2000000>;
41 bank-width = <2>;
42 device-width = <1>;
43
44 partition@0 {
45 /* 256KB for DTB Image */
46 reg = <0x0 0x00040000>;
47 label = "NOR DTB Image";
48 };
49
50 partition@40000 {
51 /* 3.75 MB for Linux Kernel Image */
52 reg = <0x00040000 0x003c0000>;
53 label = "NOR Linux Kernel Image";
54 };
55
56 partition@400000 {
57 /* 27MB for Root file System */
58 reg = <0x00400000 0x01b00000>;
59 label = "NOR Root File System";
60 };
61
62 partition@1f00000 {
63 /* This location must not be altered */
64 /* 512KB for u-boot Bootloader Image */
65 /* 512KB for u-boot Environment Variables */
66 reg = <0x01f00000 0x00100000>;
67 label = "NOR U-Boot Image";
68 read-only;
69 };
70 };
71};
72
73&soc {
74 i2c@3000 {
75 rtc@68 {
76 compatible = "dallas,ds1339";
77 reg = <0x68>;
78 };
79 };
80
81 mdio@24000 {
82 phy0: ethernet-phy@0 {
83 interrupts = <3 1 0 0>;
84 reg = <0x0>;
85 };
86 phy1: ethernet-phy@1 {
87 interrupts = <2 1 0 0>;
88 reg = <0x1>;
89 };
90 phy2: ethernet-phy@2 {
91 interrupts = <1 1 0 0>;
92 reg = <0x2>;
93 };
94 };
95
96 mdio@25000 {
97 tbi1: tbi-phy@11 {
98 reg = <0x11>;
99 device_type = "tbi-phy";
100 };
101 };
102
103 mdio@26000 {
104 tbi2: tbi-phy@11 {
105 reg = <0x11>;
106 device_type = "tbi-phy";
107 };
108 };
109
110 enet0: ethernet@b0000 {
111 phy-handle = <&phy2>;
112 phy-connection-type = "rgmii-id";
113 };
114
115 enet1: ethernet@b1000 {
116 phy-handle = <&phy0>;
117 tbi-handle = <&tbi1>;
118 phy-connection-type = "sgmii";
119 };
120
121 enet2: ethernet@b2000 {
122 phy-handle = <&phy1>;
123 phy-connection-type = "rgmii-id";
124 };
125
126 usb@22000 {
127 phy_type = "ulpi";
128 };
129
130 /* USB2 is shared with localbus, so it must be disabled
131 by default. We can't put 'status = "disabled";' here
132 since U-Boot doesn't clear the status property when
133 it enables USB2. OTOH, U-Boot does create a new node
134 when there isn't any. So, just comment it out.
135 */
136 usb@23000 {
137 status = "disabled";
138 phy_type = "ulpi";
139 };
140};
diff --git a/arch/powerpc/boot/dts/p1020utm-pc_32b.dts b/arch/powerpc/boot/dts/p1020utm-pc_32b.dts
new file mode 100644
index 000000000000..4bfdd8971cdb
--- /dev/null
+++ b/arch/powerpc/boot/dts/p1020utm-pc_32b.dts
@@ -0,0 +1,89 @@
1/*
2 * P1020 UTM-PC Device Tree Source (32-bit address map)
3 *
4 * Copyright 2012 Freescale Semiconductor Inc.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of Freescale Semiconductor nor the
14 * names of its contributors may be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 *
18 * ALTERNATIVELY, this software may be distributed under the terms of the
19 * GNU General Public License ("GPL") as published by the Free Software
20 * Foundation, either version 2 of that License or (at your option) any
21 * later version.
22 *
23 * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
24 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
27 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35/include/ "fsl/p1020si-pre.dtsi"
36/ {
37 model = "fsl,P1020UTM-PC";
38 compatible = "fsl,P1020UTM-PC";
39
40 memory {
41 device_type = "memory";
42 };
43
44 lbc: localbus@ffe05000 {
45 reg = <0x0 0xffe05000 0x0 0x1000>;
46
47 /* NOR */
48 ranges = <0x0 0x0 0x0 0xec000000 0x02000000
49 0x1 0x0 0x0 0xffa00000 0x00040000
50 0x2 0x0 0x0 0xffb00000 0x00020000>;
51 };
52
53 soc: soc@ffe00000 {
54 ranges = <0x0 0x0 0xffe00000 0x100000>;
55 };
56
57 pci0: pcie@ffe09000 {
58 reg = <0x0 0xffe09000 0x0 0x1000>;
59 ranges = <0x2000000 0x0 0xe0000000 0x0 0xa0000000 0x0 0x20000000
60 0x1000000 0x0 0x00000000 0x0 0xffc10000 0x0 0x10000>;
61 pcie@0 {
62 ranges = <0x2000000 0x0 0xe0000000
63 0x2000000 0x0 0xe0000000
64 0x0 0x20000000
65
66 0x1000000 0x0 0x0
67 0x1000000 0x0 0x0
68 0x0 0x100000>;
69 };
70 };
71
72 pci1: pcie@ffe0a000 {
73 reg = <0x0 0xffe0a000 0x0 0x1000>;
74 ranges = <0x2000000 0x0 0xe0000000 0x0 0x80000000 0x0 0x20000000
75 0x1000000 0x0 0x00000000 0x0 0xffc00000 0x0 0x10000>;
76 pcie@0 {
77 ranges = <0x2000000 0x0 0xe0000000
78 0x2000000 0x0 0xe0000000
79 0x0 0x20000000
80
81 0x1000000 0x0 0x0
82 0x1000000 0x0 0x0
83 0x0 0x100000>;
84 };
85 };
86};
87
88/include/ "p1020utm-pc.dtsi"
89/include/ "fsl/p1020si-post.dtsi"
diff --git a/arch/powerpc/boot/dts/p1020utm-pc_36b.dts b/arch/powerpc/boot/dts/p1020utm-pc_36b.dts
new file mode 100644
index 000000000000..abec53557501
--- /dev/null
+++ b/arch/powerpc/boot/dts/p1020utm-pc_36b.dts
@@ -0,0 +1,89 @@
1/*
2 * P1020 UTM-PC Device Tree Source (36-bit address map)
3 *
4 * Copyright 2012 Freescale Semiconductor Inc.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of Freescale Semiconductor nor the
14 * names of its contributors may be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 *
18 * ALTERNATIVELY, this software may be distributed under the terms of the
19 * GNU General Public License ("GPL") as published by the Free Software
20 * Foundation, either version 2 of that License or (at your option) any
21 * later version.
22 *
23 * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
24 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
27 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35/include/ "fsl/p1020si-pre.dtsi"
36/ {
37 model = "fsl,P1020UTM-PC";
38 compatible = "fsl,P1020UTM-PC";
39
40 memory {
41 device_type = "memory";
42 };
43
44 lbc: localbus@fffe05000 {
45 reg = <0xf 0xffe05000 0x0 0x1000>;
46
47 /* NOR */
48 ranges = <0x0 0x0 0xf 0xec000000 0x02000000
49 0x1 0x0 0xf 0xffa00000 0x00040000
50 0x2 0x0 0xf 0xffb00000 0x00020000>;
51 };
52
53 soc: soc@fffe00000 {
54 ranges = <0x0 0xf 0xffe00000 0x100000>;
55 };
56
57 pci0: pcie@fffe09000 {
58 reg = <0xf 0xffe09000 0x0 0x1000>;
59 ranges = <0x2000000 0x0 0xe0000000 0xc 0x20000000 0x0 0x20000000
60 0x1000000 0x0 0x00000000 0xf 0xffc10000 0x0 0x10000>;
61 pcie@0 {
62 ranges = <0x2000000 0x0 0xe0000000
63 0x2000000 0x0 0xe0000000
64 0x0 0x20000000
65
66 0x1000000 0x0 0x0
67 0x1000000 0x0 0x0
68 0x0 0x100000>;
69 };
70 };
71
72 pci1: pcie@fffe0a000 {
73 reg = <0xf 0xffe0a000 0 0x1000>;
74 ranges = <0x2000000 0x0 0xe0000000 0xc 0x00000000 0x0 0x20000000
75 0x1000000 0x0 0x00000000 0xf 0xffc00000 0x0 0x10000>;
76 pcie@0 {
77 ranges = <0x2000000 0x0 0xe0000000
78 0x2000000 0x0 0xe0000000
79 0x0 0x20000000
80
81 0x1000000 0x0 0x0
82 0x1000000 0x0 0x0
83 0x0 0x100000>;
84 };
85 };
86};
87
88/include/ "p1020utm-pc.dtsi"
89/include/ "fsl/p1020si-post.dtsi"
diff --git a/arch/powerpc/boot/dts/p2041rdb.dts b/arch/powerpc/boot/dts/p2041rdb.dts
index 4f957db01230..285213976a7f 100644
--- a/arch/powerpc/boot/dts/p2041rdb.dts
+++ b/arch/powerpc/boot/dts/p2041rdb.dts
@@ -135,7 +135,6 @@
135 reg = <0xf 0xfe200000 0 0x1000>; 135 reg = <0xf 0xfe200000 0 0x1000>;
136 ranges = <0x02000000 0 0xe0000000 0xc 0x00000000 0x0 0x20000000 136 ranges = <0x02000000 0 0xe0000000 0xc 0x00000000 0x0 0x20000000
137 0x01000000 0 0x00000000 0xf 0xf8000000 0x0 0x00010000>; 137 0x01000000 0 0x00000000 0xf 0xf8000000 0x0 0x00010000>;
138 fsl,msi = <&msi0>;
139 pcie@0 { 138 pcie@0 {
140 ranges = <0x02000000 0 0xe0000000 139 ranges = <0x02000000 0 0xe0000000
141 0x02000000 0 0xe0000000 140 0x02000000 0 0xe0000000
@@ -151,7 +150,6 @@
151 reg = <0xf 0xfe201000 0 0x1000>; 150 reg = <0xf 0xfe201000 0 0x1000>;
152 ranges = <0x02000000 0x0 0xe0000000 0xc 0x20000000 0x0 0x20000000 151 ranges = <0x02000000 0x0 0xe0000000 0xc 0x20000000 0x0 0x20000000
153 0x01000000 0x0 0x00000000 0xf 0xf8010000 0x0 0x00010000>; 152 0x01000000 0x0 0x00000000 0xf 0xf8010000 0x0 0x00010000>;
154 fsl,msi = <&msi1>;
155 pcie@0 { 153 pcie@0 {
156 ranges = <0x02000000 0 0xe0000000 154 ranges = <0x02000000 0 0xe0000000
157 0x02000000 0 0xe0000000 155 0x02000000 0 0xe0000000
@@ -167,7 +165,6 @@
167 reg = <0xf 0xfe202000 0 0x1000>; 165 reg = <0xf 0xfe202000 0 0x1000>;
168 ranges = <0x02000000 0 0xe0000000 0xc 0x40000000 0 0x20000000 166 ranges = <0x02000000 0 0xe0000000 0xc 0x40000000 0 0x20000000
169 0x01000000 0 0x00000000 0xf 0xf8020000 0 0x00010000>; 167 0x01000000 0 0x00000000 0xf 0xf8020000 0 0x00010000>;
170 fsl,msi = <&msi2>;
171 pcie@0 { 168 pcie@0 {
172 ranges = <0x02000000 0 0xe0000000 169 ranges = <0x02000000 0 0xe0000000
173 0x02000000 0 0xe0000000 170 0x02000000 0 0xe0000000
diff --git a/arch/powerpc/boot/dts/p3041ds.dts b/arch/powerpc/boot/dts/p3041ds.dts
index f469145abaeb..22a215e94162 100644
--- a/arch/powerpc/boot/dts/p3041ds.dts
+++ b/arch/powerpc/boot/dts/p3041ds.dts
@@ -173,7 +173,6 @@
173 reg = <0xf 0xfe200000 0 0x1000>; 173 reg = <0xf 0xfe200000 0 0x1000>;
174 ranges = <0x02000000 0 0xe0000000 0xc 0x00000000 0x0 0x20000000 174 ranges = <0x02000000 0 0xe0000000 0xc 0x00000000 0x0 0x20000000
175 0x01000000 0 0x00000000 0xf 0xf8000000 0x0 0x00010000>; 175 0x01000000 0 0x00000000 0xf 0xf8000000 0x0 0x00010000>;
176 fsl,msi = <&msi0>;
177 pcie@0 { 176 pcie@0 {
178 ranges = <0x02000000 0 0xe0000000 177 ranges = <0x02000000 0 0xe0000000
179 0x02000000 0 0xe0000000 178 0x02000000 0 0xe0000000
@@ -189,7 +188,6 @@
189 reg = <0xf 0xfe201000 0 0x1000>; 188 reg = <0xf 0xfe201000 0 0x1000>;
190 ranges = <0x02000000 0x0 0xe0000000 0xc 0x20000000 0x0 0x20000000 189 ranges = <0x02000000 0x0 0xe0000000 0xc 0x20000000 0x0 0x20000000
191 0x01000000 0x0 0x00000000 0xf 0xf8010000 0x0 0x00010000>; 190 0x01000000 0x0 0x00000000 0xf 0xf8010000 0x0 0x00010000>;
192 fsl,msi = <&msi1>;
193 pcie@0 { 191 pcie@0 {
194 ranges = <0x02000000 0 0xe0000000 192 ranges = <0x02000000 0 0xe0000000
195 0x02000000 0 0xe0000000 193 0x02000000 0 0xe0000000
@@ -205,7 +203,6 @@
205 reg = <0xf 0xfe202000 0 0x1000>; 203 reg = <0xf 0xfe202000 0 0x1000>;
206 ranges = <0x02000000 0 0xe0000000 0xc 0x40000000 0 0x20000000 204 ranges = <0x02000000 0 0xe0000000 0xc 0x40000000 0 0x20000000
207 0x01000000 0 0x00000000 0xf 0xf8020000 0 0x00010000>; 205 0x01000000 0 0x00000000 0xf 0xf8020000 0 0x00010000>;
208 fsl,msi = <&msi2>;
209 pcie@0 { 206 pcie@0 {
210 ranges = <0x02000000 0 0xe0000000 207 ranges = <0x02000000 0 0xe0000000
211 0x02000000 0 0xe0000000 208 0x02000000 0 0xe0000000
@@ -221,7 +218,6 @@
221 reg = <0xf 0xfe203000 0 0x1000>; 218 reg = <0xf 0xfe203000 0 0x1000>;
222 ranges = <0x02000000 0 0xe0000000 0xc 0x60000000 0 0x20000000 219 ranges = <0x02000000 0 0xe0000000 0xc 0x60000000 0 0x20000000
223 0x01000000 0 0x00000000 0xf 0xf8030000 0 0x00010000>; 220 0x01000000 0 0x00000000 0xf 0xf8030000 0 0x00010000>;
224 fsl,msi = <&msi2>;
225 pcie@0 { 221 pcie@0 {
226 ranges = <0x02000000 0 0xe0000000 222 ranges = <0x02000000 0 0xe0000000
227 0x02000000 0 0xe0000000 223 0x02000000 0 0xe0000000
diff --git a/arch/powerpc/boot/dts/p3060qds.dts b/arch/powerpc/boot/dts/p3060qds.dts
index 529042e4b9a2..9ae875c8a211 100644
--- a/arch/powerpc/boot/dts/p3060qds.dts
+++ b/arch/powerpc/boot/dts/p3060qds.dts
@@ -212,7 +212,6 @@
212 reg = <0xf 0xfe200000 0 0x1000>; 212 reg = <0xf 0xfe200000 0 0x1000>;
213 ranges = <0x02000000 0 0xe0000000 0xc 0x00000000 0x0 0x20000000 213 ranges = <0x02000000 0 0xe0000000 0xc 0x00000000 0x0 0x20000000
214 0x01000000 0 0x00000000 0xf 0xf8000000 0x0 0x00010000>; 214 0x01000000 0 0x00000000 0xf 0xf8000000 0x0 0x00010000>;
215 fsl,msi = <&msi0>;
216 pcie@0 { 215 pcie@0 {
217 ranges = <0x02000000 0 0xe0000000 216 ranges = <0x02000000 0 0xe0000000
218 0x02000000 0 0xe0000000 217 0x02000000 0 0xe0000000
@@ -228,7 +227,6 @@
228 reg = <0xf 0xfe201000 0 0x1000>; 227 reg = <0xf 0xfe201000 0 0x1000>;
229 ranges = <0x02000000 0x0 0xe0000000 0xc 0x20000000 0x0 0x20000000 228 ranges = <0x02000000 0x0 0xe0000000 0xc 0x20000000 0x0 0x20000000
230 0x01000000 0x0 0x00000000 0xf 0xf8010000 0x0 0x00010000>; 229 0x01000000 0x0 0x00000000 0xf 0xf8010000 0x0 0x00010000>;
231 fsl,msi = <&msi1>;
232 pcie@0 { 230 pcie@0 {
233 ranges = <0x02000000 0 0xe0000000 231 ranges = <0x02000000 0 0xe0000000
234 0x02000000 0 0xe0000000 232 0x02000000 0 0xe0000000
diff --git a/arch/powerpc/boot/dts/p4080ds.dts b/arch/powerpc/boot/dts/p4080ds.dts
index 6d60e54e50a0..3e204609d02e 100644
--- a/arch/powerpc/boot/dts/p4080ds.dts
+++ b/arch/powerpc/boot/dts/p4080ds.dts
@@ -141,7 +141,6 @@
141 reg = <0xf 0xfe200000 0 0x1000>; 141 reg = <0xf 0xfe200000 0 0x1000>;
142 ranges = <0x02000000 0 0xe0000000 0xc 0x00000000 0x0 0x20000000 142 ranges = <0x02000000 0 0xe0000000 0xc 0x00000000 0x0 0x20000000
143 0x01000000 0 0x00000000 0xf 0xf8000000 0x0 0x00010000>; 143 0x01000000 0 0x00000000 0xf 0xf8000000 0x0 0x00010000>;
144 fsl,msi = <&msi0>;
145 pcie@0 { 144 pcie@0 {
146 ranges = <0x02000000 0 0xe0000000 145 ranges = <0x02000000 0 0xe0000000
147 0x02000000 0 0xe0000000 146 0x02000000 0 0xe0000000
@@ -157,7 +156,6 @@
157 reg = <0xf 0xfe201000 0 0x1000>; 156 reg = <0xf 0xfe201000 0 0x1000>;
158 ranges = <0x02000000 0x0 0xe0000000 0xc 0x20000000 0x0 0x20000000 157 ranges = <0x02000000 0x0 0xe0000000 0xc 0x20000000 0x0 0x20000000
159 0x01000000 0x0 0x00000000 0xf 0xf8010000 0x0 0x00010000>; 158 0x01000000 0x0 0x00000000 0xf 0xf8010000 0x0 0x00010000>;
160 fsl,msi = <&msi1>;
161 pcie@0 { 159 pcie@0 {
162 ranges = <0x02000000 0 0xe0000000 160 ranges = <0x02000000 0 0xe0000000
163 0x02000000 0 0xe0000000 161 0x02000000 0 0xe0000000
@@ -173,7 +171,6 @@
173 reg = <0xf 0xfe202000 0 0x1000>; 171 reg = <0xf 0xfe202000 0 0x1000>;
174 ranges = <0x02000000 0 0xe0000000 0xc 0x40000000 0 0x20000000 172 ranges = <0x02000000 0 0xe0000000 0xc 0x40000000 0 0x20000000
175 0x01000000 0 0x00000000 0xf 0xf8020000 0 0x00010000>; 173 0x01000000 0 0x00000000 0xf 0xf8020000 0 0x00010000>;
176 fsl,msi = <&msi2>;
177 pcie@0 { 174 pcie@0 {
178 ranges = <0x02000000 0 0xe0000000 175 ranges = <0x02000000 0 0xe0000000
179 0x02000000 0 0xe0000000 176 0x02000000 0 0xe0000000
diff --git a/arch/powerpc/boot/dts/p5020ds.dts b/arch/powerpc/boot/dts/p5020ds.dts
index 1c250684c902..27c07ed6adc1 100644
--- a/arch/powerpc/boot/dts/p5020ds.dts
+++ b/arch/powerpc/boot/dts/p5020ds.dts
@@ -173,7 +173,6 @@
173 reg = <0xf 0xfe200000 0 0x1000>; 173 reg = <0xf 0xfe200000 0 0x1000>;
174 ranges = <0x02000000 0 0xe0000000 0xc 0x00000000 0x0 0x20000000 174 ranges = <0x02000000 0 0xe0000000 0xc 0x00000000 0x0 0x20000000
175 0x01000000 0 0x00000000 0xf 0xf8000000 0x0 0x00010000>; 175 0x01000000 0 0x00000000 0xf 0xf8000000 0x0 0x00010000>;
176 fsl,msi = <&msi0>;
177 pcie@0 { 176 pcie@0 {
178 ranges = <0x02000000 0 0xe0000000 177 ranges = <0x02000000 0 0xe0000000
179 0x02000000 0 0xe0000000 178 0x02000000 0 0xe0000000
@@ -189,7 +188,6 @@
189 reg = <0xf 0xfe201000 0 0x1000>; 188 reg = <0xf 0xfe201000 0 0x1000>;
190 ranges = <0x02000000 0x0 0xe0000000 0xc 0x20000000 0x0 0x20000000 189 ranges = <0x02000000 0x0 0xe0000000 0xc 0x20000000 0x0 0x20000000
191 0x01000000 0x0 0x00000000 0xf 0xf8010000 0x0 0x00010000>; 190 0x01000000 0x0 0x00000000 0xf 0xf8010000 0x0 0x00010000>;
192 fsl,msi = <&msi1>;
193 pcie@0 { 191 pcie@0 {
194 ranges = <0x02000000 0 0xe0000000 192 ranges = <0x02000000 0 0xe0000000
195 0x02000000 0 0xe0000000 193 0x02000000 0 0xe0000000
@@ -205,7 +203,6 @@
205 reg = <0xf 0xfe202000 0 0x1000>; 203 reg = <0xf 0xfe202000 0 0x1000>;
206 ranges = <0x02000000 0 0xe0000000 0xc 0x40000000 0 0x20000000 204 ranges = <0x02000000 0 0xe0000000 0xc 0x40000000 0 0x20000000
207 0x01000000 0 0x00000000 0xf 0xf8020000 0 0x00010000>; 205 0x01000000 0 0x00000000 0xf 0xf8020000 0 0x00010000>;
208 fsl,msi = <&msi2>;
209 pcie@0 { 206 pcie@0 {
210 ranges = <0x02000000 0 0xe0000000 207 ranges = <0x02000000 0 0xe0000000
211 0x02000000 0 0xe0000000 208 0x02000000 0 0xe0000000
@@ -221,7 +218,6 @@
221 reg = <0xf 0xfe203000 0 0x1000>; 218 reg = <0xf 0xfe203000 0 0x1000>;
222 ranges = <0x02000000 0 0xe0000000 0xc 0x60000000 0 0x20000000 219 ranges = <0x02000000 0 0xe0000000 0xc 0x60000000 0 0x20000000
223 0x01000000 0 0x00000000 0xf 0xf8030000 0 0x00010000>; 220 0x01000000 0 0x00000000 0xf 0xf8030000 0 0x00010000>;
224 fsl,msi = <&msi2>;
225 pcie@0 { 221 pcie@0 {
226 ranges = <0x02000000 0 0xe0000000 222 ranges = <0x02000000 0 0xe0000000
227 0x02000000 0 0xe0000000 223 0x02000000 0 0xe0000000
diff --git a/arch/powerpc/configs/86xx/mpc8610_hpcd_defconfig b/arch/powerpc/configs/86xx/mpc8610_hpcd_defconfig
index 0db9ba0423ff..c09598b31de1 100644
--- a/arch/powerpc/configs/86xx/mpc8610_hpcd_defconfig
+++ b/arch/powerpc/configs/86xx/mpc8610_hpcd_defconfig
@@ -100,6 +100,7 @@ CONFIG_SND_MIXER_OSS=y
100CONFIG_SND_PCM_OSS=y 100CONFIG_SND_PCM_OSS=y
101# CONFIG_SND_SUPPORT_OLD_API is not set 101# CONFIG_SND_SUPPORT_OLD_API is not set
102CONFIG_SND_SOC=y 102CONFIG_SND_SOC=y
103CONFIG_SND_POWERPC_SOC=y
103CONFIG_RTC_CLASS=y 104CONFIG_RTC_CLASS=y
104CONFIG_RTC_DRV_CMOS=y 105CONFIG_RTC_DRV_CMOS=y
105CONFIG_EXT2_FS=y 106CONFIG_EXT2_FS=y
diff --git a/arch/powerpc/configs/corenet32_smp_defconfig b/arch/powerpc/configs/corenet32_smp_defconfig
index f8aef205d222..91db656294e8 100644
--- a/arch/powerpc/configs/corenet32_smp_defconfig
+++ b/arch/powerpc/configs/corenet32_smp_defconfig
@@ -116,6 +116,7 @@ CONFIG_SERIAL_8250_RSA=y
116CONFIG_HW_RANDOM=y 116CONFIG_HW_RANDOM=y
117CONFIG_NVRAM=y 117CONFIG_NVRAM=y
118CONFIG_I2C=y 118CONFIG_I2C=y
119CONFIG_I2C_CHARDEV=y
119CONFIG_I2C_MPC=y 120CONFIG_I2C_MPC=y
120CONFIG_SPI=y 121CONFIG_SPI=y
121CONFIG_SPI_GPIO=y 122CONFIG_SPI_GPIO=y
diff --git a/arch/powerpc/configs/corenet64_smp_defconfig b/arch/powerpc/configs/corenet64_smp_defconfig
index 82b13bfcf3c0..6798343580f0 100644
--- a/arch/powerpc/configs/corenet64_smp_defconfig
+++ b/arch/powerpc/configs/corenet64_smp_defconfig
@@ -71,6 +71,8 @@ CONFIG_SERIAL_8250_MANY_PORTS=y
71CONFIG_SERIAL_8250_DETECT_IRQ=y 71CONFIG_SERIAL_8250_DETECT_IRQ=y
72CONFIG_SERIAL_8250_RSA=y 72CONFIG_SERIAL_8250_RSA=y
73CONFIG_I2C=y 73CONFIG_I2C=y
74CONFIG_I2C_CHARDEV=y
75CONFIG_I2C_MPC=y
74# CONFIG_HWMON is not set 76# CONFIG_HWMON is not set
75CONFIG_VIDEO_OUTPUT_CONTROL=y 77CONFIG_VIDEO_OUTPUT_CONTROL=y
76# CONFIG_HID_SUPPORT is not set 78# CONFIG_HID_SUPPORT is not set
diff --git a/arch/powerpc/configs/mpc85xx_defconfig b/arch/powerpc/configs/mpc85xx_defconfig
index cc87a8441566..62bb723c5b54 100644
--- a/arch/powerpc/configs/mpc85xx_defconfig
+++ b/arch/powerpc/configs/mpc85xx_defconfig
@@ -117,6 +117,7 @@ CONFIG_SERIAL_8250_RSA=y
117CONFIG_SERIAL_QE=m 117CONFIG_SERIAL_QE=m
118CONFIG_NVRAM=y 118CONFIG_NVRAM=y
119CONFIG_I2C=y 119CONFIG_I2C=y
120CONFIG_I2C_CHARDEV=y
120CONFIG_I2C_CPM=m 121CONFIG_I2C_CPM=m
121CONFIG_I2C_MPC=y 122CONFIG_I2C_MPC=y
122CONFIG_SPI=y 123CONFIG_SPI=y
@@ -140,6 +141,7 @@ CONFIG_SND_INTEL8X0=y
140# CONFIG_SND_PPC is not set 141# CONFIG_SND_PPC is not set
141# CONFIG_SND_USB is not set 142# CONFIG_SND_USB is not set
142CONFIG_SND_SOC=y 143CONFIG_SND_SOC=y
144CONFIG_SND_POWERPC_SOC=y
143CONFIG_HID_A4TECH=y 145CONFIG_HID_A4TECH=y
144CONFIG_HID_APPLE=y 146CONFIG_HID_APPLE=y
145CONFIG_HID_BELKIN=y 147CONFIG_HID_BELKIN=y
diff --git a/arch/powerpc/configs/mpc85xx_smp_defconfig b/arch/powerpc/configs/mpc85xx_smp_defconfig
index 48d6682f2434..d1828427ae55 100644
--- a/arch/powerpc/configs/mpc85xx_smp_defconfig
+++ b/arch/powerpc/configs/mpc85xx_smp_defconfig
@@ -119,6 +119,7 @@ CONFIG_SERIAL_8250_RSA=y
119CONFIG_SERIAL_QE=m 119CONFIG_SERIAL_QE=m
120CONFIG_NVRAM=y 120CONFIG_NVRAM=y
121CONFIG_I2C=y 121CONFIG_I2C=y
122CONFIG_I2C_CHARDEV=y
122CONFIG_I2C_CPM=m 123CONFIG_I2C_CPM=m
123CONFIG_I2C_MPC=y 124CONFIG_I2C_MPC=y
124CONFIG_SPI=y 125CONFIG_SPI=y
@@ -142,6 +143,7 @@ CONFIG_SND_INTEL8X0=y
142# CONFIG_SND_PPC is not set 143# CONFIG_SND_PPC is not set
143# CONFIG_SND_USB is not set 144# CONFIG_SND_USB is not set
144CONFIG_SND_SOC=y 145CONFIG_SND_SOC=y
146CONFIG_SND_POWERPC_SOC=y
145CONFIG_HID_A4TECH=y 147CONFIG_HID_A4TECH=y
146CONFIG_HID_APPLE=y 148CONFIG_HID_APPLE=y
147CONFIG_HID_BELKIN=y 149CONFIG_HID_BELKIN=y
diff --git a/arch/powerpc/include/asm/dma-mapping.h b/arch/powerpc/include/asm/dma-mapping.h
index dd70fac57ec8..62678e365ca0 100644
--- a/arch/powerpc/include/asm/dma-mapping.h
+++ b/arch/powerpc/include/asm/dma-mapping.h
@@ -22,9 +22,11 @@
22 22
23/* Some dma direct funcs must be visible for use in other dma_ops */ 23/* Some dma direct funcs must be visible for use in other dma_ops */
24extern void *dma_direct_alloc_coherent(struct device *dev, size_t size, 24extern void *dma_direct_alloc_coherent(struct device *dev, size_t size,
25 dma_addr_t *dma_handle, gfp_t flag); 25 dma_addr_t *dma_handle, gfp_t flag,
26 struct dma_attrs *attrs);
26extern void dma_direct_free_coherent(struct device *dev, size_t size, 27extern void dma_direct_free_coherent(struct device *dev, size_t size,
27 void *vaddr, dma_addr_t dma_handle); 28 void *vaddr, dma_addr_t dma_handle,
29 struct dma_attrs *attrs);
28 30
29 31
30#ifdef CONFIG_NOT_COHERENT_CACHE 32#ifdef CONFIG_NOT_COHERENT_CACHE
@@ -130,23 +132,29 @@ static inline int dma_supported(struct device *dev, u64 mask)
130 132
131extern int dma_set_mask(struct device *dev, u64 dma_mask); 133extern int dma_set_mask(struct device *dev, u64 dma_mask);
132 134
133static inline void *dma_alloc_coherent(struct device *dev, size_t size, 135#define dma_alloc_coherent(d,s,h,f) dma_alloc_attrs(d,s,h,f,NULL)
134 dma_addr_t *dma_handle, gfp_t flag) 136
137static inline void *dma_alloc_attrs(struct device *dev, size_t size,
138 dma_addr_t *dma_handle, gfp_t flag,
139 struct dma_attrs *attrs)
135{ 140{
136 struct dma_map_ops *dma_ops = get_dma_ops(dev); 141 struct dma_map_ops *dma_ops = get_dma_ops(dev);
137 void *cpu_addr; 142 void *cpu_addr;
138 143
139 BUG_ON(!dma_ops); 144 BUG_ON(!dma_ops);
140 145
141 cpu_addr = dma_ops->alloc_coherent(dev, size, dma_handle, flag); 146 cpu_addr = dma_ops->alloc(dev, size, dma_handle, flag, attrs);
142 147
143 debug_dma_alloc_coherent(dev, size, *dma_handle, cpu_addr); 148 debug_dma_alloc_coherent(dev, size, *dma_handle, cpu_addr);
144 149
145 return cpu_addr; 150 return cpu_addr;
146} 151}
147 152
148static inline void dma_free_coherent(struct device *dev, size_t size, 153#define dma_free_coherent(d,s,c,h) dma_free_attrs(d,s,c,h,NULL)
149 void *cpu_addr, dma_addr_t dma_handle) 154
155static inline void dma_free_attrs(struct device *dev, size_t size,
156 void *cpu_addr, dma_addr_t dma_handle,
157 struct dma_attrs *attrs)
150{ 158{
151 struct dma_map_ops *dma_ops = get_dma_ops(dev); 159 struct dma_map_ops *dma_ops = get_dma_ops(dev);
152 160
@@ -154,7 +162,7 @@ static inline void dma_free_coherent(struct device *dev, size_t size,
154 162
155 debug_dma_free_coherent(dev, size, cpu_addr, dma_handle); 163 debug_dma_free_coherent(dev, size, cpu_addr, dma_handle);
156 164
157 dma_ops->free_coherent(dev, size, cpu_addr, dma_handle); 165 dma_ops->free(dev, size, cpu_addr, dma_handle, attrs);
158} 166}
159 167
160static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr) 168static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
diff --git a/arch/powerpc/include/asm/epapr_hcalls.h b/arch/powerpc/include/asm/epapr_hcalls.h
index f3b0c2cc9fea..976835d8f22e 100644
--- a/arch/powerpc/include/asm/epapr_hcalls.h
+++ b/arch/powerpc/include/asm/epapr_hcalls.h
@@ -134,10 +134,15 @@
134 * whether they will be clobbered. 134 * whether they will be clobbered.
135 * 135 *
136 * Note that r11 can be used as an output parameter. 136 * Note that r11 can be used as an output parameter.
137 *
138 * The "memory" clobber is only necessary for hcalls where the Hypervisor
139 * will read or write guest memory. However, we add it to all hcalls because
140 * the impact is minimal, and we want to ensure that it's present for the
141 * hcalls that need it.
137*/ 142*/
138 143
139/* List of common clobbered registers. Do not use this macro. */ 144/* List of common clobbered registers. Do not use this macro. */
140#define EV_HCALL_CLOBBERS "r0", "r12", "xer", "ctr", "lr", "cc" 145#define EV_HCALL_CLOBBERS "r0", "r12", "xer", "ctr", "lr", "cc", "memory"
141 146
142#define EV_HCALL_CLOBBERS8 EV_HCALL_CLOBBERS 147#define EV_HCALL_CLOBBERS8 EV_HCALL_CLOBBERS
143#define EV_HCALL_CLOBBERS7 EV_HCALL_CLOBBERS8, "r10" 148#define EV_HCALL_CLOBBERS7 EV_HCALL_CLOBBERS8, "r10"
diff --git a/arch/powerpc/include/asm/exception-64s.h b/arch/powerpc/include/asm/exception-64s.h
index 548da3aa0a30..d58fc4e4149c 100644
--- a/arch/powerpc/include/asm/exception-64s.h
+++ b/arch/powerpc/include/asm/exception-64s.h
@@ -288,13 +288,6 @@ label##_hv: \
288/* Exception addition: Hard disable interrupts */ 288/* Exception addition: Hard disable interrupts */
289#define DISABLE_INTS SOFT_DISABLE_INTS(r10,r11) 289#define DISABLE_INTS SOFT_DISABLE_INTS(r10,r11)
290 290
291/* Exception addition: Keep interrupt state */
292#define ENABLE_INTS \
293 ld r11,PACAKMSR(r13); \
294 ld r12,_MSR(r1); \
295 rlwimi r11,r12,0,MSR_EE; \
296 mtmsrd r11,1
297
298#define ADD_NVGPRS \ 291#define ADD_NVGPRS \
299 bl .save_nvgprs 292 bl .save_nvgprs
300 293
diff --git a/arch/powerpc/include/asm/fsl_guts.h b/arch/powerpc/include/asm/fsl_guts.h
index ce04530d2000..aa4c488589ce 100644
--- a/arch/powerpc/include/asm/fsl_guts.h
+++ b/arch/powerpc/include/asm/fsl_guts.h
@@ -16,15 +16,6 @@
16#define __ASM_POWERPC_FSL_GUTS_H__ 16#define __ASM_POWERPC_FSL_GUTS_H__
17#ifdef __KERNEL__ 17#ifdef __KERNEL__
18 18
19/*
20 * These #ifdefs are safe because it's not possible to build a kernel that
21 * runs on e500 and e600 cores.
22 */
23
24#if !defined(CONFIG_PPC_85xx) && !defined(CONFIG_PPC_86xx)
25#error Only 85xx and 86xx SOCs are supported
26#endif
27
28/** 19/**
29 * Global Utility Registers. 20 * Global Utility Registers.
30 * 21 *
@@ -36,11 +27,7 @@
36 * different names. In these cases, one name is chosen to avoid extraneous 27 * different names. In these cases, one name is chosen to avoid extraneous
37 * #ifdefs. 28 * #ifdefs.
38 */ 29 */
39#ifdef CONFIG_PPC_85xx 30struct ccsr_guts {
40struct ccsr_guts_85xx {
41#else
42struct ccsr_guts_86xx {
43#endif
44 __be32 porpllsr; /* 0x.0000 - POR PLL Ratio Status Register */ 31 __be32 porpllsr; /* 0x.0000 - POR PLL Ratio Status Register */
45 __be32 porbmsr; /* 0x.0004 - POR Boot Mode Status Register */ 32 __be32 porbmsr; /* 0x.0004 - POR Boot Mode Status Register */
46 __be32 porimpscr; /* 0x.0008 - POR I/O Impedance Status and Control Register */ 33 __be32 porimpscr; /* 0x.0008 - POR I/O Impedance Status and Control Register */
@@ -77,11 +64,8 @@ struct ccsr_guts_86xx {
77 u8 res0a8[0xb0 - 0xa8]; 64 u8 res0a8[0xb0 - 0xa8];
78 __be32 rstcr; /* 0x.00b0 - Reset Control Register */ 65 __be32 rstcr; /* 0x.00b0 - Reset Control Register */
79 u8 res0b4[0xc0 - 0xb4]; 66 u8 res0b4[0xc0 - 0xb4];
80#ifdef CONFIG_PPC_85xx 67 __be32 iovselsr; /* 0x.00c0 - I/O voltage select status register
81 __be32 iovselsr; /* 0x.00c0 - I/O voltage select status register */ 68 Called 'elbcvselcr' on 86xx SOCs */
82#else
83 __be32 elbcvselcr; /* 0x.00c0 - eLBC Voltage Select Ctrl Reg */
84#endif
85 u8 res0c4[0x224 - 0xc4]; 69 u8 res0c4[0x224 - 0xc4];
86 __be32 iodelay1; /* 0x.0224 - IO delay control register 1 */ 70 __be32 iodelay1; /* 0x.0224 - IO delay control register 1 */
87 __be32 iodelay2; /* 0x.0228 - IO delay control register 2 */ 71 __be32 iodelay2; /* 0x.0228 - IO delay control register 2 */
@@ -136,7 +120,7 @@ struct ccsr_guts_86xx {
136 * ch: The channel on the DMA controller (0, 1, 2, or 3) 120 * ch: The channel on the DMA controller (0, 1, 2, or 3)
137 * device: The device to set as the source (CCSR_GUTS_DMACR_DEV_xx) 121 * device: The device to set as the source (CCSR_GUTS_DMACR_DEV_xx)
138 */ 122 */
139static inline void guts_set_dmacr(struct ccsr_guts_86xx __iomem *guts, 123static inline void guts_set_dmacr(struct ccsr_guts __iomem *guts,
140 unsigned int co, unsigned int ch, unsigned int device) 124 unsigned int co, unsigned int ch, unsigned int device)
141{ 125{
142 unsigned int shift = 16 + (8 * (1 - co) + 2 * (3 - ch)); 126 unsigned int shift = 16 + (8 * (1 - co) + 2 * (3 - ch));
@@ -172,7 +156,7 @@ static inline void guts_set_dmacr(struct ccsr_guts_86xx __iomem *guts,
172 * ch: The channel on the DMA controller (0, 1, 2, or 3) 156 * ch: The channel on the DMA controller (0, 1, 2, or 3)
173 * value: the new value for the bit (0 or 1) 157 * value: the new value for the bit (0 or 1)
174 */ 158 */
175static inline void guts_set_pmuxcr_dma(struct ccsr_guts_86xx __iomem *guts, 159static inline void guts_set_pmuxcr_dma(struct ccsr_guts __iomem *guts,
176 unsigned int co, unsigned int ch, unsigned int value) 160 unsigned int co, unsigned int ch, unsigned int value)
177{ 161{
178 if ((ch == 0) || (ch == 3)) { 162 if ((ch == 0) || (ch == 3)) {
diff --git a/arch/powerpc/include/asm/irq.h b/arch/powerpc/include/asm/irq.h
index cf417e510736..0e40843a1c6e 100644
--- a/arch/powerpc/include/asm/irq.h
+++ b/arch/powerpc/include/asm/irq.h
@@ -18,10 +18,6 @@
18#include <linux/atomic.h> 18#include <linux/atomic.h>
19 19
20 20
21/* Define a way to iterate across irqs. */
22#define for_each_irq(i) \
23 for ((i) = 0; (i) < NR_IRQS; ++(i))
24
25extern atomic_t ppc_n_lost_interrupts; 21extern atomic_t ppc_n_lost_interrupts;
26 22
27/* This number is used when no interrupt has been assigned */ 23/* This number is used when no interrupt has been assigned */
@@ -33,8 +29,6 @@ extern atomic_t ppc_n_lost_interrupts;
33/* Same thing, used by the generic IRQ code */ 29/* Same thing, used by the generic IRQ code */
34#define NR_IRQS_LEGACY NUM_ISA_INTERRUPTS 30#define NR_IRQS_LEGACY NUM_ISA_INTERRUPTS
35 31
36struct irq_data;
37extern irq_hw_number_t irqd_to_hwirq(struct irq_data *d);
38extern irq_hw_number_t virq_to_hw(unsigned int virq); 32extern irq_hw_number_t virq_to_hw(unsigned int virq);
39 33
40/** 34/**
diff --git a/arch/powerpc/include/asm/mpic.h b/arch/powerpc/include/asm/mpic.h
index c65b9294376e..c9f698a994be 100644
--- a/arch/powerpc/include/asm/mpic.h
+++ b/arch/powerpc/include/asm/mpic.h
@@ -275,9 +275,6 @@ struct mpic
275 unsigned int isu_mask; 275 unsigned int isu_mask;
276 /* Number of sources */ 276 /* Number of sources */
277 unsigned int num_sources; 277 unsigned int num_sources;
278 /* default senses array */
279 unsigned char *senses;
280 unsigned int senses_count;
281 278
282 /* vector numbers used for internal sources (ipi/timers) */ 279 /* vector numbers used for internal sources (ipi/timers) */
283 unsigned int ipi_vecs[4]; 280 unsigned int ipi_vecs[4];
@@ -415,21 +412,6 @@ extern struct mpic *mpic_alloc(struct device_node *node,
415extern void mpic_assign_isu(struct mpic *mpic, unsigned int isu_num, 412extern void mpic_assign_isu(struct mpic *mpic, unsigned int isu_num,
416 phys_addr_t phys_addr); 413 phys_addr_t phys_addr);
417 414
418/* Set default sense codes
419 *
420 * @mpic: controller
421 * @senses: array of sense codes
422 * @count: size of above array
423 *
424 * Optionally provide an array (indexed on hardware interrupt numbers
425 * for this MPIC) of default sense codes for the chip. Those are linux
426 * sense codes IRQ_TYPE_*
427 *
428 * The driver gets ownership of the pointer, don't dispose of it or
429 * anything like that. __init only.
430 */
431extern void mpic_set_default_senses(struct mpic *mpic, u8 *senses, int count);
432
433 415
434/* Initialize the controller. After this has been called, none of the above 416/* Initialize the controller. After this has been called, none of the above
435 * should be called again for this mpic 417 * should be called again for this mpic
diff --git a/arch/powerpc/include/asm/mpic_msgr.h b/arch/powerpc/include/asm/mpic_msgr.h
index 3ec37dc9003e..326d33ca55cd 100644
--- a/arch/powerpc/include/asm/mpic_msgr.h
+++ b/arch/powerpc/include/asm/mpic_msgr.h
@@ -13,6 +13,7 @@
13 13
14#include <linux/types.h> 14#include <linux/types.h>
15#include <linux/spinlock.h> 15#include <linux/spinlock.h>
16#include <asm/smp.h>
16 17
17struct mpic_msgr { 18struct mpic_msgr {
18 u32 __iomem *base; 19 u32 __iomem *base;
diff --git a/arch/powerpc/include/asm/reg_booke.h b/arch/powerpc/include/asm/reg_booke.h
index b86faa9107da..8a97aa7289d3 100644
--- a/arch/powerpc/include/asm/reg_booke.h
+++ b/arch/powerpc/include/asm/reg_booke.h
@@ -15,11 +15,6 @@
15#ifndef __ASM_POWERPC_REG_BOOKE_H__ 15#ifndef __ASM_POWERPC_REG_BOOKE_H__
16#define __ASM_POWERPC_REG_BOOKE_H__ 16#define __ASM_POWERPC_REG_BOOKE_H__
17 17
18#ifdef CONFIG_BOOKE_WDT
19extern u32 booke_wdt_enabled;
20extern u32 booke_wdt_period;
21#endif /* CONFIG_BOOKE_WDT */
22
23/* Machine State Register (MSR) Fields */ 18/* Machine State Register (MSR) Fields */
24#define MSR_GS (1<<28) /* Guest state */ 19#define MSR_GS (1<<28) /* Guest state */
25#define MSR_UCLE (1<<26) /* User-mode cache lock enable */ 20#define MSR_UCLE (1<<26) /* User-mode cache lock enable */
diff --git a/arch/powerpc/kernel/dma-iommu.c b/arch/powerpc/kernel/dma-iommu.c
index 3f6464b4d970..bcfdcd22c766 100644
--- a/arch/powerpc/kernel/dma-iommu.c
+++ b/arch/powerpc/kernel/dma-iommu.c
@@ -17,7 +17,8 @@
17 * to the dma address (mapping) of the first page. 17 * to the dma address (mapping) of the first page.
18 */ 18 */
19static void *dma_iommu_alloc_coherent(struct device *dev, size_t size, 19static void *dma_iommu_alloc_coherent(struct device *dev, size_t size,
20 dma_addr_t *dma_handle, gfp_t flag) 20 dma_addr_t *dma_handle, gfp_t flag,
21 struct dma_attrs *attrs)
21{ 22{
22 return iommu_alloc_coherent(dev, get_iommu_table_base(dev), size, 23 return iommu_alloc_coherent(dev, get_iommu_table_base(dev), size,
23 dma_handle, dev->coherent_dma_mask, flag, 24 dma_handle, dev->coherent_dma_mask, flag,
@@ -25,7 +26,8 @@ static void *dma_iommu_alloc_coherent(struct device *dev, size_t size,
25} 26}
26 27
27static void dma_iommu_free_coherent(struct device *dev, size_t size, 28static void dma_iommu_free_coherent(struct device *dev, size_t size,
28 void *vaddr, dma_addr_t dma_handle) 29 void *vaddr, dma_addr_t dma_handle,
30 struct dma_attrs *attrs)
29{ 31{
30 iommu_free_coherent(get_iommu_table_base(dev), size, vaddr, dma_handle); 32 iommu_free_coherent(get_iommu_table_base(dev), size, vaddr, dma_handle);
31} 33}
@@ -105,8 +107,8 @@ static u64 dma_iommu_get_required_mask(struct device *dev)
105} 107}
106 108
107struct dma_map_ops dma_iommu_ops = { 109struct dma_map_ops dma_iommu_ops = {
108 .alloc_coherent = dma_iommu_alloc_coherent, 110 .alloc = dma_iommu_alloc_coherent,
109 .free_coherent = dma_iommu_free_coherent, 111 .free = dma_iommu_free_coherent,
110 .map_sg = dma_iommu_map_sg, 112 .map_sg = dma_iommu_map_sg,
111 .unmap_sg = dma_iommu_unmap_sg, 113 .unmap_sg = dma_iommu_unmap_sg,
112 .dma_supported = dma_iommu_dma_supported, 114 .dma_supported = dma_iommu_dma_supported,
diff --git a/arch/powerpc/kernel/dma-swiotlb.c b/arch/powerpc/kernel/dma-swiotlb.c
index 1ebc9189aada..4ab88dafb235 100644
--- a/arch/powerpc/kernel/dma-swiotlb.c
+++ b/arch/powerpc/kernel/dma-swiotlb.c
@@ -47,8 +47,8 @@ static u64 swiotlb_powerpc_get_required(struct device *dev)
47 * for everything else. 47 * for everything else.
48 */ 48 */
49struct dma_map_ops swiotlb_dma_ops = { 49struct dma_map_ops swiotlb_dma_ops = {
50 .alloc_coherent = dma_direct_alloc_coherent, 50 .alloc = dma_direct_alloc_coherent,
51 .free_coherent = dma_direct_free_coherent, 51 .free = dma_direct_free_coherent,
52 .map_sg = swiotlb_map_sg_attrs, 52 .map_sg = swiotlb_map_sg_attrs,
53 .unmap_sg = swiotlb_unmap_sg_attrs, 53 .unmap_sg = swiotlb_unmap_sg_attrs,
54 .dma_supported = swiotlb_dma_supported, 54 .dma_supported = swiotlb_dma_supported,
diff --git a/arch/powerpc/kernel/dma.c b/arch/powerpc/kernel/dma.c
index 7d0233c12ee3..b1ec983dcec8 100644
--- a/arch/powerpc/kernel/dma.c
+++ b/arch/powerpc/kernel/dma.c
@@ -26,7 +26,8 @@
26 26
27 27
28void *dma_direct_alloc_coherent(struct device *dev, size_t size, 28void *dma_direct_alloc_coherent(struct device *dev, size_t size,
29 dma_addr_t *dma_handle, gfp_t flag) 29 dma_addr_t *dma_handle, gfp_t flag,
30 struct dma_attrs *attrs)
30{ 31{
31 void *ret; 32 void *ret;
32#ifdef CONFIG_NOT_COHERENT_CACHE 33#ifdef CONFIG_NOT_COHERENT_CACHE
@@ -54,7 +55,8 @@ void *dma_direct_alloc_coherent(struct device *dev, size_t size,
54} 55}
55 56
56void dma_direct_free_coherent(struct device *dev, size_t size, 57void dma_direct_free_coherent(struct device *dev, size_t size,
57 void *vaddr, dma_addr_t dma_handle) 58 void *vaddr, dma_addr_t dma_handle,
59 struct dma_attrs *attrs)
58{ 60{
59#ifdef CONFIG_NOT_COHERENT_CACHE 61#ifdef CONFIG_NOT_COHERENT_CACHE
60 __dma_free_coherent(size, vaddr); 62 __dma_free_coherent(size, vaddr);
@@ -150,8 +152,8 @@ static inline void dma_direct_sync_single(struct device *dev,
150#endif 152#endif
151 153
152struct dma_map_ops dma_direct_ops = { 154struct dma_map_ops dma_direct_ops = {
153 .alloc_coherent = dma_direct_alloc_coherent, 155 .alloc = dma_direct_alloc_coherent,
154 .free_coherent = dma_direct_free_coherent, 156 .free = dma_direct_free_coherent,
155 .map_sg = dma_direct_map_sg, 157 .map_sg = dma_direct_map_sg,
156 .unmap_sg = dma_direct_unmap_sg, 158 .unmap_sg = dma_direct_unmap_sg,
157 .dma_supported = dma_direct_dma_supported, 159 .dma_supported = dma_direct_dma_supported,
diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
index 3e57a00b8cba..ba3aeb4bc06a 100644
--- a/arch/powerpc/kernel/entry_32.S
+++ b/arch/powerpc/kernel/entry_32.S
@@ -206,40 +206,43 @@ reenable_mmu: /* re-enable mmu so we can */
206 andi. r10,r10,MSR_EE /* Did EE change? */ 206 andi. r10,r10,MSR_EE /* Did EE change? */
207 beq 1f 207 beq 1f
208 208
209 /* Save handler and return address into the 2 unused words
210 * of the STACK_FRAME_OVERHEAD (sneak sneak sneak). Everything
211 * else can be recovered from the pt_regs except r3 which for
212 * normal interrupts has been set to pt_regs and for syscalls
213 * is an argument, so we temporarily use ORIG_GPR3 to save it
214 */
215 stw r9,8(r1)
216 stw r11,12(r1)
217 stw r3,ORIG_GPR3(r1)
218 /* 209 /*
219 * The trace_hardirqs_off will use CALLER_ADDR0 and CALLER_ADDR1. 210 * The trace_hardirqs_off will use CALLER_ADDR0 and CALLER_ADDR1.
220 * If from user mode there is only one stack frame on the stack, and 211 * If from user mode there is only one stack frame on the stack, and
221 * accessing CALLER_ADDR1 will cause oops. So we need create a dummy 212 * accessing CALLER_ADDR1 will cause oops. So we need create a dummy
222 * stack frame to make trace_hardirqs_off happy. 213 * stack frame to make trace_hardirqs_off happy.
214 *
215 * This is handy because we also need to save a bunch of GPRs,
216 * r3 can be different from GPR3(r1) at this point, r9 and r11
217 * contains the old MSR and handler address respectively,
218 * r4 & r5 can contain page fault arguments that need to be passed
219 * along as well. r12, CCR, CTR, XER etc... are left clobbered as
220 * they aren't useful past this point (aren't syscall arguments),
221 * the rest is restored from the exception frame.
223 */ 222 */
223 stwu r1,-32(r1)
224 stw r9,8(r1)
225 stw r11,12(r1)
226 stw r3,16(r1)
227 stw r4,20(r1)
228 stw r5,24(r1)
224 andi. r12,r12,MSR_PR 229 andi. r12,r12,MSR_PR
225 beq 11f 230 b 11f
226 stwu r1,-16(r1)
227 bl trace_hardirqs_off 231 bl trace_hardirqs_off
228 addi r1,r1,16
229 b 12f 232 b 12f
230
23111: 23311:
232 bl trace_hardirqs_off 234 bl trace_hardirqs_off
23312: 23512:
236 lwz r5,24(r1)
237 lwz r4,20(r1)
238 lwz r3,16(r1)
239 lwz r11,12(r1)
240 lwz r9,8(r1)
241 addi r1,r1,32
234 lwz r0,GPR0(r1) 242 lwz r0,GPR0(r1)
235 lwz r3,ORIG_GPR3(r1)
236 lwz r4,GPR4(r1)
237 lwz r5,GPR5(r1)
238 lwz r6,GPR6(r1) 243 lwz r6,GPR6(r1)
239 lwz r7,GPR7(r1) 244 lwz r7,GPR7(r1)
240 lwz r8,GPR8(r1) 245 lwz r8,GPR8(r1)
241 lwz r9,8(r1)
242 lwz r11,12(r1)
2431: mtctr r11 2461: mtctr r11
244 mtlr r9 247 mtlr r9
245 bctr /* jump to handler */ 248 bctr /* jump to handler */
diff --git a/arch/powerpc/kernel/entry_64.S b/arch/powerpc/kernel/entry_64.S
index f8a7a1a1a9f4..ef2074c3e906 100644
--- a/arch/powerpc/kernel/entry_64.S
+++ b/arch/powerpc/kernel/entry_64.S
@@ -588,23 +588,19 @@ _GLOBAL(ret_from_except_lite)
588fast_exc_return_irq: 588fast_exc_return_irq:
589restore: 589restore:
590 /* 590 /*
591 * This is the main kernel exit path, we first check if we 591 * This is the main kernel exit path. First we check if we
592 * have to change our interrupt state. 592 * are about to re-enable interrupts
593 */ 593 */
594 ld r5,SOFTE(r1) 594 ld r5,SOFTE(r1)
595 lbz r6,PACASOFTIRQEN(r13) 595 lbz r6,PACASOFTIRQEN(r13)
596 cmpwi cr1,r5,0 596 cmpwi cr0,r5,0
597 cmpw cr0,r5,r6 597 beq restore_irq_off
598 beq cr0,4f
599 598
600 /* We do, handle disable first, which is easy */ 599 /* We are enabling, were we already enabled ? Yes, just return */
601 bne cr1,3f; 600 cmpwi cr0,r6,1
602 li r0,0 601 beq cr0,do_restore
603 stb r0,PACASOFTIRQEN(r13);
604 TRACE_DISABLE_INTS
605 b 4f
606 602
6073: /* 603 /*
608 * We are about to soft-enable interrupts (we are hard disabled 604 * We are about to soft-enable interrupts (we are hard disabled
609 * at this point). We check if there's anything that needs to 605 * at this point). We check if there's anything that needs to
610 * be replayed first. 606 * be replayed first.
@@ -626,7 +622,7 @@ restore_no_replay:
626 /* 622 /*
627 * Final return path. BookE is handled in a different file 623 * Final return path. BookE is handled in a different file
628 */ 624 */
6294: 625do_restore:
630#ifdef CONFIG_PPC_BOOK3E 626#ifdef CONFIG_PPC_BOOK3E
631 b .exception_return_book3e 627 b .exception_return_book3e
632#else 628#else
@@ -700,6 +696,25 @@ fast_exception_return:
700#endif /* CONFIG_PPC_BOOK3E */ 696#endif /* CONFIG_PPC_BOOK3E */
701 697
702 /* 698 /*
699 * We are returning to a context with interrupts soft disabled.
700 *
701 * However, we may also about to hard enable, so we need to
702 * make sure that in this case, we also clear PACA_IRQ_HARD_DIS
703 * or that bit can get out of sync and bad things will happen
704 */
705restore_irq_off:
706 ld r3,_MSR(r1)
707 lbz r7,PACAIRQHAPPENED(r13)
708 andi. r0,r3,MSR_EE
709 beq 1f
710 rlwinm r7,r7,0,~PACA_IRQ_HARD_DIS
711 stb r7,PACAIRQHAPPENED(r13)
7121: li r0,0
713 stb r0,PACASOFTIRQEN(r13);
714 TRACE_DISABLE_INTS
715 b do_restore
716
717 /*
703 * Something did happen, check if a re-emit is needed 718 * Something did happen, check if a re-emit is needed
704 * (this also clears paca->irq_happened) 719 * (this also clears paca->irq_happened)
705 */ 720 */
@@ -748,6 +763,9 @@ restore_check_irq_replay:
748#endif /* CONFIG_PPC_BOOK3E */ 763#endif /* CONFIG_PPC_BOOK3E */
7491: b .ret_from_except /* What else to do here ? */ 7641: b .ret_from_except /* What else to do here ? */
750 765
766
767
7683:
751do_work: 769do_work:
752#ifdef CONFIG_PREEMPT 770#ifdef CONFIG_PREEMPT
753 andi. r0,r3,MSR_PR /* Returning to user mode? */ 771 andi. r0,r3,MSR_PR /* Returning to user mode? */
@@ -767,16 +785,6 @@ do_work:
767 SOFT_DISABLE_INTS(r3,r4) 785 SOFT_DISABLE_INTS(r3,r4)
7681: bl .preempt_schedule_irq 7861: bl .preempt_schedule_irq
769 787
770 /* Hard-disable interrupts again (and update PACA) */
771#ifdef CONFIG_PPC_BOOK3E
772 wrteei 0
773#else
774 ld r10,PACAKMSR(r13) /* Get kernel MSR without EE */
775 mtmsrd r10,1
776#endif /* CONFIG_PPC_BOOK3E */
777 li r0,PACA_IRQ_HARD_DIS
778 stb r0,PACAIRQHAPPENED(r13)
779
780 /* Re-test flags and eventually loop */ 788 /* Re-test flags and eventually loop */
781 clrrdi r9,r1,THREAD_SHIFT 789 clrrdi r9,r1,THREAD_SHIFT
782 ld r4,TI_FLAGS(r9) 790 ld r4,TI_FLAGS(r9)
@@ -787,14 +795,6 @@ do_work:
787user_work: 795user_work:
788#endif /* CONFIG_PREEMPT */ 796#endif /* CONFIG_PREEMPT */
789 797
790 /* Enable interrupts */
791#ifdef CONFIG_PPC_BOOK3E
792 wrteei 1
793#else
794 ori r10,r10,MSR_EE
795 mtmsrd r10,1
796#endif /* CONFIG_PPC_BOOK3E */
797
798 andi. r0,r4,_TIF_NEED_RESCHED 798 andi. r0,r4,_TIF_NEED_RESCHED
799 beq 1f 799 beq 1f
800 bl .restore_interrupts 800 bl .restore_interrupts
diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
index cb705fdbb458..8f880bc77c56 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -768,8 +768,8 @@ alignment_common:
768 std r3,_DAR(r1) 768 std r3,_DAR(r1)
769 std r4,_DSISR(r1) 769 std r4,_DSISR(r1)
770 bl .save_nvgprs 770 bl .save_nvgprs
771 DISABLE_INTS
771 addi r3,r1,STACK_FRAME_OVERHEAD 772 addi r3,r1,STACK_FRAME_OVERHEAD
772 ENABLE_INTS
773 bl .alignment_exception 773 bl .alignment_exception
774 b .ret_from_except 774 b .ret_from_except
775 775
diff --git a/arch/powerpc/kernel/fadump.c b/arch/powerpc/kernel/fadump.c
index cfe7a38708c3..18bdf74fa164 100644
--- a/arch/powerpc/kernel/fadump.c
+++ b/arch/powerpc/kernel/fadump.c
@@ -40,6 +40,8 @@
40#include <asm/prom.h> 40#include <asm/prom.h>
41#include <asm/rtas.h> 41#include <asm/rtas.h>
42#include <asm/fadump.h> 42#include <asm/fadump.h>
43#include <asm/debug.h>
44#include <asm/setup.h>
43 45
44static struct fw_dump fw_dump; 46static struct fw_dump fw_dump;
45static struct fadump_mem_struct fdm; 47static struct fadump_mem_struct fdm;
diff --git a/arch/powerpc/kernel/ibmebus.c b/arch/powerpc/kernel/ibmebus.c
index 79bb282e6501..b01d14eeca8d 100644
--- a/arch/powerpc/kernel/ibmebus.c
+++ b/arch/powerpc/kernel/ibmebus.c
@@ -65,7 +65,8 @@ static struct of_device_id __initdata ibmebus_matches[] = {
65static void *ibmebus_alloc_coherent(struct device *dev, 65static void *ibmebus_alloc_coherent(struct device *dev,
66 size_t size, 66 size_t size,
67 dma_addr_t *dma_handle, 67 dma_addr_t *dma_handle,
68 gfp_t flag) 68 gfp_t flag,
69 struct dma_attrs *attrs)
69{ 70{
70 void *mem; 71 void *mem;
71 72
@@ -77,7 +78,8 @@ static void *ibmebus_alloc_coherent(struct device *dev,
77 78
78static void ibmebus_free_coherent(struct device *dev, 79static void ibmebus_free_coherent(struct device *dev,
79 size_t size, void *vaddr, 80 size_t size, void *vaddr,
80 dma_addr_t dma_handle) 81 dma_addr_t dma_handle,
82 struct dma_attrs *attrs)
81{ 83{
82 kfree(vaddr); 84 kfree(vaddr);
83} 85}
@@ -136,8 +138,8 @@ static u64 ibmebus_dma_get_required_mask(struct device *dev)
136} 138}
137 139
138static struct dma_map_ops ibmebus_dma_ops = { 140static struct dma_map_ops ibmebus_dma_ops = {
139 .alloc_coherent = ibmebus_alloc_coherent, 141 .alloc = ibmebus_alloc_coherent,
140 .free_coherent = ibmebus_free_coherent, 142 .free = ibmebus_free_coherent,
141 .map_sg = ibmebus_map_sg, 143 .map_sg = ibmebus_map_sg,
142 .unmap_sg = ibmebus_unmap_sg, 144 .unmap_sg = ibmebus_unmap_sg,
143 .dma_supported = ibmebus_dma_supported, 145 .dma_supported = ibmebus_dma_supported,
diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
index 243dbabfe74d..641da9e868ce 100644
--- a/arch/powerpc/kernel/irq.c
+++ b/arch/powerpc/kernel/irq.c
@@ -229,6 +229,19 @@ notrace void arch_local_irq_restore(unsigned long en)
229 */ 229 */
230 if (unlikely(irq_happened != PACA_IRQ_HARD_DIS)) 230 if (unlikely(irq_happened != PACA_IRQ_HARD_DIS))
231 __hard_irq_disable(); 231 __hard_irq_disable();
232#ifdef CONFIG_TRACE_IRQFLAG
233 else {
234 /*
235 * We should already be hard disabled here. We had bugs
236 * where that wasn't the case so let's dbl check it and
237 * warn if we are wrong. Only do that when IRQ tracing
238 * is enabled as mfmsr() can be costly.
239 */
240 if (WARN_ON(mfmsr() & MSR_EE))
241 __hard_irq_disable();
242 }
243#endif /* CONFIG_TRACE_IRQFLAG */
244
232 set_soft_enabled(0); 245 set_soft_enabled(0);
233 246
234 /* 247 /*
@@ -260,11 +273,17 @@ EXPORT_SYMBOL(arch_local_irq_restore);
260 * if they are currently disabled. This is typically called before 273 * if they are currently disabled. This is typically called before
261 * schedule() or do_signal() when returning to userspace. We do it 274 * schedule() or do_signal() when returning to userspace. We do it
262 * in C to avoid the burden of dealing with lockdep etc... 275 * in C to avoid the burden of dealing with lockdep etc...
276 *
277 * NOTE: This is called with interrupts hard disabled but not marked
278 * as such in paca->irq_happened, so we need to resync this.
263 */ 279 */
264void restore_interrupts(void) 280void restore_interrupts(void)
265{ 281{
266 if (irqs_disabled()) 282 if (irqs_disabled()) {
283 local_paca->irq_happened |= PACA_IRQ_HARD_DIS;
267 local_irq_enable(); 284 local_irq_enable();
285 } else
286 __hard_irq_enable();
268} 287}
269 288
270#endif /* CONFIG_PPC64 */ 289#endif /* CONFIG_PPC64 */
@@ -330,14 +349,10 @@ void migrate_irqs(void)
330 349
331 alloc_cpumask_var(&mask, GFP_KERNEL); 350 alloc_cpumask_var(&mask, GFP_KERNEL);
332 351
333 for_each_irq(irq) { 352 for_each_irq_desc(irq, desc) {
334 struct irq_data *data; 353 struct irq_data *data;
335 struct irq_chip *chip; 354 struct irq_chip *chip;
336 355
337 desc = irq_to_desc(irq);
338 if (!desc)
339 continue;
340
341 data = irq_desc_get_irq_data(desc); 356 data = irq_desc_get_irq_data(desc);
342 if (irqd_is_per_cpu(data)) 357 if (irqd_is_per_cpu(data))
343 continue; 358 continue;
@@ -560,12 +575,6 @@ void do_softirq(void)
560 local_irq_restore(flags); 575 local_irq_restore(flags);
561} 576}
562 577
563irq_hw_number_t irqd_to_hwirq(struct irq_data *d)
564{
565 return d->hwirq;
566}
567EXPORT_SYMBOL_GPL(irqd_to_hwirq);
568
569irq_hw_number_t virq_to_hw(unsigned int virq) 578irq_hw_number_t virq_to_hw(unsigned int virq)
570{ 579{
571 struct irq_data *irq_data = irq_get_irq_data(virq); 580 struct irq_data *irq_data = irq_get_irq_data(virq);
diff --git a/arch/powerpc/kernel/kgdb.c b/arch/powerpc/kernel/kgdb.c
index 76a6e40a6f7c..782bd0a3c2f0 100644
--- a/arch/powerpc/kernel/kgdb.c
+++ b/arch/powerpc/kernel/kgdb.c
@@ -24,6 +24,7 @@
24#include <asm/current.h> 24#include <asm/current.h>
25#include <asm/processor.h> 25#include <asm/processor.h>
26#include <asm/machdep.h> 26#include <asm/machdep.h>
27#include <asm/debug.h>
27 28
28/* 29/*
29 * This table contains the mapping between PowerPC hardware trap types, and 30 * This table contains the mapping between PowerPC hardware trap types, and
diff --git a/arch/powerpc/kernel/machine_kexec.c b/arch/powerpc/kernel/machine_kexec.c
index c957b1202bdc..5df777794403 100644
--- a/arch/powerpc/kernel/machine_kexec.c
+++ b/arch/powerpc/kernel/machine_kexec.c
@@ -23,14 +23,11 @@
23 23
24void machine_kexec_mask_interrupts(void) { 24void machine_kexec_mask_interrupts(void) {
25 unsigned int i; 25 unsigned int i;
26 struct irq_desc *desc;
26 27
27 for_each_irq(i) { 28 for_each_irq_desc(i, desc) {
28 struct irq_desc *desc = irq_to_desc(i);
29 struct irq_chip *chip; 29 struct irq_chip *chip;
30 30
31 if (!desc)
32 continue;
33
34 chip = irq_desc_get_chip(desc); 31 chip = irq_desc_get_chip(desc);
35 if (!chip) 32 if (!chip)
36 continue; 33 continue;
diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index f88698c0f332..4937c9690090 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -1235,7 +1235,7 @@ void __ppc64_runlatch_on(void)
1235 ctrl |= CTRL_RUNLATCH; 1235 ctrl |= CTRL_RUNLATCH;
1236 mtspr(SPRN_CTRLT, ctrl); 1236 mtspr(SPRN_CTRLT, ctrl);
1237 1237
1238 ti->local_flags |= TLF_RUNLATCH; 1238 ti->local_flags |= _TLF_RUNLATCH;
1239} 1239}
1240 1240
1241/* Called with hard IRQs off */ 1241/* Called with hard IRQs off */
@@ -1244,7 +1244,7 @@ void __ppc64_runlatch_off(void)
1244 struct thread_info *ti = current_thread_info(); 1244 struct thread_info *ti = current_thread_info();
1245 unsigned long ctrl; 1245 unsigned long ctrl;
1246 1246
1247 ti->local_flags &= ~TLF_RUNLATCH; 1247 ti->local_flags &= ~_TLF_RUNLATCH;
1248 1248
1249 ctrl = mfspr(SPRN_CTRLF); 1249 ctrl = mfspr(SPRN_CTRLF);
1250 ctrl &= ~CTRL_RUNLATCH; 1250 ctrl &= ~CTRL_RUNLATCH;
diff --git a/arch/powerpc/kernel/setup_32.c b/arch/powerpc/kernel/setup_32.c
index 9825f29d1faf..ec8a53fa9e8f 100644
--- a/arch/powerpc/kernel/setup_32.c
+++ b/arch/powerpc/kernel/setup_32.c
@@ -150,6 +150,9 @@ notrace void __init machine_init(u64 dt_ptr)
150} 150}
151 151
152#ifdef CONFIG_BOOKE_WDT 152#ifdef CONFIG_BOOKE_WDT
153extern u32 booke_wdt_enabled;
154extern u32 booke_wdt_period;
155
153/* Checks wdt=x and wdt_period=xx command-line option */ 156/* Checks wdt=x and wdt_period=xx command-line option */
154notrace int __init early_parse_wdt(char *p) 157notrace int __init early_parse_wdt(char *p)
155{ 158{
diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
index 6aa0c663e247..158972341a2d 100644
--- a/arch/powerpc/kernel/traps.c
+++ b/arch/powerpc/kernel/traps.c
@@ -248,7 +248,7 @@ void _exception(int signr, struct pt_regs *regs, int code, unsigned long addr)
248 addr, regs->nip, regs->link, code); 248 addr, regs->nip, regs->link, code);
249 } 249 }
250 250
251 if (!arch_irq_disabled_regs(regs)) 251 if (arch_irqs_disabled() && !arch_irq_disabled_regs(regs))
252 local_irq_enable(); 252 local_irq_enable();
253 253
254 memset(&info, 0, sizeof(info)); 254 memset(&info, 0, sizeof(info));
@@ -1019,7 +1019,9 @@ void __kprobes program_check_exception(struct pt_regs *regs)
1019 return; 1019 return;
1020 } 1020 }
1021 1021
1022 local_irq_enable(); 1022 /* We restore the interrupt state now */
1023 if (!arch_irq_disabled_regs(regs))
1024 local_irq_enable();
1023 1025
1024#ifdef CONFIG_MATH_EMULATION 1026#ifdef CONFIG_MATH_EMULATION
1025 /* (reason & REASON_ILLEGAL) would be the obvious thing here, 1027 /* (reason & REASON_ILLEGAL) would be the obvious thing here,
@@ -1069,6 +1071,10 @@ void alignment_exception(struct pt_regs *regs)
1069{ 1071{
1070 int sig, code, fixed = 0; 1072 int sig, code, fixed = 0;
1071 1073
1074 /* We restore the interrupt state now */
1075 if (!arch_irq_disabled_regs(regs))
1076 local_irq_enable();
1077
1072 /* we don't implement logging of alignment exceptions */ 1078 /* we don't implement logging of alignment exceptions */
1073 if (!(current->thread.align_ctl & PR_UNALIGN_SIGBUS)) 1079 if (!(current->thread.align_ctl & PR_UNALIGN_SIGBUS))
1074 fixed = fix_alignment(regs); 1080 fixed = fix_alignment(regs);
diff --git a/arch/powerpc/kernel/vio.c b/arch/powerpc/kernel/vio.c
index b2f7c8480bf6..a3a99901c8ec 100644
--- a/arch/powerpc/kernel/vio.c
+++ b/arch/powerpc/kernel/vio.c
@@ -482,7 +482,8 @@ static void vio_cmo_balance(struct work_struct *work)
482} 482}
483 483
484static void *vio_dma_iommu_alloc_coherent(struct device *dev, size_t size, 484static void *vio_dma_iommu_alloc_coherent(struct device *dev, size_t size,
485 dma_addr_t *dma_handle, gfp_t flag) 485 dma_addr_t *dma_handle, gfp_t flag,
486 struct dma_attrs *attrs)
486{ 487{
487 struct vio_dev *viodev = to_vio_dev(dev); 488 struct vio_dev *viodev = to_vio_dev(dev);
488 void *ret; 489 void *ret;
@@ -492,7 +493,7 @@ static void *vio_dma_iommu_alloc_coherent(struct device *dev, size_t size,
492 return NULL; 493 return NULL;
493 } 494 }
494 495
495 ret = dma_iommu_ops.alloc_coherent(dev, size, dma_handle, flag); 496 ret = dma_iommu_ops.alloc(dev, size, dma_handle, flag, attrs);
496 if (unlikely(ret == NULL)) { 497 if (unlikely(ret == NULL)) {
497 vio_cmo_dealloc(viodev, roundup(size, PAGE_SIZE)); 498 vio_cmo_dealloc(viodev, roundup(size, PAGE_SIZE));
498 atomic_inc(&viodev->cmo.allocs_failed); 499 atomic_inc(&viodev->cmo.allocs_failed);
@@ -502,11 +503,12 @@ static void *vio_dma_iommu_alloc_coherent(struct device *dev, size_t size,
502} 503}
503 504
504static void vio_dma_iommu_free_coherent(struct device *dev, size_t size, 505static void vio_dma_iommu_free_coherent(struct device *dev, size_t size,
505 void *vaddr, dma_addr_t dma_handle) 506 void *vaddr, dma_addr_t dma_handle,
507 struct dma_attrs *attrs)
506{ 508{
507 struct vio_dev *viodev = to_vio_dev(dev); 509 struct vio_dev *viodev = to_vio_dev(dev);
508 510
509 dma_iommu_ops.free_coherent(dev, size, vaddr, dma_handle); 511 dma_iommu_ops.free(dev, size, vaddr, dma_handle, attrs);
510 512
511 vio_cmo_dealloc(viodev, roundup(size, PAGE_SIZE)); 513 vio_cmo_dealloc(viodev, roundup(size, PAGE_SIZE));
512} 514}
@@ -607,8 +609,8 @@ static u64 vio_dma_get_required_mask(struct device *dev)
607} 609}
608 610
609struct dma_map_ops vio_dma_mapping_ops = { 611struct dma_map_ops vio_dma_mapping_ops = {
610 .alloc_coherent = vio_dma_iommu_alloc_coherent, 612 .alloc = vio_dma_iommu_alloc_coherent,
611 .free_coherent = vio_dma_iommu_free_coherent, 613 .free = vio_dma_iommu_free_coherent,
612 .map_sg = vio_dma_iommu_map_sg, 614 .map_sg = vio_dma_iommu_map_sg,
613 .unmap_sg = vio_dma_iommu_unmap_sg, 615 .unmap_sg = vio_dma_iommu_unmap_sg,
614 .map_page = vio_dma_iommu_map_page, 616 .map_page = vio_dma_iommu_map_page,
diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c b/arch/powerpc/kvm/book3s_64_mmu_hv.c
index ddc485a529f2..c3beaeef3f60 100644
--- a/arch/powerpc/kvm/book3s_64_mmu_hv.c
+++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c
@@ -258,6 +258,8 @@ static long kvmppc_get_guest_page(struct kvm *kvm, unsigned long gfn,
258 !(memslot->userspace_addr & (s - 1))) { 258 !(memslot->userspace_addr & (s - 1))) {
259 start &= ~(s - 1); 259 start &= ~(s - 1);
260 pgsize = s; 260 pgsize = s;
261 get_page(hpage);
262 put_page(page);
261 page = hpage; 263 page = hpage;
262 } 264 }
263 } 265 }
@@ -281,11 +283,8 @@ static long kvmppc_get_guest_page(struct kvm *kvm, unsigned long gfn,
281 err = 0; 283 err = 0;
282 284
283 out: 285 out:
284 if (got) { 286 if (got)
285 if (PageHuge(page))
286 page = compound_head(page);
287 put_page(page); 287 put_page(page);
288 }
289 return err; 288 return err;
290 289
291 up_err: 290 up_err:
@@ -678,8 +677,15 @@ int kvmppc_book3s_hv_page_fault(struct kvm_run *run, struct kvm_vcpu *vcpu,
678 SetPageDirty(page); 677 SetPageDirty(page);
679 678
680 out_put: 679 out_put:
681 if (page) 680 if (page) {
682 put_page(page); 681 /*
682 * We drop pages[0] here, not page because page might
683 * have been set to the head page of a compound, but
684 * we have to drop the reference on the correct tail
685 * page to match the get inside gup()
686 */
687 put_page(pages[0]);
688 }
683 return ret; 689 return ret;
684 690
685 out_unlock: 691 out_unlock:
@@ -979,6 +985,7 @@ void *kvmppc_pin_guest_page(struct kvm *kvm, unsigned long gpa,
979 pa = *physp; 985 pa = *physp;
980 } 986 }
981 page = pfn_to_page(pa >> PAGE_SHIFT); 987 page = pfn_to_page(pa >> PAGE_SHIFT);
988 get_page(page);
982 } else { 989 } else {
983 hva = gfn_to_hva_memslot(memslot, gfn); 990 hva = gfn_to_hva_memslot(memslot, gfn);
984 npages = get_user_pages_fast(hva, 1, 1, pages); 991 npages = get_user_pages_fast(hva, 1, 1, pages);
@@ -991,8 +998,6 @@ void *kvmppc_pin_guest_page(struct kvm *kvm, unsigned long gpa,
991 page = compound_head(page); 998 page = compound_head(page);
992 psize <<= compound_order(page); 999 psize <<= compound_order(page);
993 } 1000 }
994 if (!kvm->arch.using_mmu_notifiers)
995 get_page(page);
996 offset = gpa & (psize - 1); 1001 offset = gpa & (psize - 1);
997 if (nb_ret) 1002 if (nb_ret)
998 *nb_ret = psize - offset; 1003 *nb_ret = psize - offset;
@@ -1003,7 +1008,6 @@ void kvmppc_unpin_guest_page(struct kvm *kvm, void *va)
1003{ 1008{
1004 struct page *page = virt_to_page(va); 1009 struct page *page = virt_to_page(va);
1005 1010
1006 page = compound_head(page);
1007 put_page(page); 1011 put_page(page);
1008} 1012}
1009 1013
diff --git a/arch/powerpc/kvm/book3s_emulate.c b/arch/powerpc/kvm/book3s_emulate.c
index f1950d131827..135663a3e4fc 100644
--- a/arch/powerpc/kvm/book3s_emulate.c
+++ b/arch/powerpc/kvm/book3s_emulate.c
@@ -21,6 +21,7 @@
21#include <asm/disassemble.h> 21#include <asm/disassemble.h>
22#include <asm/kvm_book3s.h> 22#include <asm/kvm_book3s.h>
23#include <asm/reg.h> 23#include <asm/reg.h>
24#include <asm/switch_to.h>
24 25
25#define OP_19_XOP_RFID 18 26#define OP_19_XOP_RFID 18
26#define OP_19_XOP_RFI 50 27#define OP_19_XOP_RFI 50
diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index 01294a5099dd..108d1f580177 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -1192,8 +1192,6 @@ static void unpin_slot(struct kvm *kvm, int slot_id)
1192 continue; 1192 continue;
1193 pfn = physp[j] >> PAGE_SHIFT; 1193 pfn = physp[j] >> PAGE_SHIFT;
1194 page = pfn_to_page(pfn); 1194 page = pfn_to_page(pfn);
1195 if (PageHuge(page))
1196 page = compound_head(page);
1197 SetPageDirty(page); 1195 SetPageDirty(page);
1198 put_page(page); 1196 put_page(page);
1199 } 1197 }
diff --git a/arch/powerpc/kvm/book3s_hv_builtin.c b/arch/powerpc/kvm/book3s_hv_builtin.c
index bed1279aa6a8..e1b60f56f2a1 100644
--- a/arch/powerpc/kvm/book3s_hv_builtin.c
+++ b/arch/powerpc/kvm/book3s_hv_builtin.c
@@ -173,9 +173,9 @@ static void __init kvm_linear_init_one(ulong size, int count, int type)
173 173
174static struct kvmppc_linear_info *kvm_alloc_linear(int type) 174static struct kvmppc_linear_info *kvm_alloc_linear(int type)
175{ 175{
176 struct kvmppc_linear_info *ri; 176 struct kvmppc_linear_info *ri, *ret;
177 177
178 ri = NULL; 178 ret = NULL;
179 spin_lock(&linear_lock); 179 spin_lock(&linear_lock);
180 list_for_each_entry(ri, &free_linears, list) { 180 list_for_each_entry(ri, &free_linears, list) {
181 if (ri->type != type) 181 if (ri->type != type)
@@ -183,11 +183,12 @@ static struct kvmppc_linear_info *kvm_alloc_linear(int type)
183 183
184 list_del(&ri->list); 184 list_del(&ri->list);
185 atomic_inc(&ri->use_count); 185 atomic_inc(&ri->use_count);
186 memset(ri->base_virt, 0, ri->npages << PAGE_SHIFT);
187 ret = ri;
186 break; 188 break;
187 } 189 }
188 spin_unlock(&linear_lock); 190 spin_unlock(&linear_lock);
189 memset(ri->base_virt, 0, ri->npages << PAGE_SHIFT); 191 return ret;
190 return ri;
191} 192}
192 193
193static void kvm_release_linear(struct kvmppc_linear_info *ri) 194static void kvm_release_linear(struct kvmppc_linear_info *ri)
diff --git a/arch/powerpc/kvm/book3s_hv_interrupts.S b/arch/powerpc/kvm/book3s_hv_interrupts.S
index 3f7b674dd4bf..d3fb4df02c41 100644
--- a/arch/powerpc/kvm/book3s_hv_interrupts.S
+++ b/arch/powerpc/kvm/book3s_hv_interrupts.S
@@ -46,8 +46,10 @@ _GLOBAL(__kvmppc_vcore_entry)
46 /* Save host state to the stack */ 46 /* Save host state to the stack */
47 stdu r1, -SWITCH_FRAME_SIZE(r1) 47 stdu r1, -SWITCH_FRAME_SIZE(r1)
48 48
49 /* Save non-volatile registers (r14 - r31) */ 49 /* Save non-volatile registers (r14 - r31) and CR */
50 SAVE_NVGPRS(r1) 50 SAVE_NVGPRS(r1)
51 mfcr r3
52 std r3, _CCR(r1)
51 53
52 /* Save host DSCR */ 54 /* Save host DSCR */
53BEGIN_FTR_SECTION 55BEGIN_FTR_SECTION
@@ -157,8 +159,10 @@ kvmppc_handler_highmem:
157 * R13 = PACA 159 * R13 = PACA
158 */ 160 */
159 161
160 /* Restore non-volatile host registers (r14 - r31) */ 162 /* Restore non-volatile host registers (r14 - r31) and CR */
161 REST_NVGPRS(r1) 163 REST_NVGPRS(r1)
164 ld r4, _CCR(r1)
165 mtcr r4
162 166
163 addi r1, r1, SWITCH_FRAME_SIZE 167 addi r1, r1, SWITCH_FRAME_SIZE
164 ld r0, PPC_LR_STKOFF(r1) 168 ld r0, PPC_LR_STKOFF(r1)
diff --git a/arch/powerpc/kvm/book3s_interrupts.S b/arch/powerpc/kvm/book3s_interrupts.S
index 0a8515a5c042..3e35383bdb21 100644
--- a/arch/powerpc/kvm/book3s_interrupts.S
+++ b/arch/powerpc/kvm/book3s_interrupts.S
@@ -84,6 +84,10 @@ kvm_start_entry:
84 /* Save non-volatile registers (r14 - r31) */ 84 /* Save non-volatile registers (r14 - r31) */
85 SAVE_NVGPRS(r1) 85 SAVE_NVGPRS(r1)
86 86
87 /* Save CR */
88 mfcr r14
89 stw r14, _CCR(r1)
90
87 /* Save LR */ 91 /* Save LR */
88 PPC_STL r0, _LINK(r1) 92 PPC_STL r0, _LINK(r1)
89 93
@@ -165,6 +169,9 @@ kvm_exit_loop:
165 PPC_LL r4, _LINK(r1) 169 PPC_LL r4, _LINK(r1)
166 mtlr r4 170 mtlr r4
167 171
172 lwz r14, _CCR(r1)
173 mtcr r14
174
168 /* Restore non-volatile host registers (r14 - r31) */ 175 /* Restore non-volatile host registers (r14 - r31) */
169 REST_NVGPRS(r1) 176 REST_NVGPRS(r1)
170 177
diff --git a/arch/powerpc/kvm/book3s_paired_singles.c b/arch/powerpc/kvm/book3s_paired_singles.c
index e70ef2d86431..a59a25a13218 100644
--- a/arch/powerpc/kvm/book3s_paired_singles.c
+++ b/arch/powerpc/kvm/book3s_paired_singles.c
@@ -24,6 +24,7 @@
24#include <asm/kvm_fpu.h> 24#include <asm/kvm_fpu.h>
25#include <asm/reg.h> 25#include <asm/reg.h>
26#include <asm/cacheflush.h> 26#include <asm/cacheflush.h>
27#include <asm/switch_to.h>
27#include <linux/vmalloc.h> 28#include <linux/vmalloc.h>
28 29
29/* #define DEBUG */ 30/* #define DEBUG */
diff --git a/arch/powerpc/kvm/book3s_pr.c b/arch/powerpc/kvm/book3s_pr.c
index 7340e1090b77..7759053d391b 100644
--- a/arch/powerpc/kvm/book3s_pr.c
+++ b/arch/powerpc/kvm/book3s_pr.c
@@ -33,6 +33,7 @@
33#include <asm/kvm_ppc.h> 33#include <asm/kvm_ppc.h>
34#include <asm/kvm_book3s.h> 34#include <asm/kvm_book3s.h>
35#include <asm/mmu_context.h> 35#include <asm/mmu_context.h>
36#include <asm/switch_to.h>
36#include <linux/gfp.h> 37#include <linux/gfp.h>
37#include <linux/sched.h> 38#include <linux/sched.h>
38#include <linux/vmalloc.h> 39#include <linux/vmalloc.h>
@@ -776,6 +777,7 @@ program_interrupt:
776 } 777 }
777 } 778 }
778 779
780 preempt_disable();
779 if (!(r & RESUME_HOST)) { 781 if (!(r & RESUME_HOST)) {
780 /* To avoid clobbering exit_reason, only check for signals if 782 /* To avoid clobbering exit_reason, only check for signals if
781 * we aren't already exiting to userspace for some other 783 * we aren't already exiting to userspace for some other
@@ -797,8 +799,6 @@ program_interrupt:
797 run->exit_reason = KVM_EXIT_INTR; 799 run->exit_reason = KVM_EXIT_INTR;
798 r = -EINTR; 800 r = -EINTR;
799 } else { 801 } else {
800 preempt_disable();
801
802 /* In case an interrupt came in that was triggered 802 /* In case an interrupt came in that was triggered
803 * from userspace (like DEC), we need to check what 803 * from userspace (like DEC), we need to check what
804 * to inject now! */ 804 * to inject now! */
@@ -880,7 +880,8 @@ int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)
880 880
881 switch (reg->id) { 881 switch (reg->id) {
882 case KVM_REG_PPC_HIOR: 882 case KVM_REG_PPC_HIOR:
883 r = put_user(to_book3s(vcpu)->hior, (u64 __user *)reg->addr); 883 r = copy_to_user((u64 __user *)(long)reg->addr,
884 &to_book3s(vcpu)->hior, sizeof(u64));
884 break; 885 break;
885 default: 886 default:
886 break; 887 break;
@@ -895,7 +896,8 @@ int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)
895 896
896 switch (reg->id) { 897 switch (reg->id) {
897 case KVM_REG_PPC_HIOR: 898 case KVM_REG_PPC_HIOR:
898 r = get_user(to_book3s(vcpu)->hior, (u64 __user *)reg->addr); 899 r = copy_from_user(&to_book3s(vcpu)->hior,
900 (u64 __user *)(long)reg->addr, sizeof(u64));
899 if (!r) 901 if (!r)
900 to_book3s(vcpu)->hior_explicit = true; 902 to_book3s(vcpu)->hior_explicit = true;
901 break; 903 break;
diff --git a/arch/powerpc/kvm/booke_interrupts.S b/arch/powerpc/kvm/booke_interrupts.S
index 10d8ef602e5c..c8c4b878795a 100644
--- a/arch/powerpc/kvm/booke_interrupts.S
+++ b/arch/powerpc/kvm/booke_interrupts.S
@@ -34,7 +34,8 @@
34/* r2 is special: it holds 'current', and it made nonvolatile in the 34/* r2 is special: it holds 'current', and it made nonvolatile in the
35 * kernel with the -ffixed-r2 gcc option. */ 35 * kernel with the -ffixed-r2 gcc option. */
36#define HOST_R2 12 36#define HOST_R2 12
37#define HOST_NV_GPRS 16 37#define HOST_CR 16
38#define HOST_NV_GPRS 20
38#define HOST_NV_GPR(n) (HOST_NV_GPRS + ((n - 14) * 4)) 39#define HOST_NV_GPR(n) (HOST_NV_GPRS + ((n - 14) * 4))
39#define HOST_MIN_STACK_SIZE (HOST_NV_GPR(31) + 4) 40#define HOST_MIN_STACK_SIZE (HOST_NV_GPR(31) + 4)
40#define HOST_STACK_SIZE (((HOST_MIN_STACK_SIZE + 15) / 16) * 16) /* Align. */ 41#define HOST_STACK_SIZE (((HOST_MIN_STACK_SIZE + 15) / 16) * 16) /* Align. */
@@ -296,8 +297,10 @@ heavyweight_exit:
296 297
297 /* Return to kvm_vcpu_run(). */ 298 /* Return to kvm_vcpu_run(). */
298 lwz r4, HOST_STACK_LR(r1) 299 lwz r4, HOST_STACK_LR(r1)
300 lwz r5, HOST_CR(r1)
299 addi r1, r1, HOST_STACK_SIZE 301 addi r1, r1, HOST_STACK_SIZE
300 mtlr r4 302 mtlr r4
303 mtcr r5
301 /* r3 still contains the return code from kvmppc_handle_exit(). */ 304 /* r3 still contains the return code from kvmppc_handle_exit(). */
302 blr 305 blr
303 306
@@ -314,6 +317,8 @@ _GLOBAL(__kvmppc_vcpu_run)
314 stw r3, HOST_RUN(r1) 317 stw r3, HOST_RUN(r1)
315 mflr r3 318 mflr r3
316 stw r3, HOST_STACK_LR(r1) 319 stw r3, HOST_STACK_LR(r1)
320 mfcr r5
321 stw r5, HOST_CR(r1)
317 322
318 /* Save host non-volatile register state to stack. */ 323 /* Save host non-volatile register state to stack. */
319 stw r14, HOST_NV_GPR(r14)(r1) 324 stw r14, HOST_NV_GPR(r14)(r1)
diff --git a/arch/powerpc/net/bpf_jit.h b/arch/powerpc/net/bpf_jit.h
index af1ab5e9a691..5c3cf2d04e41 100644
--- a/arch/powerpc/net/bpf_jit.h
+++ b/arch/powerpc/net/bpf_jit.h
@@ -48,7 +48,13 @@
48/* 48/*
49 * Assembly helpers from arch/powerpc/net/bpf_jit.S: 49 * Assembly helpers from arch/powerpc/net/bpf_jit.S:
50 */ 50 */
51extern u8 sk_load_word[], sk_load_half[], sk_load_byte[], sk_load_byte_msh[]; 51#define DECLARE_LOAD_FUNC(func) \
52 extern u8 func[], func##_negative_offset[], func##_positive_offset[]
53
54DECLARE_LOAD_FUNC(sk_load_word);
55DECLARE_LOAD_FUNC(sk_load_half);
56DECLARE_LOAD_FUNC(sk_load_byte);
57DECLARE_LOAD_FUNC(sk_load_byte_msh);
52 58
53#define FUNCTION_DESCR_SIZE 24 59#define FUNCTION_DESCR_SIZE 24
54 60
diff --git a/arch/powerpc/net/bpf_jit_64.S b/arch/powerpc/net/bpf_jit_64.S
index ff4506e85cce..55ba3855a97f 100644
--- a/arch/powerpc/net/bpf_jit_64.S
+++ b/arch/powerpc/net/bpf_jit_64.S
@@ -31,14 +31,13 @@
31 * then branch directly to slow_path_XXX if required. (In fact, could 31 * then branch directly to slow_path_XXX if required. (In fact, could
32 * load a spare GPR with the address of slow_path_generic and pass size 32 * load a spare GPR with the address of slow_path_generic and pass size
33 * as an argument, making the call site a mtlr, li and bllr.) 33 * as an argument, making the call site a mtlr, li and bllr.)
34 *
35 * Technically, the "is addr < 0" check is unnecessary & slowing down
36 * the ABS path, as it's statically checked on generation.
37 */ 34 */
38 .globl sk_load_word 35 .globl sk_load_word
39sk_load_word: 36sk_load_word:
40 cmpdi r_addr, 0 37 cmpdi r_addr, 0
41 blt bpf_error 38 blt bpf_slow_path_word_neg
39 .globl sk_load_word_positive_offset
40sk_load_word_positive_offset:
42 /* Are we accessing past headlen? */ 41 /* Are we accessing past headlen? */
43 subi r_scratch1, r_HL, 4 42 subi r_scratch1, r_HL, 4
44 cmpd r_scratch1, r_addr 43 cmpd r_scratch1, r_addr
@@ -51,7 +50,9 @@ sk_load_word:
51 .globl sk_load_half 50 .globl sk_load_half
52sk_load_half: 51sk_load_half:
53 cmpdi r_addr, 0 52 cmpdi r_addr, 0
54 blt bpf_error 53 blt bpf_slow_path_half_neg
54 .globl sk_load_half_positive_offset
55sk_load_half_positive_offset:
55 subi r_scratch1, r_HL, 2 56 subi r_scratch1, r_HL, 2
56 cmpd r_scratch1, r_addr 57 cmpd r_scratch1, r_addr
57 blt bpf_slow_path_half 58 blt bpf_slow_path_half
@@ -61,7 +62,9 @@ sk_load_half:
61 .globl sk_load_byte 62 .globl sk_load_byte
62sk_load_byte: 63sk_load_byte:
63 cmpdi r_addr, 0 64 cmpdi r_addr, 0
64 blt bpf_error 65 blt bpf_slow_path_byte_neg
66 .globl sk_load_byte_positive_offset
67sk_load_byte_positive_offset:
65 cmpd r_HL, r_addr 68 cmpd r_HL, r_addr
66 ble bpf_slow_path_byte 69 ble bpf_slow_path_byte
67 lbzx r_A, r_D, r_addr 70 lbzx r_A, r_D, r_addr
@@ -69,22 +72,20 @@ sk_load_byte:
69 72
70/* 73/*
71 * BPF_S_LDX_B_MSH: ldxb 4*([offset]&0xf) 74 * BPF_S_LDX_B_MSH: ldxb 4*([offset]&0xf)
72 * r_addr is the offset value, already known positive 75 * r_addr is the offset value
73 */ 76 */
74 .globl sk_load_byte_msh 77 .globl sk_load_byte_msh
75sk_load_byte_msh: 78sk_load_byte_msh:
79 cmpdi r_addr, 0
80 blt bpf_slow_path_byte_msh_neg
81 .globl sk_load_byte_msh_positive_offset
82sk_load_byte_msh_positive_offset:
76 cmpd r_HL, r_addr 83 cmpd r_HL, r_addr
77 ble bpf_slow_path_byte_msh 84 ble bpf_slow_path_byte_msh
78 lbzx r_X, r_D, r_addr 85 lbzx r_X, r_D, r_addr
79 rlwinm r_X, r_X, 2, 32-4-2, 31-2 86 rlwinm r_X, r_X, 2, 32-4-2, 31-2
80 blr 87 blr
81 88
82bpf_error:
83 /* Entered with cr0 = lt */
84 li r3, 0
85 /* Generated code will 'blt epilogue', returning 0. */
86 blr
87
88/* Call out to skb_copy_bits: 89/* Call out to skb_copy_bits:
89 * We'll need to back up our volatile regs first; we have 90 * We'll need to back up our volatile regs first; we have
90 * local variable space at r1+(BPF_PPC_STACK_BASIC). 91 * local variable space at r1+(BPF_PPC_STACK_BASIC).
@@ -136,3 +137,84 @@ bpf_slow_path_byte_msh:
136 lbz r_X, BPF_PPC_STACK_BASIC+(2*8)(r1) 137 lbz r_X, BPF_PPC_STACK_BASIC+(2*8)(r1)
137 rlwinm r_X, r_X, 2, 32-4-2, 31-2 138 rlwinm r_X, r_X, 2, 32-4-2, 31-2
138 blr 139 blr
140
141/* Call out to bpf_internal_load_pointer_neg_helper:
142 * We'll need to back up our volatile regs first; we have
143 * local variable space at r1+(BPF_PPC_STACK_BASIC).
144 * Allocate a new stack frame here to remain ABI-compliant in
145 * stashing LR.
146 */
147#define sk_negative_common(SIZE) \
148 mflr r0; \
149 std r0, 16(r1); \
150 /* R3 goes in parameter space of caller's frame */ \
151 std r_skb, (BPF_PPC_STACKFRAME+48)(r1); \
152 std r_A, (BPF_PPC_STACK_BASIC+(0*8))(r1); \
153 std r_X, (BPF_PPC_STACK_BASIC+(1*8))(r1); \
154 stdu r1, -BPF_PPC_SLOWPATH_FRAME(r1); \
155 /* R3 = r_skb, as passed */ \
156 mr r4, r_addr; \
157 li r5, SIZE; \
158 bl bpf_internal_load_pointer_neg_helper; \
159 /* R3 != 0 on success */ \
160 addi r1, r1, BPF_PPC_SLOWPATH_FRAME; \
161 ld r0, 16(r1); \
162 ld r_A, (BPF_PPC_STACK_BASIC+(0*8))(r1); \
163 ld r_X, (BPF_PPC_STACK_BASIC+(1*8))(r1); \
164 mtlr r0; \
165 cmpldi r3, 0; \
166 beq bpf_error_slow; /* cr0 = EQ */ \
167 mr r_addr, r3; \
168 ld r_skb, (BPF_PPC_STACKFRAME+48)(r1); \
169 /* Great success! */
170
171bpf_slow_path_word_neg:
172 lis r_scratch1,-32 /* SKF_LL_OFF */
173 cmpd r_addr, r_scratch1 /* addr < SKF_* */
174 blt bpf_error /* cr0 = LT */
175 .globl sk_load_word_negative_offset
176sk_load_word_negative_offset:
177 sk_negative_common(4)
178 lwz r_A, 0(r_addr)
179 blr
180
181bpf_slow_path_half_neg:
182 lis r_scratch1,-32 /* SKF_LL_OFF */
183 cmpd r_addr, r_scratch1 /* addr < SKF_* */
184 blt bpf_error /* cr0 = LT */
185 .globl sk_load_half_negative_offset
186sk_load_half_negative_offset:
187 sk_negative_common(2)
188 lhz r_A, 0(r_addr)
189 blr
190
191bpf_slow_path_byte_neg:
192 lis r_scratch1,-32 /* SKF_LL_OFF */
193 cmpd r_addr, r_scratch1 /* addr < SKF_* */
194 blt bpf_error /* cr0 = LT */
195 .globl sk_load_byte_negative_offset
196sk_load_byte_negative_offset:
197 sk_negative_common(1)
198 lbz r_A, 0(r_addr)
199 blr
200
201bpf_slow_path_byte_msh_neg:
202 lis r_scratch1,-32 /* SKF_LL_OFF */
203 cmpd r_addr, r_scratch1 /* addr < SKF_* */
204 blt bpf_error /* cr0 = LT */
205 .globl sk_load_byte_msh_negative_offset
206sk_load_byte_msh_negative_offset:
207 sk_negative_common(1)
208 lbz r_X, 0(r_addr)
209 rlwinm r_X, r_X, 2, 32-4-2, 31-2
210 blr
211
212bpf_error_slow:
213 /* fabricate a cr0 = lt */
214 li r_scratch1, -1
215 cmpdi r_scratch1, 0
216bpf_error:
217 /* Entered with cr0 = lt */
218 li r3, 0
219 /* Generated code will 'blt epilogue', returning 0. */
220 blr
diff --git a/arch/powerpc/net/bpf_jit_comp.c b/arch/powerpc/net/bpf_jit_comp.c
index 73619d3aeb6c..2dc8b1484845 100644
--- a/arch/powerpc/net/bpf_jit_comp.c
+++ b/arch/powerpc/net/bpf_jit_comp.c
@@ -127,6 +127,9 @@ static void bpf_jit_build_epilogue(u32 *image, struct codegen_context *ctx)
127 PPC_BLR(); 127 PPC_BLR();
128} 128}
129 129
130#define CHOOSE_LOAD_FUNC(K, func) \
131 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
132
130/* Assemble the body code between the prologue & epilogue. */ 133/* Assemble the body code between the prologue & epilogue. */
131static int bpf_jit_build_body(struct sk_filter *fp, u32 *image, 134static int bpf_jit_build_body(struct sk_filter *fp, u32 *image,
132 struct codegen_context *ctx, 135 struct codegen_context *ctx,
@@ -391,21 +394,16 @@ static int bpf_jit_build_body(struct sk_filter *fp, u32 *image,
391 394
392 /*** Absolute loads from packet header/data ***/ 395 /*** Absolute loads from packet header/data ***/
393 case BPF_S_LD_W_ABS: 396 case BPF_S_LD_W_ABS:
394 func = sk_load_word; 397 func = CHOOSE_LOAD_FUNC(K, sk_load_word);
395 goto common_load; 398 goto common_load;
396 case BPF_S_LD_H_ABS: 399 case BPF_S_LD_H_ABS:
397 func = sk_load_half; 400 func = CHOOSE_LOAD_FUNC(K, sk_load_half);
398 goto common_load; 401 goto common_load;
399 case BPF_S_LD_B_ABS: 402 case BPF_S_LD_B_ABS:
400 func = sk_load_byte; 403 func = CHOOSE_LOAD_FUNC(K, sk_load_byte);
401 common_load: 404 common_load:
402 /* 405 /* Load from [K]. */
403 * Load from [K]. Reference with the (negative)
404 * SKF_NET_OFF/SKF_LL_OFF offsets is unsupported.
405 */
406 ctx->seen |= SEEN_DATAREF; 406 ctx->seen |= SEEN_DATAREF;
407 if ((int)K < 0)
408 return -ENOTSUPP;
409 PPC_LI64(r_scratch1, func); 407 PPC_LI64(r_scratch1, func);
410 PPC_MTLR(r_scratch1); 408 PPC_MTLR(r_scratch1);
411 PPC_LI32(r_addr, K); 409 PPC_LI32(r_addr, K);
@@ -429,7 +427,7 @@ static int bpf_jit_build_body(struct sk_filter *fp, u32 *image,
429 common_load_ind: 427 common_load_ind:
430 /* 428 /*
431 * Load from [X + K]. Negative offsets are tested for 429 * Load from [X + K]. Negative offsets are tested for
432 * in the helper functions, and result in a 'ret 0'. 430 * in the helper functions.
433 */ 431 */
434 ctx->seen |= SEEN_DATAREF | SEEN_XREG; 432 ctx->seen |= SEEN_DATAREF | SEEN_XREG;
435 PPC_LI64(r_scratch1, func); 433 PPC_LI64(r_scratch1, func);
@@ -443,13 +441,7 @@ static int bpf_jit_build_body(struct sk_filter *fp, u32 *image,
443 break; 441 break;
444 442
445 case BPF_S_LDX_B_MSH: 443 case BPF_S_LDX_B_MSH:
446 /* 444 func = CHOOSE_LOAD_FUNC(K, sk_load_byte_msh);
447 * x86 version drops packet (RET 0) when K<0, whereas
448 * interpreter does allow K<0 (__load_pointer, special
449 * ancillary data). common_load returns ENOTSUPP if K<0,
450 * so we fall back to interpreter & filter works.
451 */
452 func = sk_load_byte_msh;
453 goto common_load; 445 goto common_load;
454 break; 446 break;
455 447
diff --git a/arch/powerpc/platforms/52xx/mpc52xx_pci.c b/arch/powerpc/platforms/52xx/mpc52xx_pci.c
index bfb11e01133e..e2d401ad8fbb 100644
--- a/arch/powerpc/platforms/52xx/mpc52xx_pci.c
+++ b/arch/powerpc/platforms/52xx/mpc52xx_pci.c
@@ -93,7 +93,7 @@ struct mpc52xx_pci {
93}; 93};
94 94
95/* MPC5200 device tree match tables */ 95/* MPC5200 device tree match tables */
96const struct of_device_id mpc52xx_pci_ids[] __initdata = { 96const struct of_device_id mpc52xx_pci_ids[] __initconst = {
97 { .type = "pci", .compatible = "fsl,mpc5200-pci", }, 97 { .type = "pci", .compatible = "fsl,mpc5200-pci", },
98 { .type = "pci", .compatible = "mpc5200-pci", }, 98 { .type = "pci", .compatible = "mpc5200-pci", },
99 {} 99 {}
diff --git a/arch/powerpc/platforms/85xx/common.c b/arch/powerpc/platforms/85xx/common.c
index 9fef5302adc1..67dac22b4363 100644
--- a/arch/powerpc/platforms/85xx/common.c
+++ b/arch/powerpc/platforms/85xx/common.c
@@ -21,6 +21,12 @@ static struct of_device_id __initdata mpc85xx_common_ids[] = {
21 { .compatible = "fsl,qe", }, 21 { .compatible = "fsl,qe", },
22 { .compatible = "fsl,cpm2", }, 22 { .compatible = "fsl,cpm2", },
23 { .compatible = "fsl,srio", }, 23 { .compatible = "fsl,srio", },
24 /* So that the DMA channel nodes can be probed individually: */
25 { .compatible = "fsl,eloplus-dma", },
26 /* For the PMC driver */
27 { .compatible = "fsl,mpc8548-guts", },
28 /* Probably unnecessary? */
29 { .compatible = "gpio-leds", },
24 {}, 30 {},
25}; 31};
26 32
diff --git a/arch/powerpc/platforms/85xx/mpc85xx_mds.c b/arch/powerpc/platforms/85xx/mpc85xx_mds.c
index 3754ddc00af7..d208ebccb91c 100644
--- a/arch/powerpc/platforms/85xx/mpc85xx_mds.c
+++ b/arch/powerpc/platforms/85xx/mpc85xx_mds.c
@@ -270,7 +270,7 @@ static void __init mpc85xx_mds_qe_init(void)
270 270
271 if (machine_is(p1021_mds)) { 271 if (machine_is(p1021_mds)) {
272 272
273 struct ccsr_guts_85xx __iomem *guts; 273 struct ccsr_guts __iomem *guts;
274 274
275 np = of_find_node_by_name(NULL, "global-utilities"); 275 np = of_find_node_by_name(NULL, "global-utilities");
276 if (np) { 276 if (np) {
@@ -399,12 +399,6 @@ static int __init board_fixups(void)
399machine_arch_initcall(mpc8568_mds, board_fixups); 399machine_arch_initcall(mpc8568_mds, board_fixups);
400machine_arch_initcall(mpc8569_mds, board_fixups); 400machine_arch_initcall(mpc8569_mds, board_fixups);
401 401
402static struct of_device_id mpc85xx_ids[] = {
403 { .compatible = "fsl,mpc8548-guts", },
404 { .compatible = "gpio-leds", },
405 {},
406};
407
408static int __init mpc85xx_publish_devices(void) 402static int __init mpc85xx_publish_devices(void)
409{ 403{
410 if (machine_is(mpc8568_mds)) 404 if (machine_is(mpc8568_mds))
@@ -412,10 +406,7 @@ static int __init mpc85xx_publish_devices(void)
412 if (machine_is(mpc8569_mds)) 406 if (machine_is(mpc8569_mds))
413 simple_gpiochip_init("fsl,mpc8569mds-bcsr-gpio"); 407 simple_gpiochip_init("fsl,mpc8569mds-bcsr-gpio");
414 408
415 mpc85xx_common_publish_devices(); 409 return mpc85xx_common_publish_devices();
416 of_platform_bus_probe(NULL, mpc85xx_ids, NULL);
417
418 return 0;
419} 410}
420 411
421machine_device_initcall(mpc8568_mds, mpc85xx_publish_devices); 412machine_device_initcall(mpc8568_mds, mpc85xx_publish_devices);
diff --git a/arch/powerpc/platforms/85xx/mpc85xx_rdb.c b/arch/powerpc/platforms/85xx/mpc85xx_rdb.c
index 9848f9e39853..313fce4f5574 100644
--- a/arch/powerpc/platforms/85xx/mpc85xx_rdb.c
+++ b/arch/powerpc/platforms/85xx/mpc85xx_rdb.c
@@ -127,7 +127,7 @@ static void __init mpc85xx_rdb_setup_arch(void)
127#if defined(CONFIG_UCC_GETH) || defined(CONFIG_SERIAL_QE) 127#if defined(CONFIG_UCC_GETH) || defined(CONFIG_SERIAL_QE)
128 if (machine_is(p1025_rdb)) { 128 if (machine_is(p1025_rdb)) {
129 129
130 struct ccsr_guts_85xx __iomem *guts; 130 struct ccsr_guts __iomem *guts;
131 131
132 np = of_find_node_by_name(NULL, "global-utilities"); 132 np = of_find_node_by_name(NULL, "global-utilities");
133 if (np) { 133 if (np) {
diff --git a/arch/powerpc/platforms/85xx/p1022_ds.c b/arch/powerpc/platforms/85xx/p1022_ds.c
index 0fe88e39945e..f700c81a1321 100644
--- a/arch/powerpc/platforms/85xx/p1022_ds.c
+++ b/arch/powerpc/platforms/85xx/p1022_ds.c
@@ -150,7 +150,7 @@ static void p1022ds_set_monitor_port(enum fsl_diu_monitor_port port)
150{ 150{
151 struct device_node *guts_node; 151 struct device_node *guts_node;
152 struct device_node *indirect_node = NULL; 152 struct device_node *indirect_node = NULL;
153 struct ccsr_guts_85xx __iomem *guts; 153 struct ccsr_guts __iomem *guts;
154 u8 __iomem *lbc_lcs0_ba = NULL; 154 u8 __iomem *lbc_lcs0_ba = NULL;
155 u8 __iomem *lbc_lcs1_ba = NULL; 155 u8 __iomem *lbc_lcs1_ba = NULL;
156 u8 b; 156 u8 b;
@@ -269,7 +269,7 @@ exit:
269void p1022ds_set_pixel_clock(unsigned int pixclock) 269void p1022ds_set_pixel_clock(unsigned int pixclock)
270{ 270{
271 struct device_node *guts_np = NULL; 271 struct device_node *guts_np = NULL;
272 struct ccsr_guts_85xx __iomem *guts; 272 struct ccsr_guts __iomem *guts;
273 unsigned long freq; 273 unsigned long freq;
274 u64 temp; 274 u64 temp;
275 u32 pxclk; 275 u32 pxclk;
@@ -460,18 +460,7 @@ static void __init p1022_ds_setup_arch(void)
460 pr_info("Freescale P1022 DS reference board\n"); 460 pr_info("Freescale P1022 DS reference board\n");
461} 461}
462 462
463static struct of_device_id __initdata p1022_ds_ids[] = { 463machine_device_initcall(p1022_ds, mpc85xx_common_publish_devices);
464 /* So that the DMA channel nodes can be probed individually: */
465 { .compatible = "fsl,eloplus-dma", },
466 {},
467};
468
469static int __init p1022_ds_publish_devices(void)
470{
471 mpc85xx_common_publish_devices();
472 return of_platform_bus_probe(NULL, p1022_ds_ids, NULL);
473}
474machine_device_initcall(p1022_ds, p1022_ds_publish_devices);
475 464
476machine_arch_initcall(p1022_ds, swiotlb_setup_bus_notifier); 465machine_arch_initcall(p1022_ds, swiotlb_setup_bus_notifier);
477 466
diff --git a/arch/powerpc/platforms/86xx/mpc8610_hpcd.c b/arch/powerpc/platforms/86xx/mpc8610_hpcd.c
index bbc615206c67..62cd3c555bfb 100644
--- a/arch/powerpc/platforms/86xx/mpc8610_hpcd.c
+++ b/arch/powerpc/platforms/86xx/mpc8610_hpcd.c
@@ -225,7 +225,7 @@ void mpc8610hpcd_set_monitor_port(enum fsl_diu_monitor_port port)
225void mpc8610hpcd_set_pixel_clock(unsigned int pixclock) 225void mpc8610hpcd_set_pixel_clock(unsigned int pixclock)
226{ 226{
227 struct device_node *guts_np = NULL; 227 struct device_node *guts_np = NULL;
228 struct ccsr_guts_86xx __iomem *guts; 228 struct ccsr_guts __iomem *guts;
229 unsigned long freq; 229 unsigned long freq;
230 u64 temp; 230 u64 temp;
231 u32 pxclk; 231 u32 pxclk;
diff --git a/arch/powerpc/platforms/cell/axon_msi.c b/arch/powerpc/platforms/cell/axon_msi.c
index db360fc4cf0e..85825b5401e5 100644
--- a/arch/powerpc/platforms/cell/axon_msi.c
+++ b/arch/powerpc/platforms/cell/axon_msi.c
@@ -114,7 +114,7 @@ static void axon_msi_cascade(unsigned int irq, struct irq_desc *desc)
114 pr_devel("axon_msi: woff %x roff %x msi %x\n", 114 pr_devel("axon_msi: woff %x roff %x msi %x\n",
115 write_offset, msic->read_offset, msi); 115 write_offset, msic->read_offset, msi);
116 116
117 if (msi < NR_IRQS && irq_get_chip_data(msi) == msic) { 117 if (msi < nr_irqs && irq_get_chip_data(msi) == msic) {
118 generic_handle_irq(msi); 118 generic_handle_irq(msi);
119 msic->fifo_virt[idx] = cpu_to_le32(0xffffffff); 119 msic->fifo_virt[idx] = cpu_to_le32(0xffffffff);
120 } else { 120 } else {
@@ -276,9 +276,6 @@ static int axon_msi_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)
276 if (rc) 276 if (rc)
277 return rc; 277 return rc;
278 278
279 /* We rely on being able to stash a virq in a u16 */
280 BUILD_BUG_ON(NR_IRQS > 65536);
281
282 list_for_each_entry(entry, &dev->msi_list, list) { 279 list_for_each_entry(entry, &dev->msi_list, list) {
283 virq = irq_create_direct_mapping(msic->irq_domain); 280 virq = irq_create_direct_mapping(msic->irq_domain);
284 if (virq == NO_IRQ) { 281 if (virq == NO_IRQ) {
@@ -392,7 +389,8 @@ static int axon_msi_probe(struct platform_device *device)
392 } 389 }
393 memset(msic->fifo_virt, 0xff, MSIC_FIFO_SIZE_BYTES); 390 memset(msic->fifo_virt, 0xff, MSIC_FIFO_SIZE_BYTES);
394 391
395 msic->irq_domain = irq_domain_add_nomap(dn, &msic_host_ops, msic); 392 /* We rely on being able to stash a virq in a u16, so limit irqs to < 65536 */
393 msic->irq_domain = irq_domain_add_nomap(dn, 65536, &msic_host_ops, msic);
396 if (!msic->irq_domain) { 394 if (!msic->irq_domain) {
397 printk(KERN_ERR "axon_msi: couldn't allocate irq_domain for %s\n", 395 printk(KERN_ERR "axon_msi: couldn't allocate irq_domain for %s\n",
398 dn->full_name); 396 dn->full_name);
diff --git a/arch/powerpc/platforms/cell/beat_interrupt.c b/arch/powerpc/platforms/cell/beat_interrupt.c
index e5c3a2c6090d..8c6dc42ecf65 100644
--- a/arch/powerpc/platforms/cell/beat_interrupt.c
+++ b/arch/powerpc/platforms/cell/beat_interrupt.c
@@ -239,7 +239,7 @@ void __init beatic_init_IRQ(void)
239 ppc_md.get_irq = beatic_get_irq; 239 ppc_md.get_irq = beatic_get_irq;
240 240
241 /* Allocate an irq host */ 241 /* Allocate an irq host */
242 beatic_host = irq_domain_add_nomap(NULL, &beatic_pic_host_ops, NULL); 242 beatic_host = irq_domain_add_nomap(NULL, 0, &beatic_pic_host_ops, NULL);
243 BUG_ON(beatic_host == NULL); 243 BUG_ON(beatic_host == NULL);
244 irq_set_default_host(beatic_host); 244 irq_set_default_host(beatic_host);
245} 245}
@@ -248,6 +248,6 @@ void beatic_deinit_IRQ(void)
248{ 248{
249 int i; 249 int i;
250 250
251 for (i = 1; i < NR_IRQS; i++) 251 for (i = 1; i < nr_irqs; i++)
252 beat_destruct_irq_plug(i); 252 beat_destruct_irq_plug(i);
253} 253}
diff --git a/arch/powerpc/platforms/cell/iommu.c b/arch/powerpc/platforms/cell/iommu.c
index ae9fc7bc17d6..b9f509a34c01 100644
--- a/arch/powerpc/platforms/cell/iommu.c
+++ b/arch/powerpc/platforms/cell/iommu.c
@@ -564,7 +564,8 @@ static struct iommu_table *cell_get_iommu_table(struct device *dev)
564/* A coherent allocation implies strong ordering */ 564/* A coherent allocation implies strong ordering */
565 565
566static void *dma_fixed_alloc_coherent(struct device *dev, size_t size, 566static void *dma_fixed_alloc_coherent(struct device *dev, size_t size,
567 dma_addr_t *dma_handle, gfp_t flag) 567 dma_addr_t *dma_handle, gfp_t flag,
568 struct dma_attrs *attrs)
568{ 569{
569 if (iommu_fixed_is_weak) 570 if (iommu_fixed_is_weak)
570 return iommu_alloc_coherent(dev, cell_get_iommu_table(dev), 571 return iommu_alloc_coherent(dev, cell_get_iommu_table(dev),
@@ -572,18 +573,19 @@ static void *dma_fixed_alloc_coherent(struct device *dev, size_t size,
572 device_to_mask(dev), flag, 573 device_to_mask(dev), flag,
573 dev_to_node(dev)); 574 dev_to_node(dev));
574 else 575 else
575 return dma_direct_ops.alloc_coherent(dev, size, dma_handle, 576 return dma_direct_ops.alloc(dev, size, dma_handle, flag,
576 flag); 577 attrs);
577} 578}
578 579
579static void dma_fixed_free_coherent(struct device *dev, size_t size, 580static void dma_fixed_free_coherent(struct device *dev, size_t size,
580 void *vaddr, dma_addr_t dma_handle) 581 void *vaddr, dma_addr_t dma_handle,
582 struct dma_attrs *attrs)
581{ 583{
582 if (iommu_fixed_is_weak) 584 if (iommu_fixed_is_weak)
583 iommu_free_coherent(cell_get_iommu_table(dev), size, vaddr, 585 iommu_free_coherent(cell_get_iommu_table(dev), size, vaddr,
584 dma_handle); 586 dma_handle);
585 else 587 else
586 dma_direct_ops.free_coherent(dev, size, vaddr, dma_handle); 588 dma_direct_ops.free(dev, size, vaddr, dma_handle, attrs);
587} 589}
588 590
589static dma_addr_t dma_fixed_map_page(struct device *dev, struct page *page, 591static dma_addr_t dma_fixed_map_page(struct device *dev, struct page *page,
@@ -642,8 +644,8 @@ static int dma_fixed_dma_supported(struct device *dev, u64 mask)
642static int dma_set_mask_and_switch(struct device *dev, u64 dma_mask); 644static int dma_set_mask_and_switch(struct device *dev, u64 dma_mask);
643 645
644struct dma_map_ops dma_iommu_fixed_ops = { 646struct dma_map_ops dma_iommu_fixed_ops = {
645 .alloc_coherent = dma_fixed_alloc_coherent, 647 .alloc = dma_fixed_alloc_coherent,
646 .free_coherent = dma_fixed_free_coherent, 648 .free = dma_fixed_free_coherent,
647 .map_sg = dma_fixed_map_sg, 649 .map_sg = dma_fixed_map_sg,
648 .unmap_sg = dma_fixed_unmap_sg, 650 .unmap_sg = dma_fixed_unmap_sg,
649 .dma_supported = dma_fixed_dma_supported, 651 .dma_supported = dma_fixed_dma_supported,
diff --git a/arch/powerpc/platforms/cell/qpace_setup.c b/arch/powerpc/platforms/cell/qpace_setup.c
index 7f9b6742f8b6..6e3409d590ac 100644
--- a/arch/powerpc/platforms/cell/qpace_setup.c
+++ b/arch/powerpc/platforms/cell/qpace_setup.c
@@ -61,7 +61,7 @@ static void qpace_progress(char *s, unsigned short hex)
61 printk("*** %04x : %s\n", hex, s ? s : ""); 61 printk("*** %04x : %s\n", hex, s ? s : "");
62} 62}
63 63
64static const struct of_device_id qpace_bus_ids[] __initdata = { 64static const struct of_device_id qpace_bus_ids[] __initconst = {
65 { .type = "soc", }, 65 { .type = "soc", },
66 { .compatible = "soc", }, 66 { .compatible = "soc", },
67 { .type = "spider", }, 67 { .type = "spider", },
diff --git a/arch/powerpc/platforms/cell/setup.c b/arch/powerpc/platforms/cell/setup.c
index fa3e294fd343..4ab087671185 100644
--- a/arch/powerpc/platforms/cell/setup.c
+++ b/arch/powerpc/platforms/cell/setup.c
@@ -140,7 +140,7 @@ static int __devinit cell_setup_phb(struct pci_controller *phb)
140 return 0; 140 return 0;
141} 141}
142 142
143static const struct of_device_id cell_bus_ids[] __initdata = { 143static const struct of_device_id cell_bus_ids[] __initconst = {
144 { .type = "soc", }, 144 { .type = "soc", },
145 { .compatible = "soc", }, 145 { .compatible = "soc", },
146 { .type = "spider", }, 146 { .type = "spider", },
diff --git a/arch/powerpc/platforms/powermac/low_i2c.c b/arch/powerpc/platforms/powermac/low_i2c.c
index 996c5ff7824b..03685a329d7d 100644
--- a/arch/powerpc/platforms/powermac/low_i2c.c
+++ b/arch/powerpc/platforms/powermac/low_i2c.c
@@ -366,11 +366,20 @@ static void kw_i2c_timeout(unsigned long data)
366 unsigned long flags; 366 unsigned long flags;
367 367
368 spin_lock_irqsave(&host->lock, flags); 368 spin_lock_irqsave(&host->lock, flags);
369
370 /*
371 * If the timer is pending, that means we raced with the
372 * irq, in which case we just return
373 */
374 if (timer_pending(&host->timeout_timer))
375 goto skip;
376
369 kw_i2c_handle_interrupt(host, kw_read_reg(reg_isr)); 377 kw_i2c_handle_interrupt(host, kw_read_reg(reg_isr));
370 if (host->state != state_idle) { 378 if (host->state != state_idle) {
371 host->timeout_timer.expires = jiffies + KW_POLL_TIMEOUT; 379 host->timeout_timer.expires = jiffies + KW_POLL_TIMEOUT;
372 add_timer(&host->timeout_timer); 380 add_timer(&host->timeout_timer);
373 } 381 }
382 skip:
374 spin_unlock_irqrestore(&host->lock, flags); 383 spin_unlock_irqrestore(&host->lock, flags);
375} 384}
376 385
diff --git a/arch/powerpc/platforms/powermac/pic.c b/arch/powerpc/platforms/powermac/pic.c
index 66ad93de1d55..c4e630576ff2 100644
--- a/arch/powerpc/platforms/powermac/pic.c
+++ b/arch/powerpc/platforms/powermac/pic.c
@@ -57,9 +57,9 @@ static int max_real_irqs;
57 57
58static DEFINE_RAW_SPINLOCK(pmac_pic_lock); 58static DEFINE_RAW_SPINLOCK(pmac_pic_lock);
59 59
60#define NR_MASK_WORDS ((NR_IRQS + 31) / 32) 60/* The max irq number this driver deals with is 128; see max_irqs */
61static unsigned long ppc_lost_interrupts[NR_MASK_WORDS]; 61static DECLARE_BITMAP(ppc_lost_interrupts, 128);
62static unsigned long ppc_cached_irq_mask[NR_MASK_WORDS]; 62static DECLARE_BITMAP(ppc_cached_irq_mask, 128);
63static int pmac_irq_cascade = -1; 63static int pmac_irq_cascade = -1;
64static struct irq_domain *pmac_pic_host; 64static struct irq_domain *pmac_pic_host;
65 65
diff --git a/arch/powerpc/platforms/powermac/smp.c b/arch/powerpc/platforms/powermac/smp.c
index a81e5a88fbdf..b4ddaa3fbb29 100644
--- a/arch/powerpc/platforms/powermac/smp.c
+++ b/arch/powerpc/platforms/powermac/smp.c
@@ -192,7 +192,7 @@ static int psurge_secondary_ipi_init(void)
192{ 192{
193 int rc = -ENOMEM; 193 int rc = -ENOMEM;
194 194
195 psurge_host = irq_domain_add_nomap(NULL, &psurge_host_ops, NULL); 195 psurge_host = irq_domain_add_nomap(NULL, 0, &psurge_host_ops, NULL);
196 196
197 if (psurge_host) 197 if (psurge_host)
198 psurge_secondary_virq = irq_create_direct_mapping(psurge_host); 198 psurge_secondary_virq = irq_create_direct_mapping(psurge_host);
diff --git a/arch/powerpc/platforms/ps3/interrupt.c b/arch/powerpc/platforms/ps3/interrupt.c
index 2a4ff86cc21f..5f3b23220b8e 100644
--- a/arch/powerpc/platforms/ps3/interrupt.c
+++ b/arch/powerpc/platforms/ps3/interrupt.c
@@ -753,9 +753,8 @@ void __init ps3_init_IRQ(void)
753 unsigned cpu; 753 unsigned cpu;
754 struct irq_domain *host; 754 struct irq_domain *host;
755 755
756 host = irq_domain_add_nomap(NULL, &ps3_host_ops, NULL); 756 host = irq_domain_add_nomap(NULL, PS3_PLUG_MAX + 1, &ps3_host_ops, NULL);
757 irq_set_default_host(host); 757 irq_set_default_host(host);
758 irq_set_virq_count(PS3_PLUG_MAX + 1);
759 758
760 for_each_possible_cpu(cpu) { 759 for_each_possible_cpu(cpu) {
761 struct ps3_private *pd = &per_cpu(ps3_private, cpu); 760 struct ps3_private *pd = &per_cpu(ps3_private, cpu);
diff --git a/arch/powerpc/platforms/ps3/system-bus.c b/arch/powerpc/platforms/ps3/system-bus.c
index 880eb9ce22c5..5606fe36faf2 100644
--- a/arch/powerpc/platforms/ps3/system-bus.c
+++ b/arch/powerpc/platforms/ps3/system-bus.c
@@ -515,7 +515,8 @@ core_initcall(ps3_system_bus_init);
515 * to the dma address (mapping) of the first page. 515 * to the dma address (mapping) of the first page.
516 */ 516 */
517static void * ps3_alloc_coherent(struct device *_dev, size_t size, 517static void * ps3_alloc_coherent(struct device *_dev, size_t size,
518 dma_addr_t *dma_handle, gfp_t flag) 518 dma_addr_t *dma_handle, gfp_t flag,
519 struct dma_attrs *attrs)
519{ 520{
520 int result; 521 int result;
521 struct ps3_system_bus_device *dev = ps3_dev_to_system_bus_dev(_dev); 522 struct ps3_system_bus_device *dev = ps3_dev_to_system_bus_dev(_dev);
@@ -552,7 +553,7 @@ clean_none:
552} 553}
553 554
554static void ps3_free_coherent(struct device *_dev, size_t size, void *vaddr, 555static void ps3_free_coherent(struct device *_dev, size_t size, void *vaddr,
555 dma_addr_t dma_handle) 556 dma_addr_t dma_handle, struct dma_attrs *attrs)
556{ 557{
557 struct ps3_system_bus_device *dev = ps3_dev_to_system_bus_dev(_dev); 558 struct ps3_system_bus_device *dev = ps3_dev_to_system_bus_dev(_dev);
558 559
@@ -701,8 +702,8 @@ static u64 ps3_dma_get_required_mask(struct device *_dev)
701} 702}
702 703
703static struct dma_map_ops ps3_sb_dma_ops = { 704static struct dma_map_ops ps3_sb_dma_ops = {
704 .alloc_coherent = ps3_alloc_coherent, 705 .alloc = ps3_alloc_coherent,
705 .free_coherent = ps3_free_coherent, 706 .free = ps3_free_coherent,
706 .map_sg = ps3_sb_map_sg, 707 .map_sg = ps3_sb_map_sg,
707 .unmap_sg = ps3_sb_unmap_sg, 708 .unmap_sg = ps3_sb_unmap_sg,
708 .dma_supported = ps3_dma_supported, 709 .dma_supported = ps3_dma_supported,
@@ -712,8 +713,8 @@ static struct dma_map_ops ps3_sb_dma_ops = {
712}; 713};
713 714
714static struct dma_map_ops ps3_ioc0_dma_ops = { 715static struct dma_map_ops ps3_ioc0_dma_ops = {
715 .alloc_coherent = ps3_alloc_coherent, 716 .alloc = ps3_alloc_coherent,
716 .free_coherent = ps3_free_coherent, 717 .free = ps3_free_coherent,
717 .map_sg = ps3_ioc0_map_sg, 718 .map_sg = ps3_ioc0_map_sg,
718 .unmap_sg = ps3_ioc0_unmap_sg, 719 .unmap_sg = ps3_ioc0_unmap_sg,
719 .dma_supported = ps3_dma_supported, 720 .dma_supported = ps3_dma_supported,
diff --git a/arch/powerpc/platforms/pseries/Kconfig b/arch/powerpc/platforms/pseries/Kconfig
index aadbe4f6d537..178a5f300bc9 100644
--- a/arch/powerpc/platforms/pseries/Kconfig
+++ b/arch/powerpc/platforms/pseries/Kconfig
@@ -30,9 +30,9 @@ config PPC_SPLPAR
30 two or more partitions. 30 two or more partitions.
31 31
32config EEH 32config EEH
33 bool "PCI Extended Error Handling (EEH)" if EXPERT 33 bool
34 depends on PPC_PSERIES && PCI 34 depends on PPC_PSERIES && PCI
35 default y if !EXPERT 35 default y
36 36
37config PSERIES_MSI 37config PSERIES_MSI
38 bool 38 bool
diff --git a/arch/powerpc/platforms/pseries/eeh.c b/arch/powerpc/platforms/pseries/eeh.c
index 309d38ef7322..a75e37dc41aa 100644
--- a/arch/powerpc/platforms/pseries/eeh.c
+++ b/arch/powerpc/platforms/pseries/eeh.c
@@ -1076,7 +1076,7 @@ static void eeh_add_device_late(struct pci_dev *dev)
1076 pr_debug("EEH: Adding device %s\n", pci_name(dev)); 1076 pr_debug("EEH: Adding device %s\n", pci_name(dev));
1077 1077
1078 dn = pci_device_to_OF_node(dev); 1078 dn = pci_device_to_OF_node(dev);
1079 edev = pci_dev_to_eeh_dev(dev); 1079 edev = of_node_to_eeh_dev(dn);
1080 if (edev->pdev == dev) { 1080 if (edev->pdev == dev) {
1081 pr_debug("EEH: Already referenced !\n"); 1081 pr_debug("EEH: Already referenced !\n");
1082 return; 1082 return;
diff --git a/arch/powerpc/platforms/pseries/eeh_event.c b/arch/powerpc/platforms/pseries/eeh_event.c
index 4a4752565856..4cb375c0f8d1 100644
--- a/arch/powerpc/platforms/pseries/eeh_event.c
+++ b/arch/powerpc/platforms/pseries/eeh_event.c
@@ -59,8 +59,7 @@ static int eeh_event_handler(void * dummy)
59 struct eeh_event *event; 59 struct eeh_event *event;
60 struct eeh_dev *edev; 60 struct eeh_dev *edev;
61 61
62 daemonize("eehd"); 62 set_task_comm(current, "eehd");
63 set_current_state(TASK_INTERRUPTIBLE);
64 63
65 spin_lock_irqsave(&eeh_eventlist_lock, flags); 64 spin_lock_irqsave(&eeh_eventlist_lock, flags);
66 event = NULL; 65 event = NULL;
@@ -83,6 +82,7 @@ static int eeh_event_handler(void * dummy)
83 printk(KERN_INFO "EEH: Detected PCI bus error on device %s\n", 82 printk(KERN_INFO "EEH: Detected PCI bus error on device %s\n",
84 eeh_pci_name(edev->pdev)); 83 eeh_pci_name(edev->pdev));
85 84
85 set_current_state(TASK_INTERRUPTIBLE); /* Don't add to load average */
86 edev = handle_eeh_events(event); 86 edev = handle_eeh_events(event);
87 87
88 eeh_clear_slot(eeh_dev_to_of_node(edev), EEH_MODE_RECOVERING); 88 eeh_clear_slot(eeh_dev_to_of_node(edev), EEH_MODE_RECOVERING);
diff --git a/arch/powerpc/sysdev/cpm2_pic.c b/arch/powerpc/sysdev/cpm2_pic.c
index d3be961e2ae7..10386b676d87 100644
--- a/arch/powerpc/sysdev/cpm2_pic.c
+++ b/arch/powerpc/sysdev/cpm2_pic.c
@@ -51,8 +51,7 @@
51static intctl_cpm2_t __iomem *cpm2_intctl; 51static intctl_cpm2_t __iomem *cpm2_intctl;
52 52
53static struct irq_domain *cpm2_pic_host; 53static struct irq_domain *cpm2_pic_host;
54#define NR_MASK_WORDS ((NR_IRQS + 31) / 32) 54static unsigned long ppc_cached_irq_mask[2]; /* 2 32-bit registers */
55static unsigned long ppc_cached_irq_mask[NR_MASK_WORDS];
56 55
57static const u_char irq_to_siureg[] = { 56static const u_char irq_to_siureg[] = {
58 1, 1, 1, 1, 1, 1, 1, 1, 57 1, 1, 1, 1, 1, 1, 1, 1,
diff --git a/arch/powerpc/sysdev/mpc8xx_pic.c b/arch/powerpc/sysdev/mpc8xx_pic.c
index d5f5416be310..b724622c3a0b 100644
--- a/arch/powerpc/sysdev/mpc8xx_pic.c
+++ b/arch/powerpc/sysdev/mpc8xx_pic.c
@@ -18,69 +18,45 @@
18extern int cpm_get_irq(struct pt_regs *regs); 18extern int cpm_get_irq(struct pt_regs *regs);
19 19
20static struct irq_domain *mpc8xx_pic_host; 20static struct irq_domain *mpc8xx_pic_host;
21#define NR_MASK_WORDS ((NR_IRQS + 31) / 32) 21static unsigned long mpc8xx_cached_irq_mask;
22static unsigned long ppc_cached_irq_mask[NR_MASK_WORDS];
23static sysconf8xx_t __iomem *siu_reg; 22static sysconf8xx_t __iomem *siu_reg;
24 23
25int cpm_get_irq(struct pt_regs *regs); 24static inline unsigned long mpc8xx_irqd_to_bit(struct irq_data *d)
25{
26 return 0x80000000 >> irqd_to_hwirq(d);
27}
26 28
27static void mpc8xx_unmask_irq(struct irq_data *d) 29static void mpc8xx_unmask_irq(struct irq_data *d)
28{ 30{
29 int bit, word; 31 mpc8xx_cached_irq_mask |= mpc8xx_irqd_to_bit(d);
30 unsigned int irq_nr = (unsigned int)irqd_to_hwirq(d); 32 out_be32(&siu_reg->sc_simask, mpc8xx_cached_irq_mask);
31
32 bit = irq_nr & 0x1f;
33 word = irq_nr >> 5;
34
35 ppc_cached_irq_mask[word] |= (1 << (31-bit));
36 out_be32(&siu_reg->sc_simask, ppc_cached_irq_mask[word]);
37} 33}
38 34
39static void mpc8xx_mask_irq(struct irq_data *d) 35static void mpc8xx_mask_irq(struct irq_data *d)
40{ 36{
41 int bit, word; 37 mpc8xx_cached_irq_mask &= ~mpc8xx_irqd_to_bit(d);
42 unsigned int irq_nr = (unsigned int)irqd_to_hwirq(d); 38 out_be32(&siu_reg->sc_simask, mpc8xx_cached_irq_mask);
43
44 bit = irq_nr & 0x1f;
45 word = irq_nr >> 5;
46
47 ppc_cached_irq_mask[word] &= ~(1 << (31-bit));
48 out_be32(&siu_reg->sc_simask, ppc_cached_irq_mask[word]);
49} 39}
50 40
51static void mpc8xx_ack(struct irq_data *d) 41static void mpc8xx_ack(struct irq_data *d)
52{ 42{
53 int bit; 43 out_be32(&siu_reg->sc_sipend, mpc8xx_irqd_to_bit(d));
54 unsigned int irq_nr = (unsigned int)irqd_to_hwirq(d);
55
56 bit = irq_nr & 0x1f;
57 out_be32(&siu_reg->sc_sipend, 1 << (31-bit));
58} 44}
59 45
60static void mpc8xx_end_irq(struct irq_data *d) 46static void mpc8xx_end_irq(struct irq_data *d)
61{ 47{
62 int bit, word; 48 mpc8xx_cached_irq_mask |= mpc8xx_irqd_to_bit(d);
63 unsigned int irq_nr = (unsigned int)irqd_to_hwirq(d); 49 out_be32(&siu_reg->sc_simask, mpc8xx_cached_irq_mask);
64
65 bit = irq_nr & 0x1f;
66 word = irq_nr >> 5;
67
68 ppc_cached_irq_mask[word] |= (1 << (31-bit));
69 out_be32(&siu_reg->sc_simask, ppc_cached_irq_mask[word]);
70} 50}
71 51
72static int mpc8xx_set_irq_type(struct irq_data *d, unsigned int flow_type) 52static int mpc8xx_set_irq_type(struct irq_data *d, unsigned int flow_type)
73{ 53{
74 if (flow_type & IRQ_TYPE_EDGE_FALLING) { 54 /* only external IRQ senses are programmable */
75 irq_hw_number_t hw = (unsigned int)irqd_to_hwirq(d); 55 if ((flow_type & IRQ_TYPE_EDGE_FALLING) && !(irqd_to_hwirq(d) & 1)) {
76 unsigned int siel = in_be32(&siu_reg->sc_siel); 56 unsigned int siel = in_be32(&siu_reg->sc_siel);
77 57 siel |= mpc8xx_irqd_to_bit(d);
78 /* only external IRQ senses are programmable */ 58 out_be32(&siu_reg->sc_siel, siel);
79 if ((hw & 1) == 0) { 59 __irq_set_handler_locked(d->irq, handle_edge_irq);
80 siel |= (0x80000000 >> hw);
81 out_be32(&siu_reg->sc_siel, siel);
82 __irq_set_handler_locked(d->irq, handle_edge_irq);
83 }
84 } 60 }
85 return 0; 61 return 0;
86} 62}
@@ -132,6 +108,9 @@ static int mpc8xx_pic_host_xlate(struct irq_domain *h, struct device_node *ct,
132 IRQ_TYPE_EDGE_FALLING, 108 IRQ_TYPE_EDGE_FALLING,
133 }; 109 };
134 110
111 if (intspec[0] > 0x1f)
112 return 0;
113
135 *out_hwirq = intspec[0]; 114 *out_hwirq = intspec[0];
136 if (intsize > 1 && intspec[1] < 4) 115 if (intsize > 1 && intspec[1] < 4)
137 *out_flags = map_pic_senses[intspec[1]]; 116 *out_flags = map_pic_senses[intspec[1]];
diff --git a/arch/powerpc/sysdev/mpic.c b/arch/powerpc/sysdev/mpic.c
index 9ac71ebd2c40..395af1347749 100644
--- a/arch/powerpc/sysdev/mpic.c
+++ b/arch/powerpc/sysdev/mpic.c
@@ -604,18 +604,14 @@ static struct mpic *mpic_find(unsigned int irq)
604} 604}
605 605
606/* Determine if the linux irq is an IPI */ 606/* Determine if the linux irq is an IPI */
607static unsigned int mpic_is_ipi(struct mpic *mpic, unsigned int irq) 607static unsigned int mpic_is_ipi(struct mpic *mpic, unsigned int src)
608{ 608{
609 unsigned int src = virq_to_hw(irq);
610
611 return (src >= mpic->ipi_vecs[0] && src <= mpic->ipi_vecs[3]); 609 return (src >= mpic->ipi_vecs[0] && src <= mpic->ipi_vecs[3]);
612} 610}
613 611
614/* Determine if the linux irq is a timer */ 612/* Determine if the linux irq is a timer */
615static unsigned int mpic_is_tm(struct mpic *mpic, unsigned int irq) 613static unsigned int mpic_is_tm(struct mpic *mpic, unsigned int src)
616{ 614{
617 unsigned int src = virq_to_hw(irq);
618
619 return (src >= mpic->timer_vecs[0] && src <= mpic->timer_vecs[7]); 615 return (src >= mpic->timer_vecs[0] && src <= mpic->timer_vecs[7]);
620} 616}
621 617
@@ -876,21 +872,45 @@ int mpic_set_irq_type(struct irq_data *d, unsigned int flow_type)
876 if (src >= mpic->num_sources) 872 if (src >= mpic->num_sources)
877 return -EINVAL; 873 return -EINVAL;
878 874
875 vold = mpic_irq_read(src, MPIC_INFO(IRQ_VECTOR_PRI));
876
877 /* We don't support "none" type */
879 if (flow_type == IRQ_TYPE_NONE) 878 if (flow_type == IRQ_TYPE_NONE)
880 if (mpic->senses && src < mpic->senses_count) 879 flow_type = IRQ_TYPE_DEFAULT;
881 flow_type = mpic->senses[src]; 880
882 if (flow_type == IRQ_TYPE_NONE) 881 /* Default: read HW settings */
883 flow_type = IRQ_TYPE_LEVEL_LOW; 882 if (flow_type == IRQ_TYPE_DEFAULT) {
883 switch(vold & (MPIC_INFO(VECPRI_POLARITY_MASK) |
884 MPIC_INFO(VECPRI_SENSE_MASK))) {
885 case MPIC_INFO(VECPRI_SENSE_EDGE) |
886 MPIC_INFO(VECPRI_POLARITY_POSITIVE):
887 flow_type = IRQ_TYPE_EDGE_RISING;
888 break;
889 case MPIC_INFO(VECPRI_SENSE_EDGE) |
890 MPIC_INFO(VECPRI_POLARITY_NEGATIVE):
891 flow_type = IRQ_TYPE_EDGE_FALLING;
892 break;
893 case MPIC_INFO(VECPRI_SENSE_LEVEL) |
894 MPIC_INFO(VECPRI_POLARITY_POSITIVE):
895 flow_type = IRQ_TYPE_LEVEL_HIGH;
896 break;
897 case MPIC_INFO(VECPRI_SENSE_LEVEL) |
898 MPIC_INFO(VECPRI_POLARITY_NEGATIVE):
899 flow_type = IRQ_TYPE_LEVEL_LOW;
900 break;
901 }
902 }
884 903
904 /* Apply to irq desc */
885 irqd_set_trigger_type(d, flow_type); 905 irqd_set_trigger_type(d, flow_type);
886 906
907 /* Apply to HW */
887 if (mpic_is_ht_interrupt(mpic, src)) 908 if (mpic_is_ht_interrupt(mpic, src))
888 vecpri = MPIC_VECPRI_POLARITY_POSITIVE | 909 vecpri = MPIC_VECPRI_POLARITY_POSITIVE |
889 MPIC_VECPRI_SENSE_EDGE; 910 MPIC_VECPRI_SENSE_EDGE;
890 else 911 else
891 vecpri = mpic_type_to_vecpri(mpic, flow_type); 912 vecpri = mpic_type_to_vecpri(mpic, flow_type);
892 913
893 vold = mpic_irq_read(src, MPIC_INFO(IRQ_VECTOR_PRI));
894 vnew = vold & ~(MPIC_INFO(VECPRI_POLARITY_MASK) | 914 vnew = vold & ~(MPIC_INFO(VECPRI_POLARITY_MASK) |
895 MPIC_INFO(VECPRI_SENSE_MASK)); 915 MPIC_INFO(VECPRI_SENSE_MASK));
896 vnew |= vecpri; 916 vnew |= vecpri;
@@ -1026,7 +1046,7 @@ static int mpic_host_map(struct irq_domain *h, unsigned int virq,
1026 irq_set_chip_and_handler(virq, chip, handle_fasteoi_irq); 1046 irq_set_chip_and_handler(virq, chip, handle_fasteoi_irq);
1027 1047
1028 /* Set default irq type */ 1048 /* Set default irq type */
1029 irq_set_irq_type(virq, IRQ_TYPE_NONE); 1049 irq_set_irq_type(virq, IRQ_TYPE_DEFAULT);
1030 1050
1031 /* If the MPIC was reset, then all vectors have already been 1051 /* If the MPIC was reset, then all vectors have already been
1032 * initialized. Otherwise, a per source lazy initialization 1052 * initialized. Otherwise, a per source lazy initialization
@@ -1417,12 +1437,6 @@ void __init mpic_assign_isu(struct mpic *mpic, unsigned int isu_num,
1417 mpic->num_sources = isu_first + mpic->isu_size; 1437 mpic->num_sources = isu_first + mpic->isu_size;
1418} 1438}
1419 1439
1420void __init mpic_set_default_senses(struct mpic *mpic, u8 *senses, int count)
1421{
1422 mpic->senses = senses;
1423 mpic->senses_count = count;
1424}
1425
1426void __init mpic_init(struct mpic *mpic) 1440void __init mpic_init(struct mpic *mpic)
1427{ 1441{
1428 int i, cpu; 1442 int i, cpu;
@@ -1555,12 +1569,12 @@ void mpic_irq_set_priority(unsigned int irq, unsigned int pri)
1555 return; 1569 return;
1556 1570
1557 raw_spin_lock_irqsave(&mpic_lock, flags); 1571 raw_spin_lock_irqsave(&mpic_lock, flags);
1558 if (mpic_is_ipi(mpic, irq)) { 1572 if (mpic_is_ipi(mpic, src)) {
1559 reg = mpic_ipi_read(src - mpic->ipi_vecs[0]) & 1573 reg = mpic_ipi_read(src - mpic->ipi_vecs[0]) &
1560 ~MPIC_VECPRI_PRIORITY_MASK; 1574 ~MPIC_VECPRI_PRIORITY_MASK;
1561 mpic_ipi_write(src - mpic->ipi_vecs[0], 1575 mpic_ipi_write(src - mpic->ipi_vecs[0],
1562 reg | (pri << MPIC_VECPRI_PRIORITY_SHIFT)); 1576 reg | (pri << MPIC_VECPRI_PRIORITY_SHIFT));
1563 } else if (mpic_is_tm(mpic, irq)) { 1577 } else if (mpic_is_tm(mpic, src)) {
1564 reg = mpic_tm_read(src - mpic->timer_vecs[0]) & 1578 reg = mpic_tm_read(src - mpic->timer_vecs[0]) &
1565 ~MPIC_VECPRI_PRIORITY_MASK; 1579 ~MPIC_VECPRI_PRIORITY_MASK;
1566 mpic_tm_write(src - mpic->timer_vecs[0], 1580 mpic_tm_write(src - mpic->timer_vecs[0],
diff --git a/arch/powerpc/sysdev/mpic_msgr.c b/arch/powerpc/sysdev/mpic_msgr.c
index 6e7fa386e76a..483d8fa72e8b 100644
--- a/arch/powerpc/sysdev/mpic_msgr.c
+++ b/arch/powerpc/sysdev/mpic_msgr.c
@@ -27,6 +27,7 @@
27 27
28static struct mpic_msgr **mpic_msgrs; 28static struct mpic_msgr **mpic_msgrs;
29static unsigned int mpic_msgr_count; 29static unsigned int mpic_msgr_count;
30static DEFINE_RAW_SPINLOCK(msgrs_lock);
30 31
31static inline void _mpic_msgr_mer_write(struct mpic_msgr *msgr, u32 value) 32static inline void _mpic_msgr_mer_write(struct mpic_msgr *msgr, u32 value)
32{ 33{
@@ -56,12 +57,11 @@ struct mpic_msgr *mpic_msgr_get(unsigned int reg_num)
56 if (reg_num >= mpic_msgr_count) 57 if (reg_num >= mpic_msgr_count)
57 return ERR_PTR(-ENODEV); 58 return ERR_PTR(-ENODEV);
58 59
59 raw_spin_lock_irqsave(&msgr->lock, flags); 60 raw_spin_lock_irqsave(&msgrs_lock, flags);
60 if (mpic_msgrs[reg_num]->in_use == MSGR_FREE) { 61 msgr = mpic_msgrs[reg_num];
61 msgr = mpic_msgrs[reg_num]; 62 if (msgr->in_use == MSGR_FREE)
62 msgr->in_use = MSGR_INUSE; 63 msgr->in_use = MSGR_INUSE;
63 } 64 raw_spin_unlock_irqrestore(&msgrs_lock, flags);
64 raw_spin_unlock_irqrestore(&msgr->lock, flags);
65 65
66 return msgr; 66 return msgr;
67} 67}
@@ -228,7 +228,7 @@ static __devinit int mpic_msgr_probe(struct platform_device *dev)
228 228
229 reg_number = block_number * MPIC_MSGR_REGISTERS_PER_BLOCK + i; 229 reg_number = block_number * MPIC_MSGR_REGISTERS_PER_BLOCK + i;
230 msgr->base = msgr_block_addr + i * MPIC_MSGR_STRIDE; 230 msgr->base = msgr_block_addr + i * MPIC_MSGR_STRIDE;
231 msgr->mer = msgr->base + MPIC_MSGR_MER_OFFSET; 231 msgr->mer = (u32 *)((u8 *)msgr->base + MPIC_MSGR_MER_OFFSET);
232 msgr->in_use = MSGR_FREE; 232 msgr->in_use = MSGR_FREE;
233 msgr->num = i; 233 msgr->num = i;
234 raw_spin_lock_init(&msgr->lock); 234 raw_spin_lock_init(&msgr->lock);
diff --git a/arch/powerpc/sysdev/qe_lib/qe.c b/arch/powerpc/sysdev/qe_lib/qe.c
index ceb09cbd2329..818e763f8265 100644
--- a/arch/powerpc/sysdev/qe_lib/qe.c
+++ b/arch/powerpc/sysdev/qe_lib/qe.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (C) 2006 Freescale Semicondutor, Inc. All rights reserved. 2 * Copyright (C) 2006-2010 Freescale Semicondutor, Inc. All rights reserved.
3 * 3 *
4 * Authors: Shlomi Gridish <gridish@freescale.com> 4 * Authors: Shlomi Gridish <gridish@freescale.com>
5 * Li Yang <leoli@freescale.com> 5 * Li Yang <leoli@freescale.com>
@@ -266,7 +266,19 @@ EXPORT_SYMBOL(qe_clock_source);
266static void qe_snums_init(void) 266static void qe_snums_init(void)
267{ 267{
268 int i; 268 int i;
269 static const u8 snum_init[] = { 269 static const u8 snum_init_76[] = {
270 0x04, 0x05, 0x0C, 0x0D, 0x14, 0x15, 0x1C, 0x1D,
271 0x24, 0x25, 0x2C, 0x2D, 0x34, 0x35, 0x88, 0x89,
272 0x98, 0x99, 0xA8, 0xA9, 0xB8, 0xB9, 0xC8, 0xC9,
273 0xD8, 0xD9, 0xE8, 0xE9, 0x44, 0x45, 0x4C, 0x4D,
274 0x54, 0x55, 0x5C, 0x5D, 0x64, 0x65, 0x6C, 0x6D,
275 0x74, 0x75, 0x7C, 0x7D, 0x84, 0x85, 0x8C, 0x8D,
276 0x94, 0x95, 0x9C, 0x9D, 0xA4, 0xA5, 0xAC, 0xAD,
277 0xB4, 0xB5, 0xBC, 0xBD, 0xC4, 0xC5, 0xCC, 0xCD,
278 0xD4, 0xD5, 0xDC, 0xDD, 0xE4, 0xE5, 0xEC, 0xED,
279 0xF4, 0xF5, 0xFC, 0xFD,
280 };
281 static const u8 snum_init_46[] = {
270 0x04, 0x05, 0x0C, 0x0D, 0x14, 0x15, 0x1C, 0x1D, 282 0x04, 0x05, 0x0C, 0x0D, 0x14, 0x15, 0x1C, 0x1D,
271 0x24, 0x25, 0x2C, 0x2D, 0x34, 0x35, 0x88, 0x89, 283 0x24, 0x25, 0x2C, 0x2D, 0x34, 0x35, 0x88, 0x89,
272 0x98, 0x99, 0xA8, 0xA9, 0xB8, 0xB9, 0xC8, 0xC9, 284 0x98, 0x99, 0xA8, 0xA9, 0xB8, 0xB9, 0xC8, 0xC9,
@@ -274,9 +286,15 @@ static void qe_snums_init(void)
274 0x28, 0x29, 0x38, 0x39, 0x48, 0x49, 0x58, 0x59, 286 0x28, 0x29, 0x38, 0x39, 0x48, 0x49, 0x58, 0x59,
275 0x68, 0x69, 0x78, 0x79, 0x80, 0x81, 287 0x68, 0x69, 0x78, 0x79, 0x80, 0x81,
276 }; 288 };
289 static const u8 *snum_init;
277 290
278 qe_num_of_snum = qe_get_num_of_snums(); 291 qe_num_of_snum = qe_get_num_of_snums();
279 292
293 if (qe_num_of_snum == 76)
294 snum_init = snum_init_76;
295 else
296 snum_init = snum_init_46;
297
280 for (i = 0; i < qe_num_of_snum; i++) { 298 for (i = 0; i < qe_num_of_snum; i++) {
281 snums[i].num = snum_init[i]; 299 snums[i].num = snum_init[i];
282 snums[i].state = QE_SNUM_STATE_FREE; 300 snums[i].state = QE_SNUM_STATE_FREE;
diff --git a/arch/powerpc/sysdev/scom.c b/arch/powerpc/sysdev/scom.c
index 49a3ece1c6b3..702256a1ca11 100644
--- a/arch/powerpc/sysdev/scom.c
+++ b/arch/powerpc/sysdev/scom.c
@@ -22,6 +22,7 @@
22#include <linux/debugfs.h> 22#include <linux/debugfs.h>
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/export.h> 24#include <linux/export.h>
25#include <asm/debug.h>
25#include <asm/prom.h> 26#include <asm/prom.h>
26#include <asm/scom.h> 27#include <asm/scom.h>
27 28
diff --git a/arch/powerpc/sysdev/xics/xics-common.c b/arch/powerpc/sysdev/xics/xics-common.c
index ea5e204e3450..cd1d18db92c6 100644
--- a/arch/powerpc/sysdev/xics/xics-common.c
+++ b/arch/powerpc/sysdev/xics/xics-common.c
@@ -188,6 +188,7 @@ void xics_migrate_irqs_away(void)
188{ 188{
189 int cpu = smp_processor_id(), hw_cpu = hard_smp_processor_id(); 189 int cpu = smp_processor_id(), hw_cpu = hard_smp_processor_id();
190 unsigned int irq, virq; 190 unsigned int irq, virq;
191 struct irq_desc *desc;
191 192
192 /* If we used to be the default server, move to the new "boot_cpuid" */ 193 /* If we used to be the default server, move to the new "boot_cpuid" */
193 if (hw_cpu == xics_default_server) 194 if (hw_cpu == xics_default_server)
@@ -202,8 +203,7 @@ void xics_migrate_irqs_away(void)
202 /* Allow IPIs again... */ 203 /* Allow IPIs again... */
203 icp_ops->set_priority(DEFAULT_PRIORITY); 204 icp_ops->set_priority(DEFAULT_PRIORITY);
204 205
205 for_each_irq(virq) { 206 for_each_irq_desc(virq, desc) {
206 struct irq_desc *desc;
207 struct irq_chip *chip; 207 struct irq_chip *chip;
208 long server; 208 long server;
209 unsigned long flags; 209 unsigned long flags;
@@ -212,9 +212,8 @@ void xics_migrate_irqs_away(void)
212 /* We can't set affinity on ISA interrupts */ 212 /* We can't set affinity on ISA interrupts */
213 if (virq < NUM_ISA_INTERRUPTS) 213 if (virq < NUM_ISA_INTERRUPTS)
214 continue; 214 continue;
215 desc = irq_to_desc(virq);
216 /* We only need to migrate enabled IRQS */ 215 /* We only need to migrate enabled IRQS */
217 if (!desc || !desc->action) 216 if (!desc->action)
218 continue; 217 continue;
219 if (desc->irq_data.domain != xics_host) 218 if (desc->irq_data.domain != xics_host)
220 continue; 219 continue;
diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig
index 2b7c0fbe578e..9015060919a0 100644
--- a/arch/s390/Kconfig
+++ b/arch/s390/Kconfig
@@ -90,7 +90,6 @@ config S390
90 select HAVE_KERNEL_XZ 90 select HAVE_KERNEL_XZ
91 select HAVE_ARCH_MUTEX_CPU_RELAX 91 select HAVE_ARCH_MUTEX_CPU_RELAX
92 select HAVE_ARCH_JUMP_LABEL if !MARCH_G5 92 select HAVE_ARCH_JUMP_LABEL if !MARCH_G5
93 select HAVE_RCU_TABLE_FREE if SMP
94 select ARCH_SAVE_PAGE_KEYS if HIBERNATION 93 select ARCH_SAVE_PAGE_KEYS if HIBERNATION
95 select HAVE_MEMBLOCK 94 select HAVE_MEMBLOCK
96 select HAVE_MEMBLOCK_NODE_MAP 95 select HAVE_MEMBLOCK_NODE_MAP
diff --git a/arch/s390/defconfig b/arch/s390/defconfig
index 6cf8e26b3137..1957a9dd256d 100644
--- a/arch/s390/defconfig
+++ b/arch/s390/defconfig
@@ -1,8 +1,12 @@
1CONFIG_EXPERIMENTAL=y 1CONFIG_EXPERIMENTAL=y
2CONFIG_SYSVIPC=y 2CONFIG_SYSVIPC=y
3CONFIG_POSIX_MQUEUE=y 3CONFIG_POSIX_MQUEUE=y
4CONFIG_FHANDLE=y
5CONFIG_TASKSTATS=y
6CONFIG_TASK_DELAY_ACCT=y
7CONFIG_TASK_XACCT=y
8CONFIG_TASK_IO_ACCOUNTING=y
4CONFIG_AUDIT=y 9CONFIG_AUDIT=y
5CONFIG_RCU_TRACE=y
6CONFIG_IKCONFIG=y 10CONFIG_IKCONFIG=y
7CONFIG_IKCONFIG_PROC=y 11CONFIG_IKCONFIG_PROC=y
8CONFIG_CGROUPS=y 12CONFIG_CGROUPS=y
@@ -14,16 +18,22 @@ CONFIG_CGROUP_MEM_RES_CTLR_SWAP=y
14CONFIG_CGROUP_SCHED=y 18CONFIG_CGROUP_SCHED=y
15CONFIG_RT_GROUP_SCHED=y 19CONFIG_RT_GROUP_SCHED=y
16CONFIG_BLK_CGROUP=y 20CONFIG_BLK_CGROUP=y
21CONFIG_NAMESPACES=y
17CONFIG_BLK_DEV_INITRD=y 22CONFIG_BLK_DEV_INITRD=y
18# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set 23CONFIG_RD_BZIP2=y
24CONFIG_RD_LZMA=y
25CONFIG_RD_XZ=y
26CONFIG_RD_LZO=y
27CONFIG_EXPERT=y
19# CONFIG_COMPAT_BRK is not set 28# CONFIG_COMPAT_BRK is not set
20CONFIG_SLAB=y
21CONFIG_PROFILING=y 29CONFIG_PROFILING=y
22CONFIG_OPROFILE=y 30CONFIG_OPROFILE=y
23CONFIG_KPROBES=y 31CONFIG_KPROBES=y
24CONFIG_MODULES=y 32CONFIG_MODULES=y
25CONFIG_MODULE_UNLOAD=y 33CONFIG_MODULE_UNLOAD=y
26CONFIG_MODVERSIONS=y 34CONFIG_MODVERSIONS=y
35CONFIG_PARTITION_ADVANCED=y
36CONFIG_IBM_PARTITION=y
27CONFIG_DEFAULT_DEADLINE=y 37CONFIG_DEFAULT_DEADLINE=y
28CONFIG_NO_HZ=y 38CONFIG_NO_HZ=y
29CONFIG_HIGH_RES_TIMERS=y 39CONFIG_HIGH_RES_TIMERS=y
@@ -34,18 +44,15 @@ CONFIG_KSM=y
34CONFIG_BINFMT_MISC=m 44CONFIG_BINFMT_MISC=m
35CONFIG_CMM=m 45CONFIG_CMM=m
36CONFIG_HZ_100=y 46CONFIG_HZ_100=y
37CONFIG_KEXEC=y 47CONFIG_CRASH_DUMP=y
38CONFIG_PM=y
39CONFIG_HIBERNATION=y 48CONFIG_HIBERNATION=y
40CONFIG_PACKET=y 49CONFIG_PACKET=y
41CONFIG_UNIX=y 50CONFIG_UNIX=y
42CONFIG_NET_KEY=y 51CONFIG_NET_KEY=y
43CONFIG_AFIUCV=m
44CONFIG_INET=y 52CONFIG_INET=y
45CONFIG_IP_MULTICAST=y 53CONFIG_IP_MULTICAST=y
46# CONFIG_INET_LRO is not set 54# CONFIG_INET_LRO is not set
47CONFIG_IPV6=y 55CONFIG_IPV6=y
48CONFIG_NET_SCTPPROBE=m
49CONFIG_L2TP=m 56CONFIG_L2TP=m
50CONFIG_L2TP_DEBUGFS=m 57CONFIG_L2TP_DEBUGFS=m
51CONFIG_VLAN_8021Q=y 58CONFIG_VLAN_8021Q=y
@@ -84,15 +91,14 @@ CONFIG_SCSI_CONSTANTS=y
84CONFIG_SCSI_LOGGING=y 91CONFIG_SCSI_LOGGING=y
85CONFIG_SCSI_SCAN_ASYNC=y 92CONFIG_SCSI_SCAN_ASYNC=y
86CONFIG_ZFCP=y 93CONFIG_ZFCP=y
87CONFIG_ZFCP_DIF=y
88CONFIG_NETDEVICES=y 94CONFIG_NETDEVICES=y
89CONFIG_DUMMY=m
90CONFIG_BONDING=m 95CONFIG_BONDING=m
96CONFIG_DUMMY=m
91CONFIG_EQUALIZER=m 97CONFIG_EQUALIZER=m
92CONFIG_TUN=m 98CONFIG_TUN=m
93CONFIG_NET_ETHERNET=y
94CONFIG_VIRTIO_NET=y 99CONFIG_VIRTIO_NET=y
95CONFIG_RAW_DRIVER=m 100CONFIG_RAW_DRIVER=m
101CONFIG_VIRTIO_BALLOON=y
96CONFIG_EXT2_FS=y 102CONFIG_EXT2_FS=y
97CONFIG_EXT3_FS=y 103CONFIG_EXT3_FS=y
98# CONFIG_EXT3_DEFAULTS_TO_ORDERED is not set 104# CONFIG_EXT3_DEFAULTS_TO_ORDERED is not set
@@ -103,27 +109,21 @@ CONFIG_PROC_KCORE=y
103CONFIG_TMPFS=y 109CONFIG_TMPFS=y
104CONFIG_TMPFS_POSIX_ACL=y 110CONFIG_TMPFS_POSIX_ACL=y
105# CONFIG_NETWORK_FILESYSTEMS is not set 111# CONFIG_NETWORK_FILESYSTEMS is not set
106CONFIG_PARTITION_ADVANCED=y
107CONFIG_IBM_PARTITION=y
108CONFIG_DLM=m
109CONFIG_MAGIC_SYSRQ=y 112CONFIG_MAGIC_SYSRQ=y
110CONFIG_DEBUG_KERNEL=y
111CONFIG_TIMER_STATS=y 113CONFIG_TIMER_STATS=y
112CONFIG_PROVE_LOCKING=y 114CONFIG_PROVE_LOCKING=y
113CONFIG_PROVE_RCU=y 115CONFIG_PROVE_RCU=y
114CONFIG_LOCK_STAT=y 116CONFIG_LOCK_STAT=y
115CONFIG_DEBUG_LOCKDEP=y 117CONFIG_DEBUG_LOCKDEP=y
116CONFIG_DEBUG_SPINLOCK_SLEEP=y
117CONFIG_DEBUG_LIST=y 118CONFIG_DEBUG_LIST=y
118CONFIG_DEBUG_NOTIFIERS=y 119CONFIG_DEBUG_NOTIFIERS=y
119# CONFIG_RCU_CPU_STALL_DETECTOR is not set 120CONFIG_RCU_TRACE=y
120CONFIG_KPROBES_SANITY_TEST=y 121CONFIG_KPROBES_SANITY_TEST=y
121CONFIG_DEBUG_FORCE_WEAK_PER_CPU=y 122CONFIG_DEBUG_FORCE_WEAK_PER_CPU=y
122CONFIG_CPU_NOTIFIER_ERROR_INJECT=m 123CONFIG_CPU_NOTIFIER_ERROR_INJECT=m
123CONFIG_LATENCYTOP=y 124CONFIG_LATENCYTOP=y
124CONFIG_SYSCTL_SYSCALL_CHECK=y
125CONFIG_DEBUG_PAGEALLOC=y 125CONFIG_DEBUG_PAGEALLOC=y
126# CONFIG_FTRACE is not set 126CONFIG_BLK_DEV_IO_TRACE=y
127# CONFIG_STRICT_DEVMEM is not set 127# CONFIG_STRICT_DEVMEM is not set
128CONFIG_CRYPTO_NULL=m 128CONFIG_CRYPTO_NULL=m
129CONFIG_CRYPTO_CRYPTD=m 129CONFIG_CRYPTO_CRYPTD=m
@@ -173,4 +173,3 @@ CONFIG_CRYPTO_SHA512_S390=m
173CONFIG_CRYPTO_DES_S390=m 173CONFIG_CRYPTO_DES_S390=m
174CONFIG_CRYPTO_AES_S390=m 174CONFIG_CRYPTO_AES_S390=m
175CONFIG_CRC7=m 175CONFIG_CRC7=m
176CONFIG_VIRTIO_BALLOON=y
diff --git a/arch/s390/include/asm/facility.h b/arch/s390/include/asm/facility.h
index 1e5b27edc0c9..2ee66a65f2d4 100644
--- a/arch/s390/include/asm/facility.h
+++ b/arch/s390/include/asm/facility.h
@@ -38,12 +38,11 @@ static inline void stfle(u64 *stfle_fac_list, int size)
38 unsigned long nr; 38 unsigned long nr;
39 39
40 preempt_disable(); 40 preempt_disable();
41 S390_lowcore.stfl_fac_list = 0;
42 asm volatile( 41 asm volatile(
43 " .insn s,0xb2b10000,0(0)\n" /* stfl */ 42 " .insn s,0xb2b10000,0(0)\n" /* stfl */
44 "0:\n" 43 "0:\n"
45 EX_TABLE(0b, 0b) 44 EX_TABLE(0b, 0b)
46 : "=m" (S390_lowcore.stfl_fac_list)); 45 : "+m" (S390_lowcore.stfl_fac_list));
47 nr = 4; /* bytes stored by stfl */ 46 nr = 4; /* bytes stored by stfl */
48 memcpy(stfle_fac_list, &S390_lowcore.stfl_fac_list, 4); 47 memcpy(stfle_fac_list, &S390_lowcore.stfl_fac_list, 4);
49 if (S390_lowcore.stfl_fac_list & 0x01000000) { 48 if (S390_lowcore.stfl_fac_list & 0x01000000) {
diff --git a/arch/s390/include/asm/pgalloc.h b/arch/s390/include/asm/pgalloc.h
index 8eef9b5b3cf4..78e3041919de 100644
--- a/arch/s390/include/asm/pgalloc.h
+++ b/arch/s390/include/asm/pgalloc.h
@@ -22,10 +22,7 @@ void crst_table_free(struct mm_struct *, unsigned long *);
22 22
23unsigned long *page_table_alloc(struct mm_struct *, unsigned long); 23unsigned long *page_table_alloc(struct mm_struct *, unsigned long);
24void page_table_free(struct mm_struct *, unsigned long *); 24void page_table_free(struct mm_struct *, unsigned long *);
25#ifdef CONFIG_HAVE_RCU_TABLE_FREE
26void page_table_free_rcu(struct mmu_gather *, unsigned long *); 25void page_table_free_rcu(struct mmu_gather *, unsigned long *);
27void __tlb_remove_table(void *_table);
28#endif
29 26
30static inline void clear_table(unsigned long *s, unsigned long val, size_t n) 27static inline void clear_table(unsigned long *s, unsigned long val, size_t n)
31{ 28{
diff --git a/arch/s390/include/asm/swab.h b/arch/s390/include/asm/swab.h
index 6bdee21c077e..a3e4ebb32090 100644
--- a/arch/s390/include/asm/swab.h
+++ b/arch/s390/include/asm/swab.h
@@ -77,7 +77,7 @@ static inline __u16 __arch_swab16p(const __u16 *x)
77 77
78 asm volatile( 78 asm volatile(
79#ifndef __s390x__ 79#ifndef __s390x__
80 " icm %0,2,%O+1(%R1)\n" 80 " icm %0,2,%O1+1(%R1)\n"
81 " ic %0,%1\n" 81 " ic %0,%1\n"
82 : "=&d" (result) : "Q" (*x) : "cc"); 82 : "=&d" (result) : "Q" (*x) : "cc");
83#else /* __s390x__ */ 83#else /* __s390x__ */
diff --git a/arch/s390/include/asm/tlb.h b/arch/s390/include/asm/tlb.h
index c687a2c83462..775a5eea8f9e 100644
--- a/arch/s390/include/asm/tlb.h
+++ b/arch/s390/include/asm/tlb.h
@@ -30,14 +30,10 @@
30 30
31struct mmu_gather { 31struct mmu_gather {
32 struct mm_struct *mm; 32 struct mm_struct *mm;
33#ifdef CONFIG_HAVE_RCU_TABLE_FREE
34 struct mmu_table_batch *batch; 33 struct mmu_table_batch *batch;
35#endif
36 unsigned int fullmm; 34 unsigned int fullmm;
37 unsigned int need_flush;
38}; 35};
39 36
40#ifdef CONFIG_HAVE_RCU_TABLE_FREE
41struct mmu_table_batch { 37struct mmu_table_batch {
42 struct rcu_head rcu; 38 struct rcu_head rcu;
43 unsigned int nr; 39 unsigned int nr;
@@ -49,7 +45,6 @@ struct mmu_table_batch {
49 45
50extern void tlb_table_flush(struct mmu_gather *tlb); 46extern void tlb_table_flush(struct mmu_gather *tlb);
51extern void tlb_remove_table(struct mmu_gather *tlb, void *table); 47extern void tlb_remove_table(struct mmu_gather *tlb, void *table);
52#endif
53 48
54static inline void tlb_gather_mmu(struct mmu_gather *tlb, 49static inline void tlb_gather_mmu(struct mmu_gather *tlb,
55 struct mm_struct *mm, 50 struct mm_struct *mm,
@@ -57,29 +52,20 @@ static inline void tlb_gather_mmu(struct mmu_gather *tlb,
57{ 52{
58 tlb->mm = mm; 53 tlb->mm = mm;
59 tlb->fullmm = full_mm_flush; 54 tlb->fullmm = full_mm_flush;
60 tlb->need_flush = 0;
61#ifdef CONFIG_HAVE_RCU_TABLE_FREE
62 tlb->batch = NULL; 55 tlb->batch = NULL;
63#endif
64 if (tlb->fullmm) 56 if (tlb->fullmm)
65 __tlb_flush_mm(mm); 57 __tlb_flush_mm(mm);
66} 58}
67 59
68static inline void tlb_flush_mmu(struct mmu_gather *tlb) 60static inline void tlb_flush_mmu(struct mmu_gather *tlb)
69{ 61{
70 if (!tlb->need_flush)
71 return;
72 tlb->need_flush = 0;
73 __tlb_flush_mm(tlb->mm);
74#ifdef CONFIG_HAVE_RCU_TABLE_FREE
75 tlb_table_flush(tlb); 62 tlb_table_flush(tlb);
76#endif
77} 63}
78 64
79static inline void tlb_finish_mmu(struct mmu_gather *tlb, 65static inline void tlb_finish_mmu(struct mmu_gather *tlb,
80 unsigned long start, unsigned long end) 66 unsigned long start, unsigned long end)
81{ 67{
82 tlb_flush_mmu(tlb); 68 tlb_table_flush(tlb);
83} 69}
84 70
85/* 71/*
@@ -105,10 +91,8 @@ static inline void tlb_remove_page(struct mmu_gather *tlb, struct page *page)
105static inline void pte_free_tlb(struct mmu_gather *tlb, pgtable_t pte, 91static inline void pte_free_tlb(struct mmu_gather *tlb, pgtable_t pte,
106 unsigned long address) 92 unsigned long address)
107{ 93{
108#ifdef CONFIG_HAVE_RCU_TABLE_FREE
109 if (!tlb->fullmm) 94 if (!tlb->fullmm)
110 return page_table_free_rcu(tlb, (unsigned long *) pte); 95 return page_table_free_rcu(tlb, (unsigned long *) pte);
111#endif
112 page_table_free(tlb->mm, (unsigned long *) pte); 96 page_table_free(tlb->mm, (unsigned long *) pte);
113} 97}
114 98
@@ -125,10 +109,8 @@ static inline void pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
125#ifdef __s390x__ 109#ifdef __s390x__
126 if (tlb->mm->context.asce_limit <= (1UL << 31)) 110 if (tlb->mm->context.asce_limit <= (1UL << 31))
127 return; 111 return;
128#ifdef CONFIG_HAVE_RCU_TABLE_FREE
129 if (!tlb->fullmm) 112 if (!tlb->fullmm)
130 return tlb_remove_table(tlb, pmd); 113 return tlb_remove_table(tlb, pmd);
131#endif
132 crst_table_free(tlb->mm, (unsigned long *) pmd); 114 crst_table_free(tlb->mm, (unsigned long *) pmd);
133#endif 115#endif
134} 116}
@@ -146,10 +128,8 @@ static inline void pud_free_tlb(struct mmu_gather *tlb, pud_t *pud,
146#ifdef __s390x__ 128#ifdef __s390x__
147 if (tlb->mm->context.asce_limit <= (1UL << 42)) 129 if (tlb->mm->context.asce_limit <= (1UL << 42))
148 return; 130 return;
149#ifdef CONFIG_HAVE_RCU_TABLE_FREE
150 if (!tlb->fullmm) 131 if (!tlb->fullmm)
151 return tlb_remove_table(tlb, pud); 132 return tlb_remove_table(tlb, pud);
152#endif
153 crst_table_free(tlb->mm, (unsigned long *) pud); 133 crst_table_free(tlb->mm, (unsigned long *) pud);
154#endif 134#endif
155} 135}
diff --git a/arch/s390/kernel/head.S b/arch/s390/kernel/head.S
index c27a0727f930..adccd908ebc7 100644
--- a/arch/s390/kernel/head.S
+++ b/arch/s390/kernel/head.S
@@ -474,9 +474,9 @@ ENTRY(startup_kdump)
474 stck __LC_LAST_UPDATE_CLOCK 474 stck __LC_LAST_UPDATE_CLOCK
475 spt 5f-.LPG0(%r13) 475 spt 5f-.LPG0(%r13)
476 mvc __LC_LAST_UPDATE_TIMER(8),5f-.LPG0(%r13) 476 mvc __LC_LAST_UPDATE_TIMER(8),5f-.LPG0(%r13)
477 xc __LC_STFL_FAC_LIST(8),__LC_STFL_FAC_LIST
477#ifndef CONFIG_MARCH_G5 478#ifndef CONFIG_MARCH_G5
478 # check capabilities against MARCH_{G5,Z900,Z990,Z9_109,Z10} 479 # check capabilities against MARCH_{G5,Z900,Z990,Z9_109,Z10}
479 xc __LC_STFL_FAC_LIST(8),__LC_STFL_FAC_LIST
480 .insn s,0xb2b10000,__LC_STFL_FAC_LIST # store facility list 480 .insn s,0xb2b10000,__LC_STFL_FAC_LIST # store facility list
481 tm __LC_STFL_FAC_LIST,0x01 # stfle available ? 481 tm __LC_STFL_FAC_LIST,0x01 # stfle available ?
482 jz 0f 482 jz 0f
diff --git a/arch/s390/kernel/irq.c b/arch/s390/kernel/irq.c
index 1c2cdd59ccd0..8a22c27219dd 100644
--- a/arch/s390/kernel/irq.c
+++ b/arch/s390/kernel/irq.c
@@ -118,9 +118,10 @@ asmlinkage void do_softirq(void)
118 "a" (__do_softirq) 118 "a" (__do_softirq)
119 : "0", "1", "2", "3", "4", "5", "14", 119 : "0", "1", "2", "3", "4", "5", "14",
120 "cc", "memory" ); 120 "cc", "memory" );
121 } else 121 } else {
122 /* We are already on the async stack. */ 122 /* We are already on the async stack. */
123 __do_softirq(); 123 __do_softirq();
124 }
124 } 125 }
125 126
126 local_irq_restore(flags); 127 local_irq_restore(flags);
@@ -192,11 +193,12 @@ int unregister_external_interrupt(u16 code, ext_int_handler_t handler)
192 int index = ext_hash(code); 193 int index = ext_hash(code);
193 194
194 spin_lock_irqsave(&ext_int_hash_lock, flags); 195 spin_lock_irqsave(&ext_int_hash_lock, flags);
195 list_for_each_entry_rcu(p, &ext_int_hash[index], entry) 196 list_for_each_entry_rcu(p, &ext_int_hash[index], entry) {
196 if (p->code == code && p->handler == handler) { 197 if (p->code == code && p->handler == handler) {
197 list_del_rcu(&p->entry); 198 list_del_rcu(&p->entry);
198 kfree_rcu(p, rcu); 199 kfree_rcu(p, rcu);
199 } 200 }
201 }
200 spin_unlock_irqrestore(&ext_int_hash_lock, flags); 202 spin_unlock_irqrestore(&ext_int_hash_lock, flags);
201 return 0; 203 return 0;
202} 204}
@@ -211,9 +213,10 @@ void __irq_entry do_extint(struct pt_regs *regs, struct ext_code ext_code,
211 213
212 old_regs = set_irq_regs(regs); 214 old_regs = set_irq_regs(regs);
213 irq_enter(); 215 irq_enter();
214 if (S390_lowcore.int_clock >= S390_lowcore.clock_comparator) 216 if (S390_lowcore.int_clock >= S390_lowcore.clock_comparator) {
215 /* Serve timer interrupts first. */ 217 /* Serve timer interrupts first. */
216 clock_comparator_work(); 218 clock_comparator_work();
219 }
217 kstat_cpu(smp_processor_id()).irqs[EXTERNAL_INTERRUPT]++; 220 kstat_cpu(smp_processor_id()).irqs[EXTERNAL_INTERRUPT]++;
218 if (ext_code.code != 0x1004) 221 if (ext_code.code != 0x1004)
219 __get_cpu_var(s390_idle).nohz_delay = 1; 222 __get_cpu_var(s390_idle).nohz_delay = 1;
diff --git a/arch/s390/kernel/perf_cpum_cf.c b/arch/s390/kernel/perf_cpum_cf.c
index 46405086479c..cb019f429e88 100644
--- a/arch/s390/kernel/perf_cpum_cf.c
+++ b/arch/s390/kernel/perf_cpum_cf.c
@@ -178,7 +178,7 @@ static void cpumf_pmu_enable(struct pmu *pmu)
178 err = lcctl(cpuhw->state); 178 err = lcctl(cpuhw->state);
179 if (err) { 179 if (err) {
180 pr_err("Enabling the performance measuring unit " 180 pr_err("Enabling the performance measuring unit "
181 "failed with rc=%lx\n", err); 181 "failed with rc=%x\n", err);
182 return; 182 return;
183 } 183 }
184 184
@@ -203,7 +203,7 @@ static void cpumf_pmu_disable(struct pmu *pmu)
203 err = lcctl(inactive); 203 err = lcctl(inactive);
204 if (err) { 204 if (err) {
205 pr_err("Disabling the performance measuring unit " 205 pr_err("Disabling the performance measuring unit "
206 "failed with rc=%lx\n", err); 206 "failed with rc=%x\n", err);
207 return; 207 return;
208 } 208 }
209 209
diff --git a/arch/s390/mm/maccess.c b/arch/s390/mm/maccess.c
index 7bb15fcca75e..e1335dc2b1b7 100644
--- a/arch/s390/mm/maccess.c
+++ b/arch/s390/mm/maccess.c
@@ -61,21 +61,14 @@ long probe_kernel_write(void *dst, const void *src, size_t size)
61 return copied < 0 ? -EFAULT : 0; 61 return copied < 0 ? -EFAULT : 0;
62} 62}
63 63
64/* 64static int __memcpy_real(void *dest, void *src, size_t count)
65 * Copy memory in real mode (kernel to kernel)
66 */
67int memcpy_real(void *dest, void *src, size_t count)
68{ 65{
69 register unsigned long _dest asm("2") = (unsigned long) dest; 66 register unsigned long _dest asm("2") = (unsigned long) dest;
70 register unsigned long _len1 asm("3") = (unsigned long) count; 67 register unsigned long _len1 asm("3") = (unsigned long) count;
71 register unsigned long _src asm("4") = (unsigned long) src; 68 register unsigned long _src asm("4") = (unsigned long) src;
72 register unsigned long _len2 asm("5") = (unsigned long) count; 69 register unsigned long _len2 asm("5") = (unsigned long) count;
73 unsigned long flags;
74 int rc = -EFAULT; 70 int rc = -EFAULT;
75 71
76 if (!count)
77 return 0;
78 flags = __arch_local_irq_stnsm(0xf8UL);
79 asm volatile ( 72 asm volatile (
80 "0: mvcle %1,%2,0x0\n" 73 "0: mvcle %1,%2,0x0\n"
81 "1: jo 0b\n" 74 "1: jo 0b\n"
@@ -86,7 +79,23 @@ int memcpy_real(void *dest, void *src, size_t count)
86 "+d" (_len2), "=m" (*((long *) dest)) 79 "+d" (_len2), "=m" (*((long *) dest))
87 : "m" (*((long *) src)) 80 : "m" (*((long *) src))
88 : "cc", "memory"); 81 : "cc", "memory");
89 arch_local_irq_restore(flags); 82 return rc;
83}
84
85/*
86 * Copy memory in real mode (kernel to kernel)
87 */
88int memcpy_real(void *dest, void *src, size_t count)
89{
90 unsigned long flags;
91 int rc;
92
93 if (!count)
94 return 0;
95 local_irq_save(flags);
96 __arch_local_irq_stnsm(0xfbUL);
97 rc = __memcpy_real(dest, src, count);
98 local_irq_restore(flags);
90 return rc; 99 return rc;
91} 100}
92 101
diff --git a/arch/s390/mm/pgtable.c b/arch/s390/mm/pgtable.c
index 373adf69b01c..6e765bf00670 100644
--- a/arch/s390/mm/pgtable.c
+++ b/arch/s390/mm/pgtable.c
@@ -678,8 +678,6 @@ void page_table_free(struct mm_struct *mm, unsigned long *table)
678 } 678 }
679} 679}
680 680
681#ifdef CONFIG_HAVE_RCU_TABLE_FREE
682
683static void __page_table_free_rcu(void *table, unsigned bit) 681static void __page_table_free_rcu(void *table, unsigned bit)
684{ 682{
685 struct page *page; 683 struct page *page;
@@ -733,7 +731,66 @@ void __tlb_remove_table(void *_table)
733 free_pages((unsigned long) table, ALLOC_ORDER); 731 free_pages((unsigned long) table, ALLOC_ORDER);
734} 732}
735 733
736#endif 734static void tlb_remove_table_smp_sync(void *arg)
735{
736 /* Simply deliver the interrupt */
737}
738
739static void tlb_remove_table_one(void *table)
740{
741 /*
742 * This isn't an RCU grace period and hence the page-tables cannot be
743 * assumed to be actually RCU-freed.
744 *
745 * It is however sufficient for software page-table walkers that rely
746 * on IRQ disabling. See the comment near struct mmu_table_batch.
747 */
748 smp_call_function(tlb_remove_table_smp_sync, NULL, 1);
749 __tlb_remove_table(table);
750}
751
752static void tlb_remove_table_rcu(struct rcu_head *head)
753{
754 struct mmu_table_batch *batch;
755 int i;
756
757 batch = container_of(head, struct mmu_table_batch, rcu);
758
759 for (i = 0; i < batch->nr; i++)
760 __tlb_remove_table(batch->tables[i]);
761
762 free_page((unsigned long)batch);
763}
764
765void tlb_table_flush(struct mmu_gather *tlb)
766{
767 struct mmu_table_batch **batch = &tlb->batch;
768
769 if (*batch) {
770 __tlb_flush_mm(tlb->mm);
771 call_rcu_sched(&(*batch)->rcu, tlb_remove_table_rcu);
772 *batch = NULL;
773 }
774}
775
776void tlb_remove_table(struct mmu_gather *tlb, void *table)
777{
778 struct mmu_table_batch **batch = &tlb->batch;
779
780 if (*batch == NULL) {
781 *batch = (struct mmu_table_batch *)
782 __get_free_page(GFP_NOWAIT | __GFP_NOWARN);
783 if (*batch == NULL) {
784 __tlb_flush_mm(tlb->mm);
785 tlb_remove_table_one(table);
786 return;
787 }
788 (*batch)->nr = 0;
789 }
790 (*batch)->tables[(*batch)->nr++] = table;
791 if ((*batch)->nr == MAX_TABLE_BATCH)
792 tlb_table_flush(tlb);
793}
737 794
738/* 795/*
739 * switch on pgstes for its userspace process (for kvm) 796 * switch on pgstes for its userspace process (for kvm)
diff --git a/arch/sh/Kconfig.debug b/arch/sh/Kconfig.debug
index c1d5a820b1aa..5f2bb4242c0f 100644
--- a/arch/sh/Kconfig.debug
+++ b/arch/sh/Kconfig.debug
@@ -61,6 +61,7 @@ config DUMP_CODE
61config DWARF_UNWINDER 61config DWARF_UNWINDER
62 bool "Enable the DWARF unwinder for stacktraces" 62 bool "Enable the DWARF unwinder for stacktraces"
63 select FRAME_POINTER 63 select FRAME_POINTER
64 depends on SUPERH32
64 default n 65 default n
65 help 66 help
66 Enabling this option will make stacktraces more accurate, at 67 Enabling this option will make stacktraces more accurate, at
diff --git a/arch/sh/boards/Kconfig b/arch/sh/boards/Kconfig
index d893411022d5..c0241bd584f4 100644
--- a/arch/sh/boards/Kconfig
+++ b/arch/sh/boards/Kconfig
@@ -54,6 +54,7 @@ config SH_7724_SOLUTION_ENGINE
54 select SOLUTION_ENGINE 54 select SOLUTION_ENGINE
55 depends on CPU_SUBTYPE_SH7724 55 depends on CPU_SUBTYPE_SH7724
56 select ARCH_REQUIRE_GPIOLIB 56 select ARCH_REQUIRE_GPIOLIB
57 select SND_SOC_AK4642 if SND_SIMPLE_CARD
57 help 58 help
58 Select 7724 SolutionEngine if configuring for a Hitachi SH7724 59 Select 7724 SolutionEngine if configuring for a Hitachi SH7724
59 evaluation board. 60 evaluation board.
@@ -223,6 +224,7 @@ config SH_ECOVEC
223 bool "EcoVec" 224 bool "EcoVec"
224 depends on CPU_SUBTYPE_SH7724 225 depends on CPU_SUBTYPE_SH7724
225 select ARCH_REQUIRE_GPIOLIB 226 select ARCH_REQUIRE_GPIOLIB
227 select SND_SOC_DA7210 if SND_SIMPLE_CARD
226 help 228 help
227 Renesas "R0P7724LC0011/21RL (EcoVec)" support. 229 Renesas "R0P7724LC0011/21RL (EcoVec)" support.
228 230
diff --git a/arch/sh/boards/board-sh7785lcr.c b/arch/sh/boards/board-sh7785lcr.c
index d879848f3cdd..d0d6221d7c2e 100644
--- a/arch/sh/boards/board-sh7785lcr.c
+++ b/arch/sh/boards/board-sh7785lcr.c
@@ -28,6 +28,7 @@
28#include <cpu/sh7785.h> 28#include <cpu/sh7785.h>
29#include <asm/heartbeat.h> 29#include <asm/heartbeat.h>
30#include <asm/clock.h> 30#include <asm/clock.h>
31#include <asm/bl_bit.h>
31 32
32/* 33/*
33 * NOTE: This board has 2 physical memory maps. 34 * NOTE: This board has 2 physical memory maps.
diff --git a/arch/sh/boards/mach-ecovec24/setup.c b/arch/sh/boards/mach-ecovec24/setup.c
index d12fe9ddf3da..299a40a44c92 100644
--- a/arch/sh/boards/mach-ecovec24/setup.c
+++ b/arch/sh/boards/mach-ecovec24/setup.c
@@ -32,6 +32,7 @@
32#include <linux/videodev2.h> 32#include <linux/videodev2.h>
33#include <video/sh_mobile_lcdc.h> 33#include <video/sh_mobile_lcdc.h>
34#include <sound/sh_fsi.h> 34#include <sound/sh_fsi.h>
35#include <sound/simple_card.h>
35#include <media/sh_mobile_ceu.h> 36#include <media/sh_mobile_ceu.h>
36#include <media/soc_camera.h> 37#include <media/soc_camera.h>
37#include <media/tw9910.h> 38#include <media/tw9910.h>
@@ -809,6 +810,30 @@ static struct platform_device fsi_device = {
809 }, 810 },
810}; 811};
811 812
813static struct asoc_simple_dai_init_info fsi_da7210_init_info = {
814 .fmt = SND_SOC_DAIFMT_I2S,
815 .codec_daifmt = SND_SOC_DAIFMT_CBM_CFM,
816 .cpu_daifmt = SND_SOC_DAIFMT_CBS_CFS,
817};
818
819static struct asoc_simple_card_info fsi_da7210_info = {
820 .name = "DA7210",
821 .card = "FSIB-DA7210",
822 .cpu_dai = "fsib-dai",
823 .codec = "da7210.0-001a",
824 .platform = "sh_fsi.0",
825 .codec_dai = "da7210-hifi",
826 .init = &fsi_da7210_init_info,
827};
828
829static struct platform_device fsi_da7210_device = {
830 .name = "asoc-simple-card",
831 .dev = {
832 .platform_data = &fsi_da7210_info,
833 },
834};
835
836
812/* IrDA */ 837/* IrDA */
813static struct resource irda_resources[] = { 838static struct resource irda_resources[] = {
814 [0] = { 839 [0] = {
@@ -945,6 +970,7 @@ static struct platform_device *ecovec_devices[] __initdata = {
945 &camera_devices[1], 970 &camera_devices[1],
946 &camera_devices[2], 971 &camera_devices[2],
947 &fsi_device, 972 &fsi_device,
973 &fsi_da7210_device,
948 &irda_device, 974 &irda_device,
949 &vou_device, 975 &vou_device,
950#if defined(CONFIG_MMC_SH_MMCIF) || defined(CONFIG_MMC_SH_MMCIF_MODULE) 976#if defined(CONFIG_MMC_SH_MMCIF) || defined(CONFIG_MMC_SH_MMCIF_MODULE)
diff --git a/arch/sh/boards/mach-hp6xx/pm.c b/arch/sh/boards/mach-hp6xx/pm.c
index adc9b4bba828..8b50cf763c06 100644
--- a/arch/sh/boards/mach-hp6xx/pm.c
+++ b/arch/sh/boards/mach-hp6xx/pm.c
@@ -14,6 +14,7 @@
14#include <linux/gfp.h> 14#include <linux/gfp.h>
15#include <asm/io.h> 15#include <asm/io.h>
16#include <asm/hd64461.h> 16#include <asm/hd64461.h>
17#include <asm/bl_bit.h>
17#include <mach/hp6xx.h> 18#include <mach/hp6xx.h>
18#include <cpu/dac.h> 19#include <cpu/dac.h>
19#include <asm/freq.h> 20#include <asm/freq.h>
diff --git a/arch/sh/boards/mach-se/7724/setup.c b/arch/sh/boards/mach-se/7724/setup.c
index c540b16547c3..5cc5ed44d9af 100644
--- a/arch/sh/boards/mach-se/7724/setup.c
+++ b/arch/sh/boards/mach-se/7724/setup.c
@@ -28,6 +28,7 @@
28#include <video/sh_mobile_lcdc.h> 28#include <video/sh_mobile_lcdc.h>
29#include <media/sh_mobile_ceu.h> 29#include <media/sh_mobile_ceu.h>
30#include <sound/sh_fsi.h> 30#include <sound/sh_fsi.h>
31#include <sound/simple_card.h>
31#include <asm/io.h> 32#include <asm/io.h>
32#include <asm/heartbeat.h> 33#include <asm/heartbeat.h>
33#include <asm/clock.h> 34#include <asm/clock.h>
@@ -304,17 +305,25 @@ static struct platform_device fsi_device = {
304 }, 305 },
305}; 306};
306 307
307static struct fsi_ak4642_info fsi_ak4642_info = { 308static struct asoc_simple_dai_init_info fsi2_ak4642_init_info = {
309 .fmt = SND_SOC_DAIFMT_LEFT_J,
310 .codec_daifmt = SND_SOC_DAIFMT_CBM_CFM,
311 .cpu_daifmt = SND_SOC_DAIFMT_CBS_CFS,
312 .sysclk = 11289600,
313};
314
315static struct asoc_simple_card_info fsi_ak4642_info = {
308 .name = "AK4642", 316 .name = "AK4642",
309 .card = "FSIA-AK4642", 317 .card = "FSIA-AK4642",
310 .cpu_dai = "fsia-dai", 318 .cpu_dai = "fsia-dai",
311 .codec = "ak4642-codec.0-0012", 319 .codec = "ak4642-codec.0-0012",
312 .platform = "sh_fsi.0", 320 .platform = "sh_fsi.0",
313 .id = FSI_PORT_A, 321 .codec_dai = "ak4642-hifi",
322 .init = &fsi2_ak4642_init_info,
314}; 323};
315 324
316static struct platform_device fsi_ak4642_device = { 325static struct platform_device fsi_ak4642_device = {
317 .name = "fsi-ak4642-audio", 326 .name = "asoc-simple-card",
318 .dev = { 327 .dev = {
319 .platform_data = &fsi_ak4642_info, 328 .platform_data = &fsi_ak4642_info,
320 }, 329 },
diff --git a/arch/sh/drivers/dma/dma-sysfs.c b/arch/sh/drivers/dma/dma-sysfs.c
index b1cb2715ad6e..67ee95603813 100644
--- a/arch/sh/drivers/dma/dma-sysfs.c
+++ b/arch/sh/drivers/dma/dma-sysfs.c
@@ -54,7 +54,7 @@ static int __init dma_subsys_init(void)
54 if (unlikely(ret)) 54 if (unlikely(ret))
55 return ret; 55 return ret;
56 56
57 return device_create_file(dma_subsys.dev_root, &dev_attr_devices.attr); 57 return device_create_file(dma_subsys.dev_root, &dev_attr_devices);
58} 58}
59postcore_initcall(dma_subsys_init); 59postcore_initcall(dma_subsys_init);
60 60
diff --git a/arch/sh/include/asm/atomic.h b/arch/sh/include/asm/atomic.h
index 37f2f4a55231..f4c1c20bcdf6 100644
--- a/arch/sh/include/asm/atomic.h
+++ b/arch/sh/include/asm/atomic.h
@@ -11,7 +11,7 @@
11#include <linux/types.h> 11#include <linux/types.h>
12#include <asm/cmpxchg.h> 12#include <asm/cmpxchg.h>
13 13
14#define ATOMIC_INIT(i) ( (atomic_t) { (i) } ) 14#define ATOMIC_INIT(i) { (i) }
15 15
16#define atomic_read(v) (*(volatile int *)&(v)->counter) 16#define atomic_read(v) (*(volatile int *)&(v)->counter)
17#define atomic_set(v,i) ((v)->counter = (i)) 17#define atomic_set(v,i) ((v)->counter = (i))
diff --git a/arch/sh/include/asm/dma-mapping.h b/arch/sh/include/asm/dma-mapping.h
index 1a73c3e759a7..8bd965e00a15 100644
--- a/arch/sh/include/asm/dma-mapping.h
+++ b/arch/sh/include/asm/dma-mapping.h
@@ -52,25 +52,31 @@ static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
52 return dma_addr == 0; 52 return dma_addr == 0;
53} 53}
54 54
55static inline void *dma_alloc_coherent(struct device *dev, size_t size, 55#define dma_alloc_coherent(d,s,h,f) dma_alloc_attrs(d,s,h,f,NULL)
56 dma_addr_t *dma_handle, gfp_t gfp) 56
57static inline void *dma_alloc_attrs(struct device *dev, size_t size,
58 dma_addr_t *dma_handle, gfp_t gfp,
59 struct dma_attrs *attrs)
57{ 60{
58 struct dma_map_ops *ops = get_dma_ops(dev); 61 struct dma_map_ops *ops = get_dma_ops(dev);
59 void *memory; 62 void *memory;
60 63
61 if (dma_alloc_from_coherent(dev, size, dma_handle, &memory)) 64 if (dma_alloc_from_coherent(dev, size, dma_handle, &memory))
62 return memory; 65 return memory;
63 if (!ops->alloc_coherent) 66 if (!ops->alloc)
64 return NULL; 67 return NULL;
65 68
66 memory = ops->alloc_coherent(dev, size, dma_handle, gfp); 69 memory = ops->alloc(dev, size, dma_handle, gfp, attrs);
67 debug_dma_alloc_coherent(dev, size, *dma_handle, memory); 70 debug_dma_alloc_coherent(dev, size, *dma_handle, memory);
68 71
69 return memory; 72 return memory;
70} 73}
71 74
72static inline void dma_free_coherent(struct device *dev, size_t size, 75#define dma_free_coherent(d,s,c,h) dma_free_attrs(d,s,c,h,NULL)
73 void *vaddr, dma_addr_t dma_handle) 76
77static inline void dma_free_attrs(struct device *dev, size_t size,
78 void *vaddr, dma_addr_t dma_handle,
79 struct dma_attrs *attrs)
74{ 80{
75 struct dma_map_ops *ops = get_dma_ops(dev); 81 struct dma_map_ops *ops = get_dma_ops(dev);
76 82
@@ -78,14 +84,16 @@ static inline void dma_free_coherent(struct device *dev, size_t size,
78 return; 84 return;
79 85
80 debug_dma_free_coherent(dev, size, vaddr, dma_handle); 86 debug_dma_free_coherent(dev, size, vaddr, dma_handle);
81 if (ops->free_coherent) 87 if (ops->free)
82 ops->free_coherent(dev, size, vaddr, dma_handle); 88 ops->free(dev, size, vaddr, dma_handle, attrs);
83} 89}
84 90
85/* arch/sh/mm/consistent.c */ 91/* arch/sh/mm/consistent.c */
86extern void *dma_generic_alloc_coherent(struct device *dev, size_t size, 92extern void *dma_generic_alloc_coherent(struct device *dev, size_t size,
87 dma_addr_t *dma_addr, gfp_t flag); 93 dma_addr_t *dma_addr, gfp_t flag,
94 struct dma_attrs *attrs);
88extern void dma_generic_free_coherent(struct device *dev, size_t size, 95extern void dma_generic_free_coherent(struct device *dev, size_t size,
89 void *vaddr, dma_addr_t dma_handle); 96 void *vaddr, dma_addr_t dma_handle,
97 struct dma_attrs *attrs);
90 98
91#endif /* __ASM_SH_DMA_MAPPING_H */ 99#endif /* __ASM_SH_DMA_MAPPING_H */
diff --git a/arch/sh/kernel/cpu/fpu.c b/arch/sh/kernel/cpu/fpu.c
index 7f1b70cace35..f8f7af51c128 100644
--- a/arch/sh/kernel/cpu/fpu.c
+++ b/arch/sh/kernel/cpu/fpu.c
@@ -2,6 +2,7 @@
2#include <linux/slab.h> 2#include <linux/slab.h>
3#include <asm/processor.h> 3#include <asm/processor.h>
4#include <asm/fpu.h> 4#include <asm/fpu.h>
5#include <asm/traps.h>
5 6
6int init_fpu(struct task_struct *tsk) 7int init_fpu(struct task_struct *tsk)
7{ 8{
diff --git a/arch/sh/kernel/cpu/sh2a/fpu.c b/arch/sh/kernel/cpu/sh2a/fpu.c
index 488d24e0cdf0..98bbaa447c93 100644
--- a/arch/sh/kernel/cpu/sh2a/fpu.c
+++ b/arch/sh/kernel/cpu/sh2a/fpu.c
@@ -14,6 +14,7 @@
14#include <asm/processor.h> 14#include <asm/processor.h>
15#include <asm/io.h> 15#include <asm/io.h>
16#include <asm/fpu.h> 16#include <asm/fpu.h>
17#include <asm/traps.h>
17 18
18/* The PR (precision) bit in the FP Status Register must be clear when 19/* The PR (precision) bit in the FP Status Register must be clear when
19 * an frchg instruction is executed, otherwise the instruction is undefined. 20 * an frchg instruction is executed, otherwise the instruction is undefined.
diff --git a/arch/sh/kernel/cpu/sh4/fpu.c b/arch/sh/kernel/cpu/sh4/fpu.c
index e74cd6c0f10d..69ab4d3c8d41 100644
--- a/arch/sh/kernel/cpu/sh4/fpu.c
+++ b/arch/sh/kernel/cpu/sh4/fpu.c
@@ -16,6 +16,7 @@
16#include <cpu/fpu.h> 16#include <cpu/fpu.h>
17#include <asm/processor.h> 17#include <asm/processor.h>
18#include <asm/fpu.h> 18#include <asm/fpu.h>
19#include <asm/traps.h>
19 20
20/* The PR (precision) bit in the FP Status Register must be clear when 21/* The PR (precision) bit in the FP Status Register must be clear when
21 * an frchg instruction is executed, otherwise the instruction is undefined. 22 * an frchg instruction is executed, otherwise the instruction is undefined.
diff --git a/arch/sh/kernel/cpu/sh4a/clock-sh7757.c b/arch/sh/kernel/cpu/sh4a/clock-sh7757.c
index 5853989586ed..04ab5aeaf920 100644
--- a/arch/sh/kernel/cpu/sh4a/clock-sh7757.c
+++ b/arch/sh/kernel/cpu/sh4a/clock-sh7757.c
@@ -113,7 +113,7 @@ static struct clk_lookup lookups[] = {
113 CLKDEV_CON_ID("cpu_clk", &div4_clks[DIV4_I]), 113 CLKDEV_CON_ID("cpu_clk", &div4_clks[DIV4_I]),
114 114
115 /* MSTP32 clocks */ 115 /* MSTP32 clocks */
116 CLKDEV_CON_ID("sdhi0", &mstp_clks[MSTP004]), 116 CLKDEV_DEV_ID("sh_mobile_sdhi.0", &mstp_clks[MSTP004]),
117 CLKDEV_CON_ID("riic0", &mstp_clks[MSTP000]), 117 CLKDEV_CON_ID("riic0", &mstp_clks[MSTP000]),
118 CLKDEV_CON_ID("riic1", &mstp_clks[MSTP000]), 118 CLKDEV_CON_ID("riic1", &mstp_clks[MSTP000]),
119 CLKDEV_CON_ID("riic2", &mstp_clks[MSTP000]), 119 CLKDEV_CON_ID("riic2", &mstp_clks[MSTP000]),
diff --git a/arch/sh/kernel/cpu/shmobile/pm.c b/arch/sh/kernel/cpu/shmobile/pm.c
index a6f95ae4aae7..08d27fac8d08 100644
--- a/arch/sh/kernel/cpu/shmobile/pm.c
+++ b/arch/sh/kernel/cpu/shmobile/pm.c
@@ -16,6 +16,7 @@
16#include <asm/suspend.h> 16#include <asm/suspend.h>
17#include <asm/uaccess.h> 17#include <asm/uaccess.h>
18#include <asm/cacheflush.h> 18#include <asm/cacheflush.h>
19#include <asm/bl_bit.h>
19 20
20/* 21/*
21 * Notifier lists for pre/post sleep notification 22 * Notifier lists for pre/post sleep notification
diff --git a/arch/sh/kernel/dma-nommu.c b/arch/sh/kernel/dma-nommu.c
index 3c55b87f8b63..5b0bfcda6d0b 100644
--- a/arch/sh/kernel/dma-nommu.c
+++ b/arch/sh/kernel/dma-nommu.c
@@ -63,8 +63,8 @@ static void nommu_sync_sg(struct device *dev, struct scatterlist *sg,
63#endif 63#endif
64 64
65struct dma_map_ops nommu_dma_ops = { 65struct dma_map_ops nommu_dma_ops = {
66 .alloc_coherent = dma_generic_alloc_coherent, 66 .alloc = dma_generic_alloc_coherent,
67 .free_coherent = dma_generic_free_coherent, 67 .free = dma_generic_free_coherent,
68 .map_page = nommu_map_page, 68 .map_page = nommu_map_page,
69 .map_sg = nommu_map_sg, 69 .map_sg = nommu_map_sg,
70#ifdef CONFIG_DMA_NONCOHERENT 70#ifdef CONFIG_DMA_NONCOHERENT
diff --git a/arch/sh/kernel/idle.c b/arch/sh/kernel/idle.c
index 64852ecc6881..ee226e20c20c 100644
--- a/arch/sh/kernel/idle.c
+++ b/arch/sh/kernel/idle.c
@@ -17,8 +17,8 @@
17#include <linux/irqflags.h> 17#include <linux/irqflags.h>
18#include <linux/smp.h> 18#include <linux/smp.h>
19#include <linux/cpuidle.h> 19#include <linux/cpuidle.h>
20#include <asm/pgalloc.h>
21#include <linux/atomic.h> 20#include <linux/atomic.h>
21#include <asm/pgalloc.h>
22#include <asm/smp.h> 22#include <asm/smp.h>
23#include <asm/bl_bit.h> 23#include <asm/bl_bit.h>
24 24
diff --git a/arch/sh/kernel/kgdb.c b/arch/sh/kernel/kgdb.c
index efb6d398dec3..b117781bfea2 100644
--- a/arch/sh/kernel/kgdb.c
+++ b/arch/sh/kernel/kgdb.c
@@ -14,6 +14,7 @@
14#include <linux/irq.h> 14#include <linux/irq.h>
15#include <linux/io.h> 15#include <linux/io.h>
16#include <asm/cacheflush.h> 16#include <asm/cacheflush.h>
17#include <asm/traps.h>
17 18
18/* Macros for single step instruction identification */ 19/* Macros for single step instruction identification */
19#define OPCODE_BT(op) (((op) & 0xff00) == 0x8900) 20#define OPCODE_BT(op) (((op) & 0xff00) == 0x8900)
diff --git a/arch/sh/kernel/process_32.c b/arch/sh/kernel/process_32.c
index f72e3a951588..94273aaf78c1 100644
--- a/arch/sh/kernel/process_32.c
+++ b/arch/sh/kernel/process_32.c
@@ -26,6 +26,7 @@
26#include <asm/mmu_context.h> 26#include <asm/mmu_context.h>
27#include <asm/fpu.h> 27#include <asm/fpu.h>
28#include <asm/syscalls.h> 28#include <asm/syscalls.h>
29#include <asm/switch_to.h>
29 30
30void show_regs(struct pt_regs * regs) 31void show_regs(struct pt_regs * regs)
31{ 32{
diff --git a/arch/sh/kernel/smp.c b/arch/sh/kernel/smp.c
index a17a14d32340..eaebdf6a5c77 100644
--- a/arch/sh/kernel/smp.c
+++ b/arch/sh/kernel/smp.c
@@ -27,6 +27,7 @@
27#include <asm/smp.h> 27#include <asm/smp.h>
28#include <asm/cacheflush.h> 28#include <asm/cacheflush.h>
29#include <asm/sections.h> 29#include <asm/sections.h>
30#include <asm/setup.h>
30 31
31int __cpu_number_map[NR_CPUS]; /* Map physical to logical */ 32int __cpu_number_map[NR_CPUS]; /* Map physical to logical */
32int __cpu_logical_map[NR_CPUS]; /* Map logical to physical */ 33int __cpu_logical_map[NR_CPUS]; /* Map logical to physical */
diff --git a/arch/sh/kernel/vsyscall/vsyscall-sigreturn.S b/arch/sh/kernel/vsyscall/vsyscall-sigreturn.S
index 555a64f124ca..23af17584054 100644
--- a/arch/sh/kernel/vsyscall/vsyscall-sigreturn.S
+++ b/arch/sh/kernel/vsyscall/vsyscall-sigreturn.S
@@ -34,6 +34,41 @@ __kernel_rt_sigreturn:
341: .short __NR_rt_sigreturn 341: .short __NR_rt_sigreturn
35.LEND_rt_sigreturn: 35.LEND_rt_sigreturn:
36 .size __kernel_rt_sigreturn,.-.LSTART_rt_sigreturn 36 .size __kernel_rt_sigreturn,.-.LSTART_rt_sigreturn
37 .previous
37 38
38 .section .eh_frame,"a",@progbits 39 .section .eh_frame,"a",@progbits
40.LCIE1:
41 .ualong .LCIE1_end - .LCIE1_start
42.LCIE1_start:
43 .ualong 0 /* CIE ID */
44 .byte 0x1 /* Version number */
45 .string "zRS" /* NUL-terminated augmentation string */
46 .uleb128 0x1 /* Code alignment factor */
47 .sleb128 -4 /* Data alignment factor */
48 .byte 0x11 /* Return address register column */
49 .uleb128 0x1 /* Augmentation length and data */
50 .byte 0x1b /* DW_EH_PE_pcrel | DW_EH_PE_sdata4. */
51 .byte 0xc, 0xf, 0x0 /* DW_CFA_def_cfa: r15 ofs 0 */
52
53 .align 2
54.LCIE1_end:
55
56 .ualong .LFDE0_end-.LFDE0_start /* Length FDE0 */
57.LFDE0_start:
58 .ualong .LFDE0_start-.LCIE1 /* CIE pointer */
59 .ualong .LSTART_sigreturn-. /* PC-relative start address */
60 .ualong .LEND_sigreturn-.LSTART_sigreturn
61 .uleb128 0 /* Augmentation */
62 .align 2
63.LFDE0_end:
64
65 .ualong .LFDE1_end-.LFDE1_start /* Length FDE1 */
66.LFDE1_start:
67 .ualong .LFDE1_start-.LCIE1 /* CIE pointer */
68 .ualong .LSTART_rt_sigreturn-. /* PC-relative start address */
69 .ualong .LEND_rt_sigreturn-.LSTART_rt_sigreturn
70 .uleb128 0 /* Augmentation */
71 .align 2
72.LFDE1_end:
73
39 .previous 74 .previous
diff --git a/arch/sh/kernel/vsyscall/vsyscall-trapa.S b/arch/sh/kernel/vsyscall/vsyscall-trapa.S
index 3e70f851cdc6..0eb74d00690a 100644
--- a/arch/sh/kernel/vsyscall/vsyscall-trapa.S
+++ b/arch/sh/kernel/vsyscall/vsyscall-trapa.S
@@ -3,37 +3,34 @@
3 .type __kernel_vsyscall,@function 3 .type __kernel_vsyscall,@function
4__kernel_vsyscall: 4__kernel_vsyscall:
5.LSTART_vsyscall: 5.LSTART_vsyscall:
6 /* XXX: We'll have to do something here once we opt to use the vDSO 6 trapa #0x10
7 * page for something other than the signal trampoline.. as well as 7 nop
8 * fill out .eh_frame -- PFM. */
9.LEND_vsyscall: 8.LEND_vsyscall:
10 .size __kernel_vsyscall,.-.LSTART_vsyscall 9 .size __kernel_vsyscall,.-.LSTART_vsyscall
10 .previous
11 11
12 .section .eh_frame,"a",@progbits 12 .section .eh_frame,"a",@progbits
13 .previous
14.LCIE: 13.LCIE:
15 .ualong .LCIE_end - .LCIE_start 14 .ualong .LCIE_end - .LCIE_start
16.LCIE_start: 15.LCIE_start:
17 .ualong 0 /* CIE ID */ 16 .ualong 0 /* CIE ID */
18 .byte 0x1 /* Version number */ 17 .byte 0x1 /* Version number */
19 .string "zRS" /* NUL-terminated augmentation string */ 18 .string "zR" /* NUL-terminated augmentation string */
20 .uleb128 0x1 /* Code alignment factor */ 19 .uleb128 0x1 /* Code alignment factor */
21 .sleb128 -4 /* Data alignment factor */ 20 .sleb128 -4 /* Data alignment factor */
22 .byte 0x11 /* Return address register column */ 21 .byte 0x11 /* Return address register column */
23 /* Augmentation length and data (none) */ 22 .uleb128 0x1 /* Augmentation length and data */
24 .byte 0xc /* DW_CFA_def_cfa */ 23 .byte 0x1b /* DW_EH_PE_pcrel | DW_EH_PE_sdata4. */
25 .uleb128 0xf /* r15 */ 24 .byte 0xc,0xf,0x0 /* DW_CFA_def_cfa: r15 ofs 0 */
26 .uleb128 0x0 /* offset 0 */
27
28 .align 2 25 .align 2
29.LCIE_end: 26.LCIE_end:
30 27
31 .ualong .LFDE_end-.LFDE_start /* Length FDE */ 28 .ualong .LFDE_end-.LFDE_start /* Length FDE */
32.LFDE_start: 29.LFDE_start:
33 .ualong .LCIE /* CIE pointer */ 30 .ualong .LFDE_start-.LCIE /* CIE pointer */
34 .ualong .LSTART_vsyscall-. /* start address */ 31 .ualong .LSTART_vsyscall-. /* PC-relative start address */
35 .ualong .LEND_vsyscall-.LSTART_vsyscall 32 .ualong .LEND_vsyscall-.LSTART_vsyscall
36 .uleb128 0 33 .uleb128 0 /* Augmentation */
37 .align 2 34 .align 2
38.LFDE_end: 35.LFDE_end:
39 .previous 36 .previous
diff --git a/arch/sh/mm/cache-sh4.c b/arch/sh/mm/cache-sh4.c
index 112fea12522a..0e529285b28d 100644
--- a/arch/sh/mm/cache-sh4.c
+++ b/arch/sh/mm/cache-sh4.c
@@ -18,6 +18,7 @@
18#include <linux/highmem.h> 18#include <linux/highmem.h>
19#include <asm/pgtable.h> 19#include <asm/pgtable.h>
20#include <asm/mmu_context.h> 20#include <asm/mmu_context.h>
21#include <asm/cache_insns.h>
21#include <asm/cacheflush.h> 22#include <asm/cacheflush.h>
22 23
23/* 24/*
diff --git a/arch/sh/mm/consistent.c b/arch/sh/mm/consistent.c
index f251b5f27652..b81d9dbf9fef 100644
--- a/arch/sh/mm/consistent.c
+++ b/arch/sh/mm/consistent.c
@@ -33,7 +33,8 @@ static int __init dma_init(void)
33fs_initcall(dma_init); 33fs_initcall(dma_init);
34 34
35void *dma_generic_alloc_coherent(struct device *dev, size_t size, 35void *dma_generic_alloc_coherent(struct device *dev, size_t size,
36 dma_addr_t *dma_handle, gfp_t gfp) 36 dma_addr_t *dma_handle, gfp_t gfp,
37 struct dma_attrs *attrs)
37{ 38{
38 void *ret, *ret_nocache; 39 void *ret, *ret_nocache;
39 int order = get_order(size); 40 int order = get_order(size);
@@ -64,7 +65,8 @@ void *dma_generic_alloc_coherent(struct device *dev, size_t size,
64} 65}
65 66
66void dma_generic_free_coherent(struct device *dev, size_t size, 67void dma_generic_free_coherent(struct device *dev, size_t size,
67 void *vaddr, dma_addr_t dma_handle) 68 void *vaddr, dma_addr_t dma_handle,
69 struct dma_attrs *attrs)
68{ 70{
69 int order = get_order(size); 71 int order = get_order(size);
70 unsigned long pfn = dma_handle >> PAGE_SHIFT; 72 unsigned long pfn = dma_handle >> PAGE_SHIFT;
diff --git a/arch/sh/mm/fault_32.c b/arch/sh/mm/fault_32.c
index 324eef93c900..e99b104d967a 100644
--- a/arch/sh/mm/fault_32.c
+++ b/arch/sh/mm/fault_32.c
@@ -86,7 +86,7 @@ static noinline int vmalloc_fault(unsigned long address)
86 pte_t *pte_k; 86 pte_t *pte_k;
87 87
88 /* Make sure we are in vmalloc/module/P3 area: */ 88 /* Make sure we are in vmalloc/module/P3 area: */
89 if (!(address >= VMALLOC_START && address < P3_ADDR_MAX)) 89 if (!(address >= P3SEG && address < P3_ADDR_MAX))
90 return -1; 90 return -1;
91 91
92 /* 92 /*
diff --git a/arch/sh/mm/flush-sh4.c b/arch/sh/mm/flush-sh4.c
index 75a17f5bfa14..0b85dd9dd3a7 100644
--- a/arch/sh/mm/flush-sh4.c
+++ b/arch/sh/mm/flush-sh4.c
@@ -1,5 +1,6 @@
1#include <linux/mm.h> 1#include <linux/mm.h>
2#include <asm/mmu_context.h> 2#include <asm/mmu_context.h>
3#include <asm/cache_insns.h>
3#include <asm/cacheflush.h> 4#include <asm/cacheflush.h>
4#include <asm/traps.h> 5#include <asm/traps.h>
5 6
diff --git a/arch/sh/mm/sram.c b/arch/sh/mm/sram.c
index bc156ec4545e..2d8fa718d55e 100644
--- a/arch/sh/mm/sram.c
+++ b/arch/sh/mm/sram.c
@@ -9,6 +9,7 @@
9 */ 9 */
10#include <linux/init.h> 10#include <linux/init.h>
11#include <linux/kernel.h> 11#include <linux/kernel.h>
12#include <linux/errno.h>
12#include <asm/sram.h> 13#include <asm/sram.h>
13 14
14/* 15/*
diff --git a/arch/sparc/include/asm/dma-mapping.h b/arch/sparc/include/asm/dma-mapping.h
index 8c0e4f7bb204..48a7c65731d2 100644
--- a/arch/sparc/include/asm/dma-mapping.h
+++ b/arch/sparc/include/asm/dma-mapping.h
@@ -26,24 +26,30 @@ static inline struct dma_map_ops *get_dma_ops(struct device *dev)
26 26
27#include <asm-generic/dma-mapping-common.h> 27#include <asm-generic/dma-mapping-common.h>
28 28
29static inline void *dma_alloc_coherent(struct device *dev, size_t size, 29#define dma_alloc_coherent(d,s,h,f) dma_alloc_attrs(d,s,h,f,NULL)
30 dma_addr_t *dma_handle, gfp_t flag) 30
31static inline void *dma_alloc_attrs(struct device *dev, size_t size,
32 dma_addr_t *dma_handle, gfp_t flag,
33 struct dma_attrs *attrs)
31{ 34{
32 struct dma_map_ops *ops = get_dma_ops(dev); 35 struct dma_map_ops *ops = get_dma_ops(dev);
33 void *cpu_addr; 36 void *cpu_addr;
34 37
35 cpu_addr = ops->alloc_coherent(dev, size, dma_handle, flag); 38 cpu_addr = ops->alloc(dev, size, dma_handle, flag, attrs);
36 debug_dma_alloc_coherent(dev, size, *dma_handle, cpu_addr); 39 debug_dma_alloc_coherent(dev, size, *dma_handle, cpu_addr);
37 return cpu_addr; 40 return cpu_addr;
38} 41}
39 42
40static inline void dma_free_coherent(struct device *dev, size_t size, 43#define dma_free_coherent(d,s,c,h) dma_free_attrs(d,s,c,h,NULL)
41 void *cpu_addr, dma_addr_t dma_handle) 44
45static inline void dma_free_attrs(struct device *dev, size_t size,
46 void *cpu_addr, dma_addr_t dma_handle,
47 struct dma_attrs *attrs)
42{ 48{
43 struct dma_map_ops *ops = get_dma_ops(dev); 49 struct dma_map_ops *ops = get_dma_ops(dev);
44 50
45 debug_dma_free_coherent(dev, size, cpu_addr, dma_handle); 51 debug_dma_free_coherent(dev, size, cpu_addr, dma_handle);
46 ops->free_coherent(dev, size, cpu_addr, dma_handle); 52 ops->free(dev, size, cpu_addr, dma_handle, attrs);
47} 53}
48 54
49static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr) 55static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
diff --git a/arch/sparc/include/asm/pgtable_64.h b/arch/sparc/include/asm/pgtable_64.h
index 6fa2f7980e6b..76e4a52aa85e 100644
--- a/arch/sparc/include/asm/pgtable_64.h
+++ b/arch/sparc/include/asm/pgtable_64.h
@@ -12,8 +12,6 @@
12 * the SpitFire page tables. 12 * the SpitFire page tables.
13 */ 13 */
14 14
15#include <asm-generic/pgtable-nopud.h>
16
17#include <linux/compiler.h> 15#include <linux/compiler.h>
18#include <linux/const.h> 16#include <linux/const.h>
19#include <asm/types.h> 17#include <asm/types.h>
@@ -22,6 +20,8 @@
22#include <asm/page.h> 20#include <asm/page.h>
23#include <asm/processor.h> 21#include <asm/processor.h>
24 22
23#include <asm-generic/pgtable-nopud.h>
24
25/* The kernel image occupies 0x4000000 to 0x6000000 (4MB --> 96MB). 25/* The kernel image occupies 0x4000000 to 0x6000000 (4MB --> 96MB).
26 * The page copy blockops can use 0x6000000 to 0x8000000. 26 * The page copy blockops can use 0x6000000 to 0x8000000.
27 * The TSB is mapped in the 0x8000000 to 0xa000000 range. 27 * The TSB is mapped in the 0x8000000 to 0xa000000 range.
diff --git a/arch/sparc/kernel/central.c b/arch/sparc/kernel/central.c
index 38d48a59879c..9708851a8b9f 100644
--- a/arch/sparc/kernel/central.c
+++ b/arch/sparc/kernel/central.c
@@ -269,4 +269,4 @@ static int __init sunfire_init(void)
269 return 0; 269 return 0;
270} 270}
271 271
272subsys_initcall(sunfire_init); 272fs_initcall(sunfire_init);
diff --git a/arch/sparc/kernel/ds.c b/arch/sparc/kernel/ds.c
index fea13c7b1aee..b93c2c9ccb1d 100644
--- a/arch/sparc/kernel/ds.c
+++ b/arch/sparc/kernel/ds.c
@@ -1264,4 +1264,4 @@ static int __init ds_init(void)
1264 return vio_register_driver(&ds_driver); 1264 return vio_register_driver(&ds_driver);
1265} 1265}
1266 1266
1267subsys_initcall(ds_init); 1267fs_initcall(ds_init);
diff --git a/arch/sparc/kernel/iommu.c b/arch/sparc/kernel/iommu.c
index 4643d68713fa..070ed141aac7 100644
--- a/arch/sparc/kernel/iommu.c
+++ b/arch/sparc/kernel/iommu.c
@@ -280,7 +280,8 @@ static inline void iommu_free_ctx(struct iommu *iommu, int ctx)
280} 280}
281 281
282static void *dma_4u_alloc_coherent(struct device *dev, size_t size, 282static void *dma_4u_alloc_coherent(struct device *dev, size_t size,
283 dma_addr_t *dma_addrp, gfp_t gfp) 283 dma_addr_t *dma_addrp, gfp_t gfp,
284 struct dma_attrs *attrs)
284{ 285{
285 unsigned long flags, order, first_page; 286 unsigned long flags, order, first_page;
286 struct iommu *iommu; 287 struct iommu *iommu;
@@ -330,7 +331,8 @@ static void *dma_4u_alloc_coherent(struct device *dev, size_t size,
330} 331}
331 332
332static void dma_4u_free_coherent(struct device *dev, size_t size, 333static void dma_4u_free_coherent(struct device *dev, size_t size,
333 void *cpu, dma_addr_t dvma) 334 void *cpu, dma_addr_t dvma,
335 struct dma_attrs *attrs)
334{ 336{
335 struct iommu *iommu; 337 struct iommu *iommu;
336 unsigned long flags, order, npages; 338 unsigned long flags, order, npages;
@@ -825,8 +827,8 @@ static void dma_4u_sync_sg_for_cpu(struct device *dev,
825} 827}
826 828
827static struct dma_map_ops sun4u_dma_ops = { 829static struct dma_map_ops sun4u_dma_ops = {
828 .alloc_coherent = dma_4u_alloc_coherent, 830 .alloc = dma_4u_alloc_coherent,
829 .free_coherent = dma_4u_free_coherent, 831 .free = dma_4u_free_coherent,
830 .map_page = dma_4u_map_page, 832 .map_page = dma_4u_map_page,
831 .unmap_page = dma_4u_unmap_page, 833 .unmap_page = dma_4u_unmap_page,
832 .map_sg = dma_4u_map_sg, 834 .map_sg = dma_4u_map_sg,
diff --git a/arch/sparc/kernel/ioport.c b/arch/sparc/kernel/ioport.c
index d0479e2163fa..21bd73943f7f 100644
--- a/arch/sparc/kernel/ioport.c
+++ b/arch/sparc/kernel/ioport.c
@@ -261,7 +261,8 @@ EXPORT_SYMBOL(sbus_set_sbus64);
261 * CPU may access them without any explicit flushing. 261 * CPU may access them without any explicit flushing.
262 */ 262 */
263static void *sbus_alloc_coherent(struct device *dev, size_t len, 263static void *sbus_alloc_coherent(struct device *dev, size_t len,
264 dma_addr_t *dma_addrp, gfp_t gfp) 264 dma_addr_t *dma_addrp, gfp_t gfp,
265 struct dma_attrs *attrs)
265{ 266{
266 struct platform_device *op = to_platform_device(dev); 267 struct platform_device *op = to_platform_device(dev);
267 unsigned long len_total = PAGE_ALIGN(len); 268 unsigned long len_total = PAGE_ALIGN(len);
@@ -315,7 +316,7 @@ err_nopages:
315} 316}
316 317
317static void sbus_free_coherent(struct device *dev, size_t n, void *p, 318static void sbus_free_coherent(struct device *dev, size_t n, void *p,
318 dma_addr_t ba) 319 dma_addr_t ba, struct dma_attrs *attrs)
319{ 320{
320 struct resource *res; 321 struct resource *res;
321 struct page *pgv; 322 struct page *pgv;
@@ -407,8 +408,8 @@ static void sbus_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
407} 408}
408 409
409struct dma_map_ops sbus_dma_ops = { 410struct dma_map_ops sbus_dma_ops = {
410 .alloc_coherent = sbus_alloc_coherent, 411 .alloc = sbus_alloc_coherent,
411 .free_coherent = sbus_free_coherent, 412 .free = sbus_free_coherent,
412 .map_page = sbus_map_page, 413 .map_page = sbus_map_page,
413 .unmap_page = sbus_unmap_page, 414 .unmap_page = sbus_unmap_page,
414 .map_sg = sbus_map_sg, 415 .map_sg = sbus_map_sg,
@@ -436,7 +437,8 @@ arch_initcall(sparc_register_ioport);
436 * hwdev should be valid struct pci_dev pointer for PCI devices. 437 * hwdev should be valid struct pci_dev pointer for PCI devices.
437 */ 438 */
438static void *pci32_alloc_coherent(struct device *dev, size_t len, 439static void *pci32_alloc_coherent(struct device *dev, size_t len,
439 dma_addr_t *pba, gfp_t gfp) 440 dma_addr_t *pba, gfp_t gfp,
441 struct dma_attrs *attrs)
440{ 442{
441 unsigned long len_total = PAGE_ALIGN(len); 443 unsigned long len_total = PAGE_ALIGN(len);
442 void *va; 444 void *va;
@@ -489,7 +491,7 @@ err_nopages:
489 * past this call are illegal. 491 * past this call are illegal.
490 */ 492 */
491static void pci32_free_coherent(struct device *dev, size_t n, void *p, 493static void pci32_free_coherent(struct device *dev, size_t n, void *p,
492 dma_addr_t ba) 494 dma_addr_t ba, struct dma_attrs *attrs)
493{ 495{
494 struct resource *res; 496 struct resource *res;
495 497
@@ -645,8 +647,8 @@ static void pci32_sync_sg_for_device(struct device *device, struct scatterlist *
645} 647}
646 648
647struct dma_map_ops pci32_dma_ops = { 649struct dma_map_ops pci32_dma_ops = {
648 .alloc_coherent = pci32_alloc_coherent, 650 .alloc = pci32_alloc_coherent,
649 .free_coherent = pci32_free_coherent, 651 .free = pci32_free_coherent,
650 .map_page = pci32_map_page, 652 .map_page = pci32_map_page,
651 .unmap_page = pci32_unmap_page, 653 .unmap_page = pci32_unmap_page,
652 .map_sg = pci32_map_sg, 654 .map_sg = pci32_map_sg,
diff --git a/arch/sparc/kernel/leon_kernel.c b/arch/sparc/kernel/leon_kernel.c
index a19c8a063683..35e43673c453 100644
--- a/arch/sparc/kernel/leon_kernel.c
+++ b/arch/sparc/kernel/leon_kernel.c
@@ -104,11 +104,11 @@ static int irq_choose_cpu(const struct cpumask *affinity)
104{ 104{
105 cpumask_t mask; 105 cpumask_t mask;
106 106
107 cpus_and(mask, cpu_online_map, *affinity); 107 cpumask_and(&mask, cpu_online_mask, affinity);
108 if (cpus_equal(mask, cpu_online_map) || cpus_empty(mask)) 108 if (cpumask_equal(&mask, cpu_online_mask) || cpumask_empty(&mask))
109 return boot_cpu_id; 109 return boot_cpu_id;
110 else 110 else
111 return first_cpu(mask); 111 return cpumask_first(&mask);
112} 112}
113#else 113#else
114#define irq_choose_cpu(affinity) boot_cpu_id 114#define irq_choose_cpu(affinity) boot_cpu_id
diff --git a/arch/sparc/kernel/leon_pci.c b/arch/sparc/kernel/leon_pci.c
index aba6b958b2a5..19f56058742b 100644
--- a/arch/sparc/kernel/leon_pci.c
+++ b/arch/sparc/kernel/leon_pci.c
@@ -45,7 +45,6 @@ void leon_pci_init(struct platform_device *ofdev, struct leon_pci_info *info)
45 45
46void __devinit pcibios_fixup_bus(struct pci_bus *pbus) 46void __devinit pcibios_fixup_bus(struct pci_bus *pbus)
47{ 47{
48 struct leon_pci_info *info = pbus->sysdata;
49 struct pci_dev *dev; 48 struct pci_dev *dev;
50 int i, has_io, has_mem; 49 int i, has_io, has_mem;
51 u16 cmd; 50 u16 cmd;
@@ -111,18 +110,6 @@ int pcibios_enable_device(struct pci_dev *dev, int mask)
111 return pci_enable_resources(dev, mask); 110 return pci_enable_resources(dev, mask);
112} 111}
113 112
114struct device_node *pci_device_to_OF_node(struct pci_dev *pdev)
115{
116 /*
117 * Currently the OpenBoot nodes are not connected with the PCI device,
118 * this is because the LEON PROM does not create PCI nodes. Eventually
119 * this will change and the same approach as pcic.c can be used to
120 * match PROM nodes with pci devices.
121 */
122 return NULL;
123}
124EXPORT_SYMBOL(pci_device_to_OF_node);
125
126void __devinit pcibios_update_irq(struct pci_dev *dev, int irq) 113void __devinit pcibios_update_irq(struct pci_dev *dev, int irq)
127{ 114{
128#ifdef CONFIG_PCI_DEBUG 115#ifdef CONFIG_PCI_DEBUG
diff --git a/arch/sparc/kernel/leon_smp.c b/arch/sparc/kernel/leon_smp.c
index 1210fde18740..160cac9c4036 100644
--- a/arch/sparc/kernel/leon_smp.c
+++ b/arch/sparc/kernel/leon_smp.c
@@ -23,6 +23,7 @@
23#include <linux/pm.h> 23#include <linux/pm.h>
24#include <linux/delay.h> 24#include <linux/delay.h>
25#include <linux/gfp.h> 25#include <linux/gfp.h>
26#include <linux/cpu.h>
26 27
27#include <asm/cacheflush.h> 28#include <asm/cacheflush.h>
28#include <asm/tlbflush.h> 29#include <asm/tlbflush.h>
@@ -78,6 +79,8 @@ void __cpuinit leon_callin(void)
78 local_flush_tlb_all(); 79 local_flush_tlb_all();
79 leon_configure_cache_smp(); 80 leon_configure_cache_smp();
80 81
82 notify_cpu_starting(cpuid);
83
81 /* Get our local ticker going. */ 84 /* Get our local ticker going. */
82 smp_setup_percpu_timer(); 85 smp_setup_percpu_timer();
83 86
diff --git a/arch/sparc/kernel/pci_sun4v.c b/arch/sparc/kernel/pci_sun4v.c
index af5755d20fbe..7661e84a05a0 100644
--- a/arch/sparc/kernel/pci_sun4v.c
+++ b/arch/sparc/kernel/pci_sun4v.c
@@ -128,7 +128,8 @@ static inline long iommu_batch_end(void)
128} 128}
129 129
130static void *dma_4v_alloc_coherent(struct device *dev, size_t size, 130static void *dma_4v_alloc_coherent(struct device *dev, size_t size,
131 dma_addr_t *dma_addrp, gfp_t gfp) 131 dma_addr_t *dma_addrp, gfp_t gfp,
132 struct dma_attrs *attrs)
132{ 133{
133 unsigned long flags, order, first_page, npages, n; 134 unsigned long flags, order, first_page, npages, n;
134 struct iommu *iommu; 135 struct iommu *iommu;
@@ -198,7 +199,7 @@ range_alloc_fail:
198} 199}
199 200
200static void dma_4v_free_coherent(struct device *dev, size_t size, void *cpu, 201static void dma_4v_free_coherent(struct device *dev, size_t size, void *cpu,
201 dma_addr_t dvma) 202 dma_addr_t dvma, struct dma_attrs *attrs)
202{ 203{
203 struct pci_pbm_info *pbm; 204 struct pci_pbm_info *pbm;
204 struct iommu *iommu; 205 struct iommu *iommu;
@@ -527,8 +528,8 @@ static void dma_4v_unmap_sg(struct device *dev, struct scatterlist *sglist,
527} 528}
528 529
529static struct dma_map_ops sun4v_dma_ops = { 530static struct dma_map_ops sun4v_dma_ops = {
530 .alloc_coherent = dma_4v_alloc_coherent, 531 .alloc = dma_4v_alloc_coherent,
531 .free_coherent = dma_4v_free_coherent, 532 .free = dma_4v_free_coherent,
532 .map_page = dma_4v_map_page, 533 .map_page = dma_4v_map_page,
533 .unmap_page = dma_4v_unmap_page, 534 .unmap_page = dma_4v_unmap_page,
534 .map_sg = dma_4v_map_sg, 535 .map_sg = dma_4v_map_sg,
diff --git a/arch/sparc/kernel/rtrap_64.S b/arch/sparc/kernel/rtrap_64.S
index 77f1b95e0806..9171fc238def 100644
--- a/arch/sparc/kernel/rtrap_64.S
+++ b/arch/sparc/kernel/rtrap_64.S
@@ -20,11 +20,6 @@
20 20
21 .text 21 .text
22 .align 32 22 .align 32
23__handle_softirq:
24 call do_softirq
25 nop
26 ba,a,pt %xcc, __handle_softirq_continue
27 nop
28__handle_preemption: 23__handle_preemption:
29 call schedule 24 call schedule
30 wrpr %g0, RTRAP_PSTATE, %pstate 25 wrpr %g0, RTRAP_PSTATE, %pstate
@@ -89,9 +84,7 @@ rtrap:
89 cmp %l1, 0 84 cmp %l1, 0
90 85
91 /* mm/ultra.S:xcall_report_regs KNOWS about this load. */ 86 /* mm/ultra.S:xcall_report_regs KNOWS about this load. */
92 bne,pn %icc, __handle_softirq
93 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1 87 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
94__handle_softirq_continue:
95rtrap_xcall: 88rtrap_xcall:
96 sethi %hi(0xf << 20), %l4 89 sethi %hi(0xf << 20), %l4
97 and %l1, %l4, %l4 90 and %l1, %l4, %l4
diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
index 232df9949530..3ee51f189a55 100644
--- a/arch/sparc/kernel/sys_sparc_64.c
+++ b/arch/sparc/kernel/sys_sparc_64.c
@@ -566,15 +566,10 @@ out:
566 566
567SYSCALL_DEFINE2(64_munmap, unsigned long, addr, size_t, len) 567SYSCALL_DEFINE2(64_munmap, unsigned long, addr, size_t, len)
568{ 568{
569 long ret;
570
571 if (invalid_64bit_range(addr, len)) 569 if (invalid_64bit_range(addr, len))
572 return -EINVAL; 570 return -EINVAL;
573 571
574 down_write(&current->mm->mmap_sem); 572 return vm_munmap(addr, len);
575 ret = do_munmap(current->mm, addr, len);
576 up_write(&current->mm->mmap_sem);
577 return ret;
578} 573}
579 574
580extern unsigned long do_mremap(unsigned long addr, 575extern unsigned long do_mremap(unsigned long addr,
diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
index 7705c6731e28..df3155a17991 100644
--- a/arch/sparc/mm/fault_32.c
+++ b/arch/sparc/mm/fault_32.c
@@ -225,6 +225,8 @@ asmlinkage void do_sparc_fault(struct pt_regs *regs, int text_fault, int write,
225 unsigned long g2; 225 unsigned long g2;
226 int from_user = !(regs->psr & PSR_PS); 226 int from_user = !(regs->psr & PSR_PS);
227 int fault, code; 227 int fault, code;
228 unsigned int flags = (FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
229 (write ? FAULT_FLAG_WRITE : 0));
228 230
229 if(text_fault) 231 if(text_fault)
230 address = regs->pc; 232 address = regs->pc;
@@ -251,6 +253,7 @@ asmlinkage void do_sparc_fault(struct pt_regs *regs, int text_fault, int write,
251 253
252 perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, address); 254 perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, address);
253 255
256retry:
254 down_read(&mm->mmap_sem); 257 down_read(&mm->mmap_sem);
255 258
256 /* 259 /*
@@ -289,7 +292,11 @@ good_area:
289 * make sure we exit gracefully rather than endlessly redo 292 * make sure we exit gracefully rather than endlessly redo
290 * the fault. 293 * the fault.
291 */ 294 */
292 fault = handle_mm_fault(mm, vma, address, write ? FAULT_FLAG_WRITE : 0); 295 fault = handle_mm_fault(mm, vma, address, flags);
296
297 if ((fault & VM_FAULT_RETRY) && fatal_signal_pending(current))
298 return;
299
293 if (unlikely(fault & VM_FAULT_ERROR)) { 300 if (unlikely(fault & VM_FAULT_ERROR)) {
294 if (fault & VM_FAULT_OOM) 301 if (fault & VM_FAULT_OOM)
295 goto out_of_memory; 302 goto out_of_memory;
@@ -297,13 +304,29 @@ good_area:
297 goto do_sigbus; 304 goto do_sigbus;
298 BUG(); 305 BUG();
299 } 306 }
300 if (fault & VM_FAULT_MAJOR) { 307
301 current->maj_flt++; 308 if (flags & FAULT_FLAG_ALLOW_RETRY) {
302 perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MAJ, 1, regs, address); 309 if (fault & VM_FAULT_MAJOR) {
303 } else { 310 current->maj_flt++;
304 current->min_flt++; 311 perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MAJ,
305 perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MIN, 1, regs, address); 312 1, regs, address);
313 } else {
314 current->min_flt++;
315 perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MIN,
316 1, regs, address);
317 }
318 if (fault & VM_FAULT_RETRY) {
319 flags &= ~FAULT_FLAG_ALLOW_RETRY;
320
321 /* No need to up_read(&mm->mmap_sem) as we would
322 * have already released it in __lock_page_or_retry
323 * in mm/filemap.c.
324 */
325
326 goto retry;
327 }
306 } 328 }
329
307 up_read(&mm->mmap_sem); 330 up_read(&mm->mmap_sem);
308 return; 331 return;
309 332
diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
index 504c0622f729..1fe0429b6314 100644
--- a/arch/sparc/mm/fault_64.c
+++ b/arch/sparc/mm/fault_64.c
@@ -279,6 +279,7 @@ asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
279 unsigned int insn = 0; 279 unsigned int insn = 0;
280 int si_code, fault_code, fault; 280 int si_code, fault_code, fault;
281 unsigned long address, mm_rss; 281 unsigned long address, mm_rss;
282 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE;
282 283
283 fault_code = get_thread_fault_code(); 284 fault_code = get_thread_fault_code();
284 285
@@ -333,6 +334,8 @@ asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
333 insn = get_fault_insn(regs, insn); 334 insn = get_fault_insn(regs, insn);
334 goto handle_kernel_fault; 335 goto handle_kernel_fault;
335 } 336 }
337
338retry:
336 down_read(&mm->mmap_sem); 339 down_read(&mm->mmap_sem);
337 } 340 }
338 341
@@ -423,7 +426,12 @@ good_area:
423 goto bad_area; 426 goto bad_area;
424 } 427 }
425 428
426 fault = handle_mm_fault(mm, vma, address, (fault_code & FAULT_CODE_WRITE) ? FAULT_FLAG_WRITE : 0); 429 flags |= ((fault_code & FAULT_CODE_WRITE) ? FAULT_FLAG_WRITE : 0);
430 fault = handle_mm_fault(mm, vma, address, flags);
431
432 if ((fault & VM_FAULT_RETRY) && fatal_signal_pending(current))
433 return;
434
427 if (unlikely(fault & VM_FAULT_ERROR)) { 435 if (unlikely(fault & VM_FAULT_ERROR)) {
428 if (fault & VM_FAULT_OOM) 436 if (fault & VM_FAULT_OOM)
429 goto out_of_memory; 437 goto out_of_memory;
@@ -431,12 +439,27 @@ good_area:
431 goto do_sigbus; 439 goto do_sigbus;
432 BUG(); 440 BUG();
433 } 441 }
434 if (fault & VM_FAULT_MAJOR) { 442
435 current->maj_flt++; 443 if (flags & FAULT_FLAG_ALLOW_RETRY) {
436 perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MAJ, 1, regs, address); 444 if (fault & VM_FAULT_MAJOR) {
437 } else { 445 current->maj_flt++;
438 current->min_flt++; 446 perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MAJ,
439 perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MIN, 1, regs, address); 447 1, regs, address);
448 } else {
449 current->min_flt++;
450 perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MIN,
451 1, regs, address);
452 }
453 if (fault & VM_FAULT_RETRY) {
454 flags &= ~FAULT_FLAG_ALLOW_RETRY;
455
456 /* No need to up_read(&mm->mmap_sem) as we would
457 * have already released it in __lock_page_or_retry
458 * in mm/filemap.c.
459 */
460
461 goto retry;
462 }
440 } 463 }
441 up_read(&mm->mmap_sem); 464 up_read(&mm->mmap_sem);
442 465
diff --git a/arch/sparc/mm/ultra.S b/arch/sparc/mm/ultra.S
index b57a5942ba64..874162a11ceb 100644
--- a/arch/sparc/mm/ultra.S
+++ b/arch/sparc/mm/ultra.S
@@ -495,11 +495,11 @@ xcall_fetch_glob_regs:
495 stx %o7, [%g1 + GR_SNAP_O7] 495 stx %o7, [%g1 + GR_SNAP_O7]
496 stx %i7, [%g1 + GR_SNAP_I7] 496 stx %i7, [%g1 + GR_SNAP_I7]
497 /* Don't try this at home kids... */ 497 /* Don't try this at home kids... */
498 rdpr %cwp, %g2 498 rdpr %cwp, %g3
499 sub %g2, 1, %g7 499 sub %g3, 1, %g7
500 wrpr %g7, %cwp 500 wrpr %g7, %cwp
501 mov %i7, %g7 501 mov %i7, %g7
502 wrpr %g2, %cwp 502 wrpr %g3, %cwp
503 stx %g7, [%g1 + GR_SNAP_RPC] 503 stx %g7, [%g1 + GR_SNAP_RPC]
504 sethi %hi(trap_block), %g7 504 sethi %hi(trap_block), %g7
505 or %g7, %lo(trap_block), %g7 505 or %g7, %lo(trap_block), %g7
diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
index 11270ca22c0a..96033e2d6845 100644
--- a/arch/tile/Kconfig
+++ b/arch/tile/Kconfig
@@ -12,7 +12,7 @@ config TILE
12 select GENERIC_PENDING_IRQ if SMP 12 select GENERIC_PENDING_IRQ if SMP
13 select GENERIC_IRQ_SHOW 13 select GENERIC_IRQ_SHOW
14 select SYS_HYPERVISOR 14 select SYS_HYPERVISOR
15 select ARCH_HAVE_NMI_SAFE_CMPXCHG if !M386 15 select ARCH_HAVE_NMI_SAFE_CMPXCHG
16 16
17# FIXME: investigate whether we need/want these options. 17# FIXME: investigate whether we need/want these options.
18# select HAVE_IOREMAP_PROT 18# select HAVE_IOREMAP_PROT
@@ -69,6 +69,9 @@ config ARCH_PHYS_ADDR_T_64BIT
69config ARCH_DMA_ADDR_T_64BIT 69config ARCH_DMA_ADDR_T_64BIT
70 def_bool y 70 def_bool y
71 71
72config NEED_DMA_MAP_STATE
73 def_bool y
74
72config LOCKDEP_SUPPORT 75config LOCKDEP_SUPPORT
73 def_bool y 76 def_bool y
74 77
@@ -118,7 +121,7 @@ config 64BIT
118 121
119config ARCH_DEFCONFIG 122config ARCH_DEFCONFIG
120 string 123 string
121 default "arch/tile/configs/tile_defconfig" if !TILEGX 124 default "arch/tile/configs/tilepro_defconfig" if !TILEGX
122 default "arch/tile/configs/tilegx_defconfig" if TILEGX 125 default "arch/tile/configs/tilegx_defconfig" if TILEGX
123 126
124source "init/Kconfig" 127source "init/Kconfig"
@@ -240,6 +243,7 @@ endchoice
240 243
241config PAGE_OFFSET 244config PAGE_OFFSET
242 hex 245 hex
246 depends on !64BIT
243 default 0xF0000000 if VMSPLIT_3_75G 247 default 0xF0000000 if VMSPLIT_3_75G
244 default 0xE0000000 if VMSPLIT_3_5G 248 default 0xE0000000 if VMSPLIT_3_5G
245 default 0xB0000000 if VMSPLIT_2_75G 249 default 0xB0000000 if VMSPLIT_2_75G
diff --git a/arch/tile/Makefile b/arch/tile/Makefile
index 17acce70569b..9520bc5a4b7f 100644
--- a/arch/tile/Makefile
+++ b/arch/tile/Makefile
@@ -30,7 +30,8 @@ ifneq ($(CONFIG_DEBUG_EXTRA_FLAGS),"")
30KBUILD_CFLAGS += $(CONFIG_DEBUG_EXTRA_FLAGS) 30KBUILD_CFLAGS += $(CONFIG_DEBUG_EXTRA_FLAGS)
31endif 31endif
32 32
33LIBGCC_PATH := $(shell $(CC) $(KBUILD_CFLAGS) -print-libgcc-file-name) 33LIBGCC_PATH := \
34 $(shell $(CC) $(KBUILD_CFLAGS) $(KCFLAGS) -print-libgcc-file-name)
34 35
35# Provide the path to use for "make defconfig". 36# Provide the path to use for "make defconfig".
36KBUILD_DEFCONFIG := $(ARCH)_defconfig 37KBUILD_DEFCONFIG := $(ARCH)_defconfig
@@ -53,8 +54,6 @@ libs-y += $(LIBGCC_PATH)
53# See arch/tile/Kbuild for content of core part of the kernel 54# See arch/tile/Kbuild for content of core part of the kernel
54core-y += arch/tile/ 55core-y += arch/tile/
55 56
56core-$(CONFIG_KVM) += arch/tile/kvm/
57
58ifdef TILERA_ROOT 57ifdef TILERA_ROOT
59INSTALL_PATH ?= $(TILERA_ROOT)/tile/boot 58INSTALL_PATH ?= $(TILERA_ROOT)/tile/boot
60endif 59endif
diff --git a/arch/tile/include/arch/spr_def.h b/arch/tile/include/arch/spr_def.h
index f548efeb2de3..d6ba449b5363 100644
--- a/arch/tile/include/arch/spr_def.h
+++ b/arch/tile/include/arch/spr_def.h
@@ -60,8 +60,8 @@
60 _concat4(SPR_IPI_EVENT_, CONFIG_KERNEL_PL,,) 60 _concat4(SPR_IPI_EVENT_, CONFIG_KERNEL_PL,,)
61#define SPR_IPI_EVENT_RESET_K \ 61#define SPR_IPI_EVENT_RESET_K \
62 _concat4(SPR_IPI_EVENT_RESET_, CONFIG_KERNEL_PL,,) 62 _concat4(SPR_IPI_EVENT_RESET_, CONFIG_KERNEL_PL,,)
63#define SPR_IPI_MASK_SET_K \ 63#define SPR_IPI_EVENT_SET_K \
64 _concat4(SPR_IPI_MASK_SET_, CONFIG_KERNEL_PL,,) 64 _concat4(SPR_IPI_EVENT_SET_, CONFIG_KERNEL_PL,,)
65#define INT_IPI_K \ 65#define INT_IPI_K \
66 _concat4(INT_IPI_, CONFIG_KERNEL_PL,,) 66 _concat4(INT_IPI_, CONFIG_KERNEL_PL,,)
67 67
diff --git a/arch/tile/include/asm/atomic.h b/arch/tile/include/asm/atomic.h
index bb696da5d7cd..f2461429a4a4 100644
--- a/arch/tile/include/asm/atomic.h
+++ b/arch/tile/include/asm/atomic.h
@@ -17,6 +17,8 @@
17#ifndef _ASM_TILE_ATOMIC_H 17#ifndef _ASM_TILE_ATOMIC_H
18#define _ASM_TILE_ATOMIC_H 18#define _ASM_TILE_ATOMIC_H
19 19
20#include <asm/cmpxchg.h>
21
20#ifndef __ASSEMBLY__ 22#ifndef __ASSEMBLY__
21 23
22#include <linux/compiler.h> 24#include <linux/compiler.h>
@@ -121,54 +123,6 @@ static inline int atomic_read(const atomic_t *v)
121 */ 123 */
122#define atomic_add_negative(i, v) (atomic_add_return((i), (v)) < 0) 124#define atomic_add_negative(i, v) (atomic_add_return((i), (v)) < 0)
123 125
124/* Nonexistent functions intended to cause link errors. */
125extern unsigned long __xchg_called_with_bad_pointer(void);
126extern unsigned long __cmpxchg_called_with_bad_pointer(void);
127
128#define xchg(ptr, x) \
129 ({ \
130 typeof(*(ptr)) __x; \
131 switch (sizeof(*(ptr))) { \
132 case 4: \
133 __x = (typeof(__x))(typeof(__x-__x))atomic_xchg( \
134 (atomic_t *)(ptr), \
135 (u32)(typeof((x)-(x)))(x)); \
136 break; \
137 case 8: \
138 __x = (typeof(__x))(typeof(__x-__x))atomic64_xchg( \
139 (atomic64_t *)(ptr), \
140 (u64)(typeof((x)-(x)))(x)); \
141 break; \
142 default: \
143 __xchg_called_with_bad_pointer(); \
144 } \
145 __x; \
146 })
147
148#define cmpxchg(ptr, o, n) \
149 ({ \
150 typeof(*(ptr)) __x; \
151 switch (sizeof(*(ptr))) { \
152 case 4: \
153 __x = (typeof(__x))(typeof(__x-__x))atomic_cmpxchg( \
154 (atomic_t *)(ptr), \
155 (u32)(typeof((o)-(o)))(o), \
156 (u32)(typeof((n)-(n)))(n)); \
157 break; \
158 case 8: \
159 __x = (typeof(__x))(typeof(__x-__x))atomic64_cmpxchg( \
160 (atomic64_t *)(ptr), \
161 (u64)(typeof((o)-(o)))(o), \
162 (u64)(typeof((n)-(n)))(n)); \
163 break; \
164 default: \
165 __cmpxchg_called_with_bad_pointer(); \
166 } \
167 __x; \
168 })
169
170#define tas(ptr) (xchg((ptr), 1))
171
172#endif /* __ASSEMBLY__ */ 126#endif /* __ASSEMBLY__ */
173 127
174#ifndef __tilegx__ 128#ifndef __tilegx__
diff --git a/arch/tile/include/asm/atomic_32.h b/arch/tile/include/asm/atomic_32.h
index 466dc4a39a4f..54d1da826f93 100644
--- a/arch/tile/include/asm/atomic_32.h
+++ b/arch/tile/include/asm/atomic_32.h
@@ -200,7 +200,7 @@ static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
200 * @u: ...unless v is equal to u. 200 * @u: ...unless v is equal to u.
201 * 201 *
202 * Atomically adds @a to @v, so long as @v was not already @u. 202 * Atomically adds @a to @v, so long as @v was not already @u.
203 * Returns the old value of @v. 203 * Returns non-zero if @v was not @u, and zero otherwise.
204 */ 204 */
205static inline u64 atomic64_add_unless(atomic64_t *v, u64 a, u64 u) 205static inline u64 atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
206{ 206{
diff --git a/arch/tile/include/asm/bitops_64.h b/arch/tile/include/asm/bitops_64.h
index 58d021a9834f..60b87ee54fb8 100644
--- a/arch/tile/include/asm/bitops_64.h
+++ b/arch/tile/include/asm/bitops_64.h
@@ -38,10 +38,10 @@ static inline void clear_bit(unsigned nr, volatile unsigned long *addr)
38 38
39static inline void change_bit(unsigned nr, volatile unsigned long *addr) 39static inline void change_bit(unsigned nr, volatile unsigned long *addr)
40{ 40{
41 unsigned long old, mask = (1UL << (nr % BITS_PER_LONG)); 41 unsigned long mask = (1UL << (nr % BITS_PER_LONG));
42 long guess, oldval; 42 unsigned long guess, oldval;
43 addr += nr / BITS_PER_LONG; 43 addr += nr / BITS_PER_LONG;
44 old = *addr; 44 oldval = *addr;
45 do { 45 do {
46 guess = oldval; 46 guess = oldval;
47 oldval = atomic64_cmpxchg((atomic64_t *)addr, 47 oldval = atomic64_cmpxchg((atomic64_t *)addr,
@@ -85,7 +85,7 @@ static inline int test_and_change_bit(unsigned nr,
85 volatile unsigned long *addr) 85 volatile unsigned long *addr)
86{ 86{
87 unsigned long mask = (1UL << (nr % BITS_PER_LONG)); 87 unsigned long mask = (1UL << (nr % BITS_PER_LONG));
88 long guess, oldval = *addr; 88 unsigned long guess, oldval;
89 addr += nr / BITS_PER_LONG; 89 addr += nr / BITS_PER_LONG;
90 oldval = *addr; 90 oldval = *addr;
91 do { 91 do {
diff --git a/arch/tile/include/asm/cmpxchg.h b/arch/tile/include/asm/cmpxchg.h
new file mode 100644
index 000000000000..276f067e3640
--- /dev/null
+++ b/arch/tile/include/asm/cmpxchg.h
@@ -0,0 +1,73 @@
1/*
2 * cmpxchg.h -- forked from asm/atomic.h with this copyright:
3 *
4 * Copyright 2010 Tilera Corporation. All Rights Reserved.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation, version 2.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
13 * NON INFRINGEMENT. See the GNU General Public License for
14 * more details.
15 *
16 */
17
18#ifndef _ASM_TILE_CMPXCHG_H
19#define _ASM_TILE_CMPXCHG_H
20
21#ifndef __ASSEMBLY__
22
23/* Nonexistent functions intended to cause link errors. */
24extern unsigned long __xchg_called_with_bad_pointer(void);
25extern unsigned long __cmpxchg_called_with_bad_pointer(void);
26
27#define xchg(ptr, x) \
28 ({ \
29 typeof(*(ptr)) __x; \
30 switch (sizeof(*(ptr))) { \
31 case 4: \
32 __x = (typeof(__x))(typeof(__x-__x))atomic_xchg( \
33 (atomic_t *)(ptr), \
34 (u32)(typeof((x)-(x)))(x)); \
35 break; \
36 case 8: \
37 __x = (typeof(__x))(typeof(__x-__x))atomic64_xchg( \
38 (atomic64_t *)(ptr), \
39 (u64)(typeof((x)-(x)))(x)); \
40 break; \
41 default: \
42 __xchg_called_with_bad_pointer(); \
43 } \
44 __x; \
45 })
46
47#define cmpxchg(ptr, o, n) \
48 ({ \
49 typeof(*(ptr)) __x; \
50 switch (sizeof(*(ptr))) { \
51 case 4: \
52 __x = (typeof(__x))(typeof(__x-__x))atomic_cmpxchg( \
53 (atomic_t *)(ptr), \
54 (u32)(typeof((o)-(o)))(o), \
55 (u32)(typeof((n)-(n)))(n)); \
56 break; \
57 case 8: \
58 __x = (typeof(__x))(typeof(__x-__x))atomic64_cmpxchg( \
59 (atomic64_t *)(ptr), \
60 (u64)(typeof((o)-(o)))(o), \
61 (u64)(typeof((n)-(n)))(n)); \
62 break; \
63 default: \
64 __cmpxchg_called_with_bad_pointer(); \
65 } \
66 __x; \
67 })
68
69#define tas(ptr) (xchg((ptr), 1))
70
71#endif /* __ASSEMBLY__ */
72
73#endif /* _ASM_TILE_CMPXCHG_H */
diff --git a/arch/tile/include/asm/irq.h b/arch/tile/include/asm/irq.h
index f80f8ceabc67..33cff9a3058b 100644
--- a/arch/tile/include/asm/irq.h
+++ b/arch/tile/include/asm/irq.h
@@ -21,7 +21,7 @@
21#define NR_IRQS 32 21#define NR_IRQS 32
22 22
23/* IRQ numbers used for linux IPIs. */ 23/* IRQ numbers used for linux IPIs. */
24#define IRQ_RESCHEDULE 1 24#define IRQ_RESCHEDULE 0
25 25
26#define irq_canonicalize(irq) (irq) 26#define irq_canonicalize(irq) (irq)
27 27
diff --git a/arch/tile/include/asm/pci.h b/arch/tile/include/asm/pci.h
index 5d5a635530bd..32e6cbe8dff3 100644
--- a/arch/tile/include/asm/pci.h
+++ b/arch/tile/include/asm/pci.h
@@ -47,8 +47,8 @@ struct pci_controller {
47 */ 47 */
48#define PCI_DMA_BUS_IS_PHYS 1 48#define PCI_DMA_BUS_IS_PHYS 1
49 49
50int __devinit tile_pci_init(void); 50int __init tile_pci_init(void);
51int __devinit pcibios_init(void); 51int __init pcibios_init(void);
52 52
53static inline void pci_iounmap(struct pci_dev *dev, void __iomem *addr) {} 53static inline void pci_iounmap(struct pci_dev *dev, void __iomem *addr) {}
54 54
diff --git a/arch/tile/include/asm/spinlock_64.h b/arch/tile/include/asm/spinlock_64.h
index 72be5904e020..5f8b6a095fd8 100644
--- a/arch/tile/include/asm/spinlock_64.h
+++ b/arch/tile/include/asm/spinlock_64.h
@@ -137,7 +137,7 @@ static inline void arch_read_unlock(arch_rwlock_t *rw)
137static inline void arch_write_unlock(arch_rwlock_t *rw) 137static inline void arch_write_unlock(arch_rwlock_t *rw)
138{ 138{
139 __insn_mf(); 139 __insn_mf();
140 rw->lock = 0; 140 __insn_exch4(&rw->lock, 0); /* Avoid waiting in the write buffer. */
141} 141}
142 142
143static inline int arch_read_trylock(arch_rwlock_t *rw) 143static inline int arch_read_trylock(arch_rwlock_t *rw)
diff --git a/arch/tile/include/asm/stack.h b/arch/tile/include/asm/stack.h
index 4d97a2db932e..0e9d382a2d45 100644
--- a/arch/tile/include/asm/stack.h
+++ b/arch/tile/include/asm/stack.h
@@ -25,7 +25,6 @@
25struct KBacktraceIterator { 25struct KBacktraceIterator {
26 BacktraceIterator it; 26 BacktraceIterator it;
27 struct task_struct *task; /* task we are backtracing */ 27 struct task_struct *task; /* task we are backtracing */
28 pte_t *pgtable; /* page table for user space access */
29 int end; /* iteration complete. */ 28 int end; /* iteration complete. */
30 int new_context; /* new context is starting */ 29 int new_context; /* new context is starting */
31 int profile; /* profiling, so stop on async intrpt */ 30 int profile; /* profiling, so stop on async intrpt */
diff --git a/arch/tile/include/asm/traps.h b/arch/tile/include/asm/traps.h
index 5f20f920f932..e28c3df4176a 100644
--- a/arch/tile/include/asm/traps.h
+++ b/arch/tile/include/asm/traps.h
@@ -64,7 +64,11 @@ void do_breakpoint(struct pt_regs *, int fault_num);
64 64
65 65
66#ifdef __tilegx__ 66#ifdef __tilegx__
67/* kernel/single_step.c */
67void gx_singlestep_handle(struct pt_regs *, int fault_num); 68void gx_singlestep_handle(struct pt_regs *, int fault_num);
69
70/* kernel/intvec_64.S */
71void fill_ra_stack(void);
68#endif 72#endif
69 73
70#endif /* _ASM_TILE_SYSCALLS_H */ 74#endif /* _ASM_TILE_TRAPS_H */
diff --git a/arch/tile/kernel/entry.S b/arch/tile/kernel/entry.S
index 431e9ae60488..ec91568df880 100644
--- a/arch/tile/kernel/entry.S
+++ b/arch/tile/kernel/entry.S
@@ -85,6 +85,7 @@ STD_ENTRY(cpu_idle_on_new_stack)
85/* Loop forever on a nap during SMP boot. */ 85/* Loop forever on a nap during SMP boot. */
86STD_ENTRY(smp_nap) 86STD_ENTRY(smp_nap)
87 nap 87 nap
88 nop /* avoid provoking the icache prefetch with a jump */
88 j smp_nap /* we are not architecturally guaranteed not to exit nap */ 89 j smp_nap /* we are not architecturally guaranteed not to exit nap */
89 jrp lr /* clue in the backtracer */ 90 jrp lr /* clue in the backtracer */
90 STD_ENDPROC(smp_nap) 91 STD_ENDPROC(smp_nap)
@@ -105,5 +106,6 @@ STD_ENTRY(_cpu_idle)
105 .global _cpu_idle_nap 106 .global _cpu_idle_nap
106_cpu_idle_nap: 107_cpu_idle_nap:
107 nap 108 nap
109 nop /* avoid provoking the icache prefetch with a jump */
108 jrp lr 110 jrp lr
109 STD_ENDPROC(_cpu_idle) 111 STD_ENDPROC(_cpu_idle)
diff --git a/arch/tile/kernel/intvec_32.S b/arch/tile/kernel/intvec_32.S
index aecc8ed5f39b..5d56a1ef5ba5 100644
--- a/arch/tile/kernel/intvec_32.S
+++ b/arch/tile/kernel/intvec_32.S
@@ -799,6 +799,10 @@ handle_interrupt:
799 * This routine takes a boolean in r30 indicating if this is an NMI. 799 * This routine takes a boolean in r30 indicating if this is an NMI.
800 * If so, we also expect a boolean in r31 indicating whether to 800 * If so, we also expect a boolean in r31 indicating whether to
801 * re-enable the oprofile interrupts. 801 * re-enable the oprofile interrupts.
802 *
803 * Note that .Lresume_userspace is jumped to directly in several
804 * places, and we need to make sure r30 is set correctly in those
805 * callers as well.
802 */ 806 */
803STD_ENTRY(interrupt_return) 807STD_ENTRY(interrupt_return)
804 /* If we're resuming to kernel space, don't check thread flags. */ 808 /* If we're resuming to kernel space, don't check thread flags. */
@@ -1237,7 +1241,10 @@ handle_syscall:
1237 bzt r30, 1f 1241 bzt r30, 1f
1238 jal do_syscall_trace 1242 jal do_syscall_trace
1239 FEEDBACK_REENTER(handle_syscall) 1243 FEEDBACK_REENTER(handle_syscall)
12401: j .Lresume_userspace /* jump into middle of interrupt_return */ 12441: {
1245 movei r30, 0 /* not an NMI */
1246 j .Lresume_userspace /* jump into middle of interrupt_return */
1247 }
1241 1248
1242.Linvalid_syscall: 1249.Linvalid_syscall:
1243 /* Report an invalid syscall back to the user program */ 1250 /* Report an invalid syscall back to the user program */
@@ -1246,7 +1253,10 @@ handle_syscall:
1246 movei r28, -ENOSYS 1253 movei r28, -ENOSYS
1247 } 1254 }
1248 sw r29, r28 1255 sw r29, r28
1249 j .Lresume_userspace /* jump into middle of interrupt_return */ 1256 {
1257 movei r30, 0 /* not an NMI */
1258 j .Lresume_userspace /* jump into middle of interrupt_return */
1259 }
1250 STD_ENDPROC(handle_syscall) 1260 STD_ENDPROC(handle_syscall)
1251 1261
1252 /* Return the address for oprofile to suppress in backtraces. */ 1262 /* Return the address for oprofile to suppress in backtraces. */
@@ -1262,7 +1272,10 @@ STD_ENTRY(ret_from_fork)
1262 jal sim_notify_fork 1272 jal sim_notify_fork
1263 jal schedule_tail 1273 jal schedule_tail
1264 FEEDBACK_REENTER(ret_from_fork) 1274 FEEDBACK_REENTER(ret_from_fork)
1265 j .Lresume_userspace /* jump into middle of interrupt_return */ 1275 {
1276 movei r30, 0 /* not an NMI */
1277 j .Lresume_userspace /* jump into middle of interrupt_return */
1278 }
1266 STD_ENDPROC(ret_from_fork) 1279 STD_ENDPROC(ret_from_fork)
1267 1280
1268 /* 1281 /*
@@ -1376,7 +1389,10 @@ handle_ill:
1376 1389
1377 jal send_sigtrap /* issue a SIGTRAP */ 1390 jal send_sigtrap /* issue a SIGTRAP */
1378 FEEDBACK_REENTER(handle_ill) 1391 FEEDBACK_REENTER(handle_ill)
1379 j .Lresume_userspace /* jump into middle of interrupt_return */ 1392 {
1393 movei r30, 0 /* not an NMI */
1394 j .Lresume_userspace /* jump into middle of interrupt_return */
1395 }
1380 1396
1381.Ldispatch_normal_ill: 1397.Ldispatch_normal_ill:
1382 { 1398 {
diff --git a/arch/tile/kernel/intvec_64.S b/arch/tile/kernel/intvec_64.S
index 79c93e10ba27..49d9d6621682 100644
--- a/arch/tile/kernel/intvec_64.S
+++ b/arch/tile/kernel/intvec_64.S
@@ -22,6 +22,7 @@
22#include <asm/irqflags.h> 22#include <asm/irqflags.h>
23#include <asm/asm-offsets.h> 23#include <asm/asm-offsets.h>
24#include <asm/types.h> 24#include <asm/types.h>
25#include <asm/signal.h>
25#include <hv/hypervisor.h> 26#include <hv/hypervisor.h>
26#include <arch/abi.h> 27#include <arch/abi.h>
27#include <arch/interrupts.h> 28#include <arch/interrupts.h>
@@ -605,6 +606,10 @@ handle_interrupt:
605 * This routine takes a boolean in r30 indicating if this is an NMI. 606 * This routine takes a boolean in r30 indicating if this is an NMI.
606 * If so, we also expect a boolean in r31 indicating whether to 607 * If so, we also expect a boolean in r31 indicating whether to
607 * re-enable the oprofile interrupts. 608 * re-enable the oprofile interrupts.
609 *
610 * Note that .Lresume_userspace is jumped to directly in several
611 * places, and we need to make sure r30 is set correctly in those
612 * callers as well.
608 */ 613 */
609STD_ENTRY(interrupt_return) 614STD_ENTRY(interrupt_return)
610 /* If we're resuming to kernel space, don't check thread flags. */ 615 /* If we're resuming to kernel space, don't check thread flags. */
@@ -1039,11 +1044,28 @@ handle_syscall:
1039 1044
1040 /* Do syscall trace again, if requested. */ 1045 /* Do syscall trace again, if requested. */
1041 ld r30, r31 1046 ld r30, r31
1042 andi r30, r30, _TIF_SYSCALL_TRACE 1047 andi r0, r30, _TIF_SYSCALL_TRACE
1043 beqzt r30, 1f 1048 {
1049 andi r0, r30, _TIF_SINGLESTEP
1050 beqzt r0, 1f
1051 }
1044 jal do_syscall_trace 1052 jal do_syscall_trace
1045 FEEDBACK_REENTER(handle_syscall) 1053 FEEDBACK_REENTER(handle_syscall)
10461: j .Lresume_userspace /* jump into middle of interrupt_return */ 1054 andi r0, r30, _TIF_SINGLESTEP
1055
10561: beqzt r0, 2f
1057
1058 /* Single stepping -- notify ptrace. */
1059 {
1060 movei r0, SIGTRAP
1061 jal ptrace_notify
1062 }
1063 FEEDBACK_REENTER(handle_syscall)
1064
10652: {
1066 movei r30, 0 /* not an NMI */
1067 j .Lresume_userspace /* jump into middle of interrupt_return */
1068 }
1047 1069
1048.Lcompat_syscall: 1070.Lcompat_syscall:
1049 /* 1071 /*
@@ -1077,7 +1099,10 @@ handle_syscall:
1077 movei r28, -ENOSYS 1099 movei r28, -ENOSYS
1078 } 1100 }
1079 st r29, r28 1101 st r29, r28
1080 j .Lresume_userspace /* jump into middle of interrupt_return */ 1102 {
1103 movei r30, 0 /* not an NMI */
1104 j .Lresume_userspace /* jump into middle of interrupt_return */
1105 }
1081 STD_ENDPROC(handle_syscall) 1106 STD_ENDPROC(handle_syscall)
1082 1107
1083 /* Return the address for oprofile to suppress in backtraces. */ 1108 /* Return the address for oprofile to suppress in backtraces. */
@@ -1093,7 +1118,10 @@ STD_ENTRY(ret_from_fork)
1093 jal sim_notify_fork 1118 jal sim_notify_fork
1094 jal schedule_tail 1119 jal schedule_tail
1095 FEEDBACK_REENTER(ret_from_fork) 1120 FEEDBACK_REENTER(ret_from_fork)
1096 j .Lresume_userspace 1121 {
1122 movei r30, 0 /* not an NMI */
1123 j .Lresume_userspace /* jump into middle of interrupt_return */
1124 }
1097 STD_ENDPROC(ret_from_fork) 1125 STD_ENDPROC(ret_from_fork)
1098 1126
1099/* Various stub interrupt handlers and syscall handlers */ 1127/* Various stub interrupt handlers and syscall handlers */
@@ -1156,6 +1184,18 @@ int_unalign:
1156 push_extra_callee_saves r0 1184 push_extra_callee_saves r0
1157 j do_trap 1185 j do_trap
1158 1186
1187/* Fill the return address stack with nonzero entries. */
1188STD_ENTRY(fill_ra_stack)
1189 {
1190 move r0, lr
1191 jal 1f
1192 }
11931: jal 2f
11942: jal 3f
11953: jal 4f
11964: jrp r0
1197 STD_ENDPROC(fill_ra_stack)
1198
1159/* Include .intrpt1 array of interrupt vectors */ 1199/* Include .intrpt1 array of interrupt vectors */
1160 .section ".intrpt1", "ax" 1200 .section ".intrpt1", "ax"
1161 1201
@@ -1166,7 +1206,7 @@ int_unalign:
1166#define do_hardwall_trap bad_intr 1206#define do_hardwall_trap bad_intr
1167#endif 1207#endif
1168 1208
1169 int_hand INT_MEM_ERROR, MEM_ERROR, bad_intr 1209 int_hand INT_MEM_ERROR, MEM_ERROR, do_trap
1170 int_hand INT_SINGLE_STEP_3, SINGLE_STEP_3, bad_intr 1210 int_hand INT_SINGLE_STEP_3, SINGLE_STEP_3, bad_intr
1171#if CONFIG_KERNEL_PL == 2 1211#if CONFIG_KERNEL_PL == 2
1172 int_hand INT_SINGLE_STEP_2, SINGLE_STEP_2, gx_singlestep_handle 1212 int_hand INT_SINGLE_STEP_2, SINGLE_STEP_2, gx_singlestep_handle
diff --git a/arch/tile/kernel/module.c b/arch/tile/kernel/module.c
index b90ab9925674..98d476920106 100644
--- a/arch/tile/kernel/module.c
+++ b/arch/tile/kernel/module.c
@@ -67,6 +67,8 @@ void *module_alloc(unsigned long size)
67 area = __get_vm_area(size, VM_ALLOC, MEM_MODULE_START, MEM_MODULE_END); 67 area = __get_vm_area(size, VM_ALLOC, MEM_MODULE_START, MEM_MODULE_END);
68 if (!area) 68 if (!area)
69 goto error; 69 goto error;
70 area->nr_pages = npages;
71 area->pages = pages;
70 72
71 if (map_vm_area(area, prot_rwx, &pages)) { 73 if (map_vm_area(area, prot_rwx, &pages)) {
72 vunmap(area->addr); 74 vunmap(area->addr);
diff --git a/arch/tile/kernel/pci.c b/arch/tile/kernel/pci.c
index a1bb59eecc18..b56d12bf5900 100644
--- a/arch/tile/kernel/pci.c
+++ b/arch/tile/kernel/pci.c
@@ -141,7 +141,7 @@ static int __devinit tile_init_irqs(int controller_id,
141 * 141 *
142 * Returns the number of controllers discovered. 142 * Returns the number of controllers discovered.
143 */ 143 */
144int __devinit tile_pci_init(void) 144int __init tile_pci_init(void)
145{ 145{
146 int i; 146 int i;
147 147
@@ -287,7 +287,7 @@ static void __devinit fixup_read_and_payload_sizes(void)
287 * The controllers have been set up by the time we get here, by a call to 287 * The controllers have been set up by the time we get here, by a call to
288 * tile_pci_init. 288 * tile_pci_init.
289 */ 289 */
290int __devinit pcibios_init(void) 290int __init pcibios_init(void)
291{ 291{
292 int i; 292 int i;
293 293
diff --git a/arch/tile/kernel/proc.c b/arch/tile/kernel/proc.c
index 7a9327046404..446a7f52cc11 100644
--- a/arch/tile/kernel/proc.c
+++ b/arch/tile/kernel/proc.c
@@ -146,7 +146,6 @@ static ctl_table unaligned_table[] = {
146 }, 146 },
147 {} 147 {}
148}; 148};
149#endif
150 149
151static struct ctl_path tile_path[] = { 150static struct ctl_path tile_path[] = {
152 { .procname = "tile" }, 151 { .procname = "tile" },
@@ -155,10 +154,9 @@ static struct ctl_path tile_path[] = {
155 154
156static int __init proc_sys_tile_init(void) 155static int __init proc_sys_tile_init(void)
157{ 156{
158#ifndef __tilegx__ /* FIXME: GX: no support for unaligned access yet */
159 register_sysctl_paths(tile_path, unaligned_table); 157 register_sysctl_paths(tile_path, unaligned_table);
160#endif
161 return 0; 158 return 0;
162} 159}
163 160
164arch_initcall(proc_sys_tile_init); 161arch_initcall(proc_sys_tile_init);
162#endif
diff --git a/arch/tile/kernel/process.c b/arch/tile/kernel/process.c
index 30caecac94dc..2d5ef617bb39 100644
--- a/arch/tile/kernel/process.c
+++ b/arch/tile/kernel/process.c
@@ -28,6 +28,7 @@
28#include <linux/tracehook.h> 28#include <linux/tracehook.h>
29#include <linux/signal.h> 29#include <linux/signal.h>
30#include <asm/stack.h> 30#include <asm/stack.h>
31#include <asm/switch_to.h>
31#include <asm/homecache.h> 32#include <asm/homecache.h>
32#include <asm/syscalls.h> 33#include <asm/syscalls.h>
33#include <asm/traps.h> 34#include <asm/traps.h>
@@ -285,7 +286,7 @@ struct task_struct *validate_current(void)
285 static struct task_struct corrupt = { .comm = "<corrupt>" }; 286 static struct task_struct corrupt = { .comm = "<corrupt>" };
286 struct task_struct *tsk = current; 287 struct task_struct *tsk = current;
287 if (unlikely((unsigned long)tsk < PAGE_OFFSET || 288 if (unlikely((unsigned long)tsk < PAGE_OFFSET ||
288 (void *)tsk > high_memory || 289 (high_memory && (void *)tsk > high_memory) ||
289 ((unsigned long)tsk & (__alignof__(*tsk) - 1)) != 0)) { 290 ((unsigned long)tsk & (__alignof__(*tsk) - 1)) != 0)) {
290 pr_err("Corrupt 'current' %p (sp %#lx)\n", tsk, stack_pointer); 291 pr_err("Corrupt 'current' %p (sp %#lx)\n", tsk, stack_pointer);
291 tsk = &corrupt; 292 tsk = &corrupt;
diff --git a/arch/tile/kernel/setup.c b/arch/tile/kernel/setup.c
index 5f85d8b34dbb..bff23f476110 100644
--- a/arch/tile/kernel/setup.c
+++ b/arch/tile/kernel/setup.c
@@ -103,13 +103,11 @@ unsigned long __initdata pci_reserve_end_pfn = -1U;
103 103
104static int __init setup_maxmem(char *str) 104static int __init setup_maxmem(char *str)
105{ 105{
106 long maxmem_mb; 106 unsigned long long maxmem;
107 if (str == NULL || strict_strtol(str, 0, &maxmem_mb) != 0 || 107 if (str == NULL || (maxmem = memparse(str, NULL)) == 0)
108 maxmem_mb == 0)
109 return -EINVAL; 108 return -EINVAL;
110 109
111 maxmem_pfn = (maxmem_mb >> (HPAGE_SHIFT - 20)) << 110 maxmem_pfn = (maxmem >> HPAGE_SHIFT) << (HPAGE_SHIFT - PAGE_SHIFT);
112 (HPAGE_SHIFT - PAGE_SHIFT);
113 pr_info("Forcing RAM used to no more than %dMB\n", 111 pr_info("Forcing RAM used to no more than %dMB\n",
114 maxmem_pfn >> (20 - PAGE_SHIFT)); 112 maxmem_pfn >> (20 - PAGE_SHIFT));
115 return 0; 113 return 0;
@@ -119,14 +117,15 @@ early_param("maxmem", setup_maxmem);
119static int __init setup_maxnodemem(char *str) 117static int __init setup_maxnodemem(char *str)
120{ 118{
121 char *endp; 119 char *endp;
122 long maxnodemem_mb, node; 120 unsigned long long maxnodemem;
121 long node;
123 122
124 node = str ? simple_strtoul(str, &endp, 0) : INT_MAX; 123 node = str ? simple_strtoul(str, &endp, 0) : INT_MAX;
125 if (node >= MAX_NUMNODES || *endp != ':' || 124 if (node >= MAX_NUMNODES || *endp != ':')
126 strict_strtol(endp+1, 0, &maxnodemem_mb) != 0)
127 return -EINVAL; 125 return -EINVAL;
128 126
129 maxnodemem_pfn[node] = (maxnodemem_mb >> (HPAGE_SHIFT - 20)) << 127 maxnodemem = memparse(endp+1, NULL);
128 maxnodemem_pfn[node] = (maxnodemem >> HPAGE_SHIFT) <<
130 (HPAGE_SHIFT - PAGE_SHIFT); 129 (HPAGE_SHIFT - PAGE_SHIFT);
131 pr_info("Forcing RAM used on node %ld to no more than %dMB\n", 130 pr_info("Forcing RAM used on node %ld to no more than %dMB\n",
132 node, maxnodemem_pfn[node] >> (20 - PAGE_SHIFT)); 131 node, maxnodemem_pfn[node] >> (20 - PAGE_SHIFT));
@@ -913,6 +912,13 @@ void __cpuinit setup_cpu(int boot)
913 912
914#ifdef CONFIG_BLK_DEV_INITRD 913#ifdef CONFIG_BLK_DEV_INITRD
915 914
915/*
916 * Note that the kernel can potentially support other compression
917 * techniques than gz, though we don't do so by default. If we ever
918 * decide to do so we can either look for other filename extensions,
919 * or just allow a file with this name to be compressed with an
920 * arbitrary compressor (somewhat counterintuitively).
921 */
916static int __initdata set_initramfs_file; 922static int __initdata set_initramfs_file;
917static char __initdata initramfs_file[128] = "initramfs.cpio.gz"; 923static char __initdata initramfs_file[128] = "initramfs.cpio.gz";
918 924
@@ -928,9 +934,9 @@ static int __init setup_initramfs_file(char *str)
928early_param("initramfs_file", setup_initramfs_file); 934early_param("initramfs_file", setup_initramfs_file);
929 935
930/* 936/*
931 * We look for an additional "initramfs.cpio.gz" file in the hvfs. 937 * We look for an "initramfs.cpio.gz" file in the hvfs.
932 * If there is one, we allocate some memory for it and it will be 938 * If there is one, we allocate some memory for it and it will be
933 * unpacked to the initramfs after any built-in initramfs_data. 939 * unpacked to the initramfs.
934 */ 940 */
935static void __init load_hv_initrd(void) 941static void __init load_hv_initrd(void)
936{ 942{
@@ -1100,7 +1106,7 @@ EXPORT_SYMBOL(hash_for_home_map);
1100 1106
1101/* 1107/*
1102 * cpu_cacheable_map lists all the cpus whose caches the hypervisor can 1108 * cpu_cacheable_map lists all the cpus whose caches the hypervisor can
1103 * flush on our behalf. It is set to cpu_possible_map OR'ed with 1109 * flush on our behalf. It is set to cpu_possible_mask OR'ed with
1104 * hash_for_home_map, and it is what should be passed to 1110 * hash_for_home_map, and it is what should be passed to
1105 * hv_flush_remote() to flush all caches. Note that if there are 1111 * hv_flush_remote() to flush all caches. Note that if there are
1106 * dedicated hypervisor driver tiles that have authorized use of their 1112 * dedicated hypervisor driver tiles that have authorized use of their
@@ -1186,7 +1192,7 @@ static void __init setup_cpu_maps(void)
1186 sizeof(cpu_lotar_map)); 1192 sizeof(cpu_lotar_map));
1187 if (rc < 0) { 1193 if (rc < 0) {
1188 pr_err("warning: no HV_INQ_TILES_LOTAR; using AVAIL\n"); 1194 pr_err("warning: no HV_INQ_TILES_LOTAR; using AVAIL\n");
1189 cpu_lotar_map = cpu_possible_map; 1195 cpu_lotar_map = *cpu_possible_mask;
1190 } 1196 }
1191 1197
1192#if CHIP_HAS_CBOX_HOME_MAP() 1198#if CHIP_HAS_CBOX_HOME_MAP()
@@ -1196,9 +1202,9 @@ static void __init setup_cpu_maps(void)
1196 sizeof(hash_for_home_map)); 1202 sizeof(hash_for_home_map));
1197 if (rc < 0) 1203 if (rc < 0)
1198 early_panic("hv_inquire_tiles(HFH_CACHE) failed: rc %d\n", rc); 1204 early_panic("hv_inquire_tiles(HFH_CACHE) failed: rc %d\n", rc);
1199 cpumask_or(&cpu_cacheable_map, &cpu_possible_map, &hash_for_home_map); 1205 cpumask_or(&cpu_cacheable_map, cpu_possible_mask, &hash_for_home_map);
1200#else 1206#else
1201 cpu_cacheable_map = cpu_possible_map; 1207 cpu_cacheable_map = *cpu_possible_mask;
1202#endif 1208#endif
1203} 1209}
1204 1210
diff --git a/arch/tile/kernel/single_step.c b/arch/tile/kernel/single_step.c
index bc1eb586e24d..89529c9f0605 100644
--- a/arch/tile/kernel/single_step.c
+++ b/arch/tile/kernel/single_step.c
@@ -153,6 +153,25 @@ static tile_bundle_bits rewrite_load_store_unaligned(
153 if (((unsigned long)addr % size) == 0) 153 if (((unsigned long)addr % size) == 0)
154 return bundle; 154 return bundle;
155 155
156 /*
157 * Return SIGBUS with the unaligned address, if requested.
158 * Note that we return SIGBUS even for completely invalid addresses
159 * as long as they are in fact unaligned; this matches what the
160 * tilepro hardware would be doing, if it could provide us with the
161 * actual bad address in an SPR, which it doesn't.
162 */
163 if (unaligned_fixup == 0) {
164 siginfo_t info = {
165 .si_signo = SIGBUS,
166 .si_code = BUS_ADRALN,
167 .si_addr = addr
168 };
169 trace_unhandled_signal("unaligned trap", regs,
170 (unsigned long)addr, SIGBUS);
171 force_sig_info(info.si_signo, &info, current);
172 return (tilepro_bundle_bits) 0;
173 }
174
156#ifndef __LITTLE_ENDIAN 175#ifndef __LITTLE_ENDIAN
157# error We assume little-endian representation with copy_xx_user size 2 here 176# error We assume little-endian representation with copy_xx_user size 2 here
158#endif 177#endif
@@ -192,18 +211,6 @@ static tile_bundle_bits rewrite_load_store_unaligned(
192 return (tile_bundle_bits) 0; 211 return (tile_bundle_bits) 0;
193 } 212 }
194 213
195 if (unaligned_fixup == 0) {
196 siginfo_t info = {
197 .si_signo = SIGBUS,
198 .si_code = BUS_ADRALN,
199 .si_addr = addr
200 };
201 trace_unhandled_signal("unaligned trap", regs,
202 (unsigned long)addr, SIGBUS);
203 force_sig_info(info.si_signo, &info, current);
204 return (tile_bundle_bits) 0;
205 }
206
207 if (unaligned_printk || unaligned_fixup_count == 0) { 214 if (unaligned_printk || unaligned_fixup_count == 0) {
208 pr_info("Process %d/%s: PC %#lx: Fixup of" 215 pr_info("Process %d/%s: PC %#lx: Fixup of"
209 " unaligned %s at %#lx.\n", 216 " unaligned %s at %#lx.\n",
@@ -339,12 +346,10 @@ void single_step_once(struct pt_regs *regs)
339 } 346 }
340 347
341 /* allocate a cache line of writable, executable memory */ 348 /* allocate a cache line of writable, executable memory */
342 down_write(&current->mm->mmap_sem); 349 buffer = (void __user *) vm_mmap(NULL, 0, 64,
343 buffer = (void __user *) do_mmap(NULL, 0, 64,
344 PROT_EXEC | PROT_READ | PROT_WRITE, 350 PROT_EXEC | PROT_READ | PROT_WRITE,
345 MAP_PRIVATE | MAP_ANONYMOUS, 351 MAP_PRIVATE | MAP_ANONYMOUS,
346 0); 352 0);
347 up_write(&current->mm->mmap_sem);
348 353
349 if (IS_ERR((void __force *)buffer)) { 354 if (IS_ERR((void __force *)buffer)) {
350 kfree(state); 355 kfree(state);
diff --git a/arch/tile/kernel/smp.c b/arch/tile/kernel/smp.c
index a44e103c5a63..91da0f721958 100644
--- a/arch/tile/kernel/smp.c
+++ b/arch/tile/kernel/smp.c
@@ -103,7 +103,7 @@ static void smp_stop_cpu_interrupt(void)
103 set_cpu_online(smp_processor_id(), 0); 103 set_cpu_online(smp_processor_id(), 0);
104 arch_local_irq_disable_all(); 104 arch_local_irq_disable_all();
105 for (;;) 105 for (;;)
106 asm("nap"); 106 asm("nap; nop");
107} 107}
108 108
109/* This function calls the 'stop' function on all other CPUs in the system. */ 109/* This function calls the 'stop' function on all other CPUs in the system. */
@@ -113,6 +113,12 @@ void smp_send_stop(void)
113 send_IPI_allbutself(MSG_TAG_STOP_CPU); 113 send_IPI_allbutself(MSG_TAG_STOP_CPU);
114} 114}
115 115
116/* On panic, just wait; we may get an smp_send_stop() later on. */
117void panic_smp_self_stop(void)
118{
119 while (1)
120 asm("nap; nop");
121}
116 122
117/* 123/*
118 * Dispatch code called from hv_message_intr() for HV_MSG_TILE hv messages. 124 * Dispatch code called from hv_message_intr() for HV_MSG_TILE hv messages.
diff --git a/arch/tile/kernel/smpboot.c b/arch/tile/kernel/smpboot.c
index b949edcec200..172aef7d3159 100644
--- a/arch/tile/kernel/smpboot.c
+++ b/arch/tile/kernel/smpboot.c
@@ -196,6 +196,8 @@ void __cpuinit online_secondary(void)
196 /* This must be done before setting cpu_online_mask */ 196 /* This must be done before setting cpu_online_mask */
197 wmb(); 197 wmb();
198 198
199 notify_cpu_starting(smp_processor_id());
200
199 /* 201 /*
200 * We need to hold call_lock, so there is no inconsistency 202 * We need to hold call_lock, so there is no inconsistency
201 * between the time smp_call_function() determines number of 203 * between the time smp_call_function() determines number of
diff --git a/arch/tile/kernel/stack.c b/arch/tile/kernel/stack.c
index 37ee4d037e0b..b2f44c28dda6 100644
--- a/arch/tile/kernel/stack.c
+++ b/arch/tile/kernel/stack.c
@@ -21,10 +21,12 @@
21#include <linux/stacktrace.h> 21#include <linux/stacktrace.h>
22#include <linux/uaccess.h> 22#include <linux/uaccess.h>
23#include <linux/mmzone.h> 23#include <linux/mmzone.h>
24#include <linux/dcache.h>
25#include <linux/fs.h>
24#include <asm/backtrace.h> 26#include <asm/backtrace.h>
25#include <asm/page.h> 27#include <asm/page.h>
26#include <asm/tlbflush.h>
27#include <asm/ucontext.h> 28#include <asm/ucontext.h>
29#include <asm/switch_to.h>
28#include <asm/sigframe.h> 30#include <asm/sigframe.h>
29#include <asm/stack.h> 31#include <asm/stack.h>
30#include <arch/abi.h> 32#include <arch/abi.h>
@@ -44,72 +46,23 @@ static int in_kernel_stack(struct KBacktraceIterator *kbt, unsigned long sp)
44 return sp >= kstack_base && sp < kstack_base + THREAD_SIZE; 46 return sp >= kstack_base && sp < kstack_base + THREAD_SIZE;
45} 47}
46 48
47/* Is address valid for reading? */
48static int valid_address(struct KBacktraceIterator *kbt, unsigned long address)
49{
50 HV_PTE *l1_pgtable = kbt->pgtable;
51 HV_PTE *l2_pgtable;
52 unsigned long pfn;
53 HV_PTE pte;
54 struct page *page;
55
56 if (l1_pgtable == NULL)
57 return 0; /* can't read user space in other tasks */
58
59#ifdef CONFIG_64BIT
60 /* Find the real l1_pgtable by looking in the l0_pgtable. */
61 pte = l1_pgtable[HV_L0_INDEX(address)];
62 if (!hv_pte_get_present(pte))
63 return 0;
64 pfn = hv_pte_get_pfn(pte);
65 if (pte_huge(pte)) {
66 if (!pfn_valid(pfn)) {
67 pr_err("L0 huge page has bad pfn %#lx\n", pfn);
68 return 0;
69 }
70 return hv_pte_get_present(pte) && hv_pte_get_readable(pte);
71 }
72 page = pfn_to_page(pfn);
73 BUG_ON(PageHighMem(page)); /* No HIGHMEM on 64-bit. */
74 l1_pgtable = (HV_PTE *)pfn_to_kaddr(pfn);
75#endif
76 pte = l1_pgtable[HV_L1_INDEX(address)];
77 if (!hv_pte_get_present(pte))
78 return 0;
79 pfn = hv_pte_get_pfn(pte);
80 if (pte_huge(pte)) {
81 if (!pfn_valid(pfn)) {
82 pr_err("huge page has bad pfn %#lx\n", pfn);
83 return 0;
84 }
85 return hv_pte_get_present(pte) && hv_pte_get_readable(pte);
86 }
87
88 page = pfn_to_page(pfn);
89 if (PageHighMem(page)) {
90 pr_err("L2 page table not in LOWMEM (%#llx)\n",
91 HV_PFN_TO_CPA(pfn));
92 return 0;
93 }
94 l2_pgtable = (HV_PTE *)pfn_to_kaddr(pfn);
95 pte = l2_pgtable[HV_L2_INDEX(address)];
96 return hv_pte_get_present(pte) && hv_pte_get_readable(pte);
97}
98
99/* Callback for backtracer; basically a glorified memcpy */ 49/* Callback for backtracer; basically a glorified memcpy */
100static bool read_memory_func(void *result, unsigned long address, 50static bool read_memory_func(void *result, unsigned long address,
101 unsigned int size, void *vkbt) 51 unsigned int size, void *vkbt)
102{ 52{
103 int retval; 53 int retval;
104 struct KBacktraceIterator *kbt = (struct KBacktraceIterator *)vkbt; 54 struct KBacktraceIterator *kbt = (struct KBacktraceIterator *)vkbt;
55
56 if (address == 0)
57 return 0;
105 if (__kernel_text_address(address)) { 58 if (__kernel_text_address(address)) {
106 /* OK to read kernel code. */ 59 /* OK to read kernel code. */
107 } else if (address >= PAGE_OFFSET) { 60 } else if (address >= PAGE_OFFSET) {
108 /* We only tolerate kernel-space reads of this task's stack */ 61 /* We only tolerate kernel-space reads of this task's stack */
109 if (!in_kernel_stack(kbt, address)) 62 if (!in_kernel_stack(kbt, address))
110 return 0; 63 return 0;
111 } else if (!valid_address(kbt, address)) { 64 } else if (!kbt->is_current) {
112 return 0; /* invalid user-space address */ 65 return 0; /* can't read from other user address spaces */
113 } 66 }
114 pagefault_disable(); 67 pagefault_disable();
115 retval = __copy_from_user_inatomic(result, 68 retval = __copy_from_user_inatomic(result,
@@ -127,6 +80,8 @@ static struct pt_regs *valid_fault_handler(struct KBacktraceIterator* kbt)
127 unsigned long sp = kbt->it.sp; 80 unsigned long sp = kbt->it.sp;
128 struct pt_regs *p; 81 struct pt_regs *p;
129 82
83 if (sp % sizeof(long) != 0)
84 return NULL;
130 if (!in_kernel_stack(kbt, sp)) 85 if (!in_kernel_stack(kbt, sp))
131 return NULL; 86 return NULL;
132 if (!in_kernel_stack(kbt, sp + C_ABI_SAVE_AREA_SIZE + PTREGS_SIZE-1)) 87 if (!in_kernel_stack(kbt, sp + C_ABI_SAVE_AREA_SIZE + PTREGS_SIZE-1))
@@ -169,27 +124,27 @@ static int is_sigreturn(unsigned long pc)
169} 124}
170 125
171/* Return a pt_regs pointer for a valid signal handler frame */ 126/* Return a pt_regs pointer for a valid signal handler frame */
172static struct pt_regs *valid_sigframe(struct KBacktraceIterator* kbt) 127static struct pt_regs *valid_sigframe(struct KBacktraceIterator* kbt,
128 struct rt_sigframe* kframe)
173{ 129{
174 BacktraceIterator *b = &kbt->it; 130 BacktraceIterator *b = &kbt->it;
175 131
176 if (b->pc == VDSO_BASE) { 132 if (b->pc == VDSO_BASE && b->sp < PAGE_OFFSET &&
177 struct rt_sigframe *frame; 133 b->sp % sizeof(long) == 0) {
178 unsigned long sigframe_top = 134 int retval;
179 b->sp + sizeof(struct rt_sigframe) - 1; 135 pagefault_disable();
180 if (!valid_address(kbt, b->sp) || 136 retval = __copy_from_user_inatomic(
181 !valid_address(kbt, sigframe_top)) { 137 kframe, (void __user __force *)b->sp,
182 if (kbt->verbose) 138 sizeof(*kframe));
183 pr_err(" (odd signal: sp %#lx?)\n", 139 pagefault_enable();
184 (unsigned long)(b->sp)); 140 if (retval != 0 ||
141 (unsigned int)(kframe->info.si_signo) >= _NSIG)
185 return NULL; 142 return NULL;
186 }
187 frame = (struct rt_sigframe *)b->sp;
188 if (kbt->verbose) { 143 if (kbt->verbose) {
189 pr_err(" <received signal %d>\n", 144 pr_err(" <received signal %d>\n",
190 frame->info.si_signo); 145 kframe->info.si_signo);
191 } 146 }
192 return (struct pt_regs *)&frame->uc.uc_mcontext; 147 return (struct pt_regs *)&kframe->uc.uc_mcontext;
193 } 148 }
194 return NULL; 149 return NULL;
195} 150}
@@ -202,10 +157,11 @@ static int KBacktraceIterator_is_sigreturn(struct KBacktraceIterator *kbt)
202static int KBacktraceIterator_restart(struct KBacktraceIterator *kbt) 157static int KBacktraceIterator_restart(struct KBacktraceIterator *kbt)
203{ 158{
204 struct pt_regs *p; 159 struct pt_regs *p;
160 struct rt_sigframe kframe;
205 161
206 p = valid_fault_handler(kbt); 162 p = valid_fault_handler(kbt);
207 if (p == NULL) 163 if (p == NULL)
208 p = valid_sigframe(kbt); 164 p = valid_sigframe(kbt, &kframe);
209 if (p == NULL) 165 if (p == NULL)
210 return 0; 166 return 0;
211 backtrace_init(&kbt->it, read_memory_func, kbt, 167 backtrace_init(&kbt->it, read_memory_func, kbt,
@@ -265,41 +221,19 @@ void KBacktraceIterator_init(struct KBacktraceIterator *kbt,
265 221
266 /* 222 /*
267 * Set up callback information. We grab the kernel stack base 223 * Set up callback information. We grab the kernel stack base
268 * so we will allow reads of that address range, and if we're 224 * so we will allow reads of that address range.
269 * asking about the current process we grab the page table
270 * so we can check user accesses before trying to read them.
271 * We flush the TLB to avoid any weird skew issues.
272 */ 225 */
273 is_current = (t == NULL); 226 is_current = (t == NULL || t == current);
274 kbt->is_current = is_current; 227 kbt->is_current = is_current;
275 if (is_current) 228 if (is_current)
276 t = validate_current(); 229 t = validate_current();
277 kbt->task = t; 230 kbt->task = t;
278 kbt->pgtable = NULL;
279 kbt->verbose = 0; /* override in caller if desired */ 231 kbt->verbose = 0; /* override in caller if desired */
280 kbt->profile = 0; /* override in caller if desired */ 232 kbt->profile = 0; /* override in caller if desired */
281 kbt->end = KBT_ONGOING; 233 kbt->end = KBT_ONGOING;
282 kbt->new_context = 0; 234 kbt->new_context = 1;
283 if (is_current) { 235 if (is_current)
284 HV_PhysAddr pgdir_pa = hv_inquire_context().page_table;
285 if (pgdir_pa == (unsigned long)swapper_pg_dir - PAGE_OFFSET) {
286 /*
287 * Not just an optimization: this also allows
288 * this to work at all before va/pa mappings
289 * are set up.
290 */
291 kbt->pgtable = swapper_pg_dir;
292 } else {
293 struct page *page = pfn_to_page(PFN_DOWN(pgdir_pa));
294 if (!PageHighMem(page))
295 kbt->pgtable = __va(pgdir_pa);
296 else
297 pr_err("page table not in LOWMEM"
298 " (%#llx)\n", pgdir_pa);
299 }
300 local_flush_tlb_all();
301 validate_stack(regs); 236 validate_stack(regs);
302 }
303 237
304 if (regs == NULL) { 238 if (regs == NULL) {
305 if (is_current || t->state == TASK_RUNNING) { 239 if (is_current || t->state == TASK_RUNNING) {
@@ -345,6 +279,78 @@ void KBacktraceIterator_next(struct KBacktraceIterator *kbt)
345} 279}
346EXPORT_SYMBOL(KBacktraceIterator_next); 280EXPORT_SYMBOL(KBacktraceIterator_next);
347 281
282static void describe_addr(struct KBacktraceIterator *kbt,
283 unsigned long address,
284 int have_mmap_sem, char *buf, size_t bufsize)
285{
286 struct vm_area_struct *vma;
287 size_t namelen, remaining;
288 unsigned long size, offset, adjust;
289 char *p, *modname;
290 const char *name;
291 int rc;
292
293 /*
294 * Look one byte back for every caller frame (i.e. those that
295 * aren't a new context) so we look up symbol data for the
296 * call itself, not the following instruction, which may be on
297 * a different line (or in a different function).
298 */
299 adjust = !kbt->new_context;
300 address -= adjust;
301
302 if (address >= PAGE_OFFSET) {
303 /* Handle kernel symbols. */
304 BUG_ON(bufsize < KSYM_NAME_LEN);
305 name = kallsyms_lookup(address, &size, &offset,
306 &modname, buf);
307 if (name == NULL) {
308 buf[0] = '\0';
309 return;
310 }
311 namelen = strlen(buf);
312 remaining = (bufsize - 1) - namelen;
313 p = buf + namelen;
314 rc = snprintf(p, remaining, "+%#lx/%#lx ",
315 offset + adjust, size);
316 if (modname && rc < remaining)
317 snprintf(p + rc, remaining - rc, "[%s] ", modname);
318 buf[bufsize-1] = '\0';
319 return;
320 }
321
322 /* If we don't have the mmap_sem, we can't show any more info. */
323 buf[0] = '\0';
324 if (!have_mmap_sem)
325 return;
326
327 /* Find vma info. */
328 vma = find_vma(kbt->task->mm, address);
329 if (vma == NULL || address < vma->vm_start) {
330 snprintf(buf, bufsize, "[unmapped address] ");
331 return;
332 }
333
334 if (vma->vm_file) {
335 char *s;
336 p = d_path(&vma->vm_file->f_path, buf, bufsize);
337 if (IS_ERR(p))
338 p = "?";
339 s = strrchr(p, '/');
340 if (s)
341 p = s+1;
342 } else {
343 p = "anon";
344 }
345
346 /* Generate a string description of the vma info. */
347 namelen = strlen(p);
348 remaining = (bufsize - 1) - namelen;
349 memmove(buf, p, namelen);
350 snprintf(buf + namelen, remaining, "[%lx+%lx] ",
351 vma->vm_start, vma->vm_end - vma->vm_start);
352}
353
348/* 354/*
349 * This method wraps the backtracer's more generic support. 355 * This method wraps the backtracer's more generic support.
350 * It is only invoked from the architecture-specific code; show_stack() 356 * It is only invoked from the architecture-specific code; show_stack()
@@ -353,6 +359,7 @@ EXPORT_SYMBOL(KBacktraceIterator_next);
353void tile_show_stack(struct KBacktraceIterator *kbt, int headers) 359void tile_show_stack(struct KBacktraceIterator *kbt, int headers)
354{ 360{
355 int i; 361 int i;
362 int have_mmap_sem = 0;
356 363
357 if (headers) { 364 if (headers) {
358 /* 365 /*
@@ -369,31 +376,16 @@ void tile_show_stack(struct KBacktraceIterator *kbt, int headers)
369 kbt->verbose = 1; 376 kbt->verbose = 1;
370 i = 0; 377 i = 0;
371 for (; !KBacktraceIterator_end(kbt); KBacktraceIterator_next(kbt)) { 378 for (; !KBacktraceIterator_end(kbt); KBacktraceIterator_next(kbt)) {
372 char *modname;
373 const char *name;
374 unsigned long address = kbt->it.pc;
375 unsigned long offset, size;
376 char namebuf[KSYM_NAME_LEN+100]; 379 char namebuf[KSYM_NAME_LEN+100];
380 unsigned long address = kbt->it.pc;
377 381
378 if (address >= PAGE_OFFSET) 382 /* Try to acquire the mmap_sem as we pass into userspace. */
379 name = kallsyms_lookup(address, &size, &offset, 383 if (address < PAGE_OFFSET && !have_mmap_sem && kbt->task->mm)
380 &modname, namebuf); 384 have_mmap_sem =
381 else 385 down_read_trylock(&kbt->task->mm->mmap_sem);
382 name = NULL; 386
383 387 describe_addr(kbt, address, have_mmap_sem,
384 if (!name) 388 namebuf, sizeof(namebuf));
385 namebuf[0] = '\0';
386 else {
387 size_t namelen = strlen(namebuf);
388 size_t remaining = (sizeof(namebuf) - 1) - namelen;
389 char *p = namebuf + namelen;
390 int rc = snprintf(p, remaining, "+%#lx/%#lx ",
391 offset, size);
392 if (modname && rc < remaining)
393 snprintf(p + rc, remaining - rc,
394 "[%s] ", modname);
395 namebuf[sizeof(namebuf)-1] = '\0';
396 }
397 389
398 pr_err(" frame %d: 0x%lx %s(sp 0x%lx)\n", 390 pr_err(" frame %d: 0x%lx %s(sp 0x%lx)\n",
399 i++, address, namebuf, (unsigned long)(kbt->it.sp)); 391 i++, address, namebuf, (unsigned long)(kbt->it.sp));
@@ -408,6 +400,8 @@ void tile_show_stack(struct KBacktraceIterator *kbt, int headers)
408 pr_err("Stack dump stopped; next frame identical to this one\n"); 400 pr_err("Stack dump stopped; next frame identical to this one\n");
409 if (headers) 401 if (headers)
410 pr_err("Stack dump complete\n"); 402 pr_err("Stack dump complete\n");
403 if (have_mmap_sem)
404 up_read(&kbt->task->mm->mmap_sem);
411} 405}
412EXPORT_SYMBOL(tile_show_stack); 406EXPORT_SYMBOL(tile_show_stack);
413 407
diff --git a/arch/tile/kernel/traps.c b/arch/tile/kernel/traps.c
index 2bb6602a1ee7..73cff814ac57 100644
--- a/arch/tile/kernel/traps.c
+++ b/arch/tile/kernel/traps.c
@@ -200,7 +200,7 @@ void __kprobes do_trap(struct pt_regs *regs, int fault_num,
200{ 200{
201 siginfo_t info = { 0 }; 201 siginfo_t info = { 0 };
202 int signo, code; 202 int signo, code;
203 unsigned long address; 203 unsigned long address = 0;
204 bundle_bits instr; 204 bundle_bits instr;
205 205
206 /* Re-enable interrupts. */ 206 /* Re-enable interrupts. */
@@ -223,6 +223,10 @@ void __kprobes do_trap(struct pt_regs *regs, int fault_num,
223 } 223 }
224 224
225 switch (fault_num) { 225 switch (fault_num) {
226 case INT_MEM_ERROR:
227 signo = SIGBUS;
228 code = BUS_OBJERR;
229 break;
226 case INT_ILL: 230 case INT_ILL:
227 if (copy_from_user(&instr, (void __user *)regs->pc, 231 if (copy_from_user(&instr, (void __user *)regs->pc,
228 sizeof(instr))) { 232 sizeof(instr))) {
@@ -289,7 +293,10 @@ void __kprobes do_trap(struct pt_regs *regs, int fault_num,
289 address = regs->pc; 293 address = regs->pc;
290 break; 294 break;
291#ifdef __tilegx__ 295#ifdef __tilegx__
292 case INT_ILL_TRANS: 296 case INT_ILL_TRANS: {
297 /* Avoid a hardware erratum with the return address stack. */
298 fill_ra_stack();
299
293 signo = SIGSEGV; 300 signo = SIGSEGV;
294 code = SEGV_MAPERR; 301 code = SEGV_MAPERR;
295 if (reason & SPR_ILL_TRANS_REASON__I_STREAM_VA_RMASK) 302 if (reason & SPR_ILL_TRANS_REASON__I_STREAM_VA_RMASK)
@@ -297,6 +304,7 @@ void __kprobes do_trap(struct pt_regs *regs, int fault_num,
297 else 304 else
298 address = 0; /* FIXME: GX: single-step for address */ 305 address = 0; /* FIXME: GX: single-step for address */
299 break; 306 break;
307 }
300#endif 308#endif
301 default: 309 default:
302 panic("Unexpected do_trap interrupt number %d", fault_num); 310 panic("Unexpected do_trap interrupt number %d", fault_num);
@@ -308,7 +316,8 @@ void __kprobes do_trap(struct pt_regs *regs, int fault_num,
308 info.si_addr = (void __user *)address; 316 info.si_addr = (void __user *)address;
309 if (signo == SIGILL) 317 if (signo == SIGILL)
310 info.si_trapno = fault_num; 318 info.si_trapno = fault_num;
311 trace_unhandled_signal("trap", regs, address, signo); 319 if (signo != SIGTRAP)
320 trace_unhandled_signal("trap", regs, address, signo);
312 force_sig_info(signo, &info, current); 321 force_sig_info(signo, &info, current);
313} 322}
314 323
diff --git a/arch/tile/lib/Makefile b/arch/tile/lib/Makefile
index 0c26086ecbef..985f59858234 100644
--- a/arch/tile/lib/Makefile
+++ b/arch/tile/lib/Makefile
@@ -7,6 +7,7 @@ lib-y = cacheflush.o checksum.o cpumask.o delay.o uaccess.o \
7 strchr_$(BITS).o strlen_$(BITS).o 7 strchr_$(BITS).o strlen_$(BITS).o
8 8
9ifeq ($(CONFIG_TILEGX),y) 9ifeq ($(CONFIG_TILEGX),y)
10CFLAGS_REMOVE_memcpy_user_64.o = -fno-omit-frame-pointer
10lib-y += memcpy_user_64.o 11lib-y += memcpy_user_64.o
11else 12else
12lib-y += atomic_32.o atomic_asm_32.o memcpy_tile64.o 13lib-y += atomic_32.o atomic_asm_32.o memcpy_tile64.o
diff --git a/arch/tile/lib/cacheflush.c b/arch/tile/lib/cacheflush.c
index 8928aace7a64..db4fb89e12d8 100644
--- a/arch/tile/lib/cacheflush.c
+++ b/arch/tile/lib/cacheflush.c
@@ -39,7 +39,21 @@ void finv_buffer_remote(void *buffer, size_t size, int hfh)
39{ 39{
40 char *p, *base; 40 char *p, *base;
41 size_t step_size, load_count; 41 size_t step_size, load_count;
42
43 /*
44 * On TILEPro the striping granularity is a fixed 8KB; on
45 * TILE-Gx it is configurable, and we rely on the fact that
46 * the hypervisor always configures maximum striping, so that
47 * bits 9 and 10 of the PA are part of the stripe function, so
48 * every 512 bytes we hit a striping boundary.
49 *
50 */
51#ifdef __tilegx__
52 const unsigned long STRIPE_WIDTH = 512;
53#else
42 const unsigned long STRIPE_WIDTH = 8192; 54 const unsigned long STRIPE_WIDTH = 8192;
55#endif
56
43#ifdef __tilegx__ 57#ifdef __tilegx__
44 /* 58 /*
45 * On TILE-Gx, we must disable the dstream prefetcher before doing 59 * On TILE-Gx, we must disable the dstream prefetcher before doing
@@ -74,7 +88,7 @@ void finv_buffer_remote(void *buffer, size_t size, int hfh)
74 * memory, that one load would be sufficient, but since we may 88 * memory, that one load would be sufficient, but since we may
75 * be, we also need to back up to the last load issued to 89 * be, we also need to back up to the last load issued to
76 * another memory controller, which would be the point where 90 * another memory controller, which would be the point where
77 * we crossed an 8KB boundary (the granularity of striping 91 * we crossed a "striping" boundary (the granularity of striping
78 * across memory controllers). Keep backing up and doing this 92 * across memory controllers). Keep backing up and doing this
79 * until we are before the beginning of the buffer, or have 93 * until we are before the beginning of the buffer, or have
80 * hit all the controllers. 94 * hit all the controllers.
@@ -88,12 +102,22 @@ void finv_buffer_remote(void *buffer, size_t size, int hfh)
88 * every cache line on a full memory stripe on each 102 * every cache line on a full memory stripe on each
89 * controller" that we simply do that, to simplify the logic. 103 * controller" that we simply do that, to simplify the logic.
90 * 104 *
91 * FIXME: See bug 9535 for some issues with this code. 105 * On TILE-Gx the hash-for-home function is much more complex,
106 * with the upshot being we can't readily guarantee we have
107 * hit both entries in the 128-entry AMT that were hit by any
108 * load in the entire range, so we just re-load them all.
109 * With larger buffers, we may want to consider using a hypervisor
110 * trap to issue loads directly to each hash-for-home tile for
111 * each controller (doing it from Linux would trash the TLB).
92 */ 112 */
93 if (hfh) { 113 if (hfh) {
94 step_size = L2_CACHE_BYTES; 114 step_size = L2_CACHE_BYTES;
115#ifdef __tilegx__
116 load_count = (size + L2_CACHE_BYTES - 1) / L2_CACHE_BYTES;
117#else
95 load_count = (STRIPE_WIDTH / L2_CACHE_BYTES) * 118 load_count = (STRIPE_WIDTH / L2_CACHE_BYTES) *
96 (1 << CHIP_LOG_NUM_MSHIMS()); 119 (1 << CHIP_LOG_NUM_MSHIMS());
120#endif
97 } else { 121 } else {
98 step_size = STRIPE_WIDTH; 122 step_size = STRIPE_WIDTH;
99 load_count = (1 << CHIP_LOG_NUM_MSHIMS()); 123 load_count = (1 << CHIP_LOG_NUM_MSHIMS());
@@ -109,7 +133,7 @@ void finv_buffer_remote(void *buffer, size_t size, int hfh)
109 133
110 /* Figure out how far back we need to go. */ 134 /* Figure out how far back we need to go. */
111 base = p - (step_size * (load_count - 2)); 135 base = p - (step_size * (load_count - 2));
112 if ((long)base < (long)buffer) 136 if ((unsigned long)base < (unsigned long)buffer)
113 base = buffer; 137 base = buffer;
114 138
115 /* 139 /*
diff --git a/arch/tile/lib/memcpy_user_64.c b/arch/tile/lib/memcpy_user_64.c
index 4763b3aff1cc..37440caa7370 100644
--- a/arch/tile/lib/memcpy_user_64.c
+++ b/arch/tile/lib/memcpy_user_64.c
@@ -14,7 +14,13 @@
14 * Do memcpy(), but trap and return "n" when a load or store faults. 14 * Do memcpy(), but trap and return "n" when a load or store faults.
15 * 15 *
16 * Note: this idiom only works when memcpy() compiles to a leaf function. 16 * Note: this idiom only works when memcpy() compiles to a leaf function.
17 * If "sp" is updated during memcpy, the "jrp lr" will be incorrect. 17 * Here leaf function not only means it does not have calls, but also
18 * requires no stack operations (sp, stack frame pointer) and no
19 * use of callee-saved registers, else "jrp lr" will be incorrect since
20 * unwinding stack frame is bypassed. Since memcpy() is not complex so
21 * these conditions are satisfied here, but we need to be careful when
22 * modifying this file. This is not a clean solution but is the best
23 * one so far.
18 * 24 *
19 * Also note that we are capturing "n" from the containing scope here. 25 * Also note that we are capturing "n" from the containing scope here.
20 */ 26 */
diff --git a/arch/tile/lib/spinlock_common.h b/arch/tile/lib/spinlock_common.h
index c10109809132..6ac37509faca 100644
--- a/arch/tile/lib/spinlock_common.h
+++ b/arch/tile/lib/spinlock_common.h
@@ -60,5 +60,5 @@ static void delay_backoff(int iterations)
60 loops += __insn_crc32_32(stack_pointer, get_cycles_low()) & 60 loops += __insn_crc32_32(stack_pointer, get_cycles_low()) &
61 (loops - 1); 61 (loops - 1);
62 62
63 relax(1 << exponent); 63 relax(loops);
64} 64}
diff --git a/arch/tile/mm/fault.c b/arch/tile/mm/fault.c
index cba30e9547b4..22e58f51ed23 100644
--- a/arch/tile/mm/fault.c
+++ b/arch/tile/mm/fault.c
@@ -130,7 +130,7 @@ static inline pmd_t *vmalloc_sync_one(pgd_t *pgd, unsigned long address)
130} 130}
131 131
132/* 132/*
133 * Handle a fault on the vmalloc or module mapping area 133 * Handle a fault on the vmalloc area.
134 */ 134 */
135static inline int vmalloc_fault(pgd_t *pgd, unsigned long address) 135static inline int vmalloc_fault(pgd_t *pgd, unsigned long address)
136{ 136{
@@ -203,9 +203,14 @@ static pgd_t *get_current_pgd(void)
203 * interrupt or a critical region, and must do as little as possible. 203 * interrupt or a critical region, and must do as little as possible.
204 * Similarly, we can't use atomic ops here, since we may be handling a 204 * Similarly, we can't use atomic ops here, since we may be handling a
205 * fault caused by an atomic op access. 205 * fault caused by an atomic op access.
206 *
207 * If we find a migrating PTE while we're in an NMI context, and we're
208 * at a PC that has a registered exception handler, we don't wait,
209 * since this thread may (e.g.) have been interrupted while migrating
210 * its own stack, which would then cause us to self-deadlock.
206 */ 211 */
207static int handle_migrating_pte(pgd_t *pgd, int fault_num, 212static int handle_migrating_pte(pgd_t *pgd, int fault_num,
208 unsigned long address, 213 unsigned long address, unsigned long pc,
209 int is_kernel_mode, int write) 214 int is_kernel_mode, int write)
210{ 215{
211 pud_t *pud; 216 pud_t *pud;
@@ -227,6 +232,8 @@ static int handle_migrating_pte(pgd_t *pgd, int fault_num,
227 pte_offset_kernel(pmd, address); 232 pte_offset_kernel(pmd, address);
228 pteval = *pte; 233 pteval = *pte;
229 if (pte_migrating(pteval)) { 234 if (pte_migrating(pteval)) {
235 if (in_nmi() && search_exception_tables(pc))
236 return 0;
230 wait_for_migration(pte); 237 wait_for_migration(pte);
231 return 1; 238 return 1;
232 } 239 }
@@ -300,7 +307,7 @@ static int handle_page_fault(struct pt_regs *regs,
300 * rather than trying to patch up the existing PTE. 307 * rather than trying to patch up the existing PTE.
301 */ 308 */
302 pgd = get_current_pgd(); 309 pgd = get_current_pgd();
303 if (handle_migrating_pte(pgd, fault_num, address, 310 if (handle_migrating_pte(pgd, fault_num, address, regs->pc,
304 is_kernel_mode, write)) 311 is_kernel_mode, write))
305 return 1; 312 return 1;
306 313
@@ -335,9 +342,12 @@ static int handle_page_fault(struct pt_regs *regs,
335 /* 342 /*
336 * If we're trying to touch user-space addresses, we must 343 * If we're trying to touch user-space addresses, we must
337 * be either at PL0, or else with interrupts enabled in the 344 * be either at PL0, or else with interrupts enabled in the
338 * kernel, so either way we can re-enable interrupts here. 345 * kernel, so either way we can re-enable interrupts here
346 * unless we are doing atomic access to user space with
347 * interrupts disabled.
339 */ 348 */
340 local_irq_enable(); 349 if (!(regs->flags & PT_FLAGS_DISABLE_IRQ))
350 local_irq_enable();
341 351
342 mm = tsk->mm; 352 mm = tsk->mm;
343 353
@@ -665,7 +675,7 @@ struct intvec_state do_page_fault_ics(struct pt_regs *regs, int fault_num,
665 */ 675 */
666 if (fault_num == INT_DTLB_ACCESS) 676 if (fault_num == INT_DTLB_ACCESS)
667 write = 1; 677 write = 1;
668 if (handle_migrating_pte(pgd, fault_num, address, 1, write)) 678 if (handle_migrating_pte(pgd, fault_num, address, pc, 1, write))
669 return state; 679 return state;
670 680
671 /* Return zero so that we continue on with normal fault handling. */ 681 /* Return zero so that we continue on with normal fault handling. */
diff --git a/arch/tile/mm/homecache.c b/arch/tile/mm/homecache.c
index 1cc6ae477c98..499f73770b05 100644
--- a/arch/tile/mm/homecache.c
+++ b/arch/tile/mm/homecache.c
@@ -394,6 +394,7 @@ int page_home(struct page *page)
394 return pte_to_home(*virt_to_pte(NULL, kva)); 394 return pte_to_home(*virt_to_pte(NULL, kva));
395 } 395 }
396} 396}
397EXPORT_SYMBOL(page_home);
397 398
398void homecache_change_page_home(struct page *page, int order, int home) 399void homecache_change_page_home(struct page *page, int order, int home)
399{ 400{
diff --git a/arch/tile/mm/init.c b/arch/tile/mm/init.c
index 830c4908ea76..6a9d20ddc34f 100644
--- a/arch/tile/mm/init.c
+++ b/arch/tile/mm/init.c
@@ -254,11 +254,6 @@ static pgprot_t __init init_pgprot(ulong address)
254 return construct_pgprot(PAGE_KERNEL_RO, PAGE_HOME_IMMUTABLE); 254 return construct_pgprot(PAGE_KERNEL_RO, PAGE_HOME_IMMUTABLE);
255 } 255 }
256 256
257 /* As a performance optimization, keep the boot init stack here. */
258 if (address >= (ulong)&init_thread_union &&
259 address < (ulong)&init_thread_union + THREAD_SIZE)
260 return construct_pgprot(PAGE_KERNEL, smp_processor_id());
261
262#ifndef __tilegx__ 257#ifndef __tilegx__
263#if !ATOMIC_LOCKS_FOUND_VIA_TABLE() 258#if !ATOMIC_LOCKS_FOUND_VIA_TABLE()
264 /* Force the atomic_locks[] array page to be hash-for-home. */ 259 /* Force the atomic_locks[] array page to be hash-for-home. */
@@ -557,6 +552,7 @@ static void __init kernel_physical_mapping_init(pgd_t *pgd_base)
557 552
558 address = MEM_SV_INTRPT; 553 address = MEM_SV_INTRPT;
559 pmd = get_pmd(pgtables, address); 554 pmd = get_pmd(pgtables, address);
555 pfn = 0; /* code starts at PA 0 */
560 if (ktext_small) { 556 if (ktext_small) {
561 /* Allocate an L2 PTE for the kernel text */ 557 /* Allocate an L2 PTE for the kernel text */
562 int cpu = 0; 558 int cpu = 0;
@@ -579,10 +575,15 @@ static void __init kernel_physical_mapping_init(pgd_t *pgd_base)
579 } 575 }
580 576
581 BUG_ON(address != (unsigned long)_stext); 577 BUG_ON(address != (unsigned long)_stext);
582 pfn = 0; /* code starts at PA 0 */ 578 pte = NULL;
583 pte = alloc_pte(); 579 for (; address < (unsigned long)_einittext;
584 for (pte_ofs = 0; address < (unsigned long)_einittext; 580 pfn++, address += PAGE_SIZE) {
585 pfn++, pte_ofs++, address += PAGE_SIZE) { 581 pte_ofs = pte_index(address);
582 if (pte_ofs == 0) {
583 if (pte)
584 assign_pte(pmd++, pte);
585 pte = alloc_pte();
586 }
586 if (!ktext_local) { 587 if (!ktext_local) {
587 prot = set_remote_cache_cpu(prot, cpu); 588 prot = set_remote_cache_cpu(prot, cpu);
588 cpu = cpumask_next(cpu, &ktext_mask); 589 cpu = cpumask_next(cpu, &ktext_mask);
@@ -591,7 +592,8 @@ static void __init kernel_physical_mapping_init(pgd_t *pgd_base)
591 } 592 }
592 pte[pte_ofs] = pfn_pte(pfn, prot); 593 pte[pte_ofs] = pfn_pte(pfn, prot);
593 } 594 }
594 assign_pte(pmd, pte); 595 if (pte)
596 assign_pte(pmd, pte);
595 } else { 597 } else {
596 pte_t pteval = pfn_pte(0, PAGE_KERNEL_EXEC); 598 pte_t pteval = pfn_pte(0, PAGE_KERNEL_EXEC);
597 pteval = pte_mkhuge(pteval); 599 pteval = pte_mkhuge(pteval);
@@ -614,7 +616,9 @@ static void __init kernel_physical_mapping_init(pgd_t *pgd_base)
614 else 616 else
615 pteval = hv_pte_set_mode(pteval, 617 pteval = hv_pte_set_mode(pteval,
616 HV_PTE_MODE_CACHE_NO_L3); 618 HV_PTE_MODE_CACHE_NO_L3);
617 *(pte_t *)pmd = pteval; 619 for (; address < (unsigned long)_einittext;
620 pfn += PFN_DOWN(HPAGE_SIZE), address += HPAGE_SIZE)
621 *(pte_t *)(pmd++) = pfn_pte(pfn, pteval);
618 } 622 }
619 623
620 /* Set swapper_pgprot here so it is flushed to memory right away. */ 624 /* Set swapper_pgprot here so it is flushed to memory right away. */
diff --git a/arch/tile/mm/pgtable.c b/arch/tile/mm/pgtable.c
index 87303693a072..2410aa899b3e 100644
--- a/arch/tile/mm/pgtable.c
+++ b/arch/tile/mm/pgtable.c
@@ -177,14 +177,10 @@ void shatter_huge_page(unsigned long addr)
177 if (!pmd_huge_page(*pmd)) 177 if (!pmd_huge_page(*pmd))
178 return; 178 return;
179 179
180 /* 180 spin_lock_irqsave(&init_mm.page_table_lock, flags);
181 * Grab the pgd_lock, since we may need it to walk the pgd_list,
182 * and since we need some kind of lock here to avoid races.
183 */
184 spin_lock_irqsave(&pgd_lock, flags);
185 if (!pmd_huge_page(*pmd)) { 181 if (!pmd_huge_page(*pmd)) {
186 /* Lost the race to convert the huge page. */ 182 /* Lost the race to convert the huge page. */
187 spin_unlock_irqrestore(&pgd_lock, flags); 183 spin_unlock_irqrestore(&init_mm.page_table_lock, flags);
188 return; 184 return;
189 } 185 }
190 186
@@ -194,6 +190,7 @@ void shatter_huge_page(unsigned long addr)
194 190
195#ifdef __PAGETABLE_PMD_FOLDED 191#ifdef __PAGETABLE_PMD_FOLDED
196 /* Walk every pgd on the system and update the pmd there. */ 192 /* Walk every pgd on the system and update the pmd there. */
193 spin_lock(&pgd_lock);
197 list_for_each(pos, &pgd_list) { 194 list_for_each(pos, &pgd_list) {
198 pmd_t *copy_pmd; 195 pmd_t *copy_pmd;
199 pgd = list_to_pgd(pos) + pgd_index(addr); 196 pgd = list_to_pgd(pos) + pgd_index(addr);
@@ -201,6 +198,7 @@ void shatter_huge_page(unsigned long addr)
201 copy_pmd = pmd_offset(pud, addr); 198 copy_pmd = pmd_offset(pud, addr);
202 __set_pmd(copy_pmd, *pmd); 199 __set_pmd(copy_pmd, *pmd);
203 } 200 }
201 spin_unlock(&pgd_lock);
204#endif 202#endif
205 203
206 /* Tell every cpu to notice the change. */ 204 /* Tell every cpu to notice the change. */
@@ -208,7 +206,7 @@ void shatter_huge_page(unsigned long addr)
208 cpu_possible_mask, NULL, 0); 206 cpu_possible_mask, NULL, 0);
209 207
210 /* Hold the lock until the TLB flush is finished to avoid races. */ 208 /* Hold the lock until the TLB flush is finished to avoid races. */
211 spin_unlock_irqrestore(&pgd_lock, flags); 209 spin_unlock_irqrestore(&init_mm.page_table_lock, flags);
212} 210}
213 211
214/* 212/*
@@ -217,9 +215,13 @@ void shatter_huge_page(unsigned long addr)
217 * against pageattr.c; it is the unique case in which a valid change 215 * against pageattr.c; it is the unique case in which a valid change
218 * of kernel pagetables can't be lazily synchronized by vmalloc faults. 216 * of kernel pagetables can't be lazily synchronized by vmalloc faults.
219 * vmalloc faults work because attached pagetables are never freed. 217 * vmalloc faults work because attached pagetables are never freed.
220 * The locking scheme was chosen on the basis of manfred's 218 *
221 * recommendations and having no core impact whatsoever. 219 * The lock is always taken with interrupts disabled, unlike on x86
222 * -- wli 220 * and other platforms, because we need to take the lock in
221 * shatter_huge_page(), which may be called from an interrupt context.
222 * We are not at risk from the tlbflush IPI deadlock that was seen on
223 * x86, since we use the flush_remote() API to have the hypervisor do
224 * the TLB flushes regardless of irq disabling.
223 */ 225 */
224DEFINE_SPINLOCK(pgd_lock); 226DEFINE_SPINLOCK(pgd_lock);
225LIST_HEAD(pgd_list); 227LIST_HEAD(pgd_list);
@@ -469,10 +471,18 @@ void __set_pte(pte_t *ptep, pte_t pte)
469 471
470void set_pte(pte_t *ptep, pte_t pte) 472void set_pte(pte_t *ptep, pte_t pte)
471{ 473{
472 struct page *page = pfn_to_page(pte_pfn(pte)); 474 if (pte_present(pte) &&
473 475 (!CHIP_HAS_MMIO() || hv_pte_get_mode(pte) != HV_PTE_MODE_MMIO)) {
474 /* Update the home of a PTE if necessary */ 476 /* The PTE actually references physical memory. */
475 pte = pte_set_home(pte, page_home(page)); 477 unsigned long pfn = pte_pfn(pte);
478 if (pfn_valid(pfn)) {
479 /* Update the home of the PTE from the struct page. */
480 pte = pte_set_home(pte, page_home(pfn_to_page(pfn)));
481 } else if (hv_pte_get_mode(pte) == 0) {
482 /* remap_pfn_range(), etc, must supply PTE mode. */
483 panic("set_pte(): out-of-range PFN and mode 0\n");
484 }
485 }
476 486
477 __set_pte(ptep, pte); 487 __set_pte(ptep, pte);
478} 488}
diff --git a/arch/um/drivers/cow.h b/arch/um/drivers/cow.h
index dc36b222100b..6673508f3426 100644
--- a/arch/um/drivers/cow.h
+++ b/arch/um/drivers/cow.h
@@ -3,41 +3,6 @@
3 3
4#include <asm/types.h> 4#include <asm/types.h>
5 5
6#if defined(__KERNEL__)
7
8# include <asm/byteorder.h>
9
10# if defined(__BIG_ENDIAN)
11# define ntohll(x) (x)
12# define htonll(x) (x)
13# elif defined(__LITTLE_ENDIAN)
14# define ntohll(x) be64_to_cpu(x)
15# define htonll(x) cpu_to_be64(x)
16# else
17# error "Could not determine byte order"
18# endif
19
20#else
21/* For the definition of ntohl, htonl and __BYTE_ORDER */
22#include <endian.h>
23#include <netinet/in.h>
24#if defined(__BYTE_ORDER)
25
26# if __BYTE_ORDER == __BIG_ENDIAN
27# define ntohll(x) (x)
28# define htonll(x) (x)
29# elif __BYTE_ORDER == __LITTLE_ENDIAN
30# define ntohll(x) bswap_64(x)
31# define htonll(x) bswap_64(x)
32# else
33# error "Could not determine byte order: __BYTE_ORDER uncorrectly defined"
34# endif
35
36#else /* ! defined(__BYTE_ORDER) */
37# error "Could not determine byte order: __BYTE_ORDER not defined"
38#endif
39#endif /* ! defined(__KERNEL__) */
40
41extern int init_cow_file(int fd, char *cow_file, char *backing_file, 6extern int init_cow_file(int fd, char *cow_file, char *backing_file,
42 int sectorsize, int alignment, int *bitmap_offset_out, 7 int sectorsize, int alignment, int *bitmap_offset_out,
43 unsigned long *bitmap_len_out, int *data_offset_out); 8 unsigned long *bitmap_len_out, int *data_offset_out);
diff --git a/arch/um/drivers/cow_user.c b/arch/um/drivers/cow_user.c
index 9cbb426c0b91..0ee9cc6cc4c7 100644
--- a/arch/um/drivers/cow_user.c
+++ b/arch/um/drivers/cow_user.c
@@ -8,11 +8,10 @@
8 * that. 8 * that.
9 */ 9 */
10#include <unistd.h> 10#include <unistd.h>
11#include <byteswap.h>
12#include <errno.h> 11#include <errno.h>
13#include <string.h> 12#include <string.h>
14#include <arpa/inet.h> 13#include <arpa/inet.h>
15#include <asm/types.h> 14#include <endian.h>
16#include "cow.h" 15#include "cow.h"
17#include "cow_sys.h" 16#include "cow_sys.h"
18 17
@@ -214,8 +213,8 @@ int write_cow_header(char *cow_file, int fd, char *backing_file,
214 "header\n"); 213 "header\n");
215 goto out; 214 goto out;
216 } 215 }
217 header->magic = htonl(COW_MAGIC); 216 header->magic = htobe32(COW_MAGIC);
218 header->version = htonl(COW_VERSION); 217 header->version = htobe32(COW_VERSION);
219 218
220 err = -EINVAL; 219 err = -EINVAL;
221 if (strlen(backing_file) > sizeof(header->backing_file) - 1) { 220 if (strlen(backing_file) > sizeof(header->backing_file) - 1) {
@@ -246,10 +245,10 @@ int write_cow_header(char *cow_file, int fd, char *backing_file,
246 goto out_free; 245 goto out_free;
247 } 246 }
248 247
249 header->mtime = htonl(modtime); 248 header->mtime = htobe32(modtime);
250 header->size = htonll(*size); 249 header->size = htobe64(*size);
251 header->sectorsize = htonl(sectorsize); 250 header->sectorsize = htobe32(sectorsize);
252 header->alignment = htonl(alignment); 251 header->alignment = htobe32(alignment);
253 header->cow_format = COW_BITMAP; 252 header->cow_format = COW_BITMAP;
254 253
255 err = cow_write_file(fd, header, sizeof(*header)); 254 err = cow_write_file(fd, header, sizeof(*header));
@@ -301,8 +300,8 @@ int read_cow_header(int (*reader)(__u64, char *, int, void *), void *arg,
301 magic = header->v1.magic; 300 magic = header->v1.magic;
302 if (magic == COW_MAGIC) 301 if (magic == COW_MAGIC)
303 version = header->v1.version; 302 version = header->v1.version;
304 else if (magic == ntohl(COW_MAGIC)) 303 else if (magic == be32toh(COW_MAGIC))
305 version = ntohl(header->v1.version); 304 version = be32toh(header->v1.version);
306 /* No error printed because the non-COW case comes through here */ 305 /* No error printed because the non-COW case comes through here */
307 else goto out; 306 else goto out;
308 307
@@ -327,9 +326,9 @@ int read_cow_header(int (*reader)(__u64, char *, int, void *), void *arg,
327 "header\n"); 326 "header\n");
328 goto out; 327 goto out;
329 } 328 }
330 *mtime_out = ntohl(header->v2.mtime); 329 *mtime_out = be32toh(header->v2.mtime);
331 *size_out = ntohll(header->v2.size); 330 *size_out = be64toh(header->v2.size);
332 *sectorsize_out = ntohl(header->v2.sectorsize); 331 *sectorsize_out = be32toh(header->v2.sectorsize);
333 *bitmap_offset_out = sizeof(header->v2); 332 *bitmap_offset_out = sizeof(header->v2);
334 *align_out = *sectorsize_out; 333 *align_out = *sectorsize_out;
335 file = header->v2.backing_file; 334 file = header->v2.backing_file;
@@ -341,10 +340,10 @@ int read_cow_header(int (*reader)(__u64, char *, int, void *), void *arg,
341 "header\n"); 340 "header\n");
342 goto out; 341 goto out;
343 } 342 }
344 *mtime_out = ntohl(header->v3.mtime); 343 *mtime_out = be32toh(header->v3.mtime);
345 *size_out = ntohll(header->v3.size); 344 *size_out = be64toh(header->v3.size);
346 *sectorsize_out = ntohl(header->v3.sectorsize); 345 *sectorsize_out = be32toh(header->v3.sectorsize);
347 *align_out = ntohl(header->v3.alignment); 346 *align_out = be32toh(header->v3.alignment);
348 if (*align_out == 0) { 347 if (*align_out == 0) {
349 cow_printf("read_cow_header - invalid COW header, " 348 cow_printf("read_cow_header - invalid COW header, "
350 "align == 0\n"); 349 "align == 0\n");
@@ -366,16 +365,16 @@ int read_cow_header(int (*reader)(__u64, char *, int, void *), void *arg,
366 * this was used until Dec2005 - 64bits are needed to represent 365 * this was used until Dec2005 - 64bits are needed to represent
367 * 2038+. I.e. we can safely do this truncating cast. 366 * 2038+. I.e. we can safely do this truncating cast.
368 * 367 *
369 * Additionally, we must use ntohl() instead of ntohll(), since 368 * Additionally, we must use be32toh() instead of be64toh(), since
370 * the program used to use the former (tested - I got mtime 369 * the program used to use the former (tested - I got mtime
371 * mismatch "0 vs whatever"). 370 * mismatch "0 vs whatever").
372 * 371 *
373 * Ever heard about bug-to-bug-compatibility ? ;-) */ 372 * Ever heard about bug-to-bug-compatibility ? ;-) */
374 *mtime_out = (time32_t) ntohl(header->v3_b.mtime); 373 *mtime_out = (time32_t) be32toh(header->v3_b.mtime);
375 374
376 *size_out = ntohll(header->v3_b.size); 375 *size_out = be64toh(header->v3_b.size);
377 *sectorsize_out = ntohl(header->v3_b.sectorsize); 376 *sectorsize_out = be32toh(header->v3_b.sectorsize);
378 *align_out = ntohl(header->v3_b.alignment); 377 *align_out = be32toh(header->v3_b.alignment);
379 if (*align_out == 0) { 378 if (*align_out == 0) {
380 cow_printf("read_cow_header - invalid COW header, " 379 cow_printf("read_cow_header - invalid COW header, "
381 "align == 0\n"); 380 "align == 0\n");
diff --git a/arch/um/drivers/mconsole_kern.c b/arch/um/drivers/mconsole_kern.c
index e672bd6d43e3..43b39d61b538 100644
--- a/arch/um/drivers/mconsole_kern.c
+++ b/arch/um/drivers/mconsole_kern.c
@@ -22,6 +22,7 @@
22#include <linux/workqueue.h> 22#include <linux/workqueue.h>
23#include <linux/mutex.h> 23#include <linux/mutex.h>
24#include <asm/uaccess.h> 24#include <asm/uaccess.h>
25#include <asm/switch_to.h>
25 26
26#include "init.h" 27#include "init.h"
27#include "irq_kern.h" 28#include "irq_kern.h"
diff --git a/arch/um/include/asm/Kbuild b/arch/um/include/asm/Kbuild
index 8419f5cf2ac7..fff24352255d 100644
--- a/arch/um/include/asm/Kbuild
+++ b/arch/um/include/asm/Kbuild
@@ -1,3 +1,4 @@
1generic-y += bug.h cputime.h device.h emergency-restart.h futex.h hardirq.h 1generic-y += bug.h cputime.h device.h emergency-restart.h futex.h hardirq.h
2generic-y += hw_irq.h irq_regs.h kdebug.h percpu.h sections.h topology.h xor.h 2generic-y += hw_irq.h irq_regs.h kdebug.h percpu.h sections.h topology.h xor.h
3generic-y += ftrace.h pci.h io.h param.h delay.h mutex.h current.h 3generic-y += ftrace.h pci.h io.h param.h delay.h mutex.h current.h exec.h
4generic-y += switch_to.h
diff --git a/arch/um/kernel/Makefile b/arch/um/kernel/Makefile
index 492bc4c1b62b..65a1c3d690ea 100644
--- a/arch/um/kernel/Makefile
+++ b/arch/um/kernel/Makefile
@@ -3,9 +3,10 @@
3# Licensed under the GPL 3# Licensed under the GPL
4# 4#
5 5
6CPPFLAGS_vmlinux.lds := -DSTART=$(LDS_START) \ 6CPPFLAGS_vmlinux.lds := -DSTART=$(LDS_START) \
7 -DELF_ARCH=$(LDS_ELF_ARCH) \ 7 -DELF_ARCH=$(LDS_ELF_ARCH) \
8 -DELF_FORMAT=$(LDS_ELF_FORMAT) 8 -DELF_FORMAT=$(LDS_ELF_FORMAT) \
9 $(LDS_EXTRA)
9extra-y := vmlinux.lds 10extra-y := vmlinux.lds
10clean-files := 11clean-files :=
11 12
diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
index f386d04a84a5..2b73dedb44ca 100644
--- a/arch/um/kernel/process.c
+++ b/arch/um/kernel/process.c
@@ -88,11 +88,8 @@ static inline void set_current(struct task_struct *task)
88 88
89extern void arch_switch_to(struct task_struct *to); 89extern void arch_switch_to(struct task_struct *to);
90 90
91void *_switch_to(void *prev, void *next, void *last) 91void *__switch_to(struct task_struct *from, struct task_struct *to)
92{ 92{
93 struct task_struct *from = prev;
94 struct task_struct *to = next;
95
96 to->thread.prev_sched = from; 93 to->thread.prev_sched = from;
97 set_current(to); 94 set_current(to);
98 95
@@ -111,7 +108,6 @@ void *_switch_to(void *prev, void *next, void *last)
111 } while (current->thread.saved_task); 108 } while (current->thread.saved_task);
112 109
113 return current->thread.prev_sched; 110 return current->thread.prev_sched;
114
115} 111}
116 112
117void interrupt_end(void) 113void interrupt_end(void)
diff --git a/arch/um/kernel/skas/mmu.c b/arch/um/kernel/skas/mmu.c
index 4947b319f53a..0a49ef0c2bf4 100644
--- a/arch/um/kernel/skas/mmu.c
+++ b/arch/um/kernel/skas/mmu.c
@@ -103,7 +103,6 @@ int init_new_context(struct task_struct *task, struct mm_struct *mm)
103 103
104void uml_setup_stubs(struct mm_struct *mm) 104void uml_setup_stubs(struct mm_struct *mm)
105{ 105{
106 struct page **pages;
107 int err, ret; 106 int err, ret;
108 107
109 if (!skas_needs_stub) 108 if (!skas_needs_stub)
diff --git a/arch/um/kernel/skas/process.c b/arch/um/kernel/skas/process.c
index 2e9852c0d487..0a9e57e7446b 100644
--- a/arch/um/kernel/skas/process.c
+++ b/arch/um/kernel/skas/process.c
@@ -41,7 +41,7 @@ static int __init start_kernel_proc(void *unused)
41 cpu_tasks[0].pid = pid; 41 cpu_tasks[0].pid = pid;
42 cpu_tasks[0].task = current; 42 cpu_tasks[0].task = current;
43#ifdef CONFIG_SMP 43#ifdef CONFIG_SMP
44 cpu_online_map = cpumask_of_cpu(0); 44 init_cpu_online(get_cpu_mask(0));
45#endif 45#endif
46 start_kernel(); 46 start_kernel();
47 return 0; 47 return 0;
diff --git a/arch/um/kernel/smp.c b/arch/um/kernel/smp.c
index 155206a66908..6f588e160fb0 100644
--- a/arch/um/kernel/smp.c
+++ b/arch/um/kernel/smp.c
@@ -76,7 +76,7 @@ static int idle_proc(void *cpup)
76 cpu_relax(); 76 cpu_relax();
77 77
78 notify_cpu_starting(cpu); 78 notify_cpu_starting(cpu);
79 cpu_set(cpu, cpu_online_map); 79 set_cpu_online(cpu, true);
80 default_idle(); 80 default_idle();
81 return 0; 81 return 0;
82} 82}
@@ -110,8 +110,7 @@ void smp_prepare_cpus(unsigned int maxcpus)
110 for (i = 0; i < ncpus; ++i) 110 for (i = 0; i < ncpus; ++i)
111 set_cpu_possible(i, true); 111 set_cpu_possible(i, true);
112 112
113 cpu_clear(me, cpu_online_map); 113 set_cpu_online(me, true);
114 cpu_set(me, cpu_online_map);
115 cpu_set(me, cpu_callin_map); 114 cpu_set(me, cpu_callin_map);
116 115
117 err = os_pipe(cpu_data[me].ipi_pipe, 1, 1); 116 err = os_pipe(cpu_data[me].ipi_pipe, 1, 1);
@@ -138,13 +137,13 @@ void smp_prepare_cpus(unsigned int maxcpus)
138 137
139void smp_prepare_boot_cpu(void) 138void smp_prepare_boot_cpu(void)
140{ 139{
141 cpu_set(smp_processor_id(), cpu_online_map); 140 set_cpu_online(smp_processor_id(), true);
142} 141}
143 142
144int __cpu_up(unsigned int cpu) 143int __cpu_up(unsigned int cpu)
145{ 144{
146 cpu_set(cpu, smp_commenced_mask); 145 cpu_set(cpu, smp_commenced_mask);
147 while (!cpu_isset(cpu, cpu_online_map)) 146 while (!cpu_online(cpu))
148 mb(); 147 mb();
149 return 0; 148 return 0;
150} 149}
diff --git a/arch/unicore32/include/asm/dma-mapping.h b/arch/unicore32/include/asm/dma-mapping.h
index 9258e592f414..366460a81796 100644
--- a/arch/unicore32/include/asm/dma-mapping.h
+++ b/arch/unicore32/include/asm/dma-mapping.h
@@ -82,20 +82,26 @@ static inline int dma_set_mask(struct device *dev, u64 dma_mask)
82 return 0; 82 return 0;
83} 83}
84 84
85static inline void *dma_alloc_coherent(struct device *dev, size_t size, 85#define dma_alloc_coherent(d,s,h,f) dma_alloc_attrs(d,s,h,f,NULL)
86 dma_addr_t *dma_handle, gfp_t flag) 86
87static inline void *dma_alloc_attrs(struct device *dev, size_t size,
88 dma_addr_t *dma_handle, gfp_t flag,
89 struct dma_attrs *attrs)
87{ 90{
88 struct dma_map_ops *dma_ops = get_dma_ops(dev); 91 struct dma_map_ops *dma_ops = get_dma_ops(dev);
89 92
90 return dma_ops->alloc_coherent(dev, size, dma_handle, flag); 93 return dma_ops->alloc(dev, size, dma_handle, flag, attrs);
91} 94}
92 95
93static inline void dma_free_coherent(struct device *dev, size_t size, 96#define dma_free_coherent(d,s,c,h) dma_free_attrs(d,s,c,h,NULL)
94 void *cpu_addr, dma_addr_t dma_handle) 97
98static inline void dma_free_attrs(struct device *dev, size_t size,
99 void *cpu_addr, dma_addr_t dma_handle,
100 struct dma_attrs *attrs)
95{ 101{
96 struct dma_map_ops *dma_ops = get_dma_ops(dev); 102 struct dma_map_ops *dma_ops = get_dma_ops(dev);
97 103
98 dma_ops->free_coherent(dev, size, cpu_addr, dma_handle); 104 dma_ops->free(dev, size, cpu_addr, dma_handle, attrs);
99} 105}
100 106
101#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f) 107#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
diff --git a/arch/unicore32/mm/dma-swiotlb.c b/arch/unicore32/mm/dma-swiotlb.c
index bfa9fbb2bbb1..16c08b2143a7 100644
--- a/arch/unicore32/mm/dma-swiotlb.c
+++ b/arch/unicore32/mm/dma-swiotlb.c
@@ -17,9 +17,23 @@
17 17
18#include <asm/dma.h> 18#include <asm/dma.h>
19 19
20static void *unicore_swiotlb_alloc_coherent(struct device *dev, size_t size,
21 dma_addr_t *dma_handle, gfp_t flags,
22 struct dma_attrs *attrs)
23{
24 return swiotlb_alloc_coherent(dev, size, dma_handle, flags);
25}
26
27static void unicore_swiotlb_free_coherent(struct device *dev, size_t size,
28 void *vaddr, dma_addr_t dma_addr,
29 struct dma_attrs *attrs)
30{
31 swiotlb_free_coherent(dev, size, vaddr, dma_addr);
32}
33
20struct dma_map_ops swiotlb_dma_map_ops = { 34struct dma_map_ops swiotlb_dma_map_ops = {
21 .alloc_coherent = swiotlb_alloc_coherent, 35 .alloc = unicore_swiotlb_alloc_coherent,
22 .free_coherent = swiotlb_free_coherent, 36 .free = unicore_swiotlb_free_coherent,
23 .map_sg = swiotlb_map_sg_attrs, 37 .map_sg = swiotlb_map_sg_attrs,
24 .unmap_sg = swiotlb_unmap_sg_attrs, 38 .unmap_sg = swiotlb_unmap_sg_attrs,
25 .dma_supported = swiotlb_dma_supported, 39 .dma_supported = swiotlb_dma_supported,
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 1d14cc6b79ad..c9866b0b77d8 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -81,7 +81,7 @@ config X86
81 select CLKEVT_I8253 81 select CLKEVT_I8253
82 select ARCH_HAVE_NMI_SAFE_CMPXCHG 82 select ARCH_HAVE_NMI_SAFE_CMPXCHG
83 select GENERIC_IOMAP 83 select GENERIC_IOMAP
84 select DCACHE_WORD_ACCESS if !DEBUG_PAGEALLOC 84 select DCACHE_WORD_ACCESS
85 85
86config INSTRUCTION_DECODER 86config INSTRUCTION_DECODER
87 def_bool (KPROBES || PERF_EVENTS) 87 def_bool (KPROBES || PERF_EVENTS)
diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index 968dbe24a255..41a7237606a3 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -129,6 +129,7 @@ KBUILD_CFLAGS += -Wno-sign-compare
129KBUILD_CFLAGS += -fno-asynchronous-unwind-tables 129KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
130# prevent gcc from generating any FP code by mistake 130# prevent gcc from generating any FP code by mistake
131KBUILD_CFLAGS += $(call cc-option,-mno-sse -mno-mmx -mno-sse2 -mno-3dnow,) 131KBUILD_CFLAGS += $(call cc-option,-mno-sse -mno-mmx -mno-sse2 -mno-3dnow,)
132KBUILD_CFLAGS += $(call cc-option,-mno-avx,)
132 133
133KBUILD_CFLAGS += $(mflags-y) 134KBUILD_CFLAGS += $(mflags-y)
134KBUILD_AFLAGS += $(mflags-y) 135KBUILD_AFLAGS += $(mflags-y)
diff --git a/arch/x86/Makefile.um b/arch/x86/Makefile.um
index 4be406abeefd..36b62bc52638 100644
--- a/arch/x86/Makefile.um
+++ b/arch/x86/Makefile.um
@@ -14,6 +14,9 @@ LINK-y += $(call cc-option,-m32)
14 14
15export LDFLAGS 15export LDFLAGS
16 16
17LDS_EXTRA := -Ui386
18export LDS_EXTRA
19
17# First of all, tune CFLAGS for the specific CPU. This actually sets cflags-y. 20# First of all, tune CFLAGS for the specific CPU. This actually sets cflags-y.
18include $(srctree)/arch/x86/Makefile_32.cpu 21include $(srctree)/arch/x86/Makefile_32.cpu
19 22
diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
index a0559930a180..c85e3ac99bba 100644
--- a/arch/x86/boot/compressed/head_32.S
+++ b/arch/x86/boot/compressed/head_32.S
@@ -33,6 +33,9 @@
33 __HEAD 33 __HEAD
34ENTRY(startup_32) 34ENTRY(startup_32)
35#ifdef CONFIG_EFI_STUB 35#ifdef CONFIG_EFI_STUB
36 jmp preferred_addr
37
38 .balign 0x10
36 /* 39 /*
37 * We don't need the return address, so set up the stack so 40 * We don't need the return address, so set up the stack so
38 * efi_main() can find its arugments. 41 * efi_main() can find its arugments.
@@ -41,12 +44,17 @@ ENTRY(startup_32)
41 44
42 call efi_main 45 call efi_main
43 cmpl $0, %eax 46 cmpl $0, %eax
44 je preferred_addr
45 movl %eax, %esi 47 movl %eax, %esi
46 call 1f 48 jne 2f
471: 491:
50 /* EFI init failed, so hang. */
51 hlt
52 jmp 1b
532:
54 call 3f
553:
48 popl %eax 56 popl %eax
49 subl $1b, %eax 57 subl $3b, %eax
50 subl BP_pref_address(%esi), %eax 58 subl BP_pref_address(%esi), %eax
51 add BP_code32_start(%esi), %eax 59 add BP_code32_start(%esi), %eax
52 leal preferred_addr(%eax), %eax 60 leal preferred_addr(%eax), %eax
diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
index 558d76ce23bc..87e03a13d8e3 100644
--- a/arch/x86/boot/compressed/head_64.S
+++ b/arch/x86/boot/compressed/head_64.S
@@ -200,18 +200,28 @@ ENTRY(startup_64)
200 * entire text+data+bss and hopefully all of memory. 200 * entire text+data+bss and hopefully all of memory.
201 */ 201 */
202#ifdef CONFIG_EFI_STUB 202#ifdef CONFIG_EFI_STUB
203 pushq %rsi 203 /*
204 * The entry point for the PE/COFF executable is 0x210, so only
205 * legacy boot loaders will execute this jmp.
206 */
207 jmp preferred_addr
208
209 .org 0x210
204 mov %rcx, %rdi 210 mov %rcx, %rdi
205 mov %rdx, %rsi 211 mov %rdx, %rsi
206 call efi_main 212 call efi_main
207 popq %rsi
208 cmpq $0,%rax
209 je preferred_addr
210 movq %rax,%rsi 213 movq %rax,%rsi
211 call 1f 214 cmpq $0,%rax
215 jne 2f
2121: 2161:
217 /* EFI init failed, so hang. */
218 hlt
219 jmp 1b
2202:
221 call 3f
2223:
213 popq %rax 223 popq %rax
214 subq $1b, %rax 224 subq $3b, %rax
215 subq BP_pref_address(%rsi), %rax 225 subq BP_pref_address(%rsi), %rax
216 add BP_code32_start(%esi), %eax 226 add BP_code32_start(%esi), %eax
217 leaq preferred_addr(%rax), %rax 227 leaq preferred_addr(%rax), %rax
diff --git a/arch/x86/boot/compressed/relocs.c b/arch/x86/boot/compressed/relocs.c
index d3c0b0277666..fb7117a4ade1 100644
--- a/arch/x86/boot/compressed/relocs.c
+++ b/arch/x86/boot/compressed/relocs.c
@@ -403,13 +403,11 @@ static void print_absolute_symbols(void)
403 for (i = 0; i < ehdr.e_shnum; i++) { 403 for (i = 0; i < ehdr.e_shnum; i++) {
404 struct section *sec = &secs[i]; 404 struct section *sec = &secs[i];
405 char *sym_strtab; 405 char *sym_strtab;
406 Elf32_Sym *sh_symtab;
407 int j; 406 int j;
408 407
409 if (sec->shdr.sh_type != SHT_SYMTAB) { 408 if (sec->shdr.sh_type != SHT_SYMTAB) {
410 continue; 409 continue;
411 } 410 }
412 sh_symtab = sec->symtab;
413 sym_strtab = sec->link->strtab; 411 sym_strtab = sec->link->strtab;
414 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Sym); j++) { 412 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Sym); j++) {
415 Elf32_Sym *sym; 413 Elf32_Sym *sym;
diff --git a/arch/x86/boot/tools/build.c b/arch/x86/boot/tools/build.c
index ed549767a231..24443a332083 100644
--- a/arch/x86/boot/tools/build.c
+++ b/arch/x86/boot/tools/build.c
@@ -205,8 +205,13 @@ int main(int argc, char ** argv)
205 put_unaligned_le32(file_sz, &buf[pe_header + 0x50]); 205 put_unaligned_le32(file_sz, &buf[pe_header + 0x50]);
206 206
207#ifdef CONFIG_X86_32 207#ifdef CONFIG_X86_32
208 /* Address of entry point */ 208 /*
209 put_unaligned_le32(i, &buf[pe_header + 0x28]); 209 * Address of entry point.
210 *
211 * The EFI stub entry point is +16 bytes from the start of
212 * the .text section.
213 */
214 put_unaligned_le32(i + 16, &buf[pe_header + 0x28]);
210 215
211 /* .text size */ 216 /* .text size */
212 put_unaligned_le32(file_sz, &buf[pe_header + 0xb0]); 217 put_unaligned_le32(file_sz, &buf[pe_header + 0xb0]);
@@ -217,9 +222,11 @@ int main(int argc, char ** argv)
217 /* 222 /*
218 * Address of entry point. startup_32 is at the beginning and 223 * Address of entry point. startup_32 is at the beginning and
219 * the 64-bit entry point (startup_64) is always 512 bytes 224 * the 64-bit entry point (startup_64) is always 512 bytes
220 * after. 225 * after. The EFI stub entry point is 16 bytes after that, as
226 * the first instruction allows legacy loaders to jump over
227 * the EFI stub initialisation
221 */ 228 */
222 put_unaligned_le32(i + 512, &buf[pe_header + 0x28]); 229 put_unaligned_le32(i + 528, &buf[pe_header + 0x28]);
223 230
224 /* .text size */ 231 /* .text size */
225 put_unaligned_le32(file_sz, &buf[pe_header + 0xc0]); 232 put_unaligned_le32(file_sz, &buf[pe_header + 0xc0]);
diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
index d511d951a052..07b3a68d2d29 100644
--- a/arch/x86/ia32/ia32_aout.c
+++ b/arch/x86/ia32/ia32_aout.c
@@ -119,9 +119,7 @@ static void set_brk(unsigned long start, unsigned long end)
119 end = PAGE_ALIGN(end); 119 end = PAGE_ALIGN(end);
120 if (end <= start) 120 if (end <= start)
121 return; 121 return;
122 down_write(&current->mm->mmap_sem); 122 vm_brk(start, end - start);
123 do_brk(start, end - start);
124 up_write(&current->mm->mmap_sem);
125} 123}
126 124
127#ifdef CORE_DUMP 125#ifdef CORE_DUMP
@@ -296,8 +294,7 @@ static int load_aout_binary(struct linux_binprm *bprm, struct pt_regs *regs)
296 294
297 /* OK, This is the point of no return */ 295 /* OK, This is the point of no return */
298 set_personality(PER_LINUX); 296 set_personality(PER_LINUX);
299 set_thread_flag(TIF_IA32); 297 set_personality_ia32(false);
300 current->mm->context.ia32_compat = 1;
301 298
302 setup_new_exec(bprm); 299 setup_new_exec(bprm);
303 300
@@ -332,9 +329,7 @@ static int load_aout_binary(struct linux_binprm *bprm, struct pt_regs *regs)
332 pos = 32; 329 pos = 32;
333 map_size = ex.a_text+ex.a_data; 330 map_size = ex.a_text+ex.a_data;
334 331
335 down_write(&current->mm->mmap_sem); 332 error = vm_brk(text_addr & PAGE_MASK, map_size);
336 error = do_brk(text_addr & PAGE_MASK, map_size);
337 up_write(&current->mm->mmap_sem);
338 333
339 if (error != (text_addr & PAGE_MASK)) { 334 if (error != (text_addr & PAGE_MASK)) {
340 send_sig(SIGKILL, current, 0); 335 send_sig(SIGKILL, current, 0);
@@ -373,9 +368,7 @@ static int load_aout_binary(struct linux_binprm *bprm, struct pt_regs *regs)
373 if (!bprm->file->f_op->mmap || (fd_offset & ~PAGE_MASK) != 0) { 368 if (!bprm->file->f_op->mmap || (fd_offset & ~PAGE_MASK) != 0) {
374 loff_t pos = fd_offset; 369 loff_t pos = fd_offset;
375 370
376 down_write(&current->mm->mmap_sem); 371 vm_brk(N_TXTADDR(ex), ex.a_text+ex.a_data);
377 do_brk(N_TXTADDR(ex), ex.a_text+ex.a_data);
378 up_write(&current->mm->mmap_sem);
379 bprm->file->f_op->read(bprm->file, 372 bprm->file->f_op->read(bprm->file,
380 (char __user *)N_TXTADDR(ex), 373 (char __user *)N_TXTADDR(ex),
381 ex.a_text+ex.a_data, &pos); 374 ex.a_text+ex.a_data, &pos);
@@ -385,26 +378,22 @@ static int load_aout_binary(struct linux_binprm *bprm, struct pt_regs *regs)
385 goto beyond_if; 378 goto beyond_if;
386 } 379 }
387 380
388 down_write(&current->mm->mmap_sem); 381 error = vm_mmap(bprm->file, N_TXTADDR(ex), ex.a_text,
389 error = do_mmap(bprm->file, N_TXTADDR(ex), ex.a_text,
390 PROT_READ | PROT_EXEC, 382 PROT_READ | PROT_EXEC,
391 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | 383 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE |
392 MAP_EXECUTABLE | MAP_32BIT, 384 MAP_EXECUTABLE | MAP_32BIT,
393 fd_offset); 385 fd_offset);
394 up_write(&current->mm->mmap_sem);
395 386
396 if (error != N_TXTADDR(ex)) { 387 if (error != N_TXTADDR(ex)) {
397 send_sig(SIGKILL, current, 0); 388 send_sig(SIGKILL, current, 0);
398 return error; 389 return error;
399 } 390 }
400 391
401 down_write(&current->mm->mmap_sem); 392 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
402 error = do_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
403 PROT_READ | PROT_WRITE | PROT_EXEC, 393 PROT_READ | PROT_WRITE | PROT_EXEC,
404 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | 394 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE |
405 MAP_EXECUTABLE | MAP_32BIT, 395 MAP_EXECUTABLE | MAP_32BIT,
406 fd_offset + ex.a_text); 396 fd_offset + ex.a_text);
407 up_write(&current->mm->mmap_sem);
408 if (error != N_DATADDR(ex)) { 397 if (error != N_DATADDR(ex)) {
409 send_sig(SIGKILL, current, 0); 398 send_sig(SIGKILL, current, 0);
410 return error; 399 return error;
@@ -476,9 +465,7 @@ static int load_aout_library(struct file *file)
476 error_time = jiffies; 465 error_time = jiffies;
477 } 466 }
478#endif 467#endif
479 down_write(&current->mm->mmap_sem); 468 vm_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss);
480 do_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss);
481 up_write(&current->mm->mmap_sem);
482 469
483 file->f_op->read(file, (char __user *)start_addr, 470 file->f_op->read(file, (char __user *)start_addr,
484 ex.a_text + ex.a_data, &pos); 471 ex.a_text + ex.a_data, &pos);
@@ -490,12 +477,10 @@ static int load_aout_library(struct file *file)
490 goto out; 477 goto out;
491 } 478 }
492 /* Now use mmap to map the library into memory. */ 479 /* Now use mmap to map the library into memory. */
493 down_write(&current->mm->mmap_sem); 480 error = vm_mmap(file, start_addr, ex.a_text + ex.a_data,
494 error = do_mmap(file, start_addr, ex.a_text + ex.a_data,
495 PROT_READ | PROT_WRITE | PROT_EXEC, 481 PROT_READ | PROT_WRITE | PROT_EXEC,
496 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_32BIT, 482 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_32BIT,
497 N_TXTOFF(ex)); 483 N_TXTOFF(ex));
498 up_write(&current->mm->mmap_sem);
499 retval = error; 484 retval = error;
500 if (error != start_addr) 485 if (error != start_addr)
501 goto out; 486 goto out;
@@ -503,9 +488,7 @@ static int load_aout_library(struct file *file)
503 len = PAGE_ALIGN(ex.a_text + ex.a_data); 488 len = PAGE_ALIGN(ex.a_text + ex.a_data);
504 bss = ex.a_text + ex.a_data + ex.a_bss; 489 bss = ex.a_text + ex.a_data + ex.a_bss;
505 if (bss > len) { 490 if (bss > len) {
506 down_write(&current->mm->mmap_sem); 491 error = vm_brk(start_addr + len, bss - len);
507 error = do_brk(start_addr + len, bss - len);
508 up_write(&current->mm->mmap_sem);
509 retval = error; 492 retval = error;
510 if (error != start_addr + len) 493 if (error != start_addr + len)
511 goto out; 494 goto out;
diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
index b3b733262909..99480e55973d 100644
--- a/arch/x86/include/asm/cmpxchg.h
+++ b/arch/x86/include/asm/cmpxchg.h
@@ -43,7 +43,7 @@ extern void __add_wrong_size(void)
43 switch (sizeof(*(ptr))) { \ 43 switch (sizeof(*(ptr))) { \
44 case __X86_CASE_B: \ 44 case __X86_CASE_B: \
45 asm volatile (lock #op "b %b0, %1\n" \ 45 asm volatile (lock #op "b %b0, %1\n" \
46 : "+r" (__ret), "+m" (*(ptr)) \ 46 : "+q" (__ret), "+m" (*(ptr)) \
47 : : "memory", "cc"); \ 47 : : "memory", "cc"); \
48 break; \ 48 break; \
49 case __X86_CASE_W: \ 49 case __X86_CASE_W: \
@@ -173,7 +173,7 @@ extern void __add_wrong_size(void)
173 switch (sizeof(*(ptr))) { \ 173 switch (sizeof(*(ptr))) { \
174 case __X86_CASE_B: \ 174 case __X86_CASE_B: \
175 asm volatile (lock "addb %b1, %0\n" \ 175 asm volatile (lock "addb %b1, %0\n" \
176 : "+m" (*(ptr)) : "ri" (inc) \ 176 : "+m" (*(ptr)) : "qi" (inc) \
177 : "memory", "cc"); \ 177 : "memory", "cc"); \
178 break; \ 178 break; \
179 case __X86_CASE_W: \ 179 case __X86_CASE_W: \
diff --git a/arch/x86/include/asm/dma-mapping.h b/arch/x86/include/asm/dma-mapping.h
index ed3065fd6314..4b4331d71935 100644
--- a/arch/x86/include/asm/dma-mapping.h
+++ b/arch/x86/include/asm/dma-mapping.h
@@ -59,7 +59,8 @@ extern int dma_supported(struct device *hwdev, u64 mask);
59extern int dma_set_mask(struct device *dev, u64 mask); 59extern int dma_set_mask(struct device *dev, u64 mask);
60 60
61extern void *dma_generic_alloc_coherent(struct device *dev, size_t size, 61extern void *dma_generic_alloc_coherent(struct device *dev, size_t size,
62 dma_addr_t *dma_addr, gfp_t flag); 62 dma_addr_t *dma_addr, gfp_t flag,
63 struct dma_attrs *attrs);
63 64
64static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size) 65static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)
65{ 66{
@@ -111,9 +112,11 @@ static inline gfp_t dma_alloc_coherent_gfp_flags(struct device *dev, gfp_t gfp)
111 return gfp; 112 return gfp;
112} 113}
113 114
115#define dma_alloc_coherent(d,s,h,f) dma_alloc_attrs(d,s,h,f,NULL)
116
114static inline void * 117static inline void *
115dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle, 118dma_alloc_attrs(struct device *dev, size_t size, dma_addr_t *dma_handle,
116 gfp_t gfp) 119 gfp_t gfp, struct dma_attrs *attrs)
117{ 120{
118 struct dma_map_ops *ops = get_dma_ops(dev); 121 struct dma_map_ops *ops = get_dma_ops(dev);
119 void *memory; 122 void *memory;
@@ -129,18 +132,21 @@ dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
129 if (!is_device_dma_capable(dev)) 132 if (!is_device_dma_capable(dev))
130 return NULL; 133 return NULL;
131 134
132 if (!ops->alloc_coherent) 135 if (!ops->alloc)
133 return NULL; 136 return NULL;
134 137
135 memory = ops->alloc_coherent(dev, size, dma_handle, 138 memory = ops->alloc(dev, size, dma_handle,
136 dma_alloc_coherent_gfp_flags(dev, gfp)); 139 dma_alloc_coherent_gfp_flags(dev, gfp), attrs);
137 debug_dma_alloc_coherent(dev, size, *dma_handle, memory); 140 debug_dma_alloc_coherent(dev, size, *dma_handle, memory);
138 141
139 return memory; 142 return memory;
140} 143}
141 144
142static inline void dma_free_coherent(struct device *dev, size_t size, 145#define dma_free_coherent(d,s,c,h) dma_free_attrs(d,s,c,h,NULL)
143 void *vaddr, dma_addr_t bus) 146
147static inline void dma_free_attrs(struct device *dev, size_t size,
148 void *vaddr, dma_addr_t bus,
149 struct dma_attrs *attrs)
144{ 150{
145 struct dma_map_ops *ops = get_dma_ops(dev); 151 struct dma_map_ops *ops = get_dma_ops(dev);
146 152
@@ -150,8 +156,8 @@ static inline void dma_free_coherent(struct device *dev, size_t size,
150 return; 156 return;
151 157
152 debug_dma_free_coherent(dev, size, vaddr, bus); 158 debug_dma_free_coherent(dev, size, vaddr, bus);
153 if (ops->free_coherent) 159 if (ops->free)
154 ops->free_coherent(dev, size, vaddr, bus); 160 ops->free(dev, size, vaddr, bus, attrs);
155} 161}
156 162
157#endif 163#endif
diff --git a/arch/x86/include/asm/posix_types.h b/arch/x86/include/asm/posix_types.h
index 3427b7798dbc..7ef7c3020e5c 100644
--- a/arch/x86/include/asm/posix_types.h
+++ b/arch/x86/include/asm/posix_types.h
@@ -7,9 +7,9 @@
7#else 7#else
8# ifdef __i386__ 8# ifdef __i386__
9# include "posix_types_32.h" 9# include "posix_types_32.h"
10# elif defined(__LP64__) 10# elif defined(__ILP32__)
11# include "posix_types_64.h"
12# else
13# include "posix_types_x32.h" 11# include "posix_types_x32.h"
12# else
13# include "posix_types_64.h"
14# endif 14# endif
15#endif 15#endif
diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
index 7284c9a6a0b5..4fa7dcceb6c0 100644
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -974,16 +974,6 @@ extern bool cpu_has_amd_erratum(const int *);
974#define cpu_has_amd_erratum(x) (false) 974#define cpu_has_amd_erratum(x) (false)
975#endif /* CONFIG_CPU_SUP_AMD */ 975#endif /* CONFIG_CPU_SUP_AMD */
976 976
977#ifdef CONFIG_X86_32
978/*
979 * disable hlt during certain critical i/o operations
980 */
981#define HAVE_DISABLE_HLT
982#endif
983
984void disable_hlt(void);
985void enable_hlt(void);
986
987void cpu_idle_wait(void); 977void cpu_idle_wait(void);
988 978
989extern unsigned long arch_align_stack(unsigned long sp); 979extern unsigned long arch_align_stack(unsigned long sp);
diff --git a/arch/x86/include/asm/sigcontext.h b/arch/x86/include/asm/sigcontext.h
index 4a085383af27..5ca71c065eef 100644
--- a/arch/x86/include/asm/sigcontext.h
+++ b/arch/x86/include/asm/sigcontext.h
@@ -257,7 +257,7 @@ struct sigcontext {
257 __u64 oldmask; 257 __u64 oldmask;
258 __u64 cr2; 258 __u64 cr2;
259 struct _fpstate __user *fpstate; /* zero when no FPU context */ 259 struct _fpstate __user *fpstate; /* zero when no FPU context */
260#ifndef __LP64__ 260#ifdef __ILP32__
261 __u32 __fpstate_pad; 261 __u32 __fpstate_pad;
262#endif 262#endif
263 __u64 reserved1[8]; 263 __u64 reserved1[8];
diff --git a/arch/x86/include/asm/siginfo.h b/arch/x86/include/asm/siginfo.h
index fc1aa5535646..34c47b3341c0 100644
--- a/arch/x86/include/asm/siginfo.h
+++ b/arch/x86/include/asm/siginfo.h
@@ -2,7 +2,13 @@
2#define _ASM_X86_SIGINFO_H 2#define _ASM_X86_SIGINFO_H
3 3
4#ifdef __x86_64__ 4#ifdef __x86_64__
5# define __ARCH_SI_PREAMBLE_SIZE (4 * sizeof(int)) 5# ifdef __ILP32__ /* x32 */
6typedef long long __kernel_si_clock_t __attribute__((aligned(4)));
7# define __ARCH_SI_CLOCK_T __kernel_si_clock_t
8# define __ARCH_SI_ATTRIBUTES __attribute__((aligned(8)))
9# else /* x86-64 */
10# define __ARCH_SI_PREAMBLE_SIZE (4 * sizeof(int))
11# endif
6#endif 12#endif
7 13
8#include <asm-generic/siginfo.h> 14#include <asm-generic/siginfo.h>
diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
index 8be5f54d9360..e0544597cfe7 100644
--- a/arch/x86/include/asm/uaccess.h
+++ b/arch/x86/include/asm/uaccess.h
@@ -557,6 +557,8 @@ struct __large_struct { unsigned long buf[100]; };
557 557
558extern unsigned long 558extern unsigned long
559copy_from_user_nmi(void *to, const void __user *from, unsigned long n); 559copy_from_user_nmi(void *to, const void __user *from, unsigned long n);
560extern __must_check long
561strncpy_from_user(char *dst, const char __user *src, long count);
560 562
561/* 563/*
562 * movsl can be slow when source and dest are not both 8-byte aligned 564 * movsl can be slow when source and dest are not both 8-byte aligned
diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
index 566e803cc602..8084bc73b18c 100644
--- a/arch/x86/include/asm/uaccess_32.h
+++ b/arch/x86/include/asm/uaccess_32.h
@@ -213,11 +213,6 @@ static inline unsigned long __must_check copy_from_user(void *to,
213 return n; 213 return n;
214} 214}
215 215
216long __must_check strncpy_from_user(char *dst, const char __user *src,
217 long count);
218long __must_check __strncpy_from_user(char *dst,
219 const char __user *src, long count);
220
221/** 216/**
222 * strlen_user: - Get the size of a string in user space. 217 * strlen_user: - Get the size of a string in user space.
223 * @str: The string to measure. 218 * @str: The string to measure.
diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
index 1c66d30971ad..fcd4b6f3ef02 100644
--- a/arch/x86/include/asm/uaccess_64.h
+++ b/arch/x86/include/asm/uaccess_64.h
@@ -208,10 +208,6 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
208 } 208 }
209} 209}
210 210
211__must_check long
212strncpy_from_user(char *dst, const char __user *src, long count);
213__must_check long
214__strncpy_from_user(char *dst, const char __user *src, long count);
215__must_check long strnlen_user(const char __user *str, long n); 211__must_check long strnlen_user(const char __user *str, long n);
216__must_check long __strnlen_user(const char __user *str, long n); 212__must_check long __strnlen_user(const char __user *str, long n);
217__must_check long strlen_user(const char __user *str); 213__must_check long strlen_user(const char __user *str);
diff --git a/arch/x86/include/asm/unistd.h b/arch/x86/include/asm/unistd.h
index 37cdc9d99bb1..4437001d8e3d 100644
--- a/arch/x86/include/asm/unistd.h
+++ b/arch/x86/include/asm/unistd.h
@@ -63,10 +63,10 @@
63#else 63#else
64# ifdef __i386__ 64# ifdef __i386__
65# include <asm/unistd_32.h> 65# include <asm/unistd_32.h>
66# elif defined(__LP64__) 66# elif defined(__ILP32__)
67# include <asm/unistd_64.h>
68# else
69# include <asm/unistd_x32.h> 67# include <asm/unistd_x32.h>
68# else
69# include <asm/unistd_64.h>
70# endif 70# endif
71#endif 71#endif
72 72
diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
new file mode 100644
index 000000000000..e58f03b206c3
--- /dev/null
+++ b/arch/x86/include/asm/word-at-a-time.h
@@ -0,0 +1,79 @@
1#ifndef _ASM_WORD_AT_A_TIME_H
2#define _ASM_WORD_AT_A_TIME_H
3
4/*
5 * This is largely generic for little-endian machines, but the
6 * optimal byte mask counting is probably going to be something
7 * that is architecture-specific. If you have a reliably fast
8 * bit count instruction, that might be better than the multiply
9 * and shift, for example.
10 */
11
12#ifdef CONFIG_64BIT
13
14/*
15 * Jan Achrenius on G+: microoptimized version of
16 * the simpler "(mask & ONEBYTES) * ONEBYTES >> 56"
17 * that works for the bytemasks without having to
18 * mask them first.
19 */
20static inline long count_masked_bytes(unsigned long mask)
21{
22 return mask*0x0001020304050608ul >> 56;
23}
24
25#else /* 32-bit case */
26
27/* Carl Chatfield / Jan Achrenius G+ version for 32-bit */
28static inline long count_masked_bytes(long mask)
29{
30 /* (000000 0000ff 00ffff ffffff) -> ( 1 1 2 3 ) */
31 long a = (0x0ff0001+mask) >> 23;
32 /* Fix the 1 for 00 case */
33 return a & mask;
34}
35
36#endif
37
38#define REPEAT_BYTE(x) ((~0ul / 0xff) * (x))
39
40/* Return the high bit set in the first byte that is a zero */
41static inline unsigned long has_zero(unsigned long a)
42{
43 return ((a - REPEAT_BYTE(0x01)) & ~a) & REPEAT_BYTE(0x80);
44}
45
46/*
47 * Load an unaligned word from kernel space.
48 *
49 * In the (very unlikely) case of the word being a page-crosser
50 * and the next page not being mapped, take the exception and
51 * return zeroes in the non-existing part.
52 */
53static inline unsigned long load_unaligned_zeropad(const void *addr)
54{
55 unsigned long ret, dummy;
56
57 asm(
58 "1:\tmov %2,%0\n"
59 "2:\n"
60 ".section .fixup,\"ax\"\n"
61 "3:\t"
62 "lea %2,%1\n\t"
63 "and %3,%1\n\t"
64 "mov (%1),%0\n\t"
65 "leal %2,%%ecx\n\t"
66 "andl %4,%%ecx\n\t"
67 "shll $3,%%ecx\n\t"
68 "shr %%cl,%0\n\t"
69 "jmp 2b\n"
70 ".previous\n"
71 _ASM_EXTABLE(1b, 3b)
72 :"=&r" (ret),"=&c" (dummy)
73 :"m" (*(unsigned long *)addr),
74 "i" (-sizeof(unsigned long)),
75 "i" (sizeof(unsigned long)-1));
76 return ret;
77}
78
79#endif /* _ASM_WORD_AT_A_TIME_H */
diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
index baaca8defec8..764b66a4cf89 100644
--- a/arch/x86/include/asm/x86_init.h
+++ b/arch/x86/include/asm/x86_init.h
@@ -195,6 +195,5 @@ extern struct x86_msi_ops x86_msi;
195 195
196extern void x86_init_noop(void); 196extern void x86_init_noop(void);
197extern void x86_init_uint_noop(unsigned int unused); 197extern void x86_init_uint_noop(unsigned int unused);
198extern void x86_default_fixup_cpu_id(struct cpuinfo_x86 *c, int node);
199 198
200#endif 199#endif
diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
index 103b6ab368d3..146a49c763a4 100644
--- a/arch/x86/kernel/acpi/sleep.c
+++ b/arch/x86/kernel/acpi/sleep.c
@@ -24,6 +24,10 @@ unsigned long acpi_realmode_flags;
24static char temp_stack[4096]; 24static char temp_stack[4096];
25#endif 25#endif
26 26
27asmlinkage void acpi_enter_s3(void)
28{
29 acpi_enter_sleep_state(3, wake_sleep_flags);
30}
27/** 31/**
28 * acpi_suspend_lowlevel - save kernel state 32 * acpi_suspend_lowlevel - save kernel state
29 * 33 *
diff --git a/arch/x86/kernel/acpi/sleep.h b/arch/x86/kernel/acpi/sleep.h
index 416d4be13fef..d68677a2a010 100644
--- a/arch/x86/kernel/acpi/sleep.h
+++ b/arch/x86/kernel/acpi/sleep.h
@@ -3,12 +3,16 @@
3 */ 3 */
4 4
5#include <asm/trampoline.h> 5#include <asm/trampoline.h>
6#include <linux/linkage.h>
6 7
7extern unsigned long saved_video_mode; 8extern unsigned long saved_video_mode;
8extern long saved_magic; 9extern long saved_magic;
9 10
10extern int wakeup_pmode_return; 11extern int wakeup_pmode_return;
11 12
13extern u8 wake_sleep_flags;
14extern asmlinkage void acpi_enter_s3(void);
15
12extern unsigned long acpi_copy_wakeup_routine(unsigned long); 16extern unsigned long acpi_copy_wakeup_routine(unsigned long);
13extern void wakeup_long64(void); 17extern void wakeup_long64(void);
14 18
diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
index 13ab720573e3..72610839f03b 100644
--- a/arch/x86/kernel/acpi/wakeup_32.S
+++ b/arch/x86/kernel/acpi/wakeup_32.S
@@ -74,9 +74,7 @@ restore_registers:
74ENTRY(do_suspend_lowlevel) 74ENTRY(do_suspend_lowlevel)
75 call save_processor_state 75 call save_processor_state
76 call save_registers 76 call save_registers
77 pushl $3 77 call acpi_enter_s3
78 call acpi_enter_sleep_state
79 addl $4, %esp
80 78
81# In case of S3 failure, we'll emerge here. Jump 79# In case of S3 failure, we'll emerge here. Jump
82# to ret_point to recover 80# to ret_point to recover
diff --git a/arch/x86/kernel/acpi/wakeup_64.S b/arch/x86/kernel/acpi/wakeup_64.S
index 8ea5164cbd04..014d1d28c397 100644
--- a/arch/x86/kernel/acpi/wakeup_64.S
+++ b/arch/x86/kernel/acpi/wakeup_64.S
@@ -71,9 +71,7 @@ ENTRY(do_suspend_lowlevel)
71 movq %rsi, saved_rsi 71 movq %rsi, saved_rsi
72 72
73 addq $8, %rsp 73 addq $8, %rsp
74 movl $3, %edi 74 call acpi_enter_s3
75 xorl %eax, %eax
76 call acpi_enter_sleep_state
77 /* in case something went wrong, restore the machine status and go on */ 75 /* in case something went wrong, restore the machine status and go on */
78 jmp resume_point 76 jmp resume_point
79 77
diff --git a/arch/x86/kernel/amd_gart_64.c b/arch/x86/kernel/amd_gart_64.c
index b1e7c7f7a0af..e66311200cbd 100644
--- a/arch/x86/kernel/amd_gart_64.c
+++ b/arch/x86/kernel/amd_gart_64.c
@@ -477,7 +477,7 @@ error:
477/* allocate and map a coherent mapping */ 477/* allocate and map a coherent mapping */
478static void * 478static void *
479gart_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_addr, 479gart_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_addr,
480 gfp_t flag) 480 gfp_t flag, struct dma_attrs *attrs)
481{ 481{
482 dma_addr_t paddr; 482 dma_addr_t paddr;
483 unsigned long align_mask; 483 unsigned long align_mask;
@@ -500,7 +500,8 @@ gart_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_addr,
500 } 500 }
501 __free_pages(page, get_order(size)); 501 __free_pages(page, get_order(size));
502 } else 502 } else
503 return dma_generic_alloc_coherent(dev, size, dma_addr, flag); 503 return dma_generic_alloc_coherent(dev, size, dma_addr, flag,
504 attrs);
504 505
505 return NULL; 506 return NULL;
506} 507}
@@ -508,7 +509,7 @@ gart_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_addr,
508/* free a coherent mapping */ 509/* free a coherent mapping */
509static void 510static void
510gart_free_coherent(struct device *dev, size_t size, void *vaddr, 511gart_free_coherent(struct device *dev, size_t size, void *vaddr,
511 dma_addr_t dma_addr) 512 dma_addr_t dma_addr, struct dma_attrs *attrs)
512{ 513{
513 gart_unmap_page(dev, dma_addr, size, DMA_BIDIRECTIONAL, NULL); 514 gart_unmap_page(dev, dma_addr, size, DMA_BIDIRECTIONAL, NULL);
514 free_pages((unsigned long)vaddr, get_order(size)); 515 free_pages((unsigned long)vaddr, get_order(size));
@@ -700,8 +701,8 @@ static struct dma_map_ops gart_dma_ops = {
700 .unmap_sg = gart_unmap_sg, 701 .unmap_sg = gart_unmap_sg,
701 .map_page = gart_map_page, 702 .map_page = gart_map_page,
702 .unmap_page = gart_unmap_page, 703 .unmap_page = gart_unmap_page,
703 .alloc_coherent = gart_alloc_coherent, 704 .alloc = gart_alloc_coherent,
704 .free_coherent = gart_free_coherent, 705 .free = gart_free_coherent,
705 .mapping_error = gart_mapping_error, 706 .mapping_error = gart_mapping_error,
706}; 707};
707 708
diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index 11544d8f1e97..edc24480469f 100644
--- a/arch/x86/kernel/apic/apic.c
+++ b/arch/x86/kernel/apic/apic.c
@@ -1637,9 +1637,11 @@ static int __init apic_verify(void)
1637 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE; 1637 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
1638 1638
1639 /* The BIOS may have set up the APIC at some other address */ 1639 /* The BIOS may have set up the APIC at some other address */
1640 rdmsr(MSR_IA32_APICBASE, l, h); 1640 if (boot_cpu_data.x86 >= 6) {
1641 if (l & MSR_IA32_APICBASE_ENABLE) 1641 rdmsr(MSR_IA32_APICBASE, l, h);
1642 mp_lapic_addr = l & MSR_IA32_APICBASE_BASE; 1642 if (l & MSR_IA32_APICBASE_ENABLE)
1643 mp_lapic_addr = l & MSR_IA32_APICBASE_BASE;
1644 }
1643 1645
1644 pr_info("Found and enabled local APIC!\n"); 1646 pr_info("Found and enabled local APIC!\n");
1645 return 0; 1647 return 0;
@@ -1657,13 +1659,15 @@ int __init apic_force_enable(unsigned long addr)
1657 * MSR. This can only be done in software for Intel P6 or later 1659 * MSR. This can only be done in software for Intel P6 or later
1658 * and AMD K7 (Model > 1) or later. 1660 * and AMD K7 (Model > 1) or later.
1659 */ 1661 */
1660 rdmsr(MSR_IA32_APICBASE, l, h); 1662 if (boot_cpu_data.x86 >= 6) {
1661 if (!(l & MSR_IA32_APICBASE_ENABLE)) { 1663 rdmsr(MSR_IA32_APICBASE, l, h);
1662 pr_info("Local APIC disabled by BIOS -- reenabling.\n"); 1664 if (!(l & MSR_IA32_APICBASE_ENABLE)) {
1663 l &= ~MSR_IA32_APICBASE_BASE; 1665 pr_info("Local APIC disabled by BIOS -- reenabling.\n");
1664 l |= MSR_IA32_APICBASE_ENABLE | addr; 1666 l &= ~MSR_IA32_APICBASE_BASE;
1665 wrmsr(MSR_IA32_APICBASE, l, h); 1667 l |= MSR_IA32_APICBASE_ENABLE | addr;
1666 enabled_via_apicbase = 1; 1668 wrmsr(MSR_IA32_APICBASE, l, h);
1669 enabled_via_apicbase = 1;
1670 }
1667 } 1671 }
1668 return apic_verify(); 1672 return apic_verify();
1669} 1673}
@@ -2209,10 +2213,12 @@ static void lapic_resume(void)
2209 * FIXME! This will be wrong if we ever support suspend on 2213 * FIXME! This will be wrong if we ever support suspend on
2210 * SMP! We'll need to do this as part of the CPU restore! 2214 * SMP! We'll need to do this as part of the CPU restore!
2211 */ 2215 */
2212 rdmsr(MSR_IA32_APICBASE, l, h); 2216 if (boot_cpu_data.x86 >= 6) {
2213 l &= ~MSR_IA32_APICBASE_BASE; 2217 rdmsr(MSR_IA32_APICBASE, l, h);
2214 l |= MSR_IA32_APICBASE_ENABLE | mp_lapic_addr; 2218 l &= ~MSR_IA32_APICBASE_BASE;
2215 wrmsr(MSR_IA32_APICBASE, l, h); 2219 l |= MSR_IA32_APICBASE_ENABLE | mp_lapic_addr;
2220 wrmsr(MSR_IA32_APICBASE, l, h);
2221 }
2216 } 2222 }
2217 2223
2218 maxlvt = lapic_get_maxlvt(); 2224 maxlvt = lapic_get_maxlvt();
diff --git a/arch/x86/kernel/apic/apic_numachip.c b/arch/x86/kernel/apic/apic_numachip.c
index 899803e03214..23e75422e013 100644
--- a/arch/x86/kernel/apic/apic_numachip.c
+++ b/arch/x86/kernel/apic/apic_numachip.c
@@ -207,8 +207,11 @@ static void __init map_csrs(void)
207 207
208static void fixup_cpu_id(struct cpuinfo_x86 *c, int node) 208static void fixup_cpu_id(struct cpuinfo_x86 *c, int node)
209{ 209{
210 c->phys_proc_id = node; 210
211 per_cpu(cpu_llc_id, smp_processor_id()) = node; 211 if (c->phys_proc_id != node) {
212 c->phys_proc_id = node;
213 per_cpu(cpu_llc_id, smp_processor_id()) = node;
214 }
212} 215}
213 216
214static int __init numachip_system_init(void) 217static int __init numachip_system_init(void)
diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
index 8a778db45e3a..991e315f4227 100644
--- a/arch/x86/kernel/apic/x2apic_phys.c
+++ b/arch/x86/kernel/apic/x2apic_phys.c
@@ -24,6 +24,12 @@ static int x2apic_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
24{ 24{
25 if (x2apic_phys) 25 if (x2apic_phys)
26 return x2apic_enabled(); 26 return x2apic_enabled();
27 else if ((acpi_gbl_FADT.header.revision >= FADT2_REVISION_ID) &&
28 (acpi_gbl_FADT.flags & ACPI_FADT_APIC_PHYSICAL) &&
29 x2apic_enabled()) {
30 printk(KERN_DEBUG "System requires x2apic physical mode\n");
31 return 1;
32 }
27 else 33 else
28 return 0; 34 return 0;
29} 35}
diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
index 0a44b90602b0..146bb6218eec 100644
--- a/arch/x86/kernel/cpu/amd.c
+++ b/arch/x86/kernel/cpu/amd.c
@@ -26,7 +26,8 @@
26 * contact AMD for precise details and a CPU swap. 26 * contact AMD for precise details and a CPU swap.
27 * 27 *
28 * See http://www.multimania.com/poulot/k6bug.html 28 * See http://www.multimania.com/poulot/k6bug.html
29 * http://www.amd.com/K6/k6docs/revgd.html 29 * and section 2.6.2 of "AMD-K6 Processor Revision Guide - Model 6"
30 * (Publication # 21266 Issue Date: August 1998)
30 * 31 *
31 * The following test is erm.. interesting. AMD neglected to up 32 * The following test is erm.. interesting. AMD neglected to up
32 * the chip setting when fixing the bug but they also tweaked some 33 * the chip setting when fixing the bug but they also tweaked some
@@ -94,7 +95,6 @@ static void __cpuinit init_amd_k6(struct cpuinfo_x86 *c)
94 "system stability may be impaired when more than 32 MB are used.\n"); 95 "system stability may be impaired when more than 32 MB are used.\n");
95 else 96 else
96 printk(KERN_CONT "probably OK (after B9730xxxx).\n"); 97 printk(KERN_CONT "probably OK (after B9730xxxx).\n");
97 printk(KERN_INFO "Please see http://membres.lycos.fr/poulot/k6bug.html\n");
98 } 98 }
99 99
100 /* K6 with old style WHCR */ 100 /* K6 with old style WHCR */
@@ -353,10 +353,11 @@ static void __cpuinit srat_detect_node(struct cpuinfo_x86 *c)
353 node = per_cpu(cpu_llc_id, cpu); 353 node = per_cpu(cpu_llc_id, cpu);
354 354
355 /* 355 /*
356 * If core numbers are inconsistent, it's likely a multi-fabric platform, 356 * On multi-fabric platform (e.g. Numascale NumaChip) a
357 * so invoke platform-specific handler 357 * platform-specific handler needs to be called to fixup some
358 * IDs of the CPU.
358 */ 359 */
359 if (c->phys_proc_id != node) 360 if (x86_cpuinit.fixup_cpu_id)
360 x86_cpuinit.fixup_cpu_id(c, node); 361 x86_cpuinit.fixup_cpu_id(c, node);
361 362
362 if (!node_online(node)) { 363 if (!node_online(node)) {
@@ -579,6 +580,24 @@ static void __cpuinit init_amd(struct cpuinfo_x86 *c)
579 } 580 }
580 } 581 }
581 582
583 /* re-enable TopologyExtensions if switched off by BIOS */
584 if ((c->x86 == 0x15) &&
585 (c->x86_model >= 0x10) && (c->x86_model <= 0x1f) &&
586 !cpu_has(c, X86_FEATURE_TOPOEXT)) {
587 u64 val;
588
589 if (!rdmsrl_amd_safe(0xc0011005, &val)) {
590 val |= 1ULL << 54;
591 wrmsrl_amd_safe(0xc0011005, val);
592 rdmsrl(0xc0011005, val);
593 if (val & (1ULL << 54)) {
594 set_cpu_cap(c, X86_FEATURE_TOPOEXT);
595 printk(KERN_INFO FW_INFO "CPU: Re-enabling "
596 "disabled Topology Extensions Support\n");
597 }
598 }
599 }
600
582 cpu_detect_cache_sizes(c); 601 cpu_detect_cache_sizes(c);
583 602
584 /* Multi core CPU? */ 603 /* Multi core CPU? */
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index 67e258362a3d..cf79302198a6 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -1163,15 +1163,6 @@ static void dbg_restore_debug_regs(void)
1163#endif /* ! CONFIG_KGDB */ 1163#endif /* ! CONFIG_KGDB */
1164 1164
1165/* 1165/*
1166 * Prints an error where the NUMA and configured core-number mismatch and the
1167 * platform didn't override this to fix it up
1168 */
1169void __cpuinit x86_default_fixup_cpu_id(struct cpuinfo_x86 *c, int node)
1170{
1171 pr_err("NUMA core number %d differs from configured core number %d\n", node, c->phys_proc_id);
1172}
1173
1174/*
1175 * cpu_init() initializes state that is per-CPU. Some data is already 1166 * cpu_init() initializes state that is per-CPU. Some data is already
1176 * initialized (naturally) in the bootstrap process, such as the GDT 1167 * initialized (naturally) in the bootstrap process, such as the GDT
1177 * and IDT. We reload them nevertheless, this function acts as a 1168 * and IDT. We reload them nevertheless, this function acts as a
diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
index 73d08ed98a64..b8f3653dddbc 100644
--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
@@ -433,14 +433,14 @@ int amd_set_l3_disable_slot(struct amd_northbridge *nb, int cpu, unsigned slot,
433 /* check if @slot is already used or the index is already disabled */ 433 /* check if @slot is already used or the index is already disabled */
434 ret = amd_get_l3_disable_slot(nb, slot); 434 ret = amd_get_l3_disable_slot(nb, slot);
435 if (ret >= 0) 435 if (ret >= 0)
436 return -EINVAL; 436 return -EEXIST;
437 437
438 if (index > nb->l3_cache.indices) 438 if (index > nb->l3_cache.indices)
439 return -EINVAL; 439 return -EINVAL;
440 440
441 /* check whether the other slot has disabled the same index already */ 441 /* check whether the other slot has disabled the same index already */
442 if (index == amd_get_l3_disable_slot(nb, !slot)) 442 if (index == amd_get_l3_disable_slot(nb, !slot))
443 return -EINVAL; 443 return -EEXIST;
444 444
445 amd_l3_disable_index(nb, cpu, slot, index); 445 amd_l3_disable_index(nb, cpu, slot, index);
446 446
@@ -468,8 +468,8 @@ static ssize_t store_cache_disable(struct _cpuid4_info *this_leaf,
468 err = amd_set_l3_disable_slot(this_leaf->base.nb, cpu, slot, val); 468 err = amd_set_l3_disable_slot(this_leaf->base.nb, cpu, slot, val);
469 if (err) { 469 if (err) {
470 if (err == -EEXIST) 470 if (err == -EEXIST)
471 printk(KERN_WARNING "L3 disable slot %d in use!\n", 471 pr_warning("L3 slot %d in use/index already disabled!\n",
472 slot); 472 slot);
473 return err; 473 return err;
474 } 474 }
475 return count; 475 return count;
diff --git a/arch/x86/kernel/cpu/perf_event_p4.c b/arch/x86/kernel/cpu/perf_event_p4.c
index ef484d9d0a25..a2dfacfd7103 100644
--- a/arch/x86/kernel/cpu/perf_event_p4.c
+++ b/arch/x86/kernel/cpu/perf_event_p4.c
@@ -1271,6 +1271,17 @@ done:
1271 return num ? -EINVAL : 0; 1271 return num ? -EINVAL : 0;
1272} 1272}
1273 1273
1274PMU_FORMAT_ATTR(cccr, "config:0-31" );
1275PMU_FORMAT_ATTR(escr, "config:32-62");
1276PMU_FORMAT_ATTR(ht, "config:63" );
1277
1278static struct attribute *intel_p4_formats_attr[] = {
1279 &format_attr_cccr.attr,
1280 &format_attr_escr.attr,
1281 &format_attr_ht.attr,
1282 NULL,
1283};
1284
1274static __initconst const struct x86_pmu p4_pmu = { 1285static __initconst const struct x86_pmu p4_pmu = {
1275 .name = "Netburst P4/Xeon", 1286 .name = "Netburst P4/Xeon",
1276 .handle_irq = p4_pmu_handle_irq, 1287 .handle_irq = p4_pmu_handle_irq,
@@ -1305,6 +1316,8 @@ static __initconst const struct x86_pmu p4_pmu = {
1305 * the former idea is taken from OProfile code 1316 * the former idea is taken from OProfile code
1306 */ 1317 */
1307 .perfctr_second_write = 1, 1318 .perfctr_second_write = 1,
1319
1320 .format_attrs = intel_p4_formats_attr,
1308}; 1321};
1309 1322
1310__init int p4_pmu_init(void) 1323__init int p4_pmu_init(void)
diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
index 7734bcbb5a3a..2d6e6498c176 100644
--- a/arch/x86/kernel/i387.c
+++ b/arch/x86/kernel/i387.c
@@ -235,6 +235,7 @@ int init_fpu(struct task_struct *tsk)
235 if (tsk_used_math(tsk)) { 235 if (tsk_used_math(tsk)) {
236 if (HAVE_HWFP && tsk == current) 236 if (HAVE_HWFP && tsk == current)
237 unlazy_fpu(tsk); 237 unlazy_fpu(tsk);
238 tsk->thread.fpu.last_cpu = ~0;
238 return 0; 239 return 0;
239 } 240 }
240 241
diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
index 7943e0c21bde..3dafc6003b7c 100644
--- a/arch/x86/kernel/irq.c
+++ b/arch/x86/kernel/irq.c
@@ -282,8 +282,13 @@ void fixup_irqs(void)
282 else if (!(warned++)) 282 else if (!(warned++))
283 set_affinity = 0; 283 set_affinity = 0;
284 284
285 /*
286 * We unmask if the irq was not marked masked by the
287 * core code. That respects the lazy irq disable
288 * behaviour.
289 */
285 if (!irqd_can_move_in_process_context(data) && 290 if (!irqd_can_move_in_process_context(data) &&
286 !irqd_irq_disabled(data) && chip->irq_unmask) 291 !irqd_irq_masked(data) && chip->irq_unmask)
287 chip->irq_unmask(data); 292 chip->irq_unmask(data);
288 293
289 raw_spin_unlock(&desc->lock); 294 raw_spin_unlock(&desc->lock);
diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
index 90fcf62854bb..1d5d31ea686b 100644
--- a/arch/x86/kernel/kdebugfs.c
+++ b/arch/x86/kernel/kdebugfs.c
@@ -68,16 +68,9 @@ static ssize_t setup_data_read(struct file *file, char __user *user_buf,
68 return count; 68 return count;
69} 69}
70 70
71static int setup_data_open(struct inode *inode, struct file *file)
72{
73 file->private_data = inode->i_private;
74
75 return 0;
76}
77
78static const struct file_operations fops_setup_data = { 71static const struct file_operations fops_setup_data = {
79 .read = setup_data_read, 72 .read = setup_data_read,
80 .open = setup_data_open, 73 .open = simple_open,
81 .llseek = default_llseek, 74 .llseek = default_llseek,
82}; 75};
83 76
diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
index db6720edfdd0..8bfb6146f753 100644
--- a/arch/x86/kernel/kgdb.c
+++ b/arch/x86/kernel/kgdb.c
@@ -43,6 +43,8 @@
43#include <linux/smp.h> 43#include <linux/smp.h>
44#include <linux/nmi.h> 44#include <linux/nmi.h>
45#include <linux/hw_breakpoint.h> 45#include <linux/hw_breakpoint.h>
46#include <linux/uaccess.h>
47#include <linux/memory.h>
46 48
47#include <asm/debugreg.h> 49#include <asm/debugreg.h>
48#include <asm/apicdef.h> 50#include <asm/apicdef.h>
@@ -741,6 +743,64 @@ void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long ip)
741 regs->ip = ip; 743 regs->ip = ip;
742} 744}
743 745
746int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
747{
748 int err;
749 char opc[BREAK_INSTR_SIZE];
750
751 bpt->type = BP_BREAKPOINT;
752 err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
753 BREAK_INSTR_SIZE);
754 if (err)
755 return err;
756 err = probe_kernel_write((char *)bpt->bpt_addr,
757 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
758#ifdef CONFIG_DEBUG_RODATA
759 if (!err)
760 return err;
761 /*
762 * It is safe to call text_poke() because normal kernel execution
763 * is stopped on all cores, so long as the text_mutex is not locked.
764 */
765 if (mutex_is_locked(&text_mutex))
766 return -EBUSY;
767 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
768 BREAK_INSTR_SIZE);
769 err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
770 if (err)
771 return err;
772 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
773 return -EINVAL;
774 bpt->type = BP_POKE_BREAKPOINT;
775#endif /* CONFIG_DEBUG_RODATA */
776 return err;
777}
778
779int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
780{
781#ifdef CONFIG_DEBUG_RODATA
782 int err;
783 char opc[BREAK_INSTR_SIZE];
784
785 if (bpt->type != BP_POKE_BREAKPOINT)
786 goto knl_write;
787 /*
788 * It is safe to call text_poke() because normal kernel execution
789 * is stopped on all cores, so long as the text_mutex is not locked.
790 */
791 if (mutex_is_locked(&text_mutex))
792 goto knl_write;
793 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
794 err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
795 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
796 goto knl_write;
797 return err;
798knl_write:
799#endif /* CONFIG_DEBUG_RODATA */
800 return probe_kernel_write((char *)bpt->bpt_addr,
801 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
802}
803
744struct kgdb_arch arch_kgdb_ops = { 804struct kgdb_arch arch_kgdb_ops = {
745 /* Breakpoint instruction: */ 805 /* Breakpoint instruction: */
746 .gdb_bpt_instr = { 0xcc }, 806 .gdb_bpt_instr = { 0xcc },
diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
index 694d801bf606..e554e5ad2fe8 100644
--- a/arch/x86/kernel/kvm.c
+++ b/arch/x86/kernel/kvm.c
@@ -38,6 +38,7 @@
38#include <asm/traps.h> 38#include <asm/traps.h>
39#include <asm/desc.h> 39#include <asm/desc.h>
40#include <asm/tlbflush.h> 40#include <asm/tlbflush.h>
41#include <asm/idle.h>
41 42
42static int kvmapf = 1; 43static int kvmapf = 1;
43 44
@@ -78,7 +79,6 @@ struct kvm_task_sleep_node {
78 u32 token; 79 u32 token;
79 int cpu; 80 int cpu;
80 bool halted; 81 bool halted;
81 struct mm_struct *mm;
82}; 82};
83 83
84static struct kvm_task_sleep_head { 84static struct kvm_task_sleep_head {
@@ -125,9 +125,7 @@ void kvm_async_pf_task_wait(u32 token)
125 125
126 n.token = token; 126 n.token = token;
127 n.cpu = smp_processor_id(); 127 n.cpu = smp_processor_id();
128 n.mm = current->active_mm;
129 n.halted = idle || preempt_count() > 1; 128 n.halted = idle || preempt_count() > 1;
130 atomic_inc(&n.mm->mm_count);
131 init_waitqueue_head(&n.wq); 129 init_waitqueue_head(&n.wq);
132 hlist_add_head(&n.link, &b->list); 130 hlist_add_head(&n.link, &b->list);
133 spin_unlock(&b->lock); 131 spin_unlock(&b->lock);
@@ -160,9 +158,6 @@ EXPORT_SYMBOL_GPL(kvm_async_pf_task_wait);
160static void apf_task_wake_one(struct kvm_task_sleep_node *n) 158static void apf_task_wake_one(struct kvm_task_sleep_node *n)
161{ 159{
162 hlist_del_init(&n->link); 160 hlist_del_init(&n->link);
163 if (!n->mm)
164 return;
165 mmdrop(n->mm);
166 if (n->halted) 161 if (n->halted)
167 smp_send_reschedule(n->cpu); 162 smp_send_reschedule(n->cpu);
168 else if (waitqueue_active(&n->wq)) 163 else if (waitqueue_active(&n->wq))
@@ -206,7 +201,7 @@ again:
206 * async PF was not yet handled. 201 * async PF was not yet handled.
207 * Add dummy entry for the token. 202 * Add dummy entry for the token.
208 */ 203 */
209 n = kmalloc(sizeof(*n), GFP_ATOMIC); 204 n = kzalloc(sizeof(*n), GFP_ATOMIC);
210 if (!n) { 205 if (!n) {
211 /* 206 /*
212 * Allocation failed! Busy wait while other cpu 207 * Allocation failed! Busy wait while other cpu
@@ -218,7 +213,6 @@ again:
218 } 213 }
219 n->token = token; 214 n->token = token;
220 n->cpu = smp_processor_id(); 215 n->cpu = smp_processor_id();
221 n->mm = NULL;
222 init_waitqueue_head(&n->wq); 216 init_waitqueue_head(&n->wq);
223 hlist_add_head(&n->link, &b->list); 217 hlist_add_head(&n->link, &b->list);
224 } else 218 } else
@@ -253,7 +247,10 @@ do_async_page_fault(struct pt_regs *regs, unsigned long error_code)
253 kvm_async_pf_task_wait((u32)read_cr2()); 247 kvm_async_pf_task_wait((u32)read_cr2());
254 break; 248 break;
255 case KVM_PV_REASON_PAGE_READY: 249 case KVM_PV_REASON_PAGE_READY:
250 rcu_irq_enter();
251 exit_idle();
256 kvm_async_pf_task_wake((u32)read_cr2()); 252 kvm_async_pf_task_wake((u32)read_cr2());
253 rcu_irq_exit();
257 break; 254 break;
258 } 255 }
259} 256}
diff --git a/arch/x86/kernel/microcode_amd.c b/arch/x86/kernel/microcode_amd.c
index 73465aab28f8..8a2ce8fd41c0 100644
--- a/arch/x86/kernel/microcode_amd.c
+++ b/arch/x86/kernel/microcode_amd.c
@@ -82,11 +82,6 @@ static int collect_cpu_info_amd(int cpu, struct cpu_signature *csig)
82{ 82{
83 struct cpuinfo_x86 *c = &cpu_data(cpu); 83 struct cpuinfo_x86 *c = &cpu_data(cpu);
84 84
85 if (c->x86_vendor != X86_VENDOR_AMD || c->x86 < 0x10) {
86 pr_warning("CPU%d: family %d not supported\n", cpu, c->x86);
87 return -1;
88 }
89
90 csig->rev = c->microcode; 85 csig->rev = c->microcode;
91 pr_info("CPU%d: patch_level=0x%08x\n", cpu, csig->rev); 86 pr_info("CPU%d: patch_level=0x%08x\n", cpu, csig->rev);
92 87
@@ -380,6 +375,13 @@ static struct microcode_ops microcode_amd_ops = {
380 375
381struct microcode_ops * __init init_amd_microcode(void) 376struct microcode_ops * __init init_amd_microcode(void)
382{ 377{
378 struct cpuinfo_x86 *c = &cpu_data(0);
379
380 if (c->x86_vendor != X86_VENDOR_AMD || c->x86 < 0x10) {
381 pr_warning("AMD CPU family 0x%x not supported\n", c->x86);
382 return NULL;
383 }
384
383 patch = (void *)get_zeroed_page(GFP_KERNEL); 385 patch = (void *)get_zeroed_page(GFP_KERNEL);
384 if (!patch) 386 if (!patch)
385 return NULL; 387 return NULL;
diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
index 87a0f8688301..c9bda6d6035c 100644
--- a/arch/x86/kernel/microcode_core.c
+++ b/arch/x86/kernel/microcode_core.c
@@ -419,10 +419,8 @@ static int mc_device_add(struct device *dev, struct subsys_interface *sif)
419 if (err) 419 if (err)
420 return err; 420 return err;
421 421
422 if (microcode_init_cpu(cpu) == UCODE_ERROR) { 422 if (microcode_init_cpu(cpu) == UCODE_ERROR)
423 sysfs_remove_group(&dev->kobj, &mc_attr_group);
424 return -EINVAL; 423 return -EINVAL;
425 }
426 424
427 return err; 425 return err;
428} 426}
@@ -528,11 +526,11 @@ static int __init microcode_init(void)
528 microcode_ops = init_intel_microcode(); 526 microcode_ops = init_intel_microcode();
529 else if (c->x86_vendor == X86_VENDOR_AMD) 527 else if (c->x86_vendor == X86_VENDOR_AMD)
530 microcode_ops = init_amd_microcode(); 528 microcode_ops = init_amd_microcode();
531 529 else
532 if (!microcode_ops) {
533 pr_err("no support for this CPU vendor\n"); 530 pr_err("no support for this CPU vendor\n");
531
532 if (!microcode_ops)
534 return -ENODEV; 533 return -ENODEV;
535 }
536 534
537 microcode_pdev = platform_device_register_simple("microcode", -1, 535 microcode_pdev = platform_device_register_simple("microcode", -1,
538 NULL, 0); 536 NULL, 0);
diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
index 6ac5782f4d6b..d0b2fb9ccbb1 100644
--- a/arch/x86/kernel/pci-calgary_64.c
+++ b/arch/x86/kernel/pci-calgary_64.c
@@ -430,7 +430,7 @@ static void calgary_unmap_page(struct device *dev, dma_addr_t dma_addr,
430} 430}
431 431
432static void* calgary_alloc_coherent(struct device *dev, size_t size, 432static void* calgary_alloc_coherent(struct device *dev, size_t size,
433 dma_addr_t *dma_handle, gfp_t flag) 433 dma_addr_t *dma_handle, gfp_t flag, struct dma_attrs *attrs)
434{ 434{
435 void *ret = NULL; 435 void *ret = NULL;
436 dma_addr_t mapping; 436 dma_addr_t mapping;
@@ -463,7 +463,8 @@ error:
463} 463}
464 464
465static void calgary_free_coherent(struct device *dev, size_t size, 465static void calgary_free_coherent(struct device *dev, size_t size,
466 void *vaddr, dma_addr_t dma_handle) 466 void *vaddr, dma_addr_t dma_handle,
467 struct dma_attrs *attrs)
467{ 468{
468 unsigned int npages; 469 unsigned int npages;
469 struct iommu_table *tbl = find_iommu_table(dev); 470 struct iommu_table *tbl = find_iommu_table(dev);
@@ -476,8 +477,8 @@ static void calgary_free_coherent(struct device *dev, size_t size,
476} 477}
477 478
478static struct dma_map_ops calgary_dma_ops = { 479static struct dma_map_ops calgary_dma_ops = {
479 .alloc_coherent = calgary_alloc_coherent, 480 .alloc = calgary_alloc_coherent,
480 .free_coherent = calgary_free_coherent, 481 .free = calgary_free_coherent,
481 .map_sg = calgary_map_sg, 482 .map_sg = calgary_map_sg,
482 .unmap_sg = calgary_unmap_sg, 483 .unmap_sg = calgary_unmap_sg,
483 .map_page = calgary_map_page, 484 .map_page = calgary_map_page,
diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
index 28e5e06fcba4..3003250ac51d 100644
--- a/arch/x86/kernel/pci-dma.c
+++ b/arch/x86/kernel/pci-dma.c
@@ -96,7 +96,8 @@ void __init pci_iommu_alloc(void)
96 } 96 }
97} 97}
98void *dma_generic_alloc_coherent(struct device *dev, size_t size, 98void *dma_generic_alloc_coherent(struct device *dev, size_t size,
99 dma_addr_t *dma_addr, gfp_t flag) 99 dma_addr_t *dma_addr, gfp_t flag,
100 struct dma_attrs *attrs)
100{ 101{
101 unsigned long dma_mask; 102 unsigned long dma_mask;
102 struct page *page; 103 struct page *page;
diff --git a/arch/x86/kernel/pci-nommu.c b/arch/x86/kernel/pci-nommu.c
index 3af4af810c07..f96050685b46 100644
--- a/arch/x86/kernel/pci-nommu.c
+++ b/arch/x86/kernel/pci-nommu.c
@@ -75,7 +75,7 @@ static int nommu_map_sg(struct device *hwdev, struct scatterlist *sg,
75} 75}
76 76
77static void nommu_free_coherent(struct device *dev, size_t size, void *vaddr, 77static void nommu_free_coherent(struct device *dev, size_t size, void *vaddr,
78 dma_addr_t dma_addr) 78 dma_addr_t dma_addr, struct dma_attrs *attrs)
79{ 79{
80 free_pages((unsigned long)vaddr, get_order(size)); 80 free_pages((unsigned long)vaddr, get_order(size));
81} 81}
@@ -96,8 +96,8 @@ static void nommu_sync_sg_for_device(struct device *dev,
96} 96}
97 97
98struct dma_map_ops nommu_dma_ops = { 98struct dma_map_ops nommu_dma_ops = {
99 .alloc_coherent = dma_generic_alloc_coherent, 99 .alloc = dma_generic_alloc_coherent,
100 .free_coherent = nommu_free_coherent, 100 .free = nommu_free_coherent,
101 .map_sg = nommu_map_sg, 101 .map_sg = nommu_map_sg,
102 .map_page = nommu_map_page, 102 .map_page = nommu_map_page,
103 .sync_single_for_device = nommu_sync_single_for_device, 103 .sync_single_for_device = nommu_sync_single_for_device,
diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
index 8f972cbddef0..6c483ba98b9c 100644
--- a/arch/x86/kernel/pci-swiotlb.c
+++ b/arch/x86/kernel/pci-swiotlb.c
@@ -15,21 +15,30 @@
15int swiotlb __read_mostly; 15int swiotlb __read_mostly;
16 16
17static void *x86_swiotlb_alloc_coherent(struct device *hwdev, size_t size, 17static void *x86_swiotlb_alloc_coherent(struct device *hwdev, size_t size,
18 dma_addr_t *dma_handle, gfp_t flags) 18 dma_addr_t *dma_handle, gfp_t flags,
19 struct dma_attrs *attrs)
19{ 20{
20 void *vaddr; 21 void *vaddr;
21 22
22 vaddr = dma_generic_alloc_coherent(hwdev, size, dma_handle, flags); 23 vaddr = dma_generic_alloc_coherent(hwdev, size, dma_handle, flags,
24 attrs);
23 if (vaddr) 25 if (vaddr)
24 return vaddr; 26 return vaddr;
25 27
26 return swiotlb_alloc_coherent(hwdev, size, dma_handle, flags); 28 return swiotlb_alloc_coherent(hwdev, size, dma_handle, flags);
27} 29}
28 30
31static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
32 void *vaddr, dma_addr_t dma_addr,
33 struct dma_attrs *attrs)
34{
35 swiotlb_free_coherent(dev, size, vaddr, dma_addr);
36}
37
29static struct dma_map_ops swiotlb_dma_ops = { 38static struct dma_map_ops swiotlb_dma_ops = {
30 .mapping_error = swiotlb_dma_mapping_error, 39 .mapping_error = swiotlb_dma_mapping_error,
31 .alloc_coherent = x86_swiotlb_alloc_coherent, 40 .alloc = x86_swiotlb_alloc_coherent,
32 .free_coherent = swiotlb_free_coherent, 41 .free = x86_swiotlb_free_coherent,
33 .sync_single_for_cpu = swiotlb_sync_single_for_cpu, 42 .sync_single_for_cpu = swiotlb_sync_single_for_cpu,
34 .sync_single_for_device = swiotlb_sync_single_for_device, 43 .sync_single_for_device = swiotlb_sync_single_for_device,
35 .sync_sg_for_cpu = swiotlb_sync_sg_for_cpu, 44 .sync_sg_for_cpu = swiotlb_sync_sg_for_cpu,
diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
index a33afaa5ddb7..1d92a5ab6e8b 100644
--- a/arch/x86/kernel/process.c
+++ b/arch/x86/kernel/process.c
@@ -362,34 +362,10 @@ void (*pm_idle)(void);
362EXPORT_SYMBOL(pm_idle); 362EXPORT_SYMBOL(pm_idle);
363#endif 363#endif
364 364
365#ifdef CONFIG_X86_32
366/*
367 * This halt magic was a workaround for ancient floppy DMA
368 * wreckage. It should be safe to remove.
369 */
370static int hlt_counter;
371void disable_hlt(void)
372{
373 hlt_counter++;
374}
375EXPORT_SYMBOL(disable_hlt);
376
377void enable_hlt(void)
378{
379 hlt_counter--;
380}
381EXPORT_SYMBOL(enable_hlt);
382
383static inline int hlt_use_halt(void)
384{
385 return (!hlt_counter && boot_cpu_data.hlt_works_ok);
386}
387#else
388static inline int hlt_use_halt(void) 365static inline int hlt_use_halt(void)
389{ 366{
390 return 1; 367 return 1;
391} 368}
392#endif
393 369
394#ifndef CONFIG_SMP 370#ifndef CONFIG_SMP
395static inline void play_dead(void) 371static inline void play_dead(void)
diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
index 733ca39f367e..43d8b48b23e6 100644
--- a/arch/x86/kernel/process_64.c
+++ b/arch/x86/kernel/process_64.c
@@ -423,6 +423,7 @@ void set_personality_ia32(bool x32)
423 current_thread_info()->status |= TS_COMPAT; 423 current_thread_info()->status |= TS_COMPAT;
424 } 424 }
425} 425}
426EXPORT_SYMBOL_GPL(set_personality_ia32);
426 427
427unsigned long get_wchan(struct task_struct *p) 428unsigned long get_wchan(struct task_struct *p)
428{ 429{
diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
index 71f4727da373..5a98aa272184 100644
--- a/arch/x86/kernel/setup_percpu.c
+++ b/arch/x86/kernel/setup_percpu.c
@@ -185,10 +185,22 @@ void __init setup_per_cpu_areas(void)
185#endif 185#endif
186 rc = -EINVAL; 186 rc = -EINVAL;
187 if (pcpu_chosen_fc != PCPU_FC_PAGE) { 187 if (pcpu_chosen_fc != PCPU_FC_PAGE) {
188 const size_t atom_size = cpu_has_pse ? PMD_SIZE : PAGE_SIZE;
189 const size_t dyn_size = PERCPU_MODULE_RESERVE + 188 const size_t dyn_size = PERCPU_MODULE_RESERVE +
190 PERCPU_DYNAMIC_RESERVE - PERCPU_FIRST_CHUNK_RESERVE; 189 PERCPU_DYNAMIC_RESERVE - PERCPU_FIRST_CHUNK_RESERVE;
190 size_t atom_size;
191 191
192 /*
193 * On 64bit, use PMD_SIZE for atom_size so that embedded
194 * percpu areas are aligned to PMD. This, in the future,
195 * can also allow using PMD mappings in vmalloc area. Use
196 * PAGE_SIZE on 32bit as vmalloc space is highly contended
197 * and large vmalloc area allocs can easily fail.
198 */
199#ifdef CONFIG_X86_64
200 atom_size = PMD_SIZE;
201#else
202 atom_size = PAGE_SIZE;
203#endif
192 rc = pcpu_embed_first_chunk(PERCPU_FIRST_CHUNK_RESERVE, 204 rc = pcpu_embed_first_chunk(PERCPU_FIRST_CHUNK_RESERVE,
193 dyn_size, atom_size, 205 dyn_size, atom_size,
194 pcpu_cpu_distance, 206 pcpu_cpu_distance,
diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
index f386dc49f988..7515cf0e1805 100644
--- a/arch/x86/kernel/vsyscall_64.c
+++ b/arch/x86/kernel/vsyscall_64.c
@@ -216,9 +216,9 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
216 current_thread_info()->sig_on_uaccess_error = 1; 216 current_thread_info()->sig_on_uaccess_error = 1;
217 217
218 /* 218 /*
219 * 0 is a valid user pointer (in the access_ok sense) on 32-bit and 219 * NULL is a valid user pointer (in the access_ok sense) on 32-bit and
220 * 64-bit, so we don't need to special-case it here. For all the 220 * 64-bit, so we don't need to special-case it here. For all the
221 * vsyscalls, 0 means "don't write anything" not "write it at 221 * vsyscalls, NULL means "don't write anything" not "write it at
222 * address 0". 222 * address 0".
223 */ 223 */
224 ret = -EFAULT; 224 ret = -EFAULT;
@@ -247,7 +247,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
247 247
248 ret = sys_getcpu((unsigned __user *)regs->di, 248 ret = sys_getcpu((unsigned __user *)regs->di,
249 (unsigned __user *)regs->si, 249 (unsigned __user *)regs->si,
250 0); 250 NULL);
251 break; 251 break;
252 } 252 }
253 253
diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
index e9f265fd79ae..9cf71d0b2d37 100644
--- a/arch/x86/kernel/x86_init.c
+++ b/arch/x86/kernel/x86_init.c
@@ -93,7 +93,6 @@ struct x86_init_ops x86_init __initdata = {
93struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = { 93struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
94 .early_percpu_clock_init = x86_init_noop, 94 .early_percpu_clock_init = x86_init_noop,
95 .setup_percpu_clockev = setup_secondary_APIC_clock, 95 .setup_percpu_clockev = setup_secondary_APIC_clock,
96 .fixup_cpu_id = x86_default_fixup_cpu_id,
97}; 96};
98 97
99static void default_nmi_init(void) { }; 98static void default_nmi_init(void) { };
diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c
index a73f0c104813..2e88438ffd83 100644
--- a/arch/x86/kvm/pmu.c
+++ b/arch/x86/kvm/pmu.c
@@ -369,7 +369,7 @@ int kvm_pmu_set_msr(struct kvm_vcpu *vcpu, u32 index, u64 data)
369 case MSR_CORE_PERF_FIXED_CTR_CTRL: 369 case MSR_CORE_PERF_FIXED_CTR_CTRL:
370 if (pmu->fixed_ctr_ctrl == data) 370 if (pmu->fixed_ctr_ctrl == data)
371 return 0; 371 return 0;
372 if (!(data & 0xfffffffffffff444)) { 372 if (!(data & 0xfffffffffffff444ull)) {
373 reprogram_fixed_counters(pmu, data); 373 reprogram_fixed_counters(pmu, data);
374 return 0; 374 return 0;
375 } 375 }
@@ -459,17 +459,17 @@ void kvm_pmu_cpuid_update(struct kvm_vcpu *vcpu)
459 pmu->available_event_types = ~entry->ebx & ((1ull << bitmap_len) - 1); 459 pmu->available_event_types = ~entry->ebx & ((1ull << bitmap_len) - 1);
460 460
461 if (pmu->version == 1) { 461 if (pmu->version == 1) {
462 pmu->global_ctrl = (1 << pmu->nr_arch_gp_counters) - 1; 462 pmu->nr_arch_fixed_counters = 0;
463 return; 463 } else {
464 pmu->nr_arch_fixed_counters = min((int)(entry->edx & 0x1f),
465 X86_PMC_MAX_FIXED);
466 pmu->counter_bitmask[KVM_PMC_FIXED] =
467 ((u64)1 << ((entry->edx >> 5) & 0xff)) - 1;
464 } 468 }
465 469
466 pmu->nr_arch_fixed_counters = min((int)(entry->edx & 0x1f), 470 pmu->global_ctrl = ((1 << pmu->nr_arch_gp_counters) - 1) |
467 X86_PMC_MAX_FIXED); 471 (((1ull << pmu->nr_arch_fixed_counters) - 1) << X86_PMC_IDX_FIXED);
468 pmu->counter_bitmask[KVM_PMC_FIXED] = 472 pmu->global_ctrl_mask = ~pmu->global_ctrl;
469 ((u64)1 << ((entry->edx >> 5) & 0xff)) - 1;
470 pmu->global_ctrl_mask = ~(((1 << pmu->nr_arch_gp_counters) - 1)
471 | (((1ull << pmu->nr_arch_fixed_counters) - 1)
472 << X86_PMC_IDX_FIXED));
473} 473}
474 474
475void kvm_pmu_init(struct kvm_vcpu *vcpu) 475void kvm_pmu_init(struct kvm_vcpu *vcpu)
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 280751c84724..4ff0ab9bc3c8 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -2210,9 +2210,12 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 data)
2210 msr = find_msr_entry(vmx, msr_index); 2210 msr = find_msr_entry(vmx, msr_index);
2211 if (msr) { 2211 if (msr) {
2212 msr->data = data; 2212 msr->data = data;
2213 if (msr - vmx->guest_msrs < vmx->save_nmsrs) 2213 if (msr - vmx->guest_msrs < vmx->save_nmsrs) {
2214 preempt_disable();
2214 kvm_set_shared_msr(msr->index, msr->data, 2215 kvm_set_shared_msr(msr->index, msr->data,
2215 msr->mask); 2216 msr->mask);
2217 preempt_enable();
2218 }
2216 break; 2219 break;
2217 } 2220 }
2218 ret = kvm_set_msr_common(vcpu, msr_index, data); 2221 ret = kvm_set_msr_common(vcpu, msr_index, data);
@@ -3906,7 +3909,9 @@ static int vmx_vcpu_reset(struct kvm_vcpu *vcpu)
3906 vmcs_write16(VIRTUAL_PROCESSOR_ID, vmx->vpid); 3909 vmcs_write16(VIRTUAL_PROCESSOR_ID, vmx->vpid);
3907 3910
3908 vmx->vcpu.arch.cr0 = X86_CR0_NW | X86_CR0_CD | X86_CR0_ET; 3911 vmx->vcpu.arch.cr0 = X86_CR0_NW | X86_CR0_CD | X86_CR0_ET;
3912 vcpu->srcu_idx = srcu_read_lock(&vcpu->kvm->srcu);
3909 vmx_set_cr0(&vmx->vcpu, kvm_read_cr0(vcpu)); /* enter rmode */ 3913 vmx_set_cr0(&vmx->vcpu, kvm_read_cr0(vcpu)); /* enter rmode */
3914 srcu_read_unlock(&vcpu->kvm->srcu, vcpu->srcu_idx);
3910 vmx_set_cr4(&vmx->vcpu, 0); 3915 vmx_set_cr4(&vmx->vcpu, 0);
3911 vmx_set_efer(&vmx->vcpu, 0); 3916 vmx_set_efer(&vmx->vcpu, 0);
3912 vmx_fpu_activate(&vmx->vcpu); 3917 vmx_fpu_activate(&vmx->vcpu);
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 4044ce0bf7c1..185a2b823a2d 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -6336,13 +6336,11 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm,
6336 if (npages && !old.rmap) { 6336 if (npages && !old.rmap) {
6337 unsigned long userspace_addr; 6337 unsigned long userspace_addr;
6338 6338
6339 down_write(&current->mm->mmap_sem); 6339 userspace_addr = vm_mmap(NULL, 0,
6340 userspace_addr = do_mmap(NULL, 0,
6341 npages * PAGE_SIZE, 6340 npages * PAGE_SIZE,
6342 PROT_READ | PROT_WRITE, 6341 PROT_READ | PROT_WRITE,
6343 map_flags, 6342 map_flags,
6344 0); 6343 0);
6345 up_write(&current->mm->mmap_sem);
6346 6344
6347 if (IS_ERR((void *)userspace_addr)) 6345 if (IS_ERR((void *)userspace_addr))
6348 return PTR_ERR((void *)userspace_addr); 6346 return PTR_ERR((void *)userspace_addr);
@@ -6366,10 +6364,8 @@ void kvm_arch_commit_memory_region(struct kvm *kvm,
6366 if (!user_alloc && !old.user_alloc && old.rmap && !npages) { 6364 if (!user_alloc && !old.user_alloc && old.rmap && !npages) {
6367 int ret; 6365 int ret;
6368 6366
6369 down_write(&current->mm->mmap_sem); 6367 ret = vm_munmap(old.userspace_addr,
6370 ret = do_munmap(current->mm, old.userspace_addr,
6371 old.npages * PAGE_SIZE); 6368 old.npages * PAGE_SIZE);
6372 up_write(&current->mm->mmap_sem);
6373 if (ret < 0) 6369 if (ret < 0)
6374 printk(KERN_WARNING 6370 printk(KERN_WARNING
6375 "kvm_vm_ioctl_set_memory_region: " 6371 "kvm_vm_ioctl_set_memory_region: "
@@ -6585,6 +6581,7 @@ void kvm_arch_async_page_present(struct kvm_vcpu *vcpu,
6585 kvm_inject_page_fault(vcpu, &fault); 6581 kvm_inject_page_fault(vcpu, &fault);
6586 } 6582 }
6587 vcpu->arch.apf.halted = false; 6583 vcpu->arch.apf.halted = false;
6584 vcpu->arch.mp_state = KVM_MP_STATE_RUNNABLE;
6588} 6585}
6589 6586
6590bool kvm_arch_can_inject_async_page_present(struct kvm_vcpu *vcpu) 6587bool kvm_arch_can_inject_async_page_present(struct kvm_vcpu *vcpu)
diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
index 25feb1ae71c5..b1e6c4b2e8eb 100644
--- a/arch/x86/lib/insn.c
+++ b/arch/x86/lib/insn.c
@@ -379,8 +379,8 @@ err_out:
379 return; 379 return;
380} 380}
381 381
382/* Decode moffset16/32/64 */ 382/* Decode moffset16/32/64. Return 0 if failed */
383static void __get_moffset(struct insn *insn) 383static int __get_moffset(struct insn *insn)
384{ 384{
385 switch (insn->addr_bytes) { 385 switch (insn->addr_bytes) {
386 case 2: 386 case 2:
@@ -397,15 +397,19 @@ static void __get_moffset(struct insn *insn)
397 insn->moffset2.value = get_next(int, insn); 397 insn->moffset2.value = get_next(int, insn);
398 insn->moffset2.nbytes = 4; 398 insn->moffset2.nbytes = 4;
399 break; 399 break;
400 default: /* opnd_bytes must be modified manually */
401 goto err_out;
400 } 402 }
401 insn->moffset1.got = insn->moffset2.got = 1; 403 insn->moffset1.got = insn->moffset2.got = 1;
402 404
405 return 1;
406
403err_out: 407err_out:
404 return; 408 return 0;
405} 409}
406 410
407/* Decode imm v32(Iz) */ 411/* Decode imm v32(Iz). Return 0 if failed */
408static void __get_immv32(struct insn *insn) 412static int __get_immv32(struct insn *insn)
409{ 413{
410 switch (insn->opnd_bytes) { 414 switch (insn->opnd_bytes) {
411 case 2: 415 case 2:
@@ -417,14 +421,18 @@ static void __get_immv32(struct insn *insn)
417 insn->immediate.value = get_next(int, insn); 421 insn->immediate.value = get_next(int, insn);
418 insn->immediate.nbytes = 4; 422 insn->immediate.nbytes = 4;
419 break; 423 break;
424 default: /* opnd_bytes must be modified manually */
425 goto err_out;
420 } 426 }
421 427
428 return 1;
429
422err_out: 430err_out:
423 return; 431 return 0;
424} 432}
425 433
426/* Decode imm v64(Iv/Ov) */ 434/* Decode imm v64(Iv/Ov), Return 0 if failed */
427static void __get_immv(struct insn *insn) 435static int __get_immv(struct insn *insn)
428{ 436{
429 switch (insn->opnd_bytes) { 437 switch (insn->opnd_bytes) {
430 case 2: 438 case 2:
@@ -441,15 +449,18 @@ static void __get_immv(struct insn *insn)
441 insn->immediate2.value = get_next(int, insn); 449 insn->immediate2.value = get_next(int, insn);
442 insn->immediate2.nbytes = 4; 450 insn->immediate2.nbytes = 4;
443 break; 451 break;
452 default: /* opnd_bytes must be modified manually */
453 goto err_out;
444 } 454 }
445 insn->immediate1.got = insn->immediate2.got = 1; 455 insn->immediate1.got = insn->immediate2.got = 1;
446 456
457 return 1;
447err_out: 458err_out:
448 return; 459 return 0;
449} 460}
450 461
451/* Decode ptr16:16/32(Ap) */ 462/* Decode ptr16:16/32(Ap) */
452static void __get_immptr(struct insn *insn) 463static int __get_immptr(struct insn *insn)
453{ 464{
454 switch (insn->opnd_bytes) { 465 switch (insn->opnd_bytes) {
455 case 2: 466 case 2:
@@ -462,14 +473,17 @@ static void __get_immptr(struct insn *insn)
462 break; 473 break;
463 case 8: 474 case 8:
464 /* ptr16:64 is not exist (no segment) */ 475 /* ptr16:64 is not exist (no segment) */
465 return; 476 return 0;
477 default: /* opnd_bytes must be modified manually */
478 goto err_out;
466 } 479 }
467 insn->immediate2.value = get_next(unsigned short, insn); 480 insn->immediate2.value = get_next(unsigned short, insn);
468 insn->immediate2.nbytes = 2; 481 insn->immediate2.nbytes = 2;
469 insn->immediate1.got = insn->immediate2.got = 1; 482 insn->immediate1.got = insn->immediate2.got = 1;
470 483
484 return 1;
471err_out: 485err_out:
472 return; 486 return 0;
473} 487}
474 488
475/** 489/**
@@ -489,7 +503,8 @@ void insn_get_immediate(struct insn *insn)
489 insn_get_displacement(insn); 503 insn_get_displacement(insn);
490 504
491 if (inat_has_moffset(insn->attr)) { 505 if (inat_has_moffset(insn->attr)) {
492 __get_moffset(insn); 506 if (!__get_moffset(insn))
507 goto err_out;
493 goto done; 508 goto done;
494 } 509 }
495 510
@@ -517,16 +532,20 @@ void insn_get_immediate(struct insn *insn)
517 insn->immediate2.nbytes = 4; 532 insn->immediate2.nbytes = 4;
518 break; 533 break;
519 case INAT_IMM_PTR: 534 case INAT_IMM_PTR:
520 __get_immptr(insn); 535 if (!__get_immptr(insn))
536 goto err_out;
521 break; 537 break;
522 case INAT_IMM_VWORD32: 538 case INAT_IMM_VWORD32:
523 __get_immv32(insn); 539 if (!__get_immv32(insn))
540 goto err_out;
524 break; 541 break;
525 case INAT_IMM_VWORD: 542 case INAT_IMM_VWORD:
526 __get_immv(insn); 543 if (!__get_immv(insn))
544 goto err_out;
527 break; 545 break;
528 default: 546 default:
529 break; 547 /* Here, insn must have an immediate, but failed */
548 goto err_out;
530 } 549 }
531 if (inat_has_second_immediate(insn->attr)) { 550 if (inat_has_second_immediate(insn->attr)) {
532 insn->immediate2.value = get_next(char, insn); 551 insn->immediate2.value = get_next(char, insn);
diff --git a/arch/x86/lib/usercopy.c b/arch/x86/lib/usercopy.c
index 97be9cb54483..d6ae30bbd7bb 100644
--- a/arch/x86/lib/usercopy.c
+++ b/arch/x86/lib/usercopy.c
@@ -7,6 +7,8 @@
7#include <linux/highmem.h> 7#include <linux/highmem.h>
8#include <linux/module.h> 8#include <linux/module.h>
9 9
10#include <asm/word-at-a-time.h>
11
10/* 12/*
11 * best effort, GUP based copy_from_user() that is NMI-safe 13 * best effort, GUP based copy_from_user() that is NMI-safe
12 */ 14 */
@@ -41,3 +43,104 @@ copy_from_user_nmi(void *to, const void __user *from, unsigned long n)
41 return len; 43 return len;
42} 44}
43EXPORT_SYMBOL_GPL(copy_from_user_nmi); 45EXPORT_SYMBOL_GPL(copy_from_user_nmi);
46
47static inline unsigned long count_bytes(unsigned long mask)
48{
49 mask = (mask - 1) & ~mask;
50 mask >>= 7;
51 return count_masked_bytes(mask);
52}
53
54/*
55 * Do a strncpy, return length of string without final '\0'.
56 * 'count' is the user-supplied count (return 'count' if we
57 * hit it), 'max' is the address space maximum (and we return
58 * -EFAULT if we hit it).
59 */
60static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
61{
62 long res = 0;
63
64 /*
65 * Truncate 'max' to the user-specified limit, so that
66 * we only have one limit we need to check in the loop
67 */
68 if (max > count)
69 max = count;
70
71 while (max >= sizeof(unsigned long)) {
72 unsigned long c;
73
74 /* Fall back to byte-at-a-time if we get a page fault */
75 if (unlikely(__get_user(c,(unsigned long __user *)(src+res))))
76 break;
77 /* This can write a few bytes past the NUL character, but that's ok */
78 *(unsigned long *)(dst+res) = c;
79 c = has_zero(c);
80 if (c)
81 return res + count_bytes(c);
82 res += sizeof(unsigned long);
83 max -= sizeof(unsigned long);
84 }
85
86 while (max) {
87 char c;
88
89 if (unlikely(__get_user(c,src+res)))
90 return -EFAULT;
91 dst[res] = c;
92 if (!c)
93 return res;
94 res++;
95 max--;
96 }
97
98 /*
99 * Uhhuh. We hit 'max'. But was that the user-specified maximum
100 * too? If so, that's ok - we got as much as the user asked for.
101 */
102 if (res >= count)
103 return res;
104
105 /*
106 * Nope: we hit the address space limit, and we still had more
107 * characters the caller would have wanted. That's an EFAULT.
108 */
109 return -EFAULT;
110}
111
112/**
113 * strncpy_from_user: - Copy a NUL terminated string from userspace.
114 * @dst: Destination address, in kernel space. This buffer must be at
115 * least @count bytes long.
116 * @src: Source address, in user space.
117 * @count: Maximum number of bytes to copy, including the trailing NUL.
118 *
119 * Copies a NUL-terminated string from userspace to kernel space.
120 *
121 * On success, returns the length of the string (not including the trailing
122 * NUL).
123 *
124 * If access to userspace fails, returns -EFAULT (some data may have been
125 * copied).
126 *
127 * If @count is smaller than the length of the string, copies @count bytes
128 * and returns @count.
129 */
130long
131strncpy_from_user(char *dst, const char __user *src, long count)
132{
133 unsigned long max_addr, src_addr;
134
135 if (unlikely(count <= 0))
136 return 0;
137
138 max_addr = current_thread_info()->addr_limit.seg;
139 src_addr = (unsigned long)src;
140 if (likely(src_addr < max_addr)) {
141 unsigned long max = max_addr - src_addr;
142 return do_strncpy_from_user(dst, src, count, max);
143 }
144 return -EFAULT;
145}
146EXPORT_SYMBOL(strncpy_from_user);
diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
index d9b094ca7aaa..ef2a6a5d78e3 100644
--- a/arch/x86/lib/usercopy_32.c
+++ b/arch/x86/lib/usercopy_32.c
@@ -33,93 +33,6 @@ static inline int __movsl_is_ok(unsigned long a1, unsigned long a2, unsigned lon
33 __movsl_is_ok((unsigned long)(a1), (unsigned long)(a2), (n)) 33 __movsl_is_ok((unsigned long)(a1), (unsigned long)(a2), (n))
34 34
35/* 35/*
36 * Copy a null terminated string from userspace.
37 */
38
39#define __do_strncpy_from_user(dst, src, count, res) \
40do { \
41 int __d0, __d1, __d2; \
42 might_fault(); \
43 __asm__ __volatile__( \
44 " testl %1,%1\n" \
45 " jz 2f\n" \
46 "0: lodsb\n" \
47 " stosb\n" \
48 " testb %%al,%%al\n" \
49 " jz 1f\n" \
50 " decl %1\n" \
51 " jnz 0b\n" \
52 "1: subl %1,%0\n" \
53 "2:\n" \
54 ".section .fixup,\"ax\"\n" \
55 "3: movl %5,%0\n" \
56 " jmp 2b\n" \
57 ".previous\n" \
58 _ASM_EXTABLE(0b,3b) \
59 : "=&d"(res), "=&c"(count), "=&a" (__d0), "=&S" (__d1), \
60 "=&D" (__d2) \
61 : "i"(-EFAULT), "0"(count), "1"(count), "3"(src), "4"(dst) \
62 : "memory"); \
63} while (0)
64
65/**
66 * __strncpy_from_user: - Copy a NUL terminated string from userspace, with less checking.
67 * @dst: Destination address, in kernel space. This buffer must be at
68 * least @count bytes long.
69 * @src: Source address, in user space.
70 * @count: Maximum number of bytes to copy, including the trailing NUL.
71 *
72 * Copies a NUL-terminated string from userspace to kernel space.
73 * Caller must check the specified block with access_ok() before calling
74 * this function.
75 *
76 * On success, returns the length of the string (not including the trailing
77 * NUL).
78 *
79 * If access to userspace fails, returns -EFAULT (some data may have been
80 * copied).
81 *
82 * If @count is smaller than the length of the string, copies @count bytes
83 * and returns @count.
84 */
85long
86__strncpy_from_user(char *dst, const char __user *src, long count)
87{
88 long res;
89 __do_strncpy_from_user(dst, src, count, res);
90 return res;
91}
92EXPORT_SYMBOL(__strncpy_from_user);
93
94/**
95 * strncpy_from_user: - Copy a NUL terminated string from userspace.
96 * @dst: Destination address, in kernel space. This buffer must be at
97 * least @count bytes long.
98 * @src: Source address, in user space.
99 * @count: Maximum number of bytes to copy, including the trailing NUL.
100 *
101 * Copies a NUL-terminated string from userspace to kernel space.
102 *
103 * On success, returns the length of the string (not including the trailing
104 * NUL).
105 *
106 * If access to userspace fails, returns -EFAULT (some data may have been
107 * copied).
108 *
109 * If @count is smaller than the length of the string, copies @count bytes
110 * and returns @count.
111 */
112long
113strncpy_from_user(char *dst, const char __user *src, long count)
114{
115 long res = -EFAULT;
116 if (access_ok(VERIFY_READ, src, 1))
117 __do_strncpy_from_user(dst, src, count, res);
118 return res;
119}
120EXPORT_SYMBOL(strncpy_from_user);
121
122/*
123 * Zero Userspace 36 * Zero Userspace
124 */ 37 */
125 38
diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
index b7c2849ffb66..0d0326f388c0 100644
--- a/arch/x86/lib/usercopy_64.c
+++ b/arch/x86/lib/usercopy_64.c
@@ -9,55 +9,6 @@
9#include <asm/uaccess.h> 9#include <asm/uaccess.h>
10 10
11/* 11/*
12 * Copy a null terminated string from userspace.
13 */
14
15#define __do_strncpy_from_user(dst,src,count,res) \
16do { \
17 long __d0, __d1, __d2; \
18 might_fault(); \
19 __asm__ __volatile__( \
20 " testq %1,%1\n" \
21 " jz 2f\n" \
22 "0: lodsb\n" \
23 " stosb\n" \
24 " testb %%al,%%al\n" \
25 " jz 1f\n" \
26 " decq %1\n" \
27 " jnz 0b\n" \
28 "1: subq %1,%0\n" \
29 "2:\n" \
30 ".section .fixup,\"ax\"\n" \
31 "3: movq %5,%0\n" \
32 " jmp 2b\n" \
33 ".previous\n" \
34 _ASM_EXTABLE(0b,3b) \
35 : "=&r"(res), "=&c"(count), "=&a" (__d0), "=&S" (__d1), \
36 "=&D" (__d2) \
37 : "i"(-EFAULT), "0"(count), "1"(count), "3"(src), "4"(dst) \
38 : "memory"); \
39} while (0)
40
41long
42__strncpy_from_user(char *dst, const char __user *src, long count)
43{
44 long res;
45 __do_strncpy_from_user(dst, src, count, res);
46 return res;
47}
48EXPORT_SYMBOL(__strncpy_from_user);
49
50long
51strncpy_from_user(char *dst, const char __user *src, long count)
52{
53 long res = -EFAULT;
54 if (access_ok(VERIFY_READ, src, 1))
55 return __strncpy_from_user(dst, src, count);
56 return res;
57}
58EXPORT_SYMBOL(strncpy_from_user);
59
60/*
61 * Zero Userspace 12 * Zero Userspace
62 */ 13 */
63 14
diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
index 66870223f8c5..877b9a1b2152 100644
--- a/arch/x86/net/bpf_jit.S
+++ b/arch/x86/net/bpf_jit.S
@@ -18,17 +18,17 @@
18 * r9d : hlen = skb->len - skb->data_len 18 * r9d : hlen = skb->len - skb->data_len
19 */ 19 */
20#define SKBDATA %r8 20#define SKBDATA %r8
21 21#define SKF_MAX_NEG_OFF $(-0x200000) /* SKF_LL_OFF from filter.h */
22sk_load_word_ind:
23 .globl sk_load_word_ind
24
25 add %ebx,%esi /* offset += X */
26# test %esi,%esi /* if (offset < 0) goto bpf_error; */
27 js bpf_error
28 22
29sk_load_word: 23sk_load_word:
30 .globl sk_load_word 24 .globl sk_load_word
31 25
26 test %esi,%esi
27 js bpf_slow_path_word_neg
28
29sk_load_word_positive_offset:
30 .globl sk_load_word_positive_offset
31
32 mov %r9d,%eax # hlen 32 mov %r9d,%eax # hlen
33 sub %esi,%eax # hlen - offset 33 sub %esi,%eax # hlen - offset
34 cmp $3,%eax 34 cmp $3,%eax
@@ -37,16 +37,15 @@ sk_load_word:
37 bswap %eax /* ntohl() */ 37 bswap %eax /* ntohl() */
38 ret 38 ret
39 39
40
41sk_load_half_ind:
42 .globl sk_load_half_ind
43
44 add %ebx,%esi /* offset += X */
45 js bpf_error
46
47sk_load_half: 40sk_load_half:
48 .globl sk_load_half 41 .globl sk_load_half
49 42
43 test %esi,%esi
44 js bpf_slow_path_half_neg
45
46sk_load_half_positive_offset:
47 .globl sk_load_half_positive_offset
48
50 mov %r9d,%eax 49 mov %r9d,%eax
51 sub %esi,%eax # hlen - offset 50 sub %esi,%eax # hlen - offset
52 cmp $1,%eax 51 cmp $1,%eax
@@ -55,14 +54,15 @@ sk_load_half:
55 rol $8,%ax # ntohs() 54 rol $8,%ax # ntohs()
56 ret 55 ret
57 56
58sk_load_byte_ind:
59 .globl sk_load_byte_ind
60 add %ebx,%esi /* offset += X */
61 js bpf_error
62
63sk_load_byte: 57sk_load_byte:
64 .globl sk_load_byte 58 .globl sk_load_byte
65 59
60 test %esi,%esi
61 js bpf_slow_path_byte_neg
62
63sk_load_byte_positive_offset:
64 .globl sk_load_byte_positive_offset
65
66 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */ 66 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
67 jle bpf_slow_path_byte 67 jle bpf_slow_path_byte
68 movzbl (SKBDATA,%rsi),%eax 68 movzbl (SKBDATA,%rsi),%eax
@@ -73,25 +73,21 @@ sk_load_byte:
73 * 73 *
74 * Implements BPF_S_LDX_B_MSH : ldxb 4*([offset]&0xf) 74 * Implements BPF_S_LDX_B_MSH : ldxb 4*([offset]&0xf)
75 * Must preserve A accumulator (%eax) 75 * Must preserve A accumulator (%eax)
76 * Inputs : %esi is the offset value, already known positive 76 * Inputs : %esi is the offset value
77 */ 77 */
78ENTRY(sk_load_byte_msh) 78sk_load_byte_msh:
79 CFI_STARTPROC 79 .globl sk_load_byte_msh
80 test %esi,%esi
81 js bpf_slow_path_byte_msh_neg
82
83sk_load_byte_msh_positive_offset:
84 .globl sk_load_byte_msh_positive_offset
80 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte_msh */ 85 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte_msh */
81 jle bpf_slow_path_byte_msh 86 jle bpf_slow_path_byte_msh
82 movzbl (SKBDATA,%rsi),%ebx 87 movzbl (SKBDATA,%rsi),%ebx
83 and $15,%bl 88 and $15,%bl
84 shl $2,%bl 89 shl $2,%bl
85 ret 90 ret
86 CFI_ENDPROC
87ENDPROC(sk_load_byte_msh)
88
89bpf_error:
90# force a return 0 from jit handler
91 xor %eax,%eax
92 mov -8(%rbp),%rbx
93 leaveq
94 ret
95 91
96/* rsi contains offset and can be scratched */ 92/* rsi contains offset and can be scratched */
97#define bpf_slow_path_common(LEN) \ 93#define bpf_slow_path_common(LEN) \
@@ -138,3 +134,67 @@ bpf_slow_path_byte_msh:
138 shl $2,%al 134 shl $2,%al
139 xchg %eax,%ebx 135 xchg %eax,%ebx
140 ret 136 ret
137
138#define sk_negative_common(SIZE) \
139 push %rdi; /* save skb */ \
140 push %r9; \
141 push SKBDATA; \
142/* rsi already has offset */ \
143 mov $SIZE,%ecx; /* size */ \
144 call bpf_internal_load_pointer_neg_helper; \
145 test %rax,%rax; \
146 pop SKBDATA; \
147 pop %r9; \
148 pop %rdi; \
149 jz bpf_error
150
151
152bpf_slow_path_word_neg:
153 cmp SKF_MAX_NEG_OFF, %esi /* test range */
154 jl bpf_error /* offset lower -> error */
155sk_load_word_negative_offset:
156 .globl sk_load_word_negative_offset
157 sk_negative_common(4)
158 mov (%rax), %eax
159 bswap %eax
160 ret
161
162bpf_slow_path_half_neg:
163 cmp SKF_MAX_NEG_OFF, %esi
164 jl bpf_error
165sk_load_half_negative_offset:
166 .globl sk_load_half_negative_offset
167 sk_negative_common(2)
168 mov (%rax),%ax
169 rol $8,%ax
170 movzwl %ax,%eax
171 ret
172
173bpf_slow_path_byte_neg:
174 cmp SKF_MAX_NEG_OFF, %esi
175 jl bpf_error
176sk_load_byte_negative_offset:
177 .globl sk_load_byte_negative_offset
178 sk_negative_common(1)
179 movzbl (%rax), %eax
180 ret
181
182bpf_slow_path_byte_msh_neg:
183 cmp SKF_MAX_NEG_OFF, %esi
184 jl bpf_error
185sk_load_byte_msh_negative_offset:
186 .globl sk_load_byte_msh_negative_offset
187 xchg %eax,%ebx /* dont lose A , X is about to be scratched */
188 sk_negative_common(1)
189 movzbl (%rax),%eax
190 and $15,%al
191 shl $2,%al
192 xchg %eax,%ebx
193 ret
194
195bpf_error:
196# force a return 0 from jit handler
197 xor %eax,%eax
198 mov -8(%rbp),%rbx
199 leaveq
200 ret
diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
index 5671752f8d9c..0597f95b6da6 100644
--- a/arch/x86/net/bpf_jit_comp.c
+++ b/arch/x86/net/bpf_jit_comp.c
@@ -30,7 +30,10 @@ int bpf_jit_enable __read_mostly;
30 * assembly code in arch/x86/net/bpf_jit.S 30 * assembly code in arch/x86/net/bpf_jit.S
31 */ 31 */
32extern u8 sk_load_word[], sk_load_half[], sk_load_byte[], sk_load_byte_msh[]; 32extern u8 sk_load_word[], sk_load_half[], sk_load_byte[], sk_load_byte_msh[];
33extern u8 sk_load_word_ind[], sk_load_half_ind[], sk_load_byte_ind[]; 33extern u8 sk_load_word_positive_offset[], sk_load_half_positive_offset[];
34extern u8 sk_load_byte_positive_offset[], sk_load_byte_msh_positive_offset[];
35extern u8 sk_load_word_negative_offset[], sk_load_half_negative_offset[];
36extern u8 sk_load_byte_negative_offset[], sk_load_byte_msh_negative_offset[];
34 37
35static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len) 38static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
36{ 39{
@@ -117,6 +120,8 @@ static inline void bpf_flush_icache(void *start, void *end)
117 set_fs(old_fs); 120 set_fs(old_fs);
118} 121}
119 122
123#define CHOOSE_LOAD_FUNC(K, func) \
124 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
120 125
121void bpf_jit_compile(struct sk_filter *fp) 126void bpf_jit_compile(struct sk_filter *fp)
122{ 127{
@@ -289,7 +294,7 @@ void bpf_jit_compile(struct sk_filter *fp)
289 EMIT2(0x24, K & 0xFF); /* and imm8,%al */ 294 EMIT2(0x24, K & 0xFF); /* and imm8,%al */
290 } else if (K >= 0xFFFF0000) { 295 } else if (K >= 0xFFFF0000) {
291 EMIT2(0x66, 0x25); /* and imm16,%ax */ 296 EMIT2(0x66, 0x25); /* and imm16,%ax */
292 EMIT2(K, 2); 297 EMIT(K, 2);
293 } else { 298 } else {
294 EMIT1_off32(0x25, K); /* and imm32,%eax */ 299 EMIT1_off32(0x25, K); /* and imm32,%eax */
295 } 300 }
@@ -473,44 +478,46 @@ void bpf_jit_compile(struct sk_filter *fp)
473#endif 478#endif
474 break; 479 break;
475 case BPF_S_LD_W_ABS: 480 case BPF_S_LD_W_ABS:
476 func = sk_load_word; 481 func = CHOOSE_LOAD_FUNC(K, sk_load_word);
477common_load: seen |= SEEN_DATAREF; 482common_load: seen |= SEEN_DATAREF;
478 if ((int)K < 0) {
479 /* Abort the JIT because __load_pointer() is needed. */
480 goto out;
481 }
482 t_offset = func - (image + addrs[i]); 483 t_offset = func - (image + addrs[i]);
483 EMIT1_off32(0xbe, K); /* mov imm32,%esi */ 484 EMIT1_off32(0xbe, K); /* mov imm32,%esi */
484 EMIT1_off32(0xe8, t_offset); /* call */ 485 EMIT1_off32(0xe8, t_offset); /* call */
485 break; 486 break;
486 case BPF_S_LD_H_ABS: 487 case BPF_S_LD_H_ABS:
487 func = sk_load_half; 488 func = CHOOSE_LOAD_FUNC(K, sk_load_half);
488 goto common_load; 489 goto common_load;
489 case BPF_S_LD_B_ABS: 490 case BPF_S_LD_B_ABS:
490 func = sk_load_byte; 491 func = CHOOSE_LOAD_FUNC(K, sk_load_byte);
491 goto common_load; 492 goto common_load;
492 case BPF_S_LDX_B_MSH: 493 case BPF_S_LDX_B_MSH:
493 if ((int)K < 0) { 494 func = CHOOSE_LOAD_FUNC(K, sk_load_byte_msh);
494 /* Abort the JIT because __load_pointer() is needed. */
495 goto out;
496 }
497 seen |= SEEN_DATAREF | SEEN_XREG; 495 seen |= SEEN_DATAREF | SEEN_XREG;
498 t_offset = sk_load_byte_msh - (image + addrs[i]); 496 t_offset = func - (image + addrs[i]);
499 EMIT1_off32(0xbe, K); /* mov imm32,%esi */ 497 EMIT1_off32(0xbe, K); /* mov imm32,%esi */
500 EMIT1_off32(0xe8, t_offset); /* call sk_load_byte_msh */ 498 EMIT1_off32(0xe8, t_offset); /* call sk_load_byte_msh */
501 break; 499 break;
502 case BPF_S_LD_W_IND: 500 case BPF_S_LD_W_IND:
503 func = sk_load_word_ind; 501 func = sk_load_word;
504common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG; 502common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
505 t_offset = func - (image + addrs[i]); 503 t_offset = func - (image + addrs[i]);
506 EMIT1_off32(0xbe, K); /* mov imm32,%esi */ 504 if (K) {
505 if (is_imm8(K)) {
506 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
507 } else {
508 EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
509 EMIT(K, 4);
510 }
511 } else {
512 EMIT2(0x89,0xde); /* mov %ebx,%esi */
513 }
507 EMIT1_off32(0xe8, t_offset); /* call sk_load_xxx_ind */ 514 EMIT1_off32(0xe8, t_offset); /* call sk_load_xxx_ind */
508 break; 515 break;
509 case BPF_S_LD_H_IND: 516 case BPF_S_LD_H_IND:
510 func = sk_load_half_ind; 517 func = sk_load_half;
511 goto common_load_ind; 518 goto common_load_ind;
512 case BPF_S_LD_B_IND: 519 case BPF_S_LD_B_IND:
513 func = sk_load_byte_ind; 520 func = sk_load_byte;
514 goto common_load_ind; 521 goto common_load_ind;
515 case BPF_S_JMP_JA: 522 case BPF_S_JMP_JA:
516 t_offset = addrs[i + K] - addrs[i]; 523 t_offset = addrs[i + K] - addrs[i];
diff --git a/arch/x86/platform/geode/net5501.c b/arch/x86/platform/geode/net5501.c
index 66d377e334f7..646e3b5b4bb6 100644
--- a/arch/x86/platform/geode/net5501.c
+++ b/arch/x86/platform/geode/net5501.c
@@ -63,7 +63,7 @@ static struct gpio_led net5501_leds[] = {
63 .name = "net5501:1", 63 .name = "net5501:1",
64 .gpio = 6, 64 .gpio = 6,
65 .default_trigger = "default-on", 65 .default_trigger = "default-on",
66 .active_low = 1, 66 .active_low = 0,
67 }, 67 },
68}; 68};
69 69
diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
index e0a37233c0af..e31bcd8f2eee 100644
--- a/arch/x86/platform/mrst/mrst.c
+++ b/arch/x86/platform/mrst/mrst.c
@@ -805,7 +805,7 @@ void intel_scu_devices_create(void)
805 } else 805 } else
806 i2c_register_board_info(i2c_bus[i], i2c_devs[i], 1); 806 i2c_register_board_info(i2c_bus[i], i2c_devs[i], 1);
807 } 807 }
808 intel_scu_notifier_post(SCU_AVAILABLE, 0L); 808 intel_scu_notifier_post(SCU_AVAILABLE, NULL);
809} 809}
810EXPORT_SYMBOL_GPL(intel_scu_devices_create); 810EXPORT_SYMBOL_GPL(intel_scu_devices_create);
811 811
@@ -814,7 +814,7 @@ void intel_scu_devices_destroy(void)
814{ 814{
815 int i; 815 int i;
816 816
817 intel_scu_notifier_post(SCU_DOWN, 0L); 817 intel_scu_notifier_post(SCU_DOWN, NULL);
818 818
819 for (i = 0; i < ipc_next_dev; i++) 819 for (i = 0; i < ipc_next_dev; i++)
820 platform_device_del(ipc_devs[i]); 820 platform_device_del(ipc_devs[i]);
diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
index 47936830968c..218cdb16163c 100644
--- a/arch/x86/power/cpu.c
+++ b/arch/x86/power/cpu.c
@@ -225,13 +225,13 @@ static void __restore_processor_state(struct saved_context *ctxt)
225 fix_processor_context(); 225 fix_processor_context();
226 226
227 do_fpu_end(); 227 do_fpu_end();
228 x86_platform.restore_sched_clock_state();
228 mtrr_bp_restore(); 229 mtrr_bp_restore();
229} 230}
230 231
231/* Needed by apm.c */ 232/* Needed by apm.c */
232void restore_processor_state(void) 233void restore_processor_state(void)
233{ 234{
234 x86_platform.restore_sched_clock_state();
235 __restore_processor_state(&saved_context); 235 __restore_processor_state(&saved_context);
236} 236}
237#ifdef CONFIG_X86_32 237#ifdef CONFIG_X86_32
diff --git a/arch/x86/um/asm/barrier.h b/arch/x86/um/asm/barrier.h
new file mode 100644
index 000000000000..7d01b8c56c00
--- /dev/null
+++ b/arch/x86/um/asm/barrier.h
@@ -0,0 +1,75 @@
1#ifndef _ASM_UM_BARRIER_H_
2#define _ASM_UM_BARRIER_H_
3
4#include <asm/asm.h>
5#include <asm/segment.h>
6#include <asm/cpufeature.h>
7#include <asm/cmpxchg.h>
8#include <asm/nops.h>
9
10#include <linux/kernel.h>
11#include <linux/irqflags.h>
12
13/*
14 * Force strict CPU ordering.
15 * And yes, this is required on UP too when we're talking
16 * to devices.
17 */
18#ifdef CONFIG_X86_32
19
20#define mb() alternative("lock; addl $0,0(%%esp)", "mfence", X86_FEATURE_XMM2)
21#define rmb() alternative("lock; addl $0,0(%%esp)", "lfence", X86_FEATURE_XMM2)
22#define wmb() alternative("lock; addl $0,0(%%esp)", "sfence", X86_FEATURE_XMM)
23
24#else /* CONFIG_X86_32 */
25
26#define mb() asm volatile("mfence" : : : "memory")
27#define rmb() asm volatile("lfence" : : : "memory")
28#define wmb() asm volatile("sfence" : : : "memory")
29
30#endif /* CONFIG_X86_32 */
31
32#define read_barrier_depends() do { } while (0)
33
34#ifdef CONFIG_SMP
35
36#define smp_mb() mb()
37#ifdef CONFIG_X86_PPRO_FENCE
38#define smp_rmb() rmb()
39#else /* CONFIG_X86_PPRO_FENCE */
40#define smp_rmb() barrier()
41#endif /* CONFIG_X86_PPRO_FENCE */
42
43#ifdef CONFIG_X86_OOSTORE
44#define smp_wmb() wmb()
45#else /* CONFIG_X86_OOSTORE */
46#define smp_wmb() barrier()
47#endif /* CONFIG_X86_OOSTORE */
48
49#define smp_read_barrier_depends() read_barrier_depends()
50#define set_mb(var, value) do { (void)xchg(&var, value); } while (0)
51
52#else /* CONFIG_SMP */
53
54#define smp_mb() barrier()
55#define smp_rmb() barrier()
56#define smp_wmb() barrier()
57#define smp_read_barrier_depends() do { } while (0)
58#define set_mb(var, value) do { var = value; barrier(); } while (0)
59
60#endif /* CONFIG_SMP */
61
62/*
63 * Stop RDTSC speculation. This is needed when you need to use RDTSC
64 * (or get_cycles or vread that possibly accesses the TSC) in a defined
65 * code region.
66 *
67 * (Could use an alternative three way for this if there was one.)
68 */
69static inline void rdtsc_barrier(void)
70{
71 alternative(ASM_NOP3, "mfence", X86_FEATURE_MFENCE_RDTSC);
72 alternative(ASM_NOP3, "lfence", X86_FEATURE_LFENCE_RDTSC);
73}
74
75#endif
diff --git a/arch/x86/um/asm/system.h b/arch/x86/um/asm/system.h
deleted file mode 100644
index a459fd9b7598..000000000000
--- a/arch/x86/um/asm/system.h
+++ /dev/null
@@ -1,135 +0,0 @@
1#ifndef _ASM_X86_SYSTEM_H_
2#define _ASM_X86_SYSTEM_H_
3
4#include <asm/asm.h>
5#include <asm/segment.h>
6#include <asm/cpufeature.h>
7#include <asm/cmpxchg.h>
8#include <asm/nops.h>
9
10#include <linux/kernel.h>
11#include <linux/irqflags.h>
12
13/* entries in ARCH_DLINFO: */
14#ifdef CONFIG_IA32_EMULATION
15# define AT_VECTOR_SIZE_ARCH 2
16#else
17# define AT_VECTOR_SIZE_ARCH 1
18#endif
19
20extern unsigned long arch_align_stack(unsigned long sp);
21
22void default_idle(void);
23
24/*
25 * Force strict CPU ordering.
26 * And yes, this is required on UP too when we're talking
27 * to devices.
28 */
29#ifdef CONFIG_X86_32
30/*
31 * Some non-Intel clones support out of order store. wmb() ceases to be a
32 * nop for these.
33 */
34#define mb() alternative("lock; addl $0,0(%%esp)", "mfence", X86_FEATURE_XMM2)
35#define rmb() alternative("lock; addl $0,0(%%esp)", "lfence", X86_FEATURE_XMM2)
36#define wmb() alternative("lock; addl $0,0(%%esp)", "sfence", X86_FEATURE_XMM)
37#else
38#define mb() asm volatile("mfence":::"memory")
39#define rmb() asm volatile("lfence":::"memory")
40#define wmb() asm volatile("sfence" ::: "memory")
41#endif
42
43/**
44 * read_barrier_depends - Flush all pending reads that subsequents reads
45 * depend on.
46 *
47 * No data-dependent reads from memory-like regions are ever reordered
48 * over this barrier. All reads preceding this primitive are guaranteed
49 * to access memory (but not necessarily other CPUs' caches) before any
50 * reads following this primitive that depend on the data return by
51 * any of the preceding reads. This primitive is much lighter weight than
52 * rmb() on most CPUs, and is never heavier weight than is
53 * rmb().
54 *
55 * These ordering constraints are respected by both the local CPU
56 * and the compiler.
57 *
58 * Ordering is not guaranteed by anything other than these primitives,
59 * not even by data dependencies. See the documentation for
60 * memory_barrier() for examples and URLs to more information.
61 *
62 * For example, the following code would force ordering (the initial
63 * value of "a" is zero, "b" is one, and "p" is "&a"):
64 *
65 * <programlisting>
66 * CPU 0 CPU 1
67 *
68 * b = 2;
69 * memory_barrier();
70 * p = &b; q = p;
71 * read_barrier_depends();
72 * d = *q;
73 * </programlisting>
74 *
75 * because the read of "*q" depends on the read of "p" and these
76 * two reads are separated by a read_barrier_depends(). However,
77 * the following code, with the same initial values for "a" and "b":
78 *
79 * <programlisting>
80 * CPU 0 CPU 1
81 *
82 * a = 2;
83 * memory_barrier();
84 * b = 3; y = b;
85 * read_barrier_depends();
86 * x = a;
87 * </programlisting>
88 *
89 * does not enforce ordering, since there is no data dependency between
90 * the read of "a" and the read of "b". Therefore, on some CPUs, such
91 * as Alpha, "y" could be set to 3 and "x" to 0. Use rmb()
92 * in cases like this where there are no data dependencies.
93 **/
94
95#define read_barrier_depends() do { } while (0)
96
97#ifdef CONFIG_SMP
98#define smp_mb() mb()
99#ifdef CONFIG_X86_PPRO_FENCE
100# define smp_rmb() rmb()
101#else
102# define smp_rmb() barrier()
103#endif
104#ifdef CONFIG_X86_OOSTORE
105# define smp_wmb() wmb()
106#else
107# define smp_wmb() barrier()
108#endif
109#define smp_read_barrier_depends() read_barrier_depends()
110#define set_mb(var, value) do { (void)xchg(&var, value); } while (0)
111#else
112#define smp_mb() barrier()
113#define smp_rmb() barrier()
114#define smp_wmb() barrier()
115#define smp_read_barrier_depends() do { } while (0)
116#define set_mb(var, value) do { var = value; barrier(); } while (0)
117#endif
118
119/*
120 * Stop RDTSC speculation. This is needed when you need to use RDTSC
121 * (or get_cycles or vread that possibly accesses the TSC) in a defined
122 * code region.
123 *
124 * (Could use an alternative three way for this if there was one.)
125 */
126static inline void rdtsc_barrier(void)
127{
128 alternative(ASM_NOP3, "mfence", X86_FEATURE_MFENCE_RDTSC);
129 alternative(ASM_NOP3, "lfence", X86_FEATURE_LFENCE_RDTSC);
130}
131
132extern void *_switch_to(void *prev, void *next, void *last);
133#define switch_to(prev, next, last) prev = _switch_to(prev, next, last)
134
135#endif
diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
index b132ade26f77..95dccce8e979 100644
--- a/arch/x86/xen/enlighten.c
+++ b/arch/x86/xen/enlighten.c
@@ -63,6 +63,7 @@
63#include <asm/stackprotector.h> 63#include <asm/stackprotector.h>
64#include <asm/hypervisor.h> 64#include <asm/hypervisor.h>
65#include <asm/mwait.h> 65#include <asm/mwait.h>
66#include <asm/pci_x86.h>
66 67
67#ifdef CONFIG_ACPI 68#ifdef CONFIG_ACPI
68#include <linux/acpi.h> 69#include <linux/acpi.h>
@@ -261,7 +262,8 @@ static void xen_cpuid(unsigned int *ax, unsigned int *bx,
261 262
262static bool __init xen_check_mwait(void) 263static bool __init xen_check_mwait(void)
263{ 264{
264#ifdef CONFIG_ACPI 265#if defined(CONFIG_ACPI) && !defined(CONFIG_ACPI_PROCESSOR_AGGREGATOR) && \
266 !defined(CONFIG_ACPI_PROCESSOR_AGGREGATOR_MODULE)
265 struct xen_platform_op op = { 267 struct xen_platform_op op = {
266 .cmd = XENPF_set_processor_pminfo, 268 .cmd = XENPF_set_processor_pminfo,
267 .u.set_pminfo.id = -1, 269 .u.set_pminfo.id = -1,
@@ -349,7 +351,6 @@ static void __init xen_init_cpuid_mask(void)
349 /* Xen will set CR4.OSXSAVE if supported and not disabled by force */ 351 /* Xen will set CR4.OSXSAVE if supported and not disabled by force */
350 if ((cx & xsave_mask) != xsave_mask) 352 if ((cx & xsave_mask) != xsave_mask)
351 cpuid_leaf1_ecx_mask &= ~xsave_mask; /* disable XSAVE & OSXSAVE */ 353 cpuid_leaf1_ecx_mask &= ~xsave_mask; /* disable XSAVE & OSXSAVE */
352
353 if (xen_check_mwait()) 354 if (xen_check_mwait())
354 cpuid_leaf1_ecx_set_mask = (1 << (X86_FEATURE_MWAIT % 32)); 355 cpuid_leaf1_ecx_set_mask = (1 << (X86_FEATURE_MWAIT % 32));
355} 356}
@@ -809,9 +810,40 @@ static void xen_io_delay(void)
809} 810}
810 811
811#ifdef CONFIG_X86_LOCAL_APIC 812#ifdef CONFIG_X86_LOCAL_APIC
813static unsigned long xen_set_apic_id(unsigned int x)
814{
815 WARN_ON(1);
816 return x;
817}
818static unsigned int xen_get_apic_id(unsigned long x)
819{
820 return ((x)>>24) & 0xFFu;
821}
812static u32 xen_apic_read(u32 reg) 822static u32 xen_apic_read(u32 reg)
813{ 823{
814 return 0; 824 struct xen_platform_op op = {
825 .cmd = XENPF_get_cpuinfo,
826 .interface_version = XENPF_INTERFACE_VERSION,
827 .u.pcpu_info.xen_cpuid = 0,
828 };
829 int ret = 0;
830
831 /* Shouldn't need this as APIC is turned off for PV, and we only
832 * get called on the bootup processor. But just in case. */
833 if (!xen_initial_domain() || smp_processor_id())
834 return 0;
835
836 if (reg == APIC_LVR)
837 return 0x10;
838
839 if (reg != APIC_ID)
840 return 0;
841
842 ret = HYPERVISOR_dom0_op(&op);
843 if (ret)
844 return 0;
845
846 return op.u.pcpu_info.apic_id << 24;
815} 847}
816 848
817static void xen_apic_write(u32 reg, u32 val) 849static void xen_apic_write(u32 reg, u32 val)
@@ -849,6 +881,8 @@ static void set_xen_basic_apic_ops(void)
849 apic->icr_write = xen_apic_icr_write; 881 apic->icr_write = xen_apic_icr_write;
850 apic->wait_icr_idle = xen_apic_wait_icr_idle; 882 apic->wait_icr_idle = xen_apic_wait_icr_idle;
851 apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle; 883 apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
884 apic->set_apic_id = xen_set_apic_id;
885 apic->get_apic_id = xen_get_apic_id;
852} 886}
853 887
854#endif 888#endif
@@ -967,7 +1001,7 @@ void xen_setup_shared_info(void)
967 xen_setup_mfn_list_list(); 1001 xen_setup_mfn_list_list();
968} 1002}
969 1003
970/* This is called once we have the cpu_possible_map */ 1004/* This is called once we have the cpu_possible_mask */
971void xen_setup_vcpu_info_placement(void) 1005void xen_setup_vcpu_info_placement(void)
972{ 1006{
973 int cpu; 1007 int cpu;
@@ -1365,8 +1399,10 @@ asmlinkage void __init xen_start_kernel(void)
1365 /* Make sure ACS will be enabled */ 1399 /* Make sure ACS will be enabled */
1366 pci_request_acs(); 1400 pci_request_acs();
1367 } 1401 }
1368 1402#ifdef CONFIG_PCI
1369 1403 /* PCI BIOS service won't work from a PV guest. */
1404 pci_probe &= ~PCI_PROBE_BIOS;
1405#endif
1370 xen_raw_console_write("about to get started...\n"); 1406 xen_raw_console_write("about to get started...\n");
1371 1407
1372 xen_setup_runstate_info(0); 1408 xen_setup_runstate_info(0);
diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
index 988828b479ed..69f5857660ac 100644
--- a/arch/x86/xen/mmu.c
+++ b/arch/x86/xen/mmu.c
@@ -353,8 +353,13 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
353{ 353{
354 if (val & _PAGE_PRESENT) { 354 if (val & _PAGE_PRESENT) {
355 unsigned long mfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT; 355 unsigned long mfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
356 unsigned long pfn = mfn_to_pfn(mfn);
357
356 pteval_t flags = val & PTE_FLAGS_MASK; 358 pteval_t flags = val & PTE_FLAGS_MASK;
357 val = ((pteval_t)mfn_to_pfn(mfn) << PAGE_SHIFT) | flags; 359 if (unlikely(pfn == ~0))
360 val = flags & ~_PAGE_PRESENT;
361 else
362 val = ((pteval_t)pfn << PAGE_SHIFT) | flags;
358 } 363 }
359 364
360 return val; 365 return val;
@@ -1859,6 +1864,7 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
1859#endif /* CONFIG_X86_64 */ 1864#endif /* CONFIG_X86_64 */
1860 1865
1861static unsigned char dummy_mapping[PAGE_SIZE] __page_aligned_bss; 1866static unsigned char dummy_mapping[PAGE_SIZE] __page_aligned_bss;
1867static unsigned char fake_ioapic_mapping[PAGE_SIZE] __page_aligned_bss;
1862 1868
1863static void xen_set_fixmap(unsigned idx, phys_addr_t phys, pgprot_t prot) 1869static void xen_set_fixmap(unsigned idx, phys_addr_t phys, pgprot_t prot)
1864{ 1870{
@@ -1899,7 +1905,7 @@ static void xen_set_fixmap(unsigned idx, phys_addr_t phys, pgprot_t prot)
1899 * We just don't map the IO APIC - all access is via 1905 * We just don't map the IO APIC - all access is via
1900 * hypercalls. Keep the address in the pte for reference. 1906 * hypercalls. Keep the address in the pte for reference.
1901 */ 1907 */
1902 pte = pfn_pte(PFN_DOWN(__pa(dummy_mapping)), PAGE_KERNEL); 1908 pte = pfn_pte(PFN_DOWN(__pa(fake_ioapic_mapping)), PAGE_KERNEL);
1903 break; 1909 break;
1904#endif 1910#endif
1905 1911
@@ -2064,6 +2070,7 @@ void __init xen_init_mmu_ops(void)
2064 pv_mmu_ops = xen_mmu_ops; 2070 pv_mmu_ops = xen_mmu_ops;
2065 2071
2066 memset(dummy_mapping, 0xff, PAGE_SIZE); 2072 memset(dummy_mapping, 0xff, PAGE_SIZE);
2073 memset(fake_ioapic_mapping, 0xfd, PAGE_SIZE);
2067} 2074}
2068 2075
2069/* Protected by xen_reservation_lock. */ 2076/* Protected by xen_reservation_lock. */
diff --git a/arch/x86/xen/pci-swiotlb-xen.c b/arch/x86/xen/pci-swiotlb-xen.c
index b480d4207a4c..967633ad98c4 100644
--- a/arch/x86/xen/pci-swiotlb-xen.c
+++ b/arch/x86/xen/pci-swiotlb-xen.c
@@ -12,8 +12,8 @@ int xen_swiotlb __read_mostly;
12 12
13static struct dma_map_ops xen_swiotlb_dma_ops = { 13static struct dma_map_ops xen_swiotlb_dma_ops = {
14 .mapping_error = xen_swiotlb_dma_mapping_error, 14 .mapping_error = xen_swiotlb_dma_mapping_error,
15 .alloc_coherent = xen_swiotlb_alloc_coherent, 15 .alloc = xen_swiotlb_alloc_coherent,
16 .free_coherent = xen_swiotlb_free_coherent, 16 .free = xen_swiotlb_free_coherent,
17 .sync_single_for_cpu = xen_swiotlb_sync_single_for_cpu, 17 .sync_single_for_cpu = xen_swiotlb_sync_single_for_cpu,
18 .sync_single_for_device = xen_swiotlb_sync_single_for_device, 18 .sync_single_for_device = xen_swiotlb_sync_single_for_device,
19 .sync_sg_for_cpu = xen_swiotlb_sync_sg_for_cpu, 19 .sync_sg_for_cpu = xen_swiotlb_sync_sg_for_cpu,
diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
index 02900e8ce26c..0503c0c493a9 100644
--- a/arch/x86/xen/smp.c
+++ b/arch/x86/xen/smp.c
@@ -59,7 +59,7 @@ static irqreturn_t xen_reschedule_interrupt(int irq, void *dev_id)
59 59
60static void __cpuinit cpu_bringup(void) 60static void __cpuinit cpu_bringup(void)
61{ 61{
62 int cpu = smp_processor_id(); 62 int cpu;
63 63
64 cpu_init(); 64 cpu_init();
65 touch_softlockup_watchdog(); 65 touch_softlockup_watchdog();
@@ -178,6 +178,7 @@ static void __init xen_fill_possible_map(void)
178static void __init xen_filter_cpu_maps(void) 178static void __init xen_filter_cpu_maps(void)
179{ 179{
180 int i, rc; 180 int i, rc;
181 unsigned int subtract = 0;
181 182
182 if (!xen_initial_domain()) 183 if (!xen_initial_domain())
183 return; 184 return;
@@ -192,8 +193,22 @@ static void __init xen_filter_cpu_maps(void)
192 } else { 193 } else {
193 set_cpu_possible(i, false); 194 set_cpu_possible(i, false);
194 set_cpu_present(i, false); 195 set_cpu_present(i, false);
196 subtract++;
195 } 197 }
196 } 198 }
199#ifdef CONFIG_HOTPLUG_CPU
200 /* This is akin to using 'nr_cpus' on the Linux command line.
201 * Which is OK as when we use 'dom0_max_vcpus=X' we can only
202 * have up to X, while nr_cpu_ids is greater than X. This
203 * normally is not a problem, except when CPU hotplugging
204 * is involved and then there might be more than X CPUs
205 * in the guest - which will not work as there is no
206 * hypercall to expand the max number of VCPUs an already
207 * running guest has. So cap it up to X. */
208 if (subtract)
209 nr_cpu_ids = nr_cpu_ids - subtract;
210#endif
211
197} 212}
198 213
199static void __init xen_smp_prepare_boot_cpu(void) 214static void __init xen_smp_prepare_boot_cpu(void)
diff --git a/arch/x86/xen/xen-asm.S b/arch/x86/xen/xen-asm.S
index 79d7362ad6d1..3e45aa000718 100644
--- a/arch/x86/xen/xen-asm.S
+++ b/arch/x86/xen/xen-asm.S
@@ -96,7 +96,7 @@ ENTRY(xen_restore_fl_direct)
96 96
97 /* check for unmasked and pending */ 97 /* check for unmasked and pending */
98 cmpw $0x0001, PER_CPU_VAR(xen_vcpu_info) + XEN_vcpu_info_pending 98 cmpw $0x0001, PER_CPU_VAR(xen_vcpu_info) + XEN_vcpu_info_pending
99 jz 1f 99 jnz 1f
1002: call check_events 1002: call check_events
1011: 1011:
102ENDPATCH(xen_restore_fl_direct) 102ENDPATCH(xen_restore_fl_direct)
diff --git a/arch/xtensa/include/asm/hardirq.h b/arch/xtensa/include/asm/hardirq.h
index 26664cef8f11..91695a135498 100644
--- a/arch/xtensa/include/asm/hardirq.h
+++ b/arch/xtensa/include/asm/hardirq.h
@@ -11,9 +11,6 @@
11#ifndef _XTENSA_HARDIRQ_H 11#ifndef _XTENSA_HARDIRQ_H
12#define _XTENSA_HARDIRQ_H 12#define _XTENSA_HARDIRQ_H
13 13
14void ack_bad_irq(unsigned int irq);
15#define ack_bad_irq ack_bad_irq
16
17#include <asm-generic/hardirq.h> 14#include <asm-generic/hardirq.h>
18 15
19#endif /* _XTENSA_HARDIRQ_H */ 16#endif /* _XTENSA_HARDIRQ_H */
diff --git a/arch/xtensa/include/asm/io.h b/arch/xtensa/include/asm/io.h
index d04cd3a625fa..4beb43c087d3 100644
--- a/arch/xtensa/include/asm/io.h
+++ b/arch/xtensa/include/asm/io.h
@@ -14,6 +14,7 @@
14#ifdef __KERNEL__ 14#ifdef __KERNEL__
15#include <asm/byteorder.h> 15#include <asm/byteorder.h>
16#include <asm/page.h> 16#include <asm/page.h>
17#include <linux/bug.h>
17#include <linux/kernel.h> 18#include <linux/kernel.h>
18 19
19#include <linux/types.h> 20#include <linux/types.h>
diff --git a/arch/xtensa/kernel/signal.c b/arch/xtensa/kernel/signal.c
index b69b000349fc..d78869a00b11 100644
--- a/arch/xtensa/kernel/signal.c
+++ b/arch/xtensa/kernel/signal.c
@@ -496,6 +496,7 @@ int do_signal(struct pt_regs *regs, sigset_t *oldset)
496 signr = get_signal_to_deliver(&info, &ka, regs, NULL); 496 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
497 497
498 if (signr > 0) { 498 if (signr > 0) {
499 int ret;
499 500
500 /* Are we from a system call? */ 501 /* Are we from a system call? */
501 502
diff --git a/block/blk-core.c b/block/blk-core.c
index 3a78b00edd71..1f61b74867e4 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -483,7 +483,7 @@ struct request_queue *blk_alloc_queue_node(gfp_t gfp_mask, int node_id)
483 if (!q) 483 if (!q)
484 return NULL; 484 return NULL;
485 485
486 q->id = ida_simple_get(&blk_queue_ida, 0, 0, GFP_KERNEL); 486 q->id = ida_simple_get(&blk_queue_ida, 0, 0, gfp_mask);
487 if (q->id < 0) 487 if (q->id < 0)
488 goto fail_q; 488 goto fail_q;
489 489
@@ -1277,7 +1277,8 @@ static bool attempt_plug_merge(struct request_queue *q, struct bio *bio,
1277 list_for_each_entry_reverse(rq, &plug->list, queuelist) { 1277 list_for_each_entry_reverse(rq, &plug->list, queuelist) {
1278 int el_ret; 1278 int el_ret;
1279 1279
1280 (*request_count)++; 1280 if (rq->q == q)
1281 (*request_count)++;
1281 1282
1282 if (rq->q != q || !blk_rq_merge_ok(rq, bio)) 1283 if (rq->q != q || !blk_rq_merge_ok(rq, bio))
1283 continue; 1284 continue;
diff --git a/block/blk-throttle.c b/block/blk-throttle.c
index 5eed6a76721d..f2ddb94626bd 100644
--- a/block/blk-throttle.c
+++ b/block/blk-throttle.c
@@ -1218,7 +1218,7 @@ void blk_throtl_drain(struct request_queue *q)
1218 struct bio_list bl; 1218 struct bio_list bl;
1219 struct bio *bio; 1219 struct bio *bio;
1220 1220
1221 WARN_ON_ONCE(!queue_is_locked(q)); 1221 queue_lockdep_assert_held(q);
1222 1222
1223 bio_list_init(&bl); 1223 bio_list_init(&bl);
1224 1224
diff --git a/block/cfq-iosched.c b/block/cfq-iosched.c
index 457295253566..3c38536bd52c 100644
--- a/block/cfq-iosched.c
+++ b/block/cfq-iosched.c
@@ -295,6 +295,7 @@ struct cfq_data {
295 unsigned int cfq_slice_idle; 295 unsigned int cfq_slice_idle;
296 unsigned int cfq_group_idle; 296 unsigned int cfq_group_idle;
297 unsigned int cfq_latency; 297 unsigned int cfq_latency;
298 unsigned int cfq_target_latency;
298 299
299 /* 300 /*
300 * Fallback dummy cfqq for extreme OOM conditions 301 * Fallback dummy cfqq for extreme OOM conditions
@@ -604,7 +605,7 @@ cfq_group_slice(struct cfq_data *cfqd, struct cfq_group *cfqg)
604{ 605{
605 struct cfq_rb_root *st = &cfqd->grp_service_tree; 606 struct cfq_rb_root *st = &cfqd->grp_service_tree;
606 607
607 return cfq_target_latency * cfqg->weight / st->total_weight; 608 return cfqd->cfq_target_latency * cfqg->weight / st->total_weight;
608} 609}
609 610
610static inline unsigned 611static inline unsigned
@@ -2271,7 +2272,8 @@ new_workload:
2271 * to have higher weight. A more accurate thing would be to 2272 * to have higher weight. A more accurate thing would be to
2272 * calculate system wide asnc/sync ratio. 2273 * calculate system wide asnc/sync ratio.
2273 */ 2274 */
2274 tmp = cfq_target_latency * cfqg_busy_async_queues(cfqd, cfqg); 2275 tmp = cfqd->cfq_target_latency *
2276 cfqg_busy_async_queues(cfqd, cfqg);
2275 tmp = tmp/cfqd->busy_queues; 2277 tmp = tmp/cfqd->busy_queues;
2276 slice = min_t(unsigned, slice, tmp); 2278 slice = min_t(unsigned, slice, tmp);
2277 2279
@@ -3737,6 +3739,7 @@ static void *cfq_init_queue(struct request_queue *q)
3737 cfqd->cfq_back_penalty = cfq_back_penalty; 3739 cfqd->cfq_back_penalty = cfq_back_penalty;
3738 cfqd->cfq_slice[0] = cfq_slice_async; 3740 cfqd->cfq_slice[0] = cfq_slice_async;
3739 cfqd->cfq_slice[1] = cfq_slice_sync; 3741 cfqd->cfq_slice[1] = cfq_slice_sync;
3742 cfqd->cfq_target_latency = cfq_target_latency;
3740 cfqd->cfq_slice_async_rq = cfq_slice_async_rq; 3743 cfqd->cfq_slice_async_rq = cfq_slice_async_rq;
3741 cfqd->cfq_slice_idle = cfq_slice_idle; 3744 cfqd->cfq_slice_idle = cfq_slice_idle;
3742 cfqd->cfq_group_idle = cfq_group_idle; 3745 cfqd->cfq_group_idle = cfq_group_idle;
@@ -3788,6 +3791,7 @@ SHOW_FUNCTION(cfq_slice_sync_show, cfqd->cfq_slice[1], 1);
3788SHOW_FUNCTION(cfq_slice_async_show, cfqd->cfq_slice[0], 1); 3791SHOW_FUNCTION(cfq_slice_async_show, cfqd->cfq_slice[0], 1);
3789SHOW_FUNCTION(cfq_slice_async_rq_show, cfqd->cfq_slice_async_rq, 0); 3792SHOW_FUNCTION(cfq_slice_async_rq_show, cfqd->cfq_slice_async_rq, 0);
3790SHOW_FUNCTION(cfq_low_latency_show, cfqd->cfq_latency, 0); 3793SHOW_FUNCTION(cfq_low_latency_show, cfqd->cfq_latency, 0);
3794SHOW_FUNCTION(cfq_target_latency_show, cfqd->cfq_target_latency, 1);
3791#undef SHOW_FUNCTION 3795#undef SHOW_FUNCTION
3792 3796
3793#define STORE_FUNCTION(__FUNC, __PTR, MIN, MAX, __CONV) \ 3797#define STORE_FUNCTION(__FUNC, __PTR, MIN, MAX, __CONV) \
@@ -3821,6 +3825,7 @@ STORE_FUNCTION(cfq_slice_async_store, &cfqd->cfq_slice[0], 1, UINT_MAX, 1);
3821STORE_FUNCTION(cfq_slice_async_rq_store, &cfqd->cfq_slice_async_rq, 1, 3825STORE_FUNCTION(cfq_slice_async_rq_store, &cfqd->cfq_slice_async_rq, 1,
3822 UINT_MAX, 0); 3826 UINT_MAX, 0);
3823STORE_FUNCTION(cfq_low_latency_store, &cfqd->cfq_latency, 0, 1, 0); 3827STORE_FUNCTION(cfq_low_latency_store, &cfqd->cfq_latency, 0, 1, 0);
3828STORE_FUNCTION(cfq_target_latency_store, &cfqd->cfq_target_latency, 1, UINT_MAX, 1);
3824#undef STORE_FUNCTION 3829#undef STORE_FUNCTION
3825 3830
3826#define CFQ_ATTR(name) \ 3831#define CFQ_ATTR(name) \
@@ -3838,6 +3843,7 @@ static struct elv_fs_entry cfq_attrs[] = {
3838 CFQ_ATTR(slice_idle), 3843 CFQ_ATTR(slice_idle),
3839 CFQ_ATTR(group_idle), 3844 CFQ_ATTR(group_idle),
3840 CFQ_ATTR(low_latency), 3845 CFQ_ATTR(low_latency),
3846 CFQ_ATTR(target_latency),
3841 __ATTR_NULL 3847 __ATTR_NULL
3842}; 3848};
3843 3849
diff --git a/crypto/Kconfig b/crypto/Kconfig
index 21ff9d015432..8e84225c096b 100644
--- a/crypto/Kconfig
+++ b/crypto/Kconfig
@@ -627,7 +627,7 @@ config CRYPTO_BLOWFISH_COMMON
627 627
628config CRYPTO_BLOWFISH_X86_64 628config CRYPTO_BLOWFISH_X86_64
629 tristate "Blowfish cipher algorithm (x86_64)" 629 tristate "Blowfish cipher algorithm (x86_64)"
630 depends on (X86 || UML_X86) && 64BIT 630 depends on X86 && 64BIT
631 select CRYPTO_ALGAPI 631 select CRYPTO_ALGAPI
632 select CRYPTO_BLOWFISH_COMMON 632 select CRYPTO_BLOWFISH_COMMON
633 help 633 help
@@ -657,7 +657,7 @@ config CRYPTO_CAMELLIA
657 657
658config CRYPTO_CAMELLIA_X86_64 658config CRYPTO_CAMELLIA_X86_64
659 tristate "Camellia cipher algorithm (x86_64)" 659 tristate "Camellia cipher algorithm (x86_64)"
660 depends on (X86 || UML_X86) && 64BIT 660 depends on X86 && 64BIT
661 depends on CRYPTO 661 depends on CRYPTO
662 select CRYPTO_ALGAPI 662 select CRYPTO_ALGAPI
663 select CRYPTO_LRW 663 select CRYPTO_LRW
@@ -893,7 +893,7 @@ config CRYPTO_TWOFISH_X86_64
893 893
894config CRYPTO_TWOFISH_X86_64_3WAY 894config CRYPTO_TWOFISH_X86_64_3WAY
895 tristate "Twofish cipher algorithm (x86_64, 3-way parallel)" 895 tristate "Twofish cipher algorithm (x86_64, 3-way parallel)"
896 depends on (X86 || UML_X86) && 64BIT 896 depends on X86 && 64BIT
897 select CRYPTO_ALGAPI 897 select CRYPTO_ALGAPI
898 select CRYPTO_TWOFISH_COMMON 898 select CRYPTO_TWOFISH_COMMON
899 select CRYPTO_TWOFISH_X86_64 899 select CRYPTO_TWOFISH_X86_64
diff --git a/crypto/ablkcipher.c b/crypto/ablkcipher.c
index a0f768c1d9aa..8d3a056ebeea 100644
--- a/crypto/ablkcipher.c
+++ b/crypto/ablkcipher.c
@@ -613,8 +613,7 @@ out:
613 return err; 613 return err;
614} 614}
615 615
616static struct crypto_alg *crypto_lookup_skcipher(const char *name, u32 type, 616struct crypto_alg *crypto_lookup_skcipher(const char *name, u32 type, u32 mask)
617 u32 mask)
618{ 617{
619 struct crypto_alg *alg; 618 struct crypto_alg *alg;
620 619
@@ -652,6 +651,7 @@ static struct crypto_alg *crypto_lookup_skcipher(const char *name, u32 type,
652 651
653 return ERR_PTR(crypto_givcipher_default(alg, type, mask)); 652 return ERR_PTR(crypto_givcipher_default(alg, type, mask));
654} 653}
654EXPORT_SYMBOL_GPL(crypto_lookup_skcipher);
655 655
656int crypto_grab_skcipher(struct crypto_skcipher_spawn *spawn, const char *name, 656int crypto_grab_skcipher(struct crypto_skcipher_spawn *spawn, const char *name,
657 u32 type, u32 mask) 657 u32 type, u32 mask)
diff --git a/crypto/aead.c b/crypto/aead.c
index 04add3dca6fe..e4cb35159be4 100644
--- a/crypto/aead.c
+++ b/crypto/aead.c
@@ -470,8 +470,7 @@ out:
470 return err; 470 return err;
471} 471}
472 472
473static struct crypto_alg *crypto_lookup_aead(const char *name, u32 type, 473struct crypto_alg *crypto_lookup_aead(const char *name, u32 type, u32 mask)
474 u32 mask)
475{ 474{
476 struct crypto_alg *alg; 475 struct crypto_alg *alg;
477 476
@@ -503,6 +502,7 @@ static struct crypto_alg *crypto_lookup_aead(const char *name, u32 type,
503 502
504 return ERR_PTR(crypto_nivaead_default(alg, type, mask)); 503 return ERR_PTR(crypto_nivaead_default(alg, type, mask));
505} 504}
505EXPORT_SYMBOL_GPL(crypto_lookup_aead);
506 506
507int crypto_grab_aead(struct crypto_aead_spawn *spawn, const char *name, 507int crypto_grab_aead(struct crypto_aead_spawn *spawn, const char *name,
508 u32 type, u32 mask) 508 u32 type, u32 mask)
diff --git a/crypto/crypto_user.c b/crypto/crypto_user.c
index f76e42bcc6e7..f1ea0a064135 100644
--- a/crypto/crypto_user.c
+++ b/crypto/crypto_user.c
@@ -21,9 +21,13 @@
21#include <linux/module.h> 21#include <linux/module.h>
22#include <linux/crypto.h> 22#include <linux/crypto.h>
23#include <linux/cryptouser.h> 23#include <linux/cryptouser.h>
24#include <linux/sched.h>
24#include <net/netlink.h> 25#include <net/netlink.h>
25#include <linux/security.h> 26#include <linux/security.h>
26#include <net/net_namespace.h> 27#include <net/net_namespace.h>
28#include <crypto/internal/aead.h>
29#include <crypto/internal/skcipher.h>
30
27#include "internal.h" 31#include "internal.h"
28 32
29DEFINE_MUTEX(crypto_cfg_mutex); 33DEFINE_MUTEX(crypto_cfg_mutex);
@@ -301,6 +305,60 @@ static int crypto_del_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
301 return crypto_unregister_instance(alg); 305 return crypto_unregister_instance(alg);
302} 306}
303 307
308static struct crypto_alg *crypto_user_skcipher_alg(const char *name, u32 type,
309 u32 mask)
310{
311 int err;
312 struct crypto_alg *alg;
313
314 type = crypto_skcipher_type(type);
315 mask = crypto_skcipher_mask(mask);
316
317 for (;;) {
318 alg = crypto_lookup_skcipher(name, type, mask);
319 if (!IS_ERR(alg))
320 return alg;
321
322 err = PTR_ERR(alg);
323 if (err != -EAGAIN)
324 break;
325 if (signal_pending(current)) {
326 err = -EINTR;
327 break;
328 }
329 }
330
331 return ERR_PTR(err);
332}
333
334static struct crypto_alg *crypto_user_aead_alg(const char *name, u32 type,
335 u32 mask)
336{
337 int err;
338 struct crypto_alg *alg;
339
340 type &= ~(CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_GENIV);
341 type |= CRYPTO_ALG_TYPE_AEAD;
342 mask &= ~(CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_GENIV);
343 mask |= CRYPTO_ALG_TYPE_MASK;
344
345 for (;;) {
346 alg = crypto_lookup_aead(name, type, mask);
347 if (!IS_ERR(alg))
348 return alg;
349
350 err = PTR_ERR(alg);
351 if (err != -EAGAIN)
352 break;
353 if (signal_pending(current)) {
354 err = -EINTR;
355 break;
356 }
357 }
358
359 return ERR_PTR(err);
360}
361
304static int crypto_add_alg(struct sk_buff *skb, struct nlmsghdr *nlh, 362static int crypto_add_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
305 struct nlattr **attrs) 363 struct nlattr **attrs)
306{ 364{
@@ -325,7 +383,19 @@ static int crypto_add_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
325 else 383 else
326 name = p->cru_name; 384 name = p->cru_name;
327 385
328 alg = crypto_alg_mod_lookup(name, p->cru_type, p->cru_mask); 386 switch (p->cru_type & p->cru_mask & CRYPTO_ALG_TYPE_MASK) {
387 case CRYPTO_ALG_TYPE_AEAD:
388 alg = crypto_user_aead_alg(name, p->cru_type, p->cru_mask);
389 break;
390 case CRYPTO_ALG_TYPE_GIVCIPHER:
391 case CRYPTO_ALG_TYPE_BLKCIPHER:
392 case CRYPTO_ALG_TYPE_ABLKCIPHER:
393 alg = crypto_user_skcipher_alg(name, p->cru_type, p->cru_mask);
394 break;
395 default:
396 alg = crypto_alg_mod_lookup(name, p->cru_type, p->cru_mask);
397 }
398
329 if (IS_ERR(alg)) 399 if (IS_ERR(alg))
330 return PTR_ERR(alg); 400 return PTR_ERR(alg);
331 401
@@ -387,12 +457,20 @@ static int crypto_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
387 457
388 if ((type == (CRYPTO_MSG_GETALG - CRYPTO_MSG_BASE) && 458 if ((type == (CRYPTO_MSG_GETALG - CRYPTO_MSG_BASE) &&
389 (nlh->nlmsg_flags & NLM_F_DUMP))) { 459 (nlh->nlmsg_flags & NLM_F_DUMP))) {
460 struct crypto_alg *alg;
461 u16 dump_alloc = 0;
462
390 if (link->dump == NULL) 463 if (link->dump == NULL)
391 return -EINVAL; 464 return -EINVAL;
465
466 list_for_each_entry(alg, &crypto_alg_list, cra_list)
467 dump_alloc += CRYPTO_REPORT_MAXSIZE;
468
392 { 469 {
393 struct netlink_dump_control c = { 470 struct netlink_dump_control c = {
394 .dump = link->dump, 471 .dump = link->dump,
395 .done = link->done, 472 .done = link->done,
473 .min_dump_alloc = dump_alloc,
396 }; 474 };
397 return netlink_dump_start(crypto_nlsk, skb, nlh, &c); 475 return netlink_dump_start(crypto_nlsk, skb, nlh, &c);
398 } 476 }
diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
index 29a89dad68b6..b2c99dc1c5e2 100644
--- a/crypto/pcrypt.c
+++ b/crypto/pcrypt.c
@@ -280,11 +280,11 @@ static int pcrypt_aead_init_tfm(struct crypto_tfm *tfm)
280 280
281 ictx->tfm_count++; 281 ictx->tfm_count++;
282 282
283 cpu_index = ictx->tfm_count % cpumask_weight(cpu_active_mask); 283 cpu_index = ictx->tfm_count % cpumask_weight(cpu_online_mask);
284 284
285 ctx->cb_cpu = cpumask_first(cpu_active_mask); 285 ctx->cb_cpu = cpumask_first(cpu_online_mask);
286 for (cpu = 0; cpu < cpu_index; cpu++) 286 for (cpu = 0; cpu < cpu_index; cpu++)
287 ctx->cb_cpu = cpumask_next(ctx->cb_cpu, cpu_active_mask); 287 ctx->cb_cpu = cpumask_next(ctx->cb_cpu, cpu_online_mask);
288 288
289 cipher = crypto_spawn_aead(crypto_instance_ctx(inst)); 289 cipher = crypto_spawn_aead(crypto_instance_ctx(inst));
290 290
@@ -472,7 +472,7 @@ static int pcrypt_init_padata(struct padata_pcrypt *pcrypt,
472 goto err_free_padata; 472 goto err_free_padata;
473 } 473 }
474 474
475 cpumask_and(mask->mask, cpu_possible_mask, cpu_active_mask); 475 cpumask_and(mask->mask, cpu_possible_mask, cpu_online_mask);
476 rcu_assign_pointer(pcrypt->cb_cpumask, mask); 476 rcu_assign_pointer(pcrypt->cb_cpumask, mask);
477 477
478 pcrypt->nblock.notifier_call = pcrypt_cpumask_change_notify; 478 pcrypt->nblock.notifier_call = pcrypt_cpumask_change_notify;
diff --git a/crypto/sha512_generic.c b/crypto/sha512_generic.c
index 107f6f7be5e1..dd30f40af9f5 100644
--- a/crypto/sha512_generic.c
+++ b/crypto/sha512_generic.c
@@ -174,7 +174,7 @@ sha512_update(struct shash_desc *desc, const u8 *data, unsigned int len)
174 index = sctx->count[0] & 0x7f; 174 index = sctx->count[0] & 0x7f;
175 175
176 /* Update number of bytes */ 176 /* Update number of bytes */
177 if (!(sctx->count[0] += len)) 177 if ((sctx->count[0] += len) < len)
178 sctx->count[1]++; 178 sctx->count[1]++;
179 179
180 part_len = 128 - index; 180 part_len = 128 - index;
diff --git a/drivers/Kconfig b/drivers/Kconfig
index 6f0459cb745b..d236aef7e59f 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -50,6 +50,8 @@ source "drivers/i2c/Kconfig"
50 50
51source "drivers/spi/Kconfig" 51source "drivers/spi/Kconfig"
52 52
53source "drivers/hsi/Kconfig"
54
53source "drivers/pps/Kconfig" 55source "drivers/pps/Kconfig"
54 56
55source "drivers/ptp/Kconfig" 57source "drivers/ptp/Kconfig"
diff --git a/drivers/Makefile b/drivers/Makefile
index 262b19d6b627..95952c82bf16 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -53,6 +53,7 @@ obj-$(CONFIG_ATA) += ata/
53obj-$(CONFIG_TARGET_CORE) += target/ 53obj-$(CONFIG_TARGET_CORE) += target/
54obj-$(CONFIG_MTD) += mtd/ 54obj-$(CONFIG_MTD) += mtd/
55obj-$(CONFIG_SPI) += spi/ 55obj-$(CONFIG_SPI) += spi/
56obj-y += hsi/
56obj-y += net/ 57obj-y += net/
57obj-$(CONFIG_ATM) += atm/ 58obj-$(CONFIG_ATM) += atm/
58obj-$(CONFIG_FUSION) += message/ 59obj-$(CONFIG_FUSION) += message/
diff --git a/drivers/acpi/acpica/hwxface.c b/drivers/acpi/acpica/hwxface.c
index ab513a972c95..a716fede4f25 100644
--- a/drivers/acpi/acpica/hwxface.c
+++ b/drivers/acpi/acpica/hwxface.c
@@ -74,7 +74,8 @@ acpi_status acpi_reset(void)
74 74
75 /* Check if the reset register is supported */ 75 /* Check if the reset register is supported */
76 76
77 if (!reset_reg->address) { 77 if (!(acpi_gbl_FADT.flags & ACPI_FADT_RESET_REGISTER) ||
78 !reset_reg->address) {
78 return_ACPI_STATUS(AE_NOT_EXIST); 79 return_ACPI_STATUS(AE_NOT_EXIST);
79 } 80 }
80 81
diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
index b258cab9061c..7586544fddb4 100644
--- a/drivers/acpi/ec_sys.c
+++ b/drivers/acpi/ec_sys.c
@@ -27,12 +27,6 @@ MODULE_PARM_DESC(write_support, "Dangerous, reboot and removal of battery may "
27 27
28static struct dentry *acpi_ec_debugfs_dir; 28static struct dentry *acpi_ec_debugfs_dir;
29 29
30static int acpi_ec_open_io(struct inode *i, struct file *f)
31{
32 f->private_data = i->i_private;
33 return 0;
34}
35
36static ssize_t acpi_ec_read_io(struct file *f, char __user *buf, 30static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
37 size_t count, loff_t *off) 31 size_t count, loff_t *off)
38{ 32{
@@ -95,7 +89,7 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
95 89
96static const struct file_operations acpi_ec_io_ops = { 90static const struct file_operations acpi_ec_io_ops = {
97 .owner = THIS_MODULE, 91 .owner = THIS_MODULE,
98 .open = acpi_ec_open_io, 92 .open = simple_open,
99 .read = acpi_ec_read_io, 93 .read = acpi_ec_read_io,
100 .write = acpi_ec_write_io, 94 .write = acpi_ec_write_io,
101 .llseek = default_llseek, 95 .llseek = default_llseek,
diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c
index ba14fb93c929..c3881b2eb8b2 100644
--- a/drivers/acpi/osl.c
+++ b/drivers/acpi/osl.c
@@ -607,8 +607,7 @@ acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler,
607 607
608 acpi_irq_handler = handler; 608 acpi_irq_handler = handler;
609 acpi_irq_context = context; 609 acpi_irq_context = context;
610 if (request_threaded_irq(irq, NULL, acpi_irq, IRQF_SHARED, "acpi", 610 if (request_irq(irq, acpi_irq, IRQF_SHARED, "acpi", acpi_irq)) {
611 acpi_irq)) {
612 printk(KERN_ERR PREFIX "SCI (IRQ%d) allocation failed\n", irq); 611 printk(KERN_ERR PREFIX "SCI (IRQ%d) allocation failed\n", irq);
613 acpi_irq_handler = NULL; 612 acpi_irq_handler = NULL;
614 return AE_NOT_ACQUIRED; 613 return AE_NOT_ACQUIRED;
diff --git a/drivers/acpi/power.c b/drivers/acpi/power.c
index 7049a7d27c4f..330bb4d75852 100644
--- a/drivers/acpi/power.c
+++ b/drivers/acpi/power.c
@@ -631,7 +631,7 @@ int acpi_power_get_inferred_state(struct acpi_device *device, int *state)
631 * We know a device's inferred power state when all the resources 631 * We know a device's inferred power state when all the resources
632 * required for a given D-state are 'on'. 632 * required for a given D-state are 'on'.
633 */ 633 */
634 for (i = ACPI_STATE_D0; i < ACPI_STATE_D3; i++) { 634 for (i = ACPI_STATE_D0; i < ACPI_STATE_D3_HOT; i++) {
635 list = &device->power.states[i].resources; 635 list = &device->power.states[i].resources;
636 if (list->count < 1) 636 if (list->count < 1)
637 continue; 637 continue;
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
index b3447f63e46b..f3decb30223f 100644
--- a/drivers/acpi/processor_idle.c
+++ b/drivers/acpi/processor_idle.c
@@ -786,7 +786,7 @@ static int acpi_idle_play_dead(struct cpuidle_device *dev, int index)
786 while (1) { 786 while (1) {
787 787
788 if (cx->entry_method == ACPI_CSTATE_HALT) 788 if (cx->entry_method == ACPI_CSTATE_HALT)
789 halt(); 789 safe_halt();
790 else if (cx->entry_method == ACPI_CSTATE_SYSTEMIO) { 790 else if (cx->entry_method == ACPI_CSTATE_SYSTEMIO) {
791 inb(cx->address); 791 inb(cx->address);
792 /* See comment in acpi_idle_do_entry() */ 792 /* See comment in acpi_idle_do_entry() */
diff --git a/drivers/acpi/reboot.c b/drivers/acpi/reboot.c
index c1d612435939..a6c77e8b37bd 100644
--- a/drivers/acpi/reboot.c
+++ b/drivers/acpi/reboot.c
@@ -23,7 +23,8 @@ void acpi_reboot(void)
23 /* Is the reset register supported? The spec says we should be 23 /* Is the reset register supported? The spec says we should be
24 * checking the bit width and bit offset, but Windows ignores 24 * checking the bit width and bit offset, but Windows ignores
25 * these fields */ 25 * these fields */
26 /* Ignore also acpi_gbl_FADT.flags.ACPI_FADT_RESET_REGISTER */ 26 if (!(acpi_gbl_FADT.flags & ACPI_FADT_RESET_REGISTER))
27 return;
27 28
28 reset_value = acpi_gbl_FADT.reset_value; 29 reset_value = acpi_gbl_FADT.reset_value;
29 30
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 767e2dcb9616..7417267e88fa 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -869,7 +869,7 @@ static int acpi_bus_get_power_flags(struct acpi_device *device)
869 /* 869 /*
870 * Enumerate supported power management states 870 * Enumerate supported power management states
871 */ 871 */
872 for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3; i++) { 872 for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3_HOT; i++) {
873 struct acpi_device_power_state *ps = &device->power.states[i]; 873 struct acpi_device_power_state *ps = &device->power.states[i];
874 char object_name[5] = { '_', 'P', 'R', '0' + i, '\0' }; 874 char object_name[5] = { '_', 'P', 'R', '0' + i, '\0' };
875 875
@@ -884,21 +884,18 @@ static int acpi_bus_get_power_flags(struct acpi_device *device)
884 acpi_bus_add_power_resource(ps->resources.handles[j]); 884 acpi_bus_add_power_resource(ps->resources.handles[j]);
885 } 885 }
886 886
887 /* The exist of _PR3 indicates D3Cold support */
888 if (i == ACPI_STATE_D3) {
889 status = acpi_get_handle(device->handle, object_name, &handle);
890 if (ACPI_SUCCESS(status))
891 device->power.states[ACPI_STATE_D3_COLD].flags.valid = 1;
892 }
893
894 /* Evaluate "_PSx" to see if we can do explicit sets */ 887 /* Evaluate "_PSx" to see if we can do explicit sets */
895 object_name[2] = 'S'; 888 object_name[2] = 'S';
896 status = acpi_get_handle(device->handle, object_name, &handle); 889 status = acpi_get_handle(device->handle, object_name, &handle);
897 if (ACPI_SUCCESS(status)) 890 if (ACPI_SUCCESS(status))
898 ps->flags.explicit_set = 1; 891 ps->flags.explicit_set = 1;
899 892
900 /* State is valid if we have some power control */ 893 /*
901 if (ps->resources.count || ps->flags.explicit_set) 894 * State is valid if there are means to put the device into it.
895 * D3hot is only valid if _PR3 present.
896 */
897 if (ps->resources.count ||
898 (ps->flags.explicit_set && i < ACPI_STATE_D3_HOT))
902 ps->flags.valid = 1; 899 ps->flags.valid = 1;
903 900
904 ps->power = -1; /* Unknown - driver assigned */ 901 ps->power = -1; /* Unknown - driver assigned */
diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c
index 1d661b5c3287..eb6fd233764b 100644
--- a/drivers/acpi/sleep.c
+++ b/drivers/acpi/sleep.c
@@ -28,23 +28,33 @@
28#include "internal.h" 28#include "internal.h"
29#include "sleep.h" 29#include "sleep.h"
30 30
31u8 wake_sleep_flags = ACPI_NO_OPTIONAL_METHODS;
31static unsigned int gts, bfs; 32static unsigned int gts, bfs;
32module_param(gts, uint, 0644); 33static int set_param_wake_flag(const char *val, struct kernel_param *kp)
33module_param(bfs, uint, 0644);
34MODULE_PARM_DESC(gts, "Enable evaluation of _GTS on suspend.");
35MODULE_PARM_DESC(bfs, "Enable evaluation of _BFS on resume".);
36
37static u8 wake_sleep_flags(void)
38{ 34{
39 u8 flags = ACPI_NO_OPTIONAL_METHODS; 35 int ret = param_set_int(val, kp);
40 36
41 if (gts) 37 if (ret)
42 flags |= ACPI_EXECUTE_GTS; 38 return ret;
43 if (bfs)
44 flags |= ACPI_EXECUTE_BFS;
45 39
46 return flags; 40 if (kp->arg == (const char *)&gts) {
41 if (gts)
42 wake_sleep_flags |= ACPI_EXECUTE_GTS;
43 else
44 wake_sleep_flags &= ~ACPI_EXECUTE_GTS;
45 }
46 if (kp->arg == (const char *)&bfs) {
47 if (bfs)
48 wake_sleep_flags |= ACPI_EXECUTE_BFS;
49 else
50 wake_sleep_flags &= ~ACPI_EXECUTE_BFS;
51 }
52 return ret;
47} 53}
54module_param_call(gts, set_param_wake_flag, param_get_int, &gts, 0644);
55module_param_call(bfs, set_param_wake_flag, param_get_int, &bfs, 0644);
56MODULE_PARM_DESC(gts, "Enable evaluation of _GTS on suspend.");
57MODULE_PARM_DESC(bfs, "Enable evaluation of _BFS on resume".);
48 58
49static u8 sleep_states[ACPI_S_STATE_COUNT]; 59static u8 sleep_states[ACPI_S_STATE_COUNT];
50 60
@@ -263,7 +273,6 @@ static int acpi_suspend_enter(suspend_state_t pm_state)
263{ 273{
264 acpi_status status = AE_OK; 274 acpi_status status = AE_OK;
265 u32 acpi_state = acpi_target_sleep_state; 275 u32 acpi_state = acpi_target_sleep_state;
266 u8 flags = wake_sleep_flags();
267 int error; 276 int error;
268 277
269 ACPI_FLUSH_CPU_CACHE(); 278 ACPI_FLUSH_CPU_CACHE();
@@ -271,7 +280,7 @@ static int acpi_suspend_enter(suspend_state_t pm_state)
271 switch (acpi_state) { 280 switch (acpi_state) {
272 case ACPI_STATE_S1: 281 case ACPI_STATE_S1:
273 barrier(); 282 barrier();
274 status = acpi_enter_sleep_state(acpi_state, flags); 283 status = acpi_enter_sleep_state(acpi_state, wake_sleep_flags);
275 break; 284 break;
276 285
277 case ACPI_STATE_S3: 286 case ACPI_STATE_S3:
@@ -286,7 +295,7 @@ static int acpi_suspend_enter(suspend_state_t pm_state)
286 acpi_write_bit_register(ACPI_BITREG_SCI_ENABLE, 1); 295 acpi_write_bit_register(ACPI_BITREG_SCI_ENABLE, 1);
287 296
288 /* Reprogram control registers and execute _BFS */ 297 /* Reprogram control registers and execute _BFS */
289 acpi_leave_sleep_state_prep(acpi_state, flags); 298 acpi_leave_sleep_state_prep(acpi_state, wake_sleep_flags);
290 299
291 /* ACPI 3.0 specs (P62) says that it's the responsibility 300 /* ACPI 3.0 specs (P62) says that it's the responsibility
292 * of the OSPM to clear the status bit [ implying that the 301 * of the OSPM to clear the status bit [ implying that the
@@ -550,30 +559,27 @@ static int acpi_hibernation_begin(void)
550 559
551static int acpi_hibernation_enter(void) 560static int acpi_hibernation_enter(void)
552{ 561{
553 u8 flags = wake_sleep_flags();
554 acpi_status status = AE_OK; 562 acpi_status status = AE_OK;
555 563
556 ACPI_FLUSH_CPU_CACHE(); 564 ACPI_FLUSH_CPU_CACHE();
557 565
558 /* This shouldn't return. If it returns, we have a problem */ 566 /* This shouldn't return. If it returns, we have a problem */
559 status = acpi_enter_sleep_state(ACPI_STATE_S4, flags); 567 status = acpi_enter_sleep_state(ACPI_STATE_S4, wake_sleep_flags);
560 /* Reprogram control registers and execute _BFS */ 568 /* Reprogram control registers and execute _BFS */
561 acpi_leave_sleep_state_prep(ACPI_STATE_S4, flags); 569 acpi_leave_sleep_state_prep(ACPI_STATE_S4, wake_sleep_flags);
562 570
563 return ACPI_SUCCESS(status) ? 0 : -EFAULT; 571 return ACPI_SUCCESS(status) ? 0 : -EFAULT;
564} 572}
565 573
566static void acpi_hibernation_leave(void) 574static void acpi_hibernation_leave(void)
567{ 575{
568 u8 flags = wake_sleep_flags();
569
570 /* 576 /*
571 * If ACPI is not enabled by the BIOS and the boot kernel, we need to 577 * If ACPI is not enabled by the BIOS and the boot kernel, we need to
572 * enable it here. 578 * enable it here.
573 */ 579 */
574 acpi_enable(); 580 acpi_enable();
575 /* Reprogram control registers and execute _BFS */ 581 /* Reprogram control registers and execute _BFS */
576 acpi_leave_sleep_state_prep(ACPI_STATE_S4, flags); 582 acpi_leave_sleep_state_prep(ACPI_STATE_S4, wake_sleep_flags);
577 /* Check the hardware signature */ 583 /* Check the hardware signature */
578 if (facs && s4_hardware_signature != facs->hardware_signature) { 584 if (facs && s4_hardware_signature != facs->hardware_signature) {
579 printk(KERN_EMERG "ACPI: Hardware changed while hibernated, " 585 printk(KERN_EMERG "ACPI: Hardware changed while hibernated, "
@@ -828,12 +834,10 @@ static void acpi_power_off_prepare(void)
828 834
829static void acpi_power_off(void) 835static void acpi_power_off(void)
830{ 836{
831 u8 flags = wake_sleep_flags();
832
833 /* acpi_sleep_prepare(ACPI_STATE_S5) should have already been called */ 837 /* acpi_sleep_prepare(ACPI_STATE_S5) should have already been called */
834 printk(KERN_DEBUG "%s called\n", __func__); 838 printk(KERN_DEBUG "%s called\n", __func__);
835 local_irq_disable(); 839 local_irq_disable();
836 acpi_enter_sleep_state(ACPI_STATE_S5, flags); 840 acpi_enter_sleep_state(ACPI_STATE_S5, wake_sleep_flags);
837} 841}
838 842
839/* 843/*
diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index 01c2cf4efcdd..cc273226dbd0 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -247,8 +247,7 @@ static int amba_pm_restore(struct device *dev)
247/* 247/*
248 * Hooks to provide runtime PM of the pclk (bus clock). It is safe to 248 * Hooks to provide runtime PM of the pclk (bus clock). It is safe to
249 * enable/disable the bus clock at runtime PM suspend/resume as this 249 * enable/disable the bus clock at runtime PM suspend/resume as this
250 * does not result in loss of context. However, disabling vcore power 250 * does not result in loss of context.
251 * would do, so we leave that to the driver.
252 */ 251 */
253static int amba_pm_runtime_suspend(struct device *dev) 252static int amba_pm_runtime_suspend(struct device *dev)
254{ 253{
@@ -354,39 +353,6 @@ static void amba_put_disable_pclk(struct amba_device *pcdev)
354 clk_put(pclk); 353 clk_put(pclk);
355} 354}
356 355
357static int amba_get_enable_vcore(struct amba_device *pcdev)
358{
359 struct regulator *vcore = regulator_get(&pcdev->dev, "vcore");
360 int ret;
361
362 pcdev->vcore = vcore;
363
364 if (IS_ERR(vcore)) {
365 /* It is OK not to supply a vcore regulator */
366 if (PTR_ERR(vcore) == -ENODEV)
367 return 0;
368 return PTR_ERR(vcore);
369 }
370
371 ret = regulator_enable(vcore);
372 if (ret) {
373 regulator_put(vcore);
374 pcdev->vcore = ERR_PTR(-ENODEV);
375 }
376
377 return ret;
378}
379
380static void amba_put_disable_vcore(struct amba_device *pcdev)
381{
382 struct regulator *vcore = pcdev->vcore;
383
384 if (!IS_ERR(vcore)) {
385 regulator_disable(vcore);
386 regulator_put(vcore);
387 }
388}
389
390/* 356/*
391 * These are the device model conversion veneers; they convert the 357 * These are the device model conversion veneers; they convert the
392 * device model structures to our more specific structures. 358 * device model structures to our more specific structures.
@@ -399,10 +365,6 @@ static int amba_probe(struct device *dev)
399 int ret; 365 int ret;
400 366
401 do { 367 do {
402 ret = amba_get_enable_vcore(pcdev);
403 if (ret)
404 break;
405
406 ret = amba_get_enable_pclk(pcdev); 368 ret = amba_get_enable_pclk(pcdev);
407 if (ret) 369 if (ret)
408 break; 370 break;
@@ -420,7 +382,6 @@ static int amba_probe(struct device *dev)
420 pm_runtime_put_noidle(dev); 382 pm_runtime_put_noidle(dev);
421 383
422 amba_put_disable_pclk(pcdev); 384 amba_put_disable_pclk(pcdev);
423 amba_put_disable_vcore(pcdev);
424 } while (0); 385 } while (0);
425 386
426 return ret; 387 return ret;
@@ -442,7 +403,6 @@ static int amba_remove(struct device *dev)
442 pm_runtime_put_noidle(dev); 403 pm_runtime_put_noidle(dev);
443 404
444 amba_put_disable_pclk(pcdev); 405 amba_put_disable_pclk(pcdev);
445 amba_put_disable_vcore(pcdev);
446 406
447 return ret; 407 return ret;
448} 408}
diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index 79a1e9dd56d9..ebaf67e4b2bc 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -394,6 +394,8 @@ static const struct pci_device_id ahci_pci_tbl[] = {
394 .driver_data = board_ahci_yes_fbs }, /* 88se9128 */ 394 .driver_data = board_ahci_yes_fbs }, /* 88se9128 */
395 { PCI_DEVICE(0x1b4b, 0x9125), 395 { PCI_DEVICE(0x1b4b, 0x9125),
396 .driver_data = board_ahci_yes_fbs }, /* 88se9125 */ 396 .driver_data = board_ahci_yes_fbs }, /* 88se9125 */
397 { PCI_DEVICE(0x1b4b, 0x917a),
398 .driver_data = board_ahci_yes_fbs }, /* 88se9172 */
397 { PCI_DEVICE(0x1b4b, 0x91a3), 399 { PCI_DEVICE(0x1b4b, 0x91a3),
398 .driver_data = board_ahci_yes_fbs }, 400 .driver_data = board_ahci_yes_fbs },
399 401
diff --git a/drivers/ata/ahci_platform.c b/drivers/ata/ahci_platform.c
index 0c86c77764bc..9e419e1c2006 100644
--- a/drivers/ata/ahci_platform.c
+++ b/drivers/ata/ahci_platform.c
@@ -280,6 +280,7 @@ static struct dev_pm_ops ahci_pm_ops = {
280 280
281static const struct of_device_id ahci_of_match[] = { 281static const struct of_device_id ahci_of_match[] = {
282 { .compatible = "calxeda,hb-ahci", }, 282 { .compatible = "calxeda,hb-ahci", },
283 { .compatible = "snps,spear-ahci", },
283 {}, 284 {},
284}; 285};
285MODULE_DEVICE_TABLE(of, ahci_of_match); 286MODULE_DEVICE_TABLE(of, ahci_of_match);
diff --git a/drivers/ata/ata_piix.c b/drivers/ata/ata_piix.c
index 68013f96729f..7857e8fd0a3e 100644
--- a/drivers/ata/ata_piix.c
+++ b/drivers/ata/ata_piix.c
@@ -329,6 +329,8 @@ static const struct pci_device_id piix_pci_tbl[] = {
329 { 0x8086, 0x8c08, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata }, 329 { 0x8086, 0x8c08, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata },
330 /* SATA Controller IDE (Lynx Point) */ 330 /* SATA Controller IDE (Lynx Point) */
331 { 0x8086, 0x8c09, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata }, 331 { 0x8086, 0x8c09, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata },
332 /* SATA Controller IDE (DH89xxCC) */
333 { 0x8086, 0x2326, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata },
332 { } /* terminate list */ 334 { } /* terminate list */
333}; 335};
334 336
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index e0bda9ff89cd..23763a1ec570 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -95,7 +95,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
95static void ata_dev_xfermask(struct ata_device *dev); 95static void ata_dev_xfermask(struct ata_device *dev);
96static unsigned long ata_dev_blacklisted(const struct ata_device *dev); 96static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
97 97
98unsigned int ata_print_id = 1; 98atomic_t ata_print_id = ATOMIC_INIT(0);
99 99
100struct ata_force_param { 100struct ata_force_param {
101 const char *name; 101 const char *name;
@@ -6029,7 +6029,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
6029 6029
6030 /* give ports names and add SCSI hosts */ 6030 /* give ports names and add SCSI hosts */
6031 for (i = 0; i < host->n_ports; i++) 6031 for (i = 0; i < host->n_ports; i++)
6032 host->ports[i]->print_id = ata_print_id++; 6032 host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
6033 6033
6034 6034
6035 /* Create associated sysfs transport objects */ 6035 /* Create associated sysfs transport objects */
diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c
index c61316e9d2f7..d1fbd59ead16 100644
--- a/drivers/ata/libata-eh.c
+++ b/drivers/ata/libata-eh.c
@@ -3501,7 +3501,8 @@ static int ata_count_probe_trials_cb(struct ata_ering_entry *ent, void *void_arg
3501 u64 now = get_jiffies_64(); 3501 u64 now = get_jiffies_64();
3502 int *trials = void_arg; 3502 int *trials = void_arg;
3503 3503
3504 if (ent->timestamp < now - min(now, interval)) 3504 if ((ent->eflags & ATA_EFLAG_OLD_ER) ||
3505 (ent->timestamp < now - min(now, interval)))
3505 return -1; 3506 return -1;
3506 3507
3507 (*trials)++; 3508 (*trials)++;
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 1ee00c8b5b04..22226350cd0c 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -3399,7 +3399,8 @@ int ata_scsi_add_hosts(struct ata_host *host, struct scsi_host_template *sht)
3399 */ 3399 */
3400 shost->max_host_blocked = 1; 3400 shost->max_host_blocked = 1;
3401 3401
3402 rc = scsi_add_host(ap->scsi_host, &ap->tdev); 3402 rc = scsi_add_host_with_dma(ap->scsi_host,
3403 &ap->tdev, ap->host->dev);
3403 if (rc) 3404 if (rc)
3404 goto err_add; 3405 goto err_add;
3405 } 3406 }
@@ -3838,18 +3839,25 @@ void ata_sas_port_stop(struct ata_port *ap)
3838} 3839}
3839EXPORT_SYMBOL_GPL(ata_sas_port_stop); 3840EXPORT_SYMBOL_GPL(ata_sas_port_stop);
3840 3841
3841int ata_sas_async_port_init(struct ata_port *ap) 3842/**
3843 * ata_sas_async_probe - simply schedule probing and return
3844 * @ap: Port to probe
3845 *
3846 * For batch scheduling of probe for sas attached ata devices, assumes
3847 * the port has already been through ata_sas_port_init()
3848 */
3849void ata_sas_async_probe(struct ata_port *ap)
3842{ 3850{
3843 int rc = ap->ops->port_start(ap); 3851 __ata_port_probe(ap);
3844 3852}
3845 if (!rc) { 3853EXPORT_SYMBOL_GPL(ata_sas_async_probe);
3846 ap->print_id = ata_print_id++;
3847 __ata_port_probe(ap);
3848 }
3849 3854
3850 return rc; 3855int ata_sas_sync_probe(struct ata_port *ap)
3856{
3857 return ata_port_probe(ap);
3851} 3858}
3852EXPORT_SYMBOL_GPL(ata_sas_async_port_init); 3859EXPORT_SYMBOL_GPL(ata_sas_sync_probe);
3860
3853 3861
3854/** 3862/**
3855 * ata_sas_port_init - Initialize a SATA device 3863 * ata_sas_port_init - Initialize a SATA device
@@ -3866,12 +3874,10 @@ int ata_sas_port_init(struct ata_port *ap)
3866{ 3874{
3867 int rc = ap->ops->port_start(ap); 3875 int rc = ap->ops->port_start(ap);
3868 3876
3869 if (!rc) { 3877 if (rc)
3870 ap->print_id = ata_print_id++; 3878 return rc;
3871 rc = ata_port_probe(ap); 3879 ap->print_id = atomic_inc_return(&ata_print_id);
3872 } 3880 return 0;
3873
3874 return rc;
3875} 3881}
3876EXPORT_SYMBOL_GPL(ata_sas_port_init); 3882EXPORT_SYMBOL_GPL(ata_sas_port_init);
3877 3883
diff --git a/drivers/ata/libata-transport.c b/drivers/ata/libata-transport.c
index 74aaee30e264..c34190485377 100644
--- a/drivers/ata/libata-transport.c
+++ b/drivers/ata/libata-transport.c
@@ -294,6 +294,7 @@ int ata_tport_add(struct device *parent,
294 device_enable_async_suspend(dev); 294 device_enable_async_suspend(dev);
295 pm_runtime_set_active(dev); 295 pm_runtime_set_active(dev);
296 pm_runtime_enable(dev); 296 pm_runtime_enable(dev);
297 pm_runtime_forbid(dev);
297 298
298 transport_add_device(dev); 299 transport_add_device(dev);
299 transport_configure_device(dev); 300 transport_configure_device(dev);
diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
index 2e26fcaf635b..9d0fd0b71852 100644
--- a/drivers/ata/libata.h
+++ b/drivers/ata/libata.h
@@ -53,7 +53,7 @@ enum {
53 ATA_DNXFER_QUIET = (1 << 31), 53 ATA_DNXFER_QUIET = (1 << 31),
54}; 54};
55 55
56extern unsigned int ata_print_id; 56extern atomic_t ata_print_id;
57extern int atapi_passthru16; 57extern int atapi_passthru16;
58extern int libata_fua; 58extern int libata_fua;
59extern int libata_noacpi; 59extern int libata_noacpi;
diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
index fc2db2a89a6b..3239517f4d90 100644
--- a/drivers/ata/pata_arasan_cf.c
+++ b/drivers/ata/pata_arasan_cf.c
@@ -943,9 +943,9 @@ static int arasan_cf_resume(struct device *dev)
943 943
944 return 0; 944 return 0;
945} 945}
946#endif
946 947
947static SIMPLE_DEV_PM_OPS(arasan_cf_pm_ops, arasan_cf_suspend, arasan_cf_resume); 948static SIMPLE_DEV_PM_OPS(arasan_cf_pm_ops, arasan_cf_suspend, arasan_cf_resume);
948#endif
949 949
950static struct platform_driver arasan_cf_driver = { 950static struct platform_driver arasan_cf_driver = {
951 .probe = arasan_cf_probe, 951 .probe = arasan_cf_probe,
@@ -953,9 +953,7 @@ static struct platform_driver arasan_cf_driver = {
953 .driver = { 953 .driver = {
954 .name = DRIVER_NAME, 954 .name = DRIVER_NAME,
955 .owner = THIS_MODULE, 955 .owner = THIS_MODULE,
956#ifdef CONFIG_PM
957 .pm = &arasan_cf_pm_ops, 956 .pm = &arasan_cf_pm_ops,
958#endif
959 }, 957 },
960}; 958};
961 959
diff --git a/drivers/ata/sata_mv.c b/drivers/ata/sata_mv.c
index 38950ea8398a..7336d4a7ab31 100644
--- a/drivers/ata/sata_mv.c
+++ b/drivers/ata/sata_mv.c
@@ -4025,7 +4025,8 @@ static int mv_platform_probe(struct platform_device *pdev)
4025 struct ata_host *host; 4025 struct ata_host *host;
4026 struct mv_host_priv *hpriv; 4026 struct mv_host_priv *hpriv;
4027 struct resource *res; 4027 struct resource *res;
4028 int n_ports, rc; 4028 int n_ports = 0;
4029 int rc;
4029 4030
4030 ata_print_version_once(&pdev->dev, DRV_VERSION); 4031 ata_print_version_once(&pdev->dev, DRV_VERSION);
4031 4032
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index 6c9387d646ec..5401814c874d 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -16,10 +16,11 @@
16#include <linux/interrupt.h> 16#include <linux/interrupt.h>
17#include <linux/bitops.h> 17#include <linux/bitops.h>
18#include <linux/mutex.h> 18#include <linux/mutex.h>
19#include <linux/kthread.h> 19#include <linux/workqueue.h>
20#include <linux/highmem.h> 20#include <linux/highmem.h>
21#include <linux/firmware.h> 21#include <linux/firmware.h>
22#include <linux/slab.h> 22#include <linux/slab.h>
23#include <linux/sched.h>
23 24
24#define to_dev(obj) container_of(obj, struct device, kobj) 25#define to_dev(obj) container_of(obj, struct device, kobj)
25 26
@@ -81,6 +82,11 @@ enum {
81 82
82static int loading_timeout = 60; /* In seconds */ 83static int loading_timeout = 60; /* In seconds */
83 84
85static inline long firmware_loading_timeout(void)
86{
87 return loading_timeout > 0 ? loading_timeout * HZ : MAX_SCHEDULE_TIMEOUT;
88}
89
84/* fw_lock could be moved to 'struct firmware_priv' but since it is just 90/* fw_lock could be moved to 'struct firmware_priv' but since it is just
85 * guarding for corner cases a global lock should be OK */ 91 * guarding for corner cases a global lock should be OK */
86static DEFINE_MUTEX(fw_lock); 92static DEFINE_MUTEX(fw_lock);
@@ -440,13 +446,11 @@ fw_create_instance(struct firmware *firmware, const char *fw_name,
440{ 446{
441 struct firmware_priv *fw_priv; 447 struct firmware_priv *fw_priv;
442 struct device *f_dev; 448 struct device *f_dev;
443 int error;
444 449
445 fw_priv = kzalloc(sizeof(*fw_priv) + strlen(fw_name) + 1 , GFP_KERNEL); 450 fw_priv = kzalloc(sizeof(*fw_priv) + strlen(fw_name) + 1 , GFP_KERNEL);
446 if (!fw_priv) { 451 if (!fw_priv) {
447 dev_err(device, "%s: kmalloc failed\n", __func__); 452 dev_err(device, "%s: kmalloc failed\n", __func__);
448 error = -ENOMEM; 453 return ERR_PTR(-ENOMEM);
449 goto err_out;
450 } 454 }
451 455
452 fw_priv->fw = firmware; 456 fw_priv->fw = firmware;
@@ -463,98 +467,80 @@ fw_create_instance(struct firmware *firmware, const char *fw_name,
463 f_dev->parent = device; 467 f_dev->parent = device;
464 f_dev->class = &firmware_class; 468 f_dev->class = &firmware_class;
465 469
466 dev_set_uevent_suppress(f_dev, true);
467
468 /* Need to pin this module until class device is destroyed */
469 __module_get(THIS_MODULE);
470
471 error = device_add(f_dev);
472 if (error) {
473 dev_err(device, "%s: device_register failed\n", __func__);
474 goto err_put_dev;
475 }
476
477 error = device_create_bin_file(f_dev, &firmware_attr_data);
478 if (error) {
479 dev_err(device, "%s: sysfs_create_bin_file failed\n", __func__);
480 goto err_del_dev;
481 }
482
483 error = device_create_file(f_dev, &dev_attr_loading);
484 if (error) {
485 dev_err(device, "%s: device_create_file failed\n", __func__);
486 goto err_del_bin_attr;
487 }
488
489 if (uevent)
490 dev_set_uevent_suppress(f_dev, false);
491
492 return fw_priv; 470 return fw_priv;
493
494err_del_bin_attr:
495 device_remove_bin_file(f_dev, &firmware_attr_data);
496err_del_dev:
497 device_del(f_dev);
498err_put_dev:
499 put_device(f_dev);
500err_out:
501 return ERR_PTR(error);
502} 471}
503 472
504static void fw_destroy_instance(struct firmware_priv *fw_priv) 473static struct firmware_priv *
505{ 474_request_firmware_prepare(const struct firmware **firmware_p, const char *name,
506 struct device *f_dev = &fw_priv->dev; 475 struct device *device, bool uevent, bool nowait)
507
508 device_remove_file(f_dev, &dev_attr_loading);
509 device_remove_bin_file(f_dev, &firmware_attr_data);
510 device_unregister(f_dev);
511}
512
513static int _request_firmware(const struct firmware **firmware_p,
514 const char *name, struct device *device,
515 bool uevent, bool nowait)
516{ 476{
517 struct firmware_priv *fw_priv;
518 struct firmware *firmware; 477 struct firmware *firmware;
519 int retval = 0; 478 struct firmware_priv *fw_priv;
520 479
521 if (!firmware_p) 480 if (!firmware_p)
522 return -EINVAL; 481 return ERR_PTR(-EINVAL);
523 482
524 *firmware_p = firmware = kzalloc(sizeof(*firmware), GFP_KERNEL); 483 *firmware_p = firmware = kzalloc(sizeof(*firmware), GFP_KERNEL);
525 if (!firmware) { 484 if (!firmware) {
526 dev_err(device, "%s: kmalloc(struct firmware) failed\n", 485 dev_err(device, "%s: kmalloc(struct firmware) failed\n",
527 __func__); 486 __func__);
528 return -ENOMEM; 487 return ERR_PTR(-ENOMEM);
529 } 488 }
530 489
531 if (fw_get_builtin_firmware(firmware, name)) { 490 if (fw_get_builtin_firmware(firmware, name)) {
532 dev_dbg(device, "firmware: using built-in firmware %s\n", name); 491 dev_dbg(device, "firmware: using built-in firmware %s\n", name);
533 return 0; 492 return NULL;
493 }
494
495 fw_priv = fw_create_instance(firmware, name, device, uevent, nowait);
496 if (IS_ERR(fw_priv)) {
497 release_firmware(firmware);
498 *firmware_p = NULL;
534 } 499 }
500 return fw_priv;
501}
535 502
536 read_lock_usermodehelper(); 503static void _request_firmware_cleanup(const struct firmware **firmware_p)
504{
505 release_firmware(*firmware_p);
506 *firmware_p = NULL;
507}
537 508
538 if (WARN_ON(usermodehelper_is_disabled())) { 509static int _request_firmware_load(struct firmware_priv *fw_priv, bool uevent,
539 dev_err(device, "firmware: %s will not be loaded\n", name); 510 long timeout)
540 retval = -EBUSY; 511{
541 goto out; 512 int retval = 0;
513 struct device *f_dev = &fw_priv->dev;
514
515 dev_set_uevent_suppress(f_dev, true);
516
517 /* Need to pin this module until class device is destroyed */
518 __module_get(THIS_MODULE);
519
520 retval = device_add(f_dev);
521 if (retval) {
522 dev_err(f_dev, "%s: device_register failed\n", __func__);
523 goto err_put_dev;
542 } 524 }
543 525
544 if (uevent) 526 retval = device_create_bin_file(f_dev, &firmware_attr_data);
545 dev_dbg(device, "firmware: requesting %s\n", name); 527 if (retval) {
528 dev_err(f_dev, "%s: sysfs_create_bin_file failed\n", __func__);
529 goto err_del_dev;
530 }
546 531
547 fw_priv = fw_create_instance(firmware, name, device, uevent, nowait); 532 retval = device_create_file(f_dev, &dev_attr_loading);
548 if (IS_ERR(fw_priv)) { 533 if (retval) {
549 retval = PTR_ERR(fw_priv); 534 dev_err(f_dev, "%s: device_create_file failed\n", __func__);
550 goto out; 535 goto err_del_bin_attr;
551 } 536 }
552 537
553 if (uevent) { 538 if (uevent) {
554 if (loading_timeout > 0) 539 dev_set_uevent_suppress(f_dev, false);
540 dev_dbg(f_dev, "firmware: requesting %s\n", fw_priv->fw_id);
541 if (timeout != MAX_SCHEDULE_TIMEOUT)
555 mod_timer(&fw_priv->timeout, 542 mod_timer(&fw_priv->timeout,
556 round_jiffies_up(jiffies + 543 round_jiffies_up(jiffies + timeout));
557 loading_timeout * HZ));
558 544
559 kobject_uevent(&fw_priv->dev.kobj, KOBJ_ADD); 545 kobject_uevent(&fw_priv->dev.kobj, KOBJ_ADD);
560 } 546 }
@@ -570,16 +556,13 @@ static int _request_firmware(const struct firmware **firmware_p,
570 fw_priv->fw = NULL; 556 fw_priv->fw = NULL;
571 mutex_unlock(&fw_lock); 557 mutex_unlock(&fw_lock);
572 558
573 fw_destroy_instance(fw_priv); 559 device_remove_file(f_dev, &dev_attr_loading);
574 560err_del_bin_attr:
575out: 561 device_remove_bin_file(f_dev, &firmware_attr_data);
576 read_unlock_usermodehelper(); 562err_del_dev:
577 563 device_del(f_dev);
578 if (retval) { 564err_put_dev:
579 release_firmware(firmware); 565 put_device(f_dev);
580 *firmware_p = NULL;
581 }
582
583 return retval; 566 return retval;
584} 567}
585 568
@@ -602,7 +585,26 @@ int
602request_firmware(const struct firmware **firmware_p, const char *name, 585request_firmware(const struct firmware **firmware_p, const char *name,
603 struct device *device) 586 struct device *device)
604{ 587{
605 return _request_firmware(firmware_p, name, device, true, false); 588 struct firmware_priv *fw_priv;
589 int ret;
590
591 fw_priv = _request_firmware_prepare(firmware_p, name, device, true,
592 false);
593 if (IS_ERR_OR_NULL(fw_priv))
594 return PTR_RET(fw_priv);
595
596 ret = usermodehelper_read_trylock();
597 if (WARN_ON(ret)) {
598 dev_err(device, "firmware: %s will not be loaded\n", name);
599 } else {
600 ret = _request_firmware_load(fw_priv, true,
601 firmware_loading_timeout());
602 usermodehelper_read_unlock();
603 }
604 if (ret)
605 _request_firmware_cleanup(firmware_p);
606
607 return ret;
606} 608}
607 609
608/** 610/**
@@ -629,25 +631,39 @@ struct firmware_work {
629 bool uevent; 631 bool uevent;
630}; 632};
631 633
632static int request_firmware_work_func(void *arg) 634static void request_firmware_work_func(struct work_struct *work)
633{ 635{
634 struct firmware_work *fw_work = arg; 636 struct firmware_work *fw_work;
635 const struct firmware *fw; 637 const struct firmware *fw;
638 struct firmware_priv *fw_priv;
639 long timeout;
636 int ret; 640 int ret;
637 641
638 if (!arg) { 642 fw_work = container_of(work, struct firmware_work, work);
639 WARN_ON(1); 643 fw_priv = _request_firmware_prepare(&fw, fw_work->name, fw_work->device,
640 return 0; 644 fw_work->uevent, true);
645 if (IS_ERR_OR_NULL(fw_priv)) {
646 ret = PTR_RET(fw_priv);
647 goto out;
648 }
649
650 timeout = usermodehelper_read_lock_wait(firmware_loading_timeout());
651 if (timeout) {
652 ret = _request_firmware_load(fw_priv, fw_work->uevent, timeout);
653 usermodehelper_read_unlock();
654 } else {
655 dev_dbg(fw_work->device, "firmware: %s loading timed out\n",
656 fw_work->name);
657 ret = -EAGAIN;
641 } 658 }
659 if (ret)
660 _request_firmware_cleanup(&fw);
642 661
643 ret = _request_firmware(&fw, fw_work->name, fw_work->device, 662 out:
644 fw_work->uevent, true);
645 fw_work->cont(fw, fw_work->context); 663 fw_work->cont(fw, fw_work->context);
646 664
647 module_put(fw_work->module); 665 module_put(fw_work->module);
648 kfree(fw_work); 666 kfree(fw_work);
649
650 return ret;
651} 667}
652 668
653/** 669/**
@@ -673,7 +689,6 @@ request_firmware_nowait(
673 const char *name, struct device *device, gfp_t gfp, void *context, 689 const char *name, struct device *device, gfp_t gfp, void *context,
674 void (*cont)(const struct firmware *fw, void *context)) 690 void (*cont)(const struct firmware *fw, void *context))
675{ 691{
676 struct task_struct *task;
677 struct firmware_work *fw_work; 692 struct firmware_work *fw_work;
678 693
679 fw_work = kzalloc(sizeof (struct firmware_work), gfp); 694 fw_work = kzalloc(sizeof (struct firmware_work), gfp);
@@ -692,15 +707,8 @@ request_firmware_nowait(
692 return -EFAULT; 707 return -EFAULT;
693 } 708 }
694 709
695 task = kthread_run(request_firmware_work_func, fw_work, 710 INIT_WORK(&fw_work->work, request_firmware_work_func);
696 "firmware/%s", name); 711 schedule_work(&fw_work->work);
697 if (IS_ERR(task)) {
698 fw_work->cont(NULL, fw_work->context);
699 module_put(fw_work->module);
700 kfree(fw_work);
701 return PTR_ERR(task);
702 }
703
704 return 0; 712 return 0;
705} 713}
706 714
diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
index 541f821d4ea6..bd0f3949bcf9 100644
--- a/drivers/base/power/runtime.c
+++ b/drivers/base/power/runtime.c
@@ -532,6 +532,8 @@ static int rpm_suspend(struct device *dev, int rpmflags)
532 dev->power.suspend_time = ktime_set(0, 0); 532 dev->power.suspend_time = ktime_set(0, 0);
533 dev->power.max_time_suspended_ns = -1; 533 dev->power.max_time_suspended_ns = -1;
534 dev->power.deferred_resume = false; 534 dev->power.deferred_resume = false;
535 wake_up_all(&dev->power.wait_queue);
536
535 if (retval == -EAGAIN || retval == -EBUSY) { 537 if (retval == -EAGAIN || retval == -EBUSY) {
536 dev->power.runtime_error = 0; 538 dev->power.runtime_error = 0;
537 539
@@ -547,7 +549,6 @@ static int rpm_suspend(struct device *dev, int rpmflags)
547 } else { 549 } else {
548 pm_runtime_cancel_pending(dev); 550 pm_runtime_cancel_pending(dev);
549 } 551 }
550 wake_up_all(&dev->power.wait_queue);
551 goto out; 552 goto out;
552} 553}
553 554
diff --git a/drivers/base/regmap/Kconfig b/drivers/base/regmap/Kconfig
index 0f6c7fb418e8..9ef0a5326f17 100644
--- a/drivers/base/regmap/Kconfig
+++ b/drivers/base/regmap/Kconfig
@@ -14,5 +14,8 @@ config REGMAP_I2C
14config REGMAP_SPI 14config REGMAP_SPI
15 tristate 15 tristate
16 16
17config REGMAP_MMIO
18 tristate
19
17config REGMAP_IRQ 20config REGMAP_IRQ
18 bool 21 bool
diff --git a/drivers/base/regmap/Makefile b/drivers/base/regmap/Makefile
index defd57963c84..5e75d1b683e2 100644
--- a/drivers/base/regmap/Makefile
+++ b/drivers/base/regmap/Makefile
@@ -3,4 +3,5 @@ obj-$(CONFIG_REGMAP) += regcache-rbtree.o regcache-lzo.o
3obj-$(CONFIG_DEBUG_FS) += regmap-debugfs.o 3obj-$(CONFIG_DEBUG_FS) += regmap-debugfs.o
4obj-$(CONFIG_REGMAP_I2C) += regmap-i2c.o 4obj-$(CONFIG_REGMAP_I2C) += regmap-i2c.o
5obj-$(CONFIG_REGMAP_SPI) += regmap-spi.o 5obj-$(CONFIG_REGMAP_SPI) += regmap-spi.o
6obj-$(CONFIG_REGMAP_MMIO) += regmap-mmio.o
6obj-$(CONFIG_REGMAP_IRQ) += regmap-irq.o 7obj-$(CONFIG_REGMAP_IRQ) += regmap-irq.o
diff --git a/drivers/base/regmap/internal.h b/drivers/base/regmap/internal.h
index fcafc5b2e651..d92e9b1cb83c 100644
--- a/drivers/base/regmap/internal.h
+++ b/drivers/base/regmap/internal.h
@@ -26,21 +26,29 @@ struct regmap_format {
26 size_t val_bytes; 26 size_t val_bytes;
27 void (*format_write)(struct regmap *map, 27 void (*format_write)(struct regmap *map,
28 unsigned int reg, unsigned int val); 28 unsigned int reg, unsigned int val);
29 void (*format_reg)(void *buf, unsigned int reg); 29 void (*format_reg)(void *buf, unsigned int reg, unsigned int shift);
30 void (*format_val)(void *buf, unsigned int val); 30 void (*format_val)(void *buf, unsigned int val, unsigned int shift);
31 unsigned int (*parse_val)(void *buf); 31 unsigned int (*parse_val)(void *buf);
32}; 32};
33 33
34typedef void (*regmap_lock)(struct regmap *map);
35typedef void (*regmap_unlock)(struct regmap *map);
36
34struct regmap { 37struct regmap {
35 struct mutex lock; 38 struct mutex mutex;
39 spinlock_t spinlock;
40 regmap_lock lock;
41 regmap_unlock unlock;
36 42
37 struct device *dev; /* Device we do I/O on */ 43 struct device *dev; /* Device we do I/O on */
38 void *work_buf; /* Scratch buffer used to format I/O */ 44 void *work_buf; /* Scratch buffer used to format I/O */
39 struct regmap_format format; /* Buffer format */ 45 struct regmap_format format; /* Buffer format */
40 const struct regmap_bus *bus; 46 const struct regmap_bus *bus;
47 void *bus_context;
41 48
42#ifdef CONFIG_DEBUG_FS 49#ifdef CONFIG_DEBUG_FS
43 struct dentry *debugfs; 50 struct dentry *debugfs;
51 const char *debugfs_name;
44#endif 52#endif
45 53
46 unsigned int max_register; 54 unsigned int max_register;
@@ -52,6 +60,10 @@ struct regmap {
52 u8 read_flag_mask; 60 u8 read_flag_mask;
53 u8 write_flag_mask; 61 u8 write_flag_mask;
54 62
63 /* number of bits to (left) shift the reg value when formatting*/
64 int reg_shift;
65 int reg_stride;
66
55 /* regcache specific members */ 67 /* regcache specific members */
56 const struct regcache_ops *cache_ops; 68 const struct regcache_ops *cache_ops;
57 enum regcache_type cache_type; 69 enum regcache_type cache_type;
@@ -101,11 +113,11 @@ int _regmap_write(struct regmap *map, unsigned int reg,
101 113
102#ifdef CONFIG_DEBUG_FS 114#ifdef CONFIG_DEBUG_FS
103extern void regmap_debugfs_initcall(void); 115extern void regmap_debugfs_initcall(void);
104extern void regmap_debugfs_init(struct regmap *map); 116extern void regmap_debugfs_init(struct regmap *map, const char *name);
105extern void regmap_debugfs_exit(struct regmap *map); 117extern void regmap_debugfs_exit(struct regmap *map);
106#else 118#else
107static inline void regmap_debugfs_initcall(void) { } 119static inline void regmap_debugfs_initcall(void) { }
108static inline void regmap_debugfs_init(struct regmap *map) { } 120static inline void regmap_debugfs_init(struct regmap *map, const char *name) { }
109static inline void regmap_debugfs_exit(struct regmap *map) { } 121static inline void regmap_debugfs_exit(struct regmap *map) { }
110#endif 122#endif
111 123
diff --git a/drivers/base/regmap/regcache-lzo.c b/drivers/base/regmap/regcache-lzo.c
index 483b06d4a380..afd6aa91a0df 100644
--- a/drivers/base/regmap/regcache-lzo.c
+++ b/drivers/base/regmap/regcache-lzo.c
@@ -108,7 +108,7 @@ static int regcache_lzo_decompress_cache_block(struct regmap *map,
108static inline int regcache_lzo_get_blkindex(struct regmap *map, 108static inline int regcache_lzo_get_blkindex(struct regmap *map,
109 unsigned int reg) 109 unsigned int reg)
110{ 110{
111 return (reg * map->cache_word_size) / 111 return ((reg / map->reg_stride) * map->cache_word_size) /
112 DIV_ROUND_UP(map->cache_size_raw, 112 DIV_ROUND_UP(map->cache_size_raw,
113 regcache_lzo_block_count(map)); 113 regcache_lzo_block_count(map));
114} 114}
@@ -116,9 +116,10 @@ static inline int regcache_lzo_get_blkindex(struct regmap *map,
116static inline int regcache_lzo_get_blkpos(struct regmap *map, 116static inline int regcache_lzo_get_blkpos(struct regmap *map,
117 unsigned int reg) 117 unsigned int reg)
118{ 118{
119 return reg % (DIV_ROUND_UP(map->cache_size_raw, 119 return (reg / map->reg_stride) %
120 regcache_lzo_block_count(map)) / 120 (DIV_ROUND_UP(map->cache_size_raw,
121 map->cache_word_size); 121 regcache_lzo_block_count(map)) /
122 map->cache_word_size);
122} 123}
123 124
124static inline int regcache_lzo_get_blksize(struct regmap *map) 125static inline int regcache_lzo_get_blksize(struct regmap *map)
@@ -322,7 +323,7 @@ static int regcache_lzo_write(struct regmap *map,
322 } 323 }
323 324
324 /* set the bit so we know we have to sync this register */ 325 /* set the bit so we know we have to sync this register */
325 set_bit(reg, lzo_block->sync_bmp); 326 set_bit(reg / map->reg_stride, lzo_block->sync_bmp);
326 kfree(tmp_dst); 327 kfree(tmp_dst);
327 kfree(lzo_block->src); 328 kfree(lzo_block->src);
328 return 0; 329 return 0;
diff --git a/drivers/base/regmap/regcache-rbtree.c b/drivers/base/regmap/regcache-rbtree.c
index 5157fa04c2f0..e6732cf7c06e 100644
--- a/drivers/base/regmap/regcache-rbtree.c
+++ b/drivers/base/regmap/regcache-rbtree.c
@@ -39,11 +39,12 @@ struct regcache_rbtree_ctx {
39}; 39};
40 40
41static inline void regcache_rbtree_get_base_top_reg( 41static inline void regcache_rbtree_get_base_top_reg(
42 struct regmap *map,
42 struct regcache_rbtree_node *rbnode, 43 struct regcache_rbtree_node *rbnode,
43 unsigned int *base, unsigned int *top) 44 unsigned int *base, unsigned int *top)
44{ 45{
45 *base = rbnode->base_reg; 46 *base = rbnode->base_reg;
46 *top = rbnode->base_reg + rbnode->blklen - 1; 47 *top = rbnode->base_reg + ((rbnode->blklen - 1) * map->reg_stride);
47} 48}
48 49
49static unsigned int regcache_rbtree_get_register( 50static unsigned int regcache_rbtree_get_register(
@@ -70,7 +71,8 @@ static struct regcache_rbtree_node *regcache_rbtree_lookup(struct regmap *map,
70 71
71 rbnode = rbtree_ctx->cached_rbnode; 72 rbnode = rbtree_ctx->cached_rbnode;
72 if (rbnode) { 73 if (rbnode) {
73 regcache_rbtree_get_base_top_reg(rbnode, &base_reg, &top_reg); 74 regcache_rbtree_get_base_top_reg(map, rbnode, &base_reg,
75 &top_reg);
74 if (reg >= base_reg && reg <= top_reg) 76 if (reg >= base_reg && reg <= top_reg)
75 return rbnode; 77 return rbnode;
76 } 78 }
@@ -78,7 +80,8 @@ static struct regcache_rbtree_node *regcache_rbtree_lookup(struct regmap *map,
78 node = rbtree_ctx->root.rb_node; 80 node = rbtree_ctx->root.rb_node;
79 while (node) { 81 while (node) {
80 rbnode = container_of(node, struct regcache_rbtree_node, node); 82 rbnode = container_of(node, struct regcache_rbtree_node, node);
81 regcache_rbtree_get_base_top_reg(rbnode, &base_reg, &top_reg); 83 regcache_rbtree_get_base_top_reg(map, rbnode, &base_reg,
84 &top_reg);
82 if (reg >= base_reg && reg <= top_reg) { 85 if (reg >= base_reg && reg <= top_reg) {
83 rbtree_ctx->cached_rbnode = rbnode; 86 rbtree_ctx->cached_rbnode = rbnode;
84 return rbnode; 87 return rbnode;
@@ -92,7 +95,7 @@ static struct regcache_rbtree_node *regcache_rbtree_lookup(struct regmap *map,
92 return NULL; 95 return NULL;
93} 96}
94 97
95static int regcache_rbtree_insert(struct rb_root *root, 98static int regcache_rbtree_insert(struct regmap *map, struct rb_root *root,
96 struct regcache_rbtree_node *rbnode) 99 struct regcache_rbtree_node *rbnode)
97{ 100{
98 struct rb_node **new, *parent; 101 struct rb_node **new, *parent;
@@ -106,7 +109,7 @@ static int regcache_rbtree_insert(struct rb_root *root,
106 rbnode_tmp = container_of(*new, struct regcache_rbtree_node, 109 rbnode_tmp = container_of(*new, struct regcache_rbtree_node,
107 node); 110 node);
108 /* base and top registers of the current rbnode */ 111 /* base and top registers of the current rbnode */
109 regcache_rbtree_get_base_top_reg(rbnode_tmp, &base_reg_tmp, 112 regcache_rbtree_get_base_top_reg(map, rbnode_tmp, &base_reg_tmp,
110 &top_reg_tmp); 113 &top_reg_tmp);
111 /* base register of the rbnode to be added */ 114 /* base register of the rbnode to be added */
112 base_reg = rbnode->base_reg; 115 base_reg = rbnode->base_reg;
@@ -138,24 +141,31 @@ static int rbtree_show(struct seq_file *s, void *ignored)
138 unsigned int base, top; 141 unsigned int base, top;
139 int nodes = 0; 142 int nodes = 0;
140 int registers = 0; 143 int registers = 0;
144 int this_registers, average;
141 145
142 mutex_lock(&map->lock); 146 map->lock(map);
143 147
144 for (node = rb_first(&rbtree_ctx->root); node != NULL; 148 for (node = rb_first(&rbtree_ctx->root); node != NULL;
145 node = rb_next(node)) { 149 node = rb_next(node)) {
146 n = container_of(node, struct regcache_rbtree_node, node); 150 n = container_of(node, struct regcache_rbtree_node, node);
147 151
148 regcache_rbtree_get_base_top_reg(n, &base, &top); 152 regcache_rbtree_get_base_top_reg(map, n, &base, &top);
149 seq_printf(s, "%x-%x (%d)\n", base, top, top - base + 1); 153 this_registers = ((top - base) / map->reg_stride) + 1;
154 seq_printf(s, "%x-%x (%d)\n", base, top, this_registers);
150 155
151 nodes++; 156 nodes++;
152 registers += top - base + 1; 157 registers += this_registers;
153 } 158 }
154 159
160 if (nodes)
161 average = registers / nodes;
162 else
163 average = 0;
164
155 seq_printf(s, "%d nodes, %d registers, average %d registers\n", 165 seq_printf(s, "%d nodes, %d registers, average %d registers\n",
156 nodes, registers, registers / nodes); 166 nodes, registers, average);
157 167
158 mutex_unlock(&map->lock); 168 map->unlock(map);
159 169
160 return 0; 170 return 0;
161} 171}
@@ -249,7 +259,7 @@ static int regcache_rbtree_read(struct regmap *map,
249 259
250 rbnode = regcache_rbtree_lookup(map, reg); 260 rbnode = regcache_rbtree_lookup(map, reg);
251 if (rbnode) { 261 if (rbnode) {
252 reg_tmp = reg - rbnode->base_reg; 262 reg_tmp = (reg - rbnode->base_reg) / map->reg_stride;
253 *value = regcache_rbtree_get_register(rbnode, reg_tmp, 263 *value = regcache_rbtree_get_register(rbnode, reg_tmp,
254 map->cache_word_size); 264 map->cache_word_size);
255 } else { 265 } else {
@@ -304,7 +314,7 @@ static int regcache_rbtree_write(struct regmap *map, unsigned int reg,
304 */ 314 */
305 rbnode = regcache_rbtree_lookup(map, reg); 315 rbnode = regcache_rbtree_lookup(map, reg);
306 if (rbnode) { 316 if (rbnode) {
307 reg_tmp = reg - rbnode->base_reg; 317 reg_tmp = (reg - rbnode->base_reg) / map->reg_stride;
308 val = regcache_rbtree_get_register(rbnode, reg_tmp, 318 val = regcache_rbtree_get_register(rbnode, reg_tmp,
309 map->cache_word_size); 319 map->cache_word_size);
310 if (val == value) 320 if (val == value)
@@ -315,13 +325,15 @@ static int regcache_rbtree_write(struct regmap *map, unsigned int reg,
315 /* look for an adjacent register to the one we are about to add */ 325 /* look for an adjacent register to the one we are about to add */
316 for (node = rb_first(&rbtree_ctx->root); node; 326 for (node = rb_first(&rbtree_ctx->root); node;
317 node = rb_next(node)) { 327 node = rb_next(node)) {
318 rbnode_tmp = rb_entry(node, struct regcache_rbtree_node, node); 328 rbnode_tmp = rb_entry(node, struct regcache_rbtree_node,
329 node);
319 for (i = 0; i < rbnode_tmp->blklen; i++) { 330 for (i = 0; i < rbnode_tmp->blklen; i++) {
320 reg_tmp = rbnode_tmp->base_reg + i; 331 reg_tmp = rbnode_tmp->base_reg +
321 if (abs(reg_tmp - reg) != 1) 332 (i * map->reg_stride);
333 if (abs(reg_tmp - reg) != map->reg_stride)
322 continue; 334 continue;
323 /* decide where in the block to place our register */ 335 /* decide where in the block to place our register */
324 if (reg_tmp + 1 == reg) 336 if (reg_tmp + map->reg_stride == reg)
325 pos = i + 1; 337 pos = i + 1;
326 else 338 else
327 pos = i; 339 pos = i;
@@ -351,7 +363,7 @@ static int regcache_rbtree_write(struct regmap *map, unsigned int reg,
351 return -ENOMEM; 363 return -ENOMEM;
352 } 364 }
353 regcache_rbtree_set_register(rbnode, 0, value, map->cache_word_size); 365 regcache_rbtree_set_register(rbnode, 0, value, map->cache_word_size);
354 regcache_rbtree_insert(&rbtree_ctx->root, rbnode); 366 regcache_rbtree_insert(map, &rbtree_ctx->root, rbnode);
355 rbtree_ctx->cached_rbnode = rbnode; 367 rbtree_ctx->cached_rbnode = rbnode;
356 } 368 }
357 369
@@ -391,12 +403,12 @@ static int regcache_rbtree_sync(struct regmap *map, unsigned int min,
391 end = rbnode->blklen; 403 end = rbnode->blklen;
392 404
393 for (i = base; i < end; i++) { 405 for (i = base; i < end; i++) {
394 regtmp = rbnode->base_reg + i; 406 regtmp = rbnode->base_reg + (i * map->reg_stride);
395 val = regcache_rbtree_get_register(rbnode, i, 407 val = regcache_rbtree_get_register(rbnode, i,
396 map->cache_word_size); 408 map->cache_word_size);
397 409
398 /* Is this the hardware default? If so skip. */ 410 /* Is this the hardware default? If so skip. */
399 ret = regcache_lookup_reg(map, i); 411 ret = regcache_lookup_reg(map, regtmp);
400 if (ret >= 0 && val == map->reg_defaults[ret].def) 412 if (ret >= 0 && val == map->reg_defaults[ret].def)
401 continue; 413 continue;
402 414
diff --git a/drivers/base/regmap/regcache.c b/drivers/base/regmap/regcache.c
index 87f54dbf601b..835883bda977 100644
--- a/drivers/base/regmap/regcache.c
+++ b/drivers/base/regmap/regcache.c
@@ -59,7 +59,7 @@ static int regcache_hw_init(struct regmap *map)
59 for (count = 0, i = 0; i < map->num_reg_defaults_raw; i++) { 59 for (count = 0, i = 0; i < map->num_reg_defaults_raw; i++) {
60 val = regcache_get_val(map->reg_defaults_raw, 60 val = regcache_get_val(map->reg_defaults_raw,
61 i, map->cache_word_size); 61 i, map->cache_word_size);
62 if (regmap_volatile(map, i)) 62 if (regmap_volatile(map, i * map->reg_stride))
63 continue; 63 continue;
64 count++; 64 count++;
65 } 65 }
@@ -76,9 +76,9 @@ static int regcache_hw_init(struct regmap *map)
76 for (i = 0, j = 0; i < map->num_reg_defaults_raw; i++) { 76 for (i = 0, j = 0; i < map->num_reg_defaults_raw; i++) {
77 val = regcache_get_val(map->reg_defaults_raw, 77 val = regcache_get_val(map->reg_defaults_raw,
78 i, map->cache_word_size); 78 i, map->cache_word_size);
79 if (regmap_volatile(map, i)) 79 if (regmap_volatile(map, i * map->reg_stride))
80 continue; 80 continue;
81 map->reg_defaults[j].reg = i; 81 map->reg_defaults[j].reg = i * map->reg_stride;
82 map->reg_defaults[j].def = val; 82 map->reg_defaults[j].def = val;
83 j++; 83 j++;
84 } 84 }
@@ -98,6 +98,10 @@ int regcache_init(struct regmap *map, const struct regmap_config *config)
98 int i; 98 int i;
99 void *tmp_buf; 99 void *tmp_buf;
100 100
101 for (i = 0; i < config->num_reg_defaults; i++)
102 if (config->reg_defaults[i].reg % map->reg_stride)
103 return -EINVAL;
104
101 if (map->cache_type == REGCACHE_NONE) { 105 if (map->cache_type == REGCACHE_NONE) {
102 map->cache_bypass = true; 106 map->cache_bypass = true;
103 return 0; 107 return 0;
@@ -264,7 +268,7 @@ int regcache_sync(struct regmap *map)
264 268
265 BUG_ON(!map->cache_ops || !map->cache_ops->sync); 269 BUG_ON(!map->cache_ops || !map->cache_ops->sync);
266 270
267 mutex_lock(&map->lock); 271 map->lock(map);
268 /* Remember the initial bypass state */ 272 /* Remember the initial bypass state */
269 bypass = map->cache_bypass; 273 bypass = map->cache_bypass;
270 dev_dbg(map->dev, "Syncing %s cache\n", 274 dev_dbg(map->dev, "Syncing %s cache\n",
@@ -278,6 +282,10 @@ int regcache_sync(struct regmap *map)
278 /* Apply any patch first */ 282 /* Apply any patch first */
279 map->cache_bypass = 1; 283 map->cache_bypass = 1;
280 for (i = 0; i < map->patch_regs; i++) { 284 for (i = 0; i < map->patch_regs; i++) {
285 if (map->patch[i].reg % map->reg_stride) {
286 ret = -EINVAL;
287 goto out;
288 }
281 ret = _regmap_write(map, map->patch[i].reg, map->patch[i].def); 289 ret = _regmap_write(map, map->patch[i].reg, map->patch[i].def);
282 if (ret != 0) { 290 if (ret != 0) {
283 dev_err(map->dev, "Failed to write %x = %x: %d\n", 291 dev_err(map->dev, "Failed to write %x = %x: %d\n",
@@ -296,7 +304,7 @@ out:
296 trace_regcache_sync(map->dev, name, "stop"); 304 trace_regcache_sync(map->dev, name, "stop");
297 /* Restore the bypass state */ 305 /* Restore the bypass state */
298 map->cache_bypass = bypass; 306 map->cache_bypass = bypass;
299 mutex_unlock(&map->lock); 307 map->unlock(map);
300 308
301 return ret; 309 return ret;
302} 310}
@@ -323,7 +331,7 @@ int regcache_sync_region(struct regmap *map, unsigned int min,
323 331
324 BUG_ON(!map->cache_ops || !map->cache_ops->sync); 332 BUG_ON(!map->cache_ops || !map->cache_ops->sync);
325 333
326 mutex_lock(&map->lock); 334 map->lock(map);
327 335
328 /* Remember the initial bypass state */ 336 /* Remember the initial bypass state */
329 bypass = map->cache_bypass; 337 bypass = map->cache_bypass;
@@ -342,10 +350,11 @@ out:
342 trace_regcache_sync(map->dev, name, "stop region"); 350 trace_regcache_sync(map->dev, name, "stop region");
343 /* Restore the bypass state */ 351 /* Restore the bypass state */
344 map->cache_bypass = bypass; 352 map->cache_bypass = bypass;
345 mutex_unlock(&map->lock); 353 map->unlock(map);
346 354
347 return ret; 355 return ret;
348} 356}
357EXPORT_SYMBOL_GPL(regcache_sync_region);
349 358
350/** 359/**
351 * regcache_cache_only: Put a register map into cache only mode 360 * regcache_cache_only: Put a register map into cache only mode
@@ -361,11 +370,11 @@ out:
361 */ 370 */
362void regcache_cache_only(struct regmap *map, bool enable) 371void regcache_cache_only(struct regmap *map, bool enable)
363{ 372{
364 mutex_lock(&map->lock); 373 map->lock(map);
365 WARN_ON(map->cache_bypass && enable); 374 WARN_ON(map->cache_bypass && enable);
366 map->cache_only = enable; 375 map->cache_only = enable;
367 trace_regmap_cache_only(map->dev, enable); 376 trace_regmap_cache_only(map->dev, enable);
368 mutex_unlock(&map->lock); 377 map->unlock(map);
369} 378}
370EXPORT_SYMBOL_GPL(regcache_cache_only); 379EXPORT_SYMBOL_GPL(regcache_cache_only);
371 380
@@ -380,9 +389,9 @@ EXPORT_SYMBOL_GPL(regcache_cache_only);
380 */ 389 */
381void regcache_mark_dirty(struct regmap *map) 390void regcache_mark_dirty(struct regmap *map)
382{ 391{
383 mutex_lock(&map->lock); 392 map->lock(map);
384 map->cache_dirty = true; 393 map->cache_dirty = true;
385 mutex_unlock(&map->lock); 394 map->unlock(map);
386} 395}
387EXPORT_SYMBOL_GPL(regcache_mark_dirty); 396EXPORT_SYMBOL_GPL(regcache_mark_dirty);
388 397
@@ -399,11 +408,11 @@ EXPORT_SYMBOL_GPL(regcache_mark_dirty);
399 */ 408 */
400void regcache_cache_bypass(struct regmap *map, bool enable) 409void regcache_cache_bypass(struct regmap *map, bool enable)
401{ 410{
402 mutex_lock(&map->lock); 411 map->lock(map);
403 WARN_ON(map->cache_only && enable); 412 WARN_ON(map->cache_only && enable);
404 map->cache_bypass = enable; 413 map->cache_bypass = enable;
405 trace_regmap_cache_bypass(map->dev, enable); 414 trace_regmap_cache_bypass(map->dev, enable);
406 mutex_unlock(&map->lock); 415 map->unlock(map);
407} 416}
408EXPORT_SYMBOL_GPL(regcache_cache_bypass); 417EXPORT_SYMBOL_GPL(regcache_cache_bypass);
409 418
diff --git a/drivers/base/regmap/regmap-debugfs.c b/drivers/base/regmap/regmap-debugfs.c
index 58517a5dac13..bb1ff175b962 100644
--- a/drivers/base/regmap/regmap-debugfs.c
+++ b/drivers/base/regmap/regmap-debugfs.c
@@ -27,12 +27,6 @@ static size_t regmap_calc_reg_len(int max_val, char *buf, size_t buf_size)
27 return strlen(buf); 27 return strlen(buf);
28} 28}
29 29
30static int regmap_open_file(struct inode *inode, struct file *file)
31{
32 file->private_data = inode->i_private;
33 return 0;
34}
35
36static ssize_t regmap_name_read_file(struct file *file, 30static ssize_t regmap_name_read_file(struct file *file,
37 char __user *user_buf, size_t count, 31 char __user *user_buf, size_t count,
38 loff_t *ppos) 32 loff_t *ppos)
@@ -57,7 +51,7 @@ static ssize_t regmap_name_read_file(struct file *file,
57} 51}
58 52
59static const struct file_operations regmap_name_fops = { 53static const struct file_operations regmap_name_fops = {
60 .open = regmap_open_file, 54 .open = simple_open,
61 .read = regmap_name_read_file, 55 .read = regmap_name_read_file,
62 .llseek = default_llseek, 56 .llseek = default_llseek,
63}; 57};
@@ -86,7 +80,7 @@ static ssize_t regmap_map_read_file(struct file *file, char __user *user_buf,
86 val_len = 2 * map->format.val_bytes; 80 val_len = 2 * map->format.val_bytes;
87 tot_len = reg_len + val_len + 3; /* : \n */ 81 tot_len = reg_len + val_len + 3; /* : \n */
88 82
89 for (i = 0; i < map->max_register + 1; i++) { 83 for (i = 0; i <= map->max_register; i += map->reg_stride) {
90 if (!regmap_readable(map, i)) 84 if (!regmap_readable(map, i))
91 continue; 85 continue;
92 86
@@ -174,7 +168,7 @@ static ssize_t regmap_map_write_file(struct file *file,
174#endif 168#endif
175 169
176static const struct file_operations regmap_map_fops = { 170static const struct file_operations regmap_map_fops = {
177 .open = regmap_open_file, 171 .open = simple_open,
178 .read = regmap_map_read_file, 172 .read = regmap_map_read_file,
179 .write = regmap_map_write_file, 173 .write = regmap_map_write_file,
180 .llseek = default_llseek, 174 .llseek = default_llseek,
@@ -203,7 +197,7 @@ static ssize_t regmap_access_read_file(struct file *file,
203 reg_len = regmap_calc_reg_len(map->max_register, buf, count); 197 reg_len = regmap_calc_reg_len(map->max_register, buf, count);
204 tot_len = reg_len + 10; /* ': R W V P\n' */ 198 tot_len = reg_len + 10; /* ': R W V P\n' */
205 199
206 for (i = 0; i < map->max_register + 1; i++) { 200 for (i = 0; i <= map->max_register; i += map->reg_stride) {
207 /* Ignore registers which are neither readable nor writable */ 201 /* Ignore registers which are neither readable nor writable */
208 if (!regmap_readable(map, i) && !regmap_writeable(map, i)) 202 if (!regmap_readable(map, i) && !regmap_writeable(map, i))
209 continue; 203 continue;
@@ -243,15 +237,22 @@ out:
243} 237}
244 238
245static const struct file_operations regmap_access_fops = { 239static const struct file_operations regmap_access_fops = {
246 .open = regmap_open_file, 240 .open = simple_open,
247 .read = regmap_access_read_file, 241 .read = regmap_access_read_file,
248 .llseek = default_llseek, 242 .llseek = default_llseek,
249}; 243};
250 244
251void regmap_debugfs_init(struct regmap *map) 245void regmap_debugfs_init(struct regmap *map, const char *name)
252{ 246{
253 map->debugfs = debugfs_create_dir(dev_name(map->dev), 247 if (name) {
254 regmap_debugfs_root); 248 map->debugfs_name = kasprintf(GFP_KERNEL, "%s-%s",
249 dev_name(map->dev), name);
250 name = map->debugfs_name;
251 } else {
252 name = dev_name(map->dev);
253 }
254
255 map->debugfs = debugfs_create_dir(name, regmap_debugfs_root);
255 if (!map->debugfs) { 256 if (!map->debugfs) {
256 dev_warn(map->dev, "Failed to create debugfs directory\n"); 257 dev_warn(map->dev, "Failed to create debugfs directory\n");
257 return; 258 return;
@@ -280,6 +281,7 @@ void regmap_debugfs_init(struct regmap *map)
280void regmap_debugfs_exit(struct regmap *map) 281void regmap_debugfs_exit(struct regmap *map)
281{ 282{
282 debugfs_remove_recursive(map->debugfs); 283 debugfs_remove_recursive(map->debugfs);
284 kfree(map->debugfs_name);
283} 285}
284 286
285void regmap_debugfs_initcall(void) 287void regmap_debugfs_initcall(void)
diff --git a/drivers/base/regmap/regmap-i2c.c b/drivers/base/regmap/regmap-i2c.c
index 9a3a8c564389..5f6b2478bf17 100644
--- a/drivers/base/regmap/regmap-i2c.c
+++ b/drivers/base/regmap/regmap-i2c.c
@@ -15,8 +15,9 @@
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/init.h> 16#include <linux/init.h>
17 17
18static int regmap_i2c_write(struct device *dev, const void *data, size_t count) 18static int regmap_i2c_write(void *context, const void *data, size_t count)
19{ 19{
20 struct device *dev = context;
20 struct i2c_client *i2c = to_i2c_client(dev); 21 struct i2c_client *i2c = to_i2c_client(dev);
21 int ret; 22 int ret;
22 23
@@ -29,10 +30,11 @@ static int regmap_i2c_write(struct device *dev, const void *data, size_t count)
29 return -EIO; 30 return -EIO;
30} 31}
31 32
32static int regmap_i2c_gather_write(struct device *dev, 33static int regmap_i2c_gather_write(void *context,
33 const void *reg, size_t reg_size, 34 const void *reg, size_t reg_size,
34 const void *val, size_t val_size) 35 const void *val, size_t val_size)
35{ 36{
37 struct device *dev = context;
36 struct i2c_client *i2c = to_i2c_client(dev); 38 struct i2c_client *i2c = to_i2c_client(dev);
37 struct i2c_msg xfer[2]; 39 struct i2c_msg xfer[2];
38 int ret; 40 int ret;
@@ -62,10 +64,11 @@ static int regmap_i2c_gather_write(struct device *dev,
62 return -EIO; 64 return -EIO;
63} 65}
64 66
65static int regmap_i2c_read(struct device *dev, 67static int regmap_i2c_read(void *context,
66 const void *reg, size_t reg_size, 68 const void *reg, size_t reg_size,
67 void *val, size_t val_size) 69 void *val, size_t val_size)
68{ 70{
71 struct device *dev = context;
69 struct i2c_client *i2c = to_i2c_client(dev); 72 struct i2c_client *i2c = to_i2c_client(dev);
70 struct i2c_msg xfer[2]; 73 struct i2c_msg xfer[2];
71 int ret; 74 int ret;
@@ -107,7 +110,7 @@ static struct regmap_bus regmap_i2c = {
107struct regmap *regmap_init_i2c(struct i2c_client *i2c, 110struct regmap *regmap_init_i2c(struct i2c_client *i2c,
108 const struct regmap_config *config) 111 const struct regmap_config *config)
109{ 112{
110 return regmap_init(&i2c->dev, &regmap_i2c, config); 113 return regmap_init(&i2c->dev, &regmap_i2c, &i2c->dev, config);
111} 114}
112EXPORT_SYMBOL_GPL(regmap_init_i2c); 115EXPORT_SYMBOL_GPL(regmap_init_i2c);
113 116
@@ -124,7 +127,7 @@ EXPORT_SYMBOL_GPL(regmap_init_i2c);
124struct regmap *devm_regmap_init_i2c(struct i2c_client *i2c, 127struct regmap *devm_regmap_init_i2c(struct i2c_client *i2c,
125 const struct regmap_config *config) 128 const struct regmap_config *config)
126{ 129{
127 return devm_regmap_init(&i2c->dev, &regmap_i2c, config); 130 return devm_regmap_init(&i2c->dev, &regmap_i2c, &i2c->dev, config);
128} 131}
129EXPORT_SYMBOL_GPL(devm_regmap_init_i2c); 132EXPORT_SYMBOL_GPL(devm_regmap_init_i2c);
130 133
diff --git a/drivers/base/regmap/regmap-irq.c b/drivers/base/regmap/regmap-irq.c
index 1befaa7a31cb..fc69d29d272a 100644
--- a/drivers/base/regmap/regmap-irq.c
+++ b/drivers/base/regmap/regmap-irq.c
@@ -50,6 +50,7 @@ static void regmap_irq_lock(struct irq_data *data)
50static void regmap_irq_sync_unlock(struct irq_data *data) 50static void regmap_irq_sync_unlock(struct irq_data *data)
51{ 51{
52 struct regmap_irq_chip_data *d = irq_data_get_irq_chip_data(data); 52 struct regmap_irq_chip_data *d = irq_data_get_irq_chip_data(data);
53 struct regmap *map = d->map;
53 int i, ret; 54 int i, ret;
54 55
55 /* 56 /*
@@ -58,11 +59,12 @@ static void regmap_irq_sync_unlock(struct irq_data *data)
58 * suppress pointless writes. 59 * suppress pointless writes.
59 */ 60 */
60 for (i = 0; i < d->chip->num_regs; i++) { 61 for (i = 0; i < d->chip->num_regs; i++) {
61 ret = regmap_update_bits(d->map, d->chip->mask_base + i, 62 ret = regmap_update_bits(d->map, d->chip->mask_base +
63 (i * map->reg_stride),
62 d->mask_buf_def[i], d->mask_buf[i]); 64 d->mask_buf_def[i], d->mask_buf[i]);
63 if (ret != 0) 65 if (ret != 0)
64 dev_err(d->map->dev, "Failed to sync masks in %x\n", 66 dev_err(d->map->dev, "Failed to sync masks in %x\n",
65 d->chip->mask_base + i); 67 d->chip->mask_base + (i * map->reg_stride));
66 } 68 }
67 69
68 mutex_unlock(&d->lock); 70 mutex_unlock(&d->lock);
@@ -71,17 +73,19 @@ static void regmap_irq_sync_unlock(struct irq_data *data)
71static void regmap_irq_enable(struct irq_data *data) 73static void regmap_irq_enable(struct irq_data *data)
72{ 74{
73 struct regmap_irq_chip_data *d = irq_data_get_irq_chip_data(data); 75 struct regmap_irq_chip_data *d = irq_data_get_irq_chip_data(data);
76 struct regmap *map = d->map;
74 const struct regmap_irq *irq_data = irq_to_regmap_irq(d, data->irq); 77 const struct regmap_irq *irq_data = irq_to_regmap_irq(d, data->irq);
75 78
76 d->mask_buf[irq_data->reg_offset] &= ~irq_data->mask; 79 d->mask_buf[irq_data->reg_offset / map->reg_stride] &= ~irq_data->mask;
77} 80}
78 81
79static void regmap_irq_disable(struct irq_data *data) 82static void regmap_irq_disable(struct irq_data *data)
80{ 83{
81 struct regmap_irq_chip_data *d = irq_data_get_irq_chip_data(data); 84 struct regmap_irq_chip_data *d = irq_data_get_irq_chip_data(data);
85 struct regmap *map = d->map;
82 const struct regmap_irq *irq_data = irq_to_regmap_irq(d, data->irq); 86 const struct regmap_irq *irq_data = irq_to_regmap_irq(d, data->irq);
83 87
84 d->mask_buf[irq_data->reg_offset] |= irq_data->mask; 88 d->mask_buf[irq_data->reg_offset / map->reg_stride] |= irq_data->mask;
85} 89}
86 90
87static struct irq_chip regmap_irq_chip = { 91static struct irq_chip regmap_irq_chip = {
@@ -136,17 +140,19 @@ static irqreturn_t regmap_irq_thread(int irq, void *d)
136 data->status_buf[i] &= ~data->mask_buf[i]; 140 data->status_buf[i] &= ~data->mask_buf[i];
137 141
138 if (data->status_buf[i] && chip->ack_base) { 142 if (data->status_buf[i] && chip->ack_base) {
139 ret = regmap_write(map, chip->ack_base + i, 143 ret = regmap_write(map, chip->ack_base +
144 (i * map->reg_stride),
140 data->status_buf[i]); 145 data->status_buf[i]);
141 if (ret != 0) 146 if (ret != 0)
142 dev_err(map->dev, "Failed to ack 0x%x: %d\n", 147 dev_err(map->dev, "Failed to ack 0x%x: %d\n",
143 chip->ack_base + i, ret); 148 chip->ack_base + (i * map->reg_stride),
149 ret);
144 } 150 }
145 } 151 }
146 152
147 for (i = 0; i < chip->num_irqs; i++) { 153 for (i = 0; i < chip->num_irqs; i++) {
148 if (data->status_buf[chip->irqs[i].reg_offset] & 154 if (data->status_buf[chip->irqs[i].reg_offset /
149 chip->irqs[i].mask) { 155 map->reg_stride] & chip->irqs[i].mask) {
150 handle_nested_irq(data->irq_base + i); 156 handle_nested_irq(data->irq_base + i);
151 handled = true; 157 handled = true;
152 } 158 }
@@ -181,6 +187,14 @@ int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags,
181 int cur_irq, i; 187 int cur_irq, i;
182 int ret = -ENOMEM; 188 int ret = -ENOMEM;
183 189
190 for (i = 0; i < chip->num_irqs; i++) {
191 if (chip->irqs[i].reg_offset % map->reg_stride)
192 return -EINVAL;
193 if (chip->irqs[i].reg_offset / map->reg_stride >=
194 chip->num_regs)
195 return -EINVAL;
196 }
197
184 irq_base = irq_alloc_descs(irq_base, 0, chip->num_irqs, 0); 198 irq_base = irq_alloc_descs(irq_base, 0, chip->num_irqs, 0);
185 if (irq_base < 0) { 199 if (irq_base < 0) {
186 dev_warn(map->dev, "Failed to allocate IRQs: %d\n", 200 dev_warn(map->dev, "Failed to allocate IRQs: %d\n",
@@ -218,16 +232,17 @@ int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags,
218 mutex_init(&d->lock); 232 mutex_init(&d->lock);
219 233
220 for (i = 0; i < chip->num_irqs; i++) 234 for (i = 0; i < chip->num_irqs; i++)
221 d->mask_buf_def[chip->irqs[i].reg_offset] 235 d->mask_buf_def[chip->irqs[i].reg_offset / map->reg_stride]
222 |= chip->irqs[i].mask; 236 |= chip->irqs[i].mask;
223 237
224 /* Mask all the interrupts by default */ 238 /* Mask all the interrupts by default */
225 for (i = 0; i < chip->num_regs; i++) { 239 for (i = 0; i < chip->num_regs; i++) {
226 d->mask_buf[i] = d->mask_buf_def[i]; 240 d->mask_buf[i] = d->mask_buf_def[i];
227 ret = regmap_write(map, chip->mask_base + i, d->mask_buf[i]); 241 ret = regmap_write(map, chip->mask_base + (i * map->reg_stride),
242 d->mask_buf[i]);
228 if (ret != 0) { 243 if (ret != 0) {
229 dev_err(map->dev, "Failed to set masks in 0x%x: %d\n", 244 dev_err(map->dev, "Failed to set masks in 0x%x: %d\n",
230 chip->mask_base + i, ret); 245 chip->mask_base + (i * map->reg_stride), ret);
231 goto err_alloc; 246 goto err_alloc;
232 } 247 }
233 } 248 }
diff --git a/drivers/base/regmap/regmap-mmio.c b/drivers/base/regmap/regmap-mmio.c
new file mode 100644
index 000000000000..febd6de6c8ac
--- /dev/null
+++ b/drivers/base/regmap/regmap-mmio.c
@@ -0,0 +1,224 @@
1/*
2 * Register map access API - MMIO support
3 *
4 * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <linux/err.h>
20#include <linux/init.h>
21#include <linux/io.h>
22#include <linux/module.h>
23#include <linux/regmap.h>
24#include <linux/slab.h>
25
26struct regmap_mmio_context {
27 void __iomem *regs;
28 unsigned val_bytes;
29};
30
31static int regmap_mmio_gather_write(void *context,
32 const void *reg, size_t reg_size,
33 const void *val, size_t val_size)
34{
35 struct regmap_mmio_context *ctx = context;
36 u32 offset;
37
38 BUG_ON(reg_size != 4);
39
40 offset = be32_to_cpup(reg);
41
42 while (val_size) {
43 switch (ctx->val_bytes) {
44 case 1:
45 writeb(*(u8 *)val, ctx->regs + offset);
46 break;
47 case 2:
48 writew(be16_to_cpup(val), ctx->regs + offset);
49 break;
50 case 4:
51 writel(be32_to_cpup(val), ctx->regs + offset);
52 break;
53#ifdef CONFIG_64BIT
54 case 8:
55 writeq(be64_to_cpup(val), ctx->regs + offset);
56 break;
57#endif
58 default:
59 /* Should be caught by regmap_mmio_check_config */
60 BUG();
61 }
62 val_size -= ctx->val_bytes;
63 val += ctx->val_bytes;
64 offset += ctx->val_bytes;
65 }
66
67 return 0;
68}
69
70static int regmap_mmio_write(void *context, const void *data, size_t count)
71{
72 BUG_ON(count < 4);
73
74 return regmap_mmio_gather_write(context, data, 4, data + 4, count - 4);
75}
76
77static int regmap_mmio_read(void *context,
78 const void *reg, size_t reg_size,
79 void *val, size_t val_size)
80{
81 struct regmap_mmio_context *ctx = context;
82 u32 offset;
83
84 BUG_ON(reg_size != 4);
85
86 offset = be32_to_cpup(reg);
87
88 while (val_size) {
89 switch (ctx->val_bytes) {
90 case 1:
91 *(u8 *)val = readb(ctx->regs + offset);
92 break;
93 case 2:
94 *(u16 *)val = cpu_to_be16(readw(ctx->regs + offset));
95 break;
96 case 4:
97 *(u32 *)val = cpu_to_be32(readl(ctx->regs + offset));
98 break;
99#ifdef CONFIG_64BIT
100 case 8:
101 *(u64 *)val = cpu_to_be32(readq(ctx->regs + offset));
102 break;
103#endif
104 default:
105 /* Should be caught by regmap_mmio_check_config */
106 BUG();
107 }
108 val_size -= ctx->val_bytes;
109 val += ctx->val_bytes;
110 offset += ctx->val_bytes;
111 }
112
113 return 0;
114}
115
116static void regmap_mmio_free_context(void *context)
117{
118 kfree(context);
119}
120
121static struct regmap_bus regmap_mmio = {
122 .fast_io = true,
123 .write = regmap_mmio_write,
124 .gather_write = regmap_mmio_gather_write,
125 .read = regmap_mmio_read,
126 .free_context = regmap_mmio_free_context,
127};
128
129struct regmap_mmio_context *regmap_mmio_gen_context(void __iomem *regs,
130 const struct regmap_config *config)
131{
132 struct regmap_mmio_context *ctx;
133 int min_stride;
134
135 if (config->reg_bits != 32)
136 return ERR_PTR(-EINVAL);
137
138 if (config->pad_bits)
139 return ERR_PTR(-EINVAL);
140
141 switch (config->val_bits) {
142 case 8:
143 /* The core treats 0 as 1 */
144 min_stride = 0;
145 break;
146 case 16:
147 min_stride = 2;
148 break;
149 case 32:
150 min_stride = 4;
151 break;
152#ifdef CONFIG_64BIT
153 case 64:
154 min_stride = 8;
155 break;
156#endif
157 break;
158 default:
159 return ERR_PTR(-EINVAL);
160 }
161
162 if (config->reg_stride < min_stride)
163 return ERR_PTR(-EINVAL);
164
165 ctx = kzalloc(GFP_KERNEL, sizeof(*ctx));
166 if (!ctx)
167 return ERR_PTR(-ENOMEM);
168
169 ctx->regs = regs;
170 ctx->val_bytes = config->val_bits / 8;
171
172 return ctx;
173}
174
175/**
176 * regmap_init_mmio(): Initialise register map
177 *
178 * @dev: Device that will be interacted with
179 * @regs: Pointer to memory-mapped IO region
180 * @config: Configuration for register map
181 *
182 * The return value will be an ERR_PTR() on error or a valid pointer to
183 * a struct regmap.
184 */
185struct regmap *regmap_init_mmio(struct device *dev,
186 void __iomem *regs,
187 const struct regmap_config *config)
188{
189 struct regmap_mmio_context *ctx;
190
191 ctx = regmap_mmio_gen_context(regs, config);
192 if (IS_ERR(ctx))
193 return ERR_CAST(ctx);
194
195 return regmap_init(dev, &regmap_mmio, ctx, config);
196}
197EXPORT_SYMBOL_GPL(regmap_init_mmio);
198
199/**
200 * devm_regmap_init_mmio(): Initialise managed register map
201 *
202 * @dev: Device that will be interacted with
203 * @regs: Pointer to memory-mapped IO region
204 * @config: Configuration for register map
205 *
206 * The return value will be an ERR_PTR() on error or a valid pointer
207 * to a struct regmap. The regmap will be automatically freed by the
208 * device management code.
209 */
210struct regmap *devm_regmap_init_mmio(struct device *dev,
211 void __iomem *regs,
212 const struct regmap_config *config)
213{
214 struct regmap_mmio_context *ctx;
215
216 ctx = regmap_mmio_gen_context(regs, config);
217 if (IS_ERR(ctx))
218 return ERR_CAST(ctx);
219
220 return devm_regmap_init(dev, &regmap_mmio, ctx, config);
221}
222EXPORT_SYMBOL_GPL(devm_regmap_init_mmio);
223
224MODULE_LICENSE("GPL v2");
diff --git a/drivers/base/regmap/regmap-spi.c b/drivers/base/regmap/regmap-spi.c
index 7c0c35a39c33..ffa46a92ad33 100644
--- a/drivers/base/regmap/regmap-spi.c
+++ b/drivers/base/regmap/regmap-spi.c
@@ -15,17 +15,19 @@
15#include <linux/init.h> 15#include <linux/init.h>
16#include <linux/module.h> 16#include <linux/module.h>
17 17
18static int regmap_spi_write(struct device *dev, const void *data, size_t count) 18static int regmap_spi_write(void *context, const void *data, size_t count)
19{ 19{
20 struct device *dev = context;
20 struct spi_device *spi = to_spi_device(dev); 21 struct spi_device *spi = to_spi_device(dev);
21 22
22 return spi_write(spi, data, count); 23 return spi_write(spi, data, count);
23} 24}
24 25
25static int regmap_spi_gather_write(struct device *dev, 26static int regmap_spi_gather_write(void *context,
26 const void *reg, size_t reg_len, 27 const void *reg, size_t reg_len,
27 const void *val, size_t val_len) 28 const void *val, size_t val_len)
28{ 29{
30 struct device *dev = context;
29 struct spi_device *spi = to_spi_device(dev); 31 struct spi_device *spi = to_spi_device(dev);
30 struct spi_message m; 32 struct spi_message m;
31 struct spi_transfer t[2] = { { .tx_buf = reg, .len = reg_len, }, 33 struct spi_transfer t[2] = { { .tx_buf = reg, .len = reg_len, },
@@ -38,10 +40,11 @@ static int regmap_spi_gather_write(struct device *dev,
38 return spi_sync(spi, &m); 40 return spi_sync(spi, &m);
39} 41}
40 42
41static int regmap_spi_read(struct device *dev, 43static int regmap_spi_read(void *context,
42 const void *reg, size_t reg_size, 44 const void *reg, size_t reg_size,
43 void *val, size_t val_size) 45 void *val, size_t val_size)
44{ 46{
47 struct device *dev = context;
45 struct spi_device *spi = to_spi_device(dev); 48 struct spi_device *spi = to_spi_device(dev);
46 49
47 return spi_write_then_read(spi, reg, reg_size, val, val_size); 50 return spi_write_then_read(spi, reg, reg_size, val, val_size);
@@ -66,7 +69,7 @@ static struct regmap_bus regmap_spi = {
66struct regmap *regmap_init_spi(struct spi_device *spi, 69struct regmap *regmap_init_spi(struct spi_device *spi,
67 const struct regmap_config *config) 70 const struct regmap_config *config)
68{ 71{
69 return regmap_init(&spi->dev, &regmap_spi, config); 72 return regmap_init(&spi->dev, &regmap_spi, &spi->dev, config);
70} 73}
71EXPORT_SYMBOL_GPL(regmap_init_spi); 74EXPORT_SYMBOL_GPL(regmap_init_spi);
72 75
@@ -83,7 +86,7 @@ EXPORT_SYMBOL_GPL(regmap_init_spi);
83struct regmap *devm_regmap_init_spi(struct spi_device *spi, 86struct regmap *devm_regmap_init_spi(struct spi_device *spi,
84 const struct regmap_config *config) 87 const struct regmap_config *config)
85{ 88{
86 return devm_regmap_init(&spi->dev, &regmap_spi, config); 89 return devm_regmap_init(&spi->dev, &regmap_spi, &spi->dev, config);
87} 90}
88EXPORT_SYMBOL_GPL(devm_regmap_init_spi); 91EXPORT_SYMBOL_GPL(devm_regmap_init_spi);
89 92
diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 7a3f535e481c..de9f79650e8f 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -112,25 +112,36 @@ static void regmap_format_10_14_write(struct regmap *map,
112 out[0] = reg >> 2; 112 out[0] = reg >> 2;
113} 113}
114 114
115static void regmap_format_8(void *buf, unsigned int val) 115static void regmap_format_8(void *buf, unsigned int val, unsigned int shift)
116{ 116{
117 u8 *b = buf; 117 u8 *b = buf;
118 118
119 b[0] = val; 119 b[0] = val << shift;
120} 120}
121 121
122static void regmap_format_16(void *buf, unsigned int val) 122static void regmap_format_16(void *buf, unsigned int val, unsigned int shift)
123{ 123{
124 __be16 *b = buf; 124 __be16 *b = buf;
125 125
126 b[0] = cpu_to_be16(val); 126 b[0] = cpu_to_be16(val << shift);
127} 127}
128 128
129static void regmap_format_32(void *buf, unsigned int val) 129static void regmap_format_24(void *buf, unsigned int val, unsigned int shift)
130{
131 u8 *b = buf;
132
133 val <<= shift;
134
135 b[0] = val >> 16;
136 b[1] = val >> 8;
137 b[2] = val;
138}
139
140static void regmap_format_32(void *buf, unsigned int val, unsigned int shift)
130{ 141{
131 __be32 *b = buf; 142 __be32 *b = buf;
132 143
133 b[0] = cpu_to_be32(val); 144 b[0] = cpu_to_be32(val << shift);
134} 145}
135 146
136static unsigned int regmap_parse_8(void *buf) 147static unsigned int regmap_parse_8(void *buf)
@@ -149,6 +160,16 @@ static unsigned int regmap_parse_16(void *buf)
149 return b[0]; 160 return b[0];
150} 161}
151 162
163static unsigned int regmap_parse_24(void *buf)
164{
165 u8 *b = buf;
166 unsigned int ret = b[2];
167 ret |= ((unsigned int)b[1]) << 8;
168 ret |= ((unsigned int)b[0]) << 16;
169
170 return ret;
171}
172
152static unsigned int regmap_parse_32(void *buf) 173static unsigned int regmap_parse_32(void *buf)
153{ 174{
154 __be32 *b = buf; 175 __be32 *b = buf;
@@ -158,11 +179,32 @@ static unsigned int regmap_parse_32(void *buf)
158 return b[0]; 179 return b[0];
159} 180}
160 181
182static void regmap_lock_mutex(struct regmap *map)
183{
184 mutex_lock(&map->mutex);
185}
186
187static void regmap_unlock_mutex(struct regmap *map)
188{
189 mutex_unlock(&map->mutex);
190}
191
192static void regmap_lock_spinlock(struct regmap *map)
193{
194 spin_lock(&map->spinlock);
195}
196
197static void regmap_unlock_spinlock(struct regmap *map)
198{
199 spin_unlock(&map->spinlock);
200}
201
161/** 202/**
162 * regmap_init(): Initialise register map 203 * regmap_init(): Initialise register map
163 * 204 *
164 * @dev: Device that will be interacted with 205 * @dev: Device that will be interacted with
165 * @bus: Bus-specific callbacks to use with device 206 * @bus: Bus-specific callbacks to use with device
207 * @bus_context: Data passed to bus-specific callbacks
166 * @config: Configuration for register map 208 * @config: Configuration for register map
167 * 209 *
168 * The return value will be an ERR_PTR() on error or a valid pointer to 210 * The return value will be an ERR_PTR() on error or a valid pointer to
@@ -171,6 +213,7 @@ static unsigned int regmap_parse_32(void *buf)
171 */ 213 */
172struct regmap *regmap_init(struct device *dev, 214struct regmap *regmap_init(struct device *dev,
173 const struct regmap_bus *bus, 215 const struct regmap_bus *bus,
216 void *bus_context,
174 const struct regmap_config *config) 217 const struct regmap_config *config)
175{ 218{
176 struct regmap *map; 219 struct regmap *map;
@@ -185,14 +228,28 @@ struct regmap *regmap_init(struct device *dev,
185 goto err; 228 goto err;
186 } 229 }
187 230
188 mutex_init(&map->lock); 231 if (bus->fast_io) {
232 spin_lock_init(&map->spinlock);
233 map->lock = regmap_lock_spinlock;
234 map->unlock = regmap_unlock_spinlock;
235 } else {
236 mutex_init(&map->mutex);
237 map->lock = regmap_lock_mutex;
238 map->unlock = regmap_unlock_mutex;
239 }
189 map->format.buf_size = (config->reg_bits + config->val_bits) / 8; 240 map->format.buf_size = (config->reg_bits + config->val_bits) / 8;
190 map->format.reg_bytes = DIV_ROUND_UP(config->reg_bits, 8); 241 map->format.reg_bytes = DIV_ROUND_UP(config->reg_bits, 8);
191 map->format.pad_bytes = config->pad_bits / 8; 242 map->format.pad_bytes = config->pad_bits / 8;
192 map->format.val_bytes = DIV_ROUND_UP(config->val_bits, 8); 243 map->format.val_bytes = DIV_ROUND_UP(config->val_bits, 8);
193 map->format.buf_size += map->format.pad_bytes; 244 map->format.buf_size += map->format.pad_bytes;
245 map->reg_shift = config->pad_bits % 8;
246 if (config->reg_stride)
247 map->reg_stride = config->reg_stride;
248 else
249 map->reg_stride = 1;
194 map->dev = dev; 250 map->dev = dev;
195 map->bus = bus; 251 map->bus = bus;
252 map->bus_context = bus_context;
196 map->max_register = config->max_register; 253 map->max_register = config->max_register;
197 map->writeable_reg = config->writeable_reg; 254 map->writeable_reg = config->writeable_reg;
198 map->readable_reg = config->readable_reg; 255 map->readable_reg = config->readable_reg;
@@ -207,7 +264,7 @@ struct regmap *regmap_init(struct device *dev,
207 map->read_flag_mask = bus->read_flag_mask; 264 map->read_flag_mask = bus->read_flag_mask;
208 } 265 }
209 266
210 switch (config->reg_bits) { 267 switch (config->reg_bits + map->reg_shift) {
211 case 2: 268 case 2:
212 switch (config->val_bits) { 269 switch (config->val_bits) {
213 case 6: 270 case 6:
@@ -273,6 +330,10 @@ struct regmap *regmap_init(struct device *dev,
273 map->format.format_val = regmap_format_16; 330 map->format.format_val = regmap_format_16;
274 map->format.parse_val = regmap_parse_16; 331 map->format.parse_val = regmap_parse_16;
275 break; 332 break;
333 case 24:
334 map->format.format_val = regmap_format_24;
335 map->format.parse_val = regmap_parse_24;
336 break;
276 case 32: 337 case 32:
277 map->format.format_val = regmap_format_32; 338 map->format.format_val = regmap_format_32;
278 map->format.parse_val = regmap_parse_32; 339 map->format.parse_val = regmap_parse_32;
@@ -289,7 +350,7 @@ struct regmap *regmap_init(struct device *dev,
289 goto err_map; 350 goto err_map;
290 } 351 }
291 352
292 regmap_debugfs_init(map); 353 regmap_debugfs_init(map, config->name);
293 354
294 ret = regcache_init(map, config); 355 ret = regcache_init(map, config);
295 if (ret < 0) 356 if (ret < 0)
@@ -316,6 +377,7 @@ static void devm_regmap_release(struct device *dev, void *res)
316 * 377 *
317 * @dev: Device that will be interacted with 378 * @dev: Device that will be interacted with
318 * @bus: Bus-specific callbacks to use with device 379 * @bus: Bus-specific callbacks to use with device
380 * @bus_context: Data passed to bus-specific callbacks
319 * @config: Configuration for register map 381 * @config: Configuration for register map
320 * 382 *
321 * The return value will be an ERR_PTR() on error or a valid pointer 383 * The return value will be an ERR_PTR() on error or a valid pointer
@@ -325,6 +387,7 @@ static void devm_regmap_release(struct device *dev, void *res)
325 */ 387 */
326struct regmap *devm_regmap_init(struct device *dev, 388struct regmap *devm_regmap_init(struct device *dev,
327 const struct regmap_bus *bus, 389 const struct regmap_bus *bus,
390 void *bus_context,
328 const struct regmap_config *config) 391 const struct regmap_config *config)
329{ 392{
330 struct regmap **ptr, *regmap; 393 struct regmap **ptr, *regmap;
@@ -333,7 +396,7 @@ struct regmap *devm_regmap_init(struct device *dev,
333 if (!ptr) 396 if (!ptr)
334 return ERR_PTR(-ENOMEM); 397 return ERR_PTR(-ENOMEM);
335 398
336 regmap = regmap_init(dev, bus, config); 399 regmap = regmap_init(dev, bus, bus_context, config);
337 if (!IS_ERR(regmap)) { 400 if (!IS_ERR(regmap)) {
338 *ptr = regmap; 401 *ptr = regmap;
339 devres_add(dev, ptr); 402 devres_add(dev, ptr);
@@ -360,7 +423,7 @@ int regmap_reinit_cache(struct regmap *map, const struct regmap_config *config)
360{ 423{
361 int ret; 424 int ret;
362 425
363 mutex_lock(&map->lock); 426 map->lock(map);
364 427
365 regcache_exit(map); 428 regcache_exit(map);
366 regmap_debugfs_exit(map); 429 regmap_debugfs_exit(map);
@@ -372,14 +435,14 @@ int regmap_reinit_cache(struct regmap *map, const struct regmap_config *config)
372 map->precious_reg = config->precious_reg; 435 map->precious_reg = config->precious_reg;
373 map->cache_type = config->cache_type; 436 map->cache_type = config->cache_type;
374 437
375 regmap_debugfs_init(map); 438 regmap_debugfs_init(map, config->name);
376 439
377 map->cache_bypass = false; 440 map->cache_bypass = false;
378 map->cache_only = false; 441 map->cache_only = false;
379 442
380 ret = regcache_init(map, config); 443 ret = regcache_init(map, config);
381 444
382 mutex_unlock(&map->lock); 445 map->unlock(map);
383 446
384 return ret; 447 return ret;
385} 448}
@@ -391,6 +454,8 @@ void regmap_exit(struct regmap *map)
391{ 454{
392 regcache_exit(map); 455 regcache_exit(map);
393 regmap_debugfs_exit(map); 456 regmap_debugfs_exit(map);
457 if (map->bus->free_context)
458 map->bus->free_context(map->bus_context);
394 kfree(map->work_buf); 459 kfree(map->work_buf);
395 kfree(map); 460 kfree(map);
396} 461}
@@ -408,7 +473,8 @@ static int _regmap_raw_write(struct regmap *map, unsigned int reg,
408 /* Check for unwritable registers before we start */ 473 /* Check for unwritable registers before we start */
409 if (map->writeable_reg) 474 if (map->writeable_reg)
410 for (i = 0; i < val_len / map->format.val_bytes; i++) 475 for (i = 0; i < val_len / map->format.val_bytes; i++)
411 if (!map->writeable_reg(map->dev, reg + i)) 476 if (!map->writeable_reg(map->dev,
477 reg + (i * map->reg_stride)))
412 return -EINVAL; 478 return -EINVAL;
413 479
414 if (!map->cache_bypass && map->format.parse_val) { 480 if (!map->cache_bypass && map->format.parse_val) {
@@ -417,7 +483,8 @@ static int _regmap_raw_write(struct regmap *map, unsigned int reg,
417 for (i = 0; i < val_len / val_bytes; i++) { 483 for (i = 0; i < val_len / val_bytes; i++) {
418 memcpy(map->work_buf, val + (i * val_bytes), val_bytes); 484 memcpy(map->work_buf, val + (i * val_bytes), val_bytes);
419 ival = map->format.parse_val(map->work_buf); 485 ival = map->format.parse_val(map->work_buf);
420 ret = regcache_write(map, reg + i, ival); 486 ret = regcache_write(map, reg + (i * map->reg_stride),
487 ival);
421 if (ret) { 488 if (ret) {
422 dev_err(map->dev, 489 dev_err(map->dev,
423 "Error in caching of register: %u ret: %d\n", 490 "Error in caching of register: %u ret: %d\n",
@@ -431,7 +498,7 @@ static int _regmap_raw_write(struct regmap *map, unsigned int reg,
431 } 498 }
432 } 499 }
433 500
434 map->format.format_reg(map->work_buf, reg); 501 map->format.format_reg(map->work_buf, reg, map->reg_shift);
435 502
436 u8[0] |= map->write_flag_mask; 503 u8[0] |= map->write_flag_mask;
437 504
@@ -444,12 +511,12 @@ static int _regmap_raw_write(struct regmap *map, unsigned int reg,
444 */ 511 */
445 if (val == (map->work_buf + map->format.pad_bytes + 512 if (val == (map->work_buf + map->format.pad_bytes +
446 map->format.reg_bytes)) 513 map->format.reg_bytes))
447 ret = map->bus->write(map->dev, map->work_buf, 514 ret = map->bus->write(map->bus_context, map->work_buf,
448 map->format.reg_bytes + 515 map->format.reg_bytes +
449 map->format.pad_bytes + 516 map->format.pad_bytes +
450 val_len); 517 val_len);
451 else if (map->bus->gather_write) 518 else if (map->bus->gather_write)
452 ret = map->bus->gather_write(map->dev, map->work_buf, 519 ret = map->bus->gather_write(map->bus_context, map->work_buf,
453 map->format.reg_bytes + 520 map->format.reg_bytes +
454 map->format.pad_bytes, 521 map->format.pad_bytes,
455 val, val_len); 522 val, val_len);
@@ -464,7 +531,7 @@ static int _regmap_raw_write(struct regmap *map, unsigned int reg,
464 memcpy(buf, map->work_buf, map->format.reg_bytes); 531 memcpy(buf, map->work_buf, map->format.reg_bytes);
465 memcpy(buf + map->format.reg_bytes + map->format.pad_bytes, 532 memcpy(buf + map->format.reg_bytes + map->format.pad_bytes,
466 val, val_len); 533 val, val_len);
467 ret = map->bus->write(map->dev, buf, len); 534 ret = map->bus->write(map->bus_context, buf, len);
468 535
469 kfree(buf); 536 kfree(buf);
470 } 537 }
@@ -498,7 +565,7 @@ int _regmap_write(struct regmap *map, unsigned int reg,
498 565
499 trace_regmap_hw_write_start(map->dev, reg, 1); 566 trace_regmap_hw_write_start(map->dev, reg, 1);
500 567
501 ret = map->bus->write(map->dev, map->work_buf, 568 ret = map->bus->write(map->bus_context, map->work_buf,
502 map->format.buf_size); 569 map->format.buf_size);
503 570
504 trace_regmap_hw_write_done(map->dev, reg, 1); 571 trace_regmap_hw_write_done(map->dev, reg, 1);
@@ -506,7 +573,7 @@ int _regmap_write(struct regmap *map, unsigned int reg,
506 return ret; 573 return ret;
507 } else { 574 } else {
508 map->format.format_val(map->work_buf + map->format.reg_bytes 575 map->format.format_val(map->work_buf + map->format.reg_bytes
509 + map->format.pad_bytes, val); 576 + map->format.pad_bytes, val, 0);
510 return _regmap_raw_write(map, reg, 577 return _regmap_raw_write(map, reg,
511 map->work_buf + 578 map->work_buf +
512 map->format.reg_bytes + 579 map->format.reg_bytes +
@@ -529,11 +596,14 @@ int regmap_write(struct regmap *map, unsigned int reg, unsigned int val)
529{ 596{
530 int ret; 597 int ret;
531 598
532 mutex_lock(&map->lock); 599 if (reg % map->reg_stride)
600 return -EINVAL;
601
602 map->lock(map);
533 603
534 ret = _regmap_write(map, reg, val); 604 ret = _regmap_write(map, reg, val);
535 605
536 mutex_unlock(&map->lock); 606 map->unlock(map);
537 607
538 return ret; 608 return ret;
539} 609}
@@ -560,11 +630,16 @@ int regmap_raw_write(struct regmap *map, unsigned int reg,
560{ 630{
561 int ret; 631 int ret;
562 632
563 mutex_lock(&map->lock); 633 if (val_len % map->format.val_bytes)
634 return -EINVAL;
635 if (reg % map->reg_stride)
636 return -EINVAL;
637
638 map->lock(map);
564 639
565 ret = _regmap_raw_write(map, reg, val, val_len); 640 ret = _regmap_raw_write(map, reg, val, val_len);
566 641
567 mutex_unlock(&map->lock); 642 map->unlock(map);
568 643
569 return ret; 644 return ret;
570} 645}
@@ -593,8 +668,10 @@ int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
593 668
594 if (!map->format.parse_val) 669 if (!map->format.parse_val)
595 return -EINVAL; 670 return -EINVAL;
671 if (reg % map->reg_stride)
672 return -EINVAL;
596 673
597 mutex_lock(&map->lock); 674 map->lock(map);
598 675
599 /* No formatting is require if val_byte is 1 */ 676 /* No formatting is require if val_byte is 1 */
600 if (val_bytes == 1) { 677 if (val_bytes == 1) {
@@ -615,7 +692,7 @@ int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
615 kfree(wval); 692 kfree(wval);
616 693
617out: 694out:
618 mutex_unlock(&map->lock); 695 map->unlock(map);
619 return ret; 696 return ret;
620} 697}
621EXPORT_SYMBOL_GPL(regmap_bulk_write); 698EXPORT_SYMBOL_GPL(regmap_bulk_write);
@@ -626,7 +703,7 @@ static int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val,
626 u8 *u8 = map->work_buf; 703 u8 *u8 = map->work_buf;
627 int ret; 704 int ret;
628 705
629 map->format.format_reg(map->work_buf, reg); 706 map->format.format_reg(map->work_buf, reg, map->reg_shift);
630 707
631 /* 708 /*
632 * Some buses or devices flag reads by setting the high bits in the 709 * Some buses or devices flag reads by setting the high bits in the
@@ -639,7 +716,7 @@ static int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val,
639 trace_regmap_hw_read_start(map->dev, reg, 716 trace_regmap_hw_read_start(map->dev, reg,
640 val_len / map->format.val_bytes); 717 val_len / map->format.val_bytes);
641 718
642 ret = map->bus->read(map->dev, map->work_buf, 719 ret = map->bus->read(map->bus_context, map->work_buf,
643 map->format.reg_bytes + map->format.pad_bytes, 720 map->format.reg_bytes + map->format.pad_bytes,
644 val, val_len); 721 val, val_len);
645 722
@@ -689,11 +766,14 @@ int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val)
689{ 766{
690 int ret; 767 int ret;
691 768
692 mutex_lock(&map->lock); 769 if (reg % map->reg_stride)
770 return -EINVAL;
771
772 map->lock(map);
693 773
694 ret = _regmap_read(map, reg, val); 774 ret = _regmap_read(map, reg, val);
695 775
696 mutex_unlock(&map->lock); 776 map->unlock(map);
697 777
698 return ret; 778 return ret;
699} 779}
@@ -718,7 +798,12 @@ int regmap_raw_read(struct regmap *map, unsigned int reg, void *val,
718 unsigned int v; 798 unsigned int v;
719 int ret, i; 799 int ret, i;
720 800
721 mutex_lock(&map->lock); 801 if (val_len % map->format.val_bytes)
802 return -EINVAL;
803 if (reg % map->reg_stride)
804 return -EINVAL;
805
806 map->lock(map);
722 807
723 if (regmap_volatile_range(map, reg, val_count) || map->cache_bypass || 808 if (regmap_volatile_range(map, reg, val_count) || map->cache_bypass ||
724 map->cache_type == REGCACHE_NONE) { 809 map->cache_type == REGCACHE_NONE) {
@@ -730,16 +815,17 @@ int regmap_raw_read(struct regmap *map, unsigned int reg, void *val,
730 * cost as we expect to hit the cache. 815 * cost as we expect to hit the cache.
731 */ 816 */
732 for (i = 0; i < val_count; i++) { 817 for (i = 0; i < val_count; i++) {
733 ret = _regmap_read(map, reg + i, &v); 818 ret = _regmap_read(map, reg + (i * map->reg_stride),
819 &v);
734 if (ret != 0) 820 if (ret != 0)
735 goto out; 821 goto out;
736 822
737 map->format.format_val(val + (i * val_bytes), v); 823 map->format.format_val(val + (i * val_bytes), v, 0);
738 } 824 }
739 } 825 }
740 826
741 out: 827 out:
742 mutex_unlock(&map->lock); 828 map->unlock(map);
743 829
744 return ret; 830 return ret;
745} 831}
@@ -765,6 +851,8 @@ int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
765 851
766 if (!map->format.parse_val) 852 if (!map->format.parse_val)
767 return -EINVAL; 853 return -EINVAL;
854 if (reg % map->reg_stride)
855 return -EINVAL;
768 856
769 if (vol || map->cache_type == REGCACHE_NONE) { 857 if (vol || map->cache_type == REGCACHE_NONE) {
770 ret = regmap_raw_read(map, reg, val, val_bytes * val_count); 858 ret = regmap_raw_read(map, reg, val, val_bytes * val_count);
@@ -775,9 +863,12 @@ int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
775 map->format.parse_val(val + i); 863 map->format.parse_val(val + i);
776 } else { 864 } else {
777 for (i = 0; i < val_count; i++) { 865 for (i = 0; i < val_count; i++) {
778 ret = regmap_read(map, reg + i, val + (i * val_bytes)); 866 unsigned int ival;
867 ret = regmap_read(map, reg + (i * map->reg_stride),
868 &ival);
779 if (ret != 0) 869 if (ret != 0)
780 return ret; 870 return ret;
871 memcpy(val + (i * val_bytes), &ival, val_bytes);
781 } 872 }
782 } 873 }
783 874
@@ -792,7 +883,7 @@ static int _regmap_update_bits(struct regmap *map, unsigned int reg,
792 int ret; 883 int ret;
793 unsigned int tmp, orig; 884 unsigned int tmp, orig;
794 885
795 mutex_lock(&map->lock); 886 map->lock(map);
796 887
797 ret = _regmap_read(map, reg, &orig); 888 ret = _regmap_read(map, reg, &orig);
798 if (ret != 0) 889 if (ret != 0)
@@ -809,7 +900,7 @@ static int _regmap_update_bits(struct regmap *map, unsigned int reg,
809 } 900 }
810 901
811out: 902out:
812 mutex_unlock(&map->lock); 903 map->unlock(map);
813 904
814 return ret; 905 return ret;
815} 906}
@@ -876,7 +967,7 @@ int regmap_register_patch(struct regmap *map, const struct reg_default *regs,
876 if (map->patch) 967 if (map->patch)
877 return -EBUSY; 968 return -EBUSY;
878 969
879 mutex_lock(&map->lock); 970 map->lock(map);
880 971
881 bypass = map->cache_bypass; 972 bypass = map->cache_bypass;
882 973
@@ -904,7 +995,7 @@ int regmap_register_patch(struct regmap *map, const struct reg_default *regs,
904out: 995out:
905 map->cache_bypass = bypass; 996 map->cache_bypass = bypass;
906 997
907 mutex_unlock(&map->lock); 998 map->unlock(map);
908 999
909 return ret; 1000 return ret;
910} 1001}
diff --git a/drivers/base/soc.c b/drivers/base/soc.c
index 05f150382da8..ba29b2e73d48 100644
--- a/drivers/base/soc.c
+++ b/drivers/base/soc.c
@@ -15,7 +15,7 @@
15#include <linux/sys_soc.h> 15#include <linux/sys_soc.h>
16#include <linux/err.h> 16#include <linux/err.h>
17 17
18static DEFINE_IDR(soc_ida); 18static DEFINE_IDA(soc_ida);
19static DEFINE_SPINLOCK(soc_lock); 19static DEFINE_SPINLOCK(soc_lock);
20 20
21static ssize_t soc_info_get(struct device *dev, 21static ssize_t soc_info_get(struct device *dev,
@@ -168,8 +168,6 @@ void soc_device_unregister(struct soc_device *soc_dev)
168 168
169static int __init soc_bus_register(void) 169static int __init soc_bus_register(void)
170{ 170{
171 spin_lock_init(&soc_lock);
172
173 return bus_register(&soc_bus_type); 171 return bus_register(&soc_bus_type);
174} 172}
175core_initcall(soc_bus_register); 173core_initcall(soc_bus_register);
diff --git a/drivers/bcma/Kconfig b/drivers/bcma/Kconfig
index c1172dafdffa..fb7c80fb721e 100644
--- a/drivers/bcma/Kconfig
+++ b/drivers/bcma/Kconfig
@@ -29,7 +29,7 @@ config BCMA_HOST_PCI
29 29
30config BCMA_DRIVER_PCI_HOSTMODE 30config BCMA_DRIVER_PCI_HOSTMODE
31 bool "Driver for PCI core working in hostmode" 31 bool "Driver for PCI core working in hostmode"
32 depends on BCMA && MIPS 32 depends on BCMA && MIPS && BCMA_HOST_PCI
33 help 33 help
34 PCI core hostmode operation (external PCI bus). 34 PCI core hostmode operation (external PCI bus).
35 35
diff --git a/drivers/bcma/driver_pci_host.c b/drivers/bcma/driver_pci_host.c
index 4e20bcfa7ec5..d2097a11c3c7 100644
--- a/drivers/bcma/driver_pci_host.c
+++ b/drivers/bcma/driver_pci_host.c
@@ -10,6 +10,7 @@
10 */ 10 */
11 11
12#include "bcma_private.h" 12#include "bcma_private.h"
13#include <linux/pci.h>
13#include <linux/export.h> 14#include <linux/export.h>
14#include <linux/bcma/bcma.h> 15#include <linux/bcma/bcma.h>
15#include <asm/paccess.h> 16#include <asm/paccess.h>
diff --git a/drivers/bcma/sprom.c b/drivers/bcma/sprom.c
index cdcf75c0954f..3e2a6002aae6 100644
--- a/drivers/bcma/sprom.c
+++ b/drivers/bcma/sprom.c
@@ -404,16 +404,19 @@ int bcma_sprom_get(struct bcma_bus *bus)
404 return -EOPNOTSUPP; 404 return -EOPNOTSUPP;
405 405
406 if (!bcma_sprom_ext_available(bus)) { 406 if (!bcma_sprom_ext_available(bus)) {
407 bool sprom_onchip;
408
407 /* 409 /*
408 * External SPROM takes precedence so check 410 * External SPROM takes precedence so check
409 * on-chip OTP only when no external SPROM 411 * on-chip OTP only when no external SPROM
410 * is present. 412 * is present.
411 */ 413 */
412 if (bcma_sprom_onchip_available(bus)) { 414 sprom_onchip = bcma_sprom_onchip_available(bus);
415 if (sprom_onchip) {
413 /* determine offset */ 416 /* determine offset */
414 offset = bcma_sprom_onchip_offset(bus); 417 offset = bcma_sprom_onchip_offset(bus);
415 } 418 }
416 if (!offset) { 419 if (!offset || !sprom_onchip) {
417 /* 420 /*
418 * Maybe there is no SPROM on the device? 421 * Maybe there is no SPROM on the device?
419 * Now we ask the arch code if there is some sprom 422 * Now we ask the arch code if there is some sprom
diff --git a/drivers/block/cciss_scsi.c b/drivers/block/cciss_scsi.c
index e820b68d2f6c..acda773b3720 100644
--- a/drivers/block/cciss_scsi.c
+++ b/drivers/block/cciss_scsi.c
@@ -866,6 +866,7 @@ cciss_scsi_detect(ctlr_info_t *h)
866 sh->can_queue = cciss_tape_cmds; 866 sh->can_queue = cciss_tape_cmds;
867 sh->sg_tablesize = h->maxsgentries; 867 sh->sg_tablesize = h->maxsgentries;
868 sh->max_cmd_len = MAX_COMMAND_SIZE; 868 sh->max_cmd_len = MAX_COMMAND_SIZE;
869 sh->max_sectors = h->cciss_max_sectors;
869 870
870 ((struct cciss_scsi_adapter_data_t *) 871 ((struct cciss_scsi_adapter_data_t *)
871 h->scsi_ctlr)->scsi_host = sh; 872 h->scsi_ctlr)->scsi_host = sh;
@@ -1410,7 +1411,7 @@ static void cciss_scatter_gather(ctlr_info_t *h, CommandList_struct *c,
1410 /* track how many SG entries we are using */ 1411 /* track how many SG entries we are using */
1411 if (request_nsgs > h->maxSG) 1412 if (request_nsgs > h->maxSG)
1412 h->maxSG = request_nsgs; 1413 h->maxSG = request_nsgs;
1413 c->Header.SGTotal = (__u8) request_nsgs + chained; 1414 c->Header.SGTotal = (u16) request_nsgs + chained;
1414 if (request_nsgs > h->max_cmd_sgentries) 1415 if (request_nsgs > h->max_cmd_sgentries)
1415 c->Header.SGList = h->max_cmd_sgentries; 1416 c->Header.SGList = h->max_cmd_sgentries;
1416 else 1417 else
diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
index abfaacaaf346..946166e13953 100644
--- a/drivers/block/drbd/drbd_nl.c
+++ b/drivers/block/drbd/drbd_nl.c
@@ -2297,7 +2297,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
2297 return; 2297 return;
2298 } 2298 }
2299 2299
2300 if (!cap_raised(current_cap(), CAP_SYS_ADMIN)) { 2300 if (!capable(CAP_SYS_ADMIN)) {
2301 retcode = ERR_PERM; 2301 retcode = ERR_PERM;
2302 goto fail; 2302 goto fail;
2303 } 2303 }
diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index 76a08236430a..b0b00d70c166 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -1030,37 +1030,6 @@ static int fd_wait_for_completion(unsigned long delay, timeout_fn function)
1030 return 0; 1030 return 0;
1031} 1031}
1032 1032
1033static DEFINE_SPINLOCK(floppy_hlt_lock);
1034static int hlt_disabled;
1035static void floppy_disable_hlt(void)
1036{
1037 unsigned long flags;
1038
1039 WARN_ONCE(1, "floppy_disable_hlt() scheduled for removal in 2012");
1040 spin_lock_irqsave(&floppy_hlt_lock, flags);
1041 if (!hlt_disabled) {
1042 hlt_disabled = 1;
1043#ifdef HAVE_DISABLE_HLT
1044 disable_hlt();
1045#endif
1046 }
1047 spin_unlock_irqrestore(&floppy_hlt_lock, flags);
1048}
1049
1050static void floppy_enable_hlt(void)
1051{
1052 unsigned long flags;
1053
1054 spin_lock_irqsave(&floppy_hlt_lock, flags);
1055 if (hlt_disabled) {
1056 hlt_disabled = 0;
1057#ifdef HAVE_DISABLE_HLT
1058 enable_hlt();
1059#endif
1060 }
1061 spin_unlock_irqrestore(&floppy_hlt_lock, flags);
1062}
1063
1064static void setup_DMA(void) 1033static void setup_DMA(void)
1065{ 1034{
1066 unsigned long f; 1035 unsigned long f;
@@ -1105,7 +1074,6 @@ static void setup_DMA(void)
1105 fd_enable_dma(); 1074 fd_enable_dma();
1106 release_dma_lock(f); 1075 release_dma_lock(f);
1107#endif 1076#endif
1108 floppy_disable_hlt();
1109} 1077}
1110 1078
1111static void show_floppy(void); 1079static void show_floppy(void);
@@ -1707,7 +1675,6 @@ irqreturn_t floppy_interrupt(int irq, void *dev_id)
1707 fd_disable_dma(); 1675 fd_disable_dma();
1708 release_dma_lock(f); 1676 release_dma_lock(f);
1709 1677
1710 floppy_enable_hlt();
1711 do_floppy = NULL; 1678 do_floppy = NULL;
1712 if (fdc >= N_FDC || FDCS->address == -1) { 1679 if (fdc >= N_FDC || FDCS->address == -1) {
1713 /* we don't even know which FDC is the culprit */ 1680 /* we don't even know which FDC is the culprit */
@@ -1856,8 +1823,6 @@ static void floppy_shutdown(unsigned long data)
1856 show_floppy(); 1823 show_floppy();
1857 cancel_activity(); 1824 cancel_activity();
1858 1825
1859 floppy_enable_hlt();
1860
1861 flags = claim_dma_lock(); 1826 flags = claim_dma_lock();
1862 fd_disable_dma(); 1827 fd_disable_dma();
1863 release_dma_lock(flags); 1828 release_dma_lock(flags);
@@ -4508,7 +4473,6 @@ static void floppy_release_irq_and_dma(void)
4508#if N_FDC > 1 4473#if N_FDC > 1
4509 set_dor(1, ~8, 0); 4474 set_dor(1, ~8, 0);
4510#endif 4475#endif
4511 floppy_enable_hlt();
4512 4476
4513 if (floppy_track_buffer && max_buffer_sectors) { 4477 if (floppy_track_buffer && max_buffer_sectors) {
4514 tmpsize = max_buffer_sectors * 1024; 4478 tmpsize = max_buffer_sectors * 1024;
diff --git a/drivers/block/mtip32xx/Kconfig b/drivers/block/mtip32xx/Kconfig
index b5dd14e072f2..0ba837fc62a8 100644
--- a/drivers/block/mtip32xx/Kconfig
+++ b/drivers/block/mtip32xx/Kconfig
@@ -4,6 +4,6 @@
4 4
5config BLK_DEV_PCIESSD_MTIP32XX 5config BLK_DEV_PCIESSD_MTIP32XX
6 tristate "Block Device Driver for Micron PCIe SSDs" 6 tristate "Block Device Driver for Micron PCIe SSDs"
7 depends on HOTPLUG_PCI_PCIE 7 depends on PCI
8 help 8 help
9 This enables the block driver for Micron PCIe SSDs. 9 This enables the block driver for Micron PCIe SSDs.
diff --git a/drivers/block/mtip32xx/mtip32xx.c b/drivers/block/mtip32xx/mtip32xx.c
index 8eb81c96608f..00f9fc992090 100644
--- a/drivers/block/mtip32xx/mtip32xx.c
+++ b/drivers/block/mtip32xx/mtip32xx.c
@@ -36,6 +36,7 @@
36#include <linux/idr.h> 36#include <linux/idr.h>
37#include <linux/kthread.h> 37#include <linux/kthread.h>
38#include <../drivers/ata/ahci.h> 38#include <../drivers/ata/ahci.h>
39#include <linux/export.h>
39#include "mtip32xx.h" 40#include "mtip32xx.h"
40 41
41#define HW_CMD_SLOT_SZ (MTIP_MAX_COMMAND_SLOTS * 32) 42#define HW_CMD_SLOT_SZ (MTIP_MAX_COMMAND_SLOTS * 32)
@@ -44,6 +45,7 @@
44#define HW_PORT_PRIV_DMA_SZ \ 45#define HW_PORT_PRIV_DMA_SZ \
45 (HW_CMD_SLOT_SZ + HW_CMD_TBL_AR_SZ + AHCI_RX_FIS_SZ) 46 (HW_CMD_SLOT_SZ + HW_CMD_TBL_AR_SZ + AHCI_RX_FIS_SZ)
46 47
48#define HOST_CAP_NZDMA (1 << 19)
47#define HOST_HSORG 0xFC 49#define HOST_HSORG 0xFC
48#define HSORG_DISABLE_SLOTGRP_INTR (1<<24) 50#define HSORG_DISABLE_SLOTGRP_INTR (1<<24)
49#define HSORG_DISABLE_SLOTGRP_PXIS (1<<16) 51#define HSORG_DISABLE_SLOTGRP_PXIS (1<<16)
@@ -139,6 +141,12 @@ static void mtip_command_cleanup(struct driver_data *dd)
139 int group = 0, commandslot = 0, commandindex = 0; 141 int group = 0, commandslot = 0, commandindex = 0;
140 struct mtip_cmd *command; 142 struct mtip_cmd *command;
141 struct mtip_port *port = dd->port; 143 struct mtip_port *port = dd->port;
144 static int in_progress;
145
146 if (in_progress)
147 return;
148
149 in_progress = 1;
142 150
143 for (group = 0; group < 4; group++) { 151 for (group = 0; group < 4; group++) {
144 for (commandslot = 0; commandslot < 32; commandslot++) { 152 for (commandslot = 0; commandslot < 32; commandslot++) {
@@ -165,7 +173,8 @@ static void mtip_command_cleanup(struct driver_data *dd)
165 173
166 up(&port->cmd_slot); 174 up(&port->cmd_slot);
167 175
168 atomic_set(&dd->drv_cleanup_done, true); 176 set_bit(MTIP_DDF_CLEANUP_BIT, &dd->dd_flag);
177 in_progress = 0;
169} 178}
170 179
171/* 180/*
@@ -262,6 +271,9 @@ static int hba_reset_nosleep(struct driver_data *dd)
262 && time_before(jiffies, timeout)) 271 && time_before(jiffies, timeout))
263 mdelay(1); 272 mdelay(1);
264 273
274 if (test_bit(MTIP_DDF_REMOVE_PENDING_BIT, &dd->dd_flag))
275 return -1;
276
265 if (readl(dd->mmio + HOST_CTL) & HOST_RESET) 277 if (readl(dd->mmio + HOST_CTL) & HOST_RESET)
266 return -1; 278 return -1;
267 279
@@ -294,6 +306,10 @@ static inline void mtip_issue_ncq_command(struct mtip_port *port, int tag)
294 port->cmd_issue[MTIP_TAG_INDEX(tag)]); 306 port->cmd_issue[MTIP_TAG_INDEX(tag)]);
295 307
296 spin_unlock_irqrestore(&port->cmd_issue_lock, flags); 308 spin_unlock_irqrestore(&port->cmd_issue_lock, flags);
309
310 /* Set the command's timeout value.*/
311 port->commands[tag].comp_time = jiffies + msecs_to_jiffies(
312 MTIP_NCQ_COMMAND_TIMEOUT_MS);
297} 313}
298 314
299/* 315/*
@@ -420,7 +436,12 @@ static void mtip_init_port(struct mtip_port *port)
420 writel(0xFFFFFFFF, port->completed[i]); 436 writel(0xFFFFFFFF, port->completed[i]);
421 437
422 /* Clear any pending interrupts for this port */ 438 /* Clear any pending interrupts for this port */
423 writel(readl(port->mmio + PORT_IRQ_STAT), port->mmio + PORT_IRQ_STAT); 439 writel(readl(port->dd->mmio + PORT_IRQ_STAT),
440 port->dd->mmio + PORT_IRQ_STAT);
441
442 /* Clear any pending interrupts on the HBA. */
443 writel(readl(port->dd->mmio + HOST_IRQ_STAT),
444 port->dd->mmio + HOST_IRQ_STAT);
424 445
425 /* Enable port interrupts */ 446 /* Enable port interrupts */
426 writel(DEF_PORT_IRQ, port->mmio + PORT_IRQ_MASK); 447 writel(DEF_PORT_IRQ, port->mmio + PORT_IRQ_MASK);
@@ -447,6 +468,9 @@ static void mtip_restart_port(struct mtip_port *port)
447 && time_before(jiffies, timeout)) 468 && time_before(jiffies, timeout))
448 ; 469 ;
449 470
471 if (test_bit(MTIP_DDF_REMOVE_PENDING_BIT, &port->dd->dd_flag))
472 return;
473
450 /* 474 /*
451 * Chip quirk: escalate to hba reset if 475 * Chip quirk: escalate to hba reset if
452 * PxCMD.CR not clear after 500 ms 476 * PxCMD.CR not clear after 500 ms
@@ -475,6 +499,9 @@ static void mtip_restart_port(struct mtip_port *port)
475 while (time_before(jiffies, timeout)) 499 while (time_before(jiffies, timeout))
476 ; 500 ;
477 501
502 if (test_bit(MTIP_DDF_REMOVE_PENDING_BIT, &port->dd->dd_flag))
503 return;
504
478 /* Clear PxSCTL.DET */ 505 /* Clear PxSCTL.DET */
479 writel(readl(port->mmio + PORT_SCR_CTL) & ~1, 506 writel(readl(port->mmio + PORT_SCR_CTL) & ~1,
480 port->mmio + PORT_SCR_CTL); 507 port->mmio + PORT_SCR_CTL);
@@ -486,15 +513,35 @@ static void mtip_restart_port(struct mtip_port *port)
486 && time_before(jiffies, timeout)) 513 && time_before(jiffies, timeout))
487 ; 514 ;
488 515
516 if (test_bit(MTIP_DDF_REMOVE_PENDING_BIT, &port->dd->dd_flag))
517 return;
518
489 if ((readl(port->mmio + PORT_SCR_STAT) & 0x01) == 0) 519 if ((readl(port->mmio + PORT_SCR_STAT) & 0x01) == 0)
490 dev_warn(&port->dd->pdev->dev, 520 dev_warn(&port->dd->pdev->dev,
491 "COM reset failed\n"); 521 "COM reset failed\n");
492 522
493 /* Clear SError, the PxSERR.DIAG.x should be set so clear it */ 523 mtip_init_port(port);
494 writel(readl(port->mmio + PORT_SCR_ERR), port->mmio + PORT_SCR_ERR); 524 mtip_start_port(port);
495 525
496 /* Enable the DMA engine */ 526}
497 mtip_enable_engine(port, 1); 527
528/*
529 * Helper function for tag logging
530 */
531static void print_tags(struct driver_data *dd,
532 char *msg,
533 unsigned long *tagbits,
534 int cnt)
535{
536 unsigned char tagmap[128];
537 int group, tagmap_len = 0;
538
539 memset(tagmap, 0, sizeof(tagmap));
540 for (group = SLOTBITS_IN_LONGS; group > 0; group--)
541 tagmap_len = sprintf(tagmap + tagmap_len, "%016lX ",
542 tagbits[group-1]);
543 dev_warn(&dd->pdev->dev,
544 "%d command(s) %s: tagmap [%s]", cnt, msg, tagmap);
498} 545}
499 546
500/* 547/*
@@ -514,15 +561,18 @@ static void mtip_timeout_function(unsigned long int data)
514 int tag, cmdto_cnt = 0; 561 int tag, cmdto_cnt = 0;
515 unsigned int bit, group; 562 unsigned int bit, group;
516 unsigned int num_command_slots = port->dd->slot_groups * 32; 563 unsigned int num_command_slots = port->dd->slot_groups * 32;
564 unsigned long to, tagaccum[SLOTBITS_IN_LONGS];
517 565
518 if (unlikely(!port)) 566 if (unlikely(!port))
519 return; 567 return;
520 568
521 if (atomic_read(&port->dd->resumeflag) == true) { 569 if (test_bit(MTIP_DDF_RESUME_BIT, &port->dd->dd_flag)) {
522 mod_timer(&port->cmd_timer, 570 mod_timer(&port->cmd_timer,
523 jiffies + msecs_to_jiffies(30000)); 571 jiffies + msecs_to_jiffies(30000));
524 return; 572 return;
525 } 573 }
574 /* clear the tag accumulator */
575 memset(tagaccum, 0, SLOTBITS_IN_LONGS * sizeof(long));
526 576
527 for (tag = 0; tag < num_command_slots; tag++) { 577 for (tag = 0; tag < num_command_slots; tag++) {
528 /* 578 /*
@@ -540,12 +590,10 @@ static void mtip_timeout_function(unsigned long int data)
540 command = &port->commands[tag]; 590 command = &port->commands[tag];
541 fis = (struct host_to_dev_fis *) command->command; 591 fis = (struct host_to_dev_fis *) command->command;
542 592
543 dev_warn(&port->dd->pdev->dev, 593 set_bit(tag, tagaccum);
544 "Timeout for command tag %d\n", tag);
545
546 cmdto_cnt++; 594 cmdto_cnt++;
547 if (cmdto_cnt == 1) 595 if (cmdto_cnt == 1)
548 set_bit(MTIP_FLAG_EH_ACTIVE_BIT, &port->flags); 596 set_bit(MTIP_PF_EH_ACTIVE_BIT, &port->flags);
549 597
550 /* 598 /*
551 * Clear the completed bit. This should prevent 599 * Clear the completed bit. This should prevent
@@ -578,15 +626,29 @@ static void mtip_timeout_function(unsigned long int data)
578 } 626 }
579 } 627 }
580 628
581 if (cmdto_cnt) { 629 if (cmdto_cnt && !test_bit(MTIP_PF_IC_ACTIVE_BIT, &port->flags)) {
582 dev_warn(&port->dd->pdev->dev, 630 print_tags(port->dd, "timed out", tagaccum, cmdto_cnt);
583 "%d commands timed out: restarting port", 631
584 cmdto_cnt);
585 mtip_restart_port(port); 632 mtip_restart_port(port);
586 clear_bit(MTIP_FLAG_EH_ACTIVE_BIT, &port->flags); 633 clear_bit(MTIP_PF_EH_ACTIVE_BIT, &port->flags);
587 wake_up_interruptible(&port->svc_wait); 634 wake_up_interruptible(&port->svc_wait);
588 } 635 }
589 636
637 if (port->ic_pause_timer) {
638 to = port->ic_pause_timer + msecs_to_jiffies(1000);
639 if (time_after(jiffies, to)) {
640 if (!test_bit(MTIP_PF_IC_ACTIVE_BIT, &port->flags)) {
641 port->ic_pause_timer = 0;
642 clear_bit(MTIP_PF_SE_ACTIVE_BIT, &port->flags);
643 clear_bit(MTIP_PF_DM_ACTIVE_BIT, &port->flags);
644 clear_bit(MTIP_PF_IC_ACTIVE_BIT, &port->flags);
645 wake_up_interruptible(&port->svc_wait);
646 }
647
648
649 }
650 }
651
590 /* Restart the timer */ 652 /* Restart the timer */
591 mod_timer(&port->cmd_timer, 653 mod_timer(&port->cmd_timer,
592 jiffies + msecs_to_jiffies(MTIP_TIMEOUT_CHECK_PERIOD)); 654 jiffies + msecs_to_jiffies(MTIP_TIMEOUT_CHECK_PERIOD));
@@ -681,23 +743,18 @@ static void mtip_completion(struct mtip_port *port,
681 complete(waiting); 743 complete(waiting);
682} 744}
683 745
684/* 746static void mtip_null_completion(struct mtip_port *port,
685 * Helper function for tag logging 747 int tag,
686 */ 748 void *data,
687static void print_tags(struct driver_data *dd, 749 int status)
688 char *msg,
689 unsigned long *tagbits)
690{ 750{
691 unsigned int tag, count = 0; 751 return;
692
693 for (tag = 0; tag < (dd->slot_groups) * 32; tag++) {
694 if (test_bit(tag, tagbits))
695 count++;
696 }
697 if (count)
698 dev_info(&dd->pdev->dev, "%s [%i tags]\n", msg, count);
699} 752}
700 753
754static int mtip_read_log_page(struct mtip_port *port, u8 page, u16 *buffer,
755 dma_addr_t buffer_dma, unsigned int sectors);
756static int mtip_get_smart_attr(struct mtip_port *port, unsigned int id,
757 struct smart_attr *attrib);
701/* 758/*
702 * Handle an error. 759 * Handle an error.
703 * 760 *
@@ -708,12 +765,16 @@ static void print_tags(struct driver_data *dd,
708 */ 765 */
709static void mtip_handle_tfe(struct driver_data *dd) 766static void mtip_handle_tfe(struct driver_data *dd)
710{ 767{
711 int group, tag, bit, reissue; 768 int group, tag, bit, reissue, rv;
712 struct mtip_port *port; 769 struct mtip_port *port;
713 struct mtip_cmd *command; 770 struct mtip_cmd *cmd;
714 u32 completed; 771 u32 completed;
715 struct host_to_dev_fis *fis; 772 struct host_to_dev_fis *fis;
716 unsigned long tagaccum[SLOTBITS_IN_LONGS]; 773 unsigned long tagaccum[SLOTBITS_IN_LONGS];
774 unsigned int cmd_cnt = 0;
775 unsigned char *buf;
776 char *fail_reason = NULL;
777 int fail_all_ncq_write = 0, fail_all_ncq_cmds = 0;
717 778
718 dev_warn(&dd->pdev->dev, "Taskfile error\n"); 779 dev_warn(&dd->pdev->dev, "Taskfile error\n");
719 780
@@ -722,8 +783,11 @@ static void mtip_handle_tfe(struct driver_data *dd)
722 /* Stop the timer to prevent command timeouts. */ 783 /* Stop the timer to prevent command timeouts. */
723 del_timer(&port->cmd_timer); 784 del_timer(&port->cmd_timer);
724 785
786 /* clear the tag accumulator */
787 memset(tagaccum, 0, SLOTBITS_IN_LONGS * sizeof(long));
788
725 /* Set eh_active */ 789 /* Set eh_active */
726 set_bit(MTIP_FLAG_EH_ACTIVE_BIT, &port->flags); 790 set_bit(MTIP_PF_EH_ACTIVE_BIT, &port->flags);
727 791
728 /* Loop through all the groups */ 792 /* Loop through all the groups */
729 for (group = 0; group < dd->slot_groups; group++) { 793 for (group = 0; group < dd->slot_groups; group++) {
@@ -732,9 +796,6 @@ static void mtip_handle_tfe(struct driver_data *dd)
732 /* clear completed status register in the hardware.*/ 796 /* clear completed status register in the hardware.*/
733 writel(completed, port->completed[group]); 797 writel(completed, port->completed[group]);
734 798
735 /* clear the tag accumulator */
736 memset(tagaccum, 0, SLOTBITS_IN_LONGS * sizeof(long));
737
738 /* Process successfully completed commands */ 799 /* Process successfully completed commands */
739 for (bit = 0; bit < 32 && completed; bit++) { 800 for (bit = 0; bit < 32 && completed; bit++) {
740 if (!(completed & (1<<bit))) 801 if (!(completed & (1<<bit)))
@@ -745,13 +806,14 @@ static void mtip_handle_tfe(struct driver_data *dd)
745 if (tag == MTIP_TAG_INTERNAL) 806 if (tag == MTIP_TAG_INTERNAL)
746 continue; 807 continue;
747 808
748 command = &port->commands[tag]; 809 cmd = &port->commands[tag];
749 if (likely(command->comp_func)) { 810 if (likely(cmd->comp_func)) {
750 set_bit(tag, tagaccum); 811 set_bit(tag, tagaccum);
751 atomic_set(&port->commands[tag].active, 0); 812 cmd_cnt++;
752 command->comp_func(port, 813 atomic_set(&cmd->active, 0);
814 cmd->comp_func(port,
753 tag, 815 tag,
754 command->comp_data, 816 cmd->comp_data,
755 0); 817 0);
756 } else { 818 } else {
757 dev_err(&port->dd->pdev->dev, 819 dev_err(&port->dd->pdev->dev,
@@ -765,12 +827,45 @@ static void mtip_handle_tfe(struct driver_data *dd)
765 } 827 }
766 } 828 }
767 } 829 }
768 print_tags(dd, "TFE tags completed:", tagaccum); 830
831 print_tags(dd, "completed (TFE)", tagaccum, cmd_cnt);
769 832
770 /* Restart the port */ 833 /* Restart the port */
771 mdelay(20); 834 mdelay(20);
772 mtip_restart_port(port); 835 mtip_restart_port(port);
773 836
837 /* Trying to determine the cause of the error */
838 rv = mtip_read_log_page(dd->port, ATA_LOG_SATA_NCQ,
839 dd->port->log_buf,
840 dd->port->log_buf_dma, 1);
841 if (rv) {
842 dev_warn(&dd->pdev->dev,
843 "Error in READ LOG EXT (10h) command\n");
844 /* non-critical error, don't fail the load */
845 } else {
846 buf = (unsigned char *)dd->port->log_buf;
847 if (buf[259] & 0x1) {
848 dev_info(&dd->pdev->dev,
849 "Write protect bit is set.\n");
850 set_bit(MTIP_DDF_WRITE_PROTECT_BIT, &dd->dd_flag);
851 fail_all_ncq_write = 1;
852 fail_reason = "write protect";
853 }
854 if (buf[288] == 0xF7) {
855 dev_info(&dd->pdev->dev,
856 "Exceeded Tmax, drive in thermal shutdown.\n");
857 set_bit(MTIP_DDF_OVER_TEMP_BIT, &dd->dd_flag);
858 fail_all_ncq_cmds = 1;
859 fail_reason = "thermal shutdown";
860 }
861 if (buf[288] == 0xBF) {
862 dev_info(&dd->pdev->dev,
863 "Drive indicates rebuild has failed.\n");
864 fail_all_ncq_cmds = 1;
865 fail_reason = "rebuild failed";
866 }
867 }
868
774 /* clear the tag accumulator */ 869 /* clear the tag accumulator */
775 memset(tagaccum, 0, SLOTBITS_IN_LONGS * sizeof(long)); 870 memset(tagaccum, 0, SLOTBITS_IN_LONGS * sizeof(long));
776 871
@@ -779,32 +874,47 @@ static void mtip_handle_tfe(struct driver_data *dd)
779 for (bit = 0; bit < 32; bit++) { 874 for (bit = 0; bit < 32; bit++) {
780 reissue = 1; 875 reissue = 1;
781 tag = (group << 5) + bit; 876 tag = (group << 5) + bit;
877 cmd = &port->commands[tag];
782 878
783 /* If the active bit is set re-issue the command */ 879 /* If the active bit is set re-issue the command */
784 if (atomic_read(&port->commands[tag].active) == 0) 880 if (atomic_read(&cmd->active) == 0)
785 continue; 881 continue;
786 882
787 fis = (struct host_to_dev_fis *) 883 fis = (struct host_to_dev_fis *)cmd->command;
788 port->commands[tag].command;
789 884
790 /* Should re-issue? */ 885 /* Should re-issue? */
791 if (tag == MTIP_TAG_INTERNAL || 886 if (tag == MTIP_TAG_INTERNAL ||
792 fis->command == ATA_CMD_SET_FEATURES) 887 fis->command == ATA_CMD_SET_FEATURES)
793 reissue = 0; 888 reissue = 0;
889 else {
890 if (fail_all_ncq_cmds ||
891 (fail_all_ncq_write &&
892 fis->command == ATA_CMD_FPDMA_WRITE)) {
893 dev_warn(&dd->pdev->dev,
894 " Fail: %s w/tag %d [%s].\n",
895 fis->command == ATA_CMD_FPDMA_WRITE ?
896 "write" : "read",
897 tag,
898 fail_reason != NULL ?
899 fail_reason : "unknown");
900 atomic_set(&cmd->active, 0);
901 if (cmd->comp_func) {
902 cmd->comp_func(port, tag,
903 cmd->comp_data,
904 -ENODATA);
905 }
906 continue;
907 }
908 }
794 909
795 /* 910 /*
796 * First check if this command has 911 * First check if this command has
797 * exceeded its retries. 912 * exceeded its retries.
798 */ 913 */
799 if (reissue && 914 if (reissue && (cmd->retries-- > 0)) {
800 (port->commands[tag].retries-- > 0)) {
801 915
802 set_bit(tag, tagaccum); 916 set_bit(tag, tagaccum);
803 917
804 /* Update the timeout value. */
805 port->commands[tag].comp_time =
806 jiffies + msecs_to_jiffies(
807 MTIP_NCQ_COMMAND_TIMEOUT_MS);
808 /* Re-issue the command. */ 918 /* Re-issue the command. */
809 mtip_issue_ncq_command(port, tag); 919 mtip_issue_ncq_command(port, tag);
810 920
@@ -814,13 +924,13 @@ static void mtip_handle_tfe(struct driver_data *dd)
814 /* Retire a command that will not be reissued */ 924 /* Retire a command that will not be reissued */
815 dev_warn(&port->dd->pdev->dev, 925 dev_warn(&port->dd->pdev->dev,
816 "retiring tag %d\n", tag); 926 "retiring tag %d\n", tag);
817 atomic_set(&port->commands[tag].active, 0); 927 atomic_set(&cmd->active, 0);
818 928
819 if (port->commands[tag].comp_func) 929 if (cmd->comp_func)
820 port->commands[tag].comp_func( 930 cmd->comp_func(
821 port, 931 port,
822 tag, 932 tag,
823 port->commands[tag].comp_data, 933 cmd->comp_data,
824 PORT_IRQ_TF_ERR); 934 PORT_IRQ_TF_ERR);
825 else 935 else
826 dev_warn(&port->dd->pdev->dev, 936 dev_warn(&port->dd->pdev->dev,
@@ -828,10 +938,10 @@ static void mtip_handle_tfe(struct driver_data *dd)
828 tag); 938 tag);
829 } 939 }
830 } 940 }
831 print_tags(dd, "TFE tags reissued:", tagaccum); 941 print_tags(dd, "reissued (TFE)", tagaccum, cmd_cnt);
832 942
833 /* clear eh_active */ 943 /* clear eh_active */
834 clear_bit(MTIP_FLAG_EH_ACTIVE_BIT, &port->flags); 944 clear_bit(MTIP_PF_EH_ACTIVE_BIT, &port->flags);
835 wake_up_interruptible(&port->svc_wait); 945 wake_up_interruptible(&port->svc_wait);
836 946
837 mod_timer(&port->cmd_timer, 947 mod_timer(&port->cmd_timer,
@@ -899,7 +1009,7 @@ static inline void mtip_process_legacy(struct driver_data *dd, u32 port_stat)
899 struct mtip_port *port = dd->port; 1009 struct mtip_port *port = dd->port;
900 struct mtip_cmd *cmd = &port->commands[MTIP_TAG_INTERNAL]; 1010 struct mtip_cmd *cmd = &port->commands[MTIP_TAG_INTERNAL];
901 1011
902 if (test_bit(MTIP_FLAG_IC_ACTIVE_BIT, &port->flags) && 1012 if (test_bit(MTIP_PF_IC_ACTIVE_BIT, &port->flags) &&
903 (cmd != NULL) && !(readl(port->cmd_issue[MTIP_TAG_INTERNAL]) 1013 (cmd != NULL) && !(readl(port->cmd_issue[MTIP_TAG_INTERNAL])
904 & (1 << MTIP_TAG_INTERNAL))) { 1014 & (1 << MTIP_TAG_INTERNAL))) {
905 if (cmd->comp_func) { 1015 if (cmd->comp_func) {
@@ -911,8 +1021,6 @@ static inline void mtip_process_legacy(struct driver_data *dd, u32 port_stat)
911 } 1021 }
912 } 1022 }
913 1023
914 dev_warn(&dd->pdev->dev, "IRQ status 0x%x ignored.\n", port_stat);
915
916 return; 1024 return;
917} 1025}
918 1026
@@ -968,6 +1076,9 @@ static inline irqreturn_t mtip_handle_irq(struct driver_data *data)
968 /* don't proceed further */ 1076 /* don't proceed further */
969 return IRQ_HANDLED; 1077 return IRQ_HANDLED;
970 } 1078 }
1079 if (test_bit(MTIP_DDF_REMOVE_PENDING_BIT,
1080 &dd->dd_flag))
1081 return rv;
971 1082
972 mtip_process_errors(dd, port_stat & PORT_IRQ_ERR); 1083 mtip_process_errors(dd, port_stat & PORT_IRQ_ERR);
973 } 1084 }
@@ -1015,6 +1126,39 @@ static void mtip_issue_non_ncq_command(struct mtip_port *port, int tag)
1015 port->cmd_issue[MTIP_TAG_INDEX(tag)]); 1126 port->cmd_issue[MTIP_TAG_INDEX(tag)]);
1016} 1127}
1017 1128
1129static bool mtip_pause_ncq(struct mtip_port *port,
1130 struct host_to_dev_fis *fis)
1131{
1132 struct host_to_dev_fis *reply;
1133 unsigned long task_file_data;
1134
1135 reply = port->rxfis + RX_FIS_D2H_REG;
1136 task_file_data = readl(port->mmio+PORT_TFDATA);
1137
1138 if ((task_file_data & 1) || (fis->command == ATA_CMD_SEC_ERASE_UNIT))
1139 return false;
1140
1141 if (fis->command == ATA_CMD_SEC_ERASE_PREP) {
1142 set_bit(MTIP_PF_SE_ACTIVE_BIT, &port->flags);
1143 port->ic_pause_timer = jiffies;
1144 return true;
1145 } else if ((fis->command == ATA_CMD_DOWNLOAD_MICRO) &&
1146 (fis->features == 0x03)) {
1147 set_bit(MTIP_PF_DM_ACTIVE_BIT, &port->flags);
1148 port->ic_pause_timer = jiffies;
1149 return true;
1150 } else if ((fis->command == ATA_CMD_SEC_ERASE_UNIT) ||
1151 ((fis->command == 0xFC) &&
1152 (fis->features == 0x27 || fis->features == 0x72 ||
1153 fis->features == 0x62 || fis->features == 0x26))) {
1154 /* Com reset after secure erase or lowlevel format */
1155 mtip_restart_port(port);
1156 return false;
1157 }
1158
1159 return false;
1160}
1161
1018/* 1162/*
1019 * Wait for port to quiesce 1163 * Wait for port to quiesce
1020 * 1164 *
@@ -1033,11 +1177,13 @@ static int mtip_quiesce_io(struct mtip_port *port, unsigned long timeout)
1033 1177
1034 to = jiffies + msecs_to_jiffies(timeout); 1178 to = jiffies + msecs_to_jiffies(timeout);
1035 do { 1179 do {
1036 if (test_bit(MTIP_FLAG_SVC_THD_ACTIVE_BIT, &port->flags) && 1180 if (test_bit(MTIP_PF_SVC_THD_ACTIVE_BIT, &port->flags) &&
1037 test_bit(MTIP_FLAG_ISSUE_CMDS_BIT, &port->flags)) { 1181 test_bit(MTIP_PF_ISSUE_CMDS_BIT, &port->flags)) {
1038 msleep(20); 1182 msleep(20);
1039 continue; /* svc thd is actively issuing commands */ 1183 continue; /* svc thd is actively issuing commands */
1040 } 1184 }
1185 if (test_bit(MTIP_DDF_REMOVE_PENDING_BIT, &port->dd->dd_flag))
1186 return -EFAULT;
1041 /* 1187 /*
1042 * Ignore s_active bit 0 of array element 0. 1188 * Ignore s_active bit 0 of array element 0.
1043 * This bit will always be set 1189 * This bit will always be set
@@ -1074,7 +1220,7 @@ static int mtip_quiesce_io(struct mtip_port *port, unsigned long timeout)
1074 * -EAGAIN Time out waiting for command to complete. 1220 * -EAGAIN Time out waiting for command to complete.
1075 */ 1221 */
1076static int mtip_exec_internal_command(struct mtip_port *port, 1222static int mtip_exec_internal_command(struct mtip_port *port,
1077 void *fis, 1223 struct host_to_dev_fis *fis,
1078 int fis_len, 1224 int fis_len,
1079 dma_addr_t buffer, 1225 dma_addr_t buffer,
1080 int buf_len, 1226 int buf_len,
@@ -1084,8 +1230,9 @@ static int mtip_exec_internal_command(struct mtip_port *port,
1084{ 1230{
1085 struct mtip_cmd_sg *command_sg; 1231 struct mtip_cmd_sg *command_sg;
1086 DECLARE_COMPLETION_ONSTACK(wait); 1232 DECLARE_COMPLETION_ONSTACK(wait);
1087 int rv = 0; 1233 int rv = 0, ready2go = 1;
1088 struct mtip_cmd *int_cmd = &port->commands[MTIP_TAG_INTERNAL]; 1234 struct mtip_cmd *int_cmd = &port->commands[MTIP_TAG_INTERNAL];
1235 unsigned long to;
1089 1236
1090 /* Make sure the buffer is 8 byte aligned. This is asic specific. */ 1237 /* Make sure the buffer is 8 byte aligned. This is asic specific. */
1091 if (buffer & 0x00000007) { 1238 if (buffer & 0x00000007) {
@@ -1094,23 +1241,38 @@ static int mtip_exec_internal_command(struct mtip_port *port,
1094 return -EFAULT; 1241 return -EFAULT;
1095 } 1242 }
1096 1243
1097 /* Only one internal command should be running at a time */ 1244 to = jiffies + msecs_to_jiffies(timeout);
1098 if (test_and_set_bit(MTIP_TAG_INTERNAL, port->allocated)) { 1245 do {
1246 ready2go = !test_and_set_bit(MTIP_TAG_INTERNAL,
1247 port->allocated);
1248 if (ready2go)
1249 break;
1250 mdelay(100);
1251 } while (time_before(jiffies, to));
1252 if (!ready2go) {
1099 dev_warn(&port->dd->pdev->dev, 1253 dev_warn(&port->dd->pdev->dev,
1100 "Internal command already active\n"); 1254 "Internal cmd active. new cmd [%02X]\n", fis->command);
1101 return -EBUSY; 1255 return -EBUSY;
1102 } 1256 }
1103 set_bit(MTIP_FLAG_IC_ACTIVE_BIT, &port->flags); 1257 set_bit(MTIP_PF_IC_ACTIVE_BIT, &port->flags);
1258 port->ic_pause_timer = 0;
1259
1260 if (fis->command == ATA_CMD_SEC_ERASE_UNIT)
1261 clear_bit(MTIP_PF_SE_ACTIVE_BIT, &port->flags);
1262 else if (fis->command == ATA_CMD_DOWNLOAD_MICRO)
1263 clear_bit(MTIP_PF_DM_ACTIVE_BIT, &port->flags);
1104 1264
1105 if (atomic == GFP_KERNEL) { 1265 if (atomic == GFP_KERNEL) {
1106 /* wait for io to complete if non atomic */ 1266 if (fis->command != ATA_CMD_STANDBYNOW1) {
1107 if (mtip_quiesce_io(port, 5000) < 0) { 1267 /* wait for io to complete if non atomic */
1108 dev_warn(&port->dd->pdev->dev, 1268 if (mtip_quiesce_io(port, 5000) < 0) {
1109 "Failed to quiesce IO\n"); 1269 dev_warn(&port->dd->pdev->dev,
1110 release_slot(port, MTIP_TAG_INTERNAL); 1270 "Failed to quiesce IO\n");
1111 clear_bit(MTIP_FLAG_IC_ACTIVE_BIT, &port->flags); 1271 release_slot(port, MTIP_TAG_INTERNAL);
1112 wake_up_interruptible(&port->svc_wait); 1272 clear_bit(MTIP_PF_IC_ACTIVE_BIT, &port->flags);
1113 return -EBUSY; 1273 wake_up_interruptible(&port->svc_wait);
1274 return -EBUSY;
1275 }
1114 } 1276 }
1115 1277
1116 /* Set the completion function and data for the command. */ 1278 /* Set the completion function and data for the command. */
@@ -1120,7 +1282,7 @@ static int mtip_exec_internal_command(struct mtip_port *port,
1120 } else { 1282 } else {
1121 /* Clear completion - we're going to poll */ 1283 /* Clear completion - we're going to poll */
1122 int_cmd->comp_data = NULL; 1284 int_cmd->comp_data = NULL;
1123 int_cmd->comp_func = NULL; 1285 int_cmd->comp_func = mtip_null_completion;
1124 } 1286 }
1125 1287
1126 /* Copy the command to the command table */ 1288 /* Copy the command to the command table */
@@ -1159,6 +1321,12 @@ static int mtip_exec_internal_command(struct mtip_port *port,
1159 "Internal command did not complete [%d] " 1321 "Internal command did not complete [%d] "
1160 "within timeout of %lu ms\n", 1322 "within timeout of %lu ms\n",
1161 atomic, timeout); 1323 atomic, timeout);
1324 if (mtip_check_surprise_removal(port->dd->pdev) ||
1325 test_bit(MTIP_DDF_REMOVE_PENDING_BIT,
1326 &port->dd->dd_flag)) {
1327 rv = -ENXIO;
1328 goto exec_ic_exit;
1329 }
1162 rv = -EAGAIN; 1330 rv = -EAGAIN;
1163 } 1331 }
1164 1332
@@ -1166,31 +1334,59 @@ static int mtip_exec_internal_command(struct mtip_port *port,
1166 & (1 << MTIP_TAG_INTERNAL)) { 1334 & (1 << MTIP_TAG_INTERNAL)) {
1167 dev_warn(&port->dd->pdev->dev, 1335 dev_warn(&port->dd->pdev->dev,
1168 "Retiring internal command but CI is 1.\n"); 1336 "Retiring internal command but CI is 1.\n");
1337 if (test_bit(MTIP_DDF_REMOVE_PENDING_BIT,
1338 &port->dd->dd_flag)) {
1339 hba_reset_nosleep(port->dd);
1340 rv = -ENXIO;
1341 } else {
1342 mtip_restart_port(port);
1343 rv = -EAGAIN;
1344 }
1345 goto exec_ic_exit;
1169 } 1346 }
1170 1347
1171 } else { 1348 } else {
1172 /* Spin for <timeout> checking if command still outstanding */ 1349 /* Spin for <timeout> checking if command still outstanding */
1173 timeout = jiffies + msecs_to_jiffies(timeout); 1350 timeout = jiffies + msecs_to_jiffies(timeout);
1174 1351 while ((readl(port->cmd_issue[MTIP_TAG_INTERNAL])
1175 while ((readl( 1352 & (1 << MTIP_TAG_INTERNAL))
1176 port->cmd_issue[MTIP_TAG_INTERNAL]) 1353 && time_before(jiffies, timeout)) {
1177 & (1 << MTIP_TAG_INTERNAL)) 1354 if (mtip_check_surprise_removal(port->dd->pdev)) {
1178 && time_before(jiffies, timeout)) 1355 rv = -ENXIO;
1179 ; 1356 goto exec_ic_exit;
1357 }
1358 if ((fis->command != ATA_CMD_STANDBYNOW1) &&
1359 test_bit(MTIP_DDF_REMOVE_PENDING_BIT,
1360 &port->dd->dd_flag)) {
1361 rv = -ENXIO;
1362 goto exec_ic_exit;
1363 }
1364 }
1180 1365
1181 if (readl(port->cmd_issue[MTIP_TAG_INTERNAL]) 1366 if (readl(port->cmd_issue[MTIP_TAG_INTERNAL])
1182 & (1 << MTIP_TAG_INTERNAL)) { 1367 & (1 << MTIP_TAG_INTERNAL)) {
1183 dev_err(&port->dd->pdev->dev, 1368 dev_err(&port->dd->pdev->dev,
1184 "Internal command did not complete [%d]\n", 1369 "Internal command did not complete [atomic]\n");
1185 atomic);
1186 rv = -EAGAIN; 1370 rv = -EAGAIN;
1371 if (test_bit(MTIP_DDF_REMOVE_PENDING_BIT,
1372 &port->dd->dd_flag)) {
1373 hba_reset_nosleep(port->dd);
1374 rv = -ENXIO;
1375 } else {
1376 mtip_restart_port(port);
1377 rv = -EAGAIN;
1378 }
1187 } 1379 }
1188 } 1380 }
1189 1381exec_ic_exit:
1190 /* Clear the allocated and active bits for the internal command. */ 1382 /* Clear the allocated and active bits for the internal command. */
1191 atomic_set(&int_cmd->active, 0); 1383 atomic_set(&int_cmd->active, 0);
1192 release_slot(port, MTIP_TAG_INTERNAL); 1384 release_slot(port, MTIP_TAG_INTERNAL);
1193 clear_bit(MTIP_FLAG_IC_ACTIVE_BIT, &port->flags); 1385 if (rv >= 0 && mtip_pause_ncq(port, fis)) {
1386 /* NCQ paused */
1387 return rv;
1388 }
1389 clear_bit(MTIP_PF_IC_ACTIVE_BIT, &port->flags);
1194 wake_up_interruptible(&port->svc_wait); 1390 wake_up_interruptible(&port->svc_wait);
1195 1391
1196 return rv; 1392 return rv;
@@ -1240,6 +1436,9 @@ static int mtip_get_identify(struct mtip_port *port, void __user *user_buffer)
1240 int rv = 0; 1436 int rv = 0;
1241 struct host_to_dev_fis fis; 1437 struct host_to_dev_fis fis;
1242 1438
1439 if (test_bit(MTIP_DDF_REMOVE_PENDING_BIT, &port->dd->dd_flag))
1440 return -EFAULT;
1441
1243 /* Build the FIS. */ 1442 /* Build the FIS. */
1244 memset(&fis, 0, sizeof(struct host_to_dev_fis)); 1443 memset(&fis, 0, sizeof(struct host_to_dev_fis));
1245 fis.type = 0x27; 1444 fis.type = 0x27;
@@ -1313,6 +1512,7 @@ static int mtip_standby_immediate(struct mtip_port *port)
1313{ 1512{
1314 int rv; 1513 int rv;
1315 struct host_to_dev_fis fis; 1514 struct host_to_dev_fis fis;
1515 unsigned long start;
1316 1516
1317 /* Build the FIS. */ 1517 /* Build the FIS. */
1318 memset(&fis, 0, sizeof(struct host_to_dev_fis)); 1518 memset(&fis, 0, sizeof(struct host_to_dev_fis));
@@ -1320,15 +1520,150 @@ static int mtip_standby_immediate(struct mtip_port *port)
1320 fis.opts = 1 << 7; 1520 fis.opts = 1 << 7;
1321 fis.command = ATA_CMD_STANDBYNOW1; 1521 fis.command = ATA_CMD_STANDBYNOW1;
1322 1522
1323 /* Execute the command. Use a 15-second timeout for large drives. */ 1523 start = jiffies;
1324 rv = mtip_exec_internal_command(port, 1524 rv = mtip_exec_internal_command(port,
1325 &fis, 1525 &fis,
1326 5, 1526 5,
1327 0, 1527 0,
1328 0, 1528 0,
1329 0, 1529 0,
1330 GFP_KERNEL, 1530 GFP_ATOMIC,
1331 15000); 1531 15000);
1532 dbg_printk(MTIP_DRV_NAME "Time taken to complete standby cmd: %d ms\n",
1533 jiffies_to_msecs(jiffies - start));
1534 if (rv)
1535 dev_warn(&port->dd->pdev->dev,
1536 "STANDBY IMMEDIATE command failed.\n");
1537
1538 return rv;
1539}
1540
1541/*
1542 * Issue a READ LOG EXT command to the device.
1543 *
1544 * @port pointer to the port structure.
1545 * @page page number to fetch
1546 * @buffer pointer to buffer
1547 * @buffer_dma dma address corresponding to @buffer
1548 * @sectors page length to fetch, in sectors
1549 *
1550 * return value
1551 * @rv return value from mtip_exec_internal_command()
1552 */
1553static int mtip_read_log_page(struct mtip_port *port, u8 page, u16 *buffer,
1554 dma_addr_t buffer_dma, unsigned int sectors)
1555{
1556 struct host_to_dev_fis fis;
1557
1558 memset(&fis, 0, sizeof(struct host_to_dev_fis));
1559 fis.type = 0x27;
1560 fis.opts = 1 << 7;
1561 fis.command = ATA_CMD_READ_LOG_EXT;
1562 fis.sect_count = sectors & 0xFF;
1563 fis.sect_cnt_ex = (sectors >> 8) & 0xFF;
1564 fis.lba_low = page;
1565 fis.lba_mid = 0;
1566 fis.device = ATA_DEVICE_OBS;
1567
1568 memset(buffer, 0, sectors * ATA_SECT_SIZE);
1569
1570 return mtip_exec_internal_command(port,
1571 &fis,
1572 5,
1573 buffer_dma,
1574 sectors * ATA_SECT_SIZE,
1575 0,
1576 GFP_ATOMIC,
1577 MTIP_INTERNAL_COMMAND_TIMEOUT_MS);
1578}
1579
1580/*
1581 * Issue a SMART READ DATA command to the device.
1582 *
1583 * @port pointer to the port structure.
1584 * @buffer pointer to buffer
1585 * @buffer_dma dma address corresponding to @buffer
1586 *
1587 * return value
1588 * @rv return value from mtip_exec_internal_command()
1589 */
1590static int mtip_get_smart_data(struct mtip_port *port, u8 *buffer,
1591 dma_addr_t buffer_dma)
1592{
1593 struct host_to_dev_fis fis;
1594
1595 memset(&fis, 0, sizeof(struct host_to_dev_fis));
1596 fis.type = 0x27;
1597 fis.opts = 1 << 7;
1598 fis.command = ATA_CMD_SMART;
1599 fis.features = 0xD0;
1600 fis.sect_count = 1;
1601 fis.lba_mid = 0x4F;
1602 fis.lba_hi = 0xC2;
1603 fis.device = ATA_DEVICE_OBS;
1604
1605 return mtip_exec_internal_command(port,
1606 &fis,
1607 5,
1608 buffer_dma,
1609 ATA_SECT_SIZE,
1610 0,
1611 GFP_ATOMIC,
1612 15000);
1613}
1614
1615/*
1616 * Get the value of a smart attribute
1617 *
1618 * @port pointer to the port structure
1619 * @id attribute number
1620 * @attrib pointer to return attrib information corresponding to @id
1621 *
1622 * return value
1623 * -EINVAL NULL buffer passed or unsupported attribute @id.
1624 * -EPERM Identify data not valid, SMART not supported or not enabled
1625 */
1626static int mtip_get_smart_attr(struct mtip_port *port, unsigned int id,
1627 struct smart_attr *attrib)
1628{
1629 int rv, i;
1630 struct smart_attr *pattr;
1631
1632 if (!attrib)
1633 return -EINVAL;
1634
1635 if (!port->identify_valid) {
1636 dev_warn(&port->dd->pdev->dev, "IDENTIFY DATA not valid\n");
1637 return -EPERM;
1638 }
1639 if (!(port->identify[82] & 0x1)) {
1640 dev_warn(&port->dd->pdev->dev, "SMART not supported\n");
1641 return -EPERM;
1642 }
1643 if (!(port->identify[85] & 0x1)) {
1644 dev_warn(&port->dd->pdev->dev, "SMART not enabled\n");
1645 return -EPERM;
1646 }
1647
1648 memset(port->smart_buf, 0, ATA_SECT_SIZE);
1649 rv = mtip_get_smart_data(port, port->smart_buf, port->smart_buf_dma);
1650 if (rv) {
1651 dev_warn(&port->dd->pdev->dev, "Failed to ge SMART data\n");
1652 return rv;
1653 }
1654
1655 pattr = (struct smart_attr *)(port->smart_buf + 2);
1656 for (i = 0; i < 29; i++, pattr++)
1657 if (pattr->attr_id == id) {
1658 memcpy(attrib, pattr, sizeof(struct smart_attr));
1659 break;
1660 }
1661
1662 if (i == 29) {
1663 dev_warn(&port->dd->pdev->dev,
1664 "Query for invalid SMART attribute ID\n");
1665 rv = -EINVAL;
1666 }
1332 1667
1333 return rv; 1668 return rv;
1334} 1669}
@@ -1504,10 +1839,7 @@ static int exec_drive_task(struct mtip_port *port, u8 *command)
1504 fis.cyl_hi = command[5]; 1839 fis.cyl_hi = command[5];
1505 fis.device = command[6] & ~0x10; /* Clear the dev bit*/ 1840 fis.device = command[6] & ~0x10; /* Clear the dev bit*/
1506 1841
1507 1842 dbg_printk(MTIP_DRV_NAME " %s: User Command: cmd %x, feat %x, nsect %x, sect %x, lcyl %x, hcyl %x, sel %x\n",
1508 dbg_printk(MTIP_DRV_NAME "%s: User Command: cmd %x, feat %x, "
1509 "nsect %x, sect %x, lcyl %x, "
1510 "hcyl %x, sel %x\n",
1511 __func__, 1843 __func__,
1512 command[0], 1844 command[0],
1513 command[1], 1845 command[1],
@@ -1534,8 +1866,7 @@ static int exec_drive_task(struct mtip_port *port, u8 *command)
1534 command[4] = reply->cyl_low; 1866 command[4] = reply->cyl_low;
1535 command[5] = reply->cyl_hi; 1867 command[5] = reply->cyl_hi;
1536 1868
1537 dbg_printk(MTIP_DRV_NAME "%s: Completion Status: stat %x, " 1869 dbg_printk(MTIP_DRV_NAME " %s: Completion Status: stat %x, err %x , cyl_lo %x cyl_hi %x\n",
1538 "err %x , cyl_lo %x cyl_hi %x\n",
1539 __func__, 1870 __func__,
1540 command[0], 1871 command[0],
1541 command[1], 1872 command[1],
@@ -1578,7 +1909,7 @@ static int exec_drive_command(struct mtip_port *port, u8 *command,
1578 } 1909 }
1579 1910
1580 dbg_printk(MTIP_DRV_NAME 1911 dbg_printk(MTIP_DRV_NAME
1581 "%s: User Command: cmd %x, sect %x, " 1912 " %s: User Command: cmd %x, sect %x, "
1582 "feat %x, sectcnt %x\n", 1913 "feat %x, sectcnt %x\n",
1583 __func__, 1914 __func__,
1584 command[0], 1915 command[0],
@@ -1607,7 +1938,7 @@ static int exec_drive_command(struct mtip_port *port, u8 *command,
1607 command[2] = command[3]; 1938 command[2] = command[3];
1608 1939
1609 dbg_printk(MTIP_DRV_NAME 1940 dbg_printk(MTIP_DRV_NAME
1610 "%s: Completion Status: stat %x, " 1941 " %s: Completion Status: stat %x, "
1611 "err %x, cmd %x\n", 1942 "err %x, cmd %x\n",
1612 __func__, 1943 __func__,
1613 command[0], 1944 command[0],
@@ -1810,9 +2141,10 @@ static int exec_drive_taskfile(struct driver_data *dd,
1810 } 2141 }
1811 2142
1812 dbg_printk(MTIP_DRV_NAME 2143 dbg_printk(MTIP_DRV_NAME
1813 "taskfile: cmd %x, feat %x, nsect %x," 2144 " %s: cmd %x, feat %x, nsect %x,"
1814 " sect/lbal %x, lcyl/lbam %x, hcyl/lbah %x," 2145 " sect/lbal %x, lcyl/lbam %x, hcyl/lbah %x,"
1815 " head/dev %x\n", 2146 " head/dev %x\n",
2147 __func__,
1816 fis.command, 2148 fis.command,
1817 fis.features, 2149 fis.features,
1818 fis.sect_count, 2150 fis.sect_count,
@@ -1823,8 +2155,8 @@ static int exec_drive_taskfile(struct driver_data *dd,
1823 2155
1824 switch (fis.command) { 2156 switch (fis.command) {
1825 case ATA_CMD_DOWNLOAD_MICRO: 2157 case ATA_CMD_DOWNLOAD_MICRO:
1826 /* Change timeout for Download Microcode to 60 seconds.*/ 2158 /* Change timeout for Download Microcode to 2 minutes */
1827 timeout = 60000; 2159 timeout = 120000;
1828 break; 2160 break;
1829 case ATA_CMD_SEC_ERASE_UNIT: 2161 case ATA_CMD_SEC_ERASE_UNIT:
1830 /* Change timeout for Security Erase Unit to 4 minutes.*/ 2162 /* Change timeout for Security Erase Unit to 4 minutes.*/
@@ -1840,8 +2172,8 @@ static int exec_drive_taskfile(struct driver_data *dd,
1840 timeout = 10000; 2172 timeout = 10000;
1841 break; 2173 break;
1842 case ATA_CMD_SMART: 2174 case ATA_CMD_SMART:
1843 /* Change timeout for vendor unique command to 10 secs */ 2175 /* Change timeout for vendor unique command to 15 secs */
1844 timeout = 10000; 2176 timeout = 15000;
1845 break; 2177 break;
1846 default: 2178 default:
1847 timeout = MTIP_IOCTL_COMMAND_TIMEOUT_MS; 2179 timeout = MTIP_IOCTL_COMMAND_TIMEOUT_MS;
@@ -1903,18 +2235,8 @@ static int exec_drive_taskfile(struct driver_data *dd,
1903 req_task->hob_ports[1] = reply->features_ex; 2235 req_task->hob_ports[1] = reply->features_ex;
1904 req_task->hob_ports[2] = reply->sect_cnt_ex; 2236 req_task->hob_ports[2] = reply->sect_cnt_ex;
1905 } 2237 }
1906
1907 /* Com rest after secure erase or lowlevel format */
1908 if (((fis.command == ATA_CMD_SEC_ERASE_UNIT) ||
1909 ((fis.command == 0xFC) &&
1910 (fis.features == 0x27 || fis.features == 0x72 ||
1911 fis.features == 0x62 || fis.features == 0x26))) &&
1912 !(reply->command & 1)) {
1913 mtip_restart_port(dd->port);
1914 }
1915
1916 dbg_printk(MTIP_DRV_NAME 2238 dbg_printk(MTIP_DRV_NAME
1917 "%s: Completion: stat %x," 2239 " %s: Completion: stat %x,"
1918 "err %x, sect_cnt %x, lbalo %x," 2240 "err %x, sect_cnt %x, lbalo %x,"
1919 "lbamid %x, lbahi %x, dev %x\n", 2241 "lbamid %x, lbahi %x, dev %x\n",
1920 __func__, 2242 __func__,
@@ -2080,14 +2402,10 @@ static void mtip_hw_submit_io(struct driver_data *dd, sector_t start,
2080 struct host_to_dev_fis *fis; 2402 struct host_to_dev_fis *fis;
2081 struct mtip_port *port = dd->port; 2403 struct mtip_port *port = dd->port;
2082 struct mtip_cmd *command = &port->commands[tag]; 2404 struct mtip_cmd *command = &port->commands[tag];
2405 int dma_dir = (dir == READ) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
2083 2406
2084 /* Map the scatter list for DMA access */ 2407 /* Map the scatter list for DMA access */
2085 if (dir == READ) 2408 nents = dma_map_sg(&dd->pdev->dev, command->sg, nents, dma_dir);
2086 nents = dma_map_sg(&dd->pdev->dev, command->sg,
2087 nents, DMA_FROM_DEVICE);
2088 else
2089 nents = dma_map_sg(&dd->pdev->dev, command->sg,
2090 nents, DMA_TO_DEVICE);
2091 2409
2092 command->scatter_ents = nents; 2410 command->scatter_ents = nents;
2093 2411
@@ -2127,7 +2445,7 @@ static void mtip_hw_submit_io(struct driver_data *dd, sector_t start,
2127 */ 2445 */
2128 command->comp_data = dd; 2446 command->comp_data = dd;
2129 command->comp_func = mtip_async_complete; 2447 command->comp_func = mtip_async_complete;
2130 command->direction = (dir == READ ? DMA_FROM_DEVICE : DMA_TO_DEVICE); 2448 command->direction = dma_dir;
2131 2449
2132 /* 2450 /*
2133 * Set the completion function and data for the command passed 2451 * Set the completion function and data for the command passed
@@ -2140,19 +2458,16 @@ static void mtip_hw_submit_io(struct driver_data *dd, sector_t start,
2140 * To prevent this command from being issued 2458 * To prevent this command from being issued
2141 * if an internal command is in progress or error handling is active. 2459 * if an internal command is in progress or error handling is active.
2142 */ 2460 */
2143 if (unlikely(test_bit(MTIP_FLAG_IC_ACTIVE_BIT, &port->flags) || 2461 if (port->flags & MTIP_PF_PAUSE_IO) {
2144 test_bit(MTIP_FLAG_EH_ACTIVE_BIT, &port->flags))) {
2145 set_bit(tag, port->cmds_to_issue); 2462 set_bit(tag, port->cmds_to_issue);
2146 set_bit(MTIP_FLAG_ISSUE_CMDS_BIT, &port->flags); 2463 set_bit(MTIP_PF_ISSUE_CMDS_BIT, &port->flags);
2147 return; 2464 return;
2148 } 2465 }
2149 2466
2150 /* Issue the command to the hardware */ 2467 /* Issue the command to the hardware */
2151 mtip_issue_ncq_command(port, tag); 2468 mtip_issue_ncq_command(port, tag);
2152 2469
2153 /* Set the command's timeout value.*/ 2470 return;
2154 port->commands[tag].comp_time = jiffies + msecs_to_jiffies(
2155 MTIP_NCQ_COMMAND_TIMEOUT_MS);
2156} 2471}
2157 2472
2158/* 2473/*
@@ -2191,6 +2506,10 @@ static struct scatterlist *mtip_hw_get_scatterlist(struct driver_data *dd,
2191 down(&dd->port->cmd_slot); 2506 down(&dd->port->cmd_slot);
2192 *tag = get_slot(dd->port); 2507 *tag = get_slot(dd->port);
2193 2508
2509 if (unlikely(test_bit(MTIP_DDF_REMOVE_PENDING_BIT, &dd->dd_flag))) {
2510 up(&dd->port->cmd_slot);
2511 return NULL;
2512 }
2194 if (unlikely(*tag < 0)) 2513 if (unlikely(*tag < 0))
2195 return NULL; 2514 return NULL;
2196 2515
@@ -2207,7 +2526,7 @@ static struct scatterlist *mtip_hw_get_scatterlist(struct driver_data *dd,
2207 * return value 2526 * return value
2208 * The size, in bytes, of the data copied into buf. 2527 * The size, in bytes, of the data copied into buf.
2209 */ 2528 */
2210static ssize_t hw_show_registers(struct device *dev, 2529static ssize_t mtip_hw_show_registers(struct device *dev,
2211 struct device_attribute *attr, 2530 struct device_attribute *attr,
2212 char *buf) 2531 char *buf)
2213{ 2532{
@@ -2216,7 +2535,7 @@ static ssize_t hw_show_registers(struct device *dev,
2216 int size = 0; 2535 int size = 0;
2217 int n; 2536 int n;
2218 2537
2219 size += sprintf(&buf[size], "%s:\ns_active:\n", __func__); 2538 size += sprintf(&buf[size], "S ACTive:\n");
2220 2539
2221 for (n = 0; n < dd->slot_groups; n++) 2540 for (n = 0; n < dd->slot_groups; n++)
2222 size += sprintf(&buf[size], "0x%08x\n", 2541 size += sprintf(&buf[size], "0x%08x\n",
@@ -2240,20 +2559,39 @@ static ssize_t hw_show_registers(struct device *dev,
2240 group_allocated); 2559 group_allocated);
2241 } 2560 }
2242 2561
2243 size += sprintf(&buf[size], "completed:\n"); 2562 size += sprintf(&buf[size], "Completed:\n");
2244 2563
2245 for (n = 0; n < dd->slot_groups; n++) 2564 for (n = 0; n < dd->slot_groups; n++)
2246 size += sprintf(&buf[size], "0x%08x\n", 2565 size += sprintf(&buf[size], "0x%08x\n",
2247 readl(dd->port->completed[n])); 2566 readl(dd->port->completed[n]));
2248 2567
2249 size += sprintf(&buf[size], "PORT_IRQ_STAT 0x%08x\n", 2568 size += sprintf(&buf[size], "PORT IRQ STAT : 0x%08x\n",
2250 readl(dd->port->mmio + PORT_IRQ_STAT)); 2569 readl(dd->port->mmio + PORT_IRQ_STAT));
2251 size += sprintf(&buf[size], "HOST_IRQ_STAT 0x%08x\n", 2570 size += sprintf(&buf[size], "HOST IRQ STAT : 0x%08x\n",
2252 readl(dd->mmio + HOST_IRQ_STAT)); 2571 readl(dd->mmio + HOST_IRQ_STAT));
2253 2572
2254 return size; 2573 return size;
2255} 2574}
2256static DEVICE_ATTR(registers, S_IRUGO, hw_show_registers, NULL); 2575
2576static ssize_t mtip_hw_show_status(struct device *dev,
2577 struct device_attribute *attr,
2578 char *buf)
2579{
2580 struct driver_data *dd = dev_to_disk(dev)->private_data;
2581 int size = 0;
2582
2583 if (test_bit(MTIP_DDF_OVER_TEMP_BIT, &dd->dd_flag))
2584 size += sprintf(buf, "%s", "thermal_shutdown\n");
2585 else if (test_bit(MTIP_DDF_WRITE_PROTECT_BIT, &dd->dd_flag))
2586 size += sprintf(buf, "%s", "write_protect\n");
2587 else
2588 size += sprintf(buf, "%s", "online\n");
2589
2590 return size;
2591}
2592
2593static DEVICE_ATTR(registers, S_IRUGO, mtip_hw_show_registers, NULL);
2594static DEVICE_ATTR(status, S_IRUGO, mtip_hw_show_status, NULL);
2257 2595
2258/* 2596/*
2259 * Create the sysfs related attributes. 2597 * Create the sysfs related attributes.
@@ -2272,7 +2610,10 @@ static int mtip_hw_sysfs_init(struct driver_data *dd, struct kobject *kobj)
2272 2610
2273 if (sysfs_create_file(kobj, &dev_attr_registers.attr)) 2611 if (sysfs_create_file(kobj, &dev_attr_registers.attr))
2274 dev_warn(&dd->pdev->dev, 2612 dev_warn(&dd->pdev->dev,
2275 "Error creating registers sysfs entry\n"); 2613 "Error creating 'registers' sysfs entry\n");
2614 if (sysfs_create_file(kobj, &dev_attr_status.attr))
2615 dev_warn(&dd->pdev->dev,
2616 "Error creating 'status' sysfs entry\n");
2276 return 0; 2617 return 0;
2277} 2618}
2278 2619
@@ -2292,6 +2633,7 @@ static int mtip_hw_sysfs_exit(struct driver_data *dd, struct kobject *kobj)
2292 return -EINVAL; 2633 return -EINVAL;
2293 2634
2294 sysfs_remove_file(kobj, &dev_attr_registers.attr); 2635 sysfs_remove_file(kobj, &dev_attr_registers.attr);
2636 sysfs_remove_file(kobj, &dev_attr_status.attr);
2295 2637
2296 return 0; 2638 return 0;
2297} 2639}
@@ -2384,10 +2726,12 @@ static int mtip_ftl_rebuild_poll(struct driver_data *dd)
2384 "FTL rebuild in progress. Polling for completion.\n"); 2726 "FTL rebuild in progress. Polling for completion.\n");
2385 2727
2386 start = jiffies; 2728 start = jiffies;
2387 dd->ftlrebuildflag = 1;
2388 timeout = jiffies + msecs_to_jiffies(MTIP_FTL_REBUILD_TIMEOUT_MS); 2729 timeout = jiffies + msecs_to_jiffies(MTIP_FTL_REBUILD_TIMEOUT_MS);
2389 2730
2390 do { 2731 do {
2732 if (unlikely(test_bit(MTIP_DDF_REMOVE_PENDING_BIT,
2733 &dd->dd_flag)))
2734 return -EFAULT;
2391 if (mtip_check_surprise_removal(dd->pdev)) 2735 if (mtip_check_surprise_removal(dd->pdev))
2392 return -EFAULT; 2736 return -EFAULT;
2393 2737
@@ -2408,22 +2752,17 @@ static int mtip_ftl_rebuild_poll(struct driver_data *dd)
2408 dev_warn(&dd->pdev->dev, 2752 dev_warn(&dd->pdev->dev,
2409 "FTL rebuild complete (%d secs).\n", 2753 "FTL rebuild complete (%d secs).\n",
2410 jiffies_to_msecs(jiffies - start) / 1000); 2754 jiffies_to_msecs(jiffies - start) / 1000);
2411 dd->ftlrebuildflag = 0;
2412 mtip_block_initialize(dd); 2755 mtip_block_initialize(dd);
2413 break; 2756 return 0;
2414 } 2757 }
2415 ssleep(10); 2758 ssleep(10);
2416 } while (time_before(jiffies, timeout)); 2759 } while (time_before(jiffies, timeout));
2417 2760
2418 /* Check for timeout */ 2761 /* Check for timeout */
2419 if (dd->ftlrebuildflag) { 2762 dev_err(&dd->pdev->dev,
2420 dev_err(&dd->pdev->dev,
2421 "Timed out waiting for FTL rebuild to complete (%d secs).\n", 2763 "Timed out waiting for FTL rebuild to complete (%d secs).\n",
2422 jiffies_to_msecs(jiffies - start) / 1000); 2764 jiffies_to_msecs(jiffies - start) / 1000);
2423 return -EFAULT; 2765 return -EFAULT;
2424 }
2425
2426 return 0;
2427} 2766}
2428 2767
2429/* 2768/*
@@ -2448,14 +2787,17 @@ static int mtip_service_thread(void *data)
2448 * is in progress nor error handling is active 2787 * is in progress nor error handling is active
2449 */ 2788 */
2450 wait_event_interruptible(port->svc_wait, (port->flags) && 2789 wait_event_interruptible(port->svc_wait, (port->flags) &&
2451 !test_bit(MTIP_FLAG_IC_ACTIVE_BIT, &port->flags) && 2790 !(port->flags & MTIP_PF_PAUSE_IO));
2452 !test_bit(MTIP_FLAG_EH_ACTIVE_BIT, &port->flags));
2453 2791
2454 if (kthread_should_stop()) 2792 if (kthread_should_stop())
2455 break; 2793 break;
2456 2794
2457 set_bit(MTIP_FLAG_SVC_THD_ACTIVE_BIT, &port->flags); 2795 if (unlikely(test_bit(MTIP_DDF_REMOVE_PENDING_BIT,
2458 if (test_bit(MTIP_FLAG_ISSUE_CMDS_BIT, &port->flags)) { 2796 &dd->dd_flag)))
2797 break;
2798
2799 set_bit(MTIP_PF_SVC_THD_ACTIVE_BIT, &port->flags);
2800 if (test_bit(MTIP_PF_ISSUE_CMDS_BIT, &port->flags)) {
2459 slot = 1; 2801 slot = 1;
2460 /* used to restrict the loop to one iteration */ 2802 /* used to restrict the loop to one iteration */
2461 slot_start = num_cmd_slots; 2803 slot_start = num_cmd_slots;
@@ -2480,21 +2822,19 @@ static int mtip_service_thread(void *data)
2480 /* Issue the command to the hardware */ 2822 /* Issue the command to the hardware */
2481 mtip_issue_ncq_command(port, slot); 2823 mtip_issue_ncq_command(port, slot);
2482 2824
2483 /* Set the command's timeout value.*/
2484 port->commands[slot].comp_time = jiffies +
2485 msecs_to_jiffies(MTIP_NCQ_COMMAND_TIMEOUT_MS);
2486
2487 clear_bit(slot, port->cmds_to_issue); 2825 clear_bit(slot, port->cmds_to_issue);
2488 } 2826 }
2489 2827
2490 clear_bit(MTIP_FLAG_ISSUE_CMDS_BIT, &port->flags); 2828 clear_bit(MTIP_PF_ISSUE_CMDS_BIT, &port->flags);
2491 } else if (test_bit(MTIP_FLAG_REBUILD_BIT, &port->flags)) { 2829 } else if (test_bit(MTIP_PF_REBUILD_BIT, &port->flags)) {
2492 mtip_ftl_rebuild_poll(dd); 2830 if (!mtip_ftl_rebuild_poll(dd))
2493 clear_bit(MTIP_FLAG_REBUILD_BIT, &port->flags); 2831 set_bit(MTIP_DDF_REBUILD_FAILED_BIT,
2832 &dd->dd_flag);
2833 clear_bit(MTIP_PF_REBUILD_BIT, &port->flags);
2494 } 2834 }
2495 clear_bit(MTIP_FLAG_SVC_THD_ACTIVE_BIT, &port->flags); 2835 clear_bit(MTIP_PF_SVC_THD_ACTIVE_BIT, &port->flags);
2496 2836
2497 if (test_bit(MTIP_FLAG_SVC_THD_SHOULD_STOP_BIT, &port->flags)) 2837 if (test_bit(MTIP_PF_SVC_THD_STOP_BIT, &port->flags))
2498 break; 2838 break;
2499 } 2839 }
2500 return 0; 2840 return 0;
@@ -2513,6 +2853,9 @@ static int mtip_hw_init(struct driver_data *dd)
2513 int i; 2853 int i;
2514 int rv; 2854 int rv;
2515 unsigned int num_command_slots; 2855 unsigned int num_command_slots;
2856 unsigned long timeout, timetaken;
2857 unsigned char *buf;
2858 struct smart_attr attr242;
2516 2859
2517 dd->mmio = pcim_iomap_table(dd->pdev)[MTIP_ABAR]; 2860 dd->mmio = pcim_iomap_table(dd->pdev)[MTIP_ABAR];
2518 2861
@@ -2547,7 +2890,7 @@ static int mtip_hw_init(struct driver_data *dd)
2547 /* Allocate memory for the command list. */ 2890 /* Allocate memory for the command list. */
2548 dd->port->command_list = 2891 dd->port->command_list =
2549 dmam_alloc_coherent(&dd->pdev->dev, 2892 dmam_alloc_coherent(&dd->pdev->dev,
2550 HW_PORT_PRIV_DMA_SZ + (ATA_SECT_SIZE * 2), 2893 HW_PORT_PRIV_DMA_SZ + (ATA_SECT_SIZE * 4),
2551 &dd->port->command_list_dma, 2894 &dd->port->command_list_dma,
2552 GFP_KERNEL); 2895 GFP_KERNEL);
2553 if (!dd->port->command_list) { 2896 if (!dd->port->command_list) {
@@ -2560,7 +2903,7 @@ static int mtip_hw_init(struct driver_data *dd)
2560 /* Clear the memory we have allocated. */ 2903 /* Clear the memory we have allocated. */
2561 memset(dd->port->command_list, 2904 memset(dd->port->command_list,
2562 0, 2905 0,
2563 HW_PORT_PRIV_DMA_SZ + (ATA_SECT_SIZE * 2)); 2906 HW_PORT_PRIV_DMA_SZ + (ATA_SECT_SIZE * 4));
2564 2907
2565 /* Setup the addresse of the RX FIS. */ 2908 /* Setup the addresse of the RX FIS. */
2566 dd->port->rxfis = dd->port->command_list + HW_CMD_SLOT_SZ; 2909 dd->port->rxfis = dd->port->command_list + HW_CMD_SLOT_SZ;
@@ -2576,10 +2919,19 @@ static int mtip_hw_init(struct driver_data *dd)
2576 dd->port->identify_dma = dd->port->command_tbl_dma + 2919 dd->port->identify_dma = dd->port->command_tbl_dma +
2577 HW_CMD_TBL_AR_SZ; 2920 HW_CMD_TBL_AR_SZ;
2578 2921
2579 /* Setup the address of the sector buffer. */ 2922 /* Setup the address of the sector buffer - for some non-ncq cmds */
2580 dd->port->sector_buffer = (void *) dd->port->identify + ATA_SECT_SIZE; 2923 dd->port->sector_buffer = (void *) dd->port->identify + ATA_SECT_SIZE;
2581 dd->port->sector_buffer_dma = dd->port->identify_dma + ATA_SECT_SIZE; 2924 dd->port->sector_buffer_dma = dd->port->identify_dma + ATA_SECT_SIZE;
2582 2925
2926 /* Setup the address of the log buf - for read log command */
2927 dd->port->log_buf = (void *)dd->port->sector_buffer + ATA_SECT_SIZE;
2928 dd->port->log_buf_dma = dd->port->sector_buffer_dma + ATA_SECT_SIZE;
2929
2930 /* Setup the address of the smart buf - for smart read data command */
2931 dd->port->smart_buf = (void *)dd->port->log_buf + ATA_SECT_SIZE;
2932 dd->port->smart_buf_dma = dd->port->log_buf_dma + ATA_SECT_SIZE;
2933
2934
2583 /* Point the command headers at the command tables. */ 2935 /* Point the command headers at the command tables. */
2584 for (i = 0; i < num_command_slots; i++) { 2936 for (i = 0; i < num_command_slots; i++) {
2585 dd->port->commands[i].command_header = 2937 dd->port->commands[i].command_header =
@@ -2623,14 +2975,43 @@ static int mtip_hw_init(struct driver_data *dd)
2623 dd->port->mmio + i*0x80 + PORT_SDBV; 2975 dd->port->mmio + i*0x80 + PORT_SDBV;
2624 } 2976 }
2625 2977
2626 /* Reset the HBA. */ 2978 timetaken = jiffies;
2627 if (mtip_hba_reset(dd) < 0) { 2979 timeout = jiffies + msecs_to_jiffies(30000);
2628 dev_err(&dd->pdev->dev, 2980 while (((readl(dd->port->mmio + PORT_SCR_STAT) & 0x0F) != 0x03) &&
2629 "Card did not reset within timeout\n"); 2981 time_before(jiffies, timeout)) {
2630 rv = -EIO; 2982 mdelay(100);
2983 }
2984 if (unlikely(mtip_check_surprise_removal(dd->pdev))) {
2985 timetaken = jiffies - timetaken;
2986 dev_warn(&dd->pdev->dev,
2987 "Surprise removal detected at %u ms\n",
2988 jiffies_to_msecs(timetaken));
2989 rv = -ENODEV;
2990 goto out2 ;
2991 }
2992 if (unlikely(test_bit(MTIP_DDF_REMOVE_PENDING_BIT, &dd->dd_flag))) {
2993 timetaken = jiffies - timetaken;
2994 dev_warn(&dd->pdev->dev,
2995 "Removal detected at %u ms\n",
2996 jiffies_to_msecs(timetaken));
2997 rv = -EFAULT;
2631 goto out2; 2998 goto out2;
2632 } 2999 }
2633 3000
3001 /* Conditionally reset the HBA. */
3002 if (!(readl(dd->mmio + HOST_CAP) & HOST_CAP_NZDMA)) {
3003 if (mtip_hba_reset(dd) < 0) {
3004 dev_err(&dd->pdev->dev,
3005 "Card did not reset within timeout\n");
3006 rv = -EIO;
3007 goto out2;
3008 }
3009 } else {
3010 /* Clear any pending interrupts on the HBA */
3011 writel(readl(dd->mmio + HOST_IRQ_STAT),
3012 dd->mmio + HOST_IRQ_STAT);
3013 }
3014
2634 mtip_init_port(dd->port); 3015 mtip_init_port(dd->port);
2635 mtip_start_port(dd->port); 3016 mtip_start_port(dd->port);
2636 3017
@@ -2660,6 +3041,12 @@ static int mtip_hw_init(struct driver_data *dd)
2660 mod_timer(&dd->port->cmd_timer, 3041 mod_timer(&dd->port->cmd_timer,
2661 jiffies + msecs_to_jiffies(MTIP_TIMEOUT_CHECK_PERIOD)); 3042 jiffies + msecs_to_jiffies(MTIP_TIMEOUT_CHECK_PERIOD));
2662 3043
3044
3045 if (test_bit(MTIP_DDF_REMOVE_PENDING_BIT, &dd->dd_flag)) {
3046 rv = -EFAULT;
3047 goto out3;
3048 }
3049
2663 if (mtip_get_identify(dd->port, NULL) < 0) { 3050 if (mtip_get_identify(dd->port, NULL) < 0) {
2664 rv = -EFAULT; 3051 rv = -EFAULT;
2665 goto out3; 3052 goto out3;
@@ -2667,10 +3054,47 @@ static int mtip_hw_init(struct driver_data *dd)
2667 3054
2668 if (*(dd->port->identify + MTIP_FTL_REBUILD_OFFSET) == 3055 if (*(dd->port->identify + MTIP_FTL_REBUILD_OFFSET) ==
2669 MTIP_FTL_REBUILD_MAGIC) { 3056 MTIP_FTL_REBUILD_MAGIC) {
2670 set_bit(MTIP_FLAG_REBUILD_BIT, &dd->port->flags); 3057 set_bit(MTIP_PF_REBUILD_BIT, &dd->port->flags);
2671 return MTIP_FTL_REBUILD_MAGIC; 3058 return MTIP_FTL_REBUILD_MAGIC;
2672 } 3059 }
2673 mtip_dump_identify(dd->port); 3060 mtip_dump_identify(dd->port);
3061
3062 /* check write protect, over temp and rebuild statuses */
3063 rv = mtip_read_log_page(dd->port, ATA_LOG_SATA_NCQ,
3064 dd->port->log_buf,
3065 dd->port->log_buf_dma, 1);
3066 if (rv) {
3067 dev_warn(&dd->pdev->dev,
3068 "Error in READ LOG EXT (10h) command\n");
3069 /* non-critical error, don't fail the load */
3070 } else {
3071 buf = (unsigned char *)dd->port->log_buf;
3072 if (buf[259] & 0x1) {
3073 dev_info(&dd->pdev->dev,
3074 "Write protect bit is set.\n");
3075 set_bit(MTIP_DDF_WRITE_PROTECT_BIT, &dd->dd_flag);
3076 }
3077 if (buf[288] == 0xF7) {
3078 dev_info(&dd->pdev->dev,
3079 "Exceeded Tmax, drive in thermal shutdown.\n");
3080 set_bit(MTIP_DDF_OVER_TEMP_BIT, &dd->dd_flag);
3081 }
3082 if (buf[288] == 0xBF) {
3083 dev_info(&dd->pdev->dev,
3084 "Drive indicates rebuild has failed.\n");
3085 /* TODO */
3086 }
3087 }
3088
3089 /* get write protect progess */
3090 memset(&attr242, 0, sizeof(struct smart_attr));
3091 if (mtip_get_smart_attr(dd->port, 242, &attr242))
3092 dev_warn(&dd->pdev->dev,
3093 "Unable to check write protect progress\n");
3094 else
3095 dev_info(&dd->pdev->dev,
3096 "Write protect progress: %d%% (%d blocks)\n",
3097 attr242.cur, attr242.data);
2674 return rv; 3098 return rv;
2675 3099
2676out3: 3100out3:
@@ -2688,7 +3112,7 @@ out2:
2688 3112
2689 /* Free the command/command header memory. */ 3113 /* Free the command/command header memory. */
2690 dmam_free_coherent(&dd->pdev->dev, 3114 dmam_free_coherent(&dd->pdev->dev,
2691 HW_PORT_PRIV_DMA_SZ + (ATA_SECT_SIZE * 2), 3115 HW_PORT_PRIV_DMA_SZ + (ATA_SECT_SIZE * 4),
2692 dd->port->command_list, 3116 dd->port->command_list,
2693 dd->port->command_list_dma); 3117 dd->port->command_list_dma);
2694out1: 3118out1:
@@ -2712,9 +3136,12 @@ static int mtip_hw_exit(struct driver_data *dd)
2712 * Send standby immediate (E0h) to the drive so that it 3136 * Send standby immediate (E0h) to the drive so that it
2713 * saves its state. 3137 * saves its state.
2714 */ 3138 */
2715 if (atomic_read(&dd->drv_cleanup_done) != true) { 3139 if (!test_bit(MTIP_DDF_CLEANUP_BIT, &dd->dd_flag)) {
2716 3140
2717 mtip_standby_immediate(dd->port); 3141 if (!test_bit(MTIP_PF_REBUILD_BIT, &dd->port->flags))
3142 if (mtip_standby_immediate(dd->port))
3143 dev_warn(&dd->pdev->dev,
3144 "STANDBY IMMEDIATE failed\n");
2718 3145
2719 /* de-initialize the port. */ 3146 /* de-initialize the port. */
2720 mtip_deinit_port(dd->port); 3147 mtip_deinit_port(dd->port);
@@ -2734,7 +3161,7 @@ static int mtip_hw_exit(struct driver_data *dd)
2734 3161
2735 /* Free the command/command header memory. */ 3162 /* Free the command/command header memory. */
2736 dmam_free_coherent(&dd->pdev->dev, 3163 dmam_free_coherent(&dd->pdev->dev,
2737 HW_PORT_PRIV_DMA_SZ + (ATA_SECT_SIZE * 2), 3164 HW_PORT_PRIV_DMA_SZ + (ATA_SECT_SIZE * 4),
2738 dd->port->command_list, 3165 dd->port->command_list,
2739 dd->port->command_list_dma); 3166 dd->port->command_list_dma);
2740 /* Free the memory allocated for the for structure. */ 3167 /* Free the memory allocated for the for structure. */
@@ -2892,6 +3319,9 @@ static int mtip_block_ioctl(struct block_device *dev,
2892 if (!dd) 3319 if (!dd)
2893 return -ENOTTY; 3320 return -ENOTTY;
2894 3321
3322 if (unlikely(test_bit(MTIP_DDF_REMOVE_PENDING_BIT, &dd->dd_flag)))
3323 return -ENOTTY;
3324
2895 switch (cmd) { 3325 switch (cmd) {
2896 case BLKFLSBUF: 3326 case BLKFLSBUF:
2897 return -ENOTTY; 3327 return -ENOTTY;
@@ -2927,6 +3357,9 @@ static int mtip_block_compat_ioctl(struct block_device *dev,
2927 if (!dd) 3357 if (!dd)
2928 return -ENOTTY; 3358 return -ENOTTY;
2929 3359
3360 if (unlikely(test_bit(MTIP_DDF_REMOVE_PENDING_BIT, &dd->dd_flag)))
3361 return -ENOTTY;
3362
2930 switch (cmd) { 3363 switch (cmd) {
2931 case BLKFLSBUF: 3364 case BLKFLSBUF:
2932 return -ENOTTY; 3365 return -ENOTTY;
@@ -3049,6 +3482,24 @@ static void mtip_make_request(struct request_queue *queue, struct bio *bio)
3049 int nents = 0; 3482 int nents = 0;
3050 int tag = 0; 3483 int tag = 0;
3051 3484
3485 if (unlikely(dd->dd_flag & MTIP_DDF_STOP_IO)) {
3486 if (unlikely(test_bit(MTIP_DDF_REMOVE_PENDING_BIT,
3487 &dd->dd_flag))) {
3488 bio_endio(bio, -ENXIO);
3489 return;
3490 }
3491 if (unlikely(test_bit(MTIP_DDF_OVER_TEMP_BIT, &dd->dd_flag))) {
3492 bio_endio(bio, -ENODATA);
3493 return;
3494 }
3495 if (unlikely(test_bit(MTIP_DDF_WRITE_PROTECT_BIT,
3496 &dd->dd_flag) &&
3497 bio_data_dir(bio))) {
3498 bio_endio(bio, -ENODATA);
3499 return;
3500 }
3501 }
3502
3052 if (unlikely(!bio_has_data(bio))) { 3503 if (unlikely(!bio_has_data(bio))) {
3053 blk_queue_flush(queue, 0); 3504 blk_queue_flush(queue, 0);
3054 bio_endio(bio, 0); 3505 bio_endio(bio, 0);
@@ -3061,7 +3512,7 @@ static void mtip_make_request(struct request_queue *queue, struct bio *bio)
3061 3512
3062 if (unlikely((bio)->bi_vcnt > MTIP_MAX_SG)) { 3513 if (unlikely((bio)->bi_vcnt > MTIP_MAX_SG)) {
3063 dev_warn(&dd->pdev->dev, 3514 dev_warn(&dd->pdev->dev,
3064 "Maximum number of SGL entries exceeded"); 3515 "Maximum number of SGL entries exceeded\n");
3065 bio_io_error(bio); 3516 bio_io_error(bio);
3066 mtip_hw_release_scatterlist(dd, tag); 3517 mtip_hw_release_scatterlist(dd, tag);
3067 return; 3518 return;
@@ -3210,8 +3661,10 @@ skip_create_disk:
3210 kobject_put(kobj); 3661 kobject_put(kobj);
3211 } 3662 }
3212 3663
3213 if (dd->mtip_svc_handler) 3664 if (dd->mtip_svc_handler) {
3665 set_bit(MTIP_DDF_INIT_DONE_BIT, &dd->dd_flag);
3214 return rv; /* service thread created for handling rebuild */ 3666 return rv; /* service thread created for handling rebuild */
3667 }
3215 3668
3216start_service_thread: 3669start_service_thread:
3217 sprintf(thd_name, "mtip_svc_thd_%02d", index); 3670 sprintf(thd_name, "mtip_svc_thd_%02d", index);
@@ -3220,12 +3673,15 @@ start_service_thread:
3220 dd, thd_name); 3673 dd, thd_name);
3221 3674
3222 if (IS_ERR(dd->mtip_svc_handler)) { 3675 if (IS_ERR(dd->mtip_svc_handler)) {
3223 printk(KERN_ERR "mtip32xx: service thread failed to start\n"); 3676 dev_err(&dd->pdev->dev, "service thread failed to start\n");
3224 dd->mtip_svc_handler = NULL; 3677 dd->mtip_svc_handler = NULL;
3225 rv = -EFAULT; 3678 rv = -EFAULT;
3226 goto kthread_run_error; 3679 goto kthread_run_error;
3227 } 3680 }
3228 3681
3682 if (wait_for_rebuild == MTIP_FTL_REBUILD_MAGIC)
3683 rv = wait_for_rebuild;
3684
3229 return rv; 3685 return rv;
3230 3686
3231kthread_run_error: 3687kthread_run_error:
@@ -3266,16 +3722,18 @@ static int mtip_block_remove(struct driver_data *dd)
3266 struct kobject *kobj; 3722 struct kobject *kobj;
3267 3723
3268 if (dd->mtip_svc_handler) { 3724 if (dd->mtip_svc_handler) {
3269 set_bit(MTIP_FLAG_SVC_THD_SHOULD_STOP_BIT, &dd->port->flags); 3725 set_bit(MTIP_PF_SVC_THD_STOP_BIT, &dd->port->flags);
3270 wake_up_interruptible(&dd->port->svc_wait); 3726 wake_up_interruptible(&dd->port->svc_wait);
3271 kthread_stop(dd->mtip_svc_handler); 3727 kthread_stop(dd->mtip_svc_handler);
3272 } 3728 }
3273 3729
3274 /* Clean up the sysfs attributes managed by the protocol layer. */ 3730 /* Clean up the sysfs attributes, if created */
3275 kobj = kobject_get(&disk_to_dev(dd->disk)->kobj); 3731 if (test_bit(MTIP_DDF_INIT_DONE_BIT, &dd->dd_flag)) {
3276 if (kobj) { 3732 kobj = kobject_get(&disk_to_dev(dd->disk)->kobj);
3277 mtip_hw_sysfs_exit(dd, kobj); 3733 if (kobj) {
3278 kobject_put(kobj); 3734 mtip_hw_sysfs_exit(dd, kobj);
3735 kobject_put(kobj);
3736 }
3279 } 3737 }
3280 3738
3281 /* 3739 /*
@@ -3283,6 +3741,11 @@ static int mtip_block_remove(struct driver_data *dd)
3283 * from /dev 3741 * from /dev
3284 */ 3742 */
3285 del_gendisk(dd->disk); 3743 del_gendisk(dd->disk);
3744
3745 spin_lock(&rssd_index_lock);
3746 ida_remove(&rssd_index_ida, dd->index);
3747 spin_unlock(&rssd_index_lock);
3748
3286 blk_cleanup_queue(dd->queue); 3749 blk_cleanup_queue(dd->queue);
3287 dd->disk = NULL; 3750 dd->disk = NULL;
3288 dd->queue = NULL; 3751 dd->queue = NULL;
@@ -3312,6 +3775,11 @@ static int mtip_block_shutdown(struct driver_data *dd)
3312 3775
3313 /* Delete our gendisk structure, and cleanup the blk queue. */ 3776 /* Delete our gendisk structure, and cleanup the blk queue. */
3314 del_gendisk(dd->disk); 3777 del_gendisk(dd->disk);
3778
3779 spin_lock(&rssd_index_lock);
3780 ida_remove(&rssd_index_ida, dd->index);
3781 spin_unlock(&rssd_index_lock);
3782
3315 blk_cleanup_queue(dd->queue); 3783 blk_cleanup_queue(dd->queue);
3316 dd->disk = NULL; 3784 dd->disk = NULL;
3317 dd->queue = NULL; 3785 dd->queue = NULL;
@@ -3359,11 +3827,6 @@ static int mtip_pci_probe(struct pci_dev *pdev,
3359 return -ENOMEM; 3827 return -ENOMEM;
3360 } 3828 }
3361 3829
3362 /* Set the atomic variable as 1 in case of SRSI */
3363 atomic_set(&dd->drv_cleanup_done, true);
3364
3365 atomic_set(&dd->resumeflag, false);
3366
3367 /* Attach the private data to this PCI device. */ 3830 /* Attach the private data to this PCI device. */
3368 pci_set_drvdata(pdev, dd); 3831 pci_set_drvdata(pdev, dd);
3369 3832
@@ -3420,7 +3883,8 @@ static int mtip_pci_probe(struct pci_dev *pdev,
3420 * instance number. 3883 * instance number.
3421 */ 3884 */
3422 instance++; 3885 instance++;
3423 3886 if (rv != MTIP_FTL_REBUILD_MAGIC)
3887 set_bit(MTIP_DDF_INIT_DONE_BIT, &dd->dd_flag);
3424 goto done; 3888 goto done;
3425 3889
3426block_initialize_err: 3890block_initialize_err:
@@ -3434,9 +3898,6 @@ iomap_err:
3434 pci_set_drvdata(pdev, NULL); 3898 pci_set_drvdata(pdev, NULL);
3435 return rv; 3899 return rv;
3436done: 3900done:
3437 /* Set the atomic variable as 0 in case of SRSI */
3438 atomic_set(&dd->drv_cleanup_done, true);
3439
3440 return rv; 3901 return rv;
3441} 3902}
3442 3903
@@ -3452,8 +3913,10 @@ static void mtip_pci_remove(struct pci_dev *pdev)
3452 struct driver_data *dd = pci_get_drvdata(pdev); 3913 struct driver_data *dd = pci_get_drvdata(pdev);
3453 int counter = 0; 3914 int counter = 0;
3454 3915
3916 set_bit(MTIP_DDF_REMOVE_PENDING_BIT, &dd->dd_flag);
3917
3455 if (mtip_check_surprise_removal(pdev)) { 3918 if (mtip_check_surprise_removal(pdev)) {
3456 while (atomic_read(&dd->drv_cleanup_done) == false) { 3919 while (!test_bit(MTIP_DDF_CLEANUP_BIT, &dd->dd_flag)) {
3457 counter++; 3920 counter++;
3458 msleep(20); 3921 msleep(20);
3459 if (counter == 10) { 3922 if (counter == 10) {
@@ -3463,8 +3926,6 @@ static void mtip_pci_remove(struct pci_dev *pdev)
3463 } 3926 }
3464 } 3927 }
3465 } 3928 }
3466 /* Set the atomic variable as 1 in case of SRSI */
3467 atomic_set(&dd->drv_cleanup_done, true);
3468 3929
3469 /* Clean up the block layer. */ 3930 /* Clean up the block layer. */
3470 mtip_block_remove(dd); 3931 mtip_block_remove(dd);
@@ -3493,7 +3954,7 @@ static int mtip_pci_suspend(struct pci_dev *pdev, pm_message_t mesg)
3493 return -EFAULT; 3954 return -EFAULT;
3494 } 3955 }
3495 3956
3496 atomic_set(&dd->resumeflag, true); 3957 set_bit(MTIP_DDF_RESUME_BIT, &dd->dd_flag);
3497 3958
3498 /* Disable ports & interrupts then send standby immediate */ 3959 /* Disable ports & interrupts then send standby immediate */
3499 rv = mtip_block_suspend(dd); 3960 rv = mtip_block_suspend(dd);
@@ -3559,7 +4020,7 @@ static int mtip_pci_resume(struct pci_dev *pdev)
3559 dev_err(&pdev->dev, "Unable to resume\n"); 4020 dev_err(&pdev->dev, "Unable to resume\n");
3560 4021
3561err: 4022err:
3562 atomic_set(&dd->resumeflag, false); 4023 clear_bit(MTIP_DDF_RESUME_BIT, &dd->dd_flag);
3563 4024
3564 return rv; 4025 return rv;
3565} 4026}
@@ -3608,18 +4069,25 @@ MODULE_DEVICE_TABLE(pci, mtip_pci_tbl);
3608 */ 4069 */
3609static int __init mtip_init(void) 4070static int __init mtip_init(void)
3610{ 4071{
4072 int error;
4073
3611 printk(KERN_INFO MTIP_DRV_NAME " Version " MTIP_DRV_VERSION "\n"); 4074 printk(KERN_INFO MTIP_DRV_NAME " Version " MTIP_DRV_VERSION "\n");
3612 4075
3613 /* Allocate a major block device number to use with this driver. */ 4076 /* Allocate a major block device number to use with this driver. */
3614 mtip_major = register_blkdev(0, MTIP_DRV_NAME); 4077 error = register_blkdev(0, MTIP_DRV_NAME);
3615 if (mtip_major < 0) { 4078 if (error <= 0) {
3616 printk(KERN_ERR "Unable to register block device (%d)\n", 4079 printk(KERN_ERR "Unable to register block device (%d)\n",
3617 mtip_major); 4080 error);
3618 return -EBUSY; 4081 return -EBUSY;
3619 } 4082 }
4083 mtip_major = error;
3620 4084
3621 /* Register our PCI operations. */ 4085 /* Register our PCI operations. */
3622 return pci_register_driver(&mtip_pci_driver); 4086 error = pci_register_driver(&mtip_pci_driver);
4087 if (error)
4088 unregister_blkdev(mtip_major, MTIP_DRV_NAME);
4089
4090 return error;
3623} 4091}
3624 4092
3625/* 4093/*
diff --git a/drivers/block/mtip32xx/mtip32xx.h b/drivers/block/mtip32xx/mtip32xx.h
index e0554a8f2233..4ef58336310a 100644
--- a/drivers/block/mtip32xx/mtip32xx.h
+++ b/drivers/block/mtip32xx/mtip32xx.h
@@ -34,8 +34,8 @@
34/* offset of Device Control register in PCIe extended capabilites space */ 34/* offset of Device Control register in PCIe extended capabilites space */
35#define PCIE_CONFIG_EXT_DEVICE_CONTROL_OFFSET 0x48 35#define PCIE_CONFIG_EXT_DEVICE_CONTROL_OFFSET 0x48
36 36
37/* # of times to retry timed out IOs */ 37/* # of times to retry timed out/failed IOs */
38#define MTIP_MAX_RETRIES 5 38#define MTIP_MAX_RETRIES 2
39 39
40/* Various timeout values in ms */ 40/* Various timeout values in ms */
41#define MTIP_NCQ_COMMAND_TIMEOUT_MS 5000 41#define MTIP_NCQ_COMMAND_TIMEOUT_MS 5000
@@ -114,12 +114,41 @@
114#define __force_bit2int (unsigned int __force) 114#define __force_bit2int (unsigned int __force)
115 115
116/* below are bit numbers in 'flags' defined in mtip_port */ 116/* below are bit numbers in 'flags' defined in mtip_port */
117#define MTIP_FLAG_IC_ACTIVE_BIT 0 117#define MTIP_PF_IC_ACTIVE_BIT 0 /* pio/ioctl */
118#define MTIP_FLAG_EH_ACTIVE_BIT 1 118#define MTIP_PF_EH_ACTIVE_BIT 1 /* error handling */
119#define MTIP_FLAG_SVC_THD_ACTIVE_BIT 2 119#define MTIP_PF_SE_ACTIVE_BIT 2 /* secure erase */
120#define MTIP_FLAG_ISSUE_CMDS_BIT 4 120#define MTIP_PF_DM_ACTIVE_BIT 3 /* download microcde */
121#define MTIP_FLAG_REBUILD_BIT 5 121#define MTIP_PF_PAUSE_IO ((1 << MTIP_PF_IC_ACTIVE_BIT) | \
122#define MTIP_FLAG_SVC_THD_SHOULD_STOP_BIT 8 122 (1 << MTIP_PF_EH_ACTIVE_BIT) | \
123 (1 << MTIP_PF_SE_ACTIVE_BIT) | \
124 (1 << MTIP_PF_DM_ACTIVE_BIT))
125
126#define MTIP_PF_SVC_THD_ACTIVE_BIT 4
127#define MTIP_PF_ISSUE_CMDS_BIT 5
128#define MTIP_PF_REBUILD_BIT 6
129#define MTIP_PF_SVC_THD_STOP_BIT 8
130
131/* below are bit numbers in 'dd_flag' defined in driver_data */
132#define MTIP_DDF_REMOVE_PENDING_BIT 1
133#define MTIP_DDF_OVER_TEMP_BIT 2
134#define MTIP_DDF_WRITE_PROTECT_BIT 3
135#define MTIP_DDF_STOP_IO ((1 << MTIP_DDF_REMOVE_PENDING_BIT) | \
136 (1 << MTIP_DDF_OVER_TEMP_BIT) | \
137 (1 << MTIP_DDF_WRITE_PROTECT_BIT))
138
139#define MTIP_DDF_CLEANUP_BIT 5
140#define MTIP_DDF_RESUME_BIT 6
141#define MTIP_DDF_INIT_DONE_BIT 7
142#define MTIP_DDF_REBUILD_FAILED_BIT 8
143
144__packed struct smart_attr{
145 u8 attr_id;
146 u16 flags;
147 u8 cur;
148 u8 worst;
149 u32 data;
150 u8 res[3];
151};
123 152
124/* Register Frame Information Structure (FIS), host to device. */ 153/* Register Frame Information Structure (FIS), host to device. */
125struct host_to_dev_fis { 154struct host_to_dev_fis {
@@ -345,6 +374,12 @@ struct mtip_port {
345 * when the command slot and all associated data structures 374 * when the command slot and all associated data structures
346 * are no longer needed. 375 * are no longer needed.
347 */ 376 */
377 u16 *log_buf;
378 dma_addr_t log_buf_dma;
379
380 u8 *smart_buf;
381 dma_addr_t smart_buf_dma;
382
348 unsigned long allocated[SLOTBITS_IN_LONGS]; 383 unsigned long allocated[SLOTBITS_IN_LONGS];
349 /* 384 /*
350 * used to queue commands when an internal command is in progress 385 * used to queue commands when an internal command is in progress
@@ -368,6 +403,7 @@ struct mtip_port {
368 * Timer used to complete commands that have been active for too long. 403 * Timer used to complete commands that have been active for too long.
369 */ 404 */
370 struct timer_list cmd_timer; 405 struct timer_list cmd_timer;
406 unsigned long ic_pause_timer;
371 /* 407 /*
372 * Semaphore used to block threads if there are no 408 * Semaphore used to block threads if there are no
373 * command slots available. 409 * command slots available.
@@ -404,13 +440,9 @@ struct driver_data {
404 440
405 unsigned slot_groups; /* number of slot groups the product supports */ 441 unsigned slot_groups; /* number of slot groups the product supports */
406 442
407 atomic_t drv_cleanup_done; /* Atomic variable for SRSI */
408
409 unsigned long index; /* Index to determine the disk name */ 443 unsigned long index; /* Index to determine the disk name */
410 444
411 unsigned int ftlrebuildflag; /* FTL rebuild flag */ 445 unsigned long dd_flag; /* NOTE: use atomic bit operations on this */
412
413 atomic_t resumeflag; /* Atomic variable to track suspend/resume */
414 446
415 struct task_struct *mtip_svc_handler; /* task_struct of svc thd */ 447 struct task_struct *mtip_svc_handler; /* task_struct of svc thd */
416}; 448};
diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index c4a60badf252..0d39f2f4294a 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -351,6 +351,7 @@ static void virtblk_config_changed_work(struct work_struct *work)
351 cap_str_10, cap_str_2); 351 cap_str_10, cap_str_2);
352 352
353 set_capacity(vblk->disk, capacity); 353 set_capacity(vblk->disk, capacity);
354 revalidate_disk(vblk->disk);
354done: 355done:
355 mutex_unlock(&vblk->config_lock); 356 mutex_unlock(&vblk->config_lock);
356} 357}
@@ -374,6 +375,34 @@ static int init_vq(struct virtio_blk *vblk)
374 return err; 375 return err;
375} 376}
376 377
378/*
379 * Legacy naming scheme used for virtio devices. We are stuck with it for
380 * virtio blk but don't ever use it for any new driver.
381 */
382static int virtblk_name_format(char *prefix, int index, char *buf, int buflen)
383{
384 const int base = 'z' - 'a' + 1;
385 char *begin = buf + strlen(prefix);
386 char *end = buf + buflen;
387 char *p;
388 int unit;
389
390 p = end - 1;
391 *p = '\0';
392 unit = base;
393 do {
394 if (p == begin)
395 return -EINVAL;
396 *--p = 'a' + (index % unit);
397 index = (index / unit) - 1;
398 } while (index >= 0);
399
400 memmove(begin, p, end - p);
401 memcpy(buf, prefix, strlen(prefix));
402
403 return 0;
404}
405
377static int __devinit virtblk_probe(struct virtio_device *vdev) 406static int __devinit virtblk_probe(struct virtio_device *vdev)
378{ 407{
379 struct virtio_blk *vblk; 408 struct virtio_blk *vblk;
@@ -442,18 +471,7 @@ static int __devinit virtblk_probe(struct virtio_device *vdev)
442 471
443 q->queuedata = vblk; 472 q->queuedata = vblk;
444 473
445 if (index < 26) { 474 virtblk_name_format("vd", index, vblk->disk->disk_name, DISK_NAME_LEN);
446 sprintf(vblk->disk->disk_name, "vd%c", 'a' + index % 26);
447 } else if (index < (26 + 1) * 26) {
448 sprintf(vblk->disk->disk_name, "vd%c%c",
449 'a' + index / 26 - 1, 'a' + index % 26);
450 } else {
451 const unsigned int m1 = (index / 26 - 1) / 26 - 1;
452 const unsigned int m2 = (index / 26 - 1) % 26;
453 const unsigned int m3 = index % 26;
454 sprintf(vblk->disk->disk_name, "vd%c%c%c",
455 'a' + m1, 'a' + m2, 'a' + m3);
456 }
457 475
458 vblk->disk->major = major; 476 vblk->disk->major = major;
459 vblk->disk->first_minor = index_to_minor(index); 477 vblk->disk->first_minor = index_to_minor(index);
diff --git a/drivers/block/xen-blkback/blkback.c b/drivers/block/xen-blkback/blkback.c
index 0088bf60f368..73f196ca713f 100644
--- a/drivers/block/xen-blkback/blkback.c
+++ b/drivers/block/xen-blkback/blkback.c
@@ -321,6 +321,7 @@ struct seg_buf {
321static void xen_blkbk_unmap(struct pending_req *req) 321static void xen_blkbk_unmap(struct pending_req *req)
322{ 322{
323 struct gnttab_unmap_grant_ref unmap[BLKIF_MAX_SEGMENTS_PER_REQUEST]; 323 struct gnttab_unmap_grant_ref unmap[BLKIF_MAX_SEGMENTS_PER_REQUEST];
324 struct page *pages[BLKIF_MAX_SEGMENTS_PER_REQUEST];
324 unsigned int i, invcount = 0; 325 unsigned int i, invcount = 0;
325 grant_handle_t handle; 326 grant_handle_t handle;
326 int ret; 327 int ret;
@@ -332,25 +333,12 @@ static void xen_blkbk_unmap(struct pending_req *req)
332 gnttab_set_unmap_op(&unmap[invcount], vaddr(req, i), 333 gnttab_set_unmap_op(&unmap[invcount], vaddr(req, i),
333 GNTMAP_host_map, handle); 334 GNTMAP_host_map, handle);
334 pending_handle(req, i) = BLKBACK_INVALID_HANDLE; 335 pending_handle(req, i) = BLKBACK_INVALID_HANDLE;
336 pages[invcount] = virt_to_page(vaddr(req, i));
335 invcount++; 337 invcount++;
336 } 338 }
337 339
338 ret = HYPERVISOR_grant_table_op( 340 ret = gnttab_unmap_refs(unmap, pages, invcount, false);
339 GNTTABOP_unmap_grant_ref, unmap, invcount);
340 BUG_ON(ret); 341 BUG_ON(ret);
341 /*
342 * Note, we use invcount, so nr->pages, so we can't index
343 * using vaddr(req, i).
344 */
345 for (i = 0; i < invcount; i++) {
346 ret = m2p_remove_override(
347 virt_to_page(unmap[i].host_addr), false);
348 if (ret) {
349 pr_alert(DRV_PFX "Failed to remove M2P override for %lx\n",
350 (unsigned long)unmap[i].host_addr);
351 continue;
352 }
353 }
354} 342}
355 343
356static int xen_blkbk_map(struct blkif_request *req, 344static int xen_blkbk_map(struct blkif_request *req,
@@ -378,7 +366,7 @@ static int xen_blkbk_map(struct blkif_request *req,
378 pending_req->blkif->domid); 366 pending_req->blkif->domid);
379 } 367 }
380 368
381 ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, map, nseg); 369 ret = gnttab_map_refs(map, NULL, &blkbk->pending_page(pending_req, 0), nseg);
382 BUG_ON(ret); 370 BUG_ON(ret);
383 371
384 /* 372 /*
@@ -398,15 +386,6 @@ static int xen_blkbk_map(struct blkif_request *req,
398 if (ret) 386 if (ret)
399 continue; 387 continue;
400 388
401 ret = m2p_add_override(PFN_DOWN(map[i].dev_bus_addr),
402 blkbk->pending_page(pending_req, i), NULL);
403 if (ret) {
404 pr_alert(DRV_PFX "Failed to install M2P override for %lx (ret: %d)\n",
405 (unsigned long)map[i].dev_bus_addr, ret);
406 /* We could switch over to GNTTABOP_copy */
407 continue;
408 }
409
410 seg[i].buf = map[i].dev_bus_addr | 389 seg[i].buf = map[i].dev_bus_addr |
411 (req->u.rw.seg[i].first_sect << 9); 390 (req->u.rw.seg[i].first_sect << 9);
412 } 391 }
@@ -419,21 +398,18 @@ static int dispatch_discard_io(struct xen_blkif *blkif,
419 int err = 0; 398 int err = 0;
420 int status = BLKIF_RSP_OKAY; 399 int status = BLKIF_RSP_OKAY;
421 struct block_device *bdev = blkif->vbd.bdev; 400 struct block_device *bdev = blkif->vbd.bdev;
401 unsigned long secure;
422 402
423 blkif->st_ds_req++; 403 blkif->st_ds_req++;
424 404
425 xen_blkif_get(blkif); 405 xen_blkif_get(blkif);
426 if (blkif->blk_backend_type == BLKIF_BACKEND_PHY || 406 secure = (blkif->vbd.discard_secure &&
427 blkif->blk_backend_type == BLKIF_BACKEND_FILE) { 407 (req->u.discard.flag & BLKIF_DISCARD_SECURE)) ?
428 unsigned long secure = (blkif->vbd.discard_secure && 408 BLKDEV_DISCARD_SECURE : 0;
429 (req->u.discard.flag & BLKIF_DISCARD_SECURE)) ? 409
430 BLKDEV_DISCARD_SECURE : 0; 410 err = blkdev_issue_discard(bdev, req->u.discard.sector_number,
431 err = blkdev_issue_discard(bdev, 411 req->u.discard.nr_sectors,
432 req->u.discard.sector_number, 412 GFP_KERNEL, secure);
433 req->u.discard.nr_sectors,
434 GFP_KERNEL, secure);
435 } else
436 err = -EOPNOTSUPP;
437 413
438 if (err == -EOPNOTSUPP) { 414 if (err == -EOPNOTSUPP) {
439 pr_debug(DRV_PFX "discard op failed, not supported\n"); 415 pr_debug(DRV_PFX "discard op failed, not supported\n");
@@ -830,7 +806,7 @@ static int __init xen_blkif_init(void)
830 int i, mmap_pages; 806 int i, mmap_pages;
831 int rc = 0; 807 int rc = 0;
832 808
833 if (!xen_pv_domain()) 809 if (!xen_domain())
834 return -ENODEV; 810 return -ENODEV;
835 811
836 blkbk = kzalloc(sizeof(struct xen_blkbk), GFP_KERNEL); 812 blkbk = kzalloc(sizeof(struct xen_blkbk), GFP_KERNEL);
diff --git a/drivers/block/xen-blkback/common.h b/drivers/block/xen-blkback/common.h
index d0ee7edc9be8..773cf27dc23f 100644
--- a/drivers/block/xen-blkback/common.h
+++ b/drivers/block/xen-blkback/common.h
@@ -146,11 +146,6 @@ enum blkif_protocol {
146 BLKIF_PROTOCOL_X86_64 = 3, 146 BLKIF_PROTOCOL_X86_64 = 3,
147}; 147};
148 148
149enum blkif_backend_type {
150 BLKIF_BACKEND_PHY = 1,
151 BLKIF_BACKEND_FILE = 2,
152};
153
154struct xen_vbd { 149struct xen_vbd {
155 /* What the domain refers to this vbd as. */ 150 /* What the domain refers to this vbd as. */
156 blkif_vdev_t handle; 151 blkif_vdev_t handle;
@@ -177,7 +172,6 @@ struct xen_blkif {
177 unsigned int irq; 172 unsigned int irq;
178 /* Comms information. */ 173 /* Comms information. */
179 enum blkif_protocol blk_protocol; 174 enum blkif_protocol blk_protocol;
180 enum blkif_backend_type blk_backend_type;
181 union blkif_back_rings blk_rings; 175 union blkif_back_rings blk_rings;
182 void *blk_ring; 176 void *blk_ring;
183 /* The VBD attached to this interface. */ 177 /* The VBD attached to this interface. */
diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c
index 24a2fb57e5d0..4f66171c6683 100644
--- a/drivers/block/xen-blkback/xenbus.c
+++ b/drivers/block/xen-blkback/xenbus.c
@@ -381,72 +381,49 @@ int xen_blkbk_flush_diskcache(struct xenbus_transaction xbt,
381 err = xenbus_printf(xbt, dev->nodename, "feature-flush-cache", 381 err = xenbus_printf(xbt, dev->nodename, "feature-flush-cache",
382 "%d", state); 382 "%d", state);
383 if (err) 383 if (err)
384 xenbus_dev_fatal(dev, err, "writing feature-flush-cache"); 384 dev_warn(&dev->dev, "writing feature-flush-cache (%d)", err);
385 385
386 return err; 386 return err;
387} 387}
388 388
389int xen_blkbk_discard(struct xenbus_transaction xbt, struct backend_info *be) 389static void xen_blkbk_discard(struct xenbus_transaction xbt, struct backend_info *be)
390{ 390{
391 struct xenbus_device *dev = be->dev; 391 struct xenbus_device *dev = be->dev;
392 struct xen_blkif *blkif = be->blkif; 392 struct xen_blkif *blkif = be->blkif;
393 char *type;
394 int err; 393 int err;
395 int state = 0; 394 int state = 0;
395 struct block_device *bdev = be->blkif->vbd.bdev;
396 struct request_queue *q = bdev_get_queue(bdev);
396 397
397 type = xenbus_read(XBT_NIL, dev->nodename, "type", NULL); 398 if (blk_queue_discard(q)) {
398 if (!IS_ERR(type)) { 399 err = xenbus_printf(xbt, dev->nodename,
399 if (strncmp(type, "file", 4) == 0) { 400 "discard-granularity", "%u",
400 state = 1; 401 q->limits.discard_granularity);
401 blkif->blk_backend_type = BLKIF_BACKEND_FILE; 402 if (err) {
403 dev_warn(&dev->dev, "writing discard-granularity (%d)", err);
404 return;
402 } 405 }
403 if (strncmp(type, "phy", 3) == 0) { 406 err = xenbus_printf(xbt, dev->nodename,
404 struct block_device *bdev = be->blkif->vbd.bdev; 407 "discard-alignment", "%u",
405 struct request_queue *q = bdev_get_queue(bdev); 408 q->limits.discard_alignment);
406 if (blk_queue_discard(q)) { 409 if (err) {
407 err = xenbus_printf(xbt, dev->nodename, 410 dev_warn(&dev->dev, "writing discard-alignment (%d)", err);
408 "discard-granularity", "%u", 411 return;
409 q->limits.discard_granularity); 412 }
410 if (err) { 413 state = 1;
411 xenbus_dev_fatal(dev, err, 414 /* Optional. */
412 "writing discard-granularity"); 415 err = xenbus_printf(xbt, dev->nodename,
413 goto kfree; 416 "discard-secure", "%d",
414 } 417 blkif->vbd.discard_secure);
415 err = xenbus_printf(xbt, dev->nodename, 418 if (err) {
416 "discard-alignment", "%u", 419 dev_warn(&dev->dev, "writing discard-secure (%d)", err);
417 q->limits.discard_alignment); 420 return;
418 if (err) {
419 xenbus_dev_fatal(dev, err,
420 "writing discard-alignment");
421 goto kfree;
422 }
423 state = 1;
424 blkif->blk_backend_type = BLKIF_BACKEND_PHY;
425 }
426 /* Optional. */
427 err = xenbus_printf(xbt, dev->nodename,
428 "discard-secure", "%d",
429 blkif->vbd.discard_secure);
430 if (err) {
431 xenbus_dev_fatal(dev, err,
432 "writting discard-secure");
433 goto kfree;
434 }
435 } 421 }
436 } else {
437 err = PTR_ERR(type);
438 xenbus_dev_fatal(dev, err, "reading type");
439 goto out;
440 } 422 }
441
442 err = xenbus_printf(xbt, dev->nodename, "feature-discard", 423 err = xenbus_printf(xbt, dev->nodename, "feature-discard",
443 "%d", state); 424 "%d", state);
444 if (err) 425 if (err)
445 xenbus_dev_fatal(dev, err, "writing feature-discard"); 426 dev_warn(&dev->dev, "writing feature-discard (%d)", err);
446kfree:
447 kfree(type);
448out:
449 return err;
450} 427}
451int xen_blkbk_barrier(struct xenbus_transaction xbt, 428int xen_blkbk_barrier(struct xenbus_transaction xbt,
452 struct backend_info *be, int state) 429 struct backend_info *be, int state)
@@ -457,7 +434,7 @@ int xen_blkbk_barrier(struct xenbus_transaction xbt,
457 err = xenbus_printf(xbt, dev->nodename, "feature-barrier", 434 err = xenbus_printf(xbt, dev->nodename, "feature-barrier",
458 "%d", state); 435 "%d", state);
459 if (err) 436 if (err)
460 xenbus_dev_fatal(dev, err, "writing feature-barrier"); 437 dev_warn(&dev->dev, "writing feature-barrier (%d)", err);
461 438
462 return err; 439 return err;
463} 440}
@@ -689,14 +666,12 @@ again:
689 return; 666 return;
690 } 667 }
691 668
692 err = xen_blkbk_flush_diskcache(xbt, be, be->blkif->vbd.flush_support); 669 /* If we can't advertise it is OK. */
693 if (err) 670 xen_blkbk_flush_diskcache(xbt, be, be->blkif->vbd.flush_support);
694 goto abort;
695 671
696 err = xen_blkbk_discard(xbt, be); 672 xen_blkbk_discard(xbt, be);
697 673
698 /* If we can't advertise it is OK. */ 674 xen_blkbk_barrier(xbt, be, be->blkif->vbd.flush_support);
699 err = xen_blkbk_barrier(xbt, be, be->blkif->vbd.flush_support);
700 675
701 err = xenbus_printf(xbt, dev->nodename, "sectors", "%llu", 676 err = xenbus_printf(xbt, dev->nodename, "sectors", "%llu",
702 (unsigned long long)vbd_sz(&be->blkif->vbd)); 677 (unsigned long long)vbd_sz(&be->blkif->vbd));
diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c
index d5e1ab956740..4e86393a09cf 100644
--- a/drivers/block/xen-blkfront.c
+++ b/drivers/block/xen-blkfront.c
@@ -43,6 +43,7 @@
43#include <linux/slab.h> 43#include <linux/slab.h>
44#include <linux/mutex.h> 44#include <linux/mutex.h>
45#include <linux/scatterlist.h> 45#include <linux/scatterlist.h>
46#include <linux/bitmap.h>
46 47
47#include <xen/xen.h> 48#include <xen/xen.h>
48#include <xen/xenbus.h> 49#include <xen/xenbus.h>
@@ -81,6 +82,7 @@ static const struct block_device_operations xlvbd_block_fops;
81 */ 82 */
82struct blkfront_info 83struct blkfront_info
83{ 84{
85 spinlock_t io_lock;
84 struct mutex mutex; 86 struct mutex mutex;
85 struct xenbus_device *xbdev; 87 struct xenbus_device *xbdev;
86 struct gendisk *gd; 88 struct gendisk *gd;
@@ -105,8 +107,6 @@ struct blkfront_info
105 int is_ready; 107 int is_ready;
106}; 108};
107 109
108static DEFINE_SPINLOCK(blkif_io_lock);
109
110static unsigned int nr_minors; 110static unsigned int nr_minors;
111static unsigned long *minors; 111static unsigned long *minors;
112static DEFINE_SPINLOCK(minor_lock); 112static DEFINE_SPINLOCK(minor_lock);
@@ -177,8 +177,7 @@ static int xlbd_reserve_minors(unsigned int minor, unsigned int nr)
177 177
178 spin_lock(&minor_lock); 178 spin_lock(&minor_lock);
179 if (find_next_bit(minors, end, minor) >= end) { 179 if (find_next_bit(minors, end, minor) >= end) {
180 for (; minor < end; ++minor) 180 bitmap_set(minors, minor, nr);
181 __set_bit(minor, minors);
182 rc = 0; 181 rc = 0;
183 } else 182 } else
184 rc = -EBUSY; 183 rc = -EBUSY;
@@ -193,8 +192,7 @@ static void xlbd_release_minors(unsigned int minor, unsigned int nr)
193 192
194 BUG_ON(end > nr_minors); 193 BUG_ON(end > nr_minors);
195 spin_lock(&minor_lock); 194 spin_lock(&minor_lock);
196 for (; minor < end; ++minor) 195 bitmap_clear(minors, minor, nr);
197 __clear_bit(minor, minors);
198 spin_unlock(&minor_lock); 196 spin_unlock(&minor_lock);
199} 197}
200 198
@@ -419,7 +417,7 @@ static int xlvbd_init_blk_queue(struct gendisk *gd, u16 sector_size)
419 struct request_queue *rq; 417 struct request_queue *rq;
420 struct blkfront_info *info = gd->private_data; 418 struct blkfront_info *info = gd->private_data;
421 419
422 rq = blk_init_queue(do_blkif_request, &blkif_io_lock); 420 rq = blk_init_queue(do_blkif_request, &info->io_lock);
423 if (rq == NULL) 421 if (rq == NULL)
424 return -1; 422 return -1;
425 423
@@ -636,14 +634,14 @@ static void xlvbd_release_gendisk(struct blkfront_info *info)
636 if (info->rq == NULL) 634 if (info->rq == NULL)
637 return; 635 return;
638 636
639 spin_lock_irqsave(&blkif_io_lock, flags); 637 spin_lock_irqsave(&info->io_lock, flags);
640 638
641 /* No more blkif_request(). */ 639 /* No more blkif_request(). */
642 blk_stop_queue(info->rq); 640 blk_stop_queue(info->rq);
643 641
644 /* No more gnttab callback work. */ 642 /* No more gnttab callback work. */
645 gnttab_cancel_free_callback(&info->callback); 643 gnttab_cancel_free_callback(&info->callback);
646 spin_unlock_irqrestore(&blkif_io_lock, flags); 644 spin_unlock_irqrestore(&info->io_lock, flags);
647 645
648 /* Flush gnttab callback work. Must be done with no locks held. */ 646 /* Flush gnttab callback work. Must be done with no locks held. */
649 flush_work_sync(&info->work); 647 flush_work_sync(&info->work);
@@ -675,16 +673,16 @@ static void blkif_restart_queue(struct work_struct *work)
675{ 673{
676 struct blkfront_info *info = container_of(work, struct blkfront_info, work); 674 struct blkfront_info *info = container_of(work, struct blkfront_info, work);
677 675
678 spin_lock_irq(&blkif_io_lock); 676 spin_lock_irq(&info->io_lock);
679 if (info->connected == BLKIF_STATE_CONNECTED) 677 if (info->connected == BLKIF_STATE_CONNECTED)
680 kick_pending_request_queues(info); 678 kick_pending_request_queues(info);
681 spin_unlock_irq(&blkif_io_lock); 679 spin_unlock_irq(&info->io_lock);
682} 680}
683 681
684static void blkif_free(struct blkfront_info *info, int suspend) 682static void blkif_free(struct blkfront_info *info, int suspend)
685{ 683{
686 /* Prevent new requests being issued until we fix things up. */ 684 /* Prevent new requests being issued until we fix things up. */
687 spin_lock_irq(&blkif_io_lock); 685 spin_lock_irq(&info->io_lock);
688 info->connected = suspend ? 686 info->connected = suspend ?
689 BLKIF_STATE_SUSPENDED : BLKIF_STATE_DISCONNECTED; 687 BLKIF_STATE_SUSPENDED : BLKIF_STATE_DISCONNECTED;
690 /* No more blkif_request(). */ 688 /* No more blkif_request(). */
@@ -692,7 +690,7 @@ static void blkif_free(struct blkfront_info *info, int suspend)
692 blk_stop_queue(info->rq); 690 blk_stop_queue(info->rq);
693 /* No more gnttab callback work. */ 691 /* No more gnttab callback work. */
694 gnttab_cancel_free_callback(&info->callback); 692 gnttab_cancel_free_callback(&info->callback);
695 spin_unlock_irq(&blkif_io_lock); 693 spin_unlock_irq(&info->io_lock);
696 694
697 /* Flush gnttab callback work. Must be done with no locks held. */ 695 /* Flush gnttab callback work. Must be done with no locks held. */
698 flush_work_sync(&info->work); 696 flush_work_sync(&info->work);
@@ -728,10 +726,10 @@ static irqreturn_t blkif_interrupt(int irq, void *dev_id)
728 struct blkfront_info *info = (struct blkfront_info *)dev_id; 726 struct blkfront_info *info = (struct blkfront_info *)dev_id;
729 int error; 727 int error;
730 728
731 spin_lock_irqsave(&blkif_io_lock, flags); 729 spin_lock_irqsave(&info->io_lock, flags);
732 730
733 if (unlikely(info->connected != BLKIF_STATE_CONNECTED)) { 731 if (unlikely(info->connected != BLKIF_STATE_CONNECTED)) {
734 spin_unlock_irqrestore(&blkif_io_lock, flags); 732 spin_unlock_irqrestore(&info->io_lock, flags);
735 return IRQ_HANDLED; 733 return IRQ_HANDLED;
736 } 734 }
737 735
@@ -816,7 +814,7 @@ static irqreturn_t blkif_interrupt(int irq, void *dev_id)
816 814
817 kick_pending_request_queues(info); 815 kick_pending_request_queues(info);
818 816
819 spin_unlock_irqrestore(&blkif_io_lock, flags); 817 spin_unlock_irqrestore(&info->io_lock, flags);
820 818
821 return IRQ_HANDLED; 819 return IRQ_HANDLED;
822} 820}
@@ -991,6 +989,7 @@ static int blkfront_probe(struct xenbus_device *dev,
991 } 989 }
992 990
993 mutex_init(&info->mutex); 991 mutex_init(&info->mutex);
992 spin_lock_init(&info->io_lock);
994 info->xbdev = dev; 993 info->xbdev = dev;
995 info->vdevice = vdevice; 994 info->vdevice = vdevice;
996 info->connected = BLKIF_STATE_DISCONNECTED; 995 info->connected = BLKIF_STATE_DISCONNECTED;
@@ -1068,7 +1067,7 @@ static int blkif_recover(struct blkfront_info *info)
1068 1067
1069 xenbus_switch_state(info->xbdev, XenbusStateConnected); 1068 xenbus_switch_state(info->xbdev, XenbusStateConnected);
1070 1069
1071 spin_lock_irq(&blkif_io_lock); 1070 spin_lock_irq(&info->io_lock);
1072 1071
1073 /* Now safe for us to use the shared ring */ 1072 /* Now safe for us to use the shared ring */
1074 info->connected = BLKIF_STATE_CONNECTED; 1073 info->connected = BLKIF_STATE_CONNECTED;
@@ -1079,7 +1078,7 @@ static int blkif_recover(struct blkfront_info *info)
1079 /* Kick any other new requests queued since we resumed */ 1078 /* Kick any other new requests queued since we resumed */
1080 kick_pending_request_queues(info); 1079 kick_pending_request_queues(info);
1081 1080
1082 spin_unlock_irq(&blkif_io_lock); 1081 spin_unlock_irq(&info->io_lock);
1083 1082
1084 return 0; 1083 return 0;
1085} 1084}
@@ -1277,10 +1276,10 @@ static void blkfront_connect(struct blkfront_info *info)
1277 xenbus_switch_state(info->xbdev, XenbusStateConnected); 1276 xenbus_switch_state(info->xbdev, XenbusStateConnected);
1278 1277
1279 /* Kick pending requests. */ 1278 /* Kick pending requests. */
1280 spin_lock_irq(&blkif_io_lock); 1279 spin_lock_irq(&info->io_lock);
1281 info->connected = BLKIF_STATE_CONNECTED; 1280 info->connected = BLKIF_STATE_CONNECTED;
1282 kick_pending_request_queues(info); 1281 kick_pending_request_queues(info);
1283 spin_unlock_irq(&blkif_io_lock); 1282 spin_unlock_irq(&info->io_lock);
1284 1283
1285 add_disk(info->gd); 1284 add_disk(info->gd);
1286 1285
@@ -1410,7 +1409,6 @@ static int blkif_release(struct gendisk *disk, fmode_t mode)
1410 mutex_lock(&blkfront_mutex); 1409 mutex_lock(&blkfront_mutex);
1411 1410
1412 bdev = bdget_disk(disk, 0); 1411 bdev = bdget_disk(disk, 0);
1413 bdput(bdev);
1414 1412
1415 if (bdev->bd_openers) 1413 if (bdev->bd_openers)
1416 goto out; 1414 goto out;
@@ -1441,6 +1439,7 @@ static int blkif_release(struct gendisk *disk, fmode_t mode)
1441 } 1439 }
1442 1440
1443out: 1441out:
1442 bdput(bdev);
1444 mutex_unlock(&blkfront_mutex); 1443 mutex_unlock(&blkfront_mutex);
1445 return 0; 1444 return 0;
1446} 1445}
@@ -1475,7 +1474,7 @@ static int __init xlblk_init(void)
1475 if (!xen_domain()) 1474 if (!xen_domain())
1476 return -ENODEV; 1475 return -ENODEV;
1477 1476
1478 if (!xen_platform_pci_unplug) 1477 if (xen_hvm_domain() && !xen_platform_pci_unplug)
1479 return -ENODEV; 1478 return -ENODEV;
1480 1479
1481 if (register_blkdev(XENVBD_MAJOR, DEV_NAME)) { 1480 if (register_blkdev(XENVBD_MAJOR, DEV_NAME)) {
diff --git a/drivers/bluetooth/ath3k.c b/drivers/bluetooth/ath3k.c
index 48442476ec00..57fd867553d7 100644
--- a/drivers/bluetooth/ath3k.c
+++ b/drivers/bluetooth/ath3k.c
@@ -72,7 +72,11 @@ static struct usb_device_id ath3k_table[] = {
72 72
73 /* Atheros AR3012 with sflash firmware*/ 73 /* Atheros AR3012 with sflash firmware*/
74 { USB_DEVICE(0x0CF3, 0x3004) }, 74 { USB_DEVICE(0x0CF3, 0x3004) },
75 { USB_DEVICE(0x0CF3, 0x311D) },
75 { USB_DEVICE(0x13d3, 0x3375) }, 76 { USB_DEVICE(0x13d3, 0x3375) },
77 { USB_DEVICE(0x04CA, 0x3005) },
78 { USB_DEVICE(0x13d3, 0x3362) },
79 { USB_DEVICE(0x0CF3, 0xE004) },
76 80
77 /* Atheros AR5BBU12 with sflash firmware */ 81 /* Atheros AR5BBU12 with sflash firmware */
78 { USB_DEVICE(0x0489, 0xE02C) }, 82 { USB_DEVICE(0x0489, 0xE02C) },
@@ -89,7 +93,11 @@ static struct usb_device_id ath3k_blist_tbl[] = {
89 93
90 /* Atheros AR3012 with sflash firmware*/ 94 /* Atheros AR3012 with sflash firmware*/
91 { USB_DEVICE(0x0cf3, 0x3004), .driver_info = BTUSB_ATH3012 }, 95 { USB_DEVICE(0x0cf3, 0x3004), .driver_info = BTUSB_ATH3012 },
96 { USB_DEVICE(0x0cf3, 0x311D), .driver_info = BTUSB_ATH3012 },
92 { USB_DEVICE(0x13d3, 0x3375), .driver_info = BTUSB_ATH3012 }, 97 { USB_DEVICE(0x13d3, 0x3375), .driver_info = BTUSB_ATH3012 },
98 { USB_DEVICE(0x04ca, 0x3005), .driver_info = BTUSB_ATH3012 },
99 { USB_DEVICE(0x13d3, 0x3362), .driver_info = BTUSB_ATH3012 },
100 { USB_DEVICE(0x0cf3, 0xe004), .driver_info = BTUSB_ATH3012 },
93 101
94 { } /* Terminating entry */ 102 { } /* Terminating entry */
95}; 103};
diff --git a/drivers/bluetooth/btmrvl_debugfs.c b/drivers/bluetooth/btmrvl_debugfs.c
index 6c20bbb54b71..428dbb7574bd 100644
--- a/drivers/bluetooth/btmrvl_debugfs.c
+++ b/drivers/bluetooth/btmrvl_debugfs.c
@@ -45,12 +45,6 @@ struct btmrvl_debugfs_data {
45 struct dentry *txdnldready; 45 struct dentry *txdnldready;
46}; 46};
47 47
48static int btmrvl_open_generic(struct inode *inode, struct file *file)
49{
50 file->private_data = inode->i_private;
51 return 0;
52}
53
54static ssize_t btmrvl_hscfgcmd_write(struct file *file, 48static ssize_t btmrvl_hscfgcmd_write(struct file *file,
55 const char __user *ubuf, size_t count, loff_t *ppos) 49 const char __user *ubuf, size_t count, loff_t *ppos)
56{ 50{
@@ -93,7 +87,7 @@ static ssize_t btmrvl_hscfgcmd_read(struct file *file, char __user *userbuf,
93static const struct file_operations btmrvl_hscfgcmd_fops = { 87static const struct file_operations btmrvl_hscfgcmd_fops = {
94 .read = btmrvl_hscfgcmd_read, 88 .read = btmrvl_hscfgcmd_read,
95 .write = btmrvl_hscfgcmd_write, 89 .write = btmrvl_hscfgcmd_write,
96 .open = btmrvl_open_generic, 90 .open = simple_open,
97 .llseek = default_llseek, 91 .llseek = default_llseek,
98}; 92};
99 93
@@ -134,7 +128,7 @@ static ssize_t btmrvl_psmode_read(struct file *file, char __user *userbuf,
134static const struct file_operations btmrvl_psmode_fops = { 128static const struct file_operations btmrvl_psmode_fops = {
135 .read = btmrvl_psmode_read, 129 .read = btmrvl_psmode_read,
136 .write = btmrvl_psmode_write, 130 .write = btmrvl_psmode_write,
137 .open = btmrvl_open_generic, 131 .open = simple_open,
138 .llseek = default_llseek, 132 .llseek = default_llseek,
139}; 133};
140 134
@@ -180,7 +174,7 @@ static ssize_t btmrvl_pscmd_read(struct file *file, char __user *userbuf,
180static const struct file_operations btmrvl_pscmd_fops = { 174static const struct file_operations btmrvl_pscmd_fops = {
181 .read = btmrvl_pscmd_read, 175 .read = btmrvl_pscmd_read,
182 .write = btmrvl_pscmd_write, 176 .write = btmrvl_pscmd_write,
183 .open = btmrvl_open_generic, 177 .open = simple_open,
184 .llseek = default_llseek, 178 .llseek = default_llseek,
185}; 179};
186 180
@@ -221,7 +215,7 @@ static ssize_t btmrvl_gpiogap_read(struct file *file, char __user *userbuf,
221static const struct file_operations btmrvl_gpiogap_fops = { 215static const struct file_operations btmrvl_gpiogap_fops = {
222 .read = btmrvl_gpiogap_read, 216 .read = btmrvl_gpiogap_read,
223 .write = btmrvl_gpiogap_write, 217 .write = btmrvl_gpiogap_write,
224 .open = btmrvl_open_generic, 218 .open = simple_open,
225 .llseek = default_llseek, 219 .llseek = default_llseek,
226}; 220};
227 221
@@ -265,7 +259,7 @@ static ssize_t btmrvl_hscmd_read(struct file *file, char __user *userbuf,
265static const struct file_operations btmrvl_hscmd_fops = { 259static const struct file_operations btmrvl_hscmd_fops = {
266 .read = btmrvl_hscmd_read, 260 .read = btmrvl_hscmd_read,
267 .write = btmrvl_hscmd_write, 261 .write = btmrvl_hscmd_write,
268 .open = btmrvl_open_generic, 262 .open = simple_open,
269 .llseek = default_llseek, 263 .llseek = default_llseek,
270}; 264};
271 265
@@ -305,7 +299,7 @@ static ssize_t btmrvl_hsmode_read(struct file *file, char __user * userbuf,
305static const struct file_operations btmrvl_hsmode_fops = { 299static const struct file_operations btmrvl_hsmode_fops = {
306 .read = btmrvl_hsmode_read, 300 .read = btmrvl_hsmode_read,
307 .write = btmrvl_hsmode_write, 301 .write = btmrvl_hsmode_write,
308 .open = btmrvl_open_generic, 302 .open = simple_open,
309 .llseek = default_llseek, 303 .llseek = default_llseek,
310}; 304};
311 305
@@ -323,7 +317,7 @@ static ssize_t btmrvl_curpsmode_read(struct file *file, char __user *userbuf,
323 317
324static const struct file_operations btmrvl_curpsmode_fops = { 318static const struct file_operations btmrvl_curpsmode_fops = {
325 .read = btmrvl_curpsmode_read, 319 .read = btmrvl_curpsmode_read,
326 .open = btmrvl_open_generic, 320 .open = simple_open,
327 .llseek = default_llseek, 321 .llseek = default_llseek,
328}; 322};
329 323
@@ -341,7 +335,7 @@ static ssize_t btmrvl_psstate_read(struct file *file, char __user * userbuf,
341 335
342static const struct file_operations btmrvl_psstate_fops = { 336static const struct file_operations btmrvl_psstate_fops = {
343 .read = btmrvl_psstate_read, 337 .read = btmrvl_psstate_read,
344 .open = btmrvl_open_generic, 338 .open = simple_open,
345 .llseek = default_llseek, 339 .llseek = default_llseek,
346}; 340};
347 341
@@ -359,7 +353,7 @@ static ssize_t btmrvl_hsstate_read(struct file *file, char __user *userbuf,
359 353
360static const struct file_operations btmrvl_hsstate_fops = { 354static const struct file_operations btmrvl_hsstate_fops = {
361 .read = btmrvl_hsstate_read, 355 .read = btmrvl_hsstate_read,
362 .open = btmrvl_open_generic, 356 .open = simple_open,
363 .llseek = default_llseek, 357 .llseek = default_llseek,
364}; 358};
365 359
@@ -378,7 +372,7 @@ static ssize_t btmrvl_txdnldready_read(struct file *file, char __user *userbuf,
378 372
379static const struct file_operations btmrvl_txdnldready_fops = { 373static const struct file_operations btmrvl_txdnldready_fops = {
380 .read = btmrvl_txdnldready_read, 374 .read = btmrvl_txdnldready_read,
381 .open = btmrvl_open_generic, 375 .open = simple_open,
382 .llseek = default_llseek, 376 .llseek = default_llseek,
383}; 377};
384 378
diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index 480cad920048..9217121362e1 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -61,7 +61,7 @@ static struct usb_device_id btusb_table[] = {
61 { USB_DEVICE_INFO(0xe0, 0x01, 0x01) }, 61 { USB_DEVICE_INFO(0xe0, 0x01, 0x01) },
62 62
63 /* Broadcom SoftSailing reporting vendor specific */ 63 /* Broadcom SoftSailing reporting vendor specific */
64 { USB_DEVICE(0x05ac, 0x21e1) }, 64 { USB_DEVICE(0x0a5c, 0x21e1) },
65 65
66 /* Apple MacBookPro 7,1 */ 66 /* Apple MacBookPro 7,1 */
67 { USB_DEVICE(0x05ac, 0x8213) }, 67 { USB_DEVICE(0x05ac, 0x8213) },
@@ -101,11 +101,16 @@ static struct usb_device_id btusb_table[] = {
101 { USB_DEVICE(0x0c10, 0x0000) }, 101 { USB_DEVICE(0x0c10, 0x0000) },
102 102
103 /* Broadcom BCM20702A0 */ 103 /* Broadcom BCM20702A0 */
104 { USB_DEVICE(0x0489, 0xe042) },
104 { USB_DEVICE(0x0a5c, 0x21e3) }, 105 { USB_DEVICE(0x0a5c, 0x21e3) },
105 { USB_DEVICE(0x0a5c, 0x21e6) }, 106 { USB_DEVICE(0x0a5c, 0x21e6) },
107 { USB_DEVICE(0x0a5c, 0x21e8) },
106 { USB_DEVICE(0x0a5c, 0x21f3) }, 108 { USB_DEVICE(0x0a5c, 0x21f3) },
107 { USB_DEVICE(0x413c, 0x8197) }, 109 { USB_DEVICE(0x413c, 0x8197) },
108 110
111 /* Foxconn - Hon Hai */
112 { USB_DEVICE(0x0489, 0xe033) },
113
109 { } /* Terminating entry */ 114 { } /* Terminating entry */
110}; 115};
111 116
@@ -129,7 +134,11 @@ static struct usb_device_id blacklist_table[] = {
129 134
130 /* Atheros 3012 with sflash firmware */ 135 /* Atheros 3012 with sflash firmware */
131 { USB_DEVICE(0x0cf3, 0x3004), .driver_info = BTUSB_ATH3012 }, 136 { USB_DEVICE(0x0cf3, 0x3004), .driver_info = BTUSB_ATH3012 },
137 { USB_DEVICE(0x0cf3, 0x311d), .driver_info = BTUSB_ATH3012 },
132 { USB_DEVICE(0x13d3, 0x3375), .driver_info = BTUSB_ATH3012 }, 138 { USB_DEVICE(0x13d3, 0x3375), .driver_info = BTUSB_ATH3012 },
139 { USB_DEVICE(0x04ca, 0x3005), .driver_info = BTUSB_ATH3012 },
140 { USB_DEVICE(0x13d3, 0x3362), .driver_info = BTUSB_ATH3012 },
141 { USB_DEVICE(0x0cf3, 0xe004), .driver_info = BTUSB_ATH3012 },
133 142
134 /* Atheros AR5BBU12 with sflash firmware */ 143 /* Atheros AR5BBU12 with sflash firmware */
135 { USB_DEVICE(0x0489, 0xe02c), .driver_info = BTUSB_IGNORE }, 144 { USB_DEVICE(0x0489, 0xe02c), .driver_info = BTUSB_IGNORE },
diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c
index fd5adb408f44..98a8c05d4f23 100644
--- a/drivers/bluetooth/hci_ldisc.c
+++ b/drivers/bluetooth/hci_ldisc.c
@@ -299,11 +299,11 @@ static void hci_uart_tty_close(struct tty_struct *tty)
299 hci_uart_close(hdev); 299 hci_uart_close(hdev);
300 300
301 if (test_and_clear_bit(HCI_UART_PROTO_SET, &hu->flags)) { 301 if (test_and_clear_bit(HCI_UART_PROTO_SET, &hu->flags)) {
302 hu->proto->close(hu);
303 if (hdev) { 302 if (hdev) {
304 hci_unregister_dev(hdev); 303 hci_unregister_dev(hdev);
305 hci_free_dev(hdev); 304 hci_free_dev(hdev);
306 } 305 }
306 hu->proto->close(hu);
307 } 307 }
308 308
309 kfree(hu); 309 kfree(hu);
diff --git a/drivers/char/agp/intel-agp.h b/drivers/char/agp/intel-agp.h
index 5da67f165afa..7ea18a5fe71c 100644
--- a/drivers/char/agp/intel-agp.h
+++ b/drivers/char/agp/intel-agp.h
@@ -234,6 +234,7 @@
234#define PCI_DEVICE_ID_INTEL_IVYBRIDGE_M_GT2_IG 0x0166 234#define PCI_DEVICE_ID_INTEL_IVYBRIDGE_M_GT2_IG 0x0166
235#define PCI_DEVICE_ID_INTEL_IVYBRIDGE_S_HB 0x0158 /* Server */ 235#define PCI_DEVICE_ID_INTEL_IVYBRIDGE_S_HB 0x0158 /* Server */
236#define PCI_DEVICE_ID_INTEL_IVYBRIDGE_S_GT1_IG 0x015A 236#define PCI_DEVICE_ID_INTEL_IVYBRIDGE_S_GT1_IG 0x015A
237#define PCI_DEVICE_ID_INTEL_IVYBRIDGE_S_GT2_IG 0x016A
237 238
238int intel_gmch_probe(struct pci_dev *pdev, 239int intel_gmch_probe(struct pci_dev *pdev,
239 struct agp_bridge_data *bridge); 240 struct agp_bridge_data *bridge);
diff --git a/drivers/char/agp/intel-gtt.c b/drivers/char/agp/intel-gtt.c
index 5cf47ac2d401..7f025fb620de 100644
--- a/drivers/char/agp/intel-gtt.c
+++ b/drivers/char/agp/intel-gtt.c
@@ -1190,7 +1190,6 @@ static inline int needs_idle_maps(void)
1190{ 1190{
1191#ifdef CONFIG_INTEL_IOMMU 1191#ifdef CONFIG_INTEL_IOMMU
1192 const unsigned short gpu_devid = intel_private.pcidev->device; 1192 const unsigned short gpu_devid = intel_private.pcidev->device;
1193 extern int intel_iommu_gfx_mapped;
1194 1193
1195 /* Query intel_iommu to see if we need the workaround. Presumably that 1194 /* Query intel_iommu to see if we need the workaround. Presumably that
1196 * was loaded first. 1195 * was loaded first.
@@ -1459,6 +1458,8 @@ static const struct intel_gtt_driver_description {
1459 "Ivybridge", &sandybridge_gtt_driver }, 1458 "Ivybridge", &sandybridge_gtt_driver },
1460 { PCI_DEVICE_ID_INTEL_IVYBRIDGE_S_GT1_IG, 1459 { PCI_DEVICE_ID_INTEL_IVYBRIDGE_S_GT1_IG,
1461 "Ivybridge", &sandybridge_gtt_driver }, 1460 "Ivybridge", &sandybridge_gtt_driver },
1461 { PCI_DEVICE_ID_INTEL_IVYBRIDGE_S_GT2_IG,
1462 "Ivybridge", &sandybridge_gtt_driver },
1462 { 0, NULL, NULL } 1463 { 0, NULL, NULL }
1463}; 1464};
1464 1465
diff --git a/drivers/char/apm-emulation.c b/drivers/char/apm-emulation.c
index 57501ca9204b..46118f845948 100644
--- a/drivers/char/apm-emulation.c
+++ b/drivers/char/apm-emulation.c
@@ -301,7 +301,7 @@ apm_ioctl(struct file *filp, u_int cmd, u_long arg)
301 * anything critical, chill a bit on each iteration. 301 * anything critical, chill a bit on each iteration.
302 */ 302 */
303 while (wait_event_freezable(apm_suspend_waitqueue, 303 while (wait_event_freezable(apm_suspend_waitqueue,
304 as->suspend_state == SUSPEND_DONE)) 304 as->suspend_state != SUSPEND_ACKED))
305 msleep(10); 305 msleep(10);
306 break; 306 break;
307 case SUSPEND_ACKTO: 307 case SUSPEND_ACKTO:
diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
index 3845ab44c330..dfd7876f127c 100644
--- a/drivers/char/hpet.c
+++ b/drivers/char/hpet.c
@@ -906,8 +906,8 @@ int hpet_alloc(struct hpet_data *hdp)
906 hpetp->hp_which, hdp->hd_phys_address, 906 hpetp->hp_which, hdp->hd_phys_address,
907 hpetp->hp_ntimer > 1 ? "s" : ""); 907 hpetp->hp_ntimer > 1 ? "s" : "");
908 for (i = 0; i < hpetp->hp_ntimer; i++) 908 for (i = 0; i < hpetp->hp_ntimer; i++)
909 printk("%s %d", i > 0 ? "," : "", hdp->hd_irq[i]); 909 printk(KERN_CONT "%s %d", i > 0 ? "," : "", hdp->hd_irq[i]);
910 printk("\n"); 910 printk(KERN_CONT "\n");
911 911
912 temp = hpetp->hp_tick_freq; 912 temp = hpetp->hp_tick_freq;
913 remainder = do_div(temp, 1000000); 913 remainder = do_div(temp, 1000000);
diff --git a/drivers/char/random.c b/drivers/char/random.c
index 54ca8b23cde3..4ec04a754733 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -1260,10 +1260,15 @@ static int proc_do_uuid(ctl_table *table, int write,
1260 uuid = table->data; 1260 uuid = table->data;
1261 if (!uuid) { 1261 if (!uuid) {
1262 uuid = tmp_uuid; 1262 uuid = tmp_uuid;
1263 uuid[8] = 0;
1264 }
1265 if (uuid[8] == 0)
1266 generate_random_uuid(uuid); 1263 generate_random_uuid(uuid);
1264 } else {
1265 static DEFINE_SPINLOCK(bootid_spinlock);
1266
1267 spin_lock(&bootid_spinlock);
1268 if (!uuid[8])
1269 generate_random_uuid(uuid);
1270 spin_unlock(&bootid_spinlock);
1271 }
1267 1272
1268 sprintf(buf, "%pU", uuid); 1273 sprintf(buf, "%pU", uuid);
1269 1274
diff --git a/drivers/char/tile-srom.c b/drivers/char/tile-srom.c
index 4dc019408fac..3b22a606f79d 100644
--- a/drivers/char/tile-srom.c
+++ b/drivers/char/tile-srom.c
@@ -194,17 +194,17 @@ static ssize_t srom_read(struct file *filp, char __user *buf,
194 194
195 hv_retval = _srom_read(srom->hv_devhdl, kernbuf, 195 hv_retval = _srom_read(srom->hv_devhdl, kernbuf,
196 *f_pos, bytes_this_pass); 196 *f_pos, bytes_this_pass);
197 if (hv_retval > 0) { 197 if (hv_retval <= 0) {
198 if (copy_to_user(buf, kernbuf, hv_retval) != 0) {
199 retval = -EFAULT;
200 break;
201 }
202 } else if (hv_retval <= 0) {
203 if (retval == 0) 198 if (retval == 0)
204 retval = hv_retval; 199 retval = hv_retval;
205 break; 200 break;
206 } 201 }
207 202
203 if (copy_to_user(buf, kernbuf, hv_retval) != 0) {
204 retval = -EFAULT;
205 break;
206 }
207
208 retval += hv_retval; 208 retval += hv_retval;
209 *f_pos += hv_retval; 209 *f_pos += hv_retval;
210 buf += hv_retval; 210 buf += hv_retval;
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index b58b56187065..ddf86b6500b7 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -1038,12 +1038,6 @@ static struct attribute_group port_attribute_group = {
1038 .attrs = port_sysfs_entries, 1038 .attrs = port_sysfs_entries,
1039}; 1039};
1040 1040
1041static int debugfs_open(struct inode *inode, struct file *filp)
1042{
1043 filp->private_data = inode->i_private;
1044 return 0;
1045}
1046
1047static ssize_t debugfs_read(struct file *filp, char __user *ubuf, 1041static ssize_t debugfs_read(struct file *filp, char __user *ubuf,
1048 size_t count, loff_t *offp) 1042 size_t count, loff_t *offp)
1049{ 1043{
@@ -1087,7 +1081,7 @@ static ssize_t debugfs_read(struct file *filp, char __user *ubuf,
1087 1081
1088static const struct file_operations port_debugfs_ops = { 1082static const struct file_operations port_debugfs_ops = {
1089 .owner = THIS_MODULE, 1083 .owner = THIS_MODULE,
1090 .open = debugfs_open, 1084 .open = simple_open,
1091 .read = debugfs_read, 1085 .read = debugfs_read,
1092}; 1086};
1093 1087
diff --git a/drivers/clocksource/acpi_pm.c b/drivers/clocksource/acpi_pm.c
index 82e882028fcf..6b5cf02c35c8 100644
--- a/drivers/clocksource/acpi_pm.c
+++ b/drivers/clocksource/acpi_pm.c
@@ -23,7 +23,6 @@
23#include <linux/init.h> 23#include <linux/init.h>
24#include <linux/pci.h> 24#include <linux/pci.h>
25#include <linux/delay.h> 25#include <linux/delay.h>
26#include <linux/async.h>
27#include <asm/io.h> 26#include <asm/io.h>
28 27
29/* 28/*
@@ -180,15 +179,17 @@ static int verify_pmtmr_rate(void)
180/* Number of reads we try to get two different values */ 179/* Number of reads we try to get two different values */
181#define ACPI_PM_READ_CHECKS 10000 180#define ACPI_PM_READ_CHECKS 10000
182 181
183static void __init acpi_pm_clocksource_async(void *unused, async_cookie_t cookie) 182static int __init init_acpi_pm_clocksource(void)
184{ 183{
185 cycle_t value1, value2; 184 cycle_t value1, value2;
186 unsigned int i, j = 0; 185 unsigned int i, j = 0;
187 186
187 if (!pmtmr_ioport)
188 return -ENODEV;
188 189
189 /* "verify" this timing source: */ 190 /* "verify" this timing source: */
190 for (j = 0; j < ACPI_PM_MONOTONICITY_CHECKS; j++) { 191 for (j = 0; j < ACPI_PM_MONOTONICITY_CHECKS; j++) {
191 usleep_range(100 * j, 100 * j + 100); 192 udelay(100 * j);
192 value1 = clocksource_acpi_pm.read(&clocksource_acpi_pm); 193 value1 = clocksource_acpi_pm.read(&clocksource_acpi_pm);
193 for (i = 0; i < ACPI_PM_READ_CHECKS; i++) { 194 for (i = 0; i < ACPI_PM_READ_CHECKS; i++) {
194 value2 = clocksource_acpi_pm.read(&clocksource_acpi_pm); 195 value2 = clocksource_acpi_pm.read(&clocksource_acpi_pm);
@@ -202,34 +203,25 @@ static void __init acpi_pm_clocksource_async(void *unused, async_cookie_t cookie
202 " 0x%#llx, 0x%#llx - aborting.\n", 203 " 0x%#llx, 0x%#llx - aborting.\n",
203 value1, value2); 204 value1, value2);
204 pmtmr_ioport = 0; 205 pmtmr_ioport = 0;
205 return; 206 return -EINVAL;
206 } 207 }
207 if (i == ACPI_PM_READ_CHECKS) { 208 if (i == ACPI_PM_READ_CHECKS) {
208 printk(KERN_INFO "PM-Timer failed consistency check " 209 printk(KERN_INFO "PM-Timer failed consistency check "
209 " (0x%#llx) - aborting.\n", value1); 210 " (0x%#llx) - aborting.\n", value1);
210 pmtmr_ioport = 0; 211 pmtmr_ioport = 0;
211 return; 212 return -ENODEV;
212 } 213 }
213 } 214 }
214 215
215 if (verify_pmtmr_rate() != 0){ 216 if (verify_pmtmr_rate() != 0){
216 pmtmr_ioport = 0; 217 pmtmr_ioport = 0;
217 return; 218 return -ENODEV;
218 } 219 }
219 220
220 clocksource_register_hz(&clocksource_acpi_pm, 221 return clocksource_register_hz(&clocksource_acpi_pm,
221 PMTMR_TICKS_PER_SEC); 222 PMTMR_TICKS_PER_SEC);
222} 223}
223 224
224static int __init init_acpi_pm_clocksource(void)
225{
226 if (!pmtmr_ioport)
227 return -ENODEV;
228
229 async_schedule(acpi_pm_clocksource_async, NULL);
230 return 0;
231}
232
233/* We use fs_initcall because we want the PCI fixups to have run 225/* We use fs_initcall because we want the PCI fixups to have run
234 * but we still need to load before device_initcall 226 * but we still need to load before device_initcall
235 */ 227 */
diff --git a/drivers/cpufreq/Kconfig.arm b/drivers/cpufreq/Kconfig.arm
index 32d790dd8180..5961e6415f08 100644
--- a/drivers/cpufreq/Kconfig.arm
+++ b/drivers/cpufreq/Kconfig.arm
@@ -4,6 +4,7 @@
4 4
5config ARM_OMAP2PLUS_CPUFREQ 5config ARM_OMAP2PLUS_CPUFREQ
6 bool "TI OMAP2+" 6 bool "TI OMAP2+"
7 depends on ARCH_OMAP2PLUS
7 default ARCH_OMAP2PLUS 8 default ARCH_OMAP2PLUS
8 select CPU_FREQ_TABLE 9 select CPU_FREQ_TABLE
9 10
@@ -51,9 +52,6 @@ config ARM_S5PV210_CPUFREQ
51config ARM_EXYNOS_CPUFREQ 52config ARM_EXYNOS_CPUFREQ
52 bool "SAMSUNG EXYNOS SoCs" 53 bool "SAMSUNG EXYNOS SoCs"
53 depends on ARCH_EXYNOS 54 depends on ARCH_EXYNOS
54 select ARM_EXYNOS4210_CPUFREQ if CPU_EXYNOS4210
55 select ARM_EXYNOS4X12_CPUFREQ if (SOC_EXYNOS4212 || SOC_EXYNOS4412)
56 select ARM_EXYNOS5250_CPUFREQ if SOC_EXYNOS5250
57 default y 55 default y
58 help 56 help
59 This adds the CPUFreq driver common part for Samsung 57 This adds the CPUFreq driver common part for Samsung
@@ -62,20 +60,19 @@ config ARM_EXYNOS_CPUFREQ
62 If in doubt, say N. 60 If in doubt, say N.
63 61
64config ARM_EXYNOS4210_CPUFREQ 62config ARM_EXYNOS4210_CPUFREQ
65 bool "Samsung EXYNOS4210" 63 def_bool CPU_EXYNOS4210
66 depends on ARCH_EXYNOS
67 help 64 help
68 This adds the CPUFreq driver for Samsung EXYNOS4210 65 This adds the CPUFreq driver for Samsung EXYNOS4210
69 SoC (S5PV310 or S5PC210). 66 SoC (S5PV310 or S5PC210).
70 67
71config ARM_EXYNOS4X12_CPUFREQ 68config ARM_EXYNOS4X12_CPUFREQ
72 bool "Samsung EXYNOS4X12" 69 def_bool (SOC_EXYNOS4212 || SOC_EXYNOS4412)
73 help 70 help
74 This adds the CPUFreq driver for Samsung EXYNOS4X12 71 This adds the CPUFreq driver for Samsung EXYNOS4X12
75 SoC (EXYNOS4212 or EXYNOS4412). 72 SoC (EXYNOS4212 or EXYNOS4412).
76 73
77config ARM_EXYNOS5250_CPUFREQ 74config ARM_EXYNOS5250_CPUFREQ
78 bool "Samsung EXYNOS5250" 75 def_bool SOC_EXYNOS5250
79 help 76 help
80 This adds the CPUFreq driver for Samsung EXYNOS5250 77 This adds the CPUFreq driver for Samsung EXYNOS5250
81 SoC. 78 SoC.
diff --git a/drivers/cpufreq/db8500-cpufreq.c b/drivers/cpufreq/db8500-cpufreq.c
index a22ffa5bff9f..0bf1b8910eeb 100644
--- a/drivers/cpufreq/db8500-cpufreq.c
+++ b/drivers/cpufreq/db8500-cpufreq.c
@@ -142,7 +142,7 @@ static int __cpuinit db8500_cpufreq_init(struct cpufreq_policy *policy)
142 policy->cpuinfo.transition_latency = 20 * 1000; /* in ns */ 142 policy->cpuinfo.transition_latency = 20 * 1000; /* in ns */
143 143
144 /* policy sharing between dual CPUs */ 144 /* policy sharing between dual CPUs */
145 cpumask_copy(policy->cpus, &cpu_present_map); 145 cpumask_copy(policy->cpus, cpu_present_mask);
146 146
147 policy->shared_type = CPUFREQ_SHARED_TYPE_ALL; 147 policy->shared_type = CPUFREQ_SHARED_TYPE_ALL;
148 148
diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
index 87411cebc577..2f0083a51a9a 100644
--- a/drivers/cpuidle/cpuidle.c
+++ b/drivers/cpuidle/cpuidle.c
@@ -74,7 +74,7 @@ static cpuidle_enter_t cpuidle_enter_ops;
74/** 74/**
75 * cpuidle_play_dead - cpu off-lining 75 * cpuidle_play_dead - cpu off-lining
76 * 76 *
77 * Only returns in case of an error 77 * Returns in case of an error or no driver
78 */ 78 */
79int cpuidle_play_dead(void) 79int cpuidle_play_dead(void)
80{ 80{
@@ -83,6 +83,9 @@ int cpuidle_play_dead(void)
83 int i, dead_state = -1; 83 int i, dead_state = -1;
84 int power_usage = -1; 84 int power_usage = -1;
85 85
86 if (!drv)
87 return -ENODEV;
88
86 /* Find lowest-power state that supports long-term idle */ 89 /* Find lowest-power state that supports long-term idle */
87 for (i = CPUIDLE_DRIVER_STATE_START; i < drv->state_count; i++) { 90 for (i = CPUIDLE_DRIVER_STATE_START; i < drv->state_count; i++) {
88 struct cpuidle_state *s = &drv->states[i]; 91 struct cpuidle_state *s = &drv->states[i];
diff --git a/drivers/crypto/ixp4xx_crypto.c b/drivers/crypto/ixp4xx_crypto.c
index 0053d7ebb5ca..8f3f74ce8c7f 100644
--- a/drivers/crypto/ixp4xx_crypto.c
+++ b/drivers/crypto/ixp4xx_crypto.c
@@ -18,6 +18,7 @@
18#include <linux/interrupt.h> 18#include <linux/interrupt.h>
19#include <linux/spinlock.h> 19#include <linux/spinlock.h>
20#include <linux/gfp.h> 20#include <linux/gfp.h>
21#include <linux/module.h>
21 22
22#include <crypto/ctr.h> 23#include <crypto/ctr.h>
23#include <crypto/des.h> 24#include <crypto/des.h>
diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c
index dc641c796526..921039e56f87 100644
--- a/drivers/crypto/talitos.c
+++ b/drivers/crypto/talitos.c
@@ -124,6 +124,9 @@ struct talitos_private {
124 void __iomem *reg; 124 void __iomem *reg;
125 int irq[2]; 125 int irq[2];
126 126
127 /* SEC global registers lock */
128 spinlock_t reg_lock ____cacheline_aligned;
129
127 /* SEC version geometry (from device tree node) */ 130 /* SEC version geometry (from device tree node) */
128 unsigned int num_channels; 131 unsigned int num_channels;
129 unsigned int chfifo_len; 132 unsigned int chfifo_len;
@@ -412,6 +415,7 @@ static void talitos_done_##name(unsigned long data) \
412{ \ 415{ \
413 struct device *dev = (struct device *)data; \ 416 struct device *dev = (struct device *)data; \
414 struct talitos_private *priv = dev_get_drvdata(dev); \ 417 struct talitos_private *priv = dev_get_drvdata(dev); \
418 unsigned long flags; \
415 \ 419 \
416 if (ch_done_mask & 1) \ 420 if (ch_done_mask & 1) \
417 flush_channel(dev, 0, 0, 0); \ 421 flush_channel(dev, 0, 0, 0); \
@@ -427,8 +431,10 @@ static void talitos_done_##name(unsigned long data) \
427out: \ 431out: \
428 /* At this point, all completed channels have been processed */ \ 432 /* At this point, all completed channels have been processed */ \
429 /* Unmask done interrupts for channels completed later on. */ \ 433 /* Unmask done interrupts for channels completed later on. */ \
434 spin_lock_irqsave(&priv->reg_lock, flags); \
430 setbits32(priv->reg + TALITOS_IMR, ch_done_mask); \ 435 setbits32(priv->reg + TALITOS_IMR, ch_done_mask); \
431 setbits32(priv->reg + TALITOS_IMR_LO, TALITOS_IMR_LO_INIT); \ 436 setbits32(priv->reg + TALITOS_IMR_LO, TALITOS_IMR_LO_INIT); \
437 spin_unlock_irqrestore(&priv->reg_lock, flags); \
432} 438}
433DEF_TALITOS_DONE(4ch, TALITOS_ISR_4CHDONE) 439DEF_TALITOS_DONE(4ch, TALITOS_ISR_4CHDONE)
434DEF_TALITOS_DONE(ch0_2, TALITOS_ISR_CH_0_2_DONE) 440DEF_TALITOS_DONE(ch0_2, TALITOS_ISR_CH_0_2_DONE)
@@ -619,22 +625,28 @@ static irqreturn_t talitos_interrupt_##name(int irq, void *data) \
619 struct device *dev = data; \ 625 struct device *dev = data; \
620 struct talitos_private *priv = dev_get_drvdata(dev); \ 626 struct talitos_private *priv = dev_get_drvdata(dev); \
621 u32 isr, isr_lo; \ 627 u32 isr, isr_lo; \
628 unsigned long flags; \
622 \ 629 \
630 spin_lock_irqsave(&priv->reg_lock, flags); \
623 isr = in_be32(priv->reg + TALITOS_ISR); \ 631 isr = in_be32(priv->reg + TALITOS_ISR); \
624 isr_lo = in_be32(priv->reg + TALITOS_ISR_LO); \ 632 isr_lo = in_be32(priv->reg + TALITOS_ISR_LO); \
625 /* Acknowledge interrupt */ \ 633 /* Acknowledge interrupt */ \
626 out_be32(priv->reg + TALITOS_ICR, isr & (ch_done_mask | ch_err_mask)); \ 634 out_be32(priv->reg + TALITOS_ICR, isr & (ch_done_mask | ch_err_mask)); \
627 out_be32(priv->reg + TALITOS_ICR_LO, isr_lo); \ 635 out_be32(priv->reg + TALITOS_ICR_LO, isr_lo); \
628 \ 636 \
629 if (unlikely((isr & ~TALITOS_ISR_4CHDONE) & ch_err_mask || isr_lo)) \ 637 if (unlikely(isr & ch_err_mask || isr_lo)) { \
630 talitos_error(dev, isr, isr_lo); \ 638 spin_unlock_irqrestore(&priv->reg_lock, flags); \
631 else \ 639 talitos_error(dev, isr & ch_err_mask, isr_lo); \
640 } \
641 else { \
632 if (likely(isr & ch_done_mask)) { \ 642 if (likely(isr & ch_done_mask)) { \
633 /* mask further done interrupts. */ \ 643 /* mask further done interrupts. */ \
634 clrbits32(priv->reg + TALITOS_IMR, ch_done_mask); \ 644 clrbits32(priv->reg + TALITOS_IMR, ch_done_mask); \
635 /* done_task will unmask done interrupts at exit */ \ 645 /* done_task will unmask done interrupts at exit */ \
636 tasklet_schedule(&priv->done_task[tlet]); \ 646 tasklet_schedule(&priv->done_task[tlet]); \
637 } \ 647 } \
648 spin_unlock_irqrestore(&priv->reg_lock, flags); \
649 } \
638 \ 650 \
639 return (isr & (ch_done_mask | ch_err_mask) || isr_lo) ? IRQ_HANDLED : \ 651 return (isr & (ch_done_mask | ch_err_mask) || isr_lo) ? IRQ_HANDLED : \
640 IRQ_NONE; \ 652 IRQ_NONE; \
@@ -2719,6 +2731,8 @@ static int talitos_probe(struct platform_device *ofdev)
2719 2731
2720 priv->ofdev = ofdev; 2732 priv->ofdev = ofdev;
2721 2733
2734 spin_lock_init(&priv->reg_lock);
2735
2722 err = talitos_probe_irq(ofdev); 2736 err = talitos_probe_irq(ofdev);
2723 if (err) 2737 if (err)
2724 goto err_out; 2738 goto err_out;
diff --git a/drivers/dma/Kconfig b/drivers/dma/Kconfig
index cf9da362d64f..ef378b5b17e4 100644
--- a/drivers/dma/Kconfig
+++ b/drivers/dma/Kconfig
@@ -91,11 +91,10 @@ config DW_DMAC
91 91
92config AT_HDMAC 92config AT_HDMAC
93 tristate "Atmel AHB DMA support" 93 tristate "Atmel AHB DMA support"
94 depends on ARCH_AT91SAM9RL || ARCH_AT91SAM9G45 94 depends on ARCH_AT91
95 select DMA_ENGINE 95 select DMA_ENGINE
96 help 96 help
97 Support the Atmel AHB DMA controller. This can be integrated in 97 Support the Atmel AHB DMA controller.
98 chips such as the Atmel AT91SAM9RL.
99 98
100config FSL_DMA 99config FSL_DMA
101 tristate "Freescale Elo and Elo Plus DMA support" 100 tristate "Freescale Elo and Elo Plus DMA support"
diff --git a/drivers/dma/amba-pl08x.c b/drivers/dma/amba-pl08x.c
index c301a8ec31aa..3d704abd7912 100644
--- a/drivers/dma/amba-pl08x.c
+++ b/drivers/dma/amba-pl08x.c
@@ -1429,6 +1429,7 @@ static int pl08x_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
1429 * signal 1429 * signal
1430 */ 1430 */
1431 release_phy_channel(plchan); 1431 release_phy_channel(plchan);
1432 plchan->phychan_hold = 0;
1432 } 1433 }
1433 /* Dequeue jobs and free LLIs */ 1434 /* Dequeue jobs and free LLIs */
1434 if (plchan->at) { 1435 if (plchan->at) {
diff --git a/drivers/dma/at_hdmac.c b/drivers/dma/at_hdmac.c
index 7aa58d204892..445fdf811695 100644
--- a/drivers/dma/at_hdmac.c
+++ b/drivers/dma/at_hdmac.c
@@ -221,10 +221,6 @@ static void atc_dostart(struct at_dma_chan *atchan, struct at_desc *first)
221 221
222 vdbg_dump_regs(atchan); 222 vdbg_dump_regs(atchan);
223 223
224 /* clear any pending interrupt */
225 while (dma_readl(atdma, EBCISR))
226 cpu_relax();
227
228 channel_writel(atchan, SADDR, 0); 224 channel_writel(atchan, SADDR, 0);
229 channel_writel(atchan, DADDR, 0); 225 channel_writel(atchan, DADDR, 0);
230 channel_writel(atchan, CTRLA, 0); 226 channel_writel(atchan, CTRLA, 0);
diff --git a/drivers/dma/coh901318.c b/drivers/dma/coh901318.c
index dc89455f5550..750925f9638b 100644
--- a/drivers/dma/coh901318.c
+++ b/drivers/dma/coh901318.c
@@ -104,13 +104,6 @@ static void coh901318_list_print(struct coh901318_chan *cohc,
104static struct coh901318_base *debugfs_dma_base; 104static struct coh901318_base *debugfs_dma_base;
105static struct dentry *dma_dentry; 105static struct dentry *dma_dentry;
106 106
107static int coh901318_debugfs_open(struct inode *inode, struct file *file)
108{
109
110 file->private_data = inode->i_private;
111 return 0;
112}
113
114static int coh901318_debugfs_read(struct file *file, char __user *buf, 107static int coh901318_debugfs_read(struct file *file, char __user *buf,
115 size_t count, loff_t *f_pos) 108 size_t count, loff_t *f_pos)
116{ 109{
@@ -158,7 +151,7 @@ static int coh901318_debugfs_read(struct file *file, char __user *buf,
158 151
159static const struct file_operations coh901318_debugfs_status_operations = { 152static const struct file_operations coh901318_debugfs_status_operations = {
160 .owner = THIS_MODULE, 153 .owner = THIS_MODULE,
161 .open = coh901318_debugfs_open, 154 .open = simple_open,
162 .read = coh901318_debugfs_read, 155 .read = coh901318_debugfs_read,
163 .llseek = default_llseek, 156 .llseek = default_llseek,
164}; 157};
diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
index 767bcc31b365..2397f6f451b1 100644
--- a/drivers/dma/dmaengine.c
+++ b/drivers/dma/dmaengine.c
@@ -332,6 +332,20 @@ struct dma_chan *dma_find_channel(enum dma_transaction_type tx_type)
332} 332}
333EXPORT_SYMBOL(dma_find_channel); 333EXPORT_SYMBOL(dma_find_channel);
334 334
335/*
336 * net_dma_find_channel - find a channel for net_dma
337 * net_dma has alignment requirements
338 */
339struct dma_chan *net_dma_find_channel(void)
340{
341 struct dma_chan *chan = dma_find_channel(DMA_MEMCPY);
342 if (chan && !is_dma_copy_aligned(chan->device, 1, 1, 1))
343 return NULL;
344
345 return chan;
346}
347EXPORT_SYMBOL(net_dma_find_channel);
348
335/** 349/**
336 * dma_issue_pending_all - flush all pending operations across all channels 350 * dma_issue_pending_all - flush all pending operations across all channels
337 */ 351 */
diff --git a/drivers/dma/imx-dma.c b/drivers/dma/imx-dma.c
index a45b5d2a5987..bb787d8e1529 100644
--- a/drivers/dma/imx-dma.c
+++ b/drivers/dma/imx-dma.c
@@ -571,11 +571,14 @@ static void imxdma_tasklet(unsigned long data)
571 if (desc->desc.callback) 571 if (desc->desc.callback)
572 desc->desc.callback(desc->desc.callback_param); 572 desc->desc.callback(desc->desc.callback_param);
573 573
574 dma_cookie_complete(&desc->desc); 574 /* If we are dealing with a cyclic descriptor keep it on ld_active
575 575 * and dont mark the descripor as complete.
576 /* If we are dealing with a cyclic descriptor keep it on ld_active */ 576 * Only in non-cyclic cases it would be marked as complete
577 */
577 if (imxdma_chan_is_doing_cyclic(imxdmac)) 578 if (imxdma_chan_is_doing_cyclic(imxdmac))
578 goto out; 579 goto out;
580 else
581 dma_cookie_complete(&desc->desc);
579 582
580 /* Free 2D slot if it was an interleaved transfer */ 583 /* Free 2D slot if it was an interleaved transfer */
581 if (imxdmac->enabled_2d) { 584 if (imxdmac->enabled_2d) {
diff --git a/drivers/dma/ioat/dma.c b/drivers/dma/ioat/dma.c
index 31493d80e0e9..73b2b65cb1de 100644
--- a/drivers/dma/ioat/dma.c
+++ b/drivers/dma/ioat/dma.c
@@ -546,9 +546,9 @@ void ioat_dma_unmap(struct ioat_chan_common *chan, enum dma_ctrl_flags flags,
546 PCI_DMA_TODEVICE, flags, 0); 546 PCI_DMA_TODEVICE, flags, 0);
547} 547}
548 548
549unsigned long ioat_get_current_completion(struct ioat_chan_common *chan) 549dma_addr_t ioat_get_current_completion(struct ioat_chan_common *chan)
550{ 550{
551 unsigned long phys_complete; 551 dma_addr_t phys_complete;
552 u64 completion; 552 u64 completion;
553 553
554 completion = *chan->completion; 554 completion = *chan->completion;
@@ -569,7 +569,7 @@ unsigned long ioat_get_current_completion(struct ioat_chan_common *chan)
569} 569}
570 570
571bool ioat_cleanup_preamble(struct ioat_chan_common *chan, 571bool ioat_cleanup_preamble(struct ioat_chan_common *chan,
572 unsigned long *phys_complete) 572 dma_addr_t *phys_complete)
573{ 573{
574 *phys_complete = ioat_get_current_completion(chan); 574 *phys_complete = ioat_get_current_completion(chan);
575 if (*phys_complete == chan->last_completion) 575 if (*phys_complete == chan->last_completion)
@@ -580,14 +580,14 @@ bool ioat_cleanup_preamble(struct ioat_chan_common *chan,
580 return true; 580 return true;
581} 581}
582 582
583static void __cleanup(struct ioat_dma_chan *ioat, unsigned long phys_complete) 583static void __cleanup(struct ioat_dma_chan *ioat, dma_addr_t phys_complete)
584{ 584{
585 struct ioat_chan_common *chan = &ioat->base; 585 struct ioat_chan_common *chan = &ioat->base;
586 struct list_head *_desc, *n; 586 struct list_head *_desc, *n;
587 struct dma_async_tx_descriptor *tx; 587 struct dma_async_tx_descriptor *tx;
588 588
589 dev_dbg(to_dev(chan), "%s: phys_complete: %lx\n", 589 dev_dbg(to_dev(chan), "%s: phys_complete: %llx\n",
590 __func__, phys_complete); 590 __func__, (unsigned long long) phys_complete);
591 list_for_each_safe(_desc, n, &ioat->used_desc) { 591 list_for_each_safe(_desc, n, &ioat->used_desc) {
592 struct ioat_desc_sw *desc; 592 struct ioat_desc_sw *desc;
593 593
@@ -652,7 +652,7 @@ static void __cleanup(struct ioat_dma_chan *ioat, unsigned long phys_complete)
652static void ioat1_cleanup(struct ioat_dma_chan *ioat) 652static void ioat1_cleanup(struct ioat_dma_chan *ioat)
653{ 653{
654 struct ioat_chan_common *chan = &ioat->base; 654 struct ioat_chan_common *chan = &ioat->base;
655 unsigned long phys_complete; 655 dma_addr_t phys_complete;
656 656
657 prefetch(chan->completion); 657 prefetch(chan->completion);
658 658
@@ -698,7 +698,7 @@ static void ioat1_timer_event(unsigned long data)
698 mod_timer(&chan->timer, jiffies + COMPLETION_TIMEOUT); 698 mod_timer(&chan->timer, jiffies + COMPLETION_TIMEOUT);
699 spin_unlock_bh(&ioat->desc_lock); 699 spin_unlock_bh(&ioat->desc_lock);
700 } else if (test_bit(IOAT_COMPLETION_PENDING, &chan->state)) { 700 } else if (test_bit(IOAT_COMPLETION_PENDING, &chan->state)) {
701 unsigned long phys_complete; 701 dma_addr_t phys_complete;
702 702
703 spin_lock_bh(&ioat->desc_lock); 703 spin_lock_bh(&ioat->desc_lock);
704 /* if we haven't made progress and we have already 704 /* if we haven't made progress and we have already
diff --git a/drivers/dma/ioat/dma.h b/drivers/dma/ioat/dma.h
index c7888bccd974..5e8fe01ba69d 100644
--- a/drivers/dma/ioat/dma.h
+++ b/drivers/dma/ioat/dma.h
@@ -88,7 +88,7 @@ struct ioatdma_device {
88struct ioat_chan_common { 88struct ioat_chan_common {
89 struct dma_chan common; 89 struct dma_chan common;
90 void __iomem *reg_base; 90 void __iomem *reg_base;
91 unsigned long last_completion; 91 dma_addr_t last_completion;
92 spinlock_t cleanup_lock; 92 spinlock_t cleanup_lock;
93 unsigned long state; 93 unsigned long state;
94 #define IOAT_COMPLETION_PENDING 0 94 #define IOAT_COMPLETION_PENDING 0
@@ -310,7 +310,7 @@ int __devinit ioat_dma_self_test(struct ioatdma_device *device);
310void __devexit ioat_dma_remove(struct ioatdma_device *device); 310void __devexit ioat_dma_remove(struct ioatdma_device *device);
311struct dca_provider * __devinit ioat_dca_init(struct pci_dev *pdev, 311struct dca_provider * __devinit ioat_dca_init(struct pci_dev *pdev,
312 void __iomem *iobase); 312 void __iomem *iobase);
313unsigned long ioat_get_current_completion(struct ioat_chan_common *chan); 313dma_addr_t ioat_get_current_completion(struct ioat_chan_common *chan);
314void ioat_init_channel(struct ioatdma_device *device, 314void ioat_init_channel(struct ioatdma_device *device,
315 struct ioat_chan_common *chan, int idx); 315 struct ioat_chan_common *chan, int idx);
316enum dma_status ioat_dma_tx_status(struct dma_chan *c, dma_cookie_t cookie, 316enum dma_status ioat_dma_tx_status(struct dma_chan *c, dma_cookie_t cookie,
@@ -318,7 +318,7 @@ enum dma_status ioat_dma_tx_status(struct dma_chan *c, dma_cookie_t cookie,
318void ioat_dma_unmap(struct ioat_chan_common *chan, enum dma_ctrl_flags flags, 318void ioat_dma_unmap(struct ioat_chan_common *chan, enum dma_ctrl_flags flags,
319 size_t len, struct ioat_dma_descriptor *hw); 319 size_t len, struct ioat_dma_descriptor *hw);
320bool ioat_cleanup_preamble(struct ioat_chan_common *chan, 320bool ioat_cleanup_preamble(struct ioat_chan_common *chan,
321 unsigned long *phys_complete); 321 dma_addr_t *phys_complete);
322void ioat_kobject_add(struct ioatdma_device *device, struct kobj_type *type); 322void ioat_kobject_add(struct ioatdma_device *device, struct kobj_type *type);
323void ioat_kobject_del(struct ioatdma_device *device); 323void ioat_kobject_del(struct ioatdma_device *device);
324extern const struct sysfs_ops ioat_sysfs_ops; 324extern const struct sysfs_ops ioat_sysfs_ops;
diff --git a/drivers/dma/ioat/dma_v2.c b/drivers/dma/ioat/dma_v2.c
index e8e110ff3d96..86895760b598 100644
--- a/drivers/dma/ioat/dma_v2.c
+++ b/drivers/dma/ioat/dma_v2.c
@@ -128,7 +128,7 @@ static void ioat2_start_null_desc(struct ioat2_dma_chan *ioat)
128 spin_unlock_bh(&ioat->prep_lock); 128 spin_unlock_bh(&ioat->prep_lock);
129} 129}
130 130
131static void __cleanup(struct ioat2_dma_chan *ioat, unsigned long phys_complete) 131static void __cleanup(struct ioat2_dma_chan *ioat, dma_addr_t phys_complete)
132{ 132{
133 struct ioat_chan_common *chan = &ioat->base; 133 struct ioat_chan_common *chan = &ioat->base;
134 struct dma_async_tx_descriptor *tx; 134 struct dma_async_tx_descriptor *tx;
@@ -179,7 +179,7 @@ static void __cleanup(struct ioat2_dma_chan *ioat, unsigned long phys_complete)
179static void ioat2_cleanup(struct ioat2_dma_chan *ioat) 179static void ioat2_cleanup(struct ioat2_dma_chan *ioat)
180{ 180{
181 struct ioat_chan_common *chan = &ioat->base; 181 struct ioat_chan_common *chan = &ioat->base;
182 unsigned long phys_complete; 182 dma_addr_t phys_complete;
183 183
184 spin_lock_bh(&chan->cleanup_lock); 184 spin_lock_bh(&chan->cleanup_lock);
185 if (ioat_cleanup_preamble(chan, &phys_complete)) 185 if (ioat_cleanup_preamble(chan, &phys_complete))
@@ -260,7 +260,7 @@ int ioat2_reset_sync(struct ioat_chan_common *chan, unsigned long tmo)
260static void ioat2_restart_channel(struct ioat2_dma_chan *ioat) 260static void ioat2_restart_channel(struct ioat2_dma_chan *ioat)
261{ 261{
262 struct ioat_chan_common *chan = &ioat->base; 262 struct ioat_chan_common *chan = &ioat->base;
263 unsigned long phys_complete; 263 dma_addr_t phys_complete;
264 264
265 ioat2_quiesce(chan, 0); 265 ioat2_quiesce(chan, 0);
266 if (ioat_cleanup_preamble(chan, &phys_complete)) 266 if (ioat_cleanup_preamble(chan, &phys_complete))
@@ -275,7 +275,7 @@ void ioat2_timer_event(unsigned long data)
275 struct ioat_chan_common *chan = &ioat->base; 275 struct ioat_chan_common *chan = &ioat->base;
276 276
277 if (test_bit(IOAT_COMPLETION_PENDING, &chan->state)) { 277 if (test_bit(IOAT_COMPLETION_PENDING, &chan->state)) {
278 unsigned long phys_complete; 278 dma_addr_t phys_complete;
279 u64 status; 279 u64 status;
280 280
281 status = ioat_chansts(chan); 281 status = ioat_chansts(chan);
@@ -572,9 +572,9 @@ bool reshape_ring(struct ioat2_dma_chan *ioat, int order)
572 */ 572 */
573 struct ioat_chan_common *chan = &ioat->base; 573 struct ioat_chan_common *chan = &ioat->base;
574 struct dma_chan *c = &chan->common; 574 struct dma_chan *c = &chan->common;
575 const u16 curr_size = ioat2_ring_size(ioat); 575 const u32 curr_size = ioat2_ring_size(ioat);
576 const u16 active = ioat2_ring_active(ioat); 576 const u16 active = ioat2_ring_active(ioat);
577 const u16 new_size = 1 << order; 577 const u32 new_size = 1 << order;
578 struct ioat_ring_ent **ring; 578 struct ioat_ring_ent **ring;
579 u16 i; 579 u16 i;
580 580
diff --git a/drivers/dma/ioat/dma_v2.h b/drivers/dma/ioat/dma_v2.h
index a2c413b2b8d8..be2a55b95c23 100644
--- a/drivers/dma/ioat/dma_v2.h
+++ b/drivers/dma/ioat/dma_v2.h
@@ -74,7 +74,7 @@ static inline struct ioat2_dma_chan *to_ioat2_chan(struct dma_chan *c)
74 return container_of(chan, struct ioat2_dma_chan, base); 74 return container_of(chan, struct ioat2_dma_chan, base);
75} 75}
76 76
77static inline u16 ioat2_ring_size(struct ioat2_dma_chan *ioat) 77static inline u32 ioat2_ring_size(struct ioat2_dma_chan *ioat)
78{ 78{
79 return 1 << ioat->alloc_order; 79 return 1 << ioat->alloc_order;
80} 80}
@@ -91,7 +91,7 @@ static inline u16 ioat2_ring_pending(struct ioat2_dma_chan *ioat)
91 return CIRC_CNT(ioat->head, ioat->issued, ioat2_ring_size(ioat)); 91 return CIRC_CNT(ioat->head, ioat->issued, ioat2_ring_size(ioat));
92} 92}
93 93
94static inline u16 ioat2_ring_space(struct ioat2_dma_chan *ioat) 94static inline u32 ioat2_ring_space(struct ioat2_dma_chan *ioat)
95{ 95{
96 return ioat2_ring_size(ioat) - ioat2_ring_active(ioat); 96 return ioat2_ring_size(ioat) - ioat2_ring_active(ioat);
97} 97}
diff --git a/drivers/dma/ioat/dma_v3.c b/drivers/dma/ioat/dma_v3.c
index 2c4476c0e405..f7f1dc62c15c 100644
--- a/drivers/dma/ioat/dma_v3.c
+++ b/drivers/dma/ioat/dma_v3.c
@@ -257,7 +257,7 @@ static bool desc_has_ext(struct ioat_ring_ent *desc)
257 * The difference from the dma_v2.c __cleanup() is that this routine 257 * The difference from the dma_v2.c __cleanup() is that this routine
258 * handles extended descriptors and dma-unmapping raid operations. 258 * handles extended descriptors and dma-unmapping raid operations.
259 */ 259 */
260static void __cleanup(struct ioat2_dma_chan *ioat, unsigned long phys_complete) 260static void __cleanup(struct ioat2_dma_chan *ioat, dma_addr_t phys_complete)
261{ 261{
262 struct ioat_chan_common *chan = &ioat->base; 262 struct ioat_chan_common *chan = &ioat->base;
263 struct ioat_ring_ent *desc; 263 struct ioat_ring_ent *desc;
@@ -314,7 +314,7 @@ static void __cleanup(struct ioat2_dma_chan *ioat, unsigned long phys_complete)
314static void ioat3_cleanup(struct ioat2_dma_chan *ioat) 314static void ioat3_cleanup(struct ioat2_dma_chan *ioat)
315{ 315{
316 struct ioat_chan_common *chan = &ioat->base; 316 struct ioat_chan_common *chan = &ioat->base;
317 unsigned long phys_complete; 317 dma_addr_t phys_complete;
318 318
319 spin_lock_bh(&chan->cleanup_lock); 319 spin_lock_bh(&chan->cleanup_lock);
320 if (ioat_cleanup_preamble(chan, &phys_complete)) 320 if (ioat_cleanup_preamble(chan, &phys_complete))
@@ -333,7 +333,7 @@ static void ioat3_cleanup_event(unsigned long data)
333static void ioat3_restart_channel(struct ioat2_dma_chan *ioat) 333static void ioat3_restart_channel(struct ioat2_dma_chan *ioat)
334{ 334{
335 struct ioat_chan_common *chan = &ioat->base; 335 struct ioat_chan_common *chan = &ioat->base;
336 unsigned long phys_complete; 336 dma_addr_t phys_complete;
337 337
338 ioat2_quiesce(chan, 0); 338 ioat2_quiesce(chan, 0);
339 if (ioat_cleanup_preamble(chan, &phys_complete)) 339 if (ioat_cleanup_preamble(chan, &phys_complete))
@@ -348,7 +348,7 @@ static void ioat3_timer_event(unsigned long data)
348 struct ioat_chan_common *chan = &ioat->base; 348 struct ioat_chan_common *chan = &ioat->base;
349 349
350 if (test_bit(IOAT_COMPLETION_PENDING, &chan->state)) { 350 if (test_bit(IOAT_COMPLETION_PENDING, &chan->state)) {
351 unsigned long phys_complete; 351 dma_addr_t phys_complete;
352 u64 status; 352 u64 status;
353 353
354 status = ioat_chansts(chan); 354 status = ioat_chansts(chan);
@@ -1149,6 +1149,44 @@ static int ioat3_reset_hw(struct ioat_chan_common *chan)
1149 return ioat2_reset_sync(chan, msecs_to_jiffies(200)); 1149 return ioat2_reset_sync(chan, msecs_to_jiffies(200));
1150} 1150}
1151 1151
1152static bool is_jf_ioat(struct pci_dev *pdev)
1153{
1154 switch (pdev->device) {
1155 case PCI_DEVICE_ID_INTEL_IOAT_JSF0:
1156 case PCI_DEVICE_ID_INTEL_IOAT_JSF1:
1157 case PCI_DEVICE_ID_INTEL_IOAT_JSF2:
1158 case PCI_DEVICE_ID_INTEL_IOAT_JSF3:
1159 case PCI_DEVICE_ID_INTEL_IOAT_JSF4:
1160 case PCI_DEVICE_ID_INTEL_IOAT_JSF5:
1161 case PCI_DEVICE_ID_INTEL_IOAT_JSF6:
1162 case PCI_DEVICE_ID_INTEL_IOAT_JSF7:
1163 case PCI_DEVICE_ID_INTEL_IOAT_JSF8:
1164 case PCI_DEVICE_ID_INTEL_IOAT_JSF9:
1165 return true;
1166 default:
1167 return false;
1168 }
1169}
1170
1171static bool is_snb_ioat(struct pci_dev *pdev)
1172{
1173 switch (pdev->device) {
1174 case PCI_DEVICE_ID_INTEL_IOAT_SNB0:
1175 case PCI_DEVICE_ID_INTEL_IOAT_SNB1:
1176 case PCI_DEVICE_ID_INTEL_IOAT_SNB2:
1177 case PCI_DEVICE_ID_INTEL_IOAT_SNB3:
1178 case PCI_DEVICE_ID_INTEL_IOAT_SNB4:
1179 case PCI_DEVICE_ID_INTEL_IOAT_SNB5:
1180 case PCI_DEVICE_ID_INTEL_IOAT_SNB6:
1181 case PCI_DEVICE_ID_INTEL_IOAT_SNB7:
1182 case PCI_DEVICE_ID_INTEL_IOAT_SNB8:
1183 case PCI_DEVICE_ID_INTEL_IOAT_SNB9:
1184 return true;
1185 default:
1186 return false;
1187 }
1188}
1189
1152int __devinit ioat3_dma_probe(struct ioatdma_device *device, int dca) 1190int __devinit ioat3_dma_probe(struct ioatdma_device *device, int dca)
1153{ 1191{
1154 struct pci_dev *pdev = device->pdev; 1192 struct pci_dev *pdev = device->pdev;
@@ -1169,6 +1207,9 @@ int __devinit ioat3_dma_probe(struct ioatdma_device *device, int dca)
1169 dma->device_alloc_chan_resources = ioat2_alloc_chan_resources; 1207 dma->device_alloc_chan_resources = ioat2_alloc_chan_resources;
1170 dma->device_free_chan_resources = ioat2_free_chan_resources; 1208 dma->device_free_chan_resources = ioat2_free_chan_resources;
1171 1209
1210 if (is_jf_ioat(pdev) || is_snb_ioat(pdev))
1211 dma->copy_align = 6;
1212
1172 dma_cap_set(DMA_INTERRUPT, dma->cap_mask); 1213 dma_cap_set(DMA_INTERRUPT, dma->cap_mask);
1173 dma->device_prep_dma_interrupt = ioat3_prep_interrupt_lock; 1214 dma->device_prep_dma_interrupt = ioat3_prep_interrupt_lock;
1174 1215
diff --git a/drivers/dma/iop-adma.c b/drivers/dma/iop-adma.c
index da6c4c2c066a..79e3eba29702 100644
--- a/drivers/dma/iop-adma.c
+++ b/drivers/dma/iop-adma.c
@@ -1252,8 +1252,8 @@ iop_adma_pq_zero_sum_self_test(struct iop_adma_device *device)
1252 struct page **pq_hw = &pq[IOP_ADMA_NUM_SRC_TEST+2]; 1252 struct page **pq_hw = &pq[IOP_ADMA_NUM_SRC_TEST+2];
1253 /* address conversion buffers (dma_map / page_address) */ 1253 /* address conversion buffers (dma_map / page_address) */
1254 void *pq_sw[IOP_ADMA_NUM_SRC_TEST+2]; 1254 void *pq_sw[IOP_ADMA_NUM_SRC_TEST+2];
1255 dma_addr_t pq_src[IOP_ADMA_NUM_SRC_TEST]; 1255 dma_addr_t pq_src[IOP_ADMA_NUM_SRC_TEST+2];
1256 dma_addr_t pq_dest[2]; 1256 dma_addr_t *pq_dest = &pq_src[IOP_ADMA_NUM_SRC_TEST];
1257 1257
1258 int i; 1258 int i;
1259 struct dma_async_tx_descriptor *tx; 1259 struct dma_async_tx_descriptor *tx;
diff --git a/drivers/dma/mxs-dma.c b/drivers/dma/mxs-dma.c
index c81ef7e10e08..655d4ce6ed0d 100644
--- a/drivers/dma/mxs-dma.c
+++ b/drivers/dma/mxs-dma.c
@@ -201,10 +201,6 @@ static struct mxs_dma_chan *to_mxs_dma_chan(struct dma_chan *chan)
201 201
202static dma_cookie_t mxs_dma_tx_submit(struct dma_async_tx_descriptor *tx) 202static dma_cookie_t mxs_dma_tx_submit(struct dma_async_tx_descriptor *tx)
203{ 203{
204 struct mxs_dma_chan *mxs_chan = to_mxs_dma_chan(tx->chan);
205
206 mxs_dma_enable_chan(mxs_chan);
207
208 return dma_cookie_assign(tx); 204 return dma_cookie_assign(tx);
209} 205}
210 206
@@ -558,9 +554,9 @@ static enum dma_status mxs_dma_tx_status(struct dma_chan *chan,
558 554
559static void mxs_dma_issue_pending(struct dma_chan *chan) 555static void mxs_dma_issue_pending(struct dma_chan *chan)
560{ 556{
561 /* 557 struct mxs_dma_chan *mxs_chan = to_mxs_dma_chan(chan);
562 * Nothing to do. We only have a single descriptor. 558
563 */ 559 mxs_dma_enable_chan(mxs_chan);
564} 560}
565 561
566static int __init mxs_dma_init(struct mxs_dma_engine *mxs_dma) 562static int __init mxs_dma_init(struct mxs_dma_engine *mxs_dma)
diff --git a/drivers/dma/pl330.c b/drivers/dma/pl330.c
index 282caf118be8..2ee6e23930ad 100644
--- a/drivers/dma/pl330.c
+++ b/drivers/dma/pl330.c
@@ -2225,12 +2225,9 @@ static inline void free_desc_list(struct list_head *list)
2225{ 2225{
2226 struct dma_pl330_dmac *pdmac; 2226 struct dma_pl330_dmac *pdmac;
2227 struct dma_pl330_desc *desc; 2227 struct dma_pl330_desc *desc;
2228 struct dma_pl330_chan *pch; 2228 struct dma_pl330_chan *pch = NULL;
2229 unsigned long flags; 2229 unsigned long flags;
2230 2230
2231 if (list_empty(list))
2232 return;
2233
2234 /* Finish off the work list */ 2231 /* Finish off the work list */
2235 list_for_each_entry(desc, list, node) { 2232 list_for_each_entry(desc, list, node) {
2236 dma_async_tx_callback callback; 2233 dma_async_tx_callback callback;
@@ -2247,6 +2244,10 @@ static inline void free_desc_list(struct list_head *list)
2247 desc->pchan = NULL; 2244 desc->pchan = NULL;
2248 } 2245 }
2249 2246
2247 /* pch will be unset if list was empty */
2248 if (!pch)
2249 return;
2250
2250 pdmac = pch->dmac; 2251 pdmac = pch->dmac;
2251 2252
2252 spin_lock_irqsave(&pdmac->pool_lock, flags); 2253 spin_lock_irqsave(&pdmac->pool_lock, flags);
@@ -2257,12 +2258,9 @@ static inline void free_desc_list(struct list_head *list)
2257static inline void handle_cyclic_desc_list(struct list_head *list) 2258static inline void handle_cyclic_desc_list(struct list_head *list)
2258{ 2259{
2259 struct dma_pl330_desc *desc; 2260 struct dma_pl330_desc *desc;
2260 struct dma_pl330_chan *pch; 2261 struct dma_pl330_chan *pch = NULL;
2261 unsigned long flags; 2262 unsigned long flags;
2262 2263
2263 if (list_empty(list))
2264 return;
2265
2266 list_for_each_entry(desc, list, node) { 2264 list_for_each_entry(desc, list, node) {
2267 dma_async_tx_callback callback; 2265 dma_async_tx_callback callback;
2268 2266
@@ -2274,6 +2272,10 @@ static inline void handle_cyclic_desc_list(struct list_head *list)
2274 callback(desc->txd.callback_param); 2272 callback(desc->txd.callback_param);
2275 } 2273 }
2276 2274
2275 /* pch will be unset if list was empty */
2276 if (!pch)
2277 return;
2278
2277 spin_lock_irqsave(&pch->lock, flags); 2279 spin_lock_irqsave(&pch->lock, flags);
2278 list_splice_tail_init(list, &pch->work_list); 2280 list_splice_tail_init(list, &pch->work_list);
2279 spin_unlock_irqrestore(&pch->lock, flags); 2281 spin_unlock_irqrestore(&pch->lock, flags);
@@ -2926,8 +2928,11 @@ pl330_probe(struct amba_device *adev, const struct amba_id *id)
2926 INIT_LIST_HEAD(&pd->channels); 2928 INIT_LIST_HEAD(&pd->channels);
2927 2929
2928 /* Initialize channel parameters */ 2930 /* Initialize channel parameters */
2929 num_chan = max(pdat ? pdat->nr_valid_peri : (u8)pi->pcfg.num_peri, 2931 if (pdat)
2930 (u8)pi->pcfg.num_chan); 2932 num_chan = max_t(int, pdat->nr_valid_peri, pi->pcfg.num_chan);
2933 else
2934 num_chan = max_t(int, pi->pcfg.num_peri, pi->pcfg.num_chan);
2935
2931 pdmac->peripherals = kzalloc(num_chan * sizeof(*pch), GFP_KERNEL); 2936 pdmac->peripherals = kzalloc(num_chan * sizeof(*pch), GFP_KERNEL);
2932 2937
2933 for (i = 0; i < num_chan; i++) { 2938 for (i = 0; i < num_chan; i++) {
diff --git a/drivers/dma/sa11x0-dma.c b/drivers/dma/sa11x0-dma.c
index 16a6b48883cf..ec78ccef9132 100644
--- a/drivers/dma/sa11x0-dma.c
+++ b/drivers/dma/sa11x0-dma.c
@@ -585,7 +585,7 @@ static dma_cookie_t sa11x0_dma_tx_submit(struct dma_async_tx_descriptor *tx)
585 585
586static struct dma_async_tx_descriptor *sa11x0_dma_prep_slave_sg( 586static struct dma_async_tx_descriptor *sa11x0_dma_prep_slave_sg(
587 struct dma_chan *chan, struct scatterlist *sg, unsigned int sglen, 587 struct dma_chan *chan, struct scatterlist *sg, unsigned int sglen,
588 enum dma_transfer_direction dir, unsigned long flags) 588 enum dma_transfer_direction dir, unsigned long flags, void *context)
589{ 589{
590 struct sa11x0_dma_chan *c = to_sa11x0_dma_chan(chan); 590 struct sa11x0_dma_chan *c = to_sa11x0_dma_chan(chan);
591 struct sa11x0_dma_desc *txd; 591 struct sa11x0_dma_desc *txd;
diff --git a/drivers/dma/ste_dma40.c b/drivers/dma/ste_dma40.c
index bdd41d4bfa8d..2ed1ac3513f3 100644
--- a/drivers/dma/ste_dma40.c
+++ b/drivers/dma/ste_dma40.c
@@ -18,6 +18,7 @@
18#include <linux/pm_runtime.h> 18#include <linux/pm_runtime.h>
19#include <linux/err.h> 19#include <linux/err.h>
20#include <linux/amba/bus.h> 20#include <linux/amba/bus.h>
21#include <linux/regulator/consumer.h>
21 22
22#include <plat/ste_dma40.h> 23#include <plat/ste_dma40.h>
23 24
@@ -69,6 +70,22 @@ enum d40_command {
69}; 70};
70 71
71/* 72/*
73 * enum d40_events - The different Event Enables for the event lines.
74 *
75 * @D40_DEACTIVATE_EVENTLINE: De-activate Event line, stopping the logical chan.
76 * @D40_ACTIVATE_EVENTLINE: Activate the Event line, to start a logical chan.
77 * @D40_SUSPEND_REQ_EVENTLINE: Requesting for suspending a event line.
78 * @D40_ROUND_EVENTLINE: Status check for event line.
79 */
80
81enum d40_events {
82 D40_DEACTIVATE_EVENTLINE = 0,
83 D40_ACTIVATE_EVENTLINE = 1,
84 D40_SUSPEND_REQ_EVENTLINE = 2,
85 D40_ROUND_EVENTLINE = 3
86};
87
88/*
72 * These are the registers that has to be saved and later restored 89 * These are the registers that has to be saved and later restored
73 * when the DMA hw is powered off. 90 * when the DMA hw is powered off.
74 * TODO: Add save/restore of D40_DREG_GCC on dma40 v3 or later, if that works. 91 * TODO: Add save/restore of D40_DREG_GCC on dma40 v3 or later, if that works.
@@ -870,8 +887,8 @@ static void d40_save_restore_registers(struct d40_base *base, bool save)
870} 887}
871#endif 888#endif
872 889
873static int d40_channel_execute_command(struct d40_chan *d40c, 890static int __d40_execute_command_phy(struct d40_chan *d40c,
874 enum d40_command command) 891 enum d40_command command)
875{ 892{
876 u32 status; 893 u32 status;
877 int i; 894 int i;
@@ -880,6 +897,12 @@ static int d40_channel_execute_command(struct d40_chan *d40c,
880 unsigned long flags; 897 unsigned long flags;
881 u32 wmask; 898 u32 wmask;
882 899
900 if (command == D40_DMA_STOP) {
901 ret = __d40_execute_command_phy(d40c, D40_DMA_SUSPEND_REQ);
902 if (ret)
903 return ret;
904 }
905
883 spin_lock_irqsave(&d40c->base->execmd_lock, flags); 906 spin_lock_irqsave(&d40c->base->execmd_lock, flags);
884 907
885 if (d40c->phy_chan->num % 2 == 0) 908 if (d40c->phy_chan->num % 2 == 0)
@@ -973,67 +996,109 @@ static void d40_term_all(struct d40_chan *d40c)
973 } 996 }
974 997
975 d40c->pending_tx = 0; 998 d40c->pending_tx = 0;
976 d40c->busy = false;
977} 999}
978 1000
979static void __d40_config_set_event(struct d40_chan *d40c, bool enable, 1001static void __d40_config_set_event(struct d40_chan *d40c,
980 u32 event, int reg) 1002 enum d40_events event_type, u32 event,
1003 int reg)
981{ 1004{
982 void __iomem *addr = chan_base(d40c) + reg; 1005 void __iomem *addr = chan_base(d40c) + reg;
983 int tries; 1006 int tries;
1007 u32 status;
1008
1009 switch (event_type) {
1010
1011 case D40_DEACTIVATE_EVENTLINE:
984 1012
985 if (!enable) {
986 writel((D40_DEACTIVATE_EVENTLINE << D40_EVENTLINE_POS(event)) 1013 writel((D40_DEACTIVATE_EVENTLINE << D40_EVENTLINE_POS(event))
987 | ~D40_EVENTLINE_MASK(event), addr); 1014 | ~D40_EVENTLINE_MASK(event), addr);
988 return; 1015 break;
989 } 1016
1017 case D40_SUSPEND_REQ_EVENTLINE:
1018 status = (readl(addr) & D40_EVENTLINE_MASK(event)) >>
1019 D40_EVENTLINE_POS(event);
1020
1021 if (status == D40_DEACTIVATE_EVENTLINE ||
1022 status == D40_SUSPEND_REQ_EVENTLINE)
1023 break;
990 1024
1025 writel((D40_SUSPEND_REQ_EVENTLINE << D40_EVENTLINE_POS(event))
1026 | ~D40_EVENTLINE_MASK(event), addr);
1027
1028 for (tries = 0 ; tries < D40_SUSPEND_MAX_IT; tries++) {
1029
1030 status = (readl(addr) & D40_EVENTLINE_MASK(event)) >>
1031 D40_EVENTLINE_POS(event);
1032
1033 cpu_relax();
1034 /*
1035 * Reduce the number of bus accesses while
1036 * waiting for the DMA to suspend.
1037 */
1038 udelay(3);
1039
1040 if (status == D40_DEACTIVATE_EVENTLINE)
1041 break;
1042 }
1043
1044 if (tries == D40_SUSPEND_MAX_IT) {
1045 chan_err(d40c,
1046 "unable to stop the event_line chl %d (log: %d)"
1047 "status %x\n", d40c->phy_chan->num,
1048 d40c->log_num, status);
1049 }
1050 break;
1051
1052 case D40_ACTIVATE_EVENTLINE:
991 /* 1053 /*
992 * The hardware sometimes doesn't register the enable when src and dst 1054 * The hardware sometimes doesn't register the enable when src and dst
993 * event lines are active on the same logical channel. Retry to ensure 1055 * event lines are active on the same logical channel. Retry to ensure
994 * it does. Usually only one retry is sufficient. 1056 * it does. Usually only one retry is sufficient.
995 */ 1057 */
996 tries = 100; 1058 tries = 100;
997 while (--tries) { 1059 while (--tries) {
998 writel((D40_ACTIVATE_EVENTLINE << D40_EVENTLINE_POS(event)) 1060 writel((D40_ACTIVATE_EVENTLINE <<
999 | ~D40_EVENTLINE_MASK(event), addr); 1061 D40_EVENTLINE_POS(event)) |
1062 ~D40_EVENTLINE_MASK(event), addr);
1000 1063
1001 if (readl(addr) & D40_EVENTLINE_MASK(event)) 1064 if (readl(addr) & D40_EVENTLINE_MASK(event))
1002 break; 1065 break;
1003 } 1066 }
1004 1067
1005 if (tries != 99) 1068 if (tries != 99)
1006 dev_dbg(chan2dev(d40c), 1069 dev_dbg(chan2dev(d40c),
1007 "[%s] workaround enable S%cLNK (%d tries)\n", 1070 "[%s] workaround enable S%cLNK (%d tries)\n",
1008 __func__, reg == D40_CHAN_REG_SSLNK ? 'S' : 'D', 1071 __func__, reg == D40_CHAN_REG_SSLNK ? 'S' : 'D',
1009 100 - tries); 1072 100 - tries);
1010 1073
1011 WARN_ON(!tries); 1074 WARN_ON(!tries);
1012} 1075 break;
1013 1076
1014static void d40_config_set_event(struct d40_chan *d40c, bool do_enable) 1077 case D40_ROUND_EVENTLINE:
1015{ 1078 BUG();
1016 unsigned long flags; 1079 break;
1017 1080
1018 spin_lock_irqsave(&d40c->phy_chan->lock, flags); 1081 }
1082}
1019 1083
1084static void d40_config_set_event(struct d40_chan *d40c,
1085 enum d40_events event_type)
1086{
1020 /* Enable event line connected to device (or memcpy) */ 1087 /* Enable event line connected to device (or memcpy) */
1021 if ((d40c->dma_cfg.dir == STEDMA40_PERIPH_TO_MEM) || 1088 if ((d40c->dma_cfg.dir == STEDMA40_PERIPH_TO_MEM) ||
1022 (d40c->dma_cfg.dir == STEDMA40_PERIPH_TO_PERIPH)) { 1089 (d40c->dma_cfg.dir == STEDMA40_PERIPH_TO_PERIPH)) {
1023 u32 event = D40_TYPE_TO_EVENT(d40c->dma_cfg.src_dev_type); 1090 u32 event = D40_TYPE_TO_EVENT(d40c->dma_cfg.src_dev_type);
1024 1091
1025 __d40_config_set_event(d40c, do_enable, event, 1092 __d40_config_set_event(d40c, event_type, event,
1026 D40_CHAN_REG_SSLNK); 1093 D40_CHAN_REG_SSLNK);
1027 } 1094 }
1028 1095
1029 if (d40c->dma_cfg.dir != STEDMA40_PERIPH_TO_MEM) { 1096 if (d40c->dma_cfg.dir != STEDMA40_PERIPH_TO_MEM) {
1030 u32 event = D40_TYPE_TO_EVENT(d40c->dma_cfg.dst_dev_type); 1097 u32 event = D40_TYPE_TO_EVENT(d40c->dma_cfg.dst_dev_type);
1031 1098
1032 __d40_config_set_event(d40c, do_enable, event, 1099 __d40_config_set_event(d40c, event_type, event,
1033 D40_CHAN_REG_SDLNK); 1100 D40_CHAN_REG_SDLNK);
1034 } 1101 }
1035
1036 spin_unlock_irqrestore(&d40c->phy_chan->lock, flags);
1037} 1102}
1038 1103
1039static u32 d40_chan_has_events(struct d40_chan *d40c) 1104static u32 d40_chan_has_events(struct d40_chan *d40c)
@@ -1047,6 +1112,64 @@ static u32 d40_chan_has_events(struct d40_chan *d40c)
1047 return val; 1112 return val;
1048} 1113}
1049 1114
1115static int
1116__d40_execute_command_log(struct d40_chan *d40c, enum d40_command command)
1117{
1118 unsigned long flags;
1119 int ret = 0;
1120 u32 active_status;
1121 void __iomem *active_reg;
1122
1123 if (d40c->phy_chan->num % 2 == 0)
1124 active_reg = d40c->base->virtbase + D40_DREG_ACTIVE;
1125 else
1126 active_reg = d40c->base->virtbase + D40_DREG_ACTIVO;
1127
1128
1129 spin_lock_irqsave(&d40c->phy_chan->lock, flags);
1130
1131 switch (command) {
1132 case D40_DMA_STOP:
1133 case D40_DMA_SUSPEND_REQ:
1134
1135 active_status = (readl(active_reg) &
1136 D40_CHAN_POS_MASK(d40c->phy_chan->num)) >>
1137 D40_CHAN_POS(d40c->phy_chan->num);
1138
1139 if (active_status == D40_DMA_RUN)
1140 d40_config_set_event(d40c, D40_SUSPEND_REQ_EVENTLINE);
1141 else
1142 d40_config_set_event(d40c, D40_DEACTIVATE_EVENTLINE);
1143
1144 if (!d40_chan_has_events(d40c) && (command == D40_DMA_STOP))
1145 ret = __d40_execute_command_phy(d40c, command);
1146
1147 break;
1148
1149 case D40_DMA_RUN:
1150
1151 d40_config_set_event(d40c, D40_ACTIVATE_EVENTLINE);
1152 ret = __d40_execute_command_phy(d40c, command);
1153 break;
1154
1155 case D40_DMA_SUSPENDED:
1156 BUG();
1157 break;
1158 }
1159
1160 spin_unlock_irqrestore(&d40c->phy_chan->lock, flags);
1161 return ret;
1162}
1163
1164static int d40_channel_execute_command(struct d40_chan *d40c,
1165 enum d40_command command)
1166{
1167 if (chan_is_logical(d40c))
1168 return __d40_execute_command_log(d40c, command);
1169 else
1170 return __d40_execute_command_phy(d40c, command);
1171}
1172
1050static u32 d40_get_prmo(struct d40_chan *d40c) 1173static u32 d40_get_prmo(struct d40_chan *d40c)
1051{ 1174{
1052 static const unsigned int phy_map[] = { 1175 static const unsigned int phy_map[] = {
@@ -1149,15 +1272,7 @@ static int d40_pause(struct d40_chan *d40c)
1149 spin_lock_irqsave(&d40c->lock, flags); 1272 spin_lock_irqsave(&d40c->lock, flags);
1150 1273
1151 res = d40_channel_execute_command(d40c, D40_DMA_SUSPEND_REQ); 1274 res = d40_channel_execute_command(d40c, D40_DMA_SUSPEND_REQ);
1152 if (res == 0) { 1275
1153 if (chan_is_logical(d40c)) {
1154 d40_config_set_event(d40c, false);
1155 /* Resume the other logical channels if any */
1156 if (d40_chan_has_events(d40c))
1157 res = d40_channel_execute_command(d40c,
1158 D40_DMA_RUN);
1159 }
1160 }
1161 pm_runtime_mark_last_busy(d40c->base->dev); 1276 pm_runtime_mark_last_busy(d40c->base->dev);
1162 pm_runtime_put_autosuspend(d40c->base->dev); 1277 pm_runtime_put_autosuspend(d40c->base->dev);
1163 spin_unlock_irqrestore(&d40c->lock, flags); 1278 spin_unlock_irqrestore(&d40c->lock, flags);
@@ -1174,45 +1289,17 @@ static int d40_resume(struct d40_chan *d40c)
1174 1289
1175 spin_lock_irqsave(&d40c->lock, flags); 1290 spin_lock_irqsave(&d40c->lock, flags);
1176 pm_runtime_get_sync(d40c->base->dev); 1291 pm_runtime_get_sync(d40c->base->dev);
1177 if (d40c->base->rev == 0)
1178 if (chan_is_logical(d40c)) {
1179 res = d40_channel_execute_command(d40c,
1180 D40_DMA_SUSPEND_REQ);
1181 goto no_suspend;
1182 }
1183 1292
1184 /* If bytes left to transfer or linked tx resume job */ 1293 /* If bytes left to transfer or linked tx resume job */
1185 if (d40_residue(d40c) || d40_tx_is_linked(d40c)) { 1294 if (d40_residue(d40c) || d40_tx_is_linked(d40c))
1186
1187 if (chan_is_logical(d40c))
1188 d40_config_set_event(d40c, true);
1189
1190 res = d40_channel_execute_command(d40c, D40_DMA_RUN); 1295 res = d40_channel_execute_command(d40c, D40_DMA_RUN);
1191 }
1192 1296
1193no_suspend:
1194 pm_runtime_mark_last_busy(d40c->base->dev); 1297 pm_runtime_mark_last_busy(d40c->base->dev);
1195 pm_runtime_put_autosuspend(d40c->base->dev); 1298 pm_runtime_put_autosuspend(d40c->base->dev);
1196 spin_unlock_irqrestore(&d40c->lock, flags); 1299 spin_unlock_irqrestore(&d40c->lock, flags);
1197 return res; 1300 return res;
1198} 1301}
1199 1302
1200static int d40_terminate_all(struct d40_chan *chan)
1201{
1202 unsigned long flags;
1203 int ret = 0;
1204
1205 ret = d40_pause(chan);
1206 if (!ret && chan_is_physical(chan))
1207 ret = d40_channel_execute_command(chan, D40_DMA_STOP);
1208
1209 spin_lock_irqsave(&chan->lock, flags);
1210 d40_term_all(chan);
1211 spin_unlock_irqrestore(&chan->lock, flags);
1212
1213 return ret;
1214}
1215
1216static dma_cookie_t d40_tx_submit(struct dma_async_tx_descriptor *tx) 1303static dma_cookie_t d40_tx_submit(struct dma_async_tx_descriptor *tx)
1217{ 1304{
1218 struct d40_chan *d40c = container_of(tx->chan, 1305 struct d40_chan *d40c = container_of(tx->chan,
@@ -1232,20 +1319,6 @@ static dma_cookie_t d40_tx_submit(struct dma_async_tx_descriptor *tx)
1232 1319
1233static int d40_start(struct d40_chan *d40c) 1320static int d40_start(struct d40_chan *d40c)
1234{ 1321{
1235 if (d40c->base->rev == 0) {
1236 int err;
1237
1238 if (chan_is_logical(d40c)) {
1239 err = d40_channel_execute_command(d40c,
1240 D40_DMA_SUSPEND_REQ);
1241 if (err)
1242 return err;
1243 }
1244 }
1245
1246 if (chan_is_logical(d40c))
1247 d40_config_set_event(d40c, true);
1248
1249 return d40_channel_execute_command(d40c, D40_DMA_RUN); 1322 return d40_channel_execute_command(d40c, D40_DMA_RUN);
1250} 1323}
1251 1324
@@ -1258,10 +1331,10 @@ static struct d40_desc *d40_queue_start(struct d40_chan *d40c)
1258 d40d = d40_first_queued(d40c); 1331 d40d = d40_first_queued(d40c);
1259 1332
1260 if (d40d != NULL) { 1333 if (d40d != NULL) {
1261 if (!d40c->busy) 1334 if (!d40c->busy) {
1262 d40c->busy = true; 1335 d40c->busy = true;
1263 1336 pm_runtime_get_sync(d40c->base->dev);
1264 pm_runtime_get_sync(d40c->base->dev); 1337 }
1265 1338
1266 /* Remove from queue */ 1339 /* Remove from queue */
1267 d40_desc_remove(d40d); 1340 d40_desc_remove(d40d);
@@ -1388,8 +1461,8 @@ static void dma_tasklet(unsigned long data)
1388 1461
1389 return; 1462 return;
1390 1463
1391 err: 1464err:
1392 /* Rescue manoeuvre if receiving double interrupts */ 1465 /* Rescue manouver if receiving double interrupts */
1393 if (d40c->pending_tx > 0) 1466 if (d40c->pending_tx > 0)
1394 d40c->pending_tx--; 1467 d40c->pending_tx--;
1395 spin_unlock_irqrestore(&d40c->lock, flags); 1468 spin_unlock_irqrestore(&d40c->lock, flags);
@@ -1770,7 +1843,6 @@ static int d40_config_memcpy(struct d40_chan *d40c)
1770 return 0; 1843 return 0;
1771} 1844}
1772 1845
1773
1774static int d40_free_dma(struct d40_chan *d40c) 1846static int d40_free_dma(struct d40_chan *d40c)
1775{ 1847{
1776 1848
@@ -1806,43 +1878,18 @@ static int d40_free_dma(struct d40_chan *d40c)
1806 } 1878 }
1807 1879
1808 pm_runtime_get_sync(d40c->base->dev); 1880 pm_runtime_get_sync(d40c->base->dev);
1809 res = d40_channel_execute_command(d40c, D40_DMA_SUSPEND_REQ); 1881 res = d40_channel_execute_command(d40c, D40_DMA_STOP);
1810 if (res) { 1882 if (res) {
1811 chan_err(d40c, "suspend failed\n"); 1883 chan_err(d40c, "stop failed\n");
1812 goto out; 1884 goto out;
1813 } 1885 }
1814 1886
1815 if (chan_is_logical(d40c)) { 1887 d40_alloc_mask_free(phy, is_src, chan_is_logical(d40c) ? event : 0);
1816 /* Release logical channel, deactivate the event line */
1817 1888
1818 d40_config_set_event(d40c, false); 1889 if (chan_is_logical(d40c))
1819 d40c->base->lookup_log_chans[d40c->log_num] = NULL; 1890 d40c->base->lookup_log_chans[d40c->log_num] = NULL;
1820 1891 else
1821 /* 1892 d40c->base->lookup_phy_chans[phy->num] = NULL;
1822 * Check if there are more logical allocation
1823 * on this phy channel.
1824 */
1825 if (!d40_alloc_mask_free(phy, is_src, event)) {
1826 /* Resume the other logical channels if any */
1827 if (d40_chan_has_events(d40c)) {
1828 res = d40_channel_execute_command(d40c,
1829 D40_DMA_RUN);
1830 if (res)
1831 chan_err(d40c,
1832 "Executing RUN command\n");
1833 }
1834 goto out;
1835 }
1836 } else {
1837 (void) d40_alloc_mask_free(phy, is_src, 0);
1838 }
1839
1840 /* Release physical channel */
1841 res = d40_channel_execute_command(d40c, D40_DMA_STOP);
1842 if (res) {
1843 chan_err(d40c, "Failed to stop channel\n");
1844 goto out;
1845 }
1846 1893
1847 if (d40c->busy) { 1894 if (d40c->busy) {
1848 pm_runtime_mark_last_busy(d40c->base->dev); 1895 pm_runtime_mark_last_busy(d40c->base->dev);
@@ -1852,7 +1899,6 @@ static int d40_free_dma(struct d40_chan *d40c)
1852 d40c->busy = false; 1899 d40c->busy = false;
1853 d40c->phy_chan = NULL; 1900 d40c->phy_chan = NULL;
1854 d40c->configured = false; 1901 d40c->configured = false;
1855 d40c->base->lookup_phy_chans[phy->num] = NULL;
1856out: 1902out:
1857 1903
1858 pm_runtime_mark_last_busy(d40c->base->dev); 1904 pm_runtime_mark_last_busy(d40c->base->dev);
@@ -2070,7 +2116,7 @@ d40_prep_sg(struct dma_chan *dchan, struct scatterlist *sg_src,
2070 if (sg_next(&sg_src[sg_len - 1]) == sg_src) 2116 if (sg_next(&sg_src[sg_len - 1]) == sg_src)
2071 desc->cyclic = true; 2117 desc->cyclic = true;
2072 2118
2073 if (direction != DMA_NONE) { 2119 if (direction != DMA_TRANS_NONE) {
2074 dma_addr_t dev_addr = d40_get_dev_addr(chan, direction); 2120 dma_addr_t dev_addr = d40_get_dev_addr(chan, direction);
2075 2121
2076 if (direction == DMA_DEV_TO_MEM) 2122 if (direction == DMA_DEV_TO_MEM)
@@ -2371,6 +2417,31 @@ static void d40_issue_pending(struct dma_chan *chan)
2371 spin_unlock_irqrestore(&d40c->lock, flags); 2417 spin_unlock_irqrestore(&d40c->lock, flags);
2372} 2418}
2373 2419
2420static void d40_terminate_all(struct dma_chan *chan)
2421{
2422 unsigned long flags;
2423 struct d40_chan *d40c = container_of(chan, struct d40_chan, chan);
2424 int ret;
2425
2426 spin_lock_irqsave(&d40c->lock, flags);
2427
2428 pm_runtime_get_sync(d40c->base->dev);
2429 ret = d40_channel_execute_command(d40c, D40_DMA_STOP);
2430 if (ret)
2431 chan_err(d40c, "Failed to stop channel\n");
2432
2433 d40_term_all(d40c);
2434 pm_runtime_mark_last_busy(d40c->base->dev);
2435 pm_runtime_put_autosuspend(d40c->base->dev);
2436 if (d40c->busy) {
2437 pm_runtime_mark_last_busy(d40c->base->dev);
2438 pm_runtime_put_autosuspend(d40c->base->dev);
2439 }
2440 d40c->busy = false;
2441
2442 spin_unlock_irqrestore(&d40c->lock, flags);
2443}
2444
2374static int 2445static int
2375dma40_config_to_halfchannel(struct d40_chan *d40c, 2446dma40_config_to_halfchannel(struct d40_chan *d40c,
2376 struct stedma40_half_channel_info *info, 2447 struct stedma40_half_channel_info *info,
@@ -2551,7 +2622,8 @@ static int d40_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
2551 2622
2552 switch (cmd) { 2623 switch (cmd) {
2553 case DMA_TERMINATE_ALL: 2624 case DMA_TERMINATE_ALL:
2554 return d40_terminate_all(d40c); 2625 d40_terminate_all(chan);
2626 return 0;
2555 case DMA_PAUSE: 2627 case DMA_PAUSE:
2556 return d40_pause(d40c); 2628 return d40_pause(d40c);
2557 case DMA_RESUME: 2629 case DMA_RESUME:
@@ -2908,6 +2980,12 @@ static struct d40_base * __init d40_hw_detect_init(struct platform_device *pdev)
2908 dev_info(&pdev->dev, "hardware revision: %d @ 0x%x\n", 2980 dev_info(&pdev->dev, "hardware revision: %d @ 0x%x\n",
2909 rev, res->start); 2981 rev, res->start);
2910 2982
2983 if (rev < 2) {
2984 d40_err(&pdev->dev, "hardware revision: %d is not supported",
2985 rev);
2986 goto failure;
2987 }
2988
2911 plat_data = pdev->dev.platform_data; 2989 plat_data = pdev->dev.platform_data;
2912 2990
2913 /* Count the number of logical channels in use */ 2991 /* Count the number of logical channels in use */
@@ -2998,6 +3076,7 @@ failure:
2998 3076
2999 if (base) { 3077 if (base) {
3000 kfree(base->lcla_pool.alloc_map); 3078 kfree(base->lcla_pool.alloc_map);
3079 kfree(base->reg_val_backup_chan);
3001 kfree(base->lookup_log_chans); 3080 kfree(base->lookup_log_chans);
3002 kfree(base->lookup_phy_chans); 3081 kfree(base->lookup_phy_chans);
3003 kfree(base->phy_res); 3082 kfree(base->phy_res);
diff --git a/drivers/dma/ste_dma40_ll.h b/drivers/dma/ste_dma40_ll.h
index 8d3d490968a3..51e8e5396e9b 100644
--- a/drivers/dma/ste_dma40_ll.h
+++ b/drivers/dma/ste_dma40_ll.h
@@ -62,8 +62,6 @@
62#define D40_SREG_ELEM_LOG_LIDX_MASK (0xFF << D40_SREG_ELEM_LOG_LIDX_POS) 62#define D40_SREG_ELEM_LOG_LIDX_MASK (0xFF << D40_SREG_ELEM_LOG_LIDX_POS)
63 63
64/* Link register */ 64/* Link register */
65#define D40_DEACTIVATE_EVENTLINE 0x0
66#define D40_ACTIVATE_EVENTLINE 0x1
67#define D40_EVENTLINE_POS(i) (2 * i) 65#define D40_EVENTLINE_POS(i) (2 * i)
68#define D40_EVENTLINE_MASK(i) (0x3 << D40_EVENTLINE_POS(i)) 66#define D40_EVENTLINE_MASK(i) (0x3 << D40_EVENTLINE_POS(i))
69 67
diff --git a/drivers/edac/mce_amd.c b/drivers/edac/mce_amd.c
index 36e1486eb9aa..d0c372e30de4 100644
--- a/drivers/edac/mce_amd.c
+++ b/drivers/edac/mce_amd.c
@@ -754,9 +754,7 @@ static int __init mce_amd_init(void)
754 if (c->x86_vendor != X86_VENDOR_AMD) 754 if (c->x86_vendor != X86_VENDOR_AMD)
755 return 0; 755 return 0;
756 756
757 if ((c->x86 < 0xf || c->x86 > 0x12) && 757 if (c->x86 < 0xf || c->x86 > 0x15)
758 (c->x86 != 0x14 || c->x86_model > 0xf) &&
759 (c->x86 != 0x15 || c->x86_model > 0xf))
760 return 0; 758 return 0;
761 759
762 fam_ops = kzalloc(sizeof(struct amd_decoder_ops), GFP_KERNEL); 760 fam_ops = kzalloc(sizeof(struct amd_decoder_ops), GFP_KERNEL);
@@ -797,7 +795,7 @@ static int __init mce_amd_init(void)
797 break; 795 break;
798 796
799 default: 797 default:
800 printk(KERN_WARNING "Huh? What family is that: %d?!\n", c->x86); 798 printk(KERN_WARNING "Huh? What family is it: 0x%x?!\n", c->x86);
801 kfree(fam_ops); 799 kfree(fam_ops);
802 return -EINVAL; 800 return -EINVAL;
803 } 801 }
diff --git a/drivers/edac/tile_edac.c b/drivers/edac/tile_edac.c
index 1d5cf06f6c6b..e99d00976189 100644
--- a/drivers/edac/tile_edac.c
+++ b/drivers/edac/tile_edac.c
@@ -145,7 +145,11 @@ static int __devinit tile_edac_mc_probe(struct platform_device *pdev)
145 mci->edac_ctl_cap = EDAC_FLAG_SECDED; 145 mci->edac_ctl_cap = EDAC_FLAG_SECDED;
146 146
147 mci->mod_name = DRV_NAME; 147 mci->mod_name = DRV_NAME;
148#ifdef __tilegx__
149 mci->ctl_name = "TILEGx_Memory_Controller";
150#else
148 mci->ctl_name = "TILEPro_Memory_Controller"; 151 mci->ctl_name = "TILEPro_Memory_Controller";
152#endif
149 mci->dev_name = dev_name(&pdev->dev); 153 mci->dev_name = dev_name(&pdev->dev);
150 mci->edac_check = tile_edac_check; 154 mci->edac_check = tile_edac_check;
151 155
diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
index d25599f2a3f8..47408e802ab6 100644
--- a/drivers/firmware/efivars.c
+++ b/drivers/firmware/efivars.c
@@ -191,6 +191,190 @@ utf16_strncmp(const efi_char16_t *a, const efi_char16_t *b, size_t len)
191 } 191 }
192} 192}
193 193
194static bool
195validate_device_path(struct efi_variable *var, int match, u8 *buffer,
196 unsigned long len)
197{
198 struct efi_generic_dev_path *node;
199 int offset = 0;
200
201 node = (struct efi_generic_dev_path *)buffer;
202
203 if (len < sizeof(*node))
204 return false;
205
206 while (offset <= len - sizeof(*node) &&
207 node->length >= sizeof(*node) &&
208 node->length <= len - offset) {
209 offset += node->length;
210
211 if ((node->type == EFI_DEV_END_PATH ||
212 node->type == EFI_DEV_END_PATH2) &&
213 node->sub_type == EFI_DEV_END_ENTIRE)
214 return true;
215
216 node = (struct efi_generic_dev_path *)(buffer + offset);
217 }
218
219 /*
220 * If we're here then either node->length pointed past the end
221 * of the buffer or we reached the end of the buffer without
222 * finding a device path end node.
223 */
224 return false;
225}
226
227static bool
228validate_boot_order(struct efi_variable *var, int match, u8 *buffer,
229 unsigned long len)
230{
231 /* An array of 16-bit integers */
232 if ((len % 2) != 0)
233 return false;
234
235 return true;
236}
237
238static bool
239validate_load_option(struct efi_variable *var, int match, u8 *buffer,
240 unsigned long len)
241{
242 u16 filepathlength;
243 int i, desclength = 0, namelen;
244
245 namelen = utf16_strnlen(var->VariableName, sizeof(var->VariableName));
246
247 /* Either "Boot" or "Driver" followed by four digits of hex */
248 for (i = match; i < match+4; i++) {
249 if (var->VariableName[i] > 127 ||
250 hex_to_bin(var->VariableName[i] & 0xff) < 0)
251 return true;
252 }
253
254 /* Reject it if there's 4 digits of hex and then further content */
255 if (namelen > match + 4)
256 return false;
257
258 /* A valid entry must be at least 8 bytes */
259 if (len < 8)
260 return false;
261
262 filepathlength = buffer[4] | buffer[5] << 8;
263
264 /*
265 * There's no stored length for the description, so it has to be
266 * found by hand
267 */
268 desclength = utf16_strsize((efi_char16_t *)(buffer + 6), len - 6) + 2;
269
270 /* Each boot entry must have a descriptor */
271 if (!desclength)
272 return false;
273
274 /*
275 * If the sum of the length of the description, the claimed filepath
276 * length and the original header are greater than the length of the
277 * variable, it's malformed
278 */
279 if ((desclength + filepathlength + 6) > len)
280 return false;
281
282 /*
283 * And, finally, check the filepath
284 */
285 return validate_device_path(var, match, buffer + desclength + 6,
286 filepathlength);
287}
288
289static bool
290validate_uint16(struct efi_variable *var, int match, u8 *buffer,
291 unsigned long len)
292{
293 /* A single 16-bit integer */
294 if (len != 2)
295 return false;
296
297 return true;
298}
299
300static bool
301validate_ascii_string(struct efi_variable *var, int match, u8 *buffer,
302 unsigned long len)
303{
304 int i;
305
306 for (i = 0; i < len; i++) {
307 if (buffer[i] > 127)
308 return false;
309
310 if (buffer[i] == 0)
311 return true;
312 }
313
314 return false;
315}
316
317struct variable_validate {
318 char *name;
319 bool (*validate)(struct efi_variable *var, int match, u8 *data,
320 unsigned long len);
321};
322
323static const struct variable_validate variable_validate[] = {
324 { "BootNext", validate_uint16 },
325 { "BootOrder", validate_boot_order },
326 { "DriverOrder", validate_boot_order },
327 { "Boot*", validate_load_option },
328 { "Driver*", validate_load_option },
329 { "ConIn", validate_device_path },
330 { "ConInDev", validate_device_path },
331 { "ConOut", validate_device_path },
332 { "ConOutDev", validate_device_path },
333 { "ErrOut", validate_device_path },
334 { "ErrOutDev", validate_device_path },
335 { "Timeout", validate_uint16 },
336 { "Lang", validate_ascii_string },
337 { "PlatformLang", validate_ascii_string },
338 { "", NULL },
339};
340
341static bool
342validate_var(struct efi_variable *var, u8 *data, unsigned long len)
343{
344 int i;
345 u16 *unicode_name = var->VariableName;
346
347 for (i = 0; variable_validate[i].validate != NULL; i++) {
348 const char *name = variable_validate[i].name;
349 int match;
350
351 for (match = 0; ; match++) {
352 char c = name[match];
353 u16 u = unicode_name[match];
354
355 /* All special variables are plain ascii */
356 if (u > 127)
357 return true;
358
359 /* Wildcard in the matching name means we've matched */
360 if (c == '*')
361 return variable_validate[i].validate(var,
362 match, data, len);
363
364 /* Case sensitive match */
365 if (c != u)
366 break;
367
368 /* Reached the end of the string while matching */
369 if (!c)
370 return variable_validate[i].validate(var,
371 match, data, len);
372 }
373 }
374
375 return true;
376}
377
194static efi_status_t 378static efi_status_t
195get_var_data_locked(struct efivars *efivars, struct efi_variable *var) 379get_var_data_locked(struct efivars *efivars, struct efi_variable *var)
196{ 380{
@@ -324,6 +508,12 @@ efivar_store_raw(struct efivar_entry *entry, const char *buf, size_t count)
324 return -EINVAL; 508 return -EINVAL;
325 } 509 }
326 510
511 if ((new_var->Attributes & ~EFI_VARIABLE_MASK) != 0 ||
512 validate_var(new_var, new_var->Data, new_var->DataSize) == false) {
513 printk(KERN_ERR "efivars: Malformed variable content\n");
514 return -EINVAL;
515 }
516
327 spin_lock(&efivars->lock); 517 spin_lock(&efivars->lock);
328 status = efivars->ops->set_variable(new_var->VariableName, 518 status = efivars->ops->set_variable(new_var->VariableName,
329 &new_var->VendorGuid, 519 &new_var->VendorGuid,
@@ -626,6 +816,12 @@ static ssize_t efivar_create(struct file *filp, struct kobject *kobj,
626 if (!capable(CAP_SYS_ADMIN)) 816 if (!capable(CAP_SYS_ADMIN))
627 return -EACCES; 817 return -EACCES;
628 818
819 if ((new_var->Attributes & ~EFI_VARIABLE_MASK) != 0 ||
820 validate_var(new_var, new_var->Data, new_var->DataSize) == false) {
821 printk(KERN_ERR "efivars: Malformed variable content\n");
822 return -EINVAL;
823 }
824
629 spin_lock(&efivars->lock); 825 spin_lock(&efivars->lock);
630 826
631 /* 827 /*
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index edadbdad31d0..e03653d69357 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -430,7 +430,7 @@ config GPIO_ML_IOH
430 430
431config GPIO_SODAVILLE 431config GPIO_SODAVILLE
432 bool "Intel Sodaville GPIO support" 432 bool "Intel Sodaville GPIO support"
433 depends on X86 && PCI && OF && BROKEN 433 depends on X86 && PCI && OF
434 select GPIO_GENERIC 434 select GPIO_GENERIC
435 select GENERIC_IRQ_CHIP 435 select GENERIC_IRQ_CHIP
436 help 436 help
diff --git a/drivers/gpio/gpio-adp5588.c b/drivers/gpio/gpio-adp5588.c
index 9ad1703d1408..ae5d7f12ce66 100644
--- a/drivers/gpio/gpio-adp5588.c
+++ b/drivers/gpio/gpio-adp5588.c
@@ -252,7 +252,7 @@ static irqreturn_t adp5588_irq_handler(int irq, void *devid)
252 if (ret < 0) 252 if (ret < 0)
253 memset(dev->irq_stat, 0, ARRAY_SIZE(dev->irq_stat)); 253 memset(dev->irq_stat, 0, ARRAY_SIZE(dev->irq_stat));
254 254
255 for (bank = 0; bank <= ADP5588_BANK(ADP5588_MAXGPIO); 255 for (bank = 0, bit = 0; bank <= ADP5588_BANK(ADP5588_MAXGPIO);
256 bank++, bit = 0) { 256 bank++, bit = 0) {
257 pending = dev->irq_stat[bank] & dev->irq_mask[bank]; 257 pending = dev->irq_stat[bank] & dev->irq_mask[bank];
258 258
diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
index 1adc2ec1e383..4461540653a8 100644
--- a/drivers/gpio/gpio-omap.c
+++ b/drivers/gpio/gpio-omap.c
@@ -965,18 +965,15 @@ static void omap_gpio_mod_init(struct gpio_bank *bank)
965 } 965 }
966 966
967 _gpio_rmw(base, bank->regs->irqenable, l, bank->regs->irqenable_inv); 967 _gpio_rmw(base, bank->regs->irqenable, l, bank->regs->irqenable_inv);
968 _gpio_rmw(base, bank->regs->irqstatus, l, 968 _gpio_rmw(base, bank->regs->irqstatus, l, !bank->regs->irqenable_inv);
969 bank->regs->irqenable_inv == false);
970 _gpio_rmw(base, bank->regs->irqenable, l, bank->regs->debounce_en != 0);
971 _gpio_rmw(base, bank->regs->irqenable, l, bank->regs->ctrl != 0);
972 if (bank->regs->debounce_en) 969 if (bank->regs->debounce_en)
973 _gpio_rmw(base, bank->regs->debounce_en, 0, 1); 970 __raw_writel(0, base + bank->regs->debounce_en);
974 971
975 /* Save OE default value (0xffffffff) in the context */ 972 /* Save OE default value (0xffffffff) in the context */
976 bank->context.oe = __raw_readl(bank->base + bank->regs->direction); 973 bank->context.oe = __raw_readl(bank->base + bank->regs->direction);
977 /* Initialize interface clk ungated, module enabled */ 974 /* Initialize interface clk ungated, module enabled */
978 if (bank->regs->ctrl) 975 if (bank->regs->ctrl)
979 _gpio_rmw(base, bank->regs->ctrl, 0, 1); 976 __raw_writel(0, base + bank->regs->ctrl);
980} 977}
981 978
982static __devinit void 979static __devinit void
diff --git a/drivers/gpio/gpio-pch.c b/drivers/gpio/gpio-pch.c
index e8729cc2ba2b..2cd958e0b822 100644
--- a/drivers/gpio/gpio-pch.c
+++ b/drivers/gpio/gpio-pch.c
@@ -230,16 +230,12 @@ static void pch_gpio_setup(struct pch_gpio *chip)
230 230
231static int pch_irq_type(struct irq_data *d, unsigned int type) 231static int pch_irq_type(struct irq_data *d, unsigned int type)
232{ 232{
233 u32 im;
234 u32 __iomem *im_reg;
235 u32 ien;
236 u32 im_pos;
237 int ch;
238 unsigned long flags;
239 u32 val;
240 int irq = d->irq;
241 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); 233 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
242 struct pch_gpio *chip = gc->private; 234 struct pch_gpio *chip = gc->private;
235 u32 im, im_pos, val;
236 u32 __iomem *im_reg;
237 unsigned long flags;
238 int ch, irq = d->irq;
243 239
244 ch = irq - chip->irq_base; 240 ch = irq - chip->irq_base;
245 if (irq <= chip->irq_base + 7) { 241 if (irq <= chip->irq_base + 7) {
@@ -270,30 +266,22 @@ static int pch_irq_type(struct irq_data *d, unsigned int type)
270 case IRQ_TYPE_LEVEL_LOW: 266 case IRQ_TYPE_LEVEL_LOW:
271 val = PCH_LEVEL_L; 267 val = PCH_LEVEL_L;
272 break; 268 break;
273 case IRQ_TYPE_PROBE:
274 goto end;
275 default: 269 default:
276 dev_warn(chip->dev, "%s: unknown type(%dd)", 270 goto unlock;
277 __func__, type);
278 goto end;
279 } 271 }
280 272
281 /* Set interrupt mode */ 273 /* Set interrupt mode */
282 im = ioread32(im_reg) & ~(PCH_IM_MASK << (im_pos * 4)); 274 im = ioread32(im_reg) & ~(PCH_IM_MASK << (im_pos * 4));
283 iowrite32(im | (val << (im_pos * 4)), im_reg); 275 iowrite32(im | (val << (im_pos * 4)), im_reg);
284 276
285 /* iclr */ 277 /* And the handler */
286 iowrite32(BIT(ch), &chip->reg->iclr); 278 if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
279 __irq_set_handler_locked(d->irq, handle_level_irq);
280 else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING))
281 __irq_set_handler_locked(d->irq, handle_edge_irq);
287 282
288 /* IMASKCLR */ 283unlock:
289 iowrite32(BIT(ch), &chip->reg->imaskclr);
290
291 /* Enable interrupt */
292 ien = ioread32(&chip->reg->ien);
293 iowrite32(ien | BIT(ch), &chip->reg->ien);
294end:
295 spin_unlock_irqrestore(&chip->spinlock, flags); 284 spin_unlock_irqrestore(&chip->spinlock, flags);
296
297 return 0; 285 return 0;
298} 286}
299 287
@@ -313,18 +301,24 @@ static void pch_irq_mask(struct irq_data *d)
313 iowrite32(1 << (d->irq - chip->irq_base), &chip->reg->imask); 301 iowrite32(1 << (d->irq - chip->irq_base), &chip->reg->imask);
314} 302}
315 303
304static void pch_irq_ack(struct irq_data *d)
305{
306 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
307 struct pch_gpio *chip = gc->private;
308
309 iowrite32(1 << (d->irq - chip->irq_base), &chip->reg->iclr);
310}
311
316static irqreturn_t pch_gpio_handler(int irq, void *dev_id) 312static irqreturn_t pch_gpio_handler(int irq, void *dev_id)
317{ 313{
318 struct pch_gpio *chip = dev_id; 314 struct pch_gpio *chip = dev_id;
319 u32 reg_val = ioread32(&chip->reg->istatus); 315 u32 reg_val = ioread32(&chip->reg->istatus);
320 int i; 316 int i, ret = IRQ_NONE;
321 int ret = IRQ_NONE;
322 317
323 for (i = 0; i < gpio_pins[chip->ioh]; i++) { 318 for (i = 0; i < gpio_pins[chip->ioh]; i++) {
324 if (reg_val & BIT(i)) { 319 if (reg_val & BIT(i)) {
325 dev_dbg(chip->dev, "%s:[%d]:irq=%d status=0x%x\n", 320 dev_dbg(chip->dev, "%s:[%d]:irq=%d status=0x%x\n",
326 __func__, i, irq, reg_val); 321 __func__, i, irq, reg_val);
327 iowrite32(BIT(i), &chip->reg->iclr);
328 generic_handle_irq(chip->irq_base + i); 322 generic_handle_irq(chip->irq_base + i);
329 ret = IRQ_HANDLED; 323 ret = IRQ_HANDLED;
330 } 324 }
@@ -343,6 +337,7 @@ static __devinit void pch_gpio_alloc_generic_chip(struct pch_gpio *chip,
343 gc->private = chip; 337 gc->private = chip;
344 ct = gc->chip_types; 338 ct = gc->chip_types;
345 339
340 ct->chip.irq_ack = pch_irq_ack;
346 ct->chip.irq_mask = pch_irq_mask; 341 ct->chip.irq_mask = pch_irq_mask;
347 ct->chip.irq_unmask = pch_irq_unmask; 342 ct->chip.irq_unmask = pch_irq_unmask;
348 ct->chip.irq_set_type = pch_irq_type; 343 ct->chip.irq_set_type = pch_irq_type;
@@ -357,6 +352,7 @@ static int __devinit pch_gpio_probe(struct pci_dev *pdev,
357 s32 ret; 352 s32 ret;
358 struct pch_gpio *chip; 353 struct pch_gpio *chip;
359 int irq_base; 354 int irq_base;
355 u32 msk;
360 356
361 chip = kzalloc(sizeof(*chip), GFP_KERNEL); 357 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
362 if (chip == NULL) 358 if (chip == NULL)
@@ -408,8 +404,13 @@ static int __devinit pch_gpio_probe(struct pci_dev *pdev,
408 } 404 }
409 chip->irq_base = irq_base; 405 chip->irq_base = irq_base;
410 406
407 /* Mask all interrupts, but enable them */
408 msk = (1 << gpio_pins[chip->ioh]) - 1;
409 iowrite32(msk, &chip->reg->imask);
410 iowrite32(msk, &chip->reg->ien);
411
411 ret = request_irq(pdev->irq, pch_gpio_handler, 412 ret = request_irq(pdev->irq, pch_gpio_handler,
412 IRQF_SHARED, KBUILD_MODNAME, chip); 413 IRQF_SHARED, KBUILD_MODNAME, chip);
413 if (ret != 0) { 414 if (ret != 0) {
414 dev_err(&pdev->dev, 415 dev_err(&pdev->dev,
415 "%s request_irq failed\n", __func__); 416 "%s request_irq failed\n", __func__);
@@ -418,8 +419,6 @@ static int __devinit pch_gpio_probe(struct pci_dev *pdev,
418 419
419 pch_gpio_alloc_generic_chip(chip, irq_base, gpio_pins[chip->ioh]); 420 pch_gpio_alloc_generic_chip(chip, irq_base, gpio_pins[chip->ioh]);
420 421
421 /* Initialize interrupt ien register */
422 iowrite32(0, &chip->reg->ien);
423end: 422end:
424 return 0; 423 return 0;
425 424
diff --git a/drivers/gpio/gpio-pxa.c b/drivers/gpio/gpio-pxa.c
index 5689ce62fd81..fc3ace3fd4cb 100644
--- a/drivers/gpio/gpio-pxa.c
+++ b/drivers/gpio/gpio-pxa.c
@@ -64,6 +64,7 @@ struct pxa_gpio_chip {
64 unsigned long irq_mask; 64 unsigned long irq_mask;
65 unsigned long irq_edge_rise; 65 unsigned long irq_edge_rise;
66 unsigned long irq_edge_fall; 66 unsigned long irq_edge_fall;
67 int (*set_wake)(unsigned int gpio, unsigned int on);
67 68
68#ifdef CONFIG_PM 69#ifdef CONFIG_PM
69 unsigned long saved_gplr; 70 unsigned long saved_gplr;
@@ -269,7 +270,8 @@ static void pxa_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
269 (value ? GPSR_OFFSET : GPCR_OFFSET)); 270 (value ? GPSR_OFFSET : GPCR_OFFSET));
270} 271}
271 272
272static int __devinit pxa_init_gpio_chip(int gpio_end) 273static int __devinit pxa_init_gpio_chip(int gpio_end,
274 int (*set_wake)(unsigned int, unsigned int))
273{ 275{
274 int i, gpio, nbanks = gpio_to_bank(gpio_end) + 1; 276 int i, gpio, nbanks = gpio_to_bank(gpio_end) + 1;
275 struct pxa_gpio_chip *chips; 277 struct pxa_gpio_chip *chips;
@@ -285,6 +287,7 @@ static int __devinit pxa_init_gpio_chip(int gpio_end)
285 287
286 sprintf(chips[i].label, "gpio-%d", i); 288 sprintf(chips[i].label, "gpio-%d", i);
287 chips[i].regbase = gpio_reg_base + BANK_OFF(i); 289 chips[i].regbase = gpio_reg_base + BANK_OFF(i);
290 chips[i].set_wake = set_wake;
288 291
289 c->base = gpio; 292 c->base = gpio;
290 c->label = chips[i].label; 293 c->label = chips[i].label;
@@ -412,6 +415,17 @@ static void pxa_mask_muxed_gpio(struct irq_data *d)
412 writel_relaxed(gfer, c->regbase + GFER_OFFSET); 415 writel_relaxed(gfer, c->regbase + GFER_OFFSET);
413} 416}
414 417
418static int pxa_gpio_set_wake(struct irq_data *d, unsigned int on)
419{
420 int gpio = pxa_irq_to_gpio(d->irq);
421 struct pxa_gpio_chip *c = gpio_to_pxachip(gpio);
422
423 if (c->set_wake)
424 return c->set_wake(gpio, on);
425 else
426 return 0;
427}
428
415static void pxa_unmask_muxed_gpio(struct irq_data *d) 429static void pxa_unmask_muxed_gpio(struct irq_data *d)
416{ 430{
417 int gpio = pxa_irq_to_gpio(d->irq); 431 int gpio = pxa_irq_to_gpio(d->irq);
@@ -427,6 +441,7 @@ static struct irq_chip pxa_muxed_gpio_chip = {
427 .irq_mask = pxa_mask_muxed_gpio, 441 .irq_mask = pxa_mask_muxed_gpio,
428 .irq_unmask = pxa_unmask_muxed_gpio, 442 .irq_unmask = pxa_unmask_muxed_gpio,
429 .irq_set_type = pxa_gpio_irq_type, 443 .irq_set_type = pxa_gpio_irq_type,
444 .irq_set_wake = pxa_gpio_set_wake,
430}; 445};
431 446
432static int pxa_gpio_nums(void) 447static int pxa_gpio_nums(void)
@@ -471,6 +486,7 @@ static int __devinit pxa_gpio_probe(struct platform_device *pdev)
471 struct pxa_gpio_chip *c; 486 struct pxa_gpio_chip *c;
472 struct resource *res; 487 struct resource *res;
473 struct clk *clk; 488 struct clk *clk;
489 struct pxa_gpio_platform_data *info;
474 int gpio, irq, ret; 490 int gpio, irq, ret;
475 int irq0 = 0, irq1 = 0, irq_mux, gpio_offset = 0; 491 int irq0 = 0, irq1 = 0, irq_mux, gpio_offset = 0;
476 492
@@ -516,7 +532,8 @@ static int __devinit pxa_gpio_probe(struct platform_device *pdev)
516 } 532 }
517 533
518 /* Initialize GPIO chips */ 534 /* Initialize GPIO chips */
519 pxa_init_gpio_chip(pxa_last_gpio); 535 info = dev_get_platdata(&pdev->dev);
536 pxa_init_gpio_chip(pxa_last_gpio, info ? info->gpio_set_wake : NULL);
520 537
521 /* clear all GPIO edge detects */ 538 /* clear all GPIO edge detects */
522 for_each_gpio_chip(gpio, c) { 539 for_each_gpio_chip(gpio, c) {
diff --git a/drivers/gpio/gpio-samsung.c b/drivers/gpio/gpio-samsung.c
index 46277877b7ec..e991d9171961 100644
--- a/drivers/gpio/gpio-samsung.c
+++ b/drivers/gpio/gpio-samsung.c
@@ -452,12 +452,14 @@ static struct samsung_gpio_cfg s3c24xx_gpiocfg_banka = {
452}; 452};
453#endif 453#endif
454 454
455#if defined(CONFIG_ARCH_EXYNOS4) || defined(CONFIG_ARCH_EXYNOS5)
455static struct samsung_gpio_cfg exynos_gpio_cfg = { 456static struct samsung_gpio_cfg exynos_gpio_cfg = {
456 .set_pull = exynos_gpio_setpull, 457 .set_pull = exynos_gpio_setpull,
457 .get_pull = exynos_gpio_getpull, 458 .get_pull = exynos_gpio_getpull,
458 .set_config = samsung_gpio_setcfg_4bit, 459 .set_config = samsung_gpio_setcfg_4bit,
459 .get_config = samsung_gpio_getcfg_4bit, 460 .get_config = samsung_gpio_getcfg_4bit,
460}; 461};
462#endif
461 463
462#if defined(CONFIG_CPU_S5P6440) || defined(CONFIG_CPU_S5P6450) 464#if defined(CONFIG_CPU_S5P6440) || defined(CONFIG_CPU_S5P6450)
463static struct samsung_gpio_cfg s5p64x0_gpio_cfg_rbank = { 465static struct samsung_gpio_cfg s5p64x0_gpio_cfg_rbank = {
@@ -2123,8 +2125,8 @@ static struct samsung_gpio_chip s5pv210_gpios_4bit[] = {
2123 * uses the above macro and depends on the banks being listed in order here. 2125 * uses the above macro and depends on the banks being listed in order here.
2124 */ 2126 */
2125 2127
2126static struct samsung_gpio_chip exynos4_gpios_1[] = {
2127#ifdef CONFIG_ARCH_EXYNOS4 2128#ifdef CONFIG_ARCH_EXYNOS4
2129static struct samsung_gpio_chip exynos4_gpios_1[] = {
2128 { 2130 {
2129 .chip = { 2131 .chip = {
2130 .base = EXYNOS4_GPA0(0), 2132 .base = EXYNOS4_GPA0(0),
@@ -2222,11 +2224,11 @@ static struct samsung_gpio_chip exynos4_gpios_1[] = {
2222 .label = "GPF3", 2224 .label = "GPF3",
2223 }, 2225 },
2224 }, 2226 },
2225#endif
2226}; 2227};
2228#endif
2227 2229
2228static struct samsung_gpio_chip exynos4_gpios_2[] = {
2229#ifdef CONFIG_ARCH_EXYNOS4 2230#ifdef CONFIG_ARCH_EXYNOS4
2231static struct samsung_gpio_chip exynos4_gpios_2[] = {
2230 { 2232 {
2231 .chip = { 2233 .chip = {
2232 .base = EXYNOS4_GPJ0(0), 2234 .base = EXYNOS4_GPJ0(0),
@@ -2367,11 +2369,11 @@ static struct samsung_gpio_chip exynos4_gpios_2[] = {
2367 .to_irq = samsung_gpiolib_to_irq, 2369 .to_irq = samsung_gpiolib_to_irq,
2368 }, 2370 },
2369 }, 2371 },
2370#endif
2371}; 2372};
2373#endif
2372 2374
2373static struct samsung_gpio_chip exynos4_gpios_3[] = {
2374#ifdef CONFIG_ARCH_EXYNOS4 2375#ifdef CONFIG_ARCH_EXYNOS4
2376static struct samsung_gpio_chip exynos4_gpios_3[] = {
2375 { 2377 {
2376 .chip = { 2378 .chip = {
2377 .base = EXYNOS4_GPZ(0), 2379 .base = EXYNOS4_GPZ(0),
@@ -2379,11 +2381,11 @@ static struct samsung_gpio_chip exynos4_gpios_3[] = {
2379 .label = "GPZ", 2381 .label = "GPZ",
2380 }, 2382 },
2381 }, 2383 },
2382#endif
2383}; 2384};
2385#endif
2384 2386
2385static struct samsung_gpio_chip exynos5_gpios_1[] = {
2386#ifdef CONFIG_ARCH_EXYNOS5 2387#ifdef CONFIG_ARCH_EXYNOS5
2388static struct samsung_gpio_chip exynos5_gpios_1[] = {
2387 { 2389 {
2388 .chip = { 2390 .chip = {
2389 .base = EXYNOS5_GPA0(0), 2391 .base = EXYNOS5_GPA0(0),
@@ -2541,11 +2543,11 @@ static struct samsung_gpio_chip exynos5_gpios_1[] = {
2541 .to_irq = samsung_gpiolib_to_irq, 2543 .to_irq = samsung_gpiolib_to_irq,
2542 }, 2544 },
2543 }, 2545 },
2544#endif
2545}; 2546};
2547#endif
2546 2548
2547static struct samsung_gpio_chip exynos5_gpios_2[] = {
2548#ifdef CONFIG_ARCH_EXYNOS5 2549#ifdef CONFIG_ARCH_EXYNOS5
2550static struct samsung_gpio_chip exynos5_gpios_2[] = {
2549 { 2551 {
2550 .chip = { 2552 .chip = {
2551 .base = EXYNOS5_GPE0(0), 2553 .base = EXYNOS5_GPE0(0),
@@ -2602,11 +2604,11 @@ static struct samsung_gpio_chip exynos5_gpios_2[] = {
2602 2604
2603 }, 2605 },
2604 }, 2606 },
2605#endif
2606}; 2607};
2608#endif
2607 2609
2608static struct samsung_gpio_chip exynos5_gpios_3[] = {
2609#ifdef CONFIG_ARCH_EXYNOS5 2610#ifdef CONFIG_ARCH_EXYNOS5
2611static struct samsung_gpio_chip exynos5_gpios_3[] = {
2610 { 2612 {
2611 .chip = { 2613 .chip = {
2612 .base = EXYNOS5_GPV0(0), 2614 .base = EXYNOS5_GPV0(0),
@@ -2638,11 +2640,11 @@ static struct samsung_gpio_chip exynos5_gpios_3[] = {
2638 .label = "GPV4", 2640 .label = "GPV4",
2639 }, 2641 },
2640 }, 2642 },
2641#endif
2642}; 2643};
2644#endif
2643 2645
2644static struct samsung_gpio_chip exynos5_gpios_4[] = {
2645#ifdef CONFIG_ARCH_EXYNOS5 2646#ifdef CONFIG_ARCH_EXYNOS5
2647static struct samsung_gpio_chip exynos5_gpios_4[] = {
2646 { 2648 {
2647 .chip = { 2649 .chip = {
2648 .base = EXYNOS5_GPZ(0), 2650 .base = EXYNOS5_GPZ(0),
@@ -2650,8 +2652,8 @@ static struct samsung_gpio_chip exynos5_gpios_4[] = {
2650 .label = "GPZ", 2652 .label = "GPZ",
2651 }, 2653 },
2652 }, 2654 },
2653#endif
2654}; 2655};
2656#endif
2655 2657
2656 2658
2657#if defined(CONFIG_ARCH_EXYNOS) && defined(CONFIG_OF) 2659#if defined(CONFIG_ARCH_EXYNOS) && defined(CONFIG_OF)
@@ -2719,7 +2721,9 @@ static __init int samsung_gpiolib_init(void)
2719{ 2721{
2720 struct samsung_gpio_chip *chip; 2722 struct samsung_gpio_chip *chip;
2721 int i, nr_chips; 2723 int i, nr_chips;
2724#if defined(CONFIG_CPU_EXYNOS4210) || defined(CONFIG_SOC_EXYNOS5250)
2722 void __iomem *gpio_base1, *gpio_base2, *gpio_base3, *gpio_base4; 2725 void __iomem *gpio_base1, *gpio_base2, *gpio_base3, *gpio_base4;
2726#endif
2723 int group = 0; 2727 int group = 0;
2724 2728
2725 samsung_gpiolib_set_cfg(samsung_gpio_cfgs, ARRAY_SIZE(samsung_gpio_cfgs)); 2729 samsung_gpiolib_set_cfg(samsung_gpio_cfgs, ARRAY_SIZE(samsung_gpio_cfgs));
@@ -2971,6 +2975,7 @@ static __init int samsung_gpiolib_init(void)
2971 2975
2972 return 0; 2976 return 0;
2973 2977
2978#if defined(CONFIG_CPU_EXYNOS4210) || defined(CONFIG_SOC_EXYNOS5250)
2974err_ioremap4: 2979err_ioremap4:
2975 iounmap(gpio_base3); 2980 iounmap(gpio_base3);
2976err_ioremap3: 2981err_ioremap3:
@@ -2979,6 +2984,7 @@ err_ioremap2:
2979 iounmap(gpio_base1); 2984 iounmap(gpio_base1);
2980err_ioremap1: 2985err_ioremap1:
2981 return -ENOMEM; 2986 return -ENOMEM;
2987#endif
2982} 2988}
2983core_initcall(samsung_gpiolib_init); 2989core_initcall(samsung_gpiolib_init);
2984 2990
diff --git a/drivers/gpio/gpio-sodaville.c b/drivers/gpio/gpio-sodaville.c
index 9ba15d31d242..031e5d24837d 100644
--- a/drivers/gpio/gpio-sodaville.c
+++ b/drivers/gpio/gpio-sodaville.c
@@ -41,7 +41,7 @@
41struct sdv_gpio_chip_data { 41struct sdv_gpio_chip_data {
42 int irq_base; 42 int irq_base;
43 void __iomem *gpio_pub_base; 43 void __iomem *gpio_pub_base;
44 struct irq_domain id; 44 struct irq_domain *id;
45 struct irq_chip_generic *gc; 45 struct irq_chip_generic *gc;
46 struct bgpio_chip bgpio; 46 struct bgpio_chip bgpio;
47}; 47};
@@ -51,10 +51,9 @@ static int sdv_gpio_pub_set_type(struct irq_data *d, unsigned int type)
51 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); 51 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
52 struct sdv_gpio_chip_data *sd = gc->private; 52 struct sdv_gpio_chip_data *sd = gc->private;
53 void __iomem *type_reg; 53 void __iomem *type_reg;
54 u32 irq_offs = d->irq - sd->irq_base;
55 u32 reg; 54 u32 reg;
56 55
57 if (irq_offs < 8) 56 if (d->hwirq < 8)
58 type_reg = sd->gpio_pub_base + GPIT1R0; 57 type_reg = sd->gpio_pub_base + GPIT1R0;
59 else 58 else
60 type_reg = sd->gpio_pub_base + GPIT1R1; 59 type_reg = sd->gpio_pub_base + GPIT1R1;
@@ -63,11 +62,11 @@ static int sdv_gpio_pub_set_type(struct irq_data *d, unsigned int type)
63 62
64 switch (type) { 63 switch (type) {
65 case IRQ_TYPE_LEVEL_HIGH: 64 case IRQ_TYPE_LEVEL_HIGH:
66 reg &= ~BIT(4 * (irq_offs % 8)); 65 reg &= ~BIT(4 * (d->hwirq % 8));
67 break; 66 break;
68 67
69 case IRQ_TYPE_LEVEL_LOW: 68 case IRQ_TYPE_LEVEL_LOW:
70 reg |= BIT(4 * (irq_offs % 8)); 69 reg |= BIT(4 * (d->hwirq % 8));
71 break; 70 break;
72 71
73 default: 72 default:
@@ -91,7 +90,7 @@ static irqreturn_t sdv_gpio_pub_irq_handler(int irq, void *data)
91 u32 irq_bit = __fls(irq_stat); 90 u32 irq_bit = __fls(irq_stat);
92 91
93 irq_stat &= ~BIT(irq_bit); 92 irq_stat &= ~BIT(irq_bit);
94 generic_handle_irq(sd->irq_base + irq_bit); 93 generic_handle_irq(irq_find_mapping(sd->id, irq_bit));
95 } 94 }
96 95
97 return IRQ_HANDLED; 96 return IRQ_HANDLED;
@@ -127,7 +126,7 @@ static int sdv_xlate(struct irq_domain *h, struct device_node *node,
127} 126}
128 127
129static struct irq_domain_ops irq_domain_sdv_ops = { 128static struct irq_domain_ops irq_domain_sdv_ops = {
130 .dt_translate = sdv_xlate, 129 .xlate = sdv_xlate,
131}; 130};
132 131
133static __devinit int sdv_register_irqsupport(struct sdv_gpio_chip_data *sd, 132static __devinit int sdv_register_irqsupport(struct sdv_gpio_chip_data *sd,
@@ -149,10 +148,6 @@ static __devinit int sdv_register_irqsupport(struct sdv_gpio_chip_data *sd,
149 if (ret) 148 if (ret)
150 goto out_free_desc; 149 goto out_free_desc;
151 150
152 sd->id.irq_base = sd->irq_base;
153 sd->id.of_node = of_node_get(pdev->dev.of_node);
154 sd->id.ops = &irq_domain_sdv_ops;
155
156 /* 151 /*
157 * This gpio irq controller latches level irqs. Testing shows that if 152 * This gpio irq controller latches level irqs. Testing shows that if
158 * we unmask & ACK the IRQ before the source of the interrupt is gone 153 * we unmask & ACK the IRQ before the source of the interrupt is gone
@@ -179,7 +174,10 @@ static __devinit int sdv_register_irqsupport(struct sdv_gpio_chip_data *sd,
179 IRQ_GC_INIT_MASK_CACHE, IRQ_NOREQUEST, 174 IRQ_GC_INIT_MASK_CACHE, IRQ_NOREQUEST,
180 IRQ_LEVEL | IRQ_NOPROBE); 175 IRQ_LEVEL | IRQ_NOPROBE);
181 176
182 irq_domain_add(&sd->id); 177 sd->id = irq_domain_add_legacy(pdev->dev.of_node, SDV_NUM_PUB_GPIOS,
178 sd->irq_base, 0, &irq_domain_sdv_ops, sd);
179 if (!sd->id)
180 goto out_free_irq;
183 return 0; 181 return 0;
184out_free_irq: 182out_free_irq:
185 free_irq(pdev->irq, sd); 183 free_irq(pdev->irq, sd);
@@ -260,7 +258,6 @@ static void sdv_gpio_remove(struct pci_dev *pdev)
260{ 258{
261 struct sdv_gpio_chip_data *sd = pci_get_drvdata(pdev); 259 struct sdv_gpio_chip_data *sd = pci_get_drvdata(pdev);
262 260
263 irq_domain_del(&sd->id);
264 free_irq(pdev->irq, sd); 261 free_irq(pdev->irq, sd);
265 irq_free_descs(sd->irq_base, SDV_NUM_PUB_GPIOS); 262 irq_free_descs(sd->irq_base, SDV_NUM_PUB_GPIOS);
266 263
diff --git a/drivers/gpio/gpio-tegra.c b/drivers/gpio/gpio-tegra.c
index 32de6707e3c4..12f349b3830d 100644
--- a/drivers/gpio/gpio-tegra.c
+++ b/drivers/gpio/gpio-tegra.c
@@ -22,7 +22,7 @@
22#include <linux/interrupt.h> 22#include <linux/interrupt.h>
23#include <linux/io.h> 23#include <linux/io.h>
24#include <linux/gpio.h> 24#include <linux/gpio.h>
25#include <linux/of.h> 25#include <linux/of_device.h>
26#include <linux/platform_device.h> 26#include <linux/platform_device.h>
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/irqdomain.h> 28#include <linux/irqdomain.h>
@@ -37,7 +37,8 @@
37#define GPIO_PORT(x) (((x) >> 3) & 0x3) 37#define GPIO_PORT(x) (((x) >> 3) & 0x3)
38#define GPIO_BIT(x) ((x) & 0x7) 38#define GPIO_BIT(x) ((x) & 0x7)
39 39
40#define GPIO_REG(x) (GPIO_BANK(x) * 0x80 + GPIO_PORT(x) * 4) 40#define GPIO_REG(x) (GPIO_BANK(x) * tegra_gpio_bank_stride + \
41 GPIO_PORT(x) * 4)
41 42
42#define GPIO_CNF(x) (GPIO_REG(x) + 0x00) 43#define GPIO_CNF(x) (GPIO_REG(x) + 0x00)
43#define GPIO_OE(x) (GPIO_REG(x) + 0x10) 44#define GPIO_OE(x) (GPIO_REG(x) + 0x10)
@@ -48,12 +49,12 @@
48#define GPIO_INT_LVL(x) (GPIO_REG(x) + 0x60) 49#define GPIO_INT_LVL(x) (GPIO_REG(x) + 0x60)
49#define GPIO_INT_CLR(x) (GPIO_REG(x) + 0x70) 50#define GPIO_INT_CLR(x) (GPIO_REG(x) + 0x70)
50 51
51#define GPIO_MSK_CNF(x) (GPIO_REG(x) + 0x800) 52#define GPIO_MSK_CNF(x) (GPIO_REG(x) + tegra_gpio_upper_offset + 0x00)
52#define GPIO_MSK_OE(x) (GPIO_REG(x) + 0x810) 53#define GPIO_MSK_OE(x) (GPIO_REG(x) + tegra_gpio_upper_offset + 0x10)
53#define GPIO_MSK_OUT(x) (GPIO_REG(x) + 0X820) 54#define GPIO_MSK_OUT(x) (GPIO_REG(x) + tegra_gpio_upper_offset + 0X20)
54#define GPIO_MSK_INT_STA(x) (GPIO_REG(x) + 0x840) 55#define GPIO_MSK_INT_STA(x) (GPIO_REG(x) + tegra_gpio_upper_offset + 0x40)
55#define GPIO_MSK_INT_ENB(x) (GPIO_REG(x) + 0x850) 56#define GPIO_MSK_INT_ENB(x) (GPIO_REG(x) + tegra_gpio_upper_offset + 0x50)
56#define GPIO_MSK_INT_LVL(x) (GPIO_REG(x) + 0x860) 57#define GPIO_MSK_INT_LVL(x) (GPIO_REG(x) + tegra_gpio_upper_offset + 0x60)
57 58
58#define GPIO_INT_LVL_MASK 0x010101 59#define GPIO_INT_LVL_MASK 0x010101
59#define GPIO_INT_LVL_EDGE_RISING 0x000101 60#define GPIO_INT_LVL_EDGE_RISING 0x000101
@@ -78,6 +79,8 @@ struct tegra_gpio_bank {
78static struct irq_domain *irq_domain; 79static struct irq_domain *irq_domain;
79static void __iomem *regs; 80static void __iomem *regs;
80static u32 tegra_gpio_bank_count; 81static u32 tegra_gpio_bank_count;
82static u32 tegra_gpio_bank_stride;
83static u32 tegra_gpio_upper_offset;
81static struct tegra_gpio_bank *tegra_gpio_banks; 84static struct tegra_gpio_bank *tegra_gpio_banks;
82 85
83static inline void tegra_gpio_writel(u32 val, u32 reg) 86static inline void tegra_gpio_writel(u32 val, u32 reg)
@@ -333,6 +336,26 @@ static struct irq_chip tegra_gpio_irq_chip = {
333#endif 336#endif
334}; 337};
335 338
339struct tegra_gpio_soc_config {
340 u32 bank_stride;
341 u32 upper_offset;
342};
343
344static struct tegra_gpio_soc_config tegra20_gpio_config = {
345 .bank_stride = 0x80,
346 .upper_offset = 0x800,
347};
348
349static struct tegra_gpio_soc_config tegra30_gpio_config = {
350 .bank_stride = 0x100,
351 .upper_offset = 0x80,
352};
353
354static struct of_device_id tegra_gpio_of_match[] __devinitdata = {
355 { .compatible = "nvidia,tegra30-gpio", .data = &tegra30_gpio_config },
356 { .compatible = "nvidia,tegra20-gpio", .data = &tegra20_gpio_config },
357 { },
358};
336 359
337/* This lock class tells lockdep that GPIO irqs are in a different 360/* This lock class tells lockdep that GPIO irqs are in a different
338 * category than their parents, so it won't report false recursion. 361 * category than their parents, so it won't report false recursion.
@@ -341,6 +364,8 @@ static struct lock_class_key gpio_lock_class;
341 364
342static int __devinit tegra_gpio_probe(struct platform_device *pdev) 365static int __devinit tegra_gpio_probe(struct platform_device *pdev)
343{ 366{
367 const struct of_device_id *match;
368 struct tegra_gpio_soc_config *config;
344 int irq_base; 369 int irq_base;
345 struct resource *res; 370 struct resource *res;
346 struct tegra_gpio_bank *bank; 371 struct tegra_gpio_bank *bank;
@@ -348,6 +373,15 @@ static int __devinit tegra_gpio_probe(struct platform_device *pdev)
348 int i; 373 int i;
349 int j; 374 int j;
350 375
376 match = of_match_device(tegra_gpio_of_match, &pdev->dev);
377 if (match)
378 config = (struct tegra_gpio_soc_config *)match->data;
379 else
380 config = &tegra20_gpio_config;
381
382 tegra_gpio_bank_stride = config->bank_stride;
383 tegra_gpio_upper_offset = config->upper_offset;
384
351 for (;;) { 385 for (;;) {
352 res = platform_get_resource(pdev, IORESOURCE_IRQ, tegra_gpio_bank_count); 386 res = platform_get_resource(pdev, IORESOURCE_IRQ, tegra_gpio_bank_count);
353 if (!res) 387 if (!res)
@@ -402,7 +436,7 @@ static int __devinit tegra_gpio_probe(struct platform_device *pdev)
402 return -ENODEV; 436 return -ENODEV;
403 } 437 }
404 438
405 for (i = 0; i < 7; i++) { 439 for (i = 0; i < tegra_gpio_bank_count; i++) {
406 for (j = 0; j < 4; j++) { 440 for (j = 0; j < 4; j++) {
407 int gpio = tegra_gpio_compose(i, j, 0); 441 int gpio = tegra_gpio_compose(i, j, 0);
408 tegra_gpio_writel(0x00, GPIO_INT_ENB(gpio)); 442 tegra_gpio_writel(0x00, GPIO_INT_ENB(gpio));
@@ -441,11 +475,6 @@ static int __devinit tegra_gpio_probe(struct platform_device *pdev)
441 return 0; 475 return 0;
442} 476}
443 477
444static struct of_device_id tegra_gpio_of_match[] __devinitdata = {
445 { .compatible = "nvidia,tegra20-gpio", },
446 { },
447};
448
449static struct platform_driver tegra_gpio_driver = { 478static struct platform_driver tegra_gpio_driver = {
450 .driver = { 479 .driver = {
451 .name = "tegra-gpio", 480 .name = "tegra-gpio",
@@ -485,7 +514,7 @@ static int dbg_gpio_show(struct seq_file *s, void *unused)
485 int i; 514 int i;
486 int j; 515 int j;
487 516
488 for (i = 0; i < 7; i++) { 517 for (i = 0; i < tegra_gpio_bank_count; i++) {
489 for (j = 0; j < 4; j++) { 518 for (j = 0; j < 4; j++) {
490 int gpio = tegra_gpio_compose(i, j, 0); 519 int gpio = tegra_gpio_compose(i, j, 0);
491 seq_printf(s, 520 seq_printf(s,
diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
index cc1148837e24..e354bc0b052a 100644
--- a/drivers/gpu/drm/Kconfig
+++ b/drivers/gpu/drm/Kconfig
@@ -9,6 +9,7 @@ menuconfig DRM
9 depends on (AGP || AGP=n) && !EMULATED_CMPXCHG && MMU 9 depends on (AGP || AGP=n) && !EMULATED_CMPXCHG && MMU
10 select I2C 10 select I2C
11 select I2C_ALGOBIT 11 select I2C_ALGOBIT
12 select DMA_SHARED_BUFFER
12 help 13 help
13 Kernel-level support for the Direct Rendering Infrastructure (DRI) 14 Kernel-level support for the Direct Rendering Infrastructure (DRI)
14 introduced in XFree86 4.0. If you say Y here, you need to select 15 introduced in XFree86 4.0. If you say Y here, you need to select
diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index a858532806ae..c20da5bda355 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -12,7 +12,7 @@ drm-y := drm_auth.o drm_buffer.o drm_bufs.o drm_cache.o \
12 drm_platform.o drm_sysfs.o drm_hashtab.o drm_mm.o \ 12 drm_platform.o drm_sysfs.o drm_hashtab.o drm_mm.o \
13 drm_crtc.o drm_modes.o drm_edid.o \ 13 drm_crtc.o drm_modes.o drm_edid.o \
14 drm_info.o drm_debugfs.o drm_encoder_slave.o \ 14 drm_info.o drm_debugfs.o drm_encoder_slave.o \
15 drm_trace_points.o drm_global.o 15 drm_trace_points.o drm_global.o drm_prime.o
16 16
17drm-$(CONFIG_COMPAT) += drm_ioc32.o 17drm-$(CONFIG_COMPAT) += drm_ioc32.o
18 18
diff --git a/drivers/gpu/drm/drm_bufs.c b/drivers/gpu/drm/drm_bufs.c
index 30372f7b2d45..348b367debeb 100644
--- a/drivers/gpu/drm/drm_bufs.c
+++ b/drivers/gpu/drm/drm_bufs.c
@@ -1510,8 +1510,8 @@ int drm_freebufs(struct drm_device *dev, void *data,
1510 * \param arg pointer to a drm_buf_map structure. 1510 * \param arg pointer to a drm_buf_map structure.
1511 * \return zero on success or a negative number on failure. 1511 * \return zero on success or a negative number on failure.
1512 * 1512 *
1513 * Maps the AGP, SG or PCI buffer region with do_mmap(), and copies information 1513 * Maps the AGP, SG or PCI buffer region with vm_mmap(), and copies information
1514 * about each buffer into user space. For PCI buffers, it calls do_mmap() with 1514 * about each buffer into user space. For PCI buffers, it calls vm_mmap() with
1515 * offset equal to 0, which drm_mmap() interpretes as PCI buffers and calls 1515 * offset equal to 0, which drm_mmap() interpretes as PCI buffers and calls
1516 * drm_mmap_dma(). 1516 * drm_mmap_dma().
1517 */ 1517 */
@@ -1553,18 +1553,14 @@ int drm_mapbufs(struct drm_device *dev, void *data,
1553 retcode = -EINVAL; 1553 retcode = -EINVAL;
1554 goto done; 1554 goto done;
1555 } 1555 }
1556 down_write(&current->mm->mmap_sem); 1556 virtual = vm_mmap(file_priv->filp, 0, map->size,
1557 virtual = do_mmap(file_priv->filp, 0, map->size,
1558 PROT_READ | PROT_WRITE, 1557 PROT_READ | PROT_WRITE,
1559 MAP_SHARED, 1558 MAP_SHARED,
1560 token); 1559 token);
1561 up_write(&current->mm->mmap_sem);
1562 } else { 1560 } else {
1563 down_write(&current->mm->mmap_sem); 1561 virtual = vm_mmap(file_priv->filp, 0, dma->byte_count,
1564 virtual = do_mmap(file_priv->filp, 0, dma->byte_count,
1565 PROT_READ | PROT_WRITE, 1562 PROT_READ | PROT_WRITE,
1566 MAP_SHARED, 0); 1563 MAP_SHARED, 0);
1567 up_write(&current->mm->mmap_sem);
1568 } 1564 }
1569 if (virtual > -1024UL) { 1565 if (virtual > -1024UL) {
1570 /* Real error */ 1566 /* Real error */
diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index d3aaeb6ae236..c79870a75c2f 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -3335,10 +3335,12 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev,
3335 3335
3336 ret = crtc->funcs->page_flip(crtc, fb, e); 3336 ret = crtc->funcs->page_flip(crtc, fb, e);
3337 if (ret) { 3337 if (ret) {
3338 spin_lock_irqsave(&dev->event_lock, flags); 3338 if (page_flip->flags & DRM_MODE_PAGE_FLIP_EVENT) {
3339 file_priv->event_space += sizeof e->event; 3339 spin_lock_irqsave(&dev->event_lock, flags);
3340 spin_unlock_irqrestore(&dev->event_lock, flags); 3340 file_priv->event_space += sizeof e->event;
3341 kfree(e); 3341 spin_unlock_irqrestore(&dev->event_lock, flags);
3342 kfree(e);
3343 }
3342 } 3344 }
3343 3345
3344out: 3346out:
diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
index 0b65fbc8a630..6116e3b75393 100644
--- a/drivers/gpu/drm/drm_drv.c
+++ b/drivers/gpu/drm/drm_drv.c
@@ -136,6 +136,10 @@ static struct drm_ioctl_desc drm_ioctls[] = {
136 DRM_IOCTL_DEF(DRM_IOCTL_GEM_OPEN, drm_gem_open_ioctl, DRM_AUTH|DRM_UNLOCKED), 136 DRM_IOCTL_DEF(DRM_IOCTL_GEM_OPEN, drm_gem_open_ioctl, DRM_AUTH|DRM_UNLOCKED),
137 137
138 DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETRESOURCES, drm_mode_getresources, DRM_CONTROL_ALLOW|DRM_UNLOCKED), 138 DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETRESOURCES, drm_mode_getresources, DRM_CONTROL_ALLOW|DRM_UNLOCKED),
139
140 DRM_IOCTL_DEF(DRM_IOCTL_PRIME_HANDLE_TO_FD, drm_prime_handle_to_fd_ioctl, DRM_AUTH|DRM_UNLOCKED),
141 DRM_IOCTL_DEF(DRM_IOCTL_PRIME_FD_TO_HANDLE, drm_prime_fd_to_handle_ioctl, DRM_AUTH|DRM_UNLOCKED),
142
139 DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETPLANERESOURCES, drm_mode_getplane_res, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED), 143 DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETPLANERESOURCES, drm_mode_getplane_res, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED),
140 DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETCRTC, drm_mode_getcrtc, DRM_CONTROL_ALLOW|DRM_UNLOCKED), 144 DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETCRTC, drm_mode_getcrtc, DRM_CONTROL_ALLOW|DRM_UNLOCKED),
141 DRM_IOCTL_DEF(DRM_IOCTL_MODE_SETCRTC, drm_mode_setcrtc, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED), 145 DRM_IOCTL_DEF(DRM_IOCTL_MODE_SETCRTC, drm_mode_setcrtc, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED),
diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c
index 7740dd26f007..a0d6e894d97c 100644
--- a/drivers/gpu/drm/drm_fb_helper.c
+++ b/drivers/gpu/drm/drm_fb_helper.c
@@ -559,9 +559,13 @@ int drm_fb_helper_check_var(struct fb_var_screeninfo *var,
559 return -EINVAL; 559 return -EINVAL;
560 560
561 /* Need to resize the fb object !!! */ 561 /* Need to resize the fb object !!! */
562 if (var->bits_per_pixel > fb->bits_per_pixel || var->xres > fb->width || var->yres > fb->height) { 562 if (var->bits_per_pixel > fb->bits_per_pixel ||
563 var->xres > fb->width || var->yres > fb->height ||
564 var->xres_virtual > fb->width || var->yres_virtual > fb->height) {
563 DRM_DEBUG("fb userspace requested width/height/bpp is greater than current fb " 565 DRM_DEBUG("fb userspace requested width/height/bpp is greater than current fb "
564 "object %dx%d-%d > %dx%d-%d\n", var->xres, var->yres, var->bits_per_pixel, 566 "request %dx%d-%d (virtual %dx%d) > %dx%d-%d\n",
567 var->xres, var->yres, var->bits_per_pixel,
568 var->xres_virtual, var->yres_virtual,
565 fb->width, fb->height, fb->bits_per_pixel); 569 fb->width, fb->height, fb->bits_per_pixel);
566 return -EINVAL; 570 return -EINVAL;
567 } 571 }
diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
index 7348a3dab250..123de28f94ef 100644
--- a/drivers/gpu/drm/drm_fops.c
+++ b/drivers/gpu/drm/drm_fops.c
@@ -271,6 +271,9 @@ static int drm_open_helper(struct inode *inode, struct file *filp,
271 if (dev->driver->driver_features & DRIVER_GEM) 271 if (dev->driver->driver_features & DRIVER_GEM)
272 drm_gem_open(dev, priv); 272 drm_gem_open(dev, priv);
273 273
274 if (drm_core_check_feature(dev, DRIVER_PRIME))
275 drm_prime_init_file_private(&priv->prime);
276
274 if (dev->driver->open) { 277 if (dev->driver->open) {
275 ret = dev->driver->open(dev, priv); 278 ret = dev->driver->open(dev, priv);
276 if (ret < 0) 279 if (ret < 0)
@@ -504,12 +507,12 @@ int drm_release(struct inode *inode, struct file *filp)
504 507
505 drm_events_release(file_priv); 508 drm_events_release(file_priv);
506 509
507 if (dev->driver->driver_features & DRIVER_GEM)
508 drm_gem_release(dev, file_priv);
509
510 if (dev->driver->driver_features & DRIVER_MODESET) 510 if (dev->driver->driver_features & DRIVER_MODESET)
511 drm_fb_release(file_priv); 511 drm_fb_release(file_priv);
512 512
513 if (dev->driver->driver_features & DRIVER_GEM)
514 drm_gem_release(dev, file_priv);
515
513 mutex_lock(&dev->ctxlist_mutex); 516 mutex_lock(&dev->ctxlist_mutex);
514 if (!list_empty(&dev->ctxlist)) { 517 if (!list_empty(&dev->ctxlist)) {
515 struct drm_ctx_list *pos, *n; 518 struct drm_ctx_list *pos, *n;
@@ -571,6 +574,10 @@ int drm_release(struct inode *inode, struct file *filp)
571 574
572 if (dev->driver->postclose) 575 if (dev->driver->postclose)
573 dev->driver->postclose(dev, file_priv); 576 dev->driver->postclose(dev, file_priv);
577
578 if (drm_core_check_feature(dev, DRIVER_PRIME))
579 drm_prime_destroy_file_private(&file_priv->prime);
580
574 kfree(file_priv); 581 kfree(file_priv);
575 582
576 /* ======================================================== 583 /* ========================================================
diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c
index 0ef358e53245..83114b5e3cee 100644
--- a/drivers/gpu/drm/drm_gem.c
+++ b/drivers/gpu/drm/drm_gem.c
@@ -35,6 +35,7 @@
35#include <linux/mman.h> 35#include <linux/mman.h>
36#include <linux/pagemap.h> 36#include <linux/pagemap.h>
37#include <linux/shmem_fs.h> 37#include <linux/shmem_fs.h>
38#include <linux/dma-buf.h>
38#include "drmP.h" 39#include "drmP.h"
39 40
40/** @file drm_gem.c 41/** @file drm_gem.c
@@ -232,6 +233,10 @@ drm_gem_handle_delete(struct drm_file *filp, u32 handle)
232 idr_remove(&filp->object_idr, handle); 233 idr_remove(&filp->object_idr, handle);
233 spin_unlock(&filp->table_lock); 234 spin_unlock(&filp->table_lock);
234 235
236 if (obj->import_attach)
237 drm_prime_remove_imported_buf_handle(&filp->prime,
238 obj->import_attach->dmabuf);
239
235 if (dev->driver->gem_close_object) 240 if (dev->driver->gem_close_object)
236 dev->driver->gem_close_object(obj, filp); 241 dev->driver->gem_close_object(obj, filp);
237 drm_gem_object_handle_unreference_unlocked(obj); 242 drm_gem_object_handle_unreference_unlocked(obj);
@@ -527,6 +532,10 @@ drm_gem_object_release_handle(int id, void *ptr, void *data)
527 struct drm_gem_object *obj = ptr; 532 struct drm_gem_object *obj = ptr;
528 struct drm_device *dev = obj->dev; 533 struct drm_device *dev = obj->dev;
529 534
535 if (obj->import_attach)
536 drm_prime_remove_imported_buf_handle(&file_priv->prime,
537 obj->import_attach->dmabuf);
538
530 if (dev->driver->gem_close_object) 539 if (dev->driver->gem_close_object)
531 dev->driver->gem_close_object(obj, file_priv); 540 dev->driver->gem_close_object(obj, file_priv);
532 541
diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c
new file mode 100644
index 000000000000..1bdf2b54eaf6
--- /dev/null
+++ b/drivers/gpu/drm/drm_prime.c
@@ -0,0 +1,304 @@
1/*
2 * Copyright © 2012 Red Hat
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Dave Airlie <airlied@redhat.com>
25 * Rob Clark <rob.clark@linaro.org>
26 *
27 */
28
29#include <linux/export.h>
30#include <linux/dma-buf.h>
31#include "drmP.h"
32
33/*
34 * DMA-BUF/GEM Object references and lifetime overview:
35 *
36 * On the export the dma_buf holds a reference to the exporting GEM
37 * object. It takes this reference in handle_to_fd_ioctl, when it
38 * first calls .prime_export and stores the exporting GEM object in
39 * the dma_buf priv. This reference is released when the dma_buf
40 * object goes away in the driver .release function.
41 *
42 * On the import the importing GEM object holds a reference to the
43 * dma_buf (which in turn holds a ref to the exporting GEM object).
44 * It takes that reference in the fd_to_handle ioctl.
45 * It calls dma_buf_get, creates an attachment to it and stores the
46 * attachment in the GEM object. When this attachment is destroyed
47 * when the imported object is destroyed, we remove the attachment
48 * and drop the reference to the dma_buf.
49 *
50 * Thus the chain of references always flows in one direction
51 * (avoiding loops): importing_gem -> dmabuf -> exporting_gem
52 *
53 * Self-importing: if userspace is using PRIME as a replacement for flink
54 * then it will get a fd->handle request for a GEM object that it created.
55 * Drivers should detect this situation and return back the gem object
56 * from the dma-buf private.
57 */
58
59struct drm_prime_member {
60 struct list_head entry;
61 struct dma_buf *dma_buf;
62 uint32_t handle;
63};
64
65int drm_gem_prime_handle_to_fd(struct drm_device *dev,
66 struct drm_file *file_priv, uint32_t handle, uint32_t flags,
67 int *prime_fd)
68{
69 struct drm_gem_object *obj;
70 void *buf;
71
72 obj = drm_gem_object_lookup(dev, file_priv, handle);
73 if (!obj)
74 return -ENOENT;
75
76 mutex_lock(&file_priv->prime.lock);
77 /* re-export the original imported object */
78 if (obj->import_attach) {
79 get_dma_buf(obj->import_attach->dmabuf);
80 *prime_fd = dma_buf_fd(obj->import_attach->dmabuf, flags);
81 drm_gem_object_unreference_unlocked(obj);
82 mutex_unlock(&file_priv->prime.lock);
83 return 0;
84 }
85
86 if (obj->export_dma_buf) {
87 get_dma_buf(obj->export_dma_buf);
88 *prime_fd = dma_buf_fd(obj->export_dma_buf, flags);
89 drm_gem_object_unreference_unlocked(obj);
90 } else {
91 buf = dev->driver->gem_prime_export(dev, obj, flags);
92 if (IS_ERR(buf)) {
93 /* normally the created dma-buf takes ownership of the ref,
94 * but if that fails then drop the ref
95 */
96 drm_gem_object_unreference_unlocked(obj);
97 mutex_unlock(&file_priv->prime.lock);
98 return PTR_ERR(buf);
99 }
100 obj->export_dma_buf = buf;
101 *prime_fd = dma_buf_fd(buf, flags);
102 }
103 mutex_unlock(&file_priv->prime.lock);
104 return 0;
105}
106EXPORT_SYMBOL(drm_gem_prime_handle_to_fd);
107
108int drm_gem_prime_fd_to_handle(struct drm_device *dev,
109 struct drm_file *file_priv, int prime_fd, uint32_t *handle)
110{
111 struct dma_buf *dma_buf;
112 struct drm_gem_object *obj;
113 int ret;
114
115 dma_buf = dma_buf_get(prime_fd);
116 if (IS_ERR(dma_buf))
117 return PTR_ERR(dma_buf);
118
119 mutex_lock(&file_priv->prime.lock);
120
121 ret = drm_prime_lookup_imported_buf_handle(&file_priv->prime,
122 dma_buf, handle);
123 if (!ret) {
124 ret = 0;
125 goto out_put;
126 }
127
128 /* never seen this one, need to import */
129 obj = dev->driver->gem_prime_import(dev, dma_buf);
130 if (IS_ERR(obj)) {
131 ret = PTR_ERR(obj);
132 goto out_put;
133 }
134
135 ret = drm_gem_handle_create(file_priv, obj, handle);
136 drm_gem_object_unreference_unlocked(obj);
137 if (ret)
138 goto out_put;
139
140 ret = drm_prime_add_imported_buf_handle(&file_priv->prime,
141 dma_buf, *handle);
142 if (ret)
143 goto fail;
144
145 mutex_unlock(&file_priv->prime.lock);
146 return 0;
147
148fail:
149 /* hmm, if driver attached, we are relying on the free-object path
150 * to detach.. which seems ok..
151 */
152 drm_gem_object_handle_unreference_unlocked(obj);
153out_put:
154 dma_buf_put(dma_buf);
155 mutex_unlock(&file_priv->prime.lock);
156 return ret;
157}
158EXPORT_SYMBOL(drm_gem_prime_fd_to_handle);
159
160int drm_prime_handle_to_fd_ioctl(struct drm_device *dev, void *data,
161 struct drm_file *file_priv)
162{
163 struct drm_prime_handle *args = data;
164 uint32_t flags;
165
166 if (!drm_core_check_feature(dev, DRIVER_PRIME))
167 return -EINVAL;
168
169 if (!dev->driver->prime_handle_to_fd)
170 return -ENOSYS;
171
172 /* check flags are valid */
173 if (args->flags & ~DRM_CLOEXEC)
174 return -EINVAL;
175
176 /* we only want to pass DRM_CLOEXEC which is == O_CLOEXEC */
177 flags = args->flags & DRM_CLOEXEC;
178
179 return dev->driver->prime_handle_to_fd(dev, file_priv,
180 args->handle, flags, &args->fd);
181}
182
183int drm_prime_fd_to_handle_ioctl(struct drm_device *dev, void *data,
184 struct drm_file *file_priv)
185{
186 struct drm_prime_handle *args = data;
187
188 if (!drm_core_check_feature(dev, DRIVER_PRIME))
189 return -EINVAL;
190
191 if (!dev->driver->prime_fd_to_handle)
192 return -ENOSYS;
193
194 return dev->driver->prime_fd_to_handle(dev, file_priv,
195 args->fd, &args->handle);
196}
197
198/*
199 * drm_prime_pages_to_sg
200 *
201 * this helper creates an sg table object from a set of pages
202 * the driver is responsible for mapping the pages into the
203 * importers address space
204 */
205struct sg_table *drm_prime_pages_to_sg(struct page **pages, int nr_pages)
206{
207 struct sg_table *sg = NULL;
208 struct scatterlist *iter;
209 int i;
210 int ret;
211
212 sg = kmalloc(sizeof(struct sg_table), GFP_KERNEL);
213 if (!sg)
214 goto out;
215
216 ret = sg_alloc_table(sg, nr_pages, GFP_KERNEL);
217 if (ret)
218 goto out;
219
220 for_each_sg(sg->sgl, iter, nr_pages, i)
221 sg_set_page(iter, pages[i], PAGE_SIZE, 0);
222
223 return sg;
224out:
225 kfree(sg);
226 return NULL;
227}
228EXPORT_SYMBOL(drm_prime_pages_to_sg);
229
230/* helper function to cleanup a GEM/prime object */
231void drm_prime_gem_destroy(struct drm_gem_object *obj, struct sg_table *sg)
232{
233 struct dma_buf_attachment *attach;
234 struct dma_buf *dma_buf;
235 attach = obj->import_attach;
236 if (sg)
237 dma_buf_unmap_attachment(attach, sg, DMA_BIDIRECTIONAL);
238 dma_buf = attach->dmabuf;
239 dma_buf_detach(attach->dmabuf, attach);
240 /* remove the reference */
241 dma_buf_put(dma_buf);
242}
243EXPORT_SYMBOL(drm_prime_gem_destroy);
244
245void drm_prime_init_file_private(struct drm_prime_file_private *prime_fpriv)
246{
247 INIT_LIST_HEAD(&prime_fpriv->head);
248 mutex_init(&prime_fpriv->lock);
249}
250EXPORT_SYMBOL(drm_prime_init_file_private);
251
252void drm_prime_destroy_file_private(struct drm_prime_file_private *prime_fpriv)
253{
254 struct drm_prime_member *member, *safe;
255 list_for_each_entry_safe(member, safe, &prime_fpriv->head, entry) {
256 list_del(&member->entry);
257 kfree(member);
258 }
259}
260EXPORT_SYMBOL(drm_prime_destroy_file_private);
261
262int drm_prime_add_imported_buf_handle(struct drm_prime_file_private *prime_fpriv, struct dma_buf *dma_buf, uint32_t handle)
263{
264 struct drm_prime_member *member;
265
266 member = kmalloc(sizeof(*member), GFP_KERNEL);
267 if (!member)
268 return -ENOMEM;
269
270 member->dma_buf = dma_buf;
271 member->handle = handle;
272 list_add(&member->entry, &prime_fpriv->head);
273 return 0;
274}
275EXPORT_SYMBOL(drm_prime_add_imported_buf_handle);
276
277int drm_prime_lookup_imported_buf_handle(struct drm_prime_file_private *prime_fpriv, struct dma_buf *dma_buf, uint32_t *handle)
278{
279 struct drm_prime_member *member;
280
281 list_for_each_entry(member, &prime_fpriv->head, entry) {
282 if (member->dma_buf == dma_buf) {
283 *handle = member->handle;
284 return 0;
285 }
286 }
287 return -ENOENT;
288}
289EXPORT_SYMBOL(drm_prime_lookup_imported_buf_handle);
290
291void drm_prime_remove_imported_buf_handle(struct drm_prime_file_private *prime_fpriv, struct dma_buf *dma_buf)
292{
293 struct drm_prime_member *member, *safe;
294
295 mutex_lock(&prime_fpriv->lock);
296 list_for_each_entry_safe(member, safe, &prime_fpriv->head, entry) {
297 if (member->dma_buf == dma_buf) {
298 list_del(&member->entry);
299 kfree(member);
300 }
301 }
302 mutex_unlock(&prime_fpriv->lock);
303}
304EXPORT_SYMBOL(drm_prime_remove_imported_buf_handle);
diff --git a/drivers/gpu/drm/drm_usb.c b/drivers/gpu/drm/drm_usb.c
index c8c83dad2ce1..37c9a523dd1c 100644
--- a/drivers/gpu/drm/drm_usb.c
+++ b/drivers/gpu/drm/drm_usb.c
@@ -1,6 +1,6 @@
1#include "drmP.h" 1#include "drmP.h"
2#include <linux/usb.h> 2#include <linux/usb.h>
3#include <linux/export.h> 3#include <linux/module.h>
4 4
5int drm_get_usb_dev(struct usb_interface *interface, 5int drm_get_usb_dev(struct usb_interface *interface,
6 const struct usb_device_id *id, 6 const struct usb_device_id *id,
@@ -114,3 +114,7 @@ void drm_usb_exit(struct drm_driver *driver,
114 usb_deregister(udriver); 114 usb_deregister(udriver);
115} 115}
116EXPORT_SYMBOL(drm_usb_exit); 116EXPORT_SYMBOL(drm_usb_exit);
117
118MODULE_AUTHOR("David Airlie");
119MODULE_DESCRIPTION("USB DRM support");
120MODULE_LICENSE("GPL and additional rights");
diff --git a/drivers/gpu/drm/exynos/exynos_drm_buf.c b/drivers/gpu/drm/exynos/exynos_drm_buf.c
index 4a3a5f72ed4a..de8d2090bce3 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_buf.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_buf.c
@@ -34,14 +34,14 @@
34static int lowlevel_buffer_allocate(struct drm_device *dev, 34static int lowlevel_buffer_allocate(struct drm_device *dev,
35 unsigned int flags, struct exynos_drm_gem_buf *buf) 35 unsigned int flags, struct exynos_drm_gem_buf *buf)
36{ 36{
37 dma_addr_t start_addr, end_addr; 37 dma_addr_t start_addr;
38 unsigned int npages, page_size, i = 0; 38 unsigned int npages, page_size, i = 0;
39 struct scatterlist *sgl; 39 struct scatterlist *sgl;
40 int ret = 0; 40 int ret = 0;
41 41
42 DRM_DEBUG_KMS("%s\n", __FILE__); 42 DRM_DEBUG_KMS("%s\n", __FILE__);
43 43
44 if (flags & EXYNOS_BO_NONCONTIG) { 44 if (IS_NONCONTIG_BUFFER(flags)) {
45 DRM_DEBUG_KMS("not support allocation type.\n"); 45 DRM_DEBUG_KMS("not support allocation type.\n");
46 return -EINVAL; 46 return -EINVAL;
47 } 47 }
@@ -52,13 +52,13 @@ static int lowlevel_buffer_allocate(struct drm_device *dev,
52 } 52 }
53 53
54 if (buf->size >= SZ_1M) { 54 if (buf->size >= SZ_1M) {
55 npages = (buf->size >> SECTION_SHIFT) + 1; 55 npages = buf->size >> SECTION_SHIFT;
56 page_size = SECTION_SIZE; 56 page_size = SECTION_SIZE;
57 } else if (buf->size >= SZ_64K) { 57 } else if (buf->size >= SZ_64K) {
58 npages = (buf->size >> 16) + 1; 58 npages = buf->size >> 16;
59 page_size = SZ_64K; 59 page_size = SZ_64K;
60 } else { 60 } else {
61 npages = (buf->size >> PAGE_SHIFT) + 1; 61 npages = buf->size >> PAGE_SHIFT;
62 page_size = PAGE_SIZE; 62 page_size = PAGE_SIZE;
63 } 63 }
64 64
@@ -76,26 +76,13 @@ static int lowlevel_buffer_allocate(struct drm_device *dev,
76 return -ENOMEM; 76 return -ENOMEM;
77 } 77 }
78 78
79 buf->kvaddr = dma_alloc_writecombine(dev->dev, buf->size, 79 buf->kvaddr = dma_alloc_writecombine(dev->dev, buf->size,
80 &buf->dma_addr, GFP_KERNEL); 80 &buf->dma_addr, GFP_KERNEL);
81 if (!buf->kvaddr) { 81 if (!buf->kvaddr) {
82 DRM_ERROR("failed to allocate buffer.\n"); 82 DRM_ERROR("failed to allocate buffer.\n");
83 ret = -ENOMEM; 83 ret = -ENOMEM;
84 goto err1; 84 goto err1;
85 } 85 }
86
87 start_addr = buf->dma_addr;
88 end_addr = buf->dma_addr + buf->size;
89
90 buf->pages = kzalloc(sizeof(struct page) * npages, GFP_KERNEL);
91 if (!buf->pages) {
92 DRM_ERROR("failed to allocate pages.\n");
93 ret = -ENOMEM;
94 goto err2;
95 }
96
97 start_addr = buf->dma_addr;
98 end_addr = buf->dma_addr + buf->size;
99 86
100 buf->pages = kzalloc(sizeof(struct page) * npages, GFP_KERNEL); 87 buf->pages = kzalloc(sizeof(struct page) * npages, GFP_KERNEL);
101 if (!buf->pages) { 88 if (!buf->pages) {
@@ -105,23 +92,17 @@ static int lowlevel_buffer_allocate(struct drm_device *dev,
105 } 92 }
106 93
107 sgl = buf->sgt->sgl; 94 sgl = buf->sgt->sgl;
95 start_addr = buf->dma_addr;
108 96
109 while (i < npages) { 97 while (i < npages) {
110 buf->pages[i] = phys_to_page(start_addr); 98 buf->pages[i] = phys_to_page(start_addr);
111 sg_set_page(sgl, buf->pages[i], page_size, 0); 99 sg_set_page(sgl, buf->pages[i], page_size, 0);
112 sg_dma_address(sgl) = start_addr; 100 sg_dma_address(sgl) = start_addr;
113 start_addr += page_size; 101 start_addr += page_size;
114 if (end_addr - start_addr < page_size)
115 break;
116 sgl = sg_next(sgl); 102 sgl = sg_next(sgl);
117 i++; 103 i++;
118 } 104 }
119 105
120 buf->pages[i] = phys_to_page(start_addr);
121
122 sgl = sg_next(sgl);
123 sg_set_page(sgl, buf->pages[i+1], end_addr - start_addr, 0);
124
125 DRM_DEBUG_KMS("vaddr(0x%lx), dma_addr(0x%lx), size(0x%lx)\n", 106 DRM_DEBUG_KMS("vaddr(0x%lx), dma_addr(0x%lx), size(0x%lx)\n",
126 (unsigned long)buf->kvaddr, 107 (unsigned long)buf->kvaddr,
127 (unsigned long)buf->dma_addr, 108 (unsigned long)buf->dma_addr,
@@ -150,7 +131,7 @@ static void lowlevel_buffer_deallocate(struct drm_device *dev,
150 * non-continuous memory would be released by exynos 131 * non-continuous memory would be released by exynos
151 * gem framework. 132 * gem framework.
152 */ 133 */
153 if (flags & EXYNOS_BO_NONCONTIG) { 134 if (IS_NONCONTIG_BUFFER(flags)) {
154 DRM_DEBUG_KMS("not support allocation type.\n"); 135 DRM_DEBUG_KMS("not support allocation type.\n");
155 return; 136 return;
156 } 137 }
diff --git a/drivers/gpu/drm/exynos/exynos_drm_core.c b/drivers/gpu/drm/exynos/exynos_drm_core.c
index 411832e8e17a..eaf630dc5dba 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_core.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_core.c
@@ -54,16 +54,18 @@ static int exynos_drm_subdrv_probe(struct drm_device *dev,
54 * 54 *
55 * P.S. note that this driver is considered for modularization. 55 * P.S. note that this driver is considered for modularization.
56 */ 56 */
57 ret = subdrv->probe(dev, subdrv->manager.dev); 57 ret = subdrv->probe(dev, subdrv->dev);
58 if (ret) 58 if (ret)
59 return ret; 59 return ret;
60 } 60 }
61 61
62 if (subdrv->is_local) 62 if (!subdrv->manager)
63 return 0; 63 return 0;
64 64
65 subdrv->manager->dev = subdrv->dev;
66
65 /* create and initialize a encoder for this sub driver. */ 67 /* create and initialize a encoder for this sub driver. */
66 encoder = exynos_drm_encoder_create(dev, &subdrv->manager, 68 encoder = exynos_drm_encoder_create(dev, subdrv->manager,
67 (1 << MAX_CRTC) - 1); 69 (1 << MAX_CRTC) - 1);
68 if (!encoder) { 70 if (!encoder) {
69 DRM_ERROR("failed to create encoder\n"); 71 DRM_ERROR("failed to create encoder\n");
@@ -186,7 +188,7 @@ int exynos_drm_subdrv_open(struct drm_device *dev, struct drm_file *file)
186 188
187 list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list) { 189 list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list) {
188 if (subdrv->open) { 190 if (subdrv->open) {
189 ret = subdrv->open(dev, subdrv->manager.dev, file); 191 ret = subdrv->open(dev, subdrv->dev, file);
190 if (ret) 192 if (ret)
191 goto err; 193 goto err;
192 } 194 }
@@ -197,7 +199,7 @@ int exynos_drm_subdrv_open(struct drm_device *dev, struct drm_file *file)
197err: 199err:
198 list_for_each_entry_reverse(subdrv, &subdrv->list, list) { 200 list_for_each_entry_reverse(subdrv, &subdrv->list, list) {
199 if (subdrv->close) 201 if (subdrv->close)
200 subdrv->close(dev, subdrv->manager.dev, file); 202 subdrv->close(dev, subdrv->dev, file);
201 } 203 }
202 return ret; 204 return ret;
203} 205}
@@ -209,7 +211,7 @@ void exynos_drm_subdrv_close(struct drm_device *dev, struct drm_file *file)
209 211
210 list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list) { 212 list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list) {
211 if (subdrv->close) 213 if (subdrv->close)
212 subdrv->close(dev, subdrv->manager.dev, file); 214 subdrv->close(dev, subdrv->dev, file);
213 } 215 }
214} 216}
215EXPORT_SYMBOL_GPL(exynos_drm_subdrv_close); 217EXPORT_SYMBOL_GPL(exynos_drm_subdrv_close);
diff --git a/drivers/gpu/drm/exynos/exynos_drm_drv.h b/drivers/gpu/drm/exynos/exynos_drm_drv.h
index fbd0a232c93d..1d814175cd49 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_drv.h
+++ b/drivers/gpu/drm/exynos/exynos_drm_drv.h
@@ -225,24 +225,25 @@ struct exynos_drm_private {
225 * Exynos drm sub driver structure. 225 * Exynos drm sub driver structure.
226 * 226 *
227 * @list: sub driver has its own list object to register to exynos drm driver. 227 * @list: sub driver has its own list object to register to exynos drm driver.
228 * @dev: pointer to device object for subdrv device driver.
228 * @drm_dev: pointer to drm_device and this pointer would be set 229 * @drm_dev: pointer to drm_device and this pointer would be set
229 * when sub driver calls exynos_drm_subdrv_register(). 230 * when sub driver calls exynos_drm_subdrv_register().
230 * @is_local: appear encoder and connector disrelated device. 231 * @manager: subdrv has its own manager to control a hardware appropriately
232 * and we can access a hardware drawing on this manager.
231 * @probe: this callback would be called by exynos drm driver after 233 * @probe: this callback would be called by exynos drm driver after
232 * subdrv is registered to it. 234 * subdrv is registered to it.
233 * @remove: this callback is used to release resources created 235 * @remove: this callback is used to release resources created
234 * by probe callback. 236 * by probe callback.
235 * @open: this would be called with drm device file open. 237 * @open: this would be called with drm device file open.
236 * @close: this would be called with drm device file close. 238 * @close: this would be called with drm device file close.
237 * @manager: subdrv has its own manager to control a hardware appropriately
238 * and we can access a hardware drawing on this manager.
239 * @encoder: encoder object owned by this sub driver. 239 * @encoder: encoder object owned by this sub driver.
240 * @connector: connector object owned by this sub driver. 240 * @connector: connector object owned by this sub driver.
241 */ 241 */
242struct exynos_drm_subdrv { 242struct exynos_drm_subdrv {
243 struct list_head list; 243 struct list_head list;
244 struct device *dev;
244 struct drm_device *drm_dev; 245 struct drm_device *drm_dev;
245 bool is_local; 246 struct exynos_drm_manager *manager;
246 247
247 int (*probe)(struct drm_device *drm_dev, struct device *dev); 248 int (*probe)(struct drm_device *drm_dev, struct device *dev);
248 void (*remove)(struct drm_device *dev); 249 void (*remove)(struct drm_device *dev);
@@ -251,7 +252,6 @@ struct exynos_drm_subdrv {
251 void (*close)(struct drm_device *drm_dev, struct device *dev, 252 void (*close)(struct drm_device *drm_dev, struct device *dev,
252 struct drm_file *file); 253 struct drm_file *file);
253 254
254 struct exynos_drm_manager manager;
255 struct drm_encoder *encoder; 255 struct drm_encoder *encoder;
256 struct drm_connector *connector; 256 struct drm_connector *connector;
257}; 257};
diff --git a/drivers/gpu/drm/exynos/exynos_drm_fimd.c b/drivers/gpu/drm/exynos/exynos_drm_fimd.c
index ecb6db229700..29fdbfeb43cb 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_fimd.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_fimd.c
@@ -172,7 +172,7 @@ static void fimd_dpms(struct device *subdrv_dev, int mode)
172static void fimd_apply(struct device *subdrv_dev) 172static void fimd_apply(struct device *subdrv_dev)
173{ 173{
174 struct fimd_context *ctx = get_fimd_context(subdrv_dev); 174 struct fimd_context *ctx = get_fimd_context(subdrv_dev);
175 struct exynos_drm_manager *mgr = &ctx->subdrv.manager; 175 struct exynos_drm_manager *mgr = ctx->subdrv.manager;
176 struct exynos_drm_manager_ops *mgr_ops = mgr->ops; 176 struct exynos_drm_manager_ops *mgr_ops = mgr->ops;
177 struct exynos_drm_overlay_ops *ovl_ops = mgr->overlay_ops; 177 struct exynos_drm_overlay_ops *ovl_ops = mgr->overlay_ops;
178 struct fimd_win_data *win_data; 178 struct fimd_win_data *win_data;
@@ -577,6 +577,13 @@ static struct exynos_drm_overlay_ops fimd_overlay_ops = {
577 .disable = fimd_win_disable, 577 .disable = fimd_win_disable,
578}; 578};
579 579
580static struct exynos_drm_manager fimd_manager = {
581 .pipe = -1,
582 .ops = &fimd_manager_ops,
583 .overlay_ops = &fimd_overlay_ops,
584 .display_ops = &fimd_display_ops,
585};
586
580static void fimd_finish_pageflip(struct drm_device *drm_dev, int crtc) 587static void fimd_finish_pageflip(struct drm_device *drm_dev, int crtc)
581{ 588{
582 struct exynos_drm_private *dev_priv = drm_dev->dev_private; 589 struct exynos_drm_private *dev_priv = drm_dev->dev_private;
@@ -628,7 +635,7 @@ static irqreturn_t fimd_irq_handler(int irq, void *dev_id)
628 struct fimd_context *ctx = (struct fimd_context *)dev_id; 635 struct fimd_context *ctx = (struct fimd_context *)dev_id;
629 struct exynos_drm_subdrv *subdrv = &ctx->subdrv; 636 struct exynos_drm_subdrv *subdrv = &ctx->subdrv;
630 struct drm_device *drm_dev = subdrv->drm_dev; 637 struct drm_device *drm_dev = subdrv->drm_dev;
631 struct exynos_drm_manager *manager = &subdrv->manager; 638 struct exynos_drm_manager *manager = subdrv->manager;
632 u32 val; 639 u32 val;
633 640
634 val = readl(ctx->regs + VIDINTCON1); 641 val = readl(ctx->regs + VIDINTCON1);
@@ -744,7 +751,7 @@ static void fimd_clear_win(struct fimd_context *ctx, int win)
744static int fimd_power_on(struct fimd_context *ctx, bool enable) 751static int fimd_power_on(struct fimd_context *ctx, bool enable)
745{ 752{
746 struct exynos_drm_subdrv *subdrv = &ctx->subdrv; 753 struct exynos_drm_subdrv *subdrv = &ctx->subdrv;
747 struct device *dev = subdrv->manager.dev; 754 struct device *dev = subdrv->dev;
748 755
749 DRM_DEBUG_KMS("%s\n", __FILE__); 756 DRM_DEBUG_KMS("%s\n", __FILE__);
750 757
@@ -867,13 +874,10 @@ static int __devinit fimd_probe(struct platform_device *pdev)
867 874
868 subdrv = &ctx->subdrv; 875 subdrv = &ctx->subdrv;
869 876
877 subdrv->dev = dev;
878 subdrv->manager = &fimd_manager;
870 subdrv->probe = fimd_subdrv_probe; 879 subdrv->probe = fimd_subdrv_probe;
871 subdrv->remove = fimd_subdrv_remove; 880 subdrv->remove = fimd_subdrv_remove;
872 subdrv->manager.pipe = -1;
873 subdrv->manager.ops = &fimd_manager_ops;
874 subdrv->manager.overlay_ops = &fimd_overlay_ops;
875 subdrv->manager.display_ops = &fimd_display_ops;
876 subdrv->manager.dev = dev;
877 881
878 mutex_init(&ctx->lock); 882 mutex_init(&ctx->lock);
879 883
diff --git a/drivers/gpu/drm/exynos/exynos_drm_gem.c b/drivers/gpu/drm/exynos/exynos_drm_gem.c
index fa1aa94a3d8e..1dffa8359f88 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_gem.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_gem.c
@@ -56,9 +56,28 @@ static unsigned int convert_to_vm_err_msg(int msg)
56 return out_msg; 56 return out_msg;
57} 57}
58 58
59static unsigned int mask_gem_flags(unsigned int flags) 59static int check_gem_flags(unsigned int flags)
60{ 60{
61 return flags &= EXYNOS_BO_NONCONTIG; 61 if (flags & ~(EXYNOS_BO_MASK)) {
62 DRM_ERROR("invalid flags.\n");
63 return -EINVAL;
64 }
65
66 return 0;
67}
68
69static unsigned long roundup_gem_size(unsigned long size, unsigned int flags)
70{
71 if (!IS_NONCONTIG_BUFFER(flags)) {
72 if (size >= SZ_1M)
73 return roundup(size, SECTION_SIZE);
74 else if (size >= SZ_64K)
75 return roundup(size, SZ_64K);
76 else
77 goto out;
78 }
79out:
80 return roundup(size, PAGE_SIZE);
62} 81}
63 82
64static struct page **exynos_gem_get_pages(struct drm_gem_object *obj, 83static struct page **exynos_gem_get_pages(struct drm_gem_object *obj,
@@ -130,22 +149,12 @@ static int exynos_drm_gem_map_pages(struct drm_gem_object *obj,
130 unsigned long pfn; 149 unsigned long pfn;
131 150
132 if (exynos_gem_obj->flags & EXYNOS_BO_NONCONTIG) { 151 if (exynos_gem_obj->flags & EXYNOS_BO_NONCONTIG) {
133 unsigned long usize = buf->size;
134
135 if (!buf->pages) 152 if (!buf->pages)
136 return -EINTR; 153 return -EINTR;
137 154
138 while (usize > 0) { 155 pfn = page_to_pfn(buf->pages[page_offset++]);
139 pfn = page_to_pfn(buf->pages[page_offset++]); 156 } else
140 vm_insert_mixed(vma, f_vaddr, pfn); 157 pfn = (buf->dma_addr >> PAGE_SHIFT) + page_offset;
141 f_vaddr += PAGE_SIZE;
142 usize -= PAGE_SIZE;
143 }
144
145 return 0;
146 }
147
148 pfn = (buf->dma_addr >> PAGE_SHIFT) + page_offset;
149 158
150 return vm_insert_mixed(vma, f_vaddr, pfn); 159 return vm_insert_mixed(vma, f_vaddr, pfn);
151} 160}
@@ -319,10 +328,17 @@ struct exynos_drm_gem_obj *exynos_drm_gem_create(struct drm_device *dev,
319 struct exynos_drm_gem_buf *buf; 328 struct exynos_drm_gem_buf *buf;
320 int ret; 329 int ret;
321 330
322 size = roundup(size, PAGE_SIZE); 331 if (!size) {
323 DRM_DEBUG_KMS("%s: size = 0x%lx\n", __FILE__, size); 332 DRM_ERROR("invalid size.\n");
333 return ERR_PTR(-EINVAL);
334 }
335
336 size = roundup_gem_size(size, flags);
337 DRM_DEBUG_KMS("%s\n", __FILE__);
324 338
325 flags = mask_gem_flags(flags); 339 ret = check_gem_flags(flags);
340 if (ret)
341 return ERR_PTR(ret);
326 342
327 buf = exynos_drm_init_buf(dev, size); 343 buf = exynos_drm_init_buf(dev, size);
328 if (!buf) 344 if (!buf)
@@ -331,7 +347,7 @@ struct exynos_drm_gem_obj *exynos_drm_gem_create(struct drm_device *dev,
331 exynos_gem_obj = exynos_drm_gem_init(dev, size); 347 exynos_gem_obj = exynos_drm_gem_init(dev, size);
332 if (!exynos_gem_obj) { 348 if (!exynos_gem_obj) {
333 ret = -ENOMEM; 349 ret = -ENOMEM;
334 goto err; 350 goto err_fini_buf;
335 } 351 }
336 352
337 exynos_gem_obj->buffer = buf; 353 exynos_gem_obj->buffer = buf;
@@ -347,18 +363,19 @@ struct exynos_drm_gem_obj *exynos_drm_gem_create(struct drm_device *dev,
347 ret = exynos_drm_gem_get_pages(&exynos_gem_obj->base); 363 ret = exynos_drm_gem_get_pages(&exynos_gem_obj->base);
348 if (ret < 0) { 364 if (ret < 0) {
349 drm_gem_object_release(&exynos_gem_obj->base); 365 drm_gem_object_release(&exynos_gem_obj->base);
350 goto err; 366 goto err_fini_buf;
351 } 367 }
352 } else { 368 } else {
353 ret = exynos_drm_alloc_buf(dev, buf, flags); 369 ret = exynos_drm_alloc_buf(dev, buf, flags);
354 if (ret < 0) { 370 if (ret < 0) {
355 drm_gem_object_release(&exynos_gem_obj->base); 371 drm_gem_object_release(&exynos_gem_obj->base);
356 goto err; 372 goto err_fini_buf;
357 } 373 }
358 } 374 }
359 375
360 return exynos_gem_obj; 376 return exynos_gem_obj;
361err: 377
378err_fini_buf:
362 exynos_drm_fini_buf(dev, buf); 379 exynos_drm_fini_buf(dev, buf);
363 return ERR_PTR(ret); 380 return ERR_PTR(ret);
364} 381}
@@ -497,6 +514,8 @@ static int exynos_drm_gem_mmap_buffer(struct file *filp,
497 if (!buffer->pages) 514 if (!buffer->pages)
498 return -EINVAL; 515 return -EINVAL;
499 516
517 vma->vm_flags |= VM_MIXEDMAP;
518
500 do { 519 do {
501 ret = vm_insert_page(vma, uaddr, buffer->pages[i++]); 520 ret = vm_insert_page(vma, uaddr, buffer->pages[i++]);
502 if (ret) { 521 if (ret) {
@@ -554,10 +573,8 @@ int exynos_drm_gem_mmap_ioctl(struct drm_device *dev, void *data,
554 obj->filp->f_op = &exynos_drm_gem_fops; 573 obj->filp->f_op = &exynos_drm_gem_fops;
555 obj->filp->private_data = obj; 574 obj->filp->private_data = obj;
556 575
557 down_write(&current->mm->mmap_sem); 576 addr = vm_mmap(obj->filp, 0, args->size,
558 addr = do_mmap(obj->filp, 0, args->size,
559 PROT_READ | PROT_WRITE, MAP_SHARED, 0); 577 PROT_READ | PROT_WRITE, MAP_SHARED, 0);
560 up_write(&current->mm->mmap_sem);
561 578
562 drm_gem_object_unreference_unlocked(obj); 579 drm_gem_object_unreference_unlocked(obj);
563 580
@@ -685,7 +702,6 @@ int exynos_drm_gem_dumb_destroy(struct drm_file *file_priv,
685int exynos_drm_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf) 702int exynos_drm_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
686{ 703{
687 struct drm_gem_object *obj = vma->vm_private_data; 704 struct drm_gem_object *obj = vma->vm_private_data;
688 struct exynos_drm_gem_obj *exynos_gem_obj = to_exynos_gem_obj(obj);
689 struct drm_device *dev = obj->dev; 705 struct drm_device *dev = obj->dev;
690 unsigned long f_vaddr; 706 unsigned long f_vaddr;
691 pgoff_t page_offset; 707 pgoff_t page_offset;
@@ -697,21 +713,10 @@ int exynos_drm_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
697 713
698 mutex_lock(&dev->struct_mutex); 714 mutex_lock(&dev->struct_mutex);
699 715
700 /*
701 * allocate all pages as desired size if user wants to allocate
702 * physically non-continuous memory.
703 */
704 if (exynos_gem_obj->flags & EXYNOS_BO_NONCONTIG) {
705 ret = exynos_drm_gem_get_pages(obj);
706 if (ret < 0)
707 goto err;
708 }
709
710 ret = exynos_drm_gem_map_pages(obj, vma, f_vaddr, page_offset); 716 ret = exynos_drm_gem_map_pages(obj, vma, f_vaddr, page_offset);
711 if (ret < 0) 717 if (ret < 0)
712 DRM_ERROR("failed to map pages.\n"); 718 DRM_ERROR("failed to map pages.\n");
713 719
714err:
715 mutex_unlock(&dev->struct_mutex); 720 mutex_unlock(&dev->struct_mutex);
716 721
717 return convert_to_vm_err_msg(ret); 722 return convert_to_vm_err_msg(ret);
diff --git a/drivers/gpu/drm/exynos/exynos_drm_gem.h b/drivers/gpu/drm/exynos/exynos_drm_gem.h
index e40fbad8b705..4ed842039505 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_gem.h
+++ b/drivers/gpu/drm/exynos/exynos_drm_gem.h
@@ -29,6 +29,8 @@
29#define to_exynos_gem_obj(x) container_of(x,\ 29#define to_exynos_gem_obj(x) container_of(x,\
30 struct exynos_drm_gem_obj, base) 30 struct exynos_drm_gem_obj, base)
31 31
32#define IS_NONCONTIG_BUFFER(f) (f & EXYNOS_BO_NONCONTIG)
33
32/* 34/*
33 * exynos drm gem buffer structure. 35 * exynos drm gem buffer structure.
34 * 36 *
diff --git a/drivers/gpu/drm/exynos/exynos_drm_hdmi.c b/drivers/gpu/drm/exynos/exynos_drm_hdmi.c
index 14eb26b0ba1c..3424463676e0 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_hdmi.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_hdmi.c
@@ -30,9 +30,8 @@
30 struct drm_hdmi_context, subdrv); 30 struct drm_hdmi_context, subdrv);
31 31
32/* these callback points shoud be set by specific drivers. */ 32/* these callback points shoud be set by specific drivers. */
33static struct exynos_hdmi_display_ops *hdmi_display_ops; 33static struct exynos_hdmi_ops *hdmi_ops;
34static struct exynos_hdmi_manager_ops *hdmi_manager_ops; 34static struct exynos_mixer_ops *mixer_ops;
35static struct exynos_hdmi_overlay_ops *hdmi_overlay_ops;
36 35
37struct drm_hdmi_context { 36struct drm_hdmi_context {
38 struct exynos_drm_subdrv subdrv; 37 struct exynos_drm_subdrv subdrv;
@@ -40,31 +39,20 @@ struct drm_hdmi_context {
40 struct exynos_drm_hdmi_context *mixer_ctx; 39 struct exynos_drm_hdmi_context *mixer_ctx;
41}; 40};
42 41
43void exynos_drm_display_ops_register(struct exynos_hdmi_display_ops 42void exynos_hdmi_ops_register(struct exynos_hdmi_ops *ops)
44 *display_ops)
45{ 43{
46 DRM_DEBUG_KMS("%s\n", __FILE__); 44 DRM_DEBUG_KMS("%s\n", __FILE__);
47 45
48 if (display_ops) 46 if (ops)
49 hdmi_display_ops = display_ops; 47 hdmi_ops = ops;
50} 48}
51 49
52void exynos_drm_manager_ops_register(struct exynos_hdmi_manager_ops 50void exynos_mixer_ops_register(struct exynos_mixer_ops *ops)
53 *manager_ops)
54{ 51{
55 DRM_DEBUG_KMS("%s\n", __FILE__); 52 DRM_DEBUG_KMS("%s\n", __FILE__);
56 53
57 if (manager_ops) 54 if (ops)
58 hdmi_manager_ops = manager_ops; 55 mixer_ops = ops;
59}
60
61void exynos_drm_overlay_ops_register(struct exynos_hdmi_overlay_ops
62 *overlay_ops)
63{
64 DRM_DEBUG_KMS("%s\n", __FILE__);
65
66 if (overlay_ops)
67 hdmi_overlay_ops = overlay_ops;
68} 56}
69 57
70static bool drm_hdmi_is_connected(struct device *dev) 58static bool drm_hdmi_is_connected(struct device *dev)
@@ -73,8 +61,8 @@ static bool drm_hdmi_is_connected(struct device *dev)
73 61
74 DRM_DEBUG_KMS("%s\n", __FILE__); 62 DRM_DEBUG_KMS("%s\n", __FILE__);
75 63
76 if (hdmi_display_ops && hdmi_display_ops->is_connected) 64 if (hdmi_ops && hdmi_ops->is_connected)
77 return hdmi_display_ops->is_connected(ctx->hdmi_ctx->ctx); 65 return hdmi_ops->is_connected(ctx->hdmi_ctx->ctx);
78 66
79 return false; 67 return false;
80} 68}
@@ -86,9 +74,9 @@ static int drm_hdmi_get_edid(struct device *dev,
86 74
87 DRM_DEBUG_KMS("%s\n", __FILE__); 75 DRM_DEBUG_KMS("%s\n", __FILE__);
88 76
89 if (hdmi_display_ops && hdmi_display_ops->get_edid) 77 if (hdmi_ops && hdmi_ops->get_edid)
90 return hdmi_display_ops->get_edid(ctx->hdmi_ctx->ctx, 78 return hdmi_ops->get_edid(ctx->hdmi_ctx->ctx, connector, edid,
91 connector, edid, len); 79 len);
92 80
93 return 0; 81 return 0;
94} 82}
@@ -99,9 +87,8 @@ static int drm_hdmi_check_timing(struct device *dev, void *timing)
99 87
100 DRM_DEBUG_KMS("%s\n", __FILE__); 88 DRM_DEBUG_KMS("%s\n", __FILE__);
101 89
102 if (hdmi_display_ops && hdmi_display_ops->check_timing) 90 if (hdmi_ops && hdmi_ops->check_timing)
103 return hdmi_display_ops->check_timing(ctx->hdmi_ctx->ctx, 91 return hdmi_ops->check_timing(ctx->hdmi_ctx->ctx, timing);
104 timing);
105 92
106 return 0; 93 return 0;
107} 94}
@@ -112,8 +99,8 @@ static int drm_hdmi_power_on(struct device *dev, int mode)
112 99
113 DRM_DEBUG_KMS("%s\n", __FILE__); 100 DRM_DEBUG_KMS("%s\n", __FILE__);
114 101
115 if (hdmi_display_ops && hdmi_display_ops->power_on) 102 if (hdmi_ops && hdmi_ops->power_on)
116 return hdmi_display_ops->power_on(ctx->hdmi_ctx->ctx, mode); 103 return hdmi_ops->power_on(ctx->hdmi_ctx->ctx, mode);
117 104
118 return 0; 105 return 0;
119} 106}
@@ -130,13 +117,13 @@ static int drm_hdmi_enable_vblank(struct device *subdrv_dev)
130{ 117{
131 struct drm_hdmi_context *ctx = to_context(subdrv_dev); 118 struct drm_hdmi_context *ctx = to_context(subdrv_dev);
132 struct exynos_drm_subdrv *subdrv = &ctx->subdrv; 119 struct exynos_drm_subdrv *subdrv = &ctx->subdrv;
133 struct exynos_drm_manager *manager = &subdrv->manager; 120 struct exynos_drm_manager *manager = subdrv->manager;
134 121
135 DRM_DEBUG_KMS("%s\n", __FILE__); 122 DRM_DEBUG_KMS("%s\n", __FILE__);
136 123
137 if (hdmi_overlay_ops && hdmi_overlay_ops->enable_vblank) 124 if (mixer_ops && mixer_ops->enable_vblank)
138 return hdmi_overlay_ops->enable_vblank(ctx->mixer_ctx->ctx, 125 return mixer_ops->enable_vblank(ctx->mixer_ctx->ctx,
139 manager->pipe); 126 manager->pipe);
140 127
141 return 0; 128 return 0;
142} 129}
@@ -147,8 +134,8 @@ static void drm_hdmi_disable_vblank(struct device *subdrv_dev)
147 134
148 DRM_DEBUG_KMS("%s\n", __FILE__); 135 DRM_DEBUG_KMS("%s\n", __FILE__);
149 136
150 if (hdmi_overlay_ops && hdmi_overlay_ops->disable_vblank) 137 if (mixer_ops && mixer_ops->disable_vblank)
151 return hdmi_overlay_ops->disable_vblank(ctx->mixer_ctx->ctx); 138 return mixer_ops->disable_vblank(ctx->mixer_ctx->ctx);
152} 139}
153 140
154static void drm_hdmi_mode_fixup(struct device *subdrv_dev, 141static void drm_hdmi_mode_fixup(struct device *subdrv_dev,
@@ -160,9 +147,9 @@ static void drm_hdmi_mode_fixup(struct device *subdrv_dev,
160 147
161 DRM_DEBUG_KMS("%s\n", __FILE__); 148 DRM_DEBUG_KMS("%s\n", __FILE__);
162 149
163 if (hdmi_manager_ops && hdmi_manager_ops->mode_fixup) 150 if (hdmi_ops && hdmi_ops->mode_fixup)
164 hdmi_manager_ops->mode_fixup(ctx->hdmi_ctx->ctx, connector, 151 hdmi_ops->mode_fixup(ctx->hdmi_ctx->ctx, connector, mode,
165 mode, adjusted_mode); 152 adjusted_mode);
166} 153}
167 154
168static void drm_hdmi_mode_set(struct device *subdrv_dev, void *mode) 155static void drm_hdmi_mode_set(struct device *subdrv_dev, void *mode)
@@ -171,8 +158,8 @@ static void drm_hdmi_mode_set(struct device *subdrv_dev, void *mode)
171 158
172 DRM_DEBUG_KMS("%s\n", __FILE__); 159 DRM_DEBUG_KMS("%s\n", __FILE__);
173 160
174 if (hdmi_manager_ops && hdmi_manager_ops->mode_set) 161 if (hdmi_ops && hdmi_ops->mode_set)
175 hdmi_manager_ops->mode_set(ctx->hdmi_ctx->ctx, mode); 162 hdmi_ops->mode_set(ctx->hdmi_ctx->ctx, mode);
176} 163}
177 164
178static void drm_hdmi_get_max_resol(struct device *subdrv_dev, 165static void drm_hdmi_get_max_resol(struct device *subdrv_dev,
@@ -182,9 +169,8 @@ static void drm_hdmi_get_max_resol(struct device *subdrv_dev,
182 169
183 DRM_DEBUG_KMS("%s\n", __FILE__); 170 DRM_DEBUG_KMS("%s\n", __FILE__);
184 171
185 if (hdmi_manager_ops && hdmi_manager_ops->get_max_resol) 172 if (hdmi_ops && hdmi_ops->get_max_resol)
186 hdmi_manager_ops->get_max_resol(ctx->hdmi_ctx->ctx, width, 173 hdmi_ops->get_max_resol(ctx->hdmi_ctx->ctx, width, height);
187 height);
188} 174}
189 175
190static void drm_hdmi_commit(struct device *subdrv_dev) 176static void drm_hdmi_commit(struct device *subdrv_dev)
@@ -193,8 +179,8 @@ static void drm_hdmi_commit(struct device *subdrv_dev)
193 179
194 DRM_DEBUG_KMS("%s\n", __FILE__); 180 DRM_DEBUG_KMS("%s\n", __FILE__);
195 181
196 if (hdmi_manager_ops && hdmi_manager_ops->commit) 182 if (hdmi_ops && hdmi_ops->commit)
197 hdmi_manager_ops->commit(ctx->hdmi_ctx->ctx); 183 hdmi_ops->commit(ctx->hdmi_ctx->ctx);
198} 184}
199 185
200static void drm_hdmi_dpms(struct device *subdrv_dev, int mode) 186static void drm_hdmi_dpms(struct device *subdrv_dev, int mode)
@@ -209,8 +195,8 @@ static void drm_hdmi_dpms(struct device *subdrv_dev, int mode)
209 case DRM_MODE_DPMS_STANDBY: 195 case DRM_MODE_DPMS_STANDBY:
210 case DRM_MODE_DPMS_SUSPEND: 196 case DRM_MODE_DPMS_SUSPEND:
211 case DRM_MODE_DPMS_OFF: 197 case DRM_MODE_DPMS_OFF:
212 if (hdmi_manager_ops && hdmi_manager_ops->disable) 198 if (hdmi_ops && hdmi_ops->disable)
213 hdmi_manager_ops->disable(ctx->hdmi_ctx->ctx); 199 hdmi_ops->disable(ctx->hdmi_ctx->ctx);
214 break; 200 break;
215 default: 201 default:
216 DRM_DEBUG_KMS("unkown dps mode: %d\n", mode); 202 DRM_DEBUG_KMS("unkown dps mode: %d\n", mode);
@@ -235,8 +221,8 @@ static void drm_mixer_mode_set(struct device *subdrv_dev,
235 221
236 DRM_DEBUG_KMS("%s\n", __FILE__); 222 DRM_DEBUG_KMS("%s\n", __FILE__);
237 223
238 if (hdmi_overlay_ops && hdmi_overlay_ops->win_mode_set) 224 if (mixer_ops && mixer_ops->win_mode_set)
239 hdmi_overlay_ops->win_mode_set(ctx->mixer_ctx->ctx, overlay); 225 mixer_ops->win_mode_set(ctx->mixer_ctx->ctx, overlay);
240} 226}
241 227
242static void drm_mixer_commit(struct device *subdrv_dev, int zpos) 228static void drm_mixer_commit(struct device *subdrv_dev, int zpos)
@@ -245,8 +231,8 @@ static void drm_mixer_commit(struct device *subdrv_dev, int zpos)
245 231
246 DRM_DEBUG_KMS("%s\n", __FILE__); 232 DRM_DEBUG_KMS("%s\n", __FILE__);
247 233
248 if (hdmi_overlay_ops && hdmi_overlay_ops->win_commit) 234 if (mixer_ops && mixer_ops->win_commit)
249 hdmi_overlay_ops->win_commit(ctx->mixer_ctx->ctx, zpos); 235 mixer_ops->win_commit(ctx->mixer_ctx->ctx, zpos);
250} 236}
251 237
252static void drm_mixer_disable(struct device *subdrv_dev, int zpos) 238static void drm_mixer_disable(struct device *subdrv_dev, int zpos)
@@ -255,8 +241,8 @@ static void drm_mixer_disable(struct device *subdrv_dev, int zpos)
255 241
256 DRM_DEBUG_KMS("%s\n", __FILE__); 242 DRM_DEBUG_KMS("%s\n", __FILE__);
257 243
258 if (hdmi_overlay_ops && hdmi_overlay_ops->win_disable) 244 if (mixer_ops && mixer_ops->win_disable)
259 hdmi_overlay_ops->win_disable(ctx->mixer_ctx->ctx, zpos); 245 mixer_ops->win_disable(ctx->mixer_ctx->ctx, zpos);
260} 246}
261 247
262static struct exynos_drm_overlay_ops drm_hdmi_overlay_ops = { 248static struct exynos_drm_overlay_ops drm_hdmi_overlay_ops = {
@@ -265,6 +251,12 @@ static struct exynos_drm_overlay_ops drm_hdmi_overlay_ops = {
265 .disable = drm_mixer_disable, 251 .disable = drm_mixer_disable,
266}; 252};
267 253
254static struct exynos_drm_manager hdmi_manager = {
255 .pipe = -1,
256 .ops = &drm_hdmi_manager_ops,
257 .overlay_ops = &drm_hdmi_overlay_ops,
258 .display_ops = &drm_hdmi_display_ops,
259};
268 260
269static int hdmi_subdrv_probe(struct drm_device *drm_dev, 261static int hdmi_subdrv_probe(struct drm_device *drm_dev,
270 struct device *dev) 262 struct device *dev)
@@ -332,12 +324,9 @@ static int __devinit exynos_drm_hdmi_probe(struct platform_device *pdev)
332 324
333 subdrv = &ctx->subdrv; 325 subdrv = &ctx->subdrv;
334 326
327 subdrv->dev = dev;
328 subdrv->manager = &hdmi_manager;
335 subdrv->probe = hdmi_subdrv_probe; 329 subdrv->probe = hdmi_subdrv_probe;
336 subdrv->manager.pipe = -1;
337 subdrv->manager.ops = &drm_hdmi_manager_ops;
338 subdrv->manager.overlay_ops = &drm_hdmi_overlay_ops;
339 subdrv->manager.display_ops = &drm_hdmi_display_ops;
340 subdrv->manager.dev = dev;
341 330
342 platform_set_drvdata(pdev, subdrv); 331 platform_set_drvdata(pdev, subdrv);
343 332
diff --git a/drivers/gpu/drm/exynos/exynos_drm_hdmi.h b/drivers/gpu/drm/exynos/exynos_drm_hdmi.h
index 44497cfb6c74..f3ae192c8dcf 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_hdmi.h
+++ b/drivers/gpu/drm/exynos/exynos_drm_hdmi.h
@@ -38,15 +38,15 @@ struct exynos_drm_hdmi_context {
38 void *ctx; 38 void *ctx;
39}; 39};
40 40
41struct exynos_hdmi_display_ops { 41struct exynos_hdmi_ops {
42 /* display */
42 bool (*is_connected)(void *ctx); 43 bool (*is_connected)(void *ctx);
43 int (*get_edid)(void *ctx, struct drm_connector *connector, 44 int (*get_edid)(void *ctx, struct drm_connector *connector,
44 u8 *edid, int len); 45 u8 *edid, int len);
45 int (*check_timing)(void *ctx, void *timing); 46 int (*check_timing)(void *ctx, void *timing);
46 int (*power_on)(void *ctx, int mode); 47 int (*power_on)(void *ctx, int mode);
47};
48 48
49struct exynos_hdmi_manager_ops { 49 /* manager */
50 void (*mode_fixup)(void *ctx, struct drm_connector *connector, 50 void (*mode_fixup)(void *ctx, struct drm_connector *connector,
51 struct drm_display_mode *mode, 51 struct drm_display_mode *mode,
52 struct drm_display_mode *adjusted_mode); 52 struct drm_display_mode *adjusted_mode);
@@ -57,22 +57,17 @@ struct exynos_hdmi_manager_ops {
57 void (*disable)(void *ctx); 57 void (*disable)(void *ctx);
58}; 58};
59 59
60struct exynos_hdmi_overlay_ops { 60struct exynos_mixer_ops {
61 /* manager */
61 int (*enable_vblank)(void *ctx, int pipe); 62 int (*enable_vblank)(void *ctx, int pipe);
62 void (*disable_vblank)(void *ctx); 63 void (*disable_vblank)(void *ctx);
64
65 /* overlay */
63 void (*win_mode_set)(void *ctx, struct exynos_drm_overlay *overlay); 66 void (*win_mode_set)(void *ctx, struct exynos_drm_overlay *overlay);
64 void (*win_commit)(void *ctx, int zpos); 67 void (*win_commit)(void *ctx, int zpos);
65 void (*win_disable)(void *ctx, int zpos); 68 void (*win_disable)(void *ctx, int zpos);
66}; 69};
67 70
68extern struct platform_driver hdmi_driver; 71void exynos_hdmi_ops_register(struct exynos_hdmi_ops *ops);
69extern struct platform_driver mixer_driver; 72void exynos_mixer_ops_register(struct exynos_mixer_ops *ops);
70
71void exynos_drm_display_ops_register(struct exynos_hdmi_display_ops
72 *display_ops);
73void exynos_drm_manager_ops_register(struct exynos_hdmi_manager_ops
74 *manager_ops);
75void exynos_drm_overlay_ops_register(struct exynos_hdmi_overlay_ops
76 *overlay_ops);
77
78#endif 73#endif
diff --git a/drivers/gpu/drm/exynos/exynos_drm_plane.c b/drivers/gpu/drm/exynos/exynos_drm_plane.c
index c277a3a445f5..f92fe4c6174a 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_plane.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_plane.c
@@ -24,6 +24,10 @@ struct exynos_plane {
24 24
25static const uint32_t formats[] = { 25static const uint32_t formats[] = {
26 DRM_FORMAT_XRGB8888, 26 DRM_FORMAT_XRGB8888,
27 DRM_FORMAT_ARGB8888,
28 DRM_FORMAT_NV12,
29 DRM_FORMAT_NV12M,
30 DRM_FORMAT_NV12MT,
27}; 31};
28 32
29static int 33static int
diff --git a/drivers/gpu/drm/exynos/exynos_drm_vidi.c b/drivers/gpu/drm/exynos/exynos_drm_vidi.c
index 8e1339f9fe1f..7b9c153dceb6 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_vidi.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_vidi.c
@@ -199,7 +199,7 @@ static void vidi_dpms(struct device *subdrv_dev, int mode)
199static void vidi_apply(struct device *subdrv_dev) 199static void vidi_apply(struct device *subdrv_dev)
200{ 200{
201 struct vidi_context *ctx = get_vidi_context(subdrv_dev); 201 struct vidi_context *ctx = get_vidi_context(subdrv_dev);
202 struct exynos_drm_manager *mgr = &ctx->subdrv.manager; 202 struct exynos_drm_manager *mgr = ctx->subdrv.manager;
203 struct exynos_drm_manager_ops *mgr_ops = mgr->ops; 203 struct exynos_drm_manager_ops *mgr_ops = mgr->ops;
204 struct exynos_drm_overlay_ops *ovl_ops = mgr->overlay_ops; 204 struct exynos_drm_overlay_ops *ovl_ops = mgr->overlay_ops;
205 struct vidi_win_data *win_data; 205 struct vidi_win_data *win_data;
@@ -374,6 +374,13 @@ static struct exynos_drm_overlay_ops vidi_overlay_ops = {
374 .disable = vidi_win_disable, 374 .disable = vidi_win_disable,
375}; 375};
376 376
377static struct exynos_drm_manager vidi_manager = {
378 .pipe = -1,
379 .ops = &vidi_manager_ops,
380 .overlay_ops = &vidi_overlay_ops,
381 .display_ops = &vidi_display_ops,
382};
383
377static void vidi_finish_pageflip(struct drm_device *drm_dev, int crtc) 384static void vidi_finish_pageflip(struct drm_device *drm_dev, int crtc)
378{ 385{
379 struct exynos_drm_private *dev_priv = drm_dev->dev_private; 386 struct exynos_drm_private *dev_priv = drm_dev->dev_private;
@@ -425,7 +432,7 @@ static void vidi_fake_vblank_handler(struct work_struct *work)
425 struct vidi_context *ctx = container_of(work, struct vidi_context, 432 struct vidi_context *ctx = container_of(work, struct vidi_context,
426 work); 433 work);
427 struct exynos_drm_subdrv *subdrv = &ctx->subdrv; 434 struct exynos_drm_subdrv *subdrv = &ctx->subdrv;
428 struct exynos_drm_manager *manager = &subdrv->manager; 435 struct exynos_drm_manager *manager = subdrv->manager;
429 436
430 if (manager->pipe < 0) 437 if (manager->pipe < 0)
431 return; 438 return;
@@ -471,7 +478,7 @@ static void vidi_subdrv_remove(struct drm_device *drm_dev)
471static int vidi_power_on(struct vidi_context *ctx, bool enable) 478static int vidi_power_on(struct vidi_context *ctx, bool enable)
472{ 479{
473 struct exynos_drm_subdrv *subdrv = &ctx->subdrv; 480 struct exynos_drm_subdrv *subdrv = &ctx->subdrv;
474 struct device *dev = subdrv->manager.dev; 481 struct device *dev = subdrv->dev;
475 482
476 DRM_DEBUG_KMS("%s\n", __FILE__); 483 DRM_DEBUG_KMS("%s\n", __FILE__);
477 484
@@ -611,13 +618,10 @@ static int __devinit vidi_probe(struct platform_device *pdev)
611 ctx->raw_edid = (struct edid *)fake_edid_info; 618 ctx->raw_edid = (struct edid *)fake_edid_info;
612 619
613 subdrv = &ctx->subdrv; 620 subdrv = &ctx->subdrv;
621 subdrv->dev = dev;
622 subdrv->manager = &vidi_manager;
614 subdrv->probe = vidi_subdrv_probe; 623 subdrv->probe = vidi_subdrv_probe;
615 subdrv->remove = vidi_subdrv_remove; 624 subdrv->remove = vidi_subdrv_remove;
616 subdrv->manager.pipe = -1;
617 subdrv->manager.ops = &vidi_manager_ops;
618 subdrv->manager.overlay_ops = &vidi_overlay_ops;
619 subdrv->manager.display_ops = &vidi_display_ops;
620 subdrv->manager.dev = dev;
621 625
622 mutex_init(&ctx->lock); 626 mutex_init(&ctx->lock);
623 627
diff --git a/drivers/gpu/drm/exynos/exynos_hdmi.c b/drivers/gpu/drm/exynos/exynos_hdmi.c
index 575a8cbd3533..b00353876458 100644
--- a/drivers/gpu/drm/exynos/exynos_hdmi.c
+++ b/drivers/gpu/drm/exynos/exynos_hdmi.c
@@ -40,7 +40,6 @@
40 40
41#include "exynos_hdmi.h" 41#include "exynos_hdmi.h"
42 42
43#define HDMI_OVERLAY_NUMBER 3
44#define MAX_WIDTH 1920 43#define MAX_WIDTH 1920
45#define MAX_HEIGHT 1080 44#define MAX_HEIGHT 1080
46#define get_hdmi_context(dev) platform_get_drvdata(to_platform_device(dev)) 45#define get_hdmi_context(dev) platform_get_drvdata(to_platform_device(dev))
@@ -1194,7 +1193,7 @@ static int hdmi_conf_index(struct hdmi_context *hdata,
1194 1193
1195static bool hdmi_is_connected(void *ctx) 1194static bool hdmi_is_connected(void *ctx)
1196{ 1195{
1197 struct hdmi_context *hdata = (struct hdmi_context *)ctx; 1196 struct hdmi_context *hdata = ctx;
1198 u32 val = hdmi_reg_read(hdata, HDMI_HPD_STATUS); 1197 u32 val = hdmi_reg_read(hdata, HDMI_HPD_STATUS);
1199 1198
1200 if (val) 1199 if (val)
@@ -1207,7 +1206,7 @@ static int hdmi_get_edid(void *ctx, struct drm_connector *connector,
1207 u8 *edid, int len) 1206 u8 *edid, int len)
1208{ 1207{
1209 struct edid *raw_edid; 1208 struct edid *raw_edid;
1210 struct hdmi_context *hdata = (struct hdmi_context *)ctx; 1209 struct hdmi_context *hdata = ctx;
1211 1210
1212 DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__); 1211 DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
1213 1212
@@ -1275,7 +1274,7 @@ static int hdmi_v14_check_timing(struct fb_videomode *check_timing)
1275 1274
1276static int hdmi_check_timing(void *ctx, void *timing) 1275static int hdmi_check_timing(void *ctx, void *timing)
1277{ 1276{
1278 struct hdmi_context *hdata = (struct hdmi_context *)ctx; 1277 struct hdmi_context *hdata = ctx;
1279 struct fb_videomode *check_timing = timing; 1278 struct fb_videomode *check_timing = timing;
1280 1279
1281 DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__); 1280 DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
@@ -1312,13 +1311,6 @@ static int hdmi_display_power_on(void *ctx, int mode)
1312 return 0; 1311 return 0;
1313} 1312}
1314 1313
1315static struct exynos_hdmi_display_ops display_ops = {
1316 .is_connected = hdmi_is_connected,
1317 .get_edid = hdmi_get_edid,
1318 .check_timing = hdmi_check_timing,
1319 .power_on = hdmi_display_power_on,
1320};
1321
1322static void hdmi_set_acr(u32 freq, u8 *acr) 1314static void hdmi_set_acr(u32 freq, u8 *acr)
1323{ 1315{
1324 u32 n, cts; 1316 u32 n, cts;
@@ -1914,7 +1906,7 @@ static void hdmi_mode_fixup(void *ctx, struct drm_connector *connector,
1914 struct drm_display_mode *adjusted_mode) 1906 struct drm_display_mode *adjusted_mode)
1915{ 1907{
1916 struct drm_display_mode *m; 1908 struct drm_display_mode *m;
1917 struct hdmi_context *hdata = (struct hdmi_context *)ctx; 1909 struct hdmi_context *hdata = ctx;
1918 int index; 1910 int index;
1919 1911
1920 DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__); 1912 DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
@@ -1951,7 +1943,7 @@ static void hdmi_mode_fixup(void *ctx, struct drm_connector *connector,
1951 1943
1952static void hdmi_mode_set(void *ctx, void *mode) 1944static void hdmi_mode_set(void *ctx, void *mode)
1953{ 1945{
1954 struct hdmi_context *hdata = (struct hdmi_context *)ctx; 1946 struct hdmi_context *hdata = ctx;
1955 int conf_idx; 1947 int conf_idx;
1956 1948
1957 DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__); 1949 DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
@@ -1974,7 +1966,7 @@ static void hdmi_get_max_resol(void *ctx, unsigned int *width,
1974 1966
1975static void hdmi_commit(void *ctx) 1967static void hdmi_commit(void *ctx)
1976{ 1968{
1977 struct hdmi_context *hdata = (struct hdmi_context *)ctx; 1969 struct hdmi_context *hdata = ctx;
1978 1970
1979 DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__); 1971 DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
1980 1972
@@ -1985,7 +1977,7 @@ static void hdmi_commit(void *ctx)
1985 1977
1986static void hdmi_disable(void *ctx) 1978static void hdmi_disable(void *ctx)
1987{ 1979{
1988 struct hdmi_context *hdata = (struct hdmi_context *)ctx; 1980 struct hdmi_context *hdata = ctx;
1989 1981
1990 DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__); 1982 DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
1991 1983
@@ -1996,7 +1988,14 @@ static void hdmi_disable(void *ctx)
1996 } 1988 }
1997} 1989}
1998 1990
1999static struct exynos_hdmi_manager_ops manager_ops = { 1991static struct exynos_hdmi_ops hdmi_ops = {
1992 /* display */
1993 .is_connected = hdmi_is_connected,
1994 .get_edid = hdmi_get_edid,
1995 .check_timing = hdmi_check_timing,
1996 .power_on = hdmi_display_power_on,
1997
1998 /* manager */
2000 .mode_fixup = hdmi_mode_fixup, 1999 .mode_fixup = hdmi_mode_fixup,
2001 .mode_set = hdmi_mode_set, 2000 .mode_set = hdmi_mode_set,
2002 .get_max_resol = hdmi_get_max_resol, 2001 .get_max_resol = hdmi_get_max_resol,
@@ -2020,7 +2019,7 @@ static void hdmi_hotplug_func(struct work_struct *work)
2020static irqreturn_t hdmi_irq_handler(int irq, void *arg) 2019static irqreturn_t hdmi_irq_handler(int irq, void *arg)
2021{ 2020{
2022 struct exynos_drm_hdmi_context *ctx = arg; 2021 struct exynos_drm_hdmi_context *ctx = arg;
2023 struct hdmi_context *hdata = (struct hdmi_context *)ctx->ctx; 2022 struct hdmi_context *hdata = ctx->ctx;
2024 u32 intc_flag; 2023 u32 intc_flag;
2025 2024
2026 intc_flag = hdmi_reg_read(hdata, HDMI_INTC_FLAG); 2025 intc_flag = hdmi_reg_read(hdata, HDMI_INTC_FLAG);
@@ -2173,7 +2172,7 @@ static int hdmi_runtime_suspend(struct device *dev)
2173 2172
2174 DRM_DEBUG_KMS("%s\n", __func__); 2173 DRM_DEBUG_KMS("%s\n", __func__);
2175 2174
2176 hdmi_resource_poweroff((struct hdmi_context *)ctx->ctx); 2175 hdmi_resource_poweroff(ctx->ctx);
2177 2176
2178 return 0; 2177 return 0;
2179} 2178}
@@ -2184,7 +2183,7 @@ static int hdmi_runtime_resume(struct device *dev)
2184 2183
2185 DRM_DEBUG_KMS("%s\n", __func__); 2184 DRM_DEBUG_KMS("%s\n", __func__);
2186 2185
2187 hdmi_resource_poweron((struct hdmi_context *)ctx->ctx); 2186 hdmi_resource_poweron(ctx->ctx);
2188 2187
2189 return 0; 2188 return 0;
2190} 2189}
@@ -2322,8 +2321,7 @@ static int __devinit hdmi_probe(struct platform_device *pdev)
2322 hdata->irq = res->start; 2321 hdata->irq = res->start;
2323 2322
2324 /* register specific callbacks to common hdmi. */ 2323 /* register specific callbacks to common hdmi. */
2325 exynos_drm_display_ops_register(&display_ops); 2324 exynos_hdmi_ops_register(&hdmi_ops);
2326 exynos_drm_manager_ops_register(&manager_ops);
2327 2325
2328 hdmi_resource_poweron(hdata); 2326 hdmi_resource_poweron(hdata);
2329 2327
@@ -2351,7 +2349,7 @@ err_data:
2351static int __devexit hdmi_remove(struct platform_device *pdev) 2349static int __devexit hdmi_remove(struct platform_device *pdev)
2352{ 2350{
2353 struct exynos_drm_hdmi_context *ctx = platform_get_drvdata(pdev); 2351 struct exynos_drm_hdmi_context *ctx = platform_get_drvdata(pdev);
2354 struct hdmi_context *hdata = (struct hdmi_context *)ctx->ctx; 2352 struct hdmi_context *hdata = ctx->ctx;
2355 2353
2356 DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__); 2354 DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
2357 2355
diff --git a/drivers/gpu/drm/exynos/exynos_mixer.c b/drivers/gpu/drm/exynos/exynos_mixer.c
index 4d5f41e19527..e15438c01129 100644
--- a/drivers/gpu/drm/exynos/exynos_mixer.c
+++ b/drivers/gpu/drm/exynos/exynos_mixer.c
@@ -37,7 +37,8 @@
37#include "exynos_drm_drv.h" 37#include "exynos_drm_drv.h"
38#include "exynos_drm_hdmi.h" 38#include "exynos_drm_hdmi.h"
39 39
40#define HDMI_OVERLAY_NUMBER 3 40#define MIXER_WIN_NR 3
41#define MIXER_DEFAULT_WIN 0
41 42
42#define get_mixer_context(dev) platform_get_drvdata(to_platform_device(dev)) 43#define get_mixer_context(dev) platform_get_drvdata(to_platform_device(dev))
43 44
@@ -75,16 +76,12 @@ struct mixer_resources {
75}; 76};
76 77
77struct mixer_context { 78struct mixer_context {
78 struct fb_videomode *default_timing;
79 unsigned int default_win;
80 unsigned int default_bpp;
81 unsigned int irq; 79 unsigned int irq;
82 int pipe; 80 int pipe;
83 bool interlace; 81 bool interlace;
84 bool vp_enabled;
85 82
86 struct mixer_resources mixer_res; 83 struct mixer_resources mixer_res;
87 struct hdmi_win_data win_data[HDMI_OVERLAY_NUMBER]; 84 struct hdmi_win_data win_data[MIXER_WIN_NR];
88}; 85};
89 86
90static const u8 filter_y_horiz_tap8[] = { 87static const u8 filter_y_horiz_tap8[] = {
@@ -643,9 +640,9 @@ static void mixer_win_mode_set(void *ctx,
643 640
644 win = overlay->zpos; 641 win = overlay->zpos;
645 if (win == DEFAULT_ZPOS) 642 if (win == DEFAULT_ZPOS)
646 win = mixer_ctx->default_win; 643 win = MIXER_DEFAULT_WIN;
647 644
648 if (win < 0 || win > HDMI_OVERLAY_NUMBER) { 645 if (win < 0 || win > MIXER_WIN_NR) {
649 DRM_ERROR("overlay plane[%d] is wrong\n", win); 646 DRM_ERROR("overlay plane[%d] is wrong\n", win);
650 return; 647 return;
651 } 648 }
@@ -683,9 +680,9 @@ static void mixer_win_commit(void *ctx, int zpos)
683 DRM_DEBUG_KMS("[%d] %s, win: %d\n", __LINE__, __func__, win); 680 DRM_DEBUG_KMS("[%d] %s, win: %d\n", __LINE__, __func__, win);
684 681
685 if (win == DEFAULT_ZPOS) 682 if (win == DEFAULT_ZPOS)
686 win = mixer_ctx->default_win; 683 win = MIXER_DEFAULT_WIN;
687 684
688 if (win < 0 || win > HDMI_OVERLAY_NUMBER) { 685 if (win < 0 || win > MIXER_WIN_NR) {
689 DRM_ERROR("overlay plane[%d] is wrong\n", win); 686 DRM_ERROR("overlay plane[%d] is wrong\n", win);
690 return; 687 return;
691 } 688 }
@@ -706,9 +703,9 @@ static void mixer_win_disable(void *ctx, int zpos)
706 DRM_DEBUG_KMS("[%d] %s, win: %d\n", __LINE__, __func__, win); 703 DRM_DEBUG_KMS("[%d] %s, win: %d\n", __LINE__, __func__, win);
707 704
708 if (win == DEFAULT_ZPOS) 705 if (win == DEFAULT_ZPOS)
709 win = mixer_ctx->default_win; 706 win = MIXER_DEFAULT_WIN;
710 707
711 if (win < 0 || win > HDMI_OVERLAY_NUMBER) { 708 if (win < 0 || win > MIXER_WIN_NR) {
712 DRM_ERROR("overlay plane[%d] is wrong\n", win); 709 DRM_ERROR("overlay plane[%d] is wrong\n", win);
713 return; 710 return;
714 } 711 }
@@ -722,9 +719,12 @@ static void mixer_win_disable(void *ctx, int zpos)
722 spin_unlock_irqrestore(&res->reg_slock, flags); 719 spin_unlock_irqrestore(&res->reg_slock, flags);
723} 720}
724 721
725static struct exynos_hdmi_overlay_ops overlay_ops = { 722static struct exynos_mixer_ops mixer_ops = {
723 /* manager */
726 .enable_vblank = mixer_enable_vblank, 724 .enable_vblank = mixer_enable_vblank,
727 .disable_vblank = mixer_disable_vblank, 725 .disable_vblank = mixer_disable_vblank,
726
727 /* overlay */
728 .win_mode_set = mixer_win_mode_set, 728 .win_mode_set = mixer_win_mode_set,
729 .win_commit = mixer_win_commit, 729 .win_commit = mixer_win_commit,
730 .win_disable = mixer_win_disable, 730 .win_disable = mixer_win_disable,
@@ -771,8 +771,7 @@ static void mixer_finish_pageflip(struct drm_device *drm_dev, int crtc)
771static irqreturn_t mixer_irq_handler(int irq, void *arg) 771static irqreturn_t mixer_irq_handler(int irq, void *arg)
772{ 772{
773 struct exynos_drm_hdmi_context *drm_hdmi_ctx = arg; 773 struct exynos_drm_hdmi_context *drm_hdmi_ctx = arg;
774 struct mixer_context *ctx = 774 struct mixer_context *ctx = drm_hdmi_ctx->ctx;
775 (struct mixer_context *)drm_hdmi_ctx->ctx;
776 struct mixer_resources *res = &ctx->mixer_res; 775 struct mixer_resources *res = &ctx->mixer_res;
777 u32 val, val_base; 776 u32 val, val_base;
778 777
@@ -902,7 +901,7 @@ static int mixer_runtime_resume(struct device *dev)
902 901
903 DRM_DEBUG_KMS("resume - start\n"); 902 DRM_DEBUG_KMS("resume - start\n");
904 903
905 mixer_resource_poweron((struct mixer_context *)ctx->ctx); 904 mixer_resource_poweron(ctx->ctx);
906 905
907 return 0; 906 return 0;
908} 907}
@@ -913,7 +912,7 @@ static int mixer_runtime_suspend(struct device *dev)
913 912
914 DRM_DEBUG_KMS("suspend - start\n"); 913 DRM_DEBUG_KMS("suspend - start\n");
915 914
916 mixer_resource_poweroff((struct mixer_context *)ctx->ctx); 915 mixer_resource_poweroff(ctx->ctx);
917 916
918 return 0; 917 return 0;
919} 918}
@@ -926,8 +925,7 @@ static const struct dev_pm_ops mixer_pm_ops = {
926static int __devinit mixer_resources_init(struct exynos_drm_hdmi_context *ctx, 925static int __devinit mixer_resources_init(struct exynos_drm_hdmi_context *ctx,
927 struct platform_device *pdev) 926 struct platform_device *pdev)
928{ 927{
929 struct mixer_context *mixer_ctx = 928 struct mixer_context *mixer_ctx = ctx->ctx;
930 (struct mixer_context *)ctx->ctx;
931 struct device *dev = &pdev->dev; 929 struct device *dev = &pdev->dev;
932 struct mixer_resources *mixer_res = &mixer_ctx->mixer_res; 930 struct mixer_resources *mixer_res = &mixer_ctx->mixer_res;
933 struct resource *res; 931 struct resource *res;
@@ -1076,7 +1074,7 @@ static int __devinit mixer_probe(struct platform_device *pdev)
1076 goto fail; 1074 goto fail;
1077 1075
1078 /* register specific callback point to common hdmi. */ 1076 /* register specific callback point to common hdmi. */
1079 exynos_drm_overlay_ops_register(&overlay_ops); 1077 exynos_mixer_ops_register(&mixer_ops);
1080 1078
1081 mixer_resource_poweron(ctx); 1079 mixer_resource_poweron(ctx);
1082 1080
@@ -1093,7 +1091,7 @@ static int mixer_remove(struct platform_device *pdev)
1093 struct device *dev = &pdev->dev; 1091 struct device *dev = &pdev->dev;
1094 struct exynos_drm_hdmi_context *drm_hdmi_ctx = 1092 struct exynos_drm_hdmi_context *drm_hdmi_ctx =
1095 platform_get_drvdata(pdev); 1093 platform_get_drvdata(pdev);
1096 struct mixer_context *ctx = (struct mixer_context *)drm_hdmi_ctx->ctx; 1094 struct mixer_context *ctx = drm_hdmi_ctx->ctx;
1097 1095
1098 dev_info(dev, "remove successful\n"); 1096 dev_info(dev, "remove successful\n");
1099 1097
diff --git a/drivers/gpu/drm/gma500/mdfld_dsi_output.h b/drivers/gpu/drm/gma500/mdfld_dsi_output.h
index 21071cef92a4..36eb0744841c 100644
--- a/drivers/gpu/drm/gma500/mdfld_dsi_output.h
+++ b/drivers/gpu/drm/gma500/mdfld_dsi_output.h
@@ -29,7 +29,6 @@
29#define __MDFLD_DSI_OUTPUT_H__ 29#define __MDFLD_DSI_OUTPUT_H__
30 30
31#include <linux/backlight.h> 31#include <linux/backlight.h>
32#include <linux/version.h>
33#include <drm/drmP.h> 32#include <drm/drmP.h>
34#include <drm/drm.h> 33#include <drm/drm.h>
35#include <drm/drm_crtc.h> 34#include <drm/drm_crtc.h>
diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
index 2c8a60c3b98e..f920fb5e42b6 100644
--- a/drivers/gpu/drm/i810/i810_dma.c
+++ b/drivers/gpu/drm/i810/i810_dma.c
@@ -129,6 +129,7 @@ static int i810_map_buffer(struct drm_buf *buf, struct drm_file *file_priv)
129 if (buf_priv->currently_mapped == I810_BUF_MAPPED) 129 if (buf_priv->currently_mapped == I810_BUF_MAPPED)
130 return -EINVAL; 130 return -EINVAL;
131 131
132 /* This is all entirely broken */
132 down_write(&current->mm->mmap_sem); 133 down_write(&current->mm->mmap_sem);
133 old_fops = file_priv->filp->f_op; 134 old_fops = file_priv->filp->f_op;
134 file_priv->filp->f_op = &i810_buffer_fops; 135 file_priv->filp->f_op = &i810_buffer_fops;
@@ -157,11 +158,8 @@ static int i810_unmap_buffer(struct drm_buf *buf)
157 if (buf_priv->currently_mapped != I810_BUF_MAPPED) 158 if (buf_priv->currently_mapped != I810_BUF_MAPPED)
158 return -EINVAL; 159 return -EINVAL;
159 160
160 down_write(&current->mm->mmap_sem); 161 retcode = vm_munmap((unsigned long)buf_priv->virtual,
161 retcode = do_munmap(current->mm,
162 (unsigned long)buf_priv->virtual,
163 (size_t) buf->total); 162 (size_t) buf->total);
164 up_write(&current->mm->mmap_sem);
165 163
166 buf_priv->currently_mapped = I810_BUF_UNMAPPED; 164 buf_priv->currently_mapped = I810_BUF_UNMAPPED;
167 buf_priv->virtual = NULL; 165 buf_priv->virtual = NULL;
diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
index fdb7ccefffbd..e6162a1681f0 100644
--- a/drivers/gpu/drm/i915/i915_debugfs.c
+++ b/drivers/gpu/drm/i915/i915_debugfs.c
@@ -1224,6 +1224,9 @@ static int i915_emon_status(struct seq_file *m, void *unused)
1224 unsigned long temp, chipset, gfx; 1224 unsigned long temp, chipset, gfx;
1225 int ret; 1225 int ret;
1226 1226
1227 if (!IS_GEN5(dev))
1228 return -ENODEV;
1229
1227 ret = mutex_lock_interruptible(&dev->struct_mutex); 1230 ret = mutex_lock_interruptible(&dev->struct_mutex);
1228 if (ret) 1231 if (ret)
1229 return ret; 1232 return ret;
@@ -1502,14 +1505,6 @@ static int i915_ppgtt_info(struct seq_file *m, void *data)
1502 return 0; 1505 return 0;
1503} 1506}
1504 1507
1505static int
1506i915_debugfs_common_open(struct inode *inode,
1507 struct file *filp)
1508{
1509 filp->private_data = inode->i_private;
1510 return 0;
1511}
1512
1513static ssize_t 1508static ssize_t
1514i915_wedged_read(struct file *filp, 1509i915_wedged_read(struct file *filp,
1515 char __user *ubuf, 1510 char __user *ubuf,
@@ -1560,7 +1555,7 @@ i915_wedged_write(struct file *filp,
1560 1555
1561static const struct file_operations i915_wedged_fops = { 1556static const struct file_operations i915_wedged_fops = {
1562 .owner = THIS_MODULE, 1557 .owner = THIS_MODULE,
1563 .open = i915_debugfs_common_open, 1558 .open = simple_open,
1564 .read = i915_wedged_read, 1559 .read = i915_wedged_read,
1565 .write = i915_wedged_write, 1560 .write = i915_wedged_write,
1566 .llseek = default_llseek, 1561 .llseek = default_llseek,
@@ -1622,7 +1617,7 @@ i915_max_freq_write(struct file *filp,
1622 1617
1623static const struct file_operations i915_max_freq_fops = { 1618static const struct file_operations i915_max_freq_fops = {
1624 .owner = THIS_MODULE, 1619 .owner = THIS_MODULE,
1625 .open = i915_debugfs_common_open, 1620 .open = simple_open,
1626 .read = i915_max_freq_read, 1621 .read = i915_max_freq_read,
1627 .write = i915_max_freq_write, 1622 .write = i915_max_freq_write,
1628 .llseek = default_llseek, 1623 .llseek = default_llseek,
@@ -1693,7 +1688,7 @@ i915_cache_sharing_write(struct file *filp,
1693 1688
1694static const struct file_operations i915_cache_sharing_fops = { 1689static const struct file_operations i915_cache_sharing_fops = {
1695 .owner = THIS_MODULE, 1690 .owner = THIS_MODULE,
1696 .open = i915_debugfs_common_open, 1691 .open = simple_open,
1697 .read = i915_cache_sharing_read, 1692 .read = i915_cache_sharing_read,
1698 .write = i915_cache_sharing_write, 1693 .write = i915_cache_sharing_write,
1699 .llseek = default_llseek, 1694 .llseek = default_llseek,
diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
index 9341eb8ce93b..ba60f3c8f911 100644
--- a/drivers/gpu/drm/i915/i915_dma.c
+++ b/drivers/gpu/drm/i915/i915_dma.c
@@ -1183,6 +1183,21 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
1183 return can_switch; 1183 return can_switch;
1184} 1184}
1185 1185
1186static bool
1187intel_enable_ppgtt(struct drm_device *dev)
1188{
1189 if (i915_enable_ppgtt >= 0)
1190 return i915_enable_ppgtt;
1191
1192#ifdef CONFIG_INTEL_IOMMU
1193 /* Disable ppgtt on SNB if VT-d is on. */
1194 if (INTEL_INFO(dev)->gen == 6 && intel_iommu_gfx_mapped)
1195 return false;
1196#endif
1197
1198 return true;
1199}
1200
1186static int i915_load_gem_init(struct drm_device *dev) 1201static int i915_load_gem_init(struct drm_device *dev)
1187{ 1202{
1188 struct drm_i915_private *dev_priv = dev->dev_private; 1203 struct drm_i915_private *dev_priv = dev->dev_private;
@@ -1197,7 +1212,7 @@ static int i915_load_gem_init(struct drm_device *dev)
1197 drm_mm_init(&dev_priv->mm.stolen, 0, prealloc_size); 1212 drm_mm_init(&dev_priv->mm.stolen, 0, prealloc_size);
1198 1213
1199 mutex_lock(&dev->struct_mutex); 1214 mutex_lock(&dev->struct_mutex);
1200 if (i915_enable_ppgtt && HAS_ALIASING_PPGTT(dev)) { 1215 if (intel_enable_ppgtt(dev) && HAS_ALIASING_PPGTT(dev)) {
1201 /* PPGTT pdes are stolen from global gtt ptes, so shrink the 1216 /* PPGTT pdes are stolen from global gtt ptes, so shrink the
1202 * aperture accordingly when using aliasing ppgtt. */ 1217 * aperture accordingly when using aliasing ppgtt. */
1203 gtt_size -= I915_PPGTT_PD_ENTRIES*PAGE_SIZE; 1218 gtt_size -= I915_PPGTT_PD_ENTRIES*PAGE_SIZE;
@@ -1207,8 +1222,10 @@ static int i915_load_gem_init(struct drm_device *dev)
1207 i915_gem_do_init(dev, 0, mappable_size, gtt_size); 1222 i915_gem_do_init(dev, 0, mappable_size, gtt_size);
1208 1223
1209 ret = i915_gem_init_aliasing_ppgtt(dev); 1224 ret = i915_gem_init_aliasing_ppgtt(dev);
1210 if (ret) 1225 if (ret) {
1226 mutex_unlock(&dev->struct_mutex);
1211 return ret; 1227 return ret;
1228 }
1212 } else { 1229 } else {
1213 /* Let GEM Manage all of the aperture. 1230 /* Let GEM Manage all of the aperture.
1214 * 1231 *
@@ -1684,6 +1701,9 @@ void i915_update_gfx_val(struct drm_i915_private *dev_priv)
1684 unsigned long diffms; 1701 unsigned long diffms;
1685 u32 count; 1702 u32 count;
1686 1703
1704 if (dev_priv->info->gen != 5)
1705 return;
1706
1687 getrawmonotonic(&now); 1707 getrawmonotonic(&now);
1688 diff1 = timespec_sub(now, dev_priv->last_time2); 1708 diff1 = timespec_sub(now, dev_priv->last_time2);
1689 1709
@@ -2104,12 +2124,14 @@ int i915_driver_load(struct drm_device *dev, unsigned long flags)
2104 setup_timer(&dev_priv->hangcheck_timer, i915_hangcheck_elapsed, 2124 setup_timer(&dev_priv->hangcheck_timer, i915_hangcheck_elapsed,
2105 (unsigned long) dev); 2125 (unsigned long) dev);
2106 2126
2107 spin_lock(&mchdev_lock); 2127 if (IS_GEN5(dev)) {
2108 i915_mch_dev = dev_priv; 2128 spin_lock(&mchdev_lock);
2109 dev_priv->mchdev_lock = &mchdev_lock; 2129 i915_mch_dev = dev_priv;
2110 spin_unlock(&mchdev_lock); 2130 dev_priv->mchdev_lock = &mchdev_lock;
2131 spin_unlock(&mchdev_lock);
2111 2132
2112 ips_ping_for_i915_load(); 2133 ips_ping_for_i915_load();
2134 }
2113 2135
2114 return 0; 2136 return 0;
2115 2137
diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
index 1a7559b59997..ae8a64f9f845 100644
--- a/drivers/gpu/drm/i915/i915_drv.c
+++ b/drivers/gpu/drm/i915/i915_drv.c
@@ -64,9 +64,13 @@ MODULE_PARM_DESC(semaphores,
64 "Use semaphores for inter-ring sync (default: -1 (use per-chip defaults))"); 64 "Use semaphores for inter-ring sync (default: -1 (use per-chip defaults))");
65 65
66int i915_enable_rc6 __read_mostly = -1; 66int i915_enable_rc6 __read_mostly = -1;
67module_param_named(i915_enable_rc6, i915_enable_rc6, int, 0600); 67module_param_named(i915_enable_rc6, i915_enable_rc6, int, 0400);
68MODULE_PARM_DESC(i915_enable_rc6, 68MODULE_PARM_DESC(i915_enable_rc6,
69 "Enable power-saving render C-state 6 (default: -1 (use per-chip default)"); 69 "Enable power-saving render C-state 6. "
70 "Different stages can be selected via bitmask values "
71 "(0 = disable; 1 = enable rc6; 2 = enable deep rc6; 4 = enable deepest rc6). "
72 "For example, 3 would enable rc6 and deep rc6, and 7 would enable everything. "
73 "default: -1 (use per-chip default)");
70 74
71int i915_enable_fbc __read_mostly = -1; 75int i915_enable_fbc __read_mostly = -1;
72module_param_named(i915_enable_fbc, i915_enable_fbc, int, 0600); 76module_param_named(i915_enable_fbc, i915_enable_fbc, int, 0600);
@@ -103,8 +107,8 @@ MODULE_PARM_DESC(enable_hangcheck,
103 "WARNING: Disabling this can cause system wide hangs. " 107 "WARNING: Disabling this can cause system wide hangs. "
104 "(default: true)"); 108 "(default: true)");
105 109
106bool i915_enable_ppgtt __read_mostly = 1; 110int i915_enable_ppgtt __read_mostly = -1;
107module_param_named(i915_enable_ppgtt, i915_enable_ppgtt, bool, 0600); 111module_param_named(i915_enable_ppgtt, i915_enable_ppgtt, int, 0600);
108MODULE_PARM_DESC(i915_enable_ppgtt, 112MODULE_PARM_DESC(i915_enable_ppgtt,
109 "Enable PPGTT (default: true)"); 113 "Enable PPGTT (default: true)");
110 114
@@ -292,6 +296,7 @@ static const struct pci_device_id pciidlist[] = { /* aka */
292 INTEL_VGA_DEVICE(0x0152, &intel_ivybridge_d_info), /* GT1 desktop */ 296 INTEL_VGA_DEVICE(0x0152, &intel_ivybridge_d_info), /* GT1 desktop */
293 INTEL_VGA_DEVICE(0x0162, &intel_ivybridge_d_info), /* GT2 desktop */ 297 INTEL_VGA_DEVICE(0x0162, &intel_ivybridge_d_info), /* GT2 desktop */
294 INTEL_VGA_DEVICE(0x015a, &intel_ivybridge_d_info), /* GT1 server */ 298 INTEL_VGA_DEVICE(0x015a, &intel_ivybridge_d_info), /* GT1 server */
299 INTEL_VGA_DEVICE(0x016a, &intel_ivybridge_d_info), /* GT2 server */
295 {0, 0, 0} 300 {0, 0, 0}
296}; 301};
297 302
@@ -533,7 +538,9 @@ static int i915_drm_thaw(struct drm_device *dev)
533 drm_irq_install(dev); 538 drm_irq_install(dev);
534 539
535 /* Resume the modeset for every activated CRTC */ 540 /* Resume the modeset for every activated CRTC */
541 mutex_lock(&dev->mode_config.mutex);
536 drm_helper_resume_force_mode(dev); 542 drm_helper_resume_force_mode(dev);
543 mutex_unlock(&dev->mode_config.mutex);
537 544
538 if (IS_IRONLAKE_M(dev)) 545 if (IS_IRONLAKE_M(dev))
539 ironlake_enable_rc6(dev); 546 ironlake_enable_rc6(dev);
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index c0f19f572004..5fabc6c31fec 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -1053,6 +1053,27 @@ struct drm_i915_file_private {
1053 1053
1054#include "i915_trace.h" 1054#include "i915_trace.h"
1055 1055
1056/**
1057 * RC6 is a special power stage which allows the GPU to enter an very
1058 * low-voltage mode when idle, using down to 0V while at this stage. This
1059 * stage is entered automatically when the GPU is idle when RC6 support is
1060 * enabled, and as soon as new workload arises GPU wakes up automatically as well.
1061 *
1062 * There are different RC6 modes available in Intel GPU, which differentiate
1063 * among each other with the latency required to enter and leave RC6 and
1064 * voltage consumed by the GPU in different states.
1065 *
1066 * The combination of the following flags define which states GPU is allowed
1067 * to enter, while RC6 is the normal RC6 state, RC6p is the deep RC6, and
1068 * RC6pp is deepest RC6. Their support by hardware varies according to the
1069 * GPU, BIOS, chipset and platform. RC6 is usually the safest one and the one
1070 * which brings the most power savings; deeper states save more power, but
1071 * require higher latency to switch to and wake up.
1072 */
1073#define INTEL_RC6_ENABLE (1<<0)
1074#define INTEL_RC6p_ENABLE (1<<1)
1075#define INTEL_RC6pp_ENABLE (1<<2)
1076
1056extern struct drm_ioctl_desc i915_ioctls[]; 1077extern struct drm_ioctl_desc i915_ioctls[];
1057extern int i915_max_ioctl; 1078extern int i915_max_ioctl;
1058extern unsigned int i915_fbpercrtc __always_unused; 1079extern unsigned int i915_fbpercrtc __always_unused;
@@ -1065,7 +1086,7 @@ extern int i915_vbt_sdvo_panel_type __read_mostly;
1065extern int i915_enable_rc6 __read_mostly; 1086extern int i915_enable_rc6 __read_mostly;
1066extern int i915_enable_fbc __read_mostly; 1087extern int i915_enable_fbc __read_mostly;
1067extern bool i915_enable_hangcheck __read_mostly; 1088extern bool i915_enable_hangcheck __read_mostly;
1068extern bool i915_enable_ppgtt __read_mostly; 1089extern int i915_enable_ppgtt __read_mostly;
1069 1090
1070extern int i915_suspend(struct drm_device *dev, pm_message_t state); 1091extern int i915_suspend(struct drm_device *dev, pm_message_t state);
1071extern int i915_resume(struct drm_device *dev); 1092extern int i915_resume(struct drm_device *dev);
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 1f441f5c2405..0d1e4b7b4b99 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -1087,11 +1087,9 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data,
1087 if (obj == NULL) 1087 if (obj == NULL)
1088 return -ENOENT; 1088 return -ENOENT;
1089 1089
1090 down_write(&current->mm->mmap_sem); 1090 addr = vm_mmap(obj->filp, 0, args->size,
1091 addr = do_mmap(obj->filp, 0, args->size,
1092 PROT_READ | PROT_WRITE, MAP_SHARED, 1091 PROT_READ | PROT_WRITE, MAP_SHARED,
1093 args->offset); 1092 args->offset);
1094 up_write(&current->mm->mmap_sem);
1095 drm_gem_object_unreference_unlocked(obj); 1093 drm_gem_object_unreference_unlocked(obj);
1096 if (IS_ERR((void *)addr)) 1094 if (IS_ERR((void *)addr))
1097 return addr; 1095 return addr;
@@ -1472,16 +1470,19 @@ i915_gem_object_move_to_active(struct drm_i915_gem_object *obj,
1472 list_move_tail(&obj->ring_list, &ring->active_list); 1470 list_move_tail(&obj->ring_list, &ring->active_list);
1473 1471
1474 obj->last_rendering_seqno = seqno; 1472 obj->last_rendering_seqno = seqno;
1475 if (obj->fenced_gpu_access) {
1476 struct drm_i915_fence_reg *reg;
1477
1478 BUG_ON(obj->fence_reg == I915_FENCE_REG_NONE);
1479 1473
1474 if (obj->fenced_gpu_access) {
1480 obj->last_fenced_seqno = seqno; 1475 obj->last_fenced_seqno = seqno;
1481 obj->last_fenced_ring = ring; 1476 obj->last_fenced_ring = ring;
1482 1477
1483 reg = &dev_priv->fence_regs[obj->fence_reg]; 1478 /* Bump MRU to take account of the delayed flush */
1484 list_move_tail(&reg->lru_list, &dev_priv->mm.fence_list); 1479 if (obj->fence_reg != I915_FENCE_REG_NONE) {
1480 struct drm_i915_fence_reg *reg;
1481
1482 reg = &dev_priv->fence_regs[obj->fence_reg];
1483 list_move_tail(&reg->lru_list,
1484 &dev_priv->mm.fence_list);
1485 }
1485 } 1486 }
1486} 1487}
1487 1488
@@ -1490,6 +1491,7 @@ i915_gem_object_move_off_active(struct drm_i915_gem_object *obj)
1490{ 1491{
1491 list_del_init(&obj->ring_list); 1492 list_del_init(&obj->ring_list);
1492 obj->last_rendering_seqno = 0; 1493 obj->last_rendering_seqno = 0;
1494 obj->last_fenced_seqno = 0;
1493} 1495}
1494 1496
1495static void 1497static void
@@ -1518,6 +1520,7 @@ i915_gem_object_move_to_inactive(struct drm_i915_gem_object *obj)
1518 BUG_ON(!list_empty(&obj->gpu_write_list)); 1520 BUG_ON(!list_empty(&obj->gpu_write_list));
1519 BUG_ON(!obj->active); 1521 BUG_ON(!obj->active);
1520 obj->ring = NULL; 1522 obj->ring = NULL;
1523 obj->last_fenced_ring = NULL;
1521 1524
1522 i915_gem_object_move_off_active(obj); 1525 i915_gem_object_move_off_active(obj);
1523 obj->fenced_gpu_access = false; 1526 obj->fenced_gpu_access = false;
@@ -3754,12 +3757,32 @@ void i915_gem_init_ppgtt(struct drm_device *dev)
3754 drm_i915_private_t *dev_priv = dev->dev_private; 3757 drm_i915_private_t *dev_priv = dev->dev_private;
3755 uint32_t pd_offset; 3758 uint32_t pd_offset;
3756 struct intel_ring_buffer *ring; 3759 struct intel_ring_buffer *ring;
3760 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
3761 uint32_t __iomem *pd_addr;
3762 uint32_t pd_entry;
3757 int i; 3763 int i;
3758 3764
3759 if (!dev_priv->mm.aliasing_ppgtt) 3765 if (!dev_priv->mm.aliasing_ppgtt)
3760 return; 3766 return;
3761 3767
3762 pd_offset = dev_priv->mm.aliasing_ppgtt->pd_offset; 3768
3769 pd_addr = dev_priv->mm.gtt->gtt + ppgtt->pd_offset/sizeof(uint32_t);
3770 for (i = 0; i < ppgtt->num_pd_entries; i++) {
3771 dma_addr_t pt_addr;
3772
3773 if (dev_priv->mm.gtt->needs_dmar)
3774 pt_addr = ppgtt->pt_dma_addr[i];
3775 else
3776 pt_addr = page_to_phys(ppgtt->pt_pages[i]);
3777
3778 pd_entry = GEN6_PDE_ADDR_ENCODE(pt_addr);
3779 pd_entry |= GEN6_PDE_VALID;
3780
3781 writel(pd_entry, pd_addr + i);
3782 }
3783 readl(pd_addr);
3784
3785 pd_offset = ppgtt->pd_offset;
3763 pd_offset /= 64; /* in cachelines, */ 3786 pd_offset /= 64; /* in cachelines, */
3764 pd_offset <<= 16; 3787 pd_offset <<= 16;
3765 3788
diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
index 81687af00893..de431942ded4 100644
--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
@@ -498,8 +498,8 @@ pin_and_fence_object(struct drm_i915_gem_object *obj,
498 if (ret) 498 if (ret)
499 goto err_unpin; 499 goto err_unpin;
500 } 500 }
501 obj->pending_fenced_gpu_access = true;
501 } 502 }
502 obj->pending_fenced_gpu_access = need_fence;
503 } 503 }
504 504
505 entry->offset = obj->gtt_offset; 505 entry->offset = obj->gtt_offset;
@@ -1133,6 +1133,11 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,
1133 return -EINVAL; 1133 return -EINVAL;
1134 } 1134 }
1135 1135
1136 if (args->num_cliprects > UINT_MAX / sizeof(*cliprects)) {
1137 DRM_DEBUG("execbuf with %u cliprects\n",
1138 args->num_cliprects);
1139 return -EINVAL;
1140 }
1136 cliprects = kmalloc(args->num_cliprects * sizeof(*cliprects), 1141 cliprects = kmalloc(args->num_cliprects * sizeof(*cliprects),
1137 GFP_KERNEL); 1142 GFP_KERNEL);
1138 if (cliprects == NULL) { 1143 if (cliprects == NULL) {
@@ -1404,7 +1409,8 @@ i915_gem_execbuffer2(struct drm_device *dev, void *data,
1404 struct drm_i915_gem_exec_object2 *exec2_list = NULL; 1409 struct drm_i915_gem_exec_object2 *exec2_list = NULL;
1405 int ret; 1410 int ret;
1406 1411
1407 if (args->buffer_count < 1) { 1412 if (args->buffer_count < 1 ||
1413 args->buffer_count > UINT_MAX / sizeof(*exec2_list)) {
1408 DRM_DEBUG("execbuf2 with %d buffers\n", args->buffer_count); 1414 DRM_DEBUG("execbuf2 with %d buffers\n", args->buffer_count);
1409 return -EINVAL; 1415 return -EINVAL;
1410 } 1416 }
diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c
index 2eacd78bb93b..a135c61f4119 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.c
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
@@ -65,9 +65,7 @@ int i915_gem_init_aliasing_ppgtt(struct drm_device *dev)
65{ 65{
66 struct drm_i915_private *dev_priv = dev->dev_private; 66 struct drm_i915_private *dev_priv = dev->dev_private;
67 struct i915_hw_ppgtt *ppgtt; 67 struct i915_hw_ppgtt *ppgtt;
68 uint32_t pd_entry;
69 unsigned first_pd_entry_in_global_pt; 68 unsigned first_pd_entry_in_global_pt;
70 uint32_t __iomem *pd_addr;
71 int i; 69 int i;
72 int ret = -ENOMEM; 70 int ret = -ENOMEM;
73 71
@@ -100,7 +98,6 @@ int i915_gem_init_aliasing_ppgtt(struct drm_device *dev)
100 goto err_pt_alloc; 98 goto err_pt_alloc;
101 } 99 }
102 100
103 pd_addr = dev_priv->mm.gtt->gtt + first_pd_entry_in_global_pt;
104 for (i = 0; i < ppgtt->num_pd_entries; i++) { 101 for (i = 0; i < ppgtt->num_pd_entries; i++) {
105 dma_addr_t pt_addr; 102 dma_addr_t pt_addr;
106 if (dev_priv->mm.gtt->needs_dmar) { 103 if (dev_priv->mm.gtt->needs_dmar) {
@@ -117,13 +114,7 @@ int i915_gem_init_aliasing_ppgtt(struct drm_device *dev)
117 ppgtt->pt_dma_addr[i] = pt_addr; 114 ppgtt->pt_dma_addr[i] = pt_addr;
118 } else 115 } else
119 pt_addr = page_to_phys(ppgtt->pt_pages[i]); 116 pt_addr = page_to_phys(ppgtt->pt_pages[i]);
120
121 pd_entry = GEN6_PDE_ADDR_ENCODE(pt_addr);
122 pd_entry |= GEN6_PDE_VALID;
123
124 writel(pd_entry, pd_addr + i);
125 } 117 }
126 readl(pd_addr);
127 118
128 ppgtt->scratch_page_dma_addr = dev_priv->mm.gtt->scratch_page_dma; 119 ppgtt->scratch_page_dma_addr = dev_priv->mm.gtt->scratch_page_dma;
129 120
diff --git a/drivers/gpu/drm/i915/i915_reg.h b/drivers/gpu/drm/i915/i915_reg.h
index 3886cf051bac..9d24d65f0c3e 100644
--- a/drivers/gpu/drm/i915/i915_reg.h
+++ b/drivers/gpu/drm/i915/i915_reg.h
@@ -568,6 +568,7 @@
568#define CM0_MASK_SHIFT 16 568#define CM0_MASK_SHIFT 16
569#define CM0_IZ_OPT_DISABLE (1<<6) 569#define CM0_IZ_OPT_DISABLE (1<<6)
570#define CM0_ZR_OPT_DISABLE (1<<5) 570#define CM0_ZR_OPT_DISABLE (1<<5)
571#define CM0_STC_EVICT_DISABLE_LRA_SNB (1<<5)
571#define CM0_DEPTH_EVICT_DISABLE (1<<4) 572#define CM0_DEPTH_EVICT_DISABLE (1<<4)
572#define CM0_COLOR_EVICT_DISABLE (1<<3) 573#define CM0_COLOR_EVICT_DISABLE (1<<3)
573#define CM0_DEPTH_WRITE_DISABLE (1<<1) 574#define CM0_DEPTH_WRITE_DISABLE (1<<1)
@@ -2385,6 +2386,7 @@
2385#define PIPECONF_DISABLE 0 2386#define PIPECONF_DISABLE 0
2386#define PIPECONF_DOUBLE_WIDE (1<<30) 2387#define PIPECONF_DOUBLE_WIDE (1<<30)
2387#define I965_PIPECONF_ACTIVE (1<<30) 2388#define I965_PIPECONF_ACTIVE (1<<30)
2389#define PIPECONF_FRAME_START_DELAY_MASK (3<<27)
2388#define PIPECONF_SINGLE_WIDE 0 2390#define PIPECONF_SINGLE_WIDE 0
2389#define PIPECONF_PIPE_UNLOCKED 0 2391#define PIPECONF_PIPE_UNLOCKED 0
2390#define PIPECONF_PIPE_LOCKED (1<<25) 2392#define PIPECONF_PIPE_LOCKED (1<<25)
@@ -3727,6 +3729,9 @@
3727#define GT_FIFO_FREE_ENTRIES 0x120008 3729#define GT_FIFO_FREE_ENTRIES 0x120008
3728#define GT_FIFO_NUM_RESERVED_ENTRIES 20 3730#define GT_FIFO_NUM_RESERVED_ENTRIES 20
3729 3731
3732#define GEN6_UCGCTL1 0x9400
3733# define GEN6_BLBUNIT_CLOCK_GATE_DISABLE (1 << 5)
3734
3730#define GEN6_UCGCTL2 0x9404 3735#define GEN6_UCGCTL2 0x9404
3731# define GEN6_RCZUNIT_CLOCK_GATE_DISABLE (1 << 13) 3736# define GEN6_RCZUNIT_CLOCK_GATE_DISABLE (1 << 13)
3732# define GEN6_RCPBUNIT_CLOCK_GATE_DISABLE (1 << 12) 3737# define GEN6_RCPBUNIT_CLOCK_GATE_DISABLE (1 << 12)
diff --git a/drivers/gpu/drm/i915/intel_bios.c b/drivers/gpu/drm/i915/intel_bios.c
index 8168d8f8a634..b48fc2a8410c 100644
--- a/drivers/gpu/drm/i915/intel_bios.c
+++ b/drivers/gpu/drm/i915/intel_bios.c
@@ -24,6 +24,7 @@
24 * Eric Anholt <eric@anholt.net> 24 * Eric Anholt <eric@anholt.net>
25 * 25 *
26 */ 26 */
27#include <linux/dmi.h>
27#include <drm/drm_dp_helper.h> 28#include <drm/drm_dp_helper.h>
28#include "drmP.h" 29#include "drmP.h"
29#include "drm.h" 30#include "drm.h"
@@ -621,6 +622,26 @@ init_vbt_defaults(struct drm_i915_private *dev_priv)
621 dev_priv->edp.bpp = 18; 622 dev_priv->edp.bpp = 18;
622} 623}
623 624
625static int __init intel_no_opregion_vbt_callback(const struct dmi_system_id *id)
626{
627 DRM_DEBUG_KMS("Falling back to manually reading VBT from "
628 "VBIOS ROM for %s\n",
629 id->ident);
630 return 1;
631}
632
633static const struct dmi_system_id intel_no_opregion_vbt[] = {
634 {
635 .callback = intel_no_opregion_vbt_callback,
636 .ident = "ThinkCentre A57",
637 .matches = {
638 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
639 DMI_MATCH(DMI_PRODUCT_NAME, "97027RG"),
640 },
641 },
642 { }
643};
644
624/** 645/**
625 * intel_parse_bios - find VBT and initialize settings from the BIOS 646 * intel_parse_bios - find VBT and initialize settings from the BIOS
626 * @dev: DRM device 647 * @dev: DRM device
@@ -641,7 +662,7 @@ intel_parse_bios(struct drm_device *dev)
641 init_vbt_defaults(dev_priv); 662 init_vbt_defaults(dev_priv);
642 663
643 /* XXX Should this validation be moved to intel_opregion.c? */ 664 /* XXX Should this validation be moved to intel_opregion.c? */
644 if (dev_priv->opregion.vbt) { 665 if (!dmi_check_system(intel_no_opregion_vbt) && dev_priv->opregion.vbt) {
645 struct vbt_header *vbt = dev_priv->opregion.vbt; 666 struct vbt_header *vbt = dev_priv->opregion.vbt;
646 if (memcmp(vbt->signature, "$VBT", 4) == 0) { 667 if (memcmp(vbt->signature, "$VBT", 4) == 0) {
647 DRM_DEBUG_KMS("Using VBT from OpRegion: %20s\n", 668 DRM_DEBUG_KMS("Using VBT from OpRegion: %20s\n",
diff --git a/drivers/gpu/drm/i915/intel_crt.c b/drivers/gpu/drm/i915/intel_crt.c
index 4d3d736a4f56..90b9793fd5da 100644
--- a/drivers/gpu/drm/i915/intel_crt.c
+++ b/drivers/gpu/drm/i915/intel_crt.c
@@ -430,8 +430,8 @@ intel_crt_detect(struct drm_connector *connector, bool force)
430{ 430{
431 struct drm_device *dev = connector->dev; 431 struct drm_device *dev = connector->dev;
432 struct intel_crt *crt = intel_attached_crt(connector); 432 struct intel_crt *crt = intel_attached_crt(connector);
433 struct drm_crtc *crtc;
434 enum drm_connector_status status; 433 enum drm_connector_status status;
434 struct intel_load_detect_pipe tmp;
435 435
436 if (I915_HAS_HOTPLUG(dev)) { 436 if (I915_HAS_HOTPLUG(dev)) {
437 if (intel_crt_detect_hotplug(connector)) { 437 if (intel_crt_detect_hotplug(connector)) {
@@ -450,23 +450,16 @@ intel_crt_detect(struct drm_connector *connector, bool force)
450 return connector->status; 450 return connector->status;
451 451
452 /* for pre-945g platforms use load detect */ 452 /* for pre-945g platforms use load detect */
453 crtc = crt->base.base.crtc; 453 if (intel_get_load_detect_pipe(&crt->base, connector, NULL,
454 if (crtc && crtc->enabled) { 454 &tmp)) {
455 status = intel_crt_load_detect(crt); 455 if (intel_crt_detect_ddc(connector))
456 } else { 456 status = connector_status_connected;
457 struct intel_load_detect_pipe tmp; 457 else
458 458 status = intel_crt_load_detect(crt);
459 if (intel_get_load_detect_pipe(&crt->base, connector, NULL, 459 intel_release_load_detect_pipe(&crt->base, connector,
460 &tmp)) { 460 &tmp);
461 if (intel_crt_detect_ddc(connector)) 461 } else
462 status = connector_status_connected; 462 status = connector_status_unknown;
463 else
464 status = intel_crt_load_detect(crt);
465 intel_release_load_detect_pipe(&crt->base, connector,
466 &tmp);
467 } else
468 status = connector_status_unknown;
469 }
470 463
471 return status; 464 return status;
472} 465}
diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
index d514719f65e2..1b1cf3b3ff51 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -2245,6 +2245,33 @@ intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb,
2245} 2245}
2246 2246
2247static int 2247static int
2248intel_finish_fb(struct drm_framebuffer *old_fb)
2249{
2250 struct drm_i915_gem_object *obj = to_intel_framebuffer(old_fb)->obj;
2251 struct drm_i915_private *dev_priv = obj->base.dev->dev_private;
2252 bool was_interruptible = dev_priv->mm.interruptible;
2253 int ret;
2254
2255 wait_event(dev_priv->pending_flip_queue,
2256 atomic_read(&dev_priv->mm.wedged) ||
2257 atomic_read(&obj->pending_flip) == 0);
2258
2259 /* Big Hammer, we also need to ensure that any pending
2260 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
2261 * current scanout is retired before unpinning the old
2262 * framebuffer.
2263 *
2264 * This should only fail upon a hung GPU, in which case we
2265 * can safely continue.
2266 */
2267 dev_priv->mm.interruptible = false;
2268 ret = i915_gem_object_finish_gpu(obj);
2269 dev_priv->mm.interruptible = was_interruptible;
2270
2271 return ret;
2272}
2273
2274static int
2248intel_pipe_set_base(struct drm_crtc *crtc, int x, int y, 2275intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
2249 struct drm_framebuffer *old_fb) 2276 struct drm_framebuffer *old_fb)
2250{ 2277{
@@ -2282,25 +2309,8 @@ intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
2282 return ret; 2309 return ret;
2283 } 2310 }
2284 2311
2285 if (old_fb) { 2312 if (old_fb)
2286 struct drm_i915_private *dev_priv = dev->dev_private; 2313 intel_finish_fb(old_fb);
2287 struct drm_i915_gem_object *obj = to_intel_framebuffer(old_fb)->obj;
2288
2289 wait_event(dev_priv->pending_flip_queue,
2290 atomic_read(&dev_priv->mm.wedged) ||
2291 atomic_read(&obj->pending_flip) == 0);
2292
2293 /* Big Hammer, we also need to ensure that any pending
2294 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
2295 * current scanout is retired before unpinning the old
2296 * framebuffer.
2297 *
2298 * This should only fail upon a hung GPU, in which case we
2299 * can safely continue.
2300 */
2301 ret = i915_gem_object_finish_gpu(obj);
2302 (void) ret;
2303 }
2304 2314
2305 ret = intel_pipe_set_base_atomic(crtc, crtc->fb, x, y, 2315 ret = intel_pipe_set_base_atomic(crtc, crtc->fb, x, y,
2306 LEAVE_ATOMIC_MODE_SET); 2316 LEAVE_ATOMIC_MODE_SET);
@@ -3371,6 +3381,23 @@ static void intel_crtc_disable(struct drm_crtc *crtc)
3371 struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private; 3381 struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
3372 struct drm_device *dev = crtc->dev; 3382 struct drm_device *dev = crtc->dev;
3373 3383
3384 /* Flush any pending WAITs before we disable the pipe. Note that
3385 * we need to drop the struct_mutex in order to acquire it again
3386 * during the lowlevel dpms routines around a couple of the
3387 * operations. It does not look trivial nor desirable to move
3388 * that locking higher. So instead we leave a window for the
3389 * submission of further commands on the fb before we can actually
3390 * disable it. This race with userspace exists anyway, and we can
3391 * only rely on the pipe being disabled by userspace after it
3392 * receives the hotplug notification and has flushed any pending
3393 * batches.
3394 */
3395 if (crtc->fb) {
3396 mutex_lock(&dev->struct_mutex);
3397 intel_finish_fb(crtc->fb);
3398 mutex_unlock(&dev->struct_mutex);
3399 }
3400
3374 crtc_funcs->dpms(crtc, DRM_MODE_DPMS_OFF); 3401 crtc_funcs->dpms(crtc, DRM_MODE_DPMS_OFF);
3375 assert_plane_disabled(dev->dev_private, to_intel_crtc(crtc)->plane); 3402 assert_plane_disabled(dev->dev_private, to_intel_crtc(crtc)->plane);
3376 assert_pipe_disabled(dev->dev_private, to_intel_crtc(crtc)->pipe); 3403 assert_pipe_disabled(dev->dev_private, to_intel_crtc(crtc)->pipe);
@@ -3451,8 +3478,11 @@ static bool intel_crtc_mode_fixup(struct drm_crtc *crtc,
3451 return false; 3478 return false;
3452 } 3479 }
3453 3480
3454 /* All interlaced capable intel hw wants timings in frames. */ 3481 /* All interlaced capable intel hw wants timings in frames. Note though
3455 drm_mode_set_crtcinfo(adjusted_mode, 0); 3482 * that intel_lvds_mode_fixup does some funny tricks with the crtc
3483 * timings, so we need to be careful not to clobber these.*/
3484 if (!(adjusted_mode->private_flags & INTEL_MODE_CRTC_TIMINGS_SET))
3485 drm_mode_set_crtcinfo(adjusted_mode, 0);
3456 3486
3457 return true; 3487 return true;
3458} 3488}
@@ -5539,7 +5569,8 @@ void ironlake_init_pch_refclk(struct drm_device *dev)
5539 if (intel_panel_use_ssc(dev_priv) && can_ssc) { 5569 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
5540 DRM_DEBUG_KMS("Using SSC on panel\n"); 5570 DRM_DEBUG_KMS("Using SSC on panel\n");
5541 temp |= DREF_SSC1_ENABLE; 5571 temp |= DREF_SSC1_ENABLE;
5542 } 5572 } else
5573 temp &= ~DREF_SSC1_ENABLE;
5543 5574
5544 /* Get SSC going before enabling the outputs */ 5575 /* Get SSC going before enabling the outputs */
5545 I915_WRITE(PCH_DREF_CONTROL, temp); 5576 I915_WRITE(PCH_DREF_CONTROL, temp);
@@ -7041,9 +7072,6 @@ static void intel_decrease_pllclock(struct drm_crtc *crtc)
7041 struct drm_device *dev = crtc->dev; 7072 struct drm_device *dev = crtc->dev;
7042 drm_i915_private_t *dev_priv = dev->dev_private; 7073 drm_i915_private_t *dev_priv = dev->dev_private;
7043 struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 7074 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
7044 int pipe = intel_crtc->pipe;
7045 int dpll_reg = DPLL(pipe);
7046 int dpll = I915_READ(dpll_reg);
7047 7075
7048 if (HAS_PCH_SPLIT(dev)) 7076 if (HAS_PCH_SPLIT(dev))
7049 return; 7077 return;
@@ -7056,10 +7084,15 @@ static void intel_decrease_pllclock(struct drm_crtc *crtc)
7056 * the manual case. 7084 * the manual case.
7057 */ 7085 */
7058 if (!HAS_PIPE_CXSR(dev) && intel_crtc->lowfreq_avail) { 7086 if (!HAS_PIPE_CXSR(dev) && intel_crtc->lowfreq_avail) {
7087 int pipe = intel_crtc->pipe;
7088 int dpll_reg = DPLL(pipe);
7089 u32 dpll;
7090
7059 DRM_DEBUG_DRIVER("downclocking LVDS\n"); 7091 DRM_DEBUG_DRIVER("downclocking LVDS\n");
7060 7092
7061 assert_panel_unlocked(dev_priv, pipe); 7093 assert_panel_unlocked(dev_priv, pipe);
7062 7094
7095 dpll = I915_READ(dpll_reg);
7063 dpll |= DISPLAY_RATE_SELECT_FPA1; 7096 dpll |= DISPLAY_RATE_SELECT_FPA1;
7064 I915_WRITE(dpll_reg, dpll); 7097 I915_WRITE(dpll_reg, dpll);
7065 intel_wait_for_vblank(dev, pipe); 7098 intel_wait_for_vblank(dev, pipe);
@@ -7067,7 +7100,6 @@ static void intel_decrease_pllclock(struct drm_crtc *crtc)
7067 if (!(dpll & DISPLAY_RATE_SELECT_FPA1)) 7100 if (!(dpll & DISPLAY_RATE_SELECT_FPA1))
7068 DRM_DEBUG_DRIVER("failed to downclock LVDS!\n"); 7101 DRM_DEBUG_DRIVER("failed to downclock LVDS!\n");
7069 } 7102 }
7070
7071} 7103}
7072 7104
7073/** 7105/**
@@ -7437,7 +7469,13 @@ static int intel_gen6_queue_flip(struct drm_device *dev,
7437 OUT_RING(fb->pitches[0] | obj->tiling_mode); 7469 OUT_RING(fb->pitches[0] | obj->tiling_mode);
7438 OUT_RING(obj->gtt_offset); 7470 OUT_RING(obj->gtt_offset);
7439 7471
7440 pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE; 7472 /* Contrary to the suggestions in the documentation,
7473 * "Enable Panel Fitter" does not seem to be required when page
7474 * flipping with a non-native mode, and worse causes a normal
7475 * modeset to fail.
7476 * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
7477 */
7478 pf = 0;
7441 pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; 7479 pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
7442 OUT_RING(pf | pipesrc); 7480 OUT_RING(pf | pipesrc);
7443 ADVANCE_LP_RING(); 7481 ADVANCE_LP_RING();
@@ -7580,6 +7618,12 @@ static void intel_sanitize_modesetting(struct drm_device *dev,
7580 struct drm_i915_private *dev_priv = dev->dev_private; 7618 struct drm_i915_private *dev_priv = dev->dev_private;
7581 u32 reg, val; 7619 u32 reg, val;
7582 7620
7621 /* Clear any frame start delays used for debugging left by the BIOS */
7622 for_each_pipe(pipe) {
7623 reg = PIPECONF(pipe);
7624 I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
7625 }
7626
7583 if (HAS_PCH_SPLIT(dev)) 7627 if (HAS_PCH_SPLIT(dev))
7584 return; 7628 return;
7585 7629
@@ -8215,7 +8259,7 @@ void intel_init_emon(struct drm_device *dev)
8215 dev_priv->corr = (lcfuse & LCFUSE_HIV_MASK); 8259 dev_priv->corr = (lcfuse & LCFUSE_HIV_MASK);
8216} 8260}
8217 8261
8218static bool intel_enable_rc6(struct drm_device *dev) 8262static int intel_enable_rc6(struct drm_device *dev)
8219{ 8263{
8220 /* 8264 /*
8221 * Respect the kernel parameter if it is set 8265 * Respect the kernel parameter if it is set
@@ -8233,11 +8277,11 @@ static bool intel_enable_rc6(struct drm_device *dev)
8233 * Disable rc6 on Sandybridge 8277 * Disable rc6 on Sandybridge
8234 */ 8278 */
8235 if (INTEL_INFO(dev)->gen == 6) { 8279 if (INTEL_INFO(dev)->gen == 6) {
8236 DRM_DEBUG_DRIVER("Sandybridge: RC6 disabled\n"); 8280 DRM_DEBUG_DRIVER("Sandybridge: deep RC6 disabled\n");
8237 return 0; 8281 return INTEL_RC6_ENABLE;
8238 } 8282 }
8239 DRM_DEBUG_DRIVER("RC6 enabled\n"); 8283 DRM_DEBUG_DRIVER("RC6 and deep RC6 enabled\n");
8240 return 1; 8284 return (INTEL_RC6_ENABLE | INTEL_RC6p_ENABLE);
8241} 8285}
8242 8286
8243void gen6_enable_rps(struct drm_i915_private *dev_priv) 8287void gen6_enable_rps(struct drm_i915_private *dev_priv)
@@ -8247,6 +8291,7 @@ void gen6_enable_rps(struct drm_i915_private *dev_priv)
8247 u32 pcu_mbox, rc6_mask = 0; 8291 u32 pcu_mbox, rc6_mask = 0;
8248 u32 gtfifodbg; 8292 u32 gtfifodbg;
8249 int cur_freq, min_freq, max_freq; 8293 int cur_freq, min_freq, max_freq;
8294 int rc6_mode;
8250 int i; 8295 int i;
8251 8296
8252 /* Here begins a magic sequence of register writes to enable 8297 /* Here begins a magic sequence of register writes to enable
@@ -8284,9 +8329,20 @@ void gen6_enable_rps(struct drm_i915_private *dev_priv)
8284 I915_WRITE(GEN6_RC6p_THRESHOLD, 100000); 8329 I915_WRITE(GEN6_RC6p_THRESHOLD, 100000);
8285 I915_WRITE(GEN6_RC6pp_THRESHOLD, 64000); /* unused */ 8330 I915_WRITE(GEN6_RC6pp_THRESHOLD, 64000); /* unused */
8286 8331
8287 if (intel_enable_rc6(dev_priv->dev)) 8332 rc6_mode = intel_enable_rc6(dev_priv->dev);
8288 rc6_mask = GEN6_RC_CTL_RC6_ENABLE | 8333 if (rc6_mode & INTEL_RC6_ENABLE)
8289 ((IS_GEN7(dev_priv->dev)) ? GEN6_RC_CTL_RC6p_ENABLE : 0); 8334 rc6_mask |= GEN6_RC_CTL_RC6_ENABLE;
8335
8336 if (rc6_mode & INTEL_RC6p_ENABLE)
8337 rc6_mask |= GEN6_RC_CTL_RC6p_ENABLE;
8338
8339 if (rc6_mode & INTEL_RC6pp_ENABLE)
8340 rc6_mask |= GEN6_RC_CTL_RC6pp_ENABLE;
8341
8342 DRM_INFO("Enabling RC6 states: RC6 %s, RC6p %s, RC6pp %s\n",
8343 (rc6_mode & INTEL_RC6_ENABLE) ? "on" : "off",
8344 (rc6_mode & INTEL_RC6p_ENABLE) ? "on" : "off",
8345 (rc6_mode & INTEL_RC6pp_ENABLE) ? "on" : "off");
8290 8346
8291 I915_WRITE(GEN6_RC_CONTROL, 8347 I915_WRITE(GEN6_RC_CONTROL,
8292 rc6_mask | 8348 rc6_mask |
@@ -8510,6 +8566,10 @@ static void gen6_init_clock_gating(struct drm_device *dev)
8510 I915_WRITE(WM2_LP_ILK, 0); 8566 I915_WRITE(WM2_LP_ILK, 0);
8511 I915_WRITE(WM1_LP_ILK, 0); 8567 I915_WRITE(WM1_LP_ILK, 0);
8512 8568
8569 I915_WRITE(GEN6_UCGCTL1,
8570 I915_READ(GEN6_UCGCTL1) |
8571 GEN6_BLBUNIT_CLOCK_GATE_DISABLE);
8572
8513 /* According to the BSpec vol1g, bit 12 (RCPBUNIT) clock 8573 /* According to the BSpec vol1g, bit 12 (RCPBUNIT) clock
8514 * gating disable must be set. Failure to set it results in 8574 * gating disable must be set. Failure to set it results in
8515 * flickering pixels due to Z write ordering failures after 8575 * flickering pixels due to Z write ordering failures after
diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
index 110552ff302c..4b637919f74f 100644
--- a/drivers/gpu/drm/i915/intel_dp.c
+++ b/drivers/gpu/drm/i915/intel_dp.c
@@ -219,14 +219,38 @@ intel_dp_max_data_rate(int max_link_clock, int max_lanes)
219 return (max_link_clock * max_lanes * 8) / 10; 219 return (max_link_clock * max_lanes * 8) / 10;
220} 220}
221 221
222static bool
223intel_dp_adjust_dithering(struct intel_dp *intel_dp,
224 struct drm_display_mode *mode,
225 struct drm_display_mode *adjusted_mode)
226{
227 int max_link_clock = intel_dp_link_clock(intel_dp_max_link_bw(intel_dp));
228 int max_lanes = intel_dp_max_lane_count(intel_dp);
229 int max_rate, mode_rate;
230
231 mode_rate = intel_dp_link_required(mode->clock, 24);
232 max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
233
234 if (mode_rate > max_rate) {
235 mode_rate = intel_dp_link_required(mode->clock, 18);
236 if (mode_rate > max_rate)
237 return false;
238
239 if (adjusted_mode)
240 adjusted_mode->private_flags
241 |= INTEL_MODE_DP_FORCE_6BPC;
242
243 return true;
244 }
245
246 return true;
247}
248
222static int 249static int
223intel_dp_mode_valid(struct drm_connector *connector, 250intel_dp_mode_valid(struct drm_connector *connector,
224 struct drm_display_mode *mode) 251 struct drm_display_mode *mode)
225{ 252{
226 struct intel_dp *intel_dp = intel_attached_dp(connector); 253 struct intel_dp *intel_dp = intel_attached_dp(connector);
227 int max_link_clock = intel_dp_link_clock(intel_dp_max_link_bw(intel_dp));
228 int max_lanes = intel_dp_max_lane_count(intel_dp);
229 int max_rate, mode_rate;
230 254
231 if (is_edp(intel_dp) && intel_dp->panel_fixed_mode) { 255 if (is_edp(intel_dp) && intel_dp->panel_fixed_mode) {
232 if (mode->hdisplay > intel_dp->panel_fixed_mode->hdisplay) 256 if (mode->hdisplay > intel_dp->panel_fixed_mode->hdisplay)
@@ -236,16 +260,8 @@ intel_dp_mode_valid(struct drm_connector *connector,
236 return MODE_PANEL; 260 return MODE_PANEL;
237 } 261 }
238 262
239 mode_rate = intel_dp_link_required(mode->clock, 24); 263 if (!intel_dp_adjust_dithering(intel_dp, mode, NULL))
240 max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes); 264 return MODE_CLOCK_HIGH;
241
242 if (mode_rate > max_rate) {
243 mode_rate = intel_dp_link_required(mode->clock, 18);
244 if (mode_rate > max_rate)
245 return MODE_CLOCK_HIGH;
246 else
247 mode->private_flags |= INTEL_MODE_DP_FORCE_6BPC;
248 }
249 265
250 if (mode->clock < 10000) 266 if (mode->clock < 10000)
251 return MODE_CLOCK_LOW; 267 return MODE_CLOCK_LOW;
@@ -672,7 +688,7 @@ intel_dp_mode_fixup(struct drm_encoder *encoder, struct drm_display_mode *mode,
672 int lane_count, clock; 688 int lane_count, clock;
673 int max_lane_count = intel_dp_max_lane_count(intel_dp); 689 int max_lane_count = intel_dp_max_lane_count(intel_dp);
674 int max_clock = intel_dp_max_link_bw(intel_dp) == DP_LINK_BW_2_7 ? 1 : 0; 690 int max_clock = intel_dp_max_link_bw(intel_dp) == DP_LINK_BW_2_7 ? 1 : 0;
675 int bpp = mode->private_flags & INTEL_MODE_DP_FORCE_6BPC ? 18 : 24; 691 int bpp;
676 static int bws[2] = { DP_LINK_BW_1_62, DP_LINK_BW_2_7 }; 692 static int bws[2] = { DP_LINK_BW_1_62, DP_LINK_BW_2_7 };
677 693
678 if (is_edp(intel_dp) && intel_dp->panel_fixed_mode) { 694 if (is_edp(intel_dp) && intel_dp->panel_fixed_mode) {
@@ -686,6 +702,11 @@ intel_dp_mode_fixup(struct drm_encoder *encoder, struct drm_display_mode *mode,
686 mode->clock = intel_dp->panel_fixed_mode->clock; 702 mode->clock = intel_dp->panel_fixed_mode->clock;
687 } 703 }
688 704
705 if (!intel_dp_adjust_dithering(intel_dp, mode, adjusted_mode))
706 return false;
707
708 bpp = adjusted_mode->private_flags & INTEL_MODE_DP_FORCE_6BPC ? 18 : 24;
709
689 for (lane_count = 1; lane_count <= max_lane_count; lane_count <<= 1) { 710 for (lane_count = 1; lane_count <= max_lane_count; lane_count <<= 1) {
690 for (clock = 0; clock <= max_clock; clock++) { 711 for (clock = 0; clock <= max_clock; clock++) {
691 int link_avail = intel_dp_max_data_rate(intel_dp_link_clock(bws[clock]), lane_count); 712 int link_avail = intel_dp_max_data_rate(intel_dp_link_clock(bws[clock]), lane_count);
diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
index 5a14149b3794..715afa153025 100644
--- a/drivers/gpu/drm/i915/intel_drv.h
+++ b/drivers/gpu/drm/i915/intel_drv.h
@@ -105,6 +105,10 @@
105#define INTEL_MODE_PIXEL_MULTIPLIER_SHIFT (0x0) 105#define INTEL_MODE_PIXEL_MULTIPLIER_SHIFT (0x0)
106#define INTEL_MODE_PIXEL_MULTIPLIER_MASK (0xf << INTEL_MODE_PIXEL_MULTIPLIER_SHIFT) 106#define INTEL_MODE_PIXEL_MULTIPLIER_MASK (0xf << INTEL_MODE_PIXEL_MULTIPLIER_SHIFT)
107#define INTEL_MODE_DP_FORCE_6BPC (0x10) 107#define INTEL_MODE_DP_FORCE_6BPC (0x10)
108/* This flag must be set by the encoder's mode_fixup if it changes the crtc
109 * timings in the mode to prevent the crtc fixup from overwriting them.
110 * Currently only lvds needs that. */
111#define INTEL_MODE_CRTC_TIMINGS_SET (0x20)
108 112
109static inline void 113static inline void
110intel_mode_set_pixel_multiplier(struct drm_display_mode *mode, 114intel_mode_set_pixel_multiplier(struct drm_display_mode *mode,
diff --git a/drivers/gpu/drm/i915/intel_fb.c b/drivers/gpu/drm/i915/intel_fb.c
index 19ecd78b8a2c..6e9ee33fd412 100644
--- a/drivers/gpu/drm/i915/intel_fb.c
+++ b/drivers/gpu/drm/i915/intel_fb.c
@@ -279,6 +279,8 @@ void intel_fb_restore_mode(struct drm_device *dev)
279 struct drm_mode_config *config = &dev->mode_config; 279 struct drm_mode_config *config = &dev->mode_config;
280 struct drm_plane *plane; 280 struct drm_plane *plane;
281 281
282 mutex_lock(&dev->mode_config.mutex);
283
282 ret = drm_fb_helper_restore_fbdev_mode(&dev_priv->fbdev->helper); 284 ret = drm_fb_helper_restore_fbdev_mode(&dev_priv->fbdev->helper);
283 if (ret) 285 if (ret)
284 DRM_DEBUG("failed to restore crtc mode\n"); 286 DRM_DEBUG("failed to restore crtc mode\n");
@@ -286,4 +288,6 @@ void intel_fb_restore_mode(struct drm_device *dev)
286 /* Be sure to shut off any planes that may be active */ 288 /* Be sure to shut off any planes that may be active */
287 list_for_each_entry(plane, &config->plane_list, head) 289 list_for_each_entry(plane, &config->plane_list, head)
288 plane->funcs->disable_plane(plane); 290 plane->funcs->disable_plane(plane);
291
292 mutex_unlock(&dev->mode_config.mutex);
289} 293}
diff --git a/drivers/gpu/drm/i915/intel_hdmi.c b/drivers/gpu/drm/i915/intel_hdmi.c
index cae3e5f17a49..2d7f47b56b6a 100644
--- a/drivers/gpu/drm/i915/intel_hdmi.c
+++ b/drivers/gpu/drm/i915/intel_hdmi.c
@@ -136,7 +136,7 @@ static void i9xx_write_infoframe(struct drm_encoder *encoder,
136 136
137 val &= ~VIDEO_DIP_SELECT_MASK; 137 val &= ~VIDEO_DIP_SELECT_MASK;
138 138
139 I915_WRITE(VIDEO_DIP_CTL, val | port | flags); 139 I915_WRITE(VIDEO_DIP_CTL, VIDEO_DIP_ENABLE | val | port | flags);
140 140
141 for (i = 0; i < len; i += 4) { 141 for (i = 0; i < len; i += 4) {
142 I915_WRITE(VIDEO_DIP_DATA, *data); 142 I915_WRITE(VIDEO_DIP_DATA, *data);
diff --git a/drivers/gpu/drm/i915/intel_i2c.c b/drivers/gpu/drm/i915/intel_i2c.c
index 601c86e664af..8fdc95700218 100644
--- a/drivers/gpu/drm/i915/intel_i2c.c
+++ b/drivers/gpu/drm/i915/intel_i2c.c
@@ -390,7 +390,7 @@ int intel_setup_gmbus(struct drm_device *dev)
390 bus->has_gpio = intel_gpio_setup(bus, i); 390 bus->has_gpio = intel_gpio_setup(bus, i);
391 391
392 /* XXX force bit banging until GMBUS is fully debugged */ 392 /* XXX force bit banging until GMBUS is fully debugged */
393 if (bus->has_gpio && IS_GEN2(dev)) 393 if (bus->has_gpio)
394 bus->force_bit = true; 394 bus->force_bit = true;
395 } 395 }
396 396
diff --git a/drivers/gpu/drm/i915/intel_lvds.c b/drivers/gpu/drm/i915/intel_lvds.c
index c5c0973af8a1..9c71183629c2 100644
--- a/drivers/gpu/drm/i915/intel_lvds.c
+++ b/drivers/gpu/drm/i915/intel_lvds.c
@@ -187,6 +187,8 @@ centre_horizontally(struct drm_display_mode *mode,
187 187
188 mode->crtc_hsync_start = mode->crtc_hblank_start + sync_pos; 188 mode->crtc_hsync_start = mode->crtc_hblank_start + sync_pos;
189 mode->crtc_hsync_end = mode->crtc_hsync_start + sync_width; 189 mode->crtc_hsync_end = mode->crtc_hsync_start + sync_width;
190
191 mode->private_flags |= INTEL_MODE_CRTC_TIMINGS_SET;
190} 192}
191 193
192static void 194static void
@@ -208,6 +210,8 @@ centre_vertically(struct drm_display_mode *mode,
208 210
209 mode->crtc_vsync_start = mode->crtc_vblank_start + sync_pos; 211 mode->crtc_vsync_start = mode->crtc_vblank_start + sync_pos;
210 mode->crtc_vsync_end = mode->crtc_vsync_start + sync_width; 212 mode->crtc_vsync_end = mode->crtc_vsync_start + sync_width;
213
214 mode->private_flags |= INTEL_MODE_CRTC_TIMINGS_SET;
211} 215}
212 216
213static inline u32 panel_fitter_scaling(u32 source, u32 target) 217static inline u32 panel_fitter_scaling(u32 source, u32 target)
@@ -283,6 +287,8 @@ static bool intel_lvds_mode_fixup(struct drm_encoder *encoder,
283 for_each_pipe(pipe) 287 for_each_pipe(pipe)
284 I915_WRITE(BCLRPAT(pipe), 0); 288 I915_WRITE(BCLRPAT(pipe), 0);
285 289
290 drm_mode_set_crtcinfo(adjusted_mode, 0);
291
286 switch (intel_lvds->fitting_mode) { 292 switch (intel_lvds->fitting_mode) {
287 case DRM_MODE_SCALE_CENTER: 293 case DRM_MODE_SCALE_CENTER:
288 /* 294 /*
@@ -744,7 +750,7 @@ static const struct dmi_system_id intel_no_lvds[] = {
744 .ident = "Hewlett-Packard t5745", 750 .ident = "Hewlett-Packard t5745",
745 .matches = { 751 .matches = {
746 DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"), 752 DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
747 DMI_MATCH(DMI_BOARD_NAME, "hp t5745"), 753 DMI_MATCH(DMI_PRODUCT_NAME, "hp t5745"),
748 }, 754 },
749 }, 755 },
750 { 756 {
@@ -752,7 +758,15 @@ static const struct dmi_system_id intel_no_lvds[] = {
752 .ident = "Hewlett-Packard st5747", 758 .ident = "Hewlett-Packard st5747",
753 .matches = { 759 .matches = {
754 DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"), 760 DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
755 DMI_MATCH(DMI_BOARD_NAME, "hp st5747"), 761 DMI_MATCH(DMI_PRODUCT_NAME, "hp st5747"),
762 },
763 },
764 {
765 .callback = intel_no_lvds_dmi_callback,
766 .ident = "MSI Wind Box DC500",
767 .matches = {
768 DMI_MATCH(DMI_BOARD_VENDOR, "MICRO-STAR INTERNATIONAL CO., LTD"),
769 DMI_MATCH(DMI_BOARD_NAME, "MS-7469"),
756 }, 770 },
757 }, 771 },
758 772
diff --git a/drivers/gpu/drm/i915/intel_panel.c b/drivers/gpu/drm/i915/intel_panel.c
index 230a141dbea3..48177ec4720e 100644
--- a/drivers/gpu/drm/i915/intel_panel.c
+++ b/drivers/gpu/drm/i915/intel_panel.c
@@ -47,8 +47,6 @@ intel_fixed_panel_mode(struct drm_display_mode *fixed_mode,
47 adjusted_mode->vtotal = fixed_mode->vtotal; 47 adjusted_mode->vtotal = fixed_mode->vtotal;
48 48
49 adjusted_mode->clock = fixed_mode->clock; 49 adjusted_mode->clock = fixed_mode->clock;
50
51 drm_mode_set_crtcinfo(adjusted_mode, 0);
52} 50}
53 51
54/* adjusted_mode has been preset to be the panel's fixed mode */ 52/* adjusted_mode has been preset to be the panel's fixed mode */
diff --git a/drivers/gpu/drm/i915/intel_ringbuffer.c b/drivers/gpu/drm/i915/intel_ringbuffer.c
index fc66af6a9448..62892a826ede 100644
--- a/drivers/gpu/drm/i915/intel_ringbuffer.c
+++ b/drivers/gpu/drm/i915/intel_ringbuffer.c
@@ -398,6 +398,17 @@ static int init_render_ring(struct intel_ring_buffer *ring)
398 return ret; 398 return ret;
399 } 399 }
400 400
401
402 if (IS_GEN6(dev)) {
403 /* From the Sandybridge PRM, volume 1 part 3, page 24:
404 * "If this bit is set, STCunit will have LRA as replacement
405 * policy. [...] This bit must be reset. LRA replacement
406 * policy is not supported."
407 */
408 I915_WRITE(CACHE_MODE_0,
409 CM0_STC_EVICT_DISABLE_LRA_SNB << CM0_MASK_SHIFT);
410 }
411
401 if (INTEL_INFO(dev)->gen >= 6) { 412 if (INTEL_INFO(dev)->gen >= 6) {
402 I915_WRITE(INSTPM, 413 I915_WRITE(INSTPM,
403 INSTPM_FORCE_ORDERING << 16 | INSTPM_FORCE_ORDERING); 414 INSTPM_FORCE_ORDERING << 16 | INSTPM_FORCE_ORDERING);
@@ -626,7 +637,7 @@ gen6_ring_get_seqno(struct intel_ring_buffer *ring)
626 /* Workaround to force correct ordering between irq and seqno writes on 637 /* Workaround to force correct ordering between irq and seqno writes on
627 * ivb (and maybe also on snb) by reading from a CS register (like 638 * ivb (and maybe also on snb) by reading from a CS register (like
628 * ACTHD) before reading the status page. */ 639 * ACTHD) before reading the status page. */
629 if (IS_GEN7(dev)) 640 if (IS_GEN6(dev) || IS_GEN7(dev))
630 intel_ring_get_active_head(ring); 641 intel_ring_get_active_head(ring);
631 return intel_read_status_page(ring, I915_GEM_HWS_INDEX); 642 return intel_read_status_page(ring, I915_GEM_HWS_INDEX);
632} 643}
@@ -1038,7 +1049,7 @@ int intel_init_ring_buffer(struct drm_device *dev,
1038 * of the buffer. 1049 * of the buffer.
1039 */ 1050 */
1040 ring->effective_size = ring->size; 1051 ring->effective_size = ring->size;
1041 if (IS_I830(ring->dev)) 1052 if (IS_I830(ring->dev) || IS_845G(ring->dev))
1042 ring->effective_size -= 128; 1053 ring->effective_size -= 128;
1043 1054
1044 return 0; 1055 return 0;
diff --git a/drivers/gpu/drm/i915/intel_sdvo.c b/drivers/gpu/drm/i915/intel_sdvo.c
index e36b171c1e7d..ae5e748f39bb 100644
--- a/drivers/gpu/drm/i915/intel_sdvo.c
+++ b/drivers/gpu/drm/i915/intel_sdvo.c
@@ -731,6 +731,7 @@ static void intel_sdvo_get_dtd_from_mode(struct intel_sdvo_dtd *dtd,
731 uint16_t width, height; 731 uint16_t width, height;
732 uint16_t h_blank_len, h_sync_len, v_blank_len, v_sync_len; 732 uint16_t h_blank_len, h_sync_len, v_blank_len, v_sync_len;
733 uint16_t h_sync_offset, v_sync_offset; 733 uint16_t h_sync_offset, v_sync_offset;
734 int mode_clock;
734 735
735 width = mode->crtc_hdisplay; 736 width = mode->crtc_hdisplay;
736 height = mode->crtc_vdisplay; 737 height = mode->crtc_vdisplay;
@@ -745,7 +746,11 @@ static void intel_sdvo_get_dtd_from_mode(struct intel_sdvo_dtd *dtd,
745 h_sync_offset = mode->crtc_hsync_start - mode->crtc_hblank_start; 746 h_sync_offset = mode->crtc_hsync_start - mode->crtc_hblank_start;
746 v_sync_offset = mode->crtc_vsync_start - mode->crtc_vblank_start; 747 v_sync_offset = mode->crtc_vsync_start - mode->crtc_vblank_start;
747 748
748 dtd->part1.clock = mode->clock / 10; 749 mode_clock = mode->clock;
750 mode_clock /= intel_mode_get_pixel_multiplier(mode) ?: 1;
751 mode_clock /= 10;
752 dtd->part1.clock = mode_clock;
753
749 dtd->part1.h_active = width & 0xff; 754 dtd->part1.h_active = width & 0xff;
750 dtd->part1.h_blank = h_blank_len & 0xff; 755 dtd->part1.h_blank = h_blank_len & 0xff;
751 dtd->part1.h_high = (((width >> 8) & 0xf) << 4) | 756 dtd->part1.h_high = (((width >> 8) & 0xf) << 4) |
@@ -996,7 +1001,7 @@ static void intel_sdvo_mode_set(struct drm_encoder *encoder,
996 struct intel_sdvo *intel_sdvo = to_intel_sdvo(encoder); 1001 struct intel_sdvo *intel_sdvo = to_intel_sdvo(encoder);
997 u32 sdvox; 1002 u32 sdvox;
998 struct intel_sdvo_in_out_map in_out; 1003 struct intel_sdvo_in_out_map in_out;
999 struct intel_sdvo_dtd input_dtd; 1004 struct intel_sdvo_dtd input_dtd, output_dtd;
1000 int pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode); 1005 int pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode);
1001 int rate; 1006 int rate;
1002 1007
@@ -1021,20 +1026,13 @@ static void intel_sdvo_mode_set(struct drm_encoder *encoder,
1021 intel_sdvo->attached_output)) 1026 intel_sdvo->attached_output))
1022 return; 1027 return;
1023 1028
1024 /* We have tried to get input timing in mode_fixup, and filled into 1029 /* lvds has a special fixed output timing. */
1025 * adjusted_mode. 1030 if (intel_sdvo->is_lvds)
1026 */ 1031 intel_sdvo_get_dtd_from_mode(&output_dtd,
1027 if (intel_sdvo->is_tv || intel_sdvo->is_lvds) { 1032 intel_sdvo->sdvo_lvds_fixed_mode);
1028 input_dtd = intel_sdvo->input_dtd; 1033 else
1029 } else { 1034 intel_sdvo_get_dtd_from_mode(&output_dtd, mode);
1030 /* Set the output timing to the screen */ 1035 (void) intel_sdvo_set_output_timing(intel_sdvo, &output_dtd);
1031 if (!intel_sdvo_set_target_output(intel_sdvo,
1032 intel_sdvo->attached_output))
1033 return;
1034
1035 intel_sdvo_get_dtd_from_mode(&input_dtd, adjusted_mode);
1036 (void) intel_sdvo_set_output_timing(intel_sdvo, &input_dtd);
1037 }
1038 1036
1039 /* Set the input timing to the screen. Assume always input 0. */ 1037 /* Set the input timing to the screen. Assume always input 0. */
1040 if (!intel_sdvo_set_target_input(intel_sdvo)) 1038 if (!intel_sdvo_set_target_input(intel_sdvo))
@@ -1052,6 +1050,10 @@ static void intel_sdvo_mode_set(struct drm_encoder *encoder,
1052 !intel_sdvo_set_tv_format(intel_sdvo)) 1050 !intel_sdvo_set_tv_format(intel_sdvo))
1053 return; 1051 return;
1054 1052
1053 /* We have tried to get input timing in mode_fixup, and filled into
1054 * adjusted_mode.
1055 */
1056 intel_sdvo_get_dtd_from_mode(&input_dtd, adjusted_mode);
1055 (void) intel_sdvo_set_input_timing(intel_sdvo, &input_dtd); 1057 (void) intel_sdvo_set_input_timing(intel_sdvo, &input_dtd);
1056 1058
1057 switch (pixel_multiplier) { 1059 switch (pixel_multiplier) {
@@ -1218,8 +1220,14 @@ static bool intel_sdvo_get_capabilities(struct intel_sdvo *intel_sdvo, struct in
1218 1220
1219static int intel_sdvo_supports_hotplug(struct intel_sdvo *intel_sdvo) 1221static int intel_sdvo_supports_hotplug(struct intel_sdvo *intel_sdvo)
1220{ 1222{
1223 struct drm_device *dev = intel_sdvo->base.base.dev;
1221 u8 response[2]; 1224 u8 response[2];
1222 1225
1226 /* HW Erratum: SDVO Hotplug is broken on all i945G chips, there's noise
1227 * on the line. */
1228 if (IS_I945G(dev) || IS_I945GM(dev))
1229 return false;
1230
1223 return intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_HOT_PLUG_SUPPORT, 1231 return intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_HOT_PLUG_SUPPORT,
1224 &response, 2) && response[0]; 1232 &response, 2) && response[0];
1225} 1233}
diff --git a/drivers/gpu/drm/i915/intel_sprite.c b/drivers/gpu/drm/i915/intel_sprite.c
index 7aa0450399a1..e90dfb625c42 100644
--- a/drivers/gpu/drm/i915/intel_sprite.c
+++ b/drivers/gpu/drm/i915/intel_sprite.c
@@ -95,7 +95,6 @@ ivb_update_plane(struct drm_plane *plane, struct drm_framebuffer *fb,
95 /* must disable */ 95 /* must disable */
96 sprctl |= SPRITE_TRICKLE_FEED_DISABLE; 96 sprctl |= SPRITE_TRICKLE_FEED_DISABLE;
97 sprctl |= SPRITE_ENABLE; 97 sprctl |= SPRITE_ENABLE;
98 sprctl |= SPRITE_DEST_KEY;
99 98
100 /* Sizes are 0 based */ 99 /* Sizes are 0 based */
101 src_w--; 100 src_w--;
@@ -411,6 +410,9 @@ intel_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
411 410
412 old_obj = intel_plane->obj; 411 old_obj = intel_plane->obj;
413 412
413 src_w = src_w >> 16;
414 src_h = src_h >> 16;
415
414 /* Pipe must be running... */ 416 /* Pipe must be running... */
415 if (!(I915_READ(PIPECONF(pipe)) & PIPECONF_ENABLE)) 417 if (!(I915_READ(PIPECONF(pipe)) & PIPECONF_ENABLE))
416 return -EINVAL; 418 return -EINVAL;
diff --git a/drivers/gpu/drm/nouveau/Kconfig b/drivers/gpu/drm/nouveau/Kconfig
index ca1639918f57..97a81260485a 100644
--- a/drivers/gpu/drm/nouveau/Kconfig
+++ b/drivers/gpu/drm/nouveau/Kconfig
@@ -13,6 +13,7 @@ config DRM_NOUVEAU
13 select ACPI_VIDEO if ACPI && X86 && BACKLIGHT_CLASS_DEVICE && VIDEO_OUTPUT_CONTROL && INPUT 13 select ACPI_VIDEO if ACPI && X86 && BACKLIGHT_CLASS_DEVICE && VIDEO_OUTPUT_CONTROL && INPUT
14 select ACPI_WMI if ACPI 14 select ACPI_WMI if ACPI
15 select MXM_WMI if ACPI 15 select MXM_WMI if ACPI
16 select POWER_SUPPLY
16 help 17 help
17 Choose this option for open-source nVidia support. 18 Choose this option for open-source nVidia support.
18 19
diff --git a/drivers/gpu/drm/nouveau/nouveau_acpi.c b/drivers/gpu/drm/nouveau/nouveau_acpi.c
index 7814a760c164..284bd25d5d21 100644
--- a/drivers/gpu/drm/nouveau/nouveau_acpi.c
+++ b/drivers/gpu/drm/nouveau/nouveau_acpi.c
@@ -270,7 +270,7 @@ static bool nouveau_dsm_detect(void)
270 struct acpi_buffer buffer = {sizeof(acpi_method_name), acpi_method_name}; 270 struct acpi_buffer buffer = {sizeof(acpi_method_name), acpi_method_name};
271 struct pci_dev *pdev = NULL; 271 struct pci_dev *pdev = NULL;
272 int has_dsm = 0; 272 int has_dsm = 0;
273 int has_optimus; 273 int has_optimus = 0;
274 int vga_count = 0; 274 int vga_count = 0;
275 bool guid_valid; 275 bool guid_valid;
276 int retval; 276 int retval;
diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
index 637afe71de56..0be4a815e706 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
@@ -177,14 +177,15 @@ bios_shadow_pci(struct nvbios *bios)
177 177
178 if (!pci_enable_rom(pdev)) { 178 if (!pci_enable_rom(pdev)) {
179 void __iomem *rom = pci_map_rom(pdev, &length); 179 void __iomem *rom = pci_map_rom(pdev, &length);
180 if (rom) { 180 if (rom && length) {
181 bios->data = kmalloc(length, GFP_KERNEL); 181 bios->data = kmalloc(length, GFP_KERNEL);
182 if (bios->data) { 182 if (bios->data) {
183 memcpy_fromio(bios->data, rom, length); 183 memcpy_fromio(bios->data, rom, length);
184 bios->length = length; 184 bios->length = length;
185 } 185 }
186 pci_unmap_rom(pdev, rom);
187 } 186 }
187 if (rom)
188 pci_unmap_rom(pdev, rom);
188 189
189 pci_disable_rom(pdev); 190 pci_disable_rom(pdev);
190 } 191 }
@@ -6155,10 +6156,14 @@ dcb_fake_connectors(struct nvbios *bios)
6155 6156
6156 /* heuristic: if we ever get a non-zero connector field, assume 6157 /* heuristic: if we ever get a non-zero connector field, assume
6157 * that all the indices are valid and we don't need fake them. 6158 * that all the indices are valid and we don't need fake them.
6159 *
6160 * and, as usual, a blacklist of boards with bad bios data..
6158 */ 6161 */
6159 for (i = 0; i < dcbt->entries; i++) { 6162 if (!nv_match_device(bios->dev, 0x0392, 0x107d, 0x20a2)) {
6160 if (dcbt->entry[i].connector) 6163 for (i = 0; i < dcbt->entries; i++) {
6161 return; 6164 if (dcbt->entry[i].connector)
6165 return;
6166 }
6162 } 6167 }
6163 6168
6164 /* no useful connector info available, we need to make it up 6169 /* no useful connector info available, we need to make it up
diff --git a/drivers/gpu/drm/nouveau/nouveau_channel.c b/drivers/gpu/drm/nouveau/nouveau_channel.c
index 44e6416d4a33..846afb0bfef4 100644
--- a/drivers/gpu/drm/nouveau/nouveau_channel.c
+++ b/drivers/gpu/drm/nouveau/nouveau_channel.c
@@ -436,11 +436,11 @@ nouveau_ioctl_fifo_alloc(struct drm_device *dev, void *data,
436 } 436 }
437 437
438 if (dev_priv->card_type < NV_C0) { 438 if (dev_priv->card_type < NV_C0) {
439 init->subchan[0].handle = NvSw; 439 init->subchan[0].handle = 0x00000000;
440 init->subchan[0].grclass = NV_SW; 440 init->subchan[0].grclass = 0x0000;
441 init->nr_subchan = 1; 441 init->subchan[1].handle = NvSw;
442 } else { 442 init->subchan[1].grclass = NV_SW;
443 init->nr_subchan = 0; 443 init->nr_subchan = 2;
444 } 444 }
445 445
446 /* Named memory object area */ 446 /* Named memory object area */
diff --git a/drivers/gpu/drm/nouveau/nouveau_dma.h b/drivers/gpu/drm/nouveau/nouveau_dma.h
index bcf0fd9e313e..23d4edf992b7 100644
--- a/drivers/gpu/drm/nouveau/nouveau_dma.h
+++ b/drivers/gpu/drm/nouveau/nouveau_dma.h
@@ -48,8 +48,8 @@ void nv50_dma_push(struct nouveau_channel *, struct nouveau_bo *,
48 48
49/* Hardcoded object assignments to subchannels (subchannel id). */ 49/* Hardcoded object assignments to subchannels (subchannel id). */
50enum { 50enum {
51 NvSubSw = 0, 51 NvSubM2MF = 0,
52 NvSubM2MF = 1, 52 NvSubSw = 1,
53 NvSub2D = 2, 53 NvSub2D = 2,
54 NvSubCtxSurf2D = 2, 54 NvSubCtxSurf2D = 2,
55 NvSubGdiRect = 3, 55 NvSubGdiRect = 3,
diff --git a/drivers/gpu/drm/nouveau/nouveau_hdmi.c b/drivers/gpu/drm/nouveau/nouveau_hdmi.c
index 59ea1c14eca0..c3de36384522 100644
--- a/drivers/gpu/drm/nouveau/nouveau_hdmi.c
+++ b/drivers/gpu/drm/nouveau/nouveau_hdmi.c
@@ -32,7 +32,9 @@ static bool
32hdmi_sor(struct drm_encoder *encoder) 32hdmi_sor(struct drm_encoder *encoder)
33{ 33{
34 struct drm_nouveau_private *dev_priv = encoder->dev->dev_private; 34 struct drm_nouveau_private *dev_priv = encoder->dev->dev_private;
35 if (dev_priv->chipset < 0xa3) 35 if (dev_priv->chipset < 0xa3 ||
36 dev_priv->chipset == 0xaa ||
37 dev_priv->chipset == 0xac)
36 return false; 38 return false;
37 return true; 39 return true;
38} 40}
diff --git a/drivers/gpu/drm/nouveau/nouveau_i2c.c b/drivers/gpu/drm/nouveau/nouveau_i2c.c
index e2be95af2e52..77e564667b5c 100644
--- a/drivers/gpu/drm/nouveau/nouveau_i2c.c
+++ b/drivers/gpu/drm/nouveau/nouveau_i2c.c
@@ -29,10 +29,6 @@
29#include "nouveau_i2c.h" 29#include "nouveau_i2c.h"
30#include "nouveau_hw.h" 30#include "nouveau_hw.h"
31 31
32#define T_TIMEOUT 2200000
33#define T_RISEFALL 1000
34#define T_HOLD 5000
35
36static void 32static void
37i2c_drive_scl(void *data, int state) 33i2c_drive_scl(void *data, int state)
38{ 34{
@@ -113,175 +109,6 @@ i2c_sense_sda(void *data)
113 return 0; 109 return 0;
114} 110}
115 111
116static void
117i2c_delay(struct nouveau_i2c_chan *port, u32 nsec)
118{
119 udelay((nsec + 500) / 1000);
120}
121
122static bool
123i2c_raise_scl(struct nouveau_i2c_chan *port)
124{
125 u32 timeout = T_TIMEOUT / T_RISEFALL;
126
127 i2c_drive_scl(port, 1);
128 do {
129 i2c_delay(port, T_RISEFALL);
130 } while (!i2c_sense_scl(port) && --timeout);
131
132 return timeout != 0;
133}
134
135static int
136i2c_start(struct nouveau_i2c_chan *port)
137{
138 int ret = 0;
139
140 port->state = i2c_sense_scl(port);
141 port->state |= i2c_sense_sda(port) << 1;
142 if (port->state != 3) {
143 i2c_drive_scl(port, 0);
144 i2c_drive_sda(port, 1);
145 if (!i2c_raise_scl(port))
146 ret = -EBUSY;
147 }
148
149 i2c_drive_sda(port, 0);
150 i2c_delay(port, T_HOLD);
151 i2c_drive_scl(port, 0);
152 i2c_delay(port, T_HOLD);
153 return ret;
154}
155
156static void
157i2c_stop(struct nouveau_i2c_chan *port)
158{
159 i2c_drive_scl(port, 0);
160 i2c_drive_sda(port, 0);
161 i2c_delay(port, T_RISEFALL);
162
163 i2c_drive_scl(port, 1);
164 i2c_delay(port, T_HOLD);
165 i2c_drive_sda(port, 1);
166 i2c_delay(port, T_HOLD);
167}
168
169static int
170i2c_bitw(struct nouveau_i2c_chan *port, int sda)
171{
172 i2c_drive_sda(port, sda);
173 i2c_delay(port, T_RISEFALL);
174
175 if (!i2c_raise_scl(port))
176 return -ETIMEDOUT;
177 i2c_delay(port, T_HOLD);
178
179 i2c_drive_scl(port, 0);
180 i2c_delay(port, T_HOLD);
181 return 0;
182}
183
184static int
185i2c_bitr(struct nouveau_i2c_chan *port)
186{
187 int sda;
188
189 i2c_drive_sda(port, 1);
190 i2c_delay(port, T_RISEFALL);
191
192 if (!i2c_raise_scl(port))
193 return -ETIMEDOUT;
194 i2c_delay(port, T_HOLD);
195
196 sda = i2c_sense_sda(port);
197
198 i2c_drive_scl(port, 0);
199 i2c_delay(port, T_HOLD);
200 return sda;
201}
202
203static int
204i2c_get_byte(struct nouveau_i2c_chan *port, u8 *byte, bool last)
205{
206 int i, bit;
207
208 *byte = 0;
209 for (i = 7; i >= 0; i--) {
210 bit = i2c_bitr(port);
211 if (bit < 0)
212 return bit;
213 *byte |= bit << i;
214 }
215
216 return i2c_bitw(port, last ? 1 : 0);
217}
218
219static int
220i2c_put_byte(struct nouveau_i2c_chan *port, u8 byte)
221{
222 int i, ret;
223 for (i = 7; i >= 0; i--) {
224 ret = i2c_bitw(port, !!(byte & (1 << i)));
225 if (ret < 0)
226 return ret;
227 }
228
229 ret = i2c_bitr(port);
230 if (ret == 1) /* nack */
231 ret = -EIO;
232 return ret;
233}
234
235static int
236i2c_addr(struct nouveau_i2c_chan *port, struct i2c_msg *msg)
237{
238 u32 addr = msg->addr << 1;
239 if (msg->flags & I2C_M_RD)
240 addr |= 1;
241 return i2c_put_byte(port, addr);
242}
243
244static int
245i2c_bit_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
246{
247 struct nouveau_i2c_chan *port = (struct nouveau_i2c_chan *)adap;
248 struct i2c_msg *msg = msgs;
249 int ret = 0, mcnt = num;
250
251 while (!ret && mcnt--) {
252 u8 remaining = msg->len;
253 u8 *ptr = msg->buf;
254
255 ret = i2c_start(port);
256 if (ret == 0)
257 ret = i2c_addr(port, msg);
258
259 if (msg->flags & I2C_M_RD) {
260 while (!ret && remaining--)
261 ret = i2c_get_byte(port, ptr++, !remaining);
262 } else {
263 while (!ret && remaining--)
264 ret = i2c_put_byte(port, *ptr++);
265 }
266
267 msg++;
268 }
269
270 i2c_stop(port);
271 return (ret < 0) ? ret : num;
272}
273
274static u32
275i2c_bit_func(struct i2c_adapter *adap)
276{
277 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
278}
279
280const struct i2c_algorithm nouveau_i2c_bit_algo = {
281 .master_xfer = i2c_bit_xfer,
282 .functionality = i2c_bit_func
283};
284
285static const uint32_t nv50_i2c_port[] = { 112static const uint32_t nv50_i2c_port[] = {
286 0x00e138, 0x00e150, 0x00e168, 0x00e180, 113 0x00e138, 0x00e150, 0x00e168, 0x00e180,
287 0x00e254, 0x00e274, 0x00e764, 0x00e780, 114 0x00e254, 0x00e274, 0x00e764, 0x00e780,
@@ -384,12 +211,10 @@ nouveau_i2c_init(struct drm_device *dev)
384 case 0: /* NV04:NV50 */ 211 case 0: /* NV04:NV50 */
385 port->drive = entry[0]; 212 port->drive = entry[0];
386 port->sense = entry[1]; 213 port->sense = entry[1];
387 port->adapter.algo = &nouveau_i2c_bit_algo;
388 break; 214 break;
389 case 4: /* NV4E */ 215 case 4: /* NV4E */
390 port->drive = 0x600800 + entry[1]; 216 port->drive = 0x600800 + entry[1];
391 port->sense = port->drive; 217 port->sense = port->drive;
392 port->adapter.algo = &nouveau_i2c_bit_algo;
393 break; 218 break;
394 case 5: /* NV50- */ 219 case 5: /* NV50- */
395 port->drive = entry[0] & 0x0f; 220 port->drive = entry[0] & 0x0f;
@@ -402,7 +227,6 @@ nouveau_i2c_init(struct drm_device *dev)
402 port->drive = 0x00d014 + (port->drive * 0x20); 227 port->drive = 0x00d014 + (port->drive * 0x20);
403 port->sense = port->drive; 228 port->sense = port->drive;
404 } 229 }
405 port->adapter.algo = &nouveau_i2c_bit_algo;
406 break; 230 break;
407 case 6: /* NV50- DP AUX */ 231 case 6: /* NV50- DP AUX */
408 port->drive = entry[0]; 232 port->drive = entry[0];
@@ -413,7 +237,7 @@ nouveau_i2c_init(struct drm_device *dev)
413 break; 237 break;
414 } 238 }
415 239
416 if (!port->adapter.algo) { 240 if (!port->adapter.algo && !port->drive) {
417 NV_ERROR(dev, "I2C%d: type %d index %x/%x unknown\n", 241 NV_ERROR(dev, "I2C%d: type %d index %x/%x unknown\n",
418 i, port->type, port->drive, port->sense); 242 i, port->type, port->drive, port->sense);
419 kfree(port); 243 kfree(port);
@@ -429,7 +253,26 @@ nouveau_i2c_init(struct drm_device *dev)
429 port->dcb = ROM32(entry[0]); 253 port->dcb = ROM32(entry[0]);
430 i2c_set_adapdata(&port->adapter, i2c); 254 i2c_set_adapdata(&port->adapter, i2c);
431 255
432 ret = i2c_add_adapter(&port->adapter); 256 if (port->adapter.algo != &nouveau_dp_i2c_algo) {
257 port->adapter.algo_data = &port->bit;
258 port->bit.udelay = 10;
259 port->bit.timeout = usecs_to_jiffies(2200);
260 port->bit.data = port;
261 port->bit.setsda = i2c_drive_sda;
262 port->bit.setscl = i2c_drive_scl;
263 port->bit.getsda = i2c_sense_sda;
264 port->bit.getscl = i2c_sense_scl;
265
266 i2c_drive_scl(port, 0);
267 i2c_drive_sda(port, 1);
268 i2c_drive_scl(port, 1);
269
270 ret = i2c_bit_add_bus(&port->adapter);
271 } else {
272 port->adapter.algo = &nouveau_dp_i2c_algo;
273 ret = i2c_add_adapter(&port->adapter);
274 }
275
433 if (ret) { 276 if (ret) {
434 NV_ERROR(dev, "I2C%d: failed register: %d\n", i, ret); 277 NV_ERROR(dev, "I2C%d: failed register: %d\n", i, ret);
435 kfree(port); 278 kfree(port);
diff --git a/drivers/gpu/drm/nouveau/nouveau_i2c.h b/drivers/gpu/drm/nouveau/nouveau_i2c.h
index 4d2e4e9031be..1d083893a4d7 100644
--- a/drivers/gpu/drm/nouveau/nouveau_i2c.h
+++ b/drivers/gpu/drm/nouveau/nouveau_i2c.h
@@ -34,6 +34,7 @@
34struct nouveau_i2c_chan { 34struct nouveau_i2c_chan {
35 struct i2c_adapter adapter; 35 struct i2c_adapter adapter;
36 struct drm_device *dev; 36 struct drm_device *dev;
37 struct i2c_algo_bit_data bit;
37 struct list_head head; 38 struct list_head head;
38 u8 index; 39 u8 index;
39 u8 type; 40 u8 type;
diff --git a/drivers/gpu/drm/nouveau/nouveau_pm.c b/drivers/gpu/drm/nouveau/nouveau_pm.c
index 34d591b7d4ef..da3e7c3abab7 100644
--- a/drivers/gpu/drm/nouveau/nouveau_pm.c
+++ b/drivers/gpu/drm/nouveau/nouveau_pm.c
@@ -235,6 +235,7 @@ nouveau_pm_profile_set(struct drm_device *dev, const char *profile)
235 return -EPERM; 235 return -EPERM;
236 236
237 strncpy(string, profile, sizeof(string)); 237 strncpy(string, profile, sizeof(string));
238 string[sizeof(string) - 1] = 0;
238 if ((ptr = strchr(string, '\n'))) 239 if ((ptr = strchr(string, '\n')))
239 *ptr = '\0'; 240 *ptr = '\0';
240 241
diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
index a4886b36d0fa..c2a8511e855a 100644
--- a/drivers/gpu/drm/nouveau/nouveau_state.c
+++ b/drivers/gpu/drm/nouveau/nouveau_state.c
@@ -642,7 +642,7 @@ nouveau_card_channel_init(struct drm_device *dev)
642 OUT_RING (chan, chan->vram_handle); 642 OUT_RING (chan, chan->vram_handle);
643 OUT_RING (chan, chan->gart_handle); 643 OUT_RING (chan, chan->gart_handle);
644 } else 644 } else
645 if (dev_priv->card_type <= NV_C0) { 645 if (dev_priv->card_type <= NV_D0) {
646 ret = nouveau_gpuobj_gr_new(chan, 0x9039, 0x9039); 646 ret = nouveau_gpuobj_gr_new(chan, 0x9039, 0x9039);
647 if (ret) 647 if (ret)
648 goto error; 648 goto error;
diff --git a/drivers/gpu/drm/nouveau/nv10_gpio.c b/drivers/gpu/drm/nouveau/nv10_gpio.c
index 550ad3fcf0af..9d79180069df 100644
--- a/drivers/gpu/drm/nouveau/nv10_gpio.c
+++ b/drivers/gpu/drm/nouveau/nv10_gpio.c
@@ -65,7 +65,7 @@ nv10_gpio_drive(struct drm_device *dev, int line, int dir, int out)
65 if (line < 10) { 65 if (line < 10) {
66 line = (line - 2) * 4; 66 line = (line - 2) * 4;
67 reg = NV_PCRTC_GPIO_EXT; 67 reg = NV_PCRTC_GPIO_EXT;
68 mask = 0x00000003 << ((line - 2) * 4); 68 mask = 0x00000003;
69 data = (dir << 1) | out; 69 data = (dir << 1) | out;
70 } else 70 } else
71 if (line < 14) { 71 if (line < 14) {
diff --git a/drivers/gpu/drm/nouveau/nv50_sor.c b/drivers/gpu/drm/nouveau/nv50_sor.c
index a7844ab6a50c..274640212475 100644
--- a/drivers/gpu/drm/nouveau/nv50_sor.c
+++ b/drivers/gpu/drm/nouveau/nv50_sor.c
@@ -42,7 +42,7 @@ nv50_sor_dp_lane_map(struct drm_device *dev, struct dcb_entry *dcb, u8 lane)
42 struct drm_nouveau_private *dev_priv = dev->dev_private; 42 struct drm_nouveau_private *dev_priv = dev->dev_private;
43 static const u8 nvaf[] = { 24, 16, 8, 0 }; /* thanks, apple.. */ 43 static const u8 nvaf[] = { 24, 16, 8, 0 }; /* thanks, apple.. */
44 static const u8 nv50[] = { 16, 8, 0, 24 }; 44 static const u8 nv50[] = { 16, 8, 0, 24 };
45 if (dev_priv->card_type == 0xaf) 45 if (dev_priv->chipset == 0xaf)
46 return nvaf[lane]; 46 return nvaf[lane];
47 return nv50[lane]; 47 return nv50[lane];
48} 48}
diff --git a/drivers/gpu/drm/nouveau/nvc0_fb.c b/drivers/gpu/drm/nouveau/nvc0_fb.c
index 5bf55038fd92..f704e942372e 100644
--- a/drivers/gpu/drm/nouveau/nvc0_fb.c
+++ b/drivers/gpu/drm/nouveau/nvc0_fb.c
@@ -54,6 +54,11 @@ nvc0_mfb_isr(struct drm_device *dev)
54 nvc0_mfb_subp_isr(dev, unit, subp); 54 nvc0_mfb_subp_isr(dev, unit, subp);
55 units &= ~(1 << unit); 55 units &= ~(1 << unit);
56 } 56 }
57
58 /* we do something horribly wrong and upset PMFB a lot, so mask off
59 * interrupts from it after the first one until it's fixed
60 */
61 nv_mask(dev, 0x000640, 0x02000000, 0x00000000);
57} 62}
58 63
59static void 64static void
diff --git a/drivers/gpu/drm/radeon/atom.c b/drivers/gpu/drm/radeon/atom.c
index d1bd239cd9e9..5ce9bf51a8de 100644
--- a/drivers/gpu/drm/radeon/atom.c
+++ b/drivers/gpu/drm/radeon/atom.c
@@ -1306,8 +1306,11 @@ struct atom_context *atom_parse(struct card_info *card, void *bios)
1306 1306
1307int atom_asic_init(struct atom_context *ctx) 1307int atom_asic_init(struct atom_context *ctx)
1308{ 1308{
1309 struct radeon_device *rdev = ctx->card->dev->dev_private;
1309 int hwi = CU16(ctx->data_table + ATOM_DATA_FWI_PTR); 1310 int hwi = CU16(ctx->data_table + ATOM_DATA_FWI_PTR);
1310 uint32_t ps[16]; 1311 uint32_t ps[16];
1312 int ret;
1313
1311 memset(ps, 0, 64); 1314 memset(ps, 0, 64);
1312 1315
1313 ps[0] = cpu_to_le32(CU32(hwi + ATOM_FWI_DEFSCLK_PTR)); 1316 ps[0] = cpu_to_le32(CU32(hwi + ATOM_FWI_DEFSCLK_PTR));
@@ -1317,7 +1320,17 @@ int atom_asic_init(struct atom_context *ctx)
1317 1320
1318 if (!CU16(ctx->cmd_table + 4 + 2 * ATOM_CMD_INIT)) 1321 if (!CU16(ctx->cmd_table + 4 + 2 * ATOM_CMD_INIT))
1319 return 1; 1322 return 1;
1320 return atom_execute_table(ctx, ATOM_CMD_INIT, ps); 1323 ret = atom_execute_table(ctx, ATOM_CMD_INIT, ps);
1324 if (ret)
1325 return ret;
1326
1327 memset(ps, 0, 64);
1328
1329 if (rdev->family < CHIP_R600) {
1330 if (CU16(ctx->cmd_table + 4 + 2 * ATOM_CMD_SPDFANCNTL))
1331 atom_execute_table(ctx, ATOM_CMD_SPDFANCNTL, ps);
1332 }
1333 return ret;
1321} 1334}
1322 1335
1323void atom_destroy(struct atom_context *ctx) 1336void atom_destroy(struct atom_context *ctx)
diff --git a/drivers/gpu/drm/radeon/atom.h b/drivers/gpu/drm/radeon/atom.h
index 93cfe2086ba0..25fea631dad2 100644
--- a/drivers/gpu/drm/radeon/atom.h
+++ b/drivers/gpu/drm/radeon/atom.h
@@ -44,6 +44,7 @@
44#define ATOM_CMD_SETSCLK 0x0A 44#define ATOM_CMD_SETSCLK 0x0A
45#define ATOM_CMD_SETMCLK 0x0B 45#define ATOM_CMD_SETMCLK 0x0B
46#define ATOM_CMD_SETPCLK 0x0C 46#define ATOM_CMD_SETPCLK 0x0C
47#define ATOM_CMD_SPDFANCNTL 0x39
47 48
48#define ATOM_DATA_FWI_PTR 0xC 49#define ATOM_DATA_FWI_PTR 0xC
49#define ATOM_DATA_IIO_PTR 0x32 50#define ATOM_DATA_IIO_PTR 0x32
diff --git a/drivers/gpu/drm/radeon/atombios_crtc.c b/drivers/gpu/drm/radeon/atombios_crtc.c
index b5ff1f7b6f7e..af1054f8202a 100644
--- a/drivers/gpu/drm/radeon/atombios_crtc.c
+++ b/drivers/gpu/drm/radeon/atombios_crtc.c
@@ -575,6 +575,9 @@ static u32 atombios_adjust_pll(struct drm_crtc *crtc,
575 575
576 if (rdev->family < CHIP_RV770) 576 if (rdev->family < CHIP_RV770)
577 pll->flags |= RADEON_PLL_PREFER_MINM_OVER_MAXP; 577 pll->flags |= RADEON_PLL_PREFER_MINM_OVER_MAXP;
578 /* use frac fb div on APUs */
579 if (ASIC_IS_DCE41(rdev) || ASIC_IS_DCE61(rdev))
580 pll->flags |= RADEON_PLL_USE_FRAC_FB_DIV;
578 } else { 581 } else {
579 pll->flags |= RADEON_PLL_LEGACY; 582 pll->flags |= RADEON_PLL_LEGACY;
580 583
@@ -955,8 +958,8 @@ static void atombios_crtc_set_pll(struct drm_crtc *crtc, struct drm_display_mode
955 break; 958 break;
956 } 959 }
957 960
958 if (radeon_encoder->active_device & 961 if ((radeon_encoder->active_device & (ATOM_DEVICE_LCD_SUPPORT | ATOM_DEVICE_DFP_SUPPORT)) ||
959 (ATOM_DEVICE_LCD_SUPPORT | ATOM_DEVICE_DFP_SUPPORT)) { 962 (radeon_encoder_get_dp_bridge_encoder_id(encoder) != ENCODER_OBJECT_ID_NONE)) {
960 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; 963 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
961 struct drm_connector *connector = 964 struct drm_connector *connector =
962 radeon_get_connector_for_encoder(encoder); 965 radeon_get_connector_for_encoder(encoder);
diff --git a/drivers/gpu/drm/radeon/atombios_encoders.c b/drivers/gpu/drm/radeon/atombios_encoders.c
index e607c4d7dd98..2d39f9977e00 100644
--- a/drivers/gpu/drm/radeon/atombios_encoders.c
+++ b/drivers/gpu/drm/radeon/atombios_encoders.c
@@ -230,6 +230,10 @@ atombios_dvo_setup(struct drm_encoder *encoder, int action)
230 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev)) 230 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
231 return; 231 return;
232 232
233 /* some R4xx chips have the wrong frev */
234 if (rdev->family <= CHIP_RV410)
235 frev = 1;
236
233 switch (frev) { 237 switch (frev) {
234 case 1: 238 case 1:
235 switch (crev) { 239 switch (crev) {
diff --git a/drivers/gpu/drm/radeon/r100.c b/drivers/gpu/drm/radeon/r100.c
index 81801c176aa5..fe33d35dae8c 100644
--- a/drivers/gpu/drm/radeon/r100.c
+++ b/drivers/gpu/drm/radeon/r100.c
@@ -2553,7 +2553,7 @@ static void r100_pll_errata_after_data(struct radeon_device *rdev)
2553 * or the chip could hang on a subsequent access 2553 * or the chip could hang on a subsequent access
2554 */ 2554 */
2555 if (rdev->pll_errata & CHIP_ERRATA_PLL_DELAY) { 2555 if (rdev->pll_errata & CHIP_ERRATA_PLL_DELAY) {
2556 udelay(5000); 2556 mdelay(5);
2557 } 2557 }
2558 2558
2559 /* This function is required to workaround a hardware bug in some (all?) 2559 /* This function is required to workaround a hardware bug in some (all?)
diff --git a/drivers/gpu/drm/radeon/r600.c b/drivers/gpu/drm/radeon/r600.c
index 391bd2636a80..c8187c4b6ae8 100644
--- a/drivers/gpu/drm/radeon/r600.c
+++ b/drivers/gpu/drm/radeon/r600.c
@@ -1135,7 +1135,7 @@ static void r600_vram_gtt_location(struct radeon_device *rdev, struct radeon_mc
1135 } 1135 }
1136 if (rdev->flags & RADEON_IS_AGP) { 1136 if (rdev->flags & RADEON_IS_AGP) {
1137 size_bf = mc->gtt_start; 1137 size_bf = mc->gtt_start;
1138 size_af = 0xFFFFFFFF - mc->gtt_end + 1; 1138 size_af = 0xFFFFFFFF - mc->gtt_end;
1139 if (size_bf > size_af) { 1139 if (size_bf > size_af) {
1140 if (mc->mc_vram_size > size_bf) { 1140 if (mc->mc_vram_size > size_bf) {
1141 dev_warn(rdev->dev, "limiting VRAM\n"); 1141 dev_warn(rdev->dev, "limiting VRAM\n");
@@ -1149,7 +1149,7 @@ static void r600_vram_gtt_location(struct radeon_device *rdev, struct radeon_mc
1149 mc->real_vram_size = size_af; 1149 mc->real_vram_size = size_af;
1150 mc->mc_vram_size = size_af; 1150 mc->mc_vram_size = size_af;
1151 } 1151 }
1152 mc->vram_start = mc->gtt_end; 1152 mc->vram_start = mc->gtt_end + 1;
1153 } 1153 }
1154 mc->vram_end = mc->vram_start + mc->mc_vram_size - 1; 1154 mc->vram_end = mc->vram_start + mc->mc_vram_size - 1;
1155 dev_info(rdev->dev, "VRAM: %lluM 0x%08llX - 0x%08llX (%lluM used)\n", 1155 dev_info(rdev->dev, "VRAM: %lluM 0x%08llX - 0x%08llX (%lluM used)\n",
@@ -2839,7 +2839,7 @@ void r600_rlc_stop(struct radeon_device *rdev)
2839 /* r7xx asics need to soft reset RLC before halting */ 2839 /* r7xx asics need to soft reset RLC before halting */
2840 WREG32(SRBM_SOFT_RESET, SOFT_RESET_RLC); 2840 WREG32(SRBM_SOFT_RESET, SOFT_RESET_RLC);
2841 RREG32(SRBM_SOFT_RESET); 2841 RREG32(SRBM_SOFT_RESET);
2842 udelay(15000); 2842 mdelay(15);
2843 WREG32(SRBM_SOFT_RESET, 0); 2843 WREG32(SRBM_SOFT_RESET, 0);
2844 RREG32(SRBM_SOFT_RESET); 2844 RREG32(SRBM_SOFT_RESET);
2845 } 2845 }
diff --git a/drivers/gpu/drm/radeon/r600_cp.c b/drivers/gpu/drm/radeon/r600_cp.c
index 84c546250955..75ed17c96115 100644
--- a/drivers/gpu/drm/radeon/r600_cp.c
+++ b/drivers/gpu/drm/radeon/r600_cp.c
@@ -407,7 +407,7 @@ static void r600_cp_load_microcode(drm_radeon_private_t *dev_priv)
407 407
408 RADEON_WRITE(R600_GRBM_SOFT_RESET, R600_SOFT_RESET_CP); 408 RADEON_WRITE(R600_GRBM_SOFT_RESET, R600_SOFT_RESET_CP);
409 RADEON_READ(R600_GRBM_SOFT_RESET); 409 RADEON_READ(R600_GRBM_SOFT_RESET);
410 DRM_UDELAY(15000); 410 mdelay(15);
411 RADEON_WRITE(R600_GRBM_SOFT_RESET, 0); 411 RADEON_WRITE(R600_GRBM_SOFT_RESET, 0);
412 412
413 fw_data = (const __be32 *)dev_priv->me_fw->data; 413 fw_data = (const __be32 *)dev_priv->me_fw->data;
@@ -500,7 +500,7 @@ static void r700_cp_load_microcode(drm_radeon_private_t *dev_priv)
500 500
501 RADEON_WRITE(R600_GRBM_SOFT_RESET, R600_SOFT_RESET_CP); 501 RADEON_WRITE(R600_GRBM_SOFT_RESET, R600_SOFT_RESET_CP);
502 RADEON_READ(R600_GRBM_SOFT_RESET); 502 RADEON_READ(R600_GRBM_SOFT_RESET);
503 DRM_UDELAY(15000); 503 mdelay(15);
504 RADEON_WRITE(R600_GRBM_SOFT_RESET, 0); 504 RADEON_WRITE(R600_GRBM_SOFT_RESET, 0);
505 505
506 fw_data = (const __be32 *)dev_priv->pfp_fw->data; 506 fw_data = (const __be32 *)dev_priv->pfp_fw->data;
@@ -1797,7 +1797,7 @@ static void r600_cp_init_ring_buffer(struct drm_device *dev,
1797 1797
1798 RADEON_WRITE(R600_GRBM_SOFT_RESET, R600_SOFT_RESET_CP); 1798 RADEON_WRITE(R600_GRBM_SOFT_RESET, R600_SOFT_RESET_CP);
1799 RADEON_READ(R600_GRBM_SOFT_RESET); 1799 RADEON_READ(R600_GRBM_SOFT_RESET);
1800 DRM_UDELAY(15000); 1800 mdelay(15);
1801 RADEON_WRITE(R600_GRBM_SOFT_RESET, 0); 1801 RADEON_WRITE(R600_GRBM_SOFT_RESET, 0);
1802 1802
1803 1803
diff --git a/drivers/gpu/drm/radeon/radeon_clocks.c b/drivers/gpu/drm/radeon/radeon_clocks.c
index 6ae0c75f016a..9c6b29a41927 100644
--- a/drivers/gpu/drm/radeon/radeon_clocks.c
+++ b/drivers/gpu/drm/radeon/radeon_clocks.c
@@ -633,7 +633,7 @@ void radeon_legacy_set_clock_gating(struct radeon_device *rdev, int enable)
633 tmp &= ~(R300_SCLK_FORCE_VAP); 633 tmp &= ~(R300_SCLK_FORCE_VAP);
634 tmp |= RADEON_SCLK_FORCE_CP; 634 tmp |= RADEON_SCLK_FORCE_CP;
635 WREG32_PLL(RADEON_SCLK_CNTL, tmp); 635 WREG32_PLL(RADEON_SCLK_CNTL, tmp);
636 udelay(15000); 636 mdelay(15);
637 637
638 tmp = RREG32_PLL(R300_SCLK_CNTL2); 638 tmp = RREG32_PLL(R300_SCLK_CNTL2);
639 tmp &= ~(R300_SCLK_FORCE_TCL | 639 tmp &= ~(R300_SCLK_FORCE_TCL |
@@ -651,12 +651,12 @@ void radeon_legacy_set_clock_gating(struct radeon_device *rdev, int enable)
651 tmp |= (RADEON_ENGIN_DYNCLK_MODE | 651 tmp |= (RADEON_ENGIN_DYNCLK_MODE |
652 (0x01 << RADEON_ACTIVE_HILO_LAT_SHIFT)); 652 (0x01 << RADEON_ACTIVE_HILO_LAT_SHIFT));
653 WREG32_PLL(RADEON_CLK_PWRMGT_CNTL, tmp); 653 WREG32_PLL(RADEON_CLK_PWRMGT_CNTL, tmp);
654 udelay(15000); 654 mdelay(15);
655 655
656 tmp = RREG32_PLL(RADEON_CLK_PIN_CNTL); 656 tmp = RREG32_PLL(RADEON_CLK_PIN_CNTL);
657 tmp |= RADEON_SCLK_DYN_START_CNTL; 657 tmp |= RADEON_SCLK_DYN_START_CNTL;
658 WREG32_PLL(RADEON_CLK_PIN_CNTL, tmp); 658 WREG32_PLL(RADEON_CLK_PIN_CNTL, tmp);
659 udelay(15000); 659 mdelay(15);
660 660
661 /* When DRI is enabled, setting DYN_STOP_LAT to zero can cause some R200 661 /* When DRI is enabled, setting DYN_STOP_LAT to zero can cause some R200
662 to lockup randomly, leave them as set by BIOS. 662 to lockup randomly, leave them as set by BIOS.
@@ -696,7 +696,7 @@ void radeon_legacy_set_clock_gating(struct radeon_device *rdev, int enable)
696 tmp |= RADEON_SCLK_MORE_FORCEON; 696 tmp |= RADEON_SCLK_MORE_FORCEON;
697 } 697 }
698 WREG32_PLL(RADEON_SCLK_MORE_CNTL, tmp); 698 WREG32_PLL(RADEON_SCLK_MORE_CNTL, tmp);
699 udelay(15000); 699 mdelay(15);
700 } 700 }
701 701
702 /* RV200::A11 A12, RV250::A11 A12 */ 702 /* RV200::A11 A12, RV250::A11 A12 */
@@ -709,7 +709,7 @@ void radeon_legacy_set_clock_gating(struct radeon_device *rdev, int enable)
709 tmp |= RADEON_TCL_BYPASS_DISABLE; 709 tmp |= RADEON_TCL_BYPASS_DISABLE;
710 WREG32_PLL(RADEON_PLL_PWRMGT_CNTL, tmp); 710 WREG32_PLL(RADEON_PLL_PWRMGT_CNTL, tmp);
711 } 711 }
712 udelay(15000); 712 mdelay(15);
713 713
714 /*enable dynamic mode for display clocks (PIXCLK and PIX2CLK) */ 714 /*enable dynamic mode for display clocks (PIXCLK and PIX2CLK) */
715 tmp = RREG32_PLL(RADEON_PIXCLKS_CNTL); 715 tmp = RREG32_PLL(RADEON_PIXCLKS_CNTL);
@@ -722,14 +722,14 @@ void radeon_legacy_set_clock_gating(struct radeon_device *rdev, int enable)
722 RADEON_PIXCLK_TMDS_ALWAYS_ONb); 722 RADEON_PIXCLK_TMDS_ALWAYS_ONb);
723 723
724 WREG32_PLL(RADEON_PIXCLKS_CNTL, tmp); 724 WREG32_PLL(RADEON_PIXCLKS_CNTL, tmp);
725 udelay(15000); 725 mdelay(15);
726 726
727 tmp = RREG32_PLL(RADEON_VCLK_ECP_CNTL); 727 tmp = RREG32_PLL(RADEON_VCLK_ECP_CNTL);
728 tmp |= (RADEON_PIXCLK_ALWAYS_ONb | 728 tmp |= (RADEON_PIXCLK_ALWAYS_ONb |
729 RADEON_PIXCLK_DAC_ALWAYS_ONb); 729 RADEON_PIXCLK_DAC_ALWAYS_ONb);
730 730
731 WREG32_PLL(RADEON_VCLK_ECP_CNTL, tmp); 731 WREG32_PLL(RADEON_VCLK_ECP_CNTL, tmp);
732 udelay(15000); 732 mdelay(15);
733 } 733 }
734 } else { 734 } else {
735 /* Turn everything OFF (ForceON to everything) */ 735 /* Turn everything OFF (ForceON to everything) */
@@ -861,7 +861,7 @@ void radeon_legacy_set_clock_gating(struct radeon_device *rdev, int enable)
861 } 861 }
862 WREG32_PLL(RADEON_SCLK_CNTL, tmp); 862 WREG32_PLL(RADEON_SCLK_CNTL, tmp);
863 863
864 udelay(16000); 864 mdelay(16);
865 865
866 if ((rdev->family == CHIP_R300) || 866 if ((rdev->family == CHIP_R300) ||
867 (rdev->family == CHIP_R350)) { 867 (rdev->family == CHIP_R350)) {
@@ -870,7 +870,7 @@ void radeon_legacy_set_clock_gating(struct radeon_device *rdev, int enable)
870 R300_SCLK_FORCE_GA | 870 R300_SCLK_FORCE_GA |
871 R300_SCLK_FORCE_CBA); 871 R300_SCLK_FORCE_CBA);
872 WREG32_PLL(R300_SCLK_CNTL2, tmp); 872 WREG32_PLL(R300_SCLK_CNTL2, tmp);
873 udelay(16000); 873 mdelay(16);
874 } 874 }
875 875
876 if (rdev->flags & RADEON_IS_IGP) { 876 if (rdev->flags & RADEON_IS_IGP) {
@@ -878,7 +878,7 @@ void radeon_legacy_set_clock_gating(struct radeon_device *rdev, int enable)
878 tmp &= ~(RADEON_FORCEON_MCLKA | 878 tmp &= ~(RADEON_FORCEON_MCLKA |
879 RADEON_FORCEON_YCLKA); 879 RADEON_FORCEON_YCLKA);
880 WREG32_PLL(RADEON_MCLK_CNTL, tmp); 880 WREG32_PLL(RADEON_MCLK_CNTL, tmp);
881 udelay(16000); 881 mdelay(16);
882 } 882 }
883 883
884 if ((rdev->family == CHIP_RV200) || 884 if ((rdev->family == CHIP_RV200) ||
@@ -887,7 +887,7 @@ void radeon_legacy_set_clock_gating(struct radeon_device *rdev, int enable)
887 tmp = RREG32_PLL(RADEON_SCLK_MORE_CNTL); 887 tmp = RREG32_PLL(RADEON_SCLK_MORE_CNTL);
888 tmp |= RADEON_SCLK_MORE_FORCEON; 888 tmp |= RADEON_SCLK_MORE_FORCEON;
889 WREG32_PLL(RADEON_SCLK_MORE_CNTL, tmp); 889 WREG32_PLL(RADEON_SCLK_MORE_CNTL, tmp);
890 udelay(16000); 890 mdelay(16);
891 } 891 }
892 892
893 tmp = RREG32_PLL(RADEON_PIXCLKS_CNTL); 893 tmp = RREG32_PLL(RADEON_PIXCLKS_CNTL);
@@ -900,7 +900,7 @@ void radeon_legacy_set_clock_gating(struct radeon_device *rdev, int enable)
900 RADEON_PIXCLK_TMDS_ALWAYS_ONb); 900 RADEON_PIXCLK_TMDS_ALWAYS_ONb);
901 901
902 WREG32_PLL(RADEON_PIXCLKS_CNTL, tmp); 902 WREG32_PLL(RADEON_PIXCLKS_CNTL, tmp);
903 udelay(16000); 903 mdelay(16);
904 904
905 tmp = RREG32_PLL(RADEON_VCLK_ECP_CNTL); 905 tmp = RREG32_PLL(RADEON_VCLK_ECP_CNTL);
906 tmp &= ~(RADEON_PIXCLK_ALWAYS_ONb | 906 tmp &= ~(RADEON_PIXCLK_ALWAYS_ONb |
diff --git a/drivers/gpu/drm/radeon/radeon_combios.c b/drivers/gpu/drm/radeon/radeon_combios.c
index 81fc100be7e1..2cad9fde92fc 100644
--- a/drivers/gpu/drm/radeon/radeon_combios.c
+++ b/drivers/gpu/drm/radeon/radeon_combios.c
@@ -2845,7 +2845,7 @@ bool radeon_combios_external_tmds_setup(struct drm_encoder *encoder)
2845 case 4: 2845 case 4:
2846 val = RBIOS16(index); 2846 val = RBIOS16(index);
2847 index += 2; 2847 index += 2;
2848 udelay(val * 1000); 2848 mdelay(val);
2849 break; 2849 break;
2850 case 6: 2850 case 6:
2851 slave_addr = id & 0xff; 2851 slave_addr = id & 0xff;
@@ -3044,7 +3044,7 @@ static void combios_parse_pll_table(struct drm_device *dev, uint16_t offset)
3044 udelay(150); 3044 udelay(150);
3045 break; 3045 break;
3046 case 2: 3046 case 2:
3047 udelay(1000); 3047 mdelay(1);
3048 break; 3048 break;
3049 case 3: 3049 case 3:
3050 while (tmp--) { 3050 while (tmp--) {
@@ -3075,13 +3075,13 @@ static void combios_parse_pll_table(struct drm_device *dev, uint16_t offset)
3075 /*mclk_cntl |= 0x00001111;*//* ??? */ 3075 /*mclk_cntl |= 0x00001111;*//* ??? */
3076 WREG32_PLL(RADEON_MCLK_CNTL, 3076 WREG32_PLL(RADEON_MCLK_CNTL,
3077 mclk_cntl); 3077 mclk_cntl);
3078 udelay(10000); 3078 mdelay(10);
3079#endif 3079#endif
3080 WREG32_PLL 3080 WREG32_PLL
3081 (RADEON_CLK_PWRMGT_CNTL, 3081 (RADEON_CLK_PWRMGT_CNTL,
3082 tmp & 3082 tmp &
3083 ~RADEON_CG_NO1_DEBUG_0); 3083 ~RADEON_CG_NO1_DEBUG_0);
3084 udelay(10000); 3084 mdelay(10);
3085 } 3085 }
3086 break; 3086 break;
3087 default: 3087 default:
diff --git a/drivers/gpu/drm/radeon/radeon_connectors.c b/drivers/gpu/drm/radeon/radeon_connectors.c
index bd05156edbdb..3c2e7a000a2a 100644
--- a/drivers/gpu/drm/radeon/radeon_connectors.c
+++ b/drivers/gpu/drm/radeon/radeon_connectors.c
@@ -970,7 +970,7 @@ radeon_dvi_detect(struct drm_connector *connector, bool force)
970 970
971 encoder = obj_to_encoder(obj); 971 encoder = obj_to_encoder(obj);
972 972
973 if (encoder->encoder_type != DRM_MODE_ENCODER_DAC || 973 if (encoder->encoder_type != DRM_MODE_ENCODER_DAC &&
974 encoder->encoder_type != DRM_MODE_ENCODER_TVDAC) 974 encoder->encoder_type != DRM_MODE_ENCODER_TVDAC)
975 continue; 975 continue;
976 976
@@ -1000,6 +1000,7 @@ radeon_dvi_detect(struct drm_connector *connector, bool force)
1000 * cases the DVI port is actually a virtual KVM port connected to the service 1000 * cases the DVI port is actually a virtual KVM port connected to the service
1001 * processor. 1001 * processor.
1002 */ 1002 */
1003out:
1003 if ((!rdev->is_atom_bios) && 1004 if ((!rdev->is_atom_bios) &&
1004 (ret == connector_status_disconnected) && 1005 (ret == connector_status_disconnected) &&
1005 rdev->mode_info.bios_hardcoded_edid_size) { 1006 rdev->mode_info.bios_hardcoded_edid_size) {
@@ -1007,7 +1008,6 @@ radeon_dvi_detect(struct drm_connector *connector, bool force)
1007 ret = connector_status_connected; 1008 ret = connector_status_connected;
1008 } 1009 }
1009 1010
1010out:
1011 /* updated in get modes as well since we need to know if it's analog or digital */ 1011 /* updated in get modes as well since we need to know if it's analog or digital */
1012 radeon_connector_update_scratch_regs(connector, ret); 1012 radeon_connector_update_scratch_regs(connector, ret);
1013 return ret; 1013 return ret;
diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
index ea7df16e2f84..5992502a3448 100644
--- a/drivers/gpu/drm/radeon/radeon_device.c
+++ b/drivers/gpu/drm/radeon/radeon_device.c
@@ -241,8 +241,8 @@ int radeon_wb_init(struct radeon_device *rdev)
241 rdev->wb.use_event = true; 241 rdev->wb.use_event = true;
242 } 242 }
243 } 243 }
244 /* always use writeback/events on NI */ 244 /* always use writeback/events on NI, APUs */
245 if (ASIC_IS_DCE5(rdev)) { 245 if (rdev->family >= CHIP_PALM) {
246 rdev->wb.enabled = true; 246 rdev->wb.enabled = true;
247 rdev->wb.use_event = true; 247 rdev->wb.use_event = true;
248 } 248 }
diff --git a/drivers/gpu/drm/radeon/radeon_display.c b/drivers/gpu/drm/radeon/radeon_display.c
index 8086c96e0b06..0a1d4bd65edc 100644
--- a/drivers/gpu/drm/radeon/radeon_display.c
+++ b/drivers/gpu/drm/radeon/radeon_display.c
@@ -533,7 +533,7 @@ static void radeon_crtc_init(struct drm_device *dev, int index)
533 radeon_legacy_init_crtc(dev, radeon_crtc); 533 radeon_legacy_init_crtc(dev, radeon_crtc);
534} 534}
535 535
536static const char *encoder_names[36] = { 536static const char *encoder_names[37] = {
537 "NONE", 537 "NONE",
538 "INTERNAL_LVDS", 538 "INTERNAL_LVDS",
539 "INTERNAL_TMDS1", 539 "INTERNAL_TMDS1",
@@ -570,6 +570,7 @@ static const char *encoder_names[36] = {
570 "INTERNAL_UNIPHY2", 570 "INTERNAL_UNIPHY2",
571 "NUTMEG", 571 "NUTMEG",
572 "TRAVIS", 572 "TRAVIS",
573 "INTERNAL_VCE"
573}; 574};
574 575
575static const char *connector_names[15] = { 576static const char *connector_names[15] = {
diff --git a/drivers/gpu/drm/radeon/radeon_i2c.c b/drivers/gpu/drm/radeon/radeon_i2c.c
index 85bcfc8923a7..3edec1c198e3 100644
--- a/drivers/gpu/drm/radeon/radeon_i2c.c
+++ b/drivers/gpu/drm/radeon/radeon_i2c.c
@@ -900,6 +900,10 @@ struct radeon_i2c_chan *radeon_i2c_create(struct drm_device *dev,
900 struct radeon_i2c_chan *i2c; 900 struct radeon_i2c_chan *i2c;
901 int ret; 901 int ret;
902 902
903 /* don't add the mm_i2c bus unless hw_i2c is enabled */
904 if (rec->mm_i2c && (radeon_hw_i2c == 0))
905 return NULL;
906
903 i2c = kzalloc(sizeof(struct radeon_i2c_chan), GFP_KERNEL); 907 i2c = kzalloc(sizeof(struct radeon_i2c_chan), GFP_KERNEL);
904 if (i2c == NULL) 908 if (i2c == NULL)
905 return NULL; 909 return NULL;
diff --git a/drivers/gpu/drm/radeon/radeon_irq_kms.c b/drivers/gpu/drm/radeon/radeon_irq_kms.c
index 66d5fe1c8174..65060b77c805 100644
--- a/drivers/gpu/drm/radeon/radeon_irq_kms.c
+++ b/drivers/gpu/drm/radeon/radeon_irq_kms.c
@@ -147,6 +147,12 @@ static bool radeon_msi_ok(struct radeon_device *rdev)
147 (rdev->pdev->subsystem_device == 0x01fd)) 147 (rdev->pdev->subsystem_device == 0x01fd))
148 return true; 148 return true;
149 149
150 /* RV515 seems to have MSI issues where it loses
151 * MSI rearms occasionally. This leads to lockups and freezes.
152 * disable it by default.
153 */
154 if (rdev->family == CHIP_RV515)
155 return false;
150 if (rdev->flags & RADEON_IS_IGP) { 156 if (rdev->flags & RADEON_IS_IGP) {
151 /* APUs work fine with MSIs */ 157 /* APUs work fine with MSIs */
152 if (rdev->family >= CHIP_PALM) 158 if (rdev->family >= CHIP_PALM)
diff --git a/drivers/gpu/drm/radeon/radeon_legacy_encoders.c b/drivers/gpu/drm/radeon/radeon_legacy_encoders.c
index 2f46e0c8df53..42db254f6bb0 100644
--- a/drivers/gpu/drm/radeon/radeon_legacy_encoders.c
+++ b/drivers/gpu/drm/radeon/radeon_legacy_encoders.c
@@ -88,7 +88,7 @@ static void radeon_legacy_lvds_update(struct drm_encoder *encoder, int mode)
88 lvds_pll_cntl = RREG32(RADEON_LVDS_PLL_CNTL); 88 lvds_pll_cntl = RREG32(RADEON_LVDS_PLL_CNTL);
89 lvds_pll_cntl |= RADEON_LVDS_PLL_EN; 89 lvds_pll_cntl |= RADEON_LVDS_PLL_EN;
90 WREG32(RADEON_LVDS_PLL_CNTL, lvds_pll_cntl); 90 WREG32(RADEON_LVDS_PLL_CNTL, lvds_pll_cntl);
91 udelay(1000); 91 mdelay(1);
92 92
93 lvds_pll_cntl = RREG32(RADEON_LVDS_PLL_CNTL); 93 lvds_pll_cntl = RREG32(RADEON_LVDS_PLL_CNTL);
94 lvds_pll_cntl &= ~RADEON_LVDS_PLL_RESET; 94 lvds_pll_cntl &= ~RADEON_LVDS_PLL_RESET;
@@ -101,7 +101,7 @@ static void radeon_legacy_lvds_update(struct drm_encoder *encoder, int mode)
101 (backlight_level << RADEON_LVDS_BL_MOD_LEVEL_SHIFT)); 101 (backlight_level << RADEON_LVDS_BL_MOD_LEVEL_SHIFT));
102 if (is_mac) 102 if (is_mac)
103 lvds_gen_cntl |= RADEON_LVDS_BL_MOD_EN; 103 lvds_gen_cntl |= RADEON_LVDS_BL_MOD_EN;
104 udelay(panel_pwr_delay * 1000); 104 mdelay(panel_pwr_delay);
105 WREG32(RADEON_LVDS_GEN_CNTL, lvds_gen_cntl); 105 WREG32(RADEON_LVDS_GEN_CNTL, lvds_gen_cntl);
106 break; 106 break;
107 case DRM_MODE_DPMS_STANDBY: 107 case DRM_MODE_DPMS_STANDBY:
@@ -118,10 +118,10 @@ static void radeon_legacy_lvds_update(struct drm_encoder *encoder, int mode)
118 WREG32(RADEON_LVDS_GEN_CNTL, lvds_gen_cntl); 118 WREG32(RADEON_LVDS_GEN_CNTL, lvds_gen_cntl);
119 lvds_gen_cntl &= ~(RADEON_LVDS_ON | RADEON_LVDS_BLON | RADEON_LVDS_EN | RADEON_LVDS_DIGON); 119 lvds_gen_cntl &= ~(RADEON_LVDS_ON | RADEON_LVDS_BLON | RADEON_LVDS_EN | RADEON_LVDS_DIGON);
120 } 120 }
121 udelay(panel_pwr_delay * 1000); 121 mdelay(panel_pwr_delay);
122 WREG32(RADEON_LVDS_GEN_CNTL, lvds_gen_cntl); 122 WREG32(RADEON_LVDS_GEN_CNTL, lvds_gen_cntl);
123 WREG32_PLL(RADEON_PIXCLKS_CNTL, pixclks_cntl); 123 WREG32_PLL(RADEON_PIXCLKS_CNTL, pixclks_cntl);
124 udelay(panel_pwr_delay * 1000); 124 mdelay(panel_pwr_delay);
125 break; 125 break;
126 } 126 }
127 127
@@ -656,7 +656,7 @@ static enum drm_connector_status radeon_legacy_primary_dac_detect(struct drm_enc
656 656
657 WREG32(RADEON_DAC_MACRO_CNTL, tmp); 657 WREG32(RADEON_DAC_MACRO_CNTL, tmp);
658 658
659 udelay(2000); 659 mdelay(2);
660 660
661 if (RREG32(RADEON_DAC_CNTL) & RADEON_DAC_CMP_OUTPUT) 661 if (RREG32(RADEON_DAC_CNTL) & RADEON_DAC_CMP_OUTPUT)
662 found = connector_status_connected; 662 found = connector_status_connected;
@@ -1499,7 +1499,7 @@ static enum drm_connector_status radeon_legacy_tv_dac_detect(struct drm_encoder
1499 tmp = dac_cntl2 | RADEON_DAC2_DAC2_CLK_SEL | RADEON_DAC2_CMP_EN; 1499 tmp = dac_cntl2 | RADEON_DAC2_DAC2_CLK_SEL | RADEON_DAC2_CMP_EN;
1500 WREG32(RADEON_DAC_CNTL2, tmp); 1500 WREG32(RADEON_DAC_CNTL2, tmp);
1501 1501
1502 udelay(10000); 1502 mdelay(10);
1503 1503
1504 if (ASIC_IS_R300(rdev)) { 1504 if (ASIC_IS_R300(rdev)) {
1505 if (RREG32(RADEON_DAC_CNTL2) & RADEON_DAC2_CMP_OUT_B) 1505 if (RREG32(RADEON_DAC_CNTL2) & RADEON_DAC2_CMP_OUT_B)
diff --git a/drivers/gpu/drm/radeon/radeon_object.c b/drivers/gpu/drm/radeon/radeon_object.c
index 6f70158d34e4..df6a4dbd93f8 100644
--- a/drivers/gpu/drm/radeon/radeon_object.c
+++ b/drivers/gpu/drm/radeon/radeon_object.c
@@ -241,7 +241,8 @@ int radeon_bo_pin_restricted(struct radeon_bo *bo, u32 domain, u64 max_offset,
241 domain_start = bo->rdev->mc.vram_start; 241 domain_start = bo->rdev->mc.vram_start;
242 else 242 else
243 domain_start = bo->rdev->mc.gtt_start; 243 domain_start = bo->rdev->mc.gtt_start;
244 WARN_ON_ONCE((*gpu_addr - domain_start) > max_offset); 244 WARN_ON_ONCE(max_offset <
245 (radeon_bo_gpu_offset(bo) - domain_start));
245 } 246 }
246 247
247 return 0; 248 return 0;
diff --git a/drivers/gpu/drm/radeon/rv770.c b/drivers/gpu/drm/radeon/rv770.c
index c62ae4be3845..cdab1aeaed6e 100644
--- a/drivers/gpu/drm/radeon/rv770.c
+++ b/drivers/gpu/drm/radeon/rv770.c
@@ -969,7 +969,7 @@ void r700_vram_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc)
969 } 969 }
970 if (rdev->flags & RADEON_IS_AGP) { 970 if (rdev->flags & RADEON_IS_AGP) {
971 size_bf = mc->gtt_start; 971 size_bf = mc->gtt_start;
972 size_af = 0xFFFFFFFF - mc->gtt_end + 1; 972 size_af = 0xFFFFFFFF - mc->gtt_end;
973 if (size_bf > size_af) { 973 if (size_bf > size_af) {
974 if (mc->mc_vram_size > size_bf) { 974 if (mc->mc_vram_size > size_bf) {
975 dev_warn(rdev->dev, "limiting VRAM\n"); 975 dev_warn(rdev->dev, "limiting VRAM\n");
@@ -983,7 +983,7 @@ void r700_vram_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc)
983 mc->real_vram_size = size_af; 983 mc->real_vram_size = size_af;
984 mc->mc_vram_size = size_af; 984 mc->mc_vram_size = size_af;
985 } 985 }
986 mc->vram_start = mc->gtt_end; 986 mc->vram_start = mc->gtt_end + 1;
987 } 987 }
988 mc->vram_end = mc->vram_start + mc->mc_vram_size - 1; 988 mc->vram_end = mc->vram_start + mc->mc_vram_size - 1;
989 dev_info(rdev->dev, "VRAM: %lluM 0x%08llX - 0x%08llX (%lluM used)\n", 989 dev_info(rdev->dev, "VRAM: %lluM 0x%08llX - 0x%08llX (%lluM used)\n",
diff --git a/drivers/gpu/drm/radeon/si.c b/drivers/gpu/drm/radeon/si.c
index ac7a199ffece..27bda986fc2b 100644
--- a/drivers/gpu/drm/radeon/si.c
+++ b/drivers/gpu/drm/radeon/si.c
@@ -2999,8 +2999,8 @@ int si_rlc_init(struct radeon_device *rdev)
2999 } 2999 }
3000 r = radeon_bo_pin(rdev->rlc.save_restore_obj, RADEON_GEM_DOMAIN_VRAM, 3000 r = radeon_bo_pin(rdev->rlc.save_restore_obj, RADEON_GEM_DOMAIN_VRAM,
3001 &rdev->rlc.save_restore_gpu_addr); 3001 &rdev->rlc.save_restore_gpu_addr);
3002 radeon_bo_unreserve(rdev->rlc.save_restore_obj);
3002 if (r) { 3003 if (r) {
3003 radeon_bo_unreserve(rdev->rlc.save_restore_obj);
3004 dev_warn(rdev->dev, "(%d) pin RLC sr bo failed\n", r); 3004 dev_warn(rdev->dev, "(%d) pin RLC sr bo failed\n", r);
3005 si_rlc_fini(rdev); 3005 si_rlc_fini(rdev);
3006 return r; 3006 return r;
@@ -3023,9 +3023,8 @@ int si_rlc_init(struct radeon_device *rdev)
3023 } 3023 }
3024 r = radeon_bo_pin(rdev->rlc.clear_state_obj, RADEON_GEM_DOMAIN_VRAM, 3024 r = radeon_bo_pin(rdev->rlc.clear_state_obj, RADEON_GEM_DOMAIN_VRAM,
3025 &rdev->rlc.clear_state_gpu_addr); 3025 &rdev->rlc.clear_state_gpu_addr);
3026 radeon_bo_unreserve(rdev->rlc.clear_state_obj);
3026 if (r) { 3027 if (r) {
3027
3028 radeon_bo_unreserve(rdev->rlc.clear_state_obj);
3029 dev_warn(rdev->dev, "(%d) pin RLC c bo failed\n", r); 3028 dev_warn(rdev->dev, "(%d) pin RLC c bo failed\n", r);
3030 si_rlc_fini(rdev); 3029 si_rlc_fini(rdev);
3031 return r; 3030 return r;
diff --git a/drivers/gpu/drm/savage/savage_state.c b/drivers/gpu/drm/savage/savage_state.c
index 031aaaf79ac2..b6d8608375cd 100644
--- a/drivers/gpu/drm/savage/savage_state.c
+++ b/drivers/gpu/drm/savage/savage_state.c
@@ -988,7 +988,7 @@ int savage_bci_cmdbuf(struct drm_device *dev, void *data, struct drm_file *file_
988 * for locking on FreeBSD. 988 * for locking on FreeBSD.
989 */ 989 */
990 if (cmdbuf->size) { 990 if (cmdbuf->size) {
991 kcmd_addr = kmalloc(cmdbuf->size * 8, GFP_KERNEL); 991 kcmd_addr = kmalloc_array(cmdbuf->size, 8, GFP_KERNEL);
992 if (kcmd_addr == NULL) 992 if (kcmd_addr == NULL)
993 return -ENOMEM; 993 return -ENOMEM;
994 994
@@ -1015,8 +1015,8 @@ int savage_bci_cmdbuf(struct drm_device *dev, void *data, struct drm_file *file_
1015 cmdbuf->vb_addr = kvb_addr; 1015 cmdbuf->vb_addr = kvb_addr;
1016 } 1016 }
1017 if (cmdbuf->nbox) { 1017 if (cmdbuf->nbox) {
1018 kbox_addr = kmalloc(cmdbuf->nbox * sizeof(struct drm_clip_rect), 1018 kbox_addr = kmalloc_array(cmdbuf->nbox, sizeof(struct drm_clip_rect),
1019 GFP_KERNEL); 1019 GFP_KERNEL);
1020 if (kbox_addr == NULL) { 1020 if (kbox_addr == NULL) {
1021 ret = -ENOMEM; 1021 ret = -ENOMEM;
1022 goto done; 1022 goto done;
diff --git a/drivers/gpu/drm/udl/udl_drv.c b/drivers/gpu/drm/udl/udl_drv.c
index 5340c5f3987b..53673907a6a0 100644
--- a/drivers/gpu/drm/udl/udl_drv.c
+++ b/drivers/gpu/drm/udl/udl_drv.c
@@ -47,7 +47,7 @@ static struct vm_operations_struct udl_gem_vm_ops = {
47static const struct file_operations udl_driver_fops = { 47static const struct file_operations udl_driver_fops = {
48 .owner = THIS_MODULE, 48 .owner = THIS_MODULE,
49 .open = drm_open, 49 .open = drm_open,
50 .mmap = drm_gem_mmap, 50 .mmap = udl_drm_gem_mmap,
51 .poll = drm_poll, 51 .poll = drm_poll,
52 .read = drm_read, 52 .read = drm_read,
53 .unlocked_ioctl = drm_ioctl, 53 .unlocked_ioctl = drm_ioctl,
diff --git a/drivers/gpu/drm/udl/udl_drv.h b/drivers/gpu/drm/udl/udl_drv.h
index 1612954a5bc4..96820d03a303 100644
--- a/drivers/gpu/drm/udl/udl_drv.h
+++ b/drivers/gpu/drm/udl/udl_drv.h
@@ -121,6 +121,7 @@ struct udl_gem_object *udl_gem_alloc_object(struct drm_device *dev,
121 121
122int udl_gem_vmap(struct udl_gem_object *obj); 122int udl_gem_vmap(struct udl_gem_object *obj);
123void udl_gem_vunmap(struct udl_gem_object *obj); 123void udl_gem_vunmap(struct udl_gem_object *obj);
124int udl_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
124int udl_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf); 125int udl_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
125 126
126int udl_handle_damage(struct udl_framebuffer *fb, int x, int y, 127int udl_handle_damage(struct udl_framebuffer *fb, int x, int y,
diff --git a/drivers/gpu/drm/udl/udl_gem.c b/drivers/gpu/drm/udl/udl_gem.c
index 852642dc1187..92f19ef329b0 100644
--- a/drivers/gpu/drm/udl/udl_gem.c
+++ b/drivers/gpu/drm/udl/udl_gem.c
@@ -71,6 +71,20 @@ int udl_dumb_destroy(struct drm_file *file, struct drm_device *dev,
71 return drm_gem_handle_delete(file, handle); 71 return drm_gem_handle_delete(file, handle);
72} 72}
73 73
74int udl_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma)
75{
76 int ret;
77
78 ret = drm_gem_mmap(filp, vma);
79 if (ret)
80 return ret;
81
82 vma->vm_flags &= ~VM_PFNMAP;
83 vma->vm_flags |= VM_MIXEDMAP;
84
85 return ret;
86}
87
74int udl_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf) 88int udl_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
75{ 89{
76 struct udl_gem_object *obj = to_udl_bo(vma->vm_private_data); 90 struct udl_gem_object *obj = to_udl_bo(vma->vm_private_data);
diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
index a3d033252995..ffddcba32af6 100644
--- a/drivers/hid/Kconfig
+++ b/drivers/hid/Kconfig
@@ -34,7 +34,7 @@ config HID
34config HID_BATTERY_STRENGTH 34config HID_BATTERY_STRENGTH
35 bool 35 bool
36 depends on HID && POWER_SUPPLY && HID = POWER_SUPPLY 36 depends on HID && POWER_SUPPLY && HID = POWER_SUPPLY
37 default y 37 default n
38 38
39config HIDRAW 39config HIDRAW
40 bool "/dev/hidraw raw HID device support" 40 bool "/dev/hidraw raw HID device support"
diff --git a/drivers/hid/hid-picolcd.c b/drivers/hid/hid-picolcd.c
index 12f9777c385d..45c3433f7986 100644
--- a/drivers/hid/hid-picolcd.c
+++ b/drivers/hid/hid-picolcd.c
@@ -1525,12 +1525,6 @@ static const struct file_operations picolcd_debug_reset_fops = {
1525/* 1525/*
1526 * The "eeprom" file 1526 * The "eeprom" file
1527 */ 1527 */
1528static int picolcd_debug_eeprom_open(struct inode *i, struct file *f)
1529{
1530 f->private_data = i->i_private;
1531 return 0;
1532}
1533
1534static ssize_t picolcd_debug_eeprom_read(struct file *f, char __user *u, 1528static ssize_t picolcd_debug_eeprom_read(struct file *f, char __user *u,
1535 size_t s, loff_t *off) 1529 size_t s, loff_t *off)
1536{ 1530{
@@ -1618,7 +1612,7 @@ static ssize_t picolcd_debug_eeprom_write(struct file *f, const char __user *u,
1618 */ 1612 */
1619static const struct file_operations picolcd_debug_eeprom_fops = { 1613static const struct file_operations picolcd_debug_eeprom_fops = {
1620 .owner = THIS_MODULE, 1614 .owner = THIS_MODULE,
1621 .open = picolcd_debug_eeprom_open, 1615 .open = simple_open,
1622 .read = picolcd_debug_eeprom_read, 1616 .read = picolcd_debug_eeprom_read,
1623 .write = picolcd_debug_eeprom_write, 1617 .write = picolcd_debug_eeprom_write,
1624 .llseek = generic_file_llseek, 1618 .llseek = generic_file_llseek,
@@ -1627,12 +1621,6 @@ static const struct file_operations picolcd_debug_eeprom_fops = {
1627/* 1621/*
1628 * The "flash" file 1622 * The "flash" file
1629 */ 1623 */
1630static int picolcd_debug_flash_open(struct inode *i, struct file *f)
1631{
1632 f->private_data = i->i_private;
1633 return 0;
1634}
1635
1636/* record a flash address to buf (bounds check to be done by caller) */ 1624/* record a flash address to buf (bounds check to be done by caller) */
1637static int _picolcd_flash_setaddr(struct picolcd_data *data, u8 *buf, long off) 1625static int _picolcd_flash_setaddr(struct picolcd_data *data, u8 *buf, long off)
1638{ 1626{
@@ -1817,7 +1805,7 @@ static ssize_t picolcd_debug_flash_write(struct file *f, const char __user *u,
1817 */ 1805 */
1818static const struct file_operations picolcd_debug_flash_fops = { 1806static const struct file_operations picolcd_debug_flash_fops = {
1819 .owner = THIS_MODULE, 1807 .owner = THIS_MODULE,
1820 .open = picolcd_debug_flash_open, 1808 .open = simple_open,
1821 .read = picolcd_debug_flash_read, 1809 .read = picolcd_debug_flash_read,
1822 .write = picolcd_debug_flash_write, 1810 .write = picolcd_debug_flash_write,
1823 .llseek = generic_file_llseek, 1811 .llseek = generic_file_llseek,
diff --git a/drivers/hid/hid-tivo.c b/drivers/hid/hid-tivo.c
index de47039c708c..9f85f827607f 100644
--- a/drivers/hid/hid-tivo.c
+++ b/drivers/hid/hid-tivo.c
@@ -62,7 +62,7 @@ static int tivo_input_mapping(struct hid_device *hdev, struct hid_input *hi,
62 62
63static const struct hid_device_id tivo_devices[] = { 63static const struct hid_device_id tivo_devices[] = {
64 /* TiVo Slide Bluetooth remote, pairs with a Broadcom dongle */ 64 /* TiVo Slide Bluetooth remote, pairs with a Broadcom dongle */
65 { HID_USB_DEVICE(USB_VENDOR_ID_TIVO, USB_DEVICE_ID_TIVO_SLIDE_BT) }, 65 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_TIVO, USB_DEVICE_ID_TIVO_SLIDE_BT) },
66 { HID_USB_DEVICE(USB_VENDOR_ID_TIVO, USB_DEVICE_ID_TIVO_SLIDE) }, 66 { HID_USB_DEVICE(USB_VENDOR_ID_TIVO, USB_DEVICE_ID_TIVO_SLIDE) },
67 { } 67 { }
68}; 68};
diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
index 17dabc1f339e..eec329197c16 100644
--- a/drivers/hid/hid-wiimote-debug.c
+++ b/drivers/hid/hid-wiimote-debug.c
@@ -23,12 +23,6 @@ struct wiimote_debug {
23 struct dentry *drm; 23 struct dentry *drm;
24}; 24};
25 25
26static int wiidebug_eeprom_open(struct inode *i, struct file *f)
27{
28 f->private_data = i->i_private;
29 return 0;
30}
31
32static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s, 26static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
33 loff_t *off) 27 loff_t *off)
34{ 28{
@@ -83,7 +77,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
83 77
84static const struct file_operations wiidebug_eeprom_fops = { 78static const struct file_operations wiidebug_eeprom_fops = {
85 .owner = THIS_MODULE, 79 .owner = THIS_MODULE,
86 .open = wiidebug_eeprom_open, 80 .open = simple_open,
87 .read = wiidebug_eeprom_read, 81 .read = wiidebug_eeprom_read,
88 .llseek = generic_file_llseek, 82 .llseek = generic_file_llseek,
89}; 83};
diff --git a/drivers/hsi/Kconfig b/drivers/hsi/Kconfig
new file mode 100644
index 000000000000..d94e38dd80c7
--- /dev/null
+++ b/drivers/hsi/Kconfig
@@ -0,0 +1,19 @@
1#
2# HSI driver configuration
3#
4menuconfig HSI
5 tristate "HSI support"
6 ---help---
7 The "High speed synchronous Serial Interface" is
8 synchronous serial interface used mainly to connect
9 application engines and cellular modems.
10
11if HSI
12
13config HSI_BOARDINFO
14 bool
15 default y
16
17source "drivers/hsi/clients/Kconfig"
18
19endif # HSI
diff --git a/drivers/hsi/Makefile b/drivers/hsi/Makefile
new file mode 100644
index 000000000000..9d5d33f90de2
--- /dev/null
+++ b/drivers/hsi/Makefile
@@ -0,0 +1,6 @@
1#
2# Makefile for HSI
3#
4obj-$(CONFIG_HSI_BOARDINFO) += hsi_boardinfo.o
5obj-$(CONFIG_HSI) += hsi.o
6obj-y += clients/
diff --git a/drivers/hsi/clients/Kconfig b/drivers/hsi/clients/Kconfig
new file mode 100644
index 000000000000..3bacd275f479
--- /dev/null
+++ b/drivers/hsi/clients/Kconfig
@@ -0,0 +1,13 @@
1#
2# HSI clients configuration
3#
4
5comment "HSI clients"
6
7config HSI_CHAR
8 tristate "HSI/SSI character driver"
9 depends on HSI
10 ---help---
11 If you say Y here, you will enable the HSI/SSI character driver.
12 This driver provides a simple character device interface for
13 serial communication with the cellular modem over HSI/SSI bus.
diff --git a/drivers/hsi/clients/Makefile b/drivers/hsi/clients/Makefile
new file mode 100644
index 000000000000..327c0e27c8b0
--- /dev/null
+++ b/drivers/hsi/clients/Makefile
@@ -0,0 +1,5 @@
1#
2# Makefile for HSI clients
3#
4
5obj-$(CONFIG_HSI_CHAR) += hsi_char.o
diff --git a/drivers/hsi/clients/hsi_char.c b/drivers/hsi/clients/hsi_char.c
new file mode 100644
index 000000000000..3ad91f6447d8
--- /dev/null
+++ b/drivers/hsi/clients/hsi_char.c
@@ -0,0 +1,802 @@
1/*
2 * HSI character device driver, implements the character device
3 * interface.
4 *
5 * Copyright (C) 2010 Nokia Corporation. All rights reserved.
6 *
7 * Contact: Andras Domokos <andras.domokos@nokia.com>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * version 2 as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 */
23
24#include <linux/errno.h>
25#include <linux/types.h>
26#include <linux/atomic.h>
27#include <linux/kernel.h>
28#include <linux/init.h>
29#include <linux/module.h>
30#include <linux/mutex.h>
31#include <linux/list.h>
32#include <linux/slab.h>
33#include <linux/kmemleak.h>
34#include <linux/ioctl.h>
35#include <linux/wait.h>
36#include <linux/fs.h>
37#include <linux/sched.h>
38#include <linux/device.h>
39#include <linux/cdev.h>
40#include <linux/uaccess.h>
41#include <linux/scatterlist.h>
42#include <linux/stat.h>
43#include <linux/hsi/hsi.h>
44#include <linux/hsi/hsi_char.h>
45
46#define HSC_DEVS 16 /* Num of channels */
47#define HSC_MSGS 4
48
49#define HSC_RXBREAK 0
50
51#define HSC_ID_BITS 6
52#define HSC_PORT_ID_BITS 4
53#define HSC_ID_MASK 3
54#define HSC_PORT_ID_MASK 3
55#define HSC_CH_MASK 0xf
56
57/*
58 * We support up to 4 controllers that can have up to 4
59 * ports, which should currently be more than enough.
60 */
61#define HSC_BASEMINOR(id, port_id) \
62 ((((id) & HSC_ID_MASK) << HSC_ID_BITS) | \
63 (((port_id) & HSC_PORT_ID_MASK) << HSC_PORT_ID_BITS))
64
65enum {
66 HSC_CH_OPEN,
67 HSC_CH_READ,
68 HSC_CH_WRITE,
69 HSC_CH_WLINE,
70};
71
72enum {
73 HSC_RX,
74 HSC_TX,
75};
76
77struct hsc_client_data;
78/**
79 * struct hsc_channel - hsi_char internal channel data
80 * @ch: channel number
81 * @flags: Keeps state of the channel (open/close, reading, writing)
82 * @free_msgs_list: List of free HSI messages/requests
83 * @rx_msgs_queue: List of pending RX requests
84 * @tx_msgs_queue: List of pending TX requests
85 * @lock: Serialize access to the lists
86 * @cl: reference to the associated hsi_client
87 * @cl_data: reference to the client data that this channels belongs to
88 * @rx_wait: RX requests wait queue
89 * @tx_wait: TX requests wait queue
90 */
91struct hsc_channel {
92 unsigned int ch;
93 unsigned long flags;
94 struct list_head free_msgs_list;
95 struct list_head rx_msgs_queue;
96 struct list_head tx_msgs_queue;
97 spinlock_t lock;
98 struct hsi_client *cl;
99 struct hsc_client_data *cl_data;
100 wait_queue_head_t rx_wait;
101 wait_queue_head_t tx_wait;
102};
103
104/**
105 * struct hsc_client_data - hsi_char internal client data
106 * @cdev: Characther device associated to the hsi_client
107 * @lock: Lock to serialize open/close access
108 * @flags: Keeps track of port state (rx hwbreak armed)
109 * @usecnt: Use count for claiming the HSI port (mutex protected)
110 * @cl: Referece to the HSI client
111 * @channels: Array of channels accessible by the client
112 */
113struct hsc_client_data {
114 struct cdev cdev;
115 struct mutex lock;
116 unsigned long flags;
117 unsigned int usecnt;
118 struct hsi_client *cl;
119 struct hsc_channel channels[HSC_DEVS];
120};
121
122/* Stores the major number dynamically allocated for hsi_char */
123static unsigned int hsc_major;
124/* Maximum buffer size that hsi_char will accept from userspace */
125static unsigned int max_data_size = 0x1000;
126module_param(max_data_size, uint, 0);
127MODULE_PARM_DESC(max_data_size, "max read/write data size [4,8..65536] (^2)");
128
129static void hsc_add_tail(struct hsc_channel *channel, struct hsi_msg *msg,
130 struct list_head *queue)
131{
132 unsigned long flags;
133
134 spin_lock_irqsave(&channel->lock, flags);
135 list_add_tail(&msg->link, queue);
136 spin_unlock_irqrestore(&channel->lock, flags);
137}
138
139static struct hsi_msg *hsc_get_first_msg(struct hsc_channel *channel,
140 struct list_head *queue)
141{
142 struct hsi_msg *msg = NULL;
143 unsigned long flags;
144
145 spin_lock_irqsave(&channel->lock, flags);
146
147 if (list_empty(queue))
148 goto out;
149
150 msg = list_first_entry(queue, struct hsi_msg, link);
151 list_del(&msg->link);
152out:
153 spin_unlock_irqrestore(&channel->lock, flags);
154
155 return msg;
156}
157
158static inline void hsc_msg_free(struct hsi_msg *msg)
159{
160 kfree(sg_virt(msg->sgt.sgl));
161 hsi_free_msg(msg);
162}
163
164static void hsc_free_list(struct list_head *list)
165{
166 struct hsi_msg *msg, *tmp;
167
168 list_for_each_entry_safe(msg, tmp, list, link) {
169 list_del(&msg->link);
170 hsc_msg_free(msg);
171 }
172}
173
174static void hsc_reset_list(struct hsc_channel *channel, struct list_head *l)
175{
176 unsigned long flags;
177 LIST_HEAD(list);
178
179 spin_lock_irqsave(&channel->lock, flags);
180 list_splice_init(l, &list);
181 spin_unlock_irqrestore(&channel->lock, flags);
182
183 hsc_free_list(&list);
184}
185
186static inline struct hsi_msg *hsc_msg_alloc(unsigned int alloc_size)
187{
188 struct hsi_msg *msg;
189 void *buf;
190
191 msg = hsi_alloc_msg(1, GFP_KERNEL);
192 if (!msg)
193 goto out;
194 buf = kmalloc(alloc_size, GFP_KERNEL);
195 if (!buf) {
196 hsi_free_msg(msg);
197 goto out;
198 }
199 sg_init_one(msg->sgt.sgl, buf, alloc_size);
200 /* Ignore false positive, due to sg pointer handling */
201 kmemleak_ignore(buf);
202
203 return msg;
204out:
205 return NULL;
206}
207
208static inline int hsc_msgs_alloc(struct hsc_channel *channel)
209{
210 struct hsi_msg *msg;
211 int i;
212
213 for (i = 0; i < HSC_MSGS; i++) {
214 msg = hsc_msg_alloc(max_data_size);
215 if (!msg)
216 goto out;
217 msg->channel = channel->ch;
218 list_add_tail(&msg->link, &channel->free_msgs_list);
219 }
220
221 return 0;
222out:
223 hsc_free_list(&channel->free_msgs_list);
224
225 return -ENOMEM;
226}
227
228static inline unsigned int hsc_msg_len_get(struct hsi_msg *msg)
229{
230 return msg->sgt.sgl->length;
231}
232
233static inline void hsc_msg_len_set(struct hsi_msg *msg, unsigned int len)
234{
235 msg->sgt.sgl->length = len;
236}
237
238static void hsc_rx_completed(struct hsi_msg *msg)
239{
240 struct hsc_client_data *cl_data = hsi_client_drvdata(msg->cl);
241 struct hsc_channel *channel = cl_data->channels + msg->channel;
242
243 if (test_bit(HSC_CH_READ, &channel->flags)) {
244 hsc_add_tail(channel, msg, &channel->rx_msgs_queue);
245 wake_up(&channel->rx_wait);
246 } else {
247 hsc_add_tail(channel, msg, &channel->free_msgs_list);
248 }
249}
250
251static void hsc_rx_msg_destructor(struct hsi_msg *msg)
252{
253 msg->status = HSI_STATUS_ERROR;
254 hsc_msg_len_set(msg, 0);
255 hsc_rx_completed(msg);
256}
257
258static void hsc_tx_completed(struct hsi_msg *msg)
259{
260 struct hsc_client_data *cl_data = hsi_client_drvdata(msg->cl);
261 struct hsc_channel *channel = cl_data->channels + msg->channel;
262
263 if (test_bit(HSC_CH_WRITE, &channel->flags)) {
264 hsc_add_tail(channel, msg, &channel->tx_msgs_queue);
265 wake_up(&channel->tx_wait);
266 } else {
267 hsc_add_tail(channel, msg, &channel->free_msgs_list);
268 }
269}
270
271static void hsc_tx_msg_destructor(struct hsi_msg *msg)
272{
273 msg->status = HSI_STATUS_ERROR;
274 hsc_msg_len_set(msg, 0);
275 hsc_tx_completed(msg);
276}
277
278static void hsc_break_req_destructor(struct hsi_msg *msg)
279{
280 struct hsc_client_data *cl_data = hsi_client_drvdata(msg->cl);
281
282 hsi_free_msg(msg);
283 clear_bit(HSC_RXBREAK, &cl_data->flags);
284}
285
286static void hsc_break_received(struct hsi_msg *msg)
287{
288 struct hsc_client_data *cl_data = hsi_client_drvdata(msg->cl);
289 struct hsc_channel *channel = cl_data->channels;
290 int i, ret;
291
292 /* Broadcast HWBREAK on all channels */
293 for (i = 0; i < HSC_DEVS; i++, channel++) {
294 struct hsi_msg *msg2;
295
296 if (!test_bit(HSC_CH_READ, &channel->flags))
297 continue;
298 msg2 = hsc_get_first_msg(channel, &channel->free_msgs_list);
299 if (!msg2)
300 continue;
301 clear_bit(HSC_CH_READ, &channel->flags);
302 hsc_msg_len_set(msg2, 0);
303 msg2->status = HSI_STATUS_COMPLETED;
304 hsc_add_tail(channel, msg2, &channel->rx_msgs_queue);
305 wake_up(&channel->rx_wait);
306 }
307 hsi_flush(msg->cl);
308 ret = hsi_async_read(msg->cl, msg);
309 if (ret < 0)
310 hsc_break_req_destructor(msg);
311}
312
313static int hsc_break_request(struct hsi_client *cl)
314{
315 struct hsc_client_data *cl_data = hsi_client_drvdata(cl);
316 struct hsi_msg *msg;
317 int ret;
318
319 if (test_and_set_bit(HSC_RXBREAK, &cl_data->flags))
320 return -EBUSY;
321
322 msg = hsi_alloc_msg(0, GFP_KERNEL);
323 if (!msg) {
324 clear_bit(HSC_RXBREAK, &cl_data->flags);
325 return -ENOMEM;
326 }
327 msg->break_frame = 1;
328 msg->complete = hsc_break_received;
329 msg->destructor = hsc_break_req_destructor;
330 ret = hsi_async_read(cl, msg);
331 if (ret < 0)
332 hsc_break_req_destructor(msg);
333
334 return ret;
335}
336
337static int hsc_break_send(struct hsi_client *cl)
338{
339 struct hsi_msg *msg;
340 int ret;
341
342 msg = hsi_alloc_msg(0, GFP_ATOMIC);
343 if (!msg)
344 return -ENOMEM;
345 msg->break_frame = 1;
346 msg->complete = hsi_free_msg;
347 msg->destructor = hsi_free_msg;
348 ret = hsi_async_write(cl, msg);
349 if (ret < 0)
350 hsi_free_msg(msg);
351
352 return ret;
353}
354
355static int hsc_rx_set(struct hsi_client *cl, struct hsc_rx_config *rxc)
356{
357 struct hsi_config tmp;
358 int ret;
359
360 if ((rxc->mode != HSI_MODE_STREAM) && (rxc->mode != HSI_MODE_FRAME))
361 return -EINVAL;
362 if ((rxc->channels == 0) || (rxc->channels > HSC_DEVS))
363 return -EINVAL;
364 if (rxc->channels & (rxc->channels - 1))
365 return -EINVAL;
366 if ((rxc->flow != HSI_FLOW_SYNC) && (rxc->flow != HSI_FLOW_PIPE))
367 return -EINVAL;
368 tmp = cl->rx_cfg;
369 cl->rx_cfg.mode = rxc->mode;
370 cl->rx_cfg.channels = rxc->channels;
371 cl->rx_cfg.flow = rxc->flow;
372 ret = hsi_setup(cl);
373 if (ret < 0) {
374 cl->rx_cfg = tmp;
375 return ret;
376 }
377 if (rxc->mode == HSI_MODE_FRAME)
378 hsc_break_request(cl);
379
380 return ret;
381}
382
383static inline void hsc_rx_get(struct hsi_client *cl, struct hsc_rx_config *rxc)
384{
385 rxc->mode = cl->rx_cfg.mode;
386 rxc->channels = cl->rx_cfg.channels;
387 rxc->flow = cl->rx_cfg.flow;
388}
389
390static int hsc_tx_set(struct hsi_client *cl, struct hsc_tx_config *txc)
391{
392 struct hsi_config tmp;
393 int ret;
394
395 if ((txc->mode != HSI_MODE_STREAM) && (txc->mode != HSI_MODE_FRAME))
396 return -EINVAL;
397 if ((txc->channels == 0) || (txc->channels > HSC_DEVS))
398 return -EINVAL;
399 if (txc->channels & (txc->channels - 1))
400 return -EINVAL;
401 if ((txc->arb_mode != HSI_ARB_RR) && (txc->arb_mode != HSI_ARB_PRIO))
402 return -EINVAL;
403 tmp = cl->tx_cfg;
404 cl->tx_cfg.mode = txc->mode;
405 cl->tx_cfg.channels = txc->channels;
406 cl->tx_cfg.speed = txc->speed;
407 cl->tx_cfg.arb_mode = txc->arb_mode;
408 ret = hsi_setup(cl);
409 if (ret < 0) {
410 cl->tx_cfg = tmp;
411 return ret;
412 }
413
414 return ret;
415}
416
417static inline void hsc_tx_get(struct hsi_client *cl, struct hsc_tx_config *txc)
418{
419 txc->mode = cl->tx_cfg.mode;
420 txc->channels = cl->tx_cfg.channels;
421 txc->speed = cl->tx_cfg.speed;
422 txc->arb_mode = cl->tx_cfg.arb_mode;
423}
424
425static ssize_t hsc_read(struct file *file, char __user *buf, size_t len,
426 loff_t *ppos __maybe_unused)
427{
428 struct hsc_channel *channel = file->private_data;
429 struct hsi_msg *msg;
430 ssize_t ret;
431
432 if (len == 0)
433 return 0;
434 if (!IS_ALIGNED(len, sizeof(u32)))
435 return -EINVAL;
436 if (len > max_data_size)
437 len = max_data_size;
438 if (channel->ch >= channel->cl->rx_cfg.channels)
439 return -ECHRNG;
440 if (test_and_set_bit(HSC_CH_READ, &channel->flags))
441 return -EBUSY;
442 msg = hsc_get_first_msg(channel, &channel->free_msgs_list);
443 if (!msg) {
444 ret = -ENOSPC;
445 goto out;
446 }
447 hsc_msg_len_set(msg, len);
448 msg->complete = hsc_rx_completed;
449 msg->destructor = hsc_rx_msg_destructor;
450 ret = hsi_async_read(channel->cl, msg);
451 if (ret < 0) {
452 hsc_add_tail(channel, msg, &channel->free_msgs_list);
453 goto out;
454 }
455
456 ret = wait_event_interruptible(channel->rx_wait,
457 !list_empty(&channel->rx_msgs_queue));
458 if (ret < 0) {
459 clear_bit(HSC_CH_READ, &channel->flags);
460 hsi_flush(channel->cl);
461 return -EINTR;
462 }
463
464 msg = hsc_get_first_msg(channel, &channel->rx_msgs_queue);
465 if (msg) {
466 if (msg->status != HSI_STATUS_ERROR) {
467 ret = copy_to_user((void __user *)buf,
468 sg_virt(msg->sgt.sgl), hsc_msg_len_get(msg));
469 if (ret)
470 ret = -EFAULT;
471 else
472 ret = hsc_msg_len_get(msg);
473 } else {
474 ret = -EIO;
475 }
476 hsc_add_tail(channel, msg, &channel->free_msgs_list);
477 }
478out:
479 clear_bit(HSC_CH_READ, &channel->flags);
480
481 return ret;
482}
483
484static ssize_t hsc_write(struct file *file, const char __user *buf, size_t len,
485 loff_t *ppos __maybe_unused)
486{
487 struct hsc_channel *channel = file->private_data;
488 struct hsi_msg *msg;
489 ssize_t ret;
490
491 if ((len == 0) || !IS_ALIGNED(len, sizeof(u32)))
492 return -EINVAL;
493 if (len > max_data_size)
494 len = max_data_size;
495 if (channel->ch >= channel->cl->tx_cfg.channels)
496 return -ECHRNG;
497 if (test_and_set_bit(HSC_CH_WRITE, &channel->flags))
498 return -EBUSY;
499 msg = hsc_get_first_msg(channel, &channel->free_msgs_list);
500 if (!msg) {
501 clear_bit(HSC_CH_WRITE, &channel->flags);
502 return -ENOSPC;
503 }
504 if (copy_from_user(sg_virt(msg->sgt.sgl), (void __user *)buf, len)) {
505 ret = -EFAULT;
506 goto out;
507 }
508 hsc_msg_len_set(msg, len);
509 msg->complete = hsc_tx_completed;
510 msg->destructor = hsc_tx_msg_destructor;
511 ret = hsi_async_write(channel->cl, msg);
512 if (ret < 0)
513 goto out;
514
515 ret = wait_event_interruptible(channel->tx_wait,
516 !list_empty(&channel->tx_msgs_queue));
517 if (ret < 0) {
518 clear_bit(HSC_CH_WRITE, &channel->flags);
519 hsi_flush(channel->cl);
520 return -EINTR;
521 }
522
523 msg = hsc_get_first_msg(channel, &channel->tx_msgs_queue);
524 if (msg) {
525 if (msg->status == HSI_STATUS_ERROR)
526 ret = -EIO;
527 else
528 ret = hsc_msg_len_get(msg);
529
530 hsc_add_tail(channel, msg, &channel->free_msgs_list);
531 }
532out:
533 clear_bit(HSC_CH_WRITE, &channel->flags);
534
535 return ret;
536}
537
538static long hsc_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
539{
540 struct hsc_channel *channel = file->private_data;
541 unsigned int state;
542 struct hsc_rx_config rxc;
543 struct hsc_tx_config txc;
544 long ret = 0;
545
546 switch (cmd) {
547 case HSC_RESET:
548 hsi_flush(channel->cl);
549 break;
550 case HSC_SET_PM:
551 if (copy_from_user(&state, (void __user *)arg, sizeof(state)))
552 return -EFAULT;
553 if (state == HSC_PM_DISABLE) {
554 if (test_and_set_bit(HSC_CH_WLINE, &channel->flags))
555 return -EINVAL;
556 ret = hsi_start_tx(channel->cl);
557 } else if (state == HSC_PM_ENABLE) {
558 if (!test_and_clear_bit(HSC_CH_WLINE, &channel->flags))
559 return -EINVAL;
560 ret = hsi_stop_tx(channel->cl);
561 } else {
562 ret = -EINVAL;
563 }
564 break;
565 case HSC_SEND_BREAK:
566 return hsc_break_send(channel->cl);
567 case HSC_SET_RX:
568 if (copy_from_user(&rxc, (void __user *)arg, sizeof(rxc)))
569 return -EFAULT;
570 return hsc_rx_set(channel->cl, &rxc);
571 case HSC_GET_RX:
572 hsc_rx_get(channel->cl, &rxc);
573 if (copy_to_user((void __user *)arg, &rxc, sizeof(rxc)))
574 return -EFAULT;
575 break;
576 case HSC_SET_TX:
577 if (copy_from_user(&txc, (void __user *)arg, sizeof(txc)))
578 return -EFAULT;
579 return hsc_tx_set(channel->cl, &txc);
580 case HSC_GET_TX:
581 hsc_tx_get(channel->cl, &txc);
582 if (copy_to_user((void __user *)arg, &txc, sizeof(txc)))
583 return -EFAULT;
584 break;
585 default:
586 return -ENOIOCTLCMD;
587 }
588
589 return ret;
590}
591
592static inline void __hsc_port_release(struct hsc_client_data *cl_data)
593{
594 BUG_ON(cl_data->usecnt == 0);
595
596 if (--cl_data->usecnt == 0) {
597 hsi_flush(cl_data->cl);
598 hsi_release_port(cl_data->cl);
599 }
600}
601
602static int hsc_open(struct inode *inode, struct file *file)
603{
604 struct hsc_client_data *cl_data;
605 struct hsc_channel *channel;
606 int ret = 0;
607
608 pr_debug("open, minor = %d\n", iminor(inode));
609
610 cl_data = container_of(inode->i_cdev, struct hsc_client_data, cdev);
611 mutex_lock(&cl_data->lock);
612 channel = cl_data->channels + (iminor(inode) & HSC_CH_MASK);
613
614 if (test_and_set_bit(HSC_CH_OPEN, &channel->flags)) {
615 ret = -EBUSY;
616 goto out;
617 }
618 /*
619 * Check if we have already claimed the port associated to the HSI
620 * client. If not then try to claim it, else increase its refcount
621 */
622 if (cl_data->usecnt == 0) {
623 ret = hsi_claim_port(cl_data->cl, 0);
624 if (ret < 0)
625 goto out;
626 hsi_setup(cl_data->cl);
627 }
628 cl_data->usecnt++;
629
630 ret = hsc_msgs_alloc(channel);
631 if (ret < 0) {
632 __hsc_port_release(cl_data);
633 goto out;
634 }
635
636 file->private_data = channel;
637 mutex_unlock(&cl_data->lock);
638
639 return ret;
640out:
641 mutex_unlock(&cl_data->lock);
642
643 return ret;
644}
645
646static int hsc_release(struct inode *inode __maybe_unused, struct file *file)
647{
648 struct hsc_channel *channel = file->private_data;
649 struct hsc_client_data *cl_data = channel->cl_data;
650
651 mutex_lock(&cl_data->lock);
652 file->private_data = NULL;
653 if (test_and_clear_bit(HSC_CH_WLINE, &channel->flags))
654 hsi_stop_tx(channel->cl);
655 __hsc_port_release(cl_data);
656 hsc_reset_list(channel, &channel->rx_msgs_queue);
657 hsc_reset_list(channel, &channel->tx_msgs_queue);
658 hsc_reset_list(channel, &channel->free_msgs_list);
659 clear_bit(HSC_CH_READ, &channel->flags);
660 clear_bit(HSC_CH_WRITE, &channel->flags);
661 clear_bit(HSC_CH_OPEN, &channel->flags);
662 wake_up(&channel->rx_wait);
663 wake_up(&channel->tx_wait);
664 mutex_unlock(&cl_data->lock);
665
666 return 0;
667}
668
669static const struct file_operations hsc_fops = {
670 .owner = THIS_MODULE,
671 .read = hsc_read,
672 .write = hsc_write,
673 .unlocked_ioctl = hsc_ioctl,
674 .open = hsc_open,
675 .release = hsc_release,
676};
677
678static void __devinit hsc_channel_init(struct hsc_channel *channel)
679{
680 init_waitqueue_head(&channel->rx_wait);
681 init_waitqueue_head(&channel->tx_wait);
682 spin_lock_init(&channel->lock);
683 INIT_LIST_HEAD(&channel->free_msgs_list);
684 INIT_LIST_HEAD(&channel->rx_msgs_queue);
685 INIT_LIST_HEAD(&channel->tx_msgs_queue);
686}
687
688static int __devinit hsc_probe(struct device *dev)
689{
690 const char devname[] = "hsi_char";
691 struct hsc_client_data *cl_data;
692 struct hsc_channel *channel;
693 struct hsi_client *cl = to_hsi_client(dev);
694 unsigned int hsc_baseminor;
695 dev_t hsc_dev;
696 int ret;
697 int i;
698
699 cl_data = kzalloc(sizeof(*cl_data), GFP_KERNEL);
700 if (!cl_data) {
701 dev_err(dev, "Could not allocate hsc_client_data\n");
702 return -ENOMEM;
703 }
704 hsc_baseminor = HSC_BASEMINOR(hsi_id(cl), hsi_port_id(cl));
705 if (!hsc_major) {
706 ret = alloc_chrdev_region(&hsc_dev, hsc_baseminor,
707 HSC_DEVS, devname);
708 if (ret > 0)
709 hsc_major = MAJOR(hsc_dev);
710 } else {
711 hsc_dev = MKDEV(hsc_major, hsc_baseminor);
712 ret = register_chrdev_region(hsc_dev, HSC_DEVS, devname);
713 }
714 if (ret < 0) {
715 dev_err(dev, "Device %s allocation failed %d\n",
716 hsc_major ? "minor" : "major", ret);
717 goto out1;
718 }
719 mutex_init(&cl_data->lock);
720 hsi_client_set_drvdata(cl, cl_data);
721 cdev_init(&cl_data->cdev, &hsc_fops);
722 cl_data->cdev.owner = THIS_MODULE;
723 cl_data->cl = cl;
724 for (i = 0, channel = cl_data->channels; i < HSC_DEVS; i++, channel++) {
725 hsc_channel_init(channel);
726 channel->ch = i;
727 channel->cl = cl;
728 channel->cl_data = cl_data;
729 }
730
731 /* 1 hsi client -> N char devices (one for each channel) */
732 ret = cdev_add(&cl_data->cdev, hsc_dev, HSC_DEVS);
733 if (ret) {
734 dev_err(dev, "Could not add char device %d\n", ret);
735 goto out2;
736 }
737
738 return 0;
739out2:
740 unregister_chrdev_region(hsc_dev, HSC_DEVS);
741out1:
742 kfree(cl_data);
743
744 return ret;
745}
746
747static int __devexit hsc_remove(struct device *dev)
748{
749 struct hsi_client *cl = to_hsi_client(dev);
750 struct hsc_client_data *cl_data = hsi_client_drvdata(cl);
751 dev_t hsc_dev = cl_data->cdev.dev;
752
753 cdev_del(&cl_data->cdev);
754 unregister_chrdev_region(hsc_dev, HSC_DEVS);
755 hsi_client_set_drvdata(cl, NULL);
756 kfree(cl_data);
757
758 return 0;
759}
760
761static struct hsi_client_driver hsc_driver = {
762 .driver = {
763 .name = "hsi_char",
764 .owner = THIS_MODULE,
765 .probe = hsc_probe,
766 .remove = __devexit_p(hsc_remove),
767 },
768};
769
770static int __init hsc_init(void)
771{
772 int ret;
773
774 if ((max_data_size < 4) || (max_data_size > 0x10000) ||
775 (max_data_size & (max_data_size - 1))) {
776 pr_err("Invalid max read/write data size");
777 return -EINVAL;
778 }
779
780 ret = hsi_register_client_driver(&hsc_driver);
781 if (ret) {
782 pr_err("Error while registering HSI/SSI driver %d", ret);
783 return ret;
784 }
785
786 pr_info("HSI/SSI char device loaded\n");
787
788 return 0;
789}
790module_init(hsc_init);
791
792static void __exit hsc_exit(void)
793{
794 hsi_unregister_client_driver(&hsc_driver);
795 pr_info("HSI char device removed\n");
796}
797module_exit(hsc_exit);
798
799MODULE_AUTHOR("Andras Domokos <andras.domokos@nokia.com>");
800MODULE_ALIAS("hsi:hsi_char");
801MODULE_DESCRIPTION("HSI character device");
802MODULE_LICENSE("GPL v2");
diff --git a/drivers/hsi/hsi.c b/drivers/hsi/hsi.c
new file mode 100644
index 000000000000..2d58f939d27f
--- /dev/null
+++ b/drivers/hsi/hsi.c
@@ -0,0 +1,507 @@
1/*
2 * HSI core.
3 *
4 * Copyright (C) 2010 Nokia Corporation. All rights reserved.
5 *
6 * Contact: Carlos Chinea <carlos.chinea@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 */
22#include <linux/hsi/hsi.h>
23#include <linux/compiler.h>
24#include <linux/list.h>
25#include <linux/kobject.h>
26#include <linux/slab.h>
27#include <linux/string.h>
28#include <linux/notifier.h>
29#include "hsi_core.h"
30
31static ssize_t modalias_show(struct device *dev,
32 struct device_attribute *a __maybe_unused, char *buf)
33{
34 return sprintf(buf, "hsi:%s\n", dev_name(dev));
35}
36
37static struct device_attribute hsi_bus_dev_attrs[] = {
38 __ATTR_RO(modalias),
39 __ATTR_NULL,
40};
41
42static int hsi_bus_uevent(struct device *dev, struct kobj_uevent_env *env)
43{
44 add_uevent_var(env, "MODALIAS=hsi:%s", dev_name(dev));
45
46 return 0;
47}
48
49static int hsi_bus_match(struct device *dev, struct device_driver *driver)
50{
51 return strcmp(dev_name(dev), driver->name) == 0;
52}
53
54static struct bus_type hsi_bus_type = {
55 .name = "hsi",
56 .dev_attrs = hsi_bus_dev_attrs,
57 .match = hsi_bus_match,
58 .uevent = hsi_bus_uevent,
59};
60
61static void hsi_client_release(struct device *dev)
62{
63 kfree(to_hsi_client(dev));
64}
65
66static void hsi_new_client(struct hsi_port *port, struct hsi_board_info *info)
67{
68 struct hsi_client *cl;
69
70 cl = kzalloc(sizeof(*cl), GFP_KERNEL);
71 if (!cl)
72 return;
73 cl->tx_cfg = info->tx_cfg;
74 cl->rx_cfg = info->rx_cfg;
75 cl->device.bus = &hsi_bus_type;
76 cl->device.parent = &port->device;
77 cl->device.release = hsi_client_release;
78 dev_set_name(&cl->device, info->name);
79 cl->device.platform_data = info->platform_data;
80 if (info->archdata)
81 cl->device.archdata = *info->archdata;
82 if (device_register(&cl->device) < 0) {
83 pr_err("hsi: failed to register client: %s\n", info->name);
84 put_device(&cl->device);
85 }
86}
87
88static void hsi_scan_board_info(struct hsi_controller *hsi)
89{
90 struct hsi_cl_info *cl_info;
91 struct hsi_port *p;
92
93 list_for_each_entry(cl_info, &hsi_board_list, list)
94 if (cl_info->info.hsi_id == hsi->id) {
95 p = hsi_find_port_num(hsi, cl_info->info.port);
96 if (!p)
97 continue;
98 hsi_new_client(p, &cl_info->info);
99 }
100}
101
102static int hsi_remove_client(struct device *dev, void *data __maybe_unused)
103{
104 device_unregister(dev);
105
106 return 0;
107}
108
109static int hsi_remove_port(struct device *dev, void *data __maybe_unused)
110{
111 device_for_each_child(dev, NULL, hsi_remove_client);
112 device_unregister(dev);
113
114 return 0;
115}
116
117static void hsi_controller_release(struct device *dev)
118{
119 struct hsi_controller *hsi = to_hsi_controller(dev);
120
121 kfree(hsi->port);
122 kfree(hsi);
123}
124
125static void hsi_port_release(struct device *dev)
126{
127 kfree(to_hsi_port(dev));
128}
129
130/**
131 * hsi_unregister_controller - Unregister an HSI controller
132 * @hsi: The HSI controller to register
133 */
134void hsi_unregister_controller(struct hsi_controller *hsi)
135{
136 device_for_each_child(&hsi->device, NULL, hsi_remove_port);
137 device_unregister(&hsi->device);
138}
139EXPORT_SYMBOL_GPL(hsi_unregister_controller);
140
141/**
142 * hsi_register_controller - Register an HSI controller and its ports
143 * @hsi: The HSI controller to register
144 *
145 * Returns -errno on failure, 0 on success.
146 */
147int hsi_register_controller(struct hsi_controller *hsi)
148{
149 unsigned int i;
150 int err;
151
152 err = device_add(&hsi->device);
153 if (err < 0)
154 return err;
155 for (i = 0; i < hsi->num_ports; i++) {
156 hsi->port[i]->device.parent = &hsi->device;
157 err = device_add(&hsi->port[i]->device);
158 if (err < 0)
159 goto out;
160 }
161 /* Populate HSI bus with HSI clients */
162 hsi_scan_board_info(hsi);
163
164 return 0;
165out:
166 while (i-- > 0)
167 device_del(&hsi->port[i]->device);
168 device_del(&hsi->device);
169
170 return err;
171}
172EXPORT_SYMBOL_GPL(hsi_register_controller);
173
174/**
175 * hsi_register_client_driver - Register an HSI client to the HSI bus
176 * @drv: HSI client driver to register
177 *
178 * Returns -errno on failure, 0 on success.
179 */
180int hsi_register_client_driver(struct hsi_client_driver *drv)
181{
182 drv->driver.bus = &hsi_bus_type;
183
184 return driver_register(&drv->driver);
185}
186EXPORT_SYMBOL_GPL(hsi_register_client_driver);
187
188static inline int hsi_dummy_msg(struct hsi_msg *msg __maybe_unused)
189{
190 return 0;
191}
192
193static inline int hsi_dummy_cl(struct hsi_client *cl __maybe_unused)
194{
195 return 0;
196}
197
198/**
199 * hsi_put_controller - Free an HSI controller
200 *
201 * @hsi: Pointer to the HSI controller to freed
202 *
203 * HSI controller drivers should only use this function if they need
204 * to free their allocated hsi_controller structures before a successful
205 * call to hsi_register_controller. Other use is not allowed.
206 */
207void hsi_put_controller(struct hsi_controller *hsi)
208{
209 unsigned int i;
210
211 if (!hsi)
212 return;
213
214 for (i = 0; i < hsi->num_ports; i++)
215 if (hsi->port && hsi->port[i])
216 put_device(&hsi->port[i]->device);
217 put_device(&hsi->device);
218}
219EXPORT_SYMBOL_GPL(hsi_put_controller);
220
221/**
222 * hsi_alloc_controller - Allocate an HSI controller and its ports
223 * @n_ports: Number of ports on the HSI controller
224 * @flags: Kernel allocation flags
225 *
226 * Return NULL on failure or a pointer to an hsi_controller on success.
227 */
228struct hsi_controller *hsi_alloc_controller(unsigned int n_ports, gfp_t flags)
229{
230 struct hsi_controller *hsi;
231 struct hsi_port **port;
232 unsigned int i;
233
234 if (!n_ports)
235 return NULL;
236
237 hsi = kzalloc(sizeof(*hsi), flags);
238 if (!hsi)
239 return NULL;
240 port = kzalloc(sizeof(*port)*n_ports, flags);
241 if (!port) {
242 kfree(hsi);
243 return NULL;
244 }
245 hsi->num_ports = n_ports;
246 hsi->port = port;
247 hsi->device.release = hsi_controller_release;
248 device_initialize(&hsi->device);
249
250 for (i = 0; i < n_ports; i++) {
251 port[i] = kzalloc(sizeof(**port), flags);
252 if (port[i] == NULL)
253 goto out;
254 port[i]->num = i;
255 port[i]->async = hsi_dummy_msg;
256 port[i]->setup = hsi_dummy_cl;
257 port[i]->flush = hsi_dummy_cl;
258 port[i]->start_tx = hsi_dummy_cl;
259 port[i]->stop_tx = hsi_dummy_cl;
260 port[i]->release = hsi_dummy_cl;
261 mutex_init(&port[i]->lock);
262 ATOMIC_INIT_NOTIFIER_HEAD(&port[i]->n_head);
263 dev_set_name(&port[i]->device, "port%d", i);
264 hsi->port[i]->device.release = hsi_port_release;
265 device_initialize(&hsi->port[i]->device);
266 }
267
268 return hsi;
269out:
270 hsi_put_controller(hsi);
271
272 return NULL;
273}
274EXPORT_SYMBOL_GPL(hsi_alloc_controller);
275
276/**
277 * hsi_free_msg - Free an HSI message
278 * @msg: Pointer to the HSI message
279 *
280 * Client is responsible to free the buffers pointed by the scatterlists.
281 */
282void hsi_free_msg(struct hsi_msg *msg)
283{
284 if (!msg)
285 return;
286 sg_free_table(&msg->sgt);
287 kfree(msg);
288}
289EXPORT_SYMBOL_GPL(hsi_free_msg);
290
291/**
292 * hsi_alloc_msg - Allocate an HSI message
293 * @nents: Number of memory entries
294 * @flags: Kernel allocation flags
295 *
296 * nents can be 0. This mainly makes sense for read transfer.
297 * In that case, HSI drivers will call the complete callback when
298 * there is data to be read without consuming it.
299 *
300 * Return NULL on failure or a pointer to an hsi_msg on success.
301 */
302struct hsi_msg *hsi_alloc_msg(unsigned int nents, gfp_t flags)
303{
304 struct hsi_msg *msg;
305 int err;
306
307 msg = kzalloc(sizeof(*msg), flags);
308 if (!msg)
309 return NULL;
310
311 if (!nents)
312 return msg;
313
314 err = sg_alloc_table(&msg->sgt, nents, flags);
315 if (unlikely(err)) {
316 kfree(msg);
317 msg = NULL;
318 }
319
320 return msg;
321}
322EXPORT_SYMBOL_GPL(hsi_alloc_msg);
323
324/**
325 * hsi_async - Submit an HSI transfer to the controller
326 * @cl: HSI client sending the transfer
327 * @msg: The HSI transfer passed to controller
328 *
329 * The HSI message must have the channel, ttype, complete and destructor
330 * fields set beforehand. If nents > 0 then the client has to initialize
331 * also the scatterlists to point to the buffers to write to or read from.
332 *
333 * HSI controllers relay on pre-allocated buffers from their clients and they
334 * do not allocate buffers on their own.
335 *
336 * Once the HSI message transfer finishes, the HSI controller calls the
337 * complete callback with the status and actual_len fields of the HSI message
338 * updated. The complete callback can be called before returning from
339 * hsi_async.
340 *
341 * Returns -errno on failure or 0 on success
342 */
343int hsi_async(struct hsi_client *cl, struct hsi_msg *msg)
344{
345 struct hsi_port *port = hsi_get_port(cl);
346
347 if (!hsi_port_claimed(cl))
348 return -EACCES;
349
350 WARN_ON_ONCE(!msg->destructor || !msg->complete);
351 msg->cl = cl;
352
353 return port->async(msg);
354}
355EXPORT_SYMBOL_GPL(hsi_async);
356
357/**
358 * hsi_claim_port - Claim the HSI client's port
359 * @cl: HSI client that wants to claim its port
360 * @share: Flag to indicate if the client wants to share the port or not.
361 *
362 * Returns -errno on failure, 0 on success.
363 */
364int hsi_claim_port(struct hsi_client *cl, unsigned int share)
365{
366 struct hsi_port *port = hsi_get_port(cl);
367 int err = 0;
368
369 mutex_lock(&port->lock);
370 if ((port->claimed) && (!port->shared || !share)) {
371 err = -EBUSY;
372 goto out;
373 }
374 if (!try_module_get(to_hsi_controller(port->device.parent)->owner)) {
375 err = -ENODEV;
376 goto out;
377 }
378 port->claimed++;
379 port->shared = !!share;
380 cl->pclaimed = 1;
381out:
382 mutex_unlock(&port->lock);
383
384 return err;
385}
386EXPORT_SYMBOL_GPL(hsi_claim_port);
387
388/**
389 * hsi_release_port - Release the HSI client's port
390 * @cl: HSI client which previously claimed its port
391 */
392void hsi_release_port(struct hsi_client *cl)
393{
394 struct hsi_port *port = hsi_get_port(cl);
395
396 mutex_lock(&port->lock);
397 /* Allow HW driver to do some cleanup */
398 port->release(cl);
399 if (cl->pclaimed)
400 port->claimed--;
401 BUG_ON(port->claimed < 0);
402 cl->pclaimed = 0;
403 if (!port->claimed)
404 port->shared = 0;
405 module_put(to_hsi_controller(port->device.parent)->owner);
406 mutex_unlock(&port->lock);
407}
408EXPORT_SYMBOL_GPL(hsi_release_port);
409
410static int hsi_event_notifier_call(struct notifier_block *nb,
411 unsigned long event, void *data __maybe_unused)
412{
413 struct hsi_client *cl = container_of(nb, struct hsi_client, nb);
414
415 (*cl->ehandler)(cl, event);
416
417 return 0;
418}
419
420/**
421 * hsi_register_port_event - Register a client to receive port events
422 * @cl: HSI client that wants to receive port events
423 * @cb: Event handler callback
424 *
425 * Clients should register a callback to be able to receive
426 * events from the ports. Registration should happen after
427 * claiming the port.
428 * The handler can be called in interrupt context.
429 *
430 * Returns -errno on error, or 0 on success.
431 */
432int hsi_register_port_event(struct hsi_client *cl,
433 void (*handler)(struct hsi_client *, unsigned long))
434{
435 struct hsi_port *port = hsi_get_port(cl);
436
437 if (!handler || cl->ehandler)
438 return -EINVAL;
439 if (!hsi_port_claimed(cl))
440 return -EACCES;
441 cl->ehandler = handler;
442 cl->nb.notifier_call = hsi_event_notifier_call;
443
444 return atomic_notifier_chain_register(&port->n_head, &cl->nb);
445}
446EXPORT_SYMBOL_GPL(hsi_register_port_event);
447
448/**
449 * hsi_unregister_port_event - Stop receiving port events for a client
450 * @cl: HSI client that wants to stop receiving port events
451 *
452 * Clients should call this function before releasing their associated
453 * port.
454 *
455 * Returns -errno on error, or 0 on success.
456 */
457int hsi_unregister_port_event(struct hsi_client *cl)
458{
459 struct hsi_port *port = hsi_get_port(cl);
460 int err;
461
462 WARN_ON(!hsi_port_claimed(cl));
463
464 err = atomic_notifier_chain_unregister(&port->n_head, &cl->nb);
465 if (!err)
466 cl->ehandler = NULL;
467
468 return err;
469}
470EXPORT_SYMBOL_GPL(hsi_unregister_port_event);
471
472/**
473 * hsi_event -Notifies clients about port events
474 * @port: Port where the event occurred
475 * @event: The event type
476 *
477 * Clients should not be concerned about wake line behavior. However, due
478 * to a race condition in HSI HW protocol, clients need to be notified
479 * about wake line changes, so they can implement a workaround for it.
480 *
481 * Events:
482 * HSI_EVENT_START_RX - Incoming wake line high
483 * HSI_EVENT_STOP_RX - Incoming wake line down
484 *
485 * Returns -errno on error, or 0 on success.
486 */
487int hsi_event(struct hsi_port *port, unsigned long event)
488{
489 return atomic_notifier_call_chain(&port->n_head, event, NULL);
490}
491EXPORT_SYMBOL_GPL(hsi_event);
492
493static int __init hsi_init(void)
494{
495 return bus_register(&hsi_bus_type);
496}
497postcore_initcall(hsi_init);
498
499static void __exit hsi_exit(void)
500{
501 bus_unregister(&hsi_bus_type);
502}
503module_exit(hsi_exit);
504
505MODULE_AUTHOR("Carlos Chinea <carlos.chinea@nokia.com>");
506MODULE_DESCRIPTION("High-speed Synchronous Serial Interface (HSI) framework");
507MODULE_LICENSE("GPL v2");
diff --git a/drivers/hsi/hsi_boardinfo.c b/drivers/hsi/hsi_boardinfo.c
new file mode 100644
index 000000000000..e56bc6da5f98
--- /dev/null
+++ b/drivers/hsi/hsi_boardinfo.c
@@ -0,0 +1,62 @@
1/*
2 * HSI clients registration interface
3 *
4 * Copyright (C) 2010 Nokia Corporation. All rights reserved.
5 *
6 * Contact: Carlos Chinea <carlos.chinea@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 */
22#include <linux/hsi/hsi.h>
23#include <linux/list.h>
24#include <linux/slab.h>
25#include "hsi_core.h"
26
27/*
28 * hsi_board_list is only used internally by the HSI framework.
29 * No one else is allowed to make use of it.
30 */
31LIST_HEAD(hsi_board_list);
32EXPORT_SYMBOL_GPL(hsi_board_list);
33
34/**
35 * hsi_register_board_info - Register HSI clients information
36 * @info: Array of HSI clients on the board
37 * @len: Length of the array
38 *
39 * HSI clients are statically declared and registered on board files.
40 *
41 * HSI clients will be automatically registered to the HSI bus once the
42 * controller and the port where the clients wishes to attach are registered
43 * to it.
44 *
45 * Return -errno on failure, 0 on success.
46 */
47int __init hsi_register_board_info(struct hsi_board_info const *info,
48 unsigned int len)
49{
50 struct hsi_cl_info *cl_info;
51
52 cl_info = kzalloc(sizeof(*cl_info) * len, GFP_KERNEL);
53 if (!cl_info)
54 return -ENOMEM;
55
56 for (; len; len--, info++, cl_info++) {
57 cl_info->info = *info;
58 list_add_tail(&cl_info->list, &hsi_board_list);
59 }
60
61 return 0;
62}
diff --git a/drivers/hsi/hsi_core.h b/drivers/hsi/hsi_core.h
new file mode 100644
index 000000000000..ab5c2fb175fd
--- /dev/null
+++ b/drivers/hsi/hsi_core.h
@@ -0,0 +1,35 @@
1/*
2 * HSI framework internal interfaces,
3 *
4 * Copyright (C) 2010 Nokia Corporation. All rights reserved.
5 *
6 * Contact: Carlos Chinea <carlos.chinea@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 */
22
23#ifndef __LINUX_HSI_CORE_H__
24#define __LINUX_HSI_CORE_H__
25
26#include <linux/hsi/hsi.h>
27
28struct hsi_cl_info {
29 struct list_head list;
30 struct hsi_board_info info;
31};
32
33extern struct list_head hsi_board_list;
34
35#endif /* __LINUX_HSI_CORE_H__ */
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 5b32d56dbb4d..8deedc1b9840 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -253,7 +253,8 @@ config SENSORS_K10TEMP
253 If you say yes here you get support for the temperature 253 If you say yes here you get support for the temperature
254 sensor(s) inside your CPU. Supported are later revisions of 254 sensor(s) inside your CPU. Supported are later revisions of
255 the AMD Family 10h and all revisions of the AMD Family 11h, 255 the AMD Family 10h and all revisions of the AMD Family 11h,
256 12h (Llano), 14h (Brazos) and 15h (Bulldozer) microarchitectures. 256 12h (Llano), 14h (Brazos) and 15h (Bulldozer/Trinity)
257 microarchitectures.
257 258
258 This driver can also be built as a module. If so, the module 259 This driver can also be built as a module. If so, the module
259 will be called k10temp. 260 will be called k10temp.
@@ -425,7 +426,7 @@ config SENSORS_GL520SM
425 426
426config SENSORS_GPIO_FAN 427config SENSORS_GPIO_FAN
427 tristate "GPIO fan" 428 tristate "GPIO fan"
428 depends on GENERIC_GPIO 429 depends on GPIOLIB
429 help 430 help
430 If you say yes here you get support for fans connected to GPIO lines. 431 If you say yes here you get support for fans connected to GPIO lines.
431 432
@@ -883,7 +884,7 @@ source drivers/hwmon/pmbus/Kconfig
883 884
884config SENSORS_SHT15 885config SENSORS_SHT15
885 tristate "Sensiron humidity and temperature sensors. SHT15 and compat." 886 tristate "Sensiron humidity and temperature sensors. SHT15 and compat."
886 depends on GENERIC_GPIO 887 depends on GPIOLIB
887 help 888 help
888 If you say yes here you get support for the Sensiron SHT10, SHT11, 889 If you say yes here you get support for the Sensiron SHT10, SHT11,
889 SHT15, SHT71, SHT75 humidity and temperature sensors. 890 SHT15, SHT71, SHT75 humidity and temperature sensors.
diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
index 554f046bcf20..9140236a0182 100644
--- a/drivers/hwmon/acpi_power_meter.c
+++ b/drivers/hwmon/acpi_power_meter.c
@@ -391,6 +391,7 @@ static ssize_t show_str(struct device *dev,
391 break; 391 break;
392 default: 392 default:
393 BUG(); 393 BUG();
394 val = "";
394 } 395 }
395 396
396 return sprintf(buf, "%s\n", val); 397 return sprintf(buf, "%s\n", val);
@@ -632,6 +633,7 @@ static int register_ro_attrs(struct acpi_power_meter_resource *resource,
632 sensors->dev_attr.show = ro->show; 633 sensors->dev_attr.show = ro->show;
633 sensors->index = ro->index; 634 sensors->index = ro->index;
634 635
636 sysfs_attr_init(&sensors->dev_attr.attr);
635 res = device_create_file(dev, &sensors->dev_attr); 637 res = device_create_file(dev, &sensors->dev_attr);
636 if (res) { 638 if (res) {
637 sensors->dev_attr.attr.name = NULL; 639 sensors->dev_attr.attr.name = NULL;
@@ -661,6 +663,7 @@ static int register_rw_attrs(struct acpi_power_meter_resource *resource,
661 sensors->dev_attr.store = rw->set; 663 sensors->dev_attr.store = rw->set;
662 sensors->index = rw->index; 664 sensors->index = rw->index;
663 665
666 sysfs_attr_init(&sensors->dev_attr.attr);
664 res = device_create_file(dev, &sensors->dev_attr); 667 res = device_create_file(dev, &sensors->dev_attr);
665 if (res) { 668 if (res) {
666 sensors->dev_attr.attr.name = NULL; 669 sensors->dev_attr.attr.name = NULL;
diff --git a/drivers/hwmon/ad7314.c b/drivers/hwmon/ad7314.c
index 0e0cfcc36f8d..f85ce70d9677 100644
--- a/drivers/hwmon/ad7314.c
+++ b/drivers/hwmon/ad7314.c
@@ -47,7 +47,7 @@ struct ad7314_data {
47 u16 rx ____cacheline_aligned; 47 u16 rx ____cacheline_aligned;
48}; 48};
49 49
50static int ad7314_spi_read(struct ad7314_data *chip, s16 *data) 50static int ad7314_spi_read(struct ad7314_data *chip)
51{ 51{
52 int ret; 52 int ret;
53 53
@@ -57,9 +57,7 @@ static int ad7314_spi_read(struct ad7314_data *chip, s16 *data)
57 return ret; 57 return ret;
58 } 58 }
59 59
60 *data = be16_to_cpu(chip->rx); 60 return be16_to_cpu(chip->rx);
61
62 return ret;
63} 61}
64 62
65static ssize_t ad7314_show_temperature(struct device *dev, 63static ssize_t ad7314_show_temperature(struct device *dev,
@@ -70,12 +68,12 @@ static ssize_t ad7314_show_temperature(struct device *dev,
70 s16 data; 68 s16 data;
71 int ret; 69 int ret;
72 70
73 ret = ad7314_spi_read(chip, &data); 71 ret = ad7314_spi_read(chip);
74 if (ret < 0) 72 if (ret < 0)
75 return ret; 73 return ret;
76 switch (spi_get_device_id(chip->spi_dev)->driver_data) { 74 switch (spi_get_device_id(chip->spi_dev)->driver_data) {
77 case ad7314: 75 case ad7314:
78 data = (data & AD7314_TEMP_MASK) >> AD7314_TEMP_OFFSET; 76 data = (ret & AD7314_TEMP_MASK) >> AD7314_TEMP_OFFSET;
79 data = (data << 6) >> 6; 77 data = (data << 6) >> 6;
80 78
81 return sprintf(buf, "%d\n", 250 * data); 79 return sprintf(buf, "%d\n", 250 * data);
@@ -86,7 +84,7 @@ static ssize_t ad7314_show_temperature(struct device *dev,
86 * with a sign bit - which is a 14 bit 2's complement 84 * with a sign bit - which is a 14 bit 2's complement
87 * register. 1lsb - 31.25 milli degrees centigrade 85 * register. 1lsb - 31.25 milli degrees centigrade
88 */ 86 */
89 data &= ADT7301_TEMP_MASK; 87 data = ret & ADT7301_TEMP_MASK;
90 data = (data << 2) >> 2; 88 data = (data << 2) >> 2;
91 89
92 return sprintf(buf, "%d\n", 90 return sprintf(buf, "%d\n",
@@ -128,6 +126,7 @@ static int __devinit ad7314_probe(struct spi_device *spi_dev)
128 ret = PTR_ERR(chip->hwmon_dev); 126 ret = PTR_ERR(chip->hwmon_dev);
129 goto error_remove_group; 127 goto error_remove_group;
130 } 128 }
129 chip->spi_dev = spi_dev;
131 130
132 return 0; 131 return 0;
133error_remove_group: 132error_remove_group:
diff --git a/drivers/hwmon/adm1031.c b/drivers/hwmon/adm1031.c
index ff37363ea5bc..44e1fd7f3d81 100644
--- a/drivers/hwmon/adm1031.c
+++ b/drivers/hwmon/adm1031.c
@@ -233,18 +233,15 @@ static const auto_chan_table_t auto_channel_select_table_adm1030 = {
233 * nearest match if no exact match where found. 233 * nearest match if no exact match where found.
234 */ 234 */
235static int 235static int
236get_fan_auto_nearest(struct adm1031_data *data, 236get_fan_auto_nearest(struct adm1031_data *data, int chan, u8 val, u8 reg)
237 int chan, u8 val, u8 reg, u8 *new_reg)
238{ 237{
239 int i; 238 int i;
240 int first_match = -1, exact_match = -1; 239 int first_match = -1, exact_match = -1;
241 u8 other_reg_val = 240 u8 other_reg_val =
242 (*data->chan_select_table)[FAN_CHAN_FROM_REG(reg)][chan ? 0 : 1]; 241 (*data->chan_select_table)[FAN_CHAN_FROM_REG(reg)][chan ? 0 : 1];
243 242
244 if (val == 0) { 243 if (val == 0)
245 *new_reg = 0;
246 return 0; 244 return 0;
247 }
248 245
249 for (i = 0; i < 8; i++) { 246 for (i = 0; i < 8; i++) {
250 if ((val == (*data->chan_select_table)[i][chan]) && 247 if ((val == (*data->chan_select_table)[i][chan]) &&
@@ -264,13 +261,11 @@ get_fan_auto_nearest(struct adm1031_data *data,
264 } 261 }
265 262
266 if (exact_match >= 0) 263 if (exact_match >= 0)
267 *new_reg = exact_match; 264 return exact_match;
268 else if (first_match >= 0) 265 else if (first_match >= 0)
269 *new_reg = first_match; 266 return first_match;
270 else
271 return -EINVAL;
272 267
273 return 0; 268 return -EINVAL;
274} 269}
275 270
276static ssize_t show_fan_auto_channel(struct device *dev, 271static ssize_t show_fan_auto_channel(struct device *dev,
@@ -301,11 +296,12 @@ set_fan_auto_channel(struct device *dev, struct device_attribute *attr,
301 296
302 mutex_lock(&data->update_lock); 297 mutex_lock(&data->update_lock);
303 298
304 ret = get_fan_auto_nearest(data, nr, val, data->conf1, &reg); 299 ret = get_fan_auto_nearest(data, nr, val, data->conf1);
305 if (ret) { 300 if (ret < 0) {
306 mutex_unlock(&data->update_lock); 301 mutex_unlock(&data->update_lock);
307 return ret; 302 return ret;
308 } 303 }
304 reg = ret;
309 data->conf1 = FAN_CHAN_TO_REG(reg, data->conf1); 305 data->conf1 = FAN_CHAN_TO_REG(reg, data->conf1);
310 if ((data->conf1 & ADM1031_CONF1_AUTO_MODE) ^ 306 if ((data->conf1 & ADM1031_CONF1_AUTO_MODE) ^
311 (old_fan_mode & ADM1031_CONF1_AUTO_MODE)) { 307 (old_fan_mode & ADM1031_CONF1_AUTO_MODE)) {
diff --git a/drivers/hwmon/ads1015.c b/drivers/hwmon/ads1015.c
index 7765e4f74ec5..1958f03efd7a 100644
--- a/drivers/hwmon/ads1015.c
+++ b/drivers/hwmon/ads1015.c
@@ -59,14 +59,11 @@ struct ads1015_data {
59 struct ads1015_channel_data channel_data[ADS1015_CHANNELS]; 59 struct ads1015_channel_data channel_data[ADS1015_CHANNELS];
60}; 60};
61 61
62static int ads1015_read_value(struct i2c_client *client, unsigned int channel, 62static int ads1015_read_adc(struct i2c_client *client, unsigned int channel)
63 int *value)
64{ 63{
65 u16 config; 64 u16 config;
66 s16 conversion;
67 struct ads1015_data *data = i2c_get_clientdata(client); 65 struct ads1015_data *data = i2c_get_clientdata(client);
68 unsigned int pga = data->channel_data[channel].pga; 66 unsigned int pga = data->channel_data[channel].pga;
69 int fullscale;
70 unsigned int data_rate = data->channel_data[channel].data_rate; 67 unsigned int data_rate = data->channel_data[channel].data_rate;
71 unsigned int conversion_time_ms; 68 unsigned int conversion_time_ms;
72 int res; 69 int res;
@@ -78,7 +75,6 @@ static int ads1015_read_value(struct i2c_client *client, unsigned int channel,
78 if (res < 0) 75 if (res < 0)
79 goto err_unlock; 76 goto err_unlock;
80 config = res; 77 config = res;
81 fullscale = fullscale_table[pga];
82 conversion_time_ms = DIV_ROUND_UP(1000, data_rate_table[data_rate]); 78 conversion_time_ms = DIV_ROUND_UP(1000, data_rate_table[data_rate]);
83 79
84 /* setup and start single conversion */ 80 /* setup and start single conversion */
@@ -105,33 +101,36 @@ static int ads1015_read_value(struct i2c_client *client, unsigned int channel,
105 } 101 }
106 102
107 res = i2c_smbus_read_word_swapped(client, ADS1015_CONVERSION); 103 res = i2c_smbus_read_word_swapped(client, ADS1015_CONVERSION);
108 if (res < 0)
109 goto err_unlock;
110 conversion = res;
111
112 mutex_unlock(&data->update_lock);
113
114 *value = DIV_ROUND_CLOSEST(conversion * fullscale, 0x7ff0);
115
116 return 0;
117 104
118err_unlock: 105err_unlock:
119 mutex_unlock(&data->update_lock); 106 mutex_unlock(&data->update_lock);
120 return res; 107 return res;
121} 108}
122 109
110static int ads1015_reg_to_mv(struct i2c_client *client, unsigned int channel,
111 s16 reg)
112{
113 struct ads1015_data *data = i2c_get_clientdata(client);
114 unsigned int pga = data->channel_data[channel].pga;
115 int fullscale = fullscale_table[pga];
116
117 return DIV_ROUND_CLOSEST(reg * fullscale, 0x7ff0);
118}
119
123/* sysfs callback function */ 120/* sysfs callback function */
124static ssize_t show_in(struct device *dev, struct device_attribute *da, 121static ssize_t show_in(struct device *dev, struct device_attribute *da,
125 char *buf) 122 char *buf)
126{ 123{
127 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 124 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
128 struct i2c_client *client = to_i2c_client(dev); 125 struct i2c_client *client = to_i2c_client(dev);
129 int in;
130 int res; 126 int res;
127 int index = attr->index;
131 128
132 res = ads1015_read_value(client, attr->index, &in); 129 res = ads1015_read_adc(client, index);
130 if (res < 0)
131 return res;
133 132
134 return (res < 0) ? res : sprintf(buf, "%d\n", in); 133 return sprintf(buf, "%d\n", ads1015_reg_to_mv(client, index, res));
135} 134}
136 135
137static const struct sensor_device_attribute ads1015_in[] = { 136static const struct sensor_device_attribute ads1015_in[] = {
diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
index 0d3141fbbc20..b9d512331ed4 100644
--- a/drivers/hwmon/coretemp.c
+++ b/drivers/hwmon/coretemp.c
@@ -52,7 +52,7 @@ module_param_named(tjmax, force_tjmax, int, 0444);
52MODULE_PARM_DESC(tjmax, "TjMax value in degrees Celsius"); 52MODULE_PARM_DESC(tjmax, "TjMax value in degrees Celsius");
53 53
54#define BASE_SYSFS_ATTR_NO 2 /* Sysfs Base attr no for coretemp */ 54#define BASE_SYSFS_ATTR_NO 2 /* Sysfs Base attr no for coretemp */
55#define NUM_REAL_CORES 16 /* Number of Real cores per cpu */ 55#define NUM_REAL_CORES 32 /* Number of Real cores per cpu */
56#define CORETEMP_NAME_LENGTH 17 /* String Length of attrs */ 56#define CORETEMP_NAME_LENGTH 17 /* String Length of attrs */
57#define MAX_CORE_ATTRS 4 /* Maximum no of basic attrs */ 57#define MAX_CORE_ATTRS 4 /* Maximum no of basic attrs */
58#define TOTAL_ATTRS (MAX_CORE_ATTRS + 1) 58#define TOTAL_ATTRS (MAX_CORE_ATTRS + 1)
@@ -709,6 +709,10 @@ static void __cpuinit put_core_offline(unsigned int cpu)
709 709
710 indx = TO_ATTR_NO(cpu); 710 indx = TO_ATTR_NO(cpu);
711 711
712 /* The core id is too big, just return */
713 if (indx > MAX_CORE_DATA - 1)
714 return;
715
712 if (pdata->core_data[indx] && pdata->core_data[indx]->cpu == cpu) 716 if (pdata->core_data[indx] && pdata->core_data[indx]->cpu == cpu)
713 coretemp_remove_core(pdata, &pdev->dev, indx); 717 coretemp_remove_core(pdata, &pdev->dev, indx);
714 718
diff --git a/drivers/hwmon/f75375s.c b/drivers/hwmon/f75375s.c
index 729499e75210..ece4159bd453 100644
--- a/drivers/hwmon/f75375s.c
+++ b/drivers/hwmon/f75375s.c
@@ -276,6 +276,7 @@ static bool duty_mode_enabled(u8 pwm_enable)
276 return false; 276 return false;
277 default: 277 default:
278 BUG(); 278 BUG();
279 return true;
279 } 280 }
280} 281}
281 282
@@ -291,6 +292,7 @@ static bool auto_mode_enabled(u8 pwm_enable)
291 return true; 292 return true;
292 default: 293 default:
293 BUG(); 294 BUG();
295 return false;
294 } 296 }
295} 297}
296 298
diff --git a/drivers/hwmon/fam15h_power.c b/drivers/hwmon/fam15h_power.c
index b7494af1e4a9..e8e18cab1fb8 100644
--- a/drivers/hwmon/fam15h_power.c
+++ b/drivers/hwmon/fam15h_power.c
@@ -122,6 +122,41 @@ static bool __devinit fam15h_power_is_internal_node0(struct pci_dev *f4)
122 return true; 122 return true;
123} 123}
124 124
125/*
126 * Newer BKDG versions have an updated recommendation on how to properly
127 * initialize the running average range (was: 0xE, now: 0x9). This avoids
128 * counter saturations resulting in bogus power readings.
129 * We correct this value ourselves to cope with older BIOSes.
130 */
131static DEFINE_PCI_DEVICE_TABLE(affected_device) = {
132 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_15H_NB_F4) },
133 { 0 }
134};
135
136static void __devinit tweak_runavg_range(struct pci_dev *pdev)
137{
138 u32 val;
139
140 /*
141 * let this quirk apply only to the current version of the
142 * northbridge, since future versions may change the behavior
143 */
144 if (!pci_match_id(affected_device, pdev))
145 return;
146
147 pci_bus_read_config_dword(pdev->bus,
148 PCI_DEVFN(PCI_SLOT(pdev->devfn), 5),
149 REG_TDP_RUNNING_AVERAGE, &val);
150 if ((val & 0xf) != 0xe)
151 return;
152
153 val &= ~0xf;
154 val |= 0x9;
155 pci_bus_write_config_dword(pdev->bus,
156 PCI_DEVFN(PCI_SLOT(pdev->devfn), 5),
157 REG_TDP_RUNNING_AVERAGE, val);
158}
159
125static void __devinit fam15h_power_init_data(struct pci_dev *f4, 160static void __devinit fam15h_power_init_data(struct pci_dev *f4,
126 struct fam15h_power_data *data) 161 struct fam15h_power_data *data)
127{ 162{
@@ -155,6 +190,13 @@ static int __devinit fam15h_power_probe(struct pci_dev *pdev,
155 struct device *dev; 190 struct device *dev;
156 int err; 191 int err;
157 192
193 /*
194 * though we ignore every other northbridge, we still have to
195 * do the tweaking on _each_ node in MCM processors as the counters
196 * are working hand-in-hand
197 */
198 tweak_runavg_range(pdev);
199
158 if (!fam15h_power_is_internal_node0(pdev)) { 200 if (!fam15h_power_is_internal_node0(pdev)) {
159 err = -ENODEV; 201 err = -ENODEV;
160 goto exit; 202 goto exit;
diff --git a/drivers/hwmon/k10temp.c b/drivers/hwmon/k10temp.c
index aba29d63f195..307bb325dde9 100644
--- a/drivers/hwmon/k10temp.c
+++ b/drivers/hwmon/k10temp.c
@@ -33,6 +33,9 @@ static bool force;
33module_param(force, bool, 0444); 33module_param(force, bool, 0444);
34MODULE_PARM_DESC(force, "force loading on processors with erratum 319"); 34MODULE_PARM_DESC(force, "force loading on processors with erratum 319");
35 35
36/* PCI-IDs for Northbridge devices not used anywhere else */
37#define PCI_DEVICE_ID_AMD_15H_M10H_NB_F3 0x1403
38
36/* CPUID function 0x80000001, ebx */ 39/* CPUID function 0x80000001, ebx */
37#define CPUID_PKGTYPE_MASK 0xf0000000 40#define CPUID_PKGTYPE_MASK 0xf0000000
38#define CPUID_PKGTYPE_F 0x00000000 41#define CPUID_PKGTYPE_F 0x00000000
@@ -210,6 +213,7 @@ static DEFINE_PCI_DEVICE_TABLE(k10temp_id_table) = {
210 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_11H_NB_MISC) }, 213 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_11H_NB_MISC) },
211 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_CNB17H_F3) }, 214 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_CNB17H_F3) },
212 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_15H_NB_F3) }, 215 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_15H_NB_F3) },
216 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_15H_M10H_NB_F3) },
213 {} 217 {}
214}; 218};
215MODULE_DEVICE_TABLE(pci, k10temp_id_table); 219MODULE_DEVICE_TABLE(pci, k10temp_id_table);
diff --git a/drivers/hwmon/max6639.c b/drivers/hwmon/max6639.c
index 193067e27b6f..de8f7adaccbd 100644
--- a/drivers/hwmon/max6639.c
+++ b/drivers/hwmon/max6639.c
@@ -596,8 +596,10 @@ static int max6639_remove(struct i2c_client *client)
596 return 0; 596 return 0;
597} 597}
598 598
599static int max6639_suspend(struct i2c_client *client, pm_message_t mesg) 599#ifdef CONFIG_PM_SLEEP
600static int max6639_suspend(struct device *dev)
600{ 601{
602 struct i2c_client *client = to_i2c_client(dev);
601 int data = i2c_smbus_read_byte_data(client, MAX6639_REG_GCONFIG); 603 int data = i2c_smbus_read_byte_data(client, MAX6639_REG_GCONFIG);
602 if (data < 0) 604 if (data < 0)
603 return data; 605 return data;
@@ -606,8 +608,9 @@ static int max6639_suspend(struct i2c_client *client, pm_message_t mesg)
606 MAX6639_REG_GCONFIG, data | MAX6639_GCONFIG_STANDBY); 608 MAX6639_REG_GCONFIG, data | MAX6639_GCONFIG_STANDBY);
607} 609}
608 610
609static int max6639_resume(struct i2c_client *client) 611static int max6639_resume(struct device *dev)
610{ 612{
613 struct i2c_client *client = to_i2c_client(dev);
611 int data = i2c_smbus_read_byte_data(client, MAX6639_REG_GCONFIG); 614 int data = i2c_smbus_read_byte_data(client, MAX6639_REG_GCONFIG);
612 if (data < 0) 615 if (data < 0)
613 return data; 616 return data;
@@ -615,6 +618,7 @@ static int max6639_resume(struct i2c_client *client)
615 return i2c_smbus_write_byte_data(client, 618 return i2c_smbus_write_byte_data(client,
616 MAX6639_REG_GCONFIG, data & ~MAX6639_GCONFIG_STANDBY); 619 MAX6639_REG_GCONFIG, data & ~MAX6639_GCONFIG_STANDBY);
617} 620}
621#endif /* CONFIG_PM_SLEEP */
618 622
619static const struct i2c_device_id max6639_id[] = { 623static const struct i2c_device_id max6639_id[] = {
620 {"max6639", 0}, 624 {"max6639", 0},
@@ -623,15 +627,18 @@ static const struct i2c_device_id max6639_id[] = {
623 627
624MODULE_DEVICE_TABLE(i2c, max6639_id); 628MODULE_DEVICE_TABLE(i2c, max6639_id);
625 629
630static const struct dev_pm_ops max6639_pm_ops = {
631 SET_SYSTEM_SLEEP_PM_OPS(max6639_suspend, max6639_resume)
632};
633
626static struct i2c_driver max6639_driver = { 634static struct i2c_driver max6639_driver = {
627 .class = I2C_CLASS_HWMON, 635 .class = I2C_CLASS_HWMON,
628 .driver = { 636 .driver = {
629 .name = "max6639", 637 .name = "max6639",
638 .pm = &max6639_pm_ops,
630 }, 639 },
631 .probe = max6639_probe, 640 .probe = max6639_probe,
632 .remove = max6639_remove, 641 .remove = max6639_remove,
633 .suspend = max6639_suspend,
634 .resume = max6639_resume,
635 .id_table = max6639_id, 642 .id_table = max6639_id,
636 .detect = max6639_detect, 643 .detect = max6639_detect,
637 .address_list = normal_i2c, 644 .address_list = normal_i2c,
diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
index be51037363c8..29b319db573e 100644
--- a/drivers/hwmon/pmbus/pmbus_core.c
+++ b/drivers/hwmon/pmbus/pmbus_core.c
@@ -710,13 +710,13 @@ static u16 pmbus_data2reg(struct pmbus_data *data,
710 * If a negative value is stored in any of the referenced registers, this value 710 * If a negative value is stored in any of the referenced registers, this value
711 * reflects an error code which will be returned. 711 * reflects an error code which will be returned.
712 */ 712 */
713static int pmbus_get_boolean(struct pmbus_data *data, int index, int *val) 713static int pmbus_get_boolean(struct pmbus_data *data, int index)
714{ 714{
715 u8 s1 = (index >> 24) & 0xff; 715 u8 s1 = (index >> 24) & 0xff;
716 u8 s2 = (index >> 16) & 0xff; 716 u8 s2 = (index >> 16) & 0xff;
717 u8 reg = (index >> 8) & 0xff; 717 u8 reg = (index >> 8) & 0xff;
718 u8 mask = index & 0xff; 718 u8 mask = index & 0xff;
719 int status; 719 int ret, status;
720 u8 regval; 720 u8 regval;
721 721
722 status = data->status[reg]; 722 status = data->status[reg];
@@ -725,7 +725,7 @@ static int pmbus_get_boolean(struct pmbus_data *data, int index, int *val)
725 725
726 regval = status & mask; 726 regval = status & mask;
727 if (!s1 && !s2) 727 if (!s1 && !s2)
728 *val = !!regval; 728 ret = !!regval;
729 else { 729 else {
730 long v1, v2; 730 long v1, v2;
731 struct pmbus_sensor *sensor1, *sensor2; 731 struct pmbus_sensor *sensor1, *sensor2;
@@ -739,9 +739,9 @@ static int pmbus_get_boolean(struct pmbus_data *data, int index, int *val)
739 739
740 v1 = pmbus_reg2data(data, sensor1); 740 v1 = pmbus_reg2data(data, sensor1);
741 v2 = pmbus_reg2data(data, sensor2); 741 v2 = pmbus_reg2data(data, sensor2);
742 *val = !!(regval && v1 >= v2); 742 ret = !!(regval && v1 >= v2);
743 } 743 }
744 return 0; 744 return ret;
745} 745}
746 746
747static ssize_t pmbus_show_boolean(struct device *dev, 747static ssize_t pmbus_show_boolean(struct device *dev,
@@ -750,11 +750,10 @@ static ssize_t pmbus_show_boolean(struct device *dev,
750 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 750 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
751 struct pmbus_data *data = pmbus_update_device(dev); 751 struct pmbus_data *data = pmbus_update_device(dev);
752 int val; 752 int val;
753 int err;
754 753
755 err = pmbus_get_boolean(data, attr->index, &val); 754 val = pmbus_get_boolean(data, attr->index);
756 if (err) 755 if (val < 0)
757 return err; 756 return val;
758 return snprintf(buf, PAGE_SIZE, "%d\n", val); 757 return snprintf(buf, PAGE_SIZE, "%d\n", val);
759} 758}
760 759
diff --git a/drivers/hwmon/smsc47b397.c b/drivers/hwmon/smsc47b397.c
index d3b778da3f86..c5f6be478bad 100644
--- a/drivers/hwmon/smsc47b397.c
+++ b/drivers/hwmon/smsc47b397.c
@@ -343,10 +343,11 @@ exit:
343 return err; 343 return err;
344} 344}
345 345
346static int __init smsc47b397_find(unsigned short *addr) 346static int __init smsc47b397_find(void)
347{ 347{
348 u8 id, rev; 348 u8 id, rev;
349 char *name; 349 char *name;
350 unsigned short addr;
350 351
351 superio_enter(); 352 superio_enter();
352 id = force_id ? force_id : superio_inb(SUPERIO_REG_DEVID); 353 id = force_id ? force_id : superio_inb(SUPERIO_REG_DEVID);
@@ -370,14 +371,14 @@ static int __init smsc47b397_find(unsigned short *addr)
370 rev = superio_inb(SUPERIO_REG_DEVREV); 371 rev = superio_inb(SUPERIO_REG_DEVREV);
371 372
372 superio_select(SUPERIO_REG_LD8); 373 superio_select(SUPERIO_REG_LD8);
373 *addr = (superio_inb(SUPERIO_REG_BASE_MSB) << 8) 374 addr = (superio_inb(SUPERIO_REG_BASE_MSB) << 8)
374 | superio_inb(SUPERIO_REG_BASE_LSB); 375 | superio_inb(SUPERIO_REG_BASE_LSB);
375 376
376 pr_info("found SMSC %s (base address 0x%04x, revision %u)\n", 377 pr_info("found SMSC %s (base address 0x%04x, revision %u)\n",
377 name, *addr, rev); 378 name, addr, rev);
378 379
379 superio_exit(); 380 superio_exit();
380 return 0; 381 return addr;
381} 382}
382 383
383static int __init smsc47b397_init(void) 384static int __init smsc47b397_init(void)
@@ -385,9 +386,10 @@ static int __init smsc47b397_init(void)
385 unsigned short address; 386 unsigned short address;
386 int ret; 387 int ret;
387 388
388 ret = smsc47b397_find(&address); 389 ret = smsc47b397_find();
389 if (ret) 390 if (ret < 0)
390 return ret; 391 return ret;
392 address = ret;
391 393
392 ret = platform_driver_register(&smsc47b397_driver); 394 ret = platform_driver_register(&smsc47b397_driver);
393 if (ret) 395 if (ret)
diff --git a/drivers/hwmon/smsc47m1.c b/drivers/hwmon/smsc47m1.c
index c590c1469793..b5aa38dd7ab9 100644
--- a/drivers/hwmon/smsc47m1.c
+++ b/drivers/hwmon/smsc47m1.c
@@ -491,10 +491,10 @@ static const struct attribute_group smsc47m1_group = {
491 .attrs = smsc47m1_attributes, 491 .attrs = smsc47m1_attributes,
492}; 492};
493 493
494static int __init smsc47m1_find(unsigned short *addr, 494static int __init smsc47m1_find(struct smsc47m1_sio_data *sio_data)
495 struct smsc47m1_sio_data *sio_data)
496{ 495{
497 u8 val; 496 u8 val;
497 unsigned short addr;
498 498
499 superio_enter(); 499 superio_enter();
500 val = force_id ? force_id : superio_inb(SUPERIO_REG_DEVID); 500 val = force_id ? force_id : superio_inb(SUPERIO_REG_DEVID);
@@ -546,9 +546,9 @@ static int __init smsc47m1_find(unsigned short *addr,
546 } 546 }
547 547
548 superio_select(); 548 superio_select();
549 *addr = (superio_inb(SUPERIO_REG_BASE) << 8) 549 addr = (superio_inb(SUPERIO_REG_BASE) << 8)
550 | superio_inb(SUPERIO_REG_BASE + 1); 550 | superio_inb(SUPERIO_REG_BASE + 1);
551 if (*addr == 0) { 551 if (addr == 0) {
552 pr_info("Device address not set, will not use\n"); 552 pr_info("Device address not set, will not use\n");
553 superio_exit(); 553 superio_exit();
554 return -ENODEV; 554 return -ENODEV;
@@ -565,7 +565,7 @@ static int __init smsc47m1_find(unsigned short *addr,
565 } 565 }
566 566
567 superio_exit(); 567 superio_exit();
568 return 0; 568 return addr;
569} 569}
570 570
571/* Restore device to its initial state */ 571/* Restore device to its initial state */
@@ -938,13 +938,15 @@ static int __init sm_smsc47m1_init(void)
938 unsigned short address; 938 unsigned short address;
939 struct smsc47m1_sio_data sio_data; 939 struct smsc47m1_sio_data sio_data;
940 940
941 if (smsc47m1_find(&address, &sio_data)) 941 err = smsc47m1_find(&sio_data);
942 return -ENODEV; 942 if (err < 0)
943 return err;
944 address = err;
943 945
944 /* Sets global pdev as a side effect */ 946 /* Sets global pdev as a side effect */
945 err = smsc47m1_device_add(address, &sio_data); 947 err = smsc47m1_device_add(address, &sio_data);
946 if (err) 948 if (err)
947 goto exit; 949 return err;
948 950
949 err = platform_driver_probe(&smsc47m1_driver, smsc47m1_probe); 951 err = platform_driver_probe(&smsc47m1_driver, smsc47m1_probe);
950 if (err) 952 if (err)
@@ -955,7 +957,6 @@ static int __init sm_smsc47m1_init(void)
955exit_device: 957exit_device:
956 platform_device_unregister(pdev); 958 platform_device_unregister(pdev);
957 smsc47m1_restore(&sio_data); 959 smsc47m1_restore(&sio_data);
958exit:
959 return err; 960 return err;
960} 961}
961 962
diff --git a/drivers/hwmon/w83627ehf.c b/drivers/hwmon/w83627ehf.c
index a25350cf9554..54922ed12978 100644
--- a/drivers/hwmon/w83627ehf.c
+++ b/drivers/hwmon/w83627ehf.c
@@ -2619,15 +2619,15 @@ static struct platform_driver w83627ehf_driver = {
2619static int __init w83627ehf_find(int sioaddr, unsigned short *addr, 2619static int __init w83627ehf_find(int sioaddr, unsigned short *addr,
2620 struct w83627ehf_sio_data *sio_data) 2620 struct w83627ehf_sio_data *sio_data)
2621{ 2621{
2622 static const char __initdata sio_name_W83627EHF[] = "W83627EHF"; 2622 static const char sio_name_W83627EHF[] __initconst = "W83627EHF";
2623 static const char __initdata sio_name_W83627EHG[] = "W83627EHG"; 2623 static const char sio_name_W83627EHG[] __initconst = "W83627EHG";
2624 static const char __initdata sio_name_W83627DHG[] = "W83627DHG"; 2624 static const char sio_name_W83627DHG[] __initconst = "W83627DHG";
2625 static const char __initdata sio_name_W83627DHG_P[] = "W83627DHG-P"; 2625 static const char sio_name_W83627DHG_P[] __initconst = "W83627DHG-P";
2626 static const char __initdata sio_name_W83627UHG[] = "W83627UHG"; 2626 static const char sio_name_W83627UHG[] __initconst = "W83627UHG";
2627 static const char __initdata sio_name_W83667HG[] = "W83667HG"; 2627 static const char sio_name_W83667HG[] __initconst = "W83667HG";
2628 static const char __initdata sio_name_W83667HG_B[] = "W83667HG-B"; 2628 static const char sio_name_W83667HG_B[] __initconst = "W83667HG-B";
2629 static const char __initdata sio_name_NCT6775[] = "NCT6775F"; 2629 static const char sio_name_NCT6775[] __initconst = "NCT6775F";
2630 static const char __initdata sio_name_NCT6776[] = "NCT6776F"; 2630 static const char sio_name_NCT6776[] __initconst = "NCT6776F";
2631 2631
2632 u16 val; 2632 u16 val;
2633 const char *sio_name; 2633 const char *sio_name;
diff --git a/drivers/i2c/busses/i2c-designware-pcidrv.c b/drivers/i2c/busses/i2c-designware-pcidrv.c
index 37f42113af31..00e8f213f56e 100644
--- a/drivers/i2c/busses/i2c-designware-pcidrv.c
+++ b/drivers/i2c/busses/i2c-designware-pcidrv.c
@@ -182,7 +182,6 @@ static int i2c_dw_pci_resume(struct device *dev)
182 pci_restore_state(pdev); 182 pci_restore_state(pdev);
183 183
184 i2c_dw_init(i2c); 184 i2c_dw_init(i2c);
185 i2c_dw_enable(i2c);
186 return 0; 185 return 0;
187} 186}
188 187
diff --git a/drivers/i2c/busses/i2c-eg20t.c b/drivers/i2c/busses/i2c-eg20t.c
index f086131cb1c7..c811289b61e2 100644
--- a/drivers/i2c/busses/i2c-eg20t.c
+++ b/drivers/i2c/busses/i2c-eg20t.c
@@ -324,7 +324,7 @@ static s32 pch_i2c_wait_for_xfer_complete(struct i2c_algo_pch_data *adap)
324{ 324{
325 long ret; 325 long ret;
326 ret = wait_event_timeout(pch_event, 326 ret = wait_event_timeout(pch_event,
327 (adap->pch_event_flag != 0), msecs_to_jiffies(50)); 327 (adap->pch_event_flag != 0), msecs_to_jiffies(1000));
328 328
329 if (ret == 0) { 329 if (ret == 0) {
330 pch_err(adap, "timeout: %x\n", adap->pch_event_flag); 330 pch_err(adap, "timeout: %x\n", adap->pch_event_flag);
@@ -1063,6 +1063,6 @@ module_exit(pch_pci_exit);
1063 1063
1064MODULE_DESCRIPTION("Intel EG20T PCH/LAPIS Semico ML7213/ML7223/ML7831 IOH I2C"); 1064MODULE_DESCRIPTION("Intel EG20T PCH/LAPIS Semico ML7213/ML7223/ML7831 IOH I2C");
1065MODULE_LICENSE("GPL"); 1065MODULE_LICENSE("GPL");
1066MODULE_AUTHOR("Tomoya MORINAGA. <tomoya-linux@dsn.lapis-semi.com>"); 1066MODULE_AUTHOR("Tomoya MORINAGA. <tomoya.rohm@gmail.com>");
1067module_param(pch_i2c_speed, int, (S_IRUSR | S_IWUSR)); 1067module_param(pch_i2c_speed, int, (S_IRUSR | S_IWUSR));
1068module_param(pch_clk, int, (S_IRUSR | S_IWUSR)); 1068module_param(pch_clk, int, (S_IRUSR | S_IWUSR));
diff --git a/drivers/i2c/busses/i2c-mxs.c b/drivers/i2c/busses/i2c-mxs.c
index 3d471d56bf15..76b8af44f634 100644
--- a/drivers/i2c/busses/i2c-mxs.c
+++ b/drivers/i2c/busses/i2c-mxs.c
@@ -227,6 +227,7 @@ static int mxs_i2c_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg,
227 return -EINVAL; 227 return -EINVAL;
228 228
229 init_completion(&i2c->cmd_complete); 229 init_completion(&i2c->cmd_complete);
230 i2c->cmd_err = 0;
230 231
231 flags = stop ? MXS_I2C_CTRL0_POST_SEND_STOP : 0; 232 flags = stop ? MXS_I2C_CTRL0_POST_SEND_STOP : 0;
232 233
@@ -252,6 +253,9 @@ static int mxs_i2c_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg,
252 253
253 if (i2c->cmd_err == -ENXIO) 254 if (i2c->cmd_err == -ENXIO)
254 mxs_i2c_reset(i2c); 255 mxs_i2c_reset(i2c);
256 else
257 writel(MXS_I2C_QUEUECTRL_QUEUE_RUN,
258 i2c->regs + MXS_I2C_QUEUECTRL_CLR);
255 259
256 dev_dbg(i2c->dev, "Done with err=%d\n", i2c->cmd_err); 260 dev_dbg(i2c->dev, "Done with err=%d\n", i2c->cmd_err);
257 261
@@ -299,8 +303,6 @@ static irqreturn_t mxs_i2c_isr(int this_irq, void *dev_id)
299 MXS_I2C_CTRL1_SLAVE_STOP_IRQ | MXS_I2C_CTRL1_SLAVE_IRQ)) 303 MXS_I2C_CTRL1_SLAVE_STOP_IRQ | MXS_I2C_CTRL1_SLAVE_IRQ))
300 /* MXS_I2C_CTRL1_OVERSIZE_XFER_TERM_IRQ is only for slaves */ 304 /* MXS_I2C_CTRL1_OVERSIZE_XFER_TERM_IRQ is only for slaves */
301 i2c->cmd_err = -EIO; 305 i2c->cmd_err = -EIO;
302 else
303 i2c->cmd_err = 0;
304 306
305 is_last_cmd = (readl(i2c->regs + MXS_I2C_QUEUESTAT) & 307 is_last_cmd = (readl(i2c->regs + MXS_I2C_QUEUESTAT) &
306 MXS_I2C_QUEUESTAT_WRITE_QUEUE_CNT_MASK) == 0; 308 MXS_I2C_QUEUESTAT_WRITE_QUEUE_CNT_MASK) == 0;
@@ -384,8 +386,6 @@ static int __devexit mxs_i2c_remove(struct platform_device *pdev)
384 if (ret) 386 if (ret)
385 return -EBUSY; 387 return -EBUSY;
386 388
387 writel(MXS_I2C_QUEUECTRL_QUEUE_RUN,
388 i2c->regs + MXS_I2C_QUEUECTRL_CLR);
389 writel(MXS_I2C_CTRL0_SFTRST, i2c->regs + MXS_I2C_CTRL0_SET); 389 writel(MXS_I2C_CTRL0_SFTRST, i2c->regs + MXS_I2C_CTRL0_SET);
390 390
391 platform_set_drvdata(pdev, NULL); 391 platform_set_drvdata(pdev, NULL);
diff --git a/drivers/i2c/busses/i2c-pnx.c b/drivers/i2c/busses/i2c-pnx.c
index 04be9f82e14b..eb8ad538c79f 100644
--- a/drivers/i2c/busses/i2c-pnx.c
+++ b/drivers/i2c/busses/i2c-pnx.c
@@ -546,8 +546,7 @@ static int i2c_pnx_controller_suspend(struct platform_device *pdev,
546{ 546{
547 struct i2c_pnx_algo_data *alg_data = platform_get_drvdata(pdev); 547 struct i2c_pnx_algo_data *alg_data = platform_get_drvdata(pdev);
548 548
549 /* FIXME: shouldn't this be clk_disable? */ 549 clk_disable(alg_data->clk);
550 clk_enable(alg_data->clk);
551 550
552 return 0; 551 return 0;
553} 552}
diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c
index e978635e60f0..55e5ea62ccee 100644
--- a/drivers/i2c/busses/i2c-tegra.c
+++ b/drivers/i2c/busses/i2c-tegra.c
@@ -516,6 +516,14 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev,
516 if (likely(i2c_dev->msg_err == I2C_ERR_NONE)) 516 if (likely(i2c_dev->msg_err == I2C_ERR_NONE))
517 return 0; 517 return 0;
518 518
519 /*
520 * NACK interrupt is generated before the I2C controller generates the
521 * STOP condition on the bus. So wait for 2 clock periods before resetting
522 * the controller so that STOP condition has been delivered properly.
523 */
524 if (i2c_dev->msg_err == I2C_ERR_NO_ACK)
525 udelay(DIV_ROUND_UP(2 * 1000000, i2c_dev->bus_clk_rate));
526
519 tegra_i2c_init(i2c_dev); 527 tegra_i2c_init(i2c_dev);
520 if (i2c_dev->msg_err == I2C_ERR_NO_ACK) { 528 if (i2c_dev->msg_err == I2C_ERR_NO_ACK) {
521 if (msg->flags & I2C_M_IGNORE_NAK) 529 if (msg->flags & I2C_M_IGNORE_NAK)
diff --git a/drivers/idle/i7300_idle.c b/drivers/idle/i7300_idle.c
index c976285d313e..fa080ebd568f 100644
--- a/drivers/idle/i7300_idle.c
+++ b/drivers/idle/i7300_idle.c
@@ -516,12 +516,6 @@ static struct notifier_block i7300_idle_nb = {
516 516
517MODULE_DEVICE_TABLE(pci, pci_tbl); 517MODULE_DEVICE_TABLE(pci, pci_tbl);
518 518
519int stats_open_generic(struct inode *inode, struct file *fp)
520{
521 fp->private_data = inode->i_private;
522 return 0;
523}
524
525static ssize_t stats_read_ul(struct file *fp, char __user *ubuf, size_t count, 519static ssize_t stats_read_ul(struct file *fp, char __user *ubuf, size_t count,
526 loff_t *off) 520 loff_t *off)
527{ 521{
@@ -534,7 +528,7 @@ static ssize_t stats_read_ul(struct file *fp, char __user *ubuf, size_t count,
534} 528}
535 529
536static const struct file_operations idle_fops = { 530static const struct file_operations idle_fops = {
537 .open = stats_open_generic, 531 .open = simple_open,
538 .read = stats_read_ul, 532 .read = stats_read_ul,
539 .llseek = default_llseek, 533 .llseek = default_llseek,
540}; 534};
diff --git a/drivers/infiniband/core/mad.c b/drivers/infiniband/core/mad.c
index 426bb7617ec6..b0d0bc8a6fb6 100644
--- a/drivers/infiniband/core/mad.c
+++ b/drivers/infiniband/core/mad.c
@@ -1854,6 +1854,8 @@ static bool generate_unmatched_resp(struct ib_mad_private *recv,
1854 response->mad.mad.mad_hdr.method = IB_MGMT_METHOD_GET_RESP; 1854 response->mad.mad.mad_hdr.method = IB_MGMT_METHOD_GET_RESP;
1855 response->mad.mad.mad_hdr.status = 1855 response->mad.mad.mad_hdr.status =
1856 cpu_to_be16(IB_MGMT_MAD_STATUS_UNSUPPORTED_METHOD_ATTRIB); 1856 cpu_to_be16(IB_MGMT_MAD_STATUS_UNSUPPORTED_METHOD_ATTRIB);
1857 if (recv->mad.mad.mad_hdr.mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE)
1858 response->mad.mad.mad_hdr.status |= IB_SMP_DIRECTION;
1857 1859
1858 return true; 1860 return true;
1859 } else { 1861 } else {
@@ -1869,6 +1871,7 @@ static void ib_mad_recv_done_handler(struct ib_mad_port_private *port_priv,
1869 struct ib_mad_list_head *mad_list; 1871 struct ib_mad_list_head *mad_list;
1870 struct ib_mad_agent_private *mad_agent; 1872 struct ib_mad_agent_private *mad_agent;
1871 int port_num; 1873 int port_num;
1874 int ret = IB_MAD_RESULT_SUCCESS;
1872 1875
1873 mad_list = (struct ib_mad_list_head *)(unsigned long)wc->wr_id; 1876 mad_list = (struct ib_mad_list_head *)(unsigned long)wc->wr_id;
1874 qp_info = mad_list->mad_queue->qp_info; 1877 qp_info = mad_list->mad_queue->qp_info;
@@ -1952,8 +1955,6 @@ static void ib_mad_recv_done_handler(struct ib_mad_port_private *port_priv,
1952local: 1955local:
1953 /* Give driver "right of first refusal" on incoming MAD */ 1956 /* Give driver "right of first refusal" on incoming MAD */
1954 if (port_priv->device->process_mad) { 1957 if (port_priv->device->process_mad) {
1955 int ret;
1956
1957 ret = port_priv->device->process_mad(port_priv->device, 0, 1958 ret = port_priv->device->process_mad(port_priv->device, 0,
1958 port_priv->port_num, 1959 port_priv->port_num,
1959 wc, &recv->grh, 1960 wc, &recv->grh,
@@ -1981,7 +1982,8 @@ local:
1981 * or via recv_handler in ib_mad_complete_recv() 1982 * or via recv_handler in ib_mad_complete_recv()
1982 */ 1983 */
1983 recv = NULL; 1984 recv = NULL;
1984 } else if (generate_unmatched_resp(recv, response)) { 1985 } else if ((ret & IB_MAD_RESULT_SUCCESS) &&
1986 generate_unmatched_resp(recv, response)) {
1985 agent_send_response(&response->mad.mad, &recv->grh, wc, 1987 agent_send_response(&response->mad.mad, &recv->grh, wc,
1986 port_priv->device, port_num, qp_info->qp->qp_num); 1988 port_priv->device, port_num, qp_info->qp->qp_num);
1987 } 1989 }
diff --git a/drivers/infiniband/core/sysfs.c b/drivers/infiniband/core/sysfs.c
index 83b720ef6c34..246fdc151652 100644
--- a/drivers/infiniband/core/sysfs.c
+++ b/drivers/infiniband/core/sysfs.c
@@ -179,7 +179,7 @@ static ssize_t rate_show(struct ib_port *p, struct port_attribute *unused,
179{ 179{
180 struct ib_port_attr attr; 180 struct ib_port_attr attr;
181 char *speed = ""; 181 char *speed = "";
182 int rate = -1; /* in deci-Gb/sec */ 182 int rate; /* in deci-Gb/sec */
183 ssize_t ret; 183 ssize_t ret;
184 184
185 ret = ib_query_port(p->ibdev, p->port_num, &attr); 185 ret = ib_query_port(p->ibdev, p->port_num, &attr);
@@ -187,9 +187,6 @@ static ssize_t rate_show(struct ib_port *p, struct port_attribute *unused,
187 return ret; 187 return ret;
188 188
189 switch (attr.active_speed) { 189 switch (attr.active_speed) {
190 case IB_SPEED_SDR:
191 rate = 25;
192 break;
193 case IB_SPEED_DDR: 190 case IB_SPEED_DDR:
194 speed = " DDR"; 191 speed = " DDR";
195 rate = 50; 192 rate = 50;
@@ -210,6 +207,10 @@ static ssize_t rate_show(struct ib_port *p, struct port_attribute *unused,
210 speed = " EDR"; 207 speed = " EDR";
211 rate = 250; 208 rate = 250;
212 break; 209 break;
210 case IB_SPEED_SDR:
211 default: /* default to SDR for invalid rates */
212 rate = 25;
213 break;
213 } 214 }
214 215
215 rate *= ib_width_enum_to_int(attr.active_width); 216 rate *= ib_width_enum_to_int(attr.active_width);
diff --git a/drivers/infiniband/hw/mlx4/main.c b/drivers/infiniband/hw/mlx4/main.c
index 75d305629300..b948b6dd5d55 100644
--- a/drivers/infiniband/hw/mlx4/main.c
+++ b/drivers/infiniband/hw/mlx4/main.c
@@ -247,12 +247,17 @@ static int ib_link_query_port(struct ib_device *ibdev, u8 port,
247 err = mlx4_MAD_IFC(to_mdev(ibdev), 1, 1, port, 247 err = mlx4_MAD_IFC(to_mdev(ibdev), 1, 1, port,
248 NULL, NULL, in_mad, out_mad); 248 NULL, NULL, in_mad, out_mad);
249 if (err) 249 if (err)
250 return err; 250 goto out;
251 251
252 /* Checking LinkSpeedActive for FDR-10 */ 252 /* Checking LinkSpeedActive for FDR-10 */
253 if (out_mad->data[15] & 0x1) 253 if (out_mad->data[15] & 0x1)
254 props->active_speed = IB_SPEED_FDR10; 254 props->active_speed = IB_SPEED_FDR10;
255 } 255 }
256
257 /* Avoid wrong speed value returned by FW if the IB link is down. */
258 if (props->state == IB_PORT_DOWN)
259 props->active_speed = IB_SPEED_SDR;
260
256out: 261out:
257 kfree(in_mad); 262 kfree(in_mad);
258 kfree(out_mad); 263 kfree(out_mad);
diff --git a/drivers/infiniband/ulp/srpt/ib_srpt.c b/drivers/infiniband/ulp/srpt/ib_srpt.c
index 69e2ad06e515..daf21b899999 100644
--- a/drivers/infiniband/ulp/srpt/ib_srpt.c
+++ b/drivers/infiniband/ulp/srpt/ib_srpt.c
@@ -3232,6 +3232,7 @@ static void srpt_add_one(struct ib_device *device)
3232 srq_attr.attr.max_wr = sdev->srq_size; 3232 srq_attr.attr.max_wr = sdev->srq_size;
3233 srq_attr.attr.max_sge = 1; 3233 srq_attr.attr.max_sge = 1;
3234 srq_attr.attr.srq_limit = 0; 3234 srq_attr.attr.srq_limit = 0;
3235 srq_attr.srq_type = IB_SRQT_BASIC;
3235 3236
3236 sdev->srq = ib_create_srq(sdev->pd, &srq_attr); 3237 sdev->srq = ib_create_srq(sdev->pd, &srq_attr);
3237 if (IS_ERR(sdev->srq)) 3238 if (IS_ERR(sdev->srq))
diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index 2d787796bf50..7faf4a7fcaa9 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -380,8 +380,7 @@ config INPUT_TWL4030_VIBRA
380 380
381config INPUT_TWL6040_VIBRA 381config INPUT_TWL6040_VIBRA
382 tristate "Support for TWL6040 Vibrator" 382 tristate "Support for TWL6040 Vibrator"
383 depends on TWL4030_CORE 383 depends on TWL6040_CORE
384 select TWL6040_CORE
385 select INPUT_FF_MEMLESS 384 select INPUT_FF_MEMLESS
386 help 385 help
387 This option enables support for TWL6040 Vibrator Driver. 386 This option enables support for TWL6040 Vibrator Driver.
diff --git a/drivers/input/misc/da9052_onkey.c b/drivers/input/misc/da9052_onkey.c
index 34aebb8cd080..3c843cd725fa 100644
--- a/drivers/input/misc/da9052_onkey.c
+++ b/drivers/input/misc/da9052_onkey.c
@@ -95,7 +95,8 @@ static int __devinit da9052_onkey_probe(struct platform_device *pdev)
95 input_dev = input_allocate_device(); 95 input_dev = input_allocate_device();
96 if (!onkey || !input_dev) { 96 if (!onkey || !input_dev) {
97 dev_err(&pdev->dev, "Failed to allocate memory\n"); 97 dev_err(&pdev->dev, "Failed to allocate memory\n");
98 return -ENOMEM; 98 error = -ENOMEM;
99 goto err_free_mem;
99 } 100 }
100 101
101 onkey->input = input_dev; 102 onkey->input = input_dev;
diff --git a/drivers/input/misc/twl6040-vibra.c b/drivers/input/misc/twl6040-vibra.c
index 45874fed523a..14e94f56cb7d 100644
--- a/drivers/input/misc/twl6040-vibra.c
+++ b/drivers/input/misc/twl6040-vibra.c
@@ -28,7 +28,7 @@
28#include <linux/module.h> 28#include <linux/module.h>
29#include <linux/platform_device.h> 29#include <linux/platform_device.h>
30#include <linux/workqueue.h> 30#include <linux/workqueue.h>
31#include <linux/i2c/twl.h> 31#include <linux/input.h>
32#include <linux/mfd/twl6040.h> 32#include <linux/mfd/twl6040.h>
33#include <linux/slab.h> 33#include <linux/slab.h>
34#include <linux/delay.h> 34#include <linux/delay.h>
@@ -257,7 +257,7 @@ static SIMPLE_DEV_PM_OPS(twl6040_vibra_pm_ops, twl6040_vibra_suspend, NULL);
257 257
258static int __devinit twl6040_vibra_probe(struct platform_device *pdev) 258static int __devinit twl6040_vibra_probe(struct platform_device *pdev)
259{ 259{
260 struct twl4030_vibra_data *pdata = pdev->dev.platform_data; 260 struct twl6040_vibra_data *pdata = pdev->dev.platform_data;
261 struct vibra_info *info; 261 struct vibra_info *info;
262 int ret; 262 int ret;
263 263
diff --git a/drivers/input/mouse/elantech.c b/drivers/input/mouse/elantech.c
index d2c0db159b18..479011004a11 100644
--- a/drivers/input/mouse/elantech.c
+++ b/drivers/input/mouse/elantech.c
@@ -486,7 +486,6 @@ static void elantech_input_sync_v4(struct psmouse *psmouse)
486 unsigned char *packet = psmouse->packet; 486 unsigned char *packet = psmouse->packet;
487 487
488 input_report_key(dev, BTN_LEFT, packet[0] & 0x01); 488 input_report_key(dev, BTN_LEFT, packet[0] & 0x01);
489 input_report_key(dev, BTN_RIGHT, packet[0] & 0x02);
490 input_mt_report_pointer_emulation(dev, true); 489 input_mt_report_pointer_emulation(dev, true);
491 input_sync(dev); 490 input_sync(dev);
492} 491}
@@ -967,6 +966,7 @@ static int elantech_set_input_params(struct psmouse *psmouse)
967 if (elantech_set_range(psmouse, &x_min, &y_min, &x_max, &y_max, &width)) 966 if (elantech_set_range(psmouse, &x_min, &y_min, &x_max, &y_max, &width))
968 return -1; 967 return -1;
969 968
969 __set_bit(INPUT_PROP_POINTER, dev->propbit);
970 __set_bit(EV_KEY, dev->evbit); 970 __set_bit(EV_KEY, dev->evbit);
971 __set_bit(EV_ABS, dev->evbit); 971 __set_bit(EV_ABS, dev->evbit);
972 __clear_bit(EV_REL, dev->evbit); 972 __clear_bit(EV_REL, dev->evbit);
@@ -1017,7 +1017,9 @@ static int elantech_set_input_params(struct psmouse *psmouse)
1017 */ 1017 */
1018 psmouse_warn(psmouse, "couldn't query resolution data.\n"); 1018 psmouse_warn(psmouse, "couldn't query resolution data.\n");
1019 } 1019 }
1020 1020 /* v4 is clickpad, with only one button. */
1021 __set_bit(INPUT_PROP_BUTTONPAD, dev->propbit);
1022 __clear_bit(BTN_RIGHT, dev->keybit);
1021 __set_bit(BTN_TOOL_QUADTAP, dev->keybit); 1023 __set_bit(BTN_TOOL_QUADTAP, dev->keybit);
1022 /* For X to recognize me as touchpad. */ 1024 /* For X to recognize me as touchpad. */
1023 input_set_abs_params(dev, ABS_X, x_min, x_max, 0, 0); 1025 input_set_abs_params(dev, ABS_X, x_min, x_max, 0, 0);
@@ -1245,6 +1247,8 @@ static void elantech_disconnect(struct psmouse *psmouse)
1245 */ 1247 */
1246static int elantech_reconnect(struct psmouse *psmouse) 1248static int elantech_reconnect(struct psmouse *psmouse)
1247{ 1249{
1250 psmouse_reset(psmouse);
1251
1248 if (elantech_detect(psmouse, 0)) 1252 if (elantech_detect(psmouse, 0))
1249 return -1; 1253 return -1;
1250 1254
@@ -1324,6 +1328,8 @@ int elantech_init(struct psmouse *psmouse)
1324 if (!etd) 1328 if (!etd)
1325 return -ENOMEM; 1329 return -ENOMEM;
1326 1330
1331 psmouse_reset(psmouse);
1332
1327 etd->parity[0] = 1; 1333 etd->parity[0] = 1;
1328 for (i = 1; i < 256; i++) 1334 for (i = 1; i < 256; i++)
1329 etd->parity[i] = etd->parity[i & (i - 1)] ^ 1; 1335 etd->parity[i] = etd->parity[i & (i - 1)] ^ 1;
diff --git a/drivers/input/mouse/gpio_mouse.c b/drivers/input/mouse/gpio_mouse.c
index a9ad8e1402be..39fe9b737cae 100644
--- a/drivers/input/mouse/gpio_mouse.c
+++ b/drivers/input/mouse/gpio_mouse.c
@@ -12,9 +12,9 @@
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/platform_device.h> 13#include <linux/platform_device.h>
14#include <linux/input-polldev.h> 14#include <linux/input-polldev.h>
15#include <linux/gpio.h>
15#include <linux/gpio_mouse.h> 16#include <linux/gpio_mouse.h>
16 17
17#include <asm/gpio.h>
18 18
19/* 19/*
20 * Timer function which is run every scan_ms ms when the device is opened. 20 * Timer function which is run every scan_ms ms when the device is opened.
diff --git a/drivers/input/mouse/sentelic.c b/drivers/input/mouse/sentelic.c
index a977bfaa6821..661a0ca3b3d6 100644
--- a/drivers/input/mouse/sentelic.c
+++ b/drivers/input/mouse/sentelic.c
@@ -741,6 +741,14 @@ static psmouse_ret_t fsp_process_byte(struct psmouse *psmouse)
741 } 741 }
742 } else { 742 } else {
743 /* SFAC packet */ 743 /* SFAC packet */
744 if ((packet[0] & (FSP_PB0_LBTN|FSP_PB0_PHY_BTN)) ==
745 FSP_PB0_LBTN) {
746 /* On-pad click in SFAC mode should be handled
747 * by userspace. On-pad clicks in MFMC mode
748 * are real clickpad clicks, and not ignored.
749 */
750 packet[0] &= ~FSP_PB0_LBTN;
751 }
744 752
745 /* no multi-finger information */ 753 /* no multi-finger information */
746 ad->last_mt_fgr = 0; 754 ad->last_mt_fgr = 0;
diff --git a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c
index 8081a0a5d602..a4b14a41cbf4 100644
--- a/drivers/input/mouse/synaptics.c
+++ b/drivers/input/mouse/synaptics.c
@@ -274,7 +274,8 @@ static int synaptics_set_advanced_gesture_mode(struct psmouse *psmouse)
274 static unsigned char param = 0xc8; 274 static unsigned char param = 0xc8;
275 struct synaptics_data *priv = psmouse->private; 275 struct synaptics_data *priv = psmouse->private;
276 276
277 if (!SYN_CAP_ADV_GESTURE(priv->ext_cap_0c)) 277 if (!(SYN_CAP_ADV_GESTURE(priv->ext_cap_0c) ||
278 SYN_CAP_IMAGE_SENSOR(priv->ext_cap_0c)))
278 return 0; 279 return 0;
279 280
280 if (psmouse_sliced_command(psmouse, SYN_QUE_MODEL)) 281 if (psmouse_sliced_command(psmouse, SYN_QUE_MODEL))
diff --git a/drivers/input/mouse/trackpoint.c b/drivers/input/mouse/trackpoint.c
index 22b218018137..f3102494237d 100644
--- a/drivers/input/mouse/trackpoint.c
+++ b/drivers/input/mouse/trackpoint.c
@@ -304,7 +304,7 @@ int trackpoint_detect(struct psmouse *psmouse, bool set_properties)
304 return 0; 304 return 0;
305 305
306 if (trackpoint_read(&psmouse->ps2dev, TP_EXT_BTN, &button_info)) { 306 if (trackpoint_read(&psmouse->ps2dev, TP_EXT_BTN, &button_info)) {
307 printk(KERN_WARNING "trackpoint.c: failed to get extended button data\n"); 307 psmouse_warn(psmouse, "failed to get extended button data\n");
308 button_info = 0; 308 button_info = 0;
309 } 309 }
310 310
@@ -326,16 +326,18 @@ int trackpoint_detect(struct psmouse *psmouse, bool set_properties)
326 326
327 error = sysfs_create_group(&ps2dev->serio->dev.kobj, &trackpoint_attr_group); 327 error = sysfs_create_group(&ps2dev->serio->dev.kobj, &trackpoint_attr_group);
328 if (error) { 328 if (error) {
329 printk(KERN_ERR 329 psmouse_err(psmouse,
330 "trackpoint.c: failed to create sysfs attributes, error: %d\n", 330 "failed to create sysfs attributes, error: %d\n",
331 error); 331 error);
332 kfree(psmouse->private); 332 kfree(psmouse->private);
333 psmouse->private = NULL; 333 psmouse->private = NULL;
334 return -1; 334 return -1;
335 } 335 }
336 336
337 printk(KERN_INFO "IBM TrackPoint firmware: 0x%02x, buttons: %d/%d\n", 337 psmouse_info(psmouse,
338 firmware_id, (button_info & 0xf0) >> 4, button_info & 0x0f); 338 "IBM TrackPoint firmware: 0x%02x, buttons: %d/%d\n",
339 firmware_id,
340 (button_info & 0xf0) >> 4, button_info & 0x0f);
339 341
340 return 0; 342 return 0;
341} 343}
diff --git a/drivers/input/touchscreen/tps6507x-ts.c b/drivers/input/touchscreen/tps6507x-ts.c
index 6c6f6d8ea9b4..f7eda3d00fad 100644
--- a/drivers/input/touchscreen/tps6507x-ts.c
+++ b/drivers/input/touchscreen/tps6507x-ts.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * drivers/input/touchscreen/tps6507x_ts.c
3 *
4 * Touchscreen driver for the tps6507x chip. 2 * Touchscreen driver for the tps6507x chip.
5 * 3 *
6 * Copyright (c) 2009 RidgeRun (todd.fischer@ridgerun.com) 4 * Copyright (c) 2009 RidgeRun (todd.fischer@ridgerun.com)
@@ -376,4 +374,4 @@ module_platform_driver(tps6507x_ts_driver);
376MODULE_AUTHOR("Todd Fischer <todd.fischer@ridgerun.com>"); 374MODULE_AUTHOR("Todd Fischer <todd.fischer@ridgerun.com>");
377MODULE_DESCRIPTION("TPS6507x - TouchScreen driver"); 375MODULE_DESCRIPTION("TPS6507x - TouchScreen driver");
378MODULE_LICENSE("GPL v2"); 376MODULE_LICENSE("GPL v2");
379MODULE_ALIAS("platform:tps6507x-tsc"); 377MODULE_ALIAS("platform:tps6507x-ts");
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index ae2ec929e52f..a5bee8e2dfce 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -2707,7 +2707,8 @@ static void unmap_sg(struct device *dev, struct scatterlist *sglist,
2707 * The exported alloc_coherent function for dma_ops. 2707 * The exported alloc_coherent function for dma_ops.
2708 */ 2708 */
2709static void *alloc_coherent(struct device *dev, size_t size, 2709static void *alloc_coherent(struct device *dev, size_t size,
2710 dma_addr_t *dma_addr, gfp_t flag) 2710 dma_addr_t *dma_addr, gfp_t flag,
2711 struct dma_attrs *attrs)
2711{ 2712{
2712 unsigned long flags; 2713 unsigned long flags;
2713 void *virt_addr; 2714 void *virt_addr;
@@ -2765,7 +2766,8 @@ out_free:
2765 * The exported free_coherent function for dma_ops. 2766 * The exported free_coherent function for dma_ops.
2766 */ 2767 */
2767static void free_coherent(struct device *dev, size_t size, 2768static void free_coherent(struct device *dev, size_t size,
2768 void *virt_addr, dma_addr_t dma_addr) 2769 void *virt_addr, dma_addr_t dma_addr,
2770 struct dma_attrs *attrs)
2769{ 2771{
2770 unsigned long flags; 2772 unsigned long flags;
2771 struct protection_domain *domain; 2773 struct protection_domain *domain;
@@ -2846,8 +2848,8 @@ static void __init prealloc_protection_domains(void)
2846} 2848}
2847 2849
2848static struct dma_map_ops amd_iommu_dma_ops = { 2850static struct dma_map_ops amd_iommu_dma_ops = {
2849 .alloc_coherent = alloc_coherent, 2851 .alloc = alloc_coherent,
2850 .free_coherent = free_coherent, 2852 .free = free_coherent,
2851 .map_page = map_page, 2853 .map_page = map_page,
2852 .unmap_page = unmap_page, 2854 .unmap_page = unmap_page,
2853 .map_sg = map_sg, 2855 .map_sg = map_sg,
diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index 132f93b05154..f93d5ac8f81c 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -2949,7 +2949,8 @@ static void intel_unmap_page(struct device *dev, dma_addr_t dev_addr,
2949} 2949}
2950 2950
2951static void *intel_alloc_coherent(struct device *hwdev, size_t size, 2951static void *intel_alloc_coherent(struct device *hwdev, size_t size,
2952 dma_addr_t *dma_handle, gfp_t flags) 2952 dma_addr_t *dma_handle, gfp_t flags,
2953 struct dma_attrs *attrs)
2953{ 2954{
2954 void *vaddr; 2955 void *vaddr;
2955 int order; 2956 int order;
@@ -2981,7 +2982,7 @@ static void *intel_alloc_coherent(struct device *hwdev, size_t size,
2981} 2982}
2982 2983
2983static void intel_free_coherent(struct device *hwdev, size_t size, void *vaddr, 2984static void intel_free_coherent(struct device *hwdev, size_t size, void *vaddr,
2984 dma_addr_t dma_handle) 2985 dma_addr_t dma_handle, struct dma_attrs *attrs)
2985{ 2986{
2986 int order; 2987 int order;
2987 2988
@@ -3126,8 +3127,8 @@ static int intel_mapping_error(struct device *dev, dma_addr_t dma_addr)
3126} 3127}
3127 3128
3128struct dma_map_ops intel_dma_ops = { 3129struct dma_map_ops intel_dma_ops = {
3129 .alloc_coherent = intel_alloc_coherent, 3130 .alloc = intel_alloc_coherent,
3130 .free_coherent = intel_free_coherent, 3131 .free = intel_free_coherent,
3131 .map_sg = intel_map_sg, 3132 .map_sg = intel_map_sg,
3132 .unmap_sg = intel_unmap_sg, 3133 .unmap_sg = intel_unmap_sg,
3133 .map_page = intel_map_page, 3134 .map_page = intel_map_page,
diff --git a/drivers/iommu/omap-iommu-debug.c b/drivers/iommu/omap-iommu-debug.c
index 103dbd92e256..f55fc5dfbadc 100644
--- a/drivers/iommu/omap-iommu-debug.c
+++ b/drivers/iommu/omap-iommu-debug.c
@@ -323,15 +323,9 @@ err_out:
323 return count; 323 return count;
324} 324}
325 325
326static int debug_open_generic(struct inode *inode, struct file *file)
327{
328 file->private_data = inode->i_private;
329 return 0;
330}
331
332#define DEBUG_FOPS(name) \ 326#define DEBUG_FOPS(name) \
333 static const struct file_operations debug_##name##_fops = { \ 327 static const struct file_operations debug_##name##_fops = { \
334 .open = debug_open_generic, \ 328 .open = simple_open, \
335 .read = debug_read_##name, \ 329 .read = debug_read_##name, \
336 .write = debug_write_##name, \ 330 .write = debug_write_##name, \
337 .llseek = generic_file_llseek, \ 331 .llseek = generic_file_llseek, \
@@ -339,7 +333,7 @@ static int debug_open_generic(struct inode *inode, struct file *file)
339 333
340#define DEBUG_FOPS_RO(name) \ 334#define DEBUG_FOPS_RO(name) \
341 static const struct file_operations debug_##name##_fops = { \ 335 static const struct file_operations debug_##name##_fops = { \
342 .open = debug_open_generic, \ 336 .open = simple_open, \
343 .read = debug_read_##name, \ 337 .read = debug_read_##name, \
344 .llseek = generic_file_llseek, \ 338 .llseek = generic_file_llseek, \
345 }; 339 };
diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
index b3d6ac17272d..a6d9fd2858f7 100644
--- a/drivers/isdn/gigaset/interface.c
+++ b/drivers/isdn/gigaset/interface.c
@@ -176,7 +176,7 @@ static void if_close(struct tty_struct *tty, struct file *filp)
176 struct cardstate *cs = tty->driver_data; 176 struct cardstate *cs = tty->driver_data;
177 177
178 if (!cs) { /* happens if we didn't find cs in open */ 178 if (!cs) { /* happens if we didn't find cs in open */
179 printk(KERN_DEBUG "%s: no cardstate\n", __func__); 179 gig_dbg(DEBUG_IF, "%s: no cardstate", __func__);
180 return; 180 return;
181 } 181 }
182 182
diff --git a/drivers/isdn/hardware/mISDN/avmfritz.c b/drivers/isdn/hardware/mISDN/avmfritz.c
index 05ed4d0cb18b..c0b8c960ee3f 100644
--- a/drivers/isdn/hardware/mISDN/avmfritz.c
+++ b/drivers/isdn/hardware/mISDN/avmfritz.c
@@ -891,7 +891,7 @@ open_bchannel(struct fritzcard *fc, struct channel_req *rq)
891{ 891{
892 struct bchannel *bch; 892 struct bchannel *bch;
893 893
894 if (rq->adr.channel > 2) 894 if (rq->adr.channel == 0 || rq->adr.channel > 2)
895 return -EINVAL; 895 return -EINVAL;
896 if (rq->protocol == ISDN_P_NONE) 896 if (rq->protocol == ISDN_P_NONE)
897 return -EINVAL; 897 return -EINVAL;
diff --git a/drivers/isdn/hardware/mISDN/hfcpci.c b/drivers/isdn/hardware/mISDN/hfcpci.c
index d055ae7fa040..e2c83a2d7691 100644
--- a/drivers/isdn/hardware/mISDN/hfcpci.c
+++ b/drivers/isdn/hardware/mISDN/hfcpci.c
@@ -1962,7 +1962,7 @@ open_bchannel(struct hfc_pci *hc, struct channel_req *rq)
1962{ 1962{
1963 struct bchannel *bch; 1963 struct bchannel *bch;
1964 1964
1965 if (rq->adr.channel > 2) 1965 if (rq->adr.channel == 0 || rq->adr.channel > 2)
1966 return -EINVAL; 1966 return -EINVAL;
1967 if (rq->protocol == ISDN_P_NONE) 1967 if (rq->protocol == ISDN_P_NONE)
1968 return -EINVAL; 1968 return -EINVAL;
diff --git a/drivers/isdn/hardware/mISDN/hfcsusb.c b/drivers/isdn/hardware/mISDN/hfcsusb.c
index 602338734634..8cde2a0538ab 100644
--- a/drivers/isdn/hardware/mISDN/hfcsusb.c
+++ b/drivers/isdn/hardware/mISDN/hfcsusb.c
@@ -486,7 +486,7 @@ open_bchannel(struct hfcsusb *hw, struct channel_req *rq)
486{ 486{
487 struct bchannel *bch; 487 struct bchannel *bch;
488 488
489 if (rq->adr.channel > 2) 489 if (rq->adr.channel == 0 || rq->adr.channel > 2)
490 return -EINVAL; 490 return -EINVAL;
491 if (rq->protocol == ISDN_P_NONE) 491 if (rq->protocol == ISDN_P_NONE)
492 return -EINVAL; 492 return -EINVAL;
diff --git a/drivers/isdn/hardware/mISDN/mISDNipac.c b/drivers/isdn/hardware/mISDN/mISDNipac.c
index b47e9bed2185..884369f09cad 100644
--- a/drivers/isdn/hardware/mISDN/mISDNipac.c
+++ b/drivers/isdn/hardware/mISDN/mISDNipac.c
@@ -1506,7 +1506,7 @@ open_bchannel(struct ipac_hw *ipac, struct channel_req *rq)
1506{ 1506{
1507 struct bchannel *bch; 1507 struct bchannel *bch;
1508 1508
1509 if (rq->adr.channel > 2) 1509 if (rq->adr.channel == 0 || rq->adr.channel > 2)
1510 return -EINVAL; 1510 return -EINVAL;
1511 if (rq->protocol == ISDN_P_NONE) 1511 if (rq->protocol == ISDN_P_NONE)
1512 return -EINVAL; 1512 return -EINVAL;
diff --git a/drivers/isdn/hardware/mISDN/mISDNisar.c b/drivers/isdn/hardware/mISDN/mISDNisar.c
index 10446ab404b5..9a6da6edcfa8 100644
--- a/drivers/isdn/hardware/mISDN/mISDNisar.c
+++ b/drivers/isdn/hardware/mISDN/mISDNisar.c
@@ -1670,7 +1670,7 @@ isar_open(struct isar_hw *isar, struct channel_req *rq)
1670{ 1670{
1671 struct bchannel *bch; 1671 struct bchannel *bch;
1672 1672
1673 if (rq->adr.channel > 2) 1673 if (rq->adr.channel == 0 || rq->adr.channel > 2)
1674 return -EINVAL; 1674 return -EINVAL;
1675 if (rq->protocol == ISDN_P_NONE) 1675 if (rq->protocol == ISDN_P_NONE)
1676 return -EINVAL; 1676 return -EINVAL;
diff --git a/drivers/isdn/hardware/mISDN/netjet.c b/drivers/isdn/hardware/mISDN/netjet.c
index dd6de9f7a8a3..c726e09d0981 100644
--- a/drivers/isdn/hardware/mISDN/netjet.c
+++ b/drivers/isdn/hardware/mISDN/netjet.c
@@ -860,7 +860,7 @@ open_bchannel(struct tiger_hw *card, struct channel_req *rq)
860{ 860{
861 struct bchannel *bch; 861 struct bchannel *bch;
862 862
863 if (rq->adr.channel > 2) 863 if (rq->adr.channel == 0 || rq->adr.channel > 2)
864 return -EINVAL; 864 return -EINVAL;
865 if (rq->protocol == ISDN_P_NONE) 865 if (rq->protocol == ISDN_P_NONE)
866 return -EINVAL; 866 return -EINVAL;
diff --git a/drivers/isdn/hardware/mISDN/w6692.c b/drivers/isdn/hardware/mISDN/w6692.c
index 7f1e7ba75cd1..2183357f0799 100644
--- a/drivers/isdn/hardware/mISDN/w6692.c
+++ b/drivers/isdn/hardware/mISDN/w6692.c
@@ -1015,7 +1015,7 @@ open_bchannel(struct w6692_hw *card, struct channel_req *rq)
1015{ 1015{
1016 struct bchannel *bch; 1016 struct bchannel *bch;
1017 1017
1018 if (rq->adr.channel > 2) 1018 if (rq->adr.channel == 0 || rq->adr.channel > 2)
1019 return -EINVAL; 1019 return -EINVAL;
1020 if (rq->protocol == ISDN_P_NONE) 1020 if (rq->protocol == ISDN_P_NONE)
1021 return -EINVAL; 1021 return -EINVAL;
diff --git a/drivers/leds/leds-atmel-pwm.c b/drivers/leds/leds-atmel-pwm.c
index 800243b6037e..64ad702a2ecc 100644
--- a/drivers/leds/leds-atmel-pwm.c
+++ b/drivers/leds/leds-atmel-pwm.c
@@ -35,7 +35,7 @@ static void pwmled_brightness(struct led_classdev *cdev, enum led_brightness b)
35 * NOTE: we reuse the platform_data structure of GPIO leds, 35 * NOTE: we reuse the platform_data structure of GPIO leds,
36 * but repurpose its "gpio" number as a PWM channel number. 36 * but repurpose its "gpio" number as a PWM channel number.
37 */ 37 */
38static int __init pwmled_probe(struct platform_device *pdev) 38static int __devinit pwmled_probe(struct platform_device *pdev)
39{ 39{
40 const struct gpio_led_platform_data *pdata; 40 const struct gpio_led_platform_data *pdata;
41 struct pwmled *leds; 41 struct pwmled *leds;
diff --git a/drivers/leds/leds-netxbig.c b/drivers/leds/leds-netxbig.c
index d8433f2d53bc..73973fdbd8be 100644
--- a/drivers/leds/leds-netxbig.c
+++ b/drivers/leds/leds-netxbig.c
@@ -112,7 +112,7 @@ err_free_addr:
112 return err; 112 return err;
113} 113}
114 114
115static void __devexit gpio_ext_free(struct netxbig_gpio_ext *gpio_ext) 115static void gpio_ext_free(struct netxbig_gpio_ext *gpio_ext)
116{ 116{
117 int i; 117 int i;
118 118
@@ -294,7 +294,7 @@ static ssize_t netxbig_led_sata_show(struct device *dev,
294 294
295static DEVICE_ATTR(sata, 0644, netxbig_led_sata_show, netxbig_led_sata_store); 295static DEVICE_ATTR(sata, 0644, netxbig_led_sata_show, netxbig_led_sata_store);
296 296
297static void __devexit delete_netxbig_led(struct netxbig_led_data *led_dat) 297static void delete_netxbig_led(struct netxbig_led_data *led_dat)
298{ 298{
299 if (led_dat->mode_val[NETXBIG_LED_SATA] != NETXBIG_LED_INVALID_MODE) 299 if (led_dat->mode_val[NETXBIG_LED_SATA] != NETXBIG_LED_INVALID_MODE)
300 device_remove_file(led_dat->cdev.dev, &dev_attr_sata); 300 device_remove_file(led_dat->cdev.dev, &dev_attr_sata);
diff --git a/drivers/leds/leds-ns2.c b/drivers/leds/leds-ns2.c
index 2f0a14421a73..01cf89ec6944 100644
--- a/drivers/leds/leds-ns2.c
+++ b/drivers/leds/leds-ns2.c
@@ -255,7 +255,7 @@ err_free_cmd:
255 return ret; 255 return ret;
256} 256}
257 257
258static void __devexit delete_ns2_led(struct ns2_led_data *led_dat) 258static void delete_ns2_led(struct ns2_led_data *led_dat)
259{ 259{
260 device_remove_file(led_dat->cdev.dev, &dev_attr_sata); 260 device_remove_file(led_dat->cdev.dev, &dev_attr_sata);
261 led_classdev_unregister(&led_dat->cdev); 261 led_classdev_unregister(&led_dat->cdev);
diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
index 3d0dfa7a89a2..17e2b472e16d 100644
--- a/drivers/md/bitmap.c
+++ b/drivers/md/bitmap.c
@@ -539,9 +539,6 @@ static int bitmap_new_disk_sb(struct bitmap *bitmap)
539 bitmap->events_cleared = bitmap->mddev->events; 539 bitmap->events_cleared = bitmap->mddev->events;
540 sb->events_cleared = cpu_to_le64(bitmap->mddev->events); 540 sb->events_cleared = cpu_to_le64(bitmap->mddev->events);
541 541
542 bitmap->flags |= BITMAP_HOSTENDIAN;
543 sb->version = cpu_to_le32(BITMAP_MAJOR_HOSTENDIAN);
544
545 kunmap_atomic(sb); 542 kunmap_atomic(sb);
546 543
547 return 0; 544 return 0;
@@ -1730,8 +1727,7 @@ int bitmap_create(struct mddev *mddev)
1730 bitmap->chunkshift = (ffz(~mddev->bitmap_info.chunksize) 1727 bitmap->chunkshift = (ffz(~mddev->bitmap_info.chunksize)
1731 - BITMAP_BLOCK_SHIFT); 1728 - BITMAP_BLOCK_SHIFT);
1732 1729
1733 /* now that chunksize and chunkshift are set, we can use these macros */ 1730 chunks = (blocks + (1 << bitmap->chunkshift) - 1) >>
1734 chunks = (blocks + bitmap->chunkshift - 1) >>
1735 bitmap->chunkshift; 1731 bitmap->chunkshift;
1736 pages = (chunks + PAGE_COUNTER_RATIO - 1) / PAGE_COUNTER_RATIO; 1732 pages = (chunks + PAGE_COUNTER_RATIO - 1) / PAGE_COUNTER_RATIO;
1737 1733
@@ -1788,7 +1784,9 @@ int bitmap_load(struct mddev *mddev)
1788 * re-add of a missing device */ 1784 * re-add of a missing device */
1789 start = mddev->recovery_cp; 1785 start = mddev->recovery_cp;
1790 1786
1787 mutex_lock(&mddev->bitmap_info.mutex);
1791 err = bitmap_init_from_disk(bitmap, start); 1788 err = bitmap_init_from_disk(bitmap, start);
1789 mutex_unlock(&mddev->bitmap_info.mutex);
1792 1790
1793 if (err) 1791 if (err)
1794 goto out; 1792 goto out;
diff --git a/drivers/md/bitmap.h b/drivers/md/bitmap.h
index 55ca5aec84e4..b44b0aba2d47 100644
--- a/drivers/md/bitmap.h
+++ b/drivers/md/bitmap.h
@@ -101,9 +101,6 @@ typedef __u16 bitmap_counter_t;
101 101
102#define BITMAP_BLOCK_SHIFT 9 102#define BITMAP_BLOCK_SHIFT 9
103 103
104/* how many blocks per chunk? (this is variable) */
105#define CHUNK_BLOCK_RATIO(bitmap) ((bitmap)->mddev->bitmap_info.chunksize >> BITMAP_BLOCK_SHIFT)
106
107#endif 104#endif
108 105
109/* 106/*
diff --git a/drivers/md/dm-log-userspace-transfer.c b/drivers/md/dm-log-userspace-transfer.c
index 1f23e048f077..08d9a207259a 100644
--- a/drivers/md/dm-log-userspace-transfer.c
+++ b/drivers/md/dm-log-userspace-transfer.c
@@ -134,7 +134,7 @@ static void cn_ulog_callback(struct cn_msg *msg, struct netlink_skb_parms *nsp)
134{ 134{
135 struct dm_ulog_request *tfr = (struct dm_ulog_request *)(msg + 1); 135 struct dm_ulog_request *tfr = (struct dm_ulog_request *)(msg + 1);
136 136
137 if (!cap_raised(current_cap(), CAP_SYS_ADMIN)) 137 if (!capable(CAP_SYS_ADMIN))
138 return; 138 return;
139 139
140 spin_lock(&receiving_list_lock); 140 spin_lock(&receiving_list_lock);
diff --git a/drivers/md/dm-mpath.c b/drivers/md/dm-mpath.c
index 922a3385eead..754f38f8a692 100644
--- a/drivers/md/dm-mpath.c
+++ b/drivers/md/dm-mpath.c
@@ -718,8 +718,8 @@ static int parse_hw_handler(struct dm_arg_set *as, struct multipath *m)
718 return 0; 718 return 0;
719 719
720 m->hw_handler_name = kstrdup(dm_shift_arg(as), GFP_KERNEL); 720 m->hw_handler_name = kstrdup(dm_shift_arg(as), GFP_KERNEL);
721 request_module("scsi_dh_%s", m->hw_handler_name); 721 if (!try_then_request_module(scsi_dh_handler_exist(m->hw_handler_name),
722 if (scsi_dh_handler_exist(m->hw_handler_name) == 0) { 722 "scsi_dh_%s", m->hw_handler_name)) {
723 ti->error = "unknown hardware handler type"; 723 ti->error = "unknown hardware handler type";
724 ret = -EINVAL; 724 ret = -EINVAL;
725 goto fail; 725 goto fail;
diff --git a/drivers/md/dm-raid.c b/drivers/md/dm-raid.c
index b0ba52459ed7..68965e663248 100644
--- a/drivers/md/dm-raid.c
+++ b/drivers/md/dm-raid.c
@@ -859,7 +859,7 @@ static int analyse_superblocks(struct dm_target *ti, struct raid_set *rs)
859 int ret; 859 int ret;
860 unsigned redundancy = 0; 860 unsigned redundancy = 0;
861 struct raid_dev *dev; 861 struct raid_dev *dev;
862 struct md_rdev *rdev, *freshest; 862 struct md_rdev *rdev, *tmp, *freshest;
863 struct mddev *mddev = &rs->md; 863 struct mddev *mddev = &rs->md;
864 864
865 switch (rs->raid_type->level) { 865 switch (rs->raid_type->level) {
@@ -877,7 +877,7 @@ static int analyse_superblocks(struct dm_target *ti, struct raid_set *rs)
877 } 877 }
878 878
879 freshest = NULL; 879 freshest = NULL;
880 rdev_for_each(rdev, mddev) { 880 rdev_for_each_safe(rdev, tmp, mddev) {
881 if (!rdev->meta_bdev) 881 if (!rdev->meta_bdev)
882 continue; 882 continue;
883 883
diff --git a/drivers/md/dm-thin.c b/drivers/md/dm-thin.c
index 213ae32a0fc4..2fd87b544a93 100644
--- a/drivers/md/dm-thin.c
+++ b/drivers/md/dm-thin.c
@@ -279,8 +279,10 @@ static void __cell_release(struct cell *cell, struct bio_list *inmates)
279 279
280 hlist_del(&cell->list); 280 hlist_del(&cell->list);
281 281
282 bio_list_add(inmates, cell->holder); 282 if (inmates) {
283 bio_list_merge(inmates, &cell->bios); 283 bio_list_add(inmates, cell->holder);
284 bio_list_merge(inmates, &cell->bios);
285 }
284 286
285 mempool_free(cell, prison->cell_pool); 287 mempool_free(cell, prison->cell_pool);
286} 288}
@@ -303,9 +305,10 @@ static void cell_release(struct cell *cell, struct bio_list *bios)
303 */ 305 */
304static void __cell_release_singleton(struct cell *cell, struct bio *bio) 306static void __cell_release_singleton(struct cell *cell, struct bio *bio)
305{ 307{
306 hlist_del(&cell->list);
307 BUG_ON(cell->holder != bio); 308 BUG_ON(cell->holder != bio);
308 BUG_ON(!bio_list_empty(&cell->bios)); 309 BUG_ON(!bio_list_empty(&cell->bios));
310
311 __cell_release(cell, NULL);
309} 312}
310 313
311static void cell_release_singleton(struct cell *cell, struct bio *bio) 314static void cell_release_singleton(struct cell *cell, struct bio *bio)
@@ -1177,6 +1180,7 @@ static void no_space(struct cell *cell)
1177static void process_discard(struct thin_c *tc, struct bio *bio) 1180static void process_discard(struct thin_c *tc, struct bio *bio)
1178{ 1181{
1179 int r; 1182 int r;
1183 unsigned long flags;
1180 struct pool *pool = tc->pool; 1184 struct pool *pool = tc->pool;
1181 struct cell *cell, *cell2; 1185 struct cell *cell, *cell2;
1182 struct cell_key key, key2; 1186 struct cell_key key, key2;
@@ -1218,7 +1222,9 @@ static void process_discard(struct thin_c *tc, struct bio *bio)
1218 m->bio = bio; 1222 m->bio = bio;
1219 1223
1220 if (!ds_add_work(&pool->all_io_ds, &m->list)) { 1224 if (!ds_add_work(&pool->all_io_ds, &m->list)) {
1225 spin_lock_irqsave(&pool->lock, flags);
1221 list_add(&m->list, &pool->prepared_discards); 1226 list_add(&m->list, &pool->prepared_discards);
1227 spin_unlock_irqrestore(&pool->lock, flags);
1222 wake_worker(pool); 1228 wake_worker(pool);
1223 } 1229 }
1224 } else { 1230 } else {
@@ -2626,8 +2632,10 @@ static int thin_endio(struct dm_target *ti,
2626 if (h->all_io_entry) { 2632 if (h->all_io_entry) {
2627 INIT_LIST_HEAD(&work); 2633 INIT_LIST_HEAD(&work);
2628 ds_dec(h->all_io_entry, &work); 2634 ds_dec(h->all_io_entry, &work);
2635 spin_lock_irqsave(&pool->lock, flags);
2629 list_for_each_entry_safe(m, tmp, &work, list) 2636 list_for_each_entry_safe(m, tmp, &work, list)
2630 list_add(&m->list, &pool->prepared_discards); 2637 list_add(&m->list, &pool->prepared_discards);
2638 spin_unlock_irqrestore(&pool->lock, flags);
2631 } 2639 }
2632 2640
2633 mempool_free(h, pool->endio_hook_pool); 2641 mempool_free(h, pool->endio_hook_pool);
@@ -2759,6 +2767,6 @@ static void dm_thin_exit(void)
2759module_init(dm_thin_init); 2767module_init(dm_thin_init);
2760module_exit(dm_thin_exit); 2768module_exit(dm_thin_exit);
2761 2769
2762MODULE_DESCRIPTION(DM_NAME "device-mapper thin provisioning target"); 2770MODULE_DESCRIPTION(DM_NAME " thin provisioning target");
2763MODULE_AUTHOR("Joe Thornber <dm-devel@redhat.com>"); 2771MODULE_AUTHOR("Joe Thornber <dm-devel@redhat.com>");
2764MODULE_LICENSE("GPL"); 2772MODULE_LICENSE("GPL");
diff --git a/drivers/md/linear.c b/drivers/md/linear.c
index b0fcc7d02adb..fa211d80fc0a 100644
--- a/drivers/md/linear.c
+++ b/drivers/md/linear.c
@@ -198,6 +198,7 @@ out:
198static int linear_run (struct mddev *mddev) 198static int linear_run (struct mddev *mddev)
199{ 199{
200 struct linear_conf *conf; 200 struct linear_conf *conf;
201 int ret;
201 202
202 if (md_check_no_bitmap(mddev)) 203 if (md_check_no_bitmap(mddev))
203 return -EINVAL; 204 return -EINVAL;
@@ -211,7 +212,13 @@ static int linear_run (struct mddev *mddev)
211 blk_queue_merge_bvec(mddev->queue, linear_mergeable_bvec); 212 blk_queue_merge_bvec(mddev->queue, linear_mergeable_bvec);
212 mddev->queue->backing_dev_info.congested_fn = linear_congested; 213 mddev->queue->backing_dev_info.congested_fn = linear_congested;
213 mddev->queue->backing_dev_info.congested_data = mddev; 214 mddev->queue->backing_dev_info.congested_data = mddev;
214 return md_integrity_register(mddev); 215
216 ret = md_integrity_register(mddev);
217 if (ret) {
218 kfree(conf);
219 mddev->private = NULL;
220 }
221 return ret;
215} 222}
216 223
217static int linear_add(struct mddev *mddev, struct md_rdev *rdev) 224static int linear_add(struct mddev *mddev, struct md_rdev *rdev)
diff --git a/drivers/md/md.c b/drivers/md/md.c
index b572e1e386ce..477eb2e180c0 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -7560,14 +7560,14 @@ void md_check_recovery(struct mddev *mddev)
7560 * any transients in the value of "sync_action". 7560 * any transients in the value of "sync_action".
7561 */ 7561 */
7562 set_bit(MD_RECOVERY_RUNNING, &mddev->recovery); 7562 set_bit(MD_RECOVERY_RUNNING, &mddev->recovery);
7563 clear_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
7564 /* Clear some bits that don't mean anything, but 7563 /* Clear some bits that don't mean anything, but
7565 * might be left set 7564 * might be left set
7566 */ 7565 */
7567 clear_bit(MD_RECOVERY_INTR, &mddev->recovery); 7566 clear_bit(MD_RECOVERY_INTR, &mddev->recovery);
7568 clear_bit(MD_RECOVERY_DONE, &mddev->recovery); 7567 clear_bit(MD_RECOVERY_DONE, &mddev->recovery);
7569 7568
7570 if (test_bit(MD_RECOVERY_FROZEN, &mddev->recovery)) 7569 if (!test_and_clear_bit(MD_RECOVERY_NEEDED, &mddev->recovery) ||
7570 test_bit(MD_RECOVERY_FROZEN, &mddev->recovery))
7571 goto unlock; 7571 goto unlock;
7572 /* no recovery is running. 7572 /* no recovery is running.
7573 * remove any failed drives, then 7573 * remove any failed drives, then
@@ -8140,7 +8140,8 @@ static int md_notify_reboot(struct notifier_block *this,
8140 8140
8141 for_each_mddev(mddev, tmp) { 8141 for_each_mddev(mddev, tmp) {
8142 if (mddev_trylock(mddev)) { 8142 if (mddev_trylock(mddev)) {
8143 __md_stop_writes(mddev); 8143 if (mddev->pers)
8144 __md_stop_writes(mddev);
8144 mddev->safemode = 2; 8145 mddev->safemode = 2;
8145 mddev_unlock(mddev); 8146 mddev_unlock(mddev);
8146 } 8147 }
diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
index 6f31f5596e01..de63a1fc3737 100644
--- a/drivers/md/raid0.c
+++ b/drivers/md/raid0.c
@@ -407,6 +407,8 @@ static sector_t raid0_size(struct mddev *mddev, sector_t sectors, int raid_disks
407 return array_sectors; 407 return array_sectors;
408} 408}
409 409
410static int raid0_stop(struct mddev *mddev);
411
410static int raid0_run(struct mddev *mddev) 412static int raid0_run(struct mddev *mddev)
411{ 413{
412 struct r0conf *conf; 414 struct r0conf *conf;
@@ -454,7 +456,12 @@ static int raid0_run(struct mddev *mddev)
454 456
455 blk_queue_merge_bvec(mddev->queue, raid0_mergeable_bvec); 457 blk_queue_merge_bvec(mddev->queue, raid0_mergeable_bvec);
456 dump_zones(mddev); 458 dump_zones(mddev);
457 return md_integrity_register(mddev); 459
460 ret = md_integrity_register(mddev);
461 if (ret)
462 raid0_stop(mddev);
463
464 return ret;
458} 465}
459 466
460static int raid0_stop(struct mddev *mddev) 467static int raid0_stop(struct mddev *mddev)
@@ -625,6 +632,7 @@ static void *raid0_takeover_raid10(struct mddev *mddev)
625static void *raid0_takeover_raid1(struct mddev *mddev) 632static void *raid0_takeover_raid1(struct mddev *mddev)
626{ 633{
627 struct r0conf *priv_conf; 634 struct r0conf *priv_conf;
635 int chunksect;
628 636
629 /* Check layout: 637 /* Check layout:
630 * - (N - 1) mirror drives must be already faulty 638 * - (N - 1) mirror drives must be already faulty
@@ -635,10 +643,25 @@ static void *raid0_takeover_raid1(struct mddev *mddev)
635 return ERR_PTR(-EINVAL); 643 return ERR_PTR(-EINVAL);
636 } 644 }
637 645
646 /*
647 * a raid1 doesn't have the notion of chunk size, so
648 * figure out the largest suitable size we can use.
649 */
650 chunksect = 64 * 2; /* 64K by default */
651
652 /* The array must be an exact multiple of chunksize */
653 while (chunksect && (mddev->array_sectors & (chunksect - 1)))
654 chunksect >>= 1;
655
656 if ((chunksect << 9) < PAGE_SIZE)
657 /* array size does not allow a suitable chunk size */
658 return ERR_PTR(-EINVAL);
659
638 /* Set new parameters */ 660 /* Set new parameters */
639 mddev->new_level = 0; 661 mddev->new_level = 0;
640 mddev->new_layout = 0; 662 mddev->new_layout = 0;
641 mddev->new_chunk_sectors = 128; /* by default set chunk size to 64k */ 663 mddev->new_chunk_sectors = chunksect;
664 mddev->chunk_sectors = chunksect;
642 mddev->delta_disks = 1 - mddev->raid_disks; 665 mddev->delta_disks = 1 - mddev->raid_disks;
643 mddev->raid_disks = 1; 666 mddev->raid_disks = 1;
644 /* make sure it will be not marked as dirty */ 667 /* make sure it will be not marked as dirty */
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 4a40a200d769..15dd59b84e94 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -1712,6 +1712,7 @@ static int process_checks(struct r1bio *r1_bio)
1712 struct r1conf *conf = mddev->private; 1712 struct r1conf *conf = mddev->private;
1713 int primary; 1713 int primary;
1714 int i; 1714 int i;
1715 int vcnt;
1715 1716
1716 for (primary = 0; primary < conf->raid_disks * 2; primary++) 1717 for (primary = 0; primary < conf->raid_disks * 2; primary++)
1717 if (r1_bio->bios[primary]->bi_end_io == end_sync_read && 1718 if (r1_bio->bios[primary]->bi_end_io == end_sync_read &&
@@ -1721,9 +1722,9 @@ static int process_checks(struct r1bio *r1_bio)
1721 break; 1722 break;
1722 } 1723 }
1723 r1_bio->read_disk = primary; 1724 r1_bio->read_disk = primary;
1725 vcnt = (r1_bio->sectors + PAGE_SIZE / 512 - 1) >> (PAGE_SHIFT - 9);
1724 for (i = 0; i < conf->raid_disks * 2; i++) { 1726 for (i = 0; i < conf->raid_disks * 2; i++) {
1725 int j; 1727 int j;
1726 int vcnt = r1_bio->sectors >> (PAGE_SHIFT- 9);
1727 struct bio *pbio = r1_bio->bios[primary]; 1728 struct bio *pbio = r1_bio->bios[primary];
1728 struct bio *sbio = r1_bio->bios[i]; 1729 struct bio *sbio = r1_bio->bios[i];
1729 int size; 1730 int size;
@@ -1738,7 +1739,7 @@ static int process_checks(struct r1bio *r1_bio)
1738 s = sbio->bi_io_vec[j].bv_page; 1739 s = sbio->bi_io_vec[j].bv_page;
1739 if (memcmp(page_address(p), 1740 if (memcmp(page_address(p),
1740 page_address(s), 1741 page_address(s),
1741 PAGE_SIZE)) 1742 sbio->bi_io_vec[j].bv_len))
1742 break; 1743 break;
1743 } 1744 }
1744 } else 1745 } else
@@ -2386,8 +2387,7 @@ static sector_t sync_request(struct mddev *mddev, sector_t sector_nr, int *skipp
2386 int ok = 1; 2387 int ok = 1;
2387 for (i = 0 ; i < conf->raid_disks * 2 ; i++) 2388 for (i = 0 ; i < conf->raid_disks * 2 ; i++)
2388 if (r1_bio->bios[i]->bi_end_io == end_sync_write) { 2389 if (r1_bio->bios[i]->bi_end_io == end_sync_write) {
2389 struct md_rdev *rdev = 2390 struct md_rdev *rdev = conf->mirrors[i].rdev;
2390 rcu_dereference(conf->mirrors[i].rdev);
2391 ok = rdev_set_badblocks(rdev, sector_nr, 2391 ok = rdev_set_badblocks(rdev, sector_nr,
2392 min_bad, 0 2392 min_bad, 0
2393 ) && ok; 2393 ) && ok;
@@ -2636,11 +2636,13 @@ static struct r1conf *setup_conf(struct mddev *mddev)
2636 return ERR_PTR(err); 2636 return ERR_PTR(err);
2637} 2637}
2638 2638
2639static int stop(struct mddev *mddev);
2639static int run(struct mddev *mddev) 2640static int run(struct mddev *mddev)
2640{ 2641{
2641 struct r1conf *conf; 2642 struct r1conf *conf;
2642 int i; 2643 int i;
2643 struct md_rdev *rdev; 2644 struct md_rdev *rdev;
2645 int ret;
2644 2646
2645 if (mddev->level != 1) { 2647 if (mddev->level != 1) {
2646 printk(KERN_ERR "md/raid1:%s: raid level not set to mirroring (%d)\n", 2648 printk(KERN_ERR "md/raid1:%s: raid level not set to mirroring (%d)\n",
@@ -2705,7 +2707,11 @@ static int run(struct mddev *mddev)
2705 mddev->queue->backing_dev_info.congested_data = mddev; 2707 mddev->queue->backing_dev_info.congested_data = mddev;
2706 blk_queue_merge_bvec(mddev->queue, raid1_mergeable_bvec); 2708 blk_queue_merge_bvec(mddev->queue, raid1_mergeable_bvec);
2707 } 2709 }
2708 return md_integrity_register(mddev); 2710
2711 ret = md_integrity_register(mddev);
2712 if (ret)
2713 stop(mddev);
2714 return ret;
2709} 2715}
2710 2716
2711static int stop(struct mddev *mddev) 2717static int stop(struct mddev *mddev)
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 3540316886f2..c8dbb84d5357 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -1788,6 +1788,7 @@ static void sync_request_write(struct mddev *mddev, struct r10bio *r10_bio)
1788 struct r10conf *conf = mddev->private; 1788 struct r10conf *conf = mddev->private;
1789 int i, first; 1789 int i, first;
1790 struct bio *tbio, *fbio; 1790 struct bio *tbio, *fbio;
1791 int vcnt;
1791 1792
1792 atomic_set(&r10_bio->remaining, 1); 1793 atomic_set(&r10_bio->remaining, 1);
1793 1794
@@ -1802,10 +1803,10 @@ static void sync_request_write(struct mddev *mddev, struct r10bio *r10_bio)
1802 first = i; 1803 first = i;
1803 fbio = r10_bio->devs[i].bio; 1804 fbio = r10_bio->devs[i].bio;
1804 1805
1806 vcnt = (r10_bio->sectors + (PAGE_SIZE >> 9) - 1) >> (PAGE_SHIFT - 9);
1805 /* now find blocks with errors */ 1807 /* now find blocks with errors */
1806 for (i=0 ; i < conf->copies ; i++) { 1808 for (i=0 ; i < conf->copies ; i++) {
1807 int j, d; 1809 int j, d;
1808 int vcnt = r10_bio->sectors >> (PAGE_SHIFT-9);
1809 1810
1810 tbio = r10_bio->devs[i].bio; 1811 tbio = r10_bio->devs[i].bio;
1811 1812
@@ -1821,7 +1822,7 @@ static void sync_request_write(struct mddev *mddev, struct r10bio *r10_bio)
1821 for (j = 0; j < vcnt; j++) 1822 for (j = 0; j < vcnt; j++)
1822 if (memcmp(page_address(fbio->bi_io_vec[j].bv_page), 1823 if (memcmp(page_address(fbio->bi_io_vec[j].bv_page),
1823 page_address(tbio->bi_io_vec[j].bv_page), 1824 page_address(tbio->bi_io_vec[j].bv_page),
1824 PAGE_SIZE)) 1825 fbio->bi_io_vec[j].bv_len))
1825 break; 1826 break;
1826 if (j == vcnt) 1827 if (j == vcnt)
1827 continue; 1828 continue;
@@ -1871,7 +1872,6 @@ static void sync_request_write(struct mddev *mddev, struct r10bio *r10_bio)
1871 */ 1872 */
1872 for (i = 0; i < conf->copies; i++) { 1873 for (i = 0; i < conf->copies; i++) {
1873 int j, d; 1874 int j, d;
1874 int vcnt = r10_bio->sectors >> (PAGE_SHIFT-9);
1875 1875
1876 tbio = r10_bio->devs[i].repl_bio; 1876 tbio = r10_bio->devs[i].repl_bio;
1877 if (!tbio || !tbio->bi_end_io) 1877 if (!tbio || !tbio->bi_end_io)
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 23ac880bba9a..f351422938e0 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -2471,39 +2471,41 @@ handle_failed_sync(struct r5conf *conf, struct stripe_head *sh,
2471 int abort = 0; 2471 int abort = 0;
2472 int i; 2472 int i;
2473 2473
2474 md_done_sync(conf->mddev, STRIPE_SECTORS, 0);
2475 clear_bit(STRIPE_SYNCING, &sh->state); 2474 clear_bit(STRIPE_SYNCING, &sh->state);
2476 s->syncing = 0; 2475 s->syncing = 0;
2477 s->replacing = 0; 2476 s->replacing = 0;
2478 /* There is nothing more to do for sync/check/repair. 2477 /* There is nothing more to do for sync/check/repair.
2478 * Don't even need to abort as that is handled elsewhere
2479 * if needed, and not always wanted e.g. if there is a known
2480 * bad block here.
2479 * For recover/replace we need to record a bad block on all 2481 * For recover/replace we need to record a bad block on all
2480 * non-sync devices, or abort the recovery 2482 * non-sync devices, or abort the recovery
2481 */ 2483 */
2482 if (!test_bit(MD_RECOVERY_RECOVER, &conf->mddev->recovery)) 2484 if (test_bit(MD_RECOVERY_RECOVER, &conf->mddev->recovery)) {
2483 return; 2485 /* During recovery devices cannot be removed, so
2484 /* During recovery devices cannot be removed, so locking and 2486 * locking and refcounting of rdevs is not needed
2485 * refcounting of rdevs is not needed 2487 */
2486 */ 2488 for (i = 0; i < conf->raid_disks; i++) {
2487 for (i = 0; i < conf->raid_disks; i++) { 2489 struct md_rdev *rdev = conf->disks[i].rdev;
2488 struct md_rdev *rdev = conf->disks[i].rdev; 2490 if (rdev
2489 if (rdev 2491 && !test_bit(Faulty, &rdev->flags)
2490 && !test_bit(Faulty, &rdev->flags) 2492 && !test_bit(In_sync, &rdev->flags)
2491 && !test_bit(In_sync, &rdev->flags) 2493 && !rdev_set_badblocks(rdev, sh->sector,
2492 && !rdev_set_badblocks(rdev, sh->sector, 2494 STRIPE_SECTORS, 0))
2493 STRIPE_SECTORS, 0)) 2495 abort = 1;
2494 abort = 1; 2496 rdev = conf->disks[i].replacement;
2495 rdev = conf->disks[i].replacement; 2497 if (rdev
2496 if (rdev 2498 && !test_bit(Faulty, &rdev->flags)
2497 && !test_bit(Faulty, &rdev->flags) 2499 && !test_bit(In_sync, &rdev->flags)
2498 && !test_bit(In_sync, &rdev->flags) 2500 && !rdev_set_badblocks(rdev, sh->sector,
2499 && !rdev_set_badblocks(rdev, sh->sector, 2501 STRIPE_SECTORS, 0))
2500 STRIPE_SECTORS, 0)) 2502 abort = 1;
2501 abort = 1; 2503 }
2502 } 2504 if (abort)
2503 if (abort) { 2505 conf->recovery_disabled =
2504 conf->recovery_disabled = conf->mddev->recovery_disabled; 2506 conf->mddev->recovery_disabled;
2505 set_bit(MD_RECOVERY_INTR, &conf->mddev->recovery);
2506 } 2507 }
2508 md_done_sync(conf->mddev, STRIPE_SECTORS, !abort);
2507} 2509}
2508 2510
2509static int want_replace(struct stripe_head *sh, int disk_idx) 2511static int want_replace(struct stripe_head *sh, int disk_idx)
@@ -3203,7 +3205,8 @@ static void analyse_stripe(struct stripe_head *sh, struct stripe_head_state *s)
3203 /* Not in-sync */; 3205 /* Not in-sync */;
3204 else if (is_bad) { 3206 else if (is_bad) {
3205 /* also not in-sync */ 3207 /* also not in-sync */
3206 if (!test_bit(WriteErrorSeen, &rdev->flags)) { 3208 if (!test_bit(WriteErrorSeen, &rdev->flags) &&
3209 test_bit(R5_UPTODATE, &dev->flags)) {
3207 /* treat as in-sync, but with a read error 3210 /* treat as in-sync, but with a read error
3208 * which we can now try to correct 3211 * which we can now try to correct
3209 */ 3212 */
@@ -3276,12 +3279,14 @@ static void analyse_stripe(struct stripe_head *sh, struct stripe_head_state *s)
3276 /* If there is a failed device being replaced, 3279 /* If there is a failed device being replaced,
3277 * we must be recovering. 3280 * we must be recovering.
3278 * else if we are after recovery_cp, we must be syncing 3281 * else if we are after recovery_cp, we must be syncing
3282 * else if MD_RECOVERY_REQUESTED is set, we also are syncing.
3279 * else we can only be replacing 3283 * else we can only be replacing
3280 * sync and recovery both need to read all devices, and so 3284 * sync and recovery both need to read all devices, and so
3281 * use the same flag. 3285 * use the same flag.
3282 */ 3286 */
3283 if (do_recovery || 3287 if (do_recovery ||
3284 sh->sector >= conf->mddev->recovery_cp) 3288 sh->sector >= conf->mddev->recovery_cp ||
3289 test_bit(MD_RECOVERY_REQUESTED, &(conf->mddev->recovery)))
3285 s->syncing = 1; 3290 s->syncing = 1;
3286 else 3291 else
3287 s->replacing = 1; 3292 s->replacing = 1;
diff --git a/drivers/media/common/tuners/xc5000.c b/drivers/media/common/tuners/xc5000.c
index 7f98984e4fad..eab2ea424200 100644
--- a/drivers/media/common/tuners/xc5000.c
+++ b/drivers/media/common/tuners/xc5000.c
@@ -54,6 +54,7 @@ struct xc5000_priv {
54 struct list_head hybrid_tuner_instance_list; 54 struct list_head hybrid_tuner_instance_list;
55 55
56 u32 if_khz; 56 u32 if_khz;
57 u32 xtal_khz;
57 u32 freq_hz; 58 u32 freq_hz;
58 u32 bandwidth; 59 u32 bandwidth;
59 u8 video_standard; 60 u8 video_standard;
@@ -214,9 +215,9 @@ static const struct xc5000_fw_cfg xc5000a_1_6_114 = {
214 .size = 12401, 215 .size = 12401,
215}; 216};
216 217
217static const struct xc5000_fw_cfg xc5000c_41_024_5_31875 = { 218static const struct xc5000_fw_cfg xc5000c_41_024_5 = {
218 .name = "dvb-fe-xc5000c-41.024.5-31875.fw", 219 .name = "dvb-fe-xc5000c-41.024.5.fw",
219 .size = 16503, 220 .size = 16497,
220}; 221};
221 222
222static inline const struct xc5000_fw_cfg *xc5000_assign_firmware(int chip_id) 223static inline const struct xc5000_fw_cfg *xc5000_assign_firmware(int chip_id)
@@ -226,7 +227,7 @@ static inline const struct xc5000_fw_cfg *xc5000_assign_firmware(int chip_id)
226 case XC5000A: 227 case XC5000A:
227 return &xc5000a_1_6_114; 228 return &xc5000a_1_6_114;
228 case XC5000C: 229 case XC5000C:
229 return &xc5000c_41_024_5_31875; 230 return &xc5000c_41_024_5;
230 } 231 }
231} 232}
232 233
@@ -572,6 +573,31 @@ static int xc_tune_channel(struct xc5000_priv *priv, u32 freq_hz, int mode)
572 return found; 573 return found;
573} 574}
574 575
576static int xc_set_xtal(struct dvb_frontend *fe)
577{
578 struct xc5000_priv *priv = fe->tuner_priv;
579 int ret = XC_RESULT_SUCCESS;
580
581 switch (priv->chip_id) {
582 default:
583 case XC5000A:
584 /* 32.000 MHz xtal is default */
585 break;
586 case XC5000C:
587 switch (priv->xtal_khz) {
588 default:
589 case 32000:
590 /* 32.000 MHz xtal is default */
591 break;
592 case 31875:
593 /* 31.875 MHz xtal configuration */
594 ret = xc_write_reg(priv, 0x000f, 0x8081);
595 break;
596 }
597 break;
598 }
599 return ret;
600}
575 601
576static int xc5000_fwupload(struct dvb_frontend *fe) 602static int xc5000_fwupload(struct dvb_frontend *fe)
577{ 603{
@@ -603,6 +629,8 @@ static int xc5000_fwupload(struct dvb_frontend *fe)
603 } else { 629 } else {
604 printk(KERN_INFO "xc5000: firmware uploading...\n"); 630 printk(KERN_INFO "xc5000: firmware uploading...\n");
605 ret = xc_load_i2c_sequence(fe, fw->data); 631 ret = xc_load_i2c_sequence(fe, fw->data);
632 if (XC_RESULT_SUCCESS == ret)
633 ret = xc_set_xtal(fe);
606 printk(KERN_INFO "xc5000: firmware upload complete...\n"); 634 printk(KERN_INFO "xc5000: firmware upload complete...\n");
607 } 635 }
608 636
@@ -1164,6 +1192,9 @@ struct dvb_frontend *xc5000_attach(struct dvb_frontend *fe,
1164 priv->if_khz = cfg->if_khz; 1192 priv->if_khz = cfg->if_khz;
1165 } 1193 }
1166 1194
1195 if (priv->xtal_khz == 0)
1196 priv->xtal_khz = cfg->xtal_khz;
1197
1167 if (priv->radio_input == 0) 1198 if (priv->radio_input == 0)
1168 priv->radio_input = cfg->radio_input; 1199 priv->radio_input = cfg->radio_input;
1169 1200
diff --git a/drivers/media/common/tuners/xc5000.h b/drivers/media/common/tuners/xc5000.h
index 3396f8e02b40..39a73bf01406 100644
--- a/drivers/media/common/tuners/xc5000.h
+++ b/drivers/media/common/tuners/xc5000.h
@@ -34,6 +34,7 @@ struct xc5000_config {
34 u8 i2c_address; 34 u8 i2c_address;
35 u32 if_khz; 35 u32 if_khz;
36 u8 radio_input; 36 u8 radio_input;
37 u32 xtal_khz;
37 38
38 int chip_id; 39 int chip_id;
39}; 40};
diff --git a/drivers/media/dvb/dvb-core/dvb_frontend.c b/drivers/media/dvb/dvb-core/dvb_frontend.c
index 4555baa383b2..0f64d7182657 100644
--- a/drivers/media/dvb/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb/dvb-core/dvb_frontend.c
@@ -143,10 +143,12 @@ struct dvb_frontend_private {
143static void dvb_frontend_wakeup(struct dvb_frontend *fe); 143static void dvb_frontend_wakeup(struct dvb_frontend *fe);
144static int dtv_get_frontend(struct dvb_frontend *fe, 144static int dtv_get_frontend(struct dvb_frontend *fe,
145 struct dvb_frontend_parameters *p_out); 145 struct dvb_frontend_parameters *p_out);
146static int dtv_property_legacy_params_sync(struct dvb_frontend *fe,
147 struct dvb_frontend_parameters *p);
146 148
147static bool has_get_frontend(struct dvb_frontend *fe) 149static bool has_get_frontend(struct dvb_frontend *fe)
148{ 150{
149 return fe->ops.get_frontend; 151 return fe->ops.get_frontend != NULL;
150} 152}
151 153
152/* 154/*
@@ -697,6 +699,7 @@ restart:
697 fepriv->algo_status |= DVBFE_ALGO_SEARCH_AGAIN; 699 fepriv->algo_status |= DVBFE_ALGO_SEARCH_AGAIN;
698 fepriv->delay = HZ / 2; 700 fepriv->delay = HZ / 2;
699 } 701 }
702 dtv_property_legacy_params_sync(fe, &fepriv->parameters_out);
700 fe->ops.read_status(fe, &s); 703 fe->ops.read_status(fe, &s);
701 if (s != fepriv->status) { 704 if (s != fepriv->status) {
702 dvb_frontend_add_event(fe, s); /* update event list */ 705 dvb_frontend_add_event(fe, s); /* update event list */
@@ -1443,6 +1446,28 @@ static int set_delivery_system(struct dvb_frontend *fe, u32 desired_system)
1443 __func__); 1446 __func__);
1444 return -EINVAL; 1447 return -EINVAL;
1445 } 1448 }
1449 /*
1450 * Get a delivery system that is compatible with DVBv3
1451 * NOTE: in order for this to work with softwares like Kaffeine that
1452 * uses a DVBv5 call for DVB-S2 and a DVBv3 call to go back to
1453 * DVB-S, drivers that support both should put the SYS_DVBS entry
1454 * before the SYS_DVBS2, otherwise it won't switch back to DVB-S.
1455 * The real fix is that userspace applications should not use DVBv3
1456 * and not trust on calling FE_SET_FRONTEND to switch the delivery
1457 * system.
1458 */
1459 ncaps = 0;
1460 while (fe->ops.delsys[ncaps] && ncaps < MAX_DELSYS) {
1461 if (fe->ops.delsys[ncaps] == desired_system) {
1462 delsys = desired_system;
1463 break;
1464 }
1465 ncaps++;
1466 }
1467 if (delsys == SYS_UNDEFINED) {
1468 dprintk("%s() Couldn't find a delivery system that matches %d\n",
1469 __func__, desired_system);
1470 }
1446 } else { 1471 } else {
1447 /* 1472 /*
1448 * This is a DVBv5 call. So, it likely knows the supported 1473 * This is a DVBv5 call. So, it likely knows the supported
@@ -1491,9 +1516,10 @@ static int set_delivery_system(struct dvb_frontend *fe, u32 desired_system)
1491 __func__); 1516 __func__);
1492 return -EINVAL; 1517 return -EINVAL;
1493 } 1518 }
1494 c->delivery_system = delsys;
1495 } 1519 }
1496 1520
1521 c->delivery_system = delsys;
1522
1497 /* 1523 /*
1498 * The DVBv3 or DVBv5 call is requesting a different system. So, 1524 * The DVBv3 or DVBv5 call is requesting a different system. So,
1499 * emulation is needed. 1525 * emulation is needed.
@@ -1833,6 +1859,13 @@ static int dtv_set_frontend(struct dvb_frontend *fe)
1833 return -EINVAL; 1859 return -EINVAL;
1834 1860
1835 /* 1861 /*
1862 * Initialize output parameters to match the values given by
1863 * the user. FE_SET_FRONTEND triggers an initial frontend event
1864 * with status = 0, which copies output parameters to userspace.
1865 */
1866 dtv_property_legacy_params_sync(fe, &fepriv->parameters_out);
1867
1868 /*
1836 * Be sure that the bandwidth will be filled for all 1869 * Be sure that the bandwidth will be filled for all
1837 * non-satellite systems, as tuners need to know what 1870 * non-satellite systems, as tuners need to know what
1838 * low pass/Nyquist half filter should be applied, in 1871 * low pass/Nyquist half filter should be applied, in
diff --git a/drivers/media/dvb/dvb-usb/it913x.c b/drivers/media/dvb/dvb-usb/it913x.c
index 3b7b102f20ae..482d249ca7f3 100644
--- a/drivers/media/dvb/dvb-usb/it913x.c
+++ b/drivers/media/dvb/dvb-usb/it913x.c
@@ -238,12 +238,27 @@ static int it913x_read_reg(struct usb_device *udev, u32 reg)
238 238
239static u32 it913x_query(struct usb_device *udev, u8 pro) 239static u32 it913x_query(struct usb_device *udev, u8 pro)
240{ 240{
241 int ret; 241 int ret, i;
242 u8 data[4]; 242 u8 data[4];
243 ret = it913x_io(udev, READ_LONG, pro, CMD_DEMOD_READ, 243 u8 ver;
244 0x1222, 0, &data[0], 3); 244
245 for (i = 0; i < 5; i++) {
246 ret = it913x_io(udev, READ_LONG, pro, CMD_DEMOD_READ,
247 0x1222, 0, &data[0], 3);
248 ver = data[0];
249 if (ver > 0 && ver < 3)
250 break;
251 msleep(100);
252 }
245 253
246 it913x_config.chip_ver = data[0]; 254 if (ver < 1 || ver > 2) {
255 info("Failed to identify chip version applying 1");
256 it913x_config.chip_ver = 0x1;
257 it913x_config.chip_type = 0x9135;
258 return 0;
259 }
260
261 it913x_config.chip_ver = ver;
247 it913x_config.chip_type = (u16)(data[2] << 8) + data[1]; 262 it913x_config.chip_type = (u16)(data[2] << 8) + data[1];
248 263
249 info("Chip Version=%02x Chip Type=%04x", it913x_config.chip_ver, 264 info("Chip Version=%02x Chip Type=%04x", it913x_config.chip_ver,
@@ -660,30 +675,41 @@ static int it913x_download_firmware(struct usb_device *udev,
660 if ((packet_size > min_pkt) || (i == fw->size)) { 675 if ((packet_size > min_pkt) || (i == fw->size)) {
661 fw_data = (u8 *)(fw->data + pos); 676 fw_data = (u8 *)(fw->data + pos);
662 pos += packet_size; 677 pos += packet_size;
663 if (packet_size > 0) 678 if (packet_size > 0) {
664 ret |= it913x_io(udev, WRITE_DATA, 679 ret = it913x_io(udev, WRITE_DATA,
665 DEV_0, CMD_SCATTER_WRITE, 0, 680 DEV_0, CMD_SCATTER_WRITE, 0,
666 0, fw_data, packet_size); 681 0, fw_data, packet_size);
682 if (ret < 0)
683 break;
684 }
667 udelay(1000); 685 udelay(1000);
668 } 686 }
669 } 687 }
670 i++; 688 i++;
671 } 689 }
672 690
673 ret |= it913x_io(udev, WRITE_CMD, DEV_0, CMD_BOOT, 0, 0, NULL, 0);
674
675 msleep(100);
676
677 if (ret < 0) 691 if (ret < 0)
678 info("FRM Firmware Download Failed (%04x)" , ret); 692 info("FRM Firmware Download Failed (%d)" , ret);
679 else 693 else
680 info("FRM Firmware Download Completed - Resetting Device"); 694 info("FRM Firmware Download Completed - Resetting Device");
681 695
682 ret |= it913x_return_status(udev); 696 msleep(30);
697
698 ret = it913x_io(udev, WRITE_CMD, DEV_0, CMD_BOOT, 0, 0, NULL, 0);
699 if (ret < 0)
700 info("FRM Device not responding to reboot");
701
702 ret = it913x_return_status(udev);
703 if (ret == 0) {
704 info("FRM Failed to reboot device");
705 return -ENODEV;
706 }
683 707
684 msleep(30); 708 msleep(30);
685 709
686 ret |= it913x_wr_reg(udev, DEV_0, I2C_CLK, I2C_CLK_400); 710 ret = it913x_wr_reg(udev, DEV_0, I2C_CLK, I2C_CLK_400);
711
712 msleep(30);
687 713
688 /* Tuner function */ 714 /* Tuner function */
689 if (it913x_config.dual_mode) 715 if (it913x_config.dual_mode)
@@ -901,5 +927,5 @@ module_usb_driver(it913x_driver);
901 927
902MODULE_AUTHOR("Malcolm Priestley <tvboxspy@gmail.com>"); 928MODULE_AUTHOR("Malcolm Priestley <tvboxspy@gmail.com>");
903MODULE_DESCRIPTION("it913x USB 2 Driver"); 929MODULE_DESCRIPTION("it913x USB 2 Driver");
904MODULE_VERSION("1.27"); 930MODULE_VERSION("1.28");
905MODULE_LICENSE("GPL"); 931MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/frontends/drxk_hard.c b/drivers/media/dvb/frontends/drxk_hard.c
index 36d11756492f..a414b1f2b6a5 100644
--- a/drivers/media/dvb/frontends/drxk_hard.c
+++ b/drivers/media/dvb/frontends/drxk_hard.c
@@ -1520,8 +1520,10 @@ static int scu_command(struct drxk_state *state,
1520 dprintk(1, "\n"); 1520 dprintk(1, "\n");
1521 1521
1522 if ((cmd == 0) || ((parameterLen > 0) && (parameter == NULL)) || 1522 if ((cmd == 0) || ((parameterLen > 0) && (parameter == NULL)) ||
1523 ((resultLen > 0) && (result == NULL))) 1523 ((resultLen > 0) && (result == NULL))) {
1524 goto error; 1524 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
1525 return status;
1526 }
1525 1527
1526 mutex_lock(&state->mutex); 1528 mutex_lock(&state->mutex);
1527 1529
diff --git a/drivers/media/rc/winbond-cir.c b/drivers/media/rc/winbond-cir.c
index b09c5fae489b..af526586fa26 100644
--- a/drivers/media/rc/winbond-cir.c
+++ b/drivers/media/rc/winbond-cir.c
@@ -1046,6 +1046,7 @@ wbcir_probe(struct pnp_dev *device, const struct pnp_device_id *dev_id)
1046 goto exit_unregister_led; 1046 goto exit_unregister_led;
1047 } 1047 }
1048 1048
1049 data->dev->driver_type = RC_DRIVER_IR_RAW;
1049 data->dev->driver_name = WBCIR_NAME; 1050 data->dev->driver_name = WBCIR_NAME;
1050 data->dev->input_name = WBCIR_NAME; 1051 data->dev->input_name = WBCIR_NAME;
1051 data->dev->input_phys = "wbcir/cir0"; 1052 data->dev->input_phys = "wbcir/cir0";
diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index f2479c5c0eb2..ce1e7ba940f6 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -492,7 +492,7 @@ config VIDEO_VS6624
492 492
493config VIDEO_MT9M032 493config VIDEO_MT9M032
494 tristate "MT9M032 camera sensor support" 494 tristate "MT9M032 camera sensor support"
495 depends on I2C && VIDEO_V4L2 495 depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
496 select VIDEO_APTINA_PLL 496 select VIDEO_APTINA_PLL
497 ---help--- 497 ---help---
498 This driver supports MT9M032 camera sensors from Aptina, monochrome 498 This driver supports MT9M032 camera sensors from Aptina, monochrome
diff --git a/drivers/media/video/ivtv/ivtv-ioctl.c b/drivers/media/video/ivtv/ivtv-ioctl.c
index 5452beef8e11..989e556913ed 100644
--- a/drivers/media/video/ivtv/ivtv-ioctl.c
+++ b/drivers/media/video/ivtv/ivtv-ioctl.c
@@ -1763,13 +1763,13 @@ static int ivtv_decoder_ioctls(struct file *filp, unsigned int cmd, void *arg)
1763 IVTV_DEBUG_IOCTL("AUDIO_CHANNEL_SELECT\n"); 1763 IVTV_DEBUG_IOCTL("AUDIO_CHANNEL_SELECT\n");
1764 if (iarg > AUDIO_STEREO_SWAPPED) 1764 if (iarg > AUDIO_STEREO_SWAPPED)
1765 return -EINVAL; 1765 return -EINVAL;
1766 return v4l2_ctrl_s_ctrl(itv->ctrl_audio_playback, iarg); 1766 return v4l2_ctrl_s_ctrl(itv->ctrl_audio_playback, iarg + 1);
1767 1767
1768 case AUDIO_BILINGUAL_CHANNEL_SELECT: 1768 case AUDIO_BILINGUAL_CHANNEL_SELECT:
1769 IVTV_DEBUG_IOCTL("AUDIO_BILINGUAL_CHANNEL_SELECT\n"); 1769 IVTV_DEBUG_IOCTL("AUDIO_BILINGUAL_CHANNEL_SELECT\n");
1770 if (iarg > AUDIO_STEREO_SWAPPED) 1770 if (iarg > AUDIO_STEREO_SWAPPED)
1771 return -EINVAL; 1771 return -EINVAL;
1772 return v4l2_ctrl_s_ctrl(itv->ctrl_audio_multilingual_playback, iarg); 1772 return v4l2_ctrl_s_ctrl(itv->ctrl_audio_multilingual_playback, iarg + 1);
1773 1773
1774 default: 1774 default:
1775 return -EINVAL; 1775 return -EINVAL;
diff --git a/drivers/media/video/mt9m032.c b/drivers/media/video/mt9m032.c
index 7636672c3548..645973c5feb0 100644
--- a/drivers/media/video/mt9m032.c
+++ b/drivers/media/video/mt9m032.c
@@ -392,10 +392,11 @@ static int mt9m032_set_pad_format(struct v4l2_subdev *subdev,
392 } 392 }
393 393
394 /* Scaling is not supported, the format is thus fixed. */ 394 /* Scaling is not supported, the format is thus fixed. */
395 ret = mt9m032_get_pad_format(subdev, fh, fmt); 395 fmt->format = *__mt9m032_get_pad_format(sensor, fh, fmt->which);
396 ret = 0;
396 397
397done: 398done:
398 mutex_lock(&sensor->lock); 399 mutex_unlock(&sensor->lock);
399 return ret; 400 return ret;
400} 401}
401 402
diff --git a/drivers/media/video/uvc/uvc_video.c b/drivers/media/video/uvc/uvc_video.c
index 4a44f9a1bae0..b76b0ac0958f 100644
--- a/drivers/media/video/uvc/uvc_video.c
+++ b/drivers/media/video/uvc/uvc_video.c
@@ -468,22 +468,30 @@ uvc_video_clock_decode(struct uvc_streaming *stream, struct uvc_buffer *buf,
468 spin_unlock_irqrestore(&stream->clock.lock, flags); 468 spin_unlock_irqrestore(&stream->clock.lock, flags);
469} 469}
470 470
471static int uvc_video_clock_init(struct uvc_streaming *stream) 471static void uvc_video_clock_reset(struct uvc_streaming *stream)
472{ 472{
473 struct uvc_clock *clock = &stream->clock; 473 struct uvc_clock *clock = &stream->clock;
474 474
475 spin_lock_init(&clock->lock);
476 clock->head = 0; 475 clock->head = 0;
477 clock->count = 0; 476 clock->count = 0;
478 clock->size = 32;
479 clock->last_sof = -1; 477 clock->last_sof = -1;
480 clock->sof_offset = -1; 478 clock->sof_offset = -1;
479}
480
481static int uvc_video_clock_init(struct uvc_streaming *stream)
482{
483 struct uvc_clock *clock = &stream->clock;
484
485 spin_lock_init(&clock->lock);
486 clock->size = 32;
481 487
482 clock->samples = kmalloc(clock->size * sizeof(*clock->samples), 488 clock->samples = kmalloc(clock->size * sizeof(*clock->samples),
483 GFP_KERNEL); 489 GFP_KERNEL);
484 if (clock->samples == NULL) 490 if (clock->samples == NULL)
485 return -ENOMEM; 491 return -ENOMEM;
486 492
493 uvc_video_clock_reset(stream);
494
487 return 0; 495 return 0;
488} 496}
489 497
@@ -1424,8 +1432,6 @@ static void uvc_uninit_video(struct uvc_streaming *stream, int free_buffers)
1424 1432
1425 if (free_buffers) 1433 if (free_buffers)
1426 uvc_free_urb_buffers(stream); 1434 uvc_free_urb_buffers(stream);
1427
1428 uvc_video_clock_cleanup(stream);
1429} 1435}
1430 1436
1431/* 1437/*
@@ -1555,10 +1561,6 @@ static int uvc_init_video(struct uvc_streaming *stream, gfp_t gfp_flags)
1555 1561
1556 uvc_video_stats_start(stream); 1562 uvc_video_stats_start(stream);
1557 1563
1558 ret = uvc_video_clock_init(stream);
1559 if (ret < 0)
1560 return ret;
1561
1562 if (intf->num_altsetting > 1) { 1564 if (intf->num_altsetting > 1) {
1563 struct usb_host_endpoint *best_ep = NULL; 1565 struct usb_host_endpoint *best_ep = NULL;
1564 unsigned int best_psize = 3 * 1024; 1566 unsigned int best_psize = 3 * 1024;
@@ -1683,6 +1685,8 @@ int uvc_video_resume(struct uvc_streaming *stream, int reset)
1683 1685
1684 stream->frozen = 0; 1686 stream->frozen = 0;
1685 1687
1688 uvc_video_clock_reset(stream);
1689
1686 ret = uvc_commit_video(stream, &stream->ctrl); 1690 ret = uvc_commit_video(stream, &stream->ctrl);
1687 if (ret < 0) { 1691 if (ret < 0) {
1688 uvc_queue_enable(&stream->queue, 0); 1692 uvc_queue_enable(&stream->queue, 0);
@@ -1819,25 +1823,35 @@ int uvc_video_enable(struct uvc_streaming *stream, int enable)
1819 uvc_uninit_video(stream, 1); 1823 uvc_uninit_video(stream, 1);
1820 usb_set_interface(stream->dev->udev, stream->intfnum, 0); 1824 usb_set_interface(stream->dev->udev, stream->intfnum, 0);
1821 uvc_queue_enable(&stream->queue, 0); 1825 uvc_queue_enable(&stream->queue, 0);
1826 uvc_video_clock_cleanup(stream);
1822 return 0; 1827 return 0;
1823 } 1828 }
1824 1829
1825 ret = uvc_queue_enable(&stream->queue, 1); 1830 ret = uvc_video_clock_init(stream);
1826 if (ret < 0) 1831 if (ret < 0)
1827 return ret; 1832 return ret;
1828 1833
1834 ret = uvc_queue_enable(&stream->queue, 1);
1835 if (ret < 0)
1836 goto error_queue;
1837
1829 /* Commit the streaming parameters. */ 1838 /* Commit the streaming parameters. */
1830 ret = uvc_commit_video(stream, &stream->ctrl); 1839 ret = uvc_commit_video(stream, &stream->ctrl);
1831 if (ret < 0) { 1840 if (ret < 0)
1832 uvc_queue_enable(&stream->queue, 0); 1841 goto error_commit;
1833 return ret;
1834 }
1835 1842
1836 ret = uvc_init_video(stream, GFP_KERNEL); 1843 ret = uvc_init_video(stream, GFP_KERNEL);
1837 if (ret < 0) { 1844 if (ret < 0)
1838 usb_set_interface(stream->dev->udev, stream->intfnum, 0); 1845 goto error_video;
1839 uvc_queue_enable(&stream->queue, 0); 1846
1840 } 1847 return 0;
1848
1849error_video:
1850 usb_set_interface(stream->dev->udev, stream->intfnum, 0);
1851error_commit:
1852 uvc_queue_enable(&stream->queue, 0);
1853error_queue:
1854 uvc_video_clock_cleanup(stream);
1841 1855
1842 return ret; 1856 return ret;
1843} 1857}
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 29f463cc09cb..11e44386fa9b 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -268,10 +268,17 @@ config TWL6030_PWM
268 This is used to control charging LED brightness. 268 This is used to control charging LED brightness.
269 269
270config TWL6040_CORE 270config TWL6040_CORE
271 bool 271 bool "Support for TWL6040 audio codec"
272 depends on TWL4030_CORE && GENERIC_HARDIRQS 272 depends on I2C=y && GENERIC_HARDIRQS
273 select MFD_CORE 273 select MFD_CORE
274 select REGMAP_I2C
274 default n 275 default n
276 help
277 Say yes here if you want support for Texas Instruments TWL6040 audio
278 codec.
279 This driver provides common support for accessing the device,
280 additional drivers must be enabled in order to use the
281 functionality of the device (audio, vibra).
275 282
276config MFD_STMPE 283config MFD_STMPE
277 bool "Support STMicroelectronics STMPE" 284 bool "Support STMicroelectronics STMPE"
diff --git a/drivers/mfd/aat2870-core.c b/drivers/mfd/aat2870-core.c
index 3aa36eb5c79b..44a3fdbadef4 100644
--- a/drivers/mfd/aat2870-core.c
+++ b/drivers/mfd/aat2870-core.c
@@ -262,13 +262,6 @@ static ssize_t aat2870_dump_reg(struct aat2870_data *aat2870, char *buf)
262 return count; 262 return count;
263} 263}
264 264
265static int aat2870_reg_open_file(struct inode *inode, struct file *file)
266{
267 file->private_data = inode->i_private;
268
269 return 0;
270}
271
272static ssize_t aat2870_reg_read_file(struct file *file, char __user *user_buf, 265static ssize_t aat2870_reg_read_file(struct file *file, char __user *user_buf,
273 size_t count, loff_t *ppos) 266 size_t count, loff_t *ppos)
274{ 267{
@@ -330,7 +323,7 @@ static ssize_t aat2870_reg_write_file(struct file *file,
330} 323}
331 324
332static const struct file_operations aat2870_reg_fops = { 325static const struct file_operations aat2870_reg_fops = {
333 .open = aat2870_reg_open_file, 326 .open = simple_open,
334 .read = aat2870_reg_read_file, 327 .read = aat2870_reg_read_file,
335 .write = aat2870_reg_write_file, 328 .write = aat2870_reg_write_file,
336}; 329};
diff --git a/drivers/mfd/ab3100-core.c b/drivers/mfd/ab3100-core.c
index 60107ee166fc..1efad20fb175 100644
--- a/drivers/mfd/ab3100-core.c
+++ b/drivers/mfd/ab3100-core.c
@@ -483,12 +483,6 @@ struct ab3100_get_set_reg_priv {
483 bool mode; 483 bool mode;
484}; 484};
485 485
486static int ab3100_get_set_reg_open_file(struct inode *inode, struct file *file)
487{
488 file->private_data = inode->i_private;
489 return 0;
490}
491
492static ssize_t ab3100_get_set_reg(struct file *file, 486static ssize_t ab3100_get_set_reg(struct file *file,
493 const char __user *user_buf, 487 const char __user *user_buf,
494 size_t count, loff_t *ppos) 488 size_t count, loff_t *ppos)
@@ -583,7 +577,7 @@ static ssize_t ab3100_get_set_reg(struct file *file,
583} 577}
584 578
585static const struct file_operations ab3100_get_set_reg_fops = { 579static const struct file_operations ab3100_get_set_reg_fops = {
586 .open = ab3100_get_set_reg_open_file, 580 .open = simple_open,
587 .write = ab3100_get_set_reg, 581 .write = ab3100_get_set_reg,
588 .llseek = noop_llseek, 582 .llseek = noop_llseek,
589}; 583};
diff --git a/drivers/mfd/asic3.c b/drivers/mfd/asic3.c
index 1895cf9fab8c..1582c3d95257 100644
--- a/drivers/mfd/asic3.c
+++ b/drivers/mfd/asic3.c
@@ -527,7 +527,9 @@ static void asic3_gpio_set(struct gpio_chip *chip,
527 527
528static int asic3_gpio_to_irq(struct gpio_chip *chip, unsigned offset) 528static int asic3_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
529{ 529{
530 return (offset < ASIC3_NUM_GPIOS) ? IRQ_BOARD_START + offset : -ENXIO; 530 struct asic3 *asic = container_of(chip, struct asic3, gpio);
531
532 return (offset < ASIC3_NUM_GPIOS) ? asic->irq_base + offset : -ENXIO;
531} 533}
532 534
533static __init int asic3_gpio_probe(struct platform_device *pdev, 535static __init int asic3_gpio_probe(struct platform_device *pdev,
diff --git a/drivers/mfd/db8500-prcmu.c b/drivers/mfd/db8500-prcmu.c
index ebc1e8658226..5be32489714f 100644
--- a/drivers/mfd/db8500-prcmu.c
+++ b/drivers/mfd/db8500-prcmu.c
@@ -2788,6 +2788,7 @@ static struct regulator_init_data db8500_regulators[DB8500_NUM_REGULATORS] = {
2788 .constraints = { 2788 .constraints = {
2789 .name = "db8500-vape", 2789 .name = "db8500-vape",
2790 .valid_ops_mask = REGULATOR_CHANGE_STATUS, 2790 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
2791 .always_on = true,
2791 }, 2792 },
2792 .consumer_supplies = db8500_vape_consumers, 2793 .consumer_supplies = db8500_vape_consumers,
2793 .num_consumer_supplies = ARRAY_SIZE(db8500_vape_consumers), 2794 .num_consumer_supplies = ARRAY_SIZE(db8500_vape_consumers),
diff --git a/drivers/mfd/mc13xxx-core.c b/drivers/mfd/mc13xxx-core.c
index 9fd4f63c45cc..738722cdecaa 100644
--- a/drivers/mfd/mc13xxx-core.c
+++ b/drivers/mfd/mc13xxx-core.c
@@ -813,7 +813,8 @@ err_revision:
813 mc13xxx_add_subdevice(mc13xxx, "%s-adc"); 813 mc13xxx_add_subdevice(mc13xxx, "%s-adc");
814 814
815 if (mc13xxx->flags & MC13XXX_USE_CODEC) 815 if (mc13xxx->flags & MC13XXX_USE_CODEC)
816 mc13xxx_add_subdevice(mc13xxx, "%s-codec"); 816 mc13xxx_add_subdevice_pdata(mc13xxx, "%s-codec",
817 pdata->codec, sizeof(*pdata->codec));
817 818
818 if (mc13xxx->flags & MC13XXX_USE_RTC) 819 if (mc13xxx->flags & MC13XXX_USE_RTC)
819 mc13xxx_add_subdevice(mc13xxx, "%s-rtc"); 820 mc13xxx_add_subdevice(mc13xxx, "%s-rtc");
diff --git a/drivers/mfd/omap-usb-host.c b/drivers/mfd/omap-usb-host.c
index 95a2e546a489..7e96bb229724 100644
--- a/drivers/mfd/omap-usb-host.c
+++ b/drivers/mfd/omap-usb-host.c
@@ -25,7 +25,7 @@
25#include <linux/clk.h> 25#include <linux/clk.h>
26#include <linux/dma-mapping.h> 26#include <linux/dma-mapping.h>
27#include <linux/spinlock.h> 27#include <linux/spinlock.h>
28#include <linux/gpio.h> 28#include <plat/cpu.h>
29#include <plat/usb.h> 29#include <plat/usb.h>
30#include <linux/pm_runtime.h> 30#include <linux/pm_runtime.h>
31 31
@@ -502,19 +502,6 @@ static void omap_usbhs_init(struct device *dev)
502 pm_runtime_get_sync(dev); 502 pm_runtime_get_sync(dev);
503 spin_lock_irqsave(&omap->lock, flags); 503 spin_lock_irqsave(&omap->lock, flags);
504 504
505 if (pdata->ehci_data->phy_reset) {
506 if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[0]))
507 gpio_request_one(pdata->ehci_data->reset_gpio_port[0],
508 GPIOF_OUT_INIT_LOW, "USB1 PHY reset");
509
510 if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[1]))
511 gpio_request_one(pdata->ehci_data->reset_gpio_port[1],
512 GPIOF_OUT_INIT_LOW, "USB2 PHY reset");
513
514 /* Hold the PHY in RESET for enough time till DIR is high */
515 udelay(10);
516 }
517
518 omap->usbhs_rev = usbhs_read(omap->uhh_base, OMAP_UHH_REVISION); 505 omap->usbhs_rev = usbhs_read(omap->uhh_base, OMAP_UHH_REVISION);
519 dev_dbg(dev, "OMAP UHH_REVISION 0x%x\n", omap->usbhs_rev); 506 dev_dbg(dev, "OMAP UHH_REVISION 0x%x\n", omap->usbhs_rev);
520 507
@@ -593,39 +580,10 @@ static void omap_usbhs_init(struct device *dev)
593 usbhs_omap_tll_init(dev, OMAP_TLL_CHANNEL_COUNT); 580 usbhs_omap_tll_init(dev, OMAP_TLL_CHANNEL_COUNT);
594 } 581 }
595 582
596 if (pdata->ehci_data->phy_reset) {
597 /* Hold the PHY in RESET for enough time till
598 * PHY is settled and ready
599 */
600 udelay(10);
601
602 if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[0]))
603 gpio_set_value
604 (pdata->ehci_data->reset_gpio_port[0], 1);
605
606 if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[1]))
607 gpio_set_value
608 (pdata->ehci_data->reset_gpio_port[1], 1);
609 }
610
611 spin_unlock_irqrestore(&omap->lock, flags); 583 spin_unlock_irqrestore(&omap->lock, flags);
612 pm_runtime_put_sync(dev); 584 pm_runtime_put_sync(dev);
613} 585}
614 586
615static void omap_usbhs_deinit(struct device *dev)
616{
617 struct usbhs_hcd_omap *omap = dev_get_drvdata(dev);
618 struct usbhs_omap_platform_data *pdata = &omap->platdata;
619
620 if (pdata->ehci_data->phy_reset) {
621 if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[0]))
622 gpio_free(pdata->ehci_data->reset_gpio_port[0]);
623
624 if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[1]))
625 gpio_free(pdata->ehci_data->reset_gpio_port[1]);
626 }
627}
628
629 587
630/** 588/**
631 * usbhs_omap_probe - initialize TI-based HCDs 589 * usbhs_omap_probe - initialize TI-based HCDs
@@ -860,7 +818,6 @@ static int __devexit usbhs_omap_remove(struct platform_device *pdev)
860{ 818{
861 struct usbhs_hcd_omap *omap = platform_get_drvdata(pdev); 819 struct usbhs_hcd_omap *omap = platform_get_drvdata(pdev);
862 820
863 omap_usbhs_deinit(&pdev->dev);
864 iounmap(omap->tll_base); 821 iounmap(omap->tll_base);
865 iounmap(omap->uhh_base); 822 iounmap(omap->uhh_base);
866 clk_put(omap->init_60m_fclk); 823 clk_put(omap->init_60m_fclk);
diff --git a/drivers/mfd/rc5t583.c b/drivers/mfd/rc5t583.c
index 99ef944c621d..44afae0a69ce 100644
--- a/drivers/mfd/rc5t583.c
+++ b/drivers/mfd/rc5t583.c
@@ -80,44 +80,6 @@ static struct mfd_cell rc5t583_subdevs[] = {
80 {.name = "rc5t583-key", } 80 {.name = "rc5t583-key", }
81}; 81};
82 82
83int rc5t583_write(struct device *dev, uint8_t reg, uint8_t val)
84{
85 struct rc5t583 *rc5t583 = dev_get_drvdata(dev);
86 return regmap_write(rc5t583->regmap, reg, val);
87}
88
89int rc5t583_read(struct device *dev, uint8_t reg, uint8_t *val)
90{
91 struct rc5t583 *rc5t583 = dev_get_drvdata(dev);
92 unsigned int ival;
93 int ret;
94 ret = regmap_read(rc5t583->regmap, reg, &ival);
95 if (!ret)
96 *val = (uint8_t)ival;
97 return ret;
98}
99
100int rc5t583_set_bits(struct device *dev, unsigned int reg,
101 unsigned int bit_mask)
102{
103 struct rc5t583 *rc5t583 = dev_get_drvdata(dev);
104 return regmap_update_bits(rc5t583->regmap, reg, bit_mask, bit_mask);
105}
106
107int rc5t583_clear_bits(struct device *dev, unsigned int reg,
108 unsigned int bit_mask)
109{
110 struct rc5t583 *rc5t583 = dev_get_drvdata(dev);
111 return regmap_update_bits(rc5t583->regmap, reg, bit_mask, 0);
112}
113
114int rc5t583_update(struct device *dev, unsigned int reg,
115 unsigned int val, unsigned int mask)
116{
117 struct rc5t583 *rc5t583 = dev_get_drvdata(dev);
118 return regmap_update_bits(rc5t583->regmap, reg, mask, val);
119}
120
121static int __rc5t583_set_ext_pwrreq1_control(struct device *dev, 83static int __rc5t583_set_ext_pwrreq1_control(struct device *dev,
122 int id, int ext_pwr, int slots) 84 int id, int ext_pwr, int slots)
123{ 85{
@@ -197,6 +159,7 @@ int rc5t583_ext_power_req_config(struct device *dev, int ds_id,
197 ds_id, ext_pwr_req); 159 ds_id, ext_pwr_req);
198 return 0; 160 return 0;
199} 161}
162EXPORT_SYMBOL(rc5t583_ext_power_req_config);
200 163
201static int rc5t583_clear_ext_power_req(struct rc5t583 *rc5t583, 164static int rc5t583_clear_ext_power_req(struct rc5t583 *rc5t583,
202 struct rc5t583_platform_data *pdata) 165 struct rc5t583_platform_data *pdata)
diff --git a/drivers/mfd/twl6040-core.c b/drivers/mfd/twl6040-core.c
index b2d8e512d3cb..2d6bedadca09 100644
--- a/drivers/mfd/twl6040-core.c
+++ b/drivers/mfd/twl6040-core.c
@@ -30,7 +30,9 @@
30#include <linux/platform_device.h> 30#include <linux/platform_device.h>
31#include <linux/gpio.h> 31#include <linux/gpio.h>
32#include <linux/delay.h> 32#include <linux/delay.h>
33#include <linux/i2c/twl.h> 33#include <linux/i2c.h>
34#include <linux/regmap.h>
35#include <linux/err.h>
34#include <linux/mfd/core.h> 36#include <linux/mfd/core.h>
35#include <linux/mfd/twl6040.h> 37#include <linux/mfd/twl6040.h>
36 38
@@ -39,7 +41,7 @@
39int twl6040_reg_read(struct twl6040 *twl6040, unsigned int reg) 41int twl6040_reg_read(struct twl6040 *twl6040, unsigned int reg)
40{ 42{
41 int ret; 43 int ret;
42 u8 val = 0; 44 unsigned int val;
43 45
44 mutex_lock(&twl6040->io_mutex); 46 mutex_lock(&twl6040->io_mutex);
45 /* Vibra control registers from cache */ 47 /* Vibra control registers from cache */
@@ -47,7 +49,7 @@ int twl6040_reg_read(struct twl6040 *twl6040, unsigned int reg)
47 reg == TWL6040_REG_VIBCTLR)) { 49 reg == TWL6040_REG_VIBCTLR)) {
48 val = twl6040->vibra_ctrl_cache[VIBRACTRL_MEMBER(reg)]; 50 val = twl6040->vibra_ctrl_cache[VIBRACTRL_MEMBER(reg)];
49 } else { 51 } else {
50 ret = twl_i2c_read_u8(TWL_MODULE_AUDIO_VOICE, &val, reg); 52 ret = regmap_read(twl6040->regmap, reg, &val);
51 if (ret < 0) { 53 if (ret < 0) {
52 mutex_unlock(&twl6040->io_mutex); 54 mutex_unlock(&twl6040->io_mutex);
53 return ret; 55 return ret;
@@ -64,7 +66,7 @@ int twl6040_reg_write(struct twl6040 *twl6040, unsigned int reg, u8 val)
64 int ret; 66 int ret;
65 67
66 mutex_lock(&twl6040->io_mutex); 68 mutex_lock(&twl6040->io_mutex);
67 ret = twl_i2c_write_u8(TWL_MODULE_AUDIO_VOICE, val, reg); 69 ret = regmap_write(twl6040->regmap, reg, val);
68 /* Cache the vibra control registers */ 70 /* Cache the vibra control registers */
69 if (reg == TWL6040_REG_VIBCTLL || reg == TWL6040_REG_VIBCTLR) 71 if (reg == TWL6040_REG_VIBCTLL || reg == TWL6040_REG_VIBCTLR)
70 twl6040->vibra_ctrl_cache[VIBRACTRL_MEMBER(reg)] = val; 72 twl6040->vibra_ctrl_cache[VIBRACTRL_MEMBER(reg)] = val;
@@ -77,16 +79,9 @@ EXPORT_SYMBOL(twl6040_reg_write);
77int twl6040_set_bits(struct twl6040 *twl6040, unsigned int reg, u8 mask) 79int twl6040_set_bits(struct twl6040 *twl6040, unsigned int reg, u8 mask)
78{ 80{
79 int ret; 81 int ret;
80 u8 val;
81 82
82 mutex_lock(&twl6040->io_mutex); 83 mutex_lock(&twl6040->io_mutex);
83 ret = twl_i2c_read_u8(TWL_MODULE_AUDIO_VOICE, &val, reg); 84 ret = regmap_update_bits(twl6040->regmap, reg, mask, mask);
84 if (ret)
85 goto out;
86
87 val |= mask;
88 ret = twl_i2c_write_u8(TWL_MODULE_AUDIO_VOICE, val, reg);
89out:
90 mutex_unlock(&twl6040->io_mutex); 85 mutex_unlock(&twl6040->io_mutex);
91 return ret; 86 return ret;
92} 87}
@@ -95,16 +90,9 @@ EXPORT_SYMBOL(twl6040_set_bits);
95int twl6040_clear_bits(struct twl6040 *twl6040, unsigned int reg, u8 mask) 90int twl6040_clear_bits(struct twl6040 *twl6040, unsigned int reg, u8 mask)
96{ 91{
97 int ret; 92 int ret;
98 u8 val;
99 93
100 mutex_lock(&twl6040->io_mutex); 94 mutex_lock(&twl6040->io_mutex);
101 ret = twl_i2c_read_u8(TWL_MODULE_AUDIO_VOICE, &val, reg); 95 ret = regmap_update_bits(twl6040->regmap, reg, mask, 0);
102 if (ret)
103 goto out;
104
105 val &= ~mask;
106 ret = twl_i2c_write_u8(TWL_MODULE_AUDIO_VOICE, val, reg);
107out:
108 mutex_unlock(&twl6040->io_mutex); 96 mutex_unlock(&twl6040->io_mutex);
109 return ret; 97 return ret;
110} 98}
@@ -494,32 +482,58 @@ static struct resource twl6040_codec_rsrc[] = {
494 }, 482 },
495}; 483};
496 484
497static int __devinit twl6040_probe(struct platform_device *pdev) 485static bool twl6040_readable_reg(struct device *dev, unsigned int reg)
498{ 486{
499 struct twl4030_audio_data *pdata = pdev->dev.platform_data; 487 /* Register 0 is not readable */
488 if (!reg)
489 return false;
490 return true;
491}
492
493static struct regmap_config twl6040_regmap_config = {
494 .reg_bits = 8,
495 .val_bits = 8,
496 .max_register = TWL6040_REG_STATUS, /* 0x2e */
497
498 .readable_reg = twl6040_readable_reg,
499};
500
501static int __devinit twl6040_probe(struct i2c_client *client,
502 const struct i2c_device_id *id)
503{
504 struct twl6040_platform_data *pdata = client->dev.platform_data;
500 struct twl6040 *twl6040; 505 struct twl6040 *twl6040;
501 struct mfd_cell *cell = NULL; 506 struct mfd_cell *cell = NULL;
502 int ret, children = 0; 507 int ret, children = 0;
503 508
504 if (!pdata) { 509 if (!pdata) {
505 dev_err(&pdev->dev, "Platform data is missing\n"); 510 dev_err(&client->dev, "Platform data is missing\n");
506 return -EINVAL; 511 return -EINVAL;
507 } 512 }
508 513
509 /* In order to operate correctly we need valid interrupt config */ 514 /* In order to operate correctly we need valid interrupt config */
510 if (!pdata->naudint_irq || !pdata->irq_base) { 515 if (!client->irq || !pdata->irq_base) {
511 dev_err(&pdev->dev, "Invalid IRQ configuration\n"); 516 dev_err(&client->dev, "Invalid IRQ configuration\n");
512 return -EINVAL; 517 return -EINVAL;
513 } 518 }
514 519
515 twl6040 = kzalloc(sizeof(struct twl6040), GFP_KERNEL); 520 twl6040 = devm_kzalloc(&client->dev, sizeof(struct twl6040),
516 if (!twl6040) 521 GFP_KERNEL);
517 return -ENOMEM; 522 if (!twl6040) {
523 ret = -ENOMEM;
524 goto err;
525 }
526
527 twl6040->regmap = regmap_init_i2c(client, &twl6040_regmap_config);
528 if (IS_ERR(twl6040->regmap)) {
529 ret = PTR_ERR(twl6040->regmap);
530 goto err;
531 }
518 532
519 platform_set_drvdata(pdev, twl6040); 533 i2c_set_clientdata(client, twl6040);
520 534
521 twl6040->dev = &pdev->dev; 535 twl6040->dev = &client->dev;
522 twl6040->irq = pdata->naudint_irq; 536 twl6040->irq = client->irq;
523 twl6040->irq_base = pdata->irq_base; 537 twl6040->irq_base = pdata->irq_base;
524 538
525 mutex_init(&twl6040->mutex); 539 mutex_init(&twl6040->mutex);
@@ -588,12 +602,12 @@ static int __devinit twl6040_probe(struct platform_device *pdev)
588 } 602 }
589 603
590 if (children) { 604 if (children) {
591 ret = mfd_add_devices(&pdev->dev, pdev->id, twl6040->cells, 605 ret = mfd_add_devices(&client->dev, -1, twl6040->cells,
592 children, NULL, 0); 606 children, NULL, 0);
593 if (ret) 607 if (ret)
594 goto mfd_err; 608 goto mfd_err;
595 } else { 609 } else {
596 dev_err(&pdev->dev, "No platform data found for children\n"); 610 dev_err(&client->dev, "No platform data found for children\n");
597 ret = -ENODEV; 611 ret = -ENODEV;
598 goto mfd_err; 612 goto mfd_err;
599 } 613 }
@@ -608,14 +622,15 @@ gpio2_err:
608 if (gpio_is_valid(twl6040->audpwron)) 622 if (gpio_is_valid(twl6040->audpwron))
609 gpio_free(twl6040->audpwron); 623 gpio_free(twl6040->audpwron);
610gpio1_err: 624gpio1_err:
611 platform_set_drvdata(pdev, NULL); 625 i2c_set_clientdata(client, NULL);
612 kfree(twl6040); 626 regmap_exit(twl6040->regmap);
627err:
613 return ret; 628 return ret;
614} 629}
615 630
616static int __devexit twl6040_remove(struct platform_device *pdev) 631static int __devexit twl6040_remove(struct i2c_client *client)
617{ 632{
618 struct twl6040 *twl6040 = platform_get_drvdata(pdev); 633 struct twl6040 *twl6040 = i2c_get_clientdata(client);
619 634
620 if (twl6040->power_count) 635 if (twl6040->power_count)
621 twl6040_power(twl6040, 0); 636 twl6040_power(twl6040, 0);
@@ -626,23 +641,30 @@ static int __devexit twl6040_remove(struct platform_device *pdev)
626 free_irq(twl6040->irq_base + TWL6040_IRQ_READY, twl6040); 641 free_irq(twl6040->irq_base + TWL6040_IRQ_READY, twl6040);
627 twl6040_irq_exit(twl6040); 642 twl6040_irq_exit(twl6040);
628 643
629 mfd_remove_devices(&pdev->dev); 644 mfd_remove_devices(&client->dev);
630 platform_set_drvdata(pdev, NULL); 645 i2c_set_clientdata(client, NULL);
631 kfree(twl6040); 646 regmap_exit(twl6040->regmap);
632 647
633 return 0; 648 return 0;
634} 649}
635 650
636static struct platform_driver twl6040_driver = { 651static const struct i2c_device_id twl6040_i2c_id[] = {
652 { "twl6040", 0, },
653 { },
654};
655MODULE_DEVICE_TABLE(i2c, twl6040_i2c_id);
656
657static struct i2c_driver twl6040_driver = {
658 .driver = {
659 .name = "twl6040",
660 .owner = THIS_MODULE,
661 },
637 .probe = twl6040_probe, 662 .probe = twl6040_probe,
638 .remove = __devexit_p(twl6040_remove), 663 .remove = __devexit_p(twl6040_remove),
639 .driver = { 664 .id_table = twl6040_i2c_id,
640 .owner = THIS_MODULE,
641 .name = "twl6040",
642 },
643}; 665};
644 666
645module_platform_driver(twl6040_driver); 667module_i2c_driver(twl6040_driver);
646 668
647MODULE_DESCRIPTION("TWL6040 MFD"); 669MODULE_DESCRIPTION("TWL6040 MFD");
648MODULE_AUTHOR("Misael Lopez Cruz <misael.lopez@ti.com>"); 670MODULE_AUTHOR("Misael Lopez Cruz <misael.lopez@ti.com>");
diff --git a/drivers/misc/ibmasm/ibmasmfs.c b/drivers/misc/ibmasm/ibmasmfs.c
index 1c034b80d408..6673e578b3e9 100644
--- a/drivers/misc/ibmasm/ibmasmfs.c
+++ b/drivers/misc/ibmasm/ibmasmfs.c
@@ -500,12 +500,6 @@ static ssize_t r_heartbeat_file_write(struct file *file, const char __user *buf,
500 return 1; 500 return 1;
501} 501}
502 502
503static int remote_settings_file_open(struct inode *inode, struct file *file)
504{
505 file->private_data = inode->i_private;
506 return 0;
507}
508
509static int remote_settings_file_close(struct inode *inode, struct file *file) 503static int remote_settings_file_close(struct inode *inode, struct file *file)
510{ 504{
511 return 0; 505 return 0;
@@ -600,7 +594,7 @@ static const struct file_operations r_heartbeat_fops = {
600}; 594};
601 595
602static const struct file_operations remote_settings_fops = { 596static const struct file_operations remote_settings_fops = {
603 .open = remote_settings_file_open, 597 .open = simple_open,
604 .release = remote_settings_file_close, 598 .release = remote_settings_file_close,
605 .read = remote_settings_file_read, 599 .read = remote_settings_file_read,
606 .write = remote_settings_file_write, 600 .write = remote_settings_file_write,
diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
index 3f7ad83ed740..3aa9a969b373 100644
--- a/drivers/misc/kgdbts.c
+++ b/drivers/misc/kgdbts.c
@@ -134,12 +134,17 @@ static int force_hwbrks;
134static int hwbreaks_ok; 134static int hwbreaks_ok;
135static int hw_break_val; 135static int hw_break_val;
136static int hw_break_val2; 136static int hw_break_val2;
137static int cont_instead_of_sstep;
138static unsigned long cont_thread_id;
139static unsigned long sstep_thread_id;
137#if defined(CONFIG_ARM) || defined(CONFIG_MIPS) || defined(CONFIG_SPARC) 140#if defined(CONFIG_ARM) || defined(CONFIG_MIPS) || defined(CONFIG_SPARC)
138static int arch_needs_sstep_emulation = 1; 141static int arch_needs_sstep_emulation = 1;
139#else 142#else
140static int arch_needs_sstep_emulation; 143static int arch_needs_sstep_emulation;
141#endif 144#endif
145static unsigned long cont_addr;
142static unsigned long sstep_addr; 146static unsigned long sstep_addr;
147static int restart_from_top_after_write;
143static int sstep_state; 148static int sstep_state;
144 149
145/* Storage for the registers, in GDB format. */ 150/* Storage for the registers, in GDB format. */
@@ -187,7 +192,8 @@ static int kgdbts_unreg_thread(void *ptr)
187 */ 192 */
188 while (!final_ack) 193 while (!final_ack)
189 msleep_interruptible(1500); 194 msleep_interruptible(1500);
190 195 /* Pause for any other threads to exit after final ack. */
196 msleep_interruptible(1000);
191 if (configured) 197 if (configured)
192 kgdb_unregister_io_module(&kgdbts_io_ops); 198 kgdb_unregister_io_module(&kgdbts_io_ops);
193 configured = 0; 199 configured = 0;
@@ -211,7 +217,7 @@ static unsigned long lookup_addr(char *arg)
211 if (!strcmp(arg, "kgdbts_break_test")) 217 if (!strcmp(arg, "kgdbts_break_test"))
212 addr = (unsigned long)kgdbts_break_test; 218 addr = (unsigned long)kgdbts_break_test;
213 else if (!strcmp(arg, "sys_open")) 219 else if (!strcmp(arg, "sys_open"))
214 addr = (unsigned long)sys_open; 220 addr = (unsigned long)do_sys_open;
215 else if (!strcmp(arg, "do_fork")) 221 else if (!strcmp(arg, "do_fork"))
216 addr = (unsigned long)do_fork; 222 addr = (unsigned long)do_fork;
217 else if (!strcmp(arg, "hw_break_val")) 223 else if (!strcmp(arg, "hw_break_val"))
@@ -283,6 +289,16 @@ static void hw_break_val_write(void)
283 hw_break_val++; 289 hw_break_val++;
284} 290}
285 291
292static int get_thread_id_continue(char *put_str, char *arg)
293{
294 char *ptr = &put_str[11];
295
296 if (put_str[1] != 'T' || put_str[2] != '0')
297 return 1;
298 kgdb_hex2long(&ptr, &cont_thread_id);
299 return 0;
300}
301
286static int check_and_rewind_pc(char *put_str, char *arg) 302static int check_and_rewind_pc(char *put_str, char *arg)
287{ 303{
288 unsigned long addr = lookup_addr(arg); 304 unsigned long addr = lookup_addr(arg);
@@ -299,13 +315,21 @@ static int check_and_rewind_pc(char *put_str, char *arg)
299 if (addr + BREAK_INSTR_SIZE == ip) 315 if (addr + BREAK_INSTR_SIZE == ip)
300 offset = -BREAK_INSTR_SIZE; 316 offset = -BREAK_INSTR_SIZE;
301#endif 317#endif
302 if (strcmp(arg, "silent") && ip + offset != addr) { 318
319 if (arch_needs_sstep_emulation && sstep_addr &&
320 ip + offset == sstep_addr &&
321 ((!strcmp(arg, "sys_open") || !strcmp(arg, "do_fork")))) {
322 /* This is special case for emulated single step */
323 v2printk("Emul: rewind hit single step bp\n");
324 restart_from_top_after_write = 1;
325 } else if (strcmp(arg, "silent") && ip + offset != addr) {
303 eprintk("kgdbts: BP mismatch %lx expected %lx\n", 326 eprintk("kgdbts: BP mismatch %lx expected %lx\n",
304 ip + offset, addr); 327 ip + offset, addr);
305 return 1; 328 return 1;
306 } 329 }
307 /* Readjust the instruction pointer if needed */ 330 /* Readjust the instruction pointer if needed */
308 ip += offset; 331 ip += offset;
332 cont_addr = ip;
309#ifdef GDB_ADJUSTS_BREAK_OFFSET 333#ifdef GDB_ADJUSTS_BREAK_OFFSET
310 instruction_pointer_set(&kgdbts_regs, ip); 334 instruction_pointer_set(&kgdbts_regs, ip);
311#endif 335#endif
@@ -315,6 +339,8 @@ static int check_and_rewind_pc(char *put_str, char *arg)
315static int check_single_step(char *put_str, char *arg) 339static int check_single_step(char *put_str, char *arg)
316{ 340{
317 unsigned long addr = lookup_addr(arg); 341 unsigned long addr = lookup_addr(arg);
342 static int matched_id;
343
318 /* 344 /*
319 * From an arch indepent point of view the instruction pointer 345 * From an arch indepent point of view the instruction pointer
320 * should be on a different instruction 346 * should be on a different instruction
@@ -324,6 +350,29 @@ static int check_single_step(char *put_str, char *arg)
324 gdb_regs_to_pt_regs(kgdbts_gdb_regs, &kgdbts_regs); 350 gdb_regs_to_pt_regs(kgdbts_gdb_regs, &kgdbts_regs);
325 v2printk("Singlestep stopped at IP: %lx\n", 351 v2printk("Singlestep stopped at IP: %lx\n",
326 instruction_pointer(&kgdbts_regs)); 352 instruction_pointer(&kgdbts_regs));
353
354 if (sstep_thread_id != cont_thread_id) {
355 /*
356 * Ensure we stopped in the same thread id as before, else the
357 * debugger should continue until the original thread that was
358 * single stepped is scheduled again, emulating gdb's behavior.
359 */
360 v2printk("ThrID does not match: %lx\n", cont_thread_id);
361 if (arch_needs_sstep_emulation) {
362 if (matched_id &&
363 instruction_pointer(&kgdbts_regs) != addr)
364 goto continue_test;
365 matched_id++;
366 ts.idx -= 2;
367 sstep_state = 0;
368 return 0;
369 }
370 cont_instead_of_sstep = 1;
371 ts.idx -= 4;
372 return 0;
373 }
374continue_test:
375 matched_id = 0;
327 if (instruction_pointer(&kgdbts_regs) == addr) { 376 if (instruction_pointer(&kgdbts_regs) == addr) {
328 eprintk("kgdbts: SingleStep failed at %lx\n", 377 eprintk("kgdbts: SingleStep failed at %lx\n",
329 instruction_pointer(&kgdbts_regs)); 378 instruction_pointer(&kgdbts_regs));
@@ -365,10 +414,40 @@ static int got_break(char *put_str, char *arg)
365 return 1; 414 return 1;
366} 415}
367 416
417static void get_cont_catch(char *arg)
418{
419 /* Always send detach because the test is completed at this point */
420 fill_get_buf("D");
421}
422
423static int put_cont_catch(char *put_str, char *arg)
424{
425 /* This is at the end of the test and we catch any and all input */
426 v2printk("kgdbts: cleanup task: %lx\n", sstep_thread_id);
427 ts.idx--;
428 return 0;
429}
430
431static int emul_reset(char *put_str, char *arg)
432{
433 if (strncmp(put_str, "$OK", 3))
434 return 1;
435 if (restart_from_top_after_write) {
436 restart_from_top_after_write = 0;
437 ts.idx = -1;
438 }
439 return 0;
440}
441
368static void emul_sstep_get(char *arg) 442static void emul_sstep_get(char *arg)
369{ 443{
370 if (!arch_needs_sstep_emulation) { 444 if (!arch_needs_sstep_emulation) {
371 fill_get_buf(arg); 445 if (cont_instead_of_sstep) {
446 cont_instead_of_sstep = 0;
447 fill_get_buf("c");
448 } else {
449 fill_get_buf(arg);
450 }
372 return; 451 return;
373 } 452 }
374 switch (sstep_state) { 453 switch (sstep_state) {
@@ -398,9 +477,11 @@ static void emul_sstep_get(char *arg)
398static int emul_sstep_put(char *put_str, char *arg) 477static int emul_sstep_put(char *put_str, char *arg)
399{ 478{
400 if (!arch_needs_sstep_emulation) { 479 if (!arch_needs_sstep_emulation) {
401 if (!strncmp(put_str+1, arg, 2)) 480 char *ptr = &put_str[11];
402 return 0; 481 if (put_str[1] != 'T' || put_str[2] != '0')
403 return 1; 482 return 1;
483 kgdb_hex2long(&ptr, &sstep_thread_id);
484 return 0;
404 } 485 }
405 switch (sstep_state) { 486 switch (sstep_state) {
406 case 1: 487 case 1:
@@ -411,8 +492,7 @@ static int emul_sstep_put(char *put_str, char *arg)
411 v2printk("Stopped at IP: %lx\n", 492 v2printk("Stopped at IP: %lx\n",
412 instruction_pointer(&kgdbts_regs)); 493 instruction_pointer(&kgdbts_regs));
413 /* Want to stop at IP + break instruction size by default */ 494 /* Want to stop at IP + break instruction size by default */
414 sstep_addr = instruction_pointer(&kgdbts_regs) + 495 sstep_addr = cont_addr + BREAK_INSTR_SIZE;
415 BREAK_INSTR_SIZE;
416 break; 496 break;
417 case 2: 497 case 2:
418 if (strncmp(put_str, "$OK", 3)) { 498 if (strncmp(put_str, "$OK", 3)) {
@@ -424,6 +504,9 @@ static int emul_sstep_put(char *put_str, char *arg)
424 if (strncmp(put_str, "$T0", 3)) { 504 if (strncmp(put_str, "$T0", 3)) {
425 eprintk("kgdbts: failed continue sstep\n"); 505 eprintk("kgdbts: failed continue sstep\n");
426 return 1; 506 return 1;
507 } else {
508 char *ptr = &put_str[11];
509 kgdb_hex2long(&ptr, &sstep_thread_id);
427 } 510 }
428 break; 511 break;
429 case 4: 512 case 4:
@@ -502,10 +585,10 @@ static struct test_struct bad_read_test[] = {
502static struct test_struct singlestep_break_test[] = { 585static struct test_struct singlestep_break_test[] = {
503 { "?", "S0*" }, /* Clear break points */ 586 { "?", "S0*" }, /* Clear break points */
504 { "kgdbts_break_test", "OK", sw_break, }, /* set sw breakpoint */ 587 { "kgdbts_break_test", "OK", sw_break, }, /* set sw breakpoint */
505 { "c", "T0*", }, /* Continue */ 588 { "c", "T0*", NULL, get_thread_id_continue }, /* Continue */
589 { "kgdbts_break_test", "OK", sw_rem_break }, /*remove breakpoint */
506 { "g", "kgdbts_break_test", NULL, check_and_rewind_pc }, 590 { "g", "kgdbts_break_test", NULL, check_and_rewind_pc },
507 { "write", "OK", write_regs }, /* Write registers */ 591 { "write", "OK", write_regs }, /* Write registers */
508 { "kgdbts_break_test", "OK", sw_rem_break }, /*remove breakpoint */
509 { "s", "T0*", emul_sstep_get, emul_sstep_put }, /* Single step */ 592 { "s", "T0*", emul_sstep_get, emul_sstep_put }, /* Single step */
510 { "g", "kgdbts_break_test", NULL, check_single_step }, 593 { "g", "kgdbts_break_test", NULL, check_single_step },
511 { "kgdbts_break_test", "OK", sw_break, }, /* set sw breakpoint */ 594 { "kgdbts_break_test", "OK", sw_break, }, /* set sw breakpoint */
@@ -523,16 +606,16 @@ static struct test_struct singlestep_break_test[] = {
523static struct test_struct do_fork_test[] = { 606static struct test_struct do_fork_test[] = {
524 { "?", "S0*" }, /* Clear break points */ 607 { "?", "S0*" }, /* Clear break points */
525 { "do_fork", "OK", sw_break, }, /* set sw breakpoint */ 608 { "do_fork", "OK", sw_break, }, /* set sw breakpoint */
526 { "c", "T0*", }, /* Continue */ 609 { "c", "T0*", NULL, get_thread_id_continue }, /* Continue */
527 { "g", "do_fork", NULL, check_and_rewind_pc }, /* check location */
528 { "write", "OK", write_regs }, /* Write registers */
529 { "do_fork", "OK", sw_rem_break }, /*remove breakpoint */ 610 { "do_fork", "OK", sw_rem_break }, /*remove breakpoint */
611 { "g", "do_fork", NULL, check_and_rewind_pc }, /* check location */
612 { "write", "OK", write_regs, emul_reset }, /* Write registers */
530 { "s", "T0*", emul_sstep_get, emul_sstep_put }, /* Single step */ 613 { "s", "T0*", emul_sstep_get, emul_sstep_put }, /* Single step */
531 { "g", "do_fork", NULL, check_single_step }, 614 { "g", "do_fork", NULL, check_single_step },
532 { "do_fork", "OK", sw_break, }, /* set sw breakpoint */ 615 { "do_fork", "OK", sw_break, }, /* set sw breakpoint */
533 { "7", "T0*", skip_back_repeat_test }, /* Loop based on repeat_test */ 616 { "7", "T0*", skip_back_repeat_test }, /* Loop based on repeat_test */
534 { "D", "OK", NULL, final_ack_set }, /* detach and unregister I/O */ 617 { "D", "OK", NULL, final_ack_set }, /* detach and unregister I/O */
535 { "", "" }, 618 { "", "", get_cont_catch, put_cont_catch },
536}; 619};
537 620
538/* Test for hitting a breakpoint at sys_open for what ever the number 621/* Test for hitting a breakpoint at sys_open for what ever the number
@@ -541,16 +624,16 @@ static struct test_struct do_fork_test[] = {
541static struct test_struct sys_open_test[] = { 624static struct test_struct sys_open_test[] = {
542 { "?", "S0*" }, /* Clear break points */ 625 { "?", "S0*" }, /* Clear break points */
543 { "sys_open", "OK", sw_break, }, /* set sw breakpoint */ 626 { "sys_open", "OK", sw_break, }, /* set sw breakpoint */
544 { "c", "T0*", }, /* Continue */ 627 { "c", "T0*", NULL, get_thread_id_continue }, /* Continue */
545 { "g", "sys_open", NULL, check_and_rewind_pc }, /* check location */
546 { "write", "OK", write_regs }, /* Write registers */
547 { "sys_open", "OK", sw_rem_break }, /*remove breakpoint */ 628 { "sys_open", "OK", sw_rem_break }, /*remove breakpoint */
629 { "g", "sys_open", NULL, check_and_rewind_pc }, /* check location */
630 { "write", "OK", write_regs, emul_reset }, /* Write registers */
548 { "s", "T0*", emul_sstep_get, emul_sstep_put }, /* Single step */ 631 { "s", "T0*", emul_sstep_get, emul_sstep_put }, /* Single step */
549 { "g", "sys_open", NULL, check_single_step }, 632 { "g", "sys_open", NULL, check_single_step },
550 { "sys_open", "OK", sw_break, }, /* set sw breakpoint */ 633 { "sys_open", "OK", sw_break, }, /* set sw breakpoint */
551 { "7", "T0*", skip_back_repeat_test }, /* Loop based on repeat_test */ 634 { "7", "T0*", skip_back_repeat_test }, /* Loop based on repeat_test */
552 { "D", "OK", NULL, final_ack_set }, /* detach and unregister I/O */ 635 { "D", "OK", NULL, final_ack_set }, /* detach and unregister I/O */
553 { "", "" }, 636 { "", "", get_cont_catch, put_cont_catch },
554}; 637};
555 638
556/* 639/*
@@ -693,8 +776,8 @@ static int run_simple_test(int is_get_char, int chr)
693 /* This callback is a put char which is when kgdb sends data to 776 /* This callback is a put char which is when kgdb sends data to
694 * this I/O module. 777 * this I/O module.
695 */ 778 */
696 if (ts.tst[ts.idx].get[0] == '\0' && 779 if (ts.tst[ts.idx].get[0] == '\0' && ts.tst[ts.idx].put[0] == '\0' &&
697 ts.tst[ts.idx].put[0] == '\0') { 780 !ts.tst[ts.idx].get_handler) {
698 eprintk("kgdbts: ERROR: beyond end of test on" 781 eprintk("kgdbts: ERROR: beyond end of test on"
699 " '%s' line %i\n", ts.name, ts.idx); 782 " '%s' line %i\n", ts.name, ts.idx);
700 return 0; 783 return 0;
@@ -907,6 +990,17 @@ static void kgdbts_run_tests(void)
907 if (ptr) 990 if (ptr)
908 sstep_test = simple_strtol(ptr+1, NULL, 10); 991 sstep_test = simple_strtol(ptr+1, NULL, 10);
909 992
993 /* All HW break point tests */
994 if (arch_kgdb_ops.flags & KGDB_HW_BREAKPOINT) {
995 hwbreaks_ok = 1;
996 v1printk("kgdbts:RUN hw breakpoint test\n");
997 run_breakpoint_test(1);
998 v1printk("kgdbts:RUN hw write breakpoint test\n");
999 run_hw_break_test(1);
1000 v1printk("kgdbts:RUN access write breakpoint test\n");
1001 run_hw_break_test(0);
1002 }
1003
910 /* required internal KGDB tests */ 1004 /* required internal KGDB tests */
911 v1printk("kgdbts:RUN plant and detach test\n"); 1005 v1printk("kgdbts:RUN plant and detach test\n");
912 run_plant_and_detach_test(0); 1006 run_plant_and_detach_test(0);
@@ -924,35 +1018,11 @@ static void kgdbts_run_tests(void)
924 1018
925 /* ===Optional tests=== */ 1019 /* ===Optional tests=== */
926 1020
927 /* All HW break point tests */
928 if (arch_kgdb_ops.flags & KGDB_HW_BREAKPOINT) {
929 hwbreaks_ok = 1;
930 v1printk("kgdbts:RUN hw breakpoint test\n");
931 run_breakpoint_test(1);
932 v1printk("kgdbts:RUN hw write breakpoint test\n");
933 run_hw_break_test(1);
934 v1printk("kgdbts:RUN access write breakpoint test\n");
935 run_hw_break_test(0);
936 }
937
938 if (nmi_sleep) { 1021 if (nmi_sleep) {
939 v1printk("kgdbts:RUN NMI sleep %i seconds test\n", nmi_sleep); 1022 v1printk("kgdbts:RUN NMI sleep %i seconds test\n", nmi_sleep);
940 run_nmi_sleep_test(nmi_sleep); 1023 run_nmi_sleep_test(nmi_sleep);
941 } 1024 }
942 1025
943#ifdef CONFIG_DEBUG_RODATA
944 /* Until there is an api to write to read-only text segments, use
945 * HW breakpoints for the remainder of any tests, else print a
946 * failure message if hw breakpoints do not work.
947 */
948 if (!(arch_kgdb_ops.flags & KGDB_HW_BREAKPOINT && hwbreaks_ok)) {
949 eprintk("kgdbts: HW breakpoints do not work,"
950 "skipping remaining tests\n");
951 return;
952 }
953 force_hwbrks = 1;
954#endif /* CONFIG_DEBUG_RODATA */
955
956 /* If the do_fork test is run it will be the last test that is 1026 /* If the do_fork test is run it will be the last test that is
957 * executed because a kernel thread will be spawned at the very 1027 * executed because a kernel thread will be spawned at the very
958 * end to unregister the debug hooks. 1028 * end to unregister the debug hooks.
diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
index eed213a5c8cb..dabec556ebb8 100644
--- a/drivers/mmc/card/block.c
+++ b/drivers/mmc/card/block.c
@@ -873,7 +873,7 @@ static int mmc_blk_issue_secdiscard_rq(struct mmc_queue *mq,
873{ 873{
874 struct mmc_blk_data *md = mq->data; 874 struct mmc_blk_data *md = mq->data;
875 struct mmc_card *card = md->queue.card; 875 struct mmc_card *card = md->queue.card;
876 unsigned int from, nr, arg; 876 unsigned int from, nr, arg, trim_arg, erase_arg;
877 int err = 0, type = MMC_BLK_SECDISCARD; 877 int err = 0, type = MMC_BLK_SECDISCARD;
878 878
879 if (!(mmc_can_secure_erase_trim(card) || mmc_can_sanitize(card))) { 879 if (!(mmc_can_secure_erase_trim(card) || mmc_can_sanitize(card))) {
@@ -881,20 +881,26 @@ static int mmc_blk_issue_secdiscard_rq(struct mmc_queue *mq,
881 goto out; 881 goto out;
882 } 882 }
883 883
884 from = blk_rq_pos(req);
885 nr = blk_rq_sectors(req);
886
884 /* The sanitize operation is supported at v4.5 only */ 887 /* The sanitize operation is supported at v4.5 only */
885 if (mmc_can_sanitize(card)) { 888 if (mmc_can_sanitize(card)) {
886 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 889 erase_arg = MMC_ERASE_ARG;
887 EXT_CSD_SANITIZE_START, 1, 0); 890 trim_arg = MMC_TRIM_ARG;
888 goto out; 891 } else {
892 erase_arg = MMC_SECURE_ERASE_ARG;
893 trim_arg = MMC_SECURE_TRIM1_ARG;
889 } 894 }
890 895
891 from = blk_rq_pos(req); 896 if (mmc_erase_group_aligned(card, from, nr))
892 nr = blk_rq_sectors(req); 897 arg = erase_arg;
893 898 else if (mmc_can_trim(card))
894 if (mmc_can_trim(card) && !mmc_erase_group_aligned(card, from, nr)) 899 arg = trim_arg;
895 arg = MMC_SECURE_TRIM1_ARG; 900 else {
896 else 901 err = -EINVAL;
897 arg = MMC_SECURE_ERASE_ARG; 902 goto out;
903 }
898retry: 904retry:
899 if (card->quirks & MMC_QUIRK_INAND_CMD38) { 905 if (card->quirks & MMC_QUIRK_INAND_CMD38) {
900 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 906 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
@@ -904,25 +910,41 @@ retry:
904 INAND_CMD38_ARG_SECERASE, 910 INAND_CMD38_ARG_SECERASE,
905 0); 911 0);
906 if (err) 912 if (err)
907 goto out; 913 goto out_retry;
908 } 914 }
915
909 err = mmc_erase(card, from, nr, arg); 916 err = mmc_erase(card, from, nr, arg);
910 if (!err && arg == MMC_SECURE_TRIM1_ARG) { 917 if (err == -EIO)
918 goto out_retry;
919 if (err)
920 goto out;
921
922 if (arg == MMC_SECURE_TRIM1_ARG) {
911 if (card->quirks & MMC_QUIRK_INAND_CMD38) { 923 if (card->quirks & MMC_QUIRK_INAND_CMD38) {
912 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 924 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
913 INAND_CMD38_ARG_EXT_CSD, 925 INAND_CMD38_ARG_EXT_CSD,
914 INAND_CMD38_ARG_SECTRIM2, 926 INAND_CMD38_ARG_SECTRIM2,
915 0); 927 0);
916 if (err) 928 if (err)
917 goto out; 929 goto out_retry;
918 } 930 }
931
919 err = mmc_erase(card, from, nr, MMC_SECURE_TRIM2_ARG); 932 err = mmc_erase(card, from, nr, MMC_SECURE_TRIM2_ARG);
933 if (err == -EIO)
934 goto out_retry;
935 if (err)
936 goto out;
920 } 937 }
921out: 938
922 if (err == -EIO && !mmc_blk_reset(md, card->host, type)) 939 if (mmc_can_sanitize(card))
940 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
941 EXT_CSD_SANITIZE_START, 1, 0);
942out_retry:
943 if (err && !mmc_blk_reset(md, card->host, type))
923 goto retry; 944 goto retry;
924 if (!err) 945 if (!err)
925 mmc_blk_reset_success(md, type); 946 mmc_blk_reset_success(md, type);
947out:
926 spin_lock_irq(&md->lock); 948 spin_lock_irq(&md->lock);
927 __blk_end_request(req, err, blk_rq_bytes(req)); 949 __blk_end_request(req, err, blk_rq_bytes(req));
928 spin_unlock_irq(&md->lock); 950 spin_unlock_irq(&md->lock);
@@ -1623,24 +1645,6 @@ static int mmc_blk_alloc_parts(struct mmc_card *card, struct mmc_blk_data *md)
1623 return ret; 1645 return ret;
1624} 1646}
1625 1647
1626static int
1627mmc_blk_set_blksize(struct mmc_blk_data *md, struct mmc_card *card)
1628{
1629 int err;
1630
1631 mmc_claim_host(card->host);
1632 err = mmc_set_blocklen(card, 512);
1633 mmc_release_host(card->host);
1634
1635 if (err) {
1636 pr_err("%s: unable to set block size to 512: %d\n",
1637 md->disk->disk_name, err);
1638 return -EINVAL;
1639 }
1640
1641 return 0;
1642}
1643
1644static void mmc_blk_remove_req(struct mmc_blk_data *md) 1648static void mmc_blk_remove_req(struct mmc_blk_data *md)
1645{ 1649{
1646 struct mmc_card *card; 1650 struct mmc_card *card;
@@ -1768,7 +1772,6 @@ static const struct mmc_fixup blk_fixups[] =
1768static int mmc_blk_probe(struct mmc_card *card) 1772static int mmc_blk_probe(struct mmc_card *card)
1769{ 1773{
1770 struct mmc_blk_data *md, *part_md; 1774 struct mmc_blk_data *md, *part_md;
1771 int err;
1772 char cap_str[10]; 1775 char cap_str[10];
1773 1776
1774 /* 1777 /*
@@ -1781,10 +1784,6 @@ static int mmc_blk_probe(struct mmc_card *card)
1781 if (IS_ERR(md)) 1784 if (IS_ERR(md))
1782 return PTR_ERR(md); 1785 return PTR_ERR(md);
1783 1786
1784 err = mmc_blk_set_blksize(md, card);
1785 if (err)
1786 goto out;
1787
1788 string_get_size((u64)get_capacity(md->disk) << 9, STRING_UNITS_2, 1787 string_get_size((u64)get_capacity(md->disk) << 9, STRING_UNITS_2,
1789 cap_str, sizeof(cap_str)); 1788 cap_str, sizeof(cap_str));
1790 pr_info("%s: %s %s %s %s\n", 1789 pr_info("%s: %s %s %s %s\n",
@@ -1809,7 +1808,7 @@ static int mmc_blk_probe(struct mmc_card *card)
1809 out: 1808 out:
1810 mmc_blk_remove_parts(card, md); 1809 mmc_blk_remove_parts(card, md);
1811 mmc_blk_remove_req(md); 1810 mmc_blk_remove_req(md);
1812 return err; 1811 return 0;
1813} 1812}
1814 1813
1815static void mmc_blk_remove(struct mmc_card *card) 1814static void mmc_blk_remove(struct mmc_card *card)
@@ -1825,7 +1824,7 @@ static void mmc_blk_remove(struct mmc_card *card)
1825} 1824}
1826 1825
1827#ifdef CONFIG_PM 1826#ifdef CONFIG_PM
1828static int mmc_blk_suspend(struct mmc_card *card, pm_message_t state) 1827static int mmc_blk_suspend(struct mmc_card *card)
1829{ 1828{
1830 struct mmc_blk_data *part_md; 1829 struct mmc_blk_data *part_md;
1831 struct mmc_blk_data *md = mmc_get_drvdata(card); 1830 struct mmc_blk_data *md = mmc_get_drvdata(card);
@@ -1845,8 +1844,6 @@ static int mmc_blk_resume(struct mmc_card *card)
1845 struct mmc_blk_data *md = mmc_get_drvdata(card); 1844 struct mmc_blk_data *md = mmc_get_drvdata(card);
1846 1845
1847 if (md) { 1846 if (md) {
1848 mmc_blk_set_blksize(md, card);
1849
1850 /* 1847 /*
1851 * Resume involves the card going into idle state, 1848 * Resume involves the card going into idle state,
1852 * so current partition is always the main one. 1849 * so current partition is always the main one.
diff --git a/drivers/mmc/card/queue.c b/drivers/mmc/card/queue.c
index 2517547b4366..996f8e36e23d 100644
--- a/drivers/mmc/card/queue.c
+++ b/drivers/mmc/card/queue.c
@@ -139,7 +139,7 @@ static void mmc_queue_setup_discard(struct request_queue *q,
139 139
140 queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, q); 140 queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, q);
141 q->limits.max_discard_sectors = max_discard; 141 q->limits.max_discard_sectors = max_discard;
142 if (card->erased_byte == 0) 142 if (card->erased_byte == 0 && !mmc_can_discard(card))
143 q->limits.discard_zeroes_data = 1; 143 q->limits.discard_zeroes_data = 1;
144 q->limits.discard_granularity = card->pref_erase << 9; 144 q->limits.discard_granularity = card->pref_erase << 9;
145 /* granularity must not be greater than max. discard */ 145 /* granularity must not be greater than max. discard */
diff --git a/drivers/mmc/core/bus.c b/drivers/mmc/core/bus.c
index 5d011a39dfff..c60cee92a2b2 100644
--- a/drivers/mmc/core/bus.c
+++ b/drivers/mmc/core/bus.c
@@ -122,14 +122,14 @@ static int mmc_bus_remove(struct device *dev)
122 return 0; 122 return 0;
123} 123}
124 124
125static int mmc_bus_suspend(struct device *dev, pm_message_t state) 125static int mmc_bus_suspend(struct device *dev)
126{ 126{
127 struct mmc_driver *drv = to_mmc_driver(dev->driver); 127 struct mmc_driver *drv = to_mmc_driver(dev->driver);
128 struct mmc_card *card = mmc_dev_to_card(dev); 128 struct mmc_card *card = mmc_dev_to_card(dev);
129 int ret = 0; 129 int ret = 0;
130 130
131 if (dev->driver && drv->suspend) 131 if (dev->driver && drv->suspend)
132 ret = drv->suspend(card, state); 132 ret = drv->suspend(card);
133 return ret; 133 return ret;
134} 134}
135 135
@@ -165,20 +165,14 @@ static int mmc_runtime_idle(struct device *dev)
165 return pm_runtime_suspend(dev); 165 return pm_runtime_suspend(dev);
166} 166}
167 167
168#endif /* !CONFIG_PM_RUNTIME */
169
168static const struct dev_pm_ops mmc_bus_pm_ops = { 170static const struct dev_pm_ops mmc_bus_pm_ops = {
169 .runtime_suspend = mmc_runtime_suspend, 171 SET_RUNTIME_PM_OPS(mmc_runtime_suspend, mmc_runtime_resume,
170 .runtime_resume = mmc_runtime_resume, 172 mmc_runtime_idle)
171 .runtime_idle = mmc_runtime_idle, 173 SET_SYSTEM_SLEEP_PM_OPS(mmc_bus_suspend, mmc_bus_resume)
172}; 174};
173 175
174#define MMC_PM_OPS_PTR (&mmc_bus_pm_ops)
175
176#else /* !CONFIG_PM_RUNTIME */
177
178#define MMC_PM_OPS_PTR NULL
179
180#endif /* !CONFIG_PM_RUNTIME */
181
182static struct bus_type mmc_bus_type = { 176static struct bus_type mmc_bus_type = {
183 .name = "mmc", 177 .name = "mmc",
184 .dev_attrs = mmc_dev_attrs, 178 .dev_attrs = mmc_dev_attrs,
@@ -186,9 +180,7 @@ static struct bus_type mmc_bus_type = {
186 .uevent = mmc_bus_uevent, 180 .uevent = mmc_bus_uevent,
187 .probe = mmc_bus_probe, 181 .probe = mmc_bus_probe,
188 .remove = mmc_bus_remove, 182 .remove = mmc_bus_remove,
189 .suspend = mmc_bus_suspend, 183 .pm = &mmc_bus_pm_ops,
190 .resume = mmc_bus_resume,
191 .pm = MMC_PM_OPS_PTR,
192}; 184};
193 185
194int mmc_register_bus(void) 186int mmc_register_bus(void)
@@ -267,6 +259,15 @@ int mmc_add_card(struct mmc_card *card)
267{ 259{
268 int ret; 260 int ret;
269 const char *type; 261 const char *type;
262 const char *uhs_bus_speed_mode = "";
263 static const char *const uhs_speeds[] = {
264 [UHS_SDR12_BUS_SPEED] = "SDR12 ",
265 [UHS_SDR25_BUS_SPEED] = "SDR25 ",
266 [UHS_SDR50_BUS_SPEED] = "SDR50 ",
267 [UHS_SDR104_BUS_SPEED] = "SDR104 ",
268 [UHS_DDR50_BUS_SPEED] = "DDR50 ",
269 };
270
270 271
271 dev_set_name(&card->dev, "%s:%04x", mmc_hostname(card->host), card->rca); 272 dev_set_name(&card->dev, "%s:%04x", mmc_hostname(card->host), card->rca);
272 273
@@ -296,6 +297,10 @@ int mmc_add_card(struct mmc_card *card)
296 break; 297 break;
297 } 298 }
298 299
300 if (mmc_sd_card_uhs(card) &&
301 (card->sd_bus_speed < ARRAY_SIZE(uhs_speeds)))
302 uhs_bus_speed_mode = uhs_speeds[card->sd_bus_speed];
303
299 if (mmc_host_is_spi(card->host)) { 304 if (mmc_host_is_spi(card->host)) {
300 pr_info("%s: new %s%s%s card on SPI\n", 305 pr_info("%s: new %s%s%s card on SPI\n",
301 mmc_hostname(card->host), 306 mmc_hostname(card->host),
@@ -303,13 +308,13 @@ int mmc_add_card(struct mmc_card *card)
303 mmc_card_ddr_mode(card) ? "DDR " : "", 308 mmc_card_ddr_mode(card) ? "DDR " : "",
304 type); 309 type);
305 } else { 310 } else {
306 pr_info("%s: new %s%s%s%s card at address %04x\n", 311 pr_info("%s: new %s%s%s%s%s card at address %04x\n",
307 mmc_hostname(card->host), 312 mmc_hostname(card->host),
308 mmc_card_uhs(card) ? "ultra high speed " : 313 mmc_card_uhs(card) ? "ultra high speed " :
309 (mmc_card_highspeed(card) ? "high speed " : ""), 314 (mmc_card_highspeed(card) ? "high speed " : ""),
310 (mmc_card_hs200(card) ? "HS200 " : ""), 315 (mmc_card_hs200(card) ? "HS200 " : ""),
311 mmc_card_ddr_mode(card) ? "DDR " : "", 316 mmc_card_ddr_mode(card) ? "DDR " : "",
312 type, card->rca); 317 uhs_bus_speed_mode, type, card->rca);
313 } 318 }
314 319
315#ifdef CONFIG_DEBUG_FS 320#ifdef CONFIG_DEBUG_FS
diff --git a/drivers/mmc/core/cd-gpio.c b/drivers/mmc/core/cd-gpio.c
index 29de31e260dd..2c14be73254c 100644
--- a/drivers/mmc/core/cd-gpio.c
+++ b/drivers/mmc/core/cd-gpio.c
@@ -12,6 +12,7 @@
12#include <linux/gpio.h> 12#include <linux/gpio.h>
13#include <linux/interrupt.h> 13#include <linux/interrupt.h>
14#include <linux/jiffies.h> 14#include <linux/jiffies.h>
15#include <linux/mmc/cd-gpio.h>
15#include <linux/mmc/host.h> 16#include <linux/mmc/host.h>
16#include <linux/module.h> 17#include <linux/module.h>
17#include <linux/slab.h> 18#include <linux/slab.h>
diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 14f262e9246d..ba821fe70bca 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -527,10 +527,14 @@ void mmc_set_data_timeout(struct mmc_data *data, const struct mmc_card *card)
527 527
528 if (data->flags & MMC_DATA_WRITE) 528 if (data->flags & MMC_DATA_WRITE)
529 /* 529 /*
530 * The limit is really 250 ms, but that is 530 * The MMC spec "It is strongly recommended
531 * insufficient for some crappy cards. 531 * for hosts to implement more than 500ms
532 * timeout value even if the card indicates
533 * the 250ms maximum busy length." Even the
534 * previous value of 300ms is known to be
535 * insufficient for some cards.
532 */ 536 */
533 limit_us = 300000; 537 limit_us = 3000000;
534 else 538 else
535 limit_us = 100000; 539 limit_us = 100000;
536 540
@@ -1405,7 +1409,10 @@ static unsigned int mmc_mmc_erase_timeout(struct mmc_card *card,
1405{ 1409{
1406 unsigned int erase_timeout; 1410 unsigned int erase_timeout;
1407 1411
1408 if (card->ext_csd.erase_group_def & 1) { 1412 if (arg == MMC_DISCARD_ARG ||
1413 (arg == MMC_TRIM_ARG && card->ext_csd.rev >= 6)) {
1414 erase_timeout = card->ext_csd.trim_timeout;
1415 } else if (card->ext_csd.erase_group_def & 1) {
1409 /* High Capacity Erase Group Size uses HC timeouts */ 1416 /* High Capacity Erase Group Size uses HC timeouts */
1410 if (arg == MMC_TRIM_ARG) 1417 if (arg == MMC_TRIM_ARG)
1411 erase_timeout = card->ext_csd.trim_timeout; 1418 erase_timeout = card->ext_csd.trim_timeout;
@@ -1677,8 +1684,6 @@ int mmc_can_trim(struct mmc_card *card)
1677{ 1684{
1678 if (card->ext_csd.sec_feature_support & EXT_CSD_SEC_GB_CL_EN) 1685 if (card->ext_csd.sec_feature_support & EXT_CSD_SEC_GB_CL_EN)
1679 return 1; 1686 return 1;
1680 if (mmc_can_discard(card))
1681 return 1;
1682 return 0; 1687 return 0;
1683} 1688}
1684EXPORT_SYMBOL(mmc_can_trim); 1689EXPORT_SYMBOL(mmc_can_trim);
@@ -1697,6 +1702,8 @@ EXPORT_SYMBOL(mmc_can_discard);
1697 1702
1698int mmc_can_sanitize(struct mmc_card *card) 1703int mmc_can_sanitize(struct mmc_card *card)
1699{ 1704{
1705 if (!mmc_can_trim(card) && !mmc_can_erase(card))
1706 return 0;
1700 if (card->ext_csd.sec_feature_support & EXT_CSD_SEC_SANITIZE) 1707 if (card->ext_csd.sec_feature_support & EXT_CSD_SEC_SANITIZE)
1701 return 1; 1708 return 1;
1702 return 0; 1709 return 0;
@@ -2231,6 +2238,7 @@ int mmc_cache_ctrl(struct mmc_host *host, u8 enable)
2231 mmc_card_is_removable(host)) 2238 mmc_card_is_removable(host))
2232 return err; 2239 return err;
2233 2240
2241 mmc_claim_host(host);
2234 if (card && mmc_card_mmc(card) && 2242 if (card && mmc_card_mmc(card) &&
2235 (card->ext_csd.cache_size > 0)) { 2243 (card->ext_csd.cache_size > 0)) {
2236 enable = !!enable; 2244 enable = !!enable;
@@ -2248,6 +2256,7 @@ int mmc_cache_ctrl(struct mmc_host *host, u8 enable)
2248 card->ext_csd.cache_ctrl = enable; 2256 card->ext_csd.cache_ctrl = enable;
2249 } 2257 }
2250 } 2258 }
2259 mmc_release_host(host);
2251 2260
2252 return err; 2261 return err;
2253} 2262}
@@ -2265,49 +2274,32 @@ int mmc_suspend_host(struct mmc_host *host)
2265 2274
2266 cancel_delayed_work(&host->detect); 2275 cancel_delayed_work(&host->detect);
2267 mmc_flush_scheduled_work(); 2276 mmc_flush_scheduled_work();
2268 if (mmc_try_claim_host(host)) {
2269 err = mmc_cache_ctrl(host, 0);
2270 mmc_release_host(host);
2271 } else {
2272 err = -EBUSY;
2273 }
2274 2277
2278 err = mmc_cache_ctrl(host, 0);
2275 if (err) 2279 if (err)
2276 goto out; 2280 goto out;
2277 2281
2278 mmc_bus_get(host); 2282 mmc_bus_get(host);
2279 if (host->bus_ops && !host->bus_dead) { 2283 if (host->bus_ops && !host->bus_dead) {
2280 2284
2281 /* 2285 if (host->bus_ops->suspend)
2282 * A long response time is not acceptable for device drivers 2286 err = host->bus_ops->suspend(host);
2283 * when doing suspend. Prevent mmc_claim_host in the suspend
2284 * sequence, to potentially wait "forever" by trying to
2285 * pre-claim the host.
2286 */
2287 if (mmc_try_claim_host(host)) {
2288 if (host->bus_ops->suspend) {
2289 err = host->bus_ops->suspend(host);
2290 }
2291 mmc_release_host(host);
2292 2287
2293 if (err == -ENOSYS || !host->bus_ops->resume) { 2288 if (err == -ENOSYS || !host->bus_ops->resume) {
2294 /* 2289 /*
2295 * We simply "remove" the card in this case. 2290 * We simply "remove" the card in this case.
2296 * It will be redetected on resume. (Calling 2291 * It will be redetected on resume. (Calling
2297 * bus_ops->remove() with a claimed host can 2292 * bus_ops->remove() with a claimed host can
2298 * deadlock.) 2293 * deadlock.)
2299 */ 2294 */
2300 if (host->bus_ops->remove) 2295 if (host->bus_ops->remove)
2301 host->bus_ops->remove(host); 2296 host->bus_ops->remove(host);
2302 mmc_claim_host(host); 2297 mmc_claim_host(host);
2303 mmc_detach_bus(host); 2298 mmc_detach_bus(host);
2304 mmc_power_off(host); 2299 mmc_power_off(host);
2305 mmc_release_host(host); 2300 mmc_release_host(host);
2306 host->pm_flags = 0; 2301 host->pm_flags = 0;
2307 err = 0; 2302 err = 0;
2308 }
2309 } else {
2310 err = -EBUSY;
2311 } 2303 }
2312 } 2304 }
2313 mmc_bus_put(host); 2305 mmc_bus_put(host);
diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
index 02914d609a91..54df5adc0413 100644
--- a/drivers/mmc/core/mmc.c
+++ b/drivers/mmc/core/mmc.c
@@ -695,6 +695,11 @@ static int mmc_select_powerclass(struct mmc_card *card,
695 else if (host->ios.clock <= 200000000) 695 else if (host->ios.clock <= 200000000)
696 index = EXT_CSD_PWR_CL_200_195; 696 index = EXT_CSD_PWR_CL_200_195;
697 break; 697 break;
698 case MMC_VDD_27_28:
699 case MMC_VDD_28_29:
700 case MMC_VDD_29_30:
701 case MMC_VDD_30_31:
702 case MMC_VDD_31_32:
698 case MMC_VDD_32_33: 703 case MMC_VDD_32_33:
699 case MMC_VDD_33_34: 704 case MMC_VDD_33_34:
700 case MMC_VDD_34_35: 705 case MMC_VDD_34_35:
@@ -1111,11 +1116,10 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
1111 ext_csd_bits = (bus_width == MMC_BUS_WIDTH_8) ? 1116 ext_csd_bits = (bus_width == MMC_BUS_WIDTH_8) ?
1112 EXT_CSD_BUS_WIDTH_8 : EXT_CSD_BUS_WIDTH_4; 1117 EXT_CSD_BUS_WIDTH_8 : EXT_CSD_BUS_WIDTH_4;
1113 err = mmc_select_powerclass(card, ext_csd_bits, ext_csd); 1118 err = mmc_select_powerclass(card, ext_csd_bits, ext_csd);
1114 if (err) { 1119 if (err)
1115 pr_err("%s: power class selection to bus width %d failed\n", 1120 pr_warning("%s: power class selection to bus width %d"
1116 mmc_hostname(card->host), 1 << bus_width); 1121 " failed\n", mmc_hostname(card->host),
1117 goto err; 1122 1 << bus_width);
1118 }
1119 } 1123 }
1120 1124
1121 /* 1125 /*
@@ -1147,10 +1151,10 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
1147 err = mmc_select_powerclass(card, ext_csd_bits[idx][0], 1151 err = mmc_select_powerclass(card, ext_csd_bits[idx][0],
1148 ext_csd); 1152 ext_csd);
1149 if (err) 1153 if (err)
1150 pr_err("%s: power class selection to " 1154 pr_warning("%s: power class selection to "
1151 "bus width %d failed\n", 1155 "bus width %d failed\n",
1152 mmc_hostname(card->host), 1156 mmc_hostname(card->host),
1153 1 << bus_width); 1157 1 << bus_width);
1154 1158
1155 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 1159 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
1156 EXT_CSD_BUS_WIDTH, 1160 EXT_CSD_BUS_WIDTH,
@@ -1178,10 +1182,10 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
1178 err = mmc_select_powerclass(card, ext_csd_bits[idx][1], 1182 err = mmc_select_powerclass(card, ext_csd_bits[idx][1],
1179 ext_csd); 1183 ext_csd);
1180 if (err) 1184 if (err)
1181 pr_err("%s: power class selection to " 1185 pr_warning("%s: power class selection to "
1182 "bus width %d ddr %d failed\n", 1186 "bus width %d ddr %d failed\n",
1183 mmc_hostname(card->host), 1187 mmc_hostname(card->host),
1184 1 << bus_width, ddr); 1188 1 << bus_width, ddr);
1185 1189
1186 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 1190 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
1187 EXT_CSD_BUS_WIDTH, 1191 EXT_CSD_BUS_WIDTH,
diff --git a/drivers/mmc/core/sdio_bus.c b/drivers/mmc/core/sdio_bus.c
index 40989e6bb53a..236842ec955a 100644
--- a/drivers/mmc/core/sdio_bus.c
+++ b/drivers/mmc/core/sdio_bus.c
@@ -192,9 +192,15 @@ static int sdio_bus_remove(struct device *dev)
192 return ret; 192 return ret;
193} 193}
194 194
195#ifdef CONFIG_PM_RUNTIME 195#ifdef CONFIG_PM
196
197static int pm_no_operation(struct device *dev)
198{
199 return 0;
200}
196 201
197static const struct dev_pm_ops sdio_bus_pm_ops = { 202static const struct dev_pm_ops sdio_bus_pm_ops = {
203 SET_SYSTEM_SLEEP_PM_OPS(pm_no_operation, pm_no_operation)
198 SET_RUNTIME_PM_OPS( 204 SET_RUNTIME_PM_OPS(
199 pm_generic_runtime_suspend, 205 pm_generic_runtime_suspend,
200 pm_generic_runtime_resume, 206 pm_generic_runtime_resume,
@@ -204,11 +210,11 @@ static const struct dev_pm_ops sdio_bus_pm_ops = {
204 210
205#define SDIO_PM_OPS_PTR (&sdio_bus_pm_ops) 211#define SDIO_PM_OPS_PTR (&sdio_bus_pm_ops)
206 212
207#else /* !CONFIG_PM_RUNTIME */ 213#else /* !CONFIG_PM */
208 214
209#define SDIO_PM_OPS_PTR NULL 215#define SDIO_PM_OPS_PTR NULL
210 216
211#endif /* !CONFIG_PM_RUNTIME */ 217#endif /* !CONFIG_PM */
212 218
213static struct bus_type sdio_bus_type = { 219static struct bus_type sdio_bus_type = {
214 .name = "sdio", 220 .name = "sdio",
diff --git a/drivers/mmc/host/atmel-mci-regs.h b/drivers/mmc/host/atmel-mci-regs.h
index 000b3ad0f5ca..787aba1682bb 100644
--- a/drivers/mmc/host/atmel-mci-regs.h
+++ b/drivers/mmc/host/atmel-mci-regs.h
@@ -31,6 +31,7 @@
31# define ATMCI_MR_PDCFBYTE ( 1 << 13) /* Force Byte Transfer */ 31# define ATMCI_MR_PDCFBYTE ( 1 << 13) /* Force Byte Transfer */
32# define ATMCI_MR_PDCPADV ( 1 << 14) /* Padding Value */ 32# define ATMCI_MR_PDCPADV ( 1 << 14) /* Padding Value */
33# define ATMCI_MR_PDCMODE ( 1 << 15) /* PDC-oriented Mode */ 33# define ATMCI_MR_PDCMODE ( 1 << 15) /* PDC-oriented Mode */
34# define ATMCI_MR_CLKODD(x) ((x) << 16) /* LSB of Clock Divider */
34#define ATMCI_DTOR 0x0008 /* Data Timeout */ 35#define ATMCI_DTOR 0x0008 /* Data Timeout */
35# define ATMCI_DTOCYC(x) ((x) << 0) /* Data Timeout Cycles */ 36# define ATMCI_DTOCYC(x) ((x) << 0) /* Data Timeout Cycles */
36# define ATMCI_DTOMUL(x) ((x) << 4) /* Data Timeout Multiplier */ 37# define ATMCI_DTOMUL(x) ((x) << 4) /* Data Timeout Multiplier */
diff --git a/drivers/mmc/host/atmel-mci.c b/drivers/mmc/host/atmel-mci.c
index 9819dc09ce08..e94476beca18 100644
--- a/drivers/mmc/host/atmel-mci.c
+++ b/drivers/mmc/host/atmel-mci.c
@@ -77,6 +77,7 @@ struct atmel_mci_caps {
77 bool has_cstor_reg; 77 bool has_cstor_reg;
78 bool has_highspeed; 78 bool has_highspeed;
79 bool has_rwproof; 79 bool has_rwproof;
80 bool has_odd_clk_div;
80}; 81};
81 82
82struct atmel_mci_dma { 83struct atmel_mci_dma {
@@ -482,7 +483,14 @@ err:
482static inline unsigned int atmci_ns_to_clocks(struct atmel_mci *host, 483static inline unsigned int atmci_ns_to_clocks(struct atmel_mci *host,
483 unsigned int ns) 484 unsigned int ns)
484{ 485{
485 return (ns * (host->bus_hz / 1000000) + 999) / 1000; 486 /*
487 * It is easier here to use us instead of ns for the timeout,
488 * it prevents from overflows during calculation.
489 */
490 unsigned int us = DIV_ROUND_UP(ns, 1000);
491
492 /* Maximum clock frequency is host->bus_hz/2 */
493 return us * (DIV_ROUND_UP(host->bus_hz, 2000000));
486} 494}
487 495
488static void atmci_set_timeout(struct atmel_mci *host, 496static void atmci_set_timeout(struct atmel_mci *host,
@@ -1127,16 +1135,27 @@ static void atmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
1127 } 1135 }
1128 1136
1129 /* Calculate clock divider */ 1137 /* Calculate clock divider */
1130 clkdiv = DIV_ROUND_UP(host->bus_hz, 2 * clock_min) - 1; 1138 if (host->caps.has_odd_clk_div) {
1131 if (clkdiv > 255) { 1139 clkdiv = DIV_ROUND_UP(host->bus_hz, clock_min) - 2;
1132 dev_warn(&mmc->class_dev, 1140 if (clkdiv > 511) {
1133 "clock %u too slow; using %lu\n", 1141 dev_warn(&mmc->class_dev,
1134 clock_min, host->bus_hz / (2 * 256)); 1142 "clock %u too slow; using %lu\n",
1135 clkdiv = 255; 1143 clock_min, host->bus_hz / (511 + 2));
1144 clkdiv = 511;
1145 }
1146 host->mode_reg = ATMCI_MR_CLKDIV(clkdiv >> 1)
1147 | ATMCI_MR_CLKODD(clkdiv & 1);
1148 } else {
1149 clkdiv = DIV_ROUND_UP(host->bus_hz, 2 * clock_min) - 1;
1150 if (clkdiv > 255) {
1151 dev_warn(&mmc->class_dev,
1152 "clock %u too slow; using %lu\n",
1153 clock_min, host->bus_hz / (2 * 256));
1154 clkdiv = 255;
1155 }
1156 host->mode_reg = ATMCI_MR_CLKDIV(clkdiv);
1136 } 1157 }
1137 1158
1138 host->mode_reg = ATMCI_MR_CLKDIV(clkdiv);
1139
1140 /* 1159 /*
1141 * WRPROOF and RDPROOF prevent overruns/underruns by 1160 * WRPROOF and RDPROOF prevent overruns/underruns by
1142 * stopping the clock when the FIFO is full/empty. 1161 * stopping the clock when the FIFO is full/empty.
@@ -2007,35 +2026,35 @@ static void __init atmci_get_cap(struct atmel_mci *host)
2007 "version: 0x%x\n", version); 2026 "version: 0x%x\n", version);
2008 2027
2009 host->caps.has_dma = 0; 2028 host->caps.has_dma = 0;
2010 host->caps.has_pdc = 0; 2029 host->caps.has_pdc = 1;
2011 host->caps.has_cfg_reg = 0; 2030 host->caps.has_cfg_reg = 0;
2012 host->caps.has_cstor_reg = 0; 2031 host->caps.has_cstor_reg = 0;
2013 host->caps.has_highspeed = 0; 2032 host->caps.has_highspeed = 0;
2014 host->caps.has_rwproof = 0; 2033 host->caps.has_rwproof = 0;
2034 host->caps.has_odd_clk_div = 0;
2015 2035
2016 /* keep only major version number */ 2036 /* keep only major version number */
2017 switch (version & 0xf00) { 2037 switch (version & 0xf00) {
2018 case 0x100:
2019 case 0x200:
2020 host->caps.has_pdc = 1;
2021 host->caps.has_rwproof = 1;
2022 break;
2023 case 0x300:
2024 case 0x400:
2025 case 0x500: 2038 case 0x500:
2039 host->caps.has_odd_clk_div = 1;
2040 case 0x400:
2041 case 0x300:
2026#ifdef CONFIG_AT_HDMAC 2042#ifdef CONFIG_AT_HDMAC
2027 host->caps.has_dma = 1; 2043 host->caps.has_dma = 1;
2028#else 2044#else
2029 host->caps.has_dma = 0;
2030 dev_info(&host->pdev->dev, 2045 dev_info(&host->pdev->dev,
2031 "has dma capability but dma engine is not selected, then use pio\n"); 2046 "has dma capability but dma engine is not selected, then use pio\n");
2032#endif 2047#endif
2048 host->caps.has_pdc = 0;
2033 host->caps.has_cfg_reg = 1; 2049 host->caps.has_cfg_reg = 1;
2034 host->caps.has_cstor_reg = 1; 2050 host->caps.has_cstor_reg = 1;
2035 host->caps.has_highspeed = 1; 2051 host->caps.has_highspeed = 1;
2052 case 0x200:
2036 host->caps.has_rwproof = 1; 2053 host->caps.has_rwproof = 1;
2054 case 0x100:
2037 break; 2055 break;
2038 default: 2056 default:
2057 host->caps.has_pdc = 0;
2039 dev_warn(&host->pdev->dev, 2058 dev_warn(&host->pdev->dev,
2040 "Unmanaged mci version, set minimum capabilities\n"); 2059 "Unmanaged mci version, set minimum capabilities\n");
2041 break; 2060 break;
diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c
index bf3c9b456aaf..ab3fc4617107 100644
--- a/drivers/mmc/host/dw_mmc.c
+++ b/drivers/mmc/host/dw_mmc.c
@@ -526,8 +526,10 @@ static int dw_mci_submit_data_dma(struct dw_mci *host, struct mmc_data *data)
526 return -ENODEV; 526 return -ENODEV;
527 527
528 sg_len = dw_mci_pre_dma_transfer(host, data, 0); 528 sg_len = dw_mci_pre_dma_transfer(host, data, 0);
529 if (sg_len < 0) 529 if (sg_len < 0) {
530 host->dma_ops->stop(host);
530 return sg_len; 531 return sg_len;
532 }
531 533
532 host->using_dma = 1; 534 host->using_dma = 1;
533 535
@@ -1879,7 +1881,8 @@ static void dw_mci_init_dma(struct dw_mci *host)
1879 if (!host->dma_ops) 1881 if (!host->dma_ops)
1880 goto no_dma; 1882 goto no_dma;
1881 1883
1882 if (host->dma_ops->init) { 1884 if (host->dma_ops->init && host->dma_ops->start &&
1885 host->dma_ops->stop && host->dma_ops->cleanup) {
1883 if (host->dma_ops->init(host)) { 1886 if (host->dma_ops->init(host)) {
1884 dev_err(&host->dev, "%s: Unable to initialize " 1887 dev_err(&host->dev, "%s: Unable to initialize "
1885 "DMA Controller.\n", __func__); 1888 "DMA Controller.\n", __func__);
diff --git a/drivers/mmc/host/mxs-mmc.c b/drivers/mmc/host/mxs-mmc.c
index b0f2ef988188..e3f5af96ab87 100644
--- a/drivers/mmc/host/mxs-mmc.c
+++ b/drivers/mmc/host/mxs-mmc.c
@@ -363,6 +363,7 @@ static void mxs_mmc_bc(struct mxs_mmc_host *host)
363 goto out; 363 goto out;
364 364
365 dmaengine_submit(desc); 365 dmaengine_submit(desc);
366 dma_async_issue_pending(host->dmach);
366 return; 367 return;
367 368
368out: 369out:
@@ -403,6 +404,7 @@ static void mxs_mmc_ac(struct mxs_mmc_host *host)
403 goto out; 404 goto out;
404 405
405 dmaengine_submit(desc); 406 dmaengine_submit(desc);
407 dma_async_issue_pending(host->dmach);
406 return; 408 return;
407 409
408out: 410out:
@@ -531,6 +533,7 @@ static void mxs_mmc_adtc(struct mxs_mmc_host *host)
531 goto out; 533 goto out;
532 534
533 dmaengine_submit(desc); 535 dmaengine_submit(desc);
536 dma_async_issue_pending(host->dmach);
534 return; 537 return;
535out: 538out:
536 dev_warn(mmc_dev(host->mmc), 539 dev_warn(mmc_dev(host->mmc),
diff --git a/drivers/mmc/host/omap_hsmmc.c b/drivers/mmc/host/omap_hsmmc.c
index 47adb161d3ad..56d4499d4388 100644
--- a/drivers/mmc/host/omap_hsmmc.c
+++ b/drivers/mmc/host/omap_hsmmc.c
@@ -249,7 +249,7 @@ static int omap_hsmmc_set_power(struct device *dev, int slot, int power_on,
249 * the pbias cell programming support is still missing when 249 * the pbias cell programming support is still missing when
250 * booting with Device tree 250 * booting with Device tree
251 */ 251 */
252 if (of_have_populated_dt() && !vdd) 252 if (dev->of_node && !vdd)
253 return 0; 253 return 0;
254 254
255 if (mmc_slot(host).before_set_reg) 255 if (mmc_slot(host).before_set_reg)
@@ -1549,7 +1549,7 @@ static void omap_hsmmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
1549 * can't be allowed when booting with device 1549 * can't be allowed when booting with device
1550 * tree. 1550 * tree.
1551 */ 1551 */
1552 (!of_have_populated_dt())) { 1552 !host->dev->of_node) {
1553 /* 1553 /*
1554 * The mmc_select_voltage fn of the core does 1554 * The mmc_select_voltage fn of the core does
1555 * not seem to set the power_mode to 1555 * not seem to set the power_mode to
@@ -1741,7 +1741,7 @@ static const struct of_device_id omap_mmc_of_match[] = {
1741 .data = &omap4_reg_offset, 1741 .data = &omap4_reg_offset,
1742 }, 1742 },
1743 {}, 1743 {},
1744} 1744};
1745MODULE_DEVICE_TABLE(of, omap_mmc_of_match); 1745MODULE_DEVICE_TABLE(of, omap_mmc_of_match);
1746 1746
1747static struct omap_mmc_platform_data *of_get_hsmmc_pdata(struct device *dev) 1747static struct omap_mmc_platform_data *of_get_hsmmc_pdata(struct device *dev)
@@ -1785,7 +1785,7 @@ static inline struct omap_mmc_platform_data
1785} 1785}
1786#endif 1786#endif
1787 1787
1788static int __init omap_hsmmc_probe(struct platform_device *pdev) 1788static int __devinit omap_hsmmc_probe(struct platform_device *pdev)
1789{ 1789{
1790 struct omap_mmc_platform_data *pdata = pdev->dev.platform_data; 1790 struct omap_mmc_platform_data *pdata = pdev->dev.platform_data;
1791 struct mmc_host *mmc; 1791 struct mmc_host *mmc;
@@ -1818,8 +1818,6 @@ static int __init omap_hsmmc_probe(struct platform_device *pdev)
1818 if (res == NULL || irq < 0) 1818 if (res == NULL || irq < 0)
1819 return -ENXIO; 1819 return -ENXIO;
1820 1820
1821 res->start += pdata->reg_offset;
1822 res->end += pdata->reg_offset;
1823 res = request_mem_region(res->start, resource_size(res), pdev->name); 1821 res = request_mem_region(res->start, resource_size(res), pdev->name);
1824 if (res == NULL) 1822 if (res == NULL)
1825 return -EBUSY; 1823 return -EBUSY;
@@ -1843,7 +1841,7 @@ static int __init omap_hsmmc_probe(struct platform_device *pdev)
1843 host->dma_ch = -1; 1841 host->dma_ch = -1;
1844 host->irq = irq; 1842 host->irq = irq;
1845 host->slot_id = 0; 1843 host->slot_id = 0;
1846 host->mapbase = res->start; 1844 host->mapbase = res->start + pdata->reg_offset;
1847 host->base = ioremap(host->mapbase, SZ_4K); 1845 host->base = ioremap(host->mapbase, SZ_4K);
1848 host->power_mode = MMC_POWER_OFF; 1846 host->power_mode = MMC_POWER_OFF;
1849 host->next_data.cookie = 1; 1847 host->next_data.cookie = 1;
@@ -1875,8 +1873,6 @@ static int __init omap_hsmmc_probe(struct platform_device *pdev)
1875 goto err1; 1873 goto err1;
1876 } 1874 }
1877 1875
1878 omap_hsmmc_context_save(host);
1879
1880 if (host->pdata->controller_flags & OMAP_HSMMC_BROKEN_MULTIBLOCK_READ) { 1876 if (host->pdata->controller_flags & OMAP_HSMMC_BROKEN_MULTIBLOCK_READ) {
1881 dev_info(&pdev->dev, "multiblock reads disabled due to 35xx erratum 2.1.1.128; MMC read performance may suffer\n"); 1877 dev_info(&pdev->dev, "multiblock reads disabled due to 35xx erratum 2.1.1.128; MMC read performance may suffer\n");
1882 mmc->caps2 |= MMC_CAP2_NO_MULTI_READ; 1878 mmc->caps2 |= MMC_CAP2_NO_MULTI_READ;
@@ -1887,6 +1883,8 @@ static int __init omap_hsmmc_probe(struct platform_device *pdev)
1887 pm_runtime_set_autosuspend_delay(host->dev, MMC_AUTOSUSPEND_DELAY); 1883 pm_runtime_set_autosuspend_delay(host->dev, MMC_AUTOSUSPEND_DELAY);
1888 pm_runtime_use_autosuspend(host->dev); 1884 pm_runtime_use_autosuspend(host->dev);
1889 1885
1886 omap_hsmmc_context_save(host);
1887
1890 if (cpu_is_omap2430()) { 1888 if (cpu_is_omap2430()) {
1891 host->dbclk = clk_get(&pdev->dev, "mmchsdb_fck"); 1889 host->dbclk = clk_get(&pdev->dev, "mmchsdb_fck");
1892 /* 1890 /*
@@ -2018,8 +2016,7 @@ err_reg:
2018err_irq_cd_init: 2016err_irq_cd_init:
2019 free_irq(host->irq, host); 2017 free_irq(host->irq, host);
2020err_irq: 2018err_irq:
2021 pm_runtime_mark_last_busy(host->dev); 2019 pm_runtime_put_sync(host->dev);
2022 pm_runtime_put_autosuspend(host->dev);
2023 pm_runtime_disable(host->dev); 2020 pm_runtime_disable(host->dev);
2024 clk_put(host->fclk); 2021 clk_put(host->fclk);
2025 if (host->got_dbclk) { 2022 if (host->got_dbclk) {
@@ -2037,35 +2034,33 @@ err:
2037 return ret; 2034 return ret;
2038} 2035}
2039 2036
2040static int omap_hsmmc_remove(struct platform_device *pdev) 2037static int __devexit omap_hsmmc_remove(struct platform_device *pdev)
2041{ 2038{
2042 struct omap_hsmmc_host *host = platform_get_drvdata(pdev); 2039 struct omap_hsmmc_host *host = platform_get_drvdata(pdev);
2043 struct resource *res; 2040 struct resource *res;
2044 2041
2045 if (host) { 2042 pm_runtime_get_sync(host->dev);
2046 pm_runtime_get_sync(host->dev); 2043 mmc_remove_host(host->mmc);
2047 mmc_remove_host(host->mmc); 2044 if (host->use_reg)
2048 if (host->use_reg) 2045 omap_hsmmc_reg_put(host);
2049 omap_hsmmc_reg_put(host); 2046 if (host->pdata->cleanup)
2050 if (host->pdata->cleanup) 2047 host->pdata->cleanup(&pdev->dev);
2051 host->pdata->cleanup(&pdev->dev); 2048 free_irq(host->irq, host);
2052 free_irq(host->irq, host); 2049 if (mmc_slot(host).card_detect_irq)
2053 if (mmc_slot(host).card_detect_irq) 2050 free_irq(mmc_slot(host).card_detect_irq, host);
2054 free_irq(mmc_slot(host).card_detect_irq, host);
2055
2056 pm_runtime_put_sync(host->dev);
2057 pm_runtime_disable(host->dev);
2058 clk_put(host->fclk);
2059 if (host->got_dbclk) {
2060 clk_disable(host->dbclk);
2061 clk_put(host->dbclk);
2062 }
2063 2051
2064 mmc_free_host(host->mmc); 2052 pm_runtime_put_sync(host->dev);
2065 iounmap(host->base); 2053 pm_runtime_disable(host->dev);
2066 omap_hsmmc_gpio_free(pdev->dev.platform_data); 2054 clk_put(host->fclk);
2055 if (host->got_dbclk) {
2056 clk_disable(host->dbclk);
2057 clk_put(host->dbclk);
2067 } 2058 }
2068 2059
2060 mmc_free_host(host->mmc);
2061 iounmap(host->base);
2062 omap_hsmmc_gpio_free(pdev->dev.platform_data);
2063
2069 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 2064 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2070 if (res) 2065 if (res)
2071 release_mem_region(res->start, resource_size(res)); 2066 release_mem_region(res->start, resource_size(res));
@@ -2078,49 +2073,45 @@ static int omap_hsmmc_remove(struct platform_device *pdev)
2078static int omap_hsmmc_suspend(struct device *dev) 2073static int omap_hsmmc_suspend(struct device *dev)
2079{ 2074{
2080 int ret = 0; 2075 int ret = 0;
2081 struct platform_device *pdev = to_platform_device(dev); 2076 struct omap_hsmmc_host *host = dev_get_drvdata(dev);
2082 struct omap_hsmmc_host *host = platform_get_drvdata(pdev);
2083 2077
2084 if (host && host->suspended) 2078 if (!host)
2085 return 0; 2079 return 0;
2086 2080
2087 if (host) { 2081 if (host && host->suspended)
2088 pm_runtime_get_sync(host->dev); 2082 return 0;
2089 host->suspended = 1;
2090 if (host->pdata->suspend) {
2091 ret = host->pdata->suspend(&pdev->dev,
2092 host->slot_id);
2093 if (ret) {
2094 dev_dbg(mmc_dev(host->mmc),
2095 "Unable to handle MMC board"
2096 " level suspend\n");
2097 host->suspended = 0;
2098 return ret;
2099 }
2100 }
2101 ret = mmc_suspend_host(host->mmc);
2102 2083
2084 pm_runtime_get_sync(host->dev);
2085 host->suspended = 1;
2086 if (host->pdata->suspend) {
2087 ret = host->pdata->suspend(dev, host->slot_id);
2103 if (ret) { 2088 if (ret) {
2089 dev_dbg(dev, "Unable to handle MMC board"
2090 " level suspend\n");
2104 host->suspended = 0; 2091 host->suspended = 0;
2105 if (host->pdata->resume) { 2092 return ret;
2106 ret = host->pdata->resume(&pdev->dev,
2107 host->slot_id);
2108 if (ret)
2109 dev_dbg(mmc_dev(host->mmc),
2110 "Unmask interrupt failed\n");
2111 }
2112 goto err;
2113 } 2093 }
2094 }
2095 ret = mmc_suspend_host(host->mmc);
2114 2096
2115 if (!(host->mmc->pm_flags & MMC_PM_KEEP_POWER)) { 2097 if (ret) {
2116 omap_hsmmc_disable_irq(host); 2098 host->suspended = 0;
2117 OMAP_HSMMC_WRITE(host->base, HCTL, 2099 if (host->pdata->resume) {
2118 OMAP_HSMMC_READ(host->base, HCTL) & ~SDBP); 2100 ret = host->pdata->resume(dev, host->slot_id);
2101 if (ret)
2102 dev_dbg(dev, "Unmask interrupt failed\n");
2119 } 2103 }
2120 if (host->got_dbclk) 2104 goto err;
2121 clk_disable(host->dbclk); 2105 }
2122 2106
2107 if (!(host->mmc->pm_flags & MMC_PM_KEEP_POWER)) {
2108 omap_hsmmc_disable_irq(host);
2109 OMAP_HSMMC_WRITE(host->base, HCTL,
2110 OMAP_HSMMC_READ(host->base, HCTL) & ~SDBP);
2123 } 2111 }
2112
2113 if (host->got_dbclk)
2114 clk_disable(host->dbclk);
2124err: 2115err:
2125 pm_runtime_put_sync(host->dev); 2116 pm_runtime_put_sync(host->dev);
2126 return ret; 2117 return ret;
@@ -2130,38 +2121,37 @@ err:
2130static int omap_hsmmc_resume(struct device *dev) 2121static int omap_hsmmc_resume(struct device *dev)
2131{ 2122{
2132 int ret = 0; 2123 int ret = 0;
2133 struct platform_device *pdev = to_platform_device(dev); 2124 struct omap_hsmmc_host *host = dev_get_drvdata(dev);
2134 struct omap_hsmmc_host *host = platform_get_drvdata(pdev); 2125
2126 if (!host)
2127 return 0;
2135 2128
2136 if (host && !host->suspended) 2129 if (host && !host->suspended)
2137 return 0; 2130 return 0;
2138 2131
2139 if (host) { 2132 pm_runtime_get_sync(host->dev);
2140 pm_runtime_get_sync(host->dev);
2141 2133
2142 if (host->got_dbclk) 2134 if (host->got_dbclk)
2143 clk_enable(host->dbclk); 2135 clk_enable(host->dbclk);
2144 2136
2145 if (!(host->mmc->pm_flags & MMC_PM_KEEP_POWER)) 2137 if (!(host->mmc->pm_flags & MMC_PM_KEEP_POWER))
2146 omap_hsmmc_conf_bus_power(host); 2138 omap_hsmmc_conf_bus_power(host);
2147 2139
2148 if (host->pdata->resume) { 2140 if (host->pdata->resume) {
2149 ret = host->pdata->resume(&pdev->dev, host->slot_id); 2141 ret = host->pdata->resume(dev, host->slot_id);
2150 if (ret) 2142 if (ret)
2151 dev_dbg(mmc_dev(host->mmc), 2143 dev_dbg(dev, "Unmask interrupt failed\n");
2152 "Unmask interrupt failed\n"); 2144 }
2153 }
2154 2145
2155 omap_hsmmc_protect_card(host); 2146 omap_hsmmc_protect_card(host);
2156 2147
2157 /* Notify the core to resume the host */ 2148 /* Notify the core to resume the host */
2158 ret = mmc_resume_host(host->mmc); 2149 ret = mmc_resume_host(host->mmc);
2159 if (ret == 0) 2150 if (ret == 0)
2160 host->suspended = 0; 2151 host->suspended = 0;
2161 2152
2162 pm_runtime_mark_last_busy(host->dev); 2153 pm_runtime_mark_last_busy(host->dev);
2163 pm_runtime_put_autosuspend(host->dev); 2154 pm_runtime_put_autosuspend(host->dev);
2164 }
2165 2155
2166 return ret; 2156 return ret;
2167 2157
@@ -2178,7 +2168,7 @@ static int omap_hsmmc_runtime_suspend(struct device *dev)
2178 2168
2179 host = platform_get_drvdata(to_platform_device(dev)); 2169 host = platform_get_drvdata(to_platform_device(dev));
2180 omap_hsmmc_context_save(host); 2170 omap_hsmmc_context_save(host);
2181 dev_dbg(mmc_dev(host->mmc), "disabled\n"); 2171 dev_dbg(dev, "disabled\n");
2182 2172
2183 return 0; 2173 return 0;
2184} 2174}
@@ -2189,7 +2179,7 @@ static int omap_hsmmc_runtime_resume(struct device *dev)
2189 2179
2190 host = platform_get_drvdata(to_platform_device(dev)); 2180 host = platform_get_drvdata(to_platform_device(dev));
2191 omap_hsmmc_context_restore(host); 2181 omap_hsmmc_context_restore(host);
2192 dev_dbg(mmc_dev(host->mmc), "enabled\n"); 2182 dev_dbg(dev, "enabled\n");
2193 2183
2194 return 0; 2184 return 0;
2195} 2185}
@@ -2202,7 +2192,8 @@ static struct dev_pm_ops omap_hsmmc_dev_pm_ops = {
2202}; 2192};
2203 2193
2204static struct platform_driver omap_hsmmc_driver = { 2194static struct platform_driver omap_hsmmc_driver = {
2205 .remove = omap_hsmmc_remove, 2195 .probe = omap_hsmmc_probe,
2196 .remove = __devexit_p(omap_hsmmc_remove),
2206 .driver = { 2197 .driver = {
2207 .name = DRIVER_NAME, 2198 .name = DRIVER_NAME,
2208 .owner = THIS_MODULE, 2199 .owner = THIS_MODULE,
@@ -2211,21 +2202,7 @@ static struct platform_driver omap_hsmmc_driver = {
2211 }, 2202 },
2212}; 2203};
2213 2204
2214static int __init omap_hsmmc_init(void) 2205module_platform_driver(omap_hsmmc_driver);
2215{
2216 /* Register the MMC driver */
2217 return platform_driver_probe(&omap_hsmmc_driver, omap_hsmmc_probe);
2218}
2219
2220static void __exit omap_hsmmc_cleanup(void)
2221{
2222 /* Unregister MMC driver */
2223 platform_driver_unregister(&omap_hsmmc_driver);
2224}
2225
2226module_init(omap_hsmmc_init);
2227module_exit(omap_hsmmc_cleanup);
2228
2229MODULE_DESCRIPTION("OMAP High Speed Multimedia Card driver"); 2206MODULE_DESCRIPTION("OMAP High Speed Multimedia Card driver");
2230MODULE_LICENSE("GPL"); 2207MODULE_LICENSE("GPL");
2231MODULE_ALIAS("platform:" DRIVER_NAME); 2208MODULE_ALIAS("platform:" DRIVER_NAME);
diff --git a/drivers/mmc/host/sdhci-dove.c b/drivers/mmc/host/sdhci-dove.c
index 46fd1fd1b605..177f697b5835 100644
--- a/drivers/mmc/host/sdhci-dove.c
+++ b/drivers/mmc/host/sdhci-dove.c
@@ -20,6 +20,7 @@
20 */ 20 */
21 21
22#include <linux/io.h> 22#include <linux/io.h>
23#include <linux/module.h>
23#include <linux/mmc/host.h> 24#include <linux/mmc/host.h>
24 25
25#include "sdhci-pltfm.h" 26#include "sdhci-pltfm.h"
diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
index 6193a0d7bde5..8abdaf6697a8 100644
--- a/drivers/mmc/host/sdhci-esdhc-imx.c
+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
@@ -467,8 +467,7 @@ static int __devinit sdhci_esdhc_imx_probe(struct platform_device *pdev)
467 clk_prepare_enable(clk); 467 clk_prepare_enable(clk);
468 pltfm_host->clk = clk; 468 pltfm_host->clk = clk;
469 469
470 if (!is_imx25_esdhc(imx_data)) 470 host->quirks |= SDHCI_QUIRK_BROKEN_TIMEOUT_VAL;
471 host->quirks |= SDHCI_QUIRK_BROKEN_TIMEOUT_VAL;
472 471
473 if (is_imx25_esdhc(imx_data) || is_imx35_esdhc(imx_data)) 472 if (is_imx25_esdhc(imx_data) || is_imx35_esdhc(imx_data))
474 /* Fix errata ENGcm07207 present on i.MX25 and i.MX35 */ 473 /* Fix errata ENGcm07207 present on i.MX25 and i.MX35 */
diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
index fbbebe251e01..69ef0beae104 100644
--- a/drivers/mmc/host/sdhci-pci.c
+++ b/drivers/mmc/host/sdhci-pci.c
@@ -1418,8 +1418,6 @@ static int __devinit sdhci_pci_probe(struct pci_dev *pdev,
1418 1418
1419 slots = chip->num_slots; /* Quirk may have changed this */ 1419 slots = chip->num_slots; /* Quirk may have changed this */
1420 1420
1421 pci_enable_msi(pdev);
1422
1423 for (i = 0; i < slots; i++) { 1421 for (i = 0; i < slots; i++) {
1424 slot = sdhci_pci_probe_slot(pdev, chip, first_bar, i); 1422 slot = sdhci_pci_probe_slot(pdev, chip, first_bar, i);
1425 if (IS_ERR(slot)) { 1423 if (IS_ERR(slot)) {
@@ -1438,8 +1436,6 @@ static int __devinit sdhci_pci_probe(struct pci_dev *pdev,
1438 return 0; 1436 return 0;
1439 1437
1440free: 1438free:
1441 pci_disable_msi(pdev);
1442
1443 pci_set_drvdata(pdev, NULL); 1439 pci_set_drvdata(pdev, NULL);
1444 kfree(chip); 1440 kfree(chip);
1445 1441
@@ -1462,8 +1458,6 @@ static void __devexit sdhci_pci_remove(struct pci_dev *pdev)
1462 for (i = 0; i < chip->num_slots; i++) 1458 for (i = 0; i < chip->num_slots; i++)
1463 sdhci_pci_remove_slot(chip->slots[i]); 1459 sdhci_pci_remove_slot(chip->slots[i]);
1464 1460
1465 pci_disable_msi(pdev);
1466
1467 pci_set_drvdata(pdev, NULL); 1461 pci_set_drvdata(pdev, NULL);
1468 kfree(chip); 1462 kfree(chip);
1469 } 1463 }
diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
index b19e7d435f8d..55a164fcaa15 100644
--- a/drivers/mmc/host/sdhci-s3c.c
+++ b/drivers/mmc/host/sdhci-s3c.c
@@ -20,6 +20,10 @@
20#include <linux/io.h> 20#include <linux/io.h>
21#include <linux/gpio.h> 21#include <linux/gpio.h>
22#include <linux/module.h> 22#include <linux/module.h>
23#include <linux/of.h>
24#include <linux/of_gpio.h>
25#include <linux/pm.h>
26#include <linux/pm_runtime.h>
23 27
24#include <linux/mmc/host.h> 28#include <linux/mmc/host.h>
25 29
@@ -53,6 +57,18 @@ struct sdhci_s3c {
53 struct clk *clk_bus[MAX_BUS_CLK]; 57 struct clk *clk_bus[MAX_BUS_CLK];
54}; 58};
55 59
60/**
61 * struct sdhci_s3c_driver_data - S3C SDHCI platform specific driver data
62 * @sdhci_quirks: sdhci host specific quirks.
63 *
64 * Specifies platform specific configuration of sdhci controller.
65 * Note: A structure for driver specific platform data is used for future
66 * expansion of its usage.
67 */
68struct sdhci_s3c_drv_data {
69 unsigned int sdhci_quirks;
70};
71
56static inline struct sdhci_s3c *to_s3c(struct sdhci_host *host) 72static inline struct sdhci_s3c *to_s3c(struct sdhci_host *host)
57{ 73{
58 return sdhci_priv(host); 74 return sdhci_priv(host);
@@ -132,10 +148,10 @@ static unsigned int sdhci_s3c_consider_clock(struct sdhci_s3c *ourhost,
132 return UINT_MAX; 148 return UINT_MAX;
133 149
134 /* 150 /*
135 * Clock divider's step is different as 1 from that of host controller 151 * If controller uses a non-standard clock division, find the best clock
136 * when 'clk_type' is S3C_SDHCI_CLK_DIV_EXTERNAL. 152 * speed possible with selected clock source and skip the division.
137 */ 153 */
138 if (ourhost->pdata->clk_type) { 154 if (ourhost->host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
139 rate = clk_round_rate(clksrc, wanted); 155 rate = clk_round_rate(clksrc, wanted);
140 return wanted - rate; 156 return wanted - rate;
141 } 157 }
@@ -272,6 +288,8 @@ static unsigned int sdhci_cmu_get_min_clock(struct sdhci_host *host)
272static void sdhci_cmu_set_clock(struct sdhci_host *host, unsigned int clock) 288static void sdhci_cmu_set_clock(struct sdhci_host *host, unsigned int clock)
273{ 289{
274 struct sdhci_s3c *ourhost = to_s3c(host); 290 struct sdhci_s3c *ourhost = to_s3c(host);
291 unsigned long timeout;
292 u16 clk = 0;
275 293
276 /* don't bother if the clock is going off */ 294 /* don't bother if the clock is going off */
277 if (clock == 0) 295 if (clock == 0)
@@ -282,6 +300,25 @@ static void sdhci_cmu_set_clock(struct sdhci_host *host, unsigned int clock)
282 clk_set_rate(ourhost->clk_bus[ourhost->cur_clk], clock); 300 clk_set_rate(ourhost->clk_bus[ourhost->cur_clk], clock);
283 301
284 host->clock = clock; 302 host->clock = clock;
303
304 clk = SDHCI_CLOCK_INT_EN;
305 sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
306
307 /* Wait max 20 ms */
308 timeout = 20;
309 while (!((clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL))
310 & SDHCI_CLOCK_INT_STABLE)) {
311 if (timeout == 0) {
312 printk(KERN_ERR "%s: Internal clock never "
313 "stabilised.\n", mmc_hostname(host->mmc));
314 return;
315 }
316 timeout--;
317 mdelay(1);
318 }
319
320 clk |= SDHCI_CLOCK_CARD_EN;
321 sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
285} 322}
286 323
287/** 324/**
@@ -382,16 +419,24 @@ static void sdhci_s3c_setup_card_detect_gpio(struct sdhci_s3c *sc)
382 } 419 }
383} 420}
384 421
422static inline struct sdhci_s3c_drv_data *sdhci_s3c_get_driver_data(
423 struct platform_device *pdev)
424{
425 return (struct sdhci_s3c_drv_data *)
426 platform_get_device_id(pdev)->driver_data;
427}
428
385static int __devinit sdhci_s3c_probe(struct platform_device *pdev) 429static int __devinit sdhci_s3c_probe(struct platform_device *pdev)
386{ 430{
387 struct s3c_sdhci_platdata *pdata = pdev->dev.platform_data; 431 struct s3c_sdhci_platdata *pdata;
432 struct sdhci_s3c_drv_data *drv_data;
388 struct device *dev = &pdev->dev; 433 struct device *dev = &pdev->dev;
389 struct sdhci_host *host; 434 struct sdhci_host *host;
390 struct sdhci_s3c *sc; 435 struct sdhci_s3c *sc;
391 struct resource *res; 436 struct resource *res;
392 int ret, irq, ptr, clks; 437 int ret, irq, ptr, clks;
393 438
394 if (!pdata) { 439 if (!pdev->dev.platform_data) {
395 dev_err(dev, "no device data specified\n"); 440 dev_err(dev, "no device data specified\n");
396 return -ENOENT; 441 return -ENOENT;
397 } 442 }
@@ -402,18 +447,20 @@ static int __devinit sdhci_s3c_probe(struct platform_device *pdev)
402 return irq; 447 return irq;
403 } 448 }
404 449
405 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
406 if (!res) {
407 dev_err(dev, "no memory specified\n");
408 return -ENOENT;
409 }
410
411 host = sdhci_alloc_host(dev, sizeof(struct sdhci_s3c)); 450 host = sdhci_alloc_host(dev, sizeof(struct sdhci_s3c));
412 if (IS_ERR(host)) { 451 if (IS_ERR(host)) {
413 dev_err(dev, "sdhci_alloc_host() failed\n"); 452 dev_err(dev, "sdhci_alloc_host() failed\n");
414 return PTR_ERR(host); 453 return PTR_ERR(host);
415 } 454 }
416 455
456 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
457 if (!pdata) {
458 ret = -ENOMEM;
459 goto err_io_clk;
460 }
461 memcpy(pdata, pdev->dev.platform_data, sizeof(*pdata));
462
463 drv_data = sdhci_s3c_get_driver_data(pdev);
417 sc = sdhci_priv(host); 464 sc = sdhci_priv(host);
418 465
419 sc->host = host; 466 sc->host = host;
@@ -464,15 +511,8 @@ static int __devinit sdhci_s3c_probe(struct platform_device *pdev)
464 goto err_no_busclks; 511 goto err_no_busclks;
465 } 512 }
466 513
467 sc->ioarea = request_mem_region(res->start, resource_size(res), 514 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
468 mmc_hostname(host->mmc)); 515 host->ioaddr = devm_request_and_ioremap(&pdev->dev, res);
469 if (!sc->ioarea) {
470 dev_err(dev, "failed to reserve register area\n");
471 ret = -ENXIO;
472 goto err_req_regs;
473 }
474
475 host->ioaddr = ioremap_nocache(res->start, resource_size(res));
476 if (!host->ioaddr) { 516 if (!host->ioaddr) {
477 dev_err(dev, "failed to map registers\n"); 517 dev_err(dev, "failed to map registers\n");
478 ret = -ENXIO; 518 ret = -ENXIO;
@@ -491,6 +531,8 @@ static int __devinit sdhci_s3c_probe(struct platform_device *pdev)
491 /* Setup quirks for the controller */ 531 /* Setup quirks for the controller */
492 host->quirks |= SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC; 532 host->quirks |= SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC;
493 host->quirks |= SDHCI_QUIRK_NO_HISPD_BIT; 533 host->quirks |= SDHCI_QUIRK_NO_HISPD_BIT;
534 if (drv_data)
535 host->quirks |= drv_data->sdhci_quirks;
494 536
495#ifndef CONFIG_MMC_SDHCI_S3C_DMA 537#ifndef CONFIG_MMC_SDHCI_S3C_DMA
496 538
@@ -518,6 +560,14 @@ static int __devinit sdhci_s3c_probe(struct platform_device *pdev)
518 if (pdata->cd_type == S3C_SDHCI_CD_PERMANENT) 560 if (pdata->cd_type == S3C_SDHCI_CD_PERMANENT)
519 host->mmc->caps = MMC_CAP_NONREMOVABLE; 561 host->mmc->caps = MMC_CAP_NONREMOVABLE;
520 562
563 switch (pdata->max_width) {
564 case 8:
565 host->mmc->caps |= MMC_CAP_8_BIT_DATA;
566 case 4:
567 host->mmc->caps |= MMC_CAP_4_BIT_DATA;
568 break;
569 }
570
521 if (pdata->pm_caps) 571 if (pdata->pm_caps)
522 host->mmc->pm_caps |= pdata->pm_caps; 572 host->mmc->pm_caps |= pdata->pm_caps;
523 573
@@ -531,7 +581,7 @@ static int __devinit sdhci_s3c_probe(struct platform_device *pdev)
531 * If controller does not have internal clock divider, 581 * If controller does not have internal clock divider,
532 * we can use overriding functions instead of default. 582 * we can use overriding functions instead of default.
533 */ 583 */
534 if (pdata->clk_type) { 584 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
535 sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock; 585 sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
536 sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock; 586 sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
537 sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock; 587 sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
@@ -544,10 +594,17 @@ static int __devinit sdhci_s3c_probe(struct platform_device *pdev)
544 if (pdata->host_caps2) 594 if (pdata->host_caps2)
545 host->mmc->caps2 |= pdata->host_caps2; 595 host->mmc->caps2 |= pdata->host_caps2;
546 596
597 pm_runtime_enable(&pdev->dev);
598 pm_runtime_set_autosuspend_delay(&pdev->dev, 50);
599 pm_runtime_use_autosuspend(&pdev->dev);
600 pm_suspend_ignore_children(&pdev->dev, 1);
601
547 ret = sdhci_add_host(host); 602 ret = sdhci_add_host(host);
548 if (ret) { 603 if (ret) {
549 dev_err(dev, "sdhci_add_host() failed\n"); 604 dev_err(dev, "sdhci_add_host() failed\n");
550 goto err_add_host; 605 pm_runtime_forbid(&pdev->dev);
606 pm_runtime_get_noresume(&pdev->dev);
607 goto err_req_regs;
551 } 608 }
552 609
553 /* The following two methods of card detection might call 610 /* The following two methods of card detection might call
@@ -561,10 +618,6 @@ static int __devinit sdhci_s3c_probe(struct platform_device *pdev)
561 618
562 return 0; 619 return 0;
563 620
564 err_add_host:
565 release_resource(sc->ioarea);
566 kfree(sc->ioarea);
567
568 err_req_regs: 621 err_req_regs:
569 for (ptr = 0; ptr < MAX_BUS_CLK; ptr++) { 622 for (ptr = 0; ptr < MAX_BUS_CLK; ptr++) {
570 if (sc->clk_bus[ptr]) { 623 if (sc->clk_bus[ptr]) {
@@ -601,6 +654,8 @@ static int __devexit sdhci_s3c_remove(struct platform_device *pdev)
601 654
602 sdhci_remove_host(host, 1); 655 sdhci_remove_host(host, 1);
603 656
657 pm_runtime_disable(&pdev->dev);
658
604 for (ptr = 0; ptr < 3; ptr++) { 659 for (ptr = 0; ptr < 3; ptr++) {
605 if (sc->clk_bus[ptr]) { 660 if (sc->clk_bus[ptr]) {
606 clk_disable(sc->clk_bus[ptr]); 661 clk_disable(sc->clk_bus[ptr]);
@@ -610,18 +665,13 @@ static int __devexit sdhci_s3c_remove(struct platform_device *pdev)
610 clk_disable(sc->clk_io); 665 clk_disable(sc->clk_io);
611 clk_put(sc->clk_io); 666 clk_put(sc->clk_io);
612 667
613 iounmap(host->ioaddr);
614 release_resource(sc->ioarea);
615 kfree(sc->ioarea);
616
617 sdhci_free_host(host); 668 sdhci_free_host(host);
618 platform_set_drvdata(pdev, NULL); 669 platform_set_drvdata(pdev, NULL);
619 670
620 return 0; 671 return 0;
621} 672}
622 673
623#ifdef CONFIG_PM 674#ifdef CONFIG_PM_SLEEP
624
625static int sdhci_s3c_suspend(struct device *dev) 675static int sdhci_s3c_suspend(struct device *dev)
626{ 676{
627 struct sdhci_host *host = dev_get_drvdata(dev); 677 struct sdhci_host *host = dev_get_drvdata(dev);
@@ -635,10 +685,29 @@ static int sdhci_s3c_resume(struct device *dev)
635 685
636 return sdhci_resume_host(host); 686 return sdhci_resume_host(host);
637} 687}
688#endif
689
690#ifdef CONFIG_PM_RUNTIME
691static int sdhci_s3c_runtime_suspend(struct device *dev)
692{
693 struct sdhci_host *host = dev_get_drvdata(dev);
694
695 return sdhci_runtime_suspend_host(host);
696}
638 697
698static int sdhci_s3c_runtime_resume(struct device *dev)
699{
700 struct sdhci_host *host = dev_get_drvdata(dev);
701
702 return sdhci_runtime_resume_host(host);
703}
704#endif
705
706#ifdef CONFIG_PM
639static const struct dev_pm_ops sdhci_s3c_pmops = { 707static const struct dev_pm_ops sdhci_s3c_pmops = {
640 .suspend = sdhci_s3c_suspend, 708 SET_SYSTEM_SLEEP_PM_OPS(sdhci_s3c_suspend, sdhci_s3c_resume)
641 .resume = sdhci_s3c_resume, 709 SET_RUNTIME_PM_OPS(sdhci_s3c_runtime_suspend, sdhci_s3c_runtime_resume,
710 NULL)
642}; 711};
643 712
644#define SDHCI_S3C_PMOPS (&sdhci_s3c_pmops) 713#define SDHCI_S3C_PMOPS (&sdhci_s3c_pmops)
@@ -647,9 +716,31 @@ static const struct dev_pm_ops sdhci_s3c_pmops = {
647#define SDHCI_S3C_PMOPS NULL 716#define SDHCI_S3C_PMOPS NULL
648#endif 717#endif
649 718
719#if defined(CONFIG_CPU_EXYNOS4210) || defined(CONFIG_SOC_EXYNOS4212)
720static struct sdhci_s3c_drv_data exynos4_sdhci_drv_data = {
721 .sdhci_quirks = SDHCI_QUIRK_NONSTANDARD_CLOCK,
722};
723#define EXYNOS4_SDHCI_DRV_DATA ((kernel_ulong_t)&exynos4_sdhci_drv_data)
724#else
725#define EXYNOS4_SDHCI_DRV_DATA ((kernel_ulong_t)NULL)
726#endif
727
728static struct platform_device_id sdhci_s3c_driver_ids[] = {
729 {
730 .name = "s3c-sdhci",
731 .driver_data = (kernel_ulong_t)NULL,
732 }, {
733 .name = "exynos4-sdhci",
734 .driver_data = EXYNOS4_SDHCI_DRV_DATA,
735 },
736 { }
737};
738MODULE_DEVICE_TABLE(platform, sdhci_s3c_driver_ids);
739
650static struct platform_driver sdhci_s3c_driver = { 740static struct platform_driver sdhci_s3c_driver = {
651 .probe = sdhci_s3c_probe, 741 .probe = sdhci_s3c_probe,
652 .remove = __devexit_p(sdhci_s3c_remove), 742 .remove = __devexit_p(sdhci_s3c_remove),
743 .id_table = sdhci_s3c_driver_ids,
653 .driver = { 744 .driver = {
654 .owner = THIS_MODULE, 745 .owner = THIS_MODULE,
655 .name = "s3c-sdhci", 746 .name = "s3c-sdhci",
diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index 8262cadfdab7..ccefdebeff14 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -147,7 +147,7 @@ static void sdhci_set_card_detection(struct sdhci_host *host, bool enable)
147 u32 present, irqs; 147 u32 present, irqs;
148 148
149 if ((host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) || 149 if ((host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) ||
150 !mmc_card_is_removable(host->mmc)) 150 (host->mmc->caps & MMC_CAP_NONREMOVABLE))
151 return; 151 return;
152 152
153 present = sdhci_readl(host, SDHCI_PRESENT_STATE) & 153 present = sdhci_readl(host, SDHCI_PRESENT_STATE) &
@@ -2782,8 +2782,9 @@ int sdhci_add_host(struct sdhci_host *host)
2782 mmc_card_is_removable(mmc)) 2782 mmc_card_is_removable(mmc))
2783 mmc->caps |= MMC_CAP_NEEDS_POLL; 2783 mmc->caps |= MMC_CAP_NEEDS_POLL;
2784 2784
2785 /* UHS-I mode(s) supported by the host controller. */ 2785 /* Any UHS-I mode in caps implies SDR12 and SDR25 support. */
2786 if (host->version >= SDHCI_SPEC_300) 2786 if (caps[1] & (SDHCI_SUPPORT_SDR104 | SDHCI_SUPPORT_SDR50 |
2787 SDHCI_SUPPORT_DDR50))
2787 mmc->caps |= MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25; 2788 mmc->caps |= MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25;
2788 2789
2789 /* SDR104 supports also implies SDR50 support */ 2790 /* SDR104 supports also implies SDR50 support */
diff --git a/drivers/mmc/host/sh_mmcif.c b/drivers/mmc/host/sh_mmcif.c
index aafaf0b6eb1c..724b35e85a26 100644
--- a/drivers/mmc/host/sh_mmcif.c
+++ b/drivers/mmc/host/sh_mmcif.c
@@ -454,7 +454,8 @@ static void sh_mmcif_clock_control(struct sh_mmcif_host *host, unsigned int clk)
454 sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, CLK_SUP_PCLK); 454 sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, CLK_SUP_PCLK);
455 else 455 else
456 sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, CLK_CLEAR & 456 sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, CLK_CLEAR &
457 ((fls(host->clk / clk) - 1) << 16)); 457 ((fls(DIV_ROUND_UP(host->clk,
458 clk) - 1) - 1) << 16));
458 459
459 sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, CLK_ENABLE); 460 sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, CLK_ENABLE);
460} 461}
@@ -1297,14 +1298,8 @@ static int __devinit sh_mmcif_probe(struct platform_device *pdev)
1297 spin_lock_init(&host->lock); 1298 spin_lock_init(&host->lock);
1298 1299
1299 mmc->ops = &sh_mmcif_ops; 1300 mmc->ops = &sh_mmcif_ops;
1300 mmc->f_max = host->clk; 1301 mmc->f_max = host->clk / 2;
1301 /* close to 400KHz */ 1302 mmc->f_min = host->clk / 512;
1302 if (mmc->f_max < 51200000)
1303 mmc->f_min = mmc->f_max / 128;
1304 else if (mmc->f_max < 102400000)
1305 mmc->f_min = mmc->f_max / 256;
1306 else
1307 mmc->f_min = mmc->f_max / 512;
1308 if (pd->ocr) 1303 if (pd->ocr)
1309 mmc->ocr_avail = pd->ocr; 1304 mmc->ocr_avail = pd->ocr;
1310 mmc->caps = MMC_CAP_MMC_HIGHSPEED; 1305 mmc->caps = MMC_CAP_MMC_HIGHSPEED;
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 94eb05b1afdf..58fc65f5c817 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -106,16 +106,14 @@ static int mtdchar_open(struct inode *inode, struct file *file)
106 } 106 }
107 107
108 if (mtd->type == MTD_ABSENT) { 108 if (mtd->type == MTD_ABSENT) {
109 put_mtd_device(mtd);
110 ret = -ENODEV; 109 ret = -ENODEV;
111 goto out; 110 goto out1;
112 } 111 }
113 112
114 mtd_ino = iget_locked(mnt->mnt_sb, devnum); 113 mtd_ino = iget_locked(mnt->mnt_sb, devnum);
115 if (!mtd_ino) { 114 if (!mtd_ino) {
116 put_mtd_device(mtd);
117 ret = -ENOMEM; 115 ret = -ENOMEM;
118 goto out; 116 goto out1;
119 } 117 }
120 if (mtd_ino->i_state & I_NEW) { 118 if (mtd_ino->i_state & I_NEW) {
121 mtd_ino->i_private = mtd; 119 mtd_ino->i_private = mtd;
@@ -127,23 +125,25 @@ static int mtdchar_open(struct inode *inode, struct file *file)
127 125
128 /* You can't open it RW if it's not a writeable device */ 126 /* You can't open it RW if it's not a writeable device */
129 if ((file->f_mode & FMODE_WRITE) && !(mtd->flags & MTD_WRITEABLE)) { 127 if ((file->f_mode & FMODE_WRITE) && !(mtd->flags & MTD_WRITEABLE)) {
130 iput(mtd_ino);
131 put_mtd_device(mtd);
132 ret = -EACCES; 128 ret = -EACCES;
133 goto out; 129 goto out2;
134 } 130 }
135 131
136 mfi = kzalloc(sizeof(*mfi), GFP_KERNEL); 132 mfi = kzalloc(sizeof(*mfi), GFP_KERNEL);
137 if (!mfi) { 133 if (!mfi) {
138 iput(mtd_ino);
139 put_mtd_device(mtd);
140 ret = -ENOMEM; 134 ret = -ENOMEM;
141 goto out; 135 goto out2;
142 } 136 }
143 mfi->ino = mtd_ino; 137 mfi->ino = mtd_ino;
144 mfi->mtd = mtd; 138 mfi->mtd = mtd;
145 file->private_data = mfi; 139 file->private_data = mfi;
140 mutex_unlock(&mtd_mutex);
141 return 0;
146 142
143out2:
144 iput(mtd_ino);
145out1:
146 put_mtd_device(mtd);
147out: 147out:
148 mutex_unlock(&mtd_mutex); 148 mutex_unlock(&mtd_mutex);
149 simple_release_fs(&mnt, &count); 149 simple_release_fs(&mnt, &count);
diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
index 75b1dde16358..9ec51cec2e14 100644
--- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
+++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
@@ -266,6 +266,7 @@ int start_dma_without_bch_irq(struct gpmi_nand_data *this,
266 desc->callback = dma_irq_callback; 266 desc->callback = dma_irq_callback;
267 desc->callback_param = this; 267 desc->callback_param = this;
268 dmaengine_submit(desc); 268 dmaengine_submit(desc);
269 dma_async_issue_pending(get_dma_chan(this));
269 270
270 /* Wait for the interrupt from the DMA block. */ 271 /* Wait for the interrupt from the DMA block. */
271 err = wait_for_completion_timeout(dma_c, msecs_to_jiffies(1000)); 272 err = wait_for_completion_timeout(dma_c, msecs_to_jiffies(1000));
diff --git a/drivers/mtd/ubi/debug.c b/drivers/mtd/ubi/debug.c
index e2cdebf40840..61af9bb560ab 100644
--- a/drivers/mtd/ubi/debug.c
+++ b/drivers/mtd/ubi/debug.c
@@ -386,19 +386,11 @@ out:
386 return count; 386 return count;
387} 387}
388 388
389static int default_open(struct inode *inode, struct file *file)
390{
391 if (inode->i_private)
392 file->private_data = inode->i_private;
393
394 return 0;
395}
396
397/* File operations for all UBI debugfs files */ 389/* File operations for all UBI debugfs files */
398static const struct file_operations dfs_fops = { 390static const struct file_operations dfs_fops = {
399 .read = dfs_file_read, 391 .read = dfs_file_read,
400 .write = dfs_file_write, 392 .write = dfs_file_write,
401 .open = default_open, 393 .open = simple_open,
402 .llseek = no_llseek, 394 .llseek = no_llseek,
403 .owner = THIS_MODULE, 395 .owner = THIS_MODULE,
404}; 396};
diff --git a/drivers/net/arcnet/arc-rimi.c b/drivers/net/arcnet/arc-rimi.c
index 25197b698dd6..b8b4c7ba884f 100644
--- a/drivers/net/arcnet/arc-rimi.c
+++ b/drivers/net/arcnet/arc-rimi.c
@@ -89,16 +89,16 @@ static int __init arcrimi_probe(struct net_device *dev)
89 BUGLVL(D_NORMAL) printk(VERSION); 89 BUGLVL(D_NORMAL) printk(VERSION);
90 BUGLVL(D_NORMAL) printk("E-mail me if you actually test the RIM I driver, please!\n"); 90 BUGLVL(D_NORMAL) printk("E-mail me if you actually test the RIM I driver, please!\n");
91 91
92 BUGMSG(D_NORMAL, "Given: node %02Xh, shmem %lXh, irq %d\n", 92 BUGLVL(D_NORMAL) printk("Given: node %02Xh, shmem %lXh, irq %d\n",
93 dev->dev_addr[0], dev->mem_start, dev->irq); 93 dev->dev_addr[0], dev->mem_start, dev->irq);
94 94
95 if (dev->mem_start <= 0 || dev->irq <= 0) { 95 if (dev->mem_start <= 0 || dev->irq <= 0) {
96 BUGMSG(D_NORMAL, "No autoprobe for RIM I; you " 96 BUGLVL(D_NORMAL) printk("No autoprobe for RIM I; you "
97 "must specify the shmem and irq!\n"); 97 "must specify the shmem and irq!\n");
98 return -ENODEV; 98 return -ENODEV;
99 } 99 }
100 if (dev->dev_addr[0] == 0) { 100 if (dev->dev_addr[0] == 0) {
101 BUGMSG(D_NORMAL, "You need to specify your card's station " 101 BUGLVL(D_NORMAL) printk("You need to specify your card's station "
102 "ID!\n"); 102 "ID!\n");
103 return -ENODEV; 103 return -ENODEV;
104 } 104 }
@@ -109,7 +109,7 @@ static int __init arcrimi_probe(struct net_device *dev)
109 * will be taken. 109 * will be taken.
110 */ 110 */
111 if (!request_mem_region(dev->mem_start, MIRROR_SIZE, "arcnet (90xx)")) { 111 if (!request_mem_region(dev->mem_start, MIRROR_SIZE, "arcnet (90xx)")) {
112 BUGMSG(D_NORMAL, "Card memory already allocated\n"); 112 BUGLVL(D_NORMAL) printk("Card memory already allocated\n");
113 return -ENODEV; 113 return -ENODEV;
114 } 114 }
115 return arcrimi_found(dev); 115 return arcrimi_found(dev);
diff --git a/drivers/net/bonding/bond_3ad.c b/drivers/net/bonding/bond_3ad.c
index 793b00138275..3463b469e657 100644
--- a/drivers/net/bonding/bond_3ad.c
+++ b/drivers/net/bonding/bond_3ad.c
@@ -2173,9 +2173,10 @@ re_arm:
2173 * received frames (loopback). Since only the payload is given to this 2173 * received frames (loopback). Since only the payload is given to this
2174 * function, it check for loopback. 2174 * function, it check for loopback.
2175 */ 2175 */
2176static void bond_3ad_rx_indication(struct lacpdu *lacpdu, struct slave *slave, u16 length) 2176static int bond_3ad_rx_indication(struct lacpdu *lacpdu, struct slave *slave, u16 length)
2177{ 2177{
2178 struct port *port; 2178 struct port *port;
2179 int ret = RX_HANDLER_ANOTHER;
2179 2180
2180 if (length >= sizeof(struct lacpdu)) { 2181 if (length >= sizeof(struct lacpdu)) {
2181 2182
@@ -2184,11 +2185,12 @@ static void bond_3ad_rx_indication(struct lacpdu *lacpdu, struct slave *slave, u
2184 if (!port->slave) { 2185 if (!port->slave) {
2185 pr_warning("%s: Warning: port of slave %s is uninitialized\n", 2186 pr_warning("%s: Warning: port of slave %s is uninitialized\n",
2186 slave->dev->name, slave->dev->master->name); 2187 slave->dev->name, slave->dev->master->name);
2187 return; 2188 return ret;
2188 } 2189 }
2189 2190
2190 switch (lacpdu->subtype) { 2191 switch (lacpdu->subtype) {
2191 case AD_TYPE_LACPDU: 2192 case AD_TYPE_LACPDU:
2193 ret = RX_HANDLER_CONSUMED;
2192 pr_debug("Received LACPDU on port %d\n", 2194 pr_debug("Received LACPDU on port %d\n",
2193 port->actor_port_number); 2195 port->actor_port_number);
2194 /* Protect against concurrent state machines */ 2196 /* Protect against concurrent state machines */
@@ -2198,6 +2200,7 @@ static void bond_3ad_rx_indication(struct lacpdu *lacpdu, struct slave *slave, u
2198 break; 2200 break;
2199 2201
2200 case AD_TYPE_MARKER: 2202 case AD_TYPE_MARKER:
2203 ret = RX_HANDLER_CONSUMED;
2201 // No need to convert fields to Little Endian since we don't use the marker's fields. 2204 // No need to convert fields to Little Endian since we don't use the marker's fields.
2202 2205
2203 switch (((struct bond_marker *)lacpdu)->tlv_type) { 2206 switch (((struct bond_marker *)lacpdu)->tlv_type) {
@@ -2219,6 +2222,7 @@ static void bond_3ad_rx_indication(struct lacpdu *lacpdu, struct slave *slave, u
2219 } 2222 }
2220 } 2223 }
2221 } 2224 }
2225 return ret;
2222} 2226}
2223 2227
2224/** 2228/**
@@ -2456,18 +2460,20 @@ out:
2456 return NETDEV_TX_OK; 2460 return NETDEV_TX_OK;
2457} 2461}
2458 2462
2459void bond_3ad_lacpdu_recv(struct sk_buff *skb, struct bonding *bond, 2463int bond_3ad_lacpdu_recv(struct sk_buff *skb, struct bonding *bond,
2460 struct slave *slave) 2464 struct slave *slave)
2461{ 2465{
2466 int ret = RX_HANDLER_ANOTHER;
2462 if (skb->protocol != PKT_TYPE_LACPDU) 2467 if (skb->protocol != PKT_TYPE_LACPDU)
2463 return; 2468 return ret;
2464 2469
2465 if (!pskb_may_pull(skb, sizeof(struct lacpdu))) 2470 if (!pskb_may_pull(skb, sizeof(struct lacpdu)))
2466 return; 2471 return ret;
2467 2472
2468 read_lock(&bond->lock); 2473 read_lock(&bond->lock);
2469 bond_3ad_rx_indication((struct lacpdu *) skb->data, slave, skb->len); 2474 ret = bond_3ad_rx_indication((struct lacpdu *) skb->data, slave, skb->len);
2470 read_unlock(&bond->lock); 2475 read_unlock(&bond->lock);
2476 return ret;
2471} 2477}
2472 2478
2473/* 2479/*
diff --git a/drivers/net/bonding/bond_3ad.h b/drivers/net/bonding/bond_3ad.h
index 235b2cc58b28..5ee7e3c45db7 100644
--- a/drivers/net/bonding/bond_3ad.h
+++ b/drivers/net/bonding/bond_3ad.h
@@ -274,7 +274,7 @@ void bond_3ad_adapter_duplex_changed(struct slave *slave);
274void bond_3ad_handle_link_change(struct slave *slave, char link); 274void bond_3ad_handle_link_change(struct slave *slave, char link);
275int bond_3ad_get_active_agg_info(struct bonding *bond, struct ad_info *ad_info); 275int bond_3ad_get_active_agg_info(struct bonding *bond, struct ad_info *ad_info);
276int bond_3ad_xmit_xor(struct sk_buff *skb, struct net_device *dev); 276int bond_3ad_xmit_xor(struct sk_buff *skb, struct net_device *dev);
277void bond_3ad_lacpdu_recv(struct sk_buff *skb, struct bonding *bond, 277int bond_3ad_lacpdu_recv(struct sk_buff *skb, struct bonding *bond,
278 struct slave *slave); 278 struct slave *slave);
279int bond_3ad_set_carrier(struct bonding *bond); 279int bond_3ad_set_carrier(struct bonding *bond);
280void bond_3ad_update_lacp_rate(struct bonding *bond); 280void bond_3ad_update_lacp_rate(struct bonding *bond);
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 0c76186bb9e7..bc13b3d77432 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -891,9 +891,15 @@ static void bond_do_fail_over_mac(struct bonding *bond,
891 891
892 switch (bond->params.fail_over_mac) { 892 switch (bond->params.fail_over_mac) {
893 case BOND_FOM_ACTIVE: 893 case BOND_FOM_ACTIVE:
894 if (new_active) 894 if (new_active) {
895 memcpy(bond->dev->dev_addr, new_active->dev->dev_addr, 895 memcpy(bond->dev->dev_addr, new_active->dev->dev_addr,
896 new_active->dev->addr_len); 896 new_active->dev->addr_len);
897 write_unlock_bh(&bond->curr_slave_lock);
898 read_unlock(&bond->lock);
899 call_netdevice_notifiers(NETDEV_CHANGEADDR, bond->dev);
900 read_lock(&bond->lock);
901 write_lock_bh(&bond->curr_slave_lock);
902 }
897 break; 903 break;
898 case BOND_FOM_FOLLOW: 904 case BOND_FOM_FOLLOW:
899 /* 905 /*
@@ -1438,8 +1444,9 @@ static rx_handler_result_t bond_handle_frame(struct sk_buff **pskb)
1438 struct sk_buff *skb = *pskb; 1444 struct sk_buff *skb = *pskb;
1439 struct slave *slave; 1445 struct slave *slave;
1440 struct bonding *bond; 1446 struct bonding *bond;
1441 void (*recv_probe)(struct sk_buff *, struct bonding *, 1447 int (*recv_probe)(struct sk_buff *, struct bonding *,
1442 struct slave *); 1448 struct slave *);
1449 int ret = RX_HANDLER_ANOTHER;
1443 1450
1444 skb = skb_share_check(skb, GFP_ATOMIC); 1451 skb = skb_share_check(skb, GFP_ATOMIC);
1445 if (unlikely(!skb)) 1452 if (unlikely(!skb))
@@ -1458,8 +1465,12 @@ static rx_handler_result_t bond_handle_frame(struct sk_buff **pskb)
1458 struct sk_buff *nskb = skb_clone(skb, GFP_ATOMIC); 1465 struct sk_buff *nskb = skb_clone(skb, GFP_ATOMIC);
1459 1466
1460 if (likely(nskb)) { 1467 if (likely(nskb)) {
1461 recv_probe(nskb, bond, slave); 1468 ret = recv_probe(nskb, bond, slave);
1462 dev_kfree_skb(nskb); 1469 dev_kfree_skb(nskb);
1470 if (ret == RX_HANDLER_CONSUMED) {
1471 consume_skb(skb);
1472 return ret;
1473 }
1463 } 1474 }
1464 } 1475 }
1465 1476
@@ -1481,7 +1492,7 @@ static rx_handler_result_t bond_handle_frame(struct sk_buff **pskb)
1481 memcpy(eth_hdr(skb)->h_dest, bond->dev->dev_addr, ETH_ALEN); 1492 memcpy(eth_hdr(skb)->h_dest, bond->dev->dev_addr, ETH_ALEN);
1482 } 1493 }
1483 1494
1484 return RX_HANDLER_ANOTHER; 1495 return ret;
1485} 1496}
1486 1497
1487/* enslave device <slave> to bond device <master> */ 1498/* enslave device <slave> to bond device <master> */
@@ -2028,6 +2039,9 @@ int bond_release(struct net_device *bond_dev, struct net_device *slave_dev)
2028 write_unlock_bh(&bond->lock); 2039 write_unlock_bh(&bond->lock);
2029 unblock_netpoll_tx(); 2040 unblock_netpoll_tx();
2030 2041
2042 if (bond->slave_cnt == 0)
2043 call_netdevice_notifiers(NETDEV_CHANGEADDR, bond->dev);
2044
2031 bond_compute_features(bond); 2045 bond_compute_features(bond);
2032 if (!(bond_dev->features & NETIF_F_VLAN_CHALLENGED) && 2046 if (!(bond_dev->features & NETIF_F_VLAN_CHALLENGED) &&
2033 (old_features & NETIF_F_VLAN_CHALLENGED)) 2047 (old_features & NETIF_F_VLAN_CHALLENGED))
@@ -2714,7 +2728,7 @@ static void bond_validate_arp(struct bonding *bond, struct slave *slave, __be32
2714 } 2728 }
2715} 2729}
2716 2730
2717static void bond_arp_rcv(struct sk_buff *skb, struct bonding *bond, 2731static int bond_arp_rcv(struct sk_buff *skb, struct bonding *bond,
2718 struct slave *slave) 2732 struct slave *slave)
2719{ 2733{
2720 struct arphdr *arp; 2734 struct arphdr *arp;
@@ -2722,7 +2736,7 @@ static void bond_arp_rcv(struct sk_buff *skb, struct bonding *bond,
2722 __be32 sip, tip; 2736 __be32 sip, tip;
2723 2737
2724 if (skb->protocol != __cpu_to_be16(ETH_P_ARP)) 2738 if (skb->protocol != __cpu_to_be16(ETH_P_ARP))
2725 return; 2739 return RX_HANDLER_ANOTHER;
2726 2740
2727 read_lock(&bond->lock); 2741 read_lock(&bond->lock);
2728 2742
@@ -2767,6 +2781,7 @@ static void bond_arp_rcv(struct sk_buff *skb, struct bonding *bond,
2767 2781
2768out_unlock: 2782out_unlock:
2769 read_unlock(&bond->lock); 2783 read_unlock(&bond->lock);
2784 return RX_HANDLER_ANOTHER;
2770} 2785}
2771 2786
2772/* 2787/*
@@ -3001,7 +3016,11 @@ static void bond_ab_arp_commit(struct bonding *bond, int delta_in_ticks)
3001 trans_start + delta_in_ticks)) || 3016 trans_start + delta_in_ticks)) ||
3002 bond->curr_active_slave != slave) { 3017 bond->curr_active_slave != slave) {
3003 slave->link = BOND_LINK_UP; 3018 slave->link = BOND_LINK_UP;
3004 bond->current_arp_slave = NULL; 3019 if (bond->current_arp_slave) {
3020 bond_set_slave_inactive_flags(
3021 bond->current_arp_slave);
3022 bond->current_arp_slave = NULL;
3023 }
3005 3024
3006 pr_info("%s: link status definitely up for interface %s.\n", 3025 pr_info("%s: link status definitely up for interface %s.\n",
3007 bond->dev->name, slave->dev->name); 3026 bond->dev->name, slave->dev->name);
@@ -3695,17 +3714,52 @@ static void bond_set_multicast_list(struct net_device *bond_dev)
3695 read_unlock(&bond->lock); 3714 read_unlock(&bond->lock);
3696} 3715}
3697 3716
3698static int bond_neigh_setup(struct net_device *dev, struct neigh_parms *parms) 3717static int bond_neigh_init(struct neighbour *n)
3699{ 3718{
3700 struct bonding *bond = netdev_priv(dev); 3719 struct bonding *bond = netdev_priv(n->dev);
3701 struct slave *slave = bond->first_slave; 3720 struct slave *slave = bond->first_slave;
3721 const struct net_device_ops *slave_ops;
3722 struct neigh_parms parms;
3723 int ret;
3724
3725 if (!slave)
3726 return 0;
3727
3728 slave_ops = slave->dev->netdev_ops;
3729
3730 if (!slave_ops->ndo_neigh_setup)
3731 return 0;
3732
3733 parms.neigh_setup = NULL;
3734 parms.neigh_cleanup = NULL;
3735 ret = slave_ops->ndo_neigh_setup(slave->dev, &parms);
3736 if (ret)
3737 return ret;
3738
3739 /*
3740 * Assign slave's neigh_cleanup to neighbour in case cleanup is called
3741 * after the last slave has been detached. Assumes that all slaves
3742 * utilize the same neigh_cleanup (true at this writing as only user
3743 * is ipoib).
3744 */
3745 n->parms->neigh_cleanup = parms.neigh_cleanup;
3746
3747 if (!parms.neigh_setup)
3748 return 0;
3749
3750 return parms.neigh_setup(n);
3751}
3752
3753/*
3754 * The bonding ndo_neigh_setup is called at init time beofre any
3755 * slave exists. So we must declare proxy setup function which will
3756 * be used at run time to resolve the actual slave neigh param setup.
3757 */
3758static int bond_neigh_setup(struct net_device *dev,
3759 struct neigh_parms *parms)
3760{
3761 parms->neigh_setup = bond_neigh_init;
3702 3762
3703 if (slave) {
3704 const struct net_device_ops *slave_ops
3705 = slave->dev->netdev_ops;
3706 if (slave_ops->ndo_neigh_setup)
3707 return slave_ops->ndo_neigh_setup(slave->dev, parms);
3708 }
3709 return 0; 3763 return 0;
3710} 3764}
3711 3765
diff --git a/drivers/net/caif/caif_hsi.c b/drivers/net/caif/caif_hsi.c
index 9a66e2a910ae..9c1c8cd5223f 100644
--- a/drivers/net/caif/caif_hsi.c
+++ b/drivers/net/caif/caif_hsi.c
@@ -744,14 +744,14 @@ static void cfhsi_wake_up(struct work_struct *work)
744 size_t fifo_occupancy = 0; 744 size_t fifo_occupancy = 0;
745 745
746 /* Wakeup timeout */ 746 /* Wakeup timeout */
747 dev_err(&cfhsi->ndev->dev, "%s: Timeout.\n", 747 dev_dbg(&cfhsi->ndev->dev, "%s: Timeout.\n",
748 __func__); 748 __func__);
749 749
750 /* Check FIFO to check if modem has sent something. */ 750 /* Check FIFO to check if modem has sent something. */
751 WARN_ON(cfhsi->dev->cfhsi_fifo_occupancy(cfhsi->dev, 751 WARN_ON(cfhsi->dev->cfhsi_fifo_occupancy(cfhsi->dev,
752 &fifo_occupancy)); 752 &fifo_occupancy));
753 753
754 dev_err(&cfhsi->ndev->dev, "%s: Bytes in FIFO: %u.\n", 754 dev_dbg(&cfhsi->ndev->dev, "%s: Bytes in FIFO: %u.\n",
755 __func__, (unsigned) fifo_occupancy); 755 __func__, (unsigned) fifo_occupancy);
756 756
757 /* Check if we misssed the interrupt. */ 757 /* Check if we misssed the interrupt. */
@@ -1210,7 +1210,7 @@ int cfhsi_probe(struct platform_device *pdev)
1210 1210
1211static void cfhsi_shutdown(struct cfhsi *cfhsi) 1211static void cfhsi_shutdown(struct cfhsi *cfhsi)
1212{ 1212{
1213 u8 *tx_buf, *rx_buf; 1213 u8 *tx_buf, *rx_buf, *flip_buf;
1214 1214
1215 /* Stop TXing */ 1215 /* Stop TXing */
1216 netif_tx_stop_all_queues(cfhsi->ndev); 1216 netif_tx_stop_all_queues(cfhsi->ndev);
@@ -1234,7 +1234,7 @@ static void cfhsi_shutdown(struct cfhsi *cfhsi)
1234 /* Store bufferes: will be freed later. */ 1234 /* Store bufferes: will be freed later. */
1235 tx_buf = cfhsi->tx_buf; 1235 tx_buf = cfhsi->tx_buf;
1236 rx_buf = cfhsi->rx_buf; 1236 rx_buf = cfhsi->rx_buf;
1237 1237 flip_buf = cfhsi->rx_flip_buf;
1238 /* Flush transmit queues. */ 1238 /* Flush transmit queues. */
1239 cfhsi_abort_tx(cfhsi); 1239 cfhsi_abort_tx(cfhsi);
1240 1240
@@ -1247,6 +1247,7 @@ static void cfhsi_shutdown(struct cfhsi *cfhsi)
1247 /* Free buffers. */ 1247 /* Free buffers. */
1248 kfree(tx_buf); 1248 kfree(tx_buf);
1249 kfree(rx_buf); 1249 kfree(rx_buf);
1250 kfree(flip_buf);
1250} 1251}
1251 1252
1252int cfhsi_remove(struct platform_device *pdev) 1253int cfhsi_remove(struct platform_device *pdev)
diff --git a/drivers/net/caif/caif_spi.c b/drivers/net/caif/caif_spi.c
index 96391c36fa74..b71ce9bf0afb 100644
--- a/drivers/net/caif/caif_spi.c
+++ b/drivers/net/caif/caif_spi.c
@@ -127,12 +127,6 @@ static inline void dev_debugfs_rem(struct cfspi *cfspi)
127 debugfs_remove(cfspi->dbgfs_dir); 127 debugfs_remove(cfspi->dbgfs_dir);
128} 128}
129 129
130static int dbgfs_open(struct inode *inode, struct file *file)
131{
132 file->private_data = inode->i_private;
133 return 0;
134}
135
136static ssize_t dbgfs_state(struct file *file, char __user *user_buf, 130static ssize_t dbgfs_state(struct file *file, char __user *user_buf,
137 size_t count, loff_t *ppos) 131 size_t count, loff_t *ppos)
138{ 132{
@@ -243,13 +237,13 @@ static ssize_t dbgfs_frame(struct file *file, char __user *user_buf,
243} 237}
244 238
245static const struct file_operations dbgfs_state_fops = { 239static const struct file_operations dbgfs_state_fops = {
246 .open = dbgfs_open, 240 .open = simple_open,
247 .read = dbgfs_state, 241 .read = dbgfs_state,
248 .owner = THIS_MODULE 242 .owner = THIS_MODULE
249}; 243};
250 244
251static const struct file_operations dbgfs_frame_fops = { 245static const struct file_operations dbgfs_frame_fops = {
252 .open = dbgfs_open, 246 .open = simple_open,
253 .read = dbgfs_frame, 247 .read = dbgfs_frame,
254 .owner = THIS_MODULE 248 .owner = THIS_MODULE
255}; 249};
diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_pro.c b/drivers/net/can/usb/peak_usb/pcan_usb_pro.c
index 5234586dff15..629c4ba5d49d 100644
--- a/drivers/net/can/usb/peak_usb/pcan_usb_pro.c
+++ b/drivers/net/can/usb/peak_usb/pcan_usb_pro.c
@@ -875,6 +875,7 @@ static int pcan_usb_pro_init(struct peak_usb_device *dev)
875 PCAN_USBPRO_INFO_FW, 875 PCAN_USBPRO_INFO_FW,
876 &fi, sizeof(fi)); 876 &fi, sizeof(fi));
877 if (err) { 877 if (err) {
878 kfree(usb_if);
878 dev_err(dev->netdev->dev.parent, 879 dev_err(dev->netdev->dev.parent,
879 "unable to read %s firmware info (err %d)\n", 880 "unable to read %s firmware info (err %d)\n",
880 pcan_usb_pro.name, err); 881 pcan_usb_pro.name, err);
@@ -885,6 +886,7 @@ static int pcan_usb_pro_init(struct peak_usb_device *dev)
885 PCAN_USBPRO_INFO_BL, 886 PCAN_USBPRO_INFO_BL,
886 &bi, sizeof(bi)); 887 &bi, sizeof(bi));
887 if (err) { 888 if (err) {
889 kfree(usb_if);
888 dev_err(dev->netdev->dev.parent, 890 dev_err(dev->netdev->dev.parent,
889 "unable to read %s bootloader info (err %d)\n", 891 "unable to read %s bootloader info (err %d)\n",
890 pcan_usb_pro.name, err); 892 pcan_usb_pro.name, err);
diff --git a/drivers/net/dummy.c b/drivers/net/dummy.c
index d5c6d92f1ee7..442d91a2747b 100644
--- a/drivers/net/dummy.c
+++ b/drivers/net/dummy.c
@@ -107,14 +107,14 @@ static int dummy_dev_init(struct net_device *dev)
107 return 0; 107 return 0;
108} 108}
109 109
110static void dummy_dev_free(struct net_device *dev) 110static void dummy_dev_uninit(struct net_device *dev)
111{ 111{
112 free_percpu(dev->dstats); 112 free_percpu(dev->dstats);
113 free_netdev(dev);
114} 113}
115 114
116static const struct net_device_ops dummy_netdev_ops = { 115static const struct net_device_ops dummy_netdev_ops = {
117 .ndo_init = dummy_dev_init, 116 .ndo_init = dummy_dev_init,
117 .ndo_uninit = dummy_dev_uninit,
118 .ndo_start_xmit = dummy_xmit, 118 .ndo_start_xmit = dummy_xmit,
119 .ndo_validate_addr = eth_validate_addr, 119 .ndo_validate_addr = eth_validate_addr,
120 .ndo_set_rx_mode = set_multicast_list, 120 .ndo_set_rx_mode = set_multicast_list,
@@ -128,7 +128,7 @@ static void dummy_setup(struct net_device *dev)
128 128
129 /* Initialize the device structure. */ 129 /* Initialize the device structure. */
130 dev->netdev_ops = &dummy_netdev_ops; 130 dev->netdev_ops = &dummy_netdev_ops;
131 dev->destructor = dummy_dev_free; 131 dev->destructor = free_netdev;
132 132
133 /* Fill in device structure with ethernet-generic values. */ 133 /* Fill in device structure with ethernet-generic values. */
134 dev->tx_queue_len = 0; 134 dev->tx_queue_len = 0;
diff --git a/drivers/net/eql.c b/drivers/net/eql.c
index a59cf961a436..f219d38acf58 100644
--- a/drivers/net/eql.c
+++ b/drivers/net/eql.c
@@ -125,6 +125,7 @@
125#include <linux/if.h> 125#include <linux/if.h>
126#include <linux/if_arp.h> 126#include <linux/if_arp.h>
127#include <linux/if_eql.h> 127#include <linux/if_eql.h>
128#include <linux/pkt_sched.h>
128 129
129#include <asm/uaccess.h> 130#include <asm/uaccess.h>
130 131
@@ -143,7 +144,7 @@ static void eql_timer(unsigned long param)
143 equalizer_t *eql = (equalizer_t *) param; 144 equalizer_t *eql = (equalizer_t *) param;
144 struct list_head *this, *tmp, *head; 145 struct list_head *this, *tmp, *head;
145 146
146 spin_lock_bh(&eql->queue.lock); 147 spin_lock(&eql->queue.lock);
147 head = &eql->queue.all_slaves; 148 head = &eql->queue.all_slaves;
148 list_for_each_safe(this, tmp, head) { 149 list_for_each_safe(this, tmp, head) {
149 slave_t *slave = list_entry(this, slave_t, list); 150 slave_t *slave = list_entry(this, slave_t, list);
@@ -157,7 +158,7 @@ static void eql_timer(unsigned long param)
157 } 158 }
158 159
159 } 160 }
160 spin_unlock_bh(&eql->queue.lock); 161 spin_unlock(&eql->queue.lock);
161 162
162 eql->timer.expires = jiffies + EQL_DEFAULT_RESCHED_IVAL; 163 eql->timer.expires = jiffies + EQL_DEFAULT_RESCHED_IVAL;
163 add_timer(&eql->timer); 164 add_timer(&eql->timer);
@@ -341,7 +342,7 @@ static netdev_tx_t eql_slave_xmit(struct sk_buff *skb, struct net_device *dev)
341 struct net_device *slave_dev = slave->dev; 342 struct net_device *slave_dev = slave->dev;
342 343
343 skb->dev = slave_dev; 344 skb->dev = slave_dev;
344 skb->priority = 1; 345 skb->priority = TC_PRIO_FILLER;
345 slave->bytes_queued += skb->len; 346 slave->bytes_queued += skb->len;
346 dev_queue_xmit(skb); 347 dev_queue_xmit(skb);
347 dev->stats.tx_packets++; 348 dev->stats.tx_packets++;
diff --git a/drivers/net/ethernet/atheros/atlx/atl1.c b/drivers/net/ethernet/atheros/atlx/atl1.c
index 40ac41436549..c926857e8205 100644
--- a/drivers/net/ethernet/atheros/atlx/atl1.c
+++ b/drivers/net/ethernet/atheros/atlx/atl1.c
@@ -2476,7 +2476,7 @@ static irqreturn_t atl1_intr(int irq, void *data)
2476 "pcie phy link down %x\n", status); 2476 "pcie phy link down %x\n", status);
2477 if (netif_running(adapter->netdev)) { /* reset MAC */ 2477 if (netif_running(adapter->netdev)) { /* reset MAC */
2478 iowrite32(0, adapter->hw.hw_addr + REG_IMR); 2478 iowrite32(0, adapter->hw.hw_addr + REG_IMR);
2479 schedule_work(&adapter->pcie_dma_to_rst_task); 2479 schedule_work(&adapter->reset_dev_task);
2480 return IRQ_HANDLED; 2480 return IRQ_HANDLED;
2481 } 2481 }
2482 } 2482 }
@@ -2488,7 +2488,7 @@ static irqreturn_t atl1_intr(int irq, void *data)
2488 "pcie DMA r/w error (status = 0x%x)\n", 2488 "pcie DMA r/w error (status = 0x%x)\n",
2489 status); 2489 status);
2490 iowrite32(0, adapter->hw.hw_addr + REG_IMR); 2490 iowrite32(0, adapter->hw.hw_addr + REG_IMR);
2491 schedule_work(&adapter->pcie_dma_to_rst_task); 2491 schedule_work(&adapter->reset_dev_task);
2492 return IRQ_HANDLED; 2492 return IRQ_HANDLED;
2493 } 2493 }
2494 2494
@@ -2633,10 +2633,10 @@ static void atl1_down(struct atl1_adapter *adapter)
2633 atl1_clean_rx_ring(adapter); 2633 atl1_clean_rx_ring(adapter);
2634} 2634}
2635 2635
2636static void atl1_tx_timeout_task(struct work_struct *work) 2636static void atl1_reset_dev_task(struct work_struct *work)
2637{ 2637{
2638 struct atl1_adapter *adapter = 2638 struct atl1_adapter *adapter =
2639 container_of(work, struct atl1_adapter, tx_timeout_task); 2639 container_of(work, struct atl1_adapter, reset_dev_task);
2640 struct net_device *netdev = adapter->netdev; 2640 struct net_device *netdev = adapter->netdev;
2641 2641
2642 netif_device_detach(netdev); 2642 netif_device_detach(netdev);
@@ -3038,12 +3038,10 @@ static int __devinit atl1_probe(struct pci_dev *pdev,
3038 (unsigned long)adapter); 3038 (unsigned long)adapter);
3039 adapter->phy_timer_pending = false; 3039 adapter->phy_timer_pending = false;
3040 3040
3041 INIT_WORK(&adapter->tx_timeout_task, atl1_tx_timeout_task); 3041 INIT_WORK(&adapter->reset_dev_task, atl1_reset_dev_task);
3042 3042
3043 INIT_WORK(&adapter->link_chg_task, atlx_link_chg_task); 3043 INIT_WORK(&adapter->link_chg_task, atlx_link_chg_task);
3044 3044
3045 INIT_WORK(&adapter->pcie_dma_to_rst_task, atl1_tx_timeout_task);
3046
3047 err = register_netdev(netdev); 3045 err = register_netdev(netdev);
3048 if (err) 3046 if (err)
3049 goto err_common; 3047 goto err_common;
diff --git a/drivers/net/ethernet/atheros/atlx/atl1.h b/drivers/net/ethernet/atheros/atlx/atl1.h
index 109d6da8be97..e04bf4d71e46 100644
--- a/drivers/net/ethernet/atheros/atlx/atl1.h
+++ b/drivers/net/ethernet/atheros/atlx/atl1.h
@@ -758,9 +758,8 @@ struct atl1_adapter {
758 u16 link_speed; 758 u16 link_speed;
759 u16 link_duplex; 759 u16 link_duplex;
760 spinlock_t lock; 760 spinlock_t lock;
761 struct work_struct tx_timeout_task; 761 struct work_struct reset_dev_task;
762 struct work_struct link_chg_task; 762 struct work_struct link_chg_task;
763 struct work_struct pcie_dma_to_rst_task;
764 763
765 struct timer_list phy_config_timer; 764 struct timer_list phy_config_timer;
766 bool phy_timer_pending; 765 bool phy_timer_pending;
diff --git a/drivers/net/ethernet/atheros/atlx/atlx.c b/drivers/net/ethernet/atheros/atlx/atlx.c
index 3cd8837236dc..c9e9dc57986c 100644
--- a/drivers/net/ethernet/atheros/atlx/atlx.c
+++ b/drivers/net/ethernet/atheros/atlx/atlx.c
@@ -194,7 +194,7 @@ static void atlx_tx_timeout(struct net_device *netdev)
194{ 194{
195 struct atlx_adapter *adapter = netdev_priv(netdev); 195 struct atlx_adapter *adapter = netdev_priv(netdev);
196 /* Do the reset outside of interrupt context */ 196 /* Do the reset outside of interrupt context */
197 schedule_work(&adapter->tx_timeout_task); 197 schedule_work(&adapter->reset_dev_task);
198} 198}
199 199
200/* 200/*
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x.h
index e37161f19250..2c9ee552dffc 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x.h
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x.h
@@ -1173,6 +1173,13 @@ enum {
1173}; 1173};
1174 1174
1175 1175
1176struct bnx2x_prev_path_list {
1177 u8 bus;
1178 u8 slot;
1179 u8 path;
1180 struct list_head list;
1181};
1182
1176struct bnx2x { 1183struct bnx2x {
1177 /* Fields used in the tx and intr/napi performance paths 1184 /* Fields used in the tx and intr/napi performance paths
1178 * are grouped together in the beginning of the structure 1185 * are grouped together in the beginning of the structure
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
index f1f3ca65667a..4b054812713a 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
@@ -1721,6 +1721,29 @@ static void bnx2x_squeeze_objects(struct bnx2x *bp)
1721 } while (0) 1721 } while (0)
1722#endif 1722#endif
1723 1723
1724bool bnx2x_test_firmware_version(struct bnx2x *bp, bool is_err)
1725{
1726 /* build FW version dword */
1727 u32 my_fw = (BCM_5710_FW_MAJOR_VERSION) +
1728 (BCM_5710_FW_MINOR_VERSION << 8) +
1729 (BCM_5710_FW_REVISION_VERSION << 16) +
1730 (BCM_5710_FW_ENGINEERING_VERSION << 24);
1731
1732 /* read loaded FW from chip */
1733 u32 loaded_fw = REG_RD(bp, XSEM_REG_PRAM);
1734
1735 DP(NETIF_MSG_IFUP, "loaded fw %x, my fw %x\n", loaded_fw, my_fw);
1736
1737 if (loaded_fw != my_fw) {
1738 if (is_err)
1739 BNX2X_ERR("bnx2x with FW %x was already loaded, which mismatches my %x FW. aborting\n",
1740 loaded_fw, my_fw);
1741 return false;
1742 }
1743
1744 return true;
1745}
1746
1724/* must be called with rtnl_lock */ 1747/* must be called with rtnl_lock */
1725int bnx2x_nic_load(struct bnx2x *bp, int load_mode) 1748int bnx2x_nic_load(struct bnx2x *bp, int load_mode)
1726{ 1749{
@@ -1815,23 +1838,8 @@ int bnx2x_nic_load(struct bnx2x *bp, int load_mode)
1815 } 1838 }
1816 if (load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP && 1839 if (load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP &&
1817 load_code != FW_MSG_CODE_DRV_LOAD_COMMON) { 1840 load_code != FW_MSG_CODE_DRV_LOAD_COMMON) {
1818 /* build FW version dword */
1819 u32 my_fw = (BCM_5710_FW_MAJOR_VERSION) +
1820 (BCM_5710_FW_MINOR_VERSION << 8) +
1821 (BCM_5710_FW_REVISION_VERSION << 16) +
1822 (BCM_5710_FW_ENGINEERING_VERSION << 24);
1823
1824 /* read loaded FW from chip */
1825 u32 loaded_fw = REG_RD(bp, XSEM_REG_PRAM);
1826
1827 DP(BNX2X_MSG_SP, "loaded fw %x, my fw %x",
1828 loaded_fw, my_fw);
1829
1830 /* abort nic load if version mismatch */ 1841 /* abort nic load if version mismatch */
1831 if (my_fw != loaded_fw) { 1842 if (!bnx2x_test_firmware_version(bp, true)) {
1832 BNX2X_ERR("bnx2x with FW %x already loaded, "
1833 "which mismatches my %x FW. aborting",
1834 loaded_fw, my_fw);
1835 rc = -EBUSY; 1843 rc = -EBUSY;
1836 LOAD_ERROR_EXIT(bp, load_error2); 1844 LOAD_ERROR_EXIT(bp, load_error2);
1837 } 1845 }
@@ -1866,7 +1874,6 @@ int bnx2x_nic_load(struct bnx2x *bp, int load_mode)
1866 * bnx2x_periodic_task(). 1874 * bnx2x_periodic_task().
1867 */ 1875 */
1868 smp_mb(); 1876 smp_mb();
1869 queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
1870 } else 1877 } else
1871 bp->port.pmf = 0; 1878 bp->port.pmf = 0;
1872 1879
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
index 8b163388659a..5c27454d2ec2 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
@@ -431,6 +431,9 @@ void bnx2x_panic_dump(struct bnx2x *bp);
431 431
432void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl); 432void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl);
433 433
434/* validate currect fw is loaded */
435bool bnx2x_test_firmware_version(struct bnx2x *bp, bool is_err);
436
434/* dev_close main block */ 437/* dev_close main block */
435int bnx2x_nic_unload(struct bnx2x *bp, int unload_mode); 438int bnx2x_nic_unload(struct bnx2x *bp, int unload_mode);
436 439
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_fw_defs.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_fw_defs.h
index cd6dfa9eaa3a..b9b263323436 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_fw_defs.h
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_fw_defs.h
@@ -25,31 +25,31 @@
25 (IRO[149].base + ((funcId) * IRO[149].m1)) 25 (IRO[149].base + ((funcId) * IRO[149].m1))
26#define CSTORM_IGU_MODE_OFFSET (IRO[157].base) 26#define CSTORM_IGU_MODE_OFFSET (IRO[157].base)
27#define CSTORM_ISCSI_CQ_SIZE_OFFSET(pfId) \ 27#define CSTORM_ISCSI_CQ_SIZE_OFFSET(pfId) \
28 (IRO[315].base + ((pfId) * IRO[315].m1))
29#define CSTORM_ISCSI_CQ_SQN_SIZE_OFFSET(pfId) \
30 (IRO[316].base + ((pfId) * IRO[316].m1)) 28 (IRO[316].base + ((pfId) * IRO[316].m1))
29#define CSTORM_ISCSI_CQ_SQN_SIZE_OFFSET(pfId) \
30 (IRO[317].base + ((pfId) * IRO[317].m1))
31#define CSTORM_ISCSI_EQ_CONS_OFFSET(pfId, iscsiEqId) \ 31#define CSTORM_ISCSI_EQ_CONS_OFFSET(pfId, iscsiEqId) \
32 (IRO[308].base + ((pfId) * IRO[308].m1) + ((iscsiEqId) * IRO[308].m2)) 32 (IRO[309].base + ((pfId) * IRO[309].m1) + ((iscsiEqId) * IRO[309].m2))
33#define CSTORM_ISCSI_EQ_NEXT_EQE_ADDR_OFFSET(pfId, iscsiEqId) \ 33#define CSTORM_ISCSI_EQ_NEXT_EQE_ADDR_OFFSET(pfId, iscsiEqId) \
34 (IRO[310].base + ((pfId) * IRO[310].m1) + ((iscsiEqId) * IRO[310].m2)) 34 (IRO[311].base + ((pfId) * IRO[311].m1) + ((iscsiEqId) * IRO[311].m2))
35#define CSTORM_ISCSI_EQ_NEXT_PAGE_ADDR_OFFSET(pfId, iscsiEqId) \ 35#define CSTORM_ISCSI_EQ_NEXT_PAGE_ADDR_OFFSET(pfId, iscsiEqId) \
36 (IRO[309].base + ((pfId) * IRO[309].m1) + ((iscsiEqId) * IRO[309].m2)) 36 (IRO[310].base + ((pfId) * IRO[310].m1) + ((iscsiEqId) * IRO[310].m2))
37#define CSTORM_ISCSI_EQ_NEXT_PAGE_ADDR_VALID_OFFSET(pfId, iscsiEqId) \ 37#define CSTORM_ISCSI_EQ_NEXT_PAGE_ADDR_VALID_OFFSET(pfId, iscsiEqId) \
38 (IRO[311].base + ((pfId) * IRO[311].m1) + ((iscsiEqId) * IRO[311].m2)) 38 (IRO[312].base + ((pfId) * IRO[312].m1) + ((iscsiEqId) * IRO[312].m2))
39#define CSTORM_ISCSI_EQ_PROD_OFFSET(pfId, iscsiEqId) \ 39#define CSTORM_ISCSI_EQ_PROD_OFFSET(pfId, iscsiEqId) \
40 (IRO[307].base + ((pfId) * IRO[307].m1) + ((iscsiEqId) * IRO[307].m2)) 40 (IRO[308].base + ((pfId) * IRO[308].m1) + ((iscsiEqId) * IRO[308].m2))
41#define CSTORM_ISCSI_EQ_SB_INDEX_OFFSET(pfId, iscsiEqId) \ 41#define CSTORM_ISCSI_EQ_SB_INDEX_OFFSET(pfId, iscsiEqId) \
42 (IRO[313].base + ((pfId) * IRO[313].m1) + ((iscsiEqId) * IRO[313].m2)) 42 (IRO[314].base + ((pfId) * IRO[314].m1) + ((iscsiEqId) * IRO[314].m2))
43#define CSTORM_ISCSI_EQ_SB_NUM_OFFSET(pfId, iscsiEqId) \ 43#define CSTORM_ISCSI_EQ_SB_NUM_OFFSET(pfId, iscsiEqId) \
44 (IRO[312].base + ((pfId) * IRO[312].m1) + ((iscsiEqId) * IRO[312].m2)) 44 (IRO[313].base + ((pfId) * IRO[313].m1) + ((iscsiEqId) * IRO[313].m2))
45#define CSTORM_ISCSI_HQ_SIZE_OFFSET(pfId) \ 45#define CSTORM_ISCSI_HQ_SIZE_OFFSET(pfId) \
46 (IRO[314].base + ((pfId) * IRO[314].m1)) 46 (IRO[315].base + ((pfId) * IRO[315].m1))
47#define CSTORM_ISCSI_NUM_OF_TASKS_OFFSET(pfId) \ 47#define CSTORM_ISCSI_NUM_OF_TASKS_OFFSET(pfId) \
48 (IRO[306].base + ((pfId) * IRO[306].m1)) 48 (IRO[307].base + ((pfId) * IRO[307].m1))
49#define CSTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(pfId) \ 49#define CSTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(pfId) \
50 (IRO[305].base + ((pfId) * IRO[305].m1)) 50 (IRO[306].base + ((pfId) * IRO[306].m1))
51#define CSTORM_ISCSI_PAGE_SIZE_OFFSET(pfId) \ 51#define CSTORM_ISCSI_PAGE_SIZE_OFFSET(pfId) \
52 (IRO[304].base + ((pfId) * IRO[304].m1)) 52 (IRO[305].base + ((pfId) * IRO[305].m1))
53#define CSTORM_RECORD_SLOW_PATH_OFFSET(funcId) \ 53#define CSTORM_RECORD_SLOW_PATH_OFFSET(funcId) \
54 (IRO[151].base + ((funcId) * IRO[151].m1)) 54 (IRO[151].base + ((funcId) * IRO[151].m1))
55#define CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(pfId) \ 55#define CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(pfId) \
@@ -96,37 +96,37 @@
96#define TSTORM_FUNC_EN_OFFSET(funcId) \ 96#define TSTORM_FUNC_EN_OFFSET(funcId) \
97 (IRO[103].base + ((funcId) * IRO[103].m1)) 97 (IRO[103].base + ((funcId) * IRO[103].m1))
98#define TSTORM_ISCSI_ERROR_BITMAP_OFFSET(pfId) \ 98#define TSTORM_ISCSI_ERROR_BITMAP_OFFSET(pfId) \
99 (IRO[271].base + ((pfId) * IRO[271].m1))
100#define TSTORM_ISCSI_L2_ISCSI_OOO_CID_TABLE_OFFSET(pfId) \
101 (IRO[272].base + ((pfId) * IRO[272].m1)) 99 (IRO[272].base + ((pfId) * IRO[272].m1))
102#define TSTORM_ISCSI_L2_ISCSI_OOO_CLIENT_ID_TABLE_OFFSET(pfId) \ 100#define TSTORM_ISCSI_L2_ISCSI_OOO_CID_TABLE_OFFSET(pfId) \
103 (IRO[273].base + ((pfId) * IRO[273].m1)) 101 (IRO[273].base + ((pfId) * IRO[273].m1))
104#define TSTORM_ISCSI_L2_ISCSI_OOO_PROD_OFFSET(pfId) \ 102#define TSTORM_ISCSI_L2_ISCSI_OOO_CLIENT_ID_TABLE_OFFSET(pfId) \
105 (IRO[274].base + ((pfId) * IRO[274].m1)) 103 (IRO[274].base + ((pfId) * IRO[274].m1))
104#define TSTORM_ISCSI_L2_ISCSI_OOO_PROD_OFFSET(pfId) \
105 (IRO[275].base + ((pfId) * IRO[275].m1))
106#define TSTORM_ISCSI_NUM_OF_TASKS_OFFSET(pfId) \ 106#define TSTORM_ISCSI_NUM_OF_TASKS_OFFSET(pfId) \
107 (IRO[270].base + ((pfId) * IRO[270].m1)) 107 (IRO[271].base + ((pfId) * IRO[271].m1))
108#define TSTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(pfId) \ 108#define TSTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(pfId) \
109 (IRO[269].base + ((pfId) * IRO[269].m1)) 109 (IRO[270].base + ((pfId) * IRO[270].m1))
110#define TSTORM_ISCSI_PAGE_SIZE_OFFSET(pfId) \ 110#define TSTORM_ISCSI_PAGE_SIZE_OFFSET(pfId) \
111 (IRO[268].base + ((pfId) * IRO[268].m1)) 111 (IRO[269].base + ((pfId) * IRO[269].m1))
112#define TSTORM_ISCSI_RQ_SIZE_OFFSET(pfId) \ 112#define TSTORM_ISCSI_RQ_SIZE_OFFSET(pfId) \
113 (IRO[267].base + ((pfId) * IRO[267].m1)) 113 (IRO[268].base + ((pfId) * IRO[268].m1))
114#define TSTORM_ISCSI_TCP_LOCAL_ADV_WND_OFFSET(pfId) \ 114#define TSTORM_ISCSI_TCP_LOCAL_ADV_WND_OFFSET(pfId) \
115 (IRO[276].base + ((pfId) * IRO[276].m1)) 115 (IRO[277].base + ((pfId) * IRO[277].m1))
116#define TSTORM_ISCSI_TCP_VARS_FLAGS_OFFSET(pfId) \ 116#define TSTORM_ISCSI_TCP_VARS_FLAGS_OFFSET(pfId) \
117 (IRO[263].base + ((pfId) * IRO[263].m1))
118#define TSTORM_ISCSI_TCP_VARS_LSB_LOCAL_MAC_ADDR_OFFSET(pfId) \
119 (IRO[264].base + ((pfId) * IRO[264].m1)) 117 (IRO[264].base + ((pfId) * IRO[264].m1))
120#define TSTORM_ISCSI_TCP_VARS_MID_LOCAL_MAC_ADDR_OFFSET(pfId) \ 118#define TSTORM_ISCSI_TCP_VARS_LSB_LOCAL_MAC_ADDR_OFFSET(pfId) \
121 (IRO[265].base + ((pfId) * IRO[265].m1)) 119 (IRO[265].base + ((pfId) * IRO[265].m1))
122#define TSTORM_ISCSI_TCP_VARS_MSB_LOCAL_MAC_ADDR_OFFSET(pfId) \ 120#define TSTORM_ISCSI_TCP_VARS_MID_LOCAL_MAC_ADDR_OFFSET(pfId) \
123 (IRO[266].base + ((pfId) * IRO[266].m1)) 121 (IRO[266].base + ((pfId) * IRO[266].m1))
122#define TSTORM_ISCSI_TCP_VARS_MSB_LOCAL_MAC_ADDR_OFFSET(pfId) \
123 (IRO[267].base + ((pfId) * IRO[267].m1))
124#define TSTORM_MAC_FILTER_CONFIG_OFFSET(pfId) \ 124#define TSTORM_MAC_FILTER_CONFIG_OFFSET(pfId) \
125 (IRO[202].base + ((pfId) * IRO[202].m1)) 125 (IRO[202].base + ((pfId) * IRO[202].m1))
126#define TSTORM_RECORD_SLOW_PATH_OFFSET(funcId) \ 126#define TSTORM_RECORD_SLOW_PATH_OFFSET(funcId) \
127 (IRO[105].base + ((funcId) * IRO[105].m1)) 127 (IRO[105].base + ((funcId) * IRO[105].m1))
128#define TSTORM_TCP_MAX_CWND_OFFSET(pfId) \ 128#define TSTORM_TCP_MAX_CWND_OFFSET(pfId) \
129 (IRO[216].base + ((pfId) * IRO[216].m1)) 129 (IRO[217].base + ((pfId) * IRO[217].m1))
130#define TSTORM_VF_TO_PF_OFFSET(funcId) \ 130#define TSTORM_VF_TO_PF_OFFSET(funcId) \
131 (IRO[104].base + ((funcId) * IRO[104].m1)) 131 (IRO[104].base + ((funcId) * IRO[104].m1))
132#define USTORM_AGG_DATA_OFFSET (IRO[206].base) 132#define USTORM_AGG_DATA_OFFSET (IRO[206].base)
@@ -140,29 +140,29 @@
140#define USTORM_ETH_PAUSE_ENABLED_OFFSET(portId) \ 140#define USTORM_ETH_PAUSE_ENABLED_OFFSET(portId) \
141 (IRO[183].base + ((portId) * IRO[183].m1)) 141 (IRO[183].base + ((portId) * IRO[183].m1))
142#define USTORM_FCOE_EQ_PROD_OFFSET(pfId) \ 142#define USTORM_FCOE_EQ_PROD_OFFSET(pfId) \
143 (IRO[317].base + ((pfId) * IRO[317].m1)) 143 (IRO[318].base + ((pfId) * IRO[318].m1))
144#define USTORM_FUNC_EN_OFFSET(funcId) \ 144#define USTORM_FUNC_EN_OFFSET(funcId) \
145 (IRO[178].base + ((funcId) * IRO[178].m1)) 145 (IRO[178].base + ((funcId) * IRO[178].m1))
146#define USTORM_ISCSI_CQ_SIZE_OFFSET(pfId) \ 146#define USTORM_ISCSI_CQ_SIZE_OFFSET(pfId) \
147 (IRO[281].base + ((pfId) * IRO[281].m1))
148#define USTORM_ISCSI_CQ_SQN_SIZE_OFFSET(pfId) \
149 (IRO[282].base + ((pfId) * IRO[282].m1)) 147 (IRO[282].base + ((pfId) * IRO[282].m1))
148#define USTORM_ISCSI_CQ_SQN_SIZE_OFFSET(pfId) \
149 (IRO[283].base + ((pfId) * IRO[283].m1))
150#define USTORM_ISCSI_ERROR_BITMAP_OFFSET(pfId) \ 150#define USTORM_ISCSI_ERROR_BITMAP_OFFSET(pfId) \
151 (IRO[286].base + ((pfId) * IRO[286].m1)) 151 (IRO[287].base + ((pfId) * IRO[287].m1))
152#define USTORM_ISCSI_GLOBAL_BUF_PHYS_ADDR_OFFSET(pfId) \ 152#define USTORM_ISCSI_GLOBAL_BUF_PHYS_ADDR_OFFSET(pfId) \
153 (IRO[283].base + ((pfId) * IRO[283].m1)) 153 (IRO[284].base + ((pfId) * IRO[284].m1))
154#define USTORM_ISCSI_NUM_OF_TASKS_OFFSET(pfId) \ 154#define USTORM_ISCSI_NUM_OF_TASKS_OFFSET(pfId) \
155 (IRO[279].base + ((pfId) * IRO[279].m1)) 155 (IRO[280].base + ((pfId) * IRO[280].m1))
156#define USTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(pfId) \ 156#define USTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(pfId) \
157 (IRO[278].base + ((pfId) * IRO[278].m1)) 157 (IRO[279].base + ((pfId) * IRO[279].m1))
158#define USTORM_ISCSI_PAGE_SIZE_OFFSET(pfId) \ 158#define USTORM_ISCSI_PAGE_SIZE_OFFSET(pfId) \
159 (IRO[277].base + ((pfId) * IRO[277].m1)) 159 (IRO[278].base + ((pfId) * IRO[278].m1))
160#define USTORM_ISCSI_R2TQ_SIZE_OFFSET(pfId) \ 160#define USTORM_ISCSI_R2TQ_SIZE_OFFSET(pfId) \
161 (IRO[280].base + ((pfId) * IRO[280].m1)) 161 (IRO[281].base + ((pfId) * IRO[281].m1))
162#define USTORM_ISCSI_RQ_BUFFER_SIZE_OFFSET(pfId) \ 162#define USTORM_ISCSI_RQ_BUFFER_SIZE_OFFSET(pfId) \
163 (IRO[284].base + ((pfId) * IRO[284].m1))
164#define USTORM_ISCSI_RQ_SIZE_OFFSET(pfId) \
165 (IRO[285].base + ((pfId) * IRO[285].m1)) 163 (IRO[285].base + ((pfId) * IRO[285].m1))
164#define USTORM_ISCSI_RQ_SIZE_OFFSET(pfId) \
165 (IRO[286].base + ((pfId) * IRO[286].m1))
166#define USTORM_MEM_WORKAROUND_ADDRESS_OFFSET(pfId) \ 166#define USTORM_MEM_WORKAROUND_ADDRESS_OFFSET(pfId) \
167 (IRO[182].base + ((pfId) * IRO[182].m1)) 167 (IRO[182].base + ((pfId) * IRO[182].m1))
168#define USTORM_RECORD_SLOW_PATH_OFFSET(funcId) \ 168#define USTORM_RECORD_SLOW_PATH_OFFSET(funcId) \
@@ -188,39 +188,39 @@
188#define XSTORM_FUNC_EN_OFFSET(funcId) \ 188#define XSTORM_FUNC_EN_OFFSET(funcId) \
189 (IRO[47].base + ((funcId) * IRO[47].m1)) 189 (IRO[47].base + ((funcId) * IRO[47].m1))
190#define XSTORM_ISCSI_HQ_SIZE_OFFSET(pfId) \ 190#define XSTORM_ISCSI_HQ_SIZE_OFFSET(pfId) \
191 (IRO[294].base + ((pfId) * IRO[294].m1)) 191 (IRO[295].base + ((pfId) * IRO[295].m1))
192#define XSTORM_ISCSI_LOCAL_MAC_ADDR0_OFFSET(pfId) \ 192#define XSTORM_ISCSI_LOCAL_MAC_ADDR0_OFFSET(pfId) \
193 (IRO[297].base + ((pfId) * IRO[297].m1))
194#define XSTORM_ISCSI_LOCAL_MAC_ADDR1_OFFSET(pfId) \
195 (IRO[298].base + ((pfId) * IRO[298].m1)) 193 (IRO[298].base + ((pfId) * IRO[298].m1))
196#define XSTORM_ISCSI_LOCAL_MAC_ADDR2_OFFSET(pfId) \ 194#define XSTORM_ISCSI_LOCAL_MAC_ADDR1_OFFSET(pfId) \
197 (IRO[299].base + ((pfId) * IRO[299].m1)) 195 (IRO[299].base + ((pfId) * IRO[299].m1))
198#define XSTORM_ISCSI_LOCAL_MAC_ADDR3_OFFSET(pfId) \ 196#define XSTORM_ISCSI_LOCAL_MAC_ADDR2_OFFSET(pfId) \
199 (IRO[300].base + ((pfId) * IRO[300].m1)) 197 (IRO[300].base + ((pfId) * IRO[300].m1))
200#define XSTORM_ISCSI_LOCAL_MAC_ADDR4_OFFSET(pfId) \ 198#define XSTORM_ISCSI_LOCAL_MAC_ADDR3_OFFSET(pfId) \
201 (IRO[301].base + ((pfId) * IRO[301].m1)) 199 (IRO[301].base + ((pfId) * IRO[301].m1))
202#define XSTORM_ISCSI_LOCAL_MAC_ADDR5_OFFSET(pfId) \ 200#define XSTORM_ISCSI_LOCAL_MAC_ADDR4_OFFSET(pfId) \
203 (IRO[302].base + ((pfId) * IRO[302].m1)) 201 (IRO[302].base + ((pfId) * IRO[302].m1))
204#define XSTORM_ISCSI_LOCAL_VLAN_OFFSET(pfId) \ 202#define XSTORM_ISCSI_LOCAL_MAC_ADDR5_OFFSET(pfId) \
205 (IRO[303].base + ((pfId) * IRO[303].m1)) 203 (IRO[303].base + ((pfId) * IRO[303].m1))
204#define XSTORM_ISCSI_LOCAL_VLAN_OFFSET(pfId) \
205 (IRO[304].base + ((pfId) * IRO[304].m1))
206#define XSTORM_ISCSI_NUM_OF_TASKS_OFFSET(pfId) \ 206#define XSTORM_ISCSI_NUM_OF_TASKS_OFFSET(pfId) \
207 (IRO[293].base + ((pfId) * IRO[293].m1)) 207 (IRO[294].base + ((pfId) * IRO[294].m1))
208#define XSTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(pfId) \ 208#define XSTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(pfId) \
209 (IRO[292].base + ((pfId) * IRO[292].m1)) 209 (IRO[293].base + ((pfId) * IRO[293].m1))
210#define XSTORM_ISCSI_PAGE_SIZE_OFFSET(pfId) \ 210#define XSTORM_ISCSI_PAGE_SIZE_OFFSET(pfId) \
211 (IRO[291].base + ((pfId) * IRO[291].m1)) 211 (IRO[292].base + ((pfId) * IRO[292].m1))
212#define XSTORM_ISCSI_R2TQ_SIZE_OFFSET(pfId) \ 212#define XSTORM_ISCSI_R2TQ_SIZE_OFFSET(pfId) \
213 (IRO[296].base + ((pfId) * IRO[296].m1)) 213 (IRO[297].base + ((pfId) * IRO[297].m1))
214#define XSTORM_ISCSI_SQ_SIZE_OFFSET(pfId) \ 214#define XSTORM_ISCSI_SQ_SIZE_OFFSET(pfId) \
215 (IRO[295].base + ((pfId) * IRO[295].m1)) 215 (IRO[296].base + ((pfId) * IRO[296].m1))
216#define XSTORM_ISCSI_TCP_VARS_ADV_WND_SCL_OFFSET(pfId) \ 216#define XSTORM_ISCSI_TCP_VARS_ADV_WND_SCL_OFFSET(pfId) \
217 (IRO[290].base + ((pfId) * IRO[290].m1)) 217 (IRO[291].base + ((pfId) * IRO[291].m1))
218#define XSTORM_ISCSI_TCP_VARS_FLAGS_OFFSET(pfId) \ 218#define XSTORM_ISCSI_TCP_VARS_FLAGS_OFFSET(pfId) \
219 (IRO[289].base + ((pfId) * IRO[289].m1)) 219 (IRO[290].base + ((pfId) * IRO[290].m1))
220#define XSTORM_ISCSI_TCP_VARS_TOS_OFFSET(pfId) \ 220#define XSTORM_ISCSI_TCP_VARS_TOS_OFFSET(pfId) \
221 (IRO[288].base + ((pfId) * IRO[288].m1)) 221 (IRO[289].base + ((pfId) * IRO[289].m1))
222#define XSTORM_ISCSI_TCP_VARS_TTL_OFFSET(pfId) \ 222#define XSTORM_ISCSI_TCP_VARS_TTL_OFFSET(pfId) \
223 (IRO[287].base + ((pfId) * IRO[287].m1)) 223 (IRO[288].base + ((pfId) * IRO[288].m1))
224#define XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(pfId) \ 224#define XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(pfId) \
225 (IRO[44].base + ((pfId) * IRO[44].m1)) 225 (IRO[44].base + ((pfId) * IRO[44].m1))
226#define XSTORM_RECORD_SLOW_PATH_OFFSET(funcId) \ 226#define XSTORM_RECORD_SLOW_PATH_OFFSET(funcId) \
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_hsi.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_hsi.h
index 5d71b7d43237..dbff5915b81a 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_hsi.h
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_hsi.h
@@ -1251,6 +1251,9 @@ struct drv_func_mb {
1251 1251
1252 #define DRV_MSG_CODE_LINK_STATUS_CHANGED 0x01000000 1252 #define DRV_MSG_CODE_LINK_STATUS_CHANGED 0x01000000
1253 1253
1254 #define DRV_MSG_CODE_INITIATE_FLR 0x02000000
1255 #define REQ_BC_VER_4_INITIATE_FLR 0x00070213
1256
1254 #define BIOS_MSG_CODE_LIC_CHALLENGE 0xff010000 1257 #define BIOS_MSG_CODE_LIC_CHALLENGE 0xff010000
1255 #define BIOS_MSG_CODE_LIC_RESPONSE 0xff020000 1258 #define BIOS_MSG_CODE_LIC_RESPONSE 0xff020000
1256 #define BIOS_MSG_CODE_VIRT_MAC_PRIM 0xff030000 1259 #define BIOS_MSG_CODE_VIRT_MAC_PRIM 0xff030000
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_link.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_link.c
index beb4cdbdb6e1..64392ec410a3 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_link.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_link.c
@@ -35,7 +35,6 @@
35#define ETH_MAX_PACKET_SIZE 1500 35#define ETH_MAX_PACKET_SIZE 1500
36#define ETH_MAX_JUMBO_PACKET_SIZE 9600 36#define ETH_MAX_JUMBO_PACKET_SIZE 9600
37#define MDIO_ACCESS_TIMEOUT 1000 37#define MDIO_ACCESS_TIMEOUT 1000
38#define BMAC_CONTROL_RX_ENABLE 2
39#define WC_LANE_MAX 4 38#define WC_LANE_MAX 4
40#define I2C_SWITCH_WIDTH 2 39#define I2C_SWITCH_WIDTH 2
41#define I2C_BSC0 0 40#define I2C_BSC0 0
@@ -943,6 +942,12 @@ static int bnx2x_ets_e3b0_sp_pri_to_cos_set(const struct link_params *params,
943 const u8 max_num_of_cos = (port) ? DCBX_E3B0_MAX_NUM_COS_PORT1 : 942 const u8 max_num_of_cos = (port) ? DCBX_E3B0_MAX_NUM_COS_PORT1 :
944 DCBX_E3B0_MAX_NUM_COS_PORT0; 943 DCBX_E3B0_MAX_NUM_COS_PORT0;
945 944
945 if (pri >= max_num_of_cos) {
946 DP(NETIF_MSG_LINK, "bnx2x_ets_e3b0_sp_pri_to_cos_set invalid "
947 "parameter Illegal strict priority\n");
948 return -EINVAL;
949 }
950
946 if (sp_pri_to_cos[pri] != DCBX_INVALID_COS) { 951 if (sp_pri_to_cos[pri] != DCBX_INVALID_COS) {
947 DP(NETIF_MSG_LINK, "bnx2x_ets_e3b0_sp_pri_to_cos_set invalid " 952 DP(NETIF_MSG_LINK, "bnx2x_ets_e3b0_sp_pri_to_cos_set invalid "
948 "parameter There can't be two COS's with " 953 "parameter There can't be two COS's with "
@@ -950,12 +955,6 @@ static int bnx2x_ets_e3b0_sp_pri_to_cos_set(const struct link_params *params,
950 return -EINVAL; 955 return -EINVAL;
951 } 956 }
952 957
953 if (pri > max_num_of_cos) {
954 DP(NETIF_MSG_LINK, "bnx2x_ets_e3b0_sp_pri_to_cos_set invalid "
955 "parameter Illegal strict priority\n");
956 return -EINVAL;
957 }
958
959 sp_pri_to_cos[pri] = cos_entry; 958 sp_pri_to_cos[pri] = cos_entry;
960 return 0; 959 return 0;
961 960
@@ -1372,7 +1371,14 @@ static void bnx2x_update_pfc_xmac(struct link_params *params,
1372 pfc1_val |= XMAC_PFC_CTRL_HI_REG_PFC_REFRESH_EN | 1371 pfc1_val |= XMAC_PFC_CTRL_HI_REG_PFC_REFRESH_EN |
1373 XMAC_PFC_CTRL_HI_REG_PFC_STATS_EN | 1372 XMAC_PFC_CTRL_HI_REG_PFC_STATS_EN |
1374 XMAC_PFC_CTRL_HI_REG_RX_PFC_EN | 1373 XMAC_PFC_CTRL_HI_REG_RX_PFC_EN |
1375 XMAC_PFC_CTRL_HI_REG_TX_PFC_EN; 1374 XMAC_PFC_CTRL_HI_REG_TX_PFC_EN |
1375 XMAC_PFC_CTRL_HI_REG_FORCE_PFC_XON;
1376 /* Write pause and PFC registers */
1377 REG_WR(bp, xmac_base + XMAC_REG_PAUSE_CTRL, pause_val);
1378 REG_WR(bp, xmac_base + XMAC_REG_PFC_CTRL, pfc0_val);
1379 REG_WR(bp, xmac_base + XMAC_REG_PFC_CTRL_HI, pfc1_val);
1380 pfc1_val &= ~XMAC_PFC_CTRL_HI_REG_FORCE_PFC_XON;
1381
1376 } 1382 }
1377 1383
1378 /* Write pause and PFC registers */ 1384 /* Write pause and PFC registers */
@@ -3649,6 +3655,33 @@ static void bnx2x_ext_phy_update_adv_fc(struct bnx2x_phy *phy,
3649 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE) { 3655 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE) {
3650 bnx2x_cl22_read(bp, phy, 0x4, &ld_pause); 3656 bnx2x_cl22_read(bp, phy, 0x4, &ld_pause);
3651 bnx2x_cl22_read(bp, phy, 0x5, &lp_pause); 3657 bnx2x_cl22_read(bp, phy, 0x5, &lp_pause);
3658 } else if (CHIP_IS_E3(bp) &&
3659 SINGLE_MEDIA_DIRECT(params)) {
3660 u8 lane = bnx2x_get_warpcore_lane(phy, params);
3661 u16 gp_status, gp_mask;
3662 bnx2x_cl45_read(bp, phy,
3663 MDIO_AN_DEVAD, MDIO_WC_REG_GP2_STATUS_GP_2_4,
3664 &gp_status);
3665 gp_mask = (MDIO_WC_REG_GP2_STATUS_GP_2_4_CL73_AN_CMPL |
3666 MDIO_WC_REG_GP2_STATUS_GP_2_4_CL37_LP_AN_CAP) <<
3667 lane;
3668 if ((gp_status & gp_mask) == gp_mask) {
3669 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
3670 MDIO_AN_REG_ADV_PAUSE, &ld_pause);
3671 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
3672 MDIO_AN_REG_LP_AUTO_NEG, &lp_pause);
3673 } else {
3674 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
3675 MDIO_AN_REG_CL37_FC_LD, &ld_pause);
3676 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
3677 MDIO_AN_REG_CL37_FC_LP, &lp_pause);
3678 ld_pause = ((ld_pause &
3679 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH)
3680 << 3);
3681 lp_pause = ((lp_pause &
3682 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH)
3683 << 3);
3684 }
3652 } else { 3685 } else {
3653 bnx2x_cl45_read(bp, phy, 3686 bnx2x_cl45_read(bp, phy,
3654 MDIO_AN_DEVAD, 3687 MDIO_AN_DEVAD,
@@ -3699,7 +3732,23 @@ static void bnx2x_warpcore_enable_AN_KR(struct bnx2x_phy *phy,
3699 u16 val16 = 0, lane, bam37 = 0; 3732 u16 val16 = 0, lane, bam37 = 0;
3700 struct bnx2x *bp = params->bp; 3733 struct bnx2x *bp = params->bp;
3701 DP(NETIF_MSG_LINK, "Enable Auto Negotiation for KR\n"); 3734 DP(NETIF_MSG_LINK, "Enable Auto Negotiation for KR\n");
3702 3735 /* Set to default registers that may be overriden by 10G force */
3736 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3737 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2, 0x7);
3738 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
3739 MDIO_WC_REG_PAR_DET_10G_CTRL, 0);
3740 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3741 MDIO_WC_REG_CL72_USERB0_CL72_MISC1_CONTROL, 0);
3742 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3743 MDIO_WC_REG_XGXSBLK1_LANECTRL0, 0xff);
3744 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3745 MDIO_WC_REG_XGXSBLK1_LANECTRL1, 0x5555);
3746 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD,
3747 MDIO_WC_REG_IEEE0BLK_AUTONEGNP, 0x0);
3748 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3749 MDIO_WC_REG_RX66_CONTROL, 0x7415);
3750 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3751 MDIO_WC_REG_SERDESDIGITAL_MISC2, 0x6190);
3703 /* Disable Autoneg: re-enable it after adv is done. */ 3752 /* Disable Autoneg: re-enable it after adv is done. */
3704 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, 3753 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
3705 MDIO_WC_REG_IEEE0BLK_MIICNTL, 0); 3754 MDIO_WC_REG_IEEE0BLK_MIICNTL, 0);
@@ -3945,13 +3994,13 @@ static void bnx2x_warpcore_set_10G_XFI(struct bnx2x_phy *phy,
3945 3994
3946 } else { 3995 } else {
3947 misc1_val |= 0x9; 3996 misc1_val |= 0x9;
3948 tap_val = ((0x12 << MDIO_WC_REG_TX_FIR_TAP_POST_TAP_OFFSET) | 3997 tap_val = ((0x0f << MDIO_WC_REG_TX_FIR_TAP_POST_TAP_OFFSET) |
3949 (0x2d << MDIO_WC_REG_TX_FIR_TAP_MAIN_TAP_OFFSET) | 3998 (0x2b << MDIO_WC_REG_TX_FIR_TAP_MAIN_TAP_OFFSET) |
3950 (0x00 << MDIO_WC_REG_TX_FIR_TAP_PRE_TAP_OFFSET)); 3999 (0x02 << MDIO_WC_REG_TX_FIR_TAP_PRE_TAP_OFFSET));
3951 tx_driver_val = 4000 tx_driver_val =
3952 ((0x02 << MDIO_WC_REG_TX0_TX_DRIVER_POST2_COEFF_OFFSET) | 4001 ((0x03 << MDIO_WC_REG_TX0_TX_DRIVER_POST2_COEFF_OFFSET) |
3953 (0x02 << MDIO_WC_REG_TX0_TX_DRIVER_IDRIVER_OFFSET) | 4002 (0x02 << MDIO_WC_REG_TX0_TX_DRIVER_IDRIVER_OFFSET) |
3954 (0x02 << MDIO_WC_REG_TX0_TX_DRIVER_IPRE_DRIVER_OFFSET)); 4003 (0x06 << MDIO_WC_REG_TX0_TX_DRIVER_IPRE_DRIVER_OFFSET));
3955 } 4004 }
3956 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD, 4005 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3957 MDIO_WC_REG_SERDESDIGITAL_MISC1, misc1_val); 4006 MDIO_WC_REG_SERDESDIGITAL_MISC1, misc1_val);
@@ -4369,7 +4418,7 @@ static void bnx2x_warpcore_config_init(struct bnx2x_phy *phy,
4369 switch (serdes_net_if) { 4418 switch (serdes_net_if) {
4370 case PORT_HW_CFG_NET_SERDES_IF_KR: 4419 case PORT_HW_CFG_NET_SERDES_IF_KR:
4371 /* Enable KR Auto Neg */ 4420 /* Enable KR Auto Neg */
4372 if (params->loopback_mode == LOOPBACK_NONE) 4421 if (params->loopback_mode != LOOPBACK_EXT)
4373 bnx2x_warpcore_enable_AN_KR(phy, params, vars); 4422 bnx2x_warpcore_enable_AN_KR(phy, params, vars);
4374 else { 4423 else {
4375 DP(NETIF_MSG_LINK, "Setting KR 10G-Force\n"); 4424 DP(NETIF_MSG_LINK, "Setting KR 10G-Force\n");
@@ -6167,12 +6216,14 @@ int bnx2x_set_led(struct link_params *params,
6167 6216
6168 tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED); 6217 tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED);
6169 if (params->phy[EXT_PHY1].type == 6218 if (params->phy[EXT_PHY1].type ==
6170 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE) 6219 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE)
6171 EMAC_WR(bp, EMAC_REG_EMAC_LED, tmp & 0xfff1); 6220 tmp &= ~(EMAC_LED_1000MB_OVERRIDE |
6172 else { 6221 EMAC_LED_100MB_OVERRIDE |
6173 EMAC_WR(bp, EMAC_REG_EMAC_LED, 6222 EMAC_LED_10MB_OVERRIDE);
6174 (tmp | EMAC_LED_OVERRIDE)); 6223 else
6175 } 6224 tmp |= EMAC_LED_OVERRIDE;
6225
6226 EMAC_WR(bp, EMAC_REG_EMAC_LED, tmp);
6176 break; 6227 break;
6177 6228
6178 case LED_MODE_OPER: 6229 case LED_MODE_OPER:
@@ -6227,10 +6278,15 @@ int bnx2x_set_led(struct link_params *params,
6227 hw_led_mode); 6278 hw_led_mode);
6228 } else if ((params->phy[EXT_PHY1].type == 6279 } else if ((params->phy[EXT_PHY1].type ==
6229 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE) && 6280 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE) &&
6230 (mode != LED_MODE_OPER)) { 6281 (mode == LED_MODE_ON)) {
6231 REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4, 0); 6282 REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4, 0);
6232 tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED); 6283 tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED);
6233 EMAC_WR(bp, EMAC_REG_EMAC_LED, tmp | 0x3); 6284 EMAC_WR(bp, EMAC_REG_EMAC_LED, tmp |
6285 EMAC_LED_OVERRIDE | EMAC_LED_1000MB_OVERRIDE);
6286 /* Break here; otherwise, it'll disable the
6287 * intended override.
6288 */
6289 break;
6234 } else 6290 } else
6235 REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4, 6291 REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4,
6236 hw_led_mode); 6292 hw_led_mode);
@@ -6245,13 +6301,9 @@ int bnx2x_set_led(struct link_params *params,
6245 LED_BLINK_RATE_VAL_E1X_E2); 6301 LED_BLINK_RATE_VAL_E1X_E2);
6246 REG_WR(bp, NIG_REG_LED_CONTROL_BLINK_RATE_ENA_P0 + 6302 REG_WR(bp, NIG_REG_LED_CONTROL_BLINK_RATE_ENA_P0 +
6247 port*4, 1); 6303 port*4, 1);
6248 if ((params->phy[EXT_PHY1].type != 6304 tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED);
6249 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE) && 6305 EMAC_WR(bp, EMAC_REG_EMAC_LED,
6250 (mode != LED_MODE_OPER)) { 6306 (tmp & (~EMAC_LED_OVERRIDE)));
6251 tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED);
6252 EMAC_WR(bp, EMAC_REG_EMAC_LED,
6253 (tmp & (~EMAC_LED_OVERRIDE)));
6254 }
6255 6307
6256 if (CHIP_IS_E1(bp) && 6308 if (CHIP_IS_E1(bp) &&
6257 ((speed == SPEED_2500) || 6309 ((speed == SPEED_2500) ||
@@ -6844,6 +6896,12 @@ int bnx2x_link_update(struct link_params *params, struct link_vars *vars)
6844 SINGLE_MEDIA_DIRECT(params)) && 6896 SINGLE_MEDIA_DIRECT(params)) &&
6845 (phy_vars[active_external_phy].fault_detected == 0)); 6897 (phy_vars[active_external_phy].fault_detected == 0));
6846 6898
6899 /* Update the PFC configuration in case it was changed */
6900 if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED)
6901 vars->link_status |= LINK_STATUS_PFC_ENABLED;
6902 else
6903 vars->link_status &= ~LINK_STATUS_PFC_ENABLED;
6904
6847 if (vars->link_up) 6905 if (vars->link_up)
6848 rc = bnx2x_update_link_up(params, vars, link_10g_plus); 6906 rc = bnx2x_update_link_up(params, vars, link_10g_plus);
6849 else 6907 else
@@ -8031,7 +8089,9 @@ static int bnx2x_verify_sfp_module(struct bnx2x_phy *phy,
8031 netdev_err(bp->dev, "Warning: Unqualified SFP+ module detected," 8089 netdev_err(bp->dev, "Warning: Unqualified SFP+ module detected,"
8032 " Port %d from %s part number %s\n", 8090 " Port %d from %s part number %s\n",
8033 params->port, vendor_name, vendor_pn); 8091 params->port, vendor_name, vendor_pn);
8034 phy->flags |= FLAGS_SFP_NOT_APPROVED; 8092 if ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) !=
8093 PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_WARNING_MSG)
8094 phy->flags |= FLAGS_SFP_NOT_APPROVED;
8035 return -EINVAL; 8095 return -EINVAL;
8036} 8096}
8037 8097
@@ -9091,6 +9151,12 @@ static int bnx2x_8727_config_init(struct bnx2x_phy *phy,
9091 tmp2 &= 0xFFEF; 9151 tmp2 &= 0xFFEF;
9092 bnx2x_cl45_write(bp, phy, 9152 bnx2x_cl45_write(bp, phy,
9093 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_OPT_CFG_REG, tmp2); 9153 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_OPT_CFG_REG, tmp2);
9154 bnx2x_cl45_read(bp, phy,
9155 MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER,
9156 &tmp2);
9157 bnx2x_cl45_write(bp, phy,
9158 MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER,
9159 (tmp2 & 0x7fff));
9094 } 9160 }
9095 9161
9096 return 0; 9162 return 0;
@@ -9271,12 +9337,11 @@ static u8 bnx2x_8727_read_status(struct bnx2x_phy *phy,
9271 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXCTRL, 9337 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXCTRL,
9272 ((1<<5) | (1<<2))); 9338 ((1<<5) | (1<<2)));
9273 } 9339 }
9274 DP(NETIF_MSG_LINK, "Enabling 8727 TX laser if SFP is approved\n"); 9340
9275 bnx2x_8727_specific_func(phy, params, ENABLE_TX); 9341 if (!(phy->flags & FLAGS_SFP_NOT_APPROVED)) {
9276 /* If transmitter is disabled, ignore false link up indication */ 9342 DP(NETIF_MSG_LINK, "Enabling 8727 TX laser\n");
9277 bnx2x_cl45_read(bp, phy, 9343 bnx2x_sfp_set_transmitter(params, phy, 1);
9278 MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER, &val1); 9344 } else {
9279 if (val1 & (1<<15)) {
9280 DP(NETIF_MSG_LINK, "Tx is disabled\n"); 9345 DP(NETIF_MSG_LINK, "Tx is disabled\n");
9281 return 0; 9346 return 0;
9282 } 9347 }
@@ -9370,8 +9435,7 @@ static void bnx2x_save_848xx_spirom_version(struct bnx2x_phy *phy,
9370 9435
9371 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833) { 9436 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833) {
9372 bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD, 0x400f, &fw_ver1); 9437 bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD, 0x400f, &fw_ver1);
9373 bnx2x_save_spirom_version(bp, port, 9438 bnx2x_save_spirom_version(bp, port, fw_ver1 & 0xfff,
9374 ((fw_ver1 & 0xf000)>>5) | (fw_ver1 & 0x7f),
9375 phy->ver_addr); 9439 phy->ver_addr);
9376 } else { 9440 } else {
9377 /* For 32-bit registers in 848xx, access via MDIO2ARM i/f. */ 9441 /* For 32-bit registers in 848xx, access via MDIO2ARM i/f. */
@@ -9794,6 +9858,15 @@ static int bnx2x_84833_hw_reset_phy(struct bnx2x_phy *phy,
9794 other_shmem_base_addr)); 9858 other_shmem_base_addr));
9795 9859
9796 u32 shmem_base_path[2]; 9860 u32 shmem_base_path[2];
9861
9862 /* Work around for 84833 LED failure inside RESET status */
9863 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
9864 MDIO_AN_REG_8481_LEGACY_MII_CTRL,
9865 MDIO_AN_REG_8481_MII_CTRL_FORCE_1G);
9866 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
9867 MDIO_AN_REG_8481_1G_100T_EXT_CTRL,
9868 MIDO_AN_REG_8481_EXT_CTRL_FORCE_LEDS_OFF);
9869
9797 shmem_base_path[0] = params->shmem_base; 9870 shmem_base_path[0] = params->shmem_base;
9798 shmem_base_path[1] = other_shmem_base_addr; 9871 shmem_base_path[1] = other_shmem_base_addr;
9799 9872
@@ -10104,7 +10177,7 @@ static void bnx2x_848x3_link_reset(struct bnx2x_phy *phy,
10104 u8 port; 10177 u8 port;
10105 u16 val16; 10178 u16 val16;
10106 10179
10107 if (!(CHIP_IS_E1(bp))) 10180 if (!(CHIP_IS_E1x(bp)))
10108 port = BP_PATH(bp); 10181 port = BP_PATH(bp);
10109 else 10182 else
10110 port = params->port; 10183 port = params->port;
@@ -10131,7 +10204,7 @@ static void bnx2x_848xx_set_link_led(struct bnx2x_phy *phy,
10131 u16 val; 10204 u16 val;
10132 u8 port; 10205 u8 port;
10133 10206
10134 if (!(CHIP_IS_E1(bp))) 10207 if (!(CHIP_IS_E1x(bp)))
10135 port = BP_PATH(bp); 10208 port = BP_PATH(bp);
10136 else 10209 else
10137 port = params->port; 10210 port = params->port;
@@ -12050,6 +12123,9 @@ int bnx2x_phy_init(struct link_params *params, struct link_vars *vars)
12050 12123
12051 bnx2x_emac_init(params, vars); 12124 bnx2x_emac_init(params, vars);
12052 12125
12126 if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED)
12127 vars->link_status |= LINK_STATUS_PFC_ENABLED;
12128
12053 if (params->num_phys == 0) { 12129 if (params->num_phys == 0) {
12054 DP(NETIF_MSG_LINK, "No phy found for initialization !!\n"); 12130 DP(NETIF_MSG_LINK, "No phy found for initialization !!\n");
12055 return -EINVAL; 12131 return -EINVAL;
@@ -12129,10 +12205,10 @@ int bnx2x_link_reset(struct link_params *params, struct link_vars *vars,
12129 * Hold it as vars low 12205 * Hold it as vars low
12130 */ 12206 */
12131 /* clear link led */ 12207 /* clear link led */
12208 bnx2x_set_mdio_clk(bp, params->chip_id, port);
12132 bnx2x_set_led(params, vars, LED_MODE_OFF, 0); 12209 bnx2x_set_led(params, vars, LED_MODE_OFF, 0);
12133 12210
12134 if (reset_ext_phy) { 12211 if (reset_ext_phy) {
12135 bnx2x_set_mdio_clk(bp, params->chip_id, port);
12136 for (phy_index = EXT_PHY1; phy_index < params->num_phys; 12212 for (phy_index = EXT_PHY1; phy_index < params->num_phys;
12137 phy_index++) { 12213 phy_index++) {
12138 if (params->phy[phy_index].link_reset) { 12214 if (params->phy[phy_index].link_reset) {
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_link.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_link.h
index 7ba557a610da..763535ee4832 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_link.h
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_link.h
@@ -89,6 +89,8 @@
89#define PFC_BRB_FULL_LB_XON_THRESHOLD 250 89#define PFC_BRB_FULL_LB_XON_THRESHOLD 250
90 90
91#define MAXVAL(a, b) (((a) > (b)) ? (a) : (b)) 91#define MAXVAL(a, b) (((a) > (b)) ? (a) : (b))
92
93#define BMAC_CONTROL_RX_ENABLE 2
92/***********************************************************/ 94/***********************************************************/
93/* Structs */ 95/* Structs */
94/***********************************************************/ 96/***********************************************************/
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
index f7f9aa807264..6af310195bae 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
@@ -52,6 +52,7 @@
52#include <linux/prefetch.h> 52#include <linux/prefetch.h>
53#include <linux/zlib.h> 53#include <linux/zlib.h>
54#include <linux/io.h> 54#include <linux/io.h>
55#include <linux/semaphore.h>
55#include <linux/stringify.h> 56#include <linux/stringify.h>
56#include <linux/vmalloc.h> 57#include <linux/vmalloc.h>
57 58
@@ -211,6 +212,10 @@ static DEFINE_PCI_DEVICE_TABLE(bnx2x_pci_tbl) = {
211 212
212MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl); 213MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
213 214
215/* Global resources for unloading a previously loaded device */
216#define BNX2X_PREV_WAIT_NEEDED 1
217static DEFINE_SEMAPHORE(bnx2x_prev_sem);
218static LIST_HEAD(bnx2x_prev_list);
214/**************************************************************************** 219/****************************************************************************
215* General service functions 220* General service functions
216****************************************************************************/ 221****************************************************************************/
@@ -8812,109 +8817,392 @@ static inline void bnx2x_undi_int_disable(struct bnx2x *bp)
8812 bnx2x_undi_int_disable_e1h(bp); 8817 bnx2x_undi_int_disable_e1h(bp);
8813} 8818}
8814 8819
8815static void __devinit bnx2x_undi_unload(struct bnx2x *bp) 8820static void __devinit bnx2x_prev_unload_close_mac(struct bnx2x *bp)
8816{ 8821{
8817 u32 val; 8822 u32 val, base_addr, offset, mask, reset_reg;
8823 bool mac_stopped = false;
8824 u8 port = BP_PORT(bp);
8818 8825
8819 /* possibly another driver is trying to reset the chip */ 8826 reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
8820 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
8821 8827
8822 /* check if doorbell queue is reset */ 8828 if (!CHIP_IS_E3(bp)) {
8823 if (REG_RD(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET) 8829 val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
8824 & MISC_REGISTERS_RESET_REG_1_RST_DORQ) { 8830 mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
8831 if ((mask & reset_reg) && val) {
8832 u32 wb_data[2];
8833 BNX2X_DEV_INFO("Disable bmac Rx\n");
8834 base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
8835 : NIG_REG_INGRESS_BMAC0_MEM;
8836 offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
8837 : BIGMAC_REGISTER_BMAC_CONTROL;
8825 8838
8826 /* 8839 /*
8827 * Check if it is the UNDI driver 8840 * use rd/wr since we cannot use dmae. This is safe
8841 * since MCP won't access the bus due to the request
8842 * to unload, and no function on the path can be
8843 * loaded at this time.
8844 */
8845 wb_data[0] = REG_RD(bp, base_addr + offset);
8846 wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
8847 wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
8848 REG_WR(bp, base_addr + offset, wb_data[0]);
8849 REG_WR(bp, base_addr + offset + 0x4, wb_data[1]);
8850
8851 }
8852 BNX2X_DEV_INFO("Disable emac Rx\n");
8853 REG_WR(bp, NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4, 0);
8854
8855 mac_stopped = true;
8856 } else {
8857 if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
8858 BNX2X_DEV_INFO("Disable xmac Rx\n");
8859 base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
8860 val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
8861 REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
8862 val & ~(1 << 1));
8863 REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
8864 val | (1 << 1));
8865 REG_WR(bp, base_addr + XMAC_REG_CTRL, 0);
8866 mac_stopped = true;
8867 }
8868 mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
8869 if (mask & reset_reg) {
8870 BNX2X_DEV_INFO("Disable umac Rx\n");
8871 base_addr = BP_PORT(bp) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
8872 REG_WR(bp, base_addr + UMAC_REG_COMMAND_CONFIG, 0);
8873 mac_stopped = true;
8874 }
8875 }
8876
8877 if (mac_stopped)
8878 msleep(20);
8879
8880}
8881
8882#define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
8883#define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
8884#define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
8885#define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
8886
8887static void __devinit bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 port,
8888 u8 inc)
8889{
8890 u16 rcq, bd;
8891 u32 tmp_reg = REG_RD(bp, BNX2X_PREV_UNDI_PROD_ADDR(port));
8892
8893 rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
8894 bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
8895
8896 tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
8897 REG_WR(bp, BNX2X_PREV_UNDI_PROD_ADDR(port), tmp_reg);
8898
8899 BNX2X_DEV_INFO("UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n",
8900 port, bd, rcq);
8901}
8902
8903static int __devinit bnx2x_prev_mcp_done(struct bnx2x *bp)
8904{
8905 u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
8906 if (!rc) {
8907 BNX2X_ERR("MCP response failure, aborting\n");
8908 return -EBUSY;
8909 }
8910
8911 return 0;
8912}
8913
8914static bool __devinit bnx2x_prev_is_path_marked(struct bnx2x *bp)
8915{
8916 struct bnx2x_prev_path_list *tmp_list;
8917 int rc = false;
8918
8919 if (down_trylock(&bnx2x_prev_sem))
8920 return false;
8921
8922 list_for_each_entry(tmp_list, &bnx2x_prev_list, list) {
8923 if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
8924 bp->pdev->bus->number == tmp_list->bus &&
8925 BP_PATH(bp) == tmp_list->path) {
8926 rc = true;
8927 BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
8928 BP_PATH(bp));
8929 break;
8930 }
8931 }
8932
8933 up(&bnx2x_prev_sem);
8934
8935 return rc;
8936}
8937
8938static int __devinit bnx2x_prev_mark_path(struct bnx2x *bp)
8939{
8940 struct bnx2x_prev_path_list *tmp_list;
8941 int rc;
8942
8943 tmp_list = (struct bnx2x_prev_path_list *)
8944 kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
8945 if (!tmp_list) {
8946 BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
8947 return -ENOMEM;
8948 }
8949
8950 tmp_list->bus = bp->pdev->bus->number;
8951 tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
8952 tmp_list->path = BP_PATH(bp);
8953
8954 rc = down_interruptible(&bnx2x_prev_sem);
8955 if (rc) {
8956 BNX2X_ERR("Received %d when tried to take lock\n", rc);
8957 kfree(tmp_list);
8958 } else {
8959 BNX2X_DEV_INFO("Marked path [%d] - finished previous unload\n",
8960 BP_PATH(bp));
8961 list_add(&tmp_list->list, &bnx2x_prev_list);
8962 up(&bnx2x_prev_sem);
8963 }
8964
8965 return rc;
8966}
8967
8968static bool __devinit bnx2x_can_flr(struct bnx2x *bp)
8969{
8970 int pos;
8971 u32 cap;
8972 struct pci_dev *dev = bp->pdev;
8973
8974 pos = pci_pcie_cap(dev);
8975 if (!pos)
8976 return false;
8977
8978 pci_read_config_dword(dev, pos + PCI_EXP_DEVCAP, &cap);
8979 if (!(cap & PCI_EXP_DEVCAP_FLR))
8980 return false;
8981
8982 return true;
8983}
8984
8985static int __devinit bnx2x_do_flr(struct bnx2x *bp)
8986{
8987 int i, pos;
8988 u16 status;
8989 struct pci_dev *dev = bp->pdev;
8990
8991 /* probe the capability first */
8992 if (bnx2x_can_flr(bp))
8993 return -ENOTTY;
8994
8995 pos = pci_pcie_cap(dev);
8996 if (!pos)
8997 return -ENOTTY;
8998
8999 /* Wait for Transaction Pending bit clean */
9000 for (i = 0; i < 4; i++) {
9001 if (i)
9002 msleep((1 << (i - 1)) * 100);
9003
9004 pci_read_config_word(dev, pos + PCI_EXP_DEVSTA, &status);
9005 if (!(status & PCI_EXP_DEVSTA_TRPND))
9006 goto clear;
9007 }
9008
9009 dev_err(&dev->dev,
9010 "transaction is not cleared; proceeding with reset anyway\n");
9011
9012clear:
9013 if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
9014 BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
9015 bp->common.bc_ver);
9016 return -EINVAL;
9017 }
9018
9019 bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
9020
9021 return 0;
9022}
9023
9024static int __devinit bnx2x_prev_unload_uncommon(struct bnx2x *bp)
9025{
9026 int rc;
9027
9028 BNX2X_DEV_INFO("Uncommon unload Flow\n");
9029
9030 /* Test if previous unload process was already finished for this path */
9031 if (bnx2x_prev_is_path_marked(bp))
9032 return bnx2x_prev_mcp_done(bp);
9033
9034 /* If function has FLR capabilities, and existing FW version matches
9035 * the one required, then FLR will be sufficient to clean any residue
9036 * left by previous driver
9037 */
9038 if (bnx2x_test_firmware_version(bp, false) && bnx2x_can_flr(bp))
9039 return bnx2x_do_flr(bp);
9040
9041 /* Close the MCP request, return failure*/
9042 rc = bnx2x_prev_mcp_done(bp);
9043 if (!rc)
9044 rc = BNX2X_PREV_WAIT_NEEDED;
9045
9046 return rc;
9047}
9048
9049static int __devinit bnx2x_prev_unload_common(struct bnx2x *bp)
9050{
9051 u32 reset_reg, tmp_reg = 0, rc;
9052 /* It is possible a previous function received 'common' answer,
9053 * but hasn't loaded yet, therefore creating a scenario of
9054 * multiple functions receiving 'common' on the same path.
9055 */
9056 BNX2X_DEV_INFO("Common unload Flow\n");
9057
9058 if (bnx2x_prev_is_path_marked(bp))
9059 return bnx2x_prev_mcp_done(bp);
9060
9061 reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
9062
9063 /* Reset should be performed after BRB is emptied */
9064 if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
9065 u32 timer_count = 1000;
9066 bool prev_undi = false;
9067
9068 /* Close the MAC Rx to prevent BRB from filling up */
9069 bnx2x_prev_unload_close_mac(bp);
9070
9071 /* Check if the UNDI driver was previously loaded
8828 * UNDI driver initializes CID offset for normal bell to 0x7 9072 * UNDI driver initializes CID offset for normal bell to 0x7
8829 */ 9073 */
8830 val = REG_RD(bp, DORQ_REG_NORM_CID_OFST); 9074 reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
8831 if (val == 0x7) { 9075 if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_DORQ) {
8832 u32 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS; 9076 tmp_reg = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
8833 /* save our pf_num */ 9077 if (tmp_reg == 0x7) {
8834 int orig_pf_num = bp->pf_num; 9078 BNX2X_DEV_INFO("UNDI previously loaded\n");
8835 int port; 9079 prev_undi = true;
8836 u32 swap_en, swap_val, value; 9080 /* clear the UNDI indication */
8837 9081 REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
8838 /* clear the UNDI indication */
8839 REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
8840
8841 BNX2X_DEV_INFO("UNDI is active! reset device\n");
8842
8843 /* try unload UNDI on port 0 */
8844 bp->pf_num = 0;
8845 bp->fw_seq =
8846 (SHMEM_RD(bp, func_mb[bp->pf_num].drv_mb_header) &
8847 DRV_MSG_SEQ_NUMBER_MASK);
8848 reset_code = bnx2x_fw_command(bp, reset_code, 0);
8849
8850 /* if UNDI is loaded on the other port */
8851 if (reset_code != FW_MSG_CODE_DRV_UNLOAD_COMMON) {
8852
8853 /* send "DONE" for previous unload */
8854 bnx2x_fw_command(bp,
8855 DRV_MSG_CODE_UNLOAD_DONE, 0);
8856
8857 /* unload UNDI on port 1 */
8858 bp->pf_num = 1;
8859 bp->fw_seq =
8860 (SHMEM_RD(bp, func_mb[bp->pf_num].drv_mb_header) &
8861 DRV_MSG_SEQ_NUMBER_MASK);
8862 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
8863
8864 bnx2x_fw_command(bp, reset_code, 0);
8865 } 9082 }
9083 }
9084 /* wait until BRB is empty */
9085 tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
9086 while (timer_count) {
9087 u32 prev_brb = tmp_reg;
8866 9088
8867 bnx2x_undi_int_disable(bp); 9089 tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
8868 port = BP_PORT(bp); 9090 if (!tmp_reg)
8869 9091 break;
8870 /* close input traffic and wait for it */
8871 /* Do not rcv packets to BRB */
8872 REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_DRV_MASK :
8873 NIG_REG_LLH0_BRB1_DRV_MASK), 0x0);
8874 /* Do not direct rcv packets that are not for MCP to
8875 * the BRB */
8876 REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
8877 NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
8878 /* clear AEU */
8879 REG_WR(bp, (port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
8880 MISC_REG_AEU_MASK_ATTN_FUNC_0), 0);
8881 msleep(10);
8882
8883 /* save NIG port swap info */
8884 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
8885 swap_en = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
8886 /* reset device */
8887 REG_WR(bp,
8888 GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
8889 0xd3ffffff);
8890
8891 value = 0x1400;
8892 if (CHIP_IS_E3(bp)) {
8893 value |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
8894 value |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
8895 }
8896 9092
8897 REG_WR(bp, 9093 BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
8898 GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
8899 value);
8900 9094
8901 /* take the NIG out of reset and restore swap values */ 9095 /* reset timer as long as BRB actually gets emptied */
8902 REG_WR(bp, 9096 if (prev_brb > tmp_reg)
8903 GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 9097 timer_count = 1000;
8904 MISC_REGISTERS_RESET_REG_1_RST_NIG); 9098 else
8905 REG_WR(bp, NIG_REG_PORT_SWAP, swap_val); 9099 timer_count--;
8906 REG_WR(bp, NIG_REG_STRAP_OVERRIDE, swap_en);
8907 9100
8908 /* send unload done to the MCP */ 9101 /* If UNDI resides in memory, manually increment it */
8909 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0); 9102 if (prev_undi)
9103 bnx2x_prev_unload_undi_inc(bp, BP_PORT(bp), 1);
8910 9104
8911 /* restore our func and fw_seq */ 9105 udelay(10);
8912 bp->pf_num = orig_pf_num;
8913 } 9106 }
9107
9108 if (!timer_count)
9109 BNX2X_ERR("Failed to empty BRB, hope for the best\n");
9110
8914 } 9111 }
8915 9112
8916 /* now it's safe to release the lock */ 9113 /* No packets are in the pipeline, path is ready for reset */
8917 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET); 9114 bnx2x_reset_common(bp);
9115
9116 rc = bnx2x_prev_mark_path(bp);
9117 if (rc) {
9118 bnx2x_prev_mcp_done(bp);
9119 return rc;
9120 }
9121
9122 return bnx2x_prev_mcp_done(bp);
9123}
9124
9125/* previous driver DMAE transaction may have occurred when pre-boot stage ended
9126 * and boot began, or when kdump kernel was loaded. Either case would invalidate
9127 * the addresses of the transaction, resulting in was-error bit set in the pci
9128 * causing all hw-to-host pcie transactions to timeout. If this happened we want
9129 * to clear the interrupt which detected this from the pglueb and the was done
9130 * bit
9131 */
9132static void __devinit bnx2x_prev_interrupted_dmae(struct bnx2x *bp)
9133{
9134 u32 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS);
9135 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) {
9136 BNX2X_ERR("was error bit was found to be set in pglueb upon startup. Clearing");
9137 REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, 1 << BP_FUNC(bp));
9138 }
9139}
9140
9141static int __devinit bnx2x_prev_unload(struct bnx2x *bp)
9142{
9143 int time_counter = 10;
9144 u32 rc, fw, hw_lock_reg, hw_lock_val;
9145 BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
9146
9147 /* clear hw from errors which may have resulted from an interrupted
9148 * dmae transaction.
9149 */
9150 bnx2x_prev_interrupted_dmae(bp);
9151
9152 /* Release previously held locks */
9153 hw_lock_reg = (BP_FUNC(bp) <= 5) ?
9154 (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
9155 (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
9156
9157 hw_lock_val = (REG_RD(bp, hw_lock_reg));
9158 if (hw_lock_val) {
9159 if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
9160 BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
9161 REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
9162 (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
9163 }
9164
9165 BNX2X_DEV_INFO("Release Previously held hw lock\n");
9166 REG_WR(bp, hw_lock_reg, 0xffffffff);
9167 } else
9168 BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
9169
9170 if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
9171 BNX2X_DEV_INFO("Release previously held alr\n");
9172 REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
9173 }
9174
9175
9176 do {
9177 /* Lock MCP using an unload request */
9178 fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
9179 if (!fw) {
9180 BNX2X_ERR("MCP response failure, aborting\n");
9181 rc = -EBUSY;
9182 break;
9183 }
9184
9185 if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON) {
9186 rc = bnx2x_prev_unload_common(bp);
9187 break;
9188 }
9189
9190 /* non-common reply from MCP night require looping */
9191 rc = bnx2x_prev_unload_uncommon(bp);
9192 if (rc != BNX2X_PREV_WAIT_NEEDED)
9193 break;
9194
9195 msleep(20);
9196 } while (--time_counter);
9197
9198 if (!time_counter || rc) {
9199 BNX2X_ERR("Failed unloading previous driver, aborting\n");
9200 rc = -EBUSY;
9201 }
9202
9203 BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
9204
9205 return rc;
8918} 9206}
8919 9207
8920static void __devinit bnx2x_get_common_hwinfo(struct bnx2x *bp) 9208static void __devinit bnx2x_get_common_hwinfo(struct bnx2x *bp)
@@ -10100,8 +10388,16 @@ static int __devinit bnx2x_init_bp(struct bnx2x *bp)
10100 func = BP_FUNC(bp); 10388 func = BP_FUNC(bp);
10101 10389
10102 /* need to reset chip if undi was active */ 10390 /* need to reset chip if undi was active */
10103 if (!BP_NOMCP(bp)) 10391 if (!BP_NOMCP(bp)) {
10104 bnx2x_undi_unload(bp); 10392 /* init fw_seq */
10393 bp->fw_seq =
10394 SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
10395 DRV_MSG_SEQ_NUMBER_MASK;
10396 BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
10397
10398 bnx2x_prev_unload(bp);
10399 }
10400
10105 10401
10106 if (CHIP_REV_IS_FPGA(bp)) 10402 if (CHIP_REV_IS_FPGA(bp))
10107 dev_err(&bp->pdev->dev, "FPGA detected\n"); 10403 dev_err(&bp->pdev->dev, "FPGA detected\n");
@@ -11431,9 +11727,18 @@ static int __init bnx2x_init(void)
11431 11727
11432static void __exit bnx2x_cleanup(void) 11728static void __exit bnx2x_cleanup(void)
11433{ 11729{
11730 struct list_head *pos, *q;
11434 pci_unregister_driver(&bnx2x_pci_driver); 11731 pci_unregister_driver(&bnx2x_pci_driver);
11435 11732
11436 destroy_workqueue(bnx2x_wq); 11733 destroy_workqueue(bnx2x_wq);
11734
11735 /* Free globablly allocated resources */
11736 list_for_each_safe(pos, q, &bnx2x_prev_list) {
11737 struct bnx2x_prev_path_list *tmp =
11738 list_entry(pos, struct bnx2x_prev_path_list, list);
11739 list_del(pos);
11740 kfree(tmp);
11741 }
11437} 11742}
11438 11743
11439void bnx2x_notify_link_changed(struct bnx2x *bp) 11744void bnx2x_notify_link_changed(struct bnx2x *bp)
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_reg.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_reg.h
index fd7fb4581849..c25803b9c0ca 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_reg.h
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_reg.h
@@ -987,6 +987,7 @@
987 * clear; 1 = set. Data valid only in addresses 0-4. all the rest are zero. */ 987 * clear; 1 = set. Data valid only in addresses 0-4. all the rest are zero. */
988#define IGU_REG_WRITE_DONE_PENDING 0x130480 988#define IGU_REG_WRITE_DONE_PENDING 0x130480
989#define MCP_A_REG_MCPR_SCRATCH 0x3a0000 989#define MCP_A_REG_MCPR_SCRATCH 0x3a0000
990#define MCP_REG_MCPR_ACCESS_LOCK 0x8009c
990#define MCP_REG_MCPR_CPU_PROGRAM_COUNTER 0x8501c 991#define MCP_REG_MCPR_CPU_PROGRAM_COUNTER 0x8501c
991#define MCP_REG_MCPR_GP_INPUTS 0x800c0 992#define MCP_REG_MCPR_GP_INPUTS 0x800c0
992#define MCP_REG_MCPR_GP_OENABLE 0x800c8 993#define MCP_REG_MCPR_GP_OENABLE 0x800c8
@@ -1686,6 +1687,7 @@
1686 [10] rst_dbg; [11] rst_misc_core; [12] rst_dbue (UART); [13] 1687 [10] rst_dbg; [11] rst_misc_core; [12] rst_dbue (UART); [13]
1687 Pci_resetmdio_n; [14] rst_emac0_hard_core; [15] rst_emac1_hard_core; 16] 1688 Pci_resetmdio_n; [14] rst_emac0_hard_core; [15] rst_emac1_hard_core; 16]
1688 rst_pxp_rq_rd_wr; 31:17] reserved */ 1689 rst_pxp_rq_rd_wr; 31:17] reserved */
1690#define MISC_REG_RESET_REG_1 0xa580
1689#define MISC_REG_RESET_REG_2 0xa590 1691#define MISC_REG_RESET_REG_2 0xa590
1690/* [RW 20] 20 bit GRC address where the scratch-pad of the MCP that is 1692/* [RW 20] 20 bit GRC address where the scratch-pad of the MCP that is
1691 shared with the driver resides */ 1693 shared with the driver resides */
@@ -5352,6 +5354,7 @@
5352#define XMAC_CTRL_REG_TX_EN (0x1<<0) 5354#define XMAC_CTRL_REG_TX_EN (0x1<<0)
5353#define XMAC_PAUSE_CTRL_REG_RX_PAUSE_EN (0x1<<18) 5355#define XMAC_PAUSE_CTRL_REG_RX_PAUSE_EN (0x1<<18)
5354#define XMAC_PAUSE_CTRL_REG_TX_PAUSE_EN (0x1<<17) 5356#define XMAC_PAUSE_CTRL_REG_TX_PAUSE_EN (0x1<<17)
5357#define XMAC_PFC_CTRL_HI_REG_FORCE_PFC_XON (0x1<<1)
5355#define XMAC_PFC_CTRL_HI_REG_PFC_REFRESH_EN (0x1<<0) 5358#define XMAC_PFC_CTRL_HI_REG_PFC_REFRESH_EN (0x1<<0)
5356#define XMAC_PFC_CTRL_HI_REG_PFC_STATS_EN (0x1<<3) 5359#define XMAC_PFC_CTRL_HI_REG_PFC_STATS_EN (0x1<<3)
5357#define XMAC_PFC_CTRL_HI_REG_RX_PFC_EN (0x1<<4) 5360#define XMAC_PFC_CTRL_HI_REG_RX_PFC_EN (0x1<<4)
@@ -5606,6 +5609,7 @@
5606/* [RC 32] Parity register #0 read clear */ 5609/* [RC 32] Parity register #0 read clear */
5607#define XSEM_REG_XSEM_PRTY_STS_CLR_0 0x280128 5610#define XSEM_REG_XSEM_PRTY_STS_CLR_0 0x280128
5608#define XSEM_REG_XSEM_PRTY_STS_CLR_1 0x280138 5611#define XSEM_REG_XSEM_PRTY_STS_CLR_1 0x280138
5612#define MCPR_ACCESS_LOCK_LOCK (1L<<31)
5609#define MCPR_NVM_ACCESS_ENABLE_EN (1L<<0) 5613#define MCPR_NVM_ACCESS_ENABLE_EN (1L<<0)
5610#define MCPR_NVM_ACCESS_ENABLE_WR_EN (1L<<1) 5614#define MCPR_NVM_ACCESS_ENABLE_WR_EN (1L<<1)
5611#define MCPR_NVM_ADDR_NVM_ADDR_VALUE (0xffffffL<<0) 5615#define MCPR_NVM_ADDR_NVM_ADDR_VALUE (0xffffffL<<0)
@@ -5732,6 +5736,7 @@
5732#define MISC_REGISTERS_GPIO_PORT_SHIFT 4 5736#define MISC_REGISTERS_GPIO_PORT_SHIFT 4
5733#define MISC_REGISTERS_GPIO_SET_POS 8 5737#define MISC_REGISTERS_GPIO_SET_POS 8
5734#define MISC_REGISTERS_RESET_REG_1_CLEAR 0x588 5738#define MISC_REGISTERS_RESET_REG_1_CLEAR 0x588
5739#define MISC_REGISTERS_RESET_REG_1_RST_BRB1 (0x1<<0)
5735#define MISC_REGISTERS_RESET_REG_1_RST_DORQ (0x1<<19) 5740#define MISC_REGISTERS_RESET_REG_1_RST_DORQ (0x1<<19)
5736#define MISC_REGISTERS_RESET_REG_1_RST_HC (0x1<<29) 5741#define MISC_REGISTERS_RESET_REG_1_RST_HC (0x1<<29)
5737#define MISC_REGISTERS_RESET_REG_1_RST_NIG (0x1<<7) 5742#define MISC_REGISTERS_RESET_REG_1_RST_NIG (0x1<<7)
@@ -6816,10 +6821,13 @@ Theotherbitsarereservedandshouldbezero*/
6816 6821
6817#define MDIO_AN_REG_8481_10GBASE_T_AN_CTRL 0x0020 6822#define MDIO_AN_REG_8481_10GBASE_T_AN_CTRL 0x0020
6818#define MDIO_AN_REG_8481_LEGACY_MII_CTRL 0xffe0 6823#define MDIO_AN_REG_8481_LEGACY_MII_CTRL 0xffe0
6824#define MDIO_AN_REG_8481_MII_CTRL_FORCE_1G 0x40
6819#define MDIO_AN_REG_8481_LEGACY_MII_STATUS 0xffe1 6825#define MDIO_AN_REG_8481_LEGACY_MII_STATUS 0xffe1
6820#define MDIO_AN_REG_8481_LEGACY_AN_ADV 0xffe4 6826#define MDIO_AN_REG_8481_LEGACY_AN_ADV 0xffe4
6821#define MDIO_AN_REG_8481_LEGACY_AN_EXPANSION 0xffe6 6827#define MDIO_AN_REG_8481_LEGACY_AN_EXPANSION 0xffe6
6822#define MDIO_AN_REG_8481_1000T_CTRL 0xffe9 6828#define MDIO_AN_REG_8481_1000T_CTRL 0xffe9
6829#define MDIO_AN_REG_8481_1G_100T_EXT_CTRL 0xfff0
6830#define MIDO_AN_REG_8481_EXT_CTRL_FORCE_LEDS_OFF 0x0008
6823#define MDIO_AN_REG_8481_EXPANSION_REG_RD_RW 0xfff5 6831#define MDIO_AN_REG_8481_EXPANSION_REG_RD_RW 0xfff5
6824#define MDIO_AN_REG_8481_EXPANSION_REG_ACCESS 0xfff7 6832#define MDIO_AN_REG_8481_EXPANSION_REG_ACCESS 0xfff7
6825#define MDIO_AN_REG_8481_AUX_CTRL 0xfff8 6833#define MDIO_AN_REG_8481_AUX_CTRL 0xfff8
@@ -6939,6 +6947,10 @@ Theotherbitsarereservedandshouldbezero*/
6939#define MDIO_WC_REG_GP2_STATUS_GP_2_2 0x81d2 6947#define MDIO_WC_REG_GP2_STATUS_GP_2_2 0x81d2
6940#define MDIO_WC_REG_GP2_STATUS_GP_2_3 0x81d3 6948#define MDIO_WC_REG_GP2_STATUS_GP_2_3 0x81d3
6941#define MDIO_WC_REG_GP2_STATUS_GP_2_4 0x81d4 6949#define MDIO_WC_REG_GP2_STATUS_GP_2_4 0x81d4
6950#define MDIO_WC_REG_GP2_STATUS_GP_2_4_CL73_AN_CMPL 0x1000
6951#define MDIO_WC_REG_GP2_STATUS_GP_2_4_CL37_AN_CMPL 0x0100
6952#define MDIO_WC_REG_GP2_STATUS_GP_2_4_CL37_LP_AN_CAP 0x0010
6953#define MDIO_WC_REG_GP2_STATUS_GP_2_4_CL37_AN_CAP 0x1
6942#define MDIO_WC_REG_UC_INFO_B0_DEAD_TRAP 0x81EE 6954#define MDIO_WC_REG_UC_INFO_B0_DEAD_TRAP 0x81EE
6943#define MDIO_WC_REG_UC_INFO_B1_VERSION 0x81F0 6955#define MDIO_WC_REG_UC_INFO_B1_VERSION 0x81F0
6944#define MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE 0x81F2 6956#define MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE 0x81F2
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
index 3f52fadee3ed..513573321625 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
@@ -3847,7 +3847,7 @@ static bool bnx2x_credit_pool_get_entry(
3847 continue; 3847 continue;
3848 3848
3849 /* If we've got here we are going to find a free entry */ 3849 /* If we've got here we are going to find a free entry */
3850 for (idx = vec * BNX2X_POOL_VEC_SIZE, i = 0; 3850 for (idx = vec * BIT_VEC64_ELEM_SZ, i = 0;
3851 i < BIT_VEC64_ELEM_SZ; idx++, i++) 3851 i < BIT_VEC64_ELEM_SZ; idx++, i++)
3852 3852
3853 if (BIT_VEC64_TEST_BIT(o->pool_mirror, idx)) { 3853 if (BIT_VEC64_TEST_BIT(o->pool_mirror, idx)) {
diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c
index 4e4bb3875868..ceeab8e852ef 100644
--- a/drivers/net/ethernet/broadcom/tg3.c
+++ b/drivers/net/ethernet/broadcom/tg3.c
@@ -879,8 +879,13 @@ static inline unsigned int tg3_has_work(struct tg3_napi *tnapi)
879 if (sblk->status & SD_STATUS_LINK_CHG) 879 if (sblk->status & SD_STATUS_LINK_CHG)
880 work_exists = 1; 880 work_exists = 1;
881 } 881 }
882 /* check for RX/TX work to do */ 882
883 if (sblk->idx[0].tx_consumer != tnapi->tx_cons || 883 /* check for TX work to do */
884 if (sblk->idx[0].tx_consumer != tnapi->tx_cons)
885 work_exists = 1;
886
887 /* check for RX work to do */
888 if (tnapi->rx_rcb_prod_idx &&
884 *(tnapi->rx_rcb_prod_idx) != tnapi->rx_rcb_ptr) 889 *(tnapi->rx_rcb_prod_idx) != tnapi->rx_rcb_ptr)
885 work_exists = 1; 890 work_exists = 1;
886 891
@@ -2778,7 +2783,9 @@ static void tg3_power_down_phy(struct tg3 *tp, bool do_low_power)
2778 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || 2783 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
2779 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || 2784 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 ||
2780 (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780 && 2785 (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780 &&
2781 (tp->phy_flags & TG3_PHYFLG_MII_SERDES))) 2786 (tp->phy_flags & TG3_PHYFLG_MII_SERDES)) ||
2787 (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 &&
2788 !tp->pci_fn))
2782 return; 2789 return;
2783 2790
2784 if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX || 2791 if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX ||
@@ -6122,6 +6129,9 @@ static int tg3_poll_work(struct tg3_napi *tnapi, int work_done, int budget)
6122 return work_done; 6129 return work_done;
6123 } 6130 }
6124 6131
6132 if (!tnapi->rx_rcb_prod_idx)
6133 return work_done;
6134
6125 /* run RX thread, within the bounds set by NAPI. 6135 /* run RX thread, within the bounds set by NAPI.
6126 * All RX "locking" is done by ensuring outside 6136 * All RX "locking" is done by ensuring outside
6127 * code synchronizes with tg3->napi.poll() 6137 * code synchronizes with tg3->napi.poll()
@@ -7565,6 +7575,12 @@ static int tg3_alloc_consistent(struct tg3 *tp)
7565 */ 7575 */
7566 switch (i) { 7576 switch (i) {
7567 default: 7577 default:
7578 if (tg3_flag(tp, ENABLE_RSS)) {
7579 tnapi->rx_rcb_prod_idx = NULL;
7580 break;
7581 }
7582 /* Fall through */
7583 case 1:
7568 tnapi->rx_rcb_prod_idx = &sblk->idx[0].rx_producer; 7584 tnapi->rx_rcb_prod_idx = &sblk->idx[0].rx_producer;
7569 break; 7585 break;
7570 case 2: 7586 case 2:
diff --git a/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c b/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c
index 63bfdd10bd6d..abb6ce7c1b7e 100644
--- a/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c
+++ b/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c
@@ -1150,6 +1150,48 @@ release_tpsram:
1150} 1150}
1151 1151
1152/** 1152/**
1153 * t3_synchronize_rx - wait for current Rx processing on a port to complete
1154 * @adap: the adapter
1155 * @p: the port
1156 *
1157 * Ensures that current Rx processing on any of the queues associated with
1158 * the given port completes before returning. We do this by acquiring and
1159 * releasing the locks of the response queues associated with the port.
1160 */
1161static void t3_synchronize_rx(struct adapter *adap, const struct port_info *p)
1162{
1163 int i;
1164
1165 for (i = p->first_qset; i < p->first_qset + p->nqsets; i++) {
1166 struct sge_rspq *q = &adap->sge.qs[i].rspq;
1167
1168 spin_lock_irq(&q->lock);
1169 spin_unlock_irq(&q->lock);
1170 }
1171}
1172
1173static void cxgb_vlan_mode(struct net_device *dev, netdev_features_t features)
1174{
1175 struct port_info *pi = netdev_priv(dev);
1176 struct adapter *adapter = pi->adapter;
1177
1178 if (adapter->params.rev > 0) {
1179 t3_set_vlan_accel(adapter, 1 << pi->port_id,
1180 features & NETIF_F_HW_VLAN_RX);
1181 } else {
1182 /* single control for all ports */
1183 unsigned int i, have_vlans = features & NETIF_F_HW_VLAN_RX;
1184
1185 for_each_port(adapter, i)
1186 have_vlans |=
1187 adapter->port[i]->features & NETIF_F_HW_VLAN_RX;
1188
1189 t3_set_vlan_accel(adapter, 1, have_vlans);
1190 }
1191 t3_synchronize_rx(adapter, pi);
1192}
1193
1194/**
1153 * cxgb_up - enable the adapter 1195 * cxgb_up - enable the adapter
1154 * @adapter: adapter being enabled 1196 * @adapter: adapter being enabled
1155 * 1197 *
@@ -1161,7 +1203,7 @@ release_tpsram:
1161 */ 1203 */
1162static int cxgb_up(struct adapter *adap) 1204static int cxgb_up(struct adapter *adap)
1163{ 1205{
1164 int err; 1206 int i, err;
1165 1207
1166 if (!(adap->flags & FULL_INIT_DONE)) { 1208 if (!(adap->flags & FULL_INIT_DONE)) {
1167 err = t3_check_fw_version(adap); 1209 err = t3_check_fw_version(adap);
@@ -1198,6 +1240,9 @@ static int cxgb_up(struct adapter *adap)
1198 if (err) 1240 if (err)
1199 goto out; 1241 goto out;
1200 1242
1243 for_each_port(adap, i)
1244 cxgb_vlan_mode(adap->port[i], adap->port[i]->features);
1245
1201 setup_rss(adap); 1246 setup_rss(adap);
1202 if (!(adap->flags & NAPI_INIT)) 1247 if (!(adap->flags & NAPI_INIT))
1203 init_napi(adap); 1248 init_napi(adap);
@@ -2508,48 +2553,6 @@ static int cxgb_set_mac_addr(struct net_device *dev, void *p)
2508 return 0; 2553 return 0;
2509} 2554}
2510 2555
2511/**
2512 * t3_synchronize_rx - wait for current Rx processing on a port to complete
2513 * @adap: the adapter
2514 * @p: the port
2515 *
2516 * Ensures that current Rx processing on any of the queues associated with
2517 * the given port completes before returning. We do this by acquiring and
2518 * releasing the locks of the response queues associated with the port.
2519 */
2520static void t3_synchronize_rx(struct adapter *adap, const struct port_info *p)
2521{
2522 int i;
2523
2524 for (i = p->first_qset; i < p->first_qset + p->nqsets; i++) {
2525 struct sge_rspq *q = &adap->sge.qs[i].rspq;
2526
2527 spin_lock_irq(&q->lock);
2528 spin_unlock_irq(&q->lock);
2529 }
2530}
2531
2532static void cxgb_vlan_mode(struct net_device *dev, netdev_features_t features)
2533{
2534 struct port_info *pi = netdev_priv(dev);
2535 struct adapter *adapter = pi->adapter;
2536
2537 if (adapter->params.rev > 0) {
2538 t3_set_vlan_accel(adapter, 1 << pi->port_id,
2539 features & NETIF_F_HW_VLAN_RX);
2540 } else {
2541 /* single control for all ports */
2542 unsigned int i, have_vlans = features & NETIF_F_HW_VLAN_RX;
2543
2544 for_each_port(adapter, i)
2545 have_vlans |=
2546 adapter->port[i]->features & NETIF_F_HW_VLAN_RX;
2547
2548 t3_set_vlan_accel(adapter, 1, have_vlans);
2549 }
2550 t3_synchronize_rx(adapter, pi);
2551}
2552
2553static netdev_features_t cxgb_fix_features(struct net_device *dev, 2556static netdev_features_t cxgb_fix_features(struct net_device *dev,
2554 netdev_features_t features) 2557 netdev_features_t features)
2555{ 2558{
@@ -3353,9 +3356,6 @@ static int __devinit init_one(struct pci_dev *pdev,
3353 err = sysfs_create_group(&adapter->port[0]->dev.kobj, 3356 err = sysfs_create_group(&adapter->port[0]->dev.kobj,
3354 &cxgb3_attr_group); 3357 &cxgb3_attr_group);
3355 3358
3356 for_each_port(adapter, i)
3357 cxgb_vlan_mode(adapter->port[i], adapter->port[i]->features);
3358
3359 print_port_info(adapter, ai); 3359 print_port_info(adapter, ai);
3360 return 0; 3360 return 0;
3361 3361
diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
index 05ff076af06d..b126b98065a9 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
@@ -2000,13 +2000,6 @@ static const struct ethtool_ops cxgb_ethtool_ops = {
2000/* 2000/*
2001 * debugfs support 2001 * debugfs support
2002 */ 2002 */
2003
2004static int mem_open(struct inode *inode, struct file *file)
2005{
2006 file->private_data = inode->i_private;
2007 return 0;
2008}
2009
2010static ssize_t mem_read(struct file *file, char __user *buf, size_t count, 2003static ssize_t mem_read(struct file *file, char __user *buf, size_t count,
2011 loff_t *ppos) 2004 loff_t *ppos)
2012{ 2005{
@@ -2050,7 +2043,7 @@ static ssize_t mem_read(struct file *file, char __user *buf, size_t count,
2050 2043
2051static const struct file_operations mem_debugfs_fops = { 2044static const struct file_operations mem_debugfs_fops = {
2052 .owner = THIS_MODULE, 2045 .owner = THIS_MODULE,
2053 .open = mem_open, 2046 .open = simple_open,
2054 .read = mem_read, 2047 .read = mem_read,
2055 .llseek = default_llseek, 2048 .llseek = default_llseek,
2056}; 2049};
diff --git a/drivers/net/ethernet/dlink/dl2k.c b/drivers/net/ethernet/dlink/dl2k.c
index b2dc2c81a147..2e09edb9cdf8 100644
--- a/drivers/net/ethernet/dlink/dl2k.c
+++ b/drivers/net/ethernet/dlink/dl2k.c
@@ -1259,55 +1259,21 @@ rio_ioctl (struct net_device *dev, struct ifreq *rq, int cmd)
1259{ 1259{
1260 int phy_addr; 1260 int phy_addr;
1261 struct netdev_private *np = netdev_priv(dev); 1261 struct netdev_private *np = netdev_priv(dev);
1262 struct mii_data *miidata = (struct mii_data *) &rq->ifr_ifru; 1262 struct mii_ioctl_data *miidata = if_mii(rq);
1263
1264 struct netdev_desc *desc;
1265 int i;
1266 1263
1267 phy_addr = np->phy_addr; 1264 phy_addr = np->phy_addr;
1268 switch (cmd) { 1265 switch (cmd) {
1269 case SIOCDEVPRIVATE: 1266 case SIOCGMIIPHY:
1270 break; 1267 miidata->phy_id = phy_addr;
1271
1272 case SIOCDEVPRIVATE + 1:
1273 miidata->out_value = mii_read (dev, phy_addr, miidata->reg_num);
1274 break; 1268 break;
1275 case SIOCDEVPRIVATE + 2: 1269 case SIOCGMIIREG:
1276 mii_write (dev, phy_addr, miidata->reg_num, miidata->in_value); 1270 miidata->val_out = mii_read (dev, phy_addr, miidata->reg_num);
1277 break; 1271 break;
1278 case SIOCDEVPRIVATE + 3: 1272 case SIOCSMIIREG:
1279 break; 1273 if (!capable(CAP_NET_ADMIN))
1280 case SIOCDEVPRIVATE + 4: 1274 return -EPERM;
1281 break; 1275 mii_write (dev, phy_addr, miidata->reg_num, miidata->val_in);
1282 case SIOCDEVPRIVATE + 5:
1283 netif_stop_queue (dev);
1284 break; 1276 break;
1285 case SIOCDEVPRIVATE + 6:
1286 netif_wake_queue (dev);
1287 break;
1288 case SIOCDEVPRIVATE + 7:
1289 printk
1290 ("tx_full=%x cur_tx=%lx old_tx=%lx cur_rx=%lx old_rx=%lx\n",
1291 netif_queue_stopped(dev), np->cur_tx, np->old_tx, np->cur_rx,
1292 np->old_rx);
1293 break;
1294 case SIOCDEVPRIVATE + 8:
1295 printk("TX ring:\n");
1296 for (i = 0; i < TX_RING_SIZE; i++) {
1297 desc = &np->tx_ring[i];
1298 printk
1299 ("%02x:cur:%08x next:%08x status:%08x frag1:%08x frag0:%08x",
1300 i,
1301 (u32) (np->tx_ring_dma + i * sizeof (*desc)),
1302 (u32)le64_to_cpu(desc->next_desc),
1303 (u32)le64_to_cpu(desc->status),
1304 (u32)(le64_to_cpu(desc->fraginfo) >> 32),
1305 (u32)le64_to_cpu(desc->fraginfo));
1306 printk ("\n");
1307 }
1308 printk ("\n");
1309 break;
1310
1311 default: 1277 default:
1312 return -EOPNOTSUPP; 1278 return -EOPNOTSUPP;
1313 } 1279 }
diff --git a/drivers/net/ethernet/dlink/dl2k.h b/drivers/net/ethernet/dlink/dl2k.h
index ba0adcafa55a..30c2da3de548 100644
--- a/drivers/net/ethernet/dlink/dl2k.h
+++ b/drivers/net/ethernet/dlink/dl2k.h
@@ -365,13 +365,6 @@ struct ioctl_data {
365 char *data; 365 char *data;
366}; 366};
367 367
368struct mii_data {
369 __u16 reserved;
370 __u16 reg_num;
371 __u16 in_value;
372 __u16 out_value;
373};
374
375/* The Rx and Tx buffer descriptors. */ 368/* The Rx and Tx buffer descriptors. */
376struct netdev_desc { 369struct netdev_desc {
377 __le64 next_desc; 370 __le64 next_desc;
diff --git a/drivers/net/ethernet/freescale/fsl_pq_mdio.c b/drivers/net/ethernet/freescale/fsl_pq_mdio.c
index 9eb815941df5..f7f0bf5d037b 100644
--- a/drivers/net/ethernet/freescale/fsl_pq_mdio.c
+++ b/drivers/net/ethernet/freescale/fsl_pq_mdio.c
@@ -356,13 +356,13 @@ static int fsl_pq_mdio_probe(struct platform_device *ofdev)
356 356
357 if (prop) 357 if (prop)
358 tbiaddr = *prop; 358 tbiaddr = *prop;
359 }
360 359
361 if (tbiaddr == -1) { 360 if (tbiaddr == -1) {
362 err = -EBUSY; 361 err = -EBUSY;
363 goto err_free_irqs; 362 goto err_free_irqs;
364 } else { 363 } else {
365 out_be32(tbipa, tbiaddr); 364 out_be32(tbipa, tbiaddr);
365 }
366 } 366 }
367 367
368 err = of_mdiobus_register(new_bus, np); 368 err = of_mdiobus_register(new_bus, np);
diff --git a/drivers/net/ethernet/freescale/ucc_geth.c b/drivers/net/ethernet/freescale/ucc_geth.c
index 4e3cd2f8debb..9ac14f804851 100644
--- a/drivers/net/ethernet/freescale/ucc_geth.c
+++ b/drivers/net/ethernet/freescale/ucc_geth.c
@@ -116,10 +116,10 @@ static struct ucc_geth_info ugeth_primary_info = {
116 .maxGroupAddrInHash = 4, 116 .maxGroupAddrInHash = 4,
117 .maxIndAddrInHash = 4, 117 .maxIndAddrInHash = 4,
118 .prel = 7, 118 .prel = 7,
119 .maxFrameLength = 1518, 119 .maxFrameLength = 1518+16, /* Add extra bytes for VLANs etc. */
120 .minFrameLength = 64, 120 .minFrameLength = 64,
121 .maxD1Length = 1520, 121 .maxD1Length = 1520+16, /* Add extra bytes for VLANs etc. */
122 .maxD2Length = 1520, 122 .maxD2Length = 1520+16, /* Add extra bytes for VLANs etc. */
123 .vlantype = 0x8100, 123 .vlantype = 0x8100,
124 .ecamptr = ((uint32_t) NULL), 124 .ecamptr = ((uint32_t) NULL),
125 .eventRegMask = UCCE_OTHER, 125 .eventRegMask = UCCE_OTHER,
@@ -3945,6 +3945,8 @@ static int ucc_geth_probe(struct platform_device* ofdev)
3945 } 3945 }
3946 3946
3947 if (max_speed == SPEED_1000) { 3947 if (max_speed == SPEED_1000) {
3948 unsigned int snums = qe_get_num_of_snums();
3949
3948 /* configure muram FIFOs for gigabit operation */ 3950 /* configure muram FIFOs for gigabit operation */
3949 ug_info->uf_info.urfs = UCC_GETH_URFS_GIGA_INIT; 3951 ug_info->uf_info.urfs = UCC_GETH_URFS_GIGA_INIT;
3950 ug_info->uf_info.urfet = UCC_GETH_URFET_GIGA_INIT; 3952 ug_info->uf_info.urfet = UCC_GETH_URFET_GIGA_INIT;
@@ -3954,11 +3956,11 @@ static int ucc_geth_probe(struct platform_device* ofdev)
3954 ug_info->uf_info.utftt = UCC_GETH_UTFTT_GIGA_INIT; 3956 ug_info->uf_info.utftt = UCC_GETH_UTFTT_GIGA_INIT;
3955 ug_info->numThreadsTx = UCC_GETH_NUM_OF_THREADS_4; 3957 ug_info->numThreadsTx = UCC_GETH_NUM_OF_THREADS_4;
3956 3958
3957 /* If QE's snum number is 46 which means we need to support 3959 /* If QE's snum number is 46/76 which means we need to support
3958 * 4 UECs at 1000Base-T simultaneously, we need to allocate 3960 * 4 UECs at 1000Base-T simultaneously, we need to allocate
3959 * more Threads to Rx. 3961 * more Threads to Rx.
3960 */ 3962 */
3961 if (qe_get_num_of_snums() == 46) 3963 if ((snums == 76) || (snums == 46))
3962 ug_info->numThreadsRx = UCC_GETH_NUM_OF_THREADS_6; 3964 ug_info->numThreadsRx = UCC_GETH_NUM_OF_THREADS_6;
3963 else 3965 else
3964 ug_info->numThreadsRx = UCC_GETH_NUM_OF_THREADS_4; 3966 ug_info->numThreadsRx = UCC_GETH_NUM_OF_THREADS_4;
diff --git a/drivers/net/ethernet/freescale/ucc_geth.h b/drivers/net/ethernet/freescale/ucc_geth.h
index 2e395a2566b8..f71b3e7b12de 100644
--- a/drivers/net/ethernet/freescale/ucc_geth.h
+++ b/drivers/net/ethernet/freescale/ucc_geth.h
@@ -877,7 +877,7 @@ struct ucc_geth_hardware_statistics {
877 877
878/* Driver definitions */ 878/* Driver definitions */
879#define TX_BD_RING_LEN 0x10 879#define TX_BD_RING_LEN 0x10
880#define RX_BD_RING_LEN 0x10 880#define RX_BD_RING_LEN 0x20
881 881
882#define TX_RING_MOD_MASK(size) (size-1) 882#define TX_RING_MOD_MASK(size) (size-1)
883#define RX_RING_MOD_MASK(size) (size-1) 883#define RX_RING_MOD_MASK(size) (size-1)
diff --git a/drivers/net/ethernet/ibm/ehea/ehea_main.c b/drivers/net/ethernet/ibm/ehea/ehea_main.c
index 3516e17a399d..f4d2da0db1b1 100644
--- a/drivers/net/ethernet/ibm/ehea/ehea_main.c
+++ b/drivers/net/ethernet/ibm/ehea/ehea_main.c
@@ -290,16 +290,18 @@ static void ehea_update_bcmc_registrations(void)
290 290
291 arr[i].adh = adapter->handle; 291 arr[i].adh = adapter->handle;
292 arr[i].port_id = port->logical_port_id; 292 arr[i].port_id = port->logical_port_id;
293 arr[i].reg_type = EHEA_BCMC_SCOPE_ALL | 293 arr[i].reg_type = EHEA_BCMC_MULTICAST |
294 EHEA_BCMC_MULTICAST |
295 EHEA_BCMC_UNTAGGED; 294 EHEA_BCMC_UNTAGGED;
295 if (mc_entry->macaddr == 0)
296 arr[i].reg_type |= EHEA_BCMC_SCOPE_ALL;
296 arr[i++].macaddr = mc_entry->macaddr; 297 arr[i++].macaddr = mc_entry->macaddr;
297 298
298 arr[i].adh = adapter->handle; 299 arr[i].adh = adapter->handle;
299 arr[i].port_id = port->logical_port_id; 300 arr[i].port_id = port->logical_port_id;
300 arr[i].reg_type = EHEA_BCMC_SCOPE_ALL | 301 arr[i].reg_type = EHEA_BCMC_MULTICAST |
301 EHEA_BCMC_MULTICAST |
302 EHEA_BCMC_VLANID_ALL; 302 EHEA_BCMC_VLANID_ALL;
303 if (mc_entry->macaddr == 0)
304 arr[i].reg_type |= EHEA_BCMC_SCOPE_ALL;
303 arr[i++].macaddr = mc_entry->macaddr; 305 arr[i++].macaddr = mc_entry->macaddr;
304 num_registrations -= 2; 306 num_registrations -= 2;
305 } 307 }
@@ -1838,8 +1840,9 @@ static u64 ehea_multicast_reg_helper(struct ehea_port *port, u64 mc_mac_addr,
1838 u64 hret; 1840 u64 hret;
1839 u8 reg_type; 1841 u8 reg_type;
1840 1842
1841 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST 1843 reg_type = EHEA_BCMC_MULTICAST | EHEA_BCMC_UNTAGGED;
1842 | EHEA_BCMC_UNTAGGED; 1844 if (mc_mac_addr == 0)
1845 reg_type |= EHEA_BCMC_SCOPE_ALL;
1843 1846
1844 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle, 1847 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1845 port->logical_port_id, 1848 port->logical_port_id,
@@ -1847,8 +1850,9 @@ static u64 ehea_multicast_reg_helper(struct ehea_port *port, u64 mc_mac_addr,
1847 if (hret) 1850 if (hret)
1848 goto out; 1851 goto out;
1849 1852
1850 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST 1853 reg_type = EHEA_BCMC_MULTICAST | EHEA_BCMC_VLANID_ALL;
1851 | EHEA_BCMC_VLANID_ALL; 1854 if (mc_mac_addr == 0)
1855 reg_type |= EHEA_BCMC_SCOPE_ALL;
1852 1856
1853 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle, 1857 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1854 port->logical_port_id, 1858 port->logical_port_id,
@@ -1898,7 +1902,7 @@ static void ehea_allmulti(struct net_device *dev, int enable)
1898 netdev_err(dev, 1902 netdev_err(dev,
1899 "failed enabling IFF_ALLMULTI\n"); 1903 "failed enabling IFF_ALLMULTI\n");
1900 } 1904 }
1901 } else 1905 } else {
1902 if (!enable) { 1906 if (!enable) {
1903 /* Disable ALLMULTI */ 1907 /* Disable ALLMULTI */
1904 hret = ehea_multicast_reg_helper(port, 0, H_DEREG_BCMC); 1908 hret = ehea_multicast_reg_helper(port, 0, H_DEREG_BCMC);
@@ -1908,6 +1912,7 @@ static void ehea_allmulti(struct net_device *dev, int enable)
1908 netdev_err(dev, 1912 netdev_err(dev,
1909 "failed disabling IFF_ALLMULTI\n"); 1913 "failed disabling IFF_ALLMULTI\n");
1910 } 1914 }
1915 }
1911} 1916}
1912 1917
1913static void ehea_add_multicast_entry(struct ehea_port *port, u8 *mc_mac_addr) 1918static void ehea_add_multicast_entry(struct ehea_port *port, u8 *mc_mac_addr)
@@ -1941,11 +1946,7 @@ static void ehea_set_multicast_list(struct net_device *dev)
1941 struct netdev_hw_addr *ha; 1946 struct netdev_hw_addr *ha;
1942 int ret; 1947 int ret;
1943 1948
1944 if (port->promisc) { 1949 ehea_promiscuous(dev, !!(dev->flags & IFF_PROMISC));
1945 ehea_promiscuous(dev, 1);
1946 return;
1947 }
1948 ehea_promiscuous(dev, 0);
1949 1950
1950 if (dev->flags & IFF_ALLMULTI) { 1951 if (dev->flags & IFF_ALLMULTI) {
1951 ehea_allmulti(dev, 1); 1952 ehea_allmulti(dev, 1);
@@ -2463,6 +2464,7 @@ static int ehea_down(struct net_device *dev)
2463 return 0; 2464 return 0;
2464 2465
2465 ehea_drop_multicast_list(dev); 2466 ehea_drop_multicast_list(dev);
2467 ehea_allmulti(dev, 0);
2466 ehea_broadcast_reg_helper(port, H_DEREG_BCMC); 2468 ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
2467 2469
2468 ehea_free_interrupts(dev); 2470 ehea_free_interrupts(dev);
@@ -3261,6 +3263,7 @@ static int __devinit ehea_probe_adapter(struct platform_device *dev,
3261 struct ehea_adapter *adapter; 3263 struct ehea_adapter *adapter;
3262 const u64 *adapter_handle; 3264 const u64 *adapter_handle;
3263 int ret; 3265 int ret;
3266 int i;
3264 3267
3265 if (!dev || !dev->dev.of_node) { 3268 if (!dev || !dev->dev.of_node) {
3266 pr_err("Invalid ibmebus device probed\n"); 3269 pr_err("Invalid ibmebus device probed\n");
@@ -3314,17 +3317,9 @@ static int __devinit ehea_probe_adapter(struct platform_device *dev,
3314 tasklet_init(&adapter->neq_tasklet, ehea_neq_tasklet, 3317 tasklet_init(&adapter->neq_tasklet, ehea_neq_tasklet,
3315 (unsigned long)adapter); 3318 (unsigned long)adapter);
3316 3319
3317 ret = ibmebus_request_irq(adapter->neq->attr.ist1,
3318 ehea_interrupt_neq, IRQF_DISABLED,
3319 "ehea_neq", adapter);
3320 if (ret) {
3321 dev_err(&dev->dev, "requesting NEQ IRQ failed\n");
3322 goto out_kill_eq;
3323 }
3324
3325 ret = ehea_create_device_sysfs(dev); 3320 ret = ehea_create_device_sysfs(dev);
3326 if (ret) 3321 if (ret)
3327 goto out_free_irq; 3322 goto out_kill_eq;
3328 3323
3329 ret = ehea_setup_ports(adapter); 3324 ret = ehea_setup_ports(adapter);
3330 if (ret) { 3325 if (ret) {
@@ -3332,15 +3327,30 @@ static int __devinit ehea_probe_adapter(struct platform_device *dev,
3332 goto out_rem_dev_sysfs; 3327 goto out_rem_dev_sysfs;
3333 } 3328 }
3334 3329
3330 ret = ibmebus_request_irq(adapter->neq->attr.ist1,
3331 ehea_interrupt_neq, IRQF_DISABLED,
3332 "ehea_neq", adapter);
3333 if (ret) {
3334 dev_err(&dev->dev, "requesting NEQ IRQ failed\n");
3335 goto out_shutdown_ports;
3336 }
3337
3338 /* Handle any events that might be pending. */
3339 tasklet_hi_schedule(&adapter->neq_tasklet);
3340
3335 ret = 0; 3341 ret = 0;
3336 goto out; 3342 goto out;
3337 3343
3344out_shutdown_ports:
3345 for (i = 0; i < EHEA_MAX_PORTS; i++)
3346 if (adapter->port[i]) {
3347 ehea_shutdown_single_port(adapter->port[i]);
3348 adapter->port[i] = NULL;
3349 }
3350
3338out_rem_dev_sysfs: 3351out_rem_dev_sysfs:
3339 ehea_remove_device_sysfs(dev); 3352 ehea_remove_device_sysfs(dev);
3340 3353
3341out_free_irq:
3342 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
3343
3344out_kill_eq: 3354out_kill_eq:
3345 ehea_destroy_eq(adapter->neq); 3355 ehea_destroy_eq(adapter->neq);
3346 3356
diff --git a/drivers/net/ethernet/ibm/ehea/ehea_phyp.h b/drivers/net/ethernet/ibm/ehea/ehea_phyp.h
index 52c456ec4d6c..8364815c32ff 100644
--- a/drivers/net/ethernet/ibm/ehea/ehea_phyp.h
+++ b/drivers/net/ethernet/ibm/ehea/ehea_phyp.h
@@ -450,7 +450,7 @@ u64 ehea_h_modify_ehea_port(const u64 adapter_handle, const u16 port_num,
450 void *cb_addr); 450 void *cb_addr);
451 451
452#define H_REGBCMC_PN EHEA_BMASK_IBM(48, 63) 452#define H_REGBCMC_PN EHEA_BMASK_IBM(48, 63)
453#define H_REGBCMC_REGTYPE EHEA_BMASK_IBM(61, 63) 453#define H_REGBCMC_REGTYPE EHEA_BMASK_IBM(60, 63)
454#define H_REGBCMC_MACADDR EHEA_BMASK_IBM(16, 63) 454#define H_REGBCMC_MACADDR EHEA_BMASK_IBM(16, 63)
455#define H_REGBCMC_VLANID EHEA_BMASK_IBM(52, 63) 455#define H_REGBCMC_VLANID EHEA_BMASK_IBM(52, 63)
456 456
diff --git a/drivers/net/ethernet/intel/e1000/e1000_main.c b/drivers/net/ethernet/intel/e1000/e1000_main.c
index 0e9aec8f6917..37caa8885c2a 100644
--- a/drivers/net/ethernet/intel/e1000/e1000_main.c
+++ b/drivers/net/ethernet/intel/e1000/e1000_main.c
@@ -164,6 +164,8 @@ static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
164static bool e1000_vlan_used(struct e1000_adapter *adapter); 164static bool e1000_vlan_used(struct e1000_adapter *adapter);
165static void e1000_vlan_mode(struct net_device *netdev, 165static void e1000_vlan_mode(struct net_device *netdev,
166 netdev_features_t features); 166 netdev_features_t features);
167static void e1000_vlan_filter_on_off(struct e1000_adapter *adapter,
168 bool filter_on);
167static int e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid); 169static int e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid);
168static int e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid); 170static int e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid);
169static void e1000_restore_vlan(struct e1000_adapter *adapter); 171static void e1000_restore_vlan(struct e1000_adapter *adapter);
@@ -215,7 +217,8 @@ MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
215MODULE_LICENSE("GPL"); 217MODULE_LICENSE("GPL");
216MODULE_VERSION(DRV_VERSION); 218MODULE_VERSION(DRV_VERSION);
217 219
218static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE; 220#define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
221static int debug = -1;
219module_param(debug, int, 0); 222module_param(debug, int, 0);
220MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); 223MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
221 224
@@ -979,7 +982,7 @@ static int __devinit e1000_probe(struct pci_dev *pdev,
979 adapter = netdev_priv(netdev); 982 adapter = netdev_priv(netdev);
980 adapter->netdev = netdev; 983 adapter->netdev = netdev;
981 adapter->pdev = pdev; 984 adapter->pdev = pdev;
982 adapter->msg_enable = (1 << debug) - 1; 985 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
983 adapter->bars = bars; 986 adapter->bars = bars;
984 adapter->need_ioport = need_ioport; 987 adapter->need_ioport = need_ioport;
985 988
@@ -1214,7 +1217,7 @@ static int __devinit e1000_probe(struct pci_dev *pdev,
1214 if (err) 1217 if (err)
1215 goto err_register; 1218 goto err_register;
1216 1219
1217 e1000_vlan_mode(netdev, netdev->features); 1220 e1000_vlan_filter_on_off(adapter, false);
1218 1221
1219 /* print bus type/speed/width info */ 1222 /* print bus type/speed/width info */
1220 e_info(probe, "(PCI%s:%dMHz:%d-bit) %pM\n", 1223 e_info(probe, "(PCI%s:%dMHz:%d-bit) %pM\n",
@@ -3377,7 +3380,7 @@ static void e1000_dump(struct e1000_adapter *adapter)
3377 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) { 3380 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
3378 struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*tx_ring, i); 3381 struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*tx_ring, i);
3379 struct e1000_buffer *buffer_info = &tx_ring->buffer_info[i]; 3382 struct e1000_buffer *buffer_info = &tx_ring->buffer_info[i];
3380 struct my_u { u64 a; u64 b; }; 3383 struct my_u { __le64 a; __le64 b; };
3381 struct my_u *u = (struct my_u *)tx_desc; 3384 struct my_u *u = (struct my_u *)tx_desc;
3382 const char *type; 3385 const char *type;
3383 3386
@@ -3421,7 +3424,7 @@ rx_ring_summary:
3421 for (i = 0; rx_ring->desc && (i < rx_ring->count); i++) { 3424 for (i = 0; rx_ring->desc && (i < rx_ring->count); i++) {
3422 struct e1000_rx_desc *rx_desc = E1000_RX_DESC(*rx_ring, i); 3425 struct e1000_rx_desc *rx_desc = E1000_RX_DESC(*rx_ring, i);
3423 struct e1000_buffer *buffer_info = &rx_ring->buffer_info[i]; 3426 struct e1000_buffer *buffer_info = &rx_ring->buffer_info[i];
3424 struct my_u { u64 a; u64 b; }; 3427 struct my_u { __le64 a; __le64 b; };
3425 struct my_u *u = (struct my_u *)rx_desc; 3428 struct my_u *u = (struct my_u *)rx_desc;
3426 const char *type; 3429 const char *type;
3427 3430
@@ -4770,6 +4773,22 @@ static bool e1000_vlan_used(struct e1000_adapter *adapter)
4770 return false; 4773 return false;
4771} 4774}
4772 4775
4776static void __e1000_vlan_mode(struct e1000_adapter *adapter,
4777 netdev_features_t features)
4778{
4779 struct e1000_hw *hw = &adapter->hw;
4780 u32 ctrl;
4781
4782 ctrl = er32(CTRL);
4783 if (features & NETIF_F_HW_VLAN_RX) {
4784 /* enable VLAN tag insert/strip */
4785 ctrl |= E1000_CTRL_VME;
4786 } else {
4787 /* disable VLAN tag insert/strip */
4788 ctrl &= ~E1000_CTRL_VME;
4789 }
4790 ew32(CTRL, ctrl);
4791}
4773static void e1000_vlan_filter_on_off(struct e1000_adapter *adapter, 4792static void e1000_vlan_filter_on_off(struct e1000_adapter *adapter,
4774 bool filter_on) 4793 bool filter_on)
4775{ 4794{
@@ -4779,6 +4798,7 @@ static void e1000_vlan_filter_on_off(struct e1000_adapter *adapter,
4779 if (!test_bit(__E1000_DOWN, &adapter->flags)) 4798 if (!test_bit(__E1000_DOWN, &adapter->flags))
4780 e1000_irq_disable(adapter); 4799 e1000_irq_disable(adapter);
4781 4800
4801 __e1000_vlan_mode(adapter, adapter->netdev->features);
4782 if (filter_on) { 4802 if (filter_on) {
4783 /* enable VLAN receive filtering */ 4803 /* enable VLAN receive filtering */
4784 rctl = er32(RCTL); 4804 rctl = er32(RCTL);
@@ -4799,24 +4819,14 @@ static void e1000_vlan_filter_on_off(struct e1000_adapter *adapter,
4799} 4819}
4800 4820
4801static void e1000_vlan_mode(struct net_device *netdev, 4821static void e1000_vlan_mode(struct net_device *netdev,
4802 netdev_features_t features) 4822 netdev_features_t features)
4803{ 4823{
4804 struct e1000_adapter *adapter = netdev_priv(netdev); 4824 struct e1000_adapter *adapter = netdev_priv(netdev);
4805 struct e1000_hw *hw = &adapter->hw;
4806 u32 ctrl;
4807 4825
4808 if (!test_bit(__E1000_DOWN, &adapter->flags)) 4826 if (!test_bit(__E1000_DOWN, &adapter->flags))
4809 e1000_irq_disable(adapter); 4827 e1000_irq_disable(adapter);
4810 4828
4811 ctrl = er32(CTRL); 4829 __e1000_vlan_mode(adapter, features);
4812 if (features & NETIF_F_HW_VLAN_RX) {
4813 /* enable VLAN tag insert/strip */
4814 ctrl |= E1000_CTRL_VME;
4815 } else {
4816 /* disable VLAN tag insert/strip */
4817 ctrl &= ~E1000_CTRL_VME;
4818 }
4819 ew32(CTRL, ctrl);
4820 4830
4821 if (!test_bit(__E1000_DOWN, &adapter->flags)) 4831 if (!test_bit(__E1000_DOWN, &adapter->flags))
4822 e1000_irq_enable(adapter); 4832 e1000_irq_enable(adapter);
diff --git a/drivers/net/ethernet/intel/e1000e/e1000.h b/drivers/net/ethernet/intel/e1000e/e1000.h
index 86cdd4793992..b83897f76ee3 100644
--- a/drivers/net/ethernet/intel/e1000e/e1000.h
+++ b/drivers/net/ethernet/intel/e1000e/e1000.h
@@ -161,6 +161,12 @@ struct e1000_info;
161/* Time to wait before putting the device into D3 if there's no link (in ms). */ 161/* Time to wait before putting the device into D3 if there's no link (in ms). */
162#define LINK_TIMEOUT 100 162#define LINK_TIMEOUT 100
163 163
164/*
165 * Count for polling __E1000_RESET condition every 10-20msec.
166 * Experimentation has shown the reset can take approximately 210msec.
167 */
168#define E1000_CHECK_RESET_COUNT 25
169
164#define DEFAULT_RDTR 0 170#define DEFAULT_RDTR 0
165#define DEFAULT_RADV 8 171#define DEFAULT_RADV 8
166#define BURST_RDTR 0x20 172#define BURST_RDTR 0x20
diff --git a/drivers/net/ethernet/intel/e1000e/ich8lan.c b/drivers/net/ethernet/intel/e1000e/ich8lan.c
index 64c76443a7aa..b461c24945e3 100644
--- a/drivers/net/ethernet/intel/e1000e/ich8lan.c
+++ b/drivers/net/ethernet/intel/e1000e/ich8lan.c
@@ -1310,10 +1310,6 @@ static s32 e1000_oem_bits_config_ich8lan(struct e1000_hw *hw, bool d0_state)
1310 1310
1311 if (mac_reg & E1000_PHY_CTRL_D0A_LPLU) 1311 if (mac_reg & E1000_PHY_CTRL_D0A_LPLU)
1312 oem_reg |= HV_OEM_BITS_LPLU; 1312 oem_reg |= HV_OEM_BITS_LPLU;
1313
1314 /* Set Restart auto-neg to activate the bits */
1315 if (!hw->phy.ops.check_reset_block(hw))
1316 oem_reg |= HV_OEM_BITS_RESTART_AN;
1317 } else { 1313 } else {
1318 if (mac_reg & (E1000_PHY_CTRL_GBE_DISABLE | 1314 if (mac_reg & (E1000_PHY_CTRL_GBE_DISABLE |
1319 E1000_PHY_CTRL_NOND0A_GBE_DISABLE)) 1315 E1000_PHY_CTRL_NOND0A_GBE_DISABLE))
@@ -1324,6 +1320,11 @@ static s32 e1000_oem_bits_config_ich8lan(struct e1000_hw *hw, bool d0_state)
1324 oem_reg |= HV_OEM_BITS_LPLU; 1320 oem_reg |= HV_OEM_BITS_LPLU;
1325 } 1321 }
1326 1322
1323 /* Set Restart auto-neg to activate the bits */
1324 if ((d0_state || (hw->mac.type != e1000_pchlan)) &&
1325 !hw->phy.ops.check_reset_block(hw))
1326 oem_reg |= HV_OEM_BITS_RESTART_AN;
1327
1327 ret_val = hw->phy.ops.write_reg_locked(hw, HV_OEM_BITS, oem_reg); 1328 ret_val = hw->phy.ops.write_reg_locked(hw, HV_OEM_BITS, oem_reg);
1328 1329
1329release: 1330release:
@@ -3682,7 +3683,11 @@ void e1000_suspend_workarounds_ich8lan(struct e1000_hw *hw)
3682 3683
3683 if (hw->mac.type >= e1000_pchlan) { 3684 if (hw->mac.type >= e1000_pchlan) {
3684 e1000_oem_bits_config_ich8lan(hw, false); 3685 e1000_oem_bits_config_ich8lan(hw, false);
3685 e1000_phy_hw_reset_ich8lan(hw); 3686
3687 /* Reset PHY to activate OEM bits on 82577/8 */
3688 if (hw->mac.type == e1000_pchlan)
3689 e1000e_phy_hw_reset_generic(hw);
3690
3686 ret_val = hw->phy.ops.acquire(hw); 3691 ret_val = hw->phy.ops.acquire(hw);
3687 if (ret_val) 3692 if (ret_val)
3688 return; 3693 return;
diff --git a/drivers/net/ethernet/intel/e1000e/netdev.c b/drivers/net/ethernet/intel/e1000e/netdev.c
index 7152eb11b7b9..9520a6ac1f30 100644
--- a/drivers/net/ethernet/intel/e1000e/netdev.c
+++ b/drivers/net/ethernet/intel/e1000e/netdev.c
@@ -60,6 +60,11 @@
60char e1000e_driver_name[] = "e1000e"; 60char e1000e_driver_name[] = "e1000e";
61const char e1000e_driver_version[] = DRV_VERSION; 61const char e1000e_driver_version[] = DRV_VERSION;
62 62
63#define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
64static int debug = -1;
65module_param(debug, int, 0);
66MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
67
63static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state); 68static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state);
64 69
65static const struct e1000_info *e1000_info_tbl[] = { 70static const struct e1000_info *e1000_info_tbl[] = {
@@ -1054,6 +1059,13 @@ static void e1000_print_hw_hang(struct work_struct *work)
1054 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD); 1059 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
1055 /* execute the writes immediately */ 1060 /* execute the writes immediately */
1056 e1e_flush(); 1061 e1e_flush();
1062 /*
1063 * Due to rare timing issues, write to TIDV again to ensure
1064 * the write is successful
1065 */
1066 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
1067 /* execute the writes immediately */
1068 e1e_flush();
1057 adapter->tx_hang_recheck = true; 1069 adapter->tx_hang_recheck = true;
1058 return; 1070 return;
1059 } 1071 }
@@ -3611,6 +3623,16 @@ static void e1000e_flush_descriptors(struct e1000_adapter *adapter)
3611 3623
3612 /* execute the writes immediately */ 3624 /* execute the writes immediately */
3613 e1e_flush(); 3625 e1e_flush();
3626
3627 /*
3628 * due to rare timing issues, write to TIDV/RDTR again to ensure the
3629 * write is successful
3630 */
3631 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3632 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3633
3634 /* execute the writes immediately */
3635 e1e_flush();
3614} 3636}
3615 3637
3616static void e1000e_update_stats(struct e1000_adapter *adapter); 3638static void e1000e_update_stats(struct e1000_adapter *adapter);
@@ -3777,7 +3799,7 @@ static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
3777 /* fire an unusual interrupt on the test handler */ 3799 /* fire an unusual interrupt on the test handler */
3778 ew32(ICS, E1000_ICS_RXSEQ); 3800 ew32(ICS, E1000_ICS_RXSEQ);
3779 e1e_flush(); 3801 e1e_flush();
3780 msleep(50); 3802 msleep(100);
3781 3803
3782 e1000_irq_disable(adapter); 3804 e1000_irq_disable(adapter);
3783 3805
@@ -3963,6 +3985,10 @@ static int e1000_close(struct net_device *netdev)
3963{ 3985{
3964 struct e1000_adapter *adapter = netdev_priv(netdev); 3986 struct e1000_adapter *adapter = netdev_priv(netdev);
3965 struct pci_dev *pdev = adapter->pdev; 3987 struct pci_dev *pdev = adapter->pdev;
3988 int count = E1000_CHECK_RESET_COUNT;
3989
3990 while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
3991 usleep_range(10000, 20000);
3966 3992
3967 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state)); 3993 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
3968 3994
@@ -5467,6 +5493,11 @@ static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake,
5467 netif_device_detach(netdev); 5493 netif_device_detach(netdev);
5468 5494
5469 if (netif_running(netdev)) { 5495 if (netif_running(netdev)) {
5496 int count = E1000_CHECK_RESET_COUNT;
5497
5498 while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
5499 usleep_range(10000, 20000);
5500
5470 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state)); 5501 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
5471 e1000e_down(adapter); 5502 e1000e_down(adapter);
5472 e1000_free_irq(adapter); 5503 e1000_free_irq(adapter);
@@ -6172,7 +6203,7 @@ static int __devinit e1000_probe(struct pci_dev *pdev,
6172 adapter->hw.adapter = adapter; 6203 adapter->hw.adapter = adapter;
6173 adapter->hw.mac.type = ei->mac; 6204 adapter->hw.mac.type = ei->mac;
6174 adapter->max_hw_frame_size = ei->max_hw_frame_size; 6205 adapter->max_hw_frame_size = ei->max_hw_frame_size;
6175 adapter->msg_enable = (1 << NETIF_MSG_DRV | NETIF_MSG_PROBE) - 1; 6206 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
6176 6207
6177 mmio_start = pci_resource_start(pdev, 0); 6208 mmio_start = pci_resource_start(pdev, 0);
6178 mmio_len = pci_resource_len(pdev, 0); 6209 mmio_len = pci_resource_len(pdev, 0);
diff --git a/drivers/net/ethernet/intel/e1000e/param.c b/drivers/net/ethernet/intel/e1000e/param.c
index ff796e42c3eb..16adeb9418a8 100644
--- a/drivers/net/ethernet/intel/e1000e/param.c
+++ b/drivers/net/ethernet/intel/e1000e/param.c
@@ -106,7 +106,7 @@ E1000_PARAM(RxAbsIntDelay, "Receive Absolute Interrupt Delay");
106/* 106/*
107 * Interrupt Throttle Rate (interrupts/sec) 107 * Interrupt Throttle Rate (interrupts/sec)
108 * 108 *
109 * Valid Range: 100-100000 (0=off, 1=dynamic, 3=dynamic conservative) 109 * Valid Range: 100-100000 or one of: 0=off, 1=dynamic, 3=dynamic conservative
110 */ 110 */
111E1000_PARAM(InterruptThrottleRate, "Interrupt Throttling Rate"); 111E1000_PARAM(InterruptThrottleRate, "Interrupt Throttling Rate");
112#define DEFAULT_ITR 3 112#define DEFAULT_ITR 3
@@ -344,53 +344,60 @@ void __devinit e1000e_check_options(struct e1000_adapter *adapter)
344 344
345 if (num_InterruptThrottleRate > bd) { 345 if (num_InterruptThrottleRate > bd) {
346 adapter->itr = InterruptThrottleRate[bd]; 346 adapter->itr = InterruptThrottleRate[bd];
347 switch (adapter->itr) { 347
348 case 0: 348 /*
349 e_info("%s turned off\n", opt.name); 349 * Make sure a message is printed for non-special
350 break; 350 * values. And in case of an invalid option, display
351 case 1: 351 * warning, use default and got through itr/itr_setting
352 e_info("%s set to dynamic mode\n", opt.name); 352 * adjustment logic below
353 adapter->itr_setting = adapter->itr; 353 */
354 adapter->itr = 20000; 354 if ((adapter->itr > 4) &&
355 break; 355 e1000_validate_option(&adapter->itr, &opt, adapter))
356 case 3: 356 adapter->itr = opt.def;
357 e_info("%s set to dynamic conservative mode\n",
358 opt.name);
359 adapter->itr_setting = adapter->itr;
360 adapter->itr = 20000;
361 break;
362 case 4:
363 e_info("%s set to simplified (2000-8000 ints) "
364 "mode\n", opt.name);
365 adapter->itr_setting = 4;
366 break;
367 default:
368 /*
369 * Save the setting, because the dynamic bits
370 * change itr.
371 */
372 if (e1000_validate_option(&adapter->itr, &opt,
373 adapter) &&
374 (adapter->itr == 3)) {
375 /*
376 * In case of invalid user value,
377 * default to conservative mode.
378 */
379 adapter->itr_setting = adapter->itr;
380 adapter->itr = 20000;
381 } else {
382 /*
383 * Clear the lower two bits because
384 * they are used as control.
385 */
386 adapter->itr_setting =
387 adapter->itr & ~3;
388 }
389 break;
390 }
391 } else { 357 } else {
392 adapter->itr_setting = opt.def; 358 /*
359 * If no option specified, use default value and go
360 * through the logic below to adjust itr/itr_setting
361 */
362 adapter->itr = opt.def;
363
364 /*
365 * Make sure a message is printed for non-special
366 * default values
367 */
368 if (adapter->itr > 40)
369 e_info("%s set to default %d\n", opt.name,
370 adapter->itr);
371 }
372
373 adapter->itr_setting = adapter->itr;
374 switch (adapter->itr) {
375 case 0:
376 e_info("%s turned off\n", opt.name);
377 break;
378 case 1:
379 e_info("%s set to dynamic mode\n", opt.name);
380 adapter->itr = 20000;
381 break;
382 case 3:
383 e_info("%s set to dynamic conservative mode\n",
384 opt.name);
393 adapter->itr = 20000; 385 adapter->itr = 20000;
386 break;
387 case 4:
388 e_info("%s set to simplified (2000-8000 ints) mode\n",
389 opt.name);
390 break;
391 default:
392 /*
393 * Save the setting, because the dynamic bits
394 * change itr.
395 *
396 * Clear the lower two bits because
397 * they are used as control.
398 */
399 adapter->itr_setting &= ~3;
400 break;
394 } 401 }
395 } 402 }
396 { /* Interrupt Mode */ 403 { /* Interrupt Mode */
diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
index c4902411d749..8683ca4748c8 100644
--- a/drivers/net/ethernet/intel/igb/igb_main.c
+++ b/drivers/net/ethernet/intel/igb/igb_main.c
@@ -238,6 +238,11 @@ MODULE_DESCRIPTION("Intel(R) Gigabit Ethernet Network Driver");
238MODULE_LICENSE("GPL"); 238MODULE_LICENSE("GPL");
239MODULE_VERSION(DRV_VERSION); 239MODULE_VERSION(DRV_VERSION);
240 240
241#define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
242static int debug = -1;
243module_param(debug, int, 0);
244MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
245
241struct igb_reg_info { 246struct igb_reg_info {
242 u32 ofs; 247 u32 ofs;
243 char *name; 248 char *name;
@@ -1106,9 +1111,12 @@ msi_only:
1106 adapter->flags |= IGB_FLAG_HAS_MSI; 1111 adapter->flags |= IGB_FLAG_HAS_MSI;
1107out: 1112out:
1108 /* Notify the stack of the (possibly) reduced queue counts. */ 1113 /* Notify the stack of the (possibly) reduced queue counts. */
1114 rtnl_lock();
1109 netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues); 1115 netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues);
1110 return netif_set_real_num_rx_queues(adapter->netdev, 1116 err = netif_set_real_num_rx_queues(adapter->netdev,
1111 adapter->num_rx_queues); 1117 adapter->num_rx_queues);
1118 rtnl_unlock();
1119 return err;
1112} 1120}
1113 1121
1114/** 1122/**
@@ -1893,7 +1901,7 @@ static int __devinit igb_probe(struct pci_dev *pdev,
1893 adapter->pdev = pdev; 1901 adapter->pdev = pdev;
1894 hw = &adapter->hw; 1902 hw = &adapter->hw;
1895 hw->back = adapter; 1903 hw->back = adapter;
1896 adapter->msg_enable = NETIF_MSG_DRV | NETIF_MSG_PROBE; 1904 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
1897 1905
1898 mmio_start = pci_resource_start(pdev, 0); 1906 mmio_start = pci_resource_start(pdev, 0);
1899 mmio_len = pci_resource_len(pdev, 0); 1907 mmio_len = pci_resource_len(pdev, 0);
@@ -2766,8 +2774,6 @@ void igb_configure_tx_ring(struct igb_adapter *adapter,
2766 2774
2767 txdctl |= E1000_TXDCTL_QUEUE_ENABLE; 2775 txdctl |= E1000_TXDCTL_QUEUE_ENABLE;
2768 wr32(E1000_TXDCTL(reg_idx), txdctl); 2776 wr32(E1000_TXDCTL(reg_idx), txdctl);
2769
2770 netdev_tx_reset_queue(txring_txq(ring));
2771} 2777}
2772 2778
2773/** 2779/**
@@ -3277,6 +3283,8 @@ static void igb_clean_tx_ring(struct igb_ring *tx_ring)
3277 igb_unmap_and_free_tx_resource(tx_ring, buffer_info); 3283 igb_unmap_and_free_tx_resource(tx_ring, buffer_info);
3278 } 3284 }
3279 3285
3286 netdev_tx_reset_queue(txring_txq(tx_ring));
3287
3280 size = sizeof(struct igb_tx_buffer) * tx_ring->count; 3288 size = sizeof(struct igb_tx_buffer) * tx_ring->count;
3281 memset(tx_ring->tx_buffer_info, 0, size); 3289 memset(tx_ring->tx_buffer_info, 0, size);
3282 3290
@@ -6791,18 +6799,7 @@ static int igb_resume(struct device *dev)
6791 pci_enable_wake(pdev, PCI_D3hot, 0); 6799 pci_enable_wake(pdev, PCI_D3hot, 0);
6792 pci_enable_wake(pdev, PCI_D3cold, 0); 6800 pci_enable_wake(pdev, PCI_D3cold, 0);
6793 6801
6794 if (!rtnl_is_locked()) { 6802 if (igb_init_interrupt_scheme(adapter)) {
6795 /*
6796 * shut up ASSERT_RTNL() warning in
6797 * netif_set_real_num_tx/rx_queues.
6798 */
6799 rtnl_lock();
6800 err = igb_init_interrupt_scheme(adapter);
6801 rtnl_unlock();
6802 } else {
6803 err = igb_init_interrupt_scheme(adapter);
6804 }
6805 if (err) {
6806 dev_err(&pdev->dev, "Unable to allocate memory for queues\n"); 6803 dev_err(&pdev->dev, "Unable to allocate memory for queues\n");
6807 return -ENOMEM; 6804 return -ENOMEM;
6808 } 6805 }
diff --git a/drivers/net/ethernet/intel/igbvf/netdev.c b/drivers/net/ethernet/intel/igbvf/netdev.c
index 217c143686d2..8ec74b07f940 100644
--- a/drivers/net/ethernet/intel/igbvf/netdev.c
+++ b/drivers/net/ethernet/intel/igbvf/netdev.c
@@ -55,6 +55,11 @@ static const char igbvf_driver_string[] =
55static const char igbvf_copyright[] = 55static const char igbvf_copyright[] =
56 "Copyright (c) 2009 - 2012 Intel Corporation."; 56 "Copyright (c) 2009 - 2012 Intel Corporation.";
57 57
58#define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
59static int debug = -1;
60module_param(debug, int, 0);
61MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
62
58static int igbvf_poll(struct napi_struct *napi, int budget); 63static int igbvf_poll(struct napi_struct *napi, int budget);
59static void igbvf_reset(struct igbvf_adapter *); 64static void igbvf_reset(struct igbvf_adapter *);
60static void igbvf_set_interrupt_capability(struct igbvf_adapter *); 65static void igbvf_set_interrupt_capability(struct igbvf_adapter *);
@@ -2649,7 +2654,7 @@ static int __devinit igbvf_probe(struct pci_dev *pdev,
2649 adapter->flags = ei->flags; 2654 adapter->flags = ei->flags;
2650 adapter->hw.back = adapter; 2655 adapter->hw.back = adapter;
2651 adapter->hw.mac.type = ei->mac; 2656 adapter->hw.mac.type = ei->mac;
2652 adapter->msg_enable = (1 << NETIF_MSG_DRV | NETIF_MSG_PROBE) - 1; 2657 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
2653 2658
2654 /* PCI config space info */ 2659 /* PCI config space info */
2655 2660
@@ -2726,14 +2731,14 @@ static int __devinit igbvf_probe(struct pci_dev *pdev,
2726 netdev->addr_len); 2731 netdev->addr_len);
2727 } 2732 }
2728 2733
2729 if (!is_valid_ether_addr(netdev->perm_addr)) { 2734 if (!is_valid_ether_addr(netdev->dev_addr)) {
2730 dev_err(&pdev->dev, "Invalid MAC Address: %pM\n", 2735 dev_err(&pdev->dev, "Invalid MAC Address: %pM\n",
2731 netdev->dev_addr); 2736 netdev->dev_addr);
2732 err = -EIO; 2737 err = -EIO;
2733 goto err_hw_init; 2738 goto err_hw_init;
2734 } 2739 }
2735 2740
2736 memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len); 2741 memcpy(netdev->perm_addr, netdev->dev_addr, netdev->addr_len);
2737 2742
2738 setup_timer(&adapter->watchdog_timer, &igbvf_watchdog, 2743 setup_timer(&adapter->watchdog_timer, &igbvf_watchdog,
2739 (unsigned long) adapter); 2744 (unsigned long) adapter);
diff --git a/drivers/net/ethernet/intel/ixgb/ixgb_main.c b/drivers/net/ethernet/intel/ixgb/ixgb_main.c
index 82aaa792cbf3..5fce363d810a 100644
--- a/drivers/net/ethernet/intel/ixgb/ixgb_main.c
+++ b/drivers/net/ethernet/intel/ixgb/ixgb_main.c
@@ -134,8 +134,8 @@ MODULE_DESCRIPTION("Intel(R) PRO/10GbE Network Driver");
134MODULE_LICENSE("GPL"); 134MODULE_LICENSE("GPL");
135MODULE_VERSION(DRV_VERSION); 135MODULE_VERSION(DRV_VERSION);
136 136
137#define DEFAULT_DEBUG_LEVEL_SHIFT 3 137#define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
138static int debug = DEFAULT_DEBUG_LEVEL_SHIFT; 138static int debug = -1;
139module_param(debug, int, 0); 139module_param(debug, int, 0);
140MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); 140MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
141 141
@@ -442,7 +442,7 @@ ixgb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
442 adapter->netdev = netdev; 442 adapter->netdev = netdev;
443 adapter->pdev = pdev; 443 adapter->pdev = pdev;
444 adapter->hw.back = adapter; 444 adapter->hw.back = adapter;
445 adapter->msg_enable = netif_msg_init(debug, DEFAULT_DEBUG_LEVEL_SHIFT); 445 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
446 446
447 adapter->hw.hw_addr = pci_ioremap_bar(pdev, BAR_0); 447 adapter->hw.hw_addr = pci_ioremap_bar(pdev, BAR_0);
448 if (!adapter->hw.hw_addr) { 448 if (!adapter->hw.hw_addr) {
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe.h b/drivers/net/ethernet/intel/ixgbe/ixgbe.h
index 80e26ff30ebf..81b155589532 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe.h
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe.h
@@ -544,7 +544,7 @@ struct ixgbe_fdir_filter {
544 u16 action; 544 u16 action;
545}; 545};
546 546
547enum ixbge_state_t { 547enum ixgbe_state_t {
548 __IXGBE_TESTING, 548 __IXGBE_TESTING,
549 __IXGBE_RESETTING, 549 __IXGBE_RESETTING,
550 __IXGBE_DOWN, 550 __IXGBE_DOWN,
@@ -574,9 +574,6 @@ extern struct ixgbe_info ixgbe_82599_info;
574extern struct ixgbe_info ixgbe_X540_info; 574extern struct ixgbe_info ixgbe_X540_info;
575#ifdef CONFIG_IXGBE_DCB 575#ifdef CONFIG_IXGBE_DCB
576extern const struct dcbnl_rtnl_ops dcbnl_ops; 576extern const struct dcbnl_rtnl_ops dcbnl_ops;
577extern int ixgbe_copy_dcb_cfg(struct ixgbe_dcb_config *src_dcb_cfg,
578 struct ixgbe_dcb_config *dst_dcb_cfg,
579 int tc_max);
580#endif 577#endif
581 578
582extern char ixgbe_driver_name[]; 579extern char ixgbe_driver_name[];
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_dcb_nl.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_dcb_nl.c
index dde65f951400..32e5c02ff6d0 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_dcb_nl.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_dcb_nl.c
@@ -44,62 +44,102 @@
44#define DCB_NO_HW_CHG 1 /* DCB configuration did not change */ 44#define DCB_NO_HW_CHG 1 /* DCB configuration did not change */
45#define DCB_HW_CHG 2 /* DCB configuration changed, no reset */ 45#define DCB_HW_CHG 2 /* DCB configuration changed, no reset */
46 46
47int ixgbe_copy_dcb_cfg(struct ixgbe_dcb_config *src_dcb_cfg, 47static int ixgbe_copy_dcb_cfg(struct ixgbe_adapter *adapter, int tc_max)
48 struct ixgbe_dcb_config *dst_dcb_cfg, int tc_max)
49{ 48{
50 struct tc_configuration *src_tc_cfg = NULL; 49 struct ixgbe_dcb_config *scfg = &adapter->temp_dcb_cfg;
51 struct tc_configuration *dst_tc_cfg = NULL; 50 struct ixgbe_dcb_config *dcfg = &adapter->dcb_cfg;
52 int i; 51 struct tc_configuration *src = NULL;
52 struct tc_configuration *dst = NULL;
53 int i, j;
54 int tx = DCB_TX_CONFIG;
55 int rx = DCB_RX_CONFIG;
56 int changes = 0;
57#ifdef IXGBE_FCOE
58 struct dcb_app app = {
59 .selector = DCB_APP_IDTYPE_ETHTYPE,
60 .protocol = ETH_P_FCOE,
61 };
62 u8 up = dcb_getapp(adapter->netdev, &app);
53 63
54 if (!src_dcb_cfg || !dst_dcb_cfg) 64 if (up && !(up & (1 << adapter->fcoe.up)))
55 return -EINVAL; 65 changes |= BIT_APP_UPCHG;
66#endif
56 67
57 for (i = DCB_PG_ATTR_TC_0; i < tc_max + DCB_PG_ATTR_TC_0; i++) { 68 for (i = DCB_PG_ATTR_TC_0; i < tc_max + DCB_PG_ATTR_TC_0; i++) {
58 src_tc_cfg = &src_dcb_cfg->tc_config[i - DCB_PG_ATTR_TC_0]; 69 src = &scfg->tc_config[i - DCB_PG_ATTR_TC_0];
59 dst_tc_cfg = &dst_dcb_cfg->tc_config[i - DCB_PG_ATTR_TC_0]; 70 dst = &dcfg->tc_config[i - DCB_PG_ATTR_TC_0];
60 71
61 dst_tc_cfg->path[DCB_TX_CONFIG].prio_type = 72 if (dst->path[tx].prio_type != src->path[tx].prio_type) {
62 src_tc_cfg->path[DCB_TX_CONFIG].prio_type; 73 dst->path[tx].prio_type = src->path[tx].prio_type;
74 changes |= BIT_PG_TX;
75 }
63 76
64 dst_tc_cfg->path[DCB_TX_CONFIG].bwg_id = 77 if (dst->path[tx].bwg_id != src->path[tx].bwg_id) {
65 src_tc_cfg->path[DCB_TX_CONFIG].bwg_id; 78 dst->path[tx].bwg_id = src->path[tx].bwg_id;
79 changes |= BIT_PG_TX;
80 }
66 81
67 dst_tc_cfg->path[DCB_TX_CONFIG].bwg_percent = 82 if (dst->path[tx].bwg_percent != src->path[tx].bwg_percent) {
68 src_tc_cfg->path[DCB_TX_CONFIG].bwg_percent; 83 dst->path[tx].bwg_percent = src->path[tx].bwg_percent;
84 changes |= BIT_PG_TX;
85 }
69 86
70 dst_tc_cfg->path[DCB_TX_CONFIG].up_to_tc_bitmap = 87 if (dst->path[tx].up_to_tc_bitmap !=
71 src_tc_cfg->path[DCB_TX_CONFIG].up_to_tc_bitmap; 88 src->path[tx].up_to_tc_bitmap) {
89 dst->path[tx].up_to_tc_bitmap =
90 src->path[tx].up_to_tc_bitmap;
91 changes |= (BIT_PG_TX | BIT_PFC | BIT_APP_UPCHG);
92 }
72 93
73 dst_tc_cfg->path[DCB_RX_CONFIG].prio_type = 94 if (dst->path[rx].prio_type != src->path[rx].prio_type) {
74 src_tc_cfg->path[DCB_RX_CONFIG].prio_type; 95 dst->path[rx].prio_type = src->path[rx].prio_type;
96 changes |= BIT_PG_RX;
97 }
75 98
76 dst_tc_cfg->path[DCB_RX_CONFIG].bwg_id = 99 if (dst->path[rx].bwg_id != src->path[rx].bwg_id) {
77 src_tc_cfg->path[DCB_RX_CONFIG].bwg_id; 100 dst->path[rx].bwg_id = src->path[rx].bwg_id;
101 changes |= BIT_PG_RX;
102 }
78 103
79 dst_tc_cfg->path[DCB_RX_CONFIG].bwg_percent = 104 if (dst->path[rx].bwg_percent != src->path[rx].bwg_percent) {
80 src_tc_cfg->path[DCB_RX_CONFIG].bwg_percent; 105 dst->path[rx].bwg_percent = src->path[rx].bwg_percent;
106 changes |= BIT_PG_RX;
107 }
81 108
82 dst_tc_cfg->path[DCB_RX_CONFIG].up_to_tc_bitmap = 109 if (dst->path[rx].up_to_tc_bitmap !=
83 src_tc_cfg->path[DCB_RX_CONFIG].up_to_tc_bitmap; 110 src->path[rx].up_to_tc_bitmap) {
111 dst->path[rx].up_to_tc_bitmap =
112 src->path[rx].up_to_tc_bitmap;
113 changes |= (BIT_PG_RX | BIT_PFC | BIT_APP_UPCHG);
114 }
84 } 115 }
85 116
86 for (i = DCB_PG_ATTR_BW_ID_0; i < DCB_PG_ATTR_BW_ID_MAX; i++) { 117 for (i = DCB_PG_ATTR_BW_ID_0; i < DCB_PG_ATTR_BW_ID_MAX; i++) {
87 dst_dcb_cfg->bw_percentage[DCB_TX_CONFIG] 118 j = i - DCB_PG_ATTR_BW_ID_0;
88 [i-DCB_PG_ATTR_BW_ID_0] = src_dcb_cfg->bw_percentage 119 if (dcfg->bw_percentage[tx][j] != scfg->bw_percentage[tx][j]) {
89 [DCB_TX_CONFIG][i-DCB_PG_ATTR_BW_ID_0]; 120 dcfg->bw_percentage[tx][j] = scfg->bw_percentage[tx][j];
90 dst_dcb_cfg->bw_percentage[DCB_RX_CONFIG] 121 changes |= BIT_PG_TX;
91 [i-DCB_PG_ATTR_BW_ID_0] = src_dcb_cfg->bw_percentage 122 }
92 [DCB_RX_CONFIG][i-DCB_PG_ATTR_BW_ID_0]; 123 if (dcfg->bw_percentage[rx][j] != scfg->bw_percentage[rx][j]) {
124 dcfg->bw_percentage[rx][j] = scfg->bw_percentage[rx][j];
125 changes |= BIT_PG_RX;
126 }
93 } 127 }
94 128
95 for (i = DCB_PFC_UP_ATTR_0; i < DCB_PFC_UP_ATTR_MAX; i++) { 129 for (i = DCB_PFC_UP_ATTR_0; i < DCB_PFC_UP_ATTR_MAX; i++) {
96 dst_dcb_cfg->tc_config[i - DCB_PFC_UP_ATTR_0].dcb_pfc = 130 j = i - DCB_PFC_UP_ATTR_0;
97 src_dcb_cfg->tc_config[i - DCB_PFC_UP_ATTR_0].dcb_pfc; 131 if (dcfg->tc_config[j].dcb_pfc != scfg->tc_config[j].dcb_pfc) {
132 dcfg->tc_config[j].dcb_pfc = scfg->tc_config[j].dcb_pfc;
133 changes |= BIT_PFC;
134 }
98 } 135 }
99 136
100 dst_dcb_cfg->pfc_mode_enable = src_dcb_cfg->pfc_mode_enable; 137 if (dcfg->pfc_mode_enable != scfg->pfc_mode_enable) {
138 dcfg->pfc_mode_enable = scfg->pfc_mode_enable;
139 changes |= BIT_PFC;
140 }
101 141
102 return 0; 142 return changes;
103} 143}
104 144
105static u8 ixgbe_dcbnl_get_state(struct net_device *netdev) 145static u8 ixgbe_dcbnl_get_state(struct net_device *netdev)
@@ -179,20 +219,6 @@ static void ixgbe_dcbnl_set_pg_tc_cfg_tx(struct net_device *netdev, int tc,
179 if (up_map != DCB_ATTR_VALUE_UNDEFINED) 219 if (up_map != DCB_ATTR_VALUE_UNDEFINED)
180 adapter->temp_dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap = 220 adapter->temp_dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap =
181 up_map; 221 up_map;
182
183 if ((adapter->temp_dcb_cfg.tc_config[tc].path[0].prio_type !=
184 adapter->dcb_cfg.tc_config[tc].path[0].prio_type) ||
185 (adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_id !=
186 adapter->dcb_cfg.tc_config[tc].path[0].bwg_id) ||
187 (adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_percent !=
188 adapter->dcb_cfg.tc_config[tc].path[0].bwg_percent) ||
189 (adapter->temp_dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap !=
190 adapter->dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap))
191 adapter->dcb_set_bitmap |= BIT_PG_TX;
192
193 if (adapter->temp_dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap !=
194 adapter->dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap)
195 adapter->dcb_set_bitmap |= BIT_PFC | BIT_APP_UPCHG;
196} 222}
197 223
198static void ixgbe_dcbnl_set_pg_bwg_cfg_tx(struct net_device *netdev, int bwg_id, 224static void ixgbe_dcbnl_set_pg_bwg_cfg_tx(struct net_device *netdev, int bwg_id,
@@ -201,10 +227,6 @@ static void ixgbe_dcbnl_set_pg_bwg_cfg_tx(struct net_device *netdev, int bwg_id,
201 struct ixgbe_adapter *adapter = netdev_priv(netdev); 227 struct ixgbe_adapter *adapter = netdev_priv(netdev);
202 228
203 adapter->temp_dcb_cfg.bw_percentage[0][bwg_id] = bw_pct; 229 adapter->temp_dcb_cfg.bw_percentage[0][bwg_id] = bw_pct;
204
205 if (adapter->temp_dcb_cfg.bw_percentage[0][bwg_id] !=
206 adapter->dcb_cfg.bw_percentage[0][bwg_id])
207 adapter->dcb_set_bitmap |= BIT_PG_TX;
208} 230}
209 231
210static void ixgbe_dcbnl_set_pg_tc_cfg_rx(struct net_device *netdev, int tc, 232static void ixgbe_dcbnl_set_pg_tc_cfg_rx(struct net_device *netdev, int tc,
@@ -223,20 +245,6 @@ static void ixgbe_dcbnl_set_pg_tc_cfg_rx(struct net_device *netdev, int tc,
223 if (up_map != DCB_ATTR_VALUE_UNDEFINED) 245 if (up_map != DCB_ATTR_VALUE_UNDEFINED)
224 adapter->temp_dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap = 246 adapter->temp_dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap =
225 up_map; 247 up_map;
226
227 if ((adapter->temp_dcb_cfg.tc_config[tc].path[1].prio_type !=
228 adapter->dcb_cfg.tc_config[tc].path[1].prio_type) ||
229 (adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_id !=
230 adapter->dcb_cfg.tc_config[tc].path[1].bwg_id) ||
231 (adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_percent !=
232 adapter->dcb_cfg.tc_config[tc].path[1].bwg_percent) ||
233 (adapter->temp_dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap !=
234 adapter->dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap))
235 adapter->dcb_set_bitmap |= BIT_PG_RX;
236
237 if (adapter->temp_dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap !=
238 adapter->dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap)
239 adapter->dcb_set_bitmap |= BIT_PFC;
240} 248}
241 249
242static void ixgbe_dcbnl_set_pg_bwg_cfg_rx(struct net_device *netdev, int bwg_id, 250static void ixgbe_dcbnl_set_pg_bwg_cfg_rx(struct net_device *netdev, int bwg_id,
@@ -245,10 +253,6 @@ static void ixgbe_dcbnl_set_pg_bwg_cfg_rx(struct net_device *netdev, int bwg_id,
245 struct ixgbe_adapter *adapter = netdev_priv(netdev); 253 struct ixgbe_adapter *adapter = netdev_priv(netdev);
246 254
247 adapter->temp_dcb_cfg.bw_percentage[1][bwg_id] = bw_pct; 255 adapter->temp_dcb_cfg.bw_percentage[1][bwg_id] = bw_pct;
248
249 if (adapter->temp_dcb_cfg.bw_percentage[1][bwg_id] !=
250 adapter->dcb_cfg.bw_percentage[1][bwg_id])
251 adapter->dcb_set_bitmap |= BIT_PG_RX;
252} 256}
253 257
254static void ixgbe_dcbnl_get_pg_tc_cfg_tx(struct net_device *netdev, int tc, 258static void ixgbe_dcbnl_get_pg_tc_cfg_tx(struct net_device *netdev, int tc,
@@ -298,10 +302,8 @@ static void ixgbe_dcbnl_set_pfc_cfg(struct net_device *netdev, int priority,
298 302
299 adapter->temp_dcb_cfg.tc_config[priority].dcb_pfc = setting; 303 adapter->temp_dcb_cfg.tc_config[priority].dcb_pfc = setting;
300 if (adapter->temp_dcb_cfg.tc_config[priority].dcb_pfc != 304 if (adapter->temp_dcb_cfg.tc_config[priority].dcb_pfc !=
301 adapter->dcb_cfg.tc_config[priority].dcb_pfc) { 305 adapter->dcb_cfg.tc_config[priority].dcb_pfc)
302 adapter->dcb_set_bitmap |= BIT_PFC;
303 adapter->temp_dcb_cfg.pfc_mode_enable = true; 306 adapter->temp_dcb_cfg.pfc_mode_enable = true;
304 }
305} 307}
306 308
307static void ixgbe_dcbnl_get_pfc_cfg(struct net_device *netdev, int priority, 309static void ixgbe_dcbnl_get_pfc_cfg(struct net_device *netdev, int priority,
@@ -336,31 +338,17 @@ static void ixgbe_dcbnl_devreset(struct net_device *dev)
336static u8 ixgbe_dcbnl_set_all(struct net_device *netdev) 338static u8 ixgbe_dcbnl_set_all(struct net_device *netdev)
337{ 339{
338 struct ixgbe_adapter *adapter = netdev_priv(netdev); 340 struct ixgbe_adapter *adapter = netdev_priv(netdev);
339 int ret, i; 341 int ret = DCB_NO_HW_CHG;
340#ifdef IXGBE_FCOE 342 int i;
341 struct dcb_app app = {
342 .selector = DCB_APP_IDTYPE_ETHTYPE,
343 .protocol = ETH_P_FCOE,
344 };
345 u8 up;
346
347 /* In IEEE mode, use the IEEE Ethertype selector value */
348 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE) {
349 app.selector = IEEE_8021QAZ_APP_SEL_ETHERTYPE;
350 up = dcb_ieee_getapp_mask(netdev, &app);
351 } else {
352 up = dcb_getapp(netdev, &app);
353 }
354#endif
355 343
356 /* Fail command if not in CEE mode */ 344 /* Fail command if not in CEE mode */
357 if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE)) 345 if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
358 return 1; 346 return ret;
359 347
360 ret = ixgbe_copy_dcb_cfg(&adapter->temp_dcb_cfg, &adapter->dcb_cfg, 348 adapter->dcb_set_bitmap |= ixgbe_copy_dcb_cfg(adapter,
361 MAX_TRAFFIC_CLASS); 349 MAX_TRAFFIC_CLASS);
362 if (ret) 350 if (!adapter->dcb_set_bitmap)
363 return DCB_NO_HW_CHG; 351 return ret;
364 352
365 if (adapter->dcb_cfg.pfc_mode_enable) { 353 if (adapter->dcb_cfg.pfc_mode_enable) {
366 switch (adapter->hw.mac.type) { 354 switch (adapter->hw.mac.type) {
@@ -420,6 +408,8 @@ static u8 ixgbe_dcbnl_set_all(struct net_device *netdev)
420 408
421 for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) 409 for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++)
422 netdev_set_prio_tc_map(netdev, i, prio_tc[i]); 410 netdev_set_prio_tc_map(netdev, i, prio_tc[i]);
411
412 ret = DCB_HW_CHG_RST;
423 } 413 }
424 414
425 if (adapter->dcb_set_bitmap & BIT_PFC) { 415 if (adapter->dcb_set_bitmap & BIT_PFC) {
@@ -430,7 +420,8 @@ static u8 ixgbe_dcbnl_set_all(struct net_device *netdev)
430 DCB_TX_CONFIG, prio_tc); 420 DCB_TX_CONFIG, prio_tc);
431 ixgbe_dcb_unpack_pfc(&adapter->dcb_cfg, &pfc_en); 421 ixgbe_dcb_unpack_pfc(&adapter->dcb_cfg, &pfc_en);
432 ixgbe_dcb_hw_pfc_config(&adapter->hw, pfc_en, prio_tc); 422 ixgbe_dcb_hw_pfc_config(&adapter->hw, pfc_en, prio_tc);
433 ret = DCB_HW_CHG; 423 if (ret != DCB_HW_CHG_RST)
424 ret = DCB_HW_CHG;
434 } 425 }
435 426
436 if (adapter->dcb_cfg.pfc_mode_enable) 427 if (adapter->dcb_cfg.pfc_mode_enable)
@@ -441,8 +432,13 @@ static u8 ixgbe_dcbnl_set_all(struct net_device *netdev)
441 * FCoE is using changes. This happens if the APP info 432 * FCoE is using changes. This happens if the APP info
442 * changes or the up2tc mapping is updated. 433 * changes or the up2tc mapping is updated.
443 */ 434 */
444 if ((up && !(up & (1 << adapter->fcoe.up))) || 435 if (adapter->dcb_set_bitmap & BIT_APP_UPCHG) {
445 (adapter->dcb_set_bitmap & BIT_APP_UPCHG)) { 436 struct dcb_app app = {
437 .selector = DCB_APP_IDTYPE_ETHTYPE,
438 .protocol = ETH_P_FCOE,
439 };
440 u8 up = dcb_getapp(netdev, &app);
441
446 adapter->fcoe.up = ffs(up) - 1; 442 adapter->fcoe.up = ffs(up) - 1;
447 ixgbe_dcbnl_devreset(netdev); 443 ixgbe_dcbnl_devreset(netdev);
448 ret = DCB_HW_CHG_RST; 444 ret = DCB_HW_CHG_RST;
@@ -531,9 +527,6 @@ static void ixgbe_dcbnl_setpfcstate(struct net_device *netdev, u8 state)
531 struct ixgbe_adapter *adapter = netdev_priv(netdev); 527 struct ixgbe_adapter *adapter = netdev_priv(netdev);
532 528
533 adapter->temp_dcb_cfg.pfc_mode_enable = state; 529 adapter->temp_dcb_cfg.pfc_mode_enable = state;
534 if (adapter->temp_dcb_cfg.pfc_mode_enable !=
535 adapter->dcb_cfg.pfc_mode_enable)
536 adapter->dcb_set_bitmap |= BIT_PFC;
537} 530}
538 531
539/** 532/**
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c
index 31a2bf76a346..cfe7d269590c 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c
@@ -1780,6 +1780,8 @@ static u16 ixgbe_clean_test_rings(struct ixgbe_ring *rx_ring,
1780 rx_desc = IXGBE_RX_DESC(rx_ring, rx_ntc); 1780 rx_desc = IXGBE_RX_DESC(rx_ring, rx_ntc);
1781 } 1781 }
1782 1782
1783 netdev_tx_reset_queue(txring_txq(tx_ring));
1784
1783 /* re-map buffers to ring, store next to clean values */ 1785 /* re-map buffers to ring, store next to clean values */
1784 ixgbe_alloc_rx_buffers(rx_ring, count); 1786 ixgbe_alloc_rx_buffers(rx_ring, count);
1785 rx_ring->next_to_clean = rx_ntc; 1787 rx_ring->next_to_clean = rx_ntc;
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c
index 77ea4b716535..bc07933d67da 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c
@@ -437,6 +437,7 @@ int ixgbe_fcoe_ddp(struct ixgbe_adapter *adapter,
437 */ 437 */
438 if ((fh->fh_r_ctl == FC_RCTL_DD_SOL_DATA) && 438 if ((fh->fh_r_ctl == FC_RCTL_DD_SOL_DATA) &&
439 (fctl & FC_FC_END_SEQ)) { 439 (fctl & FC_FC_END_SEQ)) {
440 skb_linearize(skb);
440 crc = (struct fcoe_crc_eof *)skb_put(skb, sizeof(*crc)); 441 crc = (struct fcoe_crc_eof *)skb_put(skb, sizeof(*crc));
441 crc->fcoe_eof = FC_EOF_T; 442 crc->fcoe_eof = FC_EOF_T;
442 } 443 }
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_lib.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_lib.c
index 027d7a75be39..ed1b47dc0834 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_lib.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_lib.c
@@ -622,6 +622,16 @@ static int ixgbe_alloc_q_vector(struct ixgbe_adapter *adapter, int v_idx,
622 if (adapter->hw.mac.type == ixgbe_mac_82599EB) 622 if (adapter->hw.mac.type == ixgbe_mac_82599EB)
623 set_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state); 623 set_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state);
624 624
625#ifdef IXGBE_FCOE
626 if (adapter->netdev->features & NETIF_F_FCOE_MTU) {
627 struct ixgbe_ring_feature *f;
628 f = &adapter->ring_feature[RING_F_FCOE];
629 if ((rxr_idx >= f->mask) &&
630 (rxr_idx < f->mask + f->indices))
631 set_bit(__IXGBE_RX_FCOE_BUFSZ, &ring->state);
632 }
633
634#endif /* IXGBE_FCOE */
625 /* apply Rx specific ring traits */ 635 /* apply Rx specific ring traits */
626 ring->count = adapter->rx_ring_count; 636 ring->count = adapter->rx_ring_count;
627 ring->queue_index = rxr_idx; 637 ring->queue_index = rxr_idx;
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
index 398fc223cab9..467948e9ecd9 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
@@ -63,8 +63,8 @@ static char ixgbe_default_device_descr[] =
63 "Intel(R) 10 Gigabit Network Connection"; 63 "Intel(R) 10 Gigabit Network Connection";
64#endif 64#endif
65#define MAJ 3 65#define MAJ 3
66#define MIN 6 66#define MIN 8
67#define BUILD 7 67#define BUILD 21
68#define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) "." \ 68#define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) "." \
69 __stringify(BUILD) "-k" 69 __stringify(BUILD) "-k"
70const char ixgbe_driver_version[] = DRV_VERSION; 70const char ixgbe_driver_version[] = DRV_VERSION;
@@ -141,13 +141,16 @@ module_param(allow_unsupported_sfp, uint, 0);
141MODULE_PARM_DESC(allow_unsupported_sfp, 141MODULE_PARM_DESC(allow_unsupported_sfp,
142 "Allow unsupported and untested SFP+ modules on 82599-based adapters"); 142 "Allow unsupported and untested SFP+ modules on 82599-based adapters");
143 143
144#define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
145static int debug = -1;
146module_param(debug, int, 0);
147MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
148
144MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); 149MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
145MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver"); 150MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
146MODULE_LICENSE("GPL"); 151MODULE_LICENSE("GPL");
147MODULE_VERSION(DRV_VERSION); 152MODULE_VERSION(DRV_VERSION);
148 153
149#define DEFAULT_DEBUG_LEVEL_SHIFT 3
150
151static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter) 154static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter)
152{ 155{
153 if (!test_bit(__IXGBE_DOWN, &adapter->state) && 156 if (!test_bit(__IXGBE_DOWN, &adapter->state) &&
@@ -2668,8 +2671,6 @@ void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
2668 /* enable queue */ 2671 /* enable queue */
2669 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl); 2672 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
2670 2673
2671 netdev_tx_reset_queue(txring_txq(ring));
2672
2673 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */ 2674 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2674 if (hw->mac.type == ixgbe_mac_82598EB && 2675 if (hw->mac.type == ixgbe_mac_82598EB &&
2675 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) 2676 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
@@ -3151,14 +3152,6 @@ static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
3151 set_ring_rsc_enabled(rx_ring); 3152 set_ring_rsc_enabled(rx_ring);
3152 else 3153 else
3153 clear_ring_rsc_enabled(rx_ring); 3154 clear_ring_rsc_enabled(rx_ring);
3154#ifdef IXGBE_FCOE
3155 if (netdev->features & NETIF_F_FCOE_MTU) {
3156 struct ixgbe_ring_feature *f;
3157 f = &adapter->ring_feature[RING_F_FCOE];
3158 if ((i >= f->mask) && (i < f->mask + f->indices))
3159 set_bit(__IXGBE_RX_FCOE_BUFSZ, &rx_ring->state);
3160 }
3161#endif /* IXGBE_FCOE */
3162 } 3155 }
3163} 3156}
3164 3157
@@ -4172,6 +4165,8 @@ static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
4172 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info); 4165 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
4173 } 4166 }
4174 4167
4168 netdev_tx_reset_queue(txring_txq(tx_ring));
4169
4175 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; 4170 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
4176 memset(tx_ring->tx_buffer_info, 0, size); 4171 memset(tx_ring->tx_buffer_info, 0, size);
4177 4172
@@ -4423,8 +4418,8 @@ static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
4423 adapter->dcb_cfg.pfc_mode_enable = false; 4418 adapter->dcb_cfg.pfc_mode_enable = false;
4424 adapter->dcb_set_bitmap = 0x00; 4419 adapter->dcb_set_bitmap = 0x00;
4425 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE; 4420 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
4426 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg, 4421 memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
4427 MAX_TRAFFIC_CLASS); 4422 sizeof(adapter->temp_dcb_cfg));
4428 4423
4429#endif 4424#endif
4430 4425
@@ -4833,7 +4828,9 @@ static int ixgbe_resume(struct pci_dev *pdev)
4833 4828
4834 pci_wake_from_d3(pdev, false); 4829 pci_wake_from_d3(pdev, false);
4835 4830
4831 rtnl_lock();
4836 err = ixgbe_init_interrupt_scheme(adapter); 4832 err = ixgbe_init_interrupt_scheme(adapter);
4833 rtnl_unlock();
4837 if (err) { 4834 if (err) {
4838 e_dev_err("Cannot initialize interrupts for device\n"); 4835 e_dev_err("Cannot initialize interrupts for device\n");
4839 return err; 4836 return err;
@@ -4869,17 +4866,15 @@ static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
4869 netif_device_detach(netdev); 4866 netif_device_detach(netdev);
4870 4867
4871 if (netif_running(netdev)) { 4868 if (netif_running(netdev)) {
4869 rtnl_lock();
4872 ixgbe_down(adapter); 4870 ixgbe_down(adapter);
4873 ixgbe_free_irq(adapter); 4871 ixgbe_free_irq(adapter);
4874 ixgbe_free_all_tx_resources(adapter); 4872 ixgbe_free_all_tx_resources(adapter);
4875 ixgbe_free_all_rx_resources(adapter); 4873 ixgbe_free_all_rx_resources(adapter);
4874 rtnl_unlock();
4876 } 4875 }
4877 4876
4878 ixgbe_clear_interrupt_scheme(adapter); 4877 ixgbe_clear_interrupt_scheme(adapter);
4879#ifdef CONFIG_DCB
4880 kfree(adapter->ixgbe_ieee_pfc);
4881 kfree(adapter->ixgbe_ieee_ets);
4882#endif
4883 4878
4884#ifdef CONFIG_PM 4879#ifdef CONFIG_PM
4885 retval = pci_save_state(pdev); 4880 retval = pci_save_state(pdev);
@@ -4890,6 +4885,16 @@ static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
4890 if (wufc) { 4885 if (wufc) {
4891 ixgbe_set_rx_mode(netdev); 4886 ixgbe_set_rx_mode(netdev);
4892 4887
4888 /*
4889 * enable the optics for both mult-speed fiber and
4890 * 82599 SFP+ fiber as we can WoL.
4891 */
4892 if (hw->mac.ops.enable_tx_laser &&
4893 (hw->phy.multispeed_fiber ||
4894 (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber &&
4895 hw->mac.type == ixgbe_mac_82599EB)))
4896 hw->mac.ops.enable_tx_laser(hw);
4897
4893 /* turn on all-multi mode if wake on multicast is enabled */ 4898 /* turn on all-multi mode if wake on multicast is enabled */
4894 if (wufc & IXGBE_WUFC_MC) { 4899 if (wufc & IXGBE_WUFC_MC) {
4895 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); 4900 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
@@ -6834,7 +6839,7 @@ static int __devinit ixgbe_probe(struct pci_dev *pdev,
6834 adapter->pdev = pdev; 6839 adapter->pdev = pdev;
6835 hw = &adapter->hw; 6840 hw = &adapter->hw;
6836 hw->back = adapter; 6841 hw->back = adapter;
6837 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1; 6842 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
6838 6843
6839 hw->hw_addr = ioremap(pci_resource_start(pdev, 0), 6844 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
6840 pci_resource_len(pdev, 0)); 6845 pci_resource_len(pdev, 0));
@@ -7217,6 +7222,11 @@ static void __devexit ixgbe_remove(struct pci_dev *pdev)
7217 7222
7218 ixgbe_release_hw_control(adapter); 7223 ixgbe_release_hw_control(adapter);
7219 7224
7225#ifdef CONFIG_DCB
7226 kfree(adapter->ixgbe_ieee_pfc);
7227 kfree(adapter->ixgbe_ieee_ets);
7228
7229#endif
7220 iounmap(adapter->hw.hw_addr); 7230 iounmap(adapter->hw.hw_addr);
7221 pci_release_selected_regions(pdev, pci_select_bars(pdev, 7231 pci_release_selected_regions(pdev, pci_select_bars(pdev,
7222 IORESOURCE_MEM)); 7232 IORESOURCE_MEM));
diff --git a/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c b/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c
index 581c65976bb4..307611ae831d 100644
--- a/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c
+++ b/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c
@@ -91,7 +91,10 @@ MODULE_DESCRIPTION("Intel(R) 82599 Virtual Function Driver");
91MODULE_LICENSE("GPL"); 91MODULE_LICENSE("GPL");
92MODULE_VERSION(DRV_VERSION); 92MODULE_VERSION(DRV_VERSION);
93 93
94#define DEFAULT_DEBUG_LEVEL_SHIFT 3 94#define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
95static int debug = -1;
96module_param(debug, int, 0);
97MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
95 98
96/* forward decls */ 99/* forward decls */
97static void ixgbevf_set_itr_msix(struct ixgbevf_q_vector *q_vector); 100static void ixgbevf_set_itr_msix(struct ixgbevf_q_vector *q_vector);
@@ -3367,7 +3370,7 @@ static int __devinit ixgbevf_probe(struct pci_dev *pdev,
3367 adapter->pdev = pdev; 3370 adapter->pdev = pdev;
3368 hw = &adapter->hw; 3371 hw = &adapter->hw;
3369 hw->back = adapter; 3372 hw->back = adapter;
3370 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1; 3373 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
3371 3374
3372 /* 3375 /*
3373 * call save state here in standalone driver because it relies on 3376 * call save state here in standalone driver because it relies on
diff --git a/drivers/net/ethernet/marvell/sky2.c b/drivers/net/ethernet/marvell/sky2.c
index 423a1a2a702e..487a6c8bd4ec 100644
--- a/drivers/net/ethernet/marvell/sky2.c
+++ b/drivers/net/ethernet/marvell/sky2.c
@@ -1767,13 +1767,14 @@ static int sky2_open(struct net_device *dev)
1767 1767
1768 sky2_hw_up(sky2); 1768 sky2_hw_up(sky2);
1769 1769
1770 /* Enable interrupts from phy/mac for port */
1771 imask = sky2_read32(hw, B0_IMSK);
1772
1770 if (hw->chip_id == CHIP_ID_YUKON_OPT || 1773 if (hw->chip_id == CHIP_ID_YUKON_OPT ||
1771 hw->chip_id == CHIP_ID_YUKON_PRM || 1774 hw->chip_id == CHIP_ID_YUKON_PRM ||
1772 hw->chip_id == CHIP_ID_YUKON_OP_2) 1775 hw->chip_id == CHIP_ID_YUKON_OP_2)
1773 imask |= Y2_IS_PHY_QLNK; /* enable PHY Quick Link */ 1776 imask |= Y2_IS_PHY_QLNK; /* enable PHY Quick Link */
1774 1777
1775 /* Enable interrupts from phy/mac for port */
1776 imask = sky2_read32(hw, B0_IMSK);
1777 imask |= portirq_msk[port]; 1778 imask |= portirq_msk[port];
1778 sky2_write32(hw, B0_IMSK, imask); 1779 sky2_write32(hw, B0_IMSK, imask);
1779 sky2_read32(hw, B0_IMSK); 1780 sky2_read32(hw, B0_IMSK);
@@ -2468,6 +2469,17 @@ static int sky2_change_mtu(struct net_device *dev, int new_mtu)
2468 return err; 2469 return err;
2469} 2470}
2470 2471
2472static inline bool needs_copy(const struct rx_ring_info *re,
2473 unsigned length)
2474{
2475#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
2476 /* Some architectures need the IP header to be aligned */
2477 if (!IS_ALIGNED(re->data_addr + ETH_HLEN, sizeof(u32)))
2478 return true;
2479#endif
2480 return length < copybreak;
2481}
2482
2471/* For small just reuse existing skb for next receive */ 2483/* For small just reuse existing skb for next receive */
2472static struct sk_buff *receive_copy(struct sky2_port *sky2, 2484static struct sk_buff *receive_copy(struct sky2_port *sky2,
2473 const struct rx_ring_info *re, 2485 const struct rx_ring_info *re,
@@ -2482,8 +2494,13 @@ static struct sk_buff *receive_copy(struct sky2_port *sky2,
2482 skb_copy_from_linear_data(re->skb, skb->data, length); 2494 skb_copy_from_linear_data(re->skb, skb->data, length);
2483 skb->ip_summed = re->skb->ip_summed; 2495 skb->ip_summed = re->skb->ip_summed;
2484 skb->csum = re->skb->csum; 2496 skb->csum = re->skb->csum;
2497 skb->rxhash = re->skb->rxhash;
2498 skb->vlan_tci = re->skb->vlan_tci;
2499
2485 pci_dma_sync_single_for_device(sky2->hw->pdev, re->data_addr, 2500 pci_dma_sync_single_for_device(sky2->hw->pdev, re->data_addr,
2486 length, PCI_DMA_FROMDEVICE); 2501 length, PCI_DMA_FROMDEVICE);
2502 re->skb->vlan_tci = 0;
2503 re->skb->rxhash = 0;
2487 re->skb->ip_summed = CHECKSUM_NONE; 2504 re->skb->ip_summed = CHECKSUM_NONE;
2488 skb_put(skb, length); 2505 skb_put(skb, length);
2489 } 2506 }
@@ -2568,9 +2585,6 @@ static struct sk_buff *sky2_receive(struct net_device *dev,
2568 struct sk_buff *skb = NULL; 2585 struct sk_buff *skb = NULL;
2569 u16 count = (status & GMR_FS_LEN) >> 16; 2586 u16 count = (status & GMR_FS_LEN) >> 16;
2570 2587
2571 if (status & GMR_FS_VLAN)
2572 count -= VLAN_HLEN; /* Account for vlan tag */
2573
2574 netif_printk(sky2, rx_status, KERN_DEBUG, dev, 2588 netif_printk(sky2, rx_status, KERN_DEBUG, dev,
2575 "rx slot %u status 0x%x len %d\n", 2589 "rx slot %u status 0x%x len %d\n",
2576 sky2->rx_next, status, length); 2590 sky2->rx_next, status, length);
@@ -2578,6 +2592,9 @@ static struct sk_buff *sky2_receive(struct net_device *dev,
2578 sky2->rx_next = (sky2->rx_next + 1) % sky2->rx_pending; 2592 sky2->rx_next = (sky2->rx_next + 1) % sky2->rx_pending;
2579 prefetch(sky2->rx_ring + sky2->rx_next); 2593 prefetch(sky2->rx_ring + sky2->rx_next);
2580 2594
2595 if (vlan_tx_tag_present(re->skb))
2596 count -= VLAN_HLEN; /* Account for vlan tag */
2597
2581 /* This chip has hardware problems that generates bogus status. 2598 /* This chip has hardware problems that generates bogus status.
2582 * So do only marginal checking and expect higher level protocols 2599 * So do only marginal checking and expect higher level protocols
2583 * to handle crap frames. 2600 * to handle crap frames.
@@ -2598,7 +2615,7 @@ static struct sk_buff *sky2_receive(struct net_device *dev,
2598 goto error; 2615 goto error;
2599 2616
2600okay: 2617okay:
2601 if (length < copybreak) 2618 if (needs_copy(re, length))
2602 skb = receive_copy(sky2, re, length); 2619 skb = receive_copy(sky2, re, length);
2603 else 2620 else
2604 skb = receive_new(sky2, re, length); 2621 skb = receive_new(sky2, re, length);
@@ -2635,11 +2652,8 @@ static inline void sky2_tx_done(struct net_device *dev, u16 last)
2635} 2652}
2636 2653
2637static inline void sky2_skb_rx(const struct sky2_port *sky2, 2654static inline void sky2_skb_rx(const struct sky2_port *sky2,
2638 u32 status, struct sk_buff *skb) 2655 struct sk_buff *skb)
2639{ 2656{
2640 if (status & GMR_FS_VLAN)
2641 __vlan_hwaccel_put_tag(skb, be16_to_cpu(sky2->rx_tag));
2642
2643 if (skb->ip_summed == CHECKSUM_NONE) 2657 if (skb->ip_summed == CHECKSUM_NONE)
2644 netif_receive_skb(skb); 2658 netif_receive_skb(skb);
2645 else 2659 else
@@ -2693,6 +2707,14 @@ static void sky2_rx_checksum(struct sky2_port *sky2, u32 status)
2693 } 2707 }
2694} 2708}
2695 2709
2710static void sky2_rx_tag(struct sky2_port *sky2, u16 length)
2711{
2712 struct sk_buff *skb;
2713
2714 skb = sky2->rx_ring[sky2->rx_next].skb;
2715 __vlan_hwaccel_put_tag(skb, be16_to_cpu(length));
2716}
2717
2696static void sky2_rx_hash(struct sky2_port *sky2, u32 status) 2718static void sky2_rx_hash(struct sky2_port *sky2, u32 status)
2697{ 2719{
2698 struct sk_buff *skb; 2720 struct sk_buff *skb;
@@ -2751,8 +2773,7 @@ static int sky2_status_intr(struct sky2_hw *hw, int to_do, u16 idx)
2751 } 2773 }
2752 2774
2753 skb->protocol = eth_type_trans(skb, dev); 2775 skb->protocol = eth_type_trans(skb, dev);
2754 2776 sky2_skb_rx(sky2, skb);
2755 sky2_skb_rx(sky2, status, skb);
2756 2777
2757 /* Stop after net poll weight */ 2778 /* Stop after net poll weight */
2758 if (++work_done >= to_do) 2779 if (++work_done >= to_do)
@@ -2760,11 +2781,11 @@ static int sky2_status_intr(struct sky2_hw *hw, int to_do, u16 idx)
2760 break; 2781 break;
2761 2782
2762 case OP_RXVLAN: 2783 case OP_RXVLAN:
2763 sky2->rx_tag = length; 2784 sky2_rx_tag(sky2, length);
2764 break; 2785 break;
2765 2786
2766 case OP_RXCHKSVLAN: 2787 case OP_RXCHKSVLAN:
2767 sky2->rx_tag = length; 2788 sky2_rx_tag(sky2, length);
2768 /* fall through */ 2789 /* fall through */
2769 case OP_RXCHKS: 2790 case OP_RXCHKS:
2770 if (likely(dev->features & NETIF_F_RXCSUM)) 2791 if (likely(dev->features & NETIF_F_RXCSUM))
diff --git a/drivers/net/ethernet/marvell/sky2.h b/drivers/net/ethernet/marvell/sky2.h
index ff6f58bf822a..3c896ce80b71 100644
--- a/drivers/net/ethernet/marvell/sky2.h
+++ b/drivers/net/ethernet/marvell/sky2.h
@@ -2241,7 +2241,6 @@ struct sky2_port {
2241 u16 rx_pending; 2241 u16 rx_pending;
2242 u16 rx_data_size; 2242 u16 rx_data_size;
2243 u16 rx_nfrags; 2243 u16 rx_nfrags;
2244 u16 rx_tag;
2245 2244
2246 struct { 2245 struct {
2247 unsigned long last; 2246 unsigned long last;
diff --git a/drivers/net/ethernet/mellanox/mlx4/mlx4_en.h b/drivers/net/ethernet/mellanox/mlx4/mlx4_en.h
index 9e2b911a1230..d69fee41f24a 100644
--- a/drivers/net/ethernet/mellanox/mlx4/mlx4_en.h
+++ b/drivers/net/ethernet/mellanox/mlx4/mlx4_en.h
@@ -83,8 +83,9 @@
83 83
84#define MLX4_EN_WATCHDOG_TIMEOUT (15 * HZ) 84#define MLX4_EN_WATCHDOG_TIMEOUT (15 * HZ)
85 85
86#define MLX4_EN_ALLOC_ORDER 2 86/* Use the maximum between 16384 and a single page */
87#define MLX4_EN_ALLOC_SIZE (PAGE_SIZE << MLX4_EN_ALLOC_ORDER) 87#define MLX4_EN_ALLOC_SIZE PAGE_ALIGN(16384)
88#define MLX4_EN_ALLOC_ORDER get_order(MLX4_EN_ALLOC_SIZE)
88 89
89#define MLX4_EN_MAX_LRO_DESCRIPTORS 32 90#define MLX4_EN_MAX_LRO_DESCRIPTORS 32
90 91
diff --git a/drivers/net/ethernet/micrel/ks8851.c b/drivers/net/ethernet/micrel/ks8851.c
index c722aa607d07..5e313e9a252f 100644
--- a/drivers/net/ethernet/micrel/ks8851.c
+++ b/drivers/net/ethernet/micrel/ks8851.c
@@ -618,10 +618,8 @@ static void ks8851_irq_work(struct work_struct *work)
618 netif_dbg(ks, intr, ks->netdev, 618 netif_dbg(ks, intr, ks->netdev,
619 "%s: status 0x%04x\n", __func__, status); 619 "%s: status 0x%04x\n", __func__, status);
620 620
621 if (status & IRQ_LCI) { 621 if (status & IRQ_LCI)
622 /* should do something about checking link status */
623 handled |= IRQ_LCI; 622 handled |= IRQ_LCI;
624 }
625 623
626 if (status & IRQ_LDI) { 624 if (status & IRQ_LDI) {
627 u16 pmecr = ks8851_rdreg16(ks, KS_PMECR); 625 u16 pmecr = ks8851_rdreg16(ks, KS_PMECR);
@@ -684,6 +682,9 @@ static void ks8851_irq_work(struct work_struct *work)
684 682
685 mutex_unlock(&ks->lock); 683 mutex_unlock(&ks->lock);
686 684
685 if (status & IRQ_LCI)
686 mii_check_link(&ks->mii);
687
687 if (status & IRQ_TXI) 688 if (status & IRQ_TXI)
688 netif_wake_queue(ks->netdev); 689 netif_wake_queue(ks->netdev);
689 690
@@ -889,16 +890,17 @@ static int ks8851_net_stop(struct net_device *dev)
889 netif_stop_queue(dev); 890 netif_stop_queue(dev);
890 891
891 mutex_lock(&ks->lock); 892 mutex_lock(&ks->lock);
893 /* turn off the IRQs and ack any outstanding */
894 ks8851_wrreg16(ks, KS_IER, 0x0000);
895 ks8851_wrreg16(ks, KS_ISR, 0xffff);
896 mutex_unlock(&ks->lock);
892 897
893 /* stop any outstanding work */ 898 /* stop any outstanding work */
894 flush_work(&ks->irq_work); 899 flush_work(&ks->irq_work);
895 flush_work(&ks->tx_work); 900 flush_work(&ks->tx_work);
896 flush_work(&ks->rxctrl_work); 901 flush_work(&ks->rxctrl_work);
897 902
898 /* turn off the IRQs and ack any outstanding */ 903 mutex_lock(&ks->lock);
899 ks8851_wrreg16(ks, KS_IER, 0x0000);
900 ks8851_wrreg16(ks, KS_ISR, 0xffff);
901
902 /* shutdown RX process */ 904 /* shutdown RX process */
903 ks8851_wrreg16(ks, KS_RXCR1, 0x0000); 905 ks8851_wrreg16(ks, KS_RXCR1, 0x0000);
904 906
@@ -907,6 +909,7 @@ static int ks8851_net_stop(struct net_device *dev)
907 909
908 /* set powermode to soft power down to save power */ 910 /* set powermode to soft power down to save power */
909 ks8851_set_powermode(ks, PMECR_PM_SOFTDOWN); 911 ks8851_set_powermode(ks, PMECR_PM_SOFTDOWN);
912 mutex_unlock(&ks->lock);
910 913
911 /* ensure any queued tx buffers are dumped */ 914 /* ensure any queued tx buffers are dumped */
912 while (!skb_queue_empty(&ks->txq)) { 915 while (!skb_queue_empty(&ks->txq)) {
@@ -918,7 +921,6 @@ static int ks8851_net_stop(struct net_device *dev)
918 dev_kfree_skb(txb); 921 dev_kfree_skb(txb);
919 } 922 }
920 923
921 mutex_unlock(&ks->lock);
922 return 0; 924 return 0;
923} 925}
924 926
@@ -1418,6 +1420,7 @@ static int __devinit ks8851_probe(struct spi_device *spi)
1418 struct net_device *ndev; 1420 struct net_device *ndev;
1419 struct ks8851_net *ks; 1421 struct ks8851_net *ks;
1420 int ret; 1422 int ret;
1423 unsigned cider;
1421 1424
1422 ndev = alloc_etherdev(sizeof(struct ks8851_net)); 1425 ndev = alloc_etherdev(sizeof(struct ks8851_net));
1423 if (!ndev) 1426 if (!ndev)
@@ -1484,8 +1487,8 @@ static int __devinit ks8851_probe(struct spi_device *spi)
1484 ks8851_soft_reset(ks, GRR_GSR); 1487 ks8851_soft_reset(ks, GRR_GSR);
1485 1488
1486 /* simple check for a valid chip being connected to the bus */ 1489 /* simple check for a valid chip being connected to the bus */
1487 1490 cider = ks8851_rdreg16(ks, KS_CIDER);
1488 if ((ks8851_rdreg16(ks, KS_CIDER) & ~CIDER_REV_MASK) != CIDER_ID) { 1491 if ((cider & ~CIDER_REV_MASK) != CIDER_ID) {
1489 dev_err(&spi->dev, "failed to read device ID\n"); 1492 dev_err(&spi->dev, "failed to read device ID\n");
1490 ret = -ENODEV; 1493 ret = -ENODEV;
1491 goto err_id; 1494 goto err_id;
@@ -1516,15 +1519,14 @@ static int __devinit ks8851_probe(struct spi_device *spi)
1516 } 1519 }
1517 1520
1518 netdev_info(ndev, "revision %d, MAC %pM, IRQ %d, %s EEPROM\n", 1521 netdev_info(ndev, "revision %d, MAC %pM, IRQ %d, %s EEPROM\n",
1519 CIDER_REV_GET(ks8851_rdreg16(ks, KS_CIDER)), 1522 CIDER_REV_GET(cider), ndev->dev_addr, ndev->irq,
1520 ndev->dev_addr, ndev->irq,
1521 ks->rc_ccr & CCR_EEPROM ? "has" : "no"); 1523 ks->rc_ccr & CCR_EEPROM ? "has" : "no");
1522 1524
1523 return 0; 1525 return 0;
1524 1526
1525 1527
1526err_netdev: 1528err_netdev:
1527 free_irq(ndev->irq, ndev); 1529 free_irq(ndev->irq, ks);
1528 1530
1529err_id: 1531err_id:
1530err_irq: 1532err_irq:
diff --git a/drivers/net/ethernet/micrel/ks8851_mll.c b/drivers/net/ethernet/micrel/ks8851_mll.c
index b8104d9f4081..5ffde23ac8fb 100644
--- a/drivers/net/ethernet/micrel/ks8851_mll.c
+++ b/drivers/net/ethernet/micrel/ks8851_mll.c
@@ -40,7 +40,7 @@
40#define DRV_NAME "ks8851_mll" 40#define DRV_NAME "ks8851_mll"
41 41
42static u8 KS_DEFAULT_MAC_ADDRESS[] = { 0x00, 0x10, 0xA1, 0x86, 0x95, 0x11 }; 42static u8 KS_DEFAULT_MAC_ADDRESS[] = { 0x00, 0x10, 0xA1, 0x86, 0x95, 0x11 };
43#define MAX_RECV_FRAMES 32 43#define MAX_RECV_FRAMES 255
44#define MAX_BUF_SIZE 2048 44#define MAX_BUF_SIZE 2048
45#define TX_BUF_SIZE 2000 45#define TX_BUF_SIZE 2000
46#define RX_BUF_SIZE 2000 46#define RX_BUF_SIZE 2000
diff --git a/drivers/net/ethernet/micrel/ksz884x.c b/drivers/net/ethernet/micrel/ksz884x.c
index ef723b185d85..eaf9ff0262a9 100644
--- a/drivers/net/ethernet/micrel/ksz884x.c
+++ b/drivers/net/ethernet/micrel/ksz884x.c
@@ -5675,7 +5675,7 @@ static int netdev_set_mac_address(struct net_device *dev, void *addr)
5675 memcpy(hw->override_addr, mac->sa_data, ETH_ALEN); 5675 memcpy(hw->override_addr, mac->sa_data, ETH_ALEN);
5676 } 5676 }
5677 5677
5678 memcpy(dev->dev_addr, mac->sa_data, MAX_ADDR_LEN); 5678 memcpy(dev->dev_addr, mac->sa_data, ETH_ALEN);
5679 5679
5680 interrupt = hw_block_intr(hw); 5680 interrupt = hw_block_intr(hw);
5681 5681
diff --git a/drivers/net/ethernet/nxp/lpc_eth.c b/drivers/net/ethernet/nxp/lpc_eth.c
index 69444247c20b..6dfc26d85e47 100644
--- a/drivers/net/ethernet/nxp/lpc_eth.c
+++ b/drivers/net/ethernet/nxp/lpc_eth.c
@@ -1441,7 +1441,7 @@ static int lpc_eth_drv_probe(struct platform_device *pdev)
1441 } 1441 }
1442#endif 1442#endif
1443 if (!is_valid_ether_addr(ndev->dev_addr)) 1443 if (!is_valid_ether_addr(ndev->dev_addr))
1444 dev_hw_addr_random(ndev, ndev->dev_addr); 1444 eth_hw_addr_random(ndev);
1445 1445
1446 /* Reset the ethernet controller */ 1446 /* Reset the ethernet controller */
1447 __lpc_eth_reset(pldat); 1447 __lpc_eth_reset(pldat);
diff --git a/drivers/net/ethernet/realtek/8139cp.c b/drivers/net/ethernet/realtek/8139cp.c
index abc79076f867..b3287c0fe279 100644
--- a/drivers/net/ethernet/realtek/8139cp.c
+++ b/drivers/net/ethernet/realtek/8139cp.c
@@ -958,6 +958,11 @@ static inline void cp_start_hw (struct cp_private *cp)
958 cpw8(Cmd, RxOn | TxOn); 958 cpw8(Cmd, RxOn | TxOn);
959} 959}
960 960
961static void cp_enable_irq(struct cp_private *cp)
962{
963 cpw16_f(IntrMask, cp_intr_mask);
964}
965
961static void cp_init_hw (struct cp_private *cp) 966static void cp_init_hw (struct cp_private *cp)
962{ 967{
963 struct net_device *dev = cp->dev; 968 struct net_device *dev = cp->dev;
@@ -997,8 +1002,6 @@ static void cp_init_hw (struct cp_private *cp)
997 1002
998 cpw16(MultiIntr, 0); 1003 cpw16(MultiIntr, 0);
999 1004
1000 cpw16_f(IntrMask, cp_intr_mask);
1001
1002 cpw8_f(Cfg9346, Cfg9346_Lock); 1005 cpw8_f(Cfg9346, Cfg9346_Lock);
1003} 1006}
1004 1007
@@ -1130,6 +1133,8 @@ static int cp_open (struct net_device *dev)
1130 if (rc) 1133 if (rc)
1131 goto err_out_hw; 1134 goto err_out_hw;
1132 1135
1136 cp_enable_irq(cp);
1137
1133 netif_carrier_off(dev); 1138 netif_carrier_off(dev);
1134 mii_check_media(&cp->mii_if, netif_msg_link(cp), true); 1139 mii_check_media(&cp->mii_if, netif_msg_link(cp), true);
1135 netif_start_queue(dev); 1140 netif_start_queue(dev);
@@ -2031,6 +2036,7 @@ static int cp_resume (struct pci_dev *pdev)
2031 /* FIXME: sh*t may happen if the Rx ring buffer is depleted */ 2036 /* FIXME: sh*t may happen if the Rx ring buffer is depleted */
2032 cp_init_rings_index (cp); 2037 cp_init_rings_index (cp);
2033 cp_init_hw (cp); 2038 cp_init_hw (cp);
2039 cp_enable_irq(cp);
2034 netif_start_queue (dev); 2040 netif_start_queue (dev);
2035 2041
2036 spin_lock_irqsave (&cp->lock, flags); 2042 spin_lock_irqsave (&cp->lock, flags);
diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
index 7b23554f80b6..ce6b44d1f252 100644
--- a/drivers/net/ethernet/realtek/r8169.c
+++ b/drivers/net/ethernet/realtek/r8169.c
@@ -61,8 +61,12 @@
61#define R8169_MSG_DEFAULT \ 61#define R8169_MSG_DEFAULT \
62 (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN) 62 (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN)
63 63
64#define TX_BUFFS_AVAIL(tp) \ 64#define TX_SLOTS_AVAIL(tp) \
65 (tp->dirty_tx + NUM_TX_DESC - tp->cur_tx - 1) 65 (tp->dirty_tx + NUM_TX_DESC - tp->cur_tx)
66
67/* A skbuff with nr_frags needs nr_frags+1 entries in the tx queue */
68#define TX_FRAGS_READY_FOR(tp,nr_frags) \
69 (TX_SLOTS_AVAIL(tp) >= (nr_frags + 1))
66 70
67/* Maximum number of multicast addresses to filter (vs. Rx-all-multicast). 71/* Maximum number of multicast addresses to filter (vs. Rx-all-multicast).
68 The RTL chips use a 64 element hash table based on the Ethernet CRC. */ 72 The RTL chips use a 64 element hash table based on the Ethernet CRC. */
@@ -5115,7 +5119,7 @@ static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb,
5115 u32 opts[2]; 5119 u32 opts[2];
5116 int frags; 5120 int frags;
5117 5121
5118 if (unlikely(TX_BUFFS_AVAIL(tp) < skb_shinfo(skb)->nr_frags)) { 5122 if (unlikely(!TX_FRAGS_READY_FOR(tp, skb_shinfo(skb)->nr_frags))) {
5119 netif_err(tp, drv, dev, "BUG! Tx Ring full when queue awake!\n"); 5123 netif_err(tp, drv, dev, "BUG! Tx Ring full when queue awake!\n");
5120 goto err_stop_0; 5124 goto err_stop_0;
5121 } 5125 }
@@ -5169,7 +5173,7 @@ static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb,
5169 5173
5170 mmiowb(); 5174 mmiowb();
5171 5175
5172 if (TX_BUFFS_AVAIL(tp) < MAX_SKB_FRAGS) { 5176 if (!TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) {
5173 /* Avoid wrongly optimistic queue wake-up: rtl_tx thread must 5177 /* Avoid wrongly optimistic queue wake-up: rtl_tx thread must
5174 * not miss a ring update when it notices a stopped queue. 5178 * not miss a ring update when it notices a stopped queue.
5175 */ 5179 */
@@ -5183,7 +5187,7 @@ static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb,
5183 * can't. 5187 * can't.
5184 */ 5188 */
5185 smp_mb(); 5189 smp_mb();
5186 if (TX_BUFFS_AVAIL(tp) >= MAX_SKB_FRAGS) 5190 if (TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS))
5187 netif_wake_queue(dev); 5191 netif_wake_queue(dev);
5188 } 5192 }
5189 5193
@@ -5306,7 +5310,7 @@ static void rtl_tx(struct net_device *dev, struct rtl8169_private *tp)
5306 */ 5310 */
5307 smp_mb(); 5311 smp_mb();
5308 if (netif_queue_stopped(dev) && 5312 if (netif_queue_stopped(dev) &&
5309 (TX_BUFFS_AVAIL(tp) >= MAX_SKB_FRAGS)) { 5313 TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) {
5310 netif_wake_queue(dev); 5314 netif_wake_queue(dev);
5311 } 5315 }
5312 /* 5316 /*
@@ -5810,7 +5814,10 @@ static void __rtl8169_resume(struct net_device *dev)
5810 5814
5811 rtl_pll_power_up(tp); 5815 rtl_pll_power_up(tp);
5812 5816
5817 rtl_lock_work(tp);
5818 napi_enable(&tp->napi);
5813 set_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); 5819 set_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags);
5820 rtl_unlock_work(tp);
5814 5821
5815 rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); 5822 rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING);
5816} 5823}
diff --git a/drivers/net/ethernet/renesas/Kconfig b/drivers/net/ethernet/renesas/Kconfig
index 9755b49bbefb..3fb2355af37e 100644
--- a/drivers/net/ethernet/renesas/Kconfig
+++ b/drivers/net/ethernet/renesas/Kconfig
@@ -7,7 +7,8 @@ config SH_ETH
7 depends on SUPERH && \ 7 depends on SUPERH && \
8 (CPU_SUBTYPE_SH7710 || CPU_SUBTYPE_SH7712 || \ 8 (CPU_SUBTYPE_SH7710 || CPU_SUBTYPE_SH7712 || \
9 CPU_SUBTYPE_SH7763 || CPU_SUBTYPE_SH7619 || \ 9 CPU_SUBTYPE_SH7763 || CPU_SUBTYPE_SH7619 || \
10 CPU_SUBTYPE_SH7724 || CPU_SUBTYPE_SH7757) 10 CPU_SUBTYPE_SH7724 || CPU_SUBTYPE_SH7734 || \
11 CPU_SUBTYPE_SH7757)
11 select CRC32 12 select CRC32
12 select NET_CORE 13 select NET_CORE
13 select MII 14 select MII
@@ -16,4 +17,4 @@ config SH_ETH
16 ---help--- 17 ---help---
17 Renesas SuperH Ethernet device driver. 18 Renesas SuperH Ethernet device driver.
18 This driver supporting CPUs are: 19 This driver supporting CPUs are:
19 - SH7710, SH7712, SH7763, SH7619, SH7724, and SH7757. 20 - SH7619, SH7710, SH7712, SH7724, SH7734, SH7763 and SH7757.
diff --git a/drivers/net/ethernet/renesas/sh_eth.c b/drivers/net/ethernet/renesas/sh_eth.c
index 8615961c1287..d63e09b29a96 100644
--- a/drivers/net/ethernet/renesas/sh_eth.c
+++ b/drivers/net/ethernet/renesas/sh_eth.c
@@ -1,8 +1,8 @@
1/* 1/*
2 * SuperH Ethernet device driver 2 * SuperH Ethernet device driver
3 * 3 *
4 * Copyright (C) 2006-2008 Nobuhiro Iwamatsu 4 * Copyright (C) 2006-2012 Nobuhiro Iwamatsu
5 * Copyright (C) 2008-2009 Renesas Solutions Corp. 5 * Copyright (C) 2008-2012 Renesas Solutions Corp.
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify it 7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms and conditions of the GNU General Public License, 8 * under the terms and conditions of the GNU General Public License,
@@ -38,6 +38,7 @@
38#include <linux/slab.h> 38#include <linux/slab.h>
39#include <linux/ethtool.h> 39#include <linux/ethtool.h>
40#include <linux/if_vlan.h> 40#include <linux/if_vlan.h>
41#include <linux/clk.h>
41#include <linux/sh_eth.h> 42#include <linux/sh_eth.h>
42 43
43#include "sh_eth.h" 44#include "sh_eth.h"
@@ -279,8 +280,9 @@ static struct sh_eth_cpu_data *sh_eth_get_cpu_data(struct sh_eth_private *mdp)
279 return &sh_eth_my_cpu_data; 280 return &sh_eth_my_cpu_data;
280} 281}
281 282
282#elif defined(CONFIG_CPU_SUBTYPE_SH7763) 283#elif defined(CONFIG_CPU_SUBTYPE_SH7734) || defined(CONFIG_CPU_SUBTYPE_SH7763)
283#define SH_ETH_HAS_TSU 1 284#define SH_ETH_HAS_TSU 1
285static void sh_eth_reset_hw_crc(struct net_device *ndev);
284static void sh_eth_chip_reset(struct net_device *ndev) 286static void sh_eth_chip_reset(struct net_device *ndev)
285{ 287{
286 struct sh_eth_private *mdp = netdev_priv(ndev); 288 struct sh_eth_private *mdp = netdev_priv(ndev);
@@ -314,6 +316,9 @@ static void sh_eth_reset(struct net_device *ndev)
314 sh_eth_write(ndev, 0x0, RDFAR); 316 sh_eth_write(ndev, 0x0, RDFAR);
315 sh_eth_write(ndev, 0x0, RDFXR); 317 sh_eth_write(ndev, 0x0, RDFXR);
316 sh_eth_write(ndev, 0x0, RDFFR); 318 sh_eth_write(ndev, 0x0, RDFFR);
319
320 /* Reset HW CRC register */
321 sh_eth_reset_hw_crc(ndev);
317} 322}
318 323
319static void sh_eth_set_duplex(struct net_device *ndev) 324static void sh_eth_set_duplex(struct net_device *ndev)
@@ -370,8 +375,17 @@ static struct sh_eth_cpu_data sh_eth_my_cpu_data = {
370 .no_trimd = 1, 375 .no_trimd = 1,
371 .no_ade = 1, 376 .no_ade = 1,
372 .tsu = 1, 377 .tsu = 1,
378#if defined(CONFIG_CPU_SUBTYPE_SH7734)
379 .hw_crc = 1,
380#endif
373}; 381};
374 382
383static void sh_eth_reset_hw_crc(struct net_device *ndev)
384{
385 if (sh_eth_my_cpu_data.hw_crc)
386 sh_eth_write(ndev, 0x0, CSMR);
387}
388
375#elif defined(CONFIG_CPU_SUBTYPE_SH7619) 389#elif defined(CONFIG_CPU_SUBTYPE_SH7619)
376#define SH_ETH_RESET_DEFAULT 1 390#define SH_ETH_RESET_DEFAULT 1
377static struct sh_eth_cpu_data sh_eth_my_cpu_data = { 391static struct sh_eth_cpu_data sh_eth_my_cpu_data = {
@@ -790,7 +804,7 @@ static int sh_eth_dev_init(struct net_device *ndev)
790 /* all sh_eth int mask */ 804 /* all sh_eth int mask */
791 sh_eth_write(ndev, 0, EESIPR); 805 sh_eth_write(ndev, 0, EESIPR);
792 806
793#if defined(__LITTLE_ENDIAN__) 807#if defined(__LITTLE_ENDIAN)
794 if (mdp->cd->hw_swap) 808 if (mdp->cd->hw_swap)
795 sh_eth_write(ndev, EDMR_EL, EDMR); 809 sh_eth_write(ndev, EDMR_EL, EDMR);
796 else 810 else
diff --git a/drivers/net/ethernet/renesas/sh_eth.h b/drivers/net/ethernet/renesas/sh_eth.h
index 57dc26261116..0fa14afce23d 100644
--- a/drivers/net/ethernet/renesas/sh_eth.h
+++ b/drivers/net/ethernet/renesas/sh_eth.h
@@ -1,8 +1,8 @@
1/* 1/*
2 * SuperH Ethernet device driver 2 * SuperH Ethernet device driver
3 * 3 *
4 * Copyright (C) 2006-2008 Nobuhiro Iwamatsu 4 * Copyright (C) 2006-2012 Nobuhiro Iwamatsu
5 * Copyright (C) 2008-2011 Renesas Solutions Corp. 5 * Copyright (C) 2008-2012 Renesas Solutions Corp.
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify it 7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms and conditions of the GNU General Public License, 8 * under the terms and conditions of the GNU General Public License,
@@ -98,6 +98,8 @@ enum {
98 CEECR, 98 CEECR,
99 MAFCR, 99 MAFCR,
100 RTRATE, 100 RTRATE,
101 CSMR,
102 RMII_MII,
101 103
102 /* TSU Absolute address */ 104 /* TSU Absolute address */
103 ARSTR, 105 ARSTR,
@@ -172,6 +174,7 @@ static const u16 sh_eth_offset_gigabit[SH_ETH_MAX_REGISTER_OFFSET] = {
172 [RMCR] = 0x0458, 174 [RMCR] = 0x0458,
173 [RPADIR] = 0x0460, 175 [RPADIR] = 0x0460,
174 [FCFTR] = 0x0468, 176 [FCFTR] = 0x0468,
177 [CSMR] = 0x04E4,
175 178
176 [ECMR] = 0x0500, 179 [ECMR] = 0x0500,
177 [ECSR] = 0x0510, 180 [ECSR] = 0x0510,
@@ -200,6 +203,7 @@ static const u16 sh_eth_offset_gigabit[SH_ETH_MAX_REGISTER_OFFSET] = {
200 [CERCR] = 0x0768, 203 [CERCR] = 0x0768,
201 [CEECR] = 0x0770, 204 [CEECR] = 0x0770,
202 [MAFCR] = 0x0778, 205 [MAFCR] = 0x0778,
206 [RMII_MII] = 0x0790,
203 207
204 [ARSTR] = 0x0000, 208 [ARSTR] = 0x0000,
205 [TSU_CTRST] = 0x0004, 209 [TSU_CTRST] = 0x0004,
@@ -377,7 +381,7 @@ static const u16 sh_eth_offset_fast_sh3_sh2[SH_ETH_MAX_REGISTER_OFFSET] = {
377/* 381/*
378 * Register's bits 382 * Register's bits
379 */ 383 */
380#ifdef CONFIG_CPU_SUBTYPE_SH7763 384#if defined(CONFIG_CPU_SUBTYPE_SH7734) || defined(CONFIG_CPU_SUBTYPE_SH7763)
381/* EDSR */ 385/* EDSR */
382enum EDSR_BIT { 386enum EDSR_BIT {
383 EDSR_ENT = 0x01, EDSR_ENR = 0x02, 387 EDSR_ENT = 0x01, EDSR_ENR = 0x02,
@@ -689,7 +693,7 @@ enum TSU_FWSLC_BIT {
689 */ 693 */
690struct sh_eth_txdesc { 694struct sh_eth_txdesc {
691 u32 status; /* TD0 */ 695 u32 status; /* TD0 */
692#if defined(CONFIG_CPU_LITTLE_ENDIAN) 696#if defined(__LITTLE_ENDIAN)
693 u16 pad0; /* TD1 */ 697 u16 pad0; /* TD1 */
694 u16 buffer_length; /* TD1 */ 698 u16 buffer_length; /* TD1 */
695#else 699#else
@@ -706,7 +710,7 @@ struct sh_eth_txdesc {
706 */ 710 */
707struct sh_eth_rxdesc { 711struct sh_eth_rxdesc {
708 u32 status; /* RD0 */ 712 u32 status; /* RD0 */
709#if defined(CONFIG_CPU_LITTLE_ENDIAN) 713#if defined(__LITTLE_ENDIAN)
710 u16 frame_length; /* RD1 */ 714 u16 frame_length; /* RD1 */
711 u16 buffer_length; /* RD1 */ 715 u16 buffer_length; /* RD1 */
712#else 716#else
@@ -751,6 +755,7 @@ struct sh_eth_cpu_data {
751 unsigned rpadir:1; /* E-DMAC have RPADIR */ 755 unsigned rpadir:1; /* E-DMAC have RPADIR */
752 unsigned no_trimd:1; /* E-DMAC DO NOT have TRIMD */ 756 unsigned no_trimd:1; /* E-DMAC DO NOT have TRIMD */
753 unsigned no_ade:1; /* E-DMAC DO NOT have ADE bit in EESR */ 757 unsigned no_ade:1; /* E-DMAC DO NOT have ADE bit in EESR */
758 unsigned hw_crc:1; /* E-DMAC have CSMR */
754}; 759};
755 760
756struct sh_eth_private { 761struct sh_eth_private {
diff --git a/drivers/net/ethernet/sfc/efx.c b/drivers/net/ethernet/sfc/efx.c
index 3cbfbffe3f00..4a0005342e65 100644
--- a/drivers/net/ethernet/sfc/efx.c
+++ b/drivers/net/ethernet/sfc/efx.c
@@ -1349,7 +1349,7 @@ static int efx_probe_interrupts(struct efx_nic *efx)
1349 } 1349 }
1350 1350
1351 /* RSS might be usable on VFs even if it is disabled on the PF */ 1351 /* RSS might be usable on VFs even if it is disabled on the PF */
1352 efx->rss_spread = (efx->n_rx_channels > 1 ? 1352 efx->rss_spread = ((efx->n_rx_channels > 1 || !efx_sriov_wanted(efx)) ?
1353 efx->n_rx_channels : efx_vf_size(efx)); 1353 efx->n_rx_channels : efx_vf_size(efx));
1354 1354
1355 return 0; 1355 return 0;
diff --git a/drivers/net/ethernet/smsc/smsc911x.c b/drivers/net/ethernet/smsc/smsc911x.c
index 4a6971027076..cd3defb11ffb 100644
--- a/drivers/net/ethernet/smsc/smsc911x.c
+++ b/drivers/net/ethernet/smsc/smsc911x.c
@@ -1166,10 +1166,8 @@ smsc911x_rx_counterrors(struct net_device *dev, unsigned int rxstat)
1166 1166
1167/* Quickly dumps bad packets */ 1167/* Quickly dumps bad packets */
1168static void 1168static void
1169smsc911x_rx_fastforward(struct smsc911x_data *pdata, unsigned int pktbytes) 1169smsc911x_rx_fastforward(struct smsc911x_data *pdata, unsigned int pktwords)
1170{ 1170{
1171 unsigned int pktwords = (pktbytes + NET_IP_ALIGN + 3) >> 2;
1172
1173 if (likely(pktwords >= 4)) { 1171 if (likely(pktwords >= 4)) {
1174 unsigned int timeout = 500; 1172 unsigned int timeout = 500;
1175 unsigned int val; 1173 unsigned int val;
@@ -1233,7 +1231,7 @@ static int smsc911x_poll(struct napi_struct *napi, int budget)
1233 continue; 1231 continue;
1234 } 1232 }
1235 1233
1236 skb = netdev_alloc_skb(dev, pktlength + NET_IP_ALIGN); 1234 skb = netdev_alloc_skb(dev, pktwords << 2);
1237 if (unlikely(!skb)) { 1235 if (unlikely(!skb)) {
1238 SMSC_WARN(pdata, rx_err, 1236 SMSC_WARN(pdata, rx_err,
1239 "Unable to allocate skb for rx packet"); 1237 "Unable to allocate skb for rx packet");
@@ -1243,14 +1241,12 @@ static int smsc911x_poll(struct napi_struct *napi, int budget)
1243 break; 1241 break;
1244 } 1242 }
1245 1243
1246 skb->data = skb->head; 1244 pdata->ops->rx_readfifo(pdata,
1247 skb_reset_tail_pointer(skb); 1245 (unsigned int *)skb->data, pktwords);
1248 1246
1249 /* Align IP on 16B boundary */ 1247 /* Align IP on 16B boundary */
1250 skb_reserve(skb, NET_IP_ALIGN); 1248 skb_reserve(skb, NET_IP_ALIGN);
1251 skb_put(skb, pktlength - 4); 1249 skb_put(skb, pktlength - 4);
1252 pdata->ops->rx_readfifo(pdata,
1253 (unsigned int *)skb->head, pktwords);
1254 skb->protocol = eth_type_trans(skb, dev); 1250 skb->protocol = eth_type_trans(skb, dev);
1255 skb_checksum_none_assert(skb); 1251 skb_checksum_none_assert(skb);
1256 netif_receive_skb(skb); 1252 netif_receive_skb(skb);
@@ -1565,7 +1561,7 @@ static int smsc911x_open(struct net_device *dev)
1565 smsc911x_reg_write(pdata, FIFO_INT, temp); 1561 smsc911x_reg_write(pdata, FIFO_INT, temp);
1566 1562
1567 /* set RX Data offset to 2 bytes for alignment */ 1563 /* set RX Data offset to 2 bytes for alignment */
1568 smsc911x_reg_write(pdata, RX_CFG, (2 << 8)); 1564 smsc911x_reg_write(pdata, RX_CFG, (NET_IP_ALIGN << 8));
1569 1565
1570 /* enable NAPI polling before enabling RX interrupts */ 1566 /* enable NAPI polling before enabling RX interrupts */
1571 napi_enable(&pdata->napi); 1567 napi_enable(&pdata->napi);
@@ -2382,7 +2378,6 @@ static int __devinit smsc911x_drv_probe(struct platform_device *pdev)
2382 SET_NETDEV_DEV(dev, &pdev->dev); 2378 SET_NETDEV_DEV(dev, &pdev->dev);
2383 2379
2384 pdata = netdev_priv(dev); 2380 pdata = netdev_priv(dev);
2385
2386 dev->irq = irq_res->start; 2381 dev->irq = irq_res->start;
2387 irq_flags = irq_res->flags & IRQF_TRIGGER_MASK; 2382 irq_flags = irq_res->flags & IRQF_TRIGGER_MASK;
2388 pdata->ioaddr = ioremap_nocache(res->start, res_size); 2383 pdata->ioaddr = ioremap_nocache(res->start, res_size);
@@ -2446,7 +2441,7 @@ static int __devinit smsc911x_drv_probe(struct platform_device *pdev)
2446 if (retval) { 2441 if (retval) {
2447 SMSC_WARN(pdata, probe, 2442 SMSC_WARN(pdata, probe,
2448 "Unable to claim requested irq: %d", dev->irq); 2443 "Unable to claim requested irq: %d", dev->irq);
2449 goto out_free_irq; 2444 goto out_disable_resources;
2450 } 2445 }
2451 2446
2452 retval = register_netdev(dev); 2447 retval = register_netdev(dev);
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index e85ffbd54830..48d56da62f08 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -1737,10 +1737,12 @@ static int stmmac_hw_init(struct stmmac_priv *priv)
1737 struct mac_device_info *mac; 1737 struct mac_device_info *mac;
1738 1738
1739 /* Identify the MAC HW device */ 1739 /* Identify the MAC HW device */
1740 if (priv->plat->has_gmac) 1740 if (priv->plat->has_gmac) {
1741 priv->dev->priv_flags |= IFF_UNICAST_FLT;
1741 mac = dwmac1000_setup(priv->ioaddr); 1742 mac = dwmac1000_setup(priv->ioaddr);
1742 else 1743 } else {
1743 mac = dwmac100_setup(priv->ioaddr); 1744 mac = dwmac100_setup(priv->ioaddr);
1745 }
1744 if (!mac) 1746 if (!mac)
1745 return -ENOMEM; 1747 return -ENOMEM;
1746 1748
diff --git a/drivers/net/ethernet/sun/sungem.c b/drivers/net/ethernet/sun/sungem.c
index 558409ff4058..4ba969096717 100644
--- a/drivers/net/ethernet/sun/sungem.c
+++ b/drivers/net/ethernet/sun/sungem.c
@@ -2339,7 +2339,7 @@ static int gem_suspend(struct pci_dev *pdev, pm_message_t state)
2339 netif_device_detach(dev); 2339 netif_device_detach(dev);
2340 2340
2341 /* Switch off chip, remember WOL setting */ 2341 /* Switch off chip, remember WOL setting */
2342 gp->asleep_wol = gp->wake_on_lan; 2342 gp->asleep_wol = !!gp->wake_on_lan;
2343 gem_do_stop(dev, gp->asleep_wol); 2343 gem_do_stop(dev, gp->asleep_wol);
2344 2344
2345 /* Unlock the network stack */ 2345 /* Unlock the network stack */
diff --git a/drivers/net/ethernet/ti/davinci_emac.c b/drivers/net/ethernet/ti/davinci_emac.c
index 174a3348f676..08aff1a2087c 100644
--- a/drivers/net/ethernet/ti/davinci_emac.c
+++ b/drivers/net/ethernet/ti/davinci_emac.c
@@ -1511,7 +1511,7 @@ static int emac_devioctl(struct net_device *ndev, struct ifreq *ifrq, int cmd)
1511 1511
1512static int match_first_device(struct device *dev, void *data) 1512static int match_first_device(struct device *dev, void *data)
1513{ 1513{
1514 return 1; 1514 return !strncmp(dev_name(dev), "davinci_mdio", 12);
1515} 1515}
1516 1516
1517/** 1517/**
diff --git a/drivers/net/ethernet/ti/davinci_mdio.c b/drivers/net/ethernet/ti/davinci_mdio.c
index 2757c7d6e633..e4e47088e26b 100644
--- a/drivers/net/ethernet/ti/davinci_mdio.c
+++ b/drivers/net/ethernet/ti/davinci_mdio.c
@@ -181,6 +181,11 @@ static inline int wait_for_user_access(struct davinci_mdio_data *data)
181 __davinci_mdio_reset(data); 181 __davinci_mdio_reset(data);
182 return -EAGAIN; 182 return -EAGAIN;
183 } 183 }
184
185 reg = __raw_readl(&regs->user[0].access);
186 if ((reg & USERACCESS_GO) == 0)
187 return 0;
188
184 dev_err(data->dev, "timed out waiting for user access\n"); 189 dev_err(data->dev, "timed out waiting for user access\n");
185 return -ETIMEDOUT; 190 return -ETIMEDOUT;
186} 191}
diff --git a/drivers/net/ethernet/ti/tlan.c b/drivers/net/ethernet/ti/tlan.c
index 817ad3bc4957..efd36691ce54 100644
--- a/drivers/net/ethernet/ti/tlan.c
+++ b/drivers/net/ethernet/ti/tlan.c
@@ -228,7 +228,7 @@ tlan_get_skb(const struct tlan_list *tag)
228 unsigned long addr; 228 unsigned long addr;
229 229
230 addr = tag->buffer[9].address; 230 addr = tag->buffer[9].address;
231 addr |= (tag->buffer[8].address << 16) << 16; 231 addr |= ((unsigned long) tag->buffer[8].address << 16) << 16;
232 return (struct sk_buff *) addr; 232 return (struct sk_buff *) addr;
233} 233}
234 234
diff --git a/drivers/net/ethernet/tile/tilepro.c b/drivers/net/ethernet/tile/tilepro.c
index 261356c2dc99..3d501ec7fad7 100644
--- a/drivers/net/ethernet/tile/tilepro.c
+++ b/drivers/net/ethernet/tile/tilepro.c
@@ -342,6 +342,21 @@ inline int __netio_fastio1(u32 fastio_index, u32 arg0)
342} 342}
343 343
344 344
345static void tile_net_return_credit(struct tile_net_cpu *info)
346{
347 struct tile_netio_queue *queue = &info->queue;
348 netio_queue_user_impl_t *qup = &queue->__user_part;
349
350 /* Return four credits after every fourth packet. */
351 if (--qup->__receive_credit_remaining == 0) {
352 u32 interval = qup->__receive_credit_interval;
353 qup->__receive_credit_remaining = interval;
354 __netio_fastio_return_credits(qup->__fastio_index, interval);
355 }
356}
357
358
359
345/* 360/*
346 * Provide a linux buffer to LIPP. 361 * Provide a linux buffer to LIPP.
347 */ 362 */
@@ -433,7 +448,7 @@ static bool tile_net_provide_needed_buffer(struct tile_net_cpu *info,
433 struct sk_buff **skb_ptr; 448 struct sk_buff **skb_ptr;
434 449
435 /* Request 96 extra bytes for alignment purposes. */ 450 /* Request 96 extra bytes for alignment purposes. */
436 skb = netdev_alloc_skb(info->napi->dev, len + padding); 451 skb = netdev_alloc_skb(info->napi.dev, len + padding);
437 if (skb == NULL) 452 if (skb == NULL)
438 return false; 453 return false;
439 454
@@ -864,19 +879,11 @@ static bool tile_net_poll_aux(struct tile_net_cpu *info, int index)
864 879
865 stats->rx_packets++; 880 stats->rx_packets++;
866 stats->rx_bytes += len; 881 stats->rx_bytes += len;
867
868 if (small)
869 info->num_needed_small_buffers++;
870 else
871 info->num_needed_large_buffers++;
872 } 882 }
873 883
874 /* Return four credits after every fourth packet. */ 884 /* ISSUE: It would be nice to defer this until the packet has */
875 if (--qup->__receive_credit_remaining == 0) { 885 /* actually been processed. */
876 u32 interval = qup->__receive_credit_interval; 886 tile_net_return_credit(info);
877 qup->__receive_credit_remaining = interval;
878 __netio_fastio_return_credits(qup->__fastio_index, interval);
879 }
880 887
881 /* Consume this packet. */ 888 /* Consume this packet. */
882 qup->__packet_receive_read = index2; 889 qup->__packet_receive_read = index2;
@@ -1543,7 +1550,7 @@ static int tile_net_drain_lipp_buffers(struct tile_net_priv *priv)
1543 1550
1544 /* Drain all the LIPP buffers. */ 1551 /* Drain all the LIPP buffers. */
1545 while (true) { 1552 while (true) {
1546 int buffer; 1553 unsigned int buffer;
1547 1554
1548 /* NOTE: This should never fail. */ 1555 /* NOTE: This should never fail. */
1549 if (hv_dev_pread(priv->hv_devhdl, 0, (HV_VirtAddr)&buffer, 1556 if (hv_dev_pread(priv->hv_devhdl, 0, (HV_VirtAddr)&buffer,
@@ -1707,7 +1714,7 @@ static unsigned int tile_net_tx_frags(lepp_frag_t *frags,
1707 if (!hash_default) { 1714 if (!hash_default) {
1708 void *va = pfn_to_kaddr(pfn) + f->page_offset; 1715 void *va = pfn_to_kaddr(pfn) + f->page_offset;
1709 BUG_ON(PageHighMem(skb_frag_page(f))); 1716 BUG_ON(PageHighMem(skb_frag_page(f)));
1710 finv_buffer_remote(va, f->size, 0); 1717 finv_buffer_remote(va, skb_frag_size(f), 0);
1711 } 1718 }
1712 1719
1713 cpa = ((phys_addr_t)pfn << PAGE_SHIFT) + f->page_offset; 1720 cpa = ((phys_addr_t)pfn << PAGE_SHIFT) + f->page_offset;
@@ -1735,8 +1742,8 @@ static unsigned int tile_net_tx_frags(lepp_frag_t *frags,
1735 * Sometimes, if "sendfile()" requires copying, we will be called with 1742 * Sometimes, if "sendfile()" requires copying, we will be called with
1736 * "data" containing the header and payload, with "frags" being empty. 1743 * "data" containing the header and payload, with "frags" being empty.
1737 * 1744 *
1738 * In theory, "sh->nr_frags" could be 3, but in practice, it seems 1745 * Sometimes, for example when using NFS over TCP, a single segment can
1739 * that this will never actually happen. 1746 * span 3 fragments, which must be handled carefully in LEPP.
1740 * 1747 *
1741 * See "emulate_large_send_offload()" for some reference code, which 1748 * See "emulate_large_send_offload()" for some reference code, which
1742 * does not handle checksumming. 1749 * does not handle checksumming.
@@ -1844,10 +1851,8 @@ static int tile_net_tx_tso(struct sk_buff *skb, struct net_device *dev)
1844 1851
1845 spin_lock_irqsave(&priv->eq_lock, irqflags); 1852 spin_lock_irqsave(&priv->eq_lock, irqflags);
1846 1853
1847 /* 1854 /* Handle completions if needed to make room. */
1848 * Handle completions if needed to make room. 1855 /* NOTE: Return NETDEV_TX_BUSY if there is still no room. */
1849 * HACK: Spin until there is sufficient room.
1850 */
1851 if (lepp_num_free_comp_slots(eq) == 0) { 1856 if (lepp_num_free_comp_slots(eq) == 0) {
1852 nolds = tile_net_lepp_grab_comps(eq, olds, wanted, 0); 1857 nolds = tile_net_lepp_grab_comps(eq, olds, wanted, 0);
1853 if (nolds == 0) { 1858 if (nolds == 0) {
@@ -1861,6 +1866,7 @@ busy:
1861 cmd_tail = eq->cmd_tail; 1866 cmd_tail = eq->cmd_tail;
1862 1867
1863 /* Prepare to advance, detecting full queue. */ 1868 /* Prepare to advance, detecting full queue. */
1869 /* NOTE: Return NETDEV_TX_BUSY if the queue is full. */
1864 cmd_next = cmd_tail + cmd_size; 1870 cmd_next = cmd_tail + cmd_size;
1865 if (cmd_tail < cmd_head && cmd_next >= cmd_head) 1871 if (cmd_tail < cmd_head && cmd_next >= cmd_head)
1866 goto busy; 1872 goto busy;
@@ -2023,10 +2029,8 @@ static int tile_net_tx(struct sk_buff *skb, struct net_device *dev)
2023 2029
2024 spin_lock_irqsave(&priv->eq_lock, irqflags); 2030 spin_lock_irqsave(&priv->eq_lock, irqflags);
2025 2031
2026 /* 2032 /* Handle completions if needed to make room. */
2027 * Handle completions if needed to make room. 2033 /* NOTE: Return NETDEV_TX_BUSY if there is still no room. */
2028 * HACK: Spin until there is sufficient room.
2029 */
2030 if (lepp_num_free_comp_slots(eq) == 0) { 2034 if (lepp_num_free_comp_slots(eq) == 0) {
2031 nolds = tile_net_lepp_grab_comps(eq, olds, wanted, 0); 2035 nolds = tile_net_lepp_grab_comps(eq, olds, wanted, 0);
2032 if (nolds == 0) { 2036 if (nolds == 0) {
@@ -2040,6 +2044,7 @@ busy:
2040 cmd_tail = eq->cmd_tail; 2044 cmd_tail = eq->cmd_tail;
2041 2045
2042 /* Copy the commands, or fail. */ 2046 /* Copy the commands, or fail. */
2047 /* NOTE: Return NETDEV_TX_BUSY if the queue is full. */
2043 for (i = 0; i < num_frags; i++) { 2048 for (i = 0; i < num_frags; i++) {
2044 2049
2045 /* Prepare to advance, detecting full queue. */ 2050 /* Prepare to advance, detecting full queue. */
@@ -2261,6 +2266,23 @@ static int tile_net_get_mac(struct net_device *dev)
2261 return 0; 2266 return 0;
2262} 2267}
2263 2268
2269
2270#ifdef CONFIG_NET_POLL_CONTROLLER
2271/*
2272 * Polling 'interrupt' - used by things like netconsole to send skbs
2273 * without having to re-enable interrupts. It's not called while
2274 * the interrupt routine is executing.
2275 */
2276static void tile_net_netpoll(struct net_device *dev)
2277{
2278 struct tile_net_priv *priv = netdev_priv(dev);
2279 disable_percpu_irq(priv->intr_id);
2280 tile_net_handle_ingress_interrupt(priv->intr_id, dev);
2281 enable_percpu_irq(priv->intr_id, 0);
2282}
2283#endif
2284
2285
2264static const struct net_device_ops tile_net_ops = { 2286static const struct net_device_ops tile_net_ops = {
2265 .ndo_open = tile_net_open, 2287 .ndo_open = tile_net_open,
2266 .ndo_stop = tile_net_stop, 2288 .ndo_stop = tile_net_stop,
@@ -2269,7 +2291,10 @@ static const struct net_device_ops tile_net_ops = {
2269 .ndo_get_stats = tile_net_get_stats, 2291 .ndo_get_stats = tile_net_get_stats,
2270 .ndo_change_mtu = tile_net_change_mtu, 2292 .ndo_change_mtu = tile_net_change_mtu,
2271 .ndo_tx_timeout = tile_net_tx_timeout, 2293 .ndo_tx_timeout = tile_net_tx_timeout,
2272 .ndo_set_mac_address = tile_net_set_mac_address 2294 .ndo_set_mac_address = tile_net_set_mac_address,
2295#ifdef CONFIG_NET_POLL_CONTROLLER
2296 .ndo_poll_controller = tile_net_netpoll,
2297#endif
2273}; 2298};
2274 2299
2275 2300
@@ -2409,7 +2434,7 @@ static void tile_net_cleanup(void)
2409 */ 2434 */
2410static int tile_net_init_module(void) 2435static int tile_net_init_module(void)
2411{ 2436{
2412 pr_info("Tilera IPP Net Driver\n"); 2437 pr_info("Tilera Network Driver\n");
2413 2438
2414 tile_net_devs[0] = tile_net_dev_init("xgbe0"); 2439 tile_net_devs[0] = tile_net_dev_init("xgbe0");
2415 tile_net_devs[1] = tile_net_dev_init("xgbe1"); 2440 tile_net_devs[1] = tile_net_dev_init("xgbe1");
diff --git a/drivers/net/ethernet/via/via-rhine.c b/drivers/net/ethernet/via/via-rhine.c
index 39b8cf3dafcd..fcfa01f7ceb6 100644
--- a/drivers/net/ethernet/via/via-rhine.c
+++ b/drivers/net/ethernet/via/via-rhine.c
@@ -503,30 +503,32 @@ static int rhine_vlan_rx_add_vid(struct net_device *dev, unsigned short vid);
503static int rhine_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid); 503static int rhine_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid);
504static void rhine_restart_tx(struct net_device *dev); 504static void rhine_restart_tx(struct net_device *dev);
505 505
506static void rhine_wait_bit(struct rhine_private *rp, u8 reg, u8 mask, bool high) 506static void rhine_wait_bit(struct rhine_private *rp, u8 reg, u8 mask, bool low)
507{ 507{
508 void __iomem *ioaddr = rp->base; 508 void __iomem *ioaddr = rp->base;
509 int i; 509 int i;
510 510
511 for (i = 0; i < 1024; i++) { 511 for (i = 0; i < 1024; i++) {
512 if (high ^ !!(ioread8(ioaddr + reg) & mask)) 512 bool has_mask_bits = !!(ioread8(ioaddr + reg) & mask);
513
514 if (low ^ has_mask_bits)
513 break; 515 break;
514 udelay(10); 516 udelay(10);
515 } 517 }
516 if (i > 64) { 518 if (i > 64) {
517 netif_dbg(rp, hw, rp->dev, "%s bit wait (%02x/%02x) cycle " 519 netif_dbg(rp, hw, rp->dev, "%s bit wait (%02x/%02x) cycle "
518 "count: %04d\n", high ? "high" : "low", reg, mask, i); 520 "count: %04d\n", low ? "low" : "high", reg, mask, i);
519 } 521 }
520} 522}
521 523
522static void rhine_wait_bit_high(struct rhine_private *rp, u8 reg, u8 mask) 524static void rhine_wait_bit_high(struct rhine_private *rp, u8 reg, u8 mask)
523{ 525{
524 rhine_wait_bit(rp, reg, mask, true); 526 rhine_wait_bit(rp, reg, mask, false);
525} 527}
526 528
527static void rhine_wait_bit_low(struct rhine_private *rp, u8 reg, u8 mask) 529static void rhine_wait_bit_low(struct rhine_private *rp, u8 reg, u8 mask)
528{ 530{
529 rhine_wait_bit(rp, reg, mask, false); 531 rhine_wait_bit(rp, reg, mask, true);
530} 532}
531 533
532static u32 rhine_get_events(struct rhine_private *rp) 534static u32 rhine_get_events(struct rhine_private *rp)
diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet.h b/drivers/net/ethernet/xilinx/xilinx_axienet.h
index cc83af083fd7..44b8d2bad8c3 100644
--- a/drivers/net/ethernet/xilinx/xilinx_axienet.h
+++ b/drivers/net/ethernet/xilinx/xilinx_axienet.h
@@ -2,9 +2,7 @@
2 * Definitions for Xilinx Axi Ethernet device driver. 2 * Definitions for Xilinx Axi Ethernet device driver.
3 * 3 *
4 * Copyright (c) 2009 Secret Lab Technologies, Ltd. 4 * Copyright (c) 2009 Secret Lab Technologies, Ltd.
5 * Copyright (c) 2010 Xilinx, Inc. All rights reserved. 5 * Copyright (c) 2010 - 2012 Xilinx, Inc. All rights reserved.
6 * Copyright (c) 2012 Daniel Borkmann, <daniel.borkmann@tik.ee.ethz.ch>
7 * Copyright (c) 2012 Ariane Keller, <ariane.keller@tik.ee.ethz.ch>
8 */ 6 */
9 7
10#ifndef XILINX_AXIENET_H 8#ifndef XILINX_AXIENET_H
diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
index 2fcbeba6814b..9c365e192a31 100644
--- a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
+++ b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
@@ -4,9 +4,9 @@
4 * Copyright (c) 2008 Nissin Systems Co., Ltd., Yoshio Kashiwagi 4 * Copyright (c) 2008 Nissin Systems Co., Ltd., Yoshio Kashiwagi
5 * Copyright (c) 2005-2008 DLA Systems, David H. Lynch Jr. <dhlii@dlasys.net> 5 * Copyright (c) 2005-2008 DLA Systems, David H. Lynch Jr. <dhlii@dlasys.net>
6 * Copyright (c) 2008-2009 Secret Lab Technologies Ltd. 6 * Copyright (c) 2008-2009 Secret Lab Technologies Ltd.
7 * Copyright (c) 2010 Xilinx, Inc. All rights reserved. 7 * Copyright (c) 2010 - 2011 Michal Simek <monstr@monstr.eu>
8 * Copyright (c) 2012 Daniel Borkmann, <daniel.borkmann@tik.ee.ethz.ch> 8 * Copyright (c) 2010 - 2011 PetaLogix
9 * Copyright (c) 2012 Ariane Keller, <ariane.keller@tik.ee.ethz.ch> 9 * Copyright (c) 2010 - 2012 Xilinx, Inc. All rights reserved.
10 * 10 *
11 * This is a driver for the Xilinx Axi Ethernet which is used in the Virtex6 11 * This is a driver for the Xilinx Axi Ethernet which is used in the Virtex6
12 * and Spartan6. 12 * and Spartan6.
diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c b/drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c
index d70b6e79f6c0..e90e1f46121e 100644
--- a/drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c
+++ b/drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c
@@ -2,9 +2,9 @@
2 * MDIO bus driver for the Xilinx Axi Ethernet device 2 * MDIO bus driver for the Xilinx Axi Ethernet device
3 * 3 *
4 * Copyright (c) 2009 Secret Lab Technologies, Ltd. 4 * Copyright (c) 2009 Secret Lab Technologies, Ltd.
5 * Copyright (c) 2010 Xilinx, Inc. All rights reserved. 5 * Copyright (c) 2010 - 2011 Michal Simek <monstr@monstr.eu>
6 * Copyright (c) 2012 Daniel Borkmann, <daniel.borkmann@tik.ee.ethz.ch> 6 * Copyright (c) 2010 - 2011 PetaLogix
7 * Copyright (c) 2012 Ariane Keller, <ariane.keller@tik.ee.ethz.ch> 7 * Copyright (c) 2010 - 2012 Xilinx, Inc. All rights reserved.
8 */ 8 */
9 9
10#include <linux/of_address.h> 10#include <linux/of_address.h>
diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
index dd294783b5c5..2d59138db7f3 100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c
@@ -44,6 +44,7 @@ struct net_device_context {
44 /* point back to our device context */ 44 /* point back to our device context */
45 struct hv_device *device_ctx; 45 struct hv_device *device_ctx;
46 struct delayed_work dwork; 46 struct delayed_work dwork;
47 struct work_struct work;
47}; 48};
48 49
49 50
@@ -51,30 +52,22 @@ static int ring_size = 128;
51module_param(ring_size, int, S_IRUGO); 52module_param(ring_size, int, S_IRUGO);
52MODULE_PARM_DESC(ring_size, "Ring buffer size (# of pages)"); 53MODULE_PARM_DESC(ring_size, "Ring buffer size (# of pages)");
53 54
54struct set_multicast_work {
55 struct work_struct work;
56 struct net_device *net;
57};
58
59static void do_set_multicast(struct work_struct *w) 55static void do_set_multicast(struct work_struct *w)
60{ 56{
61 struct set_multicast_work *swk = 57 struct net_device_context *ndevctx =
62 container_of(w, struct set_multicast_work, work); 58 container_of(w, struct net_device_context, work);
63 struct net_device *net = swk->net;
64
65 struct net_device_context *ndevctx = netdev_priv(net);
66 struct netvsc_device *nvdev; 59 struct netvsc_device *nvdev;
67 struct rndis_device *rdev; 60 struct rndis_device *rdev;
68 61
69 nvdev = hv_get_drvdata(ndevctx->device_ctx); 62 nvdev = hv_get_drvdata(ndevctx->device_ctx);
70 if (nvdev == NULL) 63 if (nvdev == NULL || nvdev->ndev == NULL)
71 goto out; 64 return;
72 65
73 rdev = nvdev->extension; 66 rdev = nvdev->extension;
74 if (rdev == NULL) 67 if (rdev == NULL)
75 goto out; 68 return;
76 69
77 if (net->flags & IFF_PROMISC) 70 if (nvdev->ndev->flags & IFF_PROMISC)
78 rndis_filter_set_packet_filter(rdev, 71 rndis_filter_set_packet_filter(rdev,
79 NDIS_PACKET_TYPE_PROMISCUOUS); 72 NDIS_PACKET_TYPE_PROMISCUOUS);
80 else 73 else
@@ -82,21 +75,13 @@ static void do_set_multicast(struct work_struct *w)
82 NDIS_PACKET_TYPE_BROADCAST | 75 NDIS_PACKET_TYPE_BROADCAST |
83 NDIS_PACKET_TYPE_ALL_MULTICAST | 76 NDIS_PACKET_TYPE_ALL_MULTICAST |
84 NDIS_PACKET_TYPE_DIRECTED); 77 NDIS_PACKET_TYPE_DIRECTED);
85
86out:
87 kfree(w);
88} 78}
89 79
90static void netvsc_set_multicast_list(struct net_device *net) 80static void netvsc_set_multicast_list(struct net_device *net)
91{ 81{
92 struct set_multicast_work *swk = 82 struct net_device_context *net_device_ctx = netdev_priv(net);
93 kmalloc(sizeof(struct set_multicast_work), GFP_ATOMIC);
94 if (swk == NULL)
95 return;
96 83
97 swk->net = net; 84 schedule_work(&net_device_ctx->work);
98 INIT_WORK(&swk->work, do_set_multicast);
99 schedule_work(&swk->work);
100} 85}
101 86
102static int netvsc_open(struct net_device *net) 87static int netvsc_open(struct net_device *net)
@@ -125,6 +110,8 @@ static int netvsc_close(struct net_device *net)
125 110
126 netif_tx_disable(net); 111 netif_tx_disable(net);
127 112
113 /* Make sure netvsc_set_multicast_list doesn't re-enable filter! */
114 cancel_work_sync(&net_device_ctx->work);
128 ret = rndis_filter_close(device_obj); 115 ret = rndis_filter_close(device_obj);
129 if (ret != 0) 116 if (ret != 0)
130 netdev_err(net, "unable to close device (ret %d).\n", ret); 117 netdev_err(net, "unable to close device (ret %d).\n", ret);
@@ -335,6 +322,7 @@ static int netvsc_change_mtu(struct net_device *ndev, int mtu)
335 322
336 nvdev->start_remove = true; 323 nvdev->start_remove = true;
337 cancel_delayed_work_sync(&ndevctx->dwork); 324 cancel_delayed_work_sync(&ndevctx->dwork);
325 cancel_work_sync(&ndevctx->work);
338 netif_tx_disable(ndev); 326 netif_tx_disable(ndev);
339 rndis_filter_device_remove(hdev); 327 rndis_filter_device_remove(hdev);
340 328
@@ -403,6 +391,7 @@ static int netvsc_probe(struct hv_device *dev,
403 net_device_ctx->device_ctx = dev; 391 net_device_ctx->device_ctx = dev;
404 hv_set_drvdata(dev, net); 392 hv_set_drvdata(dev, net);
405 INIT_DELAYED_WORK(&net_device_ctx->dwork, netvsc_send_garp); 393 INIT_DELAYED_WORK(&net_device_ctx->dwork, netvsc_send_garp);
394 INIT_WORK(&net_device_ctx->work, do_set_multicast);
406 395
407 net->netdev_ops = &device_ops; 396 net->netdev_ops = &device_ops;
408 397
@@ -456,6 +445,7 @@ static int netvsc_remove(struct hv_device *dev)
456 445
457 ndev_ctx = netdev_priv(net); 446 ndev_ctx = netdev_priv(net);
458 cancel_delayed_work_sync(&ndev_ctx->dwork); 447 cancel_delayed_work_sync(&ndev_ctx->dwork);
448 cancel_work_sync(&ndev_ctx->work);
459 449
460 /* Stop outbound asap */ 450 /* Stop outbound asap */
461 netif_tx_disable(net); 451 netif_tx_disable(net);
diff --git a/drivers/net/irda/sa1100_ir.c b/drivers/net/irda/sa1100_ir.c
index a0d1913a58d3..e25067552b20 100644
--- a/drivers/net/irda/sa1100_ir.c
+++ b/drivers/net/irda/sa1100_ir.c
@@ -147,7 +147,7 @@ static void sa1100_irda_dma_start(struct sa1100_buf *buf,
147 struct dma_async_tx_descriptor *desc; 147 struct dma_async_tx_descriptor *desc;
148 struct dma_chan *chan = buf->chan; 148 struct dma_chan *chan = buf->chan;
149 149
150 desc = chan->device->device_prep_slave_sg(chan, &buf->sg, 1, dir, 150 desc = dmaengine_prep_slave_sg(chan, &buf->sg, 1, dir,
151 DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 151 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
152 if (desc) { 152 if (desc) {
153 desc->callback = cb; 153 desc->callback = cb;
diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
index f975afdc315c..025367a94add 100644
--- a/drivers/net/macvlan.c
+++ b/drivers/net/macvlan.c
@@ -259,7 +259,7 @@ static int macvlan_queue_xmit(struct sk_buff *skb, struct net_device *dev)
259 259
260xmit_world: 260xmit_world:
261 skb->ip_summed = ip_summed; 261 skb->ip_summed = ip_summed;
262 skb_set_dev(skb, vlan->lowerdev); 262 skb->dev = vlan->lowerdev;
263 return dev_queue_xmit(skb); 263 return dev_queue_xmit(skb);
264} 264}
265 265
diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
index 0427c6561c84..cb8fd5069dbe 100644
--- a/drivers/net/macvtap.c
+++ b/drivers/net/macvtap.c
@@ -1,5 +1,6 @@
1#include <linux/etherdevice.h> 1#include <linux/etherdevice.h>
2#include <linux/if_macvlan.h> 2#include <linux/if_macvlan.h>
3#include <linux/if_vlan.h>
3#include <linux/interrupt.h> 4#include <linux/interrupt.h>
4#include <linux/nsproxy.h> 5#include <linux/nsproxy.h>
5#include <linux/compat.h> 6#include <linux/compat.h>
@@ -759,6 +760,8 @@ static ssize_t macvtap_put_user(struct macvtap_queue *q,
759 struct macvlan_dev *vlan; 760 struct macvlan_dev *vlan;
760 int ret; 761 int ret;
761 int vnet_hdr_len = 0; 762 int vnet_hdr_len = 0;
763 int vlan_offset = 0;
764 int copied;
762 765
763 if (q->flags & IFF_VNET_HDR) { 766 if (q->flags & IFF_VNET_HDR) {
764 struct virtio_net_hdr vnet_hdr; 767 struct virtio_net_hdr vnet_hdr;
@@ -773,18 +776,48 @@ static ssize_t macvtap_put_user(struct macvtap_queue *q,
773 if (memcpy_toiovecend(iv, (void *)&vnet_hdr, 0, sizeof(vnet_hdr))) 776 if (memcpy_toiovecend(iv, (void *)&vnet_hdr, 0, sizeof(vnet_hdr)))
774 return -EFAULT; 777 return -EFAULT;
775 } 778 }
779 copied = vnet_hdr_len;
780
781 if (!vlan_tx_tag_present(skb))
782 len = min_t(int, skb->len, len);
783 else {
784 int copy;
785 struct {
786 __be16 h_vlan_proto;
787 __be16 h_vlan_TCI;
788 } veth;
789 veth.h_vlan_proto = htons(ETH_P_8021Q);
790 veth.h_vlan_TCI = htons(vlan_tx_tag_get(skb));
791
792 vlan_offset = offsetof(struct vlan_ethhdr, h_vlan_proto);
793 len = min_t(int, skb->len + VLAN_HLEN, len);
794
795 copy = min_t(int, vlan_offset, len);
796 ret = skb_copy_datagram_const_iovec(skb, 0, iv, copied, copy);
797 len -= copy;
798 copied += copy;
799 if (ret || !len)
800 goto done;
801
802 copy = min_t(int, sizeof(veth), len);
803 ret = memcpy_toiovecend(iv, (void *)&veth, copied, copy);
804 len -= copy;
805 copied += copy;
806 if (ret || !len)
807 goto done;
808 }
776 809
777 len = min_t(int, skb->len, len); 810 ret = skb_copy_datagram_const_iovec(skb, vlan_offset, iv, copied, len);
778 811 copied += len;
779 ret = skb_copy_datagram_const_iovec(skb, 0, iv, vnet_hdr_len, len);
780 812
813done:
781 rcu_read_lock_bh(); 814 rcu_read_lock_bh();
782 vlan = rcu_dereference_bh(q->vlan); 815 vlan = rcu_dereference_bh(q->vlan);
783 if (vlan) 816 if (vlan)
784 macvlan_count_rx(vlan, len, ret == 0, 0); 817 macvlan_count_rx(vlan, copied - vnet_hdr_len, ret == 0, 0);
785 rcu_read_unlock_bh(); 818 rcu_read_unlock_bh();
786 819
787 return ret ? ret : (len + vnet_hdr_len); 820 return ret ? ret : copied;
788} 821}
789 822
790static ssize_t macvtap_do_read(struct macvtap_queue *q, struct kiocb *iocb, 823static ssize_t macvtap_do_read(struct macvtap_queue *q, struct kiocb *iocb,
diff --git a/drivers/net/phy/icplus.c b/drivers/net/phy/icplus.c
index 0856e1b7a849..5ac46f5226f3 100644
--- a/drivers/net/phy/icplus.c
+++ b/drivers/net/phy/icplus.c
@@ -40,6 +40,7 @@ MODULE_LICENSE("GPL");
40#define IP1001_PHASE_SEL_MASK 3 /* IP1001 RX/TXPHASE_SEL */ 40#define IP1001_PHASE_SEL_MASK 3 /* IP1001 RX/TXPHASE_SEL */
41#define IP1001_APS_ON 11 /* IP1001 APS Mode bit */ 41#define IP1001_APS_ON 11 /* IP1001 APS Mode bit */
42#define IP101A_G_APS_ON 2 /* IP101A/G APS Mode bit */ 42#define IP101A_G_APS_ON 2 /* IP101A/G APS Mode bit */
43#define IP101A_G_IRQ_CONF_STATUS 0x11 /* Conf Info IRQ & Status Reg */
43 44
44static int ip175c_config_init(struct phy_device *phydev) 45static int ip175c_config_init(struct phy_device *phydev)
45{ 46{
@@ -162,7 +163,8 @@ static int ip101a_g_config_init(struct phy_device *phydev)
162 /* Enable Auto Power Saving mode */ 163 /* Enable Auto Power Saving mode */
163 c = phy_read(phydev, IP10XX_SPEC_CTRL_STATUS); 164 c = phy_read(phydev, IP10XX_SPEC_CTRL_STATUS);
164 c |= IP101A_G_APS_ON; 165 c |= IP101A_G_APS_ON;
165 return c; 166
167 return phy_write(phydev, IP10XX_SPEC_CTRL_STATUS, c);
166} 168}
167 169
168static int ip175c_read_status(struct phy_device *phydev) 170static int ip175c_read_status(struct phy_device *phydev)
@@ -184,6 +186,15 @@ static int ip175c_config_aneg(struct phy_device *phydev)
184 return 0; 186 return 0;
185} 187}
186 188
189static int ip101a_g_ack_interrupt(struct phy_device *phydev)
190{
191 int err = phy_read(phydev, IP101A_G_IRQ_CONF_STATUS);
192 if (err < 0)
193 return err;
194
195 return 0;
196}
197
187static struct phy_driver ip175c_driver = { 198static struct phy_driver ip175c_driver = {
188 .phy_id = 0x02430d80, 199 .phy_id = 0x02430d80,
189 .name = "ICPlus IP175C", 200 .name = "ICPlus IP175C",
@@ -203,7 +214,6 @@ static struct phy_driver ip1001_driver = {
203 .phy_id_mask = 0x0ffffff0, 214 .phy_id_mask = 0x0ffffff0,
204 .features = PHY_GBIT_FEATURES | SUPPORTED_Pause | 215 .features = PHY_GBIT_FEATURES | SUPPORTED_Pause |
205 SUPPORTED_Asym_Pause, 216 SUPPORTED_Asym_Pause,
206 .flags = PHY_HAS_INTERRUPT,
207 .config_init = &ip1001_config_init, 217 .config_init = &ip1001_config_init,
208 .config_aneg = &genphy_config_aneg, 218 .config_aneg = &genphy_config_aneg,
209 .read_status = &genphy_read_status, 219 .read_status = &genphy_read_status,
@@ -219,6 +229,7 @@ static struct phy_driver ip101a_g_driver = {
219 .features = PHY_BASIC_FEATURES | SUPPORTED_Pause | 229 .features = PHY_BASIC_FEATURES | SUPPORTED_Pause |
220 SUPPORTED_Asym_Pause, 230 SUPPORTED_Asym_Pause,
221 .flags = PHY_HAS_INTERRUPT, 231 .flags = PHY_HAS_INTERRUPT,
232 .ack_interrupt = ip101a_g_ack_interrupt,
222 .config_init = &ip101a_g_config_init, 233 .config_init = &ip101a_g_config_init,
223 .config_aneg = &genphy_config_aneg, 234 .config_aneg = &genphy_config_aneg,
224 .read_status = &genphy_read_status, 235 .read_status = &genphy_read_status,
diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
index 159da2905fe9..21d7151fb0ab 100644
--- a/drivers/net/ppp/ppp_generic.c
+++ b/drivers/net/ppp/ppp_generic.c
@@ -968,7 +968,6 @@ ppp_start_xmit(struct sk_buff *skb, struct net_device *dev)
968 proto = npindex_to_proto[npi]; 968 proto = npindex_to_proto[npi];
969 put_unaligned_be16(proto, pp); 969 put_unaligned_be16(proto, pp);
970 970
971 netif_stop_queue(dev);
972 skb_queue_tail(&ppp->file.xq, skb); 971 skb_queue_tail(&ppp->file.xq, skb);
973 ppp_xmit_process(ppp); 972 ppp_xmit_process(ppp);
974 return NETDEV_TX_OK; 973 return NETDEV_TX_OK;
@@ -1063,6 +1062,8 @@ ppp_xmit_process(struct ppp *ppp)
1063 code that we can accept some more. */ 1062 code that we can accept some more. */
1064 if (!ppp->xmit_pending && !skb_peek(&ppp->file.xq)) 1063 if (!ppp->xmit_pending && !skb_peek(&ppp->file.xq))
1065 netif_wake_queue(ppp->dev); 1064 netif_wake_queue(ppp->dev);
1065 else
1066 netif_stop_queue(ppp->dev);
1066 } 1067 }
1067 ppp_xmit_unlock(ppp); 1068 ppp_xmit_unlock(ppp);
1068} 1069}
diff --git a/drivers/net/rionet.c b/drivers/net/rionet.c
index a57f05726b57..91d25888a1b9 100644
--- a/drivers/net/rionet.c
+++ b/drivers/net/rionet.c
@@ -375,8 +375,8 @@ static void rionet_remove(struct rio_dev *rdev)
375 struct net_device *ndev = rio_get_drvdata(rdev); 375 struct net_device *ndev = rio_get_drvdata(rdev);
376 struct rionet_peer *peer, *tmp; 376 struct rionet_peer *peer, *tmp;
377 377
378 free_pages((unsigned long)rionet_active, rdev->net->hport->sys_size ? 378 free_pages((unsigned long)rionet_active, get_order(sizeof(void *) *
379 __fls(sizeof(void *)) + 4 : 0); 379 RIO_MAX_ROUTE_ENTRIES(rdev->net->hport->sys_size)));
380 unregister_netdev(ndev); 380 unregister_netdev(ndev);
381 free_netdev(ndev); 381 free_netdev(ndev);
382 382
@@ -432,15 +432,16 @@ static int rionet_setup_netdev(struct rio_mport *mport, struct net_device *ndev)
432 int rc = 0; 432 int rc = 0;
433 struct rionet_private *rnet; 433 struct rionet_private *rnet;
434 u16 device_id; 434 u16 device_id;
435 const size_t rionet_active_bytes = sizeof(void *) *
436 RIO_MAX_ROUTE_ENTRIES(mport->sys_size);
435 437
436 rionet_active = (struct rio_dev **)__get_free_pages(GFP_KERNEL, 438 rionet_active = (struct rio_dev **)__get_free_pages(GFP_KERNEL,
437 mport->sys_size ? __fls(sizeof(void *)) + 4 : 0); 439 get_order(rionet_active_bytes));
438 if (!rionet_active) { 440 if (!rionet_active) {
439 rc = -ENOMEM; 441 rc = -ENOMEM;
440 goto out; 442 goto out;
441 } 443 }
442 memset((void *)rionet_active, 0, sizeof(void *) * 444 memset((void *)rionet_active, 0, rionet_active_bytes);
443 RIO_MAX_ROUTE_ENTRIES(mport->sys_size));
444 445
445 /* Set up private area */ 446 /* Set up private area */
446 rnet = netdev_priv(ndev); 447 rnet = netdev_priv(ndev);
diff --git a/drivers/net/usb/asix.c b/drivers/net/usb/asix.c
index 5ee032cafade..42b5151aa78a 100644
--- a/drivers/net/usb/asix.c
+++ b/drivers/net/usb/asix.c
@@ -355,7 +355,7 @@ static struct sk_buff *asix_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
355 u32 packet_len; 355 u32 packet_len;
356 u32 padbytes = 0xffff0000; 356 u32 padbytes = 0xffff0000;
357 357
358 padlen = ((skb->len + 4) % 512) ? 0 : 4; 358 padlen = ((skb->len + 4) & (dev->maxpacket - 1)) ? 0 : 4;
359 359
360 if ((!skb_cloned(skb)) && 360 if ((!skb_cloned(skb)) &&
361 ((headroom + tailroom) >= (4 + padlen))) { 361 ((headroom + tailroom) >= (4 + padlen))) {
@@ -377,7 +377,7 @@ static struct sk_buff *asix_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
377 cpu_to_le32s(&packet_len); 377 cpu_to_le32s(&packet_len);
378 skb_copy_to_linear_data(skb, &packet_len, sizeof(packet_len)); 378 skb_copy_to_linear_data(skb, &packet_len, sizeof(packet_len));
379 379
380 if ((skb->len % 512) == 0) { 380 if (padlen) {
381 cpu_to_le32s(&padbytes); 381 cpu_to_le32s(&padbytes);
382 memcpy(skb_tail_pointer(skb), &padbytes, sizeof(padbytes)); 382 memcpy(skb_tail_pointer(skb), &padbytes, sizeof(padbytes));
383 skb_put(skb, sizeof(padbytes)); 383 skb_put(skb, sizeof(padbytes));
diff --git a/drivers/net/usb/cdc-phonet.c b/drivers/net/usb/cdc-phonet.c
index 3886b30ed373..3e41b00c6806 100644
--- a/drivers/net/usb/cdc-phonet.c
+++ b/drivers/net/usb/cdc-phonet.c
@@ -165,13 +165,13 @@ static void rx_complete(struct urb *req)
165 memcpy(skb_put(skb, 1), page_address(page), 1); 165 memcpy(skb_put(skb, 1), page_address(page), 1);
166 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, 166 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags,
167 page, 1, req->actual_length, 167 page, 1, req->actual_length,
168 req->actual_length); 168 PAGE_SIZE);
169 page = NULL; 169 page = NULL;
170 } 170 }
171 } else { 171 } else {
172 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, 172 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags,
173 page, 0, req->actual_length, 173 page, 0, req->actual_length,
174 req->actual_length); 174 PAGE_SIZE);
175 page = NULL; 175 page = NULL;
176 } 176 }
177 if (req->actual_length < PAGE_SIZE) 177 if (req->actual_length < PAGE_SIZE)
diff --git a/drivers/net/usb/cdc_eem.c b/drivers/net/usb/cdc_eem.c
index 439690be519f..685a4e22c768 100644
--- a/drivers/net/usb/cdc_eem.c
+++ b/drivers/net/usb/cdc_eem.c
@@ -93,6 +93,7 @@ static int eem_bind(struct usbnet *dev, struct usb_interface *intf)
93 /* no jumbogram (16K) support for now */ 93 /* no jumbogram (16K) support for now */
94 94
95 dev->net->hard_header_len += EEM_HEAD + ETH_FCS_LEN; 95 dev->net->hard_header_len += EEM_HEAD + ETH_FCS_LEN;
96 dev->hard_mtu = dev->net->mtu + dev->net->hard_header_len;
96 97
97 return 0; 98 return 0;
98} 99}
diff --git a/drivers/net/usb/cdc_ether.c b/drivers/net/usb/cdc_ether.c
index 90a30026a931..00880edba048 100644
--- a/drivers/net/usb/cdc_ether.c
+++ b/drivers/net/usb/cdc_ether.c
@@ -83,6 +83,7 @@ int usbnet_generic_cdc_bind(struct usbnet *dev, struct usb_interface *intf)
83 struct cdc_state *info = (void *) &dev->data; 83 struct cdc_state *info = (void *) &dev->data;
84 int status; 84 int status;
85 int rndis; 85 int rndis;
86 bool android_rndis_quirk = false;
86 struct usb_driver *driver = driver_of(intf); 87 struct usb_driver *driver = driver_of(intf);
87 struct usb_cdc_mdlm_desc *desc = NULL; 88 struct usb_cdc_mdlm_desc *desc = NULL;
88 struct usb_cdc_mdlm_detail_desc *detail = NULL; 89 struct usb_cdc_mdlm_detail_desc *detail = NULL;
@@ -195,6 +196,11 @@ int usbnet_generic_cdc_bind(struct usbnet *dev, struct usb_interface *intf)
195 info->control, 196 info->control,
196 info->u->bSlaveInterface0, 197 info->u->bSlaveInterface0,
197 info->data); 198 info->data);
199 /* fall back to hard-wiring for RNDIS */
200 if (rndis) {
201 android_rndis_quirk = true;
202 goto next_desc;
203 }
198 goto bad_desc; 204 goto bad_desc;
199 } 205 }
200 if (info->control != intf) { 206 if (info->control != intf) {
@@ -271,11 +277,15 @@ next_desc:
271 /* Microsoft ActiveSync based and some regular RNDIS devices lack the 277 /* Microsoft ActiveSync based and some regular RNDIS devices lack the
272 * CDC descriptors, so we'll hard-wire the interfaces and not check 278 * CDC descriptors, so we'll hard-wire the interfaces and not check
273 * for descriptors. 279 * for descriptors.
280 *
281 * Some Android RNDIS devices have a CDC Union descriptor pointing
282 * to non-existing interfaces. Ignore that and attempt the same
283 * hard-wired 0 and 1 interfaces.
274 */ 284 */
275 if (rndis && !info->u) { 285 if (rndis && (!info->u || android_rndis_quirk)) {
276 info->control = usb_ifnum_to_if(dev->udev, 0); 286 info->control = usb_ifnum_to_if(dev->udev, 0);
277 info->data = usb_ifnum_to_if(dev->udev, 1); 287 info->data = usb_ifnum_to_if(dev->udev, 1);
278 if (!info->control || !info->data) { 288 if (!info->control || !info->data || info->control != intf) {
279 dev_dbg(&intf->dev, 289 dev_dbg(&intf->dev,
280 "rndis: master #0/%p slave #1/%p\n", 290 "rndis: master #0/%p slave #1/%p\n",
281 info->control, 291 info->control,
diff --git a/drivers/net/usb/qmi_wwan.c b/drivers/net/usb/qmi_wwan.c
index 552d24bf862e..d316503b35d4 100644
--- a/drivers/net/usb/qmi_wwan.c
+++ b/drivers/net/usb/qmi_wwan.c
@@ -365,6 +365,27 @@ static const struct driver_info qmi_wwan_force_int4 = {
365 .data = BIT(4), /* interface whitelist bitmap */ 365 .data = BIT(4), /* interface whitelist bitmap */
366}; 366};
367 367
368/* Sierra Wireless provide equally useless interface descriptors
369 * Devices in QMI mode can be switched between two different
370 * configurations:
371 * a) USB interface #8 is QMI/wwan
372 * b) USB interfaces #8, #19 and #20 are QMI/wwan
373 *
374 * Both configurations provide a number of other interfaces (serial++),
375 * some of which have the same endpoint configuration as we expect, so
376 * a whitelist or blacklist is necessary.
377 *
378 * FIXME: The below whitelist should include BIT(20). It does not
379 * because I cannot get it to work...
380 */
381static const struct driver_info qmi_wwan_sierra = {
382 .description = "Sierra Wireless wwan/QMI device",
383 .flags = FLAG_WWAN,
384 .bind = qmi_wwan_bind_gobi,
385 .unbind = qmi_wwan_unbind_shared,
386 .manage_power = qmi_wwan_manage_power,
387 .data = BIT(8) | BIT(19), /* interface whitelist bitmap */
388};
368 389
369#define HUAWEI_VENDOR_ID 0x12D1 390#define HUAWEI_VENDOR_ID 0x12D1
370#define QMI_GOBI_DEVICE(vend, prod) \ 391#define QMI_GOBI_DEVICE(vend, prod) \
@@ -445,6 +466,15 @@ static const struct usb_device_id products[] = {
445 .bInterfaceProtocol = 0xff, 466 .bInterfaceProtocol = 0xff,
446 .driver_info = (unsigned long)&qmi_wwan_force_int4, 467 .driver_info = (unsigned long)&qmi_wwan_force_int4,
447 }, 468 },
469 { /* Sierra Wireless MC77xx in QMI mode */
470 .match_flags = USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_INT_INFO,
471 .idVendor = 0x1199,
472 .idProduct = 0x68a2,
473 .bInterfaceClass = 0xff,
474 .bInterfaceSubClass = 0xff,
475 .bInterfaceProtocol = 0xff,
476 .driver_info = (unsigned long)&qmi_wwan_sierra,
477 },
448 {QMI_GOBI_DEVICE(0x05c6, 0x9212)}, /* Acer Gobi Modem Device */ 478 {QMI_GOBI_DEVICE(0x05c6, 0x9212)}, /* Acer Gobi Modem Device */
449 {QMI_GOBI_DEVICE(0x03f0, 0x1f1d)}, /* HP un2400 Gobi Modem Device */ 479 {QMI_GOBI_DEVICE(0x03f0, 0x1f1d)}, /* HP un2400 Gobi Modem Device */
450 {QMI_GOBI_DEVICE(0x03f0, 0x371d)}, /* HP un2430 Mobile Broadband Module */ 480 {QMI_GOBI_DEVICE(0x03f0, 0x371d)}, /* HP un2430 Mobile Broadband Module */
diff --git a/drivers/net/usb/rtl8150.c b/drivers/net/usb/rtl8150.c
index 6dda2fe5b15b..d363b31053da 100644
--- a/drivers/net/usb/rtl8150.c
+++ b/drivers/net/usb/rtl8150.c
@@ -85,32 +85,6 @@
85#define INT_CRERR_CNT 0x06 85#define INT_CRERR_CNT 0x06
86#define INT_COL_CNT 0x07 86#define INT_COL_CNT 0x07
87 87
88/* Transmit status register errors */
89#define TSR_ECOL (1<<5)
90#define TSR_LCOL (1<<4)
91#define TSR_LOSS_CRS (1<<3)
92#define TSR_JBR (1<<2)
93#define TSR_ERRORS (TSR_ECOL | TSR_LCOL | TSR_LOSS_CRS | TSR_JBR)
94/* Receive status register errors */
95#define RSR_CRC (1<<2)
96#define RSR_FAE (1<<1)
97#define RSR_ERRORS (RSR_CRC | RSR_FAE)
98
99/* Media status register definitions */
100#define MSR_DUPLEX (1<<4)
101#define MSR_SPEED (1<<3)
102#define MSR_LINK (1<<2)
103
104/* Interrupt pipe data */
105#define INT_TSR 0x00
106#define INT_RSR 0x01
107#define INT_MSR 0x02
108#define INT_WAKSR 0x03
109#define INT_TXOK_CNT 0x04
110#define INT_RXLOST_CNT 0x05
111#define INT_CRERR_CNT 0x06
112#define INT_COL_CNT 0x07
113
114 88
115#define RTL8150_MTU 1540 89#define RTL8150_MTU 1540
116#define RTL8150_TX_TIMEOUT (HZ) 90#define RTL8150_TX_TIMEOUT (HZ)
diff --git a/drivers/net/usb/smsc75xx.c b/drivers/net/usb/smsc75xx.c
index 187d01ccb973..00103a8c5e04 100644
--- a/drivers/net/usb/smsc75xx.c
+++ b/drivers/net/usb/smsc75xx.c
@@ -98,7 +98,7 @@ static int __must_check smsc75xx_read_reg(struct usbnet *dev, u32 index,
98 98
99 if (unlikely(ret < 0)) 99 if (unlikely(ret < 0))
100 netdev_warn(dev->net, 100 netdev_warn(dev->net,
101 "Failed to read register index 0x%08x", index); 101 "Failed to read reg index 0x%08x: %d", index, ret);
102 102
103 le32_to_cpus(buf); 103 le32_to_cpus(buf);
104 *data = *buf; 104 *data = *buf;
@@ -128,7 +128,7 @@ static int __must_check smsc75xx_write_reg(struct usbnet *dev, u32 index,
128 128
129 if (unlikely(ret < 0)) 129 if (unlikely(ret < 0))
130 netdev_warn(dev->net, 130 netdev_warn(dev->net,
131 "Failed to write register index 0x%08x", index); 131 "Failed to write reg index 0x%08x: %d", index, ret);
132 132
133 kfree(buf); 133 kfree(buf);
134 134
@@ -171,7 +171,7 @@ static int smsc75xx_mdio_read(struct net_device *netdev, int phy_id, int idx)
171 idx &= dev->mii.reg_num_mask; 171 idx &= dev->mii.reg_num_mask;
172 addr = ((phy_id << MII_ACCESS_PHY_ADDR_SHIFT) & MII_ACCESS_PHY_ADDR) 172 addr = ((phy_id << MII_ACCESS_PHY_ADDR_SHIFT) & MII_ACCESS_PHY_ADDR)
173 | ((idx << MII_ACCESS_REG_ADDR_SHIFT) & MII_ACCESS_REG_ADDR) 173 | ((idx << MII_ACCESS_REG_ADDR_SHIFT) & MII_ACCESS_REG_ADDR)
174 | MII_ACCESS_READ; 174 | MII_ACCESS_READ | MII_ACCESS_BUSY;
175 ret = smsc75xx_write_reg(dev, MII_ACCESS, addr); 175 ret = smsc75xx_write_reg(dev, MII_ACCESS, addr);
176 check_warn_goto_done(ret, "Error writing MII_ACCESS"); 176 check_warn_goto_done(ret, "Error writing MII_ACCESS");
177 177
@@ -210,7 +210,7 @@ static void smsc75xx_mdio_write(struct net_device *netdev, int phy_id, int idx,
210 idx &= dev->mii.reg_num_mask; 210 idx &= dev->mii.reg_num_mask;
211 addr = ((phy_id << MII_ACCESS_PHY_ADDR_SHIFT) & MII_ACCESS_PHY_ADDR) 211 addr = ((phy_id << MII_ACCESS_PHY_ADDR_SHIFT) & MII_ACCESS_PHY_ADDR)
212 | ((idx << MII_ACCESS_REG_ADDR_SHIFT) & MII_ACCESS_REG_ADDR) 212 | ((idx << MII_ACCESS_REG_ADDR_SHIFT) & MII_ACCESS_REG_ADDR)
213 | MII_ACCESS_WRITE; 213 | MII_ACCESS_WRITE | MII_ACCESS_BUSY;
214 ret = smsc75xx_write_reg(dev, MII_ACCESS, addr); 214 ret = smsc75xx_write_reg(dev, MII_ACCESS, addr);
215 check_warn_goto_done(ret, "Error writing MII_ACCESS"); 215 check_warn_goto_done(ret, "Error writing MII_ACCESS");
216 216
@@ -508,9 +508,10 @@ static int smsc75xx_link_reset(struct usbnet *dev)
508 u16 lcladv, rmtadv; 508 u16 lcladv, rmtadv;
509 int ret; 509 int ret;
510 510
511 /* clear interrupt status */ 511 /* read and write to clear phy interrupt status */
512 ret = smsc75xx_mdio_read(dev->net, mii->phy_id, PHY_INT_SRC); 512 ret = smsc75xx_mdio_read(dev->net, mii->phy_id, PHY_INT_SRC);
513 check_warn_return(ret, "Error reading PHY_INT_SRC"); 513 check_warn_return(ret, "Error reading PHY_INT_SRC");
514 smsc75xx_mdio_write(dev->net, mii->phy_id, PHY_INT_SRC, 0xffff);
514 515
515 ret = smsc75xx_write_reg(dev, INT_STS, INT_STS_CLEAR_ALL); 516 ret = smsc75xx_write_reg(dev, INT_STS, INT_STS_CLEAR_ALL);
516 check_warn_return(ret, "Error writing INT_STS"); 517 check_warn_return(ret, "Error writing INT_STS");
@@ -643,7 +644,7 @@ static int smsc75xx_set_mac_address(struct usbnet *dev)
643 644
644static int smsc75xx_phy_initialize(struct usbnet *dev) 645static int smsc75xx_phy_initialize(struct usbnet *dev)
645{ 646{
646 int bmcr, timeout = 0; 647 int bmcr, ret, timeout = 0;
647 648
648 /* Initialize MII structure */ 649 /* Initialize MII structure */
649 dev->mii.dev = dev->net; 650 dev->mii.dev = dev->net;
@@ -651,6 +652,7 @@ static int smsc75xx_phy_initialize(struct usbnet *dev)
651 dev->mii.mdio_write = smsc75xx_mdio_write; 652 dev->mii.mdio_write = smsc75xx_mdio_write;
652 dev->mii.phy_id_mask = 0x1f; 653 dev->mii.phy_id_mask = 0x1f;
653 dev->mii.reg_num_mask = 0x1f; 654 dev->mii.reg_num_mask = 0x1f;
655 dev->mii.supports_gmii = 1;
654 dev->mii.phy_id = SMSC75XX_INTERNAL_PHY_ID; 656 dev->mii.phy_id = SMSC75XX_INTERNAL_PHY_ID;
655 657
656 /* reset phy and wait for reset to complete */ 658 /* reset phy and wait for reset to complete */
@@ -661,7 +663,7 @@ static int smsc75xx_phy_initialize(struct usbnet *dev)
661 bmcr = smsc75xx_mdio_read(dev->net, dev->mii.phy_id, MII_BMCR); 663 bmcr = smsc75xx_mdio_read(dev->net, dev->mii.phy_id, MII_BMCR);
662 check_warn_return(bmcr, "Error reading MII_BMCR"); 664 check_warn_return(bmcr, "Error reading MII_BMCR");
663 timeout++; 665 timeout++;
664 } while ((bmcr & MII_BMCR) && (timeout < 100)); 666 } while ((bmcr & BMCR_RESET) && (timeout < 100));
665 667
666 if (timeout >= 100) { 668 if (timeout >= 100) {
667 netdev_warn(dev->net, "timeout on PHY Reset"); 669 netdev_warn(dev->net, "timeout on PHY Reset");
@@ -671,10 +673,13 @@ static int smsc75xx_phy_initialize(struct usbnet *dev)
671 smsc75xx_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE, 673 smsc75xx_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
672 ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP | 674 ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP |
673 ADVERTISE_PAUSE_ASYM); 675 ADVERTISE_PAUSE_ASYM);
676 smsc75xx_mdio_write(dev->net, dev->mii.phy_id, MII_CTRL1000,
677 ADVERTISE_1000FULL);
674 678
675 /* read to clear */ 679 /* read and write to clear phy interrupt status */
676 smsc75xx_mdio_read(dev->net, dev->mii.phy_id, PHY_INT_SRC); 680 ret = smsc75xx_mdio_read(dev->net, dev->mii.phy_id, PHY_INT_SRC);
677 check_warn_return(bmcr, "Error reading PHY_INT_SRC"); 681 check_warn_return(ret, "Error reading PHY_INT_SRC");
682 smsc75xx_mdio_write(dev->net, dev->mii.phy_id, PHY_INT_SRC, 0xffff);
678 683
679 smsc75xx_mdio_write(dev->net, dev->mii.phy_id, PHY_INT_MASK, 684 smsc75xx_mdio_write(dev->net, dev->mii.phy_id, PHY_INT_MASK,
680 PHY_INT_MASK_DEFAULT); 685 PHY_INT_MASK_DEFAULT);
@@ -946,6 +951,14 @@ static int smsc75xx_reset(struct usbnet *dev)
946 ret = smsc75xx_write_reg(dev, INT_EP_CTL, buf); 951 ret = smsc75xx_write_reg(dev, INT_EP_CTL, buf);
947 check_warn_return(ret, "Failed to write INT_EP_CTL: %d", ret); 952 check_warn_return(ret, "Failed to write INT_EP_CTL: %d", ret);
948 953
954 /* allow mac to detect speed and duplex from phy */
955 ret = smsc75xx_read_reg(dev, MAC_CR, &buf);
956 check_warn_return(ret, "Failed to read MAC_CR: %d", ret);
957
958 buf |= (MAC_CR_ADD | MAC_CR_ASD);
959 ret = smsc75xx_write_reg(dev, MAC_CR, buf);
960 check_warn_return(ret, "Failed to write MAC_CR: %d", ret);
961
949 ret = smsc75xx_read_reg(dev, MAC_TX, &buf); 962 ret = smsc75xx_read_reg(dev, MAC_TX, &buf);
950 check_warn_return(ret, "Failed to read MAC_TX: %d", ret); 963 check_warn_return(ret, "Failed to read MAC_TX: %d", ret);
951 964
@@ -1051,6 +1064,7 @@ static int smsc75xx_bind(struct usbnet *dev, struct usb_interface *intf)
1051 dev->net->ethtool_ops = &smsc75xx_ethtool_ops; 1064 dev->net->ethtool_ops = &smsc75xx_ethtool_ops;
1052 dev->net->flags |= IFF_MULTICAST; 1065 dev->net->flags |= IFF_MULTICAST;
1053 dev->net->hard_header_len += SMSC75XX_TX_OVERHEAD; 1066 dev->net->hard_header_len += SMSC75XX_TX_OVERHEAD;
1067 dev->hard_mtu = dev->net->mtu + dev->net->hard_header_len;
1054 return 0; 1068 return 0;
1055} 1069}
1056 1070
@@ -1211,7 +1225,7 @@ static const struct driver_info smsc75xx_info = {
1211 .rx_fixup = smsc75xx_rx_fixup, 1225 .rx_fixup = smsc75xx_rx_fixup,
1212 .tx_fixup = smsc75xx_tx_fixup, 1226 .tx_fixup = smsc75xx_tx_fixup,
1213 .status = smsc75xx_status, 1227 .status = smsc75xx_status,
1214 .flags = FLAG_ETHER | FLAG_SEND_ZLP, 1228 .flags = FLAG_ETHER | FLAG_SEND_ZLP | FLAG_LINK_INTR,
1215}; 1229};
1216 1230
1217static const struct usb_device_id products[] = { 1231static const struct usb_device_id products[] = {
diff --git a/drivers/net/usb/smsc95xx.c b/drivers/net/usb/smsc95xx.c
index 5f19f84d3494..94ae66999f59 100644
--- a/drivers/net/usb/smsc95xx.c
+++ b/drivers/net/usb/smsc95xx.c
@@ -1017,6 +1017,7 @@ static int smsc95xx_bind(struct usbnet *dev, struct usb_interface *intf)
1017 dev->net->ethtool_ops = &smsc95xx_ethtool_ops; 1017 dev->net->ethtool_ops = &smsc95xx_ethtool_ops;
1018 dev->net->flags |= IFF_MULTICAST; 1018 dev->net->flags |= IFF_MULTICAST;
1019 dev->net->hard_header_len += SMSC95XX_TX_OVERHEAD_CSUM; 1019 dev->net->hard_header_len += SMSC95XX_TX_OVERHEAD_CSUM;
1020 dev->hard_mtu = dev->net->mtu + dev->net->hard_header_len;
1020 return 0; 1021 return 0;
1021} 1022}
1022 1023
@@ -1191,7 +1192,7 @@ static const struct driver_info smsc95xx_info = {
1191 .rx_fixup = smsc95xx_rx_fixup, 1192 .rx_fixup = smsc95xx_rx_fixup,
1192 .tx_fixup = smsc95xx_tx_fixup, 1193 .tx_fixup = smsc95xx_tx_fixup,
1193 .status = smsc95xx_status, 1194 .status = smsc95xx_status,
1194 .flags = FLAG_ETHER | FLAG_SEND_ZLP, 1195 .flags = FLAG_ETHER | FLAG_SEND_ZLP | FLAG_LINK_INTR,
1195}; 1196};
1196 1197
1197static const struct usb_device_id products[] = { 1198static const struct usb_device_id products[] = {
diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
index b7b3f5b0d406..2d927fb4adf4 100644
--- a/drivers/net/usb/usbnet.c
+++ b/drivers/net/usb/usbnet.c
@@ -210,6 +210,7 @@ static int init_status (struct usbnet *dev, struct usb_interface *intf)
210 } else { 210 } else {
211 usb_fill_int_urb(dev->interrupt, dev->udev, pipe, 211 usb_fill_int_urb(dev->interrupt, dev->udev, pipe,
212 buf, maxp, intr_complete, dev, period); 212 buf, maxp, intr_complete, dev, period);
213 dev->interrupt->transfer_flags |= URB_FREE_BUFFER;
213 dev_dbg(&intf->dev, 214 dev_dbg(&intf->dev,
214 "status ep%din, %d bytes period %d\n", 215 "status ep%din, %d bytes period %d\n",
215 usb_pipeendpoint(pipe), maxp, period); 216 usb_pipeendpoint(pipe), maxp, period);
@@ -1443,7 +1444,7 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
1443 1444
1444 status = register_netdev (net); 1445 status = register_netdev (net);
1445 if (status) 1446 if (status)
1446 goto out3; 1447 goto out4;
1447 netif_info(dev, probe, dev->net, 1448 netif_info(dev, probe, dev->net,
1448 "register '%s' at usb-%s-%s, %s, %pM\n", 1449 "register '%s' at usb-%s-%s, %s, %pM\n",
1449 udev->dev.driver->name, 1450 udev->dev.driver->name,
@@ -1461,6 +1462,8 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
1461 1462
1462 return 0; 1463 return 0;
1463 1464
1465out4:
1466 usb_free_urb(dev->interrupt);
1464out3: 1467out3:
1465 if (info->unbind) 1468 if (info->unbind)
1466 info->unbind (dev, udev); 1469 info->unbind (dev, udev);
diff --git a/drivers/net/usb/zaurus.c b/drivers/net/usb/zaurus.c
index c3197ce0e2ad..34db195fb8b0 100644
--- a/drivers/net/usb/zaurus.c
+++ b/drivers/net/usb/zaurus.c
@@ -337,6 +337,11 @@ static const struct usb_device_id products [] = {
337 .driver_info = ZAURUS_PXA_INFO, 337 .driver_info = ZAURUS_PXA_INFO,
338}, 338},
339{ 339{
340 /* Motorola Rokr E6 */
341 USB_DEVICE_AND_INTERFACE_INFO(0x22b8, 0x6027, USB_CLASS_COMM,
342 USB_CDC_SUBCLASS_MDLM, USB_CDC_PROTO_NONE),
343 .driver_info = (unsigned long) &bogus_mdlm_info,
344}, {
340 /* Motorola MOTOMAGX phones */ 345 /* Motorola MOTOMAGX phones */
341 USB_DEVICE_AND_INTERFACE_INFO(0x22b8, 0x6425, USB_CLASS_COMM, 346 USB_DEVICE_AND_INTERFACE_INFO(0x22b8, 0x6425, USB_CLASS_COMM,
342 USB_CDC_SUBCLASS_MDLM, USB_CDC_PROTO_NONE), 347 USB_CDC_SUBCLASS_MDLM, USB_CDC_PROTO_NONE),
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 019da012669f..af8acc85f4bb 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -625,16 +625,16 @@ static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev)
625 625
626 /* This can happen with OOM and indirect buffers. */ 626 /* This can happen with OOM and indirect buffers. */
627 if (unlikely(capacity < 0)) { 627 if (unlikely(capacity < 0)) {
628 if (net_ratelimit()) { 628 if (likely(capacity == -ENOMEM)) {
629 if (likely(capacity == -ENOMEM)) { 629 if (net_ratelimit())
630 dev_warn(&dev->dev, 630 dev_warn(&dev->dev,
631 "TX queue failure: out of memory\n"); 631 "TX queue failure: out of memory\n");
632 } else { 632 } else {
633 dev->stats.tx_fifo_errors++; 633 dev->stats.tx_fifo_errors++;
634 if (net_ratelimit())
634 dev_warn(&dev->dev, 635 dev_warn(&dev->dev,
635 "Unexpected TX queue failure: %d\n", 636 "Unexpected TX queue failure: %d\n",
636 capacity); 637 capacity);
637 }
638 } 638 }
639 dev->stats.tx_dropped++; 639 dev->stats.tx_dropped++;
640 kfree_skb(skb); 640 kfree_skb(skb);
diff --git a/drivers/net/wan/farsync.c b/drivers/net/wan/farsync.c
index ebb9f24eefb5..1a623183cbe5 100644
--- a/drivers/net/wan/farsync.c
+++ b/drivers/net/wan/farsync.c
@@ -2483,6 +2483,7 @@ fst_add_one(struct pci_dev *pdev, const struct pci_device_id *ent)
2483 pr_err("Control memory remap failed\n"); 2483 pr_err("Control memory remap failed\n");
2484 pci_release_regions(pdev); 2484 pci_release_regions(pdev);
2485 pci_disable_device(pdev); 2485 pci_disable_device(pdev);
2486 iounmap(card->mem);
2486 kfree(card); 2487 kfree(card);
2487 return -ENODEV; 2488 return -ENODEV;
2488 } 2489 }
diff --git a/drivers/net/wimax/i2400m/debugfs.c b/drivers/net/wimax/i2400m/debugfs.c
index 129ba36bd04d..4b66ab1d0e5c 100644
--- a/drivers/net/wimax/i2400m/debugfs.c
+++ b/drivers/net/wimax/i2400m/debugfs.c
@@ -53,17 +53,6 @@ struct dentry *debugfs_create_netdev_queue_stopped(
53 &fops_netdev_queue_stopped); 53 &fops_netdev_queue_stopped);
54} 54}
55 55
56
57/*
58 * inode->i_private has the @data argument to debugfs_create_file()
59 */
60static
61int i2400m_stats_open(struct inode *inode, struct file *filp)
62{
63 filp->private_data = inode->i_private;
64 return 0;
65}
66
67/* 56/*
68 * We don't allow partial reads of this file, as then the reader would 57 * We don't allow partial reads of this file, as then the reader would
69 * get weirdly confused data as it is updated. 58 * get weirdly confused data as it is updated.
@@ -117,7 +106,7 @@ ssize_t i2400m_rx_stats_write(struct file *filp, const char __user *buffer,
117static 106static
118const struct file_operations i2400m_rx_stats_fops = { 107const struct file_operations i2400m_rx_stats_fops = {
119 .owner = THIS_MODULE, 108 .owner = THIS_MODULE,
120 .open = i2400m_stats_open, 109 .open = simple_open,
121 .read = i2400m_rx_stats_read, 110 .read = i2400m_rx_stats_read,
122 .write = i2400m_rx_stats_write, 111 .write = i2400m_rx_stats_write,
123 .llseek = default_llseek, 112 .llseek = default_llseek,
@@ -170,7 +159,7 @@ ssize_t i2400m_tx_stats_write(struct file *filp, const char __user *buffer,
170static 159static
171const struct file_operations i2400m_tx_stats_fops = { 160const struct file_operations i2400m_tx_stats_fops = {
172 .owner = THIS_MODULE, 161 .owner = THIS_MODULE,
173 .open = i2400m_stats_open, 162 .open = simple_open,
174 .read = i2400m_tx_stats_read, 163 .read = i2400m_tx_stats_read,
175 .write = i2400m_tx_stats_write, 164 .write = i2400m_tx_stats_write,
176 .llseek = default_llseek, 165 .llseek = default_llseek,
diff --git a/drivers/net/wimax/i2400m/netdev.c b/drivers/net/wimax/i2400m/netdev.c
index 63e4b709efa9..1d76ae855f07 100644
--- a/drivers/net/wimax/i2400m/netdev.c
+++ b/drivers/net/wimax/i2400m/netdev.c
@@ -597,7 +597,8 @@ static void i2400m_get_drvinfo(struct net_device *net_dev,
597 struct i2400m *i2400m = net_dev_to_i2400m(net_dev); 597 struct i2400m *i2400m = net_dev_to_i2400m(net_dev);
598 598
599 strncpy(info->driver, KBUILD_MODNAME, sizeof(info->driver) - 1); 599 strncpy(info->driver, KBUILD_MODNAME, sizeof(info->driver) - 1);
600 strncpy(info->fw_version, i2400m->fw_name, sizeof(info->fw_version) - 1); 600 strncpy(info->fw_version,
601 i2400m->fw_name ? : "", sizeof(info->fw_version) - 1);
601 if (net_dev->dev.parent) 602 if (net_dev->dev.parent)
602 strncpy(info->bus_info, dev_name(net_dev->dev.parent), 603 strncpy(info->bus_info, dev_name(net_dev->dev.parent),
603 sizeof(info->bus_info) - 1); 604 sizeof(info->bus_info) - 1);
diff --git a/drivers/net/wimax/i2400m/usb.c b/drivers/net/wimax/i2400m/usb.c
index 2c1b8b687646..29b1e033a10b 100644
--- a/drivers/net/wimax/i2400m/usb.c
+++ b/drivers/net/wimax/i2400m/usb.c
@@ -339,6 +339,23 @@ int i2400mu_bus_reset(struct i2400m *i2400m, enum i2400m_reset_type rt)
339 return result; 339 return result;
340} 340}
341 341
342static void i2400mu_get_drvinfo(struct net_device *net_dev,
343 struct ethtool_drvinfo *info)
344{
345 struct i2400m *i2400m = net_dev_to_i2400m(net_dev);
346 struct i2400mu *i2400mu = container_of(i2400m, struct i2400mu, i2400m);
347 struct usb_device *udev = i2400mu->usb_dev;
348
349 strncpy(info->driver, KBUILD_MODNAME, sizeof(info->driver) - 1);
350 strncpy(info->fw_version,
351 i2400m->fw_name ? : "", sizeof(info->fw_version) - 1);
352 usb_make_path(udev, info->bus_info, sizeof(info->bus_info));
353}
354
355static const struct ethtool_ops i2400mu_ethtool_ops = {
356 .get_drvinfo = i2400mu_get_drvinfo,
357 .get_link = ethtool_op_get_link,
358};
342 359
343static 360static
344void i2400mu_netdev_setup(struct net_device *net_dev) 361void i2400mu_netdev_setup(struct net_device *net_dev)
@@ -347,6 +364,7 @@ void i2400mu_netdev_setup(struct net_device *net_dev)
347 struct i2400mu *i2400mu = container_of(i2400m, struct i2400mu, i2400m); 364 struct i2400mu *i2400mu = container_of(i2400m, struct i2400mu, i2400m);
348 i2400mu_init(i2400mu); 365 i2400mu_init(i2400mu);
349 i2400m_netdev_setup(net_dev); 366 i2400m_netdev_setup(net_dev);
367 net_dev->ethtool_ops = &i2400mu_ethtool_ops;
350} 368}
351 369
352 370
diff --git a/drivers/net/wireless/ath/ath5k/ahb.c b/drivers/net/wireless/ath/ath5k/ahb.c
index 8faa129da5a0..aec33cc207fd 100644
--- a/drivers/net/wireless/ath/ath5k/ahb.c
+++ b/drivers/net/wireless/ath/ath5k/ahb.c
@@ -19,6 +19,7 @@
19#include <linux/nl80211.h> 19#include <linux/nl80211.h>
20#include <linux/platform_device.h> 20#include <linux/platform_device.h>
21#include <linux/etherdevice.h> 21#include <linux/etherdevice.h>
22#include <linux/export.h>
22#include <ar231x_platform.h> 23#include <ar231x_platform.h>
23#include "ath5k.h" 24#include "ath5k.h"
24#include "debug.h" 25#include "debug.h"
@@ -119,7 +120,7 @@ static int ath_ahb_probe(struct platform_device *pdev)
119 if (res == NULL) { 120 if (res == NULL) {
120 dev_err(&pdev->dev, "no IRQ resource found\n"); 121 dev_err(&pdev->dev, "no IRQ resource found\n");
121 ret = -ENXIO; 122 ret = -ENXIO;
122 goto err_out; 123 goto err_iounmap;
123 } 124 }
124 125
125 irq = res->start; 126 irq = res->start;
@@ -128,7 +129,7 @@ static int ath_ahb_probe(struct platform_device *pdev)
128 if (hw == NULL) { 129 if (hw == NULL) {
129 dev_err(&pdev->dev, "no memory for ieee80211_hw\n"); 130 dev_err(&pdev->dev, "no memory for ieee80211_hw\n");
130 ret = -ENOMEM; 131 ret = -ENOMEM;
131 goto err_out; 132 goto err_iounmap;
132 } 133 }
133 134
134 ah = hw->priv; 135 ah = hw->priv;
@@ -185,6 +186,8 @@ static int ath_ahb_probe(struct platform_device *pdev)
185 err_free_hw: 186 err_free_hw:
186 ieee80211_free_hw(hw); 187 ieee80211_free_hw(hw);
187 platform_set_drvdata(pdev, NULL); 188 platform_set_drvdata(pdev, NULL);
189 err_iounmap:
190 iounmap(mem);
188 err_out: 191 err_out:
189 return ret; 192 return ret;
190} 193}
@@ -217,6 +220,7 @@ static int ath_ahb_remove(struct platform_device *pdev)
217 } 220 }
218 221
219 ath5k_deinit_ah(ah); 222 ath5k_deinit_ah(ah);
223 iounmap(ah->iobase);
220 platform_set_drvdata(pdev, NULL); 224 platform_set_drvdata(pdev, NULL);
221 ieee80211_free_hw(hw); 225 ieee80211_free_hw(hw);
222 226
diff --git a/drivers/net/wireless/ath/ath5k/debug.c b/drivers/net/wireless/ath/ath5k/debug.c
index 8c5ce8b0c734..e5e8f45d86ac 100644
--- a/drivers/net/wireless/ath/ath5k/debug.c
+++ b/drivers/net/wireless/ath/ath5k/debug.c
@@ -71,13 +71,6 @@ static unsigned int ath5k_debug;
71module_param_named(debug, ath5k_debug, uint, 0); 71module_param_named(debug, ath5k_debug, uint, 0);
72 72
73 73
74static int ath5k_debugfs_open(struct inode *inode, struct file *file)
75{
76 file->private_data = inode->i_private;
77 return 0;
78}
79
80
81/* debugfs: registers */ 74/* debugfs: registers */
82 75
83struct reg { 76struct reg {
@@ -265,7 +258,7 @@ static ssize_t write_file_beacon(struct file *file,
265static const struct file_operations fops_beacon = { 258static const struct file_operations fops_beacon = {
266 .read = read_file_beacon, 259 .read = read_file_beacon,
267 .write = write_file_beacon, 260 .write = write_file_beacon,
268 .open = ath5k_debugfs_open, 261 .open = simple_open,
269 .owner = THIS_MODULE, 262 .owner = THIS_MODULE,
270 .llseek = default_llseek, 263 .llseek = default_llseek,
271}; 264};
@@ -285,7 +278,7 @@ static ssize_t write_file_reset(struct file *file,
285 278
286static const struct file_operations fops_reset = { 279static const struct file_operations fops_reset = {
287 .write = write_file_reset, 280 .write = write_file_reset,
288 .open = ath5k_debugfs_open, 281 .open = simple_open,
289 .owner = THIS_MODULE, 282 .owner = THIS_MODULE,
290 .llseek = noop_llseek, 283 .llseek = noop_llseek,
291}; 284};
@@ -365,7 +358,7 @@ static ssize_t write_file_debug(struct file *file,
365static const struct file_operations fops_debug = { 358static const struct file_operations fops_debug = {
366 .read = read_file_debug, 359 .read = read_file_debug,
367 .write = write_file_debug, 360 .write = write_file_debug,
368 .open = ath5k_debugfs_open, 361 .open = simple_open,
369 .owner = THIS_MODULE, 362 .owner = THIS_MODULE,
370 .llseek = default_llseek, 363 .llseek = default_llseek,
371}; 364};
@@ -477,7 +470,7 @@ static ssize_t write_file_antenna(struct file *file,
477static const struct file_operations fops_antenna = { 470static const struct file_operations fops_antenna = {
478 .read = read_file_antenna, 471 .read = read_file_antenna,
479 .write = write_file_antenna, 472 .write = write_file_antenna,
480 .open = ath5k_debugfs_open, 473 .open = simple_open,
481 .owner = THIS_MODULE, 474 .owner = THIS_MODULE,
482 .llseek = default_llseek, 475 .llseek = default_llseek,
483}; 476};
@@ -532,7 +525,7 @@ static ssize_t read_file_misc(struct file *file, char __user *user_buf,
532 525
533static const struct file_operations fops_misc = { 526static const struct file_operations fops_misc = {
534 .read = read_file_misc, 527 .read = read_file_misc,
535 .open = ath5k_debugfs_open, 528 .open = simple_open,
536 .owner = THIS_MODULE, 529 .owner = THIS_MODULE,
537}; 530};
538 531
@@ -647,7 +640,7 @@ static ssize_t write_file_frameerrors(struct file *file,
647static const struct file_operations fops_frameerrors = { 640static const struct file_operations fops_frameerrors = {
648 .read = read_file_frameerrors, 641 .read = read_file_frameerrors,
649 .write = write_file_frameerrors, 642 .write = write_file_frameerrors,
650 .open = ath5k_debugfs_open, 643 .open = simple_open,
651 .owner = THIS_MODULE, 644 .owner = THIS_MODULE,
652 .llseek = default_llseek, 645 .llseek = default_llseek,
653}; 646};
@@ -810,7 +803,7 @@ static ssize_t write_file_ani(struct file *file,
810static const struct file_operations fops_ani = { 803static const struct file_operations fops_ani = {
811 .read = read_file_ani, 804 .read = read_file_ani,
812 .write = write_file_ani, 805 .write = write_file_ani,
813 .open = ath5k_debugfs_open, 806 .open = simple_open,
814 .owner = THIS_MODULE, 807 .owner = THIS_MODULE,
815 .llseek = default_llseek, 808 .llseek = default_llseek,
816}; 809};
@@ -881,7 +874,7 @@ static ssize_t write_file_queue(struct file *file,
881static const struct file_operations fops_queue = { 874static const struct file_operations fops_queue = {
882 .read = read_file_queue, 875 .read = read_file_queue,
883 .write = write_file_queue, 876 .write = write_file_queue,
884 .open = ath5k_debugfs_open, 877 .open = simple_open,
885 .owner = THIS_MODULE, 878 .owner = THIS_MODULE,
886 .llseek = default_llseek, 879 .llseek = default_llseek,
887}; 880};
diff --git a/drivers/net/wireless/ath/ath6kl/debug.c b/drivers/net/wireless/ath/ath6kl/debug.c
index 552adb3f80d0..d01403a263ff 100644
--- a/drivers/net/wireless/ath/ath6kl/debug.c
+++ b/drivers/net/wireless/ath/ath6kl/debug.c
@@ -217,12 +217,6 @@ void dump_cred_dist_stats(struct htc_target *target)
217 target->credit_info->cur_free_credits); 217 target->credit_info->cur_free_credits);
218} 218}
219 219
220static int ath6kl_debugfs_open(struct inode *inode, struct file *file)
221{
222 file->private_data = inode->i_private;
223 return 0;
224}
225
226void ath6kl_debug_war(struct ath6kl *ar, enum ath6kl_war war) 220void ath6kl_debug_war(struct ath6kl *ar, enum ath6kl_war war)
227{ 221{
228 switch (war) { 222 switch (war) {
@@ -263,7 +257,7 @@ static ssize_t read_file_war_stats(struct file *file, char __user *user_buf,
263 257
264static const struct file_operations fops_war_stats = { 258static const struct file_operations fops_war_stats = {
265 .read = read_file_war_stats, 259 .read = read_file_war_stats,
266 .open = ath6kl_debugfs_open, 260 .open = simple_open,
267 .owner = THIS_MODULE, 261 .owner = THIS_MODULE,
268 .llseek = default_llseek, 262 .llseek = default_llseek,
269}; 263};
@@ -488,7 +482,7 @@ static ssize_t ath6kl_fwlog_mask_write(struct file *file,
488} 482}
489 483
490static const struct file_operations fops_fwlog_mask = { 484static const struct file_operations fops_fwlog_mask = {
491 .open = ath6kl_debugfs_open, 485 .open = simple_open,
492 .read = ath6kl_fwlog_mask_read, 486 .read = ath6kl_fwlog_mask_read,
493 .write = ath6kl_fwlog_mask_write, 487 .write = ath6kl_fwlog_mask_write,
494 .owner = THIS_MODULE, 488 .owner = THIS_MODULE,
@@ -634,7 +628,7 @@ static ssize_t read_file_tgt_stats(struct file *file, char __user *user_buf,
634 628
635static const struct file_operations fops_tgt_stats = { 629static const struct file_operations fops_tgt_stats = {
636 .read = read_file_tgt_stats, 630 .read = read_file_tgt_stats,
637 .open = ath6kl_debugfs_open, 631 .open = simple_open,
638 .owner = THIS_MODULE, 632 .owner = THIS_MODULE,
639 .llseek = default_llseek, 633 .llseek = default_llseek,
640}; 634};
@@ -699,7 +693,7 @@ static ssize_t read_file_credit_dist_stats(struct file *file,
699 693
700static const struct file_operations fops_credit_dist_stats = { 694static const struct file_operations fops_credit_dist_stats = {
701 .read = read_file_credit_dist_stats, 695 .read = read_file_credit_dist_stats,
702 .open = ath6kl_debugfs_open, 696 .open = simple_open,
703 .owner = THIS_MODULE, 697 .owner = THIS_MODULE,
704 .llseek = default_llseek, 698 .llseek = default_llseek,
705}; 699};
@@ -802,7 +796,7 @@ static ssize_t ath6kl_endpoint_stats_write(struct file *file,
802} 796}
803 797
804static const struct file_operations fops_endpoint_stats = { 798static const struct file_operations fops_endpoint_stats = {
805 .open = ath6kl_debugfs_open, 799 .open = simple_open,
806 .read = ath6kl_endpoint_stats_read, 800 .read = ath6kl_endpoint_stats_read,
807 .write = ath6kl_endpoint_stats_write, 801 .write = ath6kl_endpoint_stats_write,
808 .owner = THIS_MODULE, 802 .owner = THIS_MODULE,
@@ -875,7 +869,7 @@ static ssize_t ath6kl_regread_write(struct file *file,
875static const struct file_operations fops_diag_reg_read = { 869static const struct file_operations fops_diag_reg_read = {
876 .read = ath6kl_regread_read, 870 .read = ath6kl_regread_read,
877 .write = ath6kl_regread_write, 871 .write = ath6kl_regread_write,
878 .open = ath6kl_debugfs_open, 872 .open = simple_open,
879 .owner = THIS_MODULE, 873 .owner = THIS_MODULE,
880 .llseek = default_llseek, 874 .llseek = default_llseek,
881}; 875};
@@ -999,7 +993,7 @@ static ssize_t ath6kl_lrssi_roam_read(struct file *file,
999static const struct file_operations fops_lrssi_roam_threshold = { 993static const struct file_operations fops_lrssi_roam_threshold = {
1000 .read = ath6kl_lrssi_roam_read, 994 .read = ath6kl_lrssi_roam_read,
1001 .write = ath6kl_lrssi_roam_write, 995 .write = ath6kl_lrssi_roam_write,
1002 .open = ath6kl_debugfs_open, 996 .open = simple_open,
1003 .owner = THIS_MODULE, 997 .owner = THIS_MODULE,
1004 .llseek = default_llseek, 998 .llseek = default_llseek,
1005}; 999};
@@ -1061,7 +1055,7 @@ static ssize_t ath6kl_regwrite_write(struct file *file,
1061static const struct file_operations fops_diag_reg_write = { 1055static const struct file_operations fops_diag_reg_write = {
1062 .read = ath6kl_regwrite_read, 1056 .read = ath6kl_regwrite_read,
1063 .write = ath6kl_regwrite_write, 1057 .write = ath6kl_regwrite_write,
1064 .open = ath6kl_debugfs_open, 1058 .open = simple_open,
1065 .owner = THIS_MODULE, 1059 .owner = THIS_MODULE,
1066 .llseek = default_llseek, 1060 .llseek = default_llseek,
1067}; 1061};
@@ -1166,7 +1160,7 @@ static ssize_t ath6kl_roam_table_read(struct file *file, char __user *user_buf,
1166 1160
1167static const struct file_operations fops_roam_table = { 1161static const struct file_operations fops_roam_table = {
1168 .read = ath6kl_roam_table_read, 1162 .read = ath6kl_roam_table_read,
1169 .open = ath6kl_debugfs_open, 1163 .open = simple_open,
1170 .owner = THIS_MODULE, 1164 .owner = THIS_MODULE,
1171 .llseek = default_llseek, 1165 .llseek = default_llseek,
1172}; 1166};
@@ -1204,7 +1198,7 @@ static ssize_t ath6kl_force_roam_write(struct file *file,
1204 1198
1205static const struct file_operations fops_force_roam = { 1199static const struct file_operations fops_force_roam = {
1206 .write = ath6kl_force_roam_write, 1200 .write = ath6kl_force_roam_write,
1207 .open = ath6kl_debugfs_open, 1201 .open = simple_open,
1208 .owner = THIS_MODULE, 1202 .owner = THIS_MODULE,
1209 .llseek = default_llseek, 1203 .llseek = default_llseek,
1210}; 1204};
@@ -1244,7 +1238,7 @@ static ssize_t ath6kl_roam_mode_write(struct file *file,
1244 1238
1245static const struct file_operations fops_roam_mode = { 1239static const struct file_operations fops_roam_mode = {
1246 .write = ath6kl_roam_mode_write, 1240 .write = ath6kl_roam_mode_write,
1247 .open = ath6kl_debugfs_open, 1241 .open = simple_open,
1248 .owner = THIS_MODULE, 1242 .owner = THIS_MODULE,
1249 .llseek = default_llseek, 1243 .llseek = default_llseek,
1250}; 1244};
@@ -1286,7 +1280,7 @@ static ssize_t ath6kl_keepalive_write(struct file *file,
1286} 1280}
1287 1281
1288static const struct file_operations fops_keepalive = { 1282static const struct file_operations fops_keepalive = {
1289 .open = ath6kl_debugfs_open, 1283 .open = simple_open,
1290 .read = ath6kl_keepalive_read, 1284 .read = ath6kl_keepalive_read,
1291 .write = ath6kl_keepalive_write, 1285 .write = ath6kl_keepalive_write,
1292 .owner = THIS_MODULE, 1286 .owner = THIS_MODULE,
@@ -1331,7 +1325,7 @@ static ssize_t ath6kl_disconnect_timeout_write(struct file *file,
1331} 1325}
1332 1326
1333static const struct file_operations fops_disconnect_timeout = { 1327static const struct file_operations fops_disconnect_timeout = {
1334 .open = ath6kl_debugfs_open, 1328 .open = simple_open,
1335 .read = ath6kl_disconnect_timeout_read, 1329 .read = ath6kl_disconnect_timeout_read,
1336 .write = ath6kl_disconnect_timeout_write, 1330 .write = ath6kl_disconnect_timeout_write,
1337 .owner = THIS_MODULE, 1331 .owner = THIS_MODULE,
@@ -1512,7 +1506,7 @@ static ssize_t ath6kl_create_qos_write(struct file *file,
1512 1506
1513static const struct file_operations fops_create_qos = { 1507static const struct file_operations fops_create_qos = {
1514 .write = ath6kl_create_qos_write, 1508 .write = ath6kl_create_qos_write,
1515 .open = ath6kl_debugfs_open, 1509 .open = simple_open,
1516 .owner = THIS_MODULE, 1510 .owner = THIS_MODULE,
1517 .llseek = default_llseek, 1511 .llseek = default_llseek,
1518}; 1512};
@@ -1560,7 +1554,7 @@ static ssize_t ath6kl_delete_qos_write(struct file *file,
1560 1554
1561static const struct file_operations fops_delete_qos = { 1555static const struct file_operations fops_delete_qos = {
1562 .write = ath6kl_delete_qos_write, 1556 .write = ath6kl_delete_qos_write,
1563 .open = ath6kl_debugfs_open, 1557 .open = simple_open,
1564 .owner = THIS_MODULE, 1558 .owner = THIS_MODULE,
1565 .llseek = default_llseek, 1559 .llseek = default_llseek,
1566}; 1560};
@@ -1593,7 +1587,7 @@ static ssize_t ath6kl_bgscan_int_write(struct file *file,
1593 1587
1594static const struct file_operations fops_bgscan_int = { 1588static const struct file_operations fops_bgscan_int = {
1595 .write = ath6kl_bgscan_int_write, 1589 .write = ath6kl_bgscan_int_write,
1596 .open = ath6kl_debugfs_open, 1590 .open = simple_open,
1597 .owner = THIS_MODULE, 1591 .owner = THIS_MODULE,
1598 .llseek = default_llseek, 1592 .llseek = default_llseek,
1599}; 1593};
@@ -1651,7 +1645,7 @@ static ssize_t ath6kl_listen_int_read(struct file *file,
1651static const struct file_operations fops_listen_int = { 1645static const struct file_operations fops_listen_int = {
1652 .read = ath6kl_listen_int_read, 1646 .read = ath6kl_listen_int_read,
1653 .write = ath6kl_listen_int_write, 1647 .write = ath6kl_listen_int_write,
1654 .open = ath6kl_debugfs_open, 1648 .open = simple_open,
1655 .owner = THIS_MODULE, 1649 .owner = THIS_MODULE,
1656 .llseek = default_llseek, 1650 .llseek = default_llseek,
1657}; 1651};
@@ -1711,7 +1705,7 @@ static ssize_t ath6kl_power_params_write(struct file *file,
1711 1705
1712static const struct file_operations fops_power_params = { 1706static const struct file_operations fops_power_params = {
1713 .write = ath6kl_power_params_write, 1707 .write = ath6kl_power_params_write,
1714 .open = ath6kl_debugfs_open, 1708 .open = simple_open,
1715 .owner = THIS_MODULE, 1709 .owner = THIS_MODULE,
1716 .llseek = default_llseek, 1710 .llseek = default_llseek,
1717}; 1711};
diff --git a/drivers/net/wireless/ath/ath9k/ar5008_phy.c b/drivers/net/wireless/ath/ath9k/ar5008_phy.c
index d7d8e9199140..aba088005b22 100644
--- a/drivers/net/wireless/ath/ath9k/ar5008_phy.c
+++ b/drivers/net/wireless/ath/ath9k/ar5008_phy.c
@@ -869,7 +869,7 @@ static int ar5008_hw_process_ini(struct ath_hw *ah,
869 ar5008_hw_set_channel_regs(ah, chan); 869 ar5008_hw_set_channel_regs(ah, chan);
870 ar5008_hw_init_chain_masks(ah); 870 ar5008_hw_init_chain_masks(ah);
871 ath9k_olc_init(ah); 871 ath9k_olc_init(ah);
872 ath9k_hw_apply_txpower(ah, chan); 872 ath9k_hw_apply_txpower(ah, chan, false);
873 873
874 /* Write analog registers */ 874 /* Write analog registers */
875 if (!ath9k_hw_set_rf_regs(ah, chan, freqIndex)) { 875 if (!ath9k_hw_set_rf_regs(ah, chan, freqIndex)) {
diff --git a/drivers/net/wireless/ath/ath9k/ar9003_paprd.c b/drivers/net/wireless/ath/ath9k/ar9003_paprd.c
index 59647a3ceb7f..3d400e8d6535 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_paprd.c
+++ b/drivers/net/wireless/ath/ath9k/ar9003_paprd.c
@@ -54,7 +54,7 @@ void ar9003_paprd_enable(struct ath_hw *ah, bool val)
54 54
55 if (val) { 55 if (val) {
56 ah->paprd_table_write_done = true; 56 ah->paprd_table_write_done = true;
57 ath9k_hw_apply_txpower(ah, chan); 57 ath9k_hw_apply_txpower(ah, chan, false);
58 } 58 }
59 59
60 REG_RMW_FIELD(ah, AR_PHY_PAPRD_CTRL0_B0, 60 REG_RMW_FIELD(ah, AR_PHY_PAPRD_CTRL0_B0,
diff --git a/drivers/net/wireless/ath/ath9k/ar9003_phy.c b/drivers/net/wireless/ath/ath9k/ar9003_phy.c
index bc992b237ae5..600aca9fe6b1 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_phy.c
+++ b/drivers/net/wireless/ath/ath9k/ar9003_phy.c
@@ -373,7 +373,7 @@ static void ar9003_hw_spur_ofdm_work(struct ath_hw *ah,
373 else 373 else
374 spur_subchannel_sd = 0; 374 spur_subchannel_sd = 0;
375 375
376 spur_freq_sd = (freq_offset << 9) / 11; 376 spur_freq_sd = ((freq_offset + 10) << 9) / 11;
377 377
378 } else { 378 } else {
379 if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL, 379 if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
@@ -382,7 +382,7 @@ static void ar9003_hw_spur_ofdm_work(struct ath_hw *ah,
382 else 382 else
383 spur_subchannel_sd = 1; 383 spur_subchannel_sd = 1;
384 384
385 spur_freq_sd = (freq_offset << 9) / 11; 385 spur_freq_sd = ((freq_offset - 10) << 9) / 11;
386 386
387 } 387 }
388 388
@@ -694,7 +694,7 @@ static int ar9003_hw_process_ini(struct ath_hw *ah,
694 ar9003_hw_override_ini(ah); 694 ar9003_hw_override_ini(ah);
695 ar9003_hw_set_channel_regs(ah, chan); 695 ar9003_hw_set_channel_regs(ah, chan);
696 ar9003_hw_set_chain_masks(ah, ah->rxchainmask, ah->txchainmask); 696 ar9003_hw_set_chain_masks(ah, ah->rxchainmask, ah->txchainmask);
697 ath9k_hw_apply_txpower(ah, chan); 697 ath9k_hw_apply_txpower(ah, chan, false);
698 698
699 if (AR_SREV_9462(ah)) { 699 if (AR_SREV_9462(ah)) {
700 if (REG_READ_FIELD(ah, AR_PHY_TX_IQCAL_CONTROL_0, 700 if (REG_READ_FIELD(ah, AR_PHY_TX_IQCAL_CONTROL_0,
diff --git a/drivers/net/wireless/ath/ath9k/calib.c b/drivers/net/wireless/ath/ath9k/calib.c
index 2f4b48e6fb03..e5cceb077574 100644
--- a/drivers/net/wireless/ath/ath9k/calib.c
+++ b/drivers/net/wireless/ath/ath9k/calib.c
@@ -20,7 +20,6 @@
20 20
21/* Common calibration code */ 21/* Common calibration code */
22 22
23#define ATH9K_NF_TOO_HIGH -60
24 23
25static int16_t ath9k_hw_get_nf_hist_mid(int16_t *nfCalBuffer) 24static int16_t ath9k_hw_get_nf_hist_mid(int16_t *nfCalBuffer)
26{ 25{
@@ -346,10 +345,10 @@ static void ath9k_hw_nf_sanitize(struct ath_hw *ah, s16 *nf)
346 "NF calibrated [%s] [chain %d] is %d\n", 345 "NF calibrated [%s] [chain %d] is %d\n",
347 (i >= 3 ? "ext" : "ctl"), i % 3, nf[i]); 346 (i >= 3 ? "ext" : "ctl"), i % 3, nf[i]);
348 347
349 if (nf[i] > ATH9K_NF_TOO_HIGH) { 348 if (nf[i] > limit->max) {
350 ath_dbg(common, CALIBRATE, 349 ath_dbg(common, CALIBRATE,
351 "NF[%d] (%d) > MAX (%d), correcting to MAX\n", 350 "NF[%d] (%d) > MAX (%d), correcting to MAX\n",
352 i, nf[i], ATH9K_NF_TOO_HIGH); 351 i, nf[i], limit->max);
353 nf[i] = limit->max; 352 nf[i] = limit->max;
354 } else if (nf[i] < limit->min) { 353 } else if (nf[i] < limit->min) {
355 ath_dbg(common, CALIBRATE, 354 ath_dbg(common, CALIBRATE,
diff --git a/drivers/net/wireless/ath/ath9k/debug.c b/drivers/net/wireless/ath/ath9k/debug.c
index 35d1c8e91d1c..ff47b32ecaf4 100644
--- a/drivers/net/wireless/ath/ath9k/debug.c
+++ b/drivers/net/wireless/ath/ath9k/debug.c
@@ -26,11 +26,6 @@
26#define REG_READ_D(_ah, _reg) \ 26#define REG_READ_D(_ah, _reg) \
27 ath9k_hw_common(_ah)->ops->read((_ah), (_reg)) 27 ath9k_hw_common(_ah)->ops->read((_ah), (_reg))
28 28
29static int ath9k_debugfs_open(struct inode *inode, struct file *file)
30{
31 file->private_data = inode->i_private;
32 return 0;
33}
34 29
35static ssize_t ath9k_debugfs_read_buf(struct file *file, char __user *user_buf, 30static ssize_t ath9k_debugfs_read_buf(struct file *file, char __user *user_buf,
36 size_t count, loff_t *ppos) 31 size_t count, loff_t *ppos)
@@ -83,7 +78,7 @@ static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
83static const struct file_operations fops_debug = { 78static const struct file_operations fops_debug = {
84 .read = read_file_debug, 79 .read = read_file_debug,
85 .write = write_file_debug, 80 .write = write_file_debug,
86 .open = ath9k_debugfs_open, 81 .open = simple_open,
87 .owner = THIS_MODULE, 82 .owner = THIS_MODULE,
88 .llseek = default_llseek, 83 .llseek = default_llseek,
89}; 84};
@@ -129,7 +124,7 @@ static ssize_t write_file_tx_chainmask(struct file *file, const char __user *use
129static const struct file_operations fops_tx_chainmask = { 124static const struct file_operations fops_tx_chainmask = {
130 .read = read_file_tx_chainmask, 125 .read = read_file_tx_chainmask,
131 .write = write_file_tx_chainmask, 126 .write = write_file_tx_chainmask,
132 .open = ath9k_debugfs_open, 127 .open = simple_open,
133 .owner = THIS_MODULE, 128 .owner = THIS_MODULE,
134 .llseek = default_llseek, 129 .llseek = default_llseek,
135}; 130};
@@ -172,7 +167,7 @@ static ssize_t write_file_rx_chainmask(struct file *file, const char __user *use
172static const struct file_operations fops_rx_chainmask = { 167static const struct file_operations fops_rx_chainmask = {
173 .read = read_file_rx_chainmask, 168 .read = read_file_rx_chainmask,
174 .write = write_file_rx_chainmask, 169 .write = write_file_rx_chainmask,
175 .open = ath9k_debugfs_open, 170 .open = simple_open,
176 .owner = THIS_MODULE, 171 .owner = THIS_MODULE,
177 .llseek = default_llseek, 172 .llseek = default_llseek,
178}; 173};
@@ -223,7 +218,7 @@ static ssize_t write_file_disable_ani(struct file *file,
223static const struct file_operations fops_disable_ani = { 218static const struct file_operations fops_disable_ani = {
224 .read = read_file_disable_ani, 219 .read = read_file_disable_ani,
225 .write = write_file_disable_ani, 220 .write = write_file_disable_ani,
226 .open = ath9k_debugfs_open, 221 .open = simple_open,
227 .owner = THIS_MODULE, 222 .owner = THIS_MODULE,
228 .llseek = default_llseek, 223 .llseek = default_llseek,
229}; 224};
@@ -324,7 +319,7 @@ static ssize_t read_file_dma(struct file *file, char __user *user_buf,
324 319
325static const struct file_operations fops_dma = { 320static const struct file_operations fops_dma = {
326 .read = read_file_dma, 321 .read = read_file_dma,
327 .open = ath9k_debugfs_open, 322 .open = simple_open,
328 .owner = THIS_MODULE, 323 .owner = THIS_MODULE,
329 .llseek = default_llseek, 324 .llseek = default_llseek,
330}; 325};
@@ -446,7 +441,7 @@ static ssize_t read_file_interrupt(struct file *file, char __user *user_buf,
446 441
447static const struct file_operations fops_interrupt = { 442static const struct file_operations fops_interrupt = {
448 .read = read_file_interrupt, 443 .read = read_file_interrupt,
449 .open = ath9k_debugfs_open, 444 .open = simple_open,
450 .owner = THIS_MODULE, 445 .owner = THIS_MODULE,
451 .llseek = default_llseek, 446 .llseek = default_llseek,
452}; 447};
@@ -852,28 +847,28 @@ void ath_debug_stat_tx(struct ath_softc *sc, struct ath_buf *bf,
852 847
853static const struct file_operations fops_xmit = { 848static const struct file_operations fops_xmit = {
854 .read = read_file_xmit, 849 .read = read_file_xmit,
855 .open = ath9k_debugfs_open, 850 .open = simple_open,
856 .owner = THIS_MODULE, 851 .owner = THIS_MODULE,
857 .llseek = default_llseek, 852 .llseek = default_llseek,
858}; 853};
859 854
860static const struct file_operations fops_stations = { 855static const struct file_operations fops_stations = {
861 .read = read_file_stations, 856 .read = read_file_stations,
862 .open = ath9k_debugfs_open, 857 .open = simple_open,
863 .owner = THIS_MODULE, 858 .owner = THIS_MODULE,
864 .llseek = default_llseek, 859 .llseek = default_llseek,
865}; 860};
866 861
867static const struct file_operations fops_misc = { 862static const struct file_operations fops_misc = {
868 .read = read_file_misc, 863 .read = read_file_misc,
869 .open = ath9k_debugfs_open, 864 .open = simple_open,
870 .owner = THIS_MODULE, 865 .owner = THIS_MODULE,
871 .llseek = default_llseek, 866 .llseek = default_llseek,
872}; 867};
873 868
874static const struct file_operations fops_reset = { 869static const struct file_operations fops_reset = {
875 .read = read_file_reset, 870 .read = read_file_reset,
876 .open = ath9k_debugfs_open, 871 .open = simple_open,
877 .owner = THIS_MODULE, 872 .owner = THIS_MODULE,
878 .llseek = default_llseek, 873 .llseek = default_llseek,
879}; 874};
@@ -1016,7 +1011,7 @@ void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs)
1016 1011
1017static const struct file_operations fops_recv = { 1012static const struct file_operations fops_recv = {
1018 .read = read_file_recv, 1013 .read = read_file_recv,
1019 .open = ath9k_debugfs_open, 1014 .open = simple_open,
1020 .owner = THIS_MODULE, 1015 .owner = THIS_MODULE,
1021 .llseek = default_llseek, 1016 .llseek = default_llseek,
1022}; 1017};
@@ -1055,7 +1050,7 @@ static ssize_t write_file_regidx(struct file *file, const char __user *user_buf,
1055static const struct file_operations fops_regidx = { 1050static const struct file_operations fops_regidx = {
1056 .read = read_file_regidx, 1051 .read = read_file_regidx,
1057 .write = write_file_regidx, 1052 .write = write_file_regidx,
1058 .open = ath9k_debugfs_open, 1053 .open = simple_open,
1059 .owner = THIS_MODULE, 1054 .owner = THIS_MODULE,
1060 .llseek = default_llseek, 1055 .llseek = default_llseek,
1061}; 1056};
@@ -1102,7 +1097,7 @@ static ssize_t write_file_regval(struct file *file, const char __user *user_buf,
1102static const struct file_operations fops_regval = { 1097static const struct file_operations fops_regval = {
1103 .read = read_file_regval, 1098 .read = read_file_regval,
1104 .write = write_file_regval, 1099 .write = write_file_regval,
1105 .open = ath9k_debugfs_open, 1100 .open = simple_open,
1106 .owner = THIS_MODULE, 1101 .owner = THIS_MODULE,
1107 .llseek = default_llseek, 1102 .llseek = default_llseek,
1108}; 1103};
@@ -1191,7 +1186,7 @@ static ssize_t read_file_dump_nfcal(struct file *file, char __user *user_buf,
1191 1186
1192static const struct file_operations fops_dump_nfcal = { 1187static const struct file_operations fops_dump_nfcal = {
1193 .read = read_file_dump_nfcal, 1188 .read = read_file_dump_nfcal,
1194 .open = ath9k_debugfs_open, 1189 .open = simple_open,
1195 .owner = THIS_MODULE, 1190 .owner = THIS_MODULE,
1196 .llseek = default_llseek, 1191 .llseek = default_llseek,
1197}; 1192};
@@ -1219,7 +1214,7 @@ static ssize_t read_file_base_eeprom(struct file *file, char __user *user_buf,
1219 1214
1220static const struct file_operations fops_base_eeprom = { 1215static const struct file_operations fops_base_eeprom = {
1221 .read = read_file_base_eeprom, 1216 .read = read_file_base_eeprom,
1222 .open = ath9k_debugfs_open, 1217 .open = simple_open,
1223 .owner = THIS_MODULE, 1218 .owner = THIS_MODULE,
1224 .llseek = default_llseek, 1219 .llseek = default_llseek,
1225}; 1220};
@@ -1247,7 +1242,7 @@ static ssize_t read_file_modal_eeprom(struct file *file, char __user *user_buf,
1247 1242
1248static const struct file_operations fops_modal_eeprom = { 1243static const struct file_operations fops_modal_eeprom = {
1249 .read = read_file_modal_eeprom, 1244 .read = read_file_modal_eeprom,
1250 .open = ath9k_debugfs_open, 1245 .open = simple_open,
1251 .owner = THIS_MODULE, 1246 .owner = THIS_MODULE,
1252 .llseek = default_llseek, 1247 .llseek = default_llseek,
1253}; 1248};
diff --git a/drivers/net/wireless/ath/ath9k/dfs_debug.c b/drivers/net/wireless/ath/ath9k/dfs_debug.c
index 106d031d834a..4364c103ed33 100644
--- a/drivers/net/wireless/ath/ath9k/dfs_debug.c
+++ b/drivers/net/wireless/ath/ath9k/dfs_debug.c
@@ -60,16 +60,9 @@ static ssize_t read_file_dfs(struct file *file, char __user *user_buf,
60 return retval; 60 return retval;
61} 61}
62 62
63static int ath9k_dfs_debugfs_open(struct inode *inode, struct file *file)
64{
65 file->private_data = inode->i_private;
66
67 return 0;
68}
69
70static const struct file_operations fops_dfs_stats = { 63static const struct file_operations fops_dfs_stats = {
71 .read = read_file_dfs, 64 .read = read_file_dfs,
72 .open = ath9k_dfs_debugfs_open, 65 .open = simple_open,
73 .owner = THIS_MODULE, 66 .owner = THIS_MODULE,
74 .llseek = default_llseek, 67 .llseek = default_llseek,
75}; 68};
diff --git a/drivers/net/wireless/ath/ath9k/eeprom_9287.c b/drivers/net/wireless/ath/ath9k/eeprom_9287.c
index f272236d8053..b34e8b2990b1 100644
--- a/drivers/net/wireless/ath/ath9k/eeprom_9287.c
+++ b/drivers/net/wireless/ath/ath9k/eeprom_9287.c
@@ -824,6 +824,8 @@ static void ath9k_hw_ar9287_set_txpower(struct ath_hw *ah,
824 regulatory->max_power_level = ratesArray[i]; 824 regulatory->max_power_level = ratesArray[i];
825 } 825 }
826 826
827 ath9k_hw_update_regulatory_maxpower(ah);
828
827 if (test) 829 if (test)
828 return; 830 return;
829 831
diff --git a/drivers/net/wireless/ath/ath9k/htc_drv_debug.c b/drivers/net/wireless/ath/ath9k/htc_drv_debug.c
index d3ff33c71aa5..3035deb7a0cd 100644
--- a/drivers/net/wireless/ath/ath9k/htc_drv_debug.c
+++ b/drivers/net/wireless/ath/ath9k/htc_drv_debug.c
@@ -16,12 +16,6 @@
16 16
17#include "htc.h" 17#include "htc.h"
18 18
19static int ath9k_debugfs_open(struct inode *inode, struct file *file)
20{
21 file->private_data = inode->i_private;
22 return 0;
23}
24
25static ssize_t read_file_tgt_int_stats(struct file *file, char __user *user_buf, 19static ssize_t read_file_tgt_int_stats(struct file *file, char __user *user_buf,
26 size_t count, loff_t *ppos) 20 size_t count, loff_t *ppos)
27{ 21{
@@ -75,7 +69,7 @@ static ssize_t read_file_tgt_int_stats(struct file *file, char __user *user_buf,
75 69
76static const struct file_operations fops_tgt_int_stats = { 70static const struct file_operations fops_tgt_int_stats = {
77 .read = read_file_tgt_int_stats, 71 .read = read_file_tgt_int_stats,
78 .open = ath9k_debugfs_open, 72 .open = simple_open,
79 .owner = THIS_MODULE, 73 .owner = THIS_MODULE,
80 .llseek = default_llseek, 74 .llseek = default_llseek,
81}; 75};
@@ -145,7 +139,7 @@ static ssize_t read_file_tgt_tx_stats(struct file *file, char __user *user_buf,
145 139
146static const struct file_operations fops_tgt_tx_stats = { 140static const struct file_operations fops_tgt_tx_stats = {
147 .read = read_file_tgt_tx_stats, 141 .read = read_file_tgt_tx_stats,
148 .open = ath9k_debugfs_open, 142 .open = simple_open,
149 .owner = THIS_MODULE, 143 .owner = THIS_MODULE,
150 .llseek = default_llseek, 144 .llseek = default_llseek,
151}; 145};
@@ -191,7 +185,7 @@ static ssize_t read_file_tgt_rx_stats(struct file *file, char __user *user_buf,
191 185
192static const struct file_operations fops_tgt_rx_stats = { 186static const struct file_operations fops_tgt_rx_stats = {
193 .read = read_file_tgt_rx_stats, 187 .read = read_file_tgt_rx_stats,
194 .open = ath9k_debugfs_open, 188 .open = simple_open,
195 .owner = THIS_MODULE, 189 .owner = THIS_MODULE,
196 .llseek = default_llseek, 190 .llseek = default_llseek,
197}; 191};
@@ -243,7 +237,7 @@ static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
243 237
244static const struct file_operations fops_xmit = { 238static const struct file_operations fops_xmit = {
245 .read = read_file_xmit, 239 .read = read_file_xmit,
246 .open = ath9k_debugfs_open, 240 .open = simple_open,
247 .owner = THIS_MODULE, 241 .owner = THIS_MODULE,
248 .llseek = default_llseek, 242 .llseek = default_llseek,
249}; 243};
@@ -364,7 +358,7 @@ static ssize_t read_file_recv(struct file *file, char __user *user_buf,
364 358
365static const struct file_operations fops_recv = { 359static const struct file_operations fops_recv = {
366 .read = read_file_recv, 360 .read = read_file_recv,
367 .open = ath9k_debugfs_open, 361 .open = simple_open,
368 .owner = THIS_MODULE, 362 .owner = THIS_MODULE,
369 .llseek = default_llseek, 363 .llseek = default_llseek,
370}; 364};
@@ -399,7 +393,7 @@ static ssize_t read_file_slot(struct file *file, char __user *user_buf,
399 393
400static const struct file_operations fops_slot = { 394static const struct file_operations fops_slot = {
401 .read = read_file_slot, 395 .read = read_file_slot,
402 .open = ath9k_debugfs_open, 396 .open = simple_open,
403 .owner = THIS_MODULE, 397 .owner = THIS_MODULE,
404 .llseek = default_llseek, 398 .llseek = default_llseek,
405}; 399};
@@ -446,7 +440,7 @@ static ssize_t read_file_queue(struct file *file, char __user *user_buf,
446 440
447static const struct file_operations fops_queue = { 441static const struct file_operations fops_queue = {
448 .read = read_file_queue, 442 .read = read_file_queue,
449 .open = ath9k_debugfs_open, 443 .open = simple_open,
450 .owner = THIS_MODULE, 444 .owner = THIS_MODULE,
451 .llseek = default_llseek, 445 .llseek = default_llseek,
452}; 446};
@@ -487,7 +481,7 @@ static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
487static const struct file_operations fops_debug = { 481static const struct file_operations fops_debug = {
488 .read = read_file_debug, 482 .read = read_file_debug,
489 .write = write_file_debug, 483 .write = write_file_debug,
490 .open = ath9k_debugfs_open, 484 .open = simple_open,
491 .owner = THIS_MODULE, 485 .owner = THIS_MODULE,
492 .llseek = default_llseek, 486 .llseek = default_llseek,
493}; 487};
@@ -636,7 +630,7 @@ static ssize_t read_file_base_eeprom(struct file *file, char __user *user_buf,
636 630
637static const struct file_operations fops_base_eeprom = { 631static const struct file_operations fops_base_eeprom = {
638 .read = read_file_base_eeprom, 632 .read = read_file_base_eeprom,
639 .open = ath9k_debugfs_open, 633 .open = simple_open,
640 .owner = THIS_MODULE, 634 .owner = THIS_MODULE,
641 .llseek = default_llseek, 635 .llseek = default_llseek,
642}; 636};
@@ -917,7 +911,7 @@ static ssize_t read_file_modal_eeprom(struct file *file, char __user *user_buf,
917 911
918static const struct file_operations fops_modal_eeprom = { 912static const struct file_operations fops_modal_eeprom = {
919 .read = read_file_modal_eeprom, 913 .read = read_file_modal_eeprom,
920 .open = ath9k_debugfs_open, 914 .open = simple_open,
921 .owner = THIS_MODULE, 915 .owner = THIS_MODULE,
922 .llseek = default_llseek, 916 .llseek = default_llseek,
923}; 917};
diff --git a/drivers/net/wireless/ath/ath9k/hw.c b/drivers/net/wireless/ath/ath9k/hw.c
index 6c69e4e8b1cb..fa84e37bf091 100644
--- a/drivers/net/wireless/ath/ath9k/hw.c
+++ b/drivers/net/wireless/ath/ath9k/hw.c
@@ -1454,7 +1454,7 @@ static bool ath9k_hw_channel_change(struct ath_hw *ah,
1454 return false; 1454 return false;
1455 } 1455 }
1456 ath9k_hw_set_clockrate(ah); 1456 ath9k_hw_set_clockrate(ah);
1457 ath9k_hw_apply_txpower(ah, chan); 1457 ath9k_hw_apply_txpower(ah, chan, false);
1458 ath9k_hw_rfbus_done(ah); 1458 ath9k_hw_rfbus_done(ah);
1459 1459
1460 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan)) 1460 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
@@ -2652,7 +2652,8 @@ static int get_antenna_gain(struct ath_hw *ah, struct ath9k_channel *chan)
2652 return ah->eep_ops->get_eeprom(ah, gain_param); 2652 return ah->eep_ops->get_eeprom(ah, gain_param);
2653} 2653}
2654 2654
2655void ath9k_hw_apply_txpower(struct ath_hw *ah, struct ath9k_channel *chan) 2655void ath9k_hw_apply_txpower(struct ath_hw *ah, struct ath9k_channel *chan,
2656 bool test)
2656{ 2657{
2657 struct ath_regulatory *reg = ath9k_hw_regulatory(ah); 2658 struct ath_regulatory *reg = ath9k_hw_regulatory(ah);
2658 struct ieee80211_channel *channel; 2659 struct ieee80211_channel *channel;
@@ -2673,7 +2674,7 @@ void ath9k_hw_apply_txpower(struct ath_hw *ah, struct ath9k_channel *chan)
2673 2674
2674 ah->eep_ops->set_txpower(ah, chan, 2675 ah->eep_ops->set_txpower(ah, chan,
2675 ath9k_regd_get_ctl(reg, chan), 2676 ath9k_regd_get_ctl(reg, chan),
2676 ant_reduction, new_pwr, false); 2677 ant_reduction, new_pwr, test);
2677} 2678}
2678 2679
2679void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit, bool test) 2680void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit, bool test)
@@ -2686,7 +2687,7 @@ void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit, bool test)
2686 if (test) 2687 if (test)
2687 channel->max_power = MAX_RATE_POWER / 2; 2688 channel->max_power = MAX_RATE_POWER / 2;
2688 2689
2689 ath9k_hw_apply_txpower(ah, chan); 2690 ath9k_hw_apply_txpower(ah, chan, test);
2690 2691
2691 if (test) 2692 if (test)
2692 channel->max_power = DIV_ROUND_UP(reg->max_power_level, 2); 2693 channel->max_power = DIV_ROUND_UP(reg->max_power_level, 2);
diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
index aa1680a0c7fd..e88f182ff45c 100644
--- a/drivers/net/wireless/ath/ath9k/hw.h
+++ b/drivers/net/wireless/ath/ath9k/hw.h
@@ -985,7 +985,8 @@ void ath9k_hw_name(struct ath_hw *ah, char *hw_name, size_t len);
985/* PHY */ 985/* PHY */
986void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah, u32 coef_scaled, 986void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah, u32 coef_scaled,
987 u32 *coef_mantissa, u32 *coef_exponent); 987 u32 *coef_mantissa, u32 *coef_exponent);
988void ath9k_hw_apply_txpower(struct ath_hw *ah, struct ath9k_channel *chan); 988void ath9k_hw_apply_txpower(struct ath_hw *ah, struct ath9k_channel *chan,
989 bool test);
989 990
990/* 991/*
991 * Code Specific to AR5008, AR9001 or AR9002, 992 * Code Specific to AR5008, AR9001 or AR9002,
diff --git a/drivers/net/wireless/ath/ath9k/init.c b/drivers/net/wireless/ath/ath9k/init.c
index 60159f4ee532..cb006458fc4b 100644
--- a/drivers/net/wireless/ath/ath9k/init.c
+++ b/drivers/net/wireless/ath/ath9k/init.c
@@ -680,7 +680,7 @@ void ath9k_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw)
680 hw->queues = 4; 680 hw->queues = 4;
681 hw->max_rates = 4; 681 hw->max_rates = 4;
682 hw->channel_change_time = 5000; 682 hw->channel_change_time = 5000;
683 hw->max_listen_interval = 10; 683 hw->max_listen_interval = 1;
684 hw->max_rate_tries = 10; 684 hw->max_rate_tries = 10;
685 hw->sta_data_size = sizeof(struct ath_node); 685 hw->sta_data_size = sizeof(struct ath_node);
686 hw->vif_data_size = sizeof(struct ath_vif); 686 hw->vif_data_size = sizeof(struct ath_vif);
diff --git a/drivers/net/wireless/ath/ath9k/main.c b/drivers/net/wireless/ath/ath9k/main.c
index 38794850f005..798ea57252b4 100644
--- a/drivers/net/wireless/ath/ath9k/main.c
+++ b/drivers/net/wireless/ath/ath9k/main.c
@@ -118,15 +118,13 @@ void ath9k_ps_restore(struct ath_softc *sc)
118 if (--sc->ps_usecount != 0) 118 if (--sc->ps_usecount != 0)
119 goto unlock; 119 goto unlock;
120 120
121 if (sc->ps_flags & PS_WAIT_FOR_TX_ACK) 121 if (sc->ps_idle && (sc->ps_flags & PS_WAIT_FOR_TX_ACK))
122 goto unlock;
123
124 if (sc->ps_idle)
125 mode = ATH9K_PM_FULL_SLEEP; 122 mode = ATH9K_PM_FULL_SLEEP;
126 else if (sc->ps_enabled && 123 else if (sc->ps_enabled &&
127 !(sc->ps_flags & (PS_WAIT_FOR_BEACON | 124 !(sc->ps_flags & (PS_WAIT_FOR_BEACON |
128 PS_WAIT_FOR_CAB | 125 PS_WAIT_FOR_CAB |
129 PS_WAIT_FOR_PSPOLL_DATA))) 126 PS_WAIT_FOR_PSPOLL_DATA |
127 PS_WAIT_FOR_TX_ACK)))
130 mode = ATH9K_PM_NETWORK_SLEEP; 128 mode = ATH9K_PM_NETWORK_SLEEP;
131 else 129 else
132 goto unlock; 130 goto unlock;
@@ -640,7 +638,7 @@ static void ath_node_attach(struct ath_softc *sc, struct ieee80211_sta *sta,
640 an->sta = sta; 638 an->sta = sta;
641 an->vif = vif; 639 an->vif = vif;
642 640
643 if (sta->ht_cap.ht_supported) { 641 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT) {
644 ath_tx_node_init(sc, an); 642 ath_tx_node_init(sc, an);
645 an->maxampdu = 1 << (IEEE80211_HT_MAX_AMPDU_FACTOR + 643 an->maxampdu = 1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
646 sta->ht_cap.ampdu_factor); 644 sta->ht_cap.ampdu_factor);
@@ -659,7 +657,7 @@ static void ath_node_detach(struct ath_softc *sc, struct ieee80211_sta *sta)
659 an->sta = NULL; 657 an->sta = NULL;
660#endif 658#endif
661 659
662 if (sta->ht_cap.ht_supported) 660 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT)
663 ath_tx_node_cleanup(sc, an); 661 ath_tx_node_cleanup(sc, an);
664} 662}
665 663
@@ -1550,6 +1548,7 @@ static int ath9k_config(struct ieee80211_hw *hw, u32 changed)
1550 struct ath_hw *ah = sc->sc_ah; 1548 struct ath_hw *ah = sc->sc_ah;
1551 struct ath_common *common = ath9k_hw_common(ah); 1549 struct ath_common *common = ath9k_hw_common(ah);
1552 struct ieee80211_conf *conf = &hw->conf; 1550 struct ieee80211_conf *conf = &hw->conf;
1551 bool reset_channel = false;
1553 1552
1554 ath9k_ps_wakeup(sc); 1553 ath9k_ps_wakeup(sc);
1555 mutex_lock(&sc->mutex); 1554 mutex_lock(&sc->mutex);
@@ -1558,6 +1557,12 @@ static int ath9k_config(struct ieee80211_hw *hw, u32 changed)
1558 sc->ps_idle = !!(conf->flags & IEEE80211_CONF_IDLE); 1557 sc->ps_idle = !!(conf->flags & IEEE80211_CONF_IDLE);
1559 if (sc->ps_idle) 1558 if (sc->ps_idle)
1560 ath_cancel_work(sc); 1559 ath_cancel_work(sc);
1560 else
1561 /*
1562 * The chip needs a reset to properly wake up from
1563 * full sleep
1564 */
1565 reset_channel = ah->chip_fullsleep;
1561 } 1566 }
1562 1567
1563 /* 1568 /*
@@ -1586,7 +1591,7 @@ static int ath9k_config(struct ieee80211_hw *hw, u32 changed)
1586 } 1591 }
1587 } 1592 }
1588 1593
1589 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) { 1594 if ((changed & IEEE80211_CONF_CHANGE_CHANNEL) || reset_channel) {
1590 struct ieee80211_channel *curchan = hw->conf.channel; 1595 struct ieee80211_channel *curchan = hw->conf.channel;
1591 int pos = curchan->hw_value; 1596 int pos = curchan->hw_value;
1592 int old_pos = -1; 1597 int old_pos = -1;
diff --git a/drivers/net/wireless/ath/ath9k/rc.c b/drivers/net/wireless/ath/ath9k/rc.c
index 4f848493fece..08bb45532701 100644
--- a/drivers/net/wireless/ath/ath9k/rc.c
+++ b/drivers/net/wireless/ath/ath9k/rc.c
@@ -1480,12 +1480,6 @@ static void ath_rate_update(void *priv, struct ieee80211_supported_band *sband,
1480 1480
1481#ifdef CONFIG_ATH9K_DEBUGFS 1481#ifdef CONFIG_ATH9K_DEBUGFS
1482 1482
1483static int ath9k_debugfs_open(struct inode *inode, struct file *file)
1484{
1485 file->private_data = inode->i_private;
1486 return 0;
1487}
1488
1489static ssize_t read_file_rcstat(struct file *file, char __user *user_buf, 1483static ssize_t read_file_rcstat(struct file *file, char __user *user_buf,
1490 size_t count, loff_t *ppos) 1484 size_t count, loff_t *ppos)
1491{ 1485{
@@ -1553,7 +1547,7 @@ static ssize_t read_file_rcstat(struct file *file, char __user *user_buf,
1553 1547
1554static const struct file_operations fops_rcstat = { 1548static const struct file_operations fops_rcstat = {
1555 .read = read_file_rcstat, 1549 .read = read_file_rcstat,
1556 .open = ath9k_debugfs_open, 1550 .open = simple_open,
1557 .owner = THIS_MODULE 1551 .owner = THIS_MODULE
1558}; 1552};
1559 1553
diff --git a/drivers/net/wireless/ath/ath9k/recv.c b/drivers/net/wireless/ath/ath9k/recv.c
index f4ae3ba994a8..1c4583c7ff7c 100644
--- a/drivers/net/wireless/ath/ath9k/recv.c
+++ b/drivers/net/wireless/ath/ath9k/recv.c
@@ -1913,13 +1913,13 @@ int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp)
1913 if (sc->rx.frag) { 1913 if (sc->rx.frag) {
1914 int space = skb->len - skb_tailroom(hdr_skb); 1914 int space = skb->len - skb_tailroom(hdr_skb);
1915 1915
1916 sc->rx.frag = NULL;
1917
1918 if (pskb_expand_head(hdr_skb, 0, space, GFP_ATOMIC) < 0) { 1916 if (pskb_expand_head(hdr_skb, 0, space, GFP_ATOMIC) < 0) {
1919 dev_kfree_skb(skb); 1917 dev_kfree_skb(skb);
1920 goto requeue_drop_frag; 1918 goto requeue_drop_frag;
1921 } 1919 }
1922 1920
1921 sc->rx.frag = NULL;
1922
1923 skb_copy_from_linear_data(skb, skb_put(hdr_skb, skb->len), 1923 skb_copy_from_linear_data(skb, skb_put(hdr_skb, skb->len),
1924 skb->len); 1924 skb->len);
1925 dev_kfree_skb_any(skb); 1925 dev_kfree_skb_any(skb);
diff --git a/drivers/net/wireless/ath/ath9k/xmit.c b/drivers/net/wireless/ath/ath9k/xmit.c
index 834e6bc45e8b..23eaa1b26ebe 100644
--- a/drivers/net/wireless/ath/ath9k/xmit.c
+++ b/drivers/net/wireless/ath/ath9k/xmit.c
@@ -1820,6 +1820,7 @@ static struct ath_buf *ath_tx_setup_buffer(struct ath_softc *sc,
1820 struct ath_frame_info *fi = get_frame_info(skb); 1820 struct ath_frame_info *fi = get_frame_info(skb);
1821 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; 1821 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1822 struct ath_buf *bf; 1822 struct ath_buf *bf;
1823 int fragno;
1823 u16 seqno; 1824 u16 seqno;
1824 1825
1825 bf = ath_tx_get_buffer(sc); 1826 bf = ath_tx_get_buffer(sc);
@@ -1831,9 +1832,16 @@ static struct ath_buf *ath_tx_setup_buffer(struct ath_softc *sc,
1831 ATH_TXBUF_RESET(bf); 1832 ATH_TXBUF_RESET(bf);
1832 1833
1833 if (tid) { 1834 if (tid) {
1835 fragno = le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG;
1834 seqno = tid->seq_next; 1836 seqno = tid->seq_next;
1835 hdr->seq_ctrl = cpu_to_le16(tid->seq_next << IEEE80211_SEQ_SEQ_SHIFT); 1837 hdr->seq_ctrl = cpu_to_le16(tid->seq_next << IEEE80211_SEQ_SEQ_SHIFT);
1836 INCR(tid->seq_next, IEEE80211_SEQ_MAX); 1838
1839 if (fragno)
1840 hdr->seq_ctrl |= cpu_to_le16(fragno);
1841
1842 if (!ieee80211_has_morefrags(hdr->frame_control))
1843 INCR(tid->seq_next, IEEE80211_SEQ_MAX);
1844
1837 bf->bf_state.seqno = seqno; 1845 bf->bf_state.seqno = seqno;
1838 } 1846 }
1839 1847
diff --git a/drivers/net/wireless/ath/carl9170/debug.c b/drivers/net/wireless/ath/carl9170/debug.c
index 3c164226687f..93fe6003a493 100644
--- a/drivers/net/wireless/ath/carl9170/debug.c
+++ b/drivers/net/wireless/ath/carl9170/debug.c
@@ -48,11 +48,6 @@
48#define ADD(buf, off, max, fmt, args...) \ 48#define ADD(buf, off, max, fmt, args...) \
49 off += snprintf(&buf[off], max - off, fmt, ##args); 49 off += snprintf(&buf[off], max - off, fmt, ##args);
50 50
51static int carl9170_debugfs_open(struct inode *inode, struct file *file)
52{
53 file->private_data = inode->i_private;
54 return 0;
55}
56 51
57struct carl9170_debugfs_fops { 52struct carl9170_debugfs_fops {
58 unsigned int read_bufsize; 53 unsigned int read_bufsize;
@@ -178,7 +173,7 @@ static const struct carl9170_debugfs_fops carl_debugfs_##name ##_ops = {\
178 .attr = _attr, \ 173 .attr = _attr, \
179 .req_dev_state = _dstate, \ 174 .req_dev_state = _dstate, \
180 .fops = { \ 175 .fops = { \
181 .open = carl9170_debugfs_open, \ 176 .open = simple_open, \
182 .read = carl9170_debugfs_read, \ 177 .read = carl9170_debugfs_read, \
183 .write = carl9170_debugfs_write, \ 178 .write = carl9170_debugfs_write, \
184 .owner = THIS_MODULE \ 179 .owner = THIS_MODULE \
diff --git a/drivers/net/wireless/b43/debugfs.c b/drivers/net/wireless/b43/debugfs.c
index e751fdee89b2..e807bd930647 100644
--- a/drivers/net/wireless/b43/debugfs.c
+++ b/drivers/net/wireless/b43/debugfs.c
@@ -500,12 +500,6 @@ out:
500 500
501#undef fappend 501#undef fappend
502 502
503static int b43_debugfs_open(struct inode *inode, struct file *file)
504{
505 file->private_data = inode->i_private;
506 return 0;
507}
508
509static ssize_t b43_debugfs_read(struct file *file, char __user *userbuf, 503static ssize_t b43_debugfs_read(struct file *file, char __user *userbuf,
510 size_t count, loff_t *ppos) 504 size_t count, loff_t *ppos)
511{ 505{
@@ -624,7 +618,7 @@ out_unlock:
624 .read = _read, \ 618 .read = _read, \
625 .write = _write, \ 619 .write = _write, \
626 .fops = { \ 620 .fops = { \
627 .open = b43_debugfs_open, \ 621 .open = simple_open, \
628 .read = b43_debugfs_read, \ 622 .read = b43_debugfs_read, \
629 .write = b43_debugfs_write, \ 623 .write = b43_debugfs_write, \
630 .llseek = generic_file_llseek, \ 624 .llseek = generic_file_llseek, \
diff --git a/drivers/net/wireless/b43/main.c b/drivers/net/wireless/b43/main.c
index c79e6638c88d..e4d6dc2e37d1 100644
--- a/drivers/net/wireless/b43/main.c
+++ b/drivers/net/wireless/b43/main.c
@@ -4827,8 +4827,14 @@ static int b43_op_start(struct ieee80211_hw *hw)
4827 out_mutex_unlock: 4827 out_mutex_unlock:
4828 mutex_unlock(&wl->mutex); 4828 mutex_unlock(&wl->mutex);
4829 4829
4830 /* reload configuration */ 4830 /*
4831 b43_op_config(hw, ~0); 4831 * Configuration may have been overwritten during initialization.
4832 * Reload the configuration, but only if initialization was
4833 * successful. Reloading the configuration after a failed init
4834 * may hang the system.
4835 */
4836 if (!err)
4837 b43_op_config(hw, ~0);
4832 4838
4833 return err; 4839 return err;
4834} 4840}
diff --git a/drivers/net/wireless/b43legacy/debugfs.c b/drivers/net/wireless/b43legacy/debugfs.c
index 5e28ad0d6d17..1965edb765a2 100644
--- a/drivers/net/wireless/b43legacy/debugfs.c
+++ b/drivers/net/wireless/b43legacy/debugfs.c
@@ -197,12 +197,6 @@ static int restart_write_file(struct b43legacy_wldev *dev, const char *buf, size
197 197
198#undef fappend 198#undef fappend
199 199
200static int b43legacy_debugfs_open(struct inode *inode, struct file *file)
201{
202 file->private_data = inode->i_private;
203 return 0;
204}
205
206static ssize_t b43legacy_debugfs_read(struct file *file, char __user *userbuf, 200static ssize_t b43legacy_debugfs_read(struct file *file, char __user *userbuf,
207 size_t count, loff_t *ppos) 201 size_t count, loff_t *ppos)
208{ 202{
@@ -331,7 +325,7 @@ out_unlock:
331 .read = _read, \ 325 .read = _read, \
332 .write = _write, \ 326 .write = _write, \
333 .fops = { \ 327 .fops = { \
334 .open = b43legacy_debugfs_open, \ 328 .open = simple_open, \
335 .read = b43legacy_debugfs_read, \ 329 .read = b43legacy_debugfs_read, \
336 .write = b43legacy_debugfs_write, \ 330 .write = b43legacy_debugfs_write, \
337 .llseek = generic_file_llseek, \ 331 .llseek = generic_file_llseek, \
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/bcmsdh_sdmmc.c b/drivers/net/wireless/brcm80211/brcmfmac/bcmsdh_sdmmc.c
index 4688904908ec..758c115b556e 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/bcmsdh_sdmmc.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/bcmsdh_sdmmc.c
@@ -108,9 +108,15 @@ static inline int brcmf_sdioh_f0_write_byte(struct brcmf_sdio_dev *sdiodev,
108 sdio_release_host(sdfunc); 108 sdio_release_host(sdfunc);
109 } 109 }
110 } else if (regaddr == SDIO_CCCR_ABORT) { 110 } else if (regaddr == SDIO_CCCR_ABORT) {
111 sdfunc = kmemdup(sdiodev->func[0], sizeof(struct sdio_func),
112 GFP_KERNEL);
113 if (!sdfunc)
114 return -ENOMEM;
115 sdfunc->num = 0;
111 sdio_claim_host(sdfunc); 116 sdio_claim_host(sdfunc);
112 sdio_writeb(sdfunc, *byte, regaddr, &err_ret); 117 sdio_writeb(sdfunc, *byte, regaddr, &err_ret);
113 sdio_release_host(sdfunc); 118 sdio_release_host(sdfunc);
119 kfree(sdfunc);
114 } else if (regaddr < 0xF0) { 120 } else if (regaddr < 0xF0) {
115 brcmf_dbg(ERROR, "F0 Wr:0x%02x: write disallowed\n", regaddr); 121 brcmf_dbg(ERROR, "F0 Wr:0x%02x: write disallowed\n", regaddr);
116 err_ret = -EPERM; 122 err_ret = -EPERM;
@@ -486,7 +492,7 @@ static int brcmf_ops_sdio_probe(struct sdio_func *func,
486 kfree(bus_if); 492 kfree(bus_if);
487 return -ENOMEM; 493 return -ENOMEM;
488 } 494 }
489 sdiodev->func[0] = func->card->sdio_func[0]; 495 sdiodev->func[0] = func;
490 sdiodev->func[1] = func; 496 sdiodev->func[1] = func;
491 sdiodev->bus_if = bus_if; 497 sdiodev->bus_if = bus_if;
492 bus_if->bus_priv.sdio = sdiodev; 498 bus_if->bus_priv.sdio = sdiodev;
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c b/drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c
index 2bf5dda29291..e2b34e1563f4 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c
@@ -574,6 +574,8 @@ struct brcmf_sdio {
574 574
575 struct task_struct *dpc_tsk; 575 struct task_struct *dpc_tsk;
576 struct completion dpc_wait; 576 struct completion dpc_wait;
577 struct list_head dpc_tsklst;
578 spinlock_t dpc_tl_lock;
577 579
578 struct semaphore sdsem; 580 struct semaphore sdsem;
579 581
@@ -2594,29 +2596,59 @@ clkwait:
2594 return resched; 2596 return resched;
2595} 2597}
2596 2598
2599static inline void brcmf_sdbrcm_adddpctsk(struct brcmf_sdio *bus)
2600{
2601 struct list_head *new_hd;
2602 unsigned long flags;
2603
2604 if (in_interrupt())
2605 new_hd = kzalloc(sizeof(struct list_head), GFP_ATOMIC);
2606 else
2607 new_hd = kzalloc(sizeof(struct list_head), GFP_KERNEL);
2608 if (new_hd == NULL)
2609 return;
2610
2611 spin_lock_irqsave(&bus->dpc_tl_lock, flags);
2612 list_add_tail(new_hd, &bus->dpc_tsklst);
2613 spin_unlock_irqrestore(&bus->dpc_tl_lock, flags);
2614}
2615
2597static int brcmf_sdbrcm_dpc_thread(void *data) 2616static int brcmf_sdbrcm_dpc_thread(void *data)
2598{ 2617{
2599 struct brcmf_sdio *bus = (struct brcmf_sdio *) data; 2618 struct brcmf_sdio *bus = (struct brcmf_sdio *) data;
2619 struct list_head *cur_hd, *tmp_hd;
2620 unsigned long flags;
2600 2621
2601 allow_signal(SIGTERM); 2622 allow_signal(SIGTERM);
2602 /* Run until signal received */ 2623 /* Run until signal received */
2603 while (1) { 2624 while (1) {
2604 if (kthread_should_stop()) 2625 if (kthread_should_stop())
2605 break; 2626 break;
2606 if (!wait_for_completion_interruptible(&bus->dpc_wait)) { 2627
2607 /* Call bus dpc unless it indicated down 2628 if (list_empty(&bus->dpc_tsklst))
2608 (then clean stop) */ 2629 if (wait_for_completion_interruptible(&bus->dpc_wait))
2609 if (bus->sdiodev->bus_if->state != BRCMF_BUS_DOWN) { 2630 break;
2610 if (brcmf_sdbrcm_dpc(bus)) 2631
2611 complete(&bus->dpc_wait); 2632 spin_lock_irqsave(&bus->dpc_tl_lock, flags);
2612 } else { 2633 list_for_each_safe(cur_hd, tmp_hd, &bus->dpc_tsklst) {
2634 spin_unlock_irqrestore(&bus->dpc_tl_lock, flags);
2635
2636 if (bus->sdiodev->bus_if->state == BRCMF_BUS_DOWN) {
2613 /* after stopping the bus, exit thread */ 2637 /* after stopping the bus, exit thread */
2614 brcmf_sdbrcm_bus_stop(bus->sdiodev->dev); 2638 brcmf_sdbrcm_bus_stop(bus->sdiodev->dev);
2615 bus->dpc_tsk = NULL; 2639 bus->dpc_tsk = NULL;
2640 spin_lock_irqsave(&bus->dpc_tl_lock, flags);
2616 break; 2641 break;
2617 } 2642 }
2618 } else 2643
2619 break; 2644 if (brcmf_sdbrcm_dpc(bus))
2645 brcmf_sdbrcm_adddpctsk(bus);
2646
2647 spin_lock_irqsave(&bus->dpc_tl_lock, flags);
2648 list_del(cur_hd);
2649 kfree(cur_hd);
2650 }
2651 spin_unlock_irqrestore(&bus->dpc_tl_lock, flags);
2620 } 2652 }
2621 return 0; 2653 return 0;
2622} 2654}
@@ -2669,8 +2701,10 @@ static int brcmf_sdbrcm_bus_txdata(struct device *dev, struct sk_buff *pkt)
2669 /* Schedule DPC if needed to send queued packet(s) */ 2701 /* Schedule DPC if needed to send queued packet(s) */
2670 if (!bus->dpc_sched) { 2702 if (!bus->dpc_sched) {
2671 bus->dpc_sched = true; 2703 bus->dpc_sched = true;
2672 if (bus->dpc_tsk) 2704 if (bus->dpc_tsk) {
2705 brcmf_sdbrcm_adddpctsk(bus);
2673 complete(&bus->dpc_wait); 2706 complete(&bus->dpc_wait);
2707 }
2674 } 2708 }
2675 2709
2676 return ret; 2710 return ret;
@@ -3514,8 +3548,10 @@ void brcmf_sdbrcm_isr(void *arg)
3514 brcmf_dbg(ERROR, "isr w/o interrupt configured!\n"); 3548 brcmf_dbg(ERROR, "isr w/o interrupt configured!\n");
3515 3549
3516 bus->dpc_sched = true; 3550 bus->dpc_sched = true;
3517 if (bus->dpc_tsk) 3551 if (bus->dpc_tsk) {
3552 brcmf_sdbrcm_adddpctsk(bus);
3518 complete(&bus->dpc_wait); 3553 complete(&bus->dpc_wait);
3554 }
3519} 3555}
3520 3556
3521static bool brcmf_sdbrcm_bus_watchdog(struct brcmf_sdio *bus) 3557static bool brcmf_sdbrcm_bus_watchdog(struct brcmf_sdio *bus)
@@ -3559,8 +3595,10 @@ static bool brcmf_sdbrcm_bus_watchdog(struct brcmf_sdio *bus)
3559 bus->ipend = true; 3595 bus->ipend = true;
3560 3596
3561 bus->dpc_sched = true; 3597 bus->dpc_sched = true;
3562 if (bus->dpc_tsk) 3598 if (bus->dpc_tsk) {
3599 brcmf_sdbrcm_adddpctsk(bus);
3563 complete(&bus->dpc_wait); 3600 complete(&bus->dpc_wait);
3601 }
3564 } 3602 }
3565 } 3603 }
3566 3604
@@ -3897,6 +3935,8 @@ void *brcmf_sdbrcm_probe(u32 regsva, struct brcmf_sdio_dev *sdiodev)
3897 } 3935 }
3898 /* Initialize DPC thread */ 3936 /* Initialize DPC thread */
3899 init_completion(&bus->dpc_wait); 3937 init_completion(&bus->dpc_wait);
3938 INIT_LIST_HEAD(&bus->dpc_tsklst);
3939 spin_lock_init(&bus->dpc_tl_lock);
3900 bus->dpc_tsk = kthread_run(brcmf_sdbrcm_dpc_thread, 3940 bus->dpc_tsk = kthread_run(brcmf_sdbrcm_dpc_thread,
3901 bus, "brcmf_dpc"); 3941 bus, "brcmf_dpc");
3902 if (IS_ERR(bus->dpc_tsk)) { 3942 if (IS_ERR(bus->dpc_tsk)) {
diff --git a/drivers/net/wireless/brcm80211/brcmsmac/main.c b/drivers/net/wireless/brcm80211/brcmsmac/main.c
index 231ddf4a674f..b4d92792c502 100644
--- a/drivers/net/wireless/brcm80211/brcmsmac/main.c
+++ b/drivers/net/wireless/brcm80211/brcmsmac/main.c
@@ -847,8 +847,7 @@ brcms_c_dotxstatus(struct brcms_c_info *wlc, struct tx_status *txs)
847 */ 847 */
848 if (!(txs->status & TX_STATUS_AMPDU) 848 if (!(txs->status & TX_STATUS_AMPDU)
849 && (txs->status & TX_STATUS_INTERMEDIATE)) { 849 && (txs->status & TX_STATUS_INTERMEDIATE)) {
850 wiphy_err(wlc->wiphy, "%s: INTERMEDIATE but not AMPDU\n", 850 BCMMSG(wlc->wiphy, "INTERMEDIATE but not AMPDU\n");
851 __func__);
852 return false; 851 return false;
853 } 852 }
854 853
@@ -7614,6 +7613,7 @@ brcms_c_recvctl(struct brcms_c_info *wlc, struct d11rxhdr *rxh,
7614{ 7613{
7615 int len_mpdu; 7614 int len_mpdu;
7616 struct ieee80211_rx_status rx_status; 7615 struct ieee80211_rx_status rx_status;
7616 struct ieee80211_hdr *hdr;
7617 7617
7618 memset(&rx_status, 0, sizeof(rx_status)); 7618 memset(&rx_status, 0, sizeof(rx_status));
7619 prep_mac80211_status(wlc, rxh, p, &rx_status); 7619 prep_mac80211_status(wlc, rxh, p, &rx_status);
@@ -7623,6 +7623,13 @@ brcms_c_recvctl(struct brcms_c_info *wlc, struct d11rxhdr *rxh,
7623 skb_pull(p, D11_PHY_HDR_LEN); 7623 skb_pull(p, D11_PHY_HDR_LEN);
7624 __skb_trim(p, len_mpdu); 7624 __skb_trim(p, len_mpdu);
7625 7625
7626 /* unmute transmit */
7627 if (wlc->hw->suspended_fifos) {
7628 hdr = (struct ieee80211_hdr *)p->data;
7629 if (ieee80211_is_beacon(hdr->frame_control))
7630 brcms_b_mute(wlc->hw, false);
7631 }
7632
7626 memcpy(IEEE80211_SKB_RXCB(p), &rx_status, sizeof(rx_status)); 7633 memcpy(IEEE80211_SKB_RXCB(p), &rx_status, sizeof(rx_status));
7627 ieee80211_rx_irqsafe(wlc->pub->ieee_hw, p); 7634 ieee80211_rx_irqsafe(wlc->pub->ieee_hw, p);
7628} 7635}
diff --git a/drivers/net/wireless/ipw2x00/ipw2200.c b/drivers/net/wireless/ipw2x00/ipw2200.c
index 4fcdac63a300..1779db3aa2b0 100644
--- a/drivers/net/wireless/ipw2x00/ipw2200.c
+++ b/drivers/net/wireless/ipw2x00/ipw2200.c
@@ -2191,6 +2191,7 @@ static int __ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd)
2191{ 2191{
2192 int rc = 0; 2192 int rc = 0;
2193 unsigned long flags; 2193 unsigned long flags;
2194 unsigned long now, end;
2194 2195
2195 spin_lock_irqsave(&priv->lock, flags); 2196 spin_lock_irqsave(&priv->lock, flags);
2196 if (priv->status & STATUS_HCMD_ACTIVE) { 2197 if (priv->status & STATUS_HCMD_ACTIVE) {
@@ -2232,10 +2233,20 @@ static int __ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd)
2232 } 2233 }
2233 spin_unlock_irqrestore(&priv->lock, flags); 2234 spin_unlock_irqrestore(&priv->lock, flags);
2234 2235
2236 now = jiffies;
2237 end = now + HOST_COMPLETE_TIMEOUT;
2238again:
2235 rc = wait_event_interruptible_timeout(priv->wait_command_queue, 2239 rc = wait_event_interruptible_timeout(priv->wait_command_queue,
2236 !(priv-> 2240 !(priv->
2237 status & STATUS_HCMD_ACTIVE), 2241 status & STATUS_HCMD_ACTIVE),
2238 HOST_COMPLETE_TIMEOUT); 2242 end - now);
2243 if (rc < 0) {
2244 now = jiffies;
2245 if (time_before(now, end))
2246 goto again;
2247 rc = 0;
2248 }
2249
2239 if (rc == 0) { 2250 if (rc == 0) {
2240 spin_lock_irqsave(&priv->lock, flags); 2251 spin_lock_irqsave(&priv->lock, flags);
2241 if (priv->status & STATUS_HCMD_ACTIVE) { 2252 if (priv->status & STATUS_HCMD_ACTIVE) {
@@ -11507,9 +11518,9 @@ static int ipw_wdev_init(struct net_device *dev)
11507 rc = -ENOMEM; 11518 rc = -ENOMEM;
11508 goto out; 11519 goto out;
11509 } 11520 }
11510 /* translate geo->bg to a_band.channels */ 11521 /* translate geo->a to a_band.channels */
11511 for (i = 0; i < geo->a_channels; i++) { 11522 for (i = 0; i < geo->a_channels; i++) {
11512 a_band->channels[i].band = IEEE80211_BAND_2GHZ; 11523 a_band->channels[i].band = IEEE80211_BAND_5GHZ;
11513 a_band->channels[i].center_freq = geo->a[i].freq; 11524 a_band->channels[i].center_freq = geo->a[i].freq;
11514 a_band->channels[i].hw_value = geo->a[i].channel; 11525 a_band->channels[i].hw_value = geo->a[i].channel;
11515 a_band->channels[i].max_power = geo->a[i].max_power; 11526 a_band->channels[i].max_power = geo->a[i].max_power;
diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
index 0c1209390169..faec40467208 100644
--- a/drivers/net/wireless/iwlegacy/3945-mac.c
+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
@@ -2673,8 +2673,6 @@ il3945_bg_restart(struct work_struct *data)
2673 2673
2674 if (test_and_clear_bit(S_FW_ERROR, &il->status)) { 2674 if (test_and_clear_bit(S_FW_ERROR, &il->status)) {
2675 mutex_lock(&il->mutex); 2675 mutex_lock(&il->mutex);
2676 /* FIXME: vif can be dereferenced */
2677 il->vif = NULL;
2678 il->is_open = 0; 2676 il->is_open = 0;
2679 mutex_unlock(&il->mutex); 2677 mutex_unlock(&il->mutex);
2680 il3945_down(il); 2678 il3945_down(il);
diff --git a/drivers/net/wireless/iwlegacy/3945-rs.c b/drivers/net/wireless/iwlegacy/3945-rs.c
index 70bee1a4d876..4b10157d8686 100644
--- a/drivers/net/wireless/iwlegacy/3945-rs.c
+++ b/drivers/net/wireless/iwlegacy/3945-rs.c
@@ -821,12 +821,6 @@ out:
821} 821}
822 822
823#ifdef CONFIG_MAC80211_DEBUGFS 823#ifdef CONFIG_MAC80211_DEBUGFS
824static int
825il3945_open_file_generic(struct inode *inode, struct file *file)
826{
827 file->private_data = inode->i_private;
828 return 0;
829}
830 824
831static ssize_t 825static ssize_t
832il3945_sta_dbgfs_stats_table_read(struct file *file, char __user *user_buf, 826il3945_sta_dbgfs_stats_table_read(struct file *file, char __user *user_buf,
@@ -862,7 +856,7 @@ il3945_sta_dbgfs_stats_table_read(struct file *file, char __user *user_buf,
862 856
863static const struct file_operations rs_sta_dbgfs_stats_table_ops = { 857static const struct file_operations rs_sta_dbgfs_stats_table_ops = {
864 .read = il3945_sta_dbgfs_stats_table_read, 858 .read = il3945_sta_dbgfs_stats_table_read,
865 .open = il3945_open_file_generic, 859 .open = simple_open,
866 .llseek = default_llseek, 860 .llseek = default_llseek,
867}; 861};
868 862
diff --git a/drivers/net/wireless/iwlegacy/4965-mac.c b/drivers/net/wireless/iwlegacy/4965-mac.c
index 17f1c6853182..c46275a92565 100644
--- a/drivers/net/wireless/iwlegacy/4965-mac.c
+++ b/drivers/net/wireless/iwlegacy/4965-mac.c
@@ -5652,8 +5652,6 @@ il4965_bg_restart(struct work_struct *data)
5652 5652
5653 if (test_and_clear_bit(S_FW_ERROR, &il->status)) { 5653 if (test_and_clear_bit(S_FW_ERROR, &il->status)) {
5654 mutex_lock(&il->mutex); 5654 mutex_lock(&il->mutex);
5655 /* FIXME: do we dereference vif without mutex locked ? */
5656 il->vif = NULL;
5657 il->is_open = 0; 5655 il->is_open = 0;
5658 5656
5659 __il4965_down(il); 5657 __il4965_down(il);
diff --git a/drivers/net/wireless/iwlegacy/4965-rs.c b/drivers/net/wireless/iwlegacy/4965-rs.c
index d7e2856e41d3..11ab1247fae1 100644
--- a/drivers/net/wireless/iwlegacy/4965-rs.c
+++ b/drivers/net/wireless/iwlegacy/4965-rs.c
@@ -2518,12 +2518,6 @@ il4965_rs_free_sta(void *il_r, struct ieee80211_sta *sta, void *il_sta)
2518} 2518}
2519 2519
2520#ifdef CONFIG_MAC80211_DEBUGFS 2520#ifdef CONFIG_MAC80211_DEBUGFS
2521static int
2522il4965_open_file_generic(struct inode *inode, struct file *file)
2523{
2524 file->private_data = inode->i_private;
2525 return 0;
2526}
2527 2521
2528static void 2522static void
2529il4965_rs_dbgfs_set_mcs(struct il_lq_sta *lq_sta, u32 * rate_n_flags, int idx) 2523il4965_rs_dbgfs_set_mcs(struct il_lq_sta *lq_sta, u32 * rate_n_flags, int idx)
@@ -2695,7 +2689,7 @@ il4965_rs_sta_dbgfs_scale_table_read(struct file *file, char __user *user_buf,
2695static const struct file_operations rs_sta_dbgfs_scale_table_ops = { 2689static const struct file_operations rs_sta_dbgfs_scale_table_ops = {
2696 .write = il4965_rs_sta_dbgfs_scale_table_write, 2690 .write = il4965_rs_sta_dbgfs_scale_table_write,
2697 .read = il4965_rs_sta_dbgfs_scale_table_read, 2691 .read = il4965_rs_sta_dbgfs_scale_table_read,
2698 .open = il4965_open_file_generic, 2692 .open = simple_open,
2699 .llseek = default_llseek, 2693 .llseek = default_llseek,
2700}; 2694};
2701 2695
@@ -2740,7 +2734,7 @@ il4965_rs_sta_dbgfs_stats_table_read(struct file *file, char __user *user_buf,
2740 2734
2741static const struct file_operations rs_sta_dbgfs_stats_table_ops = { 2735static const struct file_operations rs_sta_dbgfs_stats_table_ops = {
2742 .read = il4965_rs_sta_dbgfs_stats_table_read, 2736 .read = il4965_rs_sta_dbgfs_stats_table_read,
2743 .open = il4965_open_file_generic, 2737 .open = simple_open,
2744 .llseek = default_llseek, 2738 .llseek = default_llseek,
2745}; 2739};
2746 2740
@@ -2768,7 +2762,7 @@ il4965_rs_sta_dbgfs_rate_scale_data_read(struct file *file,
2768 2762
2769static const struct file_operations rs_sta_dbgfs_rate_scale_data_ops = { 2763static const struct file_operations rs_sta_dbgfs_rate_scale_data_ops = {
2770 .read = il4965_rs_sta_dbgfs_rate_scale_data_read, 2764 .read = il4965_rs_sta_dbgfs_rate_scale_data_read,
2771 .open = il4965_open_file_generic, 2765 .open = simple_open,
2772 .llseek = default_llseek, 2766 .llseek = default_llseek,
2773}; 2767};
2774 2768
diff --git a/drivers/net/wireless/iwlegacy/common.c b/drivers/net/wireless/iwlegacy/common.c
index e5ac04739bcc..eaf249452e51 100644
--- a/drivers/net/wireless/iwlegacy/common.c
+++ b/drivers/net/wireless/iwlegacy/common.c
@@ -4508,6 +4508,7 @@ il_mac_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
4508{ 4508{
4509 struct il_priv *il = hw->priv; 4509 struct il_priv *il = hw->priv;
4510 int err; 4510 int err;
4511 bool reset;
4511 4512
4512 mutex_lock(&il->mutex); 4513 mutex_lock(&il->mutex);
4513 D_MAC80211("enter: type %d, addr %pM\n", vif->type, vif->addr); 4514 D_MAC80211("enter: type %d, addr %pM\n", vif->type, vif->addr);
@@ -4518,7 +4519,12 @@ il_mac_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
4518 goto out; 4519 goto out;
4519 } 4520 }
4520 4521
4521 if (il->vif) { 4522 /*
4523 * We do not support multiple virtual interfaces, but on hardware reset
4524 * we have to add the same interface again.
4525 */
4526 reset = (il->vif == vif);
4527 if (il->vif && !reset) {
4522 err = -EOPNOTSUPP; 4528 err = -EOPNOTSUPP;
4523 goto out; 4529 goto out;
4524 } 4530 }
@@ -4528,8 +4534,11 @@ il_mac_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
4528 4534
4529 err = il_set_mode(il); 4535 err = il_set_mode(il);
4530 if (err) { 4536 if (err) {
4531 il->vif = NULL; 4537 IL_WARN("Fail to set mode %d\n", vif->type);
4532 il->iw_mode = NL80211_IFTYPE_STATION; 4538 if (!reset) {
4539 il->vif = NULL;
4540 il->iw_mode = NL80211_IFTYPE_STATION;
4541 }
4533 } 4542 }
4534 4543
4535out: 4544out:
@@ -5279,9 +5288,9 @@ il_mac_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5279 D_MAC80211("BSSID %pM\n", bss_conf->bssid); 5288 D_MAC80211("BSSID %pM\n", bss_conf->bssid);
5280 5289
5281 /* 5290 /*
5282 * If there is currently a HW scan going on in the 5291 * If there is currently a HW scan going on in the background,
5283 * background then we need to cancel it else the RXON 5292 * then we need to cancel it, otherwise sometimes we are not
5284 * below/in post_associate will fail. 5293 * able to authenticate (FIXME: why ?)
5285 */ 5294 */
5286 if (il_scan_cancel_timeout(il, 100)) { 5295 if (il_scan_cancel_timeout(il, 100)) {
5287 D_MAC80211("leave - scan abort failed\n"); 5296 D_MAC80211("leave - scan abort failed\n");
@@ -5290,14 +5299,10 @@ il_mac_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5290 } 5299 }
5291 5300
5292 /* mac80211 only sets assoc when in STATION mode */ 5301 /* mac80211 only sets assoc when in STATION mode */
5293 if (vif->type == NL80211_IFTYPE_ADHOC || bss_conf->assoc) { 5302 memcpy(il->staging.bssid_addr, bss_conf->bssid, ETH_ALEN);
5294 memcpy(il->staging.bssid_addr, bss_conf->bssid,
5295 ETH_ALEN);
5296 5303
5297 /* currently needed in a few places */ 5304 /* FIXME: currently needed in a few places */
5298 memcpy(il->bssid, bss_conf->bssid, ETH_ALEN); 5305 memcpy(il->bssid, bss_conf->bssid, ETH_ALEN);
5299 } else
5300 il->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
5301 } 5306 }
5302 5307
5303 /* 5308 /*
diff --git a/drivers/net/wireless/iwlegacy/debug.c b/drivers/net/wireless/iwlegacy/debug.c
index 229849150aac..eff26501d60a 100644
--- a/drivers/net/wireless/iwlegacy/debug.c
+++ b/drivers/net/wireless/iwlegacy/debug.c
@@ -160,18 +160,12 @@ static ssize_t il_dbgfs_##name##_write(struct file *file, \
160 const char __user *user_buf, \ 160 const char __user *user_buf, \
161 size_t count, loff_t *ppos); 161 size_t count, loff_t *ppos);
162 162
163static int
164il_dbgfs_open_file_generic(struct inode *inode, struct file *file)
165{
166 file->private_data = inode->i_private;
167 return 0;
168}
169 163
170#define DEBUGFS_READ_FILE_OPS(name) \ 164#define DEBUGFS_READ_FILE_OPS(name) \
171 DEBUGFS_READ_FUNC(name); \ 165 DEBUGFS_READ_FUNC(name); \
172static const struct file_operations il_dbgfs_##name##_ops = { \ 166static const struct file_operations il_dbgfs_##name##_ops = { \
173 .read = il_dbgfs_##name##_read, \ 167 .read = il_dbgfs_##name##_read, \
174 .open = il_dbgfs_open_file_generic, \ 168 .open = simple_open, \
175 .llseek = generic_file_llseek, \ 169 .llseek = generic_file_llseek, \
176}; 170};
177 171
@@ -179,7 +173,7 @@ static const struct file_operations il_dbgfs_##name##_ops = { \
179 DEBUGFS_WRITE_FUNC(name); \ 173 DEBUGFS_WRITE_FUNC(name); \
180static const struct file_operations il_dbgfs_##name##_ops = { \ 174static const struct file_operations il_dbgfs_##name##_ops = { \
181 .write = il_dbgfs_##name##_write, \ 175 .write = il_dbgfs_##name##_write, \
182 .open = il_dbgfs_open_file_generic, \ 176 .open = simple_open, \
183 .llseek = generic_file_llseek, \ 177 .llseek = generic_file_llseek, \
184}; 178};
185 179
@@ -189,7 +183,7 @@ static const struct file_operations il_dbgfs_##name##_ops = { \
189static const struct file_operations il_dbgfs_##name##_ops = { \ 183static const struct file_operations il_dbgfs_##name##_ops = { \
190 .write = il_dbgfs_##name##_write, \ 184 .write = il_dbgfs_##name##_write, \
191 .read = il_dbgfs_##name##_read, \ 185 .read = il_dbgfs_##name##_read, \
192 .open = il_dbgfs_open_file_generic, \ 186 .open = simple_open, \
193 .llseek = generic_file_llseek, \ 187 .llseek = generic_file_llseek, \
194}; 188};
195 189
diff --git a/drivers/net/wireless/iwlwifi/iwl-1000.c b/drivers/net/wireless/iwlwifi/iwl-1000.c
index 5b0d888f746b..8d80e233bc7a 100644
--- a/drivers/net/wireless/iwlwifi/iwl-1000.c
+++ b/drivers/net/wireless/iwlwifi/iwl-1000.c
@@ -46,8 +46,8 @@
46#include "iwl-prph.h" 46#include "iwl-prph.h"
47 47
48/* Highest firmware API version supported */ 48/* Highest firmware API version supported */
49#define IWL1000_UCODE_API_MAX 6 49#define IWL1000_UCODE_API_MAX 5
50#define IWL100_UCODE_API_MAX 6 50#define IWL100_UCODE_API_MAX 5
51 51
52/* Oldest version we won't warn about */ 52/* Oldest version we won't warn about */
53#define IWL1000_UCODE_API_OK 5 53#define IWL1000_UCODE_API_OK 5
@@ -226,5 +226,5 @@ const struct iwl_cfg iwl100_bg_cfg = {
226 IWL_DEVICE_100, 226 IWL_DEVICE_100,
227}; 227};
228 228
229MODULE_FIRMWARE(IWL1000_MODULE_FIRMWARE(IWL1000_UCODE_API_MAX)); 229MODULE_FIRMWARE(IWL1000_MODULE_FIRMWARE(IWL1000_UCODE_API_OK));
230MODULE_FIRMWARE(IWL100_MODULE_FIRMWARE(IWL100_UCODE_API_MAX)); 230MODULE_FIRMWARE(IWL100_MODULE_FIRMWARE(IWL100_UCODE_API_OK));
diff --git a/drivers/net/wireless/iwlwifi/iwl-2000.c b/drivers/net/wireless/iwlwifi/iwl-2000.c
index 5635b9e2c69e..ea108622e0bd 100644
--- a/drivers/net/wireless/iwlwifi/iwl-2000.c
+++ b/drivers/net/wireless/iwlwifi/iwl-2000.c
@@ -51,10 +51,10 @@
51#define IWL135_UCODE_API_MAX 6 51#define IWL135_UCODE_API_MAX 6
52 52
53/* Oldest version we won't warn about */ 53/* Oldest version we won't warn about */
54#define IWL2030_UCODE_API_OK 5 54#define IWL2030_UCODE_API_OK 6
55#define IWL2000_UCODE_API_OK 5 55#define IWL2000_UCODE_API_OK 6
56#define IWL105_UCODE_API_OK 5 56#define IWL105_UCODE_API_OK 6
57#define IWL135_UCODE_API_OK 5 57#define IWL135_UCODE_API_OK 6
58 58
59/* Lowest firmware API version supported */ 59/* Lowest firmware API version supported */
60#define IWL2030_UCODE_API_MIN 5 60#define IWL2030_UCODE_API_MIN 5
@@ -328,7 +328,7 @@ const struct iwl_cfg iwl135_bgn_cfg = {
328 .ht_params = &iwl2000_ht_params, 328 .ht_params = &iwl2000_ht_params,
329}; 329};
330 330
331MODULE_FIRMWARE(IWL2000_MODULE_FIRMWARE(IWL2000_UCODE_API_MAX)); 331MODULE_FIRMWARE(IWL2000_MODULE_FIRMWARE(IWL2000_UCODE_API_OK));
332MODULE_FIRMWARE(IWL2030_MODULE_FIRMWARE(IWL2030_UCODE_API_MAX)); 332MODULE_FIRMWARE(IWL2030_MODULE_FIRMWARE(IWL2030_UCODE_API_OK));
333MODULE_FIRMWARE(IWL105_MODULE_FIRMWARE(IWL105_UCODE_API_MAX)); 333MODULE_FIRMWARE(IWL105_MODULE_FIRMWARE(IWL105_UCODE_API_OK));
334MODULE_FIRMWARE(IWL135_MODULE_FIRMWARE(IWL135_UCODE_API_MAX)); 334MODULE_FIRMWARE(IWL135_MODULE_FIRMWARE(IWL135_UCODE_API_OK));
diff --git a/drivers/net/wireless/iwlwifi/iwl-5000.c b/drivers/net/wireless/iwlwifi/iwl-5000.c
index a805e97b89af..de0920c74cdd 100644
--- a/drivers/net/wireless/iwlwifi/iwl-5000.c
+++ b/drivers/net/wireless/iwlwifi/iwl-5000.c
@@ -51,6 +51,10 @@
51#define IWL5000_UCODE_API_MAX 5 51#define IWL5000_UCODE_API_MAX 5
52#define IWL5150_UCODE_API_MAX 2 52#define IWL5150_UCODE_API_MAX 2
53 53
54/* Oldest version we won't warn about */
55#define IWL5000_UCODE_API_OK 5
56#define IWL5150_UCODE_API_OK 2
57
54/* Lowest firmware API version supported */ 58/* Lowest firmware API version supported */
55#define IWL5000_UCODE_API_MIN 1 59#define IWL5000_UCODE_API_MIN 1
56#define IWL5150_UCODE_API_MIN 1 60#define IWL5150_UCODE_API_MIN 1
@@ -326,6 +330,7 @@ static const struct iwl_ht_params iwl5000_ht_params = {
326#define IWL_DEVICE_5000 \ 330#define IWL_DEVICE_5000 \
327 .fw_name_pre = IWL5000_FW_PRE, \ 331 .fw_name_pre = IWL5000_FW_PRE, \
328 .ucode_api_max = IWL5000_UCODE_API_MAX, \ 332 .ucode_api_max = IWL5000_UCODE_API_MAX, \
333 .ucode_api_ok = IWL5000_UCODE_API_OK, \
329 .ucode_api_min = IWL5000_UCODE_API_MIN, \ 334 .ucode_api_min = IWL5000_UCODE_API_MIN, \
330 .max_inst_size = IWLAGN_RTC_INST_SIZE, \ 335 .max_inst_size = IWLAGN_RTC_INST_SIZE, \
331 .max_data_size = IWLAGN_RTC_DATA_SIZE, \ 336 .max_data_size = IWLAGN_RTC_DATA_SIZE, \
@@ -371,6 +376,7 @@ const struct iwl_cfg iwl5350_agn_cfg = {
371 .name = "Intel(R) WiMAX/WiFi Link 5350 AGN", 376 .name = "Intel(R) WiMAX/WiFi Link 5350 AGN",
372 .fw_name_pre = IWL5000_FW_PRE, 377 .fw_name_pre = IWL5000_FW_PRE,
373 .ucode_api_max = IWL5000_UCODE_API_MAX, 378 .ucode_api_max = IWL5000_UCODE_API_MAX,
379 .ucode_api_ok = IWL5000_UCODE_API_OK,
374 .ucode_api_min = IWL5000_UCODE_API_MIN, 380 .ucode_api_min = IWL5000_UCODE_API_MIN,
375 .max_inst_size = IWLAGN_RTC_INST_SIZE, 381 .max_inst_size = IWLAGN_RTC_INST_SIZE,
376 .max_data_size = IWLAGN_RTC_DATA_SIZE, 382 .max_data_size = IWLAGN_RTC_DATA_SIZE,
@@ -386,6 +392,7 @@ const struct iwl_cfg iwl5350_agn_cfg = {
386#define IWL_DEVICE_5150 \ 392#define IWL_DEVICE_5150 \
387 .fw_name_pre = IWL5150_FW_PRE, \ 393 .fw_name_pre = IWL5150_FW_PRE, \
388 .ucode_api_max = IWL5150_UCODE_API_MAX, \ 394 .ucode_api_max = IWL5150_UCODE_API_MAX, \
395 .ucode_api_ok = IWL5150_UCODE_API_OK, \
389 .ucode_api_min = IWL5150_UCODE_API_MIN, \ 396 .ucode_api_min = IWL5150_UCODE_API_MIN, \
390 .max_inst_size = IWLAGN_RTC_INST_SIZE, \ 397 .max_inst_size = IWLAGN_RTC_INST_SIZE, \
391 .max_data_size = IWLAGN_RTC_DATA_SIZE, \ 398 .max_data_size = IWLAGN_RTC_DATA_SIZE, \
@@ -409,5 +416,5 @@ const struct iwl_cfg iwl5150_abg_cfg = {
409 IWL_DEVICE_5150, 416 IWL_DEVICE_5150,
410}; 417};
411 418
412MODULE_FIRMWARE(IWL5000_MODULE_FIRMWARE(IWL5000_UCODE_API_MAX)); 419MODULE_FIRMWARE(IWL5000_MODULE_FIRMWARE(IWL5000_UCODE_API_OK));
413MODULE_FIRMWARE(IWL5150_MODULE_FIRMWARE(IWL5150_UCODE_API_MAX)); 420MODULE_FIRMWARE(IWL5150_MODULE_FIRMWARE(IWL5150_UCODE_API_OK));
diff --git a/drivers/net/wireless/iwlwifi/iwl-6000.c b/drivers/net/wireless/iwlwifi/iwl-6000.c
index 64060cd738b5..f0c91505a7f7 100644
--- a/drivers/net/wireless/iwlwifi/iwl-6000.c
+++ b/drivers/net/wireless/iwlwifi/iwl-6000.c
@@ -53,6 +53,8 @@
53/* Oldest version we won't warn about */ 53/* Oldest version we won't warn about */
54#define IWL6000_UCODE_API_OK 4 54#define IWL6000_UCODE_API_OK 4
55#define IWL6000G2_UCODE_API_OK 5 55#define IWL6000G2_UCODE_API_OK 5
56#define IWL6050_UCODE_API_OK 5
57#define IWL6000G2B_UCODE_API_OK 6
56 58
57/* Lowest firmware API version supported */ 59/* Lowest firmware API version supported */
58#define IWL6000_UCODE_API_MIN 4 60#define IWL6000_UCODE_API_MIN 4
@@ -388,7 +390,7 @@ const struct iwl_cfg iwl6005_2agn_mow2_cfg = {
388#define IWL_DEVICE_6030 \ 390#define IWL_DEVICE_6030 \
389 .fw_name_pre = IWL6030_FW_PRE, \ 391 .fw_name_pre = IWL6030_FW_PRE, \
390 .ucode_api_max = IWL6000G2_UCODE_API_MAX, \ 392 .ucode_api_max = IWL6000G2_UCODE_API_MAX, \
391 .ucode_api_ok = IWL6000G2_UCODE_API_OK, \ 393 .ucode_api_ok = IWL6000G2B_UCODE_API_OK, \
392 .ucode_api_min = IWL6000G2_UCODE_API_MIN, \ 394 .ucode_api_min = IWL6000G2_UCODE_API_MIN, \
393 .max_inst_size = IWL60_RTC_INST_SIZE, \ 395 .max_inst_size = IWL60_RTC_INST_SIZE, \
394 .max_data_size = IWL60_RTC_DATA_SIZE, \ 396 .max_data_size = IWL60_RTC_DATA_SIZE, \
@@ -557,6 +559,6 @@ const struct iwl_cfg iwl6000_3agn_cfg = {
557}; 559};
558 560
559MODULE_FIRMWARE(IWL6000_MODULE_FIRMWARE(IWL6000_UCODE_API_OK)); 561MODULE_FIRMWARE(IWL6000_MODULE_FIRMWARE(IWL6000_UCODE_API_OK));
560MODULE_FIRMWARE(IWL6050_MODULE_FIRMWARE(IWL6050_UCODE_API_MAX)); 562MODULE_FIRMWARE(IWL6050_MODULE_FIRMWARE(IWL6050_UCODE_API_OK));
561MODULE_FIRMWARE(IWL6005_MODULE_FIRMWARE(IWL6000G2_UCODE_API_MAX)); 563MODULE_FIRMWARE(IWL6005_MODULE_FIRMWARE(IWL6000G2_UCODE_API_OK));
562MODULE_FIRMWARE(IWL6030_MODULE_FIRMWARE(IWL6000G2_UCODE_API_MAX)); 564MODULE_FIRMWARE(IWL6030_MODULE_FIRMWARE(IWL6000G2B_UCODE_API_OK));
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-rs.c b/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
index 53f8c51cfcdb..7e590b349dd7 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
@@ -3083,11 +3083,6 @@ static void rs_free_sta(void *priv_r, struct ieee80211_sta *sta,
3083} 3083}
3084 3084
3085#ifdef CONFIG_MAC80211_DEBUGFS 3085#ifdef CONFIG_MAC80211_DEBUGFS
3086static int open_file_generic(struct inode *inode, struct file *file)
3087{
3088 file->private_data = inode->i_private;
3089 return 0;
3090}
3091static void rs_dbgfs_set_mcs(struct iwl_lq_sta *lq_sta, 3086static void rs_dbgfs_set_mcs(struct iwl_lq_sta *lq_sta,
3092 u32 *rate_n_flags, int index) 3087 u32 *rate_n_flags, int index)
3093{ 3088{
@@ -3226,7 +3221,7 @@ static ssize_t rs_sta_dbgfs_scale_table_read(struct file *file,
3226static const struct file_operations rs_sta_dbgfs_scale_table_ops = { 3221static const struct file_operations rs_sta_dbgfs_scale_table_ops = {
3227 .write = rs_sta_dbgfs_scale_table_write, 3222 .write = rs_sta_dbgfs_scale_table_write,
3228 .read = rs_sta_dbgfs_scale_table_read, 3223 .read = rs_sta_dbgfs_scale_table_read,
3229 .open = open_file_generic, 3224 .open = simple_open,
3230 .llseek = default_llseek, 3225 .llseek = default_llseek,
3231}; 3226};
3232static ssize_t rs_sta_dbgfs_stats_table_read(struct file *file, 3227static ssize_t rs_sta_dbgfs_stats_table_read(struct file *file,
@@ -3269,7 +3264,7 @@ static ssize_t rs_sta_dbgfs_stats_table_read(struct file *file,
3269 3264
3270static const struct file_operations rs_sta_dbgfs_stats_table_ops = { 3265static const struct file_operations rs_sta_dbgfs_stats_table_ops = {
3271 .read = rs_sta_dbgfs_stats_table_read, 3266 .read = rs_sta_dbgfs_stats_table_read,
3272 .open = open_file_generic, 3267 .open = simple_open,
3273 .llseek = default_llseek, 3268 .llseek = default_llseek,
3274}; 3269};
3275 3270
@@ -3295,7 +3290,7 @@ static ssize_t rs_sta_dbgfs_rate_scale_data_read(struct file *file,
3295 3290
3296static const struct file_operations rs_sta_dbgfs_rate_scale_data_ops = { 3291static const struct file_operations rs_sta_dbgfs_rate_scale_data_ops = {
3297 .read = rs_sta_dbgfs_rate_scale_data_read, 3292 .read = rs_sta_dbgfs_rate_scale_data_read,
3298 .open = open_file_generic, 3293 .open = simple_open,
3299 .llseek = default_llseek, 3294 .llseek = default_llseek,
3300}; 3295};
3301 3296
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-rx.c b/drivers/net/wireless/iwlwifi/iwl-agn-rx.c
index f4b84d1596e3..22474608a70b 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-rx.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-rx.c
@@ -773,8 +773,7 @@ static void iwlagn_pass_packet_to_mac80211(struct iwl_priv *priv,
773 struct sk_buff *skb; 773 struct sk_buff *skb;
774 __le16 fc = hdr->frame_control; 774 __le16 fc = hdr->frame_control;
775 struct iwl_rxon_context *ctx; 775 struct iwl_rxon_context *ctx;
776 struct page *p; 776 unsigned int hdrlen, fraglen;
777 int offset;
778 777
779 /* We only process data packets if the interface is open */ 778 /* We only process data packets if the interface is open */
780 if (unlikely(!priv->is_open)) { 779 if (unlikely(!priv->is_open)) {
@@ -788,16 +787,24 @@ static void iwlagn_pass_packet_to_mac80211(struct iwl_priv *priv,
788 iwlagn_set_decrypted_flag(priv, hdr, ampdu_status, stats)) 787 iwlagn_set_decrypted_flag(priv, hdr, ampdu_status, stats))
789 return; 788 return;
790 789
791 skb = dev_alloc_skb(128); 790 /* Dont use dev_alloc_skb(), we'll have enough headroom once
791 * ieee80211_hdr pulled.
792 */
793 skb = alloc_skb(128, GFP_ATOMIC);
792 if (!skb) { 794 if (!skb) {
793 IWL_ERR(priv, "dev_alloc_skb failed\n"); 795 IWL_ERR(priv, "alloc_skb failed\n");
794 return; 796 return;
795 } 797 }
798 hdrlen = min_t(unsigned int, len, skb_tailroom(skb));
799 memcpy(skb_put(skb, hdrlen), hdr, hdrlen);
800 fraglen = len - hdrlen;
796 801
797 offset = (void *)hdr - rxb_addr(rxb); 802 if (fraglen) {
798 p = rxb_steal_page(rxb); 803 int offset = (void *)hdr + hdrlen - rxb_addr(rxb);
799 skb_add_rx_frag(skb, 0, p, offset, len, len);
800 804
805 skb_add_rx_frag(skb, 0, rxb_steal_page(rxb), offset,
806 fraglen, rxb->truesize);
807 }
801 iwl_update_stats(priv, false, fc, len); 808 iwl_update_stats(priv, false, fc, len);
802 809
803 /* 810 /*
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn.c b/drivers/net/wireless/iwlwifi/iwl-agn.c
index f1226dbf789d..2a9a16f901c3 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn.c
@@ -863,7 +863,6 @@ static void iwl_bg_run_time_calib_work(struct work_struct *work)
863 863
864void iwlagn_prepare_restart(struct iwl_priv *priv) 864void iwlagn_prepare_restart(struct iwl_priv *priv)
865{ 865{
866 struct iwl_rxon_context *ctx;
867 bool bt_full_concurrent; 866 bool bt_full_concurrent;
868 u8 bt_ci_compliance; 867 u8 bt_ci_compliance;
869 u8 bt_load; 868 u8 bt_load;
@@ -872,8 +871,6 @@ void iwlagn_prepare_restart(struct iwl_priv *priv)
872 871
873 lockdep_assert_held(&priv->mutex); 872 lockdep_assert_held(&priv->mutex);
874 873
875 for_each_context(priv, ctx)
876 ctx->vif = NULL;
877 priv->is_open = 0; 874 priv->is_open = 0;
878 875
879 /* 876 /*
diff --git a/drivers/net/wireless/iwlwifi/iwl-debugfs.c b/drivers/net/wireless/iwlwifi/iwl-debugfs.c
index b7b1c04f2fba..2bbaebd99ad4 100644
--- a/drivers/net/wireless/iwlwifi/iwl-debugfs.c
+++ b/drivers/net/wireless/iwlwifi/iwl-debugfs.c
@@ -84,17 +84,11 @@ static ssize_t iwl_dbgfs_##name##_write(struct file *file, \
84 size_t count, loff_t *ppos); 84 size_t count, loff_t *ppos);
85 85
86 86
87static int iwl_dbgfs_open_file_generic(struct inode *inode, struct file *file)
88{
89 file->private_data = inode->i_private;
90 return 0;
91}
92
93#define DEBUGFS_READ_FILE_OPS(name) \ 87#define DEBUGFS_READ_FILE_OPS(name) \
94 DEBUGFS_READ_FUNC(name); \ 88 DEBUGFS_READ_FUNC(name); \
95static const struct file_operations iwl_dbgfs_##name##_ops = { \ 89static const struct file_operations iwl_dbgfs_##name##_ops = { \
96 .read = iwl_dbgfs_##name##_read, \ 90 .read = iwl_dbgfs_##name##_read, \
97 .open = iwl_dbgfs_open_file_generic, \ 91 .open = simple_open, \
98 .llseek = generic_file_llseek, \ 92 .llseek = generic_file_llseek, \
99}; 93};
100 94
@@ -102,7 +96,7 @@ static const struct file_operations iwl_dbgfs_##name##_ops = { \
102 DEBUGFS_WRITE_FUNC(name); \ 96 DEBUGFS_WRITE_FUNC(name); \
103static const struct file_operations iwl_dbgfs_##name##_ops = { \ 97static const struct file_operations iwl_dbgfs_##name##_ops = { \
104 .write = iwl_dbgfs_##name##_write, \ 98 .write = iwl_dbgfs_##name##_write, \
105 .open = iwl_dbgfs_open_file_generic, \ 99 .open = simple_open, \
106 .llseek = generic_file_llseek, \ 100 .llseek = generic_file_llseek, \
107}; 101};
108 102
@@ -113,7 +107,7 @@ static const struct file_operations iwl_dbgfs_##name##_ops = { \
113static const struct file_operations iwl_dbgfs_##name##_ops = { \ 107static const struct file_operations iwl_dbgfs_##name##_ops = { \
114 .write = iwl_dbgfs_##name##_write, \ 108 .write = iwl_dbgfs_##name##_write, \
115 .read = iwl_dbgfs_##name##_read, \ 109 .read = iwl_dbgfs_##name##_read, \
116 .open = iwl_dbgfs_open_file_generic, \ 110 .open = simple_open, \
117 .llseek = generic_file_llseek, \ 111 .llseek = generic_file_llseek, \
118}; 112};
119 113
diff --git a/drivers/net/wireless/iwlwifi/iwl-fh.h b/drivers/net/wireless/iwlwifi/iwl-fh.h
index 90208094b8eb..74bce97a8600 100644
--- a/drivers/net/wireless/iwlwifi/iwl-fh.h
+++ b/drivers/net/wireless/iwlwifi/iwl-fh.h
@@ -104,15 +104,29 @@
104 * (see struct iwl_tfd_frame). These 16 pointer registers are offset by 0x04 104 * (see struct iwl_tfd_frame). These 16 pointer registers are offset by 0x04
105 * bytes from one another. Each TFD circular buffer in DRAM must be 256-byte 105 * bytes from one another. Each TFD circular buffer in DRAM must be 256-byte
106 * aligned (address bits 0-7 must be 0). 106 * aligned (address bits 0-7 must be 0).
107 * Later devices have 20 (5000 series) or 30 (higher) queues, but the registers
108 * for them are in different places.
107 * 109 *
108 * Bit fields in each pointer register: 110 * Bit fields in each pointer register:
109 * 27-0: TFD CB physical base address [35:8], must be 256-byte aligned 111 * 27-0: TFD CB physical base address [35:8], must be 256-byte aligned
110 */ 112 */
111#define FH_MEM_CBBC_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0x9D0) 113#define FH_MEM_CBBC_0_15_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0x9D0)
112#define FH_MEM_CBBC_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xA10) 114#define FH_MEM_CBBC_0_15_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xA10)
113 115#define FH_MEM_CBBC_16_19_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0xBF0)
114/* Find TFD CB base pointer for given queue (range 0-15). */ 116#define FH_MEM_CBBC_16_19_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xC00)
115#define FH_MEM_CBBC_QUEUE(x) (FH_MEM_CBBC_LOWER_BOUND + (x) * 0x4) 117#define FH_MEM_CBBC_20_31_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0xB20)
118#define FH_MEM_CBBC_20_31_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xB80)
119
120/* Find TFD CB base pointer for given queue */
121static inline unsigned int FH_MEM_CBBC_QUEUE(unsigned int chnl)
122{
123 if (chnl < 16)
124 return FH_MEM_CBBC_0_15_LOWER_BOUND + 4 * chnl;
125 if (chnl < 20)
126 return FH_MEM_CBBC_16_19_LOWER_BOUND + 4 * (chnl - 16);
127 WARN_ON_ONCE(chnl >= 32);
128 return FH_MEM_CBBC_20_31_LOWER_BOUND + 4 * (chnl - 20);
129}
116 130
117 131
118/** 132/**
diff --git a/drivers/net/wireless/iwlwifi/iwl-mac80211.c b/drivers/net/wireless/iwlwifi/iwl-mac80211.c
index b6805f8e9a01..c24a7134a6f9 100644
--- a/drivers/net/wireless/iwlwifi/iwl-mac80211.c
+++ b/drivers/net/wireless/iwlwifi/iwl-mac80211.c
@@ -1244,6 +1244,7 @@ static int iwlagn_mac_add_interface(struct ieee80211_hw *hw,
1244 struct iwl_rxon_context *tmp, *ctx = NULL; 1244 struct iwl_rxon_context *tmp, *ctx = NULL;
1245 int err; 1245 int err;
1246 enum nl80211_iftype viftype = ieee80211_vif_type_p2p(vif); 1246 enum nl80211_iftype viftype = ieee80211_vif_type_p2p(vif);
1247 bool reset = false;
1247 1248
1248 IWL_DEBUG_MAC80211(priv, "enter: type %d, addr %pM\n", 1249 IWL_DEBUG_MAC80211(priv, "enter: type %d, addr %pM\n",
1249 viftype, vif->addr); 1250 viftype, vif->addr);
@@ -1265,6 +1266,13 @@ static int iwlagn_mac_add_interface(struct ieee80211_hw *hw,
1265 tmp->interface_modes | tmp->exclusive_interface_modes; 1266 tmp->interface_modes | tmp->exclusive_interface_modes;
1266 1267
1267 if (tmp->vif) { 1268 if (tmp->vif) {
1269 /* On reset we need to add the same interface again */
1270 if (tmp->vif == vif) {
1271 reset = true;
1272 ctx = tmp;
1273 break;
1274 }
1275
1268 /* check if this busy context is exclusive */ 1276 /* check if this busy context is exclusive */
1269 if (tmp->exclusive_interface_modes & 1277 if (tmp->exclusive_interface_modes &
1270 BIT(tmp->vif->type)) { 1278 BIT(tmp->vif->type)) {
@@ -1291,7 +1299,7 @@ static int iwlagn_mac_add_interface(struct ieee80211_hw *hw,
1291 ctx->vif = vif; 1299 ctx->vif = vif;
1292 1300
1293 err = iwl_setup_interface(priv, ctx); 1301 err = iwl_setup_interface(priv, ctx);
1294 if (!err) 1302 if (!err || reset)
1295 goto out; 1303 goto out;
1296 1304
1297 ctx->vif = NULL; 1305 ctx->vif = NULL;
diff --git a/drivers/net/wireless/iwlwifi/iwl-prph.h b/drivers/net/wireless/iwlwifi/iwl-prph.h
index 75dc20bd965b..3b1069290fa9 100644
--- a/drivers/net/wireless/iwlwifi/iwl-prph.h
+++ b/drivers/net/wireless/iwlwifi/iwl-prph.h
@@ -223,12 +223,33 @@
223#define SCD_AIT (SCD_BASE + 0x0c) 223#define SCD_AIT (SCD_BASE + 0x0c)
224#define SCD_TXFACT (SCD_BASE + 0x10) 224#define SCD_TXFACT (SCD_BASE + 0x10)
225#define SCD_ACTIVE (SCD_BASE + 0x14) 225#define SCD_ACTIVE (SCD_BASE + 0x14)
226#define SCD_QUEUE_WRPTR(x) (SCD_BASE + 0x18 + (x) * 4)
227#define SCD_QUEUE_RDPTR(x) (SCD_BASE + 0x68 + (x) * 4)
228#define SCD_QUEUECHAIN_SEL (SCD_BASE + 0xe8) 226#define SCD_QUEUECHAIN_SEL (SCD_BASE + 0xe8)
229#define SCD_AGGR_SEL (SCD_BASE + 0x248) 227#define SCD_AGGR_SEL (SCD_BASE + 0x248)
230#define SCD_INTERRUPT_MASK (SCD_BASE + 0x108) 228#define SCD_INTERRUPT_MASK (SCD_BASE + 0x108)
231#define SCD_QUEUE_STATUS_BITS(x) (SCD_BASE + 0x10c + (x) * 4) 229
230static inline unsigned int SCD_QUEUE_WRPTR(unsigned int chnl)
231{
232 if (chnl < 20)
233 return SCD_BASE + 0x18 + chnl * 4;
234 WARN_ON_ONCE(chnl >= 32);
235 return SCD_BASE + 0x284 + (chnl - 20) * 4;
236}
237
238static inline unsigned int SCD_QUEUE_RDPTR(unsigned int chnl)
239{
240 if (chnl < 20)
241 return SCD_BASE + 0x68 + chnl * 4;
242 WARN_ON_ONCE(chnl >= 32);
243 return SCD_BASE + 0x2B4 + (chnl - 20) * 4;
244}
245
246static inline unsigned int SCD_QUEUE_STATUS_BITS(unsigned int chnl)
247{
248 if (chnl < 20)
249 return SCD_BASE + 0x10c + chnl * 4;
250 WARN_ON_ONCE(chnl >= 32);
251 return SCD_BASE + 0x384 + (chnl - 20) * 4;
252}
232 253
233/*********************** END TX SCHEDULER *************************************/ 254/*********************** END TX SCHEDULER *************************************/
234 255
diff --git a/drivers/net/wireless/iwlwifi/iwl-trans-pcie-rx.c b/drivers/net/wireless/iwlwifi/iwl-trans-pcie-rx.c
index 8b1a7988e176..aa7aea168138 100644
--- a/drivers/net/wireless/iwlwifi/iwl-trans-pcie-rx.c
+++ b/drivers/net/wireless/iwlwifi/iwl-trans-pcie-rx.c
@@ -374,8 +374,9 @@ static void iwl_rx_handle_rxbuf(struct iwl_trans *trans,
374 if (WARN_ON(!rxb)) 374 if (WARN_ON(!rxb))
375 return; 375 return;
376 376
377 rxcb.truesize = PAGE_SIZE << hw_params(trans).rx_page_order;
377 dma_unmap_page(trans->dev, rxb->page_dma, 378 dma_unmap_page(trans->dev, rxb->page_dma,
378 PAGE_SIZE << hw_params(trans).rx_page_order, 379 rxcb.truesize,
379 DMA_FROM_DEVICE); 380 DMA_FROM_DEVICE);
380 381
381 rxcb._page = rxb->page; 382 rxcb._page = rxb->page;
diff --git a/drivers/net/wireless/iwlwifi/iwl-trans-pcie.c b/drivers/net/wireless/iwlwifi/iwl-trans-pcie.c
index b4f796c82e1e..4d7b30d3e648 100644
--- a/drivers/net/wireless/iwlwifi/iwl-trans-pcie.c
+++ b/drivers/net/wireless/iwlwifi/iwl-trans-pcie.c
@@ -1898,17 +1898,11 @@ static ssize_t iwl_dbgfs_##name##_write(struct file *file, \
1898 size_t count, loff_t *ppos); 1898 size_t count, loff_t *ppos);
1899 1899
1900 1900
1901static int iwl_dbgfs_open_file_generic(struct inode *inode, struct file *file)
1902{
1903 file->private_data = inode->i_private;
1904 return 0;
1905}
1906
1907#define DEBUGFS_READ_FILE_OPS(name) \ 1901#define DEBUGFS_READ_FILE_OPS(name) \
1908 DEBUGFS_READ_FUNC(name); \ 1902 DEBUGFS_READ_FUNC(name); \
1909static const struct file_operations iwl_dbgfs_##name##_ops = { \ 1903static const struct file_operations iwl_dbgfs_##name##_ops = { \
1910 .read = iwl_dbgfs_##name##_read, \ 1904 .read = iwl_dbgfs_##name##_read, \
1911 .open = iwl_dbgfs_open_file_generic, \ 1905 .open = simple_open, \
1912 .llseek = generic_file_llseek, \ 1906 .llseek = generic_file_llseek, \
1913}; 1907};
1914 1908
@@ -1916,7 +1910,7 @@ static const struct file_operations iwl_dbgfs_##name##_ops = { \
1916 DEBUGFS_WRITE_FUNC(name); \ 1910 DEBUGFS_WRITE_FUNC(name); \
1917static const struct file_operations iwl_dbgfs_##name##_ops = { \ 1911static const struct file_operations iwl_dbgfs_##name##_ops = { \
1918 .write = iwl_dbgfs_##name##_write, \ 1912 .write = iwl_dbgfs_##name##_write, \
1919 .open = iwl_dbgfs_open_file_generic, \ 1913 .open = simple_open, \
1920 .llseek = generic_file_llseek, \ 1914 .llseek = generic_file_llseek, \
1921}; 1915};
1922 1916
@@ -1926,7 +1920,7 @@ static const struct file_operations iwl_dbgfs_##name##_ops = { \
1926static const struct file_operations iwl_dbgfs_##name##_ops = { \ 1920static const struct file_operations iwl_dbgfs_##name##_ops = { \
1927 .write = iwl_dbgfs_##name##_write, \ 1921 .write = iwl_dbgfs_##name##_write, \
1928 .read = iwl_dbgfs_##name##_read, \ 1922 .read = iwl_dbgfs_##name##_read, \
1929 .open = iwl_dbgfs_open_file_generic, \ 1923 .open = simple_open, \
1930 .llseek = generic_file_llseek, \ 1924 .llseek = generic_file_llseek, \
1931}; 1925};
1932 1926
diff --git a/drivers/net/wireless/iwlwifi/iwl-trans.h b/drivers/net/wireless/iwlwifi/iwl-trans.h
index 0c81cbaa8088..fdf97886a5e4 100644
--- a/drivers/net/wireless/iwlwifi/iwl-trans.h
+++ b/drivers/net/wireless/iwlwifi/iwl-trans.h
@@ -260,6 +260,7 @@ static inline void iwl_free_resp(struct iwl_host_cmd *cmd)
260 260
261struct iwl_rx_cmd_buffer { 261struct iwl_rx_cmd_buffer {
262 struct page *_page; 262 struct page *_page;
263 unsigned int truesize;
263}; 264};
264 265
265static inline void *rxb_addr(struct iwl_rx_cmd_buffer *r) 266static inline void *rxb_addr(struct iwl_rx_cmd_buffer *r)
diff --git a/drivers/net/wireless/iwmc3200wifi/debugfs.c b/drivers/net/wireless/iwmc3200wifi/debugfs.c
index 87eef5773a02..b6199d124bb9 100644
--- a/drivers/net/wireless/iwmc3200wifi/debugfs.c
+++ b/drivers/net/wireless/iwmc3200wifi/debugfs.c
@@ -99,12 +99,6 @@ DEFINE_SIMPLE_ATTRIBUTE(fops_iwm_dbg_modules,
99 iwm_debugfs_u32_read, iwm_debugfs_dbg_modules_write, 99 iwm_debugfs_u32_read, iwm_debugfs_dbg_modules_write,
100 "%llu\n"); 100 "%llu\n");
101 101
102static int iwm_generic_open(struct inode *inode, struct file *filp)
103{
104 filp->private_data = inode->i_private;
105 return 0;
106}
107
108 102
109static ssize_t iwm_debugfs_txq_read(struct file *filp, char __user *buffer, 103static ssize_t iwm_debugfs_txq_read(struct file *filp, char __user *buffer,
110 size_t count, loff_t *ppos) 104 size_t count, loff_t *ppos)
@@ -401,28 +395,28 @@ out:
401 395
402static const struct file_operations iwm_debugfs_txq_fops = { 396static const struct file_operations iwm_debugfs_txq_fops = {
403 .owner = THIS_MODULE, 397 .owner = THIS_MODULE,
404 .open = iwm_generic_open, 398 .open = simple_open,
405 .read = iwm_debugfs_txq_read, 399 .read = iwm_debugfs_txq_read,
406 .llseek = default_llseek, 400 .llseek = default_llseek,
407}; 401};
408 402
409static const struct file_operations iwm_debugfs_tx_credit_fops = { 403static const struct file_operations iwm_debugfs_tx_credit_fops = {
410 .owner = THIS_MODULE, 404 .owner = THIS_MODULE,
411 .open = iwm_generic_open, 405 .open = simple_open,
412 .read = iwm_debugfs_tx_credit_read, 406 .read = iwm_debugfs_tx_credit_read,
413 .llseek = default_llseek, 407 .llseek = default_llseek,
414}; 408};
415 409
416static const struct file_operations iwm_debugfs_rx_ticket_fops = { 410static const struct file_operations iwm_debugfs_rx_ticket_fops = {
417 .owner = THIS_MODULE, 411 .owner = THIS_MODULE,
418 .open = iwm_generic_open, 412 .open = simple_open,
419 .read = iwm_debugfs_rx_ticket_read, 413 .read = iwm_debugfs_rx_ticket_read,
420 .llseek = default_llseek, 414 .llseek = default_llseek,
421}; 415};
422 416
423static const struct file_operations iwm_debugfs_fw_err_fops = { 417static const struct file_operations iwm_debugfs_fw_err_fops = {
424 .owner = THIS_MODULE, 418 .owner = THIS_MODULE,
425 .open = iwm_generic_open, 419 .open = simple_open,
426 .read = iwm_debugfs_fw_err_read, 420 .read = iwm_debugfs_fw_err_read,
427 .llseek = default_llseek, 421 .llseek = default_llseek,
428}; 422};
diff --git a/drivers/net/wireless/iwmc3200wifi/sdio.c b/drivers/net/wireless/iwmc3200wifi/sdio.c
index 764b40dd24ad..0042f204b07f 100644
--- a/drivers/net/wireless/iwmc3200wifi/sdio.c
+++ b/drivers/net/wireless/iwmc3200wifi/sdio.c
@@ -264,13 +264,6 @@ static int if_sdio_send_chunk(struct iwm_priv *iwm, u8 *buf, int count)
264 return ret; 264 return ret;
265} 265}
266 266
267/* debugfs hooks */
268static int iwm_debugfs_sdio_open(struct inode *inode, struct file *filp)
269{
270 filp->private_data = inode->i_private;
271 return 0;
272}
273
274static ssize_t iwm_debugfs_sdio_read(struct file *filp, char __user *buffer, 267static ssize_t iwm_debugfs_sdio_read(struct file *filp, char __user *buffer,
275 size_t count, loff_t *ppos) 268 size_t count, loff_t *ppos)
276{ 269{
@@ -363,7 +356,7 @@ err:
363 356
364static const struct file_operations iwm_debugfs_sdio_fops = { 357static const struct file_operations iwm_debugfs_sdio_fops = {
365 .owner = THIS_MODULE, 358 .owner = THIS_MODULE,
366 .open = iwm_debugfs_sdio_open, 359 .open = simple_open,
367 .read = iwm_debugfs_sdio_read, 360 .read = iwm_debugfs_sdio_read,
368 .llseek = default_llseek, 361 .llseek = default_llseek,
369}; 362};
diff --git a/drivers/net/wireless/libertas/cfg.c b/drivers/net/wireless/libertas/cfg.c
index 3fa1ecebadfd..2fa879b015b6 100644
--- a/drivers/net/wireless/libertas/cfg.c
+++ b/drivers/net/wireless/libertas/cfg.c
@@ -103,7 +103,7 @@ static const u32 cipher_suites[] = {
103 * Convert NL80211's auth_type to the one from Libertas, see chapter 5.9.1 103 * Convert NL80211's auth_type to the one from Libertas, see chapter 5.9.1
104 * in the firmware spec 104 * in the firmware spec
105 */ 105 */
106static u8 lbs_auth_to_authtype(enum nl80211_auth_type auth_type) 106static int lbs_auth_to_authtype(enum nl80211_auth_type auth_type)
107{ 107{
108 int ret = -ENOTSUPP; 108 int ret = -ENOTSUPP;
109 109
@@ -1411,7 +1411,12 @@ static int lbs_cfg_connect(struct wiphy *wiphy, struct net_device *dev,
1411 goto done; 1411 goto done;
1412 } 1412 }
1413 1413
1414 lbs_set_authtype(priv, sme); 1414 ret = lbs_set_authtype(priv, sme);
1415 if (ret == -ENOTSUPP) {
1416 wiphy_err(wiphy, "unsupported authtype 0x%x\n", sme->auth_type);
1417 goto done;
1418 }
1419
1415 lbs_set_radio(priv, preamble, 1); 1420 lbs_set_radio(priv, preamble, 1);
1416 1421
1417 /* Do the actual association */ 1422 /* Do the actual association */
diff --git a/drivers/net/wireless/libertas/debugfs.c b/drivers/net/wireless/libertas/debugfs.c
index c192671610fc..a06cc283e23d 100644
--- a/drivers/net/wireless/libertas/debugfs.c
+++ b/drivers/net/wireless/libertas/debugfs.c
@@ -21,12 +21,6 @@ static char *szStates[] = {
21static void lbs_debug_init(struct lbs_private *priv); 21static void lbs_debug_init(struct lbs_private *priv);
22#endif 22#endif
23 23
24static int open_file_generic(struct inode *inode, struct file *file)
25{
26 file->private_data = inode->i_private;
27 return 0;
28}
29
30static ssize_t write_file_dummy(struct file *file, const char __user *buf, 24static ssize_t write_file_dummy(struct file *file, const char __user *buf,
31 size_t count, loff_t *ppos) 25 size_t count, loff_t *ppos)
32{ 26{
@@ -696,7 +690,7 @@ out_unlock:
696 690
697#define FOPS(fread, fwrite) { \ 691#define FOPS(fread, fwrite) { \
698 .owner = THIS_MODULE, \ 692 .owner = THIS_MODULE, \
699 .open = open_file_generic, \ 693 .open = simple_open, \
700 .read = (fread), \ 694 .read = (fread), \
701 .write = (fwrite), \ 695 .write = (fwrite), \
702 .llseek = generic_file_llseek, \ 696 .llseek = generic_file_llseek, \
@@ -962,7 +956,7 @@ static ssize_t lbs_debugfs_write(struct file *f, const char __user *buf,
962 956
963static const struct file_operations lbs_debug_fops = { 957static const struct file_operations lbs_debug_fops = {
964 .owner = THIS_MODULE, 958 .owner = THIS_MODULE,
965 .open = open_file_generic, 959 .open = simple_open,
966 .write = lbs_debugfs_write, 960 .write = lbs_debugfs_write,
967 .read = lbs_debugfs_read, 961 .read = lbs_debugfs_read,
968 .llseek = default_llseek, 962 .llseek = default_llseek,
diff --git a/drivers/net/wireless/mwifiex/debugfs.c b/drivers/net/wireless/mwifiex/debugfs.c
index d26a78b6b3c4..1a845074c52a 100644
--- a/drivers/net/wireless/mwifiex/debugfs.c
+++ b/drivers/net/wireless/mwifiex/debugfs.c
@@ -140,18 +140,6 @@ static struct mwifiex_debug_data items[] = {
140static int num_of_items = ARRAY_SIZE(items); 140static int num_of_items = ARRAY_SIZE(items);
141 141
142/* 142/*
143 * Generic proc file open handler.
144 *
145 * This function is called every time a file is accessed for read or write.
146 */
147static int
148mwifiex_open_generic(struct inode *inode, struct file *file)
149{
150 file->private_data = inode->i_private;
151 return 0;
152}
153
154/*
155 * Proc info file read handler. 143 * Proc info file read handler.
156 * 144 *
157 * This function is called when the 'info' file is opened for reading. 145 * This function is called when the 'info' file is opened for reading.
@@ -676,19 +664,19 @@ done:
676static const struct file_operations mwifiex_dfs_##name##_fops = { \ 664static const struct file_operations mwifiex_dfs_##name##_fops = { \
677 .read = mwifiex_##name##_read, \ 665 .read = mwifiex_##name##_read, \
678 .write = mwifiex_##name##_write, \ 666 .write = mwifiex_##name##_write, \
679 .open = mwifiex_open_generic, \ 667 .open = simple_open, \
680}; 668};
681 669
682#define MWIFIEX_DFS_FILE_READ_OPS(name) \ 670#define MWIFIEX_DFS_FILE_READ_OPS(name) \
683static const struct file_operations mwifiex_dfs_##name##_fops = { \ 671static const struct file_operations mwifiex_dfs_##name##_fops = { \
684 .read = mwifiex_##name##_read, \ 672 .read = mwifiex_##name##_read, \
685 .open = mwifiex_open_generic, \ 673 .open = simple_open, \
686}; 674};
687 675
688#define MWIFIEX_DFS_FILE_WRITE_OPS(name) \ 676#define MWIFIEX_DFS_FILE_WRITE_OPS(name) \
689static const struct file_operations mwifiex_dfs_##name##_fops = { \ 677static const struct file_operations mwifiex_dfs_##name##_fops = { \
690 .write = mwifiex_##name##_write, \ 678 .write = mwifiex_##name##_write, \
691 .open = mwifiex_open_generic, \ 679 .open = simple_open, \
692}; 680};
693 681
694 682
diff --git a/drivers/net/wireless/mwifiex/pcie.h b/drivers/net/wireless/mwifiex/pcie.h
index 445ff21772e2..2f218f9a3fd3 100644
--- a/drivers/net/wireless/mwifiex/pcie.h
+++ b/drivers/net/wireless/mwifiex/pcie.h
@@ -48,15 +48,15 @@
48#define PCIE_HOST_INT_STATUS_MASK 0xC3C 48#define PCIE_HOST_INT_STATUS_MASK 0xC3C
49#define PCIE_SCRATCH_2_REG 0xC40 49#define PCIE_SCRATCH_2_REG 0xC40
50#define PCIE_SCRATCH_3_REG 0xC44 50#define PCIE_SCRATCH_3_REG 0xC44
51#define PCIE_SCRATCH_4_REG 0xCC0 51#define PCIE_SCRATCH_4_REG 0xCD0
52#define PCIE_SCRATCH_5_REG 0xCC4 52#define PCIE_SCRATCH_5_REG 0xCD4
53#define PCIE_SCRATCH_6_REG 0xCC8 53#define PCIE_SCRATCH_6_REG 0xCD8
54#define PCIE_SCRATCH_7_REG 0xCCC 54#define PCIE_SCRATCH_7_REG 0xCDC
55#define PCIE_SCRATCH_8_REG 0xCD0 55#define PCIE_SCRATCH_8_REG 0xCE0
56#define PCIE_SCRATCH_9_REG 0xCD4 56#define PCIE_SCRATCH_9_REG 0xCE4
57#define PCIE_SCRATCH_10_REG 0xCD8 57#define PCIE_SCRATCH_10_REG 0xCE8
58#define PCIE_SCRATCH_11_REG 0xCDC 58#define PCIE_SCRATCH_11_REG 0xCEC
59#define PCIE_SCRATCH_12_REG 0xCE0 59#define PCIE_SCRATCH_12_REG 0xCF0
60 60
61#define CPU_INTR_DNLD_RDY BIT(0) 61#define CPU_INTR_DNLD_RDY BIT(0)
62#define CPU_INTR_DOOR_BELL BIT(1) 62#define CPU_INTR_DOOR_BELL BIT(1)
diff --git a/drivers/net/wireless/orinoco/main.c b/drivers/net/wireless/orinoco/main.c
index dd6c64ac406e..88e3ad2d1db8 100644
--- a/drivers/net/wireless/orinoco/main.c
+++ b/drivers/net/wireless/orinoco/main.c
@@ -1336,6 +1336,10 @@ static void qbuf_scan(struct orinoco_private *priv, void *buf,
1336 unsigned long flags; 1336 unsigned long flags;
1337 1337
1338 sd = kmalloc(sizeof(*sd), GFP_ATOMIC); 1338 sd = kmalloc(sizeof(*sd), GFP_ATOMIC);
1339 if (!sd) {
1340 printk(KERN_ERR "%s: failed to alloc memory\n", __func__);
1341 return;
1342 }
1339 sd->buf = buf; 1343 sd->buf = buf;
1340 sd->len = len; 1344 sd->len = len;
1341 sd->type = type; 1345 sd->type = type;
@@ -1353,6 +1357,10 @@ static void qabort_scan(struct orinoco_private *priv)
1353 unsigned long flags; 1357 unsigned long flags;
1354 1358
1355 sd = kmalloc(sizeof(*sd), GFP_ATOMIC); 1359 sd = kmalloc(sizeof(*sd), GFP_ATOMIC);
1360 if (!sd) {
1361 printk(KERN_ERR "%s: failed to alloc memory\n", __func__);
1362 return;
1363 }
1356 sd->len = -1; /* Abort */ 1364 sd->len = -1; /* Abort */
1357 1365
1358 spin_lock_irqsave(&priv->scan_lock, flags); 1366 spin_lock_irqsave(&priv->scan_lock, flags);
diff --git a/drivers/net/wireless/rt2x00/rt2800usb.c b/drivers/net/wireless/rt2x00/rt2800usb.c
index cd490abced91..001735f7a661 100644
--- a/drivers/net/wireless/rt2x00/rt2800usb.c
+++ b/drivers/net/wireless/rt2x00/rt2800usb.c
@@ -163,7 +163,13 @@ static bool rt2800usb_tx_sta_fifo_read_completed(struct rt2x00_dev *rt2x00dev,
163 163
164 /* Reschedule urb to read TX status again instantly */ 164 /* Reschedule urb to read TX status again instantly */
165 return true; 165 return true;
166 } else if (rt2800usb_txstatus_pending(rt2x00dev)) { 166 }
167
168 /* Check if there is any entry that timedout waiting on TX status */
169 if (rt2800usb_txstatus_timeout(rt2x00dev))
170 queue_work(rt2x00dev->workqueue, &rt2x00dev->txdone_work);
171
172 if (rt2800usb_txstatus_pending(rt2x00dev)) {
167 /* Read register after 250 us */ 173 /* Read register after 250 us */
168 hrtimer_start(&rt2x00dev->txstatus_timer, ktime_set(0, 250000), 174 hrtimer_start(&rt2x00dev->txstatus_timer, ktime_set(0, 250000),
169 HRTIMER_MODE_REL); 175 HRTIMER_MODE_REL);
@@ -178,7 +184,7 @@ stop_reading:
178 * here again if status reading is needed. 184 * here again if status reading is needed.
179 */ 185 */
180 if (rt2800usb_txstatus_pending(rt2x00dev) && 186 if (rt2800usb_txstatus_pending(rt2x00dev) &&
181 test_and_set_bit(TX_STATUS_READING, &rt2x00dev->flags)) 187 !test_and_set_bit(TX_STATUS_READING, &rt2x00dev->flags))
182 return true; 188 return true;
183 else 189 else
184 return false; 190 return false;
diff --git a/drivers/net/wireless/rt2x00/rt2x00dev.c b/drivers/net/wireless/rt2x00/rt2x00dev.c
index fc9901e027c1..90cc5e772650 100644
--- a/drivers/net/wireless/rt2x00/rt2x00dev.c
+++ b/drivers/net/wireless/rt2x00/rt2x00dev.c
@@ -1062,11 +1062,6 @@ static int rt2x00lib_initialize(struct rt2x00_dev *rt2x00dev)
1062 1062
1063 set_bit(DEVICE_STATE_INITIALIZED, &rt2x00dev->flags); 1063 set_bit(DEVICE_STATE_INITIALIZED, &rt2x00dev->flags);
1064 1064
1065 /*
1066 * Register the extra components.
1067 */
1068 rt2x00rfkill_register(rt2x00dev);
1069
1070 return 0; 1065 return 0;
1071} 1066}
1072 1067
@@ -1210,6 +1205,7 @@ int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev)
1210 rt2x00link_register(rt2x00dev); 1205 rt2x00link_register(rt2x00dev);
1211 rt2x00leds_register(rt2x00dev); 1206 rt2x00leds_register(rt2x00dev);
1212 rt2x00debug_register(rt2x00dev); 1207 rt2x00debug_register(rt2x00dev);
1208 rt2x00rfkill_register(rt2x00dev);
1213 1209
1214 return 0; 1210 return 0;
1215 1211
diff --git a/drivers/net/wireless/rtlwifi/base.c b/drivers/net/wireless/rtlwifi/base.c
index 510023554e5f..e54488db0e10 100644
--- a/drivers/net/wireless/rtlwifi/base.c
+++ b/drivers/net/wireless/rtlwifi/base.c
@@ -838,7 +838,10 @@ void rtl_get_tcb_desc(struct ieee80211_hw *hw,
838 __le16 fc = hdr->frame_control; 838 __le16 fc = hdr->frame_control;
839 839
840 txrate = ieee80211_get_tx_rate(hw, info); 840 txrate = ieee80211_get_tx_rate(hw, info);
841 tcb_desc->hw_rate = txrate->hw_value; 841 if (txrate)
842 tcb_desc->hw_rate = txrate->hw_value;
843 else
844 tcb_desc->hw_rate = 0;
842 845
843 if (ieee80211_is_data(fc)) { 846 if (ieee80211_is_data(fc)) {
844 /* 847 /*
diff --git a/drivers/net/wireless/rtlwifi/pci.c b/drivers/net/wireless/rtlwifi/pci.c
index 07dd38efe62a..cc15fdb36060 100644
--- a/drivers/net/wireless/rtlwifi/pci.c
+++ b/drivers/net/wireless/rtlwifi/pci.c
@@ -912,8 +912,13 @@ static void _rtl_pci_prepare_bcn_tasklet(struct ieee80211_hw *hw)
912 memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc)); 912 memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc));
913 ring = &rtlpci->tx_ring[BEACON_QUEUE]; 913 ring = &rtlpci->tx_ring[BEACON_QUEUE];
914 pskb = __skb_dequeue(&ring->queue); 914 pskb = __skb_dequeue(&ring->queue);
915 if (pskb) 915 if (pskb) {
916 struct rtl_tx_desc *entry = &ring->desc[ring->idx];
917 pci_unmap_single(rtlpci->pdev, rtlpriv->cfg->ops->get_desc(
918 (u8 *) entry, true, HW_DESC_TXBUFF_ADDR),
919 pskb->len, PCI_DMA_TODEVICE);
916 kfree_skb(pskb); 920 kfree_skb(pskb);
921 }
917 922
918 /*NB: the beacon data buffer must be 32-bit aligned. */ 923 /*NB: the beacon data buffer must be 32-bit aligned. */
919 pskb = ieee80211_beacon_get(hw, mac->vif); 924 pskb = ieee80211_beacon_get(hw, mac->vif);
@@ -1936,6 +1941,7 @@ void rtl_pci_disconnect(struct pci_dev *pdev)
1936 rtl_deinit_deferred_work(hw); 1941 rtl_deinit_deferred_work(hw);
1937 rtlpriv->intf_ops->adapter_stop(hw); 1942 rtlpriv->intf_ops->adapter_stop(hw);
1938 } 1943 }
1944 rtlpriv->cfg->ops->disable_interrupt(hw);
1939 1945
1940 /*deinit rfkill */ 1946 /*deinit rfkill */
1941 rtl_deinit_rfkill(hw); 1947 rtl_deinit_rfkill(hw);
diff --git a/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.c b/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.c
index 1eec3a06d1f3..4c016241f340 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.c
@@ -1893,7 +1893,7 @@ void rtl92c_phy_set_io(struct ieee80211_hw *hw)
1893 break; 1893 break;
1894 case IO_CMD_PAUSE_DM_BY_SCAN: 1894 case IO_CMD_PAUSE_DM_BY_SCAN:
1895 rtlphy->initgain_backup.xaagccore1 = dm_digtable.cur_igvalue; 1895 rtlphy->initgain_backup.xaagccore1 = dm_digtable.cur_igvalue;
1896 dm_digtable.cur_igvalue = 0x17; 1896 dm_digtable.cur_igvalue = 0x37;
1897 rtl92c_dm_write_dig(hw); 1897 rtl92c_dm_write_dig(hw);
1898 break; 1898 break;
1899 default: 1899 default:
diff --git a/drivers/net/wireless/rtlwifi/rtl8192de/phy.c b/drivers/net/wireless/rtlwifi/rtl8192de/phy.c
index 34591eeb8376..28fc5fb8057b 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192de/phy.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192de/phy.c
@@ -3077,7 +3077,7 @@ static void rtl92d_phy_set_io(struct ieee80211_hw *hw)
3077 break; 3077 break;
3078 case IO_CMD_PAUSE_DM_BY_SCAN: 3078 case IO_CMD_PAUSE_DM_BY_SCAN:
3079 rtlphy->initgain_backup.xaagccore1 = de_digtable.cur_igvalue; 3079 rtlphy->initgain_backup.xaagccore1 = de_digtable.cur_igvalue;
3080 de_digtable.cur_igvalue = 0x17; 3080 de_digtable.cur_igvalue = 0x37;
3081 rtl92d_dm_write_dig(hw); 3081 rtl92d_dm_write_dig(hw);
3082 break; 3082 break;
3083 default: 3083 default:
diff --git a/drivers/net/wireless/rtlwifi/rtl8192de/sw.c b/drivers/net/wireless/rtlwifi/rtl8192de/sw.c
index 4898c502974d..480862c07f92 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192de/sw.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192de/sw.c
@@ -91,7 +91,6 @@ static int rtl92d_init_sw_vars(struct ieee80211_hw *hw)
91 u8 tid; 91 u8 tid;
92 struct rtl_priv *rtlpriv = rtl_priv(hw); 92 struct rtl_priv *rtlpriv = rtl_priv(hw);
93 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); 93 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
94 static int header_print;
95 94
96 rtlpriv->dm.dm_initialgain_enable = true; 95 rtlpriv->dm.dm_initialgain_enable = true;
97 rtlpriv->dm.dm_flag = 0; 96 rtlpriv->dm.dm_flag = 0;
@@ -171,10 +170,6 @@ static int rtl92d_init_sw_vars(struct ieee80211_hw *hw)
171 for (tid = 0; tid < 8; tid++) 170 for (tid = 0; tid < 8; tid++)
172 skb_queue_head_init(&rtlpriv->mac80211.skb_waitq[tid]); 171 skb_queue_head_init(&rtlpriv->mac80211.skb_waitq[tid]);
173 172
174 /* Only load firmware for first MAC */
175 if (header_print)
176 return 0;
177
178 /* for firmware buf */ 173 /* for firmware buf */
179 rtlpriv->rtlhal.pfirmware = vzalloc(0x8000); 174 rtlpriv->rtlhal.pfirmware = vzalloc(0x8000);
180 if (!rtlpriv->rtlhal.pfirmware) { 175 if (!rtlpriv->rtlhal.pfirmware) {
@@ -186,7 +181,6 @@ static int rtl92d_init_sw_vars(struct ieee80211_hw *hw)
186 rtlpriv->max_fw_size = 0x8000; 181 rtlpriv->max_fw_size = 0x8000;
187 pr_info("Driver for Realtek RTL8192DE WLAN interface\n"); 182 pr_info("Driver for Realtek RTL8192DE WLAN interface\n");
188 pr_info("Loading firmware file %s\n", rtlpriv->cfg->fw_name); 183 pr_info("Loading firmware file %s\n", rtlpriv->cfg->fw_name);
189 header_print++;
190 184
191 /* request fw */ 185 /* request fw */
192 err = request_firmware_nowait(THIS_MODULE, 1, rtlpriv->cfg->fw_name, 186 err = request_firmware_nowait(THIS_MODULE, 1, rtlpriv->cfg->fw_name,
diff --git a/drivers/net/wireless/rtlwifi/usb.c b/drivers/net/wireless/rtlwifi/usb.c
index 2e1e352864bb..d04dbda13f5a 100644
--- a/drivers/net/wireless/rtlwifi/usb.c
+++ b/drivers/net/wireless/rtlwifi/usb.c
@@ -124,46 +124,38 @@ static int _usbctrl_vendorreq_sync_read(struct usb_device *udev, u8 request,
124 return status; 124 return status;
125} 125}
126 126
127static u32 _usb_read_sync(struct usb_device *udev, u32 addr, u16 len) 127static u32 _usb_read_sync(struct rtl_priv *rtlpriv, u32 addr, u16 len)
128{ 128{
129 struct device *dev = rtlpriv->io.dev;
130 struct usb_device *udev = to_usb_device(dev);
129 u8 request; 131 u8 request;
130 u16 wvalue; 132 u16 wvalue;
131 u16 index; 133 u16 index;
132 u32 *data; 134 __le32 *data = &rtlpriv->usb_data[rtlpriv->usb_data_index];
133 u32 ret;
134 135
135 data = kmalloc(sizeof(u32), GFP_KERNEL);
136 if (!data)
137 return -ENOMEM;
138 request = REALTEK_USB_VENQT_CMD_REQ; 136 request = REALTEK_USB_VENQT_CMD_REQ;
139 index = REALTEK_USB_VENQT_CMD_IDX; /* n/a */ 137 index = REALTEK_USB_VENQT_CMD_IDX; /* n/a */
140 138
141 wvalue = (u16)addr; 139 wvalue = (u16)addr;
142 _usbctrl_vendorreq_sync_read(udev, request, wvalue, index, data, len); 140 _usbctrl_vendorreq_sync_read(udev, request, wvalue, index, data, len);
143 ret = le32_to_cpu(*data); 141 if (++rtlpriv->usb_data_index >= RTL_USB_MAX_RX_COUNT)
144 kfree(data); 142 rtlpriv->usb_data_index = 0;
145 return ret; 143 return le32_to_cpu(*data);
146} 144}
147 145
148static u8 _usb_read8_sync(struct rtl_priv *rtlpriv, u32 addr) 146static u8 _usb_read8_sync(struct rtl_priv *rtlpriv, u32 addr)
149{ 147{
150 struct device *dev = rtlpriv->io.dev; 148 return (u8)_usb_read_sync(rtlpriv, addr, 1);
151
152 return (u8)_usb_read_sync(to_usb_device(dev), addr, 1);
153} 149}
154 150
155static u16 _usb_read16_sync(struct rtl_priv *rtlpriv, u32 addr) 151static u16 _usb_read16_sync(struct rtl_priv *rtlpriv, u32 addr)
156{ 152{
157 struct device *dev = rtlpriv->io.dev; 153 return (u16)_usb_read_sync(rtlpriv, addr, 2);
158
159 return (u16)_usb_read_sync(to_usb_device(dev), addr, 2);
160} 154}
161 155
162static u32 _usb_read32_sync(struct rtl_priv *rtlpriv, u32 addr) 156static u32 _usb_read32_sync(struct rtl_priv *rtlpriv, u32 addr)
163{ 157{
164 struct device *dev = rtlpriv->io.dev; 158 return _usb_read_sync(rtlpriv, addr, 4);
165
166 return _usb_read_sync(to_usb_device(dev), addr, 4);
167} 159}
168 160
169static void _usb_write_async(struct usb_device *udev, u32 addr, u32 val, 161static void _usb_write_async(struct usb_device *udev, u32 addr, u32 val,
@@ -955,6 +947,11 @@ int __devinit rtl_usb_probe(struct usb_interface *intf,
955 return -ENOMEM; 947 return -ENOMEM;
956 } 948 }
957 rtlpriv = hw->priv; 949 rtlpriv = hw->priv;
950 rtlpriv->usb_data = kzalloc(RTL_USB_MAX_RX_COUNT * sizeof(u32),
951 GFP_KERNEL);
952 if (!rtlpriv->usb_data)
953 return -ENOMEM;
954 rtlpriv->usb_data_index = 0;
958 init_completion(&rtlpriv->firmware_loading_complete); 955 init_completion(&rtlpriv->firmware_loading_complete);
959 SET_IEEE80211_DEV(hw, &intf->dev); 956 SET_IEEE80211_DEV(hw, &intf->dev);
960 udev = interface_to_usbdev(intf); 957 udev = interface_to_usbdev(intf);
@@ -1025,6 +1022,7 @@ void rtl_usb_disconnect(struct usb_interface *intf)
1025 /* rtl_deinit_rfkill(hw); */ 1022 /* rtl_deinit_rfkill(hw); */
1026 rtl_usb_deinit(hw); 1023 rtl_usb_deinit(hw);
1027 rtl_deinit_core(hw); 1024 rtl_deinit_core(hw);
1025 kfree(rtlpriv->usb_data);
1028 rtlpriv->cfg->ops->deinit_sw_leds(hw); 1026 rtlpriv->cfg->ops->deinit_sw_leds(hw);
1029 rtlpriv->cfg->ops->deinit_sw_vars(hw); 1027 rtlpriv->cfg->ops->deinit_sw_vars(hw);
1030 _rtl_usb_io_handler_release(hw); 1028 _rtl_usb_io_handler_release(hw);
diff --git a/drivers/net/wireless/rtlwifi/wifi.h b/drivers/net/wireless/rtlwifi/wifi.h
index b591614c3b9b..28ebc69218a3 100644
--- a/drivers/net/wireless/rtlwifi/wifi.h
+++ b/drivers/net/wireless/rtlwifi/wifi.h
@@ -67,7 +67,7 @@
67#define QOS_QUEUE_NUM 4 67#define QOS_QUEUE_NUM 4
68#define RTL_MAC80211_NUM_QUEUE 5 68#define RTL_MAC80211_NUM_QUEUE 5
69#define REALTEK_USB_VENQT_MAX_BUF_SIZE 254 69#define REALTEK_USB_VENQT_MAX_BUF_SIZE 254
70 70#define RTL_USB_MAX_RX_COUNT 100
71#define QBSS_LOAD_SIZE 5 71#define QBSS_LOAD_SIZE 5
72#define MAX_WMMELE_LENGTH 64 72#define MAX_WMMELE_LENGTH 64
73 73
@@ -1629,6 +1629,10 @@ struct rtl_priv {
1629 interface or hardware */ 1629 interface or hardware */
1630 unsigned long status; 1630 unsigned long status;
1631 1631
1632 /* data buffer pointer for USB reads */
1633 __le32 *usb_data;
1634 int usb_data_index;
1635
1632 /*This must be the last item so 1636 /*This must be the last item so
1633 that it points to the data allocated 1637 that it points to the data allocated
1634 beyond this structure like: 1638 beyond this structure like:
diff --git a/drivers/net/wireless/wl1251/debugfs.c b/drivers/net/wireless/wl1251/debugfs.c
index 6c274007d200..448da1f8c22f 100644
--- a/drivers/net/wireless/wl1251/debugfs.c
+++ b/drivers/net/wireless/wl1251/debugfs.c
@@ -47,7 +47,7 @@ static ssize_t name## _read(struct file *file, char __user *userbuf, \
47 \ 47 \
48static const struct file_operations name## _ops = { \ 48static const struct file_operations name## _ops = { \
49 .read = name## _read, \ 49 .read = name## _read, \
50 .open = wl1251_open_file_generic, \ 50 .open = simple_open, \
51 .llseek = generic_file_llseek, \ 51 .llseek = generic_file_llseek, \
52}; 52};
53 53
@@ -84,7 +84,7 @@ static ssize_t sub## _ ##name## _read(struct file *file, \
84 \ 84 \
85static const struct file_operations sub## _ ##name## _ops = { \ 85static const struct file_operations sub## _ ##name## _ops = { \
86 .read = sub## _ ##name## _read, \ 86 .read = sub## _ ##name## _read, \
87 .open = wl1251_open_file_generic, \ 87 .open = simple_open, \
88 .llseek = generic_file_llseek, \ 88 .llseek = generic_file_llseek, \
89}; 89};
90 90
@@ -117,12 +117,6 @@ out:
117 mutex_unlock(&wl->mutex); 117 mutex_unlock(&wl->mutex);
118} 118}
119 119
120static int wl1251_open_file_generic(struct inode *inode, struct file *file)
121{
122 file->private_data = inode->i_private;
123 return 0;
124}
125
126DEBUGFS_FWSTATS_FILE(tx, internal_desc_overflow, 20, "%u"); 120DEBUGFS_FWSTATS_FILE(tx, internal_desc_overflow, 20, "%u");
127 121
128DEBUGFS_FWSTATS_FILE(rx, out_of_mem, 20, "%u"); 122DEBUGFS_FWSTATS_FILE(rx, out_of_mem, 20, "%u");
@@ -235,7 +229,7 @@ static ssize_t tx_queue_len_read(struct file *file, char __user *userbuf,
235 229
236static const struct file_operations tx_queue_len_ops = { 230static const struct file_operations tx_queue_len_ops = {
237 .read = tx_queue_len_read, 231 .read = tx_queue_len_read,
238 .open = wl1251_open_file_generic, 232 .open = simple_open,
239 .llseek = generic_file_llseek, 233 .llseek = generic_file_llseek,
240}; 234};
241 235
@@ -257,7 +251,7 @@ static ssize_t tx_queue_status_read(struct file *file, char __user *userbuf,
257 251
258static const struct file_operations tx_queue_status_ops = { 252static const struct file_operations tx_queue_status_ops = {
259 .read = tx_queue_status_read, 253 .read = tx_queue_status_read,
260 .open = wl1251_open_file_generic, 254 .open = simple_open,
261 .llseek = generic_file_llseek, 255 .llseek = generic_file_llseek,
262}; 256};
263 257
diff --git a/drivers/net/wireless/wl1251/main.c b/drivers/net/wireless/wl1251/main.c
index 41302c7b1ad0..d1afb8e3b2ef 100644
--- a/drivers/net/wireless/wl1251/main.c
+++ b/drivers/net/wireless/wl1251/main.c
@@ -479,6 +479,7 @@ static void wl1251_op_stop(struct ieee80211_hw *hw)
479 cancel_work_sync(&wl->irq_work); 479 cancel_work_sync(&wl->irq_work);
480 cancel_work_sync(&wl->tx_work); 480 cancel_work_sync(&wl->tx_work);
481 cancel_work_sync(&wl->filter_work); 481 cancel_work_sync(&wl->filter_work);
482 cancel_delayed_work_sync(&wl->elp_work);
482 483
483 mutex_lock(&wl->mutex); 484 mutex_lock(&wl->mutex);
484 485
diff --git a/drivers/net/wireless/wl1251/sdio.c b/drivers/net/wireless/wl1251/sdio.c
index f78694295c39..1b851f650e07 100644
--- a/drivers/net/wireless/wl1251/sdio.c
+++ b/drivers/net/wireless/wl1251/sdio.c
@@ -315,8 +315,8 @@ static void __devexit wl1251_sdio_remove(struct sdio_func *func)
315 315
316 if (wl->irq) 316 if (wl->irq)
317 free_irq(wl->irq, wl); 317 free_irq(wl->irq, wl);
318 kfree(wl_sdio);
319 wl1251_free_hw(wl); 318 wl1251_free_hw(wl);
319 kfree(wl_sdio);
320 320
321 sdio_claim_host(func); 321 sdio_claim_host(func);
322 sdio_release_irq(func); 322 sdio_release_irq(func);
diff --git a/drivers/net/wireless/wl12xx/debugfs.c b/drivers/net/wireless/wl12xx/debugfs.c
index e1cf72765965..564d49575c94 100644
--- a/drivers/net/wireless/wl12xx/debugfs.c
+++ b/drivers/net/wireless/wl12xx/debugfs.c
@@ -63,7 +63,7 @@ static ssize_t name## _read(struct file *file, char __user *userbuf, \
63 \ 63 \
64static const struct file_operations name## _ops = { \ 64static const struct file_operations name## _ops = { \
65 .read = name## _read, \ 65 .read = name## _read, \
66 .open = wl1271_open_file_generic, \ 66 .open = simple_open, \
67 .llseek = generic_file_llseek, \ 67 .llseek = generic_file_llseek, \
68}; 68};
69 69
@@ -96,7 +96,7 @@ static ssize_t sub## _ ##name## _read(struct file *file, \
96 \ 96 \
97static const struct file_operations sub## _ ##name## _ops = { \ 97static const struct file_operations sub## _ ##name## _ops = { \
98 .read = sub## _ ##name## _read, \ 98 .read = sub## _ ##name## _read, \
99 .open = wl1271_open_file_generic, \ 99 .open = simple_open, \
100 .llseek = generic_file_llseek, \ 100 .llseek = generic_file_llseek, \
101}; 101};
102 102
@@ -126,12 +126,6 @@ out:
126 mutex_unlock(&wl->mutex); 126 mutex_unlock(&wl->mutex);
127} 127}
128 128
129static int wl1271_open_file_generic(struct inode *inode, struct file *file)
130{
131 file->private_data = inode->i_private;
132 return 0;
133}
134
135DEBUGFS_FWSTATS_FILE(tx, internal_desc_overflow, "%u"); 129DEBUGFS_FWSTATS_FILE(tx, internal_desc_overflow, "%u");
136 130
137DEBUGFS_FWSTATS_FILE(rx, out_of_mem, "%u"); 131DEBUGFS_FWSTATS_FILE(rx, out_of_mem, "%u");
@@ -243,7 +237,7 @@ static ssize_t tx_queue_len_read(struct file *file, char __user *userbuf,
243 237
244static const struct file_operations tx_queue_len_ops = { 238static const struct file_operations tx_queue_len_ops = {
245 .read = tx_queue_len_read, 239 .read = tx_queue_len_read,
246 .open = wl1271_open_file_generic, 240 .open = simple_open,
247 .llseek = default_llseek, 241 .llseek = default_llseek,
248}; 242};
249 243
@@ -289,7 +283,7 @@ static ssize_t gpio_power_write(struct file *file,
289static const struct file_operations gpio_power_ops = { 283static const struct file_operations gpio_power_ops = {
290 .read = gpio_power_read, 284 .read = gpio_power_read,
291 .write = gpio_power_write, 285 .write = gpio_power_write,
292 .open = wl1271_open_file_generic, 286 .open = simple_open,
293 .llseek = default_llseek, 287 .llseek = default_llseek,
294}; 288};
295 289
@@ -308,7 +302,7 @@ static ssize_t start_recovery_write(struct file *file,
308 302
309static const struct file_operations start_recovery_ops = { 303static const struct file_operations start_recovery_ops = {
310 .write = start_recovery_write, 304 .write = start_recovery_write,
311 .open = wl1271_open_file_generic, 305 .open = simple_open,
312 .llseek = default_llseek, 306 .llseek = default_llseek,
313}; 307};
314 308
@@ -372,7 +366,7 @@ out:
372static const struct file_operations dynamic_ps_timeout_ops = { 366static const struct file_operations dynamic_ps_timeout_ops = {
373 .read = dynamic_ps_timeout_read, 367 .read = dynamic_ps_timeout_read,
374 .write = dynamic_ps_timeout_write, 368 .write = dynamic_ps_timeout_write,
375 .open = wl1271_open_file_generic, 369 .open = simple_open,
376 .llseek = default_llseek, 370 .llseek = default_llseek,
377}; 371};
378 372
@@ -441,7 +435,7 @@ out:
441static const struct file_operations forced_ps_ops = { 435static const struct file_operations forced_ps_ops = {
442 .read = forced_ps_read, 436 .read = forced_ps_read,
443 .write = forced_ps_write, 437 .write = forced_ps_write,
444 .open = wl1271_open_file_generic, 438 .open = simple_open,
445 .llseek = default_llseek, 439 .llseek = default_llseek,
446}; 440};
447 441
@@ -483,7 +477,7 @@ static ssize_t split_scan_timeout_write(struct file *file,
483static const struct file_operations split_scan_timeout_ops = { 477static const struct file_operations split_scan_timeout_ops = {
484 .read = split_scan_timeout_read, 478 .read = split_scan_timeout_read,
485 .write = split_scan_timeout_write, 479 .write = split_scan_timeout_write,
486 .open = wl1271_open_file_generic, 480 .open = simple_open,
487 .llseek = default_llseek, 481 .llseek = default_llseek,
488}; 482};
489 483
@@ -566,7 +560,7 @@ static ssize_t driver_state_read(struct file *file, char __user *user_buf,
566 560
567static const struct file_operations driver_state_ops = { 561static const struct file_operations driver_state_ops = {
568 .read = driver_state_read, 562 .read = driver_state_read,
569 .open = wl1271_open_file_generic, 563 .open = simple_open,
570 .llseek = default_llseek, 564 .llseek = default_llseek,
571}; 565};
572 566
@@ -675,7 +669,7 @@ static ssize_t vifs_state_read(struct file *file, char __user *user_buf,
675 669
676static const struct file_operations vifs_state_ops = { 670static const struct file_operations vifs_state_ops = {
677 .read = vifs_state_read, 671 .read = vifs_state_read,
678 .open = wl1271_open_file_generic, 672 .open = simple_open,
679 .llseek = default_llseek, 673 .llseek = default_llseek,
680}; 674};
681 675
@@ -733,7 +727,7 @@ static ssize_t dtim_interval_write(struct file *file,
733static const struct file_operations dtim_interval_ops = { 727static const struct file_operations dtim_interval_ops = {
734 .read = dtim_interval_read, 728 .read = dtim_interval_read,
735 .write = dtim_interval_write, 729 .write = dtim_interval_write,
736 .open = wl1271_open_file_generic, 730 .open = simple_open,
737 .llseek = default_llseek, 731 .llseek = default_llseek,
738}; 732};
739 733
@@ -791,7 +785,7 @@ static ssize_t suspend_dtim_interval_write(struct file *file,
791static const struct file_operations suspend_dtim_interval_ops = { 785static const struct file_operations suspend_dtim_interval_ops = {
792 .read = suspend_dtim_interval_read, 786 .read = suspend_dtim_interval_read,
793 .write = suspend_dtim_interval_write, 787 .write = suspend_dtim_interval_write,
794 .open = wl1271_open_file_generic, 788 .open = simple_open,
795 .llseek = default_llseek, 789 .llseek = default_llseek,
796}; 790};
797 791
@@ -849,7 +843,7 @@ static ssize_t beacon_interval_write(struct file *file,
849static const struct file_operations beacon_interval_ops = { 843static const struct file_operations beacon_interval_ops = {
850 .read = beacon_interval_read, 844 .read = beacon_interval_read,
851 .write = beacon_interval_write, 845 .write = beacon_interval_write,
852 .open = wl1271_open_file_generic, 846 .open = simple_open,
853 .llseek = default_llseek, 847 .llseek = default_llseek,
854}; 848};
855 849
@@ -904,7 +898,7 @@ static ssize_t rx_streaming_interval_read(struct file *file,
904static const struct file_operations rx_streaming_interval_ops = { 898static const struct file_operations rx_streaming_interval_ops = {
905 .read = rx_streaming_interval_read, 899 .read = rx_streaming_interval_read,
906 .write = rx_streaming_interval_write, 900 .write = rx_streaming_interval_write,
907 .open = wl1271_open_file_generic, 901 .open = simple_open,
908 .llseek = default_llseek, 902 .llseek = default_llseek,
909}; 903};
910 904
@@ -959,7 +953,7 @@ static ssize_t rx_streaming_always_read(struct file *file,
959static const struct file_operations rx_streaming_always_ops = { 953static const struct file_operations rx_streaming_always_ops = {
960 .read = rx_streaming_always_read, 954 .read = rx_streaming_always_read,
961 .write = rx_streaming_always_write, 955 .write = rx_streaming_always_write,
962 .open = wl1271_open_file_generic, 956 .open = simple_open,
963 .llseek = default_llseek, 957 .llseek = default_llseek,
964}; 958};
965 959
@@ -1003,7 +997,7 @@ out:
1003 997
1004static const struct file_operations beacon_filtering_ops = { 998static const struct file_operations beacon_filtering_ops = {
1005 .write = beacon_filtering_write, 999 .write = beacon_filtering_write,
1006 .open = wl1271_open_file_generic, 1000 .open = simple_open,
1007 .llseek = default_llseek, 1001 .llseek = default_llseek,
1008}; 1002};
1009 1003
diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c
index 663b32c2e931..0ebbb1906c30 100644
--- a/drivers/net/xen-netfront.c
+++ b/drivers/net/xen-netfront.c
@@ -1965,7 +1965,7 @@ static int __init netif_init(void)
1965 if (xen_initial_domain()) 1965 if (xen_initial_domain())
1966 return 0; 1966 return 0;
1967 1967
1968 if (!xen_platform_pci_unplug) 1968 if (xen_hvm_domain() && !xen_platform_pci_unplug)
1969 return -ENODEV; 1969 return -ENODEV;
1970 1970
1971 printk(KERN_INFO "Initialising Xen virtual ethernet driver.\n"); 1971 printk(KERN_INFO "Initialising Xen virtual ethernet driver.\n");
diff --git a/drivers/of/gpio.c b/drivers/of/gpio.c
index bba81216b4db..bf984b6dc477 100644
--- a/drivers/of/gpio.c
+++ b/drivers/of/gpio.c
@@ -140,7 +140,7 @@ int of_gpio_simple_xlate(struct gpio_chip *gc,
140 if (WARN_ON(gpiospec->args_count < gc->of_gpio_n_cells)) 140 if (WARN_ON(gpiospec->args_count < gc->of_gpio_n_cells))
141 return -EINVAL; 141 return -EINVAL;
142 142
143 if (gpiospec->args[0] > gc->ngpio) 143 if (gpiospec->args[0] >= gc->ngpio)
144 return -EINVAL; 144 return -EINVAL;
145 145
146 if (flags) 146 if (flags)
diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
index ee8fd037bb53..849357c1045c 100644
--- a/drivers/oprofile/oprofilefs.c
+++ b/drivers/oprofile/oprofilefs.c
@@ -117,25 +117,17 @@ static ssize_t ulong_write_file(struct file *file, char const __user *buf, size_
117} 117}
118 118
119 119
120static int default_open(struct inode *inode, struct file *filp)
121{
122 if (inode->i_private)
123 filp->private_data = inode->i_private;
124 return 0;
125}
126
127
128static const struct file_operations ulong_fops = { 120static const struct file_operations ulong_fops = {
129 .read = ulong_read_file, 121 .read = ulong_read_file,
130 .write = ulong_write_file, 122 .write = ulong_write_file,
131 .open = default_open, 123 .open = simple_open,
132 .llseek = default_llseek, 124 .llseek = default_llseek,
133}; 125};
134 126
135 127
136static const struct file_operations ulong_ro_fops = { 128static const struct file_operations ulong_ro_fops = {
137 .read = ulong_read_file, 129 .read = ulong_read_file,
138 .open = default_open, 130 .open = simple_open,
139 .llseek = default_llseek, 131 .llseek = default_llseek,
140}; 132};
141 133
@@ -187,7 +179,7 @@ static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t coun
187 179
188static const struct file_operations atomic_ro_fops = { 180static const struct file_operations atomic_ro_fops = {
189 .read = atomic_read_file, 181 .read = atomic_read_file,
190 .open = default_open, 182 .open = simple_open,
191 .llseek = default_llseek, 183 .llseek = default_llseek,
192}; 184};
193 185
diff --git a/drivers/parisc/sba_iommu.c b/drivers/parisc/sba_iommu.c
index 8644d5372e7f..42cfcd9eb9aa 100644
--- a/drivers/parisc/sba_iommu.c
+++ b/drivers/parisc/sba_iommu.c
@@ -44,6 +44,7 @@
44#include <asm/ropes.h> 44#include <asm/ropes.h>
45#include <asm/mckinley.h> /* for proc_mckinley_root */ 45#include <asm/mckinley.h> /* for proc_mckinley_root */
46#include <asm/runway.h> /* for proc_runway_root */ 46#include <asm/runway.h> /* for proc_runway_root */
47#include <asm/page.h> /* for PAGE0 */
47#include <asm/pdc.h> /* for PDC_MODEL_* */ 48#include <asm/pdc.h> /* for PDC_MODEL_* */
48#include <asm/pdcpat.h> /* for is_pdc_pat() */ 49#include <asm/pdcpat.h> /* for is_pdc_pat() */
49#include <asm/parisc-device.h> 50#include <asm/parisc-device.h>
diff --git a/drivers/pci/Makefile b/drivers/pci/Makefile
index 083a49fee56a..165274c064bc 100644
--- a/drivers/pci/Makefile
+++ b/drivers/pci/Makefile
@@ -42,6 +42,7 @@ obj-$(CONFIG_UNICORE32) += setup-bus.o setup-irq.o
42obj-$(CONFIG_PARISC) += setup-bus.o 42obj-$(CONFIG_PARISC) += setup-bus.o
43obj-$(CONFIG_SUPERH) += setup-bus.o setup-irq.o 43obj-$(CONFIG_SUPERH) += setup-bus.o setup-irq.o
44obj-$(CONFIG_PPC) += setup-bus.o 44obj-$(CONFIG_PPC) += setup-bus.o
45obj-$(CONFIG_FRV) += setup-bus.o
45obj-$(CONFIG_MIPS) += setup-bus.o setup-irq.o 46obj-$(CONFIG_MIPS) += setup-bus.o setup-irq.o
46obj-$(CONFIG_X86_VISWS) += setup-irq.o 47obj-$(CONFIG_X86_VISWS) += setup-irq.o
47obj-$(CONFIG_MN10300) += setup-bus.o 48obj-$(CONFIG_MN10300) += setup-bus.o
diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c
index 0f150f271c2a..1929c0c63b75 100644
--- a/drivers/pci/pci-acpi.c
+++ b/drivers/pci/pci-acpi.c
@@ -200,7 +200,7 @@ static pci_power_t acpi_pci_choose_state(struct pci_dev *pdev)
200 return PCI_D1; 200 return PCI_D1;
201 case ACPI_STATE_D2: 201 case ACPI_STATE_D2:
202 return PCI_D2; 202 return PCI_D2;
203 case ACPI_STATE_D3: 203 case ACPI_STATE_D3_HOT:
204 return PCI_D3hot; 204 return PCI_D3hot;
205 case ACPI_STATE_D3_COLD: 205 case ACPI_STATE_D3_COLD:
206 return PCI_D3cold; 206 return PCI_D3cold;
@@ -223,7 +223,7 @@ static int acpi_pci_set_power_state(struct pci_dev *dev, pci_power_t state)
223 [PCI_D0] = ACPI_STATE_D0, 223 [PCI_D0] = ACPI_STATE_D0,
224 [PCI_D1] = ACPI_STATE_D1, 224 [PCI_D1] = ACPI_STATE_D1,
225 [PCI_D2] = ACPI_STATE_D2, 225 [PCI_D2] = ACPI_STATE_D2,
226 [PCI_D3hot] = ACPI_STATE_D3, 226 [PCI_D3hot] = ACPI_STATE_D3_HOT,
227 [PCI_D3cold] = ACPI_STATE_D3 227 [PCI_D3cold] = ACPI_STATE_D3
228 }; 228 };
229 int error = -EINVAL; 229 int error = -EINVAL;
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 815674415267..111569ccab43 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -967,16 +967,59 @@ pci_save_state(struct pci_dev *dev)
967 return 0; 967 return 0;
968} 968}
969 969
970static void pci_restore_config_dword(struct pci_dev *pdev, int offset,
971 u32 saved_val, int retry)
972{
973 u32 val;
974
975 pci_read_config_dword(pdev, offset, &val);
976 if (val == saved_val)
977 return;
978
979 for (;;) {
980 dev_dbg(&pdev->dev, "restoring config space at offset "
981 "%#x (was %#x, writing %#x)\n", offset, val, saved_val);
982 pci_write_config_dword(pdev, offset, saved_val);
983 if (retry-- <= 0)
984 return;
985
986 pci_read_config_dword(pdev, offset, &val);
987 if (val == saved_val)
988 return;
989
990 mdelay(1);
991 }
992}
993
994static void pci_restore_config_space_range(struct pci_dev *pdev,
995 int start, int end, int retry)
996{
997 int index;
998
999 for (index = end; index >= start; index--)
1000 pci_restore_config_dword(pdev, 4 * index,
1001 pdev->saved_config_space[index],
1002 retry);
1003}
1004
1005static void pci_restore_config_space(struct pci_dev *pdev)
1006{
1007 if (pdev->hdr_type == PCI_HEADER_TYPE_NORMAL) {
1008 pci_restore_config_space_range(pdev, 10, 15, 0);
1009 /* Restore BARs before the command register. */
1010 pci_restore_config_space_range(pdev, 4, 9, 10);
1011 pci_restore_config_space_range(pdev, 0, 3, 0);
1012 } else {
1013 pci_restore_config_space_range(pdev, 0, 15, 0);
1014 }
1015}
1016
970/** 1017/**
971 * pci_restore_state - Restore the saved state of a PCI device 1018 * pci_restore_state - Restore the saved state of a PCI device
972 * @dev: - PCI device that we're dealing with 1019 * @dev: - PCI device that we're dealing with
973 */ 1020 */
974void pci_restore_state(struct pci_dev *dev) 1021void pci_restore_state(struct pci_dev *dev)
975{ 1022{
976 int i;
977 u32 val;
978 int tries;
979
980 if (!dev->state_saved) 1023 if (!dev->state_saved)
981 return; 1024 return;
982 1025
@@ -984,24 +1027,8 @@ void pci_restore_state(struct pci_dev *dev)
984 pci_restore_pcie_state(dev); 1027 pci_restore_pcie_state(dev);
985 pci_restore_ats_state(dev); 1028 pci_restore_ats_state(dev);
986 1029
987 /* 1030 pci_restore_config_space(dev);
988 * The Base Address register should be programmed before the command 1031
989 * register(s)
990 */
991 for (i = 15; i >= 0; i--) {
992 pci_read_config_dword(dev, i * 4, &val);
993 tries = 10;
994 while (tries && val != dev->saved_config_space[i]) {
995 dev_dbg(&dev->dev, "restoring config "
996 "space at offset %#x (was %#x, writing %#x)\n",
997 i, val, (int)dev->saved_config_space[i]);
998 pci_write_config_dword(dev,i * 4,
999 dev->saved_config_space[i]);
1000 pci_read_config_dword(dev, i * 4, &val);
1001 mdelay(10);
1002 tries--;
1003 }
1004 }
1005 pci_restore_pcix_state(dev); 1032 pci_restore_pcix_state(dev);
1006 pci_restore_msi_state(dev); 1033 pci_restore_msi_state(dev);
1007 pci_restore_iov_state(dev); 1034 pci_restore_iov_state(dev);
diff --git a/drivers/pci/xen-pcifront.c b/drivers/pci/xen-pcifront.c
index fd00ff02ab4d..d6cc62cb4cf7 100644
--- a/drivers/pci/xen-pcifront.c
+++ b/drivers/pci/xen-pcifront.c
@@ -290,6 +290,7 @@ static int pci_frontend_enable_msix(struct pci_dev *dev,
290 } else { 290 } else {
291 printk(KERN_DEBUG "enable msix get value %x\n", 291 printk(KERN_DEBUG "enable msix get value %x\n",
292 op.value); 292 op.value);
293 err = op.value;
293 } 294 }
294 } else { 295 } else {
295 dev_err(&dev->dev, "enable msix get err %x\n", err); 296 dev_err(&dev->dev, "enable msix get err %x\n", err);
diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
index ec3b8cc188af..df6296c5f47b 100644
--- a/drivers/pinctrl/core.c
+++ b/drivers/pinctrl/core.c
@@ -908,10 +908,6 @@ static int pinctrl_groups_show(struct seq_file *s, void *what)
908 const struct pinctrl_ops *ops = pctldev->desc->pctlops; 908 const struct pinctrl_ops *ops = pctldev->desc->pctlops;
909 unsigned selector = 0; 909 unsigned selector = 0;
910 910
911 /* No grouping */
912 if (!ops)
913 return 0;
914
915 mutex_lock(&pinctrl_mutex); 911 mutex_lock(&pinctrl_mutex);
916 912
917 seq_puts(s, "registered pin groups:\n"); 913 seq_puts(s, "registered pin groups:\n");
@@ -1225,6 +1221,19 @@ static void pinctrl_remove_device_debugfs(struct pinctrl_dev *pctldev)
1225 1221
1226#endif 1222#endif
1227 1223
1224static int pinctrl_check_ops(struct pinctrl_dev *pctldev)
1225{
1226 const struct pinctrl_ops *ops = pctldev->desc->pctlops;
1227
1228 if (!ops ||
1229 !ops->list_groups ||
1230 !ops->get_group_name ||
1231 !ops->get_group_pins)
1232 return -EINVAL;
1233
1234 return 0;
1235}
1236
1228/** 1237/**
1229 * pinctrl_register() - register a pin controller device 1238 * pinctrl_register() - register a pin controller device
1230 * @pctldesc: descriptor for this pin controller 1239 * @pctldesc: descriptor for this pin controller
@@ -1256,6 +1265,14 @@ struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc,
1256 INIT_LIST_HEAD(&pctldev->gpio_ranges); 1265 INIT_LIST_HEAD(&pctldev->gpio_ranges);
1257 pctldev->dev = dev; 1266 pctldev->dev = dev;
1258 1267
1268 /* check core ops for sanity */
1269 ret = pinctrl_check_ops(pctldev);
1270 if (ret) {
1271 pr_err("%s pinctrl ops lacks necessary functions\n",
1272 pctldesc->name);
1273 goto out_err;
1274 }
1275
1259 /* If we're implementing pinmuxing, check the ops for sanity */ 1276 /* If we're implementing pinmuxing, check the ops for sanity */
1260 if (pctldesc->pmxops) { 1277 if (pctldesc->pmxops) {
1261 ret = pinmux_check_ops(pctldev); 1278 ret = pinmux_check_ops(pctldev);
diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c
index bc8384c6f3eb..639db4d0aa76 100644
--- a/drivers/platform/x86/acerhdf.c
+++ b/drivers/platform/x86/acerhdf.c
@@ -50,7 +50,7 @@
50 */ 50 */
51#undef START_IN_KERNEL_MODE 51#undef START_IN_KERNEL_MODE
52 52
53#define DRV_VER "0.5.24" 53#define DRV_VER "0.5.26"
54 54
55/* 55/*
56 * According to the Atom N270 datasheet, 56 * According to the Atom N270 datasheet,
@@ -83,8 +83,8 @@ static int kernelmode;
83#endif 83#endif
84 84
85static unsigned int interval = 10; 85static unsigned int interval = 10;
86static unsigned int fanon = 63000; 86static unsigned int fanon = 60000;
87static unsigned int fanoff = 58000; 87static unsigned int fanoff = 53000;
88static unsigned int verbose; 88static unsigned int verbose;
89static unsigned int fanstate = ACERHDF_FAN_AUTO; 89static unsigned int fanstate = ACERHDF_FAN_AUTO;
90static char force_bios[16]; 90static char force_bios[16];
@@ -150,6 +150,8 @@ static const struct bios_settings_t bios_tbl[] = {
150 {"Acer", "AOA150", "v0.3308", 0x55, 0x58, {0x20, 0x00} }, 150 {"Acer", "AOA150", "v0.3308", 0x55, 0x58, {0x20, 0x00} },
151 {"Acer", "AOA150", "v0.3309", 0x55, 0x58, {0x20, 0x00} }, 151 {"Acer", "AOA150", "v0.3309", 0x55, 0x58, {0x20, 0x00} },
152 {"Acer", "AOA150", "v0.3310", 0x55, 0x58, {0x20, 0x00} }, 152 {"Acer", "AOA150", "v0.3310", 0x55, 0x58, {0x20, 0x00} },
153 /* LT1005u */
154 {"Acer", "LT-10Q", "v0.3310", 0x55, 0x58, {0x20, 0x00} },
153 /* Acer 1410 */ 155 /* Acer 1410 */
154 {"Acer", "Aspire 1410", "v0.3108", 0x55, 0x58, {0x9e, 0x00} }, 156 {"Acer", "Aspire 1410", "v0.3108", 0x55, 0x58, {0x9e, 0x00} },
155 {"Acer", "Aspire 1410", "v0.3113", 0x55, 0x58, {0x9e, 0x00} }, 157 {"Acer", "Aspire 1410", "v0.3113", 0x55, 0x58, {0x9e, 0x00} },
@@ -161,6 +163,7 @@ static const struct bios_settings_t bios_tbl[] = {
161 {"Acer", "Aspire 1410", "v1.3303", 0x55, 0x58, {0x9e, 0x00} }, 163 {"Acer", "Aspire 1410", "v1.3303", 0x55, 0x58, {0x9e, 0x00} },
162 {"Acer", "Aspire 1410", "v1.3308", 0x55, 0x58, {0x9e, 0x00} }, 164 {"Acer", "Aspire 1410", "v1.3308", 0x55, 0x58, {0x9e, 0x00} },
163 {"Acer", "Aspire 1410", "v1.3310", 0x55, 0x58, {0x9e, 0x00} }, 165 {"Acer", "Aspire 1410", "v1.3310", 0x55, 0x58, {0x9e, 0x00} },
166 {"Acer", "Aspire 1410", "v1.3314", 0x55, 0x58, {0x9e, 0x00} },
164 /* Acer 1810xx */ 167 /* Acer 1810xx */
165 {"Acer", "Aspire 1810TZ", "v0.3108", 0x55, 0x58, {0x9e, 0x00} }, 168 {"Acer", "Aspire 1810TZ", "v0.3108", 0x55, 0x58, {0x9e, 0x00} },
166 {"Acer", "Aspire 1810T", "v0.3108", 0x55, 0x58, {0x9e, 0x00} }, 169 {"Acer", "Aspire 1810T", "v0.3108", 0x55, 0x58, {0x9e, 0x00} },
@@ -183,29 +186,44 @@ static const struct bios_settings_t bios_tbl[] = {
183 {"Acer", "Aspire 1810TZ", "v1.3310", 0x55, 0x58, {0x9e, 0x00} }, 186 {"Acer", "Aspire 1810TZ", "v1.3310", 0x55, 0x58, {0x9e, 0x00} },
184 {"Acer", "Aspire 1810T", "v1.3310", 0x55, 0x58, {0x9e, 0x00} }, 187 {"Acer", "Aspire 1810T", "v1.3310", 0x55, 0x58, {0x9e, 0x00} },
185 {"Acer", "Aspire 1810TZ", "v1.3314", 0x55, 0x58, {0x9e, 0x00} }, 188 {"Acer", "Aspire 1810TZ", "v1.3314", 0x55, 0x58, {0x9e, 0x00} },
189 {"Acer", "Aspire 1810T", "v1.3314", 0x55, 0x58, {0x9e, 0x00} },
186 /* Acer 531 */ 190 /* Acer 531 */
191 {"Acer", "AO531h", "v0.3104", 0x55, 0x58, {0x20, 0x00} },
187 {"Acer", "AO531h", "v0.3201", 0x55, 0x58, {0x20, 0x00} }, 192 {"Acer", "AO531h", "v0.3201", 0x55, 0x58, {0x20, 0x00} },
193 {"Acer", "AO531h", "v0.3304", 0x55, 0x58, {0x20, 0x00} },
194 /* Acer 751 */
195 {"Acer", "AO751h", "V0.3212", 0x55, 0x58, {0x21, 0x00} },
196 /* Acer 1825 */
197 {"Acer", "Aspire 1825PTZ", "V1.3118", 0x55, 0x58, {0x9e, 0x00} },
198 {"Acer", "Aspire 1825PTZ", "V1.3127", 0x55, 0x58, {0x9e, 0x00} },
199 /* Acer TravelMate 7730 */
200 {"Acer", "TravelMate 7730G", "v0.3509", 0x55, 0x58, {0xaf, 0x00} },
188 /* Gateway */ 201 /* Gateway */
189 {"Gateway", "AOA110", "v0.3103", 0x55, 0x58, {0x21, 0x00} }, 202 {"Gateway", "AOA110", "v0.3103", 0x55, 0x58, {0x21, 0x00} },
190 {"Gateway", "AOA150", "v0.3103", 0x55, 0x58, {0x20, 0x00} }, 203 {"Gateway", "AOA150", "v0.3103", 0x55, 0x58, {0x20, 0x00} },
191 {"Gateway", "LT31", "v1.3103", 0x55, 0x58, {0x9e, 0x00} }, 204 {"Gateway", "LT31", "v1.3103", 0x55, 0x58, {0x9e, 0x00} },
192 {"Gateway", "LT31", "v1.3201", 0x55, 0x58, {0x9e, 0x00} }, 205 {"Gateway", "LT31", "v1.3201", 0x55, 0x58, {0x9e, 0x00} },
193 {"Gateway", "LT31", "v1.3302", 0x55, 0x58, {0x9e, 0x00} }, 206 {"Gateway", "LT31", "v1.3302", 0x55, 0x58, {0x9e, 0x00} },
207 {"Gateway", "LT31", "v1.3303t", 0x55, 0x58, {0x9e, 0x00} },
194 /* Packard Bell */ 208 /* Packard Bell */
195 {"Packard Bell", "DOA150", "v0.3104", 0x55, 0x58, {0x21, 0x00} }, 209 {"Packard Bell", "DOA150", "v0.3104", 0x55, 0x58, {0x21, 0x00} },
196 {"Packard Bell", "DOA150", "v0.3105", 0x55, 0x58, {0x20, 0x00} }, 210 {"Packard Bell", "DOA150", "v0.3105", 0x55, 0x58, {0x20, 0x00} },
197 {"Packard Bell", "AOA110", "v0.3105", 0x55, 0x58, {0x21, 0x00} }, 211 {"Packard Bell", "AOA110", "v0.3105", 0x55, 0x58, {0x21, 0x00} },
198 {"Packard Bell", "AOA150", "v0.3105", 0x55, 0x58, {0x20, 0x00} }, 212 {"Packard Bell", "AOA150", "v0.3105", 0x55, 0x58, {0x20, 0x00} },
199 {"Packard Bell", "DOTMU", "v1.3303", 0x55, 0x58, {0x9e, 0x00} }, 213 {"Packard Bell", "ENBFT", "V1.3118", 0x55, 0x58, {0x9e, 0x00} },
200 {"Packard Bell", "DOTMU", "v0.3120", 0x55, 0x58, {0x9e, 0x00} }, 214 {"Packard Bell", "ENBFT", "V1.3127", 0x55, 0x58, {0x9e, 0x00} },
201 {"Packard Bell", "DOTMU", "v0.3108", 0x55, 0x58, {0x9e, 0x00} }, 215 {"Packard Bell", "DOTMU", "v1.3303", 0x55, 0x58, {0x9e, 0x00} },
202 {"Packard Bell", "DOTMU", "v0.3113", 0x55, 0x58, {0x9e, 0x00} }, 216 {"Packard Bell", "DOTMU", "v0.3120", 0x55, 0x58, {0x9e, 0x00} },
203 {"Packard Bell", "DOTMU", "v0.3115", 0x55, 0x58, {0x9e, 0x00} }, 217 {"Packard Bell", "DOTMU", "v0.3108", 0x55, 0x58, {0x9e, 0x00} },
204 {"Packard Bell", "DOTMU", "v0.3117", 0x55, 0x58, {0x9e, 0x00} }, 218 {"Packard Bell", "DOTMU", "v0.3113", 0x55, 0x58, {0x9e, 0x00} },
205 {"Packard Bell", "DOTMU", "v0.3119", 0x55, 0x58, {0x9e, 0x00} }, 219 {"Packard Bell", "DOTMU", "v0.3115", 0x55, 0x58, {0x9e, 0x00} },
206 {"Packard Bell", "DOTMU", "v1.3204", 0x55, 0x58, {0x9e, 0x00} }, 220 {"Packard Bell", "DOTMU", "v0.3117", 0x55, 0x58, {0x9e, 0x00} },
207 {"Packard Bell", "DOTMA", "v1.3201", 0x55, 0x58, {0x9e, 0x00} }, 221 {"Packard Bell", "DOTMU", "v0.3119", 0x55, 0x58, {0x9e, 0x00} },
208 {"Packard Bell", "DOTMA", "v1.3302", 0x55, 0x58, {0x9e, 0x00} }, 222 {"Packard Bell", "DOTMU", "v1.3204", 0x55, 0x58, {0x9e, 0x00} },
223 {"Packard Bell", "DOTMA", "v1.3201", 0x55, 0x58, {0x9e, 0x00} },
224 {"Packard Bell", "DOTMA", "v1.3302", 0x55, 0x58, {0x9e, 0x00} },
225 {"Packard Bell", "DOTMA", "v1.3303t", 0x55, 0x58, {0x9e, 0x00} },
226 {"Packard Bell", "DOTVR46", "v1.3308", 0x55, 0x58, {0x9e, 0x00} },
209 /* pewpew-terminator */ 227 /* pewpew-terminator */
210 {"", "", "", 0, 0, {0, 0} } 228 {"", "", "", 0, 0, {0, 0} }
211}; 229};
@@ -701,15 +719,20 @@ MODULE_LICENSE("GPL");
701MODULE_AUTHOR("Peter Feuerer"); 719MODULE_AUTHOR("Peter Feuerer");
702MODULE_DESCRIPTION("Aspire One temperature and fan driver"); 720MODULE_DESCRIPTION("Aspire One temperature and fan driver");
703MODULE_ALIAS("dmi:*:*Acer*:pnAOA*:"); 721MODULE_ALIAS("dmi:*:*Acer*:pnAOA*:");
722MODULE_ALIAS("dmi:*:*Acer*:pnAO751h*:");
704MODULE_ALIAS("dmi:*:*Acer*:pnAspire*1410*:"); 723MODULE_ALIAS("dmi:*:*Acer*:pnAspire*1410*:");
705MODULE_ALIAS("dmi:*:*Acer*:pnAspire*1810*:"); 724MODULE_ALIAS("dmi:*:*Acer*:pnAspire*1810*:");
725MODULE_ALIAS("dmi:*:*Acer*:pnAspire*1825PTZ:");
706MODULE_ALIAS("dmi:*:*Acer*:pnAO531*:"); 726MODULE_ALIAS("dmi:*:*Acer*:pnAO531*:");
727MODULE_ALIAS("dmi:*:*Acer*:TravelMate*7730G:");
707MODULE_ALIAS("dmi:*:*Gateway*:pnAOA*:"); 728MODULE_ALIAS("dmi:*:*Gateway*:pnAOA*:");
708MODULE_ALIAS("dmi:*:*Gateway*:pnLT31*:"); 729MODULE_ALIAS("dmi:*:*Gateway*:pnLT31*:");
709MODULE_ALIAS("dmi:*:*Packard*Bell*:pnAOA*:"); 730MODULE_ALIAS("dmi:*:*Packard*Bell*:pnAOA*:");
710MODULE_ALIAS("dmi:*:*Packard*Bell*:pnDOA*:"); 731MODULE_ALIAS("dmi:*:*Packard*Bell*:pnDOA*:");
711MODULE_ALIAS("dmi:*:*Packard*Bell*:pnDOTMU*:"); 732MODULE_ALIAS("dmi:*:*Packard*Bell*:pnDOTMU*:");
733MODULE_ALIAS("dmi:*:*Packard*Bell*:pnENBFT*:");
712MODULE_ALIAS("dmi:*:*Packard*Bell*:pnDOTMA*:"); 734MODULE_ALIAS("dmi:*:*Packard*Bell*:pnDOTMA*:");
735MODULE_ALIAS("dmi:*:*Packard*Bell*:pnDOTVR46*:");
713 736
714module_init(acerhdf_init); 737module_init(acerhdf_init);
715module_exit(acerhdf_exit); 738module_exit(acerhdf_exit);
diff --git a/drivers/platform/x86/dell-laptop.c b/drivers/platform/x86/dell-laptop.c
index a05fc9c955d8..e6c08ee8d46c 100644
--- a/drivers/platform/x86/dell-laptop.c
+++ b/drivers/platform/x86/dell-laptop.c
@@ -212,6 +212,7 @@ static struct dmi_system_id __devinitdata dell_quirks[] = {
212 }, 212 },
213 .driver_data = &quirk_dell_vostro_v130, 213 .driver_data = &quirk_dell_vostro_v130,
214 }, 214 },
215 { }
215}; 216};
216 217
217static struct calling_interface_buffer *buffer; 218static struct calling_interface_buffer *buffer;
diff --git a/drivers/platform/x86/intel_ips.c b/drivers/platform/x86/intel_ips.c
index f7ba316e0ed6..0ffdb3cde2bb 100644
--- a/drivers/platform/x86/intel_ips.c
+++ b/drivers/platform/x86/intel_ips.c
@@ -1565,7 +1565,7 @@ static int ips_probe(struct pci_dev *dev, const struct pci_device_id *id)
1565 ips->poll_turbo_status = true; 1565 ips->poll_turbo_status = true;
1566 1566
1567 if (!ips_get_i915_syms(ips)) { 1567 if (!ips_get_i915_syms(ips)) {
1568 dev_err(&dev->dev, "failed to get i915 symbols, graphics turbo disabled\n"); 1568 dev_info(&dev->dev, "failed to get i915 symbols, graphics turbo disabled until i915 loads\n");
1569 ips->gpu_turbo_enabled = false; 1569 ips->gpu_turbo_enabled = false;
1570 } else { 1570 } else {
1571 dev_dbg(&dev->dev, "graphics turbo enabled\n"); 1571 dev_dbg(&dev->dev, "graphics turbo enabled\n");
diff --git a/drivers/platform/x86/intel_mid_powerbtn.c b/drivers/platform/x86/intel_mid_powerbtn.c
index 0a3594c7e912..bcbad8452a6f 100644
--- a/drivers/platform/x86/intel_mid_powerbtn.c
+++ b/drivers/platform/x86/intel_mid_powerbtn.c
@@ -78,7 +78,7 @@ static int __devinit mfld_pb_probe(struct platform_device *pdev)
78 78
79 input_set_capability(input, EV_KEY, KEY_POWER); 79 input_set_capability(input, EV_KEY, KEY_POWER);
80 80
81 error = request_threaded_irq(irq, NULL, mfld_pb_isr, 0, 81 error = request_threaded_irq(irq, NULL, mfld_pb_isr, IRQF_NO_SUSPEND,
82 DRIVER_NAME, input); 82 DRIVER_NAME, input);
83 if (error) { 83 if (error) {
84 dev_err(&pdev->dev, "Unable to request irq %d for mfld power" 84 dev_err(&pdev->dev, "Unable to request irq %d for mfld power"
diff --git a/drivers/regulator/anatop-regulator.c b/drivers/regulator/anatop-regulator.c
index 17499a55113d..81fd606e47bc 100644
--- a/drivers/regulator/anatop-regulator.c
+++ b/drivers/regulator/anatop-regulator.c
@@ -138,9 +138,10 @@ static int __devinit anatop_regulator_probe(struct platform_device *pdev)
138 rdesc->type = REGULATOR_VOLTAGE; 138 rdesc->type = REGULATOR_VOLTAGE;
139 rdesc->owner = THIS_MODULE; 139 rdesc->owner = THIS_MODULE;
140 sreg->mfd = anatopmfd; 140 sreg->mfd = anatopmfd;
141 ret = of_property_read_u32(np, "reg", &sreg->control_reg); 141 ret = of_property_read_u32(np, "anatop-reg-offset",
142 &sreg->control_reg);
142 if (ret) { 143 if (ret) {
143 dev_err(dev, "no reg property set\n"); 144 dev_err(dev, "no anatop-reg-offset property set\n");
144 goto anatop_probe_end; 145 goto anatop_probe_end;
145 } 146 }
146 ret = of_property_read_u32(np, "anatop-vol-bit-width", 147 ret = of_property_read_u32(np, "anatop-vol-bit-width",
@@ -213,7 +214,7 @@ static struct of_device_id __devinitdata of_anatop_regulator_match_tbl[] = {
213 { /* end */ } 214 { /* end */ }
214}; 215};
215 216
216static struct platform_driver anatop_regulator = { 217static struct platform_driver anatop_regulator_driver = {
217 .driver = { 218 .driver = {
218 .name = "anatop_regulator", 219 .name = "anatop_regulator",
219 .owner = THIS_MODULE, 220 .owner = THIS_MODULE,
@@ -225,13 +226,13 @@ static struct platform_driver anatop_regulator = {
225 226
226static int __init anatop_regulator_init(void) 227static int __init anatop_regulator_init(void)
227{ 228{
228 return platform_driver_register(&anatop_regulator); 229 return platform_driver_register(&anatop_regulator_driver);
229} 230}
230postcore_initcall(anatop_regulator_init); 231postcore_initcall(anatop_regulator_init);
231 232
232static void __exit anatop_regulator_exit(void) 233static void __exit anatop_regulator_exit(void)
233{ 234{
234 platform_driver_unregister(&anatop_regulator); 235 platform_driver_unregister(&anatop_regulator_driver);
235} 236}
236module_exit(anatop_regulator_exit); 237module_exit(anatop_regulator_exit);
237 238
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index c056abd7562a..046fb1bd8619 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -1431,7 +1431,10 @@ void devm_regulator_put(struct regulator *regulator)
1431 1431
1432 rc = devres_destroy(regulator->dev, devm_regulator_release, 1432 rc = devres_destroy(regulator->dev, devm_regulator_release,
1433 devm_regulator_match, regulator); 1433 devm_regulator_match, regulator);
1434 WARN_ON(rc); 1434 if (rc == 0)
1435 regulator_put(regulator);
1436 else
1437 WARN_ON(rc);
1435} 1438}
1436EXPORT_SYMBOL_GPL(devm_regulator_put); 1439EXPORT_SYMBOL_GPL(devm_regulator_put);
1437 1440
@@ -2992,14 +2995,14 @@ void regulator_unregister(struct regulator_dev *rdev)
2992 if (rdev == NULL) 2995 if (rdev == NULL)
2993 return; 2996 return;
2994 2997
2998 if (rdev->supply)
2999 regulator_put(rdev->supply);
2995 mutex_lock(&regulator_list_mutex); 3000 mutex_lock(&regulator_list_mutex);
2996 debugfs_remove_recursive(rdev->debugfs); 3001 debugfs_remove_recursive(rdev->debugfs);
2997 flush_work_sync(&rdev->disable_work.work); 3002 flush_work_sync(&rdev->disable_work.work);
2998 WARN_ON(rdev->open_count); 3003 WARN_ON(rdev->open_count);
2999 unset_regulator_supplies(rdev); 3004 unset_regulator_supplies(rdev);
3000 list_del(&rdev->list); 3005 list_del(&rdev->list);
3001 if (rdev->supply)
3002 regulator_put(rdev->supply);
3003 kfree(rdev->constraints); 3006 kfree(rdev->constraints);
3004 device_unregister(&rdev->dev); 3007 device_unregister(&rdev->dev);
3005 mutex_unlock(&regulator_list_mutex); 3008 mutex_unlock(&regulator_list_mutex);
diff --git a/drivers/regulator/fixed-helper.c b/drivers/regulator/fixed-helper.c
index 30d0a15b8949..cacd33c9d042 100644
--- a/drivers/regulator/fixed-helper.c
+++ b/drivers/regulator/fixed-helper.c
@@ -18,7 +18,6 @@ static void regulator_fixed_release(struct device *dev)
18 18
19/** 19/**
20 * regulator_register_fixed - register a no-op fixed regulator 20 * regulator_register_fixed - register a no-op fixed regulator
21 * @name: supply name
22 * @id: platform device id 21 * @id: platform device id
23 * @supplies: consumers for this regulator 22 * @supplies: consumers for this regulator
24 * @num_supplies: number of consumers 23 * @num_supplies: number of consumers
@@ -32,7 +31,7 @@ struct platform_device *regulator_register_fixed(int id,
32 if (!data) 31 if (!data)
33 return NULL; 32 return NULL;
34 33
35 data->cfg.supply_name = "dummy"; 34 data->cfg.supply_name = "fixed-dummy";
36 data->cfg.microvolts = 0; 35 data->cfg.microvolts = 0;
37 data->cfg.gpio = -EINVAL; 36 data->cfg.gpio = -EINVAL;
38 data->cfg.enabled_at_boot = 1; 37 data->cfg.enabled_at_boot = 1;
diff --git a/drivers/regulator/max8997.c b/drivers/regulator/max8997.c
index 96579296f04d..17a58c56eebf 100644
--- a/drivers/regulator/max8997.c
+++ b/drivers/regulator/max8997.c
@@ -684,7 +684,7 @@ static int max8997_set_voltage_buck(struct regulator_dev *rdev,
684 } 684 }
685 685
686 new_val++; 686 new_val++;
687 } while (desc->min + desc->step + new_val <= desc->max); 687 } while (desc->min + desc->step * new_val <= desc->max);
688 688
689 new_idx = tmp_idx; 689 new_idx = tmp_idx;
690 new_val = tmp_val; 690 new_val = tmp_val;
diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
index e8cfc99dd8f0..845aa2263b8a 100644
--- a/drivers/regulator/mc13892-regulator.c
+++ b/drivers/regulator/mc13892-regulator.c
@@ -552,7 +552,7 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
552 mc13xxx_lock(mc13892); 552 mc13xxx_lock(mc13892);
553 ret = mc13xxx_reg_read(mc13892, MC13892_REVISION, &val); 553 ret = mc13xxx_reg_read(mc13892, MC13892_REVISION, &val);
554 if (ret) 554 if (ret)
555 goto err_free; 555 goto err_unlock;
556 556
557 /* enable switch auto mode */ 557 /* enable switch auto mode */
558 if ((val & 0x0000FFFF) == 0x45d0) { 558 if ((val & 0x0000FFFF) == 0x45d0) {
@@ -562,7 +562,7 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
562 MC13892_SWITCHERS4_SW1MODE_AUTO | 562 MC13892_SWITCHERS4_SW1MODE_AUTO |
563 MC13892_SWITCHERS4_SW2MODE_AUTO); 563 MC13892_SWITCHERS4_SW2MODE_AUTO);
564 if (ret) 564 if (ret)
565 goto err_free; 565 goto err_unlock;
566 566
567 ret = mc13xxx_reg_rmw(mc13892, MC13892_SWITCHERS5, 567 ret = mc13xxx_reg_rmw(mc13892, MC13892_SWITCHERS5,
568 MC13892_SWITCHERS5_SW3MODE_M | 568 MC13892_SWITCHERS5_SW3MODE_M |
@@ -570,7 +570,7 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
570 MC13892_SWITCHERS5_SW3MODE_AUTO | 570 MC13892_SWITCHERS5_SW3MODE_AUTO |
571 MC13892_SWITCHERS5_SW4MODE_AUTO); 571 MC13892_SWITCHERS5_SW4MODE_AUTO);
572 if (ret) 572 if (ret)
573 goto err_free; 573 goto err_unlock;
574 } 574 }
575 mc13xxx_unlock(mc13892); 575 mc13xxx_unlock(mc13892);
576 576
@@ -612,10 +612,10 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
612err: 612err:
613 while (--i >= 0) 613 while (--i >= 0)
614 regulator_unregister(priv->regulators[i]); 614 regulator_unregister(priv->regulators[i]);
615 return ret;
615 616
616err_free: 617err_unlock:
617 mc13xxx_unlock(mc13892); 618 mc13xxx_unlock(mc13892);
618
619 return ret; 619 return ret;
620} 620}
621 621
diff --git a/drivers/regulator/s5m8767.c b/drivers/regulator/s5m8767.c
index 58447db15de1..4ca2db059004 100644
--- a/drivers/regulator/s5m8767.c
+++ b/drivers/regulator/s5m8767.c
@@ -311,8 +311,7 @@ static int s5m8767_set_voltage(struct regulator_dev *rdev,
311 struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); 311 struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev);
312 const struct s5m_voltage_desc *desc; 312 const struct s5m_voltage_desc *desc;
313 int reg_id = rdev_get_id(rdev); 313 int reg_id = rdev_get_id(rdev);
314 int reg, mask, ret; 314 int sel, reg, mask, ret;
315 int i;
316 u8 val; 315 u8 val;
317 316
318 switch (reg_id) { 317 switch (reg_id) {
@@ -333,19 +332,20 @@ static int s5m8767_set_voltage(struct regulator_dev *rdev,
333 332
334 desc = reg_voltage_map[reg_id]; 333 desc = reg_voltage_map[reg_id];
335 334
336 i = s5m8767_convert_voltage_to_sel(desc, min_uV, max_uV); 335 sel = s5m8767_convert_voltage_to_sel(desc, min_uV, max_uV);
337 if (i < 0) 336 if (sel < 0)
338 return i; 337 return sel;
339 338
340 ret = s5m8767_get_voltage_register(rdev, &reg); 339 ret = s5m8767_get_voltage_register(rdev, &reg);
341 if (ret) 340 if (ret)
342 return ret; 341 return ret;
343 342
344 s5m_reg_read(s5m8767->iodev, reg, &val); 343 s5m_reg_read(s5m8767->iodev, reg, &val);
345 val = val & mask; 344 val &= ~mask;
345 val |= sel;
346 346
347 ret = s5m_reg_write(s5m8767->iodev, reg, val); 347 ret = s5m_reg_write(s5m8767->iodev, reg, val);
348 *selector = i; 348 *selector = sel;
349 349
350 return ret; 350 return ret;
351} 351}
diff --git a/drivers/regulator/tps6586x-regulator.c b/drivers/regulator/tps6586x-regulator.c
index 29b615ce3aff..cfc1f16f7771 100644
--- a/drivers/regulator/tps6586x-regulator.c
+++ b/drivers/regulator/tps6586x-regulator.c
@@ -79,6 +79,11 @@ static int tps6586x_ldo_list_voltage(struct regulator_dev *rdev,
79 unsigned selector) 79 unsigned selector)
80{ 80{
81 struct tps6586x_regulator *info = rdev_get_drvdata(rdev); 81 struct tps6586x_regulator *info = rdev_get_drvdata(rdev);
82 int rid = rdev_get_id(rdev);
83
84 /* LDO0 has minimal voltage 1.2V rather than 1.25V */
85 if ((rid == TPS6586X_ID_LDO_0) && (selector == 0))
86 return (info->voltages[0] - 50) * 1000;
82 87
83 return info->voltages[selector] * 1000; 88 return info->voltages[selector] * 1000;
84} 89}
diff --git a/drivers/regulator/wm831x-dcdc.c b/drivers/regulator/wm831x-dcdc.c
index 4904a40b0d46..ff810e787eac 100644
--- a/drivers/regulator/wm831x-dcdc.c
+++ b/drivers/regulator/wm831x-dcdc.c
@@ -380,13 +380,15 @@ static int wm831x_buckv_set_current_limit(struct regulator_dev *rdev,
380 int i; 380 int i;
381 381
382 for (i = 0; i < ARRAY_SIZE(wm831x_dcdc_ilim); i++) { 382 for (i = 0; i < ARRAY_SIZE(wm831x_dcdc_ilim); i++) {
383 if (max_uA <= wm831x_dcdc_ilim[i]) 383 if ((min_uA <= wm831x_dcdc_ilim[i]) &&
384 (wm831x_dcdc_ilim[i] <= max_uA))
384 break; 385 break;
385 } 386 }
386 if (i == ARRAY_SIZE(wm831x_dcdc_ilim)) 387 if (i == ARRAY_SIZE(wm831x_dcdc_ilim))
387 return -EINVAL; 388 return -EINVAL;
388 389
389 return wm831x_set_bits(wm831x, reg, WM831X_DC1_HC_THR_MASK, i); 390 return wm831x_set_bits(wm831x, reg, WM831X_DC1_HC_THR_MASK,
391 i << WM831X_DC1_HC_THR_SHIFT);
390} 392}
391 393
392static int wm831x_buckv_get_current_limit(struct regulator_dev *rdev) 394static int wm831x_buckv_get_current_limit(struct regulator_dev *rdev)
@@ -400,7 +402,8 @@ static int wm831x_buckv_get_current_limit(struct regulator_dev *rdev)
400 if (val < 0) 402 if (val < 0)
401 return val; 403 return val;
402 404
403 return wm831x_dcdc_ilim[val & WM831X_DC1_HC_THR_MASK]; 405 val = (val & WM831X_DC1_HC_THR_MASK) >> WM831X_DC1_HC_THR_SHIFT;
406 return wm831x_dcdc_ilim[val];
404} 407}
405 408
406static struct regulator_ops wm831x_buckv_ops = { 409static struct regulator_ops wm831x_buckv_ops = {
diff --git a/drivers/regulator/wm831x-isink.c b/drivers/regulator/wm831x-isink.c
index 634aac3f2d5f..b414e09c5620 100644
--- a/drivers/regulator/wm831x-isink.c
+++ b/drivers/regulator/wm831x-isink.c
@@ -101,7 +101,7 @@ static int wm831x_isink_set_current(struct regulator_dev *rdev,
101 101
102 for (i = 0; i < ARRAY_SIZE(wm831x_isinkv_values); i++) { 102 for (i = 0; i < ARRAY_SIZE(wm831x_isinkv_values); i++) {
103 int val = wm831x_isinkv_values[i]; 103 int val = wm831x_isinkv_values[i];
104 if (min_uA >= val && val <= max_uA) { 104 if (min_uA <= val && val <= max_uA) {
105 ret = wm831x_set_bits(wm831x, isink->reg, 105 ret = wm831x_set_bits(wm831x, isink->reg,
106 WM831X_CS1_ISEL_MASK, i); 106 WM831X_CS1_ISEL_MASK, i);
107 return ret; 107 return ret;
diff --git a/drivers/regulator/wm831x-ldo.c b/drivers/regulator/wm831x-ldo.c
index f1e4ab0f9fda..641e9f6499d1 100644
--- a/drivers/regulator/wm831x-ldo.c
+++ b/drivers/regulator/wm831x-ldo.c
@@ -506,22 +506,19 @@ static int wm831x_aldo_set_mode(struct regulator_dev *rdev,
506{ 506{
507 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); 507 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
508 struct wm831x *wm831x = ldo->wm831x; 508 struct wm831x *wm831x = ldo->wm831x;
509 int ctrl_reg = ldo->base + WM831X_LDO_CONTROL;
510 int on_reg = ldo->base + WM831X_LDO_ON_CONTROL; 509 int on_reg = ldo->base + WM831X_LDO_ON_CONTROL;
511 int ret; 510 int ret;
512 511
513 512
514 switch (mode) { 513 switch (mode) {
515 case REGULATOR_MODE_NORMAL: 514 case REGULATOR_MODE_NORMAL:
516 ret = wm831x_set_bits(wm831x, on_reg, 515 ret = wm831x_set_bits(wm831x, on_reg, WM831X_LDO7_ON_MODE, 0);
517 WM831X_LDO7_ON_MODE, 0);
518 if (ret < 0) 516 if (ret < 0)
519 return ret; 517 return ret;
520 break; 518 break;
521 519
522 case REGULATOR_MODE_IDLE: 520 case REGULATOR_MODE_IDLE:
523 ret = wm831x_set_bits(wm831x, ctrl_reg, 521 ret = wm831x_set_bits(wm831x, on_reg, WM831X_LDO7_ON_MODE,
524 WM831X_LDO7_ON_MODE,
525 WM831X_LDO7_ON_MODE); 522 WM831X_LDO7_ON_MODE);
526 if (ret < 0) 523 if (ret < 0)
527 return ret; 524 return ret;
diff --git a/drivers/regulator/wm8350-regulator.c b/drivers/regulator/wm8350-regulator.c
index ab1e183a74b5..05ecfb872319 100644
--- a/drivers/regulator/wm8350-regulator.c
+++ b/drivers/regulator/wm8350-regulator.c
@@ -99,7 +99,7 @@ static int get_isink_val(int min_uA, int max_uA, u16 *setting)
99{ 99{
100 int i; 100 int i;
101 101
102 for (i = ARRAY_SIZE(isink_cur) - 1; i >= 0; i--) { 102 for (i = 0; i < ARRAY_SIZE(isink_cur); i++) {
103 if (min_uA <= isink_cur[i] && max_uA >= isink_cur[i]) { 103 if (min_uA <= isink_cur[i] && max_uA >= isink_cur[i]) {
104 *setting = i; 104 *setting = i;
105 return 0; 105 return 0;
@@ -186,7 +186,7 @@ static int wm8350_isink_get_current(struct regulator_dev *rdev)
186 return 0; 186 return 0;
187 } 187 }
188 188
189 return DIV_ROUND_CLOSEST(isink_cur[val], 100); 189 return isink_cur[val];
190} 190}
191 191
192/* turn on ISINK followed by DCDC */ 192/* turn on ISINK followed by DCDC */
@@ -495,25 +495,25 @@ static int wm8350_dcdc_set_suspend_enable(struct regulator_dev *rdev)
495 val = wm8350_reg_read(wm8350, WM8350_DCDC1_LOW_POWER) 495 val = wm8350_reg_read(wm8350, WM8350_DCDC1_LOW_POWER)
496 & ~WM8350_DCDC_HIB_MODE_MASK; 496 & ~WM8350_DCDC_HIB_MODE_MASK;
497 wm8350_reg_write(wm8350, WM8350_DCDC1_LOW_POWER, 497 wm8350_reg_write(wm8350, WM8350_DCDC1_LOW_POWER,
498 wm8350->pmic.dcdc1_hib_mode); 498 val | wm8350->pmic.dcdc1_hib_mode);
499 break; 499 break;
500 case WM8350_DCDC_3: 500 case WM8350_DCDC_3:
501 val = wm8350_reg_read(wm8350, WM8350_DCDC3_LOW_POWER) 501 val = wm8350_reg_read(wm8350, WM8350_DCDC3_LOW_POWER)
502 & ~WM8350_DCDC_HIB_MODE_MASK; 502 & ~WM8350_DCDC_HIB_MODE_MASK;
503 wm8350_reg_write(wm8350, WM8350_DCDC3_LOW_POWER, 503 wm8350_reg_write(wm8350, WM8350_DCDC3_LOW_POWER,
504 wm8350->pmic.dcdc3_hib_mode); 504 val | wm8350->pmic.dcdc3_hib_mode);
505 break; 505 break;
506 case WM8350_DCDC_4: 506 case WM8350_DCDC_4:
507 val = wm8350_reg_read(wm8350, WM8350_DCDC4_LOW_POWER) 507 val = wm8350_reg_read(wm8350, WM8350_DCDC4_LOW_POWER)
508 & ~WM8350_DCDC_HIB_MODE_MASK; 508 & ~WM8350_DCDC_HIB_MODE_MASK;
509 wm8350_reg_write(wm8350, WM8350_DCDC4_LOW_POWER, 509 wm8350_reg_write(wm8350, WM8350_DCDC4_LOW_POWER,
510 wm8350->pmic.dcdc4_hib_mode); 510 val | wm8350->pmic.dcdc4_hib_mode);
511 break; 511 break;
512 case WM8350_DCDC_6: 512 case WM8350_DCDC_6:
513 val = wm8350_reg_read(wm8350, WM8350_DCDC6_LOW_POWER) 513 val = wm8350_reg_read(wm8350, WM8350_DCDC6_LOW_POWER)
514 & ~WM8350_DCDC_HIB_MODE_MASK; 514 & ~WM8350_DCDC_HIB_MODE_MASK;
515 wm8350_reg_write(wm8350, WM8350_DCDC6_LOW_POWER, 515 wm8350_reg_write(wm8350, WM8350_DCDC6_LOW_POWER,
516 wm8350->pmic.dcdc6_hib_mode); 516 val | wm8350->pmic.dcdc6_hib_mode);
517 break; 517 break;
518 case WM8350_DCDC_2: 518 case WM8350_DCDC_2:
519 case WM8350_DCDC_5: 519 case WM8350_DCDC_5:
@@ -535,25 +535,25 @@ static int wm8350_dcdc_set_suspend_disable(struct regulator_dev *rdev)
535 val = wm8350_reg_read(wm8350, WM8350_DCDC1_LOW_POWER); 535 val = wm8350_reg_read(wm8350, WM8350_DCDC1_LOW_POWER);
536 wm8350->pmic.dcdc1_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK; 536 wm8350->pmic.dcdc1_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK;
537 wm8350_reg_write(wm8350, WM8350_DCDC1_LOW_POWER, 537 wm8350_reg_write(wm8350, WM8350_DCDC1_LOW_POWER,
538 WM8350_DCDC_HIB_MODE_DIS); 538 val | WM8350_DCDC_HIB_MODE_DIS);
539 break; 539 break;
540 case WM8350_DCDC_3: 540 case WM8350_DCDC_3:
541 val = wm8350_reg_read(wm8350, WM8350_DCDC3_LOW_POWER); 541 val = wm8350_reg_read(wm8350, WM8350_DCDC3_LOW_POWER);
542 wm8350->pmic.dcdc3_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK; 542 wm8350->pmic.dcdc3_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK;
543 wm8350_reg_write(wm8350, WM8350_DCDC3_LOW_POWER, 543 wm8350_reg_write(wm8350, WM8350_DCDC3_LOW_POWER,
544 WM8350_DCDC_HIB_MODE_DIS); 544 val | WM8350_DCDC_HIB_MODE_DIS);
545 break; 545 break;
546 case WM8350_DCDC_4: 546 case WM8350_DCDC_4:
547 val = wm8350_reg_read(wm8350, WM8350_DCDC4_LOW_POWER); 547 val = wm8350_reg_read(wm8350, WM8350_DCDC4_LOW_POWER);
548 wm8350->pmic.dcdc4_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK; 548 wm8350->pmic.dcdc4_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK;
549 wm8350_reg_write(wm8350, WM8350_DCDC4_LOW_POWER, 549 wm8350_reg_write(wm8350, WM8350_DCDC4_LOW_POWER,
550 WM8350_DCDC_HIB_MODE_DIS); 550 val | WM8350_DCDC_HIB_MODE_DIS);
551 break; 551 break;
552 case WM8350_DCDC_6: 552 case WM8350_DCDC_6:
553 val = wm8350_reg_read(wm8350, WM8350_DCDC6_LOW_POWER); 553 val = wm8350_reg_read(wm8350, WM8350_DCDC6_LOW_POWER);
554 wm8350->pmic.dcdc6_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK; 554 wm8350->pmic.dcdc6_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK;
555 wm8350_reg_write(wm8350, WM8350_DCDC6_LOW_POWER, 555 wm8350_reg_write(wm8350, WM8350_DCDC6_LOW_POWER,
556 WM8350_DCDC_HIB_MODE_DIS); 556 val | WM8350_DCDC_HIB_MODE_DIS);
557 break; 557 break;
558 case WM8350_DCDC_2: 558 case WM8350_DCDC_2:
559 case WM8350_DCDC_5: 559 case WM8350_DCDC_5:
@@ -575,13 +575,13 @@ static int wm8350_dcdc25_set_suspend_enable(struct regulator_dev *rdev)
575 val = wm8350_reg_read(wm8350, WM8350_DCDC2_CONTROL) 575 val = wm8350_reg_read(wm8350, WM8350_DCDC2_CONTROL)
576 & ~WM8350_DC2_HIB_MODE_MASK; 576 & ~WM8350_DC2_HIB_MODE_MASK;
577 wm8350_reg_write(wm8350, WM8350_DCDC2_CONTROL, val | 577 wm8350_reg_write(wm8350, WM8350_DCDC2_CONTROL, val |
578 WM8350_DC2_HIB_MODE_ACTIVE); 578 (WM8350_DC2_HIB_MODE_ACTIVE << WM8350_DC2_HIB_MODE_SHIFT));
579 break; 579 break;
580 case WM8350_DCDC_5: 580 case WM8350_DCDC_5:
581 val = wm8350_reg_read(wm8350, WM8350_DCDC5_CONTROL) 581 val = wm8350_reg_read(wm8350, WM8350_DCDC5_CONTROL)
582 & ~WM8350_DC2_HIB_MODE_MASK; 582 & ~WM8350_DC5_HIB_MODE_MASK;
583 wm8350_reg_write(wm8350, WM8350_DCDC5_CONTROL, val | 583 wm8350_reg_write(wm8350, WM8350_DCDC5_CONTROL, val |
584 WM8350_DC5_HIB_MODE_ACTIVE); 584 (WM8350_DC5_HIB_MODE_ACTIVE << WM8350_DC5_HIB_MODE_SHIFT));
585 break; 585 break;
586 default: 586 default:
587 return -EINVAL; 587 return -EINVAL;
@@ -600,13 +600,13 @@ static int wm8350_dcdc25_set_suspend_disable(struct regulator_dev *rdev)
600 val = wm8350_reg_read(wm8350, WM8350_DCDC2_CONTROL) 600 val = wm8350_reg_read(wm8350, WM8350_DCDC2_CONTROL)
601 & ~WM8350_DC2_HIB_MODE_MASK; 601 & ~WM8350_DC2_HIB_MODE_MASK;
602 wm8350_reg_write(wm8350, WM8350_DCDC2_CONTROL, val | 602 wm8350_reg_write(wm8350, WM8350_DCDC2_CONTROL, val |
603 WM8350_DC2_HIB_MODE_DISABLE); 603 (WM8350_DC2_HIB_MODE_DISABLE << WM8350_DC2_HIB_MODE_SHIFT));
604 break; 604 break;
605 case WM8350_DCDC_5: 605 case WM8350_DCDC_5:
606 val = wm8350_reg_read(wm8350, WM8350_DCDC5_CONTROL) 606 val = wm8350_reg_read(wm8350, WM8350_DCDC5_CONTROL)
607 & ~WM8350_DC2_HIB_MODE_MASK; 607 & ~WM8350_DC5_HIB_MODE_MASK;
608 wm8350_reg_write(wm8350, WM8350_DCDC5_CONTROL, val | 608 wm8350_reg_write(wm8350, WM8350_DCDC5_CONTROL, val |
609 WM8350_DC2_HIB_MODE_DISABLE); 609 (WM8350_DC5_HIB_MODE_DISABLE << WM8350_DC5_HIB_MODE_SHIFT));
610 break; 610 break;
611 default: 611 default:
612 return -EINVAL; 612 return -EINVAL;
@@ -749,7 +749,7 @@ static int wm8350_ldo_set_suspend_disable(struct regulator_dev *rdev)
749 749
750 /* all LDOs have same mV bits */ 750 /* all LDOs have same mV bits */
751 val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_LDO1_HIB_MODE_MASK; 751 val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_LDO1_HIB_MODE_MASK;
752 wm8350_reg_write(wm8350, volt_reg, WM8350_LDO1_HIB_MODE_DIS); 752 wm8350_reg_write(wm8350, volt_reg, val | WM8350_LDO1_HIB_MODE_DIS);
753 return 0; 753 return 0;
754} 754}
755 755
diff --git a/drivers/remoteproc/remoteproc_debugfs.c b/drivers/remoteproc/remoteproc_debugfs.c
index 70277a530133..85d31a69e117 100644
--- a/drivers/remoteproc/remoteproc_debugfs.c
+++ b/drivers/remoteproc/remoteproc_debugfs.c
@@ -50,16 +50,9 @@ static ssize_t rproc_trace_read(struct file *filp, char __user *userbuf,
50 return simple_read_from_buffer(userbuf, count, ppos, trace->va, len); 50 return simple_read_from_buffer(userbuf, count, ppos, trace->va, len);
51} 51}
52 52
53static int rproc_open_generic(struct inode *inode, struct file *file)
54{
55 file->private_data = inode->i_private;
56
57 return 0;
58}
59
60static const struct file_operations trace_rproc_ops = { 53static const struct file_operations trace_rproc_ops = {
61 .read = rproc_trace_read, 54 .read = rproc_trace_read,
62 .open = rproc_open_generic, 55 .open = simple_open,
63 .llseek = generic_file_llseek, 56 .llseek = generic_file_llseek,
64}; 57};
65 58
@@ -94,7 +87,7 @@ static ssize_t rproc_state_read(struct file *filp, char __user *userbuf,
94 87
95static const struct file_operations rproc_state_ops = { 88static const struct file_operations rproc_state_ops = {
96 .read = rproc_state_read, 89 .read = rproc_state_read,
97 .open = rproc_open_generic, 90 .open = simple_open,
98 .llseek = generic_file_llseek, 91 .llseek = generic_file_llseek,
99}; 92};
100 93
@@ -114,7 +107,7 @@ static ssize_t rproc_name_read(struct file *filp, char __user *userbuf,
114 107
115static const struct file_operations rproc_name_ops = { 108static const struct file_operations rproc_name_ops = {
116 .read = rproc_name_read, 109 .read = rproc_name_read,
117 .open = rproc_open_generic, 110 .open = simple_open,
118 .llseek = generic_file_llseek, 111 .llseek = generic_file_llseek,
119}; 112};
120 113
diff --git a/drivers/rtc/rtc-88pm860x.c b/drivers/rtc/rtc-88pm860x.c
index afee0e8ae714..feddefc42109 100644
--- a/drivers/rtc/rtc-88pm860x.c
+++ b/drivers/rtc/rtc-88pm860x.c
@@ -72,9 +72,9 @@ static int pm860x_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
72 struct pm860x_rtc_info *info = dev_get_drvdata(dev); 72 struct pm860x_rtc_info *info = dev_get_drvdata(dev);
73 73
74 if (enabled) 74 if (enabled)
75 pm860x_set_bits(info->i2c, PM8607_RTC1, ALARM, ALARM); 75 pm860x_set_bits(info->i2c, PM8607_RTC1, ALARM_EN, ALARM_EN);
76 else 76 else
77 pm860x_set_bits(info->i2c, PM8607_RTC1, ALARM, 0); 77 pm860x_set_bits(info->i2c, PM8607_RTC1, ALARM_EN, 0);
78 return 0; 78 return 0;
79} 79}
80 80
diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index cd188ab72f79..c293d0cdb104 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -902,6 +902,7 @@ read_rtc:
902 } 902 }
903 ds1307->nvram->attr.name = "nvram"; 903 ds1307->nvram->attr.name = "nvram";
904 ds1307->nvram->attr.mode = S_IRUGO | S_IWUSR; 904 ds1307->nvram->attr.mode = S_IRUGO | S_IWUSR;
905 sysfs_bin_attr_init(ds1307->nvram);
905 ds1307->nvram->read = ds1307_nvram_read, 906 ds1307->nvram->read = ds1307_nvram_read,
906 ds1307->nvram->write = ds1307_nvram_write, 907 ds1307->nvram->write = ds1307_nvram_write,
907 ds1307->nvram->size = chip->nvram_size; 908 ds1307->nvram->size = chip->nvram_size;
diff --git a/drivers/rtc/rtc-efi.c b/drivers/rtc/rtc-efi.c
index 550292304b0f..c9f890b088da 100644
--- a/drivers/rtc/rtc-efi.c
+++ b/drivers/rtc/rtc-efi.c
@@ -213,7 +213,6 @@ static struct platform_driver efi_rtc_driver = {
213 .name = "rtc-efi", 213 .name = "rtc-efi",
214 .owner = THIS_MODULE, 214 .owner = THIS_MODULE,
215 }, 215 },
216 .probe = efi_rtc_probe,
217 .remove = __exit_p(efi_rtc_remove), 216 .remove = __exit_p(efi_rtc_remove),
218}; 217};
219 218
diff --git a/drivers/rtc/rtc-mpc5121.c b/drivers/rtc/rtc-mpc5121.c
index 42f5f829b3ee..029e421baaed 100644
--- a/drivers/rtc/rtc-mpc5121.c
+++ b/drivers/rtc/rtc-mpc5121.c
@@ -360,12 +360,11 @@ static int __devinit mpc5121_rtc_probe(struct platform_device *op)
360 &mpc5200_rtc_ops, THIS_MODULE); 360 &mpc5200_rtc_ops, THIS_MODULE);
361 } 361 }
362 362
363 rtc->rtc->uie_unsupported = 1;
364
365 if (IS_ERR(rtc->rtc)) { 363 if (IS_ERR(rtc->rtc)) {
366 err = PTR_ERR(rtc->rtc); 364 err = PTR_ERR(rtc->rtc);
367 goto out_free_irq; 365 goto out_free_irq;
368 } 366 }
367 rtc->rtc->uie_unsupported = 1;
369 368
370 return 0; 369 return 0;
371 370
diff --git a/drivers/rtc/rtc-pl031.c b/drivers/rtc/rtc-pl031.c
index 692de7360e94..684ef4bbfce4 100644
--- a/drivers/rtc/rtc-pl031.c
+++ b/drivers/rtc/rtc-pl031.c
@@ -339,8 +339,7 @@ static int pl031_probe(struct amba_device *adev, const struct amba_id *id)
339 dev_dbg(&adev->dev, "revision = 0x%01x\n", ldata->hw_revision); 339 dev_dbg(&adev->dev, "revision = 0x%01x\n", ldata->hw_revision);
340 340
341 /* Enable the clockwatch on ST Variants */ 341 /* Enable the clockwatch on ST Variants */
342 if ((ldata->hw_designer == AMBA_VENDOR_ST) && 342 if (ldata->hw_designer == AMBA_VENDOR_ST)
343 (ldata->hw_revision > 1))
344 writel(readl(ldata->base + RTC_CR) | RTC_CR_CWEN, 343 writel(readl(ldata->base + RTC_CR) | RTC_CR_CWEN,
345 ldata->base + RTC_CR); 344 ldata->base + RTC_CR);
346 345
diff --git a/drivers/rtc/rtc-r9701.c b/drivers/rtc/rtc-r9701.c
index 7f8e6c247935..33b6ba0afa0d 100644
--- a/drivers/rtc/rtc-r9701.c
+++ b/drivers/rtc/rtc-r9701.c
@@ -122,6 +122,7 @@ static const struct rtc_class_ops r9701_rtc_ops = {
122static int __devinit r9701_probe(struct spi_device *spi) 122static int __devinit r9701_probe(struct spi_device *spi)
123{ 123{
124 struct rtc_device *rtc; 124 struct rtc_device *rtc;
125 struct rtc_time dt;
125 unsigned char tmp; 126 unsigned char tmp;
126 int res; 127 int res;
127 128
@@ -132,6 +133,27 @@ static int __devinit r9701_probe(struct spi_device *spi)
132 return -ENODEV; 133 return -ENODEV;
133 } 134 }
134 135
136 /*
137 * The device seems to be present. Now check if the registers
138 * contain invalid values. If so, try to write a default date:
139 * 2000/1/1 00:00:00
140 */
141 r9701_get_datetime(&spi->dev, &dt);
142 if (rtc_valid_tm(&dt)) {
143 dev_info(&spi->dev, "trying to repair invalid date/time\n");
144 dt.tm_sec = 0;
145 dt.tm_min = 0;
146 dt.tm_hour = 0;
147 dt.tm_mday = 1;
148 dt.tm_mon = 0;
149 dt.tm_year = 100;
150
151 if (r9701_set_datetime(&spi->dev, &dt)) {
152 dev_err(&spi->dev, "cannot repair RTC register\n");
153 return -ENODEV;
154 }
155 }
156
135 rtc = rtc_device_register("r9701", 157 rtc = rtc_device_register("r9701",
136 &spi->dev, &r9701_rtc_ops, THIS_MODULE); 158 &spi->dev, &r9701_rtc_ops, THIS_MODULE);
137 if (IS_ERR(rtc)) 159 if (IS_ERR(rtc))
diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c
index 9ccea134a996..3f3a29752369 100644
--- a/drivers/rtc/rtc-s3c.c
+++ b/drivers/rtc/rtc-s3c.c
@@ -40,6 +40,10 @@ enum s3c_cpu_type {
40 TYPE_S3C64XX, 40 TYPE_S3C64XX,
41}; 41};
42 42
43struct s3c_rtc_drv_data {
44 int cpu_type;
45};
46
43/* I have yet to find an S3C implementation with more than one 47/* I have yet to find an S3C implementation with more than one
44 * of these rtc blocks in */ 48 * of these rtc blocks in */
45 49
@@ -446,10 +450,12 @@ static const struct of_device_id s3c_rtc_dt_match[];
446static inline int s3c_rtc_get_driver_data(struct platform_device *pdev) 450static inline int s3c_rtc_get_driver_data(struct platform_device *pdev)
447{ 451{
448#ifdef CONFIG_OF 452#ifdef CONFIG_OF
453 struct s3c_rtc_drv_data *data;
449 if (pdev->dev.of_node) { 454 if (pdev->dev.of_node) {
450 const struct of_device_id *match; 455 const struct of_device_id *match;
451 match = of_match_node(s3c_rtc_dt_match, pdev->dev.of_node); 456 match = of_match_node(s3c_rtc_dt_match, pdev->dev.of_node);
452 return match->data; 457 data = (struct s3c_rtc_drv_data *) match->data;
458 return data->cpu_type;
453 } 459 }
454#endif 460#endif
455 return platform_get_device_id(pdev)->driver_data; 461 return platform_get_device_id(pdev)->driver_data;
@@ -664,20 +670,27 @@ static int s3c_rtc_resume(struct platform_device *pdev)
664#define s3c_rtc_resume NULL 670#define s3c_rtc_resume NULL
665#endif 671#endif
666 672
673static struct s3c_rtc_drv_data s3c_rtc_drv_data_array[] = {
674 [TYPE_S3C2410] = { TYPE_S3C2410 },
675 [TYPE_S3C2416] = { TYPE_S3C2416 },
676 [TYPE_S3C2443] = { TYPE_S3C2443 },
677 [TYPE_S3C64XX] = { TYPE_S3C64XX },
678};
679
667#ifdef CONFIG_OF 680#ifdef CONFIG_OF
668static const struct of_device_id s3c_rtc_dt_match[] = { 681static const struct of_device_id s3c_rtc_dt_match[] = {
669 { 682 {
670 .compatible = "samsung,s3c2410-rtc" 683 .compatible = "samsung,s3c2410-rtc",
671 .data = TYPE_S3C2410, 684 .data = &s3c_rtc_drv_data_array[TYPE_S3C2410],
672 }, { 685 }, {
673 .compatible = "samsung,s3c2416-rtc" 686 .compatible = "samsung,s3c2416-rtc",
674 .data = TYPE_S3C2416, 687 .data = &s3c_rtc_drv_data_array[TYPE_S3C2416],
675 }, { 688 }, {
676 .compatible = "samsung,s3c2443-rtc" 689 .compatible = "samsung,s3c2443-rtc",
677 .data = TYPE_S3C2443, 690 .data = &s3c_rtc_drv_data_array[TYPE_S3C2443],
678 }, { 691 }, {
679 .compatible = "samsung,s3c6410-rtc" 692 .compatible = "samsung,s3c6410-rtc",
680 .data = TYPE_S3C64XX, 693 .data = &s3c_rtc_drv_data_array[TYPE_S3C64XX],
681 }, 694 },
682 {}, 695 {},
683}; 696};
diff --git a/drivers/rtc/rtc-twl.c b/drivers/rtc/rtc-twl.c
index 4c2c6df2a9ef..258abeabf624 100644
--- a/drivers/rtc/rtc-twl.c
+++ b/drivers/rtc/rtc-twl.c
@@ -112,6 +112,7 @@ static const u8 twl6030_rtc_reg_map[] = {
112#define BIT_RTC_CTRL_REG_TEST_MODE_M 0x10 112#define BIT_RTC_CTRL_REG_TEST_MODE_M 0x10
113#define BIT_RTC_CTRL_REG_SET_32_COUNTER_M 0x20 113#define BIT_RTC_CTRL_REG_SET_32_COUNTER_M 0x20
114#define BIT_RTC_CTRL_REG_GET_TIME_M 0x40 114#define BIT_RTC_CTRL_REG_GET_TIME_M 0x40
115#define BIT_RTC_CTRL_REG_RTC_V_OPT 0x80
115 116
116/* RTC_STATUS_REG bitfields */ 117/* RTC_STATUS_REG bitfields */
117#define BIT_RTC_STATUS_REG_RUN_M 0x02 118#define BIT_RTC_STATUS_REG_RUN_M 0x02
@@ -235,25 +236,57 @@ static int twl_rtc_read_time(struct device *dev, struct rtc_time *tm)
235 unsigned char rtc_data[ALL_TIME_REGS + 1]; 236 unsigned char rtc_data[ALL_TIME_REGS + 1];
236 int ret; 237 int ret;
237 u8 save_control; 238 u8 save_control;
239 u8 rtc_control;
238 240
239 ret = twl_rtc_read_u8(&save_control, REG_RTC_CTRL_REG); 241 ret = twl_rtc_read_u8(&save_control, REG_RTC_CTRL_REG);
240 if (ret < 0) 242 if (ret < 0) {
243 dev_err(dev, "%s: reading CTRL_REG, error %d\n", __func__, ret);
241 return ret; 244 return ret;
245 }
246 /* for twl6030/32 make sure BIT_RTC_CTRL_REG_GET_TIME_M is clear */
247 if (twl_class_is_6030()) {
248 if (save_control & BIT_RTC_CTRL_REG_GET_TIME_M) {
249 save_control &= ~BIT_RTC_CTRL_REG_GET_TIME_M;
250 ret = twl_rtc_write_u8(save_control, REG_RTC_CTRL_REG);
251 if (ret < 0) {
252 dev_err(dev, "%s clr GET_TIME, error %d\n",
253 __func__, ret);
254 return ret;
255 }
256 }
257 }
242 258
243 save_control |= BIT_RTC_CTRL_REG_GET_TIME_M; 259 /* Copy RTC counting registers to static registers or latches */
260 rtc_control = save_control | BIT_RTC_CTRL_REG_GET_TIME_M;
244 261
245 ret = twl_rtc_write_u8(save_control, REG_RTC_CTRL_REG); 262 /* for twl6030/32 enable read access to static shadowed registers */
246 if (ret < 0) 263 if (twl_class_is_6030())
264 rtc_control |= BIT_RTC_CTRL_REG_RTC_V_OPT;
265
266 ret = twl_rtc_write_u8(rtc_control, REG_RTC_CTRL_REG);
267 if (ret < 0) {
268 dev_err(dev, "%s: writing CTRL_REG, error %d\n", __func__, ret);
247 return ret; 269 return ret;
270 }
248 271
249 ret = twl_i2c_read(TWL_MODULE_RTC, rtc_data, 272 ret = twl_i2c_read(TWL_MODULE_RTC, rtc_data,
250 (rtc_reg_map[REG_SECONDS_REG]), ALL_TIME_REGS); 273 (rtc_reg_map[REG_SECONDS_REG]), ALL_TIME_REGS);
251 274
252 if (ret < 0) { 275 if (ret < 0) {
253 dev_err(dev, "rtc_read_time error %d\n", ret); 276 dev_err(dev, "%s: reading data, error %d\n", __func__, ret);
254 return ret; 277 return ret;
255 } 278 }
256 279
280 /* for twl6030 restore original state of rtc control register */
281 if (twl_class_is_6030()) {
282 ret = twl_rtc_write_u8(save_control, REG_RTC_CTRL_REG);
283 if (ret < 0) {
284 dev_err(dev, "%s: restore CTRL_REG, error %d\n",
285 __func__, ret);
286 return ret;
287 }
288 }
289
257 tm->tm_sec = bcd2bin(rtc_data[0]); 290 tm->tm_sec = bcd2bin(rtc_data[0]);
258 tm->tm_min = bcd2bin(rtc_data[1]); 291 tm->tm_min = bcd2bin(rtc_data[1]);
259 tm->tm_hour = bcd2bin(rtc_data[2]); 292 tm->tm_hour = bcd2bin(rtc_data[2]);
diff --git a/drivers/s390/block/dasd_eckd.c b/drivers/s390/block/dasd_eckd.c
index c21871a4e73d..bc2e8a7c265b 100644
--- a/drivers/s390/block/dasd_eckd.c
+++ b/drivers/s390/block/dasd_eckd.c
@@ -2844,6 +2844,7 @@ static struct dasd_ccw_req *dasd_eckd_build_cp_tpm_track(
2844 sector_t recid, trkid; 2844 sector_t recid, trkid;
2845 unsigned int offs; 2845 unsigned int offs;
2846 unsigned int count, count_to_trk_end; 2846 unsigned int count, count_to_trk_end;
2847 int ret;
2847 2848
2848 basedev = block->base; 2849 basedev = block->base;
2849 if (rq_data_dir(req) == READ) { 2850 if (rq_data_dir(req) == READ) {
@@ -2884,8 +2885,8 @@ static struct dasd_ccw_req *dasd_eckd_build_cp_tpm_track(
2884 2885
2885 itcw = itcw_init(cqr->data, itcw_size, itcw_op, 0, ctidaw, 0); 2886 itcw = itcw_init(cqr->data, itcw_size, itcw_op, 0, ctidaw, 0);
2886 if (IS_ERR(itcw)) { 2887 if (IS_ERR(itcw)) {
2887 dasd_sfree_request(cqr, startdev); 2888 ret = -EINVAL;
2888 return ERR_PTR(-EINVAL); 2889 goto out_error;
2889 } 2890 }
2890 cqr->cpaddr = itcw_get_tcw(itcw); 2891 cqr->cpaddr = itcw_get_tcw(itcw);
2891 if (prepare_itcw(itcw, first_trk, last_trk, 2892 if (prepare_itcw(itcw, first_trk, last_trk,
@@ -2897,8 +2898,8 @@ static struct dasd_ccw_req *dasd_eckd_build_cp_tpm_track(
2897 /* Clock not in sync and XRC is enabled. 2898 /* Clock not in sync and XRC is enabled.
2898 * Try again later. 2899 * Try again later.
2899 */ 2900 */
2900 dasd_sfree_request(cqr, startdev); 2901 ret = -EAGAIN;
2901 return ERR_PTR(-EAGAIN); 2902 goto out_error;
2902 } 2903 }
2903 len_to_track_end = 0; 2904 len_to_track_end = 0;
2904 /* 2905 /*
@@ -2937,8 +2938,10 @@ static struct dasd_ccw_req *dasd_eckd_build_cp_tpm_track(
2937 tidaw_flags = 0; 2938 tidaw_flags = 0;
2938 last_tidaw = itcw_add_tidaw(itcw, tidaw_flags, 2939 last_tidaw = itcw_add_tidaw(itcw, tidaw_flags,
2939 dst, part_len); 2940 dst, part_len);
2940 if (IS_ERR(last_tidaw)) 2941 if (IS_ERR(last_tidaw)) {
2941 return ERR_PTR(-EINVAL); 2942 ret = -EINVAL;
2943 goto out_error;
2944 }
2942 dst += part_len; 2945 dst += part_len;
2943 } 2946 }
2944 } 2947 }
@@ -2947,8 +2950,10 @@ static struct dasd_ccw_req *dasd_eckd_build_cp_tpm_track(
2947 dst = page_address(bv->bv_page) + bv->bv_offset; 2950 dst = page_address(bv->bv_page) + bv->bv_offset;
2948 last_tidaw = itcw_add_tidaw(itcw, 0x00, 2951 last_tidaw = itcw_add_tidaw(itcw, 0x00,
2949 dst, bv->bv_len); 2952 dst, bv->bv_len);
2950 if (IS_ERR(last_tidaw)) 2953 if (IS_ERR(last_tidaw)) {
2951 return ERR_PTR(-EINVAL); 2954 ret = -EINVAL;
2955 goto out_error;
2956 }
2952 } 2957 }
2953 } 2958 }
2954 last_tidaw->flags |= TIDAW_FLAGS_LAST; 2959 last_tidaw->flags |= TIDAW_FLAGS_LAST;
@@ -2968,6 +2973,9 @@ static struct dasd_ccw_req *dasd_eckd_build_cp_tpm_track(
2968 cqr->buildclk = get_clock(); 2973 cqr->buildclk = get_clock();
2969 cqr->status = DASD_CQR_FILLED; 2974 cqr->status = DASD_CQR_FILLED;
2970 return cqr; 2975 return cqr;
2976out_error:
2977 dasd_sfree_request(cqr, startdev);
2978 return ERR_PTR(ret);
2971} 2979}
2972 2980
2973static struct dasd_ccw_req *dasd_eckd_build_cp(struct dasd_device *startdev, 2981static struct dasd_ccw_req *dasd_eckd_build_cp(struct dasd_device *startdev,
diff --git a/drivers/s390/char/vmur.c b/drivers/s390/char/vmur.c
index 85f4a9a5d12e..73bef0bd394c 100644
--- a/drivers/s390/char/vmur.c
+++ b/drivers/s390/char/vmur.c
@@ -903,7 +903,7 @@ static int ur_set_online(struct ccw_device *cdev)
903 goto fail_urdev_put; 903 goto fail_urdev_put;
904 } 904 }
905 905
906 cdev_init(urd->char_device, &ur_fops); 906 urd->char_device->ops = &ur_fops;
907 urd->char_device->dev = MKDEV(major, minor); 907 urd->char_device->dev = MKDEV(major, minor);
908 urd->char_device->owner = ur_fops.owner; 908 urd->char_device->owner = ur_fops.owner;
909 909
diff --git a/drivers/s390/net/qeth_core_main.c b/drivers/s390/net/qeth_core_main.c
index 120955c66410..8334dadc681d 100644
--- a/drivers/s390/net/qeth_core_main.c
+++ b/drivers/s390/net/qeth_core_main.c
@@ -1672,7 +1672,8 @@ static void qeth_configure_blkt_default(struct qeth_card *card, char *prcd)
1672{ 1672{
1673 QETH_DBF_TEXT(SETUP, 2, "cfgblkt"); 1673 QETH_DBF_TEXT(SETUP, 2, "cfgblkt");
1674 1674
1675 if (prcd[74] == 0xF0 && prcd[75] == 0xF0 && prcd[76] == 0xF5) { 1675 if (prcd[74] == 0xF0 && prcd[75] == 0xF0 &&
1676 (prcd[76] == 0xF5 || prcd[76] == 0xF6)) {
1676 card->info.blkt.time_total = 250; 1677 card->info.blkt.time_total = 250;
1677 card->info.blkt.inter_packet = 5; 1678 card->info.blkt.inter_packet = 5;
1678 card->info.blkt.inter_packet_jumbo = 15; 1679 card->info.blkt.inter_packet_jumbo = 15;
@@ -4540,7 +4541,8 @@ static void qeth_determine_capabilities(struct qeth_card *card)
4540 goto out_offline; 4541 goto out_offline;
4541 } 4542 }
4542 qeth_configure_unitaddr(card, prcd); 4543 qeth_configure_unitaddr(card, prcd);
4543 qeth_configure_blkt_default(card, prcd); 4544 if (ddev_offline)
4545 qeth_configure_blkt_default(card, prcd);
4544 kfree(prcd); 4546 kfree(prcd);
4545 4547
4546 rc = qdio_get_ssqd_desc(ddev, &card->ssqd); 4548 rc = qdio_get_ssqd_desc(ddev, &card->ssqd);
diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
index 351dc0b86fab..a3a056a9db67 100644
--- a/drivers/scsi/hosts.c
+++ b/drivers/scsi/hosts.c
@@ -218,6 +218,9 @@ int scsi_add_host_with_dma(struct Scsi_Host *shost, struct device *dev,
218 218
219 if (!shost->shost_gendev.parent) 219 if (!shost->shost_gendev.parent)
220 shost->shost_gendev.parent = dev ? dev : &platform_bus; 220 shost->shost_gendev.parent = dev ? dev : &platform_bus;
221 if (!dma_dev)
222 dma_dev = shost->shost_gendev.parent;
223
221 shost->dma_dev = dma_dev; 224 shost->dma_dev = dma_dev;
222 225
223 error = device_add(&shost->shost_gendev); 226 error = device_add(&shost->shost_gendev);
diff --git a/drivers/scsi/ipr.c b/drivers/scsi/ipr.c
index e002cd466e9a..467dc38246f9 100644
--- a/drivers/scsi/ipr.c
+++ b/drivers/scsi/ipr.c
@@ -4549,8 +4549,12 @@ static int ipr_ata_slave_alloc(struct scsi_device *sdev)
4549 ENTER; 4549 ENTER;
4550 if (sdev->sdev_target) 4550 if (sdev->sdev_target)
4551 sata_port = sdev->sdev_target->hostdata; 4551 sata_port = sdev->sdev_target->hostdata;
4552 if (sata_port) 4552 if (sata_port) {
4553 rc = ata_sas_port_init(sata_port->ap); 4553 rc = ata_sas_port_init(sata_port->ap);
4554 if (rc == 0)
4555 rc = ata_sas_sync_probe(sata_port->ap);
4556 }
4557
4554 if (rc) 4558 if (rc)
4555 ipr_slave_destroy(sdev); 4559 ipr_slave_destroy(sdev);
4556 4560
diff --git a/drivers/scsi/libfc/fc_lport.c b/drivers/scsi/libfc/fc_lport.c
index ef9560dff295..cc83b66d45b7 100644
--- a/drivers/scsi/libfc/fc_lport.c
+++ b/drivers/scsi/libfc/fc_lport.c
@@ -1742,17 +1742,19 @@ void fc_lport_flogi_resp(struct fc_seq *sp, struct fc_frame *fp,
1742 1742
1743 mfs = ntohs(flp->fl_csp.sp_bb_data) & 1743 mfs = ntohs(flp->fl_csp.sp_bb_data) &
1744 FC_SP_BB_DATA_MASK; 1744 FC_SP_BB_DATA_MASK;
1745 if (mfs >= FC_SP_MIN_MAX_PAYLOAD && 1745
1746 mfs <= lport->mfs) { 1746 if (mfs < FC_SP_MIN_MAX_PAYLOAD || mfs > FC_SP_MAX_MAX_PAYLOAD) {
1747 lport->mfs = mfs;
1748 fc_host_maxframe_size(lport->host) = mfs;
1749 } else {
1750 FC_LPORT_DBG(lport, "FLOGI bad mfs:%hu response, " 1747 FC_LPORT_DBG(lport, "FLOGI bad mfs:%hu response, "
1751 "lport->mfs:%hu\n", mfs, lport->mfs); 1748 "lport->mfs:%hu\n", mfs, lport->mfs);
1752 fc_lport_error(lport, fp); 1749 fc_lport_error(lport, fp);
1753 goto err; 1750 goto err;
1754 } 1751 }
1755 1752
1753 if (mfs <= lport->mfs) {
1754 lport->mfs = mfs;
1755 fc_host_maxframe_size(lport->host) = mfs;
1756 }
1757
1756 csp_flags = ntohs(flp->fl_csp.sp_features); 1758 csp_flags = ntohs(flp->fl_csp.sp_features);
1757 r_a_tov = ntohl(flp->fl_csp.sp_r_a_tov); 1759 r_a_tov = ntohl(flp->fl_csp.sp_r_a_tov);
1758 e_d_tov = ntohl(flp->fl_csp.sp_e_d_tov); 1760 e_d_tov = ntohl(flp->fl_csp.sp_e_d_tov);
diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
index bc0cecc6ad62..441d88ad99a7 100644
--- a/drivers/scsi/libsas/sas_ata.c
+++ b/drivers/scsi/libsas/sas_ata.c
@@ -546,11 +546,12 @@ static struct ata_port_info sata_port_info = {
546 .port_ops = &sas_sata_ops 546 .port_ops = &sas_sata_ops
547}; 547};
548 548
549int sas_ata_init_host_and_port(struct domain_device *found_dev) 549int sas_ata_init(struct domain_device *found_dev)
550{ 550{
551 struct sas_ha_struct *ha = found_dev->port->ha; 551 struct sas_ha_struct *ha = found_dev->port->ha;
552 struct Scsi_Host *shost = ha->core.shost; 552 struct Scsi_Host *shost = ha->core.shost;
553 struct ata_port *ap; 553 struct ata_port *ap;
554 int rc;
554 555
555 ata_host_init(&found_dev->sata_dev.ata_host, 556 ata_host_init(&found_dev->sata_dev.ata_host,
556 ha->dev, 557 ha->dev,
@@ -567,8 +568,11 @@ int sas_ata_init_host_and_port(struct domain_device *found_dev)
567 ap->private_data = found_dev; 568 ap->private_data = found_dev;
568 ap->cbl = ATA_CBL_SATA; 569 ap->cbl = ATA_CBL_SATA;
569 ap->scsi_host = shost; 570 ap->scsi_host = shost;
570 /* publish initialized ata port */ 571 rc = ata_sas_port_init(ap);
571 smp_wmb(); 572 if (rc) {
573 ata_sas_port_destroy(ap);
574 return rc;
575 }
572 found_dev->sata_dev.ap = ap; 576 found_dev->sata_dev.ap = ap;
573 577
574 return 0; 578 return 0;
@@ -648,18 +652,13 @@ static void sas_get_ata_command_set(struct domain_device *dev)
648void sas_probe_sata(struct asd_sas_port *port) 652void sas_probe_sata(struct asd_sas_port *port)
649{ 653{
650 struct domain_device *dev, *n; 654 struct domain_device *dev, *n;
651 int err;
652 655
653 mutex_lock(&port->ha->disco_mutex); 656 mutex_lock(&port->ha->disco_mutex);
654 list_for_each_entry_safe(dev, n, &port->disco_list, disco_list_node) { 657 list_for_each_entry(dev, &port->disco_list, disco_list_node) {
655 if (!dev_is_sata(dev)) 658 if (!dev_is_sata(dev))
656 continue; 659 continue;
657 660
658 err = sas_ata_init_host_and_port(dev); 661 ata_sas_async_probe(dev->sata_dev.ap);
659 if (err)
660 sas_fail_probe(dev, __func__, err);
661 else
662 ata_sas_async_port_init(dev->sata_dev.ap);
663 } 662 }
664 mutex_unlock(&port->ha->disco_mutex); 663 mutex_unlock(&port->ha->disco_mutex);
665 664
@@ -718,18 +717,6 @@ static void async_sas_ata_eh(void *data, async_cookie_t cookie)
718 sas_put_device(dev); 717 sas_put_device(dev);
719} 718}
720 719
721static bool sas_ata_dev_eh_valid(struct domain_device *dev)
722{
723 struct ata_port *ap;
724
725 if (!dev_is_sata(dev))
726 return false;
727 ap = dev->sata_dev.ap;
728 /* consume fully initialized ata ports */
729 smp_rmb();
730 return !!ap;
731}
732
733void sas_ata_strategy_handler(struct Scsi_Host *shost) 720void sas_ata_strategy_handler(struct Scsi_Host *shost)
734{ 721{
735 struct sas_ha_struct *sas_ha = SHOST_TO_SAS_HA(shost); 722 struct sas_ha_struct *sas_ha = SHOST_TO_SAS_HA(shost);
@@ -753,7 +740,7 @@ void sas_ata_strategy_handler(struct Scsi_Host *shost)
753 740
754 spin_lock(&port->dev_list_lock); 741 spin_lock(&port->dev_list_lock);
755 list_for_each_entry(dev, &port->dev_list, dev_list_node) { 742 list_for_each_entry(dev, &port->dev_list, dev_list_node) {
756 if (!sas_ata_dev_eh_valid(dev)) 743 if (!dev_is_sata(dev))
757 continue; 744 continue;
758 async_schedule_domain(async_sas_ata_eh, dev, &async); 745 async_schedule_domain(async_sas_ata_eh, dev, &async);
759 } 746 }
diff --git a/drivers/scsi/libsas/sas_discover.c b/drivers/scsi/libsas/sas_discover.c
index 364679675602..629a0865b130 100644
--- a/drivers/scsi/libsas/sas_discover.c
+++ b/drivers/scsi/libsas/sas_discover.c
@@ -72,6 +72,7 @@ static int sas_get_port_device(struct asd_sas_port *port)
72 struct asd_sas_phy *phy; 72 struct asd_sas_phy *phy;
73 struct sas_rphy *rphy; 73 struct sas_rphy *rphy;
74 struct domain_device *dev; 74 struct domain_device *dev;
75 int rc = -ENODEV;
75 76
76 dev = sas_alloc_device(); 77 dev = sas_alloc_device();
77 if (!dev) 78 if (!dev)
@@ -110,9 +111,16 @@ static int sas_get_port_device(struct asd_sas_port *port)
110 111
111 sas_init_dev(dev); 112 sas_init_dev(dev);
112 113
114 dev->port = port;
113 switch (dev->dev_type) { 115 switch (dev->dev_type) {
114 case SAS_END_DEV:
115 case SATA_DEV: 116 case SATA_DEV:
117 rc = sas_ata_init(dev);
118 if (rc) {
119 rphy = NULL;
120 break;
121 }
122 /* fall through */
123 case SAS_END_DEV:
116 rphy = sas_end_device_alloc(port->port); 124 rphy = sas_end_device_alloc(port->port);
117 break; 125 break;
118 case EDGE_DEV: 126 case EDGE_DEV:
@@ -131,19 +139,14 @@ static int sas_get_port_device(struct asd_sas_port *port)
131 139
132 if (!rphy) { 140 if (!rphy) {
133 sas_put_device(dev); 141 sas_put_device(dev);
134 return -ENODEV; 142 return rc;
135 } 143 }
136 144
137 spin_lock_irq(&port->phy_list_lock);
138 list_for_each_entry(phy, &port->phy_list, port_phy_el)
139 sas_phy_set_target(phy, dev);
140 spin_unlock_irq(&port->phy_list_lock);
141 rphy->identify.phy_identifier = phy->phy->identify.phy_identifier; 145 rphy->identify.phy_identifier = phy->phy->identify.phy_identifier;
142 memcpy(dev->sas_addr, port->attached_sas_addr, SAS_ADDR_SIZE); 146 memcpy(dev->sas_addr, port->attached_sas_addr, SAS_ADDR_SIZE);
143 sas_fill_in_rphy(dev, rphy); 147 sas_fill_in_rphy(dev, rphy);
144 sas_hash_addr(dev->hashed_sas_addr, dev->sas_addr); 148 sas_hash_addr(dev->hashed_sas_addr, dev->sas_addr);
145 port->port_dev = dev; 149 port->port_dev = dev;
146 dev->port = port;
147 dev->linkrate = port->linkrate; 150 dev->linkrate = port->linkrate;
148 dev->min_linkrate = port->linkrate; 151 dev->min_linkrate = port->linkrate;
149 dev->max_linkrate = port->linkrate; 152 dev->max_linkrate = port->linkrate;
@@ -155,6 +158,7 @@ static int sas_get_port_device(struct asd_sas_port *port)
155 sas_device_set_phy(dev, port->port); 158 sas_device_set_phy(dev, port->port);
156 159
157 dev->rphy = rphy; 160 dev->rphy = rphy;
161 get_device(&dev->rphy->dev);
158 162
159 if (dev_is_sata(dev) || dev->dev_type == SAS_END_DEV) 163 if (dev_is_sata(dev) || dev->dev_type == SAS_END_DEV)
160 list_add_tail(&dev->disco_list_node, &port->disco_list); 164 list_add_tail(&dev->disco_list_node, &port->disco_list);
@@ -164,6 +168,11 @@ static int sas_get_port_device(struct asd_sas_port *port)
164 spin_unlock_irq(&port->dev_list_lock); 168 spin_unlock_irq(&port->dev_list_lock);
165 } 169 }
166 170
171 spin_lock_irq(&port->phy_list_lock);
172 list_for_each_entry(phy, &port->phy_list, port_phy_el)
173 sas_phy_set_target(phy, dev);
174 spin_unlock_irq(&port->phy_list_lock);
175
167 return 0; 176 return 0;
168} 177}
169 178
@@ -205,8 +214,7 @@ void sas_notify_lldd_dev_gone(struct domain_device *dev)
205static void sas_probe_devices(struct work_struct *work) 214static void sas_probe_devices(struct work_struct *work)
206{ 215{
207 struct domain_device *dev, *n; 216 struct domain_device *dev, *n;
208 struct sas_discovery_event *ev = 217 struct sas_discovery_event *ev = to_sas_discovery_event(work);
209 container_of(work, struct sas_discovery_event, work);
210 struct asd_sas_port *port = ev->port; 218 struct asd_sas_port *port = ev->port;
211 219
212 clear_bit(DISCE_PROBE, &port->disc.pending); 220 clear_bit(DISCE_PROBE, &port->disc.pending);
@@ -255,6 +263,9 @@ void sas_free_device(struct kref *kref)
255{ 263{
256 struct domain_device *dev = container_of(kref, typeof(*dev), kref); 264 struct domain_device *dev = container_of(kref, typeof(*dev), kref);
257 265
266 put_device(&dev->rphy->dev);
267 dev->rphy = NULL;
268
258 if (dev->parent) 269 if (dev->parent)
259 sas_put_device(dev->parent); 270 sas_put_device(dev->parent);
260 271
@@ -291,8 +302,7 @@ static void sas_unregister_common_dev(struct asd_sas_port *port, struct domain_d
291static void sas_destruct_devices(struct work_struct *work) 302static void sas_destruct_devices(struct work_struct *work)
292{ 303{
293 struct domain_device *dev, *n; 304 struct domain_device *dev, *n;
294 struct sas_discovery_event *ev = 305 struct sas_discovery_event *ev = to_sas_discovery_event(work);
295 container_of(work, struct sas_discovery_event, work);
296 struct asd_sas_port *port = ev->port; 306 struct asd_sas_port *port = ev->port;
297 307
298 clear_bit(DISCE_DESTRUCT, &port->disc.pending); 308 clear_bit(DISCE_DESTRUCT, &port->disc.pending);
@@ -302,7 +312,6 @@ static void sas_destruct_devices(struct work_struct *work)
302 312
303 sas_remove_children(&dev->rphy->dev); 313 sas_remove_children(&dev->rphy->dev);
304 sas_rphy_delete(dev->rphy); 314 sas_rphy_delete(dev->rphy);
305 dev->rphy = NULL;
306 sas_unregister_common_dev(port, dev); 315 sas_unregister_common_dev(port, dev);
307 } 316 }
308} 317}
@@ -314,11 +323,11 @@ void sas_unregister_dev(struct asd_sas_port *port, struct domain_device *dev)
314 /* this rphy never saw sas_rphy_add */ 323 /* this rphy never saw sas_rphy_add */
315 list_del_init(&dev->disco_list_node); 324 list_del_init(&dev->disco_list_node);
316 sas_rphy_free(dev->rphy); 325 sas_rphy_free(dev->rphy);
317 dev->rphy = NULL;
318 sas_unregister_common_dev(port, dev); 326 sas_unregister_common_dev(port, dev);
327 return;
319 } 328 }
320 329
321 if (dev->rphy && !test_and_set_bit(SAS_DEV_DESTROY, &dev->state)) { 330 if (!test_and_set_bit(SAS_DEV_DESTROY, &dev->state)) {
322 sas_rphy_unlink(dev->rphy); 331 sas_rphy_unlink(dev->rphy);
323 list_move_tail(&dev->disco_list_node, &port->destroy_list); 332 list_move_tail(&dev->disco_list_node, &port->destroy_list);
324 sas_discover_event(dev->port, DISCE_DESTRUCT); 333 sas_discover_event(dev->port, DISCE_DESTRUCT);
@@ -377,8 +386,7 @@ static void sas_discover_domain(struct work_struct *work)
377{ 386{
378 struct domain_device *dev; 387 struct domain_device *dev;
379 int error = 0; 388 int error = 0;
380 struct sas_discovery_event *ev = 389 struct sas_discovery_event *ev = to_sas_discovery_event(work);
381 container_of(work, struct sas_discovery_event, work);
382 struct asd_sas_port *port = ev->port; 390 struct asd_sas_port *port = ev->port;
383 391
384 clear_bit(DISCE_DISCOVER_DOMAIN, &port->disc.pending); 392 clear_bit(DISCE_DISCOVER_DOMAIN, &port->disc.pending);
@@ -419,8 +427,6 @@ static void sas_discover_domain(struct work_struct *work)
419 427
420 if (error) { 428 if (error) {
421 sas_rphy_free(dev->rphy); 429 sas_rphy_free(dev->rphy);
422 dev->rphy = NULL;
423
424 list_del_init(&dev->disco_list_node); 430 list_del_init(&dev->disco_list_node);
425 spin_lock_irq(&port->dev_list_lock); 431 spin_lock_irq(&port->dev_list_lock);
426 list_del_init(&dev->dev_list_node); 432 list_del_init(&dev->dev_list_node);
@@ -437,8 +443,7 @@ static void sas_discover_domain(struct work_struct *work)
437static void sas_revalidate_domain(struct work_struct *work) 443static void sas_revalidate_domain(struct work_struct *work)
438{ 444{
439 int res = 0; 445 int res = 0;
440 struct sas_discovery_event *ev = 446 struct sas_discovery_event *ev = to_sas_discovery_event(work);
441 container_of(work, struct sas_discovery_event, work);
442 struct asd_sas_port *port = ev->port; 447 struct asd_sas_port *port = ev->port;
443 struct sas_ha_struct *ha = port->ha; 448 struct sas_ha_struct *ha = port->ha;
444 449
@@ -466,21 +471,25 @@ static void sas_revalidate_domain(struct work_struct *work)
466 471
467/* ---------- Events ---------- */ 472/* ---------- Events ---------- */
468 473
469static void sas_chain_work(struct sas_ha_struct *ha, struct work_struct *work) 474static void sas_chain_work(struct sas_ha_struct *ha, struct sas_work *sw)
470{ 475{
471 /* chained work is not subject to SA_HA_DRAINING or SAS_HA_REGISTERED */ 476 /* chained work is not subject to SA_HA_DRAINING or
472 scsi_queue_work(ha->core.shost, work); 477 * SAS_HA_REGISTERED, because it is either submitted in the
478 * workqueue, or known to be submitted from a context that is
479 * not racing against draining
480 */
481 scsi_queue_work(ha->core.shost, &sw->work);
473} 482}
474 483
475static void sas_chain_event(int event, unsigned long *pending, 484static void sas_chain_event(int event, unsigned long *pending,
476 struct work_struct *work, 485 struct sas_work *sw,
477 struct sas_ha_struct *ha) 486 struct sas_ha_struct *ha)
478{ 487{
479 if (!test_and_set_bit(event, pending)) { 488 if (!test_and_set_bit(event, pending)) {
480 unsigned long flags; 489 unsigned long flags;
481 490
482 spin_lock_irqsave(&ha->state_lock, flags); 491 spin_lock_irqsave(&ha->state_lock, flags);
483 sas_chain_work(ha, work); 492 sas_chain_work(ha, sw);
484 spin_unlock_irqrestore(&ha->state_lock, flags); 493 spin_unlock_irqrestore(&ha->state_lock, flags);
485 } 494 }
486} 495}
@@ -519,7 +528,7 @@ void sas_init_disc(struct sas_discovery *disc, struct asd_sas_port *port)
519 528
520 disc->pending = 0; 529 disc->pending = 0;
521 for (i = 0; i < DISC_NUM_EVENTS; i++) { 530 for (i = 0; i < DISC_NUM_EVENTS; i++) {
522 INIT_WORK(&disc->disc_work[i].work, sas_event_fns[i]); 531 INIT_SAS_WORK(&disc->disc_work[i].work, sas_event_fns[i]);
523 disc->disc_work[i].port = port; 532 disc->disc_work[i].port = port;
524 } 533 }
525} 534}
diff --git a/drivers/scsi/libsas/sas_event.c b/drivers/scsi/libsas/sas_event.c
index 16639bbae629..4e4292d210c1 100644
--- a/drivers/scsi/libsas/sas_event.c
+++ b/drivers/scsi/libsas/sas_event.c
@@ -27,19 +27,21 @@
27#include "sas_internal.h" 27#include "sas_internal.h"
28#include "sas_dump.h" 28#include "sas_dump.h"
29 29
30void sas_queue_work(struct sas_ha_struct *ha, struct work_struct *work) 30void sas_queue_work(struct sas_ha_struct *ha, struct sas_work *sw)
31{ 31{
32 if (!test_bit(SAS_HA_REGISTERED, &ha->state)) 32 if (!test_bit(SAS_HA_REGISTERED, &ha->state))
33 return; 33 return;
34 34
35 if (test_bit(SAS_HA_DRAINING, &ha->state)) 35 if (test_bit(SAS_HA_DRAINING, &ha->state)) {
36 list_add(&work->entry, &ha->defer_q); 36 /* add it to the defer list, if not already pending */
37 else 37 if (list_empty(&sw->drain_node))
38 scsi_queue_work(ha->core.shost, work); 38 list_add(&sw->drain_node, &ha->defer_q);
39 } else
40 scsi_queue_work(ha->core.shost, &sw->work);
39} 41}
40 42
41static void sas_queue_event(int event, unsigned long *pending, 43static void sas_queue_event(int event, unsigned long *pending,
42 struct work_struct *work, 44 struct sas_work *work,
43 struct sas_ha_struct *ha) 45 struct sas_ha_struct *ha)
44{ 46{
45 if (!test_and_set_bit(event, pending)) { 47 if (!test_and_set_bit(event, pending)) {
@@ -55,7 +57,7 @@ static void sas_queue_event(int event, unsigned long *pending,
55void __sas_drain_work(struct sas_ha_struct *ha) 57void __sas_drain_work(struct sas_ha_struct *ha)
56{ 58{
57 struct workqueue_struct *wq = ha->core.shost->work_q; 59 struct workqueue_struct *wq = ha->core.shost->work_q;
58 struct work_struct *w, *_w; 60 struct sas_work *sw, *_sw;
59 61
60 set_bit(SAS_HA_DRAINING, &ha->state); 62 set_bit(SAS_HA_DRAINING, &ha->state);
61 /* flush submitters */ 63 /* flush submitters */
@@ -66,9 +68,9 @@ void __sas_drain_work(struct sas_ha_struct *ha)
66 68
67 spin_lock_irq(&ha->state_lock); 69 spin_lock_irq(&ha->state_lock);
68 clear_bit(SAS_HA_DRAINING, &ha->state); 70 clear_bit(SAS_HA_DRAINING, &ha->state);
69 list_for_each_entry_safe(w, _w, &ha->defer_q, entry) { 71 list_for_each_entry_safe(sw, _sw, &ha->defer_q, drain_node) {
70 list_del_init(&w->entry); 72 list_del_init(&sw->drain_node);
71 sas_queue_work(ha, w); 73 sas_queue_work(ha, sw);
72 } 74 }
73 spin_unlock_irq(&ha->state_lock); 75 spin_unlock_irq(&ha->state_lock);
74} 76}
@@ -151,7 +153,7 @@ int sas_init_events(struct sas_ha_struct *sas_ha)
151 int i; 153 int i;
152 154
153 for (i = 0; i < HA_NUM_EVENTS; i++) { 155 for (i = 0; i < HA_NUM_EVENTS; i++) {
154 INIT_WORK(&sas_ha->ha_events[i].work, sas_ha_event_fns[i]); 156 INIT_SAS_WORK(&sas_ha->ha_events[i].work, sas_ha_event_fns[i]);
155 sas_ha->ha_events[i].ha = sas_ha; 157 sas_ha->ha_events[i].ha = sas_ha;
156 } 158 }
157 159
diff --git a/drivers/scsi/libsas/sas_expander.c b/drivers/scsi/libsas/sas_expander.c
index 05acd9e35fc4..caa0525d2523 100644
--- a/drivers/scsi/libsas/sas_expander.c
+++ b/drivers/scsi/libsas/sas_expander.c
@@ -202,6 +202,7 @@ static void sas_set_ex_phy(struct domain_device *dev, int phy_id, void *rsp)
202 u8 sas_addr[SAS_ADDR_SIZE]; 202 u8 sas_addr[SAS_ADDR_SIZE];
203 struct smp_resp *resp = rsp; 203 struct smp_resp *resp = rsp;
204 struct discover_resp *dr = &resp->disc; 204 struct discover_resp *dr = &resp->disc;
205 struct sas_ha_struct *ha = dev->port->ha;
205 struct expander_device *ex = &dev->ex_dev; 206 struct expander_device *ex = &dev->ex_dev;
206 struct ex_phy *phy = &ex->ex_phy[phy_id]; 207 struct ex_phy *phy = &ex->ex_phy[phy_id];
207 struct sas_rphy *rphy = dev->rphy; 208 struct sas_rphy *rphy = dev->rphy;
@@ -209,6 +210,8 @@ static void sas_set_ex_phy(struct domain_device *dev, int phy_id, void *rsp)
209 char *type; 210 char *type;
210 211
211 if (new_phy) { 212 if (new_phy) {
213 if (WARN_ON_ONCE(test_bit(SAS_HA_ATA_EH_ACTIVE, &ha->state)))
214 return;
212 phy->phy = sas_phy_alloc(&rphy->dev, phy_id); 215 phy->phy = sas_phy_alloc(&rphy->dev, phy_id);
213 216
214 /* FIXME: error_handling */ 217 /* FIXME: error_handling */
@@ -233,6 +236,8 @@ static void sas_set_ex_phy(struct domain_device *dev, int phy_id, void *rsp)
233 memcpy(sas_addr, phy->attached_sas_addr, SAS_ADDR_SIZE); 236 memcpy(sas_addr, phy->attached_sas_addr, SAS_ADDR_SIZE);
234 237
235 phy->attached_dev_type = to_dev_type(dr); 238 phy->attached_dev_type = to_dev_type(dr);
239 if (test_bit(SAS_HA_ATA_EH_ACTIVE, &ha->state))
240 goto out;
236 phy->phy_id = phy_id; 241 phy->phy_id = phy_id;
237 phy->linkrate = dr->linkrate; 242 phy->linkrate = dr->linkrate;
238 phy->attached_sata_host = dr->attached_sata_host; 243 phy->attached_sata_host = dr->attached_sata_host;
@@ -240,7 +245,14 @@ static void sas_set_ex_phy(struct domain_device *dev, int phy_id, void *rsp)
240 phy->attached_sata_ps = dr->attached_sata_ps; 245 phy->attached_sata_ps = dr->attached_sata_ps;
241 phy->attached_iproto = dr->iproto << 1; 246 phy->attached_iproto = dr->iproto << 1;
242 phy->attached_tproto = dr->tproto << 1; 247 phy->attached_tproto = dr->tproto << 1;
243 memcpy(phy->attached_sas_addr, dr->attached_sas_addr, SAS_ADDR_SIZE); 248 /* help some expanders that fail to zero sas_address in the 'no
249 * device' case
250 */
251 if (phy->attached_dev_type == NO_DEVICE ||
252 phy->linkrate < SAS_LINK_RATE_1_5_GBPS)
253 memset(phy->attached_sas_addr, 0, SAS_ADDR_SIZE);
254 else
255 memcpy(phy->attached_sas_addr, dr->attached_sas_addr, SAS_ADDR_SIZE);
244 phy->attached_phy_id = dr->attached_phy_id; 256 phy->attached_phy_id = dr->attached_phy_id;
245 phy->phy_change_count = dr->change_count; 257 phy->phy_change_count = dr->change_count;
246 phy->routing_attr = dr->routing_attr; 258 phy->routing_attr = dr->routing_attr;
@@ -266,6 +278,7 @@ static void sas_set_ex_phy(struct domain_device *dev, int phy_id, void *rsp)
266 return; 278 return;
267 } 279 }
268 280
281 out:
269 switch (phy->attached_dev_type) { 282 switch (phy->attached_dev_type) {
270 case SATA_PENDING: 283 case SATA_PENDING:
271 type = "stp pending"; 284 type = "stp pending";
@@ -304,7 +317,15 @@ static void sas_set_ex_phy(struct domain_device *dev, int phy_id, void *rsp)
304 else 317 else
305 return; 318 return;
306 319
307 SAS_DPRINTK("ex %016llx phy%02d:%c:%X attached: %016llx (%s)\n", 320 /* if the attached device type changed and ata_eh is active,
321 * make sure we run revalidation when eh completes (see:
322 * sas_enable_revalidation)
323 */
324 if (test_bit(SAS_HA_ATA_EH_ACTIVE, &ha->state))
325 set_bit(DISCE_REVALIDATE_DOMAIN, &dev->port->disc.pending);
326
327 SAS_DPRINTK("%sex %016llx phy%02d:%c:%X attached: %016llx (%s)\n",
328 test_bit(SAS_HA_ATA_EH_ACTIVE, &ha->state) ? "ata: " : "",
308 SAS_ADDR(dev->sas_addr), phy->phy_id, 329 SAS_ADDR(dev->sas_addr), phy->phy_id,
309 sas_route_char(dev, phy), phy->linkrate, 330 sas_route_char(dev, phy), phy->linkrate,
310 SAS_ADDR(phy->attached_sas_addr), type); 331 SAS_ADDR(phy->attached_sas_addr), type);
@@ -776,13 +797,16 @@ static struct domain_device *sas_ex_discover_end_dev(
776 if (res) 797 if (res)
777 goto out_free; 798 goto out_free;
778 799
800 sas_init_dev(child);
801 res = sas_ata_init(child);
802 if (res)
803 goto out_free;
779 rphy = sas_end_device_alloc(phy->port); 804 rphy = sas_end_device_alloc(phy->port);
780 if (unlikely(!rphy)) 805 if (!rphy)
781 goto out_free; 806 goto out_free;
782 807
783 sas_init_dev(child);
784
785 child->rphy = rphy; 808 child->rphy = rphy;
809 get_device(&rphy->dev);
786 810
787 list_add_tail(&child->disco_list_node, &parent->port->disco_list); 811 list_add_tail(&child->disco_list_node, &parent->port->disco_list);
788 812
@@ -806,6 +830,7 @@ static struct domain_device *sas_ex_discover_end_dev(
806 sas_init_dev(child); 830 sas_init_dev(child);
807 831
808 child->rphy = rphy; 832 child->rphy = rphy;
833 get_device(&rphy->dev);
809 sas_fill_in_rphy(child, rphy); 834 sas_fill_in_rphy(child, rphy);
810 835
811 list_add_tail(&child->disco_list_node, &parent->port->disco_list); 836 list_add_tail(&child->disco_list_node, &parent->port->disco_list);
@@ -830,8 +855,6 @@ static struct domain_device *sas_ex_discover_end_dev(
830 855
831 out_list_del: 856 out_list_del:
832 sas_rphy_free(child->rphy); 857 sas_rphy_free(child->rphy);
833 child->rphy = NULL;
834
835 list_del(&child->disco_list_node); 858 list_del(&child->disco_list_node);
836 spin_lock_irq(&parent->port->dev_list_lock); 859 spin_lock_irq(&parent->port->dev_list_lock);
837 list_del(&child->dev_list_node); 860 list_del(&child->dev_list_node);
@@ -911,6 +934,7 @@ static struct domain_device *sas_ex_discover_expander(
911 } 934 }
912 port = parent->port; 935 port = parent->port;
913 child->rphy = rphy; 936 child->rphy = rphy;
937 get_device(&rphy->dev);
914 edev = rphy_to_expander_device(rphy); 938 edev = rphy_to_expander_device(rphy);
915 child->dev_type = phy->attached_dev_type; 939 child->dev_type = phy->attached_dev_type;
916 kref_get(&parent->kref); 940 kref_get(&parent->kref);
@@ -934,6 +958,7 @@ static struct domain_device *sas_ex_discover_expander(
934 958
935 res = sas_discover_expander(child); 959 res = sas_discover_expander(child);
936 if (res) { 960 if (res) {
961 sas_rphy_delete(rphy);
937 spin_lock_irq(&parent->port->dev_list_lock); 962 spin_lock_irq(&parent->port->dev_list_lock);
938 list_del(&child->dev_list_node); 963 list_del(&child->dev_list_node);
939 spin_unlock_irq(&parent->port->dev_list_lock); 964 spin_unlock_irq(&parent->port->dev_list_lock);
@@ -1718,9 +1743,17 @@ static int sas_find_bcast_phy(struct domain_device *dev, int *phy_id,
1718 int phy_change_count = 0; 1743 int phy_change_count = 0;
1719 1744
1720 res = sas_get_phy_change_count(dev, i, &phy_change_count); 1745 res = sas_get_phy_change_count(dev, i, &phy_change_count);
1721 if (res) 1746 switch (res) {
1722 goto out; 1747 case SMP_RESP_PHY_VACANT:
1723 else if (phy_change_count != ex->ex_phy[i].phy_change_count) { 1748 case SMP_RESP_NO_PHY:
1749 continue;
1750 case SMP_RESP_FUNC_ACC:
1751 break;
1752 default:
1753 return res;
1754 }
1755
1756 if (phy_change_count != ex->ex_phy[i].phy_change_count) {
1724 if (update) 1757 if (update)
1725 ex->ex_phy[i].phy_change_count = 1758 ex->ex_phy[i].phy_change_count =
1726 phy_change_count; 1759 phy_change_count;
@@ -1728,8 +1761,7 @@ static int sas_find_bcast_phy(struct domain_device *dev, int *phy_id,
1728 return 0; 1761 return 0;
1729 } 1762 }
1730 } 1763 }
1731out: 1764 return 0;
1732 return res;
1733} 1765}
1734 1766
1735static int sas_get_ex_change_count(struct domain_device *dev, int *ecc) 1767static int sas_get_ex_change_count(struct domain_device *dev, int *ecc)
diff --git a/drivers/scsi/libsas/sas_init.c b/drivers/scsi/libsas/sas_init.c
index 120bff64be30..10cb5ae30977 100644
--- a/drivers/scsi/libsas/sas_init.c
+++ b/drivers/scsi/libsas/sas_init.c
@@ -94,8 +94,7 @@ void sas_hash_addr(u8 *hashed, const u8 *sas_addr)
94 94
95void sas_hae_reset(struct work_struct *work) 95void sas_hae_reset(struct work_struct *work)
96{ 96{
97 struct sas_ha_event *ev = 97 struct sas_ha_event *ev = to_sas_ha_event(work);
98 container_of(work, struct sas_ha_event, work);
99 struct sas_ha_struct *ha = ev->ha; 98 struct sas_ha_struct *ha = ev->ha;
100 99
101 clear_bit(HAE_RESET, &ha->pending); 100 clear_bit(HAE_RESET, &ha->pending);
@@ -369,14 +368,14 @@ static void sas_phy_release(struct sas_phy *phy)
369 368
370static void phy_reset_work(struct work_struct *work) 369static void phy_reset_work(struct work_struct *work)
371{ 370{
372 struct sas_phy_data *d = container_of(work, typeof(*d), reset_work); 371 struct sas_phy_data *d = container_of(work, typeof(*d), reset_work.work);
373 372
374 d->reset_result = transport_sas_phy_reset(d->phy, d->hard_reset); 373 d->reset_result = transport_sas_phy_reset(d->phy, d->hard_reset);
375} 374}
376 375
377static void phy_enable_work(struct work_struct *work) 376static void phy_enable_work(struct work_struct *work)
378{ 377{
379 struct sas_phy_data *d = container_of(work, typeof(*d), enable_work); 378 struct sas_phy_data *d = container_of(work, typeof(*d), enable_work.work);
380 379
381 d->enable_result = sas_phy_enable(d->phy, d->enable); 380 d->enable_result = sas_phy_enable(d->phy, d->enable);
382} 381}
@@ -389,8 +388,8 @@ static int sas_phy_setup(struct sas_phy *phy)
389 return -ENOMEM; 388 return -ENOMEM;
390 389
391 mutex_init(&d->event_lock); 390 mutex_init(&d->event_lock);
392 INIT_WORK(&d->reset_work, phy_reset_work); 391 INIT_SAS_WORK(&d->reset_work, phy_reset_work);
393 INIT_WORK(&d->enable_work, phy_enable_work); 392 INIT_SAS_WORK(&d->enable_work, phy_enable_work);
394 d->phy = phy; 393 d->phy = phy;
395 phy->hostdata = d; 394 phy->hostdata = d;
396 395
diff --git a/drivers/scsi/libsas/sas_internal.h b/drivers/scsi/libsas/sas_internal.h
index f05c63879949..507e4cf12e56 100644
--- a/drivers/scsi/libsas/sas_internal.h
+++ b/drivers/scsi/libsas/sas_internal.h
@@ -45,10 +45,10 @@ struct sas_phy_data {
45 struct mutex event_lock; 45 struct mutex event_lock;
46 int hard_reset; 46 int hard_reset;
47 int reset_result; 47 int reset_result;
48 struct work_struct reset_work; 48 struct sas_work reset_work;
49 int enable; 49 int enable;
50 int enable_result; 50 int enable_result;
51 struct work_struct enable_work; 51 struct sas_work enable_work;
52}; 52};
53 53
54void sas_scsi_recover_host(struct Scsi_Host *shost); 54void sas_scsi_recover_host(struct Scsi_Host *shost);
@@ -80,7 +80,7 @@ void sas_porte_broadcast_rcvd(struct work_struct *work);
80void sas_porte_link_reset_err(struct work_struct *work); 80void sas_porte_link_reset_err(struct work_struct *work);
81void sas_porte_timer_event(struct work_struct *work); 81void sas_porte_timer_event(struct work_struct *work);
82void sas_porte_hard_reset(struct work_struct *work); 82void sas_porte_hard_reset(struct work_struct *work);
83void sas_queue_work(struct sas_ha_struct *ha, struct work_struct *work); 83void sas_queue_work(struct sas_ha_struct *ha, struct sas_work *sw);
84 84
85int sas_notify_lldd_dev_found(struct domain_device *); 85int sas_notify_lldd_dev_found(struct domain_device *);
86void sas_notify_lldd_dev_gone(struct domain_device *); 86void sas_notify_lldd_dev_gone(struct domain_device *);
diff --git a/drivers/scsi/libsas/sas_phy.c b/drivers/scsi/libsas/sas_phy.c
index dcfd4a9105c5..521422e857ab 100644
--- a/drivers/scsi/libsas/sas_phy.c
+++ b/drivers/scsi/libsas/sas_phy.c
@@ -32,8 +32,7 @@
32 32
33static void sas_phye_loss_of_signal(struct work_struct *work) 33static void sas_phye_loss_of_signal(struct work_struct *work)
34{ 34{
35 struct asd_sas_event *ev = 35 struct asd_sas_event *ev = to_asd_sas_event(work);
36 container_of(work, struct asd_sas_event, work);
37 struct asd_sas_phy *phy = ev->phy; 36 struct asd_sas_phy *phy = ev->phy;
38 37
39 clear_bit(PHYE_LOSS_OF_SIGNAL, &phy->phy_events_pending); 38 clear_bit(PHYE_LOSS_OF_SIGNAL, &phy->phy_events_pending);
@@ -43,8 +42,7 @@ static void sas_phye_loss_of_signal(struct work_struct *work)
43 42
44static void sas_phye_oob_done(struct work_struct *work) 43static void sas_phye_oob_done(struct work_struct *work)
45{ 44{
46 struct asd_sas_event *ev = 45 struct asd_sas_event *ev = to_asd_sas_event(work);
47 container_of(work, struct asd_sas_event, work);
48 struct asd_sas_phy *phy = ev->phy; 46 struct asd_sas_phy *phy = ev->phy;
49 47
50 clear_bit(PHYE_OOB_DONE, &phy->phy_events_pending); 48 clear_bit(PHYE_OOB_DONE, &phy->phy_events_pending);
@@ -53,8 +51,7 @@ static void sas_phye_oob_done(struct work_struct *work)
53 51
54static void sas_phye_oob_error(struct work_struct *work) 52static void sas_phye_oob_error(struct work_struct *work)
55{ 53{
56 struct asd_sas_event *ev = 54 struct asd_sas_event *ev = to_asd_sas_event(work);
57 container_of(work, struct asd_sas_event, work);
58 struct asd_sas_phy *phy = ev->phy; 55 struct asd_sas_phy *phy = ev->phy;
59 struct sas_ha_struct *sas_ha = phy->ha; 56 struct sas_ha_struct *sas_ha = phy->ha;
60 struct asd_sas_port *port = phy->port; 57 struct asd_sas_port *port = phy->port;
@@ -85,8 +82,7 @@ static void sas_phye_oob_error(struct work_struct *work)
85 82
86static void sas_phye_spinup_hold(struct work_struct *work) 83static void sas_phye_spinup_hold(struct work_struct *work)
87{ 84{
88 struct asd_sas_event *ev = 85 struct asd_sas_event *ev = to_asd_sas_event(work);
89 container_of(work, struct asd_sas_event, work);
90 struct asd_sas_phy *phy = ev->phy; 86 struct asd_sas_phy *phy = ev->phy;
91 struct sas_ha_struct *sas_ha = phy->ha; 87 struct sas_ha_struct *sas_ha = phy->ha;
92 struct sas_internal *i = 88 struct sas_internal *i =
@@ -127,14 +123,12 @@ int sas_register_phys(struct sas_ha_struct *sas_ha)
127 phy->error = 0; 123 phy->error = 0;
128 INIT_LIST_HEAD(&phy->port_phy_el); 124 INIT_LIST_HEAD(&phy->port_phy_el);
129 for (k = 0; k < PORT_NUM_EVENTS; k++) { 125 for (k = 0; k < PORT_NUM_EVENTS; k++) {
130 INIT_WORK(&phy->port_events[k].work, 126 INIT_SAS_WORK(&phy->port_events[k].work, sas_port_event_fns[k]);
131 sas_port_event_fns[k]);
132 phy->port_events[k].phy = phy; 127 phy->port_events[k].phy = phy;
133 } 128 }
134 129
135 for (k = 0; k < PHY_NUM_EVENTS; k++) { 130 for (k = 0; k < PHY_NUM_EVENTS; k++) {
136 INIT_WORK(&phy->phy_events[k].work, 131 INIT_SAS_WORK(&phy->phy_events[k].work, sas_phy_event_fns[k]);
137 sas_phy_event_fns[k]);
138 phy->phy_events[k].phy = phy; 132 phy->phy_events[k].phy = phy;
139 } 133 }
140 134
@@ -144,8 +138,7 @@ int sas_register_phys(struct sas_ha_struct *sas_ha)
144 spin_lock_init(&phy->sas_prim_lock); 138 spin_lock_init(&phy->sas_prim_lock);
145 phy->frame_rcvd_size = 0; 139 phy->frame_rcvd_size = 0;
146 140
147 phy->phy = sas_phy_alloc(&sas_ha->core.shost->shost_gendev, 141 phy->phy = sas_phy_alloc(&sas_ha->core.shost->shost_gendev, i);
148 i);
149 if (!phy->phy) 142 if (!phy->phy)
150 return -ENOMEM; 143 return -ENOMEM;
151 144
diff --git a/drivers/scsi/libsas/sas_port.c b/drivers/scsi/libsas/sas_port.c
index eb19c016d500..e884a8c58a0c 100644
--- a/drivers/scsi/libsas/sas_port.c
+++ b/drivers/scsi/libsas/sas_port.c
@@ -123,7 +123,7 @@ static void sas_form_port(struct asd_sas_phy *phy)
123 spin_unlock_irqrestore(&sas_ha->phy_port_lock, flags); 123 spin_unlock_irqrestore(&sas_ha->phy_port_lock, flags);
124 124
125 if (!port->port) { 125 if (!port->port) {
126 port->port = sas_port_alloc(phy->phy->dev.parent, phy->id); 126 port->port = sas_port_alloc(phy->phy->dev.parent, port->id);
127 BUG_ON(!port->port); 127 BUG_ON(!port->port);
128 sas_port_add(port->port); 128 sas_port_add(port->port);
129 } 129 }
@@ -208,8 +208,7 @@ void sas_deform_port(struct asd_sas_phy *phy, int gone)
208 208
209void sas_porte_bytes_dmaed(struct work_struct *work) 209void sas_porte_bytes_dmaed(struct work_struct *work)
210{ 210{
211 struct asd_sas_event *ev = 211 struct asd_sas_event *ev = to_asd_sas_event(work);
212 container_of(work, struct asd_sas_event, work);
213 struct asd_sas_phy *phy = ev->phy; 212 struct asd_sas_phy *phy = ev->phy;
214 213
215 clear_bit(PORTE_BYTES_DMAED, &phy->port_events_pending); 214 clear_bit(PORTE_BYTES_DMAED, &phy->port_events_pending);
@@ -219,8 +218,7 @@ void sas_porte_bytes_dmaed(struct work_struct *work)
219 218
220void sas_porte_broadcast_rcvd(struct work_struct *work) 219void sas_porte_broadcast_rcvd(struct work_struct *work)
221{ 220{
222 struct asd_sas_event *ev = 221 struct asd_sas_event *ev = to_asd_sas_event(work);
223 container_of(work, struct asd_sas_event, work);
224 struct asd_sas_phy *phy = ev->phy; 222 struct asd_sas_phy *phy = ev->phy;
225 unsigned long flags; 223 unsigned long flags;
226 u32 prim; 224 u32 prim;
@@ -237,8 +235,7 @@ void sas_porte_broadcast_rcvd(struct work_struct *work)
237 235
238void sas_porte_link_reset_err(struct work_struct *work) 236void sas_porte_link_reset_err(struct work_struct *work)
239{ 237{
240 struct asd_sas_event *ev = 238 struct asd_sas_event *ev = to_asd_sas_event(work);
241 container_of(work, struct asd_sas_event, work);
242 struct asd_sas_phy *phy = ev->phy; 239 struct asd_sas_phy *phy = ev->phy;
243 240
244 clear_bit(PORTE_LINK_RESET_ERR, &phy->port_events_pending); 241 clear_bit(PORTE_LINK_RESET_ERR, &phy->port_events_pending);
@@ -248,8 +245,7 @@ void sas_porte_link_reset_err(struct work_struct *work)
248 245
249void sas_porte_timer_event(struct work_struct *work) 246void sas_porte_timer_event(struct work_struct *work)
250{ 247{
251 struct asd_sas_event *ev = 248 struct asd_sas_event *ev = to_asd_sas_event(work);
252 container_of(work, struct asd_sas_event, work);
253 struct asd_sas_phy *phy = ev->phy; 249 struct asd_sas_phy *phy = ev->phy;
254 250
255 clear_bit(PORTE_TIMER_EVENT, &phy->port_events_pending); 251 clear_bit(PORTE_TIMER_EVENT, &phy->port_events_pending);
@@ -259,8 +255,7 @@ void sas_porte_timer_event(struct work_struct *work)
259 255
260void sas_porte_hard_reset(struct work_struct *work) 256void sas_porte_hard_reset(struct work_struct *work)
261{ 257{
262 struct asd_sas_event *ev = 258 struct asd_sas_event *ev = to_asd_sas_event(work);
263 container_of(work, struct asd_sas_event, work);
264 struct asd_sas_phy *phy = ev->phy; 259 struct asd_sas_phy *phy = ev->phy;
265 260
266 clear_bit(PORTE_HARD_RESET, &phy->port_events_pending); 261 clear_bit(PORTE_HARD_RESET, &phy->port_events_pending);
diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
index 5bdf2eecb178..af04b0d6688d 100644
--- a/drivers/scsi/lpfc/lpfc_debugfs.c
+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
@@ -997,13 +997,6 @@ lpfc_debugfs_dumpDataDif_write(struct file *file, const char __user *buf,
997 return nbytes; 997 return nbytes;
998} 998}
999 999
1000static int
1001lpfc_debugfs_dif_err_open(struct inode *inode, struct file *file)
1002{
1003 file->private_data = inode->i_private;
1004 return 0;
1005}
1006
1007static ssize_t 1000static ssize_t
1008lpfc_debugfs_dif_err_read(struct file *file, char __user *buf, 1001lpfc_debugfs_dif_err_read(struct file *file, char __user *buf,
1009 size_t nbytes, loff_t *ppos) 1002 size_t nbytes, loff_t *ppos)
@@ -3541,7 +3534,7 @@ static const struct file_operations lpfc_debugfs_op_dumpDif = {
3541#undef lpfc_debugfs_op_dif_err 3534#undef lpfc_debugfs_op_dif_err
3542static const struct file_operations lpfc_debugfs_op_dif_err = { 3535static const struct file_operations lpfc_debugfs_op_dif_err = {
3543 .owner = THIS_MODULE, 3536 .owner = THIS_MODULE,
3544 .open = lpfc_debugfs_dif_err_open, 3537 .open = simple_open,
3545 .llseek = lpfc_debugfs_lseek, 3538 .llseek = lpfc_debugfs_lseek,
3546 .read = lpfc_debugfs_dif_err_read, 3539 .read = lpfc_debugfs_dif_err_read,
3547 .write = lpfc_debugfs_dif_err_write, 3540 .write = lpfc_debugfs_dif_err_write,
diff --git a/drivers/scsi/qla2xxx/qla_bsg.c b/drivers/scsi/qla2xxx/qla_bsg.c
index f74cc0602f3b..bc3cc6d91117 100644
--- a/drivers/scsi/qla2xxx/qla_bsg.c
+++ b/drivers/scsi/qla2xxx/qla_bsg.c
@@ -1367,6 +1367,9 @@ qla2x00_read_optrom(struct fc_bsg_job *bsg_job)
1367 struct qla_hw_data *ha = vha->hw; 1367 struct qla_hw_data *ha = vha->hw;
1368 int rval = 0; 1368 int rval = 0;
1369 1369
1370 if (ha->flags.isp82xx_reset_hdlr_active)
1371 return -EBUSY;
1372
1370 rval = qla2x00_optrom_setup(bsg_job, vha, 0); 1373 rval = qla2x00_optrom_setup(bsg_job, vha, 0);
1371 if (rval) 1374 if (rval)
1372 return rval; 1375 return rval;
diff --git a/drivers/scsi/qla2xxx/qla_dbg.c b/drivers/scsi/qla2xxx/qla_dbg.c
index 897731b93df2..62324a1d5573 100644
--- a/drivers/scsi/qla2xxx/qla_dbg.c
+++ b/drivers/scsi/qla2xxx/qla_dbg.c
@@ -15,7 +15,7 @@
15 * | Mailbox commands | 0x113e | 0x112c-0x112e | 15 * | Mailbox commands | 0x113e | 0x112c-0x112e |
16 * | | | 0x113a | 16 * | | | 0x113a |
17 * | Device Discovery | 0x2086 | 0x2020-0x2022 | 17 * | Device Discovery | 0x2086 | 0x2020-0x2022 |
18 * | Queue Command and IO tracing | 0x302f | 0x3006,0x3008 | 18 * | Queue Command and IO tracing | 0x3030 | 0x3006,0x3008 |
19 * | | | 0x302d-0x302e | 19 * | | | 0x302d-0x302e |
20 * | DPC Thread | 0x401c | | 20 * | DPC Thread | 0x401c | |
21 * | Async Events | 0x505d | 0x502b-0x502f | 21 * | Async Events | 0x505d | 0x502b-0x502f |
diff --git a/drivers/scsi/qla2xxx/qla_isr.c b/drivers/scsi/qla2xxx/qla_isr.c
index f79844ce7122..ce42288049b5 100644
--- a/drivers/scsi/qla2xxx/qla_isr.c
+++ b/drivers/scsi/qla2xxx/qla_isr.c
@@ -1715,13 +1715,24 @@ qla2x00_status_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, void *pkt)
1715 res = DID_ERROR << 16; 1715 res = DID_ERROR << 16;
1716 break; 1716 break;
1717 } 1717 }
1718 } else { 1718 } else if (lscsi_status != SAM_STAT_TASK_SET_FULL &&
1719 lscsi_status != SAM_STAT_BUSY) {
1720 /*
1721 * scsi status of task set and busy are considered to be
1722 * task not completed.
1723 */
1724
1719 ql_dbg(ql_dbg_io, fcport->vha, 0x301f, 1725 ql_dbg(ql_dbg_io, fcport->vha, 0x301f,
1720 "Dropped frame(s) detected (0x%x " 1726 "Dropped frame(s) detected (0x%x "
1721 "of 0x%x bytes).\n", resid, scsi_bufflen(cp)); 1727 "of 0x%x bytes).\n", resid,
1728 scsi_bufflen(cp));
1722 1729
1723 res = DID_ERROR << 16 | lscsi_status; 1730 res = DID_ERROR << 16 | lscsi_status;
1724 goto check_scsi_status; 1731 goto check_scsi_status;
1732 } else {
1733 ql_dbg(ql_dbg_io, fcport->vha, 0x3030,
1734 "scsi_status: 0x%x, lscsi_status: 0x%x\n",
1735 scsi_status, lscsi_status);
1725 } 1736 }
1726 1737
1727 res = DID_OK << 16 | lscsi_status; 1738 res = DID_OK << 16 | lscsi_status;
diff --git a/drivers/scsi/qla2xxx/qla_nx.c b/drivers/scsi/qla2xxx/qla_nx.c
index f0528539bbbc..de722a933438 100644
--- a/drivers/scsi/qla2xxx/qla_nx.c
+++ b/drivers/scsi/qla2xxx/qla_nx.c
@@ -3125,6 +3125,7 @@ qla82xx_need_reset_handler(scsi_qla_host_t *vha)
3125 ql_log(ql_log_info, vha, 0x00b7, 3125 ql_log(ql_log_info, vha, 0x00b7,
3126 "HW State: COLD/RE-INIT.\n"); 3126 "HW State: COLD/RE-INIT.\n");
3127 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE, QLA82XX_DEV_COLD); 3127 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE, QLA82XX_DEV_COLD);
3128 qla82xx_set_rst_ready(ha);
3128 if (ql2xmdenable) { 3129 if (ql2xmdenable) {
3129 if (qla82xx_md_collect(vha)) 3130 if (qla82xx_md_collect(vha))
3130 ql_log(ql_log_warn, vha, 0xb02c, 3131 ql_log(ql_log_warn, vha, 0xb02c,
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index a2f999273a5f..7db803377c64 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -3577,9 +3577,25 @@ void qla2x00_relogin(struct scsi_qla_host *vha)
3577 continue; 3577 continue;
3578 /* Attempt a retry. */ 3578 /* Attempt a retry. */
3579 status = 1; 3579 status = 1;
3580 } else 3580 } else {
3581 status = qla2x00_fabric_login(vha, 3581 status = qla2x00_fabric_login(vha,
3582 fcport, &next_loopid); 3582 fcport, &next_loopid);
3583 if (status == QLA_SUCCESS) {
3584 int status2;
3585 uint8_t opts;
3586
3587 opts = 0;
3588 if (fcport->flags &
3589 FCF_FCP2_DEVICE)
3590 opts |= BIT_1;
3591 status2 =
3592 qla2x00_get_port_database(
3593 vha, fcport,
3594 opts);
3595 if (status2 != QLA_SUCCESS)
3596 status = 1;
3597 }
3598 }
3583 } else 3599 } else
3584 status = qla2x00_local_device_login(vha, 3600 status = qla2x00_local_device_login(vha,
3585 fcport); 3601 fcport);
diff --git a/drivers/scsi/qla2xxx/qla_sup.c b/drivers/scsi/qla2xxx/qla_sup.c
index 3c13c0a6be63..a683e766d1ae 100644
--- a/drivers/scsi/qla2xxx/qla_sup.c
+++ b/drivers/scsi/qla2xxx/qla_sup.c
@@ -1017,6 +1017,9 @@ qla2xxx_flash_npiv_conf(scsi_qla_host_t *vha)
1017 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha)) 1017 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha))
1018 return; 1018 return;
1019 1019
1020 if (ha->flags.isp82xx_reset_hdlr_active)
1021 return;
1022
1020 ha->isp_ops->read_optrom(vha, (uint8_t *)&hdr, 1023 ha->isp_ops->read_optrom(vha, (uint8_t *)&hdr,
1021 ha->flt_region_npiv_conf << 2, sizeof(struct qla_npiv_header)); 1024 ha->flt_region_npiv_conf << 2, sizeof(struct qla_npiv_header));
1022 if (hdr.version == __constant_cpu_to_le16(0xffff)) 1025 if (hdr.version == __constant_cpu_to_le16(0xffff))
diff --git a/drivers/scsi/qla2xxx/qla_version.h b/drivers/scsi/qla2xxx/qla_version.h
index 29d780c38040..f5fdb16bec9b 100644
--- a/drivers/scsi/qla2xxx/qla_version.h
+++ b/drivers/scsi/qla2xxx/qla_version.h
@@ -7,9 +7,9 @@
7/* 7/*
8 * Driver version 8 * Driver version
9 */ 9 */
10#define QLA2XXX_VERSION "8.03.07.13-k" 10#define QLA2XXX_VERSION "8.04.00.03-k"
11 11
12#define QLA_DRIVER_MAJOR_VER 8 12#define QLA_DRIVER_MAJOR_VER 8
13#define QLA_DRIVER_MINOR_VER 3 13#define QLA_DRIVER_MINOR_VER 4
14#define QLA_DRIVER_PATCH_VER 7 14#define QLA_DRIVER_PATCH_VER 0
15#define QLA_DRIVER_BETA_VER 3 15#define QLA_DRIVER_BETA_VER 3
diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c
index 2cfcbffa41fd..386f0c53bea7 100644
--- a/drivers/scsi/scsi_error.c
+++ b/drivers/scsi/scsi_error.c
@@ -835,7 +835,7 @@ static int scsi_send_eh_cmnd(struct scsi_cmnd *scmd, unsigned char *cmnd,
835 835
836 scsi_eh_restore_cmnd(scmd, &ses); 836 scsi_eh_restore_cmnd(scmd, &ses);
837 837
838 if (sdrv->eh_action) 838 if (sdrv && sdrv->eh_action)
839 rtn = sdrv->eh_action(scmd, cmnd, cmnd_size, rtn); 839 rtn = sdrv->eh_action(scmd, cmnd, cmnd_size, rtn);
840 840
841 return rtn; 841 return rtn;
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index ead6405f3e51..5dfd7495d1a1 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -1638,7 +1638,7 @@ struct request_queue *__scsi_alloc_queue(struct Scsi_Host *shost,
1638 request_fn_proc *request_fn) 1638 request_fn_proc *request_fn)
1639{ 1639{
1640 struct request_queue *q; 1640 struct request_queue *q;
1641 struct device *dev = shost->shost_gendev.parent; 1641 struct device *dev = shost->dma_dev;
1642 1642
1643 q = blk_init_queue(request_fn, NULL); 1643 q = blk_init_queue(request_fn, NULL);
1644 if (!q) 1644 if (!q)
diff --git a/drivers/scsi/virtio_scsi.c b/drivers/scsi/virtio_scsi.c
index efccd72c4a3e..1b3843117268 100644
--- a/drivers/scsi/virtio_scsi.c
+++ b/drivers/scsi/virtio_scsi.c
@@ -175,7 +175,8 @@ static void virtscsi_complete_free(void *buf)
175 175
176 if (cmd->comp) 176 if (cmd->comp)
177 complete_all(cmd->comp); 177 complete_all(cmd->comp);
178 mempool_free(cmd, virtscsi_cmd_pool); 178 else
179 mempool_free(cmd, virtscsi_cmd_pool);
179} 180}
180 181
181static void virtscsi_ctrl_done(struct virtqueue *vq) 182static void virtscsi_ctrl_done(struct virtqueue *vq)
@@ -311,21 +312,22 @@ out:
311static int virtscsi_tmf(struct virtio_scsi *vscsi, struct virtio_scsi_cmd *cmd) 312static int virtscsi_tmf(struct virtio_scsi *vscsi, struct virtio_scsi_cmd *cmd)
312{ 313{
313 DECLARE_COMPLETION_ONSTACK(comp); 314 DECLARE_COMPLETION_ONSTACK(comp);
314 int ret; 315 int ret = FAILED;
315 316
316 cmd->comp = &comp; 317 cmd->comp = &comp;
317 ret = virtscsi_kick_cmd(vscsi, vscsi->ctrl_vq, cmd, 318 if (virtscsi_kick_cmd(vscsi, vscsi->ctrl_vq, cmd,
318 sizeof cmd->req.tmf, sizeof cmd->resp.tmf, 319 sizeof cmd->req.tmf, sizeof cmd->resp.tmf,
319 GFP_NOIO); 320 GFP_NOIO) < 0)
320 if (ret < 0) 321 goto out;
321 return FAILED;
322 322
323 wait_for_completion(&comp); 323 wait_for_completion(&comp);
324 if (cmd->resp.tmf.response != VIRTIO_SCSI_S_OK && 324 if (cmd->resp.tmf.response == VIRTIO_SCSI_S_OK ||
325 cmd->resp.tmf.response != VIRTIO_SCSI_S_FUNCTION_SUCCEEDED) 325 cmd->resp.tmf.response == VIRTIO_SCSI_S_FUNCTION_SUCCEEDED)
326 return FAILED; 326 ret = SUCCESS;
327 327
328 return SUCCESS; 328out:
329 mempool_free(cmd, virtscsi_cmd_pool);
330 return ret;
329} 331}
330 332
331static int virtscsi_device_reset(struct scsi_cmnd *sc) 333static int virtscsi_device_reset(struct scsi_cmnd *sc)
diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index 3ed748355b98..00c024039c97 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -74,7 +74,7 @@ config SPI_ATMEL
74 This selects a driver for the Atmel SPI Controller, present on 74 This selects a driver for the Atmel SPI Controller, present on
75 many AT32 (AVR32) and AT91 (ARM) chips. 75 many AT32 (AVR32) and AT91 (ARM) chips.
76 76
77config SPI_BFIN 77config SPI_BFIN5XX
78 tristate "SPI controller driver for ADI Blackfin5xx" 78 tristate "SPI controller driver for ADI Blackfin5xx"
79 depends on BLACKFIN 79 depends on BLACKFIN
80 help 80 help
diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile
index a1d48e0ba3dc..9d75d2198ff5 100644
--- a/drivers/spi/Makefile
+++ b/drivers/spi/Makefile
@@ -15,7 +15,7 @@ obj-$(CONFIG_SPI_ATMEL) += spi-atmel.o
15obj-$(CONFIG_SPI_ATH79) += spi-ath79.o 15obj-$(CONFIG_SPI_ATH79) += spi-ath79.o
16obj-$(CONFIG_SPI_AU1550) += spi-au1550.o 16obj-$(CONFIG_SPI_AU1550) += spi-au1550.o
17obj-$(CONFIG_SPI_BCM63XX) += spi-bcm63xx.o 17obj-$(CONFIG_SPI_BCM63XX) += spi-bcm63xx.o
18obj-$(CONFIG_SPI_BFIN) += spi-bfin5xx.o 18obj-$(CONFIG_SPI_BFIN5XX) += spi-bfin5xx.o
19obj-$(CONFIG_SPI_BFIN_SPORT) += spi-bfin-sport.o 19obj-$(CONFIG_SPI_BFIN_SPORT) += spi-bfin-sport.o
20obj-$(CONFIG_SPI_BITBANG) += spi-bitbang.o 20obj-$(CONFIG_SPI_BITBANG) += spi-bitbang.o
21obj-$(CONFIG_SPI_BUTTERFLY) += spi-butterfly.o 21obj-$(CONFIG_SPI_BUTTERFLY) += spi-butterfly.o
diff --git a/drivers/spi/spi-bcm63xx.c b/drivers/spi/spi-bcm63xx.c
index f01b2648452e..7491971139a6 100644
--- a/drivers/spi/spi-bcm63xx.c
+++ b/drivers/spi/spi-bcm63xx.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Broadcom BCM63xx SPI controller support 2 * Broadcom BCM63xx SPI controller support
3 * 3 *
4 * Copyright (C) 2009-2011 Florian Fainelli <florian@openwrt.org> 4 * Copyright (C) 2009-2012 Florian Fainelli <florian@openwrt.org>
5 * Copyright (C) 2010 Tanguy Bouzeloc <tanguy.bouzeloc@efixo.com> 5 * Copyright (C) 2010 Tanguy Bouzeloc <tanguy.bouzeloc@efixo.com>
6 * 6 *
7 * This program is free software; you can redistribute it and/or 7 * This program is free software; you can redistribute it and/or
@@ -30,6 +30,8 @@
30#include <linux/spi/spi.h> 30#include <linux/spi/spi.h>
31#include <linux/completion.h> 31#include <linux/completion.h>
32#include <linux/err.h> 32#include <linux/err.h>
33#include <linux/workqueue.h>
34#include <linux/pm_runtime.h>
33 35
34#include <bcm63xx_dev_spi.h> 36#include <bcm63xx_dev_spi.h>
35 37
@@ -37,8 +39,6 @@
37#define DRV_VER "0.1.2" 39#define DRV_VER "0.1.2"
38 40
39struct bcm63xx_spi { 41struct bcm63xx_spi {
40 spinlock_t lock;
41 int stopping;
42 struct completion done; 42 struct completion done;
43 43
44 void __iomem *regs; 44 void __iomem *regs;
@@ -96,17 +96,12 @@ static const unsigned bcm63xx_spi_freq_table[SPI_CLK_MASK][2] = {
96 { 391000, SPI_CLK_0_391MHZ } 96 { 391000, SPI_CLK_0_391MHZ }
97}; 97};
98 98
99static int bcm63xx_spi_setup_transfer(struct spi_device *spi, 99static int bcm63xx_spi_check_transfer(struct spi_device *spi,
100 struct spi_transfer *t) 100 struct spi_transfer *t)
101{ 101{
102 struct bcm63xx_spi *bs = spi_master_get_devdata(spi->master);
103 u8 bits_per_word; 102 u8 bits_per_word;
104 u8 clk_cfg, reg;
105 u32 hz;
106 int i;
107 103
108 bits_per_word = (t) ? t->bits_per_word : spi->bits_per_word; 104 bits_per_word = (t) ? t->bits_per_word : spi->bits_per_word;
109 hz = (t) ? t->speed_hz : spi->max_speed_hz;
110 if (bits_per_word != 8) { 105 if (bits_per_word != 8) {
111 dev_err(&spi->dev, "%s, unsupported bits_per_word=%d\n", 106 dev_err(&spi->dev, "%s, unsupported bits_per_word=%d\n",
112 __func__, bits_per_word); 107 __func__, bits_per_word);
@@ -119,6 +114,19 @@ static int bcm63xx_spi_setup_transfer(struct spi_device *spi,
119 return -EINVAL; 114 return -EINVAL;
120 } 115 }
121 116
117 return 0;
118}
119
120static void bcm63xx_spi_setup_transfer(struct spi_device *spi,
121 struct spi_transfer *t)
122{
123 struct bcm63xx_spi *bs = spi_master_get_devdata(spi->master);
124 u32 hz;
125 u8 clk_cfg, reg;
126 int i;
127
128 hz = (t) ? t->speed_hz : spi->max_speed_hz;
129
122 /* Find the closest clock configuration */ 130 /* Find the closest clock configuration */
123 for (i = 0; i < SPI_CLK_MASK; i++) { 131 for (i = 0; i < SPI_CLK_MASK; i++) {
124 if (hz <= bcm63xx_spi_freq_table[i][0]) { 132 if (hz <= bcm63xx_spi_freq_table[i][0]) {
@@ -139,8 +147,6 @@ static int bcm63xx_spi_setup_transfer(struct spi_device *spi,
139 bcm_spi_writeb(bs, reg, SPI_CLK_CFG); 147 bcm_spi_writeb(bs, reg, SPI_CLK_CFG);
140 dev_dbg(&spi->dev, "Setting clock register to %02x (hz %d)\n", 148 dev_dbg(&spi->dev, "Setting clock register to %02x (hz %d)\n",
141 clk_cfg, hz); 149 clk_cfg, hz);
142
143 return 0;
144} 150}
145 151
146/* the spi->mode bits understood by this driver: */ 152/* the spi->mode bits understood by this driver: */
@@ -153,9 +159,6 @@ static int bcm63xx_spi_setup(struct spi_device *spi)
153 159
154 bs = spi_master_get_devdata(spi->master); 160 bs = spi_master_get_devdata(spi->master);
155 161
156 if (bs->stopping)
157 return -ESHUTDOWN;
158
159 if (!spi->bits_per_word) 162 if (!spi->bits_per_word)
160 spi->bits_per_word = 8; 163 spi->bits_per_word = 8;
161 164
@@ -165,7 +168,7 @@ static int bcm63xx_spi_setup(struct spi_device *spi)
165 return -EINVAL; 168 return -EINVAL;
166 } 169 }
167 170
168 ret = bcm63xx_spi_setup_transfer(spi, NULL); 171 ret = bcm63xx_spi_check_transfer(spi, NULL);
169 if (ret < 0) { 172 if (ret < 0) {
170 dev_err(&spi->dev, "setup: unsupported mode bits %x\n", 173 dev_err(&spi->dev, "setup: unsupported mode bits %x\n",
171 spi->mode & ~MODEBITS); 174 spi->mode & ~MODEBITS);
@@ -190,28 +193,29 @@ static void bcm63xx_spi_fill_tx_fifo(struct bcm63xx_spi *bs)
190 bs->remaining_bytes -= size; 193 bs->remaining_bytes -= size;
191} 194}
192 195
193static int bcm63xx_txrx_bufs(struct spi_device *spi, struct spi_transfer *t) 196static unsigned int bcm63xx_txrx_bufs(struct spi_device *spi,
197 struct spi_transfer *t)
194{ 198{
195 struct bcm63xx_spi *bs = spi_master_get_devdata(spi->master); 199 struct bcm63xx_spi *bs = spi_master_get_devdata(spi->master);
196 u16 msg_ctl; 200 u16 msg_ctl;
197 u16 cmd; 201 u16 cmd;
198 202
203 /* Disable the CMD_DONE interrupt */
204 bcm_spi_writeb(bs, 0, SPI_INT_MASK);
205
199 dev_dbg(&spi->dev, "txrx: tx %p, rx %p, len %d\n", 206 dev_dbg(&spi->dev, "txrx: tx %p, rx %p, len %d\n",
200 t->tx_buf, t->rx_buf, t->len); 207 t->tx_buf, t->rx_buf, t->len);
201 208
202 /* Transmitter is inhibited */ 209 /* Transmitter is inhibited */
203 bs->tx_ptr = t->tx_buf; 210 bs->tx_ptr = t->tx_buf;
204 bs->rx_ptr = t->rx_buf; 211 bs->rx_ptr = t->rx_buf;
205 init_completion(&bs->done);
206 212
207 if (t->tx_buf) { 213 if (t->tx_buf) {
208 bs->remaining_bytes = t->len; 214 bs->remaining_bytes = t->len;
209 bcm63xx_spi_fill_tx_fifo(bs); 215 bcm63xx_spi_fill_tx_fifo(bs);
210 } 216 }
211 217
212 /* Enable the command done interrupt which 218 init_completion(&bs->done);
213 * we use to determine completion of a command */
214 bcm_spi_writeb(bs, SPI_INTR_CMD_DONE, SPI_INT_MASK);
215 219
216 /* Fill in the Message control register */ 220 /* Fill in the Message control register */
217 msg_ctl = (t->len << SPI_BYTE_CNT_SHIFT); 221 msg_ctl = (t->len << SPI_BYTE_CNT_SHIFT);
@@ -230,33 +234,76 @@ static int bcm63xx_txrx_bufs(struct spi_device *spi, struct spi_transfer *t)
230 cmd |= (0 << SPI_CMD_PREPEND_BYTE_CNT_SHIFT); 234 cmd |= (0 << SPI_CMD_PREPEND_BYTE_CNT_SHIFT);
231 cmd |= (spi->chip_select << SPI_CMD_DEVICE_ID_SHIFT); 235 cmd |= (spi->chip_select << SPI_CMD_DEVICE_ID_SHIFT);
232 bcm_spi_writew(bs, cmd, SPI_CMD); 236 bcm_spi_writew(bs, cmd, SPI_CMD);
233 wait_for_completion(&bs->done);
234 237
235 /* Disable the CMD_DONE interrupt */ 238 /* Enable the CMD_DONE interrupt */
236 bcm_spi_writeb(bs, 0, SPI_INT_MASK); 239 bcm_spi_writeb(bs, SPI_INTR_CMD_DONE, SPI_INT_MASK);
237 240
238 return t->len - bs->remaining_bytes; 241 return t->len - bs->remaining_bytes;
239} 242}
240 243
241static int bcm63xx_transfer(struct spi_device *spi, struct spi_message *m) 244static int bcm63xx_spi_prepare_transfer(struct spi_master *master)
242{ 245{
243 struct bcm63xx_spi *bs = spi_master_get_devdata(spi->master); 246 struct bcm63xx_spi *bs = spi_master_get_devdata(master);
244 struct spi_transfer *t;
245 int ret = 0;
246 247
247 if (unlikely(list_empty(&m->transfers))) 248 pm_runtime_get_sync(&bs->pdev->dev);
248 return -EINVAL;
249 249
250 if (bs->stopping) 250 return 0;
251 return -ESHUTDOWN; 251}
252
253static int bcm63xx_spi_unprepare_transfer(struct spi_master *master)
254{
255 struct bcm63xx_spi *bs = spi_master_get_devdata(master);
256
257 pm_runtime_put(&bs->pdev->dev);
258
259 return 0;
260}
261
262static int bcm63xx_spi_transfer_one(struct spi_master *master,
263 struct spi_message *m)
264{
265 struct bcm63xx_spi *bs = spi_master_get_devdata(master);
266 struct spi_transfer *t;
267 struct spi_device *spi = m->spi;
268 int status = 0;
269 unsigned int timeout = 0;
252 270
253 list_for_each_entry(t, &m->transfers, transfer_list) { 271 list_for_each_entry(t, &m->transfers, transfer_list) {
254 ret += bcm63xx_txrx_bufs(spi, t); 272 unsigned int len = t->len;
255 } 273 u8 rx_tail;
256 274
257 m->complete(m->context); 275 status = bcm63xx_spi_check_transfer(spi, t);
276 if (status < 0)
277 goto exit;
258 278
259 return ret; 279 /* configure adapter for a new transfer */
280 bcm63xx_spi_setup_transfer(spi, t);
281
282 while (len) {
283 /* send the data */
284 len -= bcm63xx_txrx_bufs(spi, t);
285
286 timeout = wait_for_completion_timeout(&bs->done, HZ);
287 if (!timeout) {
288 status = -ETIMEDOUT;
289 goto exit;
290 }
291
292 /* read out all data */
293 rx_tail = bcm_spi_readb(bs, SPI_RX_TAIL);
294
295 /* Read out all the data */
296 if (rx_tail)
297 memcpy_fromio(bs->rx_ptr, bs->rx_io, rx_tail);
298 }
299
300 m->actual_length += t->len;
301 }
302exit:
303 m->status = status;
304 spi_finalize_current_message(master);
305
306 return 0;
260} 307}
261 308
262/* This driver supports single master mode only. Hence 309/* This driver supports single master mode only. Hence
@@ -267,39 +314,15 @@ static irqreturn_t bcm63xx_spi_interrupt(int irq, void *dev_id)
267 struct spi_master *master = (struct spi_master *)dev_id; 314 struct spi_master *master = (struct spi_master *)dev_id;
268 struct bcm63xx_spi *bs = spi_master_get_devdata(master); 315 struct bcm63xx_spi *bs = spi_master_get_devdata(master);
269 u8 intr; 316 u8 intr;
270 u16 cmd;
271 317
272 /* Read interupts and clear them immediately */ 318 /* Read interupts and clear them immediately */
273 intr = bcm_spi_readb(bs, SPI_INT_STATUS); 319 intr = bcm_spi_readb(bs, SPI_INT_STATUS);
274 bcm_spi_writeb(bs, SPI_INTR_CLEAR_ALL, SPI_INT_STATUS); 320 bcm_spi_writeb(bs, SPI_INTR_CLEAR_ALL, SPI_INT_STATUS);
275 bcm_spi_writeb(bs, 0, SPI_INT_MASK); 321 bcm_spi_writeb(bs, 0, SPI_INT_MASK);
276 322
277 /* A tansfer completed */ 323 /* A transfer completed */
278 if (intr & SPI_INTR_CMD_DONE) { 324 if (intr & SPI_INTR_CMD_DONE)
279 u8 rx_tail; 325 complete(&bs->done);
280
281 rx_tail = bcm_spi_readb(bs, SPI_RX_TAIL);
282
283 /* Read out all the data */
284 if (rx_tail)
285 memcpy_fromio(bs->rx_ptr, bs->rx_io, rx_tail);
286
287 /* See if there is more data to send */
288 if (bs->remaining_bytes > 0) {
289 bcm63xx_spi_fill_tx_fifo(bs);
290
291 /* Start the transfer */
292 bcm_spi_writew(bs, SPI_HD_W << SPI_MSG_TYPE_SHIFT,
293 SPI_MSG_CTL);
294 cmd = bcm_spi_readw(bs, SPI_CMD);
295 cmd |= SPI_CMD_START_IMMEDIATE;
296 cmd |= (0 << SPI_CMD_PREPEND_BYTE_CNT_SHIFT);
297 bcm_spi_writeb(bs, SPI_INTR_CMD_DONE, SPI_INT_MASK);
298 bcm_spi_writew(bs, cmd, SPI_CMD);
299 } else {
300 complete(&bs->done);
301 }
302 }
303 326
304 return IRQ_HANDLED; 327 return IRQ_HANDLED;
305} 328}
@@ -345,7 +368,6 @@ static int __devinit bcm63xx_spi_probe(struct platform_device *pdev)
345 } 368 }
346 369
347 bs = spi_master_get_devdata(master); 370 bs = spi_master_get_devdata(master);
348 init_completion(&bs->done);
349 371
350 platform_set_drvdata(pdev, master); 372 platform_set_drvdata(pdev, master);
351 bs->pdev = pdev; 373 bs->pdev = pdev;
@@ -379,12 +401,13 @@ static int __devinit bcm63xx_spi_probe(struct platform_device *pdev)
379 master->bus_num = pdata->bus_num; 401 master->bus_num = pdata->bus_num;
380 master->num_chipselect = pdata->num_chipselect; 402 master->num_chipselect = pdata->num_chipselect;
381 master->setup = bcm63xx_spi_setup; 403 master->setup = bcm63xx_spi_setup;
382 master->transfer = bcm63xx_transfer; 404 master->prepare_transfer_hardware = bcm63xx_spi_prepare_transfer;
405 master->unprepare_transfer_hardware = bcm63xx_spi_unprepare_transfer;
406 master->transfer_one_message = bcm63xx_spi_transfer_one;
407 master->mode_bits = MODEBITS;
383 bs->speed_hz = pdata->speed_hz; 408 bs->speed_hz = pdata->speed_hz;
384 bs->stopping = 0;
385 bs->tx_io = (u8 *)(bs->regs + bcm63xx_spireg(SPI_MSG_DATA)); 409 bs->tx_io = (u8 *)(bs->regs + bcm63xx_spireg(SPI_MSG_DATA));
386 bs->rx_io = (const u8 *)(bs->regs + bcm63xx_spireg(SPI_RX_DATA)); 410 bs->rx_io = (const u8 *)(bs->regs + bcm63xx_spireg(SPI_RX_DATA));
387 spin_lock_init(&bs->lock);
388 411
389 /* Initialize hardware */ 412 /* Initialize hardware */
390 clk_enable(bs->clk); 413 clk_enable(bs->clk);
@@ -418,18 +441,16 @@ static int __devexit bcm63xx_spi_remove(struct platform_device *pdev)
418 struct spi_master *master = platform_get_drvdata(pdev); 441 struct spi_master *master = platform_get_drvdata(pdev);
419 struct bcm63xx_spi *bs = spi_master_get_devdata(master); 442 struct bcm63xx_spi *bs = spi_master_get_devdata(master);
420 443
444 spi_unregister_master(master);
445
421 /* reset spi block */ 446 /* reset spi block */
422 bcm_spi_writeb(bs, 0, SPI_INT_MASK); 447 bcm_spi_writeb(bs, 0, SPI_INT_MASK);
423 spin_lock(&bs->lock);
424 bs->stopping = 1;
425 448
426 /* HW shutdown */ 449 /* HW shutdown */
427 clk_disable(bs->clk); 450 clk_disable(bs->clk);
428 clk_put(bs->clk); 451 clk_put(bs->clk);
429 452
430 spin_unlock(&bs->lock);
431 platform_set_drvdata(pdev, 0); 453 platform_set_drvdata(pdev, 0);
432 spi_unregister_master(master);
433 454
434 return 0; 455 return 0;
435} 456}
diff --git a/drivers/spi/spi-bfin-sport.c b/drivers/spi/spi-bfin-sport.c
index 248a2cc671a9..1fe51198a622 100644
--- a/drivers/spi/spi-bfin-sport.c
+++ b/drivers/spi/spi-bfin-sport.c
@@ -252,19 +252,15 @@ static void
252bfin_sport_spi_restore_state(struct bfin_sport_spi_master_data *drv_data) 252bfin_sport_spi_restore_state(struct bfin_sport_spi_master_data *drv_data)
253{ 253{
254 struct bfin_sport_spi_slave_data *chip = drv_data->cur_chip; 254 struct bfin_sport_spi_slave_data *chip = drv_data->cur_chip;
255 unsigned int bits = (drv_data->ops == &bfin_sport_transfer_ops_u8 ? 7 : 15);
256 255
257 bfin_sport_spi_disable(drv_data); 256 bfin_sport_spi_disable(drv_data);
258 dev_dbg(drv_data->dev, "restoring spi ctl state\n"); 257 dev_dbg(drv_data->dev, "restoring spi ctl state\n");
259 258
260 bfin_write(&drv_data->regs->tcr1, chip->ctl_reg); 259 bfin_write(&drv_data->regs->tcr1, chip->ctl_reg);
261 bfin_write(&drv_data->regs->tcr2, bits);
262 bfin_write(&drv_data->regs->tclkdiv, chip->baud); 260 bfin_write(&drv_data->regs->tclkdiv, chip->baud);
263 bfin_write(&drv_data->regs->tfsdiv, bits);
264 SSYNC(); 261 SSYNC();
265 262
266 bfin_write(&drv_data->regs->rcr1, chip->ctl_reg & ~(ITCLK | ITFS)); 263 bfin_write(&drv_data->regs->rcr1, chip->ctl_reg & ~(ITCLK | ITFS));
267 bfin_write(&drv_data->regs->rcr2, bits);
268 SSYNC(); 264 SSYNC();
269 265
270 bfin_sport_spi_cs_active(chip); 266 bfin_sport_spi_cs_active(chip);
@@ -420,11 +416,15 @@ bfin_sport_spi_pump_transfers(unsigned long data)
420 drv_data->cs_change = transfer->cs_change; 416 drv_data->cs_change = transfer->cs_change;
421 417
422 /* Bits per word setup */ 418 /* Bits per word setup */
423 bits_per_word = transfer->bits_per_word ? : message->spi->bits_per_word; 419 bits_per_word = transfer->bits_per_word ? :
424 if (bits_per_word == 8) 420 message->spi->bits_per_word ? : 8;
425 drv_data->ops = &bfin_sport_transfer_ops_u8; 421 if (bits_per_word % 16 == 0)
426 else
427 drv_data->ops = &bfin_sport_transfer_ops_u16; 422 drv_data->ops = &bfin_sport_transfer_ops_u16;
423 else
424 drv_data->ops = &bfin_sport_transfer_ops_u8;
425 bfin_write(&drv_data->regs->tcr2, bits_per_word - 1);
426 bfin_write(&drv_data->regs->tfsdiv, bits_per_word - 1);
427 bfin_write(&drv_data->regs->rcr2, bits_per_word - 1);
428 428
429 drv_data->state = RUNNING_STATE; 429 drv_data->state = RUNNING_STATE;
430 430
@@ -598,11 +598,12 @@ bfin_sport_spi_setup(struct spi_device *spi)
598 } 598 }
599 chip->cs_chg_udelay = chip_info->cs_chg_udelay; 599 chip->cs_chg_udelay = chip_info->cs_chg_udelay;
600 chip->idle_tx_val = chip_info->idle_tx_val; 600 chip->idle_tx_val = chip_info->idle_tx_val;
601 spi->bits_per_word = chip_info->bits_per_word;
602 } 601 }
603 } 602 }
604 603
605 if (spi->bits_per_word != 8 && spi->bits_per_word != 16) { 604 if (spi->bits_per_word % 8) {
605 dev_err(&spi->dev, "%d bits_per_word is not supported\n",
606 spi->bits_per_word);
606 ret = -EINVAL; 607 ret = -EINVAL;
607 goto error; 608 goto error;
608 } 609 }
diff --git a/drivers/spi/spi-bfin5xx.c b/drivers/spi/spi-bfin5xx.c
index 3b83ff8b1e2b..9bb4d4af8547 100644
--- a/drivers/spi/spi-bfin5xx.c
+++ b/drivers/spi/spi-bfin5xx.c
@@ -396,7 +396,7 @@ static irqreturn_t bfin_spi_pio_irq_handler(int irq, void *dev_id)
396 /* last read */ 396 /* last read */
397 if (drv_data->rx) { 397 if (drv_data->rx) {
398 dev_dbg(&drv_data->pdev->dev, "last read\n"); 398 dev_dbg(&drv_data->pdev->dev, "last read\n");
399 if (n_bytes % 2) { 399 if (!(n_bytes % 2)) {
400 u16 *buf = (u16 *)drv_data->rx; 400 u16 *buf = (u16 *)drv_data->rx;
401 for (loop = 0; loop < n_bytes / 2; loop++) 401 for (loop = 0; loop < n_bytes / 2; loop++)
402 *buf++ = bfin_read(&drv_data->regs->rdbr); 402 *buf++ = bfin_read(&drv_data->regs->rdbr);
@@ -424,7 +424,7 @@ static irqreturn_t bfin_spi_pio_irq_handler(int irq, void *dev_id)
424 if (drv_data->rx && drv_data->tx) { 424 if (drv_data->rx && drv_data->tx) {
425 /* duplex */ 425 /* duplex */
426 dev_dbg(&drv_data->pdev->dev, "duplex: write_TDBR\n"); 426 dev_dbg(&drv_data->pdev->dev, "duplex: write_TDBR\n");
427 if (n_bytes % 2) { 427 if (!(n_bytes % 2)) {
428 u16 *buf = (u16 *)drv_data->rx; 428 u16 *buf = (u16 *)drv_data->rx;
429 u16 *buf2 = (u16 *)drv_data->tx; 429 u16 *buf2 = (u16 *)drv_data->tx;
430 for (loop = 0; loop < n_bytes / 2; loop++) { 430 for (loop = 0; loop < n_bytes / 2; loop++) {
@@ -442,7 +442,7 @@ static irqreturn_t bfin_spi_pio_irq_handler(int irq, void *dev_id)
442 } else if (drv_data->rx) { 442 } else if (drv_data->rx) {
443 /* read */ 443 /* read */
444 dev_dbg(&drv_data->pdev->dev, "read: write_TDBR\n"); 444 dev_dbg(&drv_data->pdev->dev, "read: write_TDBR\n");
445 if (n_bytes % 2) { 445 if (!(n_bytes % 2)) {
446 u16 *buf = (u16 *)drv_data->rx; 446 u16 *buf = (u16 *)drv_data->rx;
447 for (loop = 0; loop < n_bytes / 2; loop++) { 447 for (loop = 0; loop < n_bytes / 2; loop++) {
448 *buf++ = bfin_read(&drv_data->regs->rdbr); 448 *buf++ = bfin_read(&drv_data->regs->rdbr);
@@ -458,7 +458,7 @@ static irqreturn_t bfin_spi_pio_irq_handler(int irq, void *dev_id)
458 } else if (drv_data->tx) { 458 } else if (drv_data->tx) {
459 /* write */ 459 /* write */
460 dev_dbg(&drv_data->pdev->dev, "write: write_TDBR\n"); 460 dev_dbg(&drv_data->pdev->dev, "write: write_TDBR\n");
461 if (n_bytes % 2) { 461 if (!(n_bytes % 2)) {
462 u16 *buf = (u16 *)drv_data->tx; 462 u16 *buf = (u16 *)drv_data->tx;
463 for (loop = 0; loop < n_bytes / 2; loop++) { 463 for (loop = 0; loop < n_bytes / 2; loop++) {
464 bfin_read(&drv_data->regs->rdbr); 464 bfin_read(&drv_data->regs->rdbr);
@@ -587,6 +587,7 @@ static void bfin_spi_pump_transfers(unsigned long data)
587 if (message->state == DONE_STATE) { 587 if (message->state == DONE_STATE) {
588 dev_dbg(&drv_data->pdev->dev, "transfer: all done!\n"); 588 dev_dbg(&drv_data->pdev->dev, "transfer: all done!\n");
589 message->status = 0; 589 message->status = 0;
590 bfin_spi_flush(drv_data);
590 bfin_spi_giveback(drv_data); 591 bfin_spi_giveback(drv_data);
591 return; 592 return;
592 } 593 }
@@ -870,8 +871,10 @@ static void bfin_spi_pump_transfers(unsigned long data)
870 message->actual_length += drv_data->len_in_bytes; 871 message->actual_length += drv_data->len_in_bytes;
871 /* Move to next transfer of this msg */ 872 /* Move to next transfer of this msg */
872 message->state = bfin_spi_next_transfer(drv_data); 873 message->state = bfin_spi_next_transfer(drv_data);
873 if (drv_data->cs_change) 874 if (drv_data->cs_change && message->state != DONE_STATE) {
875 bfin_spi_flush(drv_data);
874 bfin_spi_cs_deactive(drv_data, chip); 876 bfin_spi_cs_deactive(drv_data, chip);
877 }
875 } 878 }
876 879
877 /* Schedule next transfer tasklet */ 880 /* Schedule next transfer tasklet */
@@ -1026,7 +1029,6 @@ static int bfin_spi_setup(struct spi_device *spi)
1026 chip->cs_chg_udelay = chip_info->cs_chg_udelay; 1029 chip->cs_chg_udelay = chip_info->cs_chg_udelay;
1027 chip->idle_tx_val = chip_info->idle_tx_val; 1030 chip->idle_tx_val = chip_info->idle_tx_val;
1028 chip->pio_interrupt = chip_info->pio_interrupt; 1031 chip->pio_interrupt = chip_info->pio_interrupt;
1029 spi->bits_per_word = chip_info->bits_per_word;
1030 } else { 1032 } else {
1031 /* force a default base state */ 1033 /* force a default base state */
1032 chip->ctl_reg &= bfin_ctl_reg; 1034 chip->ctl_reg &= bfin_ctl_reg;
diff --git a/drivers/spi/spi-davinci.c b/drivers/spi/spi-davinci.c
index 31bfba805cf4..9b2901feaf78 100644
--- a/drivers/spi/spi-davinci.c
+++ b/drivers/spi/spi-davinci.c
@@ -653,7 +653,7 @@ static int davinci_spi_bufs(struct spi_device *spi, struct spi_transfer *t)
653 dev_dbg(sdev, "Couldn't DMA map a %d bytes RX buffer\n", 653 dev_dbg(sdev, "Couldn't DMA map a %d bytes RX buffer\n",
654 rx_buf_count); 654 rx_buf_count);
655 if (t->tx_buf) 655 if (t->tx_buf)
656 dma_unmap_single(NULL, t->tx_dma, t->len, 656 dma_unmap_single(&spi->dev, t->tx_dma, t->len,
657 DMA_TO_DEVICE); 657 DMA_TO_DEVICE);
658 return -ENOMEM; 658 return -ENOMEM;
659 } 659 }
@@ -692,10 +692,10 @@ static int davinci_spi_bufs(struct spi_device *spi, struct spi_transfer *t)
692 if (spicfg->io_type == SPI_IO_TYPE_DMA) { 692 if (spicfg->io_type == SPI_IO_TYPE_DMA) {
693 693
694 if (t->tx_buf) 694 if (t->tx_buf)
695 dma_unmap_single(NULL, t->tx_dma, t->len, 695 dma_unmap_single(&spi->dev, t->tx_dma, t->len,
696 DMA_TO_DEVICE); 696 DMA_TO_DEVICE);
697 697
698 dma_unmap_single(NULL, t->rx_dma, rx_buf_count, 698 dma_unmap_single(&spi->dev, t->rx_dma, rx_buf_count,
699 DMA_FROM_DEVICE); 699 DMA_FROM_DEVICE);
700 700
701 clear_io_bits(dspi->base + SPIINT, SPIINT_DMA_REQ_EN); 701 clear_io_bits(dspi->base + SPIINT, SPIINT_DMA_REQ_EN);
diff --git a/drivers/spi/spi-dw.c b/drivers/spi/spi-dw.c
index 082458d73ce9..d1a495f64e2d 100644
--- a/drivers/spi/spi-dw.c
+++ b/drivers/spi/spi-dw.c
@@ -63,12 +63,6 @@ struct chip_data {
63}; 63};
64 64
65#ifdef CONFIG_DEBUG_FS 65#ifdef CONFIG_DEBUG_FS
66static int spi_show_regs_open(struct inode *inode, struct file *file)
67{
68 file->private_data = inode->i_private;
69 return 0;
70}
71
72#define SPI_REGS_BUFSIZE 1024 66#define SPI_REGS_BUFSIZE 1024
73static ssize_t spi_show_regs(struct file *file, char __user *user_buf, 67static ssize_t spi_show_regs(struct file *file, char __user *user_buf,
74 size_t count, loff_t *ppos) 68 size_t count, loff_t *ppos)
@@ -128,7 +122,7 @@ static ssize_t spi_show_regs(struct file *file, char __user *user_buf,
128 122
129static const struct file_operations mrst_spi_regs_ops = { 123static const struct file_operations mrst_spi_regs_ops = {
130 .owner = THIS_MODULE, 124 .owner = THIS_MODULE,
131 .open = spi_show_regs_open, 125 .open = simple_open,
132 .read = spi_show_regs, 126 .read = spi_show_regs,
133 .llseek = default_llseek, 127 .llseek = default_llseek,
134}; 128};
diff --git a/drivers/spi/spi-ep93xx.c b/drivers/spi/spi-ep93xx.c
index 6db2887852d6..e8055073e84d 100644
--- a/drivers/spi/spi-ep93xx.c
+++ b/drivers/spi/spi-ep93xx.c
@@ -545,13 +545,12 @@ static void ep93xx_spi_pio_transfer(struct ep93xx_spi *espi)
545 * in case of failure. 545 * in case of failure.
546 */ 546 */
547static struct dma_async_tx_descriptor * 547static struct dma_async_tx_descriptor *
548ep93xx_spi_dma_prepare(struct ep93xx_spi *espi, enum dma_data_direction dir) 548ep93xx_spi_dma_prepare(struct ep93xx_spi *espi, enum dma_transfer_direction dir)
549{ 549{
550 struct spi_transfer *t = espi->current_msg->state; 550 struct spi_transfer *t = espi->current_msg->state;
551 struct dma_async_tx_descriptor *txd; 551 struct dma_async_tx_descriptor *txd;
552 enum dma_slave_buswidth buswidth; 552 enum dma_slave_buswidth buswidth;
553 struct dma_slave_config conf; 553 struct dma_slave_config conf;
554 enum dma_transfer_direction slave_dirn;
555 struct scatterlist *sg; 554 struct scatterlist *sg;
556 struct sg_table *sgt; 555 struct sg_table *sgt;
557 struct dma_chan *chan; 556 struct dma_chan *chan;
@@ -567,14 +566,13 @@ ep93xx_spi_dma_prepare(struct ep93xx_spi *espi, enum dma_data_direction dir)
567 memset(&conf, 0, sizeof(conf)); 566 memset(&conf, 0, sizeof(conf));
568 conf.direction = dir; 567 conf.direction = dir;
569 568
570 if (dir == DMA_FROM_DEVICE) { 569 if (dir == DMA_DEV_TO_MEM) {
571 chan = espi->dma_rx; 570 chan = espi->dma_rx;
572 buf = t->rx_buf; 571 buf = t->rx_buf;
573 sgt = &espi->rx_sgt; 572 sgt = &espi->rx_sgt;
574 573
575 conf.src_addr = espi->sspdr_phys; 574 conf.src_addr = espi->sspdr_phys;
576 conf.src_addr_width = buswidth; 575 conf.src_addr_width = buswidth;
577 slave_dirn = DMA_DEV_TO_MEM;
578 } else { 576 } else {
579 chan = espi->dma_tx; 577 chan = espi->dma_tx;
580 buf = t->tx_buf; 578 buf = t->tx_buf;
@@ -582,7 +580,6 @@ ep93xx_spi_dma_prepare(struct ep93xx_spi *espi, enum dma_data_direction dir)
582 580
583 conf.dst_addr = espi->sspdr_phys; 581 conf.dst_addr = espi->sspdr_phys;
584 conf.dst_addr_width = buswidth; 582 conf.dst_addr_width = buswidth;
585 slave_dirn = DMA_MEM_TO_DEV;
586 } 583 }
587 584
588 ret = dmaengine_slave_config(chan, &conf); 585 ret = dmaengine_slave_config(chan, &conf);
@@ -633,8 +630,7 @@ ep93xx_spi_dma_prepare(struct ep93xx_spi *espi, enum dma_data_direction dir)
633 if (!nents) 630 if (!nents)
634 return ERR_PTR(-ENOMEM); 631 return ERR_PTR(-ENOMEM);
635 632
636 txd = dmaengine_prep_slave_sg(chan, sgt->sgl, nents, 633 txd = dmaengine_prep_slave_sg(chan, sgt->sgl, nents, dir, DMA_CTRL_ACK);
637 slave_dirn, DMA_CTRL_ACK);
638 if (!txd) { 634 if (!txd) {
639 dma_unmap_sg(chan->device->dev, sgt->sgl, sgt->nents, dir); 635 dma_unmap_sg(chan->device->dev, sgt->sgl, sgt->nents, dir);
640 return ERR_PTR(-ENOMEM); 636 return ERR_PTR(-ENOMEM);
@@ -651,12 +647,12 @@ ep93xx_spi_dma_prepare(struct ep93xx_spi *espi, enum dma_data_direction dir)
651 * unmapped. 647 * unmapped.
652 */ 648 */
653static void ep93xx_spi_dma_finish(struct ep93xx_spi *espi, 649static void ep93xx_spi_dma_finish(struct ep93xx_spi *espi,
654 enum dma_data_direction dir) 650 enum dma_transfer_direction dir)
655{ 651{
656 struct dma_chan *chan; 652 struct dma_chan *chan;
657 struct sg_table *sgt; 653 struct sg_table *sgt;
658 654
659 if (dir == DMA_FROM_DEVICE) { 655 if (dir == DMA_DEV_TO_MEM) {
660 chan = espi->dma_rx; 656 chan = espi->dma_rx;
661 sgt = &espi->rx_sgt; 657 sgt = &espi->rx_sgt;
662 } else { 658 } else {
@@ -677,16 +673,16 @@ static void ep93xx_spi_dma_transfer(struct ep93xx_spi *espi)
677 struct spi_message *msg = espi->current_msg; 673 struct spi_message *msg = espi->current_msg;
678 struct dma_async_tx_descriptor *rxd, *txd; 674 struct dma_async_tx_descriptor *rxd, *txd;
679 675
680 rxd = ep93xx_spi_dma_prepare(espi, DMA_FROM_DEVICE); 676 rxd = ep93xx_spi_dma_prepare(espi, DMA_DEV_TO_MEM);
681 if (IS_ERR(rxd)) { 677 if (IS_ERR(rxd)) {
682 dev_err(&espi->pdev->dev, "DMA RX failed: %ld\n", PTR_ERR(rxd)); 678 dev_err(&espi->pdev->dev, "DMA RX failed: %ld\n", PTR_ERR(rxd));
683 msg->status = PTR_ERR(rxd); 679 msg->status = PTR_ERR(rxd);
684 return; 680 return;
685 } 681 }
686 682
687 txd = ep93xx_spi_dma_prepare(espi, DMA_TO_DEVICE); 683 txd = ep93xx_spi_dma_prepare(espi, DMA_MEM_TO_DEV);
688 if (IS_ERR(txd)) { 684 if (IS_ERR(txd)) {
689 ep93xx_spi_dma_finish(espi, DMA_FROM_DEVICE); 685 ep93xx_spi_dma_finish(espi, DMA_DEV_TO_MEM);
690 dev_err(&espi->pdev->dev, "DMA TX failed: %ld\n", PTR_ERR(rxd)); 686 dev_err(&espi->pdev->dev, "DMA TX failed: %ld\n", PTR_ERR(rxd));
691 msg->status = PTR_ERR(txd); 687 msg->status = PTR_ERR(txd);
692 return; 688 return;
@@ -705,8 +701,8 @@ static void ep93xx_spi_dma_transfer(struct ep93xx_spi *espi)
705 701
706 wait_for_completion(&espi->wait); 702 wait_for_completion(&espi->wait);
707 703
708 ep93xx_spi_dma_finish(espi, DMA_TO_DEVICE); 704 ep93xx_spi_dma_finish(espi, DMA_MEM_TO_DEV);
709 ep93xx_spi_dma_finish(espi, DMA_FROM_DEVICE); 705 ep93xx_spi_dma_finish(espi, DMA_DEV_TO_MEM);
710} 706}
711 707
712/** 708/**
diff --git a/drivers/spi/spi-fsl-spi.c b/drivers/spi/spi-fsl-spi.c
index 24cacff57786..5f748c0d96bd 100644
--- a/drivers/spi/spi-fsl-spi.c
+++ b/drivers/spi/spi-fsl-spi.c
@@ -139,10 +139,12 @@ static void fsl_spi_change_mode(struct spi_device *spi)
139static void fsl_spi_chipselect(struct spi_device *spi, int value) 139static void fsl_spi_chipselect(struct spi_device *spi, int value)
140{ 140{
141 struct mpc8xxx_spi *mpc8xxx_spi = spi_master_get_devdata(spi->master); 141 struct mpc8xxx_spi *mpc8xxx_spi = spi_master_get_devdata(spi->master);
142 struct fsl_spi_platform_data *pdata = spi->dev.parent->platform_data; 142 struct fsl_spi_platform_data *pdata;
143 bool pol = spi->mode & SPI_CS_HIGH; 143 bool pol = spi->mode & SPI_CS_HIGH;
144 struct spi_mpc8xxx_cs *cs = spi->controller_state; 144 struct spi_mpc8xxx_cs *cs = spi->controller_state;
145 145
146 pdata = spi->dev.parent->parent->platform_data;
147
146 if (value == BITBANG_CS_INACTIVE) { 148 if (value == BITBANG_CS_INACTIVE) {
147 if (pdata->cs_control) 149 if (pdata->cs_control)
148 pdata->cs_control(spi, !pol); 150 pdata->cs_control(spi, !pol);
diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
index 31054e3de4c1..570f22053be8 100644
--- a/drivers/spi/spi-imx.c
+++ b/drivers/spi/spi-imx.c
@@ -83,7 +83,7 @@ struct spi_imx_data {
83 struct spi_bitbang bitbang; 83 struct spi_bitbang bitbang;
84 84
85 struct completion xfer_done; 85 struct completion xfer_done;
86 void *base; 86 void __iomem *base;
87 int irq; 87 int irq;
88 struct clk *clk; 88 struct clk *clk;
89 unsigned long spi_clk; 89 unsigned long spi_clk;
@@ -766,8 +766,12 @@ static int __devinit spi_imx_probe(struct platform_device *pdev)
766 } 766 }
767 767
768 ret = of_property_read_u32(np, "fsl,spi-num-chipselects", &num_cs); 768 ret = of_property_read_u32(np, "fsl,spi-num-chipselects", &num_cs);
769 if (ret < 0) 769 if (ret < 0) {
770 num_cs = mxc_platform_info->num_chipselect; 770 if (mxc_platform_info)
771 num_cs = mxc_platform_info->num_chipselect;
772 else
773 return ret;
774 }
771 775
772 master = spi_alloc_master(&pdev->dev, 776 master = spi_alloc_master(&pdev->dev,
773 sizeof(struct spi_imx_data) + sizeof(int) * num_cs); 777 sizeof(struct spi_imx_data) + sizeof(int) * num_cs);
@@ -784,7 +788,7 @@ static int __devinit spi_imx_probe(struct platform_device *pdev)
784 788
785 for (i = 0; i < master->num_chipselect; i++) { 789 for (i = 0; i < master->num_chipselect; i++) {
786 int cs_gpio = of_get_named_gpio(np, "cs-gpios", i); 790 int cs_gpio = of_get_named_gpio(np, "cs-gpios", i);
787 if (cs_gpio < 0) 791 if (cs_gpio < 0 && mxc_platform_info)
788 cs_gpio = mxc_platform_info->chipselect[i]; 792 cs_gpio = mxc_platform_info->chipselect[i];
789 793
790 spi_imx->chipselect[i] = cs_gpio; 794 spi_imx->chipselect[i] = cs_gpio;
diff --git a/drivers/spi/spi-pl022.c b/drivers/spi/spi-pl022.c
index 96f0da66b185..400ae2121a2a 100644
--- a/drivers/spi/spi-pl022.c
+++ b/drivers/spi/spi-pl022.c
@@ -1667,9 +1667,15 @@ static int calculate_effective_freq(struct pl022 *pl022, int freq, struct
1667 /* cpsdvsr = 254 & scr = 255 */ 1667 /* cpsdvsr = 254 & scr = 255 */
1668 min_tclk = spi_rate(rate, CPSDVR_MAX, SCR_MAX); 1668 min_tclk = spi_rate(rate, CPSDVR_MAX, SCR_MAX);
1669 1669
1670 if (!((freq <= max_tclk) && (freq >= min_tclk))) { 1670 if (freq > max_tclk)
1671 dev_warn(&pl022->adev->dev,
1672 "Max speed that can be programmed is %d Hz, you requested %d\n",
1673 max_tclk, freq);
1674
1675 if (freq < min_tclk) {
1671 dev_err(&pl022->adev->dev, 1676 dev_err(&pl022->adev->dev,
1672 "controller data is incorrect: out of range frequency"); 1677 "Requested frequency: %d Hz is less than minimum possible %d Hz\n",
1678 freq, min_tclk);
1673 return -EINVAL; 1679 return -EINVAL;
1674 } 1680 }
1675 1681
@@ -1681,26 +1687,37 @@ static int calculate_effective_freq(struct pl022 *pl022, int freq, struct
1681 while (scr <= SCR_MAX) { 1687 while (scr <= SCR_MAX) {
1682 tmp = spi_rate(rate, cpsdvsr, scr); 1688 tmp = spi_rate(rate, cpsdvsr, scr);
1683 1689
1684 if (tmp > freq) 1690 if (tmp > freq) {
1691 /* we need lower freq */
1685 scr++; 1692 scr++;
1693 continue;
1694 }
1695
1686 /* 1696 /*
1687 * If found exact value, update and break. 1697 * If found exact value, mark found and break.
1688 * If found more closer value, update and continue. 1698 * If found more closer value, update and break.
1689 */ 1699 */
1690 else if ((tmp == freq) || (tmp > best_freq)) { 1700 if (tmp > best_freq) {
1691 best_freq = tmp; 1701 best_freq = tmp;
1692 best_cpsdvsr = cpsdvsr; 1702 best_cpsdvsr = cpsdvsr;
1693 best_scr = scr; 1703 best_scr = scr;
1694 1704
1695 if (tmp == freq) 1705 if (tmp == freq)
1696 break; 1706 found = 1;
1697 } 1707 }
1698 scr++; 1708 /*
1709 * increased scr will give lower rates, which are not
1710 * required
1711 */
1712 break;
1699 } 1713 }
1700 cpsdvsr += 2; 1714 cpsdvsr += 2;
1701 scr = SCR_MIN; 1715 scr = SCR_MIN;
1702 } 1716 }
1703 1717
1718 WARN(!best_freq, "pl022: Matching cpsdvsr and scr not found for %d Hz rate \n",
1719 freq);
1720
1704 clk_freq->cpsdvsr = (u8) (best_cpsdvsr & 0xFF); 1721 clk_freq->cpsdvsr = (u8) (best_cpsdvsr & 0xFF);
1705 clk_freq->scr = (u8) (best_scr & 0xFF); 1722 clk_freq->scr = (u8) (best_scr & 0xFF);
1706 dev_dbg(&pl022->adev->dev, 1723 dev_dbg(&pl022->adev->dev,
@@ -1823,9 +1840,12 @@ static int pl022_setup(struct spi_device *spi)
1823 } else 1840 } else
1824 chip->cs_control = chip_info->cs_control; 1841 chip->cs_control = chip_info->cs_control;
1825 1842
1826 if (bits <= 3) { 1843 /* Check bits per word with vendor specific range */
1827 /* PL022 doesn't support less than 4-bits */ 1844 if ((bits <= 3) || (bits > pl022->vendor->max_bpw)) {
1828 status = -ENOTSUPP; 1845 status = -ENOTSUPP;
1846 dev_err(&spi->dev, "illegal data size for this controller!\n");
1847 dev_err(&spi->dev, "This controller can only handle 4 <= n <= %d bit words\n",
1848 pl022->vendor->max_bpw);
1829 goto err_config_params; 1849 goto err_config_params;
1830 } else if (bits <= 8) { 1850 } else if (bits <= 8) {
1831 dev_dbg(&spi->dev, "4 <= n <=8 bits per word\n"); 1851 dev_dbg(&spi->dev, "4 <= n <=8 bits per word\n");
@@ -1838,20 +1858,10 @@ static int pl022_setup(struct spi_device *spi)
1838 chip->read = READING_U16; 1858 chip->read = READING_U16;
1839 chip->write = WRITING_U16; 1859 chip->write = WRITING_U16;
1840 } else { 1860 } else {
1841 if (pl022->vendor->max_bpw >= 32) { 1861 dev_dbg(&spi->dev, "17 <= n <= 32 bits per word\n");
1842 dev_dbg(&spi->dev, "17 <= n <= 32 bits per word\n"); 1862 chip->n_bytes = 4;
1843 chip->n_bytes = 4; 1863 chip->read = READING_U32;
1844 chip->read = READING_U32; 1864 chip->write = WRITING_U32;
1845 chip->write = WRITING_U32;
1846 } else {
1847 dev_err(&spi->dev,
1848 "illegal data size for this controller!\n");
1849 dev_err(&spi->dev,
1850 "a standard pl022 can only handle "
1851 "1 <= n <= 16 bit words\n");
1852 status = -ENOTSUPP;
1853 goto err_config_params;
1854 }
1855 } 1865 }
1856 1866
1857 /* Now Initialize all register settings required for this chip */ 1867 /* Now Initialize all register settings required for this chip */
@@ -2195,7 +2205,6 @@ static int pl022_runtime_suspend(struct device *dev)
2195 struct pl022 *pl022 = dev_get_drvdata(dev); 2205 struct pl022 *pl022 = dev_get_drvdata(dev);
2196 2206
2197 clk_disable(pl022->clk); 2207 clk_disable(pl022->clk);
2198 amba_vcore_disable(pl022->adev);
2199 2208
2200 return 0; 2209 return 0;
2201} 2210}
@@ -2204,7 +2213,6 @@ static int pl022_runtime_resume(struct device *dev)
2204{ 2213{
2205 struct pl022 *pl022 = dev_get_drvdata(dev); 2214 struct pl022 *pl022 = dev_get_drvdata(dev);
2206 2215
2207 amba_vcore_enable(pl022->adev);
2208 clk_enable(pl022->clk); 2216 clk_enable(pl022->clk);
2209 2217
2210 return 0; 2218 return 0;
diff --git a/drivers/staging/android/Kconfig b/drivers/staging/android/Kconfig
index 08a3b1133d29..eb1dee26bda3 100644
--- a/drivers/staging/android/Kconfig
+++ b/drivers/staging/android/Kconfig
@@ -27,13 +27,14 @@ config ANDROID_LOGGER
27 27
28config ANDROID_PERSISTENT_RAM 28config ANDROID_PERSISTENT_RAM
29 bool 29 bool
30 depends on HAVE_MEMBLOCK
30 select REED_SOLOMON 31 select REED_SOLOMON
31 select REED_SOLOMON_ENC8 32 select REED_SOLOMON_ENC8
32 select REED_SOLOMON_DEC8 33 select REED_SOLOMON_DEC8
33 34
34config ANDROID_RAM_CONSOLE 35config ANDROID_RAM_CONSOLE
35 bool "Android RAM buffer console" 36 bool "Android RAM buffer console"
36 depends on !S390 && !UML 37 depends on !S390 && !UML && HAVE_MEMBLOCK
37 select ANDROID_PERSISTENT_RAM 38 select ANDROID_PERSISTENT_RAM
38 default n 39 default n
39 40
diff --git a/drivers/staging/android/lowmemorykiller.c b/drivers/staging/android/lowmemorykiller.c
index 052b43e4e505..b91e4bc332a7 100644
--- a/drivers/staging/android/lowmemorykiller.c
+++ b/drivers/staging/android/lowmemorykiller.c
@@ -55,7 +55,6 @@ static int lowmem_minfree[6] = {
55}; 55};
56static int lowmem_minfree_size = 4; 56static int lowmem_minfree_size = 4;
57 57
58static struct task_struct *lowmem_deathpending;
59static unsigned long lowmem_deathpending_timeout; 58static unsigned long lowmem_deathpending_timeout;
60 59
61#define lowmem_print(level, x...) \ 60#define lowmem_print(level, x...) \
@@ -64,24 +63,6 @@ static unsigned long lowmem_deathpending_timeout;
64 printk(x); \ 63 printk(x); \
65 } while (0) 64 } while (0)
66 65
67static int
68task_notify_func(struct notifier_block *self, unsigned long val, void *data);
69
70static struct notifier_block task_nb = {
71 .notifier_call = task_notify_func,
72};
73
74static int
75task_notify_func(struct notifier_block *self, unsigned long val, void *data)
76{
77 struct task_struct *task = data;
78
79 if (task == lowmem_deathpending)
80 lowmem_deathpending = NULL;
81
82 return NOTIFY_OK;
83}
84
85static int lowmem_shrink(struct shrinker *s, struct shrink_control *sc) 66static int lowmem_shrink(struct shrinker *s, struct shrink_control *sc)
86{ 67{
87 struct task_struct *tsk; 68 struct task_struct *tsk;
@@ -97,19 +78,6 @@ static int lowmem_shrink(struct shrinker *s, struct shrink_control *sc)
97 int other_file = global_page_state(NR_FILE_PAGES) - 78 int other_file = global_page_state(NR_FILE_PAGES) -
98 global_page_state(NR_SHMEM); 79 global_page_state(NR_SHMEM);
99 80
100 /*
101 * If we already have a death outstanding, then
102 * bail out right away; indicating to vmscan
103 * that we have nothing further to offer on
104 * this pass.
105 *
106 * Note: Currently you need CONFIG_PROFILING
107 * for this to work correctly.
108 */
109 if (lowmem_deathpending &&
110 time_before_eq(jiffies, lowmem_deathpending_timeout))
111 return 0;
112
113 if (lowmem_adj_size < array_size) 81 if (lowmem_adj_size < array_size)
114 array_size = lowmem_adj_size; 82 array_size = lowmem_adj_size;
115 if (lowmem_minfree_size < array_size) 83 if (lowmem_minfree_size < array_size)
@@ -148,6 +116,12 @@ static int lowmem_shrink(struct shrinker *s, struct shrink_control *sc)
148 if (!p) 116 if (!p)
149 continue; 117 continue;
150 118
119 if (test_tsk_thread_flag(p, TIF_MEMDIE) &&
120 time_before_eq(jiffies, lowmem_deathpending_timeout)) {
121 task_unlock(p);
122 rcu_read_unlock();
123 return 0;
124 }
151 oom_score_adj = p->signal->oom_score_adj; 125 oom_score_adj = p->signal->oom_score_adj;
152 if (oom_score_adj < min_score_adj) { 126 if (oom_score_adj < min_score_adj) {
153 task_unlock(p); 127 task_unlock(p);
@@ -174,15 +148,9 @@ static int lowmem_shrink(struct shrinker *s, struct shrink_control *sc)
174 lowmem_print(1, "send sigkill to %d (%s), adj %d, size %d\n", 148 lowmem_print(1, "send sigkill to %d (%s), adj %d, size %d\n",
175 selected->pid, selected->comm, 149 selected->pid, selected->comm,
176 selected_oom_score_adj, selected_tasksize); 150 selected_oom_score_adj, selected_tasksize);
177 /*
178 * If CONFIG_PROFILING is off, then we don't want to stall
179 * the killer by setting lowmem_deathpending.
180 */
181#ifdef CONFIG_PROFILING
182 lowmem_deathpending = selected;
183 lowmem_deathpending_timeout = jiffies + HZ; 151 lowmem_deathpending_timeout = jiffies + HZ;
184#endif
185 send_sig(SIGKILL, selected, 0); 152 send_sig(SIGKILL, selected, 0);
153 set_tsk_thread_flag(selected, TIF_MEMDIE);
186 rem -= selected_tasksize; 154 rem -= selected_tasksize;
187 } 155 }
188 lowmem_print(4, "lowmem_shrink %lu, %x, return %d\n", 156 lowmem_print(4, "lowmem_shrink %lu, %x, return %d\n",
@@ -198,7 +166,6 @@ static struct shrinker lowmem_shrinker = {
198 166
199static int __init lowmem_init(void) 167static int __init lowmem_init(void)
200{ 168{
201 task_handoff_register(&task_nb);
202 register_shrinker(&lowmem_shrinker); 169 register_shrinker(&lowmem_shrinker);
203 return 0; 170 return 0;
204} 171}
@@ -206,7 +173,6 @@ static int __init lowmem_init(void)
206static void __exit lowmem_exit(void) 173static void __exit lowmem_exit(void)
207{ 174{
208 unregister_shrinker(&lowmem_shrinker); 175 unregister_shrinker(&lowmem_shrinker);
209 task_handoff_unregister(&task_nb);
210} 176}
211 177
212module_param_named(cost, lowmem_shrinker.seeks, int, S_IRUGO | S_IWUSR); 178module_param_named(cost, lowmem_shrinker.seeks, int, S_IRUGO | S_IWUSR);
diff --git a/drivers/staging/android/persistent_ram.c b/drivers/staging/android/persistent_ram.c
index e08f2574e30a..8d8c1e33e0ff 100644
--- a/drivers/staging/android/persistent_ram.c
+++ b/drivers/staging/android/persistent_ram.c
@@ -399,12 +399,12 @@ static __init
399struct persistent_ram_zone *__persistent_ram_init(struct device *dev, bool ecc) 399struct persistent_ram_zone *__persistent_ram_init(struct device *dev, bool ecc)
400{ 400{
401 struct persistent_ram_zone *prz; 401 struct persistent_ram_zone *prz;
402 int ret; 402 int ret = -ENOMEM;
403 403
404 prz = kzalloc(sizeof(struct persistent_ram_zone), GFP_KERNEL); 404 prz = kzalloc(sizeof(struct persistent_ram_zone), GFP_KERNEL);
405 if (!prz) { 405 if (!prz) {
406 pr_err("persistent_ram: failed to allocate persistent ram zone\n"); 406 pr_err("persistent_ram: failed to allocate persistent ram zone\n");
407 return ERR_PTR(-ENOMEM); 407 goto err;
408 } 408 }
409 409
410 INIT_LIST_HEAD(&prz->node); 410 INIT_LIST_HEAD(&prz->node);
@@ -412,13 +412,13 @@ struct persistent_ram_zone *__persistent_ram_init(struct device *dev, bool ecc)
412 ret = persistent_ram_buffer_init(dev_name(dev), prz); 412 ret = persistent_ram_buffer_init(dev_name(dev), prz);
413 if (ret) { 413 if (ret) {
414 pr_err("persistent_ram: failed to initialize buffer\n"); 414 pr_err("persistent_ram: failed to initialize buffer\n");
415 return ERR_PTR(ret); 415 goto err;
416 } 416 }
417 417
418 prz->ecc = ecc; 418 prz->ecc = ecc;
419 ret = persistent_ram_init_ecc(prz, prz->buffer_size); 419 ret = persistent_ram_init_ecc(prz, prz->buffer_size);
420 if (ret) 420 if (ret)
421 return ERR_PTR(ret); 421 goto err;
422 422
423 if (prz->buffer->sig == PERSISTENT_RAM_SIG) { 423 if (prz->buffer->sig == PERSISTENT_RAM_SIG) {
424 if (buffer_size(prz) > prz->buffer_size || 424 if (buffer_size(prz) > prz->buffer_size ||
@@ -442,6 +442,9 @@ struct persistent_ram_zone *__persistent_ram_init(struct device *dev, bool ecc)
442 atomic_set(&prz->buffer->size, 0); 442 atomic_set(&prz->buffer->size, 0);
443 443
444 return prz; 444 return prz;
445err:
446 kfree(prz);
447 return ERR_PTR(ret);
445} 448}
446 449
447struct persistent_ram_zone * __init 450struct persistent_ram_zone * __init
diff --git a/drivers/staging/android/timed_gpio.c b/drivers/staging/android/timed_gpio.c
index bc723eff11af..45c522cbe784 100644
--- a/drivers/staging/android/timed_gpio.c
+++ b/drivers/staging/android/timed_gpio.c
@@ -85,7 +85,7 @@ static int timed_gpio_probe(struct platform_device *pdev)
85 struct timed_gpio_platform_data *pdata = pdev->dev.platform_data; 85 struct timed_gpio_platform_data *pdata = pdev->dev.platform_data;
86 struct timed_gpio *cur_gpio; 86 struct timed_gpio *cur_gpio;
87 struct timed_gpio_data *gpio_data, *gpio_dat; 87 struct timed_gpio_data *gpio_data, *gpio_dat;
88 int i, j, ret = 0; 88 int i, ret;
89 89
90 if (!pdata) 90 if (!pdata)
91 return -EBUSY; 91 return -EBUSY;
@@ -108,18 +108,12 @@ static int timed_gpio_probe(struct platform_device *pdev)
108 gpio_dat->dev.get_time = gpio_get_time; 108 gpio_dat->dev.get_time = gpio_get_time;
109 gpio_dat->dev.enable = gpio_enable; 109 gpio_dat->dev.enable = gpio_enable;
110 ret = gpio_request(cur_gpio->gpio, cur_gpio->name); 110 ret = gpio_request(cur_gpio->gpio, cur_gpio->name);
111 if (ret >= 0) { 111 if (ret < 0)
112 ret = timed_output_dev_register(&gpio_dat->dev); 112 goto err_out;
113 if (ret < 0) 113 ret = timed_output_dev_register(&gpio_dat->dev);
114 gpio_free(cur_gpio->gpio);
115 }
116 if (ret < 0) { 114 if (ret < 0) {
117 for (j = 0; j < i; j++) { 115 gpio_free(cur_gpio->gpio);
118 timed_output_dev_unregister(&gpio_data[i].dev); 116 goto err_out;
119 gpio_free(gpio_data[i].gpio);
120 }
121 kfree(gpio_data);
122 return ret;
123 } 117 }
124 118
125 gpio_dat->gpio = cur_gpio->gpio; 119 gpio_dat->gpio = cur_gpio->gpio;
@@ -131,6 +125,15 @@ static int timed_gpio_probe(struct platform_device *pdev)
131 platform_set_drvdata(pdev, gpio_data); 125 platform_set_drvdata(pdev, gpio_data);
132 126
133 return 0; 127 return 0;
128
129err_out:
130 while (--i >= 0) {
131 timed_output_dev_unregister(&gpio_data[i].dev);
132 gpio_free(gpio_data[i].gpio);
133 }
134 kfree(gpio_data);
135
136 return ret;
134} 137}
135 138
136static int timed_gpio_remove(struct platform_device *pdev) 139static int timed_gpio_remove(struct platform_device *pdev)
diff --git a/drivers/staging/iio/inkern.c b/drivers/staging/iio/inkern.c
index de2c8ea64965..ef07a02bf542 100644
--- a/drivers/staging/iio/inkern.c
+++ b/drivers/staging/iio/inkern.c
@@ -82,6 +82,7 @@ int iio_map_array_unregister(struct iio_dev *indio_dev,
82 ret = -ENODEV; 82 ret = -ENODEV;
83 goto error_ret; 83 goto error_ret;
84 } 84 }
85 i++;
85 } 86 }
86error_ret: 87error_ret:
87 mutex_unlock(&iio_map_list_lock); 88 mutex_unlock(&iio_map_list_lock);
diff --git a/drivers/staging/iio/magnetometer/ak8975.c b/drivers/staging/iio/magnetometer/ak8975.c
index d5ddac3d8831..ebc2d0840caf 100644
--- a/drivers/staging/iio/magnetometer/ak8975.c
+++ b/drivers/staging/iio/magnetometer/ak8975.c
@@ -108,7 +108,8 @@ static const int ak8975_index_to_reg[] = {
108static int ak8975_write_data(struct i2c_client *client, 108static int ak8975_write_data(struct i2c_client *client,
109 u8 reg, u8 val, u8 mask, u8 shift) 109 u8 reg, u8 val, u8 mask, u8 shift)
110{ 110{
111 struct ak8975_data *data = i2c_get_clientdata(client); 111 struct iio_dev *indio_dev = i2c_get_clientdata(client);
112 struct ak8975_data *data = iio_priv(indio_dev);
112 u8 regval; 113 u8 regval;
113 int ret; 114 int ret;
114 115
@@ -159,7 +160,8 @@ static int ak8975_read_data(struct i2c_client *client,
159 */ 160 */
160static int ak8975_setup(struct i2c_client *client) 161static int ak8975_setup(struct i2c_client *client)
161{ 162{
162 struct ak8975_data *data = i2c_get_clientdata(client); 163 struct iio_dev *indio_dev = i2c_get_clientdata(client);
164 struct ak8975_data *data = iio_priv(indio_dev);
163 u8 device_id; 165 u8 device_id;
164 int ret; 166 int ret;
165 167
@@ -509,6 +511,7 @@ static int ak8975_probe(struct i2c_client *client,
509 goto exit_gpio; 511 goto exit_gpio;
510 } 512 }
511 data = iio_priv(indio_dev); 513 data = iio_priv(indio_dev);
514 i2c_set_clientdata(client, indio_dev);
512 /* Perform some basic start-of-day setup of the device. */ 515 /* Perform some basic start-of-day setup of the device. */
513 err = ak8975_setup(client); 516 err = ak8975_setup(client);
514 if (err < 0) { 517 if (err < 0) {
@@ -516,7 +519,6 @@ static int ak8975_probe(struct i2c_client *client,
516 goto exit_free_iio; 519 goto exit_free_iio;
517 } 520 }
518 521
519 i2c_set_clientdata(client, indio_dev);
520 data->client = client; 522 data->client = client;
521 mutex_init(&data->lock); 523 mutex_init(&data->lock);
522 data->eoc_irq = client->irq; 524 data->eoc_irq = client->irq;
diff --git a/drivers/staging/iio/magnetometer/hmc5843.c b/drivers/staging/iio/magnetometer/hmc5843.c
index 91dd3da70cb4..e00b416c4d33 100644
--- a/drivers/staging/iio/magnetometer/hmc5843.c
+++ b/drivers/staging/iio/magnetometer/hmc5843.c
@@ -521,7 +521,9 @@ static int hmc5843_detect(struct i2c_client *client,
521/* Called when we have found a new HMC5843. */ 521/* Called when we have found a new HMC5843. */
522static void hmc5843_init_client(struct i2c_client *client) 522static void hmc5843_init_client(struct i2c_client *client)
523{ 523{
524 struct hmc5843_data *data = i2c_get_clientdata(client); 524 struct iio_dev *indio_dev = i2c_get_clientdata(client);
525 struct hmc5843_data *data = iio_priv(indio_dev);
526
525 hmc5843_set_meas_conf(client, data->meas_conf); 527 hmc5843_set_meas_conf(client, data->meas_conf);
526 hmc5843_set_rate(client, data->rate); 528 hmc5843_set_rate(client, data->rate);
527 hmc5843_configure(client, data->operating_mode); 529 hmc5843_configure(client, data->operating_mode);
diff --git a/drivers/staging/media/as102/as102_fw.c b/drivers/staging/media/as102/as102_fw.c
index 43ebc43e6b9a..1075fb1df0d9 100644
--- a/drivers/staging/media/as102/as102_fw.c
+++ b/drivers/staging/media/as102/as102_fw.c
@@ -165,7 +165,7 @@ error:
165int as102_fw_upload(struct as10x_bus_adapter_t *bus_adap) 165int as102_fw_upload(struct as10x_bus_adapter_t *bus_adap)
166{ 166{
167 int errno = -EFAULT; 167 int errno = -EFAULT;
168 const struct firmware *firmware; 168 const struct firmware *firmware = NULL;
169 unsigned char *cmd_buf = NULL; 169 unsigned char *cmd_buf = NULL;
170 char *fw1, *fw2; 170 char *fw1, *fw2;
171 struct usb_device *dev = bus_adap->usb_dev; 171 struct usb_device *dev = bus_adap->usb_dev;
diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
index 400df8cbee53..d91751f9ffe8 100644
--- a/drivers/staging/octeon/ethernet-rx.c
+++ b/drivers/staging/octeon/ethernet-rx.c
@@ -36,6 +36,7 @@
36#include <linux/prefetch.h> 36#include <linux/prefetch.h>
37#include <linux/ratelimit.h> 37#include <linux/ratelimit.h>
38#include <linux/smp.h> 38#include <linux/smp.h>
39#include <linux/interrupt.h>
39#include <net/dst.h> 40#include <net/dst.h>
40#ifdef CONFIG_XFRM 41#ifdef CONFIG_XFRM
41#include <linux/xfrm.h> 42#include <linux/xfrm.h>
diff --git a/drivers/staging/octeon/ethernet-tx.c b/drivers/staging/octeon/ethernet-tx.c
index 56d74dc2fbd5..91a97b3e45c6 100644
--- a/drivers/staging/octeon/ethernet-tx.c
+++ b/drivers/staging/octeon/ethernet-tx.c
@@ -32,6 +32,7 @@
32#include <linux/ip.h> 32#include <linux/ip.h>
33#include <linux/ratelimit.h> 33#include <linux/ratelimit.h>
34#include <linux/string.h> 34#include <linux/string.h>
35#include <linux/interrupt.h>
35#include <net/dst.h> 36#include <net/dst.h>
36#ifdef CONFIG_XFRM 37#ifdef CONFIG_XFRM
37#include <linux/xfrm.h> 38#include <linux/xfrm.h>
diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
index 9112cd882154..60cba8194de3 100644
--- a/drivers/staging/octeon/ethernet.c
+++ b/drivers/staging/octeon/ethernet.c
@@ -31,6 +31,7 @@
31#include <linux/etherdevice.h> 31#include <linux/etherdevice.h>
32#include <linux/phy.h> 32#include <linux/phy.h>
33#include <linux/slab.h> 33#include <linux/slab.h>
34#include <linux/interrupt.h>
34 35
35#include <net/dst.h> 36#include <net/dst.h>
36 37
diff --git a/drivers/staging/omapdrm/omap_drv.c b/drivers/staging/omapdrm/omap_drv.c
index 3df5b4c58ecd..620b8d54223d 100644
--- a/drivers/staging/omapdrm/omap_drv.c
+++ b/drivers/staging/omapdrm/omap_drv.c
@@ -803,9 +803,6 @@ static void pdev_shutdown(struct platform_device *device)
803static int pdev_probe(struct platform_device *device) 803static int pdev_probe(struct platform_device *device)
804{ 804{
805 DBG("%s", device->name); 805 DBG("%s", device->name);
806 if (platform_driver_register(&omap_dmm_driver))
807 dev_err(&device->dev, "DMM registration failed\n");
808
809 return drm_platform_init(&omap_drm_driver, device); 806 return drm_platform_init(&omap_drm_driver, device);
810} 807}
811 808
@@ -833,6 +830,10 @@ struct platform_driver pdev = {
833static int __init omap_drm_init(void) 830static int __init omap_drm_init(void)
834{ 831{
835 DBG("init"); 832 DBG("init");
833 if (platform_driver_register(&omap_dmm_driver)) {
834 /* we can continue on without DMM.. so not fatal */
835 dev_err(NULL, "DMM registration failed\n");
836 }
836 return platform_driver_register(&pdev); 837 return platform_driver_register(&pdev);
837} 838}
838 839
diff --git a/drivers/staging/ozwpan/TODO b/drivers/staging/ozwpan/TODO
index f7a9c122f596..c2d30a7112f3 100644
--- a/drivers/staging/ozwpan/TODO
+++ b/drivers/staging/ozwpan/TODO
@@ -8,5 +8,7 @@ TODO:
8 - code review by USB developer community. 8 - code review by USB developer community.
9 - testing with as many devices as possible. 9 - testing with as many devices as possible.
10 10
11Please send any patches for this driver to Chris Kelly <ckelly@ozmodevices.com> 11Please send any patches for this driver to
12Rupesh Gujare <rgujare@ozmodevices.com>
13Chris Kelly <ckelly@ozmodevices.com>
12and Greg Kroah-Hartman <gregkh@linuxfoundation.org>. 14and Greg Kroah-Hartman <gregkh@linuxfoundation.org>.
diff --git a/drivers/staging/ozwpan/ozpd.c b/drivers/staging/ozwpan/ozpd.c
index 2b45d3d1800c..04cd57f2a6da 100644
--- a/drivers/staging/ozwpan/ozpd.c
+++ b/drivers/staging/ozwpan/ozpd.c
@@ -383,8 +383,6 @@ static void oz_tx_frame_free(struct oz_pd *pd, struct oz_tx_frame *f)
383 pd->tx_pool = &f->link; 383 pd->tx_pool = &f->link;
384 pd->tx_pool_count++; 384 pd->tx_pool_count++;
385 f = 0; 385 f = 0;
386 } else {
387 kfree(f);
388 } 386 }
389 spin_unlock_bh(&pd->tx_frame_lock); 387 spin_unlock_bh(&pd->tx_frame_lock);
390 if (f) 388 if (f)
diff --git a/drivers/staging/ramster/Kconfig b/drivers/staging/ramster/Kconfig
index 8b57b87edda4..4af1f8d4b953 100644
--- a/drivers/staging/ramster/Kconfig
+++ b/drivers/staging/ramster/Kconfig
@@ -1,10 +1,6 @@
1# Dependency on CONFIG_BROKEN is because there is a commit dependency
2# on a cleancache naming change to be submitted by Konrad Wilk
3# a39c00ded70339603ffe1b0ffdf3ade85bcf009a "Merge branch 'stable/cleancache.v13'
4# into linux-next. Once this commit is present, BROKEN can be removed
5config RAMSTER 1config RAMSTER
6 bool "Cross-machine RAM capacity sharing, aka peer-to-peer tmem" 2 bool "Cross-machine RAM capacity sharing, aka peer-to-peer tmem"
7 depends on (CLEANCACHE || FRONTSWAP) && CONFIGFS_FS=y && !ZCACHE && !XVMALLOC && !HIGHMEM && BROKEN 3 depends on (CLEANCACHE || FRONTSWAP) && CONFIGFS_FS=y && !ZCACHE && !XVMALLOC && !HIGHMEM
8 select LZO_COMPRESS 4 select LZO_COMPRESS
9 select LZO_DECOMPRESS 5 select LZO_DECOMPRESS
10 default n 6 default n
diff --git a/drivers/staging/rts_pstor/ms.c b/drivers/staging/rts_pstor/ms.c
index 66341dff8c99..f9a4498984cc 100644
--- a/drivers/staging/rts_pstor/ms.c
+++ b/drivers/staging/rts_pstor/ms.c
@@ -3498,7 +3498,8 @@ static int ms_rw_multi_sector(struct scsi_cmnd *srb, struct rtsx_chip *chip, u32
3498 3498
3499 log_blk++; 3499 log_blk++;
3500 3500
3501 for (seg_no = 0; seg_no < sizeof(ms_start_idx)/2; seg_no++) { 3501 for (seg_no = 0; seg_no < ARRAY_SIZE(ms_start_idx) - 1;
3502 seg_no++) {
3502 if (log_blk < ms_start_idx[seg_no+1]) 3503 if (log_blk < ms_start_idx[seg_no+1])
3503 break; 3504 break;
3504 } 3505 }
diff --git a/drivers/staging/rts_pstor/rtsx.c b/drivers/staging/rts_pstor/rtsx.c
index a7feb3e328a0..1dccd933a7e4 100644
--- a/drivers/staging/rts_pstor/rtsx.c
+++ b/drivers/staging/rts_pstor/rtsx.c
@@ -1000,6 +1000,11 @@ static int __devinit rtsx_probe(struct pci_dev *pci,
1000 1000
1001 rtsx_init_chip(dev->chip); 1001 rtsx_init_chip(dev->chip);
1002 1002
1003 /* set the supported max_lun and max_id for the scsi host
1004 * NOTE: the minimal value of max_id is 1 */
1005 host->max_id = 1;
1006 host->max_lun = dev->chip->max_lun;
1007
1003 /* Start up our control thread */ 1008 /* Start up our control thread */
1004 th = kthread_run(rtsx_control_thread, dev, CR_DRIVER_NAME); 1009 th = kthread_run(rtsx_control_thread, dev, CR_DRIVER_NAME);
1005 if (IS_ERR(th)) { 1010 if (IS_ERR(th)) {
diff --git a/drivers/staging/rts_pstor/rtsx_transport.c b/drivers/staging/rts_pstor/rtsx_transport.c
index 4e3d2c106af0..9b2e5c99870f 100644
--- a/drivers/staging/rts_pstor/rtsx_transport.c
+++ b/drivers/staging/rts_pstor/rtsx_transport.c
@@ -335,6 +335,7 @@ static int rtsx_transfer_sglist_adma_partial(struct rtsx_chip *chip, u8 card,
335 int sg_cnt, i, resid; 335 int sg_cnt, i, resid;
336 int err = 0; 336 int err = 0;
337 long timeleft; 337 long timeleft;
338 struct scatterlist *sg_ptr;
338 u32 val = TRIG_DMA; 339 u32 val = TRIG_DMA;
339 340
340 if ((sg == NULL) || (num_sg <= 0) || !offset || !index) 341 if ((sg == NULL) || (num_sg <= 0) || !offset || !index)
@@ -371,7 +372,7 @@ static int rtsx_transfer_sglist_adma_partial(struct rtsx_chip *chip, u8 card,
371 sg_cnt = dma_map_sg(&(rtsx->pci->dev), sg, num_sg, dma_dir); 372 sg_cnt = dma_map_sg(&(rtsx->pci->dev), sg, num_sg, dma_dir);
372 373
373 resid = size; 374 resid = size;
374 375 sg_ptr = sg;
375 chip->sgi = 0; 376 chip->sgi = 0;
376 /* Usually the next entry will be @sg@ + 1, but if this sg element 377 /* Usually the next entry will be @sg@ + 1, but if this sg element
377 * is part of a chained scatterlist, it could jump to the start of 378 * is part of a chained scatterlist, it could jump to the start of
@@ -379,14 +380,14 @@ static int rtsx_transfer_sglist_adma_partial(struct rtsx_chip *chip, u8 card,
379 * the proper sg 380 * the proper sg
380 */ 381 */
381 for (i = 0; i < *index; i++) 382 for (i = 0; i < *index; i++)
382 sg = sg_next(sg); 383 sg_ptr = sg_next(sg_ptr);
383 for (i = *index; i < sg_cnt; i++) { 384 for (i = *index; i < sg_cnt; i++) {
384 dma_addr_t addr; 385 dma_addr_t addr;
385 unsigned int len; 386 unsigned int len;
386 u8 option; 387 u8 option;
387 388
388 addr = sg_dma_address(sg); 389 addr = sg_dma_address(sg_ptr);
389 len = sg_dma_len(sg); 390 len = sg_dma_len(sg_ptr);
390 391
391 RTSX_DEBUGP("DMA addr: 0x%x, Len: 0x%x\n", 392 RTSX_DEBUGP("DMA addr: 0x%x, Len: 0x%x\n",
392 (unsigned int)addr, len); 393 (unsigned int)addr, len);
@@ -415,7 +416,7 @@ static int rtsx_transfer_sglist_adma_partial(struct rtsx_chip *chip, u8 card,
415 if (!resid) 416 if (!resid)
416 break; 417 break;
417 418
418 sg = sg_next(sg); 419 sg_ptr = sg_next(sg_ptr);
419 } 420 }
420 421
421 RTSX_DEBUGP("SG table count = %d\n", chip->sgi); 422 RTSX_DEBUGP("SG table count = %d\n", chip->sgi);
diff --git a/drivers/staging/sep/sep_main.c b/drivers/staging/sep/sep_main.c
index ad54c2e5c932..f1701bc6e312 100644
--- a/drivers/staging/sep/sep_main.c
+++ b/drivers/staging/sep/sep_main.c
@@ -3114,7 +3114,7 @@ static long sep_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3114 current->pid); 3114 current->pid);
3115 if (1 == test_bit(SEP_LEGACY_SENDMSG_DONE_OFFSET, 3115 if (1 == test_bit(SEP_LEGACY_SENDMSG_DONE_OFFSET,
3116 &call_status->status)) { 3116 &call_status->status)) {
3117 dev_warn(&sep->pdev->dev, 3117 dev_dbg(&sep->pdev->dev,
3118 "[PID%d] dcb prep needed before send msg\n", 3118 "[PID%d] dcb prep needed before send msg\n",
3119 current->pid); 3119 current->pid);
3120 error = -EPROTO; 3120 error = -EPROTO;
@@ -3122,9 +3122,9 @@ static long sep_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3122 } 3122 }
3123 3123
3124 if (!arg) { 3124 if (!arg) {
3125 dev_warn(&sep->pdev->dev, 3125 dev_dbg(&sep->pdev->dev,
3126 "[PID%d] dcb null arg\n", current->pid); 3126 "[PID%d] dcb null arg\n", current->pid);
3127 error = EINVAL; 3127 error = -EINVAL;
3128 goto end_function; 3128 goto end_function;
3129 } 3129 }
3130 3130
diff --git a/drivers/staging/tidspbridge/core/tiomap3430.c b/drivers/staging/tidspbridge/core/tiomap3430.c
index 7862513cc295..9cf29fcea11e 100644
--- a/drivers/staging/tidspbridge/core/tiomap3430.c
+++ b/drivers/staging/tidspbridge/core/tiomap3430.c
@@ -79,10 +79,6 @@
79#define OMAP343X_CONTROL_IVA2_BOOTADDR (OMAP2_CONTROL_GENERAL + 0x0190) 79#define OMAP343X_CONTROL_IVA2_BOOTADDR (OMAP2_CONTROL_GENERAL + 0x0190)
80#define OMAP343X_CONTROL_IVA2_BOOTMOD (OMAP2_CONTROL_GENERAL + 0x0194) 80#define OMAP343X_CONTROL_IVA2_BOOTMOD (OMAP2_CONTROL_GENERAL + 0x0194)
81 81
82#define OMAP343X_CTRL_REGADDR(reg) \
83 OMAP2_L4_IO_ADDRESS(OMAP343X_CTRL_BASE + (reg))
84
85
86/* Forward Declarations: */ 82/* Forward Declarations: */
87static int bridge_brd_monitor(struct bridge_dev_context *dev_ctxt); 83static int bridge_brd_monitor(struct bridge_dev_context *dev_ctxt);
88static int bridge_brd_read(struct bridge_dev_context *dev_ctxt, 84static int bridge_brd_read(struct bridge_dev_context *dev_ctxt,
@@ -418,19 +414,27 @@ static int bridge_brd_start(struct bridge_dev_context *dev_ctxt,
418 414
419 /* Assert RST1 i.e only the RST only for DSP megacell */ 415 /* Assert RST1 i.e only the RST only for DSP megacell */
420 if (!status) { 416 if (!status) {
417 /*
418 * XXX: ioremapping MUST be removed once ctrl
419 * function is made available.
420 */
421 void __iomem *ctrl = ioremap(OMAP343X_CTRL_BASE, SZ_4K);
422 if (!ctrl)
423 return -ENOMEM;
424
421 (*pdata->dsp_prm_rmw_bits)(OMAP3430_RST1_IVA2_MASK, 425 (*pdata->dsp_prm_rmw_bits)(OMAP3430_RST1_IVA2_MASK,
422 OMAP3430_RST1_IVA2_MASK, OMAP3430_IVA2_MOD, 426 OMAP3430_RST1_IVA2_MASK, OMAP3430_IVA2_MOD,
423 OMAP2_RM_RSTCTRL); 427 OMAP2_RM_RSTCTRL);
424 /* Mask address with 1K for compatibility */ 428 /* Mask address with 1K for compatibility */
425 __raw_writel(dsp_addr & OMAP3_IVA2_BOOTADDR_MASK, 429 __raw_writel(dsp_addr & OMAP3_IVA2_BOOTADDR_MASK,
426 OMAP343X_CTRL_REGADDR( 430 ctrl + OMAP343X_CONTROL_IVA2_BOOTADDR);
427 OMAP343X_CONTROL_IVA2_BOOTADDR));
428 /* 431 /*
429 * Set bootmode to self loop if dsp_debug flag is true 432 * Set bootmode to self loop if dsp_debug flag is true
430 */ 433 */
431 __raw_writel((dsp_debug) ? OMAP3_IVA2_BOOTMOD_IDLE : 0, 434 __raw_writel((dsp_debug) ? OMAP3_IVA2_BOOTMOD_IDLE : 0,
432 OMAP343X_CTRL_REGADDR( 435 ctrl + OMAP343X_CONTROL_IVA2_BOOTMOD);
433 OMAP343X_CONTROL_IVA2_BOOTMOD)); 436
437 iounmap(ctrl);
434 } 438 }
435 } 439 }
436 if (!status) { 440 if (!status) {
diff --git a/drivers/staging/tidspbridge/core/wdt.c b/drivers/staging/tidspbridge/core/wdt.c
index 70055c8111ed..870f934f4f3b 100644
--- a/drivers/staging/tidspbridge/core/wdt.c
+++ b/drivers/staging/tidspbridge/core/wdt.c
@@ -53,7 +53,10 @@ int dsp_wdt_init(void)
53 int ret = 0; 53 int ret = 0;
54 54
55 dsp_wdt.sm_wdt = NULL; 55 dsp_wdt.sm_wdt = NULL;
56 dsp_wdt.reg_base = OMAP2_L4_IO_ADDRESS(OMAP34XX_WDT3_BASE); 56 dsp_wdt.reg_base = ioremap(OMAP34XX_WDT3_BASE, SZ_4K);
57 if (!dsp_wdt.reg_base)
58 return -ENOMEM;
59
57 tasklet_init(&dsp_wdt.wdt3_tasklet, dsp_wdt_dpc, 0); 60 tasklet_init(&dsp_wdt.wdt3_tasklet, dsp_wdt_dpc, 0);
58 61
59 dsp_wdt.fclk = clk_get(NULL, "wdt3_fck"); 62 dsp_wdt.fclk = clk_get(NULL, "wdt3_fck");
@@ -99,6 +102,9 @@ void dsp_wdt_exit(void)
99 dsp_wdt.fclk = NULL; 102 dsp_wdt.fclk = NULL;
100 dsp_wdt.iclk = NULL; 103 dsp_wdt.iclk = NULL;
101 dsp_wdt.sm_wdt = NULL; 104 dsp_wdt.sm_wdt = NULL;
105
106 if (dsp_wdt.reg_base)
107 iounmap(dsp_wdt.reg_base);
102 dsp_wdt.reg_base = NULL; 108 dsp_wdt.reg_base = NULL;
103} 109}
104 110
diff --git a/drivers/staging/vme/devices/vme_pio2_core.c b/drivers/staging/vme/devices/vme_pio2_core.c
index 9fedc442a779..573c80003f0c 100644
--- a/drivers/staging/vme/devices/vme_pio2_core.c
+++ b/drivers/staging/vme/devices/vme_pio2_core.c
@@ -35,10 +35,10 @@ static int vector[PIO2_CARDS_MAX];
35static int vector_num; 35static int vector_num;
36static int level[PIO2_CARDS_MAX]; 36static int level[PIO2_CARDS_MAX];
37static int level_num; 37static int level_num;
38static const char *variant[PIO2_CARDS_MAX]; 38static char *variant[PIO2_CARDS_MAX];
39static int variant_num; 39static int variant_num;
40 40
41static int loopback; 41static bool loopback;
42 42
43static int pio2_match(struct vme_dev *); 43static int pio2_match(struct vme_dev *);
44static int __devinit pio2_probe(struct vme_dev *); 44static int __devinit pio2_probe(struct vme_dev *);
diff --git a/drivers/staging/vt6655/key.c b/drivers/staging/vt6655/key.c
index 0ff8d7bbf2a7..774b0d4a7e06 100644
--- a/drivers/staging/vt6655/key.c
+++ b/drivers/staging/vt6655/key.c
@@ -655,6 +655,9 @@ bool KeybSetDefaultKey (
655 return (false); 655 return (false);
656 } 656 }
657 657
658 if (uKeyLength > MAX_KEY_LEN)
659 return false;
660
658 pTable->KeyTable[MAX_KEY_TABLE-1].bInUse = true; 661 pTable->KeyTable[MAX_KEY_TABLE-1].bInUse = true;
659 for(ii=0;ii<ETH_ALEN;ii++) 662 for(ii=0;ii<ETH_ALEN;ii++)
660 pTable->KeyTable[MAX_KEY_TABLE-1].abyBSSID[ii] = 0xFF; 663 pTable->KeyTable[MAX_KEY_TABLE-1].abyBSSID[ii] = 0xFF;
diff --git a/drivers/staging/vt6656/ioctl.c b/drivers/staging/vt6656/ioctl.c
index 1463d76895f0..d59456c29df1 100644
--- a/drivers/staging/vt6656/ioctl.c
+++ b/drivers/staging/vt6656/ioctl.c
@@ -565,7 +565,7 @@ int private_ioctl(PSDevice pDevice, struct ifreq *rq)
565 result = -ENOMEM; 565 result = -ENOMEM;
566 break; 566 break;
567 } 567 }
568 pNodeList = (PSNodeList)kmalloc(sizeof(SNodeList) + (sNodeList.uItem * sizeof(SNodeItem)), (int)GFP_ATOMIC); 568 pNodeList = kmalloc(sizeof(SNodeList) + (sNodeList.uItem * sizeof(SNodeItem)), (int)GFP_ATOMIC);
569 if (pNodeList == NULL) { 569 if (pNodeList == NULL) {
570 result = -ENOMEM; 570 result = -ENOMEM;
571 break; 571 break;
@@ -601,6 +601,7 @@ int private_ioctl(PSDevice pDevice, struct ifreq *rq)
601 } 601 }
602 } 602 }
603 if (copy_to_user(pReq->data, pNodeList, sizeof(SNodeList) + (sNodeList.uItem * sizeof(SNodeItem)))) { 603 if (copy_to_user(pReq->data, pNodeList, sizeof(SNodeList) + (sNodeList.uItem * sizeof(SNodeItem)))) {
604 kfree(pNodeList);
604 result = -EFAULT; 605 result = -EFAULT;
605 break; 606 break;
606 } 607 }
diff --git a/drivers/staging/vt6656/key.c b/drivers/staging/vt6656/key.c
index 27bb523c8a97..ee62a06a75f4 100644
--- a/drivers/staging/vt6656/key.c
+++ b/drivers/staging/vt6656/key.c
@@ -684,6 +684,9 @@ BOOL KeybSetDefaultKey(
684 return (FALSE); 684 return (FALSE);
685 } 685 }
686 686
687 if (uKeyLength > MAX_KEY_LEN)
688 return false;
689
687 pTable->KeyTable[MAX_KEY_TABLE-1].bInUse = TRUE; 690 pTable->KeyTable[MAX_KEY_TABLE-1].bInUse = TRUE;
688 for (ii = 0; ii < ETH_ALEN; ii++) 691 for (ii = 0; ii < ETH_ALEN; ii++)
689 pTable->KeyTable[MAX_KEY_TABLE-1].abyBSSID[ii] = 0xFF; 692 pTable->KeyTable[MAX_KEY_TABLE-1].abyBSSID[ii] = 0xFF;
diff --git a/drivers/staging/xgifb/vb_init.c b/drivers/staging/xgifb/vb_init.c
index 94d5c35e22fb..3650bbff7686 100644
--- a/drivers/staging/xgifb/vb_init.c
+++ b/drivers/staging/xgifb/vb_init.c
@@ -61,7 +61,7 @@ XGINew_GetXG20DRAMType(struct xgi_hw_device_info *HwDeviceExtension,
61 } 61 }
62 temp = xgifb_reg_get(pVBInfo->P3c4, 0x3B); 62 temp = xgifb_reg_get(pVBInfo->P3c4, 0x3B);
63 /* SR3B[7][3]MAA15 MAA11 (Power on Trapping) */ 63 /* SR3B[7][3]MAA15 MAA11 (Power on Trapping) */
64 if ((temp & 0x88) == 0x80) 64 if (((temp & 0x88) == 0x80) || ((temp & 0x88) == 0x08))
65 data = 0; /* DDR */ 65 data = 0; /* DDR */
66 else 66 else
67 data = 1; /* DDRII */ 67 data = 1; /* DDRII */
diff --git a/drivers/staging/xgifb/vb_setmode.c b/drivers/staging/xgifb/vb_setmode.c
index 2919924213c4..60d4adf99923 100644
--- a/drivers/staging/xgifb/vb_setmode.c
+++ b/drivers/staging/xgifb/vb_setmode.c
@@ -152,6 +152,7 @@ void InitTo330Pointer(unsigned char ChipType, struct vb_device_info *pVBInfo)
152 pVBInfo->pXGINew_CR97 = &XG20_CR97; 152 pVBInfo->pXGINew_CR97 = &XG20_CR97;
153 153
154 if (ChipType == XG27) { 154 if (ChipType == XG27) {
155 unsigned char temp;
155 pVBInfo->MCLKData 156 pVBInfo->MCLKData
156 = (struct SiS_MCLKData *) XGI27New_MCLKData; 157 = (struct SiS_MCLKData *) XGI27New_MCLKData;
157 pVBInfo->CR40 = XGI27_cr41; 158 pVBInfo->CR40 = XGI27_cr41;
@@ -162,7 +163,13 @@ void InitTo330Pointer(unsigned char ChipType, struct vb_device_info *pVBInfo)
162 pVBInfo->pCRDE = XG27_CRDE; 163 pVBInfo->pCRDE = XG27_CRDE;
163 pVBInfo->pSR40 = &XG27_SR40; 164 pVBInfo->pSR40 = &XG27_SR40;
164 pVBInfo->pSR41 = &XG27_SR41; 165 pVBInfo->pSR41 = &XG27_SR41;
166 pVBInfo->SR15 = XG27_SR13;
165 167
168 /*Z11m DDR*/
169 temp = xgifb_reg_get(pVBInfo->P3c4, 0x3B);
170 /* SR3B[7][3]MAA15 MAA11 (Power on Trapping) */
171 if (((temp & 0x88) == 0x80) || ((temp & 0x88) == 0x08))
172 pVBInfo->pXGINew_CR97 = &Z11m_CR97;
166 } 173 }
167 174
168 if (ChipType >= XG20) { 175 if (ChipType >= XG20) {
diff --git a/drivers/staging/xgifb/vb_table.h b/drivers/staging/xgifb/vb_table.h
index dddf261ed53d..e8d6f674b274 100644
--- a/drivers/staging/xgifb/vb_table.h
+++ b/drivers/staging/xgifb/vb_table.h
@@ -33,6 +33,13 @@ static struct XGI_ECLKDataStruct XGI340_ECLKData[] = {
33 {0x5c, 0x23, 0x01, 166} 33 {0x5c, 0x23, 0x01, 166}
34}; 34};
35 35
36static unsigned char XG27_SR13[4][8] = {
37 {0x35, 0x45, 0xb1, 0x00, 0x00, 0x00, 0x00, 0x00}, /* SR13 */
38 {0x41, 0x51, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00}, /* SR14 */
39 {0x32, 0x32, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00}, /* SR18 */
40 {0x03, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00} /* SR1B */
41};
42
36static unsigned char XGI340_SR13[4][8] = { 43static unsigned char XGI340_SR13[4][8] = {
37 {0x35, 0x45, 0xb1, 0x00, 0x00, 0x00, 0x00, 0x00}, /* SR13 */ 44 {0x35, 0x45, 0xb1, 0x00, 0x00, 0x00, 0x00, 0x00}, /* SR13 */
38 {0x41, 0x51, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00}, /* SR14 */ 45 {0x41, 0x51, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00}, /* SR14 */
@@ -71,7 +78,7 @@ static unsigned char XGI27_cr41[24][8] = {
71 {0x20, 0x40, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0 CR41 */ 78 {0x20, 0x40, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0 CR41 */
72 {0xC4, 0x40, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 1 CR8A */ 79 {0xC4, 0x40, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 1 CR8A */
73 {0xC4, 0x40, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 2 CR8B */ 80 {0xC4, 0x40, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 2 CR8B */
74 {0xB5, 0x13, 0xa4, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 3 CR40[7], 81 {0xB3, 0x13, 0xa4, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 3 CR40[7],
75 CR99[2:0], 82 CR99[2:0],
76 CR45[3:0]*/ 83 CR45[3:0]*/
77 {0xf0, 0xf5, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 4 CR59 */ 84 {0xf0, 0xf5, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 4 CR59 */
@@ -2803,6 +2810,8 @@ static unsigned char XG27_CRDE[2];
2803static unsigned char XG27_SR40 = 0x04 ; 2810static unsigned char XG27_SR40 = 0x04 ;
2804static unsigned char XG27_SR41 = 0x00 ; 2811static unsigned char XG27_SR41 = 0x00 ;
2805 2812
2813static unsigned char Z11m_CR97 = 0x80 ;
2814
2806static struct XGI330_VCLKDataStruct XGI_VCLKData[] = { 2815static struct XGI330_VCLKDataStruct XGI_VCLKData[] = {
2807 /* SR2B,SR2C,SR2D */ 2816 /* SR2B,SR2C,SR2D */
2808 {0x1B, 0xE1, 25}, /* 00 (25.175MHz) */ 2817 {0x1B, 0xE1, 25}, /* 00 (25.175MHz) */
diff --git a/drivers/staging/zcache/Kconfig b/drivers/staging/zcache/Kconfig
index 3ed2c8f656a5..7048e01f0817 100644
--- a/drivers/staging/zcache/Kconfig
+++ b/drivers/staging/zcache/Kconfig
@@ -2,7 +2,7 @@ config ZCACHE
2 bool "Dynamic compression of swap pages and clean pagecache pages" 2 bool "Dynamic compression of swap pages and clean pagecache pages"
3 # X86 dependency is because zsmalloc uses non-portable pte/tlb 3 # X86 dependency is because zsmalloc uses non-portable pte/tlb
4 # functions 4 # functions
5 depends on (CLEANCACHE || FRONTSWAP) && CRYPTO && X86 5 depends on (CLEANCACHE || FRONTSWAP) && CRYPTO=y && X86
6 select ZSMALLOC 6 select ZSMALLOC
7 select CRYPTO_LZO 7 select CRYPTO_LZO
8 default n 8 default n
diff --git a/drivers/staging/zsmalloc/zsmalloc-main.c b/drivers/staging/zsmalloc/zsmalloc-main.c
index 09caa4f2687e..917461c66014 100644
--- a/drivers/staging/zsmalloc/zsmalloc-main.c
+++ b/drivers/staging/zsmalloc/zsmalloc-main.c
@@ -267,33 +267,39 @@ static unsigned long obj_idx_to_offset(struct page *page,
267 return off + obj_idx * class_size; 267 return off + obj_idx * class_size;
268} 268}
269 269
270static void reset_page(struct page *page)
271{
272 clear_bit(PG_private, &page->flags);
273 clear_bit(PG_private_2, &page->flags);
274 set_page_private(page, 0);
275 page->mapping = NULL;
276 page->freelist = NULL;
277 reset_page_mapcount(page);
278}
279
270static void free_zspage(struct page *first_page) 280static void free_zspage(struct page *first_page)
271{ 281{
272 struct page *nextp, *tmp; 282 struct page *nextp, *tmp, *head_extra;
273 283
274 BUG_ON(!is_first_page(first_page)); 284 BUG_ON(!is_first_page(first_page));
275 BUG_ON(first_page->inuse); 285 BUG_ON(first_page->inuse);
276 286
277 nextp = (struct page *)page_private(first_page); 287 head_extra = (struct page *)page_private(first_page);
278 288
279 clear_bit(PG_private, &first_page->flags); 289 reset_page(first_page);
280 clear_bit(PG_private_2, &first_page->flags);
281 set_page_private(first_page, 0);
282 first_page->mapping = NULL;
283 first_page->freelist = NULL;
284 reset_page_mapcount(first_page);
285 __free_page(first_page); 290 __free_page(first_page);
286 291
287 /* zspage with only 1 system page */ 292 /* zspage with only 1 system page */
288 if (!nextp) 293 if (!head_extra)
289 return; 294 return;
290 295
291 list_for_each_entry_safe(nextp, tmp, &nextp->lru, lru) { 296 list_for_each_entry_safe(nextp, tmp, &head_extra->lru, lru) {
292 list_del(&nextp->lru); 297 list_del(&nextp->lru);
293 clear_bit(PG_private_2, &nextp->flags); 298 reset_page(nextp);
294 nextp->index = 0;
295 __free_page(nextp); 299 __free_page(nextp);
296 } 300 }
301 reset_page(head_extra);
302 __free_page(head_extra);
297} 303}
298 304
299/* Initialize a newly allocated zspage */ 305/* Initialize a newly allocated zspage */
diff --git a/drivers/target/target_core_tpg.c b/drivers/target/target_core_tpg.c
index 70c3ffb981e7..e320ec24aa1b 100644
--- a/drivers/target/target_core_tpg.c
+++ b/drivers/target/target_core_tpg.c
@@ -60,7 +60,6 @@ static void core_clear_initiator_node_from_tpg(
60 int i; 60 int i;
61 struct se_dev_entry *deve; 61 struct se_dev_entry *deve;
62 struct se_lun *lun; 62 struct se_lun *lun;
63 struct se_lun_acl *acl, *acl_tmp;
64 63
65 spin_lock_irq(&nacl->device_list_lock); 64 spin_lock_irq(&nacl->device_list_lock);
66 for (i = 0; i < TRANSPORT_MAX_LUNS_PER_TPG; i++) { 65 for (i = 0; i < TRANSPORT_MAX_LUNS_PER_TPG; i++) {
@@ -81,28 +80,7 @@ static void core_clear_initiator_node_from_tpg(
81 core_update_device_list_for_node(lun, NULL, deve->mapped_lun, 80 core_update_device_list_for_node(lun, NULL, deve->mapped_lun,
82 TRANSPORT_LUNFLAGS_NO_ACCESS, nacl, tpg, 0); 81 TRANSPORT_LUNFLAGS_NO_ACCESS, nacl, tpg, 0);
83 82
84 spin_lock(&lun->lun_acl_lock);
85 list_for_each_entry_safe(acl, acl_tmp,
86 &lun->lun_acl_list, lacl_list) {
87 if (!strcmp(acl->initiatorname, nacl->initiatorname) &&
88 (acl->mapped_lun == deve->mapped_lun))
89 break;
90 }
91
92 if (!acl) {
93 pr_err("Unable to locate struct se_lun_acl for %s,"
94 " mapped_lun: %u\n", nacl->initiatorname,
95 deve->mapped_lun);
96 spin_unlock(&lun->lun_acl_lock);
97 spin_lock_irq(&nacl->device_list_lock);
98 continue;
99 }
100
101 list_del(&acl->lacl_list);
102 spin_unlock(&lun->lun_acl_lock);
103
104 spin_lock_irq(&nacl->device_list_lock); 83 spin_lock_irq(&nacl->device_list_lock);
105 kfree(acl);
106 } 84 }
107 spin_unlock_irq(&nacl->device_list_lock); 85 spin_unlock_irq(&nacl->device_list_lock);
108} 86}
diff --git a/drivers/target/tcm_fc/tcm_fc.h b/drivers/target/tcm_fc/tcm_fc.h
index 830657908db8..c5eb3c33c3db 100644
--- a/drivers/target/tcm_fc/tcm_fc.h
+++ b/drivers/target/tcm_fc/tcm_fc.h
@@ -122,6 +122,7 @@ struct ft_cmd {
122 /* Local sense buffer */ 122 /* Local sense buffer */
123 unsigned char ft_sense_buffer[TRANSPORT_SENSE_BUFFER]; 123 unsigned char ft_sense_buffer[TRANSPORT_SENSE_BUFFER];
124 u32 was_ddp_setup:1; /* Set only if ddp is setup */ 124 u32 was_ddp_setup:1; /* Set only if ddp is setup */
125 u32 aborted:1; /* Set if aborted by reset or timeout */
125 struct scatterlist *sg; /* Set only if DDP is setup */ 126 struct scatterlist *sg; /* Set only if DDP is setup */
126 u32 sg_cnt; /* No. of item in scatterlist */ 127 u32 sg_cnt; /* No. of item in scatterlist */
127}; 128};
diff --git a/drivers/target/tcm_fc/tfc_cmd.c b/drivers/target/tcm_fc/tfc_cmd.c
index 62dec9715ce5..a375f257aabc 100644
--- a/drivers/target/tcm_fc/tfc_cmd.c
+++ b/drivers/target/tcm_fc/tfc_cmd.c
@@ -121,6 +121,8 @@ int ft_queue_status(struct se_cmd *se_cmd)
121 struct fc_exch *ep; 121 struct fc_exch *ep;
122 size_t len; 122 size_t len;
123 123
124 if (cmd->aborted)
125 return 0;
124 ft_dump_cmd(cmd, __func__); 126 ft_dump_cmd(cmd, __func__);
125 ep = fc_seq_exch(cmd->seq); 127 ep = fc_seq_exch(cmd->seq);
126 lport = ep->lp; 128 lport = ep->lp;
@@ -187,6 +189,8 @@ int ft_write_pending(struct se_cmd *se_cmd)
187 189
188 ft_dump_cmd(cmd, __func__); 190 ft_dump_cmd(cmd, __func__);
189 191
192 if (cmd->aborted)
193 return 0;
190 ep = fc_seq_exch(cmd->seq); 194 ep = fc_seq_exch(cmd->seq);
191 lport = ep->lp; 195 lport = ep->lp;
192 fp = fc_frame_alloc(lport, sizeof(*txrdy)); 196 fp = fc_frame_alloc(lport, sizeof(*txrdy));
@@ -252,10 +256,10 @@ static void ft_recv_seq(struct fc_seq *sp, struct fc_frame *fp, void *arg)
252 struct ft_cmd *cmd = arg; 256 struct ft_cmd *cmd = arg;
253 struct fc_frame_header *fh; 257 struct fc_frame_header *fh;
254 258
255 if (IS_ERR(fp)) { 259 if (unlikely(IS_ERR(fp))) {
256 /* XXX need to find cmd if queued */ 260 /* XXX need to find cmd if queued */
257 cmd->seq = NULL; 261 cmd->seq = NULL;
258 transport_generic_free_cmd(&cmd->se_cmd, 0); 262 cmd->aborted = true;
259 return; 263 return;
260 } 264 }
261 265
@@ -399,6 +403,8 @@ int ft_queue_tm_resp(struct se_cmd *se_cmd)
399 struct se_tmr_req *tmr = se_cmd->se_tmr_req; 403 struct se_tmr_req *tmr = se_cmd->se_tmr_req;
400 enum fcp_resp_rsp_codes code; 404 enum fcp_resp_rsp_codes code;
401 405
406 if (cmd->aborted)
407 return 0;
402 switch (tmr->response) { 408 switch (tmr->response) {
403 case TMR_FUNCTION_COMPLETE: 409 case TMR_FUNCTION_COMPLETE:
404 code = FCP_TMF_CMPL; 410 code = FCP_TMF_CMPL;
diff --git a/drivers/target/tcm_fc/tfc_conf.c b/drivers/target/tcm_fc/tfc_conf.c
index f357039349ba..2948dc944619 100644
--- a/drivers/target/tcm_fc/tfc_conf.c
+++ b/drivers/target/tcm_fc/tfc_conf.c
@@ -300,6 +300,7 @@ static struct se_portal_group *ft_add_tpg(
300{ 300{
301 struct ft_lport_acl *lacl; 301 struct ft_lport_acl *lacl;
302 struct ft_tpg *tpg; 302 struct ft_tpg *tpg;
303 struct workqueue_struct *wq;
303 unsigned long index; 304 unsigned long index;
304 int ret; 305 int ret;
305 306
@@ -321,18 +322,20 @@ static struct se_portal_group *ft_add_tpg(
321 tpg->lport_acl = lacl; 322 tpg->lport_acl = lacl;
322 INIT_LIST_HEAD(&tpg->lun_list); 323 INIT_LIST_HEAD(&tpg->lun_list);
323 324
324 ret = core_tpg_register(&ft_configfs->tf_ops, wwn, &tpg->se_tpg, 325 wq = alloc_workqueue("tcm_fc", 0, 1);
325 tpg, TRANSPORT_TPG_TYPE_NORMAL); 326 if (!wq) {
326 if (ret < 0) {
327 kfree(tpg); 327 kfree(tpg);
328 return NULL; 328 return NULL;
329 } 329 }
330 330
331 tpg->workqueue = alloc_workqueue("tcm_fc", 0, 1); 331 ret = core_tpg_register(&ft_configfs->tf_ops, wwn, &tpg->se_tpg,
332 if (!tpg->workqueue) { 332 tpg, TRANSPORT_TPG_TYPE_NORMAL);
333 if (ret < 0) {
334 destroy_workqueue(wq);
333 kfree(tpg); 335 kfree(tpg);
334 return NULL; 336 return NULL;
335 } 337 }
338 tpg->workqueue = wq;
336 339
337 mutex_lock(&ft_lport_lock); 340 mutex_lock(&ft_lport_lock);
338 list_add_tail(&tpg->list, &lacl->tpg_list); 341 list_add_tail(&tpg->list, &lacl->tpg_list);
diff --git a/drivers/target/tcm_fc/tfc_io.c b/drivers/target/tcm_fc/tfc_io.c
index 2b693eefac55..dc7c0db26e20 100644
--- a/drivers/target/tcm_fc/tfc_io.c
+++ b/drivers/target/tcm_fc/tfc_io.c
@@ -81,6 +81,8 @@ int ft_queue_data_in(struct se_cmd *se_cmd)
81 void *from; 81 void *from;
82 void *to = NULL; 82 void *to = NULL;
83 83
84 if (cmd->aborted)
85 return 0;
84 ep = fc_seq_exch(cmd->seq); 86 ep = fc_seq_exch(cmd->seq);
85 lport = ep->lp; 87 lport = ep->lp;
86 cmd->seq = lport->tt.seq_start_next(cmd->seq); 88 cmd->seq = lport->tt.seq_start_next(cmd->seq);
diff --git a/drivers/tty/amiserial.c b/drivers/tty/amiserial.c
index 24145c30c9b0..6cc4358f68c1 100644
--- a/drivers/tty/amiserial.c
+++ b/drivers/tty/amiserial.c
@@ -1073,8 +1073,10 @@ static int set_serial_info(struct tty_struct *tty, struct serial_state *state,
1073 (new_serial.close_delay != port->close_delay) || 1073 (new_serial.close_delay != port->close_delay) ||
1074 (new_serial.xmit_fifo_size != state->xmit_fifo_size) || 1074 (new_serial.xmit_fifo_size != state->xmit_fifo_size) ||
1075 ((new_serial.flags & ~ASYNC_USR_MASK) != 1075 ((new_serial.flags & ~ASYNC_USR_MASK) !=
1076 (port->flags & ~ASYNC_USR_MASK))) 1076 (port->flags & ~ASYNC_USR_MASK))) {
1077 tty_unlock();
1077 return -EPERM; 1078 return -EPERM;
1079 }
1078 port->flags = ((port->flags & ~ASYNC_USR_MASK) | 1080 port->flags = ((port->flags & ~ASYNC_USR_MASK) |
1079 (new_serial.flags & ASYNC_USR_MASK)); 1081 (new_serial.flags & ASYNC_USR_MASK));
1080 state->custom_divisor = new_serial.custom_divisor; 1082 state->custom_divisor = new_serial.custom_divisor;
diff --git a/drivers/tty/serial/8250/8250.c b/drivers/tty/serial/8250/8250.c
index 5b149b466ec8..5c27f7e6c9f1 100644
--- a/drivers/tty/serial/8250/8250.c
+++ b/drivers/tty/serial/8250/8250.c
@@ -1572,13 +1572,11 @@ static irqreturn_t serial8250_interrupt(int irq, void *dev_id)
1572 do { 1572 do {
1573 struct uart_8250_port *up; 1573 struct uart_8250_port *up;
1574 struct uart_port *port; 1574 struct uart_port *port;
1575 bool skip;
1576 1575
1577 up = list_entry(l, struct uart_8250_port, list); 1576 up = list_entry(l, struct uart_8250_port, list);
1578 port = &up->port; 1577 port = &up->port;
1579 skip = pass_counter && up->port.flags & UPF_IIR_ONCE;
1580 1578
1581 if (!skip && port->handle_irq(port)) { 1579 if (port->handle_irq(port)) {
1582 handled = 1; 1580 handled = 1;
1583 end = NULL; 1581 end = NULL;
1584 } else if (end == NULL) 1582 } else if (end == NULL)
@@ -2037,10 +2035,12 @@ static int serial8250_startup(struct uart_port *port)
2037 spin_unlock_irqrestore(&port->lock, flags); 2035 spin_unlock_irqrestore(&port->lock, flags);
2038 2036
2039 /* 2037 /*
2040 * If the interrupt is not reasserted, setup a timer to 2038 * If the interrupt is not reasserted, or we otherwise
2041 * kick the UART on a regular basis. 2039 * don't trust the iir, setup a timer to kick the UART
2040 * on a regular basis.
2042 */ 2041 */
2043 if (!(iir1 & UART_IIR_NO_INT) && (iir & UART_IIR_NO_INT)) { 2042 if ((!(iir1 & UART_IIR_NO_INT) && (iir & UART_IIR_NO_INT)) ||
2043 up->port.flags & UPF_BUG_THRE) {
2044 up->bugs |= UART_BUG_THRE; 2044 up->bugs |= UART_BUG_THRE;
2045 pr_debug("ttyS%d - using backup timer\n", 2045 pr_debug("ttyS%d - using backup timer\n",
2046 serial_index(port)); 2046 serial_index(port));
diff --git a/drivers/tty/serial/8250/8250_pci.c b/drivers/tty/serial/8250/8250_pci.c
index da2b0b0a183f..858dca865d6a 100644
--- a/drivers/tty/serial/8250/8250_pci.c
+++ b/drivers/tty/serial/8250/8250_pci.c
@@ -1096,7 +1096,7 @@ static int kt_serial_setup(struct serial_private *priv,
1096 const struct pciserial_board *board, 1096 const struct pciserial_board *board,
1097 struct uart_port *port, int idx) 1097 struct uart_port *port, int idx)
1098{ 1098{
1099 port->flags |= UPF_IIR_ONCE; 1099 port->flags |= UPF_BUG_THRE;
1100 return skip_tx_en_setup(priv, board, port, idx); 1100 return skip_tx_en_setup(priv, board, port, idx);
1101} 1101}
1102 1102
@@ -1118,18 +1118,6 @@ pci_xr17c154_setup(struct serial_private *priv,
1118 return pci_default_setup(priv, board, port, idx); 1118 return pci_default_setup(priv, board, port, idx);
1119} 1119}
1120 1120
1121static int try_enable_msi(struct pci_dev *dev)
1122{
1123 /* use msi if available, but fallback to legacy otherwise */
1124 pci_enable_msi(dev);
1125 return 0;
1126}
1127
1128static void disable_msi(struct pci_dev *dev)
1129{
1130 pci_disable_msi(dev);
1131}
1132
1133#define PCI_VENDOR_ID_SBSMODULARIO 0x124B 1121#define PCI_VENDOR_ID_SBSMODULARIO 0x124B
1134#define PCI_SUBVENDOR_ID_SBSMODULARIO 0x124B 1122#define PCI_SUBVENDOR_ID_SBSMODULARIO 0x124B
1135#define PCI_DEVICE_ID_OCTPRO 0x0001 1123#define PCI_DEVICE_ID_OCTPRO 0x0001
@@ -1249,9 +1237,7 @@ static struct pci_serial_quirk pci_serial_quirks[] __refdata = {
1249 .device = PCI_DEVICE_ID_INTEL_PATSBURG_KT, 1237 .device = PCI_DEVICE_ID_INTEL_PATSBURG_KT,
1250 .subvendor = PCI_ANY_ID, 1238 .subvendor = PCI_ANY_ID,
1251 .subdevice = PCI_ANY_ID, 1239 .subdevice = PCI_ANY_ID,
1252 .init = try_enable_msi,
1253 .setup = kt_serial_setup, 1240 .setup = kt_serial_setup,
1254 .exit = disable_msi,
1255 }, 1241 },
1256 /* 1242 /*
1257 * ITE 1243 * ITE
diff --git a/drivers/tty/serial/Kconfig b/drivers/tty/serial/Kconfig
index 665beb68f670..070b442c1f81 100644
--- a/drivers/tty/serial/Kconfig
+++ b/drivers/tty/serial/Kconfig
@@ -1041,7 +1041,7 @@ config SERIAL_OMAP
1041 1041
1042config SERIAL_OMAP_CONSOLE 1042config SERIAL_OMAP_CONSOLE
1043 bool "Console on OMAP serial port" 1043 bool "Console on OMAP serial port"
1044 depends on SERIAL_OMAP 1044 depends on SERIAL_OMAP=y
1045 select SERIAL_CORE_CONSOLE 1045 select SERIAL_CORE_CONSOLE
1046 help 1046 help
1047 Select this option if you would like to use omap serial port as 1047 Select this option if you would like to use omap serial port as
diff --git a/drivers/tty/serial/altera_uart.c b/drivers/tty/serial/altera_uart.c
index e7903751e058..1f0330915d5a 100644
--- a/drivers/tty/serial/altera_uart.c
+++ b/drivers/tty/serial/altera_uart.c
@@ -556,7 +556,7 @@ static int __devinit altera_uart_probe(struct platform_device *pdev)
556 res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 556 res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
557 if (res_mem) 557 if (res_mem)
558 port->mapbase = res_mem->start; 558 port->mapbase = res_mem->start;
559 else if (platp->mapbase) 559 else if (platp)
560 port->mapbase = platp->mapbase; 560 port->mapbase = platp->mapbase;
561 else 561 else
562 return -EINVAL; 562 return -EINVAL;
@@ -564,7 +564,7 @@ static int __devinit altera_uart_probe(struct platform_device *pdev)
564 res_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 564 res_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
565 if (res_irq) 565 if (res_irq)
566 port->irq = res_irq->start; 566 port->irq = res_irq->start;
567 else if (platp->irq) 567 else if (platp)
568 port->irq = platp->irq; 568 port->irq = platp->irq;
569 569
570 /* Check platform data first so we can override device node data */ 570 /* Check platform data first so we can override device node data */
diff --git a/drivers/tty/serial/amba-pl011.c b/drivers/tty/serial/amba-pl011.c
index 0c65c9e66986..3d569cd68f58 100644
--- a/drivers/tty/serial/amba-pl011.c
+++ b/drivers/tty/serial/amba-pl011.c
@@ -1946,10 +1946,6 @@ static int pl011_probe(struct amba_device *dev, const struct amba_id *id)
1946 goto unmap; 1946 goto unmap;
1947 } 1947 }
1948 1948
1949 /* Ensure interrupts from this UART are masked and cleared */
1950 writew(0, uap->port.membase + UART011_IMSC);
1951 writew(0xffff, uap->port.membase + UART011_ICR);
1952
1953 uap->vendor = vendor; 1949 uap->vendor = vendor;
1954 uap->lcrh_rx = vendor->lcrh_rx; 1950 uap->lcrh_rx = vendor->lcrh_rx;
1955 uap->lcrh_tx = vendor->lcrh_tx; 1951 uap->lcrh_tx = vendor->lcrh_tx;
@@ -1967,6 +1963,10 @@ static int pl011_probe(struct amba_device *dev, const struct amba_id *id)
1967 uap->port.line = i; 1963 uap->port.line = i;
1968 pl011_dma_probe(uap); 1964 pl011_dma_probe(uap);
1969 1965
1966 /* Ensure interrupts from this UART are masked and cleared */
1967 writew(0, uap->port.membase + UART011_IMSC);
1968 writew(0xffff, uap->port.membase + UART011_ICR);
1969
1970 snprintf(uap->type, sizeof(uap->type), "PL011 rev%u", amba_rev(dev)); 1970 snprintf(uap->type, sizeof(uap->type), "PL011 rev%u", amba_rev(dev));
1971 1971
1972 amba_ports[i] = uap; 1972 amba_ports[i] = uap;
diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
index f9a6be7a9bed..3d7e1ee2fa57 100644
--- a/drivers/tty/serial/atmel_serial.c
+++ b/drivers/tty/serial/atmel_serial.c
@@ -389,6 +389,8 @@ static void atmel_start_rx(struct uart_port *port)
389{ 389{
390 UART_PUT_CR(port, ATMEL_US_RSTSTA); /* reset status and receiver */ 390 UART_PUT_CR(port, ATMEL_US_RSTSTA); /* reset status and receiver */
391 391
392 UART_PUT_CR(port, ATMEL_US_RXEN);
393
392 if (atmel_use_dma_rx(port)) { 394 if (atmel_use_dma_rx(port)) {
393 /* enable PDC controller */ 395 /* enable PDC controller */
394 UART_PUT_IER(port, ATMEL_US_ENDRX | ATMEL_US_TIMEOUT | 396 UART_PUT_IER(port, ATMEL_US_ENDRX | ATMEL_US_TIMEOUT |
@@ -404,6 +406,8 @@ static void atmel_start_rx(struct uart_port *port)
404 */ 406 */
405static void atmel_stop_rx(struct uart_port *port) 407static void atmel_stop_rx(struct uart_port *port)
406{ 408{
409 UART_PUT_CR(port, ATMEL_US_RXDIS);
410
407 if (atmel_use_dma_rx(port)) { 411 if (atmel_use_dma_rx(port)) {
408 /* disable PDC receive */ 412 /* disable PDC receive */
409 UART_PUT_PTCR(port, ATMEL_PDC_RXTDIS); 413 UART_PUT_PTCR(port, ATMEL_PDC_RXTDIS);
diff --git a/drivers/tty/serial/clps711x.c b/drivers/tty/serial/clps711x.c
index e6c3dbd781d6..836fe2731234 100644
--- a/drivers/tty/serial/clps711x.c
+++ b/drivers/tty/serial/clps711x.c
@@ -154,10 +154,9 @@ static irqreturn_t clps711xuart_int_tx(int irq, void *dev_id)
154 port->x_char = 0; 154 port->x_char = 0;
155 return IRQ_HANDLED; 155 return IRQ_HANDLED;
156 } 156 }
157 if (uart_circ_empty(xmit) || uart_tx_stopped(port)) { 157
158 clps711xuart_stop_tx(port); 158 if (uart_circ_empty(xmit) || uart_tx_stopped(port))
159 return IRQ_HANDLED; 159 goto disable_tx_irq;
160 }
161 160
162 count = port->fifosize >> 1; 161 count = port->fifosize >> 1;
163 do { 162 do {
@@ -171,8 +170,11 @@ static irqreturn_t clps711xuart_int_tx(int irq, void *dev_id)
171 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) 170 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
172 uart_write_wakeup(port); 171 uart_write_wakeup(port);
173 172
174 if (uart_circ_empty(xmit)) 173 if (uart_circ_empty(xmit)) {
175 clps711xuart_stop_tx(port); 174 disable_tx_irq:
175 disable_irq_nosync(TX_IRQ(port));
176 tx_enabled(port) = 0;
177 }
176 178
177 return IRQ_HANDLED; 179 return IRQ_HANDLED;
178} 180}
diff --git a/drivers/tty/serial/mfd.c b/drivers/tty/serial/mfd.c
index a9234ba8f8d5..c4b50af46c44 100644
--- a/drivers/tty/serial/mfd.c
+++ b/drivers/tty/serial/mfd.c
@@ -127,11 +127,6 @@ static inline void serial_out(struct uart_hsu_port *up, int offset, int value)
127 127
128#define HSU_REGS_BUFSIZE 1024 128#define HSU_REGS_BUFSIZE 1024
129 129
130static int hsu_show_regs_open(struct inode *inode, struct file *file)
131{
132 file->private_data = inode->i_private;
133 return 0;
134}
135 130
136static ssize_t port_show_regs(struct file *file, char __user *user_buf, 131static ssize_t port_show_regs(struct file *file, char __user *user_buf,
137 size_t count, loff_t *ppos) 132 size_t count, loff_t *ppos)
@@ -231,14 +226,14 @@ static ssize_t dma_show_regs(struct file *file, char __user *user_buf,
231 226
232static const struct file_operations port_regs_ops = { 227static const struct file_operations port_regs_ops = {
233 .owner = THIS_MODULE, 228 .owner = THIS_MODULE,
234 .open = hsu_show_regs_open, 229 .open = simple_open,
235 .read = port_show_regs, 230 .read = port_show_regs,
236 .llseek = default_llseek, 231 .llseek = default_llseek,
237}; 232};
238 233
239static const struct file_operations dma_regs_ops = { 234static const struct file_operations dma_regs_ops = {
240 .owner = THIS_MODULE, 235 .owner = THIS_MODULE,
241 .open = hsu_show_regs_open, 236 .open = simple_open,
242 .read = dma_show_regs, 237 .read = dma_show_regs,
243 .llseek = default_llseek, 238 .llseek = default_llseek,
244}; 239};
diff --git a/drivers/tty/serial/omap-serial.c b/drivers/tty/serial/omap-serial.c
index 0121486ac4fa..d00b38eb268e 100644
--- a/drivers/tty/serial/omap-serial.c
+++ b/drivers/tty/serial/omap-serial.c
@@ -1381,29 +1381,24 @@ static int serial_omap_probe(struct platform_device *pdev)
1381 return -ENODEV; 1381 return -ENODEV;
1382 } 1382 }
1383 1383
1384 if (!request_mem_region(mem->start, resource_size(mem), 1384 if (!devm_request_mem_region(&pdev->dev, mem->start, resource_size(mem),
1385 pdev->dev.driver->name)) { 1385 pdev->dev.driver->name)) {
1386 dev_err(&pdev->dev, "memory region already claimed\n"); 1386 dev_err(&pdev->dev, "memory region already claimed\n");
1387 return -EBUSY; 1387 return -EBUSY;
1388 } 1388 }
1389 1389
1390 dma_rx = platform_get_resource_byname(pdev, IORESOURCE_DMA, "rx"); 1390 dma_rx = platform_get_resource_byname(pdev, IORESOURCE_DMA, "rx");
1391 if (!dma_rx) { 1391 if (!dma_rx)
1392 ret = -EINVAL; 1392 return -ENXIO;
1393 goto err;
1394 }
1395 1393
1396 dma_tx = platform_get_resource_byname(pdev, IORESOURCE_DMA, "tx"); 1394 dma_tx = platform_get_resource_byname(pdev, IORESOURCE_DMA, "tx");
1397 if (!dma_tx) { 1395 if (!dma_tx)
1398 ret = -EINVAL; 1396 return -ENXIO;
1399 goto err; 1397
1400 } 1398 up = devm_kzalloc(&pdev->dev, sizeof(*up), GFP_KERNEL);
1399 if (!up)
1400 return -ENOMEM;
1401 1401
1402 up = kzalloc(sizeof(*up), GFP_KERNEL);
1403 if (up == NULL) {
1404 ret = -ENOMEM;
1405 goto do_release_region;
1406 }
1407 up->pdev = pdev; 1402 up->pdev = pdev;
1408 up->port.dev = &pdev->dev; 1403 up->port.dev = &pdev->dev;
1409 up->port.type = PORT_OMAP; 1404 up->port.type = PORT_OMAP;
@@ -1423,16 +1418,17 @@ static int serial_omap_probe(struct platform_device *pdev)
1423 dev_err(&pdev->dev, "failed to get alias/pdev id, errno %d\n", 1418 dev_err(&pdev->dev, "failed to get alias/pdev id, errno %d\n",
1424 up->port.line); 1419 up->port.line);
1425 ret = -ENODEV; 1420 ret = -ENODEV;
1426 goto err; 1421 goto err_port_line;
1427 } 1422 }
1428 1423
1429 sprintf(up->name, "OMAP UART%d", up->port.line); 1424 sprintf(up->name, "OMAP UART%d", up->port.line);
1430 up->port.mapbase = mem->start; 1425 up->port.mapbase = mem->start;
1431 up->port.membase = ioremap(mem->start, resource_size(mem)); 1426 up->port.membase = devm_ioremap(&pdev->dev, mem->start,
1427 resource_size(mem));
1432 if (!up->port.membase) { 1428 if (!up->port.membase) {
1433 dev_err(&pdev->dev, "can't ioremap UART\n"); 1429 dev_err(&pdev->dev, "can't ioremap UART\n");
1434 ret = -ENOMEM; 1430 ret = -ENOMEM;
1435 goto err; 1431 goto err_ioremap;
1436 } 1432 }
1437 1433
1438 up->port.flags = omap_up_info->flags; 1434 up->port.flags = omap_up_info->flags;
@@ -1478,16 +1474,19 @@ static int serial_omap_probe(struct platform_device *pdev)
1478 1474
1479 ret = uart_add_one_port(&serial_omap_reg, &up->port); 1475 ret = uart_add_one_port(&serial_omap_reg, &up->port);
1480 if (ret != 0) 1476 if (ret != 0)
1481 goto do_release_region; 1477 goto err_add_port;
1482 1478
1483 pm_runtime_put(&pdev->dev); 1479 pm_runtime_put(&pdev->dev);
1484 platform_set_drvdata(pdev, up); 1480 platform_set_drvdata(pdev, up);
1485 return 0; 1481 return 0;
1486err: 1482
1483err_add_port:
1484 pm_runtime_put(&pdev->dev);
1485 pm_runtime_disable(&pdev->dev);
1486err_ioremap:
1487err_port_line:
1487 dev_err(&pdev->dev, "[UART%d]: failure [%s]: %d\n", 1488 dev_err(&pdev->dev, "[UART%d]: failure [%s]: %d\n",
1488 pdev->id, __func__, ret); 1489 pdev->id, __func__, ret);
1489do_release_region:
1490 release_mem_region(mem->start, resource_size(mem));
1491 return ret; 1490 return ret;
1492} 1491}
1493 1492
@@ -1499,8 +1498,6 @@ static int serial_omap_remove(struct platform_device *dev)
1499 pm_runtime_disable(&up->pdev->dev); 1498 pm_runtime_disable(&up->pdev->dev);
1500 uart_remove_one_port(&serial_omap_reg, &up->port); 1499 uart_remove_one_port(&serial_omap_reg, &up->port);
1501 pm_qos_remove_request(&up->pm_qos_request); 1500 pm_qos_remove_request(&up->pm_qos_request);
1502
1503 kfree(up);
1504 } 1501 }
1505 1502
1506 platform_set_drvdata(dev, NULL); 1503 platform_set_drvdata(dev, NULL);
diff --git a/drivers/tty/serial/pch_uart.c b/drivers/tty/serial/pch_uart.c
index e825460478be..c2816f494807 100644
--- a/drivers/tty/serial/pch_uart.c
+++ b/drivers/tty/serial/pch_uart.c
@@ -210,6 +210,7 @@ enum {
210#define CMITC_UARTCLK 192000000 /* 192.0000 MHz */ 210#define CMITC_UARTCLK 192000000 /* 192.0000 MHz */
211#define FRI2_64_UARTCLK 64000000 /* 64.0000 MHz */ 211#define FRI2_64_UARTCLK 64000000 /* 64.0000 MHz */
212#define FRI2_48_UARTCLK 48000000 /* 48.0000 MHz */ 212#define FRI2_48_UARTCLK 48000000 /* 48.0000 MHz */
213#define NTC1_UARTCLK 64000000 /* 64.0000 MHz */
213 214
214struct pch_uart_buffer { 215struct pch_uart_buffer {
215 unsigned char *buf; 216 unsigned char *buf;
@@ -304,11 +305,7 @@ static const int trigger_level_1[4] = { 1, 1, 1, 1 };
304#ifdef CONFIG_DEBUG_FS 305#ifdef CONFIG_DEBUG_FS
305 306
306#define PCH_REGS_BUFSIZE 1024 307#define PCH_REGS_BUFSIZE 1024
307static int pch_show_regs_open(struct inode *inode, struct file *file) 308
308{
309 file->private_data = inode->i_private;
310 return 0;
311}
312 309
313static ssize_t port_show_regs(struct file *file, char __user *user_buf, 310static ssize_t port_show_regs(struct file *file, char __user *user_buf,
314 size_t count, loff_t *ppos) 311 size_t count, loff_t *ppos)
@@ -362,7 +359,7 @@ static ssize_t port_show_regs(struct file *file, char __user *user_buf,
362 359
363static const struct file_operations port_regs_ops = { 360static const struct file_operations port_regs_ops = {
364 .owner = THIS_MODULE, 361 .owner = THIS_MODULE,
365 .open = pch_show_regs_open, 362 .open = simple_open,
366 .read = port_show_regs, 363 .read = port_show_regs,
367 .llseek = default_llseek, 364 .llseek = default_llseek,
368}; 365};
@@ -388,6 +385,12 @@ static int pch_uart_get_uartclk(void)
388 if (cmp && strstr(cmp, "Fish River Island II")) 385 if (cmp && strstr(cmp, "Fish River Island II"))
389 return FRI2_48_UARTCLK; 386 return FRI2_48_UARTCLK;
390 387
388 /* Kontron COMe-mTT10 (nanoETXexpress-TT) */
389 cmp = dmi_get_system_info(DMI_BOARD_NAME);
390 if (cmp && (strstr(cmp, "COMe-mTT") ||
391 strstr(cmp, "nanoETXexpress-TT")))
392 return NTC1_UARTCLK;
393
391 return DEFAULT_UARTCLK; 394 return DEFAULT_UARTCLK;
392} 395}
393 396
@@ -1444,9 +1447,11 @@ static int pch_uart_verify_port(struct uart_port *port,
1444 __func__); 1447 __func__);
1445 return -EOPNOTSUPP; 1448 return -EOPNOTSUPP;
1446#endif 1449#endif
1447 priv->use_dma = 1;
1448 priv->use_dma_flag = 1; 1450 priv->use_dma_flag = 1;
1449 dev_info(priv->port.dev, "PCH UART : Use DMA Mode\n"); 1451 dev_info(priv->port.dev, "PCH UART : Use DMA Mode\n");
1452 if (!priv->use_dma)
1453 pch_request_dma(port);
1454 priv->use_dma = 1;
1450 } 1455 }
1451 1456
1452 return 0; 1457 return 0;
@@ -1655,6 +1660,7 @@ static struct eg20t_port *pch_uart_init_port(struct pci_dev *pdev,
1655 } 1660 }
1656 1661
1657 pci_enable_msi(pdev); 1662 pci_enable_msi(pdev);
1663 pci_set_master(pdev);
1658 1664
1659 iobase = pci_resource_start(pdev, 0); 1665 iobase = pci_resource_start(pdev, 0);
1660 mapbase = pci_resource_start(pdev, 1); 1666 mapbase = pci_resource_start(pdev, 1);
diff --git a/drivers/tty/serial/pmac_zilog.c b/drivers/tty/serial/pmac_zilog.c
index 08ebe901bb59..654755a990df 100644
--- a/drivers/tty/serial/pmac_zilog.c
+++ b/drivers/tty/serial/pmac_zilog.c
@@ -469,7 +469,7 @@ static irqreturn_t pmz_interrupt(int irq, void *dev_id)
469 tty = NULL; 469 tty = NULL;
470 if (r3 & (CHAEXT | CHATxIP | CHARxIP)) { 470 if (r3 & (CHAEXT | CHATxIP | CHARxIP)) {
471 if (!ZS_IS_OPEN(uap_a)) { 471 if (!ZS_IS_OPEN(uap_a)) {
472 pmz_debug("ChanA interrupt while open !\n"); 472 pmz_debug("ChanA interrupt while not open !\n");
473 goto skip_a; 473 goto skip_a;
474 } 474 }
475 write_zsreg(uap_a, R0, RES_H_IUS); 475 write_zsreg(uap_a, R0, RES_H_IUS);
@@ -493,8 +493,8 @@ static irqreturn_t pmz_interrupt(int irq, void *dev_id)
493 spin_lock(&uap_b->port.lock); 493 spin_lock(&uap_b->port.lock);
494 tty = NULL; 494 tty = NULL;
495 if (r3 & (CHBEXT | CHBTxIP | CHBRxIP)) { 495 if (r3 & (CHBEXT | CHBTxIP | CHBRxIP)) {
496 if (!ZS_IS_OPEN(uap_a)) { 496 if (!ZS_IS_OPEN(uap_b)) {
497 pmz_debug("ChanB interrupt while open !\n"); 497 pmz_debug("ChanB interrupt while not open !\n");
498 goto skip_b; 498 goto skip_b;
499 } 499 }
500 write_zsreg(uap_b, R0, RES_H_IUS); 500 write_zsreg(uap_b, R0, RES_H_IUS);
diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
index de249d265bec..d8b0aee35632 100644
--- a/drivers/tty/serial/samsung.c
+++ b/drivers/tty/serial/samsung.c
@@ -982,6 +982,7 @@ static void s3c24xx_serial_resetport(struct uart_port *port,
982 982
983 ucon &= ucon_mask; 983 ucon &= ucon_mask;
984 wr_regl(port, S3C2410_UCON, ucon | cfg->ucon); 984 wr_regl(port, S3C2410_UCON, ucon | cfg->ucon);
985 wr_regl(port, S3C2410_ULCON, cfg->ulcon);
985 986
986 /* reset both fifos */ 987 /* reset both fifos */
987 wr_regl(port, S3C2410_UFCON, cfg->ufcon | S3C2410_UFCON_RESETBOTH); 988 wr_regl(port, S3C2410_UFCON, cfg->ufcon | S3C2410_UFCON_RESETBOTH);
diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index bf461cf99616..3158e17b665c 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -355,9 +355,6 @@ static void sci_serial_out(struct uart_port *p, int offset, int value)
355 WARN(1, "Invalid register access\n"); 355 WARN(1, "Invalid register access\n");
356} 356}
357 357
358#define sci_in(up, offset) (up->serial_in(up, offset))
359#define sci_out(up, offset, value) (up->serial_out(up, offset, value))
360
361static int sci_probe_regmap(struct plat_sci_port *cfg) 358static int sci_probe_regmap(struct plat_sci_port *cfg)
362{ 359{
363 switch (cfg->type) { 360 switch (cfg->type) {
@@ -422,9 +419,9 @@ static int sci_poll_get_char(struct uart_port *port)
422 int c; 419 int c;
423 420
424 do { 421 do {
425 status = sci_in(port, SCxSR); 422 status = serial_port_in(port, SCxSR);
426 if (status & SCxSR_ERRORS(port)) { 423 if (status & SCxSR_ERRORS(port)) {
427 sci_out(port, SCxSR, SCxSR_ERROR_CLEAR(port)); 424 serial_port_out(port, SCxSR, SCxSR_ERROR_CLEAR(port));
428 continue; 425 continue;
429 } 426 }
430 break; 427 break;
@@ -433,11 +430,11 @@ static int sci_poll_get_char(struct uart_port *port)
433 if (!(status & SCxSR_RDxF(port))) 430 if (!(status & SCxSR_RDxF(port)))
434 return NO_POLL_CHAR; 431 return NO_POLL_CHAR;
435 432
436 c = sci_in(port, SCxRDR); 433 c = serial_port_in(port, SCxRDR);
437 434
438 /* Dummy read */ 435 /* Dummy read */
439 sci_in(port, SCxSR); 436 serial_port_in(port, SCxSR);
440 sci_out(port, SCxSR, SCxSR_RDxF_CLEAR(port)); 437 serial_port_out(port, SCxSR, SCxSR_RDxF_CLEAR(port));
441 438
442 return c; 439 return c;
443} 440}
@@ -448,11 +445,11 @@ static void sci_poll_put_char(struct uart_port *port, unsigned char c)
448 unsigned short status; 445 unsigned short status;
449 446
450 do { 447 do {
451 status = sci_in(port, SCxSR); 448 status = serial_port_in(port, SCxSR);
452 } while (!(status & SCxSR_TDxE(port))); 449 } while (!(status & SCxSR_TDxE(port)));
453 450
454 sci_out(port, SCxTDR, c); 451 serial_port_out(port, SCxTDR, c);
455 sci_out(port, SCxSR, SCxSR_TDxE_CLEAR(port) & ~SCxSR_TEND(port)); 452 serial_port_out(port, SCxSR, SCxSR_TDxE_CLEAR(port) & ~SCxSR_TEND(port));
456} 453}
457#endif /* CONFIG_CONSOLE_POLL || CONFIG_SERIAL_SH_SCI_CONSOLE */ 454#endif /* CONFIG_CONSOLE_POLL || CONFIG_SERIAL_SH_SCI_CONSOLE */
458 455
@@ -480,10 +477,10 @@ static void sci_init_pins(struct uart_port *port, unsigned int cflag)
480 ((!(cflag & CRTSCTS)))) { 477 ((!(cflag & CRTSCTS)))) {
481 unsigned short status; 478 unsigned short status;
482 479
483 status = sci_in(port, SCSPTR); 480 status = serial_port_in(port, SCSPTR);
484 status &= ~SCSPTR_CTSIO; 481 status &= ~SCSPTR_CTSIO;
485 status |= SCSPTR_RTSIO; 482 status |= SCSPTR_RTSIO;
486 sci_out(port, SCSPTR, status); /* Set RTS = 1 */ 483 serial_port_out(port, SCSPTR, status); /* Set RTS = 1 */
487 } 484 }
488} 485}
489 486
@@ -493,13 +490,13 @@ static int sci_txfill(struct uart_port *port)
493 490
494 reg = sci_getreg(port, SCTFDR); 491 reg = sci_getreg(port, SCTFDR);
495 if (reg->size) 492 if (reg->size)
496 return sci_in(port, SCTFDR) & 0xff; 493 return serial_port_in(port, SCTFDR) & 0xff;
497 494
498 reg = sci_getreg(port, SCFDR); 495 reg = sci_getreg(port, SCFDR);
499 if (reg->size) 496 if (reg->size)
500 return sci_in(port, SCFDR) >> 8; 497 return serial_port_in(port, SCFDR) >> 8;
501 498
502 return !(sci_in(port, SCxSR) & SCI_TDRE); 499 return !(serial_port_in(port, SCxSR) & SCI_TDRE);
503} 500}
504 501
505static int sci_txroom(struct uart_port *port) 502static int sci_txroom(struct uart_port *port)
@@ -513,13 +510,13 @@ static int sci_rxfill(struct uart_port *port)
513 510
514 reg = sci_getreg(port, SCRFDR); 511 reg = sci_getreg(port, SCRFDR);
515 if (reg->size) 512 if (reg->size)
516 return sci_in(port, SCRFDR) & 0xff; 513 return serial_port_in(port, SCRFDR) & 0xff;
517 514
518 reg = sci_getreg(port, SCFDR); 515 reg = sci_getreg(port, SCFDR);
519 if (reg->size) 516 if (reg->size)
520 return sci_in(port, SCFDR) & ((port->fifosize << 1) - 1); 517 return serial_port_in(port, SCFDR) & ((port->fifosize << 1) - 1);
521 518
522 return (sci_in(port, SCxSR) & SCxSR_RDxF(port)) != 0; 519 return (serial_port_in(port, SCxSR) & SCxSR_RDxF(port)) != 0;
523} 520}
524 521
525/* 522/*
@@ -547,14 +544,14 @@ static void sci_transmit_chars(struct uart_port *port)
547 unsigned short ctrl; 544 unsigned short ctrl;
548 int count; 545 int count;
549 546
550 status = sci_in(port, SCxSR); 547 status = serial_port_in(port, SCxSR);
551 if (!(status & SCxSR_TDxE(port))) { 548 if (!(status & SCxSR_TDxE(port))) {
552 ctrl = sci_in(port, SCSCR); 549 ctrl = serial_port_in(port, SCSCR);
553 if (uart_circ_empty(xmit)) 550 if (uart_circ_empty(xmit))
554 ctrl &= ~SCSCR_TIE; 551 ctrl &= ~SCSCR_TIE;
555 else 552 else
556 ctrl |= SCSCR_TIE; 553 ctrl |= SCSCR_TIE;
557 sci_out(port, SCSCR, ctrl); 554 serial_port_out(port, SCSCR, ctrl);
558 return; 555 return;
559 } 556 }
560 557
@@ -573,27 +570,27 @@ static void sci_transmit_chars(struct uart_port *port)
573 break; 570 break;
574 } 571 }
575 572
576 sci_out(port, SCxTDR, c); 573 serial_port_out(port, SCxTDR, c);
577 574
578 port->icount.tx++; 575 port->icount.tx++;
579 } while (--count > 0); 576 } while (--count > 0);
580 577
581 sci_out(port, SCxSR, SCxSR_TDxE_CLEAR(port)); 578 serial_port_out(port, SCxSR, SCxSR_TDxE_CLEAR(port));
582 579
583 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) 580 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
584 uart_write_wakeup(port); 581 uart_write_wakeup(port);
585 if (uart_circ_empty(xmit)) { 582 if (uart_circ_empty(xmit)) {
586 sci_stop_tx(port); 583 sci_stop_tx(port);
587 } else { 584 } else {
588 ctrl = sci_in(port, SCSCR); 585 ctrl = serial_port_in(port, SCSCR);
589 586
590 if (port->type != PORT_SCI) { 587 if (port->type != PORT_SCI) {
591 sci_in(port, SCxSR); /* Dummy read */ 588 serial_port_in(port, SCxSR); /* Dummy read */
592 sci_out(port, SCxSR, SCxSR_TDxE_CLEAR(port)); 589 serial_port_out(port, SCxSR, SCxSR_TDxE_CLEAR(port));
593 } 590 }
594 591
595 ctrl |= SCSCR_TIE; 592 ctrl |= SCSCR_TIE;
596 sci_out(port, SCSCR, ctrl); 593 serial_port_out(port, SCSCR, ctrl);
597 } 594 }
598} 595}
599 596
@@ -608,7 +605,7 @@ static void sci_receive_chars(struct uart_port *port)
608 unsigned short status; 605 unsigned short status;
609 unsigned char flag; 606 unsigned char flag;
610 607
611 status = sci_in(port, SCxSR); 608 status = serial_port_in(port, SCxSR);
612 if (!(status & SCxSR_RDxF(port))) 609 if (!(status & SCxSR_RDxF(port)))
613 return; 610 return;
614 611
@@ -621,7 +618,7 @@ static void sci_receive_chars(struct uart_port *port)
621 break; 618 break;
622 619
623 if (port->type == PORT_SCI) { 620 if (port->type == PORT_SCI) {
624 char c = sci_in(port, SCxRDR); 621 char c = serial_port_in(port, SCxRDR);
625 if (uart_handle_sysrq_char(port, c) || 622 if (uart_handle_sysrq_char(port, c) ||
626 sci_port->break_flag) 623 sci_port->break_flag)
627 count = 0; 624 count = 0;
@@ -629,9 +626,9 @@ static void sci_receive_chars(struct uart_port *port)
629 tty_insert_flip_char(tty, c, TTY_NORMAL); 626 tty_insert_flip_char(tty, c, TTY_NORMAL);
630 } else { 627 } else {
631 for (i = 0; i < count; i++) { 628 for (i = 0; i < count; i++) {
632 char c = sci_in(port, SCxRDR); 629 char c = serial_port_in(port, SCxRDR);
633 630
634 status = sci_in(port, SCxSR); 631 status = serial_port_in(port, SCxSR);
635#if defined(CONFIG_CPU_SH3) 632#if defined(CONFIG_CPU_SH3)
636 /* Skip "chars" during break */ 633 /* Skip "chars" during break */
637 if (sci_port->break_flag) { 634 if (sci_port->break_flag) {
@@ -672,8 +669,8 @@ static void sci_receive_chars(struct uart_port *port)
672 } 669 }
673 } 670 }
674 671
675 sci_in(port, SCxSR); /* dummy read */ 672 serial_port_in(port, SCxSR); /* dummy read */
676 sci_out(port, SCxSR, SCxSR_RDxF_CLEAR(port)); 673 serial_port_out(port, SCxSR, SCxSR_RDxF_CLEAR(port));
677 674
678 copied += count; 675 copied += count;
679 port->icount.rx += count; 676 port->icount.rx += count;
@@ -683,8 +680,8 @@ static void sci_receive_chars(struct uart_port *port)
683 /* Tell the rest of the system the news. New characters! */ 680 /* Tell the rest of the system the news. New characters! */
684 tty_flip_buffer_push(tty); 681 tty_flip_buffer_push(tty);
685 } else { 682 } else {
686 sci_in(port, SCxSR); /* dummy read */ 683 serial_port_in(port, SCxSR); /* dummy read */
687 sci_out(port, SCxSR, SCxSR_RDxF_CLEAR(port)); 684 serial_port_out(port, SCxSR, SCxSR_RDxF_CLEAR(port));
688 } 685 }
689} 686}
690 687
@@ -726,7 +723,7 @@ static void sci_break_timer(unsigned long data)
726static int sci_handle_errors(struct uart_port *port) 723static int sci_handle_errors(struct uart_port *port)
727{ 724{
728 int copied = 0; 725 int copied = 0;
729 unsigned short status = sci_in(port, SCxSR); 726 unsigned short status = serial_port_in(port, SCxSR);
730 struct tty_struct *tty = port->state->port.tty; 727 struct tty_struct *tty = port->state->port.tty;
731 struct sci_port *s = to_sci_port(port); 728 struct sci_port *s = to_sci_port(port);
732 729
@@ -804,8 +801,8 @@ static int sci_handle_fifo_overrun(struct uart_port *port)
804 if (!reg->size) 801 if (!reg->size)
805 return 0; 802 return 0;
806 803
807 if ((sci_in(port, SCLSR) & (1 << s->cfg->overrun_bit))) { 804 if ((serial_port_in(port, SCLSR) & (1 << s->cfg->overrun_bit))) {
808 sci_out(port, SCLSR, 0); 805 serial_port_out(port, SCLSR, 0);
809 806
810 port->icount.overrun++; 807 port->icount.overrun++;
811 808
@@ -822,7 +819,7 @@ static int sci_handle_fifo_overrun(struct uart_port *port)
822static int sci_handle_breaks(struct uart_port *port) 819static int sci_handle_breaks(struct uart_port *port)
823{ 820{
824 int copied = 0; 821 int copied = 0;
825 unsigned short status = sci_in(port, SCxSR); 822 unsigned short status = serial_port_in(port, SCxSR);
826 struct tty_struct *tty = port->state->port.tty; 823 struct tty_struct *tty = port->state->port.tty;
827 struct sci_port *s = to_sci_port(port); 824 struct sci_port *s = to_sci_port(port);
828 825
@@ -859,8 +856,8 @@ static irqreturn_t sci_rx_interrupt(int irq, void *ptr)
859 struct sci_port *s = to_sci_port(port); 856 struct sci_port *s = to_sci_port(port);
860 857
861 if (s->chan_rx) { 858 if (s->chan_rx) {
862 u16 scr = sci_in(port, SCSCR); 859 u16 scr = serial_port_in(port, SCSCR);
863 u16 ssr = sci_in(port, SCxSR); 860 u16 ssr = serial_port_in(port, SCxSR);
864 861
865 /* Disable future Rx interrupts */ 862 /* Disable future Rx interrupts */
866 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) { 863 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) {
@@ -869,9 +866,9 @@ static irqreturn_t sci_rx_interrupt(int irq, void *ptr)
869 } else { 866 } else {
870 scr &= ~SCSCR_RIE; 867 scr &= ~SCSCR_RIE;
871 } 868 }
872 sci_out(port, SCSCR, scr); 869 serial_port_out(port, SCSCR, scr);
873 /* Clear current interrupt */ 870 /* Clear current interrupt */
874 sci_out(port, SCxSR, ssr & ~(1 | SCxSR_RDxF(port))); 871 serial_port_out(port, SCxSR, ssr & ~(1 | SCxSR_RDxF(port)));
875 dev_dbg(port->dev, "Rx IRQ %lu: setup t-out in %u jiffies\n", 872 dev_dbg(port->dev, "Rx IRQ %lu: setup t-out in %u jiffies\n",
876 jiffies, s->rx_timeout); 873 jiffies, s->rx_timeout);
877 mod_timer(&s->rx_timer, jiffies + s->rx_timeout); 874 mod_timer(&s->rx_timer, jiffies + s->rx_timeout);
@@ -909,15 +906,15 @@ static irqreturn_t sci_er_interrupt(int irq, void *ptr)
909 if (port->type == PORT_SCI) { 906 if (port->type == PORT_SCI) {
910 if (sci_handle_errors(port)) { 907 if (sci_handle_errors(port)) {
911 /* discard character in rx buffer */ 908 /* discard character in rx buffer */
912 sci_in(port, SCxSR); 909 serial_port_in(port, SCxSR);
913 sci_out(port, SCxSR, SCxSR_RDxF_CLEAR(port)); 910 serial_port_out(port, SCxSR, SCxSR_RDxF_CLEAR(port));
914 } 911 }
915 } else { 912 } else {
916 sci_handle_fifo_overrun(port); 913 sci_handle_fifo_overrun(port);
917 sci_rx_interrupt(irq, ptr); 914 sci_rx_interrupt(irq, ptr);
918 } 915 }
919 916
920 sci_out(port, SCxSR, SCxSR_ERROR_CLEAR(port)); 917 serial_port_out(port, SCxSR, SCxSR_ERROR_CLEAR(port));
921 918
922 /* Kick the transmission */ 919 /* Kick the transmission */
923 sci_tx_interrupt(irq, ptr); 920 sci_tx_interrupt(irq, ptr);
@@ -931,7 +928,7 @@ static irqreturn_t sci_br_interrupt(int irq, void *ptr)
931 928
932 /* Handle BREAKs */ 929 /* Handle BREAKs */
933 sci_handle_breaks(port); 930 sci_handle_breaks(port);
934 sci_out(port, SCxSR, SCxSR_BREAK_CLEAR(port)); 931 serial_port_out(port, SCxSR, SCxSR_BREAK_CLEAR(port));
935 932
936 return IRQ_HANDLED; 933 return IRQ_HANDLED;
937} 934}
@@ -955,8 +952,8 @@ static irqreturn_t sci_mpxed_interrupt(int irq, void *ptr)
955 struct sci_port *s = to_sci_port(port); 952 struct sci_port *s = to_sci_port(port);
956 irqreturn_t ret = IRQ_NONE; 953 irqreturn_t ret = IRQ_NONE;
957 954
958 ssr_status = sci_in(port, SCxSR); 955 ssr_status = serial_port_in(port, SCxSR);
959 scr_status = sci_in(port, SCSCR); 956 scr_status = serial_port_in(port, SCSCR);
960 err_enabled = scr_status & port_rx_irq_mask(port); 957 err_enabled = scr_status & port_rx_irq_mask(port);
961 958
962 /* Tx Interrupt */ 959 /* Tx Interrupt */
@@ -1170,7 +1167,7 @@ static void sci_free_gpios(struct sci_port *port)
1170 1167
1171static unsigned int sci_tx_empty(struct uart_port *port) 1168static unsigned int sci_tx_empty(struct uart_port *port)
1172{ 1169{
1173 unsigned short status = sci_in(port, SCxSR); 1170 unsigned short status = serial_port_in(port, SCxSR);
1174 unsigned short in_tx_fifo = sci_txfill(port); 1171 unsigned short in_tx_fifo = sci_txfill(port);
1175 1172
1176 return (status & SCxSR_TEND(port)) && !in_tx_fifo ? TIOCSER_TEMT : 0; 1173 return (status & SCxSR_TEND(port)) && !in_tx_fifo ? TIOCSER_TEMT : 0;
@@ -1198,7 +1195,7 @@ static void sci_set_mctrl(struct uart_port *port, unsigned int mctrl)
1198 */ 1195 */
1199 reg = sci_getreg(port, SCFCR); 1196 reg = sci_getreg(port, SCFCR);
1200 if (reg->size) 1197 if (reg->size)
1201 sci_out(port, SCFCR, sci_in(port, SCFCR) | 1); 1198 serial_port_out(port, SCFCR, serial_port_in(port, SCFCR) | 1);
1202 } 1199 }
1203} 1200}
1204 1201
@@ -1240,8 +1237,8 @@ static void sci_dma_tx_complete(void *arg)
1240 } else { 1237 } else {
1241 s->cookie_tx = -EINVAL; 1238 s->cookie_tx = -EINVAL;
1242 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) { 1239 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) {
1243 u16 ctrl = sci_in(port, SCSCR); 1240 u16 ctrl = serial_port_in(port, SCSCR);
1244 sci_out(port, SCSCR, ctrl & ~SCSCR_TIE); 1241 serial_port_out(port, SCSCR, ctrl & ~SCSCR_TIE);
1245 } 1242 }
1246 } 1243 }
1247 1244
@@ -1494,13 +1491,13 @@ static void sci_start_tx(struct uart_port *port)
1494 1491
1495#ifdef CONFIG_SERIAL_SH_SCI_DMA 1492#ifdef CONFIG_SERIAL_SH_SCI_DMA
1496 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) { 1493 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) {
1497 u16 new, scr = sci_in(port, SCSCR); 1494 u16 new, scr = serial_port_in(port, SCSCR);
1498 if (s->chan_tx) 1495 if (s->chan_tx)
1499 new = scr | 0x8000; 1496 new = scr | 0x8000;
1500 else 1497 else
1501 new = scr & ~0x8000; 1498 new = scr & ~0x8000;
1502 if (new != scr) 1499 if (new != scr)
1503 sci_out(port, SCSCR, new); 1500 serial_port_out(port, SCSCR, new);
1504 } 1501 }
1505 1502
1506 if (s->chan_tx && !uart_circ_empty(&s->port.state->xmit) && 1503 if (s->chan_tx && !uart_circ_empty(&s->port.state->xmit) &&
@@ -1512,8 +1509,8 @@ static void sci_start_tx(struct uart_port *port)
1512 1509
1513 if (!s->chan_tx || port->type == PORT_SCIFA || port->type == PORT_SCIFB) { 1510 if (!s->chan_tx || port->type == PORT_SCIFA || port->type == PORT_SCIFB) {
1514 /* Set TIE (Transmit Interrupt Enable) bit in SCSCR */ 1511 /* Set TIE (Transmit Interrupt Enable) bit in SCSCR */
1515 ctrl = sci_in(port, SCSCR); 1512 ctrl = serial_port_in(port, SCSCR);
1516 sci_out(port, SCSCR, ctrl | SCSCR_TIE); 1513 serial_port_out(port, SCSCR, ctrl | SCSCR_TIE);
1517 } 1514 }
1518} 1515}
1519 1516
@@ -1522,40 +1519,40 @@ static void sci_stop_tx(struct uart_port *port)
1522 unsigned short ctrl; 1519 unsigned short ctrl;
1523 1520
1524 /* Clear TIE (Transmit Interrupt Enable) bit in SCSCR */ 1521 /* Clear TIE (Transmit Interrupt Enable) bit in SCSCR */
1525 ctrl = sci_in(port, SCSCR); 1522 ctrl = serial_port_in(port, SCSCR);
1526 1523
1527 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) 1524 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB)
1528 ctrl &= ~0x8000; 1525 ctrl &= ~0x8000;
1529 1526
1530 ctrl &= ~SCSCR_TIE; 1527 ctrl &= ~SCSCR_TIE;
1531 1528
1532 sci_out(port, SCSCR, ctrl); 1529 serial_port_out(port, SCSCR, ctrl);
1533} 1530}
1534 1531
1535static void sci_start_rx(struct uart_port *port) 1532static void sci_start_rx(struct uart_port *port)
1536{ 1533{
1537 unsigned short ctrl; 1534 unsigned short ctrl;
1538 1535
1539 ctrl = sci_in(port, SCSCR) | port_rx_irq_mask(port); 1536 ctrl = serial_port_in(port, SCSCR) | port_rx_irq_mask(port);
1540 1537
1541 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) 1538 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB)
1542 ctrl &= ~0x4000; 1539 ctrl &= ~0x4000;
1543 1540
1544 sci_out(port, SCSCR, ctrl); 1541 serial_port_out(port, SCSCR, ctrl);
1545} 1542}
1546 1543
1547static void sci_stop_rx(struct uart_port *port) 1544static void sci_stop_rx(struct uart_port *port)
1548{ 1545{
1549 unsigned short ctrl; 1546 unsigned short ctrl;
1550 1547
1551 ctrl = sci_in(port, SCSCR); 1548 ctrl = serial_port_in(port, SCSCR);
1552 1549
1553 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) 1550 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB)
1554 ctrl &= ~0x4000; 1551 ctrl &= ~0x4000;
1555 1552
1556 ctrl &= ~port_rx_irq_mask(port); 1553 ctrl &= ~port_rx_irq_mask(port);
1557 1554
1558 sci_out(port, SCSCR, ctrl); 1555 serial_port_out(port, SCSCR, ctrl);
1559} 1556}
1560 1557
1561static void sci_enable_ms(struct uart_port *port) 1558static void sci_enable_ms(struct uart_port *port)
@@ -1589,13 +1586,13 @@ static void rx_timer_fn(unsigned long arg)
1589{ 1586{
1590 struct sci_port *s = (struct sci_port *)arg; 1587 struct sci_port *s = (struct sci_port *)arg;
1591 struct uart_port *port = &s->port; 1588 struct uart_port *port = &s->port;
1592 u16 scr = sci_in(port, SCSCR); 1589 u16 scr = serial_port_in(port, SCSCR);
1593 1590
1594 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) { 1591 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) {
1595 scr &= ~0x4000; 1592 scr &= ~0x4000;
1596 enable_irq(s->cfg->irqs[1]); 1593 enable_irq(s->cfg->irqs[1]);
1597 } 1594 }
1598 sci_out(port, SCSCR, scr | SCSCR_RIE); 1595 serial_port_out(port, SCSCR, scr | SCSCR_RIE);
1599 dev_dbg(port->dev, "DMA Rx timed out\n"); 1596 dev_dbg(port->dev, "DMA Rx timed out\n");
1600 schedule_work(&s->work_rx); 1597 schedule_work(&s->work_rx);
1601} 1598}
@@ -1776,14 +1773,14 @@ static void sci_reset(struct uart_port *port)
1776 unsigned int status; 1773 unsigned int status;
1777 1774
1778 do { 1775 do {
1779 status = sci_in(port, SCxSR); 1776 status = serial_port_in(port, SCxSR);
1780 } while (!(status & SCxSR_TEND(port))); 1777 } while (!(status & SCxSR_TEND(port)));
1781 1778
1782 sci_out(port, SCSCR, 0x00); /* TE=0, RE=0, CKE1=0 */ 1779 serial_port_out(port, SCSCR, 0x00); /* TE=0, RE=0, CKE1=0 */
1783 1780
1784 reg = sci_getreg(port, SCFCR); 1781 reg = sci_getreg(port, SCFCR);
1785 if (reg->size) 1782 if (reg->size)
1786 sci_out(port, SCFCR, SCFCR_RFRST | SCFCR_TFRST); 1783 serial_port_out(port, SCFCR, SCFCR_RFRST | SCFCR_TFRST);
1787} 1784}
1788 1785
1789static void sci_set_termios(struct uart_port *port, struct ktermios *termios, 1786static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
@@ -1812,7 +1809,7 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
1812 1809
1813 sci_reset(port); 1810 sci_reset(port);
1814 1811
1815 smr_val = sci_in(port, SCSMR) & 3; 1812 smr_val = serial_port_in(port, SCSMR) & 3;
1816 1813
1817 if ((termios->c_cflag & CSIZE) == CS7) 1814 if ((termios->c_cflag & CSIZE) == CS7)
1818 smr_val |= 0x40; 1815 smr_val |= 0x40;
@@ -1825,19 +1822,19 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
1825 1822
1826 uart_update_timeout(port, termios->c_cflag, baud); 1823 uart_update_timeout(port, termios->c_cflag, baud);
1827 1824
1828 sci_out(port, SCSMR, smr_val); 1825 serial_port_out(port, SCSMR, smr_val);
1829 1826
1830 dev_dbg(port->dev, "%s: SMR %x, t %x, SCSCR %x\n", __func__, smr_val, t, 1827 dev_dbg(port->dev, "%s: SMR %x, t %x, SCSCR %x\n", __func__, smr_val, t,
1831 s->cfg->scscr); 1828 s->cfg->scscr);
1832 1829
1833 if (t > 0) { 1830 if (t > 0) {
1834 if (t >= 256) { 1831 if (t >= 256) {
1835 sci_out(port, SCSMR, (sci_in(port, SCSMR) & ~3) | 1); 1832 serial_port_out(port, SCSMR, (serial_port_in(port, SCSMR) & ~3) | 1);
1836 t >>= 2; 1833 t >>= 2;
1837 } else 1834 } else
1838 sci_out(port, SCSMR, sci_in(port, SCSMR) & ~3); 1835 serial_port_out(port, SCSMR, serial_port_in(port, SCSMR) & ~3);
1839 1836
1840 sci_out(port, SCBRR, t); 1837 serial_port_out(port, SCBRR, t);
1841 udelay((1000000+(baud-1)) / baud); /* Wait one bit interval */ 1838 udelay((1000000+(baud-1)) / baud); /* Wait one bit interval */
1842 } 1839 }
1843 1840
@@ -1845,7 +1842,7 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
1845 1842
1846 reg = sci_getreg(port, SCFCR); 1843 reg = sci_getreg(port, SCFCR);
1847 if (reg->size) { 1844 if (reg->size) {
1848 unsigned short ctrl = sci_in(port, SCFCR); 1845 unsigned short ctrl = serial_port_in(port, SCFCR);
1849 1846
1850 if (s->cfg->capabilities & SCIx_HAVE_RTSCTS) { 1847 if (s->cfg->capabilities & SCIx_HAVE_RTSCTS) {
1851 if (termios->c_cflag & CRTSCTS) 1848 if (termios->c_cflag & CRTSCTS)
@@ -1861,10 +1858,10 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
1861 */ 1858 */
1862 ctrl &= ~(SCFCR_RFRST | SCFCR_TFRST); 1859 ctrl &= ~(SCFCR_RFRST | SCFCR_TFRST);
1863 1860
1864 sci_out(port, SCFCR, ctrl); 1861 serial_port_out(port, SCFCR, ctrl);
1865 } 1862 }
1866 1863
1867 sci_out(port, SCSCR, s->cfg->scscr); 1864 serial_port_out(port, SCSCR, s->cfg->scscr);
1868 1865
1869#ifdef CONFIG_SERIAL_SH_SCI_DMA 1866#ifdef CONFIG_SERIAL_SH_SCI_DMA
1870 /* 1867 /*
@@ -2166,7 +2163,7 @@ static void serial_console_write(struct console *co, const char *s,
2166 2163
2167 /* wait until fifo is empty and last bit has been transmitted */ 2164 /* wait until fifo is empty and last bit has been transmitted */
2168 bits = SCxSR_TDxE(port) | SCxSR_TEND(port); 2165 bits = SCxSR_TDxE(port) | SCxSR_TEND(port);
2169 while ((sci_in(port, SCxSR) & bits) != bits) 2166 while ((serial_port_in(port, SCxSR) & bits) != bits)
2170 cpu_relax(); 2167 cpu_relax();
2171 2168
2172 sci_port_disable(sci_port); 2169 sci_port_disable(sci_port);
@@ -2260,12 +2257,12 @@ static int sci_runtime_suspend(struct device *dev)
2260 if (uart_console(port)) { 2257 if (uart_console(port)) {
2261 struct plat_sci_reg *reg; 2258 struct plat_sci_reg *reg;
2262 2259
2263 sci_port->saved_smr = sci_in(port, SCSMR); 2260 sci_port->saved_smr = serial_port_in(port, SCSMR);
2264 sci_port->saved_brr = sci_in(port, SCBRR); 2261 sci_port->saved_brr = serial_port_in(port, SCBRR);
2265 2262
2266 reg = sci_getreg(port, SCFCR); 2263 reg = sci_getreg(port, SCFCR);
2267 if (reg->size) 2264 if (reg->size)
2268 sci_port->saved_fcr = sci_in(port, SCFCR); 2265 sci_port->saved_fcr = serial_port_in(port, SCFCR);
2269 else 2266 else
2270 sci_port->saved_fcr = 0; 2267 sci_port->saved_fcr = 0;
2271 } 2268 }
@@ -2279,13 +2276,13 @@ static int sci_runtime_resume(struct device *dev)
2279 2276
2280 if (uart_console(port)) { 2277 if (uart_console(port)) {
2281 sci_reset(port); 2278 sci_reset(port);
2282 sci_out(port, SCSMR, sci_port->saved_smr); 2279 serial_port_out(port, SCSMR, sci_port->saved_smr);
2283 sci_out(port, SCBRR, sci_port->saved_brr); 2280 serial_port_out(port, SCBRR, sci_port->saved_brr);
2284 2281
2285 if (sci_port->saved_fcr) 2282 if (sci_port->saved_fcr)
2286 sci_out(port, SCFCR, sci_port->saved_fcr); 2283 serial_port_out(port, SCFCR, sci_port->saved_fcr);
2287 2284
2288 sci_out(port, SCSCR, sci_port->cfg->scscr); 2285 serial_port_out(port, SCSCR, sci_port->cfg->scscr);
2289 } 2286 }
2290 return 0; 2287 return 0;
2291} 2288}
diff --git a/drivers/tty/serial/sh-sci.h b/drivers/tty/serial/sh-sci.h
index a1a2d364f92b..4c22a1529aac 100644
--- a/drivers/tty/serial/sh-sci.h
+++ b/drivers/tty/serial/sh-sci.h
@@ -20,10 +20,10 @@
20 defined(CONFIG_ARCH_SH7372) || \ 20 defined(CONFIG_ARCH_SH7372) || \
21 defined(CONFIG_ARCH_R8A7740) 21 defined(CONFIG_ARCH_R8A7740)
22 22
23# define SCxSR_RDxF_CLEAR(port) (sci_in(port, SCxSR) & 0xfffc) 23# define SCxSR_RDxF_CLEAR(port) (serial_port_in(port, SCxSR) & 0xfffc)
24# define SCxSR_ERROR_CLEAR(port) (sci_in(port, SCxSR) & 0xfd73) 24# define SCxSR_ERROR_CLEAR(port) (serial_port_in(port, SCxSR) & 0xfd73)
25# define SCxSR_TDxE_CLEAR(port) (sci_in(port, SCxSR) & 0xffdf) 25# define SCxSR_TDxE_CLEAR(port) (serial_port_in(port, SCxSR) & 0xffdf)
26# define SCxSR_BREAK_CLEAR(port) (sci_in(port, SCxSR) & 0xffe3) 26# define SCxSR_BREAK_CLEAR(port) (serial_port_in(port, SCxSR) & 0xffe3)
27#else 27#else
28# define SCxSR_RDxF_CLEAR(port) (((port)->type == PORT_SCI) ? 0xbc : 0x00fc) 28# define SCxSR_RDxF_CLEAR(port) (((port)->type == PORT_SCI) ? 0xbc : 0x00fc)
29# define SCxSR_ERROR_CLEAR(port) (((port)->type == PORT_SCI) ? 0xc4 : 0x0073) 29# define SCxSR_ERROR_CLEAR(port) (((port)->type == PORT_SCI) ? 0xc4 : 0x0073)
diff --git a/drivers/tty/serial/sunzilog.c b/drivers/tty/serial/sunzilog.c
index b3b70b0bf85b..babd9470982b 100644
--- a/drivers/tty/serial/sunzilog.c
+++ b/drivers/tty/serial/sunzilog.c
@@ -1581,7 +1581,7 @@ static int __init sunzilog_init(void)
1581 if (err) 1581 if (err)
1582 goto out_unregister_uart; 1582 goto out_unregister_uart;
1583 1583
1584 if (!zilog_irq) { 1584 if (zilog_irq) {
1585 struct uart_sunzilog_port *up = sunzilog_irq_chain; 1585 struct uart_sunzilog_port *up = sunzilog_irq_chain;
1586 err = request_irq(zilog_irq, sunzilog_interrupt, IRQF_SHARED, 1586 err = request_irq(zilog_irq, sunzilog_interrupt, IRQF_SHARED,
1587 "zs", sunzilog_irq_chain); 1587 "zs", sunzilog_irq_chain);
@@ -1622,7 +1622,7 @@ static void __exit sunzilog_exit(void)
1622{ 1622{
1623 platform_driver_unregister(&zs_driver); 1623 platform_driver_unregister(&zs_driver);
1624 1624
1625 if (!zilog_irq) { 1625 if (zilog_irq) {
1626 struct uart_sunzilog_port *up = sunzilog_irq_chain; 1626 struct uart_sunzilog_port *up = sunzilog_irq_chain;
1627 1627
1628 /* Disable Interrupts */ 1628 /* Disable Interrupts */
diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
index 136e86faa1e1..05728894a88c 100644
--- a/drivers/tty/sysrq.c
+++ b/drivers/tty/sysrq.c
@@ -327,7 +327,7 @@ static void send_sig_all(int sig)
327 if (is_global_init(p)) 327 if (is_global_init(p))
328 continue; 328 continue;
329 329
330 force_sig(sig, p); 330 do_send_sig_info(sig, SEND_SIG_FORCED, p, true);
331 } 331 }
332 read_unlock(&tasklist_lock); 332 read_unlock(&tasklist_lock);
333} 333}
diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
index 86dd1e302bb3..29ca20dbd335 100644
--- a/drivers/tty/vt/keyboard.c
+++ b/drivers/tty/vt/keyboard.c
@@ -1085,15 +1085,21 @@ void vt_set_led_state(int console, int leds)
1085 * 1085 *
1086 * Handle console start. This is a wrapper for the VT layer 1086 * Handle console start. This is a wrapper for the VT layer
1087 * so that we can keep kbd knowledge internal 1087 * so that we can keep kbd knowledge internal
1088 *
1089 * FIXME: We eventually need to hold the kbd lock here to protect
1090 * the LED updating. We can't do it yet because fn_hold calls stop_tty
1091 * and start_tty under the kbd_event_lock, while normal tty paths
1092 * don't hold the lock. We probably need to split out an LED lock
1093 * but not during an -rc release!
1088 */ 1094 */
1089void vt_kbd_con_start(int console) 1095void vt_kbd_con_start(int console)
1090{ 1096{
1091 struct kbd_struct * kbd = kbd_table + console; 1097 struct kbd_struct * kbd = kbd_table + console;
1092 unsigned long flags; 1098/* unsigned long flags; */
1093 spin_lock_irqsave(&kbd_event_lock, flags); 1099/* spin_lock_irqsave(&kbd_event_lock, flags); */
1094 clr_vc_kbd_led(kbd, VC_SCROLLOCK); 1100 clr_vc_kbd_led(kbd, VC_SCROLLOCK);
1095 set_leds(); 1101 set_leds();
1096 spin_unlock_irqrestore(&kbd_event_lock, flags); 1102/* spin_unlock_irqrestore(&kbd_event_lock, flags); */
1097} 1103}
1098 1104
1099/** 1105/**
@@ -1102,22 +1108,28 @@ void vt_kbd_con_start(int console)
1102 * 1108 *
1103 * Handle console stop. This is a wrapper for the VT layer 1109 * Handle console stop. This is a wrapper for the VT layer
1104 * so that we can keep kbd knowledge internal 1110 * so that we can keep kbd knowledge internal
1111 *
1112 * FIXME: We eventually need to hold the kbd lock here to protect
1113 * the LED updating. We can't do it yet because fn_hold calls stop_tty
1114 * and start_tty under the kbd_event_lock, while normal tty paths
1115 * don't hold the lock. We probably need to split out an LED lock
1116 * but not during an -rc release!
1105 */ 1117 */
1106void vt_kbd_con_stop(int console) 1118void vt_kbd_con_stop(int console)
1107{ 1119{
1108 struct kbd_struct * kbd = kbd_table + console; 1120 struct kbd_struct * kbd = kbd_table + console;
1109 unsigned long flags; 1121/* unsigned long flags; */
1110 spin_lock_irqsave(&kbd_event_lock, flags); 1122/* spin_lock_irqsave(&kbd_event_lock, flags); */
1111 set_vc_kbd_led(kbd, VC_SCROLLOCK); 1123 set_vc_kbd_led(kbd, VC_SCROLLOCK);
1112 set_leds(); 1124 set_leds();
1113 spin_unlock_irqrestore(&kbd_event_lock, flags); 1125/* spin_unlock_irqrestore(&kbd_event_lock, flags); */
1114} 1126}
1115 1127
1116/* 1128/*
1117 * This is the tasklet that updates LED state on all keyboards 1129 * This is the tasklet that updates LED state on all keyboards
1118 * attached to the box. The reason we use tasklet is that we 1130 * attached to the box. The reason we use tasklet is that we
1119 * need to handle the scenario when keyboard handler is not 1131 * need to handle the scenario when keyboard handler is not
1120 * registered yet but we already getting updates form VT to 1132 * registered yet but we already getting updates from the VT to
1121 * update led state. 1133 * update led state.
1122 */ 1134 */
1123static void kbd_bh(unsigned long dummy) 1135static void kbd_bh(unsigned long dummy)
diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
index 3bdd4b19dd06..2156188db4a6 100644
--- a/drivers/tty/vt/vt.c
+++ b/drivers/tty/vt/vt.c
@@ -2932,11 +2932,10 @@ static int __init con_init(void)
2932 gotoxy(vc, vc->vc_x, vc->vc_y); 2932 gotoxy(vc, vc->vc_x, vc->vc_y);
2933 csi_J(vc, 0); 2933 csi_J(vc, 0);
2934 update_screen(vc); 2934 update_screen(vc);
2935 pr_info("Console: %s %s %dx%d", 2935 pr_info("Console: %s %s %dx%d\n",
2936 vc->vc_can_do_color ? "colour" : "mono", 2936 vc->vc_can_do_color ? "colour" : "mono",
2937 display_desc, vc->vc_cols, vc->vc_rows); 2937 display_desc, vc->vc_cols, vc->vc_rows);
2938 printable = 1; 2938 printable = 1;
2939 printk("\n");
2940 2939
2941 console_unlock(); 2940 console_unlock();
2942 2941
diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig
index cbd8f5f80596..76316a33061b 100644
--- a/drivers/usb/Kconfig
+++ b/drivers/usb/Kconfig
@@ -2,14 +2,6 @@
2# USB device configuration 2# USB device configuration
3# 3#
4 4
5menuconfig USB_SUPPORT
6 bool "USB support"
7 depends on HAS_IOMEM
8 default y
9 ---help---
10 This option adds core support for Universal Serial Bus (USB).
11 You will also need drivers from the following menu to make use of it.
12
13# many non-PCI SOC chips embed OHCI 5# many non-PCI SOC chips embed OHCI
14config USB_ARCH_HAS_OHCI 6config USB_ARCH_HAS_OHCI
15 boolean 7 boolean
@@ -63,6 +55,14 @@ config USB_ARCH_HAS_XHCI
63 boolean 55 boolean
64 default PCI 56 default PCI
65 57
58menuconfig USB_SUPPORT
59 bool "USB support"
60 depends on HAS_IOMEM
61 default y
62 ---help---
63 This option adds core support for Universal Serial Bus (USB).
64 You will also need drivers from the following menu to make use of it.
65
66if USB_SUPPORT 66if USB_SUPPORT
67 67
68config USB_COMMON 68config USB_COMMON
diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c
index c6f6560d436c..0bb2b3248dad 100644
--- a/drivers/usb/class/cdc-wdm.c
+++ b/drivers/usb/class/cdc-wdm.c
@@ -157,8 +157,9 @@ static void wdm_out_callback(struct urb *urb)
157 spin_lock(&desc->iuspin); 157 spin_lock(&desc->iuspin);
158 desc->werr = urb->status; 158 desc->werr = urb->status;
159 spin_unlock(&desc->iuspin); 159 spin_unlock(&desc->iuspin);
160 clear_bit(WDM_IN_USE, &desc->flags);
161 kfree(desc->outbuf); 160 kfree(desc->outbuf);
161 desc->outbuf = NULL;
162 clear_bit(WDM_IN_USE, &desc->flags);
162 wake_up(&desc->wait); 163 wake_up(&desc->wait);
163} 164}
164 165
@@ -338,7 +339,7 @@ static ssize_t wdm_write
338 if (we < 0) 339 if (we < 0)
339 return -EIO; 340 return -EIO;
340 341
341 desc->outbuf = buf = kmalloc(count, GFP_KERNEL); 342 buf = kmalloc(count, GFP_KERNEL);
342 if (!buf) { 343 if (!buf) {
343 rv = -ENOMEM; 344 rv = -ENOMEM;
344 goto outnl; 345 goto outnl;
@@ -406,10 +407,12 @@ static ssize_t wdm_write
406 req->wIndex = desc->inum; 407 req->wIndex = desc->inum;
407 req->wLength = cpu_to_le16(count); 408 req->wLength = cpu_to_le16(count);
408 set_bit(WDM_IN_USE, &desc->flags); 409 set_bit(WDM_IN_USE, &desc->flags);
410 desc->outbuf = buf;
409 411
410 rv = usb_submit_urb(desc->command, GFP_KERNEL); 412 rv = usb_submit_urb(desc->command, GFP_KERNEL);
411 if (rv < 0) { 413 if (rv < 0) {
412 kfree(buf); 414 kfree(buf);
415 desc->outbuf = NULL;
413 clear_bit(WDM_IN_USE, &desc->flags); 416 clear_bit(WDM_IN_USE, &desc->flags);
414 dev_err(&desc->intf->dev, "Tx URB error: %d\n", rv); 417 dev_err(&desc->intf->dev, "Tx URB error: %d\n", rv);
415 } else { 418 } else {
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index f8e2d6d52e5c..9a56635dc19c 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -1189,8 +1189,13 @@ static int usb_suspend_both(struct usb_device *udev, pm_message_t msg)
1189 if (status == 0) { 1189 if (status == 0) {
1190 status = usb_suspend_device(udev, msg); 1190 status = usb_suspend_device(udev, msg);
1191 1191
1192 /* Again, ignore errors during system sleep transitions */ 1192 /*
1193 if (!PMSG_IS_AUTO(msg)) 1193 * Ignore errors from non-root-hub devices during
1194 * system sleep transitions. For the most part,
1195 * these devices should go to low power anyway when
1196 * the entire bus is suspended.
1197 */
1198 if (udev->parent && !PMSG_IS_AUTO(msg))
1194 status = 0; 1199 status = 0;
1195 } 1200 }
1196 1201
diff --git a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c
index 622b4a48e732..57ed9e400c06 100644
--- a/drivers/usb/core/hcd-pci.c
+++ b/drivers/usb/core/hcd-pci.c
@@ -493,6 +493,15 @@ static int hcd_pci_suspend_noirq(struct device *dev)
493 493
494 pci_save_state(pci_dev); 494 pci_save_state(pci_dev);
495 495
496 /*
497 * Some systems crash if an EHCI controller is in D3 during
498 * a sleep transition. We have to leave such controllers in D0.
499 */
500 if (hcd->broken_pci_sleep) {
501 dev_dbg(dev, "Staying in PCI D0\n");
502 return retval;
503 }
504
496 /* If the root hub is dead rather than suspended, disallow remote 505 /* If the root hub is dead rather than suspended, disallow remote
497 * wakeup. usb_hc_died() should ensure that both hosts are marked as 506 * wakeup. usb_hc_died() should ensure that both hosts are marked as
498 * dying, so we only need to check the primary roothub. 507 * dying, so we only need to check the primary roothub.
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 9d7fc9a39933..140d3e11f212 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -1978,6 +1978,18 @@ int hcd_bus_suspend(struct usb_device *rhdev, pm_message_t msg)
1978 if (status == 0) { 1978 if (status == 0) {
1979 usb_set_device_state(rhdev, USB_STATE_SUSPENDED); 1979 usb_set_device_state(rhdev, USB_STATE_SUSPENDED);
1980 hcd->state = HC_STATE_SUSPENDED; 1980 hcd->state = HC_STATE_SUSPENDED;
1981
1982 /* Did we race with a root-hub wakeup event? */
1983 if (rhdev->do_remote_wakeup) {
1984 char buffer[6];
1985
1986 status = hcd->driver->hub_status_data(hcd, buffer);
1987 if (status != 0) {
1988 dev_dbg(&rhdev->dev, "suspend raced with wakeup event\n");
1989 hcd_bus_resume(rhdev, PMSG_AUTO_RESUME);
1990 status = -EBUSY;
1991 }
1992 }
1981 } else { 1993 } else {
1982 spin_lock_irq(&hcd_root_hub_lock); 1994 spin_lock_irq(&hcd_root_hub_lock);
1983 if (!HCD_DEAD(hcd)) { 1995 if (!HCD_DEAD(hcd)) {
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 28664eb7f555..ec6c97dadbe4 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -1667,7 +1667,6 @@ void usb_disconnect(struct usb_device **pdev)
1667{ 1667{
1668 struct usb_device *udev = *pdev; 1668 struct usb_device *udev = *pdev;
1669 int i; 1669 int i;
1670 struct usb_hcd *hcd = bus_to_hcd(udev->bus);
1671 1670
1672 /* mark the device as inactive, so any further urb submissions for 1671 /* mark the device as inactive, so any further urb submissions for
1673 * this device (and any of its children) will fail immediately. 1672 * this device (and any of its children) will fail immediately.
@@ -1690,9 +1689,7 @@ void usb_disconnect(struct usb_device **pdev)
1690 * so that the hardware is now fully quiesced. 1689 * so that the hardware is now fully quiesced.
1691 */ 1690 */
1692 dev_dbg (&udev->dev, "unregistering device\n"); 1691 dev_dbg (&udev->dev, "unregistering device\n");
1693 mutex_lock(hcd->bandwidth_mutex);
1694 usb_disable_device(udev, 0); 1692 usb_disable_device(udev, 0);
1695 mutex_unlock(hcd->bandwidth_mutex);
1696 usb_hcd_synchronize_unlinks(udev); 1693 usb_hcd_synchronize_unlinks(udev);
1697 1694
1698 usb_remove_ep_devs(&udev->ep0); 1695 usb_remove_ep_devs(&udev->ep0);
@@ -3163,6 +3160,22 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
3163 if (retval) 3160 if (retval)
3164 goto fail; 3161 goto fail;
3165 3162
3163 /*
3164 * Some superspeed devices have finished the link training process
3165 * and attached to a superspeed hub port, but the device descriptor
3166 * got from those devices show they aren't superspeed devices. Warm
3167 * reset the port attached by the devices can fix them.
3168 */
3169 if ((udev->speed == USB_SPEED_SUPER) &&
3170 (le16_to_cpu(udev->descriptor.bcdUSB) < 0x0300)) {
3171 dev_err(&udev->dev, "got a wrong device descriptor, "
3172 "warm reset device\n");
3173 hub_port_reset(hub, port1, udev,
3174 HUB_BH_RESET_TIME, true);
3175 retval = -EINVAL;
3176 goto fail;
3177 }
3178
3166 if (udev->descriptor.bMaxPacketSize0 == 0xff || 3179 if (udev->descriptor.bMaxPacketSize0 == 0xff ||
3167 udev->speed == USB_SPEED_SUPER) 3180 udev->speed == USB_SPEED_SUPER)
3168 i = 512; 3181 i = 512;
diff --git a/drivers/usb/core/inode.c b/drivers/usb/core/inode.c
index cefa0c8b5b6a..d2b9af59cba9 100644
--- a/drivers/usb/core/inode.c
+++ b/drivers/usb/core/inode.c
@@ -428,18 +428,10 @@ static loff_t default_file_lseek (struct file *file, loff_t offset, int orig)
428 return retval; 428 return retval;
429} 429}
430 430
431static int default_open (struct inode *inode, struct file *file)
432{
433 if (inode->i_private)
434 file->private_data = inode->i_private;
435
436 return 0;
437}
438
439static const struct file_operations default_file_operations = { 431static const struct file_operations default_file_operations = {
440 .read = default_read_file, 432 .read = default_read_file,
441 .write = default_write_file, 433 .write = default_write_file,
442 .open = default_open, 434 .open = simple_open,
443 .llseek = default_file_lseek, 435 .llseek = default_file_lseek,
444}; 436};
445 437
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
index b3bdfede45e6..ca717da3be95 100644
--- a/drivers/usb/core/message.c
+++ b/drivers/usb/core/message.c
@@ -308,7 +308,8 @@ static void sg_complete(struct urb *urb)
308 retval = usb_unlink_urb(io->urbs [i]); 308 retval = usb_unlink_urb(io->urbs [i]);
309 if (retval != -EINPROGRESS && 309 if (retval != -EINPROGRESS &&
310 retval != -ENODEV && 310 retval != -ENODEV &&
311 retval != -EBUSY) 311 retval != -EBUSY &&
312 retval != -EIDRM)
312 dev_err(&io->dev->dev, 313 dev_err(&io->dev->dev,
313 "%s, unlink --> %d\n", 314 "%s, unlink --> %d\n",
314 __func__, retval); 315 __func__, retval);
@@ -317,7 +318,6 @@ static void sg_complete(struct urb *urb)
317 } 318 }
318 spin_lock(&io->lock); 319 spin_lock(&io->lock);
319 } 320 }
320 urb->dev = NULL;
321 321
322 /* on the last completion, signal usb_sg_wait() */ 322 /* on the last completion, signal usb_sg_wait() */
323 io->bytes += urb->actual_length; 323 io->bytes += urb->actual_length;
@@ -524,7 +524,6 @@ void usb_sg_wait(struct usb_sg_request *io)
524 case -ENXIO: /* hc didn't queue this one */ 524 case -ENXIO: /* hc didn't queue this one */
525 case -EAGAIN: 525 case -EAGAIN:
526 case -ENOMEM: 526 case -ENOMEM:
527 io->urbs[i]->dev = NULL;
528 retval = 0; 527 retval = 0;
529 yield(); 528 yield();
530 break; 529 break;
@@ -542,7 +541,6 @@ void usb_sg_wait(struct usb_sg_request *io)
542 541
543 /* fail any uncompleted urbs */ 542 /* fail any uncompleted urbs */
544 default: 543 default:
545 io->urbs[i]->dev = NULL;
546 io->urbs[i]->status = retval; 544 io->urbs[i]->status = retval;
547 dev_dbg(&io->dev->dev, "%s, submit --> %d\n", 545 dev_dbg(&io->dev->dev, "%s, submit --> %d\n",
548 __func__, retval); 546 __func__, retval);
@@ -593,7 +591,10 @@ void usb_sg_cancel(struct usb_sg_request *io)
593 if (!io->urbs [i]->dev) 591 if (!io->urbs [i]->dev)
594 continue; 592 continue;
595 retval = usb_unlink_urb(io->urbs [i]); 593 retval = usb_unlink_urb(io->urbs [i]);
596 if (retval != -EINPROGRESS && retval != -EBUSY) 594 if (retval != -EINPROGRESS
595 && retval != -ENODEV
596 && retval != -EBUSY
597 && retval != -EIDRM)
597 dev_warn(&io->dev->dev, "%s, unlink --> %d\n", 598 dev_warn(&io->dev->dev, "%s, unlink --> %d\n",
598 __func__, retval); 599 __func__, retval);
599 } 600 }
@@ -1135,8 +1136,6 @@ void usb_disable_interface(struct usb_device *dev, struct usb_interface *intf,
1135 * Deallocates hcd/hardware state for the endpoints (nuking all or most 1136 * Deallocates hcd/hardware state for the endpoints (nuking all or most
1136 * pending urbs) and usbcore state for the interfaces, so that usbcore 1137 * pending urbs) and usbcore state for the interfaces, so that usbcore
1137 * must usb_set_configuration() before any interfaces could be used. 1138 * must usb_set_configuration() before any interfaces could be used.
1138 *
1139 * Must be called with hcd->bandwidth_mutex held.
1140 */ 1139 */
1141void usb_disable_device(struct usb_device *dev, int skip_ep0) 1140void usb_disable_device(struct usb_device *dev, int skip_ep0)
1142{ 1141{
@@ -1189,7 +1188,9 @@ void usb_disable_device(struct usb_device *dev, int skip_ep0)
1189 usb_disable_endpoint(dev, i + USB_DIR_IN, false); 1188 usb_disable_endpoint(dev, i + USB_DIR_IN, false);
1190 } 1189 }
1191 /* Remove endpoints from the host controller internal state */ 1190 /* Remove endpoints from the host controller internal state */
1191 mutex_lock(hcd->bandwidth_mutex);
1192 usb_hcd_alloc_bandwidth(dev, NULL, NULL, NULL); 1192 usb_hcd_alloc_bandwidth(dev, NULL, NULL, NULL);
1193 mutex_unlock(hcd->bandwidth_mutex);
1193 /* Second pass: remove endpoint pointers */ 1194 /* Second pass: remove endpoint pointers */
1194 } 1195 }
1195 for (i = skip_ep0; i < 16; ++i) { 1196 for (i = skip_ep0; i < 16; ++i) {
@@ -1749,7 +1750,6 @@ free_interfaces:
1749 /* if it's already configured, clear out old state first. 1750 /* if it's already configured, clear out old state first.
1750 * getting rid of old interfaces means unbinding their drivers. 1751 * getting rid of old interfaces means unbinding their drivers.
1751 */ 1752 */
1752 mutex_lock(hcd->bandwidth_mutex);
1753 if (dev->state != USB_STATE_ADDRESS) 1753 if (dev->state != USB_STATE_ADDRESS)
1754 usb_disable_device(dev, 1); /* Skip ep0 */ 1754 usb_disable_device(dev, 1); /* Skip ep0 */
1755 1755
@@ -1762,6 +1762,7 @@ free_interfaces:
1762 * host controller will not allow submissions to dropped endpoints. If 1762 * host controller will not allow submissions to dropped endpoints. If
1763 * this call fails, the device state is unchanged. 1763 * this call fails, the device state is unchanged.
1764 */ 1764 */
1765 mutex_lock(hcd->bandwidth_mutex);
1765 ret = usb_hcd_alloc_bandwidth(dev, cp, NULL, NULL); 1766 ret = usb_hcd_alloc_bandwidth(dev, cp, NULL, NULL);
1766 if (ret < 0) { 1767 if (ret < 0) {
1767 mutex_unlock(hcd->bandwidth_mutex); 1768 mutex_unlock(hcd->bandwidth_mutex);
diff --git a/drivers/usb/core/urb.c b/drivers/usb/core/urb.c
index 7239a73c1b8c..cd9b3a2cd8a7 100644
--- a/drivers/usb/core/urb.c
+++ b/drivers/usb/core/urb.c
@@ -539,6 +539,10 @@ EXPORT_SYMBOL_GPL(usb_submit_urb);
539 * never submitted, or it was unlinked before, or the hardware is already 539 * never submitted, or it was unlinked before, or the hardware is already
540 * finished with it), even if the completion handler has not yet run. 540 * finished with it), even if the completion handler has not yet run.
541 * 541 *
542 * The URB must not be deallocated while this routine is running. In
543 * particular, when a driver calls this routine, it must insure that the
544 * completion handler cannot deallocate the URB.
545 *
542 * Unlinking and Endpoint Queues: 546 * Unlinking and Endpoint Queues:
543 * 547 *
544 * [The behaviors and guarantees described below do not apply to virtual 548 * [The behaviors and guarantees described below do not apply to virtual
@@ -603,6 +607,10 @@ EXPORT_SYMBOL_GPL(usb_unlink_urb);
603 * with error -EPERM. Thus even if the URB's completion handler always 607 * with error -EPERM. Thus even if the URB's completion handler always
604 * tries to resubmit, it will not succeed and the URB will become idle. 608 * tries to resubmit, it will not succeed and the URB will become idle.
605 * 609 *
610 * The URB must not be deallocated while this routine is running. In
611 * particular, when a driver calls this routine, it must insure that the
612 * completion handler cannot deallocate the URB.
613 *
606 * This routine may not be used in an interrupt context (such as a bottom 614 * This routine may not be used in an interrupt context (such as a bottom
607 * half or a completion handler), or when holding a spinlock, or in other 615 * half or a completion handler), or when holding a spinlock, or in other
608 * situations where the caller can't schedule(). 616 * situations where the caller can't schedule().
@@ -640,6 +648,10 @@ EXPORT_SYMBOL_GPL(usb_kill_urb);
640 * with error -EPERM. Thus even if the URB's completion handler always 648 * with error -EPERM. Thus even if the URB's completion handler always
641 * tries to resubmit, it will not succeed and the URB will become idle. 649 * tries to resubmit, it will not succeed and the URB will become idle.
642 * 650 *
651 * The URB must not be deallocated while this routine is running. In
652 * particular, when a driver calls this routine, it must insure that the
653 * completion handler cannot deallocate the URB.
654 *
643 * This routine may not be used in an interrupt context (such as a bottom 655 * This routine may not be used in an interrupt context (such as a bottom
644 * half or a completion handler), or when holding a spinlock, or in other 656 * half or a completion handler), or when holding a spinlock, or in other
645 * situations where the caller can't schedule(). 657 * situations where the caller can't schedule().
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 7bd815a507e8..99b58d84553a 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -206,11 +206,11 @@ static void dwc3_free_event_buffers(struct dwc3 *dwc)
206 206
207 for (i = 0; i < dwc->num_event_buffers; i++) { 207 for (i = 0; i < dwc->num_event_buffers; i++) {
208 evt = dwc->ev_buffs[i]; 208 evt = dwc->ev_buffs[i];
209 if (evt) { 209 if (evt)
210 dwc3_free_one_event_buffer(dwc, evt); 210 dwc3_free_one_event_buffer(dwc, evt);
211 dwc->ev_buffs[i] = NULL;
212 }
213 } 211 }
212
213 kfree(dwc->ev_buffs);
214} 214}
215 215
216/** 216/**
diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c
index 25910e251c04..3584a169886f 100644
--- a/drivers/usb/dwc3/ep0.c
+++ b/drivers/usb/dwc3/ep0.c
@@ -353,6 +353,9 @@ static int dwc3_ep0_handle_feature(struct dwc3 *dwc,
353 353
354 dwc->test_mode_nr = wIndex >> 8; 354 dwc->test_mode_nr = wIndex >> 8;
355 dwc->test_mode = true; 355 dwc->test_mode = true;
356 break;
357 default:
358 return -EINVAL;
356 } 359 }
357 break; 360 break;
358 361
@@ -559,15 +562,20 @@ static void dwc3_ep0_complete_data(struct dwc3 *dwc,
559 length = trb->size & DWC3_TRB_SIZE_MASK; 562 length = trb->size & DWC3_TRB_SIZE_MASK;
560 563
561 if (dwc->ep0_bounced) { 564 if (dwc->ep0_bounced) {
565 unsigned transfer_size = ur->length;
566 unsigned maxp = ep0->endpoint.maxpacket;
567
568 transfer_size += (maxp - (transfer_size % maxp));
562 transferred = min_t(u32, ur->length, 569 transferred = min_t(u32, ur->length,
563 ep0->endpoint.maxpacket - length); 570 transfer_size - length);
564 memcpy(ur->buf, dwc->ep0_bounce, transferred); 571 memcpy(ur->buf, dwc->ep0_bounce, transferred);
565 dwc->ep0_bounced = false; 572 dwc->ep0_bounced = false;
566 } else { 573 } else {
567 transferred = ur->length - length; 574 transferred = ur->length - length;
568 ur->actual += transferred;
569 } 575 }
570 576
577 ur->actual += transferred;
578
571 if ((epnum & 1) && ur->actual < ur->length) { 579 if ((epnum & 1) && ur->actual < ur->length) {
572 /* for some reason we did not get everything out */ 580 /* for some reason we did not get everything out */
573 581
diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c
index 0c935d7c65bd..9d7bcd910074 100644
--- a/drivers/usb/gadget/at91_udc.c
+++ b/drivers/usb/gadget/at91_udc.c
@@ -1863,8 +1863,8 @@ static int __devinit at91udc_probe(struct platform_device *pdev)
1863 mod_timer(&udc->vbus_timer, 1863 mod_timer(&udc->vbus_timer,
1864 jiffies + VBUS_POLL_TIMEOUT); 1864 jiffies + VBUS_POLL_TIMEOUT);
1865 } else { 1865 } else {
1866 if (request_irq(udc->board.vbus_pin, at91_vbus_irq, 1866 if (request_irq(gpio_to_irq(udc->board.vbus_pin),
1867 0, driver_name, udc)) { 1867 at91_vbus_irq, 0, driver_name, udc)) {
1868 DBG("request vbus irq %d failed\n", 1868 DBG("request vbus irq %d failed\n",
1869 udc->board.vbus_pin); 1869 udc->board.vbus_pin);
1870 retval = -EBUSY; 1870 retval = -EBUSY;
@@ -1886,7 +1886,7 @@ static int __devinit at91udc_probe(struct platform_device *pdev)
1886 return 0; 1886 return 0;
1887fail4: 1887fail4:
1888 if (gpio_is_valid(udc->board.vbus_pin) && !udc->board.vbus_polled) 1888 if (gpio_is_valid(udc->board.vbus_pin) && !udc->board.vbus_polled)
1889 free_irq(udc->board.vbus_pin, udc); 1889 free_irq(gpio_to_irq(udc->board.vbus_pin), udc);
1890fail3: 1890fail3:
1891 if (gpio_is_valid(udc->board.vbus_pin)) 1891 if (gpio_is_valid(udc->board.vbus_pin))
1892 gpio_free(udc->board.vbus_pin); 1892 gpio_free(udc->board.vbus_pin);
@@ -1924,7 +1924,7 @@ static int __exit at91udc_remove(struct platform_device *pdev)
1924 device_init_wakeup(&pdev->dev, 0); 1924 device_init_wakeup(&pdev->dev, 0);
1925 remove_debug_file(udc); 1925 remove_debug_file(udc);
1926 if (gpio_is_valid(udc->board.vbus_pin)) { 1926 if (gpio_is_valid(udc->board.vbus_pin)) {
1927 free_irq(udc->board.vbus_pin, udc); 1927 free_irq(gpio_to_irq(udc->board.vbus_pin), udc);
1928 gpio_free(udc->board.vbus_pin); 1928 gpio_free(udc->board.vbus_pin);
1929 } 1929 }
1930 free_irq(udc->udp_irq, udc); 1930 free_irq(udc->udp_irq, udc);
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c
index a6dfd2164166..170cbe89d9f8 100644
--- a/drivers/usb/gadget/dummy_hcd.c
+++ b/drivers/usb/gadget/dummy_hcd.c
@@ -927,7 +927,6 @@ static int dummy_udc_stop(struct usb_gadget *g,
927 927
928 dum->driver = NULL; 928 dum->driver = NULL;
929 929
930 dummy_pullup(&dum->gadget, 0);
931 return 0; 930 return 0;
932} 931}
933 932
diff --git a/drivers/usb/gadget/f_fs.c b/drivers/usb/gadget/f_fs.c
index 1cbba70836bc..f52cb1ae45d9 100644
--- a/drivers/usb/gadget/f_fs.c
+++ b/drivers/usb/gadget/f_fs.c
@@ -712,7 +712,7 @@ static long ffs_ep0_ioctl(struct file *file, unsigned code, unsigned long value)
712 if (code == FUNCTIONFS_INTERFACE_REVMAP) { 712 if (code == FUNCTIONFS_INTERFACE_REVMAP) {
713 struct ffs_function *func = ffs->func; 713 struct ffs_function *func = ffs->func;
714 ret = func ? ffs_func_revmap_intf(func, value) : -ENODEV; 714 ret = func ? ffs_func_revmap_intf(func, value) : -ENODEV;
715 } else if (gadget->ops->ioctl) { 715 } else if (gadget && gadget->ops->ioctl) {
716 ret = gadget->ops->ioctl(gadget, code, value); 716 ret = gadget->ops->ioctl(gadget, code, value);
717 } else { 717 } else {
718 ret = -ENOTTY; 718 ret = -ENOTTY;
@@ -1382,6 +1382,7 @@ static void functionfs_unbind(struct ffs_data *ffs)
1382 ffs->ep0req = NULL; 1382 ffs->ep0req = NULL;
1383 ffs->gadget = NULL; 1383 ffs->gadget = NULL;
1384 ffs_data_put(ffs); 1384 ffs_data_put(ffs);
1385 clear_bit(FFS_FL_BOUND, &ffs->flags);
1385 } 1386 }
1386} 1387}
1387 1388
diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c
index a371e966425f..cb8c162cae5a 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -2189,7 +2189,7 @@ unknown_cmnd:
2189 common->data_size_from_cmnd = 0; 2189 common->data_size_from_cmnd = 0;
2190 sprintf(unknown, "Unknown x%02x", common->cmnd[0]); 2190 sprintf(unknown, "Unknown x%02x", common->cmnd[0]);
2191 reply = check_command(common, common->cmnd_size, 2191 reply = check_command(common, common->cmnd_size,
2192 DATA_DIR_UNKNOWN, 0xff, 0, unknown); 2192 DATA_DIR_UNKNOWN, ~0, 0, unknown);
2193 if (reply == 0) { 2193 if (reply == 0) {
2194 common->curlun->sense_data = SS_INVALID_COMMAND; 2194 common->curlun->sense_data = SS_INVALID_COMMAND;
2195 reply = -EINVAL; 2195 reply = -EINVAL;
diff --git a/drivers/usb/gadget/f_phonet.c b/drivers/usb/gadget/f_phonet.c
index 85a5cebe96b3..965a6293206a 100644
--- a/drivers/usb/gadget/f_phonet.c
+++ b/drivers/usb/gadget/f_phonet.c
@@ -345,7 +345,7 @@ static void pn_rx_complete(struct usb_ep *ep, struct usb_request *req)
345 } 345 }
346 346
347 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page, 347 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page,
348 skb->len <= 1, req->actual, req->actual); 348 skb->len <= 1, req->actual, PAGE_SIZE);
349 page = NULL; 349 page = NULL;
350 350
351 if (req->actual < req->length) { /* Last fragment */ 351 if (req->actual < req->length) { /* Last fragment */
diff --git a/drivers/usb/gadget/f_rndis.c b/drivers/usb/gadget/f_rndis.c
index 7b1cf18df5e3..52343654f5df 100644
--- a/drivers/usb/gadget/f_rndis.c
+++ b/drivers/usb/gadget/f_rndis.c
@@ -500,6 +500,7 @@ rndis_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl)
500 if (buf) { 500 if (buf) {
501 memcpy(req->buf, buf, n); 501 memcpy(req->buf, buf, n);
502 req->complete = rndis_response_complete; 502 req->complete = rndis_response_complete;
503 req->context = rndis;
503 rndis_free_response(rndis->config, buf); 504 rndis_free_response(rndis->config, buf);
504 value = n; 505 value = n;
505 } 506 }
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
index 4fac56927741..a896d73f7a93 100644
--- a/drivers/usb/gadget/file_storage.c
+++ b/drivers/usb/gadget/file_storage.c
@@ -2579,7 +2579,7 @@ static int do_scsi_command(struct fsg_dev *fsg)
2579 fsg->data_size_from_cmnd = 0; 2579 fsg->data_size_from_cmnd = 0;
2580 sprintf(unknown, "Unknown x%02x", fsg->cmnd[0]); 2580 sprintf(unknown, "Unknown x%02x", fsg->cmnd[0]);
2581 if ((reply = check_command(fsg, fsg->cmnd_size, 2581 if ((reply = check_command(fsg, fsg->cmnd_size,
2582 DATA_DIR_UNKNOWN, 0xff, 0, unknown)) == 0) { 2582 DATA_DIR_UNKNOWN, ~0, 0, unknown)) == 0) {
2583 fsg->curlun->sense_data = SS_INVALID_COMMAND; 2583 fsg->curlun->sense_data = SS_INVALID_COMMAND;
2584 reply = -EINVAL; 2584 reply = -EINVAL;
2585 } 2585 }
diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
index 5f94e79cd6b9..55abfb6bd612 100644
--- a/drivers/usb/gadget/fsl_udc_core.c
+++ b/drivers/usb/gadget/fsl_udc_core.c
@@ -730,7 +730,7 @@ static void fsl_queue_td(struct fsl_ep *ep, struct fsl_req *req)
730 : (1 << (ep_index(ep))); 730 : (1 << (ep_index(ep)));
731 731
732 /* check if the pipe is empty */ 732 /* check if the pipe is empty */
733 if (!(list_empty(&ep->queue))) { 733 if (!(list_empty(&ep->queue)) && !(ep_index(ep) == 0)) {
734 /* Add td to the end */ 734 /* Add td to the end */
735 struct fsl_req *lastreq; 735 struct fsl_req *lastreq;
736 lastreq = list_entry(ep->queue.prev, struct fsl_req, queue); 736 lastreq = list_entry(ep->queue.prev, struct fsl_req, queue);
@@ -918,10 +918,6 @@ fsl_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
918 return -ENOMEM; 918 return -ENOMEM;
919 } 919 }
920 920
921 /* Update ep0 state */
922 if ((ep_index(ep) == 0))
923 udc->ep0_state = DATA_STATE_XMIT;
924
925 /* irq handler advances the queue */ 921 /* irq handler advances the queue */
926 if (req != NULL) 922 if (req != NULL)
927 list_add_tail(&req->queue, &ep->queue); 923 list_add_tail(&req->queue, &ep->queue);
@@ -1279,7 +1275,8 @@ static int ep0_prime_status(struct fsl_udc *udc, int direction)
1279 udc->ep0_dir = USB_DIR_OUT; 1275 udc->ep0_dir = USB_DIR_OUT;
1280 1276
1281 ep = &udc->eps[0]; 1277 ep = &udc->eps[0];
1282 udc->ep0_state = WAIT_FOR_OUT_STATUS; 1278 if (udc->ep0_state != DATA_STATE_XMIT)
1279 udc->ep0_state = WAIT_FOR_OUT_STATUS;
1283 1280
1284 req->ep = ep; 1281 req->ep = ep;
1285 req->req.length = 0; 1282 req->req.length = 0;
@@ -1384,6 +1381,9 @@ static void ch9getstatus(struct fsl_udc *udc, u8 request_type, u16 value,
1384 1381
1385 list_add_tail(&req->queue, &ep->queue); 1382 list_add_tail(&req->queue, &ep->queue);
1386 udc->ep0_state = DATA_STATE_XMIT; 1383 udc->ep0_state = DATA_STATE_XMIT;
1384 if (ep0_prime_status(udc, EP_DIR_OUT))
1385 ep0stall(udc);
1386
1387 return; 1387 return;
1388stall: 1388stall:
1389 ep0stall(udc); 1389 ep0stall(udc);
@@ -1492,6 +1492,14 @@ static void setup_received_irq(struct fsl_udc *udc,
1492 spin_lock(&udc->lock); 1492 spin_lock(&udc->lock);
1493 udc->ep0_state = (setup->bRequestType & USB_DIR_IN) 1493 udc->ep0_state = (setup->bRequestType & USB_DIR_IN)
1494 ? DATA_STATE_XMIT : DATA_STATE_RECV; 1494 ? DATA_STATE_XMIT : DATA_STATE_RECV;
1495 /*
1496 * If the data stage is IN, send status prime immediately.
1497 * See 2.0 Spec chapter 8.5.3.3 for detail.
1498 */
1499 if (udc->ep0_state == DATA_STATE_XMIT)
1500 if (ep0_prime_status(udc, EP_DIR_OUT))
1501 ep0stall(udc);
1502
1495 } else { 1503 } else {
1496 /* No data phase, IN status from gadget */ 1504 /* No data phase, IN status from gadget */
1497 udc->ep0_dir = USB_DIR_IN; 1505 udc->ep0_dir = USB_DIR_IN;
@@ -1520,9 +1528,8 @@ static void ep0_req_complete(struct fsl_udc *udc, struct fsl_ep *ep0,
1520 1528
1521 switch (udc->ep0_state) { 1529 switch (udc->ep0_state) {
1522 case DATA_STATE_XMIT: 1530 case DATA_STATE_XMIT:
1523 /* receive status phase */ 1531 /* already primed at setup_received_irq */
1524 if (ep0_prime_status(udc, EP_DIR_OUT)) 1532 udc->ep0_state = WAIT_FOR_OUT_STATUS;
1525 ep0stall(udc);
1526 break; 1533 break;
1527 case DATA_STATE_RECV: 1534 case DATA_STATE_RECV:
1528 /* send status phase */ 1535 /* send status phase */
diff --git a/drivers/usb/gadget/g_ffs.c b/drivers/usb/gadget/g_ffs.c
index 331cd6729d3c..a85eaf40b948 100644
--- a/drivers/usb/gadget/g_ffs.c
+++ b/drivers/usb/gadget/g_ffs.c
@@ -161,7 +161,7 @@ static struct usb_composite_driver gfs_driver = {
161static struct ffs_data *gfs_ffs_data; 161static struct ffs_data *gfs_ffs_data;
162static unsigned long gfs_registered; 162static unsigned long gfs_registered;
163 163
164static int gfs_init(void) 164static int __init gfs_init(void)
165{ 165{
166 ENTER(); 166 ENTER();
167 167
@@ -169,7 +169,7 @@ static int gfs_init(void)
169} 169}
170module_init(gfs_init); 170module_init(gfs_init);
171 171
172static void gfs_exit(void) 172static void __exit gfs_exit(void)
173{ 173{
174 ENTER(); 174 ENTER();
175 175
diff --git a/drivers/usb/gadget/inode.c b/drivers/usb/gadget/inode.c
index 8793f32bab11..e58b16442971 100644
--- a/drivers/usb/gadget/inode.c
+++ b/drivers/usb/gadget/inode.c
@@ -1574,7 +1574,6 @@ static void destroy_ep_files (struct dev_data *dev)
1574 DBG (dev, "%s %d\n", __func__, dev->state); 1574 DBG (dev, "%s %d\n", __func__, dev->state);
1575 1575
1576 /* dev->state must prevent interference */ 1576 /* dev->state must prevent interference */
1577restart:
1578 spin_lock_irq (&dev->lock); 1577 spin_lock_irq (&dev->lock);
1579 while (!list_empty(&dev->epfiles)) { 1578 while (!list_empty(&dev->epfiles)) {
1580 struct ep_data *ep; 1579 struct ep_data *ep;
diff --git a/drivers/usb/gadget/s3c-hsotg.c b/drivers/usb/gadget/s3c-hsotg.c
index 69295ba9d99a..105b206cd844 100644
--- a/drivers/usb/gadget/s3c-hsotg.c
+++ b/drivers/usb/gadget/s3c-hsotg.c
@@ -340,7 +340,7 @@ static void s3c_hsotg_init_fifo(struct s3c_hsotg *hsotg)
340 /* currently we allocate TX FIFOs for all possible endpoints, 340 /* currently we allocate TX FIFOs for all possible endpoints,
341 * and assume that they are all the same size. */ 341 * and assume that they are all the same size. */
342 342
343 for (ep = 0; ep <= 15; ep++) { 343 for (ep = 1; ep <= 15; ep++) {
344 val = addr; 344 val = addr;
345 val |= size << S3C_DPTXFSIZn_DPTxFSize_SHIFT; 345 val |= size << S3C_DPTXFSIZn_DPTxFSize_SHIFT;
346 addr += size; 346 addr += size;
@@ -741,7 +741,7 @@ static void s3c_hsotg_start_req(struct s3c_hsotg *hsotg,
741 /* write size / packets */ 741 /* write size / packets */
742 writel(epsize, hsotg->regs + epsize_reg); 742 writel(epsize, hsotg->regs + epsize_reg);
743 743
744 if (using_dma(hsotg)) { 744 if (using_dma(hsotg) && !continuing) {
745 unsigned int dma_reg; 745 unsigned int dma_reg;
746 746
747 /* write DMA address to control register, buffer already 747 /* write DMA address to control register, buffer already
@@ -1696,10 +1696,12 @@ static void s3c_hsotg_set_ep_maxpacket(struct s3c_hsotg *hsotg,
1696 reg |= mpsval; 1696 reg |= mpsval;
1697 writel(reg, regs + S3C_DIEPCTL(ep)); 1697 writel(reg, regs + S3C_DIEPCTL(ep));
1698 1698
1699 reg = readl(regs + S3C_DOEPCTL(ep)); 1699 if (ep) {
1700 reg &= ~S3C_DxEPCTL_MPS_MASK; 1700 reg = readl(regs + S3C_DOEPCTL(ep));
1701 reg |= mpsval; 1701 reg &= ~S3C_DxEPCTL_MPS_MASK;
1702 writel(reg, regs + S3C_DOEPCTL(ep)); 1702 reg |= mpsval;
1703 writel(reg, regs + S3C_DOEPCTL(ep));
1704 }
1703 1705
1704 return; 1706 return;
1705 1707
@@ -1919,7 +1921,8 @@ static void s3c_hsotg_epint(struct s3c_hsotg *hsotg, unsigned int idx,
1919 ints & S3C_DIEPMSK_TxFIFOEmpty) { 1921 ints & S3C_DIEPMSK_TxFIFOEmpty) {
1920 dev_dbg(hsotg->dev, "%s: ep%d: TxFIFOEmpty\n", 1922 dev_dbg(hsotg->dev, "%s: ep%d: TxFIFOEmpty\n",
1921 __func__, idx); 1923 __func__, idx);
1922 s3c_hsotg_trytx(hsotg, hs_ep); 1924 if (!using_dma(hsotg))
1925 s3c_hsotg_trytx(hsotg, hs_ep);
1923 } 1926 }
1924 } 1927 }
1925} 1928}
diff --git a/drivers/usb/gadget/udc-core.c b/drivers/usb/gadget/udc-core.c
index 56da49f31d6c..e5e44f8cde9a 100644
--- a/drivers/usb/gadget/udc-core.c
+++ b/drivers/usb/gadget/udc-core.c
@@ -263,9 +263,9 @@ static void usb_gadget_remove_driver(struct usb_udc *udc)
263 263
264 if (udc_is_newstyle(udc)) { 264 if (udc_is_newstyle(udc)) {
265 udc->driver->disconnect(udc->gadget); 265 udc->driver->disconnect(udc->gadget);
266 usb_gadget_disconnect(udc->gadget);
266 udc->driver->unbind(udc->gadget); 267 udc->driver->unbind(udc->gadget);
267 usb_gadget_udc_stop(udc->gadget, udc->driver); 268 usb_gadget_udc_stop(udc->gadget, udc->driver);
268 usb_gadget_disconnect(udc->gadget);
269 } else { 269 } else {
270 usb_gadget_stop(udc->gadget, udc->driver); 270 usb_gadget_stop(udc->gadget, udc->driver);
271 } 271 }
@@ -411,9 +411,13 @@ static ssize_t usb_udc_softconn_store(struct device *dev,
411 struct usb_udc *udc = container_of(dev, struct usb_udc, dev); 411 struct usb_udc *udc = container_of(dev, struct usb_udc, dev);
412 412
413 if (sysfs_streq(buf, "connect")) { 413 if (sysfs_streq(buf, "connect")) {
414 if (udc_is_newstyle(udc))
415 usb_gadget_udc_start(udc->gadget, udc->driver);
414 usb_gadget_connect(udc->gadget); 416 usb_gadget_connect(udc->gadget);
415 } else if (sysfs_streq(buf, "disconnect")) { 417 } else if (sysfs_streq(buf, "disconnect")) {
416 usb_gadget_disconnect(udc->gadget); 418 usb_gadget_disconnect(udc->gadget);
419 if (udc_is_newstyle(udc))
420 usb_gadget_udc_stop(udc->gadget, udc->driver);
417 } else { 421 } else {
418 dev_err(dev, "unsupported command '%s'\n", buf); 422 dev_err(dev, "unsupported command '%s'\n", buf);
419 return -EINVAL; 423 return -EINVAL;
diff --git a/drivers/usb/gadget/uvc.h b/drivers/usb/gadget/uvc.h
index bc78c606c12b..ca4e03a1c73a 100644
--- a/drivers/usb/gadget/uvc.h
+++ b/drivers/usb/gadget/uvc.h
@@ -28,7 +28,7 @@
28 28
29struct uvc_request_data 29struct uvc_request_data
30{ 30{
31 unsigned int length; 31 __s32 length;
32 __u8 data[60]; 32 __u8 data[60];
33}; 33};
34 34
diff --git a/drivers/usb/gadget/uvc_queue.c b/drivers/usb/gadget/uvc_queue.c
index d776adb2da67..0cdf89d32a15 100644
--- a/drivers/usb/gadget/uvc_queue.c
+++ b/drivers/usb/gadget/uvc_queue.c
@@ -543,11 +543,11 @@ done:
543 return ret; 543 return ret;
544} 544}
545 545
546/* called with queue->irqlock held.. */
546static struct uvc_buffer * 547static struct uvc_buffer *
547uvc_queue_next_buffer(struct uvc_video_queue *queue, struct uvc_buffer *buf) 548uvc_queue_next_buffer(struct uvc_video_queue *queue, struct uvc_buffer *buf)
548{ 549{
549 struct uvc_buffer *nextbuf; 550 struct uvc_buffer *nextbuf;
550 unsigned long flags;
551 551
552 if ((queue->flags & UVC_QUEUE_DROP_INCOMPLETE) && 552 if ((queue->flags & UVC_QUEUE_DROP_INCOMPLETE) &&
553 buf->buf.length != buf->buf.bytesused) { 553 buf->buf.length != buf->buf.bytesused) {
@@ -556,14 +556,12 @@ uvc_queue_next_buffer(struct uvc_video_queue *queue, struct uvc_buffer *buf)
556 return buf; 556 return buf;
557 } 557 }
558 558
559 spin_lock_irqsave(&queue->irqlock, flags);
560 list_del(&buf->queue); 559 list_del(&buf->queue);
561 if (!list_empty(&queue->irqqueue)) 560 if (!list_empty(&queue->irqqueue))
562 nextbuf = list_first_entry(&queue->irqqueue, struct uvc_buffer, 561 nextbuf = list_first_entry(&queue->irqqueue, struct uvc_buffer,
563 queue); 562 queue);
564 else 563 else
565 nextbuf = NULL; 564 nextbuf = NULL;
566 spin_unlock_irqrestore(&queue->irqlock, flags);
567 565
568 buf->buf.sequence = queue->sequence++; 566 buf->buf.sequence = queue->sequence++;
569 do_gettimeofday(&buf->buf.timestamp); 567 do_gettimeofday(&buf->buf.timestamp);
diff --git a/drivers/usb/gadget/uvc_v4l2.c b/drivers/usb/gadget/uvc_v4l2.c
index f6e083b50191..54d7ca559cb2 100644
--- a/drivers/usb/gadget/uvc_v4l2.c
+++ b/drivers/usb/gadget/uvc_v4l2.c
@@ -39,7 +39,7 @@ uvc_send_response(struct uvc_device *uvc, struct uvc_request_data *data)
39 if (data->length < 0) 39 if (data->length < 0)
40 return usb_ep_set_halt(cdev->gadget->ep0); 40 return usb_ep_set_halt(cdev->gadget->ep0);
41 41
42 req->length = min(uvc->event_length, data->length); 42 req->length = min_t(unsigned int, uvc->event_length, data->length);
43 req->zero = data->length < uvc->event_length; 43 req->zero = data->length < uvc->event_length;
44 req->dma = DMA_ADDR_INVALID; 44 req->dma = DMA_ADDR_INVALID;
45 45
diff --git a/drivers/usb/host/ehci-atmel.c b/drivers/usb/host/ehci-atmel.c
index 19f318ababa2..cf14c95a6700 100644
--- a/drivers/usb/host/ehci-atmel.c
+++ b/drivers/usb/host/ehci-atmel.c
@@ -13,6 +13,7 @@
13 13
14#include <linux/clk.h> 14#include <linux/clk.h>
15#include <linux/platform_device.h> 15#include <linux/platform_device.h>
16#include <linux/of.h>
16#include <linux/of_platform.h> 17#include <linux/of_platform.h>
17 18
18/* interface and function clocks */ 19/* interface and function clocks */
diff --git a/drivers/usb/host/ehci-dbg.c b/drivers/usb/host/ehci-dbg.c
index fd9109d7eb0e..680e1a31fb87 100644
--- a/drivers/usb/host/ehci-dbg.c
+++ b/drivers/usb/host/ehci-dbg.c
@@ -352,7 +352,6 @@ static int debug_async_open(struct inode *, struct file *);
352static int debug_periodic_open(struct inode *, struct file *); 352static int debug_periodic_open(struct inode *, struct file *);
353static int debug_registers_open(struct inode *, struct file *); 353static int debug_registers_open(struct inode *, struct file *);
354static int debug_async_open(struct inode *, struct file *); 354static int debug_async_open(struct inode *, struct file *);
355static int debug_lpm_open(struct inode *, struct file *);
356static ssize_t debug_lpm_read(struct file *file, char __user *user_buf, 355static ssize_t debug_lpm_read(struct file *file, char __user *user_buf,
357 size_t count, loff_t *ppos); 356 size_t count, loff_t *ppos);
358static ssize_t debug_lpm_write(struct file *file, const char __user *buffer, 357static ssize_t debug_lpm_write(struct file *file, const char __user *buffer,
@@ -385,7 +384,7 @@ static const struct file_operations debug_registers_fops = {
385}; 384};
386static const struct file_operations debug_lpm_fops = { 385static const struct file_operations debug_lpm_fops = {
387 .owner = THIS_MODULE, 386 .owner = THIS_MODULE,
388 .open = debug_lpm_open, 387 .open = simple_open,
389 .read = debug_lpm_read, 388 .read = debug_lpm_read,
390 .write = debug_lpm_write, 389 .write = debug_lpm_write,
391 .release = debug_lpm_close, 390 .release = debug_lpm_close,
@@ -970,12 +969,6 @@ static int debug_registers_open(struct inode *inode, struct file *file)
970 return file->private_data ? 0 : -ENOMEM; 969 return file->private_data ? 0 : -ENOMEM;
971} 970}
972 971
973static int debug_lpm_open(struct inode *inode, struct file *file)
974{
975 file->private_data = inode->i_private;
976 return 0;
977}
978
979static int debug_lpm_close(struct inode *inode, struct file *file) 972static int debug_lpm_close(struct inode *inode, struct file *file)
980{ 973{
981 return 0; 974 return 0;
diff --git a/drivers/usb/host/ehci-fsl.c b/drivers/usb/host/ehci-fsl.c
index 3e7345172e03..d0a84bd3f3eb 100644
--- a/drivers/usb/host/ehci-fsl.c
+++ b/drivers/usb/host/ehci-fsl.c
@@ -218,6 +218,9 @@ static void ehci_fsl_setup_phy(struct ehci_hcd *ehci,
218 u32 portsc; 218 u32 portsc;
219 struct usb_hcd *hcd = ehci_to_hcd(ehci); 219 struct usb_hcd *hcd = ehci_to_hcd(ehci);
220 void __iomem *non_ehci = hcd->regs; 220 void __iomem *non_ehci = hcd->regs;
221 struct fsl_usb2_platform_data *pdata;
222
223 pdata = hcd->self.controller->platform_data;
221 224
222 portsc = ehci_readl(ehci, &ehci->regs->port_status[port_offset]); 225 portsc = ehci_readl(ehci, &ehci->regs->port_status[port_offset]);
223 portsc &= ~(PORT_PTS_MSK | PORT_PTS_PTW); 226 portsc &= ~(PORT_PTS_MSK | PORT_PTS_PTW);
@@ -234,7 +237,9 @@ static void ehci_fsl_setup_phy(struct ehci_hcd *ehci,
234 /* fall through */ 237 /* fall through */
235 case FSL_USB2_PHY_UTMI: 238 case FSL_USB2_PHY_UTMI:
236 /* enable UTMI PHY */ 239 /* enable UTMI PHY */
237 setbits32(non_ehci + FSL_SOC_USB_CTRL, CTRL_UTMI_PHY_EN); 240 if (pdata->have_sysif_regs)
241 setbits32(non_ehci + FSL_SOC_USB_CTRL,
242 CTRL_UTMI_PHY_EN);
238 portsc |= PORT_PTS_UTMI; 243 portsc |= PORT_PTS_UTMI;
239 break; 244 break;
240 case FSL_USB2_PHY_NONE: 245 case FSL_USB2_PHY_NONE:
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 057cdda7a489..4a3bc5b7a06f 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -347,6 +347,8 @@ static int ehci_reset (struct ehci_hcd *ehci)
347 if (ehci->debug) 347 if (ehci->debug)
348 dbgp_external_startup(); 348 dbgp_external_startup();
349 349
350 ehci->port_c_suspend = ehci->suspended_ports =
351 ehci->resuming_ports = 0;
350 return retval; 352 return retval;
351} 353}
352 354
@@ -856,8 +858,13 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd)
856 goto dead; 858 goto dead;
857 } 859 }
858 860
861 /*
862 * We don't use STS_FLR, but some controllers don't like it to
863 * remain on, so mask it out along with the other status bits.
864 */
865 masked_status = status & (INTR_MASK | STS_FLR);
866
859 /* Shared IRQ? */ 867 /* Shared IRQ? */
860 masked_status = status & INTR_MASK;
861 if (!masked_status || unlikely(ehci->rh_state == EHCI_RH_HALTED)) { 868 if (!masked_status || unlikely(ehci->rh_state == EHCI_RH_HALTED)) {
862 spin_unlock(&ehci->lock); 869 spin_unlock(&ehci->lock);
863 return IRQ_NONE; 870 return IRQ_NONE;
@@ -908,7 +915,7 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd)
908 pcd_status = status; 915 pcd_status = status;
909 916
910 /* resume root hub? */ 917 /* resume root hub? */
911 if (!(cmd & CMD_RUN)) 918 if (ehci->rh_state == EHCI_RH_SUSPENDED)
912 usb_hcd_resume_root_hub(hcd); 919 usb_hcd_resume_root_hub(hcd);
913 920
914 /* get per-port change detect bits */ 921 /* get per-port change detect bits */
@@ -939,6 +946,7 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd)
939 * like usb_port_resume() does. 946 * like usb_port_resume() does.
940 */ 947 */
941 ehci->reset_done[i] = jiffies + msecs_to_jiffies(25); 948 ehci->reset_done[i] = jiffies + msecs_to_jiffies(25);
949 set_bit(i, &ehci->resuming_ports);
942 ehci_dbg (ehci, "port %d remote wakeup\n", i + 1); 950 ehci_dbg (ehci, "port %d remote wakeup\n", i + 1);
943 mod_timer(&hcd->rh_timer, ehci->reset_done[i]); 951 mod_timer(&hcd->rh_timer, ehci->reset_done[i]);
944 } 952 }
diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
index 256fbd42e48c..38fe07623152 100644
--- a/drivers/usb/host/ehci-hub.c
+++ b/drivers/usb/host/ehci-hub.c
@@ -223,15 +223,10 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
223 * remote wakeup, we must fail the suspend. 223 * remote wakeup, we must fail the suspend.
224 */ 224 */
225 if (hcd->self.root_hub->do_remote_wakeup) { 225 if (hcd->self.root_hub->do_remote_wakeup) {
226 port = HCS_N_PORTS(ehci->hcs_params); 226 if (ehci->resuming_ports) {
227 while (port--) { 227 spin_unlock_irq(&ehci->lock);
228 if (ehci->reset_done[port] != 0) { 228 ehci_dbg(ehci, "suspend failed because a port is resuming\n");
229 spin_unlock_irq(&ehci->lock); 229 return -EBUSY;
230 ehci_dbg(ehci, "suspend failed because "
231 "port %d is resuming\n",
232 port + 1);
233 return -EBUSY;
234 }
235 } 230 }
236 } 231 }
237 232
@@ -554,16 +549,12 @@ static int
554ehci_hub_status_data (struct usb_hcd *hcd, char *buf) 549ehci_hub_status_data (struct usb_hcd *hcd, char *buf)
555{ 550{
556 struct ehci_hcd *ehci = hcd_to_ehci (hcd); 551 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
557 u32 temp, status = 0; 552 u32 temp, status;
558 u32 mask; 553 u32 mask;
559 int ports, i, retval = 1; 554 int ports, i, retval = 1;
560 unsigned long flags; 555 unsigned long flags;
561 u32 ppcd = 0; 556 u32 ppcd = 0;
562 557
563 /* if !USB_SUSPEND, root hub timers won't get shut down ... */
564 if (ehci->rh_state != EHCI_RH_RUNNING)
565 return 0;
566
567 /* init status to no-changes */ 558 /* init status to no-changes */
568 buf [0] = 0; 559 buf [0] = 0;
569 ports = HCS_N_PORTS (ehci->hcs_params); 560 ports = HCS_N_PORTS (ehci->hcs_params);
@@ -572,6 +563,11 @@ ehci_hub_status_data (struct usb_hcd *hcd, char *buf)
572 retval++; 563 retval++;
573 } 564 }
574 565
566 /* Inform the core about resumes-in-progress by returning
567 * a non-zero value even if there are no status changes.
568 */
569 status = ehci->resuming_ports;
570
575 /* Some boards (mostly VIA?) report bogus overcurrent indications, 571 /* Some boards (mostly VIA?) report bogus overcurrent indications,
576 * causing massive log spam unless we completely ignore them. It 572 * causing massive log spam unless we completely ignore them. It
577 * may be relevant that VIA VT8235 controllers, where PORT_POWER is 573 * may be relevant that VIA VT8235 controllers, where PORT_POWER is
@@ -846,6 +842,7 @@ static int ehci_hub_control (
846 ehci_writel(ehci, 842 ehci_writel(ehci,
847 temp & ~(PORT_RWC_BITS | PORT_RESUME), 843 temp & ~(PORT_RWC_BITS | PORT_RESUME),
848 status_reg); 844 status_reg);
845 clear_bit(wIndex, &ehci->resuming_ports);
849 retval = handshake(ehci, status_reg, 846 retval = handshake(ehci, status_reg,
850 PORT_RESUME, 0, 2000 /* 2msec */); 847 PORT_RESUME, 0, 2000 /* 2msec */);
851 if (retval != 0) { 848 if (retval != 0) {
@@ -864,6 +861,7 @@ static int ehci_hub_control (
864 ehci->reset_done[wIndex])) { 861 ehci->reset_done[wIndex])) {
865 status |= USB_PORT_STAT_C_RESET << 16; 862 status |= USB_PORT_STAT_C_RESET << 16;
866 ehci->reset_done [wIndex] = 0; 863 ehci->reset_done [wIndex] = 0;
864 clear_bit(wIndex, &ehci->resuming_ports);
867 865
868 /* force reset to complete */ 866 /* force reset to complete */
869 ehci_writel(ehci, temp & ~(PORT_RWC_BITS | PORT_RESET), 867 ehci_writel(ehci, temp & ~(PORT_RWC_BITS | PORT_RESET),
@@ -884,8 +882,10 @@ static int ehci_hub_control (
884 ehci_readl(ehci, status_reg)); 882 ehci_readl(ehci, status_reg));
885 } 883 }
886 884
887 if (!(temp & (PORT_RESUME|PORT_RESET))) 885 if (!(temp & (PORT_RESUME|PORT_RESET))) {
888 ehci->reset_done[wIndex] = 0; 886 ehci->reset_done[wIndex] = 0;
887 clear_bit(wIndex, &ehci->resuming_ports);
888 }
889 889
890 /* transfer dedicated ports to the companion hc */ 890 /* transfer dedicated ports to the companion hc */
891 if ((temp & PORT_CONNECT) && 891 if ((temp & PORT_CONNECT) &&
@@ -920,6 +920,7 @@ static int ehci_hub_control (
920 status |= USB_PORT_STAT_SUSPEND; 920 status |= USB_PORT_STAT_SUSPEND;
921 } else if (test_bit(wIndex, &ehci->suspended_ports)) { 921 } else if (test_bit(wIndex, &ehci->suspended_ports)) {
922 clear_bit(wIndex, &ehci->suspended_ports); 922 clear_bit(wIndex, &ehci->suspended_ports);
923 clear_bit(wIndex, &ehci->resuming_ports);
923 ehci->reset_done[wIndex] = 0; 924 ehci->reset_done[wIndex] = 0;
924 if (temp & PORT_PE) 925 if (temp & PORT_PE)
925 set_bit(wIndex, &ehci->port_c_suspend); 926 set_bit(wIndex, &ehci->port_c_suspend);
diff --git a/drivers/usb/host/ehci-omap.c b/drivers/usb/host/ehci-omap.c
index bba9850f32f0..5c78f9e71466 100644
--- a/drivers/usb/host/ehci-omap.c
+++ b/drivers/usb/host/ehci-omap.c
@@ -42,6 +42,7 @@
42#include <plat/usb.h> 42#include <plat/usb.h>
43#include <linux/regulator/consumer.h> 43#include <linux/regulator/consumer.h>
44#include <linux/pm_runtime.h> 44#include <linux/pm_runtime.h>
45#include <linux/gpio.h>
45 46
46/* EHCI Register Set */ 47/* EHCI Register Set */
47#define EHCI_INSNREG04 (0xA0) 48#define EHCI_INSNREG04 (0xA0)
@@ -191,6 +192,19 @@ static int ehci_hcd_omap_probe(struct platform_device *pdev)
191 } 192 }
192 } 193 }
193 194
195 if (pdata->phy_reset) {
196 if (gpio_is_valid(pdata->reset_gpio_port[0]))
197 gpio_request_one(pdata->reset_gpio_port[0],
198 GPIOF_OUT_INIT_LOW, "USB1 PHY reset");
199
200 if (gpio_is_valid(pdata->reset_gpio_port[1]))
201 gpio_request_one(pdata->reset_gpio_port[1],
202 GPIOF_OUT_INIT_LOW, "USB2 PHY reset");
203
204 /* Hold the PHY in RESET for enough time till DIR is high */
205 udelay(10);
206 }
207
194 pm_runtime_enable(dev); 208 pm_runtime_enable(dev);
195 pm_runtime_get_sync(dev); 209 pm_runtime_get_sync(dev);
196 210
@@ -237,6 +251,19 @@ static int ehci_hcd_omap_probe(struct platform_device *pdev)
237 /* root ports should always stay powered */ 251 /* root ports should always stay powered */
238 ehci_port_power(omap_ehci, 1); 252 ehci_port_power(omap_ehci, 1);
239 253
254 if (pdata->phy_reset) {
255 /* Hold the PHY in RESET for enough time till
256 * PHY is settled and ready
257 */
258 udelay(10);
259
260 if (gpio_is_valid(pdata->reset_gpio_port[0]))
261 gpio_set_value(pdata->reset_gpio_port[0], 1);
262
263 if (gpio_is_valid(pdata->reset_gpio_port[1]))
264 gpio_set_value(pdata->reset_gpio_port[1], 1);
265 }
266
240 return 0; 267 return 0;
241 268
242err_add_hcd: 269err_add_hcd:
@@ -259,8 +286,9 @@ err_io:
259 */ 286 */
260static int ehci_hcd_omap_remove(struct platform_device *pdev) 287static int ehci_hcd_omap_remove(struct platform_device *pdev)
261{ 288{
262 struct device *dev = &pdev->dev; 289 struct device *dev = &pdev->dev;
263 struct usb_hcd *hcd = dev_get_drvdata(dev); 290 struct usb_hcd *hcd = dev_get_drvdata(dev);
291 struct ehci_hcd_omap_platform_data *pdata = dev->platform_data;
264 292
265 usb_remove_hcd(hcd); 293 usb_remove_hcd(hcd);
266 disable_put_regulator(dev->platform_data); 294 disable_put_regulator(dev->platform_data);
@@ -269,6 +297,13 @@ static int ehci_hcd_omap_remove(struct platform_device *pdev)
269 pm_runtime_put_sync(dev); 297 pm_runtime_put_sync(dev);
270 pm_runtime_disable(dev); 298 pm_runtime_disable(dev);
271 299
300 if (pdata->phy_reset) {
301 if (gpio_is_valid(pdata->reset_gpio_port[0]))
302 gpio_free(pdata->reset_gpio_port[0]);
303
304 if (gpio_is_valid(pdata->reset_gpio_port[1]))
305 gpio_free(pdata->reset_gpio_port[1]);
306 }
272 return 0; 307 return 0;
273} 308}
274 309
diff --git a/drivers/usb/host/ehci-pci.c b/drivers/usb/host/ehci-pci.c
index 01bb7241d6ef..fe8dc069164e 100644
--- a/drivers/usb/host/ehci-pci.c
+++ b/drivers/usb/host/ehci-pci.c
@@ -144,6 +144,14 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
144 hcd->has_tt = 1; 144 hcd->has_tt = 1;
145 tdi_reset(ehci); 145 tdi_reset(ehci);
146 } 146 }
147 if (pdev->subsystem_vendor == PCI_VENDOR_ID_ASUSTEK) {
148 /* EHCI #1 or #2 on 6 Series/C200 Series chipset */
149 if (pdev->device == 0x1c26 || pdev->device == 0x1c2d) {
150 ehci_info(ehci, "broken D3 during system sleep on ASUS\n");
151 hcd->broken_pci_sleep = 1;
152 device_set_wakeup_capable(&pdev->dev, false);
153 }
154 }
147 break; 155 break;
148 case PCI_VENDOR_ID_TDI: 156 case PCI_VENDOR_ID_TDI:
149 if (pdev->device == PCI_DEVICE_ID_TDI_EHCI) { 157 if (pdev->device == PCI_DEVICE_ID_TDI_EHCI) {
diff --git a/drivers/usb/host/ehci-tegra.c b/drivers/usb/host/ehci-tegra.c
index 3de48a2d7955..f214a80cdee2 100644
--- a/drivers/usb/host/ehci-tegra.c
+++ b/drivers/usb/host/ehci-tegra.c
@@ -24,6 +24,7 @@
24#include <linux/gpio.h> 24#include <linux/gpio.h>
25#include <linux/of.h> 25#include <linux/of.h>
26#include <linux/of_gpio.h> 26#include <linux/of_gpio.h>
27#include <linux/pm_runtime.h>
27 28
28#include <mach/usb_phy.h> 29#include <mach/usb_phy.h>
29#include <mach/iomap.h> 30#include <mach/iomap.h>
@@ -37,9 +38,7 @@ struct tegra_ehci_hcd {
37 struct clk *emc_clk; 38 struct clk *emc_clk;
38 struct usb_phy *transceiver; 39 struct usb_phy *transceiver;
39 int host_resumed; 40 int host_resumed;
40 int bus_suspended;
41 int port_resuming; 41 int port_resuming;
42 int power_down_on_bus_suspend;
43 enum tegra_usb_phy_port_speed port_speed; 42 enum tegra_usb_phy_port_speed port_speed;
44}; 43};
45 44
@@ -224,6 +223,7 @@ static int tegra_ehci_hub_control(
224 temp &= ~(PORT_RWC_BITS | PORT_WAKE_BITS); 223 temp &= ~(PORT_RWC_BITS | PORT_WAKE_BITS);
225 /* start resume signalling */ 224 /* start resume signalling */
226 ehci_writel(ehci, temp | PORT_RESUME, status_reg); 225 ehci_writel(ehci, temp | PORT_RESUME, status_reg);
226 set_bit(wIndex-1, &ehci->resuming_ports);
227 227
228 spin_unlock_irqrestore(&ehci->lock, flags); 228 spin_unlock_irqrestore(&ehci->lock, flags);
229 msleep(20); 229 msleep(20);
@@ -236,6 +236,7 @@ static int tegra_ehci_hub_control(
236 pr_err("%s: timeout waiting for SUSPEND\n", __func__); 236 pr_err("%s: timeout waiting for SUSPEND\n", __func__);
237 237
238 ehci->reset_done[wIndex-1] = 0; 238 ehci->reset_done[wIndex-1] = 0;
239 clear_bit(wIndex-1, &ehci->resuming_ports);
239 240
240 tegra->port_resuming = 1; 241 tegra->port_resuming = 1;
241 goto done; 242 goto done;
@@ -271,120 +272,6 @@ static void tegra_ehci_restart(struct usb_hcd *hcd)
271 up_write(&ehci_cf_port_reset_rwsem); 272 up_write(&ehci_cf_port_reset_rwsem);
272} 273}
273 274
274static int tegra_usb_suspend(struct usb_hcd *hcd)
275{
276 struct tegra_ehci_hcd *tegra = dev_get_drvdata(hcd->self.controller);
277 struct ehci_regs __iomem *hw = tegra->ehci->regs;
278 unsigned long flags;
279
280 spin_lock_irqsave(&tegra->ehci->lock, flags);
281
282 tegra->port_speed = (readl(&hw->port_status[0]) >> 26) & 0x3;
283 ehci_halt(tegra->ehci);
284 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
285
286 spin_unlock_irqrestore(&tegra->ehci->lock, flags);
287
288 tegra_ehci_power_down(hcd);
289 return 0;
290}
291
292static int tegra_usb_resume(struct usb_hcd *hcd)
293{
294 struct tegra_ehci_hcd *tegra = dev_get_drvdata(hcd->self.controller);
295 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
296 struct ehci_regs __iomem *hw = ehci->regs;
297 unsigned long val;
298
299 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
300 tegra_ehci_power_up(hcd);
301
302 if (tegra->port_speed > TEGRA_USB_PHY_PORT_SPEED_HIGH) {
303 /* Wait for the phy to detect new devices
304 * before we restart the controller */
305 msleep(10);
306 goto restart;
307 }
308
309 /* Force the phy to keep data lines in suspend state */
310 tegra_ehci_phy_restore_start(tegra->phy, tegra->port_speed);
311
312 /* Enable host mode */
313 tdi_reset(ehci);
314
315 /* Enable Port Power */
316 val = readl(&hw->port_status[0]);
317 val |= PORT_POWER;
318 writel(val, &hw->port_status[0]);
319 udelay(10);
320
321 /* Check if the phy resume from LP0. When the phy resume from LP0
322 * USB register will be reset. */
323 if (!readl(&hw->async_next)) {
324 /* Program the field PTC based on the saved speed mode */
325 val = readl(&hw->port_status[0]);
326 val &= ~PORT_TEST(~0);
327 if (tegra->port_speed == TEGRA_USB_PHY_PORT_SPEED_HIGH)
328 val |= PORT_TEST_FORCE;
329 else if (tegra->port_speed == TEGRA_USB_PHY_PORT_SPEED_FULL)
330 val |= PORT_TEST(6);
331 else if (tegra->port_speed == TEGRA_USB_PHY_PORT_SPEED_LOW)
332 val |= PORT_TEST(7);
333 writel(val, &hw->port_status[0]);
334 udelay(10);
335
336 /* Disable test mode by setting PTC field to NORMAL_OP */
337 val = readl(&hw->port_status[0]);
338 val &= ~PORT_TEST(~0);
339 writel(val, &hw->port_status[0]);
340 udelay(10);
341 }
342
343 /* Poll until CCS is enabled */
344 if (handshake(ehci, &hw->port_status[0], PORT_CONNECT,
345 PORT_CONNECT, 2000)) {
346 pr_err("%s: timeout waiting for PORT_CONNECT\n", __func__);
347 goto restart;
348 }
349
350 /* Poll until PE is enabled */
351 if (handshake(ehci, &hw->port_status[0], PORT_PE,
352 PORT_PE, 2000)) {
353 pr_err("%s: timeout waiting for USB_PORTSC1_PE\n", __func__);
354 goto restart;
355 }
356
357 /* Clear the PCI status, to avoid an interrupt taken upon resume */
358 val = readl(&hw->status);
359 val |= STS_PCD;
360 writel(val, &hw->status);
361
362 /* Put controller in suspend mode by writing 1 to SUSP bit of PORTSC */
363 val = readl(&hw->port_status[0]);
364 if ((val & PORT_POWER) && (val & PORT_PE)) {
365 val |= PORT_SUSPEND;
366 writel(val, &hw->port_status[0]);
367
368 /* Wait until port suspend completes */
369 if (handshake(ehci, &hw->port_status[0], PORT_SUSPEND,
370 PORT_SUSPEND, 1000)) {
371 pr_err("%s: timeout waiting for PORT_SUSPEND\n",
372 __func__);
373 goto restart;
374 }
375 }
376
377 tegra_ehci_phy_restore_end(tegra->phy);
378 return 0;
379
380restart:
381 if (tegra->port_speed <= TEGRA_USB_PHY_PORT_SPEED_HIGH)
382 tegra_ehci_phy_restore_end(tegra->phy);
383
384 tegra_ehci_restart(hcd);
385 return 0;
386}
387
388static void tegra_ehci_shutdown(struct usb_hcd *hcd) 275static void tegra_ehci_shutdown(struct usb_hcd *hcd)
389{ 276{
390 struct tegra_ehci_hcd *tegra = dev_get_drvdata(hcd->self.controller); 277 struct tegra_ehci_hcd *tegra = dev_get_drvdata(hcd->self.controller);
@@ -432,36 +319,6 @@ static int tegra_ehci_setup(struct usb_hcd *hcd)
432 return retval; 319 return retval;
433} 320}
434 321
435#ifdef CONFIG_PM
436static int tegra_ehci_bus_suspend(struct usb_hcd *hcd)
437{
438 struct tegra_ehci_hcd *tegra = dev_get_drvdata(hcd->self.controller);
439 int error_status = 0;
440
441 error_status = ehci_bus_suspend(hcd);
442 if (!error_status && tegra->power_down_on_bus_suspend) {
443 tegra_usb_suspend(hcd);
444 tegra->bus_suspended = 1;
445 }
446
447 return error_status;
448}
449
450static int tegra_ehci_bus_resume(struct usb_hcd *hcd)
451{
452 struct tegra_ehci_hcd *tegra = dev_get_drvdata(hcd->self.controller);
453
454 if (tegra->bus_suspended && tegra->power_down_on_bus_suspend) {
455 tegra_usb_resume(hcd);
456 tegra->bus_suspended = 0;
457 }
458
459 tegra_usb_phy_preresume(tegra->phy);
460 tegra->port_resuming = 1;
461 return ehci_bus_resume(hcd);
462}
463#endif
464
465struct temp_buffer { 322struct temp_buffer {
466 void *kmalloc_ptr; 323 void *kmalloc_ptr;
467 void *old_xfer_buffer; 324 void *old_xfer_buffer;
@@ -572,8 +429,8 @@ static const struct hc_driver tegra_ehci_hc_driver = {
572 .hub_control = tegra_ehci_hub_control, 429 .hub_control = tegra_ehci_hub_control,
573 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, 430 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
574#ifdef CONFIG_PM 431#ifdef CONFIG_PM
575 .bus_suspend = tegra_ehci_bus_suspend, 432 .bus_suspend = ehci_bus_suspend,
576 .bus_resume = tegra_ehci_bus_resume, 433 .bus_resume = ehci_bus_resume,
577#endif 434#endif
578 .relinquish_port = ehci_relinquish_port, 435 .relinquish_port = ehci_relinquish_port,
579 .port_handed_over = ehci_port_handed_over, 436 .port_handed_over = ehci_port_handed_over,
@@ -601,11 +458,187 @@ static int setup_vbus_gpio(struct platform_device *pdev)
601 dev_err(&pdev->dev, "can't enable vbus\n"); 458 dev_err(&pdev->dev, "can't enable vbus\n");
602 return err; 459 return err;
603 } 460 }
604 gpio_set_value(gpio, 1);
605 461
606 return err; 462 return err;
607} 463}
608 464
465#ifdef CONFIG_PM
466
467static int controller_suspend(struct device *dev)
468{
469 struct tegra_ehci_hcd *tegra =
470 platform_get_drvdata(to_platform_device(dev));
471 struct ehci_hcd *ehci = tegra->ehci;
472 struct usb_hcd *hcd = ehci_to_hcd(ehci);
473 struct ehci_regs __iomem *hw = ehci->regs;
474 unsigned long flags;
475
476 if (time_before(jiffies, ehci->next_statechange))
477 msleep(10);
478
479 spin_lock_irqsave(&ehci->lock, flags);
480
481 tegra->port_speed = (readl(&hw->port_status[0]) >> 26) & 0x3;
482 ehci_halt(ehci);
483 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
484
485 spin_unlock_irqrestore(&ehci->lock, flags);
486
487 tegra_ehci_power_down(hcd);
488 return 0;
489}
490
491static int controller_resume(struct device *dev)
492{
493 struct tegra_ehci_hcd *tegra =
494 platform_get_drvdata(to_platform_device(dev));
495 struct ehci_hcd *ehci = tegra->ehci;
496 struct usb_hcd *hcd = ehci_to_hcd(ehci);
497 struct ehci_regs __iomem *hw = ehci->regs;
498 unsigned long val;
499
500 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
501 tegra_ehci_power_up(hcd);
502
503 if (tegra->port_speed > TEGRA_USB_PHY_PORT_SPEED_HIGH) {
504 /* Wait for the phy to detect new devices
505 * before we restart the controller */
506 msleep(10);
507 goto restart;
508 }
509
510 /* Force the phy to keep data lines in suspend state */
511 tegra_ehci_phy_restore_start(tegra->phy, tegra->port_speed);
512
513 /* Enable host mode */
514 tdi_reset(ehci);
515
516 /* Enable Port Power */
517 val = readl(&hw->port_status[0]);
518 val |= PORT_POWER;
519 writel(val, &hw->port_status[0]);
520 udelay(10);
521
522 /* Check if the phy resume from LP0. When the phy resume from LP0
523 * USB register will be reset. */
524 if (!readl(&hw->async_next)) {
525 /* Program the field PTC based on the saved speed mode */
526 val = readl(&hw->port_status[0]);
527 val &= ~PORT_TEST(~0);
528 if (tegra->port_speed == TEGRA_USB_PHY_PORT_SPEED_HIGH)
529 val |= PORT_TEST_FORCE;
530 else if (tegra->port_speed == TEGRA_USB_PHY_PORT_SPEED_FULL)
531 val |= PORT_TEST(6);
532 else if (tegra->port_speed == TEGRA_USB_PHY_PORT_SPEED_LOW)
533 val |= PORT_TEST(7);
534 writel(val, &hw->port_status[0]);
535 udelay(10);
536
537 /* Disable test mode by setting PTC field to NORMAL_OP */
538 val = readl(&hw->port_status[0]);
539 val &= ~PORT_TEST(~0);
540 writel(val, &hw->port_status[0]);
541 udelay(10);
542 }
543
544 /* Poll until CCS is enabled */
545 if (handshake(ehci, &hw->port_status[0], PORT_CONNECT,
546 PORT_CONNECT, 2000)) {
547 pr_err("%s: timeout waiting for PORT_CONNECT\n", __func__);
548 goto restart;
549 }
550
551 /* Poll until PE is enabled */
552 if (handshake(ehci, &hw->port_status[0], PORT_PE,
553 PORT_PE, 2000)) {
554 pr_err("%s: timeout waiting for USB_PORTSC1_PE\n", __func__);
555 goto restart;
556 }
557
558 /* Clear the PCI status, to avoid an interrupt taken upon resume */
559 val = readl(&hw->status);
560 val |= STS_PCD;
561 writel(val, &hw->status);
562
563 /* Put controller in suspend mode by writing 1 to SUSP bit of PORTSC */
564 val = readl(&hw->port_status[0]);
565 if ((val & PORT_POWER) && (val & PORT_PE)) {
566 val |= PORT_SUSPEND;
567 writel(val, &hw->port_status[0]);
568
569 /* Wait until port suspend completes */
570 if (handshake(ehci, &hw->port_status[0], PORT_SUSPEND,
571 PORT_SUSPEND, 1000)) {
572 pr_err("%s: timeout waiting for PORT_SUSPEND\n",
573 __func__);
574 goto restart;
575 }
576 }
577
578 tegra_ehci_phy_restore_end(tegra->phy);
579 goto done;
580
581 restart:
582 if (tegra->port_speed <= TEGRA_USB_PHY_PORT_SPEED_HIGH)
583 tegra_ehci_phy_restore_end(tegra->phy);
584
585 tegra_ehci_restart(hcd);
586
587 done:
588 tegra_usb_phy_preresume(tegra->phy);
589 tegra->port_resuming = 1;
590 return 0;
591}
592
593static int tegra_ehci_suspend(struct device *dev)
594{
595 struct tegra_ehci_hcd *tegra =
596 platform_get_drvdata(to_platform_device(dev));
597 struct usb_hcd *hcd = ehci_to_hcd(tegra->ehci);
598 int rc = 0;
599
600 /*
601 * When system sleep is supported and USB controller wakeup is
602 * implemented: If the controller is runtime-suspended and the
603 * wakeup setting needs to be changed, call pm_runtime_resume().
604 */
605 if (HCD_HW_ACCESSIBLE(hcd))
606 rc = controller_suspend(dev);
607 return rc;
608}
609
610static int tegra_ehci_resume(struct device *dev)
611{
612 int rc;
613
614 rc = controller_resume(dev);
615 if (rc == 0) {
616 pm_runtime_disable(dev);
617 pm_runtime_set_active(dev);
618 pm_runtime_enable(dev);
619 }
620 return rc;
621}
622
623static int tegra_ehci_runtime_suspend(struct device *dev)
624{
625 return controller_suspend(dev);
626}
627
628static int tegra_ehci_runtime_resume(struct device *dev)
629{
630 return controller_resume(dev);
631}
632
633static const struct dev_pm_ops tegra_ehci_pm_ops = {
634 .suspend = tegra_ehci_suspend,
635 .resume = tegra_ehci_resume,
636 .runtime_suspend = tegra_ehci_runtime_suspend,
637 .runtime_resume = tegra_ehci_runtime_resume,
638};
639
640#endif
641
609static u64 tegra_ehci_dma_mask = DMA_BIT_MASK(32); 642static u64 tegra_ehci_dma_mask = DMA_BIT_MASK(32);
610 643
611static int tegra_ehci_probe(struct platform_device *pdev) 644static int tegra_ehci_probe(struct platform_device *pdev)
@@ -720,7 +753,6 @@ static int tegra_ehci_probe(struct platform_device *pdev)
720 } 753 }
721 754
722 tegra->host_resumed = 1; 755 tegra->host_resumed = 1;
723 tegra->power_down_on_bus_suspend = pdata->power_down_on_bus_suspend;
724 tegra->ehci = hcd_to_ehci(hcd); 756 tegra->ehci = hcd_to_ehci(hcd);
725 757
726 irq = platform_get_irq(pdev, 0); 758 irq = platform_get_irq(pdev, 0);
@@ -729,7 +761,6 @@ static int tegra_ehci_probe(struct platform_device *pdev)
729 err = -ENODEV; 761 err = -ENODEV;
730 goto fail; 762 goto fail;
731 } 763 }
732 set_irq_flags(irq, IRQF_VALID);
733 764
734#ifdef CONFIG_USB_OTG_UTILS 765#ifdef CONFIG_USB_OTG_UTILS
735 if (pdata->operating_mode == TEGRA_USB_OTG) { 766 if (pdata->operating_mode == TEGRA_USB_OTG) {
@@ -745,6 +776,14 @@ static int tegra_ehci_probe(struct platform_device *pdev)
745 goto fail; 776 goto fail;
746 } 777 }
747 778
779 pm_runtime_set_active(&pdev->dev);
780 pm_runtime_get_noresume(&pdev->dev);
781
782 /* Don't skip the pm_runtime_forbid call if wakeup isn't working */
783 /* if (!pdata->power_down_on_bus_suspend) */
784 pm_runtime_forbid(&pdev->dev);
785 pm_runtime_enable(&pdev->dev);
786 pm_runtime_put_sync(&pdev->dev);
748 return err; 787 return err;
749 788
750fail: 789fail:
@@ -771,33 +810,6 @@ fail_hcd:
771 return err; 810 return err;
772} 811}
773 812
774#ifdef CONFIG_PM
775static int tegra_ehci_resume(struct platform_device *pdev)
776{
777 struct tegra_ehci_hcd *tegra = platform_get_drvdata(pdev);
778 struct usb_hcd *hcd = ehci_to_hcd(tegra->ehci);
779
780 if (tegra->bus_suspended)
781 return 0;
782
783 return tegra_usb_resume(hcd);
784}
785
786static int tegra_ehci_suspend(struct platform_device *pdev, pm_message_t state)
787{
788 struct tegra_ehci_hcd *tegra = platform_get_drvdata(pdev);
789 struct usb_hcd *hcd = ehci_to_hcd(tegra->ehci);
790
791 if (tegra->bus_suspended)
792 return 0;
793
794 if (time_before(jiffies, tegra->ehci->next_statechange))
795 msleep(10);
796
797 return tegra_usb_suspend(hcd);
798}
799#endif
800
801static int tegra_ehci_remove(struct platform_device *pdev) 813static int tegra_ehci_remove(struct platform_device *pdev)
802{ 814{
803 struct tegra_ehci_hcd *tegra = platform_get_drvdata(pdev); 815 struct tegra_ehci_hcd *tegra = platform_get_drvdata(pdev);
@@ -806,6 +818,10 @@ static int tegra_ehci_remove(struct platform_device *pdev)
806 if (tegra == NULL || hcd == NULL) 818 if (tegra == NULL || hcd == NULL)
807 return -EINVAL; 819 return -EINVAL;
808 820
821 pm_runtime_get_sync(&pdev->dev);
822 pm_runtime_disable(&pdev->dev);
823 pm_runtime_put_noidle(&pdev->dev);
824
809#ifdef CONFIG_USB_OTG_UTILS 825#ifdef CONFIG_USB_OTG_UTILS
810 if (tegra->transceiver) { 826 if (tegra->transceiver) {
811 otg_set_host(tegra->transceiver->otg, NULL); 827 otg_set_host(tegra->transceiver->otg, NULL);
@@ -846,13 +862,12 @@ static struct of_device_id tegra_ehci_of_match[] __devinitdata = {
846static struct platform_driver tegra_ehci_driver = { 862static struct platform_driver tegra_ehci_driver = {
847 .probe = tegra_ehci_probe, 863 .probe = tegra_ehci_probe,
848 .remove = tegra_ehci_remove, 864 .remove = tegra_ehci_remove,
849#ifdef CONFIG_PM
850 .suspend = tegra_ehci_suspend,
851 .resume = tegra_ehci_resume,
852#endif
853 .shutdown = tegra_ehci_hcd_shutdown, 865 .shutdown = tegra_ehci_hcd_shutdown,
854 .driver = { 866 .driver = {
855 .name = "tegra-ehci", 867 .name = "tegra-ehci",
856 .of_match_table = tegra_ehci_of_match, 868 .of_match_table = tegra_ehci_of_match,
869#ifdef CONFIG_PM
870 .pm = &tegra_ehci_pm_ops,
871#endif
857 } 872 }
858}; 873};
diff --git a/drivers/usb/host/ehci.h b/drivers/usb/host/ehci.h
index 8f9acbc96fde..2694ed6558d2 100644
--- a/drivers/usb/host/ehci.h
+++ b/drivers/usb/host/ehci.h
@@ -117,6 +117,8 @@ struct ehci_hcd { /* one per controller */
117 the change-suspend feature turned on */ 117 the change-suspend feature turned on */
118 unsigned long suspended_ports; /* which ports are 118 unsigned long suspended_ports; /* which ports are
119 suspended */ 119 suspended */
120 unsigned long resuming_ports; /* which ports have
121 started to resume */
120 122
121 /* per-HC memory pools (could be per-bus, but ...) */ 123 /* per-HC memory pools (could be per-bus, but ...) */
122 struct dma_pool *qh_pool; /* qh per active urb */ 124 struct dma_pool *qh_pool; /* qh per active urb */
diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
index db8963f5fbce..13ebeca8e73e 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -27,6 +27,10 @@
27#error "CONFIG_ARCH_AT91 must be defined." 27#error "CONFIG_ARCH_AT91 must be defined."
28#endif 28#endif
29 29
30#define valid_port(index) ((index) >= 0 && (index) < AT91_MAX_USBH_PORTS)
31#define at91_for_each_port(index) \
32 for ((index) = 0; (index) < AT91_MAX_USBH_PORTS; (index)++)
33
30/* interface and function clocks; sometimes also an AHB clock */ 34/* interface and function clocks; sometimes also an AHB clock */
31static struct clk *iclk, *fclk, *hclk; 35static struct clk *iclk, *fclk, *hclk;
32static int clocked; 36static int clocked;
@@ -90,7 +94,7 @@ static void at91_stop_hc(struct platform_device *pdev)
90 94
91/*-------------------------------------------------------------------------*/ 95/*-------------------------------------------------------------------------*/
92 96
93static void usb_hcd_at91_remove (struct usb_hcd *, struct platform_device *); 97static void __devexit usb_hcd_at91_remove (struct usb_hcd *, struct platform_device *);
94 98
95/* configure so an HC device and id are always provided */ 99/* configure so an HC device and id are always provided */
96/* always called with process context; sleeping is OK */ 100/* always called with process context; sleeping is OK */
@@ -104,7 +108,7 @@ static void usb_hcd_at91_remove (struct usb_hcd *, struct platform_device *);
104 * then invokes the start() method for the HCD associated with it 108 * then invokes the start() method for the HCD associated with it
105 * through the hotplug entry's driver_data. 109 * through the hotplug entry's driver_data.
106 */ 110 */
107static int usb_hcd_at91_probe(const struct hc_driver *driver, 111static int __devinit usb_hcd_at91_probe(const struct hc_driver *driver,
108 struct platform_device *pdev) 112 struct platform_device *pdev)
109{ 113{
110 int retval; 114 int retval;
@@ -199,7 +203,7 @@ static int usb_hcd_at91_probe(const struct hc_driver *driver,
199 * context, "rmmod" or something similar. 203 * context, "rmmod" or something similar.
200 * 204 *
201 */ 205 */
202static void usb_hcd_at91_remove(struct usb_hcd *hcd, 206static void __devexit usb_hcd_at91_remove(struct usb_hcd *hcd,
203 struct platform_device *pdev) 207 struct platform_device *pdev)
204{ 208{
205 usb_remove_hcd(hcd); 209 usb_remove_hcd(hcd);
@@ -240,26 +244,26 @@ ohci_at91_start (struct usb_hcd *hcd)
240 244
241static void ohci_at91_usb_set_power(struct at91_usbh_data *pdata, int port, int enable) 245static void ohci_at91_usb_set_power(struct at91_usbh_data *pdata, int port, int enable)
242{ 246{
243 if (port < 0 || port >= 2) 247 if (!valid_port(port))
244 return; 248 return;
245 249
246 if (!gpio_is_valid(pdata->vbus_pin[port])) 250 if (!gpio_is_valid(pdata->vbus_pin[port]))
247 return; 251 return;
248 252
249 gpio_set_value(pdata->vbus_pin[port], 253 gpio_set_value(pdata->vbus_pin[port],
250 !pdata->vbus_pin_active_low[port] ^ enable); 254 pdata->vbus_pin_active_low[port] ^ enable);
251} 255}
252 256
253static int ohci_at91_usb_get_power(struct at91_usbh_data *pdata, int port) 257static int ohci_at91_usb_get_power(struct at91_usbh_data *pdata, int port)
254{ 258{
255 if (port < 0 || port >= 2) 259 if (!valid_port(port))
256 return -EINVAL; 260 return -EINVAL;
257 261
258 if (!gpio_is_valid(pdata->vbus_pin[port])) 262 if (!gpio_is_valid(pdata->vbus_pin[port]))
259 return -EINVAL; 263 return -EINVAL;
260 264
261 return gpio_get_value(pdata->vbus_pin[port]) ^ 265 return gpio_get_value(pdata->vbus_pin[port]) ^
262 !pdata->vbus_pin_active_low[port]; 266 pdata->vbus_pin_active_low[port];
263} 267}
264 268
265/* 269/*
@@ -271,9 +275,9 @@ static int ohci_at91_hub_status_data(struct usb_hcd *hcd, char *buf)
271 int length = ohci_hub_status_data(hcd, buf); 275 int length = ohci_hub_status_data(hcd, buf);
272 int port; 276 int port;
273 277
274 for (port = 0; port < ARRAY_SIZE(pdata->overcurrent_pin); port++) { 278 at91_for_each_port(port) {
275 if (pdata->overcurrent_changed[port]) { 279 if (pdata->overcurrent_changed[port]) {
276 if (! length) 280 if (!length)
277 length = 1; 281 length = 1;
278 buf[0] |= 1 << (port + 1); 282 buf[0] |= 1 << (port + 1);
279 } 283 }
@@ -297,11 +301,17 @@ static int ohci_at91_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
297 "ohci_at91_hub_control(%p,0x%04x,0x%04x,0x%04x,%p,%04x)\n", 301 "ohci_at91_hub_control(%p,0x%04x,0x%04x,0x%04x,%p,%04x)\n",
298 hcd, typeReq, wValue, wIndex, buf, wLength); 302 hcd, typeReq, wValue, wIndex, buf, wLength);
299 303
304 wIndex--;
305
300 switch (typeReq) { 306 switch (typeReq) {
301 case SetPortFeature: 307 case SetPortFeature:
302 if (wValue == USB_PORT_FEAT_POWER) { 308 if (wValue == USB_PORT_FEAT_POWER) {
303 dev_dbg(hcd->self.controller, "SetPortFeat: POWER\n"); 309 dev_dbg(hcd->self.controller, "SetPortFeat: POWER\n");
304 ohci_at91_usb_set_power(pdata, wIndex - 1, 1); 310 if (valid_port(wIndex)) {
311 ohci_at91_usb_set_power(pdata, wIndex, 1);
312 ret = 0;
313 }
314
305 goto out; 315 goto out;
306 } 316 }
307 break; 317 break;
@@ -312,9 +322,9 @@ static int ohci_at91_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
312 dev_dbg(hcd->self.controller, 322 dev_dbg(hcd->self.controller,
313 "ClearPortFeature: C_OVER_CURRENT\n"); 323 "ClearPortFeature: C_OVER_CURRENT\n");
314 324
315 if (wIndex == 1 || wIndex == 2) { 325 if (valid_port(wIndex)) {
316 pdata->overcurrent_changed[wIndex-1] = 0; 326 pdata->overcurrent_changed[wIndex] = 0;
317 pdata->overcurrent_status[wIndex-1] = 0; 327 pdata->overcurrent_status[wIndex] = 0;
318 } 328 }
319 329
320 goto out; 330 goto out;
@@ -323,9 +333,8 @@ static int ohci_at91_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
323 dev_dbg(hcd->self.controller, 333 dev_dbg(hcd->self.controller,
324 "ClearPortFeature: OVER_CURRENT\n"); 334 "ClearPortFeature: OVER_CURRENT\n");
325 335
326 if (wIndex == 1 || wIndex == 2) { 336 if (valid_port(wIndex))
327 pdata->overcurrent_status[wIndex-1] = 0; 337 pdata->overcurrent_status[wIndex] = 0;
328 }
329 338
330 goto out; 339 goto out;
331 340
@@ -333,15 +342,15 @@ static int ohci_at91_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
333 dev_dbg(hcd->self.controller, 342 dev_dbg(hcd->self.controller,
334 "ClearPortFeature: POWER\n"); 343 "ClearPortFeature: POWER\n");
335 344
336 if (wIndex == 1 || wIndex == 2) { 345 if (valid_port(wIndex)) {
337 ohci_at91_usb_set_power(pdata, wIndex - 1, 0); 346 ohci_at91_usb_set_power(pdata, wIndex, 0);
338 return 0; 347 return 0;
339 } 348 }
340 } 349 }
341 break; 350 break;
342 } 351 }
343 352
344 ret = ohci_hub_control(hcd, typeReq, wValue, wIndex, buf, wLength); 353 ret = ohci_hub_control(hcd, typeReq, wValue, wIndex + 1, buf, wLength);
345 if (ret) 354 if (ret)
346 goto out; 355 goto out;
347 356
@@ -377,18 +386,15 @@ static int ohci_at91_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
377 386
378 dev_dbg(hcd->self.controller, "GetPortStatus(%d)\n", wIndex); 387 dev_dbg(hcd->self.controller, "GetPortStatus(%d)\n", wIndex);
379 388
380 if (wIndex == 1 || wIndex == 2) { 389 if (valid_port(wIndex)) {
381 if (! ohci_at91_usb_get_power(pdata, wIndex-1)) { 390 if (!ohci_at91_usb_get_power(pdata, wIndex))
382 *data &= ~cpu_to_le32(RH_PS_PPS); 391 *data &= ~cpu_to_le32(RH_PS_PPS);
383 }
384 392
385 if (pdata->overcurrent_changed[wIndex-1]) { 393 if (pdata->overcurrent_changed[wIndex])
386 *data |= cpu_to_le32(RH_PS_OCIC); 394 *data |= cpu_to_le32(RH_PS_OCIC);
387 }
388 395
389 if (pdata->overcurrent_status[wIndex-1]) { 396 if (pdata->overcurrent_status[wIndex])
390 *data |= cpu_to_le32(RH_PS_POCI); 397 *data |= cpu_to_le32(RH_PS_POCI);
391 }
392 } 398 }
393 } 399 }
394 400
@@ -450,14 +456,14 @@ static irqreturn_t ohci_hcd_at91_overcurrent_irq(int irq, void *data)
450 456
451 /* From the GPIO notifying the over-current situation, find 457 /* From the GPIO notifying the over-current situation, find
452 * out the corresponding port */ 458 * out the corresponding port */
453 for (port = 0; port < ARRAY_SIZE(pdata->overcurrent_pin); port++) { 459 at91_for_each_port(port) {
454 if (gpio_to_irq(pdata->overcurrent_pin[port]) == irq) { 460 if (gpio_to_irq(pdata->overcurrent_pin[port]) == irq) {
455 gpio = pdata->overcurrent_pin[port]; 461 gpio = pdata->overcurrent_pin[port];
456 break; 462 break;
457 } 463 }
458 } 464 }
459 465
460 if (port == ARRAY_SIZE(pdata->overcurrent_pin)) { 466 if (port == AT91_MAX_USBH_PORTS) {
461 dev_err(& pdev->dev, "overcurrent interrupt from unknown GPIO\n"); 467 dev_err(& pdev->dev, "overcurrent interrupt from unknown GPIO\n");
462 return IRQ_HANDLED; 468 return IRQ_HANDLED;
463 } 469 }
@@ -467,7 +473,7 @@ static irqreturn_t ohci_hcd_at91_overcurrent_irq(int irq, void *data)
467 /* When notified of an over-current situation, disable power 473 /* When notified of an over-current situation, disable power
468 on the corresponding port, and mark this port in 474 on the corresponding port, and mark this port in
469 over-current. */ 475 over-current. */
470 if (! val) { 476 if (!val) {
471 ohci_at91_usb_set_power(pdata, port, 0); 477 ohci_at91_usb_set_power(pdata, port, 0);
472 pdata->overcurrent_status[port] = 1; 478 pdata->overcurrent_status[port] = 1;
473 pdata->overcurrent_changed[port] = 1; 479 pdata->overcurrent_changed[port] = 1;
@@ -492,7 +498,7 @@ static u64 at91_ohci_dma_mask = DMA_BIT_MASK(32);
492static int __devinit ohci_at91_of_init(struct platform_device *pdev) 498static int __devinit ohci_at91_of_init(struct platform_device *pdev)
493{ 499{
494 struct device_node *np = pdev->dev.of_node; 500 struct device_node *np = pdev->dev.of_node;
495 int i, ret, gpio; 501 int i, gpio;
496 enum of_gpio_flags flags; 502 enum of_gpio_flags flags;
497 struct at91_usbh_data *pdata; 503 struct at91_usbh_data *pdata;
498 u32 ports; 504 u32 ports;
@@ -514,48 +520,17 @@ static int __devinit ohci_at91_of_init(struct platform_device *pdev)
514 if (!of_property_read_u32(np, "num-ports", &ports)) 520 if (!of_property_read_u32(np, "num-ports", &ports))
515 pdata->ports = ports; 521 pdata->ports = ports;
516 522
517 for (i = 0; i < 2; i++) { 523 at91_for_each_port(i) {
518 gpio = of_get_named_gpio_flags(np, "atmel,vbus-gpio", i, &flags); 524 gpio = of_get_named_gpio_flags(np, "atmel,vbus-gpio", i, &flags);
519 pdata->vbus_pin[i] = gpio; 525 pdata->vbus_pin[i] = gpio;
520 if (!gpio_is_valid(gpio)) 526 if (!gpio_is_valid(gpio))
521 continue; 527 continue;
522 pdata->vbus_pin_active_low[i] = flags & OF_GPIO_ACTIVE_LOW; 528 pdata->vbus_pin_active_low[i] = flags & OF_GPIO_ACTIVE_LOW;
523 ret = gpio_request(gpio, "ohci_vbus");
524 if (ret) {
525 dev_warn(&pdev->dev, "can't request vbus gpio %d", gpio);
526 continue;
527 }
528 ret = gpio_direction_output(gpio, !(flags & OF_GPIO_ACTIVE_LOW) ^ 1);
529 if (ret)
530 dev_warn(&pdev->dev, "can't put vbus gpio %d as output %d",
531 !(flags & OF_GPIO_ACTIVE_LOW) ^ 1, gpio);
532 } 529 }
533 530
534 for (i = 0; i < 2; i++) { 531 at91_for_each_port(i)
535 gpio = of_get_named_gpio_flags(np, "atmel,oc-gpio", i, &flags); 532 pdata->overcurrent_pin[i] =
536 pdata->overcurrent_pin[i] = gpio; 533 of_get_named_gpio_flags(np, "atmel,oc-gpio", i, &flags);
537 if (!gpio_is_valid(gpio))
538 continue;
539 ret = gpio_request(gpio, "ohci_overcurrent");
540 if (ret) {
541 dev_err(&pdev->dev, "can't request overcurrent gpio %d", gpio);
542 continue;
543 }
544
545 ret = gpio_direction_input(gpio);
546 if (ret) {
547 dev_err(&pdev->dev, "can't configure overcurrent gpio %d as input", gpio);
548 continue;
549 }
550
551 ret = request_irq(gpio_to_irq(gpio),
552 ohci_hcd_at91_overcurrent_irq,
553 IRQF_SHARED, "ohci_overcurrent", pdev);
554 if (ret) {
555 gpio_free(gpio);
556 dev_warn(& pdev->dev, "cannot get GPIO IRQ for overcurrent\n");
557 }
558 }
559 534
560 pdev->dev.platform_data = pdata; 535 pdev->dev.platform_data = pdata;
561 536
@@ -570,39 +545,73 @@ static int __devinit ohci_at91_of_init(struct platform_device *pdev)
570 545
571/*-------------------------------------------------------------------------*/ 546/*-------------------------------------------------------------------------*/
572 547
573static int ohci_hcd_at91_drv_probe(struct platform_device *pdev) 548static int __devinit ohci_hcd_at91_drv_probe(struct platform_device *pdev)
574{ 549{
575 struct at91_usbh_data *pdata; 550 struct at91_usbh_data *pdata;
576 int i; 551 int i;
552 int gpio;
553 int ret;
577 554
578 i = ohci_at91_of_init(pdev); 555 ret = ohci_at91_of_init(pdev);
579 556 if (ret)
580 if (i) 557 return ret;
581 return i;
582 558
583 pdata = pdev->dev.platform_data; 559 pdata = pdev->dev.platform_data;
584 560
585 if (pdata) { 561 if (pdata) {
586 for (i = 0; i < ARRAY_SIZE(pdata->vbus_pin); i++) { 562 at91_for_each_port(i) {
587 if (!gpio_is_valid(pdata->vbus_pin[i])) 563 if (!gpio_is_valid(pdata->vbus_pin[i]))
588 continue; 564 continue;
589 gpio_request(pdata->vbus_pin[i], "ohci_vbus"); 565 gpio = pdata->vbus_pin[i];
566
567 ret = gpio_request(gpio, "ohci_vbus");
568 if (ret) {
569 dev_err(&pdev->dev,
570 "can't request vbus gpio %d\n", gpio);
571 continue;
572 }
573 ret = gpio_direction_output(gpio,
574 !pdata->vbus_pin_active_low[i]);
575 if (ret) {
576 dev_err(&pdev->dev,
577 "can't put vbus gpio %d as output %d\n",
578 gpio, !pdata->vbus_pin_active_low[i]);
579 gpio_free(gpio);
580 continue;
581 }
582
590 ohci_at91_usb_set_power(pdata, i, 1); 583 ohci_at91_usb_set_power(pdata, i, 1);
591 } 584 }
592 585
593 for (i = 0; i < ARRAY_SIZE(pdata->overcurrent_pin); i++) { 586 at91_for_each_port(i) {
594 int ret;
595
596 if (!gpio_is_valid(pdata->overcurrent_pin[i])) 587 if (!gpio_is_valid(pdata->overcurrent_pin[i]))
597 continue; 588 continue;
598 gpio_request(pdata->overcurrent_pin[i], "ohci_overcurrent"); 589 gpio = pdata->overcurrent_pin[i];
590
591 ret = gpio_request(gpio, "ohci_overcurrent");
592 if (ret) {
593 dev_err(&pdev->dev,
594 "can't request overcurrent gpio %d\n",
595 gpio);
596 continue;
597 }
598
599 ret = gpio_direction_input(gpio);
600 if (ret) {
601 dev_err(&pdev->dev,
602 "can't configure overcurrent gpio %d as input\n",
603 gpio);
604 gpio_free(gpio);
605 continue;
606 }
599 607
600 ret = request_irq(gpio_to_irq(pdata->overcurrent_pin[i]), 608 ret = request_irq(gpio_to_irq(gpio),
601 ohci_hcd_at91_overcurrent_irq, 609 ohci_hcd_at91_overcurrent_irq,
602 IRQF_SHARED, "ohci_overcurrent", pdev); 610 IRQF_SHARED, "ohci_overcurrent", pdev);
603 if (ret) { 611 if (ret) {
604 gpio_free(pdata->overcurrent_pin[i]); 612 gpio_free(gpio);
605 dev_warn(& pdev->dev, "cannot get GPIO IRQ for overcurrent\n"); 613 dev_err(&pdev->dev,
614 "can't get gpio IRQ for overcurrent\n");
606 } 615 }
607 } 616 }
608 } 617 }
@@ -611,20 +620,20 @@ static int ohci_hcd_at91_drv_probe(struct platform_device *pdev)
611 return usb_hcd_at91_probe(&ohci_at91_hc_driver, pdev); 620 return usb_hcd_at91_probe(&ohci_at91_hc_driver, pdev);
612} 621}
613 622
614static int ohci_hcd_at91_drv_remove(struct platform_device *pdev) 623static int __devexit ohci_hcd_at91_drv_remove(struct platform_device *pdev)
615{ 624{
616 struct at91_usbh_data *pdata = pdev->dev.platform_data; 625 struct at91_usbh_data *pdata = pdev->dev.platform_data;
617 int i; 626 int i;
618 627
619 if (pdata) { 628 if (pdata) {
620 for (i = 0; i < ARRAY_SIZE(pdata->vbus_pin); i++) { 629 at91_for_each_port(i) {
621 if (!gpio_is_valid(pdata->vbus_pin[i])) 630 if (!gpio_is_valid(pdata->vbus_pin[i]))
622 continue; 631 continue;
623 ohci_at91_usb_set_power(pdata, i, 0); 632 ohci_at91_usb_set_power(pdata, i, 0);
624 gpio_free(pdata->vbus_pin[i]); 633 gpio_free(pdata->vbus_pin[i]);
625 } 634 }
626 635
627 for (i = 0; i < ARRAY_SIZE(pdata->overcurrent_pin); i++) { 636 at91_for_each_port(i) {
628 if (!gpio_is_valid(pdata->overcurrent_pin[i])) 637 if (!gpio_is_valid(pdata->overcurrent_pin[i]))
629 continue; 638 continue;
630 free_irq(gpio_to_irq(pdata->overcurrent_pin[i]), pdev); 639 free_irq(gpio_to_irq(pdata->overcurrent_pin[i]), pdev);
@@ -687,7 +696,7 @@ MODULE_ALIAS("platform:at91_ohci");
687 696
688static struct platform_driver ohci_hcd_at91_driver = { 697static struct platform_driver ohci_hcd_at91_driver = {
689 .probe = ohci_hcd_at91_drv_probe, 698 .probe = ohci_hcd_at91_drv_probe,
690 .remove = ohci_hcd_at91_drv_remove, 699 .remove = __devexit_p(ohci_hcd_at91_drv_remove),
691 .shutdown = usb_hcd_platform_shutdown, 700 .shutdown = usb_hcd_platform_shutdown,
692 .suspend = ohci_hcd_at91_drv_suspend, 701 .suspend = ohci_hcd_at91_drv_suspend,
693 .resume = ohci_hcd_at91_drv_resume, 702 .resume = ohci_hcd_at91_drv_resume,
diff --git a/drivers/usb/host/pci-quirks.c b/drivers/usb/host/pci-quirks.c
index 11de5f1be981..32dada8c8b4f 100644
--- a/drivers/usb/host/pci-quirks.c
+++ b/drivers/usb/host/pci-quirks.c
@@ -825,9 +825,13 @@ static void __devinit quirk_usb_handoff_xhci(struct pci_dev *pdev)
825 } 825 }
826 } 826 }
827 827
828 /* Disable any BIOS SMIs */ 828 val = readl(base + ext_cap_offset + XHCI_LEGACY_CONTROL_OFFSET);
829 writel(XHCI_LEGACY_DISABLE_SMI, 829 /* Mask off (turn off) any enabled SMIs */
830 base + ext_cap_offset + XHCI_LEGACY_CONTROL_OFFSET); 830 val &= XHCI_LEGACY_DISABLE_SMI;
831 /* Mask all SMI events bits, RW1C */
832 val |= XHCI_LEGACY_SMI_EVENTS;
833 /* Disable any BIOS SMIs and clear all SMI events*/
834 writel(val, base + ext_cap_offset + XHCI_LEGACY_CONTROL_OFFSET);
831 835
832 if (usb_is_intel_switchable_xhci(pdev)) 836 if (usb_is_intel_switchable_xhci(pdev))
833 usb_enable_xhci_ports(pdev); 837 usb_enable_xhci_ports(pdev);
diff --git a/drivers/usb/host/uhci-hub.c b/drivers/usb/host/uhci-hub.c
index 045cde4cbc3d..768d54295a20 100644
--- a/drivers/usb/host/uhci-hub.c
+++ b/drivers/usb/host/uhci-hub.c
@@ -196,11 +196,12 @@ static int uhci_hub_status_data(struct usb_hcd *hcd, char *buf)
196 status = get_hub_status_data(uhci, buf); 196 status = get_hub_status_data(uhci, buf);
197 197
198 switch (uhci->rh_state) { 198 switch (uhci->rh_state) {
199 case UHCI_RH_SUSPENDING:
200 case UHCI_RH_SUSPENDED: 199 case UHCI_RH_SUSPENDED:
201 /* if port change, ask to be resumed */ 200 /* if port change, ask to be resumed */
202 if (status || uhci->resuming_ports) 201 if (status || uhci->resuming_ports) {
202 status = 1;
203 usb_hcd_resume_root_hub(hcd); 203 usb_hcd_resume_root_hub(hcd);
204 }
204 break; 205 break;
205 206
206 case UHCI_RH_AUTO_STOPPED: 207 case UHCI_RH_AUTO_STOPPED:
diff --git a/drivers/usb/host/xhci-dbg.c b/drivers/usb/host/xhci-dbg.c
index e9b0f043455d..4b436f5a4171 100644
--- a/drivers/usb/host/xhci-dbg.c
+++ b/drivers/usb/host/xhci-dbg.c
@@ -119,7 +119,7 @@ static void xhci_print_command_reg(struct xhci_hcd *xhci)
119 xhci_dbg(xhci, " Event Interrupts %s\n", 119 xhci_dbg(xhci, " Event Interrupts %s\n",
120 (temp & CMD_EIE) ? "enabled " : "disabled"); 120 (temp & CMD_EIE) ? "enabled " : "disabled");
121 xhci_dbg(xhci, " Host System Error Interrupts %s\n", 121 xhci_dbg(xhci, " Host System Error Interrupts %s\n",
122 (temp & CMD_EIE) ? "enabled " : "disabled"); 122 (temp & CMD_HSEIE) ? "enabled " : "disabled");
123 xhci_dbg(xhci, " HC has %sfinished light reset\n", 123 xhci_dbg(xhci, " HC has %sfinished light reset\n",
124 (temp & CMD_LRESET) ? "not " : ""); 124 (temp & CMD_LRESET) ? "not " : "");
125} 125}
diff --git a/drivers/usb/host/xhci-ext-caps.h b/drivers/usb/host/xhci-ext-caps.h
index c7f33123d4c0..377f4242dabb 100644
--- a/drivers/usb/host/xhci-ext-caps.h
+++ b/drivers/usb/host/xhci-ext-caps.h
@@ -62,8 +62,9 @@
62/* USB Legacy Support Control and Status Register - section 7.1.2 */ 62/* USB Legacy Support Control and Status Register - section 7.1.2 */
63/* Add this offset, plus the value of xECP in HCCPARAMS to the base address */ 63/* Add this offset, plus the value of xECP in HCCPARAMS to the base address */
64#define XHCI_LEGACY_CONTROL_OFFSET (0x04) 64#define XHCI_LEGACY_CONTROL_OFFSET (0x04)
65/* bits 1:2, 5:12, and 17:19 need to be preserved; bits 21:28 should be zero */ 65/* bits 1:3, 5:12, and 17:19 need to be preserved; bits 21:28 should be zero */
66#define XHCI_LEGACY_DISABLE_SMI ((0x3 << 1) + (0xff << 5) + (0x7 << 17)) 66#define XHCI_LEGACY_DISABLE_SMI ((0x7 << 1) + (0xff << 5) + (0x7 << 17))
67#define XHCI_LEGACY_SMI_EVENTS (0x7 << 29)
67 68
68/* USB 2.0 xHCI 0.96 L1C capability - section 7.2.2.1.3.2 */ 69/* USB 2.0 xHCI 0.96 L1C capability - section 7.2.2.1.3.2 */
69#define XHCI_L1C (1 << 16) 70#define XHCI_L1C (1 << 16)
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index cae4c6f2845a..68eaa908ac8e 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -1796,11 +1796,6 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci)
1796 int i; 1796 int i;
1797 1797
1798 /* Free the Event Ring Segment Table and the actual Event Ring */ 1798 /* Free the Event Ring Segment Table and the actual Event Ring */
1799 if (xhci->ir_set) {
1800 xhci_writel(xhci, 0, &xhci->ir_set->erst_size);
1801 xhci_write_64(xhci, 0, &xhci->ir_set->erst_base);
1802 xhci_write_64(xhci, 0, &xhci->ir_set->erst_dequeue);
1803 }
1804 size = sizeof(struct xhci_erst_entry)*(xhci->erst.num_entries); 1799 size = sizeof(struct xhci_erst_entry)*(xhci->erst.num_entries);
1805 if (xhci->erst.entries) 1800 if (xhci->erst.entries)
1806 dma_free_coherent(&pdev->dev, size, 1801 dma_free_coherent(&pdev->dev, size,
@@ -1812,7 +1807,6 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci)
1812 xhci->event_ring = NULL; 1807 xhci->event_ring = NULL;
1813 xhci_dbg(xhci, "Freed event ring\n"); 1808 xhci_dbg(xhci, "Freed event ring\n");
1814 1809
1815 xhci_write_64(xhci, 0, &xhci->op_regs->cmd_ring);
1816 if (xhci->cmd_ring) 1810 if (xhci->cmd_ring)
1817 xhci_ring_free(xhci, xhci->cmd_ring); 1811 xhci_ring_free(xhci, xhci->cmd_ring);
1818 xhci->cmd_ring = NULL; 1812 xhci->cmd_ring = NULL;
@@ -1841,7 +1835,6 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci)
1841 xhci->medium_streams_pool = NULL; 1835 xhci->medium_streams_pool = NULL;
1842 xhci_dbg(xhci, "Freed medium stream array pool\n"); 1836 xhci_dbg(xhci, "Freed medium stream array pool\n");
1843 1837
1844 xhci_write_64(xhci, 0, &xhci->op_regs->dcbaa_ptr);
1845 if (xhci->dcbaa) 1838 if (xhci->dcbaa)
1846 dma_free_coherent(&pdev->dev, sizeof(*xhci->dcbaa), 1839 dma_free_coherent(&pdev->dev, sizeof(*xhci->dcbaa),
1847 xhci->dcbaa, xhci->dcbaa->dma); 1840 xhci->dcbaa, xhci->dcbaa->dma);
@@ -2459,6 +2452,8 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
2459 2452
2460fail: 2453fail:
2461 xhci_warn(xhci, "Couldn't initialize memory\n"); 2454 xhci_warn(xhci, "Couldn't initialize memory\n");
2455 xhci_halt(xhci);
2456 xhci_reset(xhci);
2462 xhci_mem_cleanup(xhci); 2457 xhci_mem_cleanup(xhci);
2463 return -ENOMEM; 2458 return -ENOMEM;
2464} 2459}
diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index ef98b38626fb..7a856a767e77 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -95,6 +95,8 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)
95 xhci->quirks |= XHCI_RESET_ON_RESUME; 95 xhci->quirks |= XHCI_RESET_ON_RESUME;
96 xhci_dbg(xhci, "QUIRK: Resetting on resume\n"); 96 xhci_dbg(xhci, "QUIRK: Resetting on resume\n");
97 } 97 }
98 if (pdev->vendor == PCI_VENDOR_ID_VIA)
99 xhci->quirks |= XHCI_RESET_ON_RESUME;
98} 100}
99 101
100/* called during probe() after chip reset completes */ 102/* called during probe() after chip reset completes */
@@ -326,7 +328,7 @@ int __init xhci_register_pci(void)
326 return pci_register_driver(&xhci_pci_driver); 328 return pci_register_driver(&xhci_pci_driver);
327} 329}
328 330
329void __exit xhci_unregister_pci(void) 331void xhci_unregister_pci(void)
330{ 332{
331 pci_unregister_driver(&xhci_pci_driver); 333 pci_unregister_driver(&xhci_pci_driver);
332} 334}
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 6bd9d53062eb..3d9422f16a20 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -2417,7 +2417,7 @@ hw_died:
2417 u32 irq_pending; 2417 u32 irq_pending;
2418 /* Acknowledge the PCI interrupt */ 2418 /* Acknowledge the PCI interrupt */
2419 irq_pending = xhci_readl(xhci, &xhci->ir_set->irq_pending); 2419 irq_pending = xhci_readl(xhci, &xhci->ir_set->irq_pending);
2420 irq_pending |= 0x3; 2420 irq_pending |= IMAN_IP;
2421 xhci_writel(xhci, irq_pending, &xhci->ir_set->irq_pending); 2421 xhci_writel(xhci, irq_pending, &xhci->ir_set->irq_pending);
2422 } 2422 }
2423 2423
@@ -2734,7 +2734,7 @@ int xhci_queue_intr_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2734 urb->dev->speed == USB_SPEED_FULL) 2734 urb->dev->speed == USB_SPEED_FULL)
2735 urb->interval /= 8; 2735 urb->interval /= 8;
2736 } 2736 }
2737 return xhci_queue_bulk_tx(xhci, GFP_ATOMIC, urb, slot_id, ep_index); 2737 return xhci_queue_bulk_tx(xhci, mem_flags, urb, slot_id, ep_index);
2738} 2738}
2739 2739
2740/* 2740/*
@@ -3514,7 +3514,7 @@ int xhci_queue_isoc_tx_prepare(struct xhci_hcd *xhci, gfp_t mem_flags,
3514 } 3514 }
3515 ep_ring->num_trbs_free_temp = ep_ring->num_trbs_free; 3515 ep_ring->num_trbs_free_temp = ep_ring->num_trbs_free;
3516 3516
3517 return xhci_queue_isoc_tx(xhci, GFP_ATOMIC, urb, slot_id, ep_index); 3517 return xhci_queue_isoc_tx(xhci, mem_flags, urb, slot_id, ep_index);
3518} 3518}
3519 3519
3520/**** Command Ring Operations ****/ 3520/**** Command Ring Operations ****/
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index e1963d4a430f..36641a7f2371 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -106,6 +106,9 @@ int xhci_halt(struct xhci_hcd *xhci)
106 STS_HALT, STS_HALT, XHCI_MAX_HALT_USEC); 106 STS_HALT, STS_HALT, XHCI_MAX_HALT_USEC);
107 if (!ret) 107 if (!ret)
108 xhci->xhc_state |= XHCI_STATE_HALTED; 108 xhci->xhc_state |= XHCI_STATE_HALTED;
109 else
110 xhci_warn(xhci, "Host not halted after %u microseconds.\n",
111 XHCI_MAX_HALT_USEC);
109 return ret; 112 return ret;
110} 113}
111 114
@@ -664,11 +667,11 @@ static void xhci_save_registers(struct xhci_hcd *xhci)
664 xhci->s3.dev_nt = xhci_readl(xhci, &xhci->op_regs->dev_notification); 667 xhci->s3.dev_nt = xhci_readl(xhci, &xhci->op_regs->dev_notification);
665 xhci->s3.dcbaa_ptr = xhci_read_64(xhci, &xhci->op_regs->dcbaa_ptr); 668 xhci->s3.dcbaa_ptr = xhci_read_64(xhci, &xhci->op_regs->dcbaa_ptr);
666 xhci->s3.config_reg = xhci_readl(xhci, &xhci->op_regs->config_reg); 669 xhci->s3.config_reg = xhci_readl(xhci, &xhci->op_regs->config_reg);
667 xhci->s3.irq_pending = xhci_readl(xhci, &xhci->ir_set->irq_pending);
668 xhci->s3.irq_control = xhci_readl(xhci, &xhci->ir_set->irq_control);
669 xhci->s3.erst_size = xhci_readl(xhci, &xhci->ir_set->erst_size); 670 xhci->s3.erst_size = xhci_readl(xhci, &xhci->ir_set->erst_size);
670 xhci->s3.erst_base = xhci_read_64(xhci, &xhci->ir_set->erst_base); 671 xhci->s3.erst_base = xhci_read_64(xhci, &xhci->ir_set->erst_base);
671 xhci->s3.erst_dequeue = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue); 672 xhci->s3.erst_dequeue = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue);
673 xhci->s3.irq_pending = xhci_readl(xhci, &xhci->ir_set->irq_pending);
674 xhci->s3.irq_control = xhci_readl(xhci, &xhci->ir_set->irq_control);
672} 675}
673 676
674static void xhci_restore_registers(struct xhci_hcd *xhci) 677static void xhci_restore_registers(struct xhci_hcd *xhci)
@@ -677,10 +680,11 @@ static void xhci_restore_registers(struct xhci_hcd *xhci)
677 xhci_writel(xhci, xhci->s3.dev_nt, &xhci->op_regs->dev_notification); 680 xhci_writel(xhci, xhci->s3.dev_nt, &xhci->op_regs->dev_notification);
678 xhci_write_64(xhci, xhci->s3.dcbaa_ptr, &xhci->op_regs->dcbaa_ptr); 681 xhci_write_64(xhci, xhci->s3.dcbaa_ptr, &xhci->op_regs->dcbaa_ptr);
679 xhci_writel(xhci, xhci->s3.config_reg, &xhci->op_regs->config_reg); 682 xhci_writel(xhci, xhci->s3.config_reg, &xhci->op_regs->config_reg);
680 xhci_writel(xhci, xhci->s3.irq_pending, &xhci->ir_set->irq_pending);
681 xhci_writel(xhci, xhci->s3.irq_control, &xhci->ir_set->irq_control);
682 xhci_writel(xhci, xhci->s3.erst_size, &xhci->ir_set->erst_size); 683 xhci_writel(xhci, xhci->s3.erst_size, &xhci->ir_set->erst_size);
683 xhci_write_64(xhci, xhci->s3.erst_base, &xhci->ir_set->erst_base); 684 xhci_write_64(xhci, xhci->s3.erst_base, &xhci->ir_set->erst_base);
685 xhci_write_64(xhci, xhci->s3.erst_dequeue, &xhci->ir_set->erst_dequeue);
686 xhci_writel(xhci, xhci->s3.irq_pending, &xhci->ir_set->irq_pending);
687 xhci_writel(xhci, xhci->s3.irq_control, &xhci->ir_set->irq_control);
684} 688}
685 689
686static void xhci_set_cmd_ring_deq(struct xhci_hcd *xhci) 690static void xhci_set_cmd_ring_deq(struct xhci_hcd *xhci)
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index 91074fdab3eb..3d69c4b2b542 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -205,6 +205,10 @@ struct xhci_op_regs {
205#define CMD_PM_INDEX (1 << 11) 205#define CMD_PM_INDEX (1 << 11)
206/* bits 12:31 are reserved (and should be preserved on writes). */ 206/* bits 12:31 are reserved (and should be preserved on writes). */
207 207
208/* IMAN - Interrupt Management Register */
209#define IMAN_IP (1 << 1)
210#define IMAN_IE (1 << 0)
211
208/* USBSTS - USB status - status bitmasks */ 212/* USBSTS - USB status - status bitmasks */
209/* HC not running - set to 1 when run/stop bit is cleared. */ 213/* HC not running - set to 1 when run/stop bit is cleared. */
210#define STS_HALT XHCI_STS_HALT 214#define STS_HALT XHCI_STS_HALT
diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c
index 959145baf3cf..9dcb68f04f03 100644
--- a/drivers/usb/misc/usbtest.c
+++ b/drivers/usb/misc/usbtest.c
@@ -423,7 +423,7 @@ alloc_sglist(int nents, int max, int vary)
423 unsigned i; 423 unsigned i;
424 unsigned size = max; 424 unsigned size = max;
425 425
426 sg = kmalloc(nents * sizeof *sg, GFP_KERNEL); 426 sg = kmalloc_array(nents, sizeof *sg, GFP_KERNEL);
427 if (!sg) 427 if (!sg)
428 return NULL; 428 return NULL;
429 sg_init_table(sg, nents); 429 sg_init_table(sg, nents);
@@ -904,6 +904,9 @@ test_ctrl_queue(struct usbtest_dev *dev, struct usbtest_param *param)
904 struct ctrl_ctx context; 904 struct ctrl_ctx context;
905 int i; 905 int i;
906 906
907 if (param->sglen == 0 || param->iterations > UINT_MAX / param->sglen)
908 return -EOPNOTSUPP;
909
907 spin_lock_init(&context.lock); 910 spin_lock_init(&context.lock);
908 context.dev = dev; 911 context.dev = dev;
909 init_completion(&context.complete); 912 init_completion(&context.complete);
@@ -1981,8 +1984,6 @@ usbtest_ioctl(struct usb_interface *intf, unsigned int code, void *buf)
1981 1984
1982 /* queued control messaging */ 1985 /* queued control messaging */
1983 case 10: 1986 case 10:
1984 if (param->sglen == 0)
1985 break;
1986 retval = 0; 1987 retval = 0;
1987 dev_info(&intf->dev, 1988 dev_info(&intf->dev,
1988 "TEST 10: queue %d control calls, %d times\n", 1989 "TEST 10: queue %d control calls, %d times\n",
@@ -2276,6 +2277,8 @@ usbtest_probe(struct usb_interface *intf, const struct usb_device_id *id)
2276 if (status < 0) { 2277 if (status < 0) {
2277 WARNING(dev, "couldn't get endpoints, %d\n", 2278 WARNING(dev, "couldn't get endpoints, %d\n",
2278 status); 2279 status);
2280 kfree(dev->buf);
2281 kfree(dev);
2279 return status; 2282 return status;
2280 } 2283 }
2281 /* may find bulk or ISO pipes */ 2284 /* may find bulk or ISO pipes */
diff --git a/drivers/usb/misc/yurex.c b/drivers/usb/misc/yurex.c
index 897edda42270..70201462e19c 100644
--- a/drivers/usb/misc/yurex.c
+++ b/drivers/usb/misc/yurex.c
@@ -99,9 +99,7 @@ static void yurex_delete(struct kref *kref)
99 usb_put_dev(dev->udev); 99 usb_put_dev(dev->udev);
100 if (dev->cntl_urb) { 100 if (dev->cntl_urb) {
101 usb_kill_urb(dev->cntl_urb); 101 usb_kill_urb(dev->cntl_urb);
102 if (dev->cntl_req) 102 kfree(dev->cntl_req);
103 usb_free_coherent(dev->udev, YUREX_BUF_SIZE,
104 dev->cntl_req, dev->cntl_urb->setup_dma);
105 if (dev->cntl_buffer) 103 if (dev->cntl_buffer)
106 usb_free_coherent(dev->udev, YUREX_BUF_SIZE, 104 usb_free_coherent(dev->udev, YUREX_BUF_SIZE,
107 dev->cntl_buffer, dev->cntl_urb->transfer_dma); 105 dev->cntl_buffer, dev->cntl_urb->transfer_dma);
@@ -234,9 +232,7 @@ static int yurex_probe(struct usb_interface *interface, const struct usb_device_
234 } 232 }
235 233
236 /* allocate buffer for control req */ 234 /* allocate buffer for control req */
237 dev->cntl_req = usb_alloc_coherent(dev->udev, YUREX_BUF_SIZE, 235 dev->cntl_req = kmalloc(YUREX_BUF_SIZE, GFP_KERNEL);
238 GFP_KERNEL,
239 &dev->cntl_urb->setup_dma);
240 if (!dev->cntl_req) { 236 if (!dev->cntl_req) {
241 err("Could not allocate cntl_req"); 237 err("Could not allocate cntl_req");
242 goto error; 238 goto error;
@@ -286,7 +282,7 @@ static int yurex_probe(struct usb_interface *interface, const struct usb_device_
286 usb_rcvintpipe(dev->udev, dev->int_in_endpointAddr), 282 usb_rcvintpipe(dev->udev, dev->int_in_endpointAddr),
287 dev->int_buffer, YUREX_BUF_SIZE, yurex_interrupt, 283 dev->int_buffer, YUREX_BUF_SIZE, yurex_interrupt,
288 dev, 1); 284 dev, 1);
289 dev->cntl_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 285 dev->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
290 if (usb_submit_urb(dev->urb, GFP_KERNEL)) { 286 if (usb_submit_urb(dev->urb, GFP_KERNEL)) {
291 retval = -EIO; 287 retval = -EIO;
292 err("Could not submitting URB"); 288 err("Could not submitting URB");
diff --git a/drivers/usb/musb/davinci.c b/drivers/usb/musb/davinci.c
index 97ab975fa442..768b4b55c816 100644
--- a/drivers/usb/musb/davinci.c
+++ b/drivers/usb/musb/davinci.c
@@ -386,7 +386,7 @@ static int davinci_musb_init(struct musb *musb)
386 usb_nop_xceiv_register(); 386 usb_nop_xceiv_register();
387 musb->xceiv = usb_get_transceiver(); 387 musb->xceiv = usb_get_transceiver();
388 if (!musb->xceiv) 388 if (!musb->xceiv)
389 return -ENODEV; 389 goto unregister;
390 390
391 musb->mregs += DAVINCI_BASE_OFFSET; 391 musb->mregs += DAVINCI_BASE_OFFSET;
392 392
@@ -444,6 +444,7 @@ static int davinci_musb_init(struct musb *musb)
444 444
445fail: 445fail:
446 usb_put_transceiver(musb->xceiv); 446 usb_put_transceiver(musb->xceiv);
447unregister:
447 usb_nop_xceiv_unregister(); 448 usb_nop_xceiv_unregister();
448 return -ENODEV; 449 return -ENODEV;
449} 450}
diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 0f8b82918a40..66aaccf04490 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -137,6 +137,9 @@ static int musb_ulpi_read(struct usb_phy *phy, u32 offset)
137 int i = 0; 137 int i = 0;
138 u8 r; 138 u8 r;
139 u8 power; 139 u8 power;
140 int ret;
141
142 pm_runtime_get_sync(phy->io_dev);
140 143
141 /* Make sure the transceiver is not in low power mode */ 144 /* Make sure the transceiver is not in low power mode */
142 power = musb_readb(addr, MUSB_POWER); 145 power = musb_readb(addr, MUSB_POWER);
@@ -154,15 +157,22 @@ static int musb_ulpi_read(struct usb_phy *phy, u32 offset)
154 while (!(musb_readb(addr, MUSB_ULPI_REG_CONTROL) 157 while (!(musb_readb(addr, MUSB_ULPI_REG_CONTROL)
155 & MUSB_ULPI_REG_CMPLT)) { 158 & MUSB_ULPI_REG_CMPLT)) {
156 i++; 159 i++;
157 if (i == 10000) 160 if (i == 10000) {
158 return -ETIMEDOUT; 161 ret = -ETIMEDOUT;
162 goto out;
163 }
159 164
160 } 165 }
161 r = musb_readb(addr, MUSB_ULPI_REG_CONTROL); 166 r = musb_readb(addr, MUSB_ULPI_REG_CONTROL);
162 r &= ~MUSB_ULPI_REG_CMPLT; 167 r &= ~MUSB_ULPI_REG_CMPLT;
163 musb_writeb(addr, MUSB_ULPI_REG_CONTROL, r); 168 musb_writeb(addr, MUSB_ULPI_REG_CONTROL, r);
164 169
165 return musb_readb(addr, MUSB_ULPI_REG_DATA); 170 ret = musb_readb(addr, MUSB_ULPI_REG_DATA);
171
172out:
173 pm_runtime_put(phy->io_dev);
174
175 return ret;
166} 176}
167 177
168static int musb_ulpi_write(struct usb_phy *phy, u32 offset, u32 data) 178static int musb_ulpi_write(struct usb_phy *phy, u32 offset, u32 data)
@@ -171,6 +181,9 @@ static int musb_ulpi_write(struct usb_phy *phy, u32 offset, u32 data)
171 int i = 0; 181 int i = 0;
172 u8 r = 0; 182 u8 r = 0;
173 u8 power; 183 u8 power;
184 int ret = 0;
185
186 pm_runtime_get_sync(phy->io_dev);
174 187
175 /* Make sure the transceiver is not in low power mode */ 188 /* Make sure the transceiver is not in low power mode */
176 power = musb_readb(addr, MUSB_POWER); 189 power = musb_readb(addr, MUSB_POWER);
@@ -184,15 +197,20 @@ static int musb_ulpi_write(struct usb_phy *phy, u32 offset, u32 data)
184 while (!(musb_readb(addr, MUSB_ULPI_REG_CONTROL) 197 while (!(musb_readb(addr, MUSB_ULPI_REG_CONTROL)
185 & MUSB_ULPI_REG_CMPLT)) { 198 & MUSB_ULPI_REG_CMPLT)) {
186 i++; 199 i++;
187 if (i == 10000) 200 if (i == 10000) {
188 return -ETIMEDOUT; 201 ret = -ETIMEDOUT;
202 goto out;
203 }
189 } 204 }
190 205
191 r = musb_readb(addr, MUSB_ULPI_REG_CONTROL); 206 r = musb_readb(addr, MUSB_ULPI_REG_CONTROL);
192 r &= ~MUSB_ULPI_REG_CMPLT; 207 r &= ~MUSB_ULPI_REG_CMPLT;
193 musb_writeb(addr, MUSB_ULPI_REG_CONTROL, r); 208 musb_writeb(addr, MUSB_ULPI_REG_CONTROL, r);
194 209
195 return 0; 210out:
211 pm_runtime_put(phy->io_dev);
212
213 return ret;
196} 214}
197#else 215#else
198#define musb_ulpi_read NULL 216#define musb_ulpi_read NULL
@@ -1904,14 +1922,17 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
1904 1922
1905 if (!musb->isr) { 1923 if (!musb->isr) {
1906 status = -ENODEV; 1924 status = -ENODEV;
1907 goto fail3; 1925 goto fail2;
1908 } 1926 }
1909 1927
1910 if (!musb->xceiv->io_ops) { 1928 if (!musb->xceiv->io_ops) {
1929 musb->xceiv->io_dev = musb->controller;
1911 musb->xceiv->io_priv = musb->mregs; 1930 musb->xceiv->io_priv = musb->mregs;
1912 musb->xceiv->io_ops = &musb_ulpi_access; 1931 musb->xceiv->io_ops = &musb_ulpi_access;
1913 } 1932 }
1914 1933
1934 pm_runtime_get_sync(musb->controller);
1935
1915#ifndef CONFIG_MUSB_PIO_ONLY 1936#ifndef CONFIG_MUSB_PIO_ONLY
1916 if (use_dma && dev->dma_mask) { 1937 if (use_dma && dev->dma_mask) {
1917 struct dma_controller *c; 1938 struct dma_controller *c;
@@ -2023,6 +2044,8 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
2023 goto fail5; 2044 goto fail5;
2024#endif 2045#endif
2025 2046
2047 pm_runtime_put(musb->controller);
2048
2026 dev_info(dev, "USB %s mode controller at %p using %s, IRQ %d\n", 2049 dev_info(dev, "USB %s mode controller at %p using %s, IRQ %d\n",
2027 ({char *s; 2050 ({char *s;
2028 switch (musb->board_mode) { 2051 switch (musb->board_mode) {
@@ -2047,6 +2070,9 @@ fail4:
2047 musb_gadget_cleanup(musb); 2070 musb_gadget_cleanup(musb);
2048 2071
2049fail3: 2072fail3:
2073 pm_runtime_put_sync(musb->controller);
2074
2075fail2:
2050 if (musb->irq_wake) 2076 if (musb->irq_wake)
2051 device_init_wakeup(dev, 0); 2077 device_init_wakeup(dev, 0);
2052 musb_platform_exit(musb); 2078 musb_platform_exit(musb);
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index 93de517a32a0..f4a40f001c88 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -449,7 +449,7 @@ struct musb {
449 * We added this flag to forcefully disable double 449 * We added this flag to forcefully disable double
450 * buffering until we get it working. 450 * buffering until we get it working.
451 */ 451 */
452 unsigned double_buffer_not_ok:1 __deprecated; 452 unsigned double_buffer_not_ok:1;
453 453
454 struct musb_hdrc_config *config; 454 struct musb_hdrc_config *config;
455 455
diff --git a/drivers/usb/musb/musb_host.c b/drivers/usb/musb/musb_host.c
index 79cb0af779fa..ef8d744800ac 100644
--- a/drivers/usb/musb/musb_host.c
+++ b/drivers/usb/musb/musb_host.c
@@ -2098,7 +2098,7 @@ static int musb_cleanup_urb(struct urb *urb, struct musb_qh *qh)
2098 } 2098 }
2099 2099
2100 /* turn off DMA requests, discard state, stop polling ... */ 2100 /* turn off DMA requests, discard state, stop polling ... */
2101 if (is_in) { 2101 if (ep->epnum && is_in) {
2102 /* giveback saves bulk toggle */ 2102 /* giveback saves bulk toggle */
2103 csr = musb_h_flush_rxfifo(ep, 0); 2103 csr = musb_h_flush_rxfifo(ep, 0);
2104 2104
diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c
index 2ae0bb309994..c7785e81254c 100644
--- a/drivers/usb/musb/omap2430.c
+++ b/drivers/usb/musb/omap2430.c
@@ -282,7 +282,8 @@ static void musb_otg_notifier_work(struct work_struct *data_notifier_work)
282 282
283static int omap2430_musb_init(struct musb *musb) 283static int omap2430_musb_init(struct musb *musb)
284{ 284{
285 u32 l, status = 0; 285 u32 l;
286 int status = 0;
286 struct device *dev = musb->controller; 287 struct device *dev = musb->controller;
287 struct musb_hdrc_platform_data *plat = dev->platform_data; 288 struct musb_hdrc_platform_data *plat = dev->platform_data;
288 struct omap_musb_board_data *data = plat->board_data; 289 struct omap_musb_board_data *data = plat->board_data;
@@ -301,7 +302,7 @@ static int omap2430_musb_init(struct musb *musb)
301 302
302 status = pm_runtime_get_sync(dev); 303 status = pm_runtime_get_sync(dev);
303 if (status < 0) { 304 if (status < 0) {
304 dev_err(dev, "pm_runtime_get_sync FAILED"); 305 dev_err(dev, "pm_runtime_get_sync FAILED %d\n", status);
305 goto err1; 306 goto err1;
306 } 307 }
307 308
@@ -333,6 +334,7 @@ static int omap2430_musb_init(struct musb *musb)
333 334
334 setup_timer(&musb_idle_timer, musb_do_idle, (unsigned long) musb); 335 setup_timer(&musb_idle_timer, musb_do_idle, (unsigned long) musb);
335 336
337 pm_runtime_put_noidle(musb->controller);
336 return 0; 338 return 0;
337 339
338err1: 340err1:
@@ -452,14 +454,14 @@ static int __devinit omap2430_probe(struct platform_device *pdev)
452 goto err2; 454 goto err2;
453 } 455 }
454 456
457 pm_runtime_enable(&pdev->dev);
458
455 ret = platform_device_add(musb); 459 ret = platform_device_add(musb);
456 if (ret) { 460 if (ret) {
457 dev_err(&pdev->dev, "failed to register musb device\n"); 461 dev_err(&pdev->dev, "failed to register musb device\n");
458 goto err2; 462 goto err2;
459 } 463 }
460 464
461 pm_runtime_enable(&pdev->dev);
462
463 return 0; 465 return 0;
464 466
465err2: 467err2:
@@ -478,7 +480,6 @@ static int __devexit omap2430_remove(struct platform_device *pdev)
478 480
479 platform_device_del(glue->musb); 481 platform_device_del(glue->musb);
480 platform_device_put(glue->musb); 482 platform_device_put(glue->musb);
481 pm_runtime_put(&pdev->dev);
482 kfree(glue); 483 kfree(glue);
483 484
484 return 0; 485 return 0;
@@ -491,11 +492,13 @@ static int omap2430_runtime_suspend(struct device *dev)
491 struct omap2430_glue *glue = dev_get_drvdata(dev); 492 struct omap2430_glue *glue = dev_get_drvdata(dev);
492 struct musb *musb = glue_to_musb(glue); 493 struct musb *musb = glue_to_musb(glue);
493 494
494 musb->context.otg_interfsel = musb_readl(musb->mregs, 495 if (musb) {
495 OTG_INTERFSEL); 496 musb->context.otg_interfsel = musb_readl(musb->mregs,
497 OTG_INTERFSEL);
496 498
497 omap2430_low_level_exit(musb); 499 omap2430_low_level_exit(musb);
498 usb_phy_set_suspend(musb->xceiv, 1); 500 usb_phy_set_suspend(musb->xceiv, 1);
501 }
499 502
500 return 0; 503 return 0;
501} 504}
@@ -505,11 +508,13 @@ static int omap2430_runtime_resume(struct device *dev)
505 struct omap2430_glue *glue = dev_get_drvdata(dev); 508 struct omap2430_glue *glue = dev_get_drvdata(dev);
506 struct musb *musb = glue_to_musb(glue); 509 struct musb *musb = glue_to_musb(glue);
507 510
508 omap2430_low_level_init(musb); 511 if (musb) {
509 musb_writel(musb->mregs, OTG_INTERFSEL, 512 omap2430_low_level_init(musb);
510 musb->context.otg_interfsel); 513 musb_writel(musb->mregs, OTG_INTERFSEL,
514 musb->context.otg_interfsel);
511 515
512 usb_phy_set_suspend(musb->xceiv, 0); 516 usb_phy_set_suspend(musb->xceiv, 0);
517 }
513 518
514 return 0; 519 return 0;
515} 520}
diff --git a/drivers/usb/otg/gpio_vbus.c b/drivers/usb/otg/gpio_vbus.c
index 3ece43a2e4c1..a0a2178974fe 100644
--- a/drivers/usb/otg/gpio_vbus.c
+++ b/drivers/usb/otg/gpio_vbus.c
@@ -96,7 +96,7 @@ static void gpio_vbus_work(struct work_struct *work)
96 struct gpio_vbus_data *gpio_vbus = 96 struct gpio_vbus_data *gpio_vbus =
97 container_of(work, struct gpio_vbus_data, work); 97 container_of(work, struct gpio_vbus_data, work);
98 struct gpio_vbus_mach_info *pdata = gpio_vbus->dev->platform_data; 98 struct gpio_vbus_mach_info *pdata = gpio_vbus->dev->platform_data;
99 int gpio; 99 int gpio, status;
100 100
101 if (!gpio_vbus->phy.otg->gadget) 101 if (!gpio_vbus->phy.otg->gadget)
102 return; 102 return;
@@ -108,7 +108,9 @@ static void gpio_vbus_work(struct work_struct *work)
108 */ 108 */
109 gpio = pdata->gpio_pullup; 109 gpio = pdata->gpio_pullup;
110 if (is_vbus_powered(pdata)) { 110 if (is_vbus_powered(pdata)) {
111 status = USB_EVENT_VBUS;
111 gpio_vbus->phy.state = OTG_STATE_B_PERIPHERAL; 112 gpio_vbus->phy.state = OTG_STATE_B_PERIPHERAL;
113 gpio_vbus->phy.last_event = status;
112 usb_gadget_vbus_connect(gpio_vbus->phy.otg->gadget); 114 usb_gadget_vbus_connect(gpio_vbus->phy.otg->gadget);
113 115
114 /* drawing a "unit load" is *always* OK, except for OTG */ 116 /* drawing a "unit load" is *always* OK, except for OTG */
@@ -117,6 +119,9 @@ static void gpio_vbus_work(struct work_struct *work)
117 /* optionally enable D+ pullup */ 119 /* optionally enable D+ pullup */
118 if (gpio_is_valid(gpio)) 120 if (gpio_is_valid(gpio))
119 gpio_set_value(gpio, !pdata->gpio_pullup_inverted); 121 gpio_set_value(gpio, !pdata->gpio_pullup_inverted);
122
123 atomic_notifier_call_chain(&gpio_vbus->phy.notifier,
124 status, gpio_vbus->phy.otg->gadget);
120 } else { 125 } else {
121 /* optionally disable D+ pullup */ 126 /* optionally disable D+ pullup */
122 if (gpio_is_valid(gpio)) 127 if (gpio_is_valid(gpio))
@@ -125,7 +130,12 @@ static void gpio_vbus_work(struct work_struct *work)
125 set_vbus_draw(gpio_vbus, 0); 130 set_vbus_draw(gpio_vbus, 0);
126 131
127 usb_gadget_vbus_disconnect(gpio_vbus->phy.otg->gadget); 132 usb_gadget_vbus_disconnect(gpio_vbus->phy.otg->gadget);
133 status = USB_EVENT_NONE;
128 gpio_vbus->phy.state = OTG_STATE_B_IDLE; 134 gpio_vbus->phy.state = OTG_STATE_B_IDLE;
135 gpio_vbus->phy.last_event = status;
136
137 atomic_notifier_call_chain(&gpio_vbus->phy.notifier,
138 status, gpio_vbus->phy.otg->gadget);
129 } 139 }
130} 140}
131 141
@@ -287,6 +297,9 @@ static int __init gpio_vbus_probe(struct platform_device *pdev)
287 irq, err); 297 irq, err);
288 goto err_irq; 298 goto err_irq;
289 } 299 }
300
301 ATOMIC_INIT_NOTIFIER_HEAD(&gpio_vbus->phy.notifier);
302
290 INIT_WORK(&gpio_vbus->work, gpio_vbus_work); 303 INIT_WORK(&gpio_vbus->work, gpio_vbus_work);
291 304
292 gpio_vbus->vbus_draw = regulator_get(&pdev->dev, "vbus_draw"); 305 gpio_vbus->vbus_draw = regulator_get(&pdev->dev, "vbus_draw");
diff --git a/drivers/usb/serial/bus.c b/drivers/usb/serial/bus.c
index 7f547dc3a590..ed8adb052ca7 100644
--- a/drivers/usb/serial/bus.c
+++ b/drivers/usb/serial/bus.c
@@ -60,8 +60,6 @@ static int usb_serial_device_probe(struct device *dev)
60 retval = -ENODEV; 60 retval = -ENODEV;
61 goto exit; 61 goto exit;
62 } 62 }
63 if (port->dev_state != PORT_REGISTERING)
64 goto exit;
65 63
66 driver = port->serial->type; 64 driver = port->serial->type;
67 if (driver->port_probe) { 65 if (driver->port_probe) {
@@ -98,9 +96,6 @@ static int usb_serial_device_remove(struct device *dev)
98 if (!port) 96 if (!port)
99 return -ENODEV; 97 return -ENODEV;
100 98
101 if (port->dev_state != PORT_UNREGISTERING)
102 return retval;
103
104 device_remove_file(&port->dev, &dev_attr_port_number); 99 device_remove_file(&port->dev, &dev_attr_port_number);
105 100
106 driver = port->serial->type; 101 driver = port->serial->type;
diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
index 0310e2df59f5..ec30f95ef399 100644
--- a/drivers/usb/serial/cp210x.c
+++ b/drivers/usb/serial/cp210x.c
@@ -287,7 +287,8 @@ static int cp210x_get_config(struct usb_serial_port *port, u8 request,
287 /* Issue the request, attempting to read 'size' bytes */ 287 /* Issue the request, attempting to read 'size' bytes */
288 result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), 288 result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
289 request, REQTYPE_DEVICE_TO_HOST, 0x0000, 289 request, REQTYPE_DEVICE_TO_HOST, 0x0000,
290 port_priv->bInterfaceNumber, buf, size, 300); 290 port_priv->bInterfaceNumber, buf, size,
291 USB_CTRL_GET_TIMEOUT);
291 292
292 /* Convert data into an array of integers */ 293 /* Convert data into an array of integers */
293 for (i = 0; i < length; i++) 294 for (i = 0; i < length; i++)
@@ -340,12 +341,14 @@ static int cp210x_set_config(struct usb_serial_port *port, u8 request,
340 result = usb_control_msg(serial->dev, 341 result = usb_control_msg(serial->dev,
341 usb_sndctrlpipe(serial->dev, 0), 342 usb_sndctrlpipe(serial->dev, 0),
342 request, REQTYPE_HOST_TO_DEVICE, 0x0000, 343 request, REQTYPE_HOST_TO_DEVICE, 0x0000,
343 port_priv->bInterfaceNumber, buf, size, 300); 344 port_priv->bInterfaceNumber, buf, size,
345 USB_CTRL_SET_TIMEOUT);
344 } else { 346 } else {
345 result = usb_control_msg(serial->dev, 347 result = usb_control_msg(serial->dev,
346 usb_sndctrlpipe(serial->dev, 0), 348 usb_sndctrlpipe(serial->dev, 0),
347 request, REQTYPE_HOST_TO_DEVICE, data[0], 349 request, REQTYPE_HOST_TO_DEVICE, data[0],
348 port_priv->bInterfaceNumber, NULL, 0, 300); 350 port_priv->bInterfaceNumber, NULL, 0,
351 USB_CTRL_SET_TIMEOUT);
349 } 352 }
350 353
351 kfree(buf); 354 kfree(buf);
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index ff8605b4b4be..02e7f2d32d52 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -75,7 +75,8 @@ struct ftdi_private {
75 unsigned long last_dtr_rts; /* saved modem control outputs */ 75 unsigned long last_dtr_rts; /* saved modem control outputs */
76 struct async_icount icount; 76 struct async_icount icount;
77 wait_queue_head_t delta_msr_wait; /* Used for TIOCMIWAIT */ 77 wait_queue_head_t delta_msr_wait; /* Used for TIOCMIWAIT */
78 char prev_status, diff_status; /* Used for TIOCMIWAIT */ 78 char prev_status; /* Used for TIOCMIWAIT */
79 bool dev_gone; /* Used to abort TIOCMIWAIT */
79 char transmit_empty; /* If transmitter is empty or not */ 80 char transmit_empty; /* If transmitter is empty or not */
80 struct usb_serial_port *port; 81 struct usb_serial_port *port;
81 __u16 interface; /* FT2232C, FT2232H or FT4232H port interface 82 __u16 interface; /* FT2232C, FT2232H or FT4232H port interface
@@ -1681,6 +1682,7 @@ static int ftdi_sio_port_probe(struct usb_serial_port *port)
1681 init_waitqueue_head(&priv->delta_msr_wait); 1682 init_waitqueue_head(&priv->delta_msr_wait);
1682 1683
1683 priv->flags = ASYNC_LOW_LATENCY; 1684 priv->flags = ASYNC_LOW_LATENCY;
1685 priv->dev_gone = false;
1684 1686
1685 if (quirk && quirk->port_probe) 1687 if (quirk && quirk->port_probe)
1686 quirk->port_probe(priv); 1688 quirk->port_probe(priv);
@@ -1839,6 +1841,9 @@ static int ftdi_sio_port_remove(struct usb_serial_port *port)
1839 1841
1840 dbg("%s", __func__); 1842 dbg("%s", __func__);
1841 1843
1844 priv->dev_gone = true;
1845 wake_up_interruptible_all(&priv->delta_msr_wait);
1846
1842 remove_sysfs_attrs(port); 1847 remove_sysfs_attrs(port);
1843 1848
1844 kref_put(&priv->kref, ftdi_sio_priv_release); 1849 kref_put(&priv->kref, ftdi_sio_priv_release);
@@ -1982,17 +1987,19 @@ static int ftdi_process_packet(struct tty_struct *tty,
1982 N.B. packet may be processed more than once, but differences 1987 N.B. packet may be processed more than once, but differences
1983 are only processed once. */ 1988 are only processed once. */
1984 status = packet[0] & FTDI_STATUS_B0_MASK; 1989 status = packet[0] & FTDI_STATUS_B0_MASK;
1985 if (status & FTDI_RS0_CTS)
1986 priv->icount.cts++;
1987 if (status & FTDI_RS0_DSR)
1988 priv->icount.dsr++;
1989 if (status & FTDI_RS0_RI)
1990 priv->icount.rng++;
1991 if (status & FTDI_RS0_RLSD)
1992 priv->icount.dcd++;
1993 if (status != priv->prev_status) { 1990 if (status != priv->prev_status) {
1994 priv->diff_status |= status ^ priv->prev_status; 1991 char diff_status = status ^ priv->prev_status;
1995 wake_up_interruptible(&priv->delta_msr_wait); 1992
1993 if (diff_status & FTDI_RS0_CTS)
1994 priv->icount.cts++;
1995 if (diff_status & FTDI_RS0_DSR)
1996 priv->icount.dsr++;
1997 if (diff_status & FTDI_RS0_RI)
1998 priv->icount.rng++;
1999 if (diff_status & FTDI_RS0_RLSD)
2000 priv->icount.dcd++;
2001
2002 wake_up_interruptible_all(&priv->delta_msr_wait);
1996 priv->prev_status = status; 2003 priv->prev_status = status;
1997 } 2004 }
1998 2005
@@ -2395,15 +2402,12 @@ static int ftdi_ioctl(struct tty_struct *tty,
2395 */ 2402 */
2396 case TIOCMIWAIT: 2403 case TIOCMIWAIT:
2397 cprev = priv->icount; 2404 cprev = priv->icount;
2398 while (1) { 2405 while (!priv->dev_gone) {
2399 interruptible_sleep_on(&priv->delta_msr_wait); 2406 interruptible_sleep_on(&priv->delta_msr_wait);
2400 /* see if a signal did it */ 2407 /* see if a signal did it */
2401 if (signal_pending(current)) 2408 if (signal_pending(current))
2402 return -ERESTARTSYS; 2409 return -ERESTARTSYS;
2403 cnow = priv->icount; 2410 cnow = priv->icount;
2404 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
2405 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
2406 return -EIO; /* no change => error */
2407 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) || 2411 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
2408 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) || 2412 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
2409 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) || 2413 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
@@ -2412,7 +2416,7 @@ static int ftdi_ioctl(struct tty_struct *tty,
2412 } 2416 }
2413 cprev = cnow; 2417 cprev = cnow;
2414 } 2418 }
2415 /* not reached */ 2419 return -EIO;
2416 break; 2420 break;
2417 case TIOCSERGETLSR: 2421 case TIOCSERGETLSR:
2418 return get_lsr_info(port, (struct serial_struct __user *)arg); 2422 return get_lsr_info(port, (struct serial_struct __user *)arg);
diff --git a/drivers/usb/serial/metro-usb.c b/drivers/usb/serial/metro-usb.c
index 6e1622f2a297..08d16e8c002d 100644
--- a/drivers/usb/serial/metro-usb.c
+++ b/drivers/usb/serial/metro-usb.c
@@ -27,8 +27,8 @@
27 27
28/* Product information. */ 28/* Product information. */
29#define FOCUS_VENDOR_ID 0x0C2E 29#define FOCUS_VENDOR_ID 0x0C2E
30#define FOCUS_PRODUCT_ID 0x0720 30#define FOCUS_PRODUCT_ID_BI 0x0720
31#define FOCUS_PRODUCT_ID_UNI 0x0710 31#define FOCUS_PRODUCT_ID_UNI 0x0700
32 32
33#define METROUSB_SET_REQUEST_TYPE 0x40 33#define METROUSB_SET_REQUEST_TYPE 0x40
34#define METROUSB_SET_MODEM_CTRL_REQUEST 10 34#define METROUSB_SET_MODEM_CTRL_REQUEST 10
@@ -47,7 +47,7 @@ struct metrousb_private {
47 47
48/* Device table list. */ 48/* Device table list. */
49static struct usb_device_id id_table[] = { 49static struct usb_device_id id_table[] = {
50 { USB_DEVICE(FOCUS_VENDOR_ID, FOCUS_PRODUCT_ID) }, 50 { USB_DEVICE(FOCUS_VENDOR_ID, FOCUS_PRODUCT_ID_BI) },
51 { USB_DEVICE(FOCUS_VENDOR_ID, FOCUS_PRODUCT_ID_UNI) }, 51 { USB_DEVICE(FOCUS_VENDOR_ID, FOCUS_PRODUCT_ID_UNI) },
52 { }, /* Terminating entry. */ 52 { }, /* Terminating entry. */
53}; 53};
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index 836cfa9a515f..f4465ccddc35 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -708,6 +708,7 @@ static const struct usb_device_id option_ids[] = {
708 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_EVDO_EMBEDDED_FULLSPEED) }, 708 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_EVDO_EMBEDDED_FULLSPEED) },
709 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_HSPA_EMBEDDED_FULLSPEED) }, 709 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_HSPA_EMBEDDED_FULLSPEED) },
710 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_EVDO_HIGHSPEED) }, 710 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_EVDO_HIGHSPEED) },
711 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_HSPA_HIGHSPEED) },
711 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_HSPA_HIGHSPEED3) }, 712 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_HSPA_HIGHSPEED3) },
712 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_HSPA_HIGHSPEED4) }, 713 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_HSPA_HIGHSPEED4) },
713 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_HSPA_HIGHSPEED5) }, 714 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_HSPA_HIGHSPEED5) },
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
index ff4a174fa5de..a1a9062954c4 100644
--- a/drivers/usb/serial/pl2303.c
+++ b/drivers/usb/serial/pl2303.c
@@ -420,7 +420,7 @@ static void pl2303_set_termios(struct tty_struct *tty,
420 control = priv->line_control; 420 control = priv->line_control;
421 if ((cflag & CBAUD) == B0) 421 if ((cflag & CBAUD) == B0)
422 priv->line_control &= ~(CONTROL_DTR | CONTROL_RTS); 422 priv->line_control &= ~(CONTROL_DTR | CONTROL_RTS);
423 else 423 else if ((old_termios->c_cflag & CBAUD) == B0)
424 priv->line_control |= (CONTROL_DTR | CONTROL_RTS); 424 priv->line_control |= (CONTROL_DTR | CONTROL_RTS);
425 if (control != priv->line_control) { 425 if (control != priv->line_control) {
426 control = priv->line_control; 426 control = priv->line_control;
diff --git a/drivers/usb/serial/sierra.c b/drivers/usb/serial/sierra.c
index f14465a83dd1..8c8bf806f6fa 100644
--- a/drivers/usb/serial/sierra.c
+++ b/drivers/usb/serial/sierra.c
@@ -221,7 +221,7 @@ static const struct sierra_iface_info typeB_interface_list = {
221}; 221};
222 222
223/* 'blacklist' of interfaces not served by this driver */ 223/* 'blacklist' of interfaces not served by this driver */
224static const u8 direct_ip_non_serial_ifaces[] = { 7, 8, 9, 10, 11 }; 224static const u8 direct_ip_non_serial_ifaces[] = { 7, 8, 9, 10, 11, 19, 20 };
225static const struct sierra_iface_info direct_ip_interface_blacklist = { 225static const struct sierra_iface_info direct_ip_interface_blacklist = {
226 .infolen = ARRAY_SIZE(direct_ip_non_serial_ifaces), 226 .infolen = ARRAY_SIZE(direct_ip_non_serial_ifaces),
227 .ifaceinfo = direct_ip_non_serial_ifaces, 227 .ifaceinfo = direct_ip_non_serial_ifaces,
@@ -298,6 +298,9 @@ static const struct usb_device_id id_table[] = {
298 /* Sierra Wireless HSPA Non-Composite Device */ 298 /* Sierra Wireless HSPA Non-Composite Device */
299 { USB_DEVICE_AND_INTERFACE_INFO(0x1199, 0x6892, 0xFF, 0xFF, 0xFF)}, 299 { USB_DEVICE_AND_INTERFACE_INFO(0x1199, 0x6892, 0xFF, 0xFF, 0xFF)},
300 { USB_DEVICE(0x1199, 0x6893) }, /* Sierra Wireless Device */ 300 { USB_DEVICE(0x1199, 0x6893) }, /* Sierra Wireless Device */
301 { USB_DEVICE(0x1199, 0x68A2), /* Sierra Wireless MC77xx in QMI mode */
302 .driver_info = (kernel_ulong_t)&direct_ip_interface_blacklist
303 },
301 { USB_DEVICE(0x1199, 0x68A3), /* Sierra Wireless Direct IP modems */ 304 { USB_DEVICE(0x1199, 0x68A3), /* Sierra Wireless Direct IP modems */
302 .driver_info = (kernel_ulong_t)&direct_ip_interface_blacklist 305 .driver_info = (kernel_ulong_t)&direct_ip_interface_blacklist
303 }, 306 },
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index 69230f01056a..97355a15bbea 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -1059,6 +1059,12 @@ int usb_serial_probe(struct usb_interface *interface,
1059 serial->attached = 1; 1059 serial->attached = 1;
1060 } 1060 }
1061 1061
1062 /* Avoid race with tty_open and serial_install by setting the
1063 * disconnected flag and not clearing it until all ports have been
1064 * registered.
1065 */
1066 serial->disconnected = 1;
1067
1062 if (get_free_serial(serial, num_ports, &minor) == NULL) { 1068 if (get_free_serial(serial, num_ports, &minor) == NULL) {
1063 dev_err(&interface->dev, "No more free serial devices\n"); 1069 dev_err(&interface->dev, "No more free serial devices\n");
1064 goto probe_error; 1070 goto probe_error;
@@ -1070,19 +1076,16 @@ int usb_serial_probe(struct usb_interface *interface,
1070 port = serial->port[i]; 1076 port = serial->port[i];
1071 dev_set_name(&port->dev, "ttyUSB%d", port->number); 1077 dev_set_name(&port->dev, "ttyUSB%d", port->number);
1072 dbg ("%s - registering %s", __func__, dev_name(&port->dev)); 1078 dbg ("%s - registering %s", __func__, dev_name(&port->dev));
1073 port->dev_state = PORT_REGISTERING;
1074 device_enable_async_suspend(&port->dev); 1079 device_enable_async_suspend(&port->dev);
1075 1080
1076 retval = device_add(&port->dev); 1081 retval = device_add(&port->dev);
1077 if (retval) { 1082 if (retval)
1078 dev_err(&port->dev, "Error registering port device, " 1083 dev_err(&port->dev, "Error registering port device, "
1079 "continuing\n"); 1084 "continuing\n");
1080 port->dev_state = PORT_UNREGISTERED;
1081 } else {
1082 port->dev_state = PORT_REGISTERED;
1083 }
1084 } 1085 }
1085 1086
1087 serial->disconnected = 0;
1088
1086 usb_serial_console_init(debug, minor); 1089 usb_serial_console_init(debug, minor);
1087 1090
1088exit: 1091exit:
@@ -1124,22 +1127,8 @@ void usb_serial_disconnect(struct usb_interface *interface)
1124 } 1127 }
1125 kill_traffic(port); 1128 kill_traffic(port);
1126 cancel_work_sync(&port->work); 1129 cancel_work_sync(&port->work);
1127 if (port->dev_state == PORT_REGISTERED) { 1130 if (device_is_registered(&port->dev))
1128
1129 /* Make sure the port is bound so that the
1130 * driver's port_remove method is called.
1131 */
1132 if (!port->dev.driver) {
1133 int rc;
1134
1135 port->dev.driver =
1136 &serial->type->driver;
1137 rc = device_bind_driver(&port->dev);
1138 }
1139 port->dev_state = PORT_UNREGISTERING;
1140 device_del(&port->dev); 1131 device_del(&port->dev);
1141 port->dev_state = PORT_UNREGISTERED;
1142 }
1143 } 1132 }
1144 } 1133 }
1145 serial->type->disconnect(serial); 1134 serial->type->disconnect(serial);
diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c
index c18538e4a6db..2653e73db623 100644
--- a/drivers/usb/storage/usb.c
+++ b/drivers/usb/storage/usb.c
@@ -132,6 +132,35 @@ static struct us_unusual_dev for_dynamic_ids =
132#undef COMPLIANT_DEV 132#undef COMPLIANT_DEV
133#undef USUAL_DEV 133#undef USUAL_DEV
134 134
135#ifdef CONFIG_LOCKDEP
136
137static struct lock_class_key us_interface_key[USB_MAXINTERFACES];
138
139static void us_set_lock_class(struct mutex *mutex,
140 struct usb_interface *intf)
141{
142 struct usb_device *udev = interface_to_usbdev(intf);
143 struct usb_host_config *config = udev->actconfig;
144 int i;
145
146 for (i = 0; i < config->desc.bNumInterfaces; i++) {
147 if (config->interface[i] == intf)
148 break;
149 }
150
151 BUG_ON(i == config->desc.bNumInterfaces);
152
153 lockdep_set_class(mutex, &us_interface_key[i]);
154}
155
156#else
157
158static void us_set_lock_class(struct mutex *mutex,
159 struct usb_interface *intf)
160{
161}
162
163#endif
135 164
136#ifdef CONFIG_PM /* Minimal support for suspend and resume */ 165#ifdef CONFIG_PM /* Minimal support for suspend and resume */
137 166
@@ -895,6 +924,7 @@ int usb_stor_probe1(struct us_data **pus,
895 *pus = us = host_to_us(host); 924 *pus = us = host_to_us(host);
896 memset(us, 0, sizeof(struct us_data)); 925 memset(us, 0, sizeof(struct us_data));
897 mutex_init(&(us->dev_mutex)); 926 mutex_init(&(us->dev_mutex));
927 us_set_lock_class(&us->dev_mutex, intf);
898 init_completion(&us->cmnd_ready); 928 init_completion(&us->cmnd_ready);
899 init_completion(&(us->notify)); 929 init_completion(&(us->notify));
900 init_waitqueue_head(&us->delay_wait); 930 init_waitqueue_head(&us->delay_wait);
diff --git a/drivers/uwb/hwa-rc.c b/drivers/uwb/hwa-rc.c
index 66797e9c5010..810c90ae2c55 100644
--- a/drivers/uwb/hwa-rc.c
+++ b/drivers/uwb/hwa-rc.c
@@ -645,7 +645,8 @@ void hwarc_neep_cb(struct urb *urb)
645 dev_err(dev, "NEEP: URB error %d\n", urb->status); 645 dev_err(dev, "NEEP: URB error %d\n", urb->status);
646 } 646 }
647 result = usb_submit_urb(urb, GFP_ATOMIC); 647 result = usb_submit_urb(urb, GFP_ATOMIC);
648 if (result < 0) { 648 if (result < 0 && result != -ENODEV && result != -EPERM) {
649 /* ignoring unrecoverable errors */
649 dev_err(dev, "NEEP: Can't resubmit URB (%d) resetting device\n", 650 dev_err(dev, "NEEP: Can't resubmit URB (%d) resetting device\n",
650 result); 651 result);
651 goto error; 652 goto error;
diff --git a/drivers/uwb/neh.c b/drivers/uwb/neh.c
index a269937be1b8..8cb71bb333c2 100644
--- a/drivers/uwb/neh.c
+++ b/drivers/uwb/neh.c
@@ -107,6 +107,7 @@ struct uwb_rc_neh {
107 u8 evt_type; 107 u8 evt_type;
108 __le16 evt; 108 __le16 evt;
109 u8 context; 109 u8 context;
110 u8 completed;
110 uwb_rc_cmd_cb_f cb; 111 uwb_rc_cmd_cb_f cb;
111 void *arg; 112 void *arg;
112 113
@@ -409,6 +410,7 @@ static void uwb_rc_neh_grok_event(struct uwb_rc *rc, struct uwb_rceb *rceb, size
409 struct device *dev = &rc->uwb_dev.dev; 410 struct device *dev = &rc->uwb_dev.dev;
410 struct uwb_rc_neh *neh; 411 struct uwb_rc_neh *neh;
411 struct uwb_rceb *notif; 412 struct uwb_rceb *notif;
413 unsigned long flags;
412 414
413 if (rceb->bEventContext == 0) { 415 if (rceb->bEventContext == 0) {
414 notif = kmalloc(size, GFP_ATOMIC); 416 notif = kmalloc(size, GFP_ATOMIC);
@@ -422,7 +424,11 @@ static void uwb_rc_neh_grok_event(struct uwb_rc *rc, struct uwb_rceb *rceb, size
422 } else { 424 } else {
423 neh = uwb_rc_neh_lookup(rc, rceb); 425 neh = uwb_rc_neh_lookup(rc, rceb);
424 if (neh) { 426 if (neh) {
425 del_timer_sync(&neh->timer); 427 spin_lock_irqsave(&rc->neh_lock, flags);
428 /* to guard against a timeout */
429 neh->completed = 1;
430 del_timer(&neh->timer);
431 spin_unlock_irqrestore(&rc->neh_lock, flags);
426 uwb_rc_neh_cb(neh, rceb, size); 432 uwb_rc_neh_cb(neh, rceb, size);
427 } else 433 } else
428 dev_warn(dev, "event 0x%02x/%04x/%02x (%zu bytes): nobody cared\n", 434 dev_warn(dev, "event 0x%02x/%04x/%02x (%zu bytes): nobody cared\n",
@@ -568,6 +574,10 @@ static void uwb_rc_neh_timer(unsigned long arg)
568 unsigned long flags; 574 unsigned long flags;
569 575
570 spin_lock_irqsave(&rc->neh_lock, flags); 576 spin_lock_irqsave(&rc->neh_lock, flags);
577 if (neh->completed) {
578 spin_unlock_irqrestore(&rc->neh_lock, flags);
579 return;
580 }
571 if (neh->context) 581 if (neh->context)
572 __uwb_rc_neh_rm(rc, neh); 582 __uwb_rc_neh_rm(rc, neh);
573 else 583 else
diff --git a/drivers/uwb/uwb-debug.c b/drivers/uwb/uwb-debug.c
index 2eecec0c13c9..6ec45beb7af5 100644
--- a/drivers/uwb/uwb-debug.c
+++ b/drivers/uwb/uwb-debug.c
@@ -159,13 +159,6 @@ static int cmd_ie_rm(struct uwb_rc *rc, struct uwb_dbg_cmd_ie *ie_to_rm)
159 return uwb_rc_ie_rm(rc, ie_to_rm->data[0]); 159 return uwb_rc_ie_rm(rc, ie_to_rm->data[0]);
160} 160}
161 161
162static int command_open(struct inode *inode, struct file *file)
163{
164 file->private_data = inode->i_private;
165
166 return 0;
167}
168
169static ssize_t command_write(struct file *file, const char __user *buf, 162static ssize_t command_write(struct file *file, const char __user *buf,
170 size_t len, loff_t *off) 163 size_t len, loff_t *off)
171{ 164{
@@ -206,7 +199,7 @@ static ssize_t command_write(struct file *file, const char __user *buf,
206} 199}
207 200
208static const struct file_operations command_fops = { 201static const struct file_operations command_fops = {
209 .open = command_open, 202 .open = simple_open,
210 .write = command_write, 203 .write = command_write,
211 .read = NULL, 204 .read = NULL,
212 .llseek = no_llseek, 205 .llseek = no_llseek,
diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
index f0da2c32fbde..5c170100de9c 100644
--- a/drivers/vhost/net.c
+++ b/drivers/vhost/net.c
@@ -24,6 +24,7 @@
24#include <linux/if_arp.h> 24#include <linux/if_arp.h>
25#include <linux/if_tun.h> 25#include <linux/if_tun.h>
26#include <linux/if_macvlan.h> 26#include <linux/if_macvlan.h>
27#include <linux/if_vlan.h>
27 28
28#include <net/sock.h> 29#include <net/sock.h>
29 30
@@ -238,7 +239,7 @@ static void handle_tx(struct vhost_net *net)
238 239
239 vq->heads[vq->upend_idx].len = len; 240 vq->heads[vq->upend_idx].len = len;
240 ubuf->callback = vhost_zerocopy_callback; 241 ubuf->callback = vhost_zerocopy_callback;
241 ubuf->arg = vq->ubufs; 242 ubuf->ctx = vq->ubufs;
242 ubuf->desc = vq->upend_idx; 243 ubuf->desc = vq->upend_idx;
243 msg.msg_control = ubuf; 244 msg.msg_control = ubuf;
244 msg.msg_controllen = sizeof(ubuf); 245 msg.msg_controllen = sizeof(ubuf);
@@ -283,8 +284,12 @@ static int peek_head_len(struct sock *sk)
283 284
284 spin_lock_irqsave(&sk->sk_receive_queue.lock, flags); 285 spin_lock_irqsave(&sk->sk_receive_queue.lock, flags);
285 head = skb_peek(&sk->sk_receive_queue); 286 head = skb_peek(&sk->sk_receive_queue);
286 if (likely(head)) 287 if (likely(head)) {
287 len = head->len; 288 len = head->len;
289 if (vlan_tx_tag_present(head))
290 len += VLAN_HLEN;
291 }
292
288 spin_unlock_irqrestore(&sk->sk_receive_queue.lock, flags); 293 spin_unlock_irqrestore(&sk->sk_receive_queue.lock, flags);
289 return len; 294 return len;
290} 295}
diff --git a/drivers/vhost/test.c b/drivers/vhost/test.c
index fc9a1d75281f..3de00d9fae2e 100644
--- a/drivers/vhost/test.c
+++ b/drivers/vhost/test.c
@@ -155,7 +155,7 @@ static int vhost_test_release(struct inode *inode, struct file *f)
155 155
156 vhost_test_stop(n, &private); 156 vhost_test_stop(n, &private);
157 vhost_test_flush(n); 157 vhost_test_flush(n);
158 vhost_dev_cleanup(&n->dev); 158 vhost_dev_cleanup(&n->dev, false);
159 /* We do an extra flush before freeing memory, 159 /* We do an extra flush before freeing memory,
160 * since jobs can re-queue themselves. */ 160 * since jobs can re-queue themselves. */
161 vhost_test_flush(n); 161 vhost_test_flush(n);
diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index 947f00d8e091..51e4c1eeec4f 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -1598,10 +1598,9 @@ void vhost_ubuf_put_and_wait(struct vhost_ubuf_ref *ubufs)
1598 kfree(ubufs); 1598 kfree(ubufs);
1599} 1599}
1600 1600
1601void vhost_zerocopy_callback(void *arg) 1601void vhost_zerocopy_callback(struct ubuf_info *ubuf)
1602{ 1602{
1603 struct ubuf_info *ubuf = arg; 1603 struct vhost_ubuf_ref *ubufs = ubuf->ctx;
1604 struct vhost_ubuf_ref *ubufs = ubuf->arg;
1605 struct vhost_virtqueue *vq = ubufs->vq; 1604 struct vhost_virtqueue *vq = ubufs->vq;
1606 1605
1607 /* set len = 1 to mark this desc buffers done DMA */ 1606 /* set len = 1 to mark this desc buffers done DMA */
diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h
index 8dcf4cca6bf2..8de1fd5b8efb 100644
--- a/drivers/vhost/vhost.h
+++ b/drivers/vhost/vhost.h
@@ -188,7 +188,7 @@ bool vhost_enable_notify(struct vhost_dev *, struct vhost_virtqueue *);
188 188
189int vhost_log_write(struct vhost_virtqueue *vq, struct vhost_log *log, 189int vhost_log_write(struct vhost_virtqueue *vq, struct vhost_log *log,
190 unsigned int log_num, u64 len); 190 unsigned int log_num, u64 len);
191void vhost_zerocopy_callback(void *arg); 191void vhost_zerocopy_callback(struct ubuf_info *);
192int vhost_zerocopy_signal_used(struct vhost_virtqueue *vq); 192int vhost_zerocopy_signal_used(struct vhost_virtqueue *vq);
193 193
194#define vq_err(vq, fmt, ...) do { \ 194#define vq_err(vq, fmt, ...) do { \
diff --git a/drivers/video/au1100fb.c b/drivers/video/au1100fb.c
index befcbd8ef019..ffbce4525468 100644
--- a/drivers/video/au1100fb.c
+++ b/drivers/video/au1100fb.c
@@ -499,7 +499,8 @@ static int __devinit au1100fb_drv_probe(struct platform_device *dev)
499 au1100fb_fix.mmio_start = regs_res->start; 499 au1100fb_fix.mmio_start = regs_res->start;
500 au1100fb_fix.mmio_len = resource_size(regs_res); 500 au1100fb_fix.mmio_len = resource_size(regs_res);
501 501
502 if (!devm_request_mem_region(au1100fb_fix.mmio_start, 502 if (!devm_request_mem_region(&dev->dev,
503 au1100fb_fix.mmio_start,
503 au1100fb_fix.mmio_len, 504 au1100fb_fix.mmio_len,
504 DRIVER_NAME)) { 505 DRIVER_NAME)) {
505 print_err("fail to lock memory region at 0x%08lx", 506 print_err("fail to lock memory region at 0x%08lx",
@@ -516,7 +517,7 @@ static int __devinit au1100fb_drv_probe(struct platform_device *dev)
516 fbdev->fb_len = fbdev->panel->xres * fbdev->panel->yres * 517 fbdev->fb_len = fbdev->panel->xres * fbdev->panel->yres *
517 (fbdev->panel->bpp >> 3) * AU1100FB_NBR_VIDEO_BUFFERS; 518 (fbdev->panel->bpp >> 3) * AU1100FB_NBR_VIDEO_BUFFERS;
518 519
519 fbdev->fb_mem = dmam_alloc_coherent(&dev->dev, &dev->dev, 520 fbdev->fb_mem = dmam_alloc_coherent(&dev->dev,
520 PAGE_ALIGN(fbdev->fb_len), 521 PAGE_ALIGN(fbdev->fb_len),
521 &fbdev->fb_phys, GFP_KERNEL); 522 &fbdev->fb_phys, GFP_KERNEL);
522 if (!fbdev->fb_mem) { 523 if (!fbdev->fb_mem) {
diff --git a/drivers/video/au1200fb.c b/drivers/video/au1200fb.c
index 3e9a773db09f..7ca79f02056e 100644
--- a/drivers/video/au1200fb.c
+++ b/drivers/video/au1200fb.c
@@ -1724,7 +1724,7 @@ static int __devinit au1200fb_drv_probe(struct platform_device *dev)
1724 /* Allocate the framebuffer to the maximum screen size */ 1724 /* Allocate the framebuffer to the maximum screen size */
1725 fbdev->fb_len = (win->w[plane].xres * win->w[plane].yres * bpp) / 8; 1725 fbdev->fb_len = (win->w[plane].xres * win->w[plane].yres * bpp) / 8;
1726 1726
1727 fbdev->fb_mem = dmam_alloc_noncoherent(&dev->dev, &dev->dev, 1727 fbdev->fb_mem = dmam_alloc_noncoherent(&dev->dev,
1728 PAGE_ALIGN(fbdev->fb_len), 1728 PAGE_ALIGN(fbdev->fb_len),
1729 &fbdev->fb_phys, GFP_KERNEL); 1729 &fbdev->fb_phys, GFP_KERNEL);
1730 if (!fbdev->fb_mem) { 1730 if (!fbdev->fb_mem) {
diff --git a/drivers/video/backlight/Kconfig b/drivers/video/backlight/Kconfig
index 7ed9991fa747..af16884491ed 100644
--- a/drivers/video/backlight/Kconfig
+++ b/drivers/video/backlight/Kconfig
@@ -245,6 +245,12 @@ config BACKLIGHT_DA903X
245 If you have a LCD backlight connected to the WLED output of DA9030 245 If you have a LCD backlight connected to the WLED output of DA9030
246 or DA9034 WLED output, say Y here to enable this driver. 246 or DA9034 WLED output, say Y here to enable this driver.
247 247
248config BACKLIGHT_DA9052
249 tristate "Dialog DA9052/DA9053 WLED"
250 depends on PMIC_DA9052
251 help
252 Enable the Backlight Driver for DA9052-BC and DA9053-AA/Bx PMICs.
253
248config BACKLIGHT_MAX8925 254config BACKLIGHT_MAX8925
249 tristate "Backlight driver for MAX8925" 255 tristate "Backlight driver for MAX8925"
250 depends on MFD_MAX8925 256 depends on MFD_MAX8925
diff --git a/drivers/video/backlight/Makefile b/drivers/video/backlight/Makefile
index 8071eb656147..36855ae887d6 100644
--- a/drivers/video/backlight/Makefile
+++ b/drivers/video/backlight/Makefile
@@ -29,6 +29,7 @@ obj-$(CONFIG_BACKLIGHT_PROGEAR) += progear_bl.o
29obj-$(CONFIG_BACKLIGHT_CARILLO_RANCH) += cr_bllcd.o 29obj-$(CONFIG_BACKLIGHT_CARILLO_RANCH) += cr_bllcd.o
30obj-$(CONFIG_BACKLIGHT_PWM) += pwm_bl.o 30obj-$(CONFIG_BACKLIGHT_PWM) += pwm_bl.o
31obj-$(CONFIG_BACKLIGHT_DA903X) += da903x_bl.o 31obj-$(CONFIG_BACKLIGHT_DA903X) += da903x_bl.o
32obj-$(CONFIG_BACKLIGHT_DA9052) += da9052_bl.o
32obj-$(CONFIG_BACKLIGHT_MAX8925) += max8925_bl.o 33obj-$(CONFIG_BACKLIGHT_MAX8925) += max8925_bl.o
33obj-$(CONFIG_BACKLIGHT_APPLE) += apple_bl.o 34obj-$(CONFIG_BACKLIGHT_APPLE) += apple_bl.o
34obj-$(CONFIG_BACKLIGHT_TOSA) += tosa_bl.o 35obj-$(CONFIG_BACKLIGHT_TOSA) += tosa_bl.o
diff --git a/drivers/video/backlight/da9052_bl.c b/drivers/video/backlight/da9052_bl.c
new file mode 100644
index 000000000000..b628d68f5162
--- /dev/null
+++ b/drivers/video/backlight/da9052_bl.c
@@ -0,0 +1,187 @@
1/*
2 * Backlight Driver for Dialog DA9052 PMICs
3 *
4 * Copyright(c) 2012 Dialog Semiconductor Ltd.
5 *
6 * Author: David Dajun Chen <dchen@diasemi.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 */
14
15#include <linux/backlight.h>
16#include <linux/delay.h>
17#include <linux/fb.h>
18#include <linux/module.h>
19#include <linux/platform_device.h>
20
21#include <linux/mfd/da9052/da9052.h>
22#include <linux/mfd/da9052/reg.h>
23
24#define DA9052_MAX_BRIGHTNESS 0xFF
25
26enum {
27 DA9052_WLEDS_OFF,
28 DA9052_WLEDS_ON,
29};
30
31enum {
32 DA9052_TYPE_WLED1,
33 DA9052_TYPE_WLED2,
34 DA9052_TYPE_WLED3,
35};
36
37static unsigned char wled_bank[] = {
38 DA9052_LED1_CONF_REG,
39 DA9052_LED2_CONF_REG,
40 DA9052_LED3_CONF_REG,
41};
42
43struct da9052_bl {
44 struct da9052 *da9052;
45 uint brightness;
46 uint state;
47 uint led_reg;
48};
49
50static int da9052_adjust_wled_brightness(struct da9052_bl *wleds)
51{
52 unsigned char boost_en;
53 unsigned char i_sink;
54 int ret;
55
56 boost_en = 0x3F;
57 i_sink = 0xFF;
58 if (wleds->state == DA9052_WLEDS_OFF) {
59 boost_en = 0x00;
60 i_sink = 0x00;
61 }
62
63 ret = da9052_reg_write(wleds->da9052, DA9052_BOOST_REG, boost_en);
64 if (ret < 0)
65 return ret;
66
67 ret = da9052_reg_write(wleds->da9052, DA9052_LED_CONT_REG, i_sink);
68 if (ret < 0)
69 return ret;
70
71 ret = da9052_reg_write(wleds->da9052, wled_bank[wleds->led_reg], 0x0);
72 if (ret < 0)
73 return ret;
74
75 msleep(10);
76
77 if (wleds->brightness) {
78 ret = da9052_reg_write(wleds->da9052, wled_bank[wleds->led_reg],
79 wleds->brightness);
80 if (ret < 0)
81 return ret;
82 }
83
84 return 0;
85}
86
87static int da9052_backlight_update_status(struct backlight_device *bl)
88{
89 int brightness = bl->props.brightness;
90 struct da9052_bl *wleds = bl_get_data(bl);
91
92 wleds->brightness = brightness;
93 wleds->state = DA9052_WLEDS_ON;
94
95 return da9052_adjust_wled_brightness(wleds);
96}
97
98static int da9052_backlight_get_brightness(struct backlight_device *bl)
99{
100 struct da9052_bl *wleds = bl_get_data(bl);
101
102 return wleds->brightness;
103}
104
105static const struct backlight_ops da9052_backlight_ops = {
106 .update_status = da9052_backlight_update_status,
107 .get_brightness = da9052_backlight_get_brightness,
108};
109
110static int da9052_backlight_probe(struct platform_device *pdev)
111{
112 struct backlight_device *bl;
113 struct backlight_properties props;
114 struct da9052_bl *wleds;
115
116 wleds = devm_kzalloc(&pdev->dev, sizeof(struct da9052_bl), GFP_KERNEL);
117 if (!wleds)
118 return -ENOMEM;
119
120 wleds->da9052 = dev_get_drvdata(pdev->dev.parent);
121 wleds->brightness = 0;
122 wleds->led_reg = platform_get_device_id(pdev)->driver_data;
123 wleds->state = DA9052_WLEDS_OFF;
124
125 props.type = BACKLIGHT_RAW;
126 props.max_brightness = DA9052_MAX_BRIGHTNESS;
127
128 bl = backlight_device_register(pdev->name, wleds->da9052->dev, wleds,
129 &da9052_backlight_ops, &props);
130 if (IS_ERR(bl)) {
131 dev_err(&pdev->dev, "Failed to register backlight\n");
132 devm_kfree(&pdev->dev, wleds);
133 return PTR_ERR(bl);
134 }
135
136 bl->props.max_brightness = DA9052_MAX_BRIGHTNESS;
137 bl->props.brightness = 0;
138 platform_set_drvdata(pdev, bl);
139
140 return da9052_adjust_wled_brightness(wleds);
141}
142
143static int da9052_backlight_remove(struct platform_device *pdev)
144{
145 struct backlight_device *bl = platform_get_drvdata(pdev);
146 struct da9052_bl *wleds = bl_get_data(bl);
147
148 wleds->brightness = 0;
149 wleds->state = DA9052_WLEDS_OFF;
150 da9052_adjust_wled_brightness(wleds);
151 backlight_device_unregister(bl);
152 devm_kfree(&pdev->dev, wleds);
153
154 return 0;
155}
156
157static struct platform_device_id da9052_wled_ids[] = {
158 {
159 .name = "da9052-wled1",
160 .driver_data = DA9052_TYPE_WLED1,
161 },
162 {
163 .name = "da9052-wled2",
164 .driver_data = DA9052_TYPE_WLED2,
165 },
166 {
167 .name = "da9052-wled3",
168 .driver_data = DA9052_TYPE_WLED3,
169 },
170};
171
172static struct platform_driver da9052_wled_driver = {
173 .probe = da9052_backlight_probe,
174 .remove = da9052_backlight_remove,
175 .id_table = da9052_wled_ids,
176 .driver = {
177 .name = "da9052-wled",
178 .owner = THIS_MODULE,
179 },
180};
181
182module_platform_driver(da9052_wled_driver);
183
184MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>");
185MODULE_DESCRIPTION("Backlight driver for DA9052 PMIC");
186MODULE_LICENSE("GPL");
187MODULE_ALIAS("platform:da9052-backlight");
diff --git a/drivers/video/backlight/locomolcd.c b/drivers/video/backlight/locomolcd.c
index be20b5cbe26c..3a6d5419e3e3 100644
--- a/drivers/video/backlight/locomolcd.c
+++ b/drivers/video/backlight/locomolcd.c
@@ -229,14 +229,7 @@ static struct locomo_driver poodle_lcd_driver = {
229 229
230static int __init locomolcd_init(void) 230static int __init locomolcd_init(void)
231{ 231{
232 int ret = locomo_driver_register(&poodle_lcd_driver); 232 return locomo_driver_register(&poodle_lcd_driver);
233 if (ret)
234 return ret;
235
236#ifdef CONFIG_SA1100_COLLIE
237 sa1100fb_lcd_power = locomolcd_power;
238#endif
239 return 0;
240} 233}
241 234
242static void __exit locomolcd_exit(void) 235static void __exit locomolcd_exit(void)
diff --git a/drivers/video/bfin-lq035q1-fb.c b/drivers/video/bfin-lq035q1-fb.c
index 86922ac84412..353c02fe8a95 100644
--- a/drivers/video/bfin-lq035q1-fb.c
+++ b/drivers/video/bfin-lq035q1-fb.c
@@ -13,6 +13,7 @@
13#include <linux/errno.h> 13#include <linux/errno.h>
14#include <linux/string.h> 14#include <linux/string.h>
15#include <linux/fb.h> 15#include <linux/fb.h>
16#include <linux/gpio.h>
16#include <linux/slab.h> 17#include <linux/slab.h>
17#include <linux/init.h> 18#include <linux/init.h>
18#include <linux/types.h> 19#include <linux/types.h>
diff --git a/drivers/video/console/sticore.c b/drivers/video/console/sticore.c
index 6468a297e341..39571f9e0162 100644
--- a/drivers/video/console/sticore.c
+++ b/drivers/video/console/sticore.c
@@ -22,7 +22,9 @@
22#include <linux/font.h> 22#include <linux/font.h>
23 23
24#include <asm/hardware.h> 24#include <asm/hardware.h>
25#include <asm/page.h>
25#include <asm/parisc-device.h> 26#include <asm/parisc-device.h>
27#include <asm/pdc.h>
26#include <asm/cacheflush.h> 28#include <asm/cacheflush.h>
27#include <asm/grfioctl.h> 29#include <asm/grfioctl.h>
28 30
diff --git a/drivers/video/kyro/STG4000Reg.h b/drivers/video/kyro/STG4000Reg.h
index 5d6269882589..50f4670e9252 100644
--- a/drivers/video/kyro/STG4000Reg.h
+++ b/drivers/video/kyro/STG4000Reg.h
@@ -73,210 +73,210 @@ typedef enum _OVRL_PIX_FORMAT {
73/* Register Table */ 73/* Register Table */
74typedef struct { 74typedef struct {
75 /* 0h */ 75 /* 0h */
76 volatile unsigned long Thread0Enable; /* 0x0000 */ 76 volatile u32 Thread0Enable; /* 0x0000 */
77 volatile unsigned long Thread1Enable; /* 0x0004 */ 77 volatile u32 Thread1Enable; /* 0x0004 */
78 volatile unsigned long Thread0Recover; /* 0x0008 */ 78 volatile u32 Thread0Recover; /* 0x0008 */
79 volatile unsigned long Thread1Recover; /* 0x000C */ 79 volatile u32 Thread1Recover; /* 0x000C */
80 volatile unsigned long Thread0Step; /* 0x0010 */ 80 volatile u32 Thread0Step; /* 0x0010 */
81 volatile unsigned long Thread1Step; /* 0x0014 */ 81 volatile u32 Thread1Step; /* 0x0014 */
82 volatile unsigned long VideoInStatus; /* 0x0018 */ 82 volatile u32 VideoInStatus; /* 0x0018 */
83 volatile unsigned long Core2InSignStart; /* 0x001C */ 83 volatile u32 Core2InSignStart; /* 0x001C */
84 volatile unsigned long Core1ResetVector; /* 0x0020 */ 84 volatile u32 Core1ResetVector; /* 0x0020 */
85 volatile unsigned long Core1ROMOffset; /* 0x0024 */ 85 volatile u32 Core1ROMOffset; /* 0x0024 */
86 volatile unsigned long Core1ArbiterPriority; /* 0x0028 */ 86 volatile u32 Core1ArbiterPriority; /* 0x0028 */
87 volatile unsigned long VideoInControl; /* 0x002C */ 87 volatile u32 VideoInControl; /* 0x002C */
88 volatile unsigned long VideoInReg0CtrlA; /* 0x0030 */ 88 volatile u32 VideoInReg0CtrlA; /* 0x0030 */
89 volatile unsigned long VideoInReg0CtrlB; /* 0x0034 */ 89 volatile u32 VideoInReg0CtrlB; /* 0x0034 */
90 volatile unsigned long VideoInReg1CtrlA; /* 0x0038 */ 90 volatile u32 VideoInReg1CtrlA; /* 0x0038 */
91 volatile unsigned long VideoInReg1CtrlB; /* 0x003C */ 91 volatile u32 VideoInReg1CtrlB; /* 0x003C */
92 volatile unsigned long Thread0Kicker; /* 0x0040 */ 92 volatile u32 Thread0Kicker; /* 0x0040 */
93 volatile unsigned long Core2InputSign; /* 0x0044 */ 93 volatile u32 Core2InputSign; /* 0x0044 */
94 volatile unsigned long Thread0ProgCtr; /* 0x0048 */ 94 volatile u32 Thread0ProgCtr; /* 0x0048 */
95 volatile unsigned long Thread1ProgCtr; /* 0x004C */ 95 volatile u32 Thread1ProgCtr; /* 0x004C */
96 volatile unsigned long Thread1Kicker; /* 0x0050 */ 96 volatile u32 Thread1Kicker; /* 0x0050 */
97 volatile unsigned long GPRegister1; /* 0x0054 */ 97 volatile u32 GPRegister1; /* 0x0054 */
98 volatile unsigned long GPRegister2; /* 0x0058 */ 98 volatile u32 GPRegister2; /* 0x0058 */
99 volatile unsigned long GPRegister3; /* 0x005C */ 99 volatile u32 GPRegister3; /* 0x005C */
100 volatile unsigned long GPRegister4; /* 0x0060 */ 100 volatile u32 GPRegister4; /* 0x0060 */
101 volatile unsigned long SerialIntA; /* 0x0064 */ 101 volatile u32 SerialIntA; /* 0x0064 */
102 102
103 volatile unsigned long Fill0[6]; /* GAP 0x0068 - 0x007C */ 103 volatile u32 Fill0[6]; /* GAP 0x0068 - 0x007C */
104 104
105 volatile unsigned long SoftwareReset; /* 0x0080 */ 105 volatile u32 SoftwareReset; /* 0x0080 */
106 volatile unsigned long SerialIntB; /* 0x0084 */ 106 volatile u32 SerialIntB; /* 0x0084 */
107 107
108 volatile unsigned long Fill1[37]; /* GAP 0x0088 - 0x011C */ 108 volatile u32 Fill1[37]; /* GAP 0x0088 - 0x011C */
109 109
110 volatile unsigned long ROMELQV; /* 0x011C */ 110 volatile u32 ROMELQV; /* 0x011C */
111 volatile unsigned long WLWH; /* 0x0120 */ 111 volatile u32 WLWH; /* 0x0120 */
112 volatile unsigned long ROMELWL; /* 0x0124 */ 112 volatile u32 ROMELWL; /* 0x0124 */
113 113
114 volatile unsigned long dwFill_1; /* GAP 0x0128 */ 114 volatile u32 dwFill_1; /* GAP 0x0128 */
115 115
116 volatile unsigned long IntStatus; /* 0x012C */ 116 volatile u32 IntStatus; /* 0x012C */
117 volatile unsigned long IntMask; /* 0x0130 */ 117 volatile u32 IntMask; /* 0x0130 */
118 volatile unsigned long IntClear; /* 0x0134 */ 118 volatile u32 IntClear; /* 0x0134 */
119 119
120 volatile unsigned long Fill2[6]; /* GAP 0x0138 - 0x014C */ 120 volatile u32 Fill2[6]; /* GAP 0x0138 - 0x014C */
121 121
122 volatile unsigned long ROMGPIOA; /* 0x0150 */ 122 volatile u32 ROMGPIOA; /* 0x0150 */
123 volatile unsigned long ROMGPIOB; /* 0x0154 */ 123 volatile u32 ROMGPIOB; /* 0x0154 */
124 volatile unsigned long ROMGPIOC; /* 0x0158 */ 124 volatile u32 ROMGPIOC; /* 0x0158 */
125 volatile unsigned long ROMGPIOD; /* 0x015C */ 125 volatile u32 ROMGPIOD; /* 0x015C */
126 126
127 volatile unsigned long Fill3[2]; /* GAP 0x0160 - 0x0168 */ 127 volatile u32 Fill3[2]; /* GAP 0x0160 - 0x0168 */
128 128
129 volatile unsigned long AGPIntID; /* 0x0168 */ 129 volatile u32 AGPIntID; /* 0x0168 */
130 volatile unsigned long AGPIntClassCode; /* 0x016C */ 130 volatile u32 AGPIntClassCode; /* 0x016C */
131 volatile unsigned long AGPIntBIST; /* 0x0170 */ 131 volatile u32 AGPIntBIST; /* 0x0170 */
132 volatile unsigned long AGPIntSSID; /* 0x0174 */ 132 volatile u32 AGPIntSSID; /* 0x0174 */
133 volatile unsigned long AGPIntPMCSR; /* 0x0178 */ 133 volatile u32 AGPIntPMCSR; /* 0x0178 */
134 volatile unsigned long VGAFrameBufBase; /* 0x017C */ 134 volatile u32 VGAFrameBufBase; /* 0x017C */
135 volatile unsigned long VGANotify; /* 0x0180 */ 135 volatile u32 VGANotify; /* 0x0180 */
136 volatile unsigned long DACPLLMode; /* 0x0184 */ 136 volatile u32 DACPLLMode; /* 0x0184 */
137 volatile unsigned long Core1VideoClockDiv; /* 0x0188 */ 137 volatile u32 Core1VideoClockDiv; /* 0x0188 */
138 volatile unsigned long AGPIntStat; /* 0x018C */ 138 volatile u32 AGPIntStat; /* 0x018C */
139 139
140 /* 140 /*
141 volatile unsigned long Fill4[0x0400/4 - 0x0190/4]; //GAP 0x0190 - 0x0400 141 volatile u32 Fill4[0x0400/4 - 0x0190/4]; //GAP 0x0190 - 0x0400
142 volatile unsigned long Fill5[0x05FC/4 - 0x0400/4]; //GAP 0x0400 - 0x05FC Fog Table 142 volatile u32 Fill5[0x05FC/4 - 0x0400/4]; //GAP 0x0400 - 0x05FC Fog Table
143 volatile unsigned long Fill6[0x0604/4 - 0x0600/4]; //GAP 0x0600 - 0x0604 143 volatile u32 Fill6[0x0604/4 - 0x0600/4]; //GAP 0x0600 - 0x0604
144 volatile unsigned long Fill7[0x0680/4 - 0x0608/4]; //GAP 0x0608 - 0x0680 144 volatile u32 Fill7[0x0680/4 - 0x0608/4]; //GAP 0x0608 - 0x0680
145 volatile unsigned long Fill8[0x07FC/4 - 0x0684/4]; //GAP 0x0684 - 0x07FC 145 volatile u32 Fill8[0x07FC/4 - 0x0684/4]; //GAP 0x0684 - 0x07FC
146 */ 146 */
147 volatile unsigned long Fill4[412]; /* 0x0190 - 0x07FC */ 147 volatile u32 Fill4[412]; /* 0x0190 - 0x07FC */
148 148
149 volatile unsigned long TACtrlStreamBase; /* 0x0800 */ 149 volatile u32 TACtrlStreamBase; /* 0x0800 */
150 volatile unsigned long TAObjDataBase; /* 0x0804 */ 150 volatile u32 TAObjDataBase; /* 0x0804 */
151 volatile unsigned long TAPtrDataBase; /* 0x0808 */ 151 volatile u32 TAPtrDataBase; /* 0x0808 */
152 volatile unsigned long TARegionDataBase; /* 0x080C */ 152 volatile u32 TARegionDataBase; /* 0x080C */
153 volatile unsigned long TATailPtrBase; /* 0x0810 */ 153 volatile u32 TATailPtrBase; /* 0x0810 */
154 volatile unsigned long TAPtrRegionSize; /* 0x0814 */ 154 volatile u32 TAPtrRegionSize; /* 0x0814 */
155 volatile unsigned long TAConfiguration; /* 0x0818 */ 155 volatile u32 TAConfiguration; /* 0x0818 */
156 volatile unsigned long TAObjDataStartAddr; /* 0x081C */ 156 volatile u32 TAObjDataStartAddr; /* 0x081C */
157 volatile unsigned long TAObjDataEndAddr; /* 0x0820 */ 157 volatile u32 TAObjDataEndAddr; /* 0x0820 */
158 volatile unsigned long TAXScreenClip; /* 0x0824 */ 158 volatile u32 TAXScreenClip; /* 0x0824 */
159 volatile unsigned long TAYScreenClip; /* 0x0828 */ 159 volatile u32 TAYScreenClip; /* 0x0828 */
160 volatile unsigned long TARHWClamp; /* 0x082C */ 160 volatile u32 TARHWClamp; /* 0x082C */
161 volatile unsigned long TARHWCompare; /* 0x0830 */ 161 volatile u32 TARHWCompare; /* 0x0830 */
162 volatile unsigned long TAStart; /* 0x0834 */ 162 volatile u32 TAStart; /* 0x0834 */
163 volatile unsigned long TAObjReStart; /* 0x0838 */ 163 volatile u32 TAObjReStart; /* 0x0838 */
164 volatile unsigned long TAPtrReStart; /* 0x083C */ 164 volatile u32 TAPtrReStart; /* 0x083C */
165 volatile unsigned long TAStatus1; /* 0x0840 */ 165 volatile u32 TAStatus1; /* 0x0840 */
166 volatile unsigned long TAStatus2; /* 0x0844 */ 166 volatile u32 TAStatus2; /* 0x0844 */
167 volatile unsigned long TAIntStatus; /* 0x0848 */ 167 volatile u32 TAIntStatus; /* 0x0848 */
168 volatile unsigned long TAIntMask; /* 0x084C */ 168 volatile u32 TAIntMask; /* 0x084C */
169 169
170 volatile unsigned long Fill5[235]; /* GAP 0x0850 - 0x0BF8 */ 170 volatile u32 Fill5[235]; /* GAP 0x0850 - 0x0BF8 */
171 171
172 volatile unsigned long TextureAddrThresh; /* 0x0BFC */ 172 volatile u32 TextureAddrThresh; /* 0x0BFC */
173 volatile unsigned long Core1Translation; /* 0x0C00 */ 173 volatile u32 Core1Translation; /* 0x0C00 */
174 volatile unsigned long TextureAddrReMap; /* 0x0C04 */ 174 volatile u32 TextureAddrReMap; /* 0x0C04 */
175 volatile unsigned long RenderOutAGPRemap; /* 0x0C08 */ 175 volatile u32 RenderOutAGPRemap; /* 0x0C08 */
176 volatile unsigned long _3DRegionReadTrans; /* 0x0C0C */ 176 volatile u32 _3DRegionReadTrans; /* 0x0C0C */
177 volatile unsigned long _3DPtrReadTrans; /* 0x0C10 */ 177 volatile u32 _3DPtrReadTrans; /* 0x0C10 */
178 volatile unsigned long _3DParamReadTrans; /* 0x0C14 */ 178 volatile u32 _3DParamReadTrans; /* 0x0C14 */
179 volatile unsigned long _3DRegionReadThresh; /* 0x0C18 */ 179 volatile u32 _3DRegionReadThresh; /* 0x0C18 */
180 volatile unsigned long _3DPtrReadThresh; /* 0x0C1C */ 180 volatile u32 _3DPtrReadThresh; /* 0x0C1C */
181 volatile unsigned long _3DParamReadThresh; /* 0x0C20 */ 181 volatile u32 _3DParamReadThresh; /* 0x0C20 */
182 volatile unsigned long _3DRegionReadAGPRemap; /* 0x0C24 */ 182 volatile u32 _3DRegionReadAGPRemap; /* 0x0C24 */
183 volatile unsigned long _3DPtrReadAGPRemap; /* 0x0C28 */ 183 volatile u32 _3DPtrReadAGPRemap; /* 0x0C28 */
184 volatile unsigned long _3DParamReadAGPRemap; /* 0x0C2C */ 184 volatile u32 _3DParamReadAGPRemap; /* 0x0C2C */
185 volatile unsigned long ZBufferAGPRemap; /* 0x0C30 */ 185 volatile u32 ZBufferAGPRemap; /* 0x0C30 */
186 volatile unsigned long TAIndexAGPRemap; /* 0x0C34 */ 186 volatile u32 TAIndexAGPRemap; /* 0x0C34 */
187 volatile unsigned long TAVertexAGPRemap; /* 0x0C38 */ 187 volatile u32 TAVertexAGPRemap; /* 0x0C38 */
188 volatile unsigned long TAUVAddrTrans; /* 0x0C3C */ 188 volatile u32 TAUVAddrTrans; /* 0x0C3C */
189 volatile unsigned long TATailPtrCacheTrans; /* 0x0C40 */ 189 volatile u32 TATailPtrCacheTrans; /* 0x0C40 */
190 volatile unsigned long TAParamWriteTrans; /* 0x0C44 */ 190 volatile u32 TAParamWriteTrans; /* 0x0C44 */
191 volatile unsigned long TAPtrWriteTrans; /* 0x0C48 */ 191 volatile u32 TAPtrWriteTrans; /* 0x0C48 */
192 volatile unsigned long TAParamWriteThresh; /* 0x0C4C */ 192 volatile u32 TAParamWriteThresh; /* 0x0C4C */
193 volatile unsigned long TAPtrWriteThresh; /* 0x0C50 */ 193 volatile u32 TAPtrWriteThresh; /* 0x0C50 */
194 volatile unsigned long TATailPtrCacheAGPRe; /* 0x0C54 */ 194 volatile u32 TATailPtrCacheAGPRe; /* 0x0C54 */
195 volatile unsigned long TAParamWriteAGPRe; /* 0x0C58 */ 195 volatile u32 TAParamWriteAGPRe; /* 0x0C58 */
196 volatile unsigned long TAPtrWriteAGPRe; /* 0x0C5C */ 196 volatile u32 TAPtrWriteAGPRe; /* 0x0C5C */
197 volatile unsigned long SDRAMArbiterConf; /* 0x0C60 */ 197 volatile u32 SDRAMArbiterConf; /* 0x0C60 */
198 volatile unsigned long SDRAMConf0; /* 0x0C64 */ 198 volatile u32 SDRAMConf0; /* 0x0C64 */
199 volatile unsigned long SDRAMConf1; /* 0x0C68 */ 199 volatile u32 SDRAMConf1; /* 0x0C68 */
200 volatile unsigned long SDRAMConf2; /* 0x0C6C */ 200 volatile u32 SDRAMConf2; /* 0x0C6C */
201 volatile unsigned long SDRAMRefresh; /* 0x0C70 */ 201 volatile u32 SDRAMRefresh; /* 0x0C70 */
202 volatile unsigned long SDRAMPowerStat; /* 0x0C74 */ 202 volatile u32 SDRAMPowerStat; /* 0x0C74 */
203 203
204 volatile unsigned long Fill6[2]; /* GAP 0x0C78 - 0x0C7C */ 204 volatile u32 Fill6[2]; /* GAP 0x0C78 - 0x0C7C */
205 205
206 volatile unsigned long RAMBistData; /* 0x0C80 */ 206 volatile u32 RAMBistData; /* 0x0C80 */
207 volatile unsigned long RAMBistCtrl; /* 0x0C84 */ 207 volatile u32 RAMBistCtrl; /* 0x0C84 */
208 volatile unsigned long FIFOBistKey; /* 0x0C88 */ 208 volatile u32 FIFOBistKey; /* 0x0C88 */
209 volatile unsigned long RAMBistResult; /* 0x0C8C */ 209 volatile u32 RAMBistResult; /* 0x0C8C */
210 volatile unsigned long FIFOBistResult; /* 0x0C90 */ 210 volatile u32 FIFOBistResult; /* 0x0C90 */
211 211
212 /* 212 /*
213 volatile unsigned long Fill11[0x0CBC/4 - 0x0C94/4]; //GAP 0x0C94 - 0x0CBC 213 volatile u32 Fill11[0x0CBC/4 - 0x0C94/4]; //GAP 0x0C94 - 0x0CBC
214 volatile unsigned long Fill12[0x0CD0/4 - 0x0CC0/4]; //GAP 0x0CC0 - 0x0CD0 3DRegisters 214 volatile u32 Fill12[0x0CD0/4 - 0x0CC0/4]; //GAP 0x0CC0 - 0x0CD0 3DRegisters
215 */ 215 */
216 216
217 volatile unsigned long Fill7[16]; /* 0x0c94 - 0x0cd0 */ 217 volatile u32 Fill7[16]; /* 0x0c94 - 0x0cd0 */
218 218
219 volatile unsigned long SDRAMAddrSign; /* 0x0CD4 */ 219 volatile u32 SDRAMAddrSign; /* 0x0CD4 */
220 volatile unsigned long SDRAMDataSign; /* 0x0CD8 */ 220 volatile u32 SDRAMDataSign; /* 0x0CD8 */
221 volatile unsigned long SDRAMSignConf; /* 0x0CDC */ 221 volatile u32 SDRAMSignConf; /* 0x0CDC */
222 222
223 /* DWFILL; //GAP 0x0CE0 */ 223 /* DWFILL; //GAP 0x0CE0 */
224 volatile unsigned long dwFill_2; 224 volatile u32 dwFill_2;
225 225
226 volatile unsigned long ISPSignature; /* 0x0CE4 */ 226 volatile u32 ISPSignature; /* 0x0CE4 */
227 227
228 volatile unsigned long Fill8[454]; /*GAP 0x0CE8 - 0x13FC */ 228 volatile u32 Fill8[454]; /*GAP 0x0CE8 - 0x13FC */
229 229
230 volatile unsigned long DACPrimAddress; /* 0x1400 */ 230 volatile u32 DACPrimAddress; /* 0x1400 */
231 volatile unsigned long DACPrimSize; /* 0x1404 */ 231 volatile u32 DACPrimSize; /* 0x1404 */
232 volatile unsigned long DACCursorAddr; /* 0x1408 */ 232 volatile u32 DACCursorAddr; /* 0x1408 */
233 volatile unsigned long DACCursorCtrl; /* 0x140C */ 233 volatile u32 DACCursorCtrl; /* 0x140C */
234 volatile unsigned long DACOverlayAddr; /* 0x1410 */ 234 volatile u32 DACOverlayAddr; /* 0x1410 */
235 volatile unsigned long DACOverlayUAddr; /* 0x1414 */ 235 volatile u32 DACOverlayUAddr; /* 0x1414 */
236 volatile unsigned long DACOverlayVAddr; /* 0x1418 */ 236 volatile u32 DACOverlayVAddr; /* 0x1418 */
237 volatile unsigned long DACOverlaySize; /* 0x141C */ 237 volatile u32 DACOverlaySize; /* 0x141C */
238 volatile unsigned long DACOverlayVtDec; /* 0x1420 */ 238 volatile u32 DACOverlayVtDec; /* 0x1420 */
239 239
240 volatile unsigned long Fill9[9]; /* GAP 0x1424 - 0x1444 */ 240 volatile u32 Fill9[9]; /* GAP 0x1424 - 0x1444 */
241 241
242 volatile unsigned long DACVerticalScal; /* 0x1448 */ 242 volatile u32 DACVerticalScal; /* 0x1448 */
243 volatile unsigned long DACPixelFormat; /* 0x144C */ 243 volatile u32 DACPixelFormat; /* 0x144C */
244 volatile unsigned long DACHorizontalScal; /* 0x1450 */ 244 volatile u32 DACHorizontalScal; /* 0x1450 */
245 volatile unsigned long DACVidWinStart; /* 0x1454 */ 245 volatile u32 DACVidWinStart; /* 0x1454 */
246 volatile unsigned long DACVidWinEnd; /* 0x1458 */ 246 volatile u32 DACVidWinEnd; /* 0x1458 */
247 volatile unsigned long DACBlendCtrl; /* 0x145C */ 247 volatile u32 DACBlendCtrl; /* 0x145C */
248 volatile unsigned long DACHorTim1; /* 0x1460 */ 248 volatile u32 DACHorTim1; /* 0x1460 */
249 volatile unsigned long DACHorTim2; /* 0x1464 */ 249 volatile u32 DACHorTim2; /* 0x1464 */
250 volatile unsigned long DACHorTim3; /* 0x1468 */ 250 volatile u32 DACHorTim3; /* 0x1468 */
251 volatile unsigned long DACVerTim1; /* 0x146C */ 251 volatile u32 DACVerTim1; /* 0x146C */
252 volatile unsigned long DACVerTim2; /* 0x1470 */ 252 volatile u32 DACVerTim2; /* 0x1470 */
253 volatile unsigned long DACVerTim3; /* 0x1474 */ 253 volatile u32 DACVerTim3; /* 0x1474 */
254 volatile unsigned long DACBorderColor; /* 0x1478 */ 254 volatile u32 DACBorderColor; /* 0x1478 */
255 volatile unsigned long DACSyncCtrl; /* 0x147C */ 255 volatile u32 DACSyncCtrl; /* 0x147C */
256 volatile unsigned long DACStreamCtrl; /* 0x1480 */ 256 volatile u32 DACStreamCtrl; /* 0x1480 */
257 volatile unsigned long DACLUTAddress; /* 0x1484 */ 257 volatile u32 DACLUTAddress; /* 0x1484 */
258 volatile unsigned long DACLUTData; /* 0x1488 */ 258 volatile u32 DACLUTData; /* 0x1488 */
259 volatile unsigned long DACBurstCtrl; /* 0x148C */ 259 volatile u32 DACBurstCtrl; /* 0x148C */
260 volatile unsigned long DACCrcTrigger; /* 0x1490 */ 260 volatile u32 DACCrcTrigger; /* 0x1490 */
261 volatile unsigned long DACCrcDone; /* 0x1494 */ 261 volatile u32 DACCrcDone; /* 0x1494 */
262 volatile unsigned long DACCrcResult1; /* 0x1498 */ 262 volatile u32 DACCrcResult1; /* 0x1498 */
263 volatile unsigned long DACCrcResult2; /* 0x149C */ 263 volatile u32 DACCrcResult2; /* 0x149C */
264 volatile unsigned long DACLinecount; /* 0x14A0 */ 264 volatile u32 DACLinecount; /* 0x14A0 */
265 265
266 volatile unsigned long Fill10[151]; /*GAP 0x14A4 - 0x16FC */ 266 volatile u32 Fill10[151]; /*GAP 0x14A4 - 0x16FC */
267 267
268 volatile unsigned long DigVidPortCtrl; /* 0x1700 */ 268 volatile u32 DigVidPortCtrl; /* 0x1700 */
269 volatile unsigned long DigVidPortStat; /* 0x1704 */ 269 volatile u32 DigVidPortStat; /* 0x1704 */
270 270
271 /* 271 /*
272 volatile unsigned long Fill11[0x1FFC/4 - 0x1708/4]; //GAP 0x1708 - 0x1FFC 272 volatile u32 Fill11[0x1FFC/4 - 0x1708/4]; //GAP 0x1708 - 0x1FFC
273 volatile unsigned long Fill17[0x3000/4 - 0x2FFC/4]; //GAP 0x2000 - 0x2FFC ALUT 273 volatile u32 Fill17[0x3000/4 - 0x2FFC/4]; //GAP 0x2000 - 0x2FFC ALUT
274 */ 274 */
275 275
276 volatile unsigned long Fill11[1598]; 276 volatile u32 Fill11[1598];
277 277
278 /* DWFILL; //GAP 0x3000 ALUT 256MB offset */ 278 /* DWFILL; //GAP 0x3000 ALUT 256MB offset */
279 volatile unsigned long Fill_3; 279 volatile u32 Fill_3;
280 280
281} STG4000REG; 281} STG4000REG;
282 282
diff --git a/drivers/video/msm/mddi.c b/drivers/video/msm/mddi.c
index 4527cbf0a4ec..b061d709bc44 100644
--- a/drivers/video/msm/mddi.c
+++ b/drivers/video/msm/mddi.c
@@ -420,7 +420,7 @@ static void mddi_resume(struct msm_mddi_client_data *cdata)
420 mddi_set_auto_hibernate(&mddi->client_data, 1); 420 mddi_set_auto_hibernate(&mddi->client_data, 1);
421} 421}
422 422
423static int __init mddi_get_client_caps(struct mddi_info *mddi) 423static int __devinit mddi_get_client_caps(struct mddi_info *mddi)
424{ 424{
425 int i, j; 425 int i, j;
426 426
@@ -622,9 +622,9 @@ uint32_t mddi_remote_read(struct msm_mddi_client_data *cdata, uint32_t reg)
622 622
623static struct mddi_info mddi_info[2]; 623static struct mddi_info mddi_info[2];
624 624
625static int __init mddi_clk_setup(struct platform_device *pdev, 625static int __devinit mddi_clk_setup(struct platform_device *pdev,
626 struct mddi_info *mddi, 626 struct mddi_info *mddi,
627 unsigned long clk_rate) 627 unsigned long clk_rate)
628{ 628{
629 int ret; 629 int ret;
630 630
diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
index 260cca7ddb41..b0e2a4261afe 100644
--- a/drivers/video/uvesafb.c
+++ b/drivers/video/uvesafb.c
@@ -73,7 +73,7 @@ static void uvesafb_cn_callback(struct cn_msg *msg, struct netlink_skb_parms *ns
73 struct uvesafb_task *utask; 73 struct uvesafb_task *utask;
74 struct uvesafb_ktask *task; 74 struct uvesafb_ktask *task;
75 75
76 if (!cap_raised(current_cap(), CAP_SYS_ADMIN)) 76 if (!capable(CAP_SYS_ADMIN))
77 return; 77 return;
78 78
79 if (msg->seq >= UVESAFB_TASKS_MAX) 79 if (msg->seq >= UVESAFB_TASKS_MAX)
@@ -815,8 +815,15 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
815 par->pmi_setpal = pmi_setpal; 815 par->pmi_setpal = pmi_setpal;
816 par->ypan = ypan; 816 par->ypan = ypan;
817 817
818 if (par->pmi_setpal || par->ypan) 818 if (par->pmi_setpal || par->ypan) {
819 uvesafb_vbe_getpmi(task, par); 819 if (__supported_pte_mask & _PAGE_NX) {
820 par->pmi_setpal = par->ypan = 0;
821 printk(KERN_WARNING "uvesafb: NX protection is actively."
822 "We have better not to use the PMI.\n");
823 } else {
824 uvesafb_vbe_getpmi(task, par);
825 }
826 }
820#else 827#else
821 /* The protected mode interface is not available on non-x86. */ 828 /* The protected mode interface is not available on non-x86. */
822 par->pmi_setpal = par->ypan = 0; 829 par->pmi_setpal = par->ypan = 0;
diff --git a/drivers/video/xen-fbfront.c b/drivers/video/xen-fbfront.c
index cb4529c40d74..b7f5173ff9e9 100644
--- a/drivers/video/xen-fbfront.c
+++ b/drivers/video/xen-fbfront.c
@@ -365,7 +365,7 @@ static int __devinit xenfb_probe(struct xenbus_device *dev,
365 struct fb_info *fb_info; 365 struct fb_info *fb_info;
366 int fb_size; 366 int fb_size;
367 int val; 367 int val;
368 int ret; 368 int ret = 0;
369 369
370 info = kzalloc(sizeof(*info), GFP_KERNEL); 370 info = kzalloc(sizeof(*info), GFP_KERNEL);
371 if (info == NULL) { 371 if (info == NULL) {
@@ -458,26 +458,31 @@ static int __devinit xenfb_probe(struct xenbus_device *dev,
458 xenfb_init_shared_page(info, fb_info); 458 xenfb_init_shared_page(info, fb_info);
459 459
460 ret = xenfb_connect_backend(dev, info); 460 ret = xenfb_connect_backend(dev, info);
461 if (ret < 0) 461 if (ret < 0) {
462 goto error; 462 xenbus_dev_fatal(dev, ret, "xenfb_connect_backend");
463 goto error_fb;
464 }
463 465
464 ret = register_framebuffer(fb_info); 466 ret = register_framebuffer(fb_info);
465 if (ret) { 467 if (ret) {
466 fb_deferred_io_cleanup(fb_info);
467 fb_dealloc_cmap(&fb_info->cmap);
468 framebuffer_release(fb_info);
469 xenbus_dev_fatal(dev, ret, "register_framebuffer"); 468 xenbus_dev_fatal(dev, ret, "register_framebuffer");
470 goto error; 469 goto error_fb;
471 } 470 }
472 info->fb_info = fb_info; 471 info->fb_info = fb_info;
473 472
474 xenfb_make_preferred_console(); 473 xenfb_make_preferred_console();
475 return 0; 474 return 0;
476 475
477 error_nomem: 476error_fb:
478 ret = -ENOMEM; 477 fb_deferred_io_cleanup(fb_info);
479 xenbus_dev_fatal(dev, ret, "allocating device memory"); 478 fb_dealloc_cmap(&fb_info->cmap);
480 error: 479 framebuffer_release(fb_info);
480error_nomem:
481 if (!ret) {
482 ret = -ENOMEM;
483 xenbus_dev_fatal(dev, ret, "allocating device memory");
484 }
485error:
481 xenfb_remove(dev); 486 xenfb_remove(dev);
482 return ret; 487 return ret;
483} 488}
diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index 05f0a80818a2..c2d05a8279fd 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -28,6 +28,13 @@
28#include <linux/slab.h> 28#include <linux/slab.h>
29#include <linux/module.h> 29#include <linux/module.h>
30 30
31/*
32 * Balloon device works in 4K page units. So each page is pointed to by
33 * multiple balloon pages. All memory counters in this driver are in balloon
34 * page units.
35 */
36#define VIRTIO_BALLOON_PAGES_PER_PAGE (PAGE_SIZE >> VIRTIO_BALLOON_PFN_SHIFT)
37
31struct virtio_balloon 38struct virtio_balloon
32{ 39{
33 struct virtio_device *vdev; 40 struct virtio_device *vdev;
@@ -42,8 +49,13 @@ struct virtio_balloon
42 /* Waiting for host to ack the pages we released. */ 49 /* Waiting for host to ack the pages we released. */
43 struct completion acked; 50 struct completion acked;
44 51
45 /* The pages we've told the Host we're not using. */ 52 /* Number of balloon pages we've told the Host we're not using. */
46 unsigned int num_pages; 53 unsigned int num_pages;
54 /*
55 * The pages we've told the Host we're not using.
56 * Each page on this list adds VIRTIO_BALLOON_PAGES_PER_PAGE
57 * to num_pages above.
58 */
47 struct list_head pages; 59 struct list_head pages;
48 60
49 /* The array of pfns we tell the Host about. */ 61 /* The array of pfns we tell the Host about. */
@@ -66,7 +78,13 @@ static u32 page_to_balloon_pfn(struct page *page)
66 78
67 BUILD_BUG_ON(PAGE_SHIFT < VIRTIO_BALLOON_PFN_SHIFT); 79 BUILD_BUG_ON(PAGE_SHIFT < VIRTIO_BALLOON_PFN_SHIFT);
68 /* Convert pfn from Linux page size to balloon page size. */ 80 /* Convert pfn from Linux page size to balloon page size. */
69 return pfn >> (PAGE_SHIFT - VIRTIO_BALLOON_PFN_SHIFT); 81 return pfn * VIRTIO_BALLOON_PAGES_PER_PAGE;
82}
83
84static struct page *balloon_pfn_to_page(u32 pfn)
85{
86 BUG_ON(pfn % VIRTIO_BALLOON_PAGES_PER_PAGE);
87 return pfn_to_page(pfn / VIRTIO_BALLOON_PAGES_PER_PAGE);
70} 88}
71 89
72static void balloon_ack(struct virtqueue *vq) 90static void balloon_ack(struct virtqueue *vq)
@@ -96,12 +114,23 @@ static void tell_host(struct virtio_balloon *vb, struct virtqueue *vq)
96 wait_for_completion(&vb->acked); 114 wait_for_completion(&vb->acked);
97} 115}
98 116
117static void set_page_pfns(u32 pfns[], struct page *page)
118{
119 unsigned int i;
120
121 /* Set balloon pfns pointing at this page.
122 * Note that the first pfn points at start of the page. */
123 for (i = 0; i < VIRTIO_BALLOON_PAGES_PER_PAGE; i++)
124 pfns[i] = page_to_balloon_pfn(page) + i;
125}
126
99static void fill_balloon(struct virtio_balloon *vb, size_t num) 127static void fill_balloon(struct virtio_balloon *vb, size_t num)
100{ 128{
101 /* We can only do one array worth at a time. */ 129 /* We can only do one array worth at a time. */
102 num = min(num, ARRAY_SIZE(vb->pfns)); 130 num = min(num, ARRAY_SIZE(vb->pfns));
103 131
104 for (vb->num_pfns = 0; vb->num_pfns < num; vb->num_pfns++) { 132 for (vb->num_pfns = 0; vb->num_pfns < num;
133 vb->num_pfns += VIRTIO_BALLOON_PAGES_PER_PAGE) {
105 struct page *page = alloc_page(GFP_HIGHUSER | __GFP_NORETRY | 134 struct page *page = alloc_page(GFP_HIGHUSER | __GFP_NORETRY |
106 __GFP_NOMEMALLOC | __GFP_NOWARN); 135 __GFP_NOMEMALLOC | __GFP_NOWARN);
107 if (!page) { 136 if (!page) {
@@ -113,9 +142,9 @@ static void fill_balloon(struct virtio_balloon *vb, size_t num)
113 msleep(200); 142 msleep(200);
114 break; 143 break;
115 } 144 }
116 vb->pfns[vb->num_pfns] = page_to_balloon_pfn(page); 145 set_page_pfns(vb->pfns + vb->num_pfns, page);
146 vb->num_pages += VIRTIO_BALLOON_PAGES_PER_PAGE;
117 totalram_pages--; 147 totalram_pages--;
118 vb->num_pages++;
119 list_add(&page->lru, &vb->pages); 148 list_add(&page->lru, &vb->pages);
120 } 149 }
121 150
@@ -130,8 +159,9 @@ static void release_pages_by_pfn(const u32 pfns[], unsigned int num)
130{ 159{
131 unsigned int i; 160 unsigned int i;
132 161
133 for (i = 0; i < num; i++) { 162 /* Find pfns pointing at start of each page, get pages and free them. */
134 __free_page(pfn_to_page(pfns[i])); 163 for (i = 0; i < num; i += VIRTIO_BALLOON_PAGES_PER_PAGE) {
164 __free_page(balloon_pfn_to_page(pfns[i]));
135 totalram_pages++; 165 totalram_pages++;
136 } 166 }
137} 167}
@@ -143,11 +173,12 @@ static void leak_balloon(struct virtio_balloon *vb, size_t num)
143 /* We can only do one array worth at a time. */ 173 /* We can only do one array worth at a time. */
144 num = min(num, ARRAY_SIZE(vb->pfns)); 174 num = min(num, ARRAY_SIZE(vb->pfns));
145 175
146 for (vb->num_pfns = 0; vb->num_pfns < num; vb->num_pfns++) { 176 for (vb->num_pfns = 0; vb->num_pfns < num;
177 vb->num_pfns += VIRTIO_BALLOON_PAGES_PER_PAGE) {
147 page = list_first_entry(&vb->pages, struct page, lru); 178 page = list_first_entry(&vb->pages, struct page, lru);
148 list_del(&page->lru); 179 list_del(&page->lru);
149 vb->pfns[vb->num_pfns] = page_to_balloon_pfn(page); 180 set_page_pfns(vb->pfns + vb->num_pfns, page);
150 vb->num_pages--; 181 vb->num_pages -= VIRTIO_BALLOON_PAGES_PER_PAGE;
151 } 182 }
152 183
153 /* 184 /*
@@ -234,11 +265,14 @@ static void virtballoon_changed(struct virtio_device *vdev)
234 265
235static inline s64 towards_target(struct virtio_balloon *vb) 266static inline s64 towards_target(struct virtio_balloon *vb)
236{ 267{
237 u32 v; 268 __le32 v;
269 s64 target;
270
238 vb->vdev->config->get(vb->vdev, 271 vb->vdev->config->get(vb->vdev,
239 offsetof(struct virtio_balloon_config, num_pages), 272 offsetof(struct virtio_balloon_config, num_pages),
240 &v, sizeof(v)); 273 &v, sizeof(v));
241 return (s64)v - vb->num_pages; 274 target = le32_to_cpu(v);
275 return target - vb->num_pages;
242} 276}
243 277
244static void update_balloon_size(struct virtio_balloon *vb) 278static void update_balloon_size(struct virtio_balloon *vb)
diff --git a/drivers/watchdog/hpwdt.c b/drivers/watchdog/hpwdt.c
index cbc7ceef2786..9f13b897fd64 100644
--- a/drivers/watchdog/hpwdt.c
+++ b/drivers/watchdog/hpwdt.c
@@ -435,16 +435,16 @@ static void hpwdt_start(void)
435{ 435{
436 reload = SECS_TO_TICKS(soft_margin); 436 reload = SECS_TO_TICKS(soft_margin);
437 iowrite16(reload, hpwdt_timer_reg); 437 iowrite16(reload, hpwdt_timer_reg);
438 iowrite16(0x85, hpwdt_timer_con); 438 iowrite8(0x85, hpwdt_timer_con);
439} 439}
440 440
441static void hpwdt_stop(void) 441static void hpwdt_stop(void)
442{ 442{
443 unsigned long data; 443 unsigned long data;
444 444
445 data = ioread16(hpwdt_timer_con); 445 data = ioread8(hpwdt_timer_con);
446 data &= 0xFE; 446 data &= 0xFE;
447 iowrite16(data, hpwdt_timer_con); 447 iowrite8(data, hpwdt_timer_con);
448} 448}
449 449
450static void hpwdt_ping(void) 450static void hpwdt_ping(void)
diff --git a/drivers/xen/Kconfig b/drivers/xen/Kconfig
index 94243136f6bf..ea20c51d24c7 100644
--- a/drivers/xen/Kconfig
+++ b/drivers/xen/Kconfig
@@ -183,15 +183,17 @@ config XEN_ACPI_PROCESSOR
183 depends on XEN && X86 && ACPI_PROCESSOR && CPU_FREQ 183 depends on XEN && X86 && ACPI_PROCESSOR && CPU_FREQ
184 default m 184 default m
185 help 185 help
186 This ACPI processor uploads Power Management information to the Xen hypervisor. 186 This ACPI processor uploads Power Management information to the Xen
187 187 hypervisor.
188 To do that the driver parses the Power Management data and uploads said 188
189 information to the Xen hypervisor. Then the Xen hypervisor can select the 189 To do that the driver parses the Power Management data and uploads
190 proper Cx and Pxx states. It also registers itslef as the SMM so that 190 said information to the Xen hypervisor. Then the Xen hypervisor can
191 other drivers (such as ACPI cpufreq scaling driver) will not load. 191 select the proper Cx and Pxx states. It also registers itslef as the
192 192 SMM so that other drivers (such as ACPI cpufreq scaling driver) will
193 To compile this driver as a module, choose M here: the 193 not load.
194 module will be called xen_acpi_processor If you do not know what to choose, 194
195 select M here. If the CPUFREQ drivers are built in, select Y here. 195 To compile this driver as a module, choose M here: the module will be
196 called xen_acpi_processor If you do not know what to choose, select
197 M here. If the CPUFREQ drivers are built in, select Y here.
196 198
197endmenu 199endmenu
diff --git a/drivers/xen/events.c b/drivers/xen/events.c
index 4b33acd8ed4e..0a8a17cd80be 100644
--- a/drivers/xen/events.c
+++ b/drivers/xen/events.c
@@ -274,7 +274,7 @@ static unsigned int cpu_from_evtchn(unsigned int evtchn)
274 274
275static bool pirq_check_eoi_map(unsigned irq) 275static bool pirq_check_eoi_map(unsigned irq)
276{ 276{
277 return test_bit(irq, pirq_eoi_map); 277 return test_bit(pirq_from_irq(irq), pirq_eoi_map);
278} 278}
279 279
280static bool pirq_needs_eoi_flag(unsigned irq) 280static bool pirq_needs_eoi_flag(unsigned irq)
diff --git a/drivers/xen/gntdev.c b/drivers/xen/gntdev.c
index 99d8151c824a..1ffd03bf8e10 100644
--- a/drivers/xen/gntdev.c
+++ b/drivers/xen/gntdev.c
@@ -722,7 +722,7 @@ static int gntdev_mmap(struct file *flip, struct vm_area_struct *vma)
722 vma->vm_flags |= VM_RESERVED|VM_DONTEXPAND; 722 vma->vm_flags |= VM_RESERVED|VM_DONTEXPAND;
723 723
724 if (use_ptemod) 724 if (use_ptemod)
725 vma->vm_flags |= VM_DONTCOPY|VM_PFNMAP; 725 vma->vm_flags |= VM_DONTCOPY;
726 726
727 vma->vm_private_data = map; 727 vma->vm_private_data = map;
728 728
diff --git a/drivers/xen/grant-table.c b/drivers/xen/grant-table.c
index b4d4eac761db..f100ce20b16b 100644
--- a/drivers/xen/grant-table.c
+++ b/drivers/xen/grant-table.c
@@ -1029,6 +1029,7 @@ int gnttab_init(void)
1029 int i; 1029 int i;
1030 unsigned int max_nr_glist_frames, nr_glist_frames; 1030 unsigned int max_nr_glist_frames, nr_glist_frames;
1031 unsigned int nr_init_grefs; 1031 unsigned int nr_init_grefs;
1032 int ret;
1032 1033
1033 nr_grant_frames = 1; 1034 nr_grant_frames = 1;
1034 boot_max_nr_grant_frames = __max_nr_grant_frames(); 1035 boot_max_nr_grant_frames = __max_nr_grant_frames();
@@ -1047,12 +1048,16 @@ int gnttab_init(void)
1047 nr_glist_frames = (nr_grant_frames * GREFS_PER_GRANT_FRAME + RPP - 1) / RPP; 1048 nr_glist_frames = (nr_grant_frames * GREFS_PER_GRANT_FRAME + RPP - 1) / RPP;
1048 for (i = 0; i < nr_glist_frames; i++) { 1049 for (i = 0; i < nr_glist_frames; i++) {
1049 gnttab_list[i] = (grant_ref_t *)__get_free_page(GFP_KERNEL); 1050 gnttab_list[i] = (grant_ref_t *)__get_free_page(GFP_KERNEL);
1050 if (gnttab_list[i] == NULL) 1051 if (gnttab_list[i] == NULL) {
1052 ret = -ENOMEM;
1051 goto ini_nomem; 1053 goto ini_nomem;
1054 }
1052 } 1055 }
1053 1056
1054 if (gnttab_resume() < 0) 1057 if (gnttab_resume() < 0) {
1055 return -ENODEV; 1058 ret = -ENODEV;
1059 goto ini_nomem;
1060 }
1056 1061
1057 nr_init_grefs = nr_grant_frames * GREFS_PER_GRANT_FRAME; 1062 nr_init_grefs = nr_grant_frames * GREFS_PER_GRANT_FRAME;
1058 1063
@@ -1070,7 +1075,7 @@ int gnttab_init(void)
1070 for (i--; i >= 0; i--) 1075 for (i--; i >= 0; i--)
1071 free_page((unsigned long)gnttab_list[i]); 1076 free_page((unsigned long)gnttab_list[i]);
1072 kfree(gnttab_list); 1077 kfree(gnttab_list);
1073 return -ENOMEM; 1078 return ret;
1074} 1079}
1075EXPORT_SYMBOL_GPL(gnttab_init); 1080EXPORT_SYMBOL_GPL(gnttab_init);
1076 1081
diff --git a/drivers/xen/manage.c b/drivers/xen/manage.c
index 9e14ae6cd49c..412b96cc5305 100644
--- a/drivers/xen/manage.c
+++ b/drivers/xen/manage.c
@@ -132,6 +132,7 @@ static void do_suspend(void)
132 err = dpm_suspend_end(PMSG_FREEZE); 132 err = dpm_suspend_end(PMSG_FREEZE);
133 if (err) { 133 if (err) {
134 printk(KERN_ERR "dpm_suspend_end failed: %d\n", err); 134 printk(KERN_ERR "dpm_suspend_end failed: %d\n", err);
135 si.cancelled = 0;
135 goto out_resume; 136 goto out_resume;
136 } 137 }
137 138
diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
index 19e6a2041371..1afb4fba11b4 100644
--- a/drivers/xen/swiotlb-xen.c
+++ b/drivers/xen/swiotlb-xen.c
@@ -204,7 +204,8 @@ error:
204 204
205void * 205void *
206xen_swiotlb_alloc_coherent(struct device *hwdev, size_t size, 206xen_swiotlb_alloc_coherent(struct device *hwdev, size_t size,
207 dma_addr_t *dma_handle, gfp_t flags) 207 dma_addr_t *dma_handle, gfp_t flags,
208 struct dma_attrs *attrs)
208{ 209{
209 void *ret; 210 void *ret;
210 int order = get_order(size); 211 int order = get_order(size);
@@ -253,7 +254,7 @@ EXPORT_SYMBOL_GPL(xen_swiotlb_alloc_coherent);
253 254
254void 255void
255xen_swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr, 256xen_swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
256 dma_addr_t dev_addr) 257 dma_addr_t dev_addr, struct dma_attrs *attrs)
257{ 258{
258 int order = get_order(size); 259 int order = get_order(size);
259 phys_addr_t phys; 260 phys_addr_t phys;
diff --git a/drivers/xen/xen-acpi-processor.c b/drivers/xen/xen-acpi-processor.c
index 174b5653cd8a..0b48579a9cd6 100644
--- a/drivers/xen/xen-acpi-processor.c
+++ b/drivers/xen/xen-acpi-processor.c
@@ -128,7 +128,10 @@ static int push_cxx_to_hypervisor(struct acpi_processor *_pr)
128 pr_debug(" C%d: %s %d uS\n", 128 pr_debug(" C%d: %s %d uS\n",
129 cx->type, cx->desc, (u32)cx->latency); 129 cx->type, cx->desc, (u32)cx->latency);
130 } 130 }
131 } else 131 } else if (ret != -EINVAL)
132 /* EINVAL means the ACPI ID is incorrect - meaning the ACPI
133 * table is referencing a non-existing CPU - which can happen
134 * with broken ACPI tables. */
132 pr_err(DRV_NAME "(CX): Hypervisor error (%d) for ACPI CPU%u\n", 135 pr_err(DRV_NAME "(CX): Hypervisor error (%d) for ACPI CPU%u\n",
133 ret, _pr->acpi_id); 136 ret, _pr->acpi_id);
134 137
diff --git a/drivers/xen/xen-pciback/pciback_ops.c b/drivers/xen/xen-pciback/pciback_ops.c
index 63616d7453e6..97f5d264c31e 100644
--- a/drivers/xen/xen-pciback/pciback_ops.c
+++ b/drivers/xen/xen-pciback/pciback_ops.c
@@ -234,7 +234,7 @@ int xen_pcibk_enable_msix(struct xen_pcibk_device *pdev,
234 if (dev_data) 234 if (dev_data)
235 dev_data->ack_intr = 0; 235 dev_data->ack_intr = 0;
236 236
237 return result; 237 return result > 0 ? 0 : result;
238} 238}
239 239
240static 240static
diff --git a/drivers/xen/xenbus/xenbus_probe_frontend.c b/drivers/xen/xenbus/xenbus_probe_frontend.c
index f20c5f178b40..a31b54d48839 100644
--- a/drivers/xen/xenbus/xenbus_probe_frontend.c
+++ b/drivers/xen/xenbus/xenbus_probe_frontend.c
@@ -135,7 +135,7 @@ static int read_backend_details(struct xenbus_device *xendev)
135 return xenbus_read_otherend_details(xendev, "backend-id", "backend"); 135 return xenbus_read_otherend_details(xendev, "backend-id", "backend");
136} 136}
137 137
138static int is_device_connecting(struct device *dev, void *data) 138static int is_device_connecting(struct device *dev, void *data, bool ignore_nonessential)
139{ 139{
140 struct xenbus_device *xendev = to_xenbus_device(dev); 140 struct xenbus_device *xendev = to_xenbus_device(dev);
141 struct device_driver *drv = data; 141 struct device_driver *drv = data;
@@ -152,16 +152,41 @@ static int is_device_connecting(struct device *dev, void *data)
152 if (drv && (dev->driver != drv)) 152 if (drv && (dev->driver != drv))
153 return 0; 153 return 0;
154 154
155 if (ignore_nonessential) {
156 /* With older QEMU, for PVonHVM guests the guest config files
157 * could contain: vfb = [ 'vnc=1, vnclisten=0.0.0.0']
158 * which is nonsensical as there is no PV FB (there can be
159 * a PVKB) running as HVM guest. */
160
161 if ((strncmp(xendev->nodename, "device/vkbd", 11) == 0))
162 return 0;
163
164 if ((strncmp(xendev->nodename, "device/vfb", 10) == 0))
165 return 0;
166 }
155 xendrv = to_xenbus_driver(dev->driver); 167 xendrv = to_xenbus_driver(dev->driver);
156 return (xendev->state < XenbusStateConnected || 168 return (xendev->state < XenbusStateConnected ||
157 (xendev->state == XenbusStateConnected && 169 (xendev->state == XenbusStateConnected &&
158 xendrv->is_ready && !xendrv->is_ready(xendev))); 170 xendrv->is_ready && !xendrv->is_ready(xendev)));
159} 171}
172static int essential_device_connecting(struct device *dev, void *data)
173{
174 return is_device_connecting(dev, data, true /* ignore PV[KBB+FB] */);
175}
176static int non_essential_device_connecting(struct device *dev, void *data)
177{
178 return is_device_connecting(dev, data, false);
179}
160 180
161static int exists_connecting_device(struct device_driver *drv) 181static int exists_essential_connecting_device(struct device_driver *drv)
162{ 182{
163 return bus_for_each_dev(&xenbus_frontend.bus, NULL, drv, 183 return bus_for_each_dev(&xenbus_frontend.bus, NULL, drv,
164 is_device_connecting); 184 essential_device_connecting);
185}
186static int exists_non_essential_connecting_device(struct device_driver *drv)
187{
188 return bus_for_each_dev(&xenbus_frontend.bus, NULL, drv,
189 non_essential_device_connecting);
165} 190}
166 191
167static int print_device_status(struct device *dev, void *data) 192static int print_device_status(struct device *dev, void *data)
@@ -192,6 +217,23 @@ static int print_device_status(struct device *dev, void *data)
192/* We only wait for device setup after most initcalls have run. */ 217/* We only wait for device setup after most initcalls have run. */
193static int ready_to_wait_for_devices; 218static int ready_to_wait_for_devices;
194 219
220static bool wait_loop(unsigned long start, unsigned int max_delay,
221 unsigned int *seconds_waited)
222{
223 if (time_after(jiffies, start + (*seconds_waited+5)*HZ)) {
224 if (!*seconds_waited)
225 printk(KERN_WARNING "XENBUS: Waiting for "
226 "devices to initialise: ");
227 *seconds_waited += 5;
228 printk("%us...", max_delay - *seconds_waited);
229 if (*seconds_waited == max_delay)
230 return true;
231 }
232
233 schedule_timeout_interruptible(HZ/10);
234
235 return false;
236}
195/* 237/*
196 * On a 5-minute timeout, wait for all devices currently configured. We need 238 * On a 5-minute timeout, wait for all devices currently configured. We need
197 * to do this to guarantee that the filesystems and / or network devices 239 * to do this to guarantee that the filesystems and / or network devices
@@ -215,19 +257,14 @@ static void wait_for_devices(struct xenbus_driver *xendrv)
215 if (!ready_to_wait_for_devices || !xen_domain()) 257 if (!ready_to_wait_for_devices || !xen_domain())
216 return; 258 return;
217 259
218 while (exists_connecting_device(drv)) { 260 while (exists_non_essential_connecting_device(drv))
219 if (time_after(jiffies, start + (seconds_waited+5)*HZ)) { 261 if (wait_loop(start, 30, &seconds_waited))
220 if (!seconds_waited) 262 break;
221 printk(KERN_WARNING "XENBUS: Waiting for " 263
222 "devices to initialise: "); 264 /* Skips PVKB and PVFB check.*/
223 seconds_waited += 5; 265 while (exists_essential_connecting_device(drv))
224 printk("%us...", 300 - seconds_waited); 266 if (wait_loop(start, 270, &seconds_waited))
225 if (seconds_waited == 300) 267 break;
226 break;
227 }
228
229 schedule_timeout_interruptible(HZ/10);
230 }
231 268
232 if (seconds_waited) 269 if (seconds_waited)
233 printk("\n"); 270 printk("\n");
diff --git a/fs/aio.c b/fs/aio.c
index da887604dfc5..67a6db3e1b6f 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -93,9 +93,8 @@ static void aio_free_ring(struct kioctx *ctx)
93 put_page(info->ring_pages[i]); 93 put_page(info->ring_pages[i]);
94 94
95 if (info->mmap_size) { 95 if (info->mmap_size) {
96 down_write(&ctx->mm->mmap_sem); 96 BUG_ON(ctx->mm != current->mm);
97 do_munmap(ctx->mm, info->mmap_base, info->mmap_size); 97 vm_munmap(info->mmap_base, info->mmap_size);
98 up_write(&ctx->mm->mmap_sem);
99 } 98 }
100 99
101 if (info->ring_pages && info->ring_pages != info->internal_pages) 100 if (info->ring_pages && info->ring_pages != info->internal_pages)
@@ -389,6 +388,17 @@ void exit_aio(struct mm_struct *mm)
389 "exit_aio:ioctx still alive: %d %d %d\n", 388 "exit_aio:ioctx still alive: %d %d %d\n",
390 atomic_read(&ctx->users), ctx->dead, 389 atomic_read(&ctx->users), ctx->dead,
391 ctx->reqs_active); 390 ctx->reqs_active);
391 /*
392 * We don't need to bother with munmap() here -
393 * exit_mmap(mm) is coming and it'll unmap everything.
394 * Since aio_free_ring() uses non-zero ->mmap_size
395 * as indicator that it needs to unmap the area,
396 * just set it to 0; aio_free_ring() is the only
397 * place that uses ->mmap_size, so it's safe.
398 * That way we get all munmap done to current->mm -
399 * all other callers have ctx->mm == current->mm.
400 */
401 ctx->ring_info.mmap_size = 0;
392 put_ioctx(ctx); 402 put_ioctx(ctx);
393 } 403 }
394} 404}
diff --git a/fs/autofs4/autofs_i.h b/fs/autofs4/autofs_i.h
index eb1cc92cd67d..908e18455413 100644
--- a/fs/autofs4/autofs_i.h
+++ b/fs/autofs4/autofs_i.h
@@ -110,7 +110,6 @@ struct autofs_sb_info {
110 int sub_version; 110 int sub_version;
111 int min_proto; 111 int min_proto;
112 int max_proto; 112 int max_proto;
113 int compat_daemon;
114 unsigned long exp_timeout; 113 unsigned long exp_timeout;
115 unsigned int type; 114 unsigned int type;
116 int reghost_enabled; 115 int reghost_enabled;
@@ -270,6 +269,17 @@ int autofs4_fill_super(struct super_block *, void *, int);
270struct autofs_info *autofs4_new_ino(struct autofs_sb_info *); 269struct autofs_info *autofs4_new_ino(struct autofs_sb_info *);
271void autofs4_clean_ino(struct autofs_info *); 270void autofs4_clean_ino(struct autofs_info *);
272 271
272static inline int autofs_prepare_pipe(struct file *pipe)
273{
274 if (!pipe->f_op || !pipe->f_op->write)
275 return -EINVAL;
276 if (!S_ISFIFO(pipe->f_dentry->d_inode->i_mode))
277 return -EINVAL;
278 /* We want a packet pipe */
279 pipe->f_flags |= O_DIRECT;
280 return 0;
281}
282
273/* Queue management functions */ 283/* Queue management functions */
274 284
275int autofs4_wait(struct autofs_sb_info *,struct dentry *, enum autofs_notify); 285int autofs4_wait(struct autofs_sb_info *,struct dentry *, enum autofs_notify);
diff --git a/fs/autofs4/dev-ioctl.c b/fs/autofs4/dev-ioctl.c
index 9dacb8586701..aa9103f8f01b 100644
--- a/fs/autofs4/dev-ioctl.c
+++ b/fs/autofs4/dev-ioctl.c
@@ -376,7 +376,7 @@ static int autofs_dev_ioctl_setpipefd(struct file *fp,
376 err = -EBADF; 376 err = -EBADF;
377 goto out; 377 goto out;
378 } 378 }
379 if (!pipe->f_op || !pipe->f_op->write) { 379 if (autofs_prepare_pipe(pipe) < 0) {
380 err = -EPIPE; 380 err = -EPIPE;
381 fput(pipe); 381 fput(pipe);
382 goto out; 382 goto out;
@@ -385,7 +385,6 @@ static int autofs_dev_ioctl_setpipefd(struct file *fp,
385 sbi->pipefd = pipefd; 385 sbi->pipefd = pipefd;
386 sbi->pipe = pipe; 386 sbi->pipe = pipe;
387 sbi->catatonic = 0; 387 sbi->catatonic = 0;
388 sbi->compat_daemon = is_compat_task();
389 } 388 }
390out: 389out:
391 mutex_unlock(&sbi->wq_mutex); 390 mutex_unlock(&sbi->wq_mutex);
diff --git a/fs/autofs4/inode.c b/fs/autofs4/inode.c
index d8dc002e9cc3..6e488ebe7784 100644
--- a/fs/autofs4/inode.c
+++ b/fs/autofs4/inode.c
@@ -19,7 +19,6 @@
19#include <linux/parser.h> 19#include <linux/parser.h>
20#include <linux/bitops.h> 20#include <linux/bitops.h>
21#include <linux/magic.h> 21#include <linux/magic.h>
22#include <linux/compat.h>
23#include "autofs_i.h" 22#include "autofs_i.h"
24#include <linux/module.h> 23#include <linux/module.h>
25 24
@@ -225,7 +224,6 @@ int autofs4_fill_super(struct super_block *s, void *data, int silent)
225 set_autofs_type_indirect(&sbi->type); 224 set_autofs_type_indirect(&sbi->type);
226 sbi->min_proto = 0; 225 sbi->min_proto = 0;
227 sbi->max_proto = 0; 226 sbi->max_proto = 0;
228 sbi->compat_daemon = is_compat_task();
229 mutex_init(&sbi->wq_mutex); 227 mutex_init(&sbi->wq_mutex);
230 mutex_init(&sbi->pipe_mutex); 228 mutex_init(&sbi->pipe_mutex);
231 spin_lock_init(&sbi->fs_lock); 229 spin_lock_init(&sbi->fs_lock);
@@ -292,7 +290,7 @@ int autofs4_fill_super(struct super_block *s, void *data, int silent)
292 printk("autofs: could not open pipe file descriptor\n"); 290 printk("autofs: could not open pipe file descriptor\n");
293 goto fail_dput; 291 goto fail_dput;
294 } 292 }
295 if (!pipe->f_op || !pipe->f_op->write) 293 if (autofs_prepare_pipe(pipe) < 0)
296 goto fail_fput; 294 goto fail_fput;
297 sbi->pipe = pipe; 295 sbi->pipe = pipe;
298 sbi->pipefd = pipefd; 296 sbi->pipefd = pipefd;
diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
index 9c098db43344..da8876d38a7b 100644
--- a/fs/autofs4/waitq.c
+++ b/fs/autofs4/waitq.c
@@ -91,24 +91,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
91 91
92 return (bytes > 0); 92 return (bytes > 0);
93} 93}
94 94
95/*
96 * The autofs_v5 packet was misdesigned.
97 *
98 * The packets are identical on x86-32 and x86-64, but have different
99 * alignment. Which means that 'sizeof()' will give different results.
100 * Fix it up for the case of running 32-bit user mode on a 64-bit kernel.
101 */
102static noinline size_t autofs_v5_packet_size(struct autofs_sb_info *sbi)
103{
104 size_t pktsz = sizeof(struct autofs_v5_packet);
105#if defined(CONFIG_X86_64) && defined(CONFIG_COMPAT)
106 if (sbi->compat_daemon > 0)
107 pktsz -= 4;
108#endif
109 return pktsz;
110}
111
112static void autofs4_notify_daemon(struct autofs_sb_info *sbi, 95static void autofs4_notify_daemon(struct autofs_sb_info *sbi,
113 struct autofs_wait_queue *wq, 96 struct autofs_wait_queue *wq,
114 int type) 97 int type)
@@ -172,7 +155,8 @@ static void autofs4_notify_daemon(struct autofs_sb_info *sbi,
172 { 155 {
173 struct autofs_v5_packet *packet = &pkt.v5_pkt.v5_packet; 156 struct autofs_v5_packet *packet = &pkt.v5_pkt.v5_packet;
174 157
175 pktsz = autofs_v5_packet_size(sbi); 158 pktsz = sizeof(*packet);
159
176 packet->wait_queue_token = wq->wait_queue_token; 160 packet->wait_queue_token = wq->wait_queue_token;
177 packet->len = wq->name.len; 161 packet->len = wq->name.len;
178 memcpy(packet->name, wq->name.name, wq->name.len); 162 memcpy(packet->name, wq->name.name, wq->name.len);
diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
index 2eb12f13593d..d146e181d10d 100644
--- a/fs/binfmt_aout.c
+++ b/fs/binfmt_aout.c
@@ -50,9 +50,7 @@ static int set_brk(unsigned long start, unsigned long end)
50 end = PAGE_ALIGN(end); 50 end = PAGE_ALIGN(end);
51 if (end > start) { 51 if (end > start) {
52 unsigned long addr; 52 unsigned long addr;
53 down_write(&current->mm->mmap_sem); 53 addr = vm_brk(start, end - start);
54 addr = do_brk(start, end - start);
55 up_write(&current->mm->mmap_sem);
56 if (BAD_ADDR(addr)) 54 if (BAD_ADDR(addr))
57 return addr; 55 return addr;
58 } 56 }
@@ -280,9 +278,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
280 pos = 32; 278 pos = 32;
281 map_size = ex.a_text+ex.a_data; 279 map_size = ex.a_text+ex.a_data;
282#endif 280#endif
283 down_write(&current->mm->mmap_sem); 281 error = vm_brk(text_addr & PAGE_MASK, map_size);
284 error = do_brk(text_addr & PAGE_MASK, map_size);
285 up_write(&current->mm->mmap_sem);
286 if (error != (text_addr & PAGE_MASK)) { 282 if (error != (text_addr & PAGE_MASK)) {
287 send_sig(SIGKILL, current, 0); 283 send_sig(SIGKILL, current, 0);
288 return error; 284 return error;
@@ -313,9 +309,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
313 309
314 if (!bprm->file->f_op->mmap||((fd_offset & ~PAGE_MASK) != 0)) { 310 if (!bprm->file->f_op->mmap||((fd_offset & ~PAGE_MASK) != 0)) {
315 loff_t pos = fd_offset; 311 loff_t pos = fd_offset;
316 down_write(&current->mm->mmap_sem); 312 vm_brk(N_TXTADDR(ex), ex.a_text+ex.a_data);
317 do_brk(N_TXTADDR(ex), ex.a_text+ex.a_data);
318 up_write(&current->mm->mmap_sem);
319 bprm->file->f_op->read(bprm->file, 313 bprm->file->f_op->read(bprm->file,
320 (char __user *)N_TXTADDR(ex), 314 (char __user *)N_TXTADDR(ex),
321 ex.a_text+ex.a_data, &pos); 315 ex.a_text+ex.a_data, &pos);
@@ -325,24 +319,20 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
325 goto beyond_if; 319 goto beyond_if;
326 } 320 }
327 321
328 down_write(&current->mm->mmap_sem); 322 error = vm_mmap(bprm->file, N_TXTADDR(ex), ex.a_text,
329 error = do_mmap(bprm->file, N_TXTADDR(ex), ex.a_text,
330 PROT_READ | PROT_EXEC, 323 PROT_READ | PROT_EXEC,
331 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE, 324 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
332 fd_offset); 325 fd_offset);
333 up_write(&current->mm->mmap_sem);
334 326
335 if (error != N_TXTADDR(ex)) { 327 if (error != N_TXTADDR(ex)) {
336 send_sig(SIGKILL, current, 0); 328 send_sig(SIGKILL, current, 0);
337 return error; 329 return error;
338 } 330 }
339 331
340 down_write(&current->mm->mmap_sem); 332 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
341 error = do_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
342 PROT_READ | PROT_WRITE | PROT_EXEC, 333 PROT_READ | PROT_WRITE | PROT_EXEC,
343 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE, 334 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
344 fd_offset + ex.a_text); 335 fd_offset + ex.a_text);
345 up_write(&current->mm->mmap_sem);
346 if (error != N_DATADDR(ex)) { 336 if (error != N_DATADDR(ex)) {
347 send_sig(SIGKILL, current, 0); 337 send_sig(SIGKILL, current, 0);
348 return error; 338 return error;
@@ -412,9 +402,7 @@ static int load_aout_library(struct file *file)
412 "N_TXTOFF is not page aligned. Please convert library: %s\n", 402 "N_TXTOFF is not page aligned. Please convert library: %s\n",
413 file->f_path.dentry->d_name.name); 403 file->f_path.dentry->d_name.name);
414 } 404 }
415 down_write(&current->mm->mmap_sem); 405 vm_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss);
416 do_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss);
417 up_write(&current->mm->mmap_sem);
418 406
419 file->f_op->read(file, (char __user *)start_addr, 407 file->f_op->read(file, (char __user *)start_addr,
420 ex.a_text + ex.a_data, &pos); 408 ex.a_text + ex.a_data, &pos);
@@ -425,12 +413,10 @@ static int load_aout_library(struct file *file)
425 goto out; 413 goto out;
426 } 414 }
427 /* Now use mmap to map the library into memory. */ 415 /* Now use mmap to map the library into memory. */
428 down_write(&current->mm->mmap_sem); 416 error = vm_mmap(file, start_addr, ex.a_text + ex.a_data,
429 error = do_mmap(file, start_addr, ex.a_text + ex.a_data,
430 PROT_READ | PROT_WRITE | PROT_EXEC, 417 PROT_READ | PROT_WRITE | PROT_EXEC,
431 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE, 418 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE,
432 N_TXTOFF(ex)); 419 N_TXTOFF(ex));
433 up_write(&current->mm->mmap_sem);
434 retval = error; 420 retval = error;
435 if (error != start_addr) 421 if (error != start_addr)
436 goto out; 422 goto out;
@@ -438,9 +424,7 @@ static int load_aout_library(struct file *file)
438 len = PAGE_ALIGN(ex.a_text + ex.a_data); 424 len = PAGE_ALIGN(ex.a_text + ex.a_data);
439 bss = ex.a_text + ex.a_data + ex.a_bss; 425 bss = ex.a_text + ex.a_data + ex.a_bss;
440 if (bss > len) { 426 if (bss > len) {
441 down_write(&current->mm->mmap_sem); 427 error = vm_brk(start_addr + len, bss - len);
442 error = do_brk(start_addr + len, bss - len);
443 up_write(&current->mm->mmap_sem);
444 retval = error; 428 retval = error;
445 if (error != start_addr + len) 429 if (error != start_addr + len)
446 goto out; 430 goto out;
diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index 48ffb3dc610a..16f735417072 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -82,9 +82,7 @@ static int set_brk(unsigned long start, unsigned long end)
82 end = ELF_PAGEALIGN(end); 82 end = ELF_PAGEALIGN(end);
83 if (end > start) { 83 if (end > start) {
84 unsigned long addr; 84 unsigned long addr;
85 down_write(&current->mm->mmap_sem); 85 addr = vm_brk(start, end - start);
86 addr = do_brk(start, end - start);
87 up_write(&current->mm->mmap_sem);
88 if (BAD_ADDR(addr)) 86 if (BAD_ADDR(addr))
89 return addr; 87 return addr;
90 } 88 }
@@ -514,9 +512,7 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
514 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1); 512 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
515 513
516 /* Map the last of the bss segment */ 514 /* Map the last of the bss segment */
517 down_write(&current->mm->mmap_sem); 515 error = vm_brk(elf_bss, last_bss - elf_bss);
518 error = do_brk(elf_bss, last_bss - elf_bss);
519 up_write(&current->mm->mmap_sem);
520 if (BAD_ADDR(error)) 516 if (BAD_ADDR(error))
521 goto out_close; 517 goto out_close;
522 } 518 }
@@ -962,10 +958,8 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
962 and some applications "depend" upon this behavior. 958 and some applications "depend" upon this behavior.
963 Since we do not have the power to recompile these, we 959 Since we do not have the power to recompile these, we
964 emulate the SVr4 behavior. Sigh. */ 960 emulate the SVr4 behavior. Sigh. */
965 down_write(&current->mm->mmap_sem); 961 error = vm_mmap(NULL, 0, PAGE_SIZE, PROT_READ | PROT_EXEC,
966 error = do_mmap(NULL, 0, PAGE_SIZE, PROT_READ | PROT_EXEC,
967 MAP_FIXED | MAP_PRIVATE, 0); 962 MAP_FIXED | MAP_PRIVATE, 0);
968 up_write(&current->mm->mmap_sem);
969 } 963 }
970 964
971#ifdef ELF_PLAT_INIT 965#ifdef ELF_PLAT_INIT
@@ -1050,8 +1044,7 @@ static int load_elf_library(struct file *file)
1050 eppnt++; 1044 eppnt++;
1051 1045
1052 /* Now use mmap to map the library into memory. */ 1046 /* Now use mmap to map the library into memory. */
1053 down_write(&current->mm->mmap_sem); 1047 error = vm_mmap(file,
1054 error = do_mmap(file,
1055 ELF_PAGESTART(eppnt->p_vaddr), 1048 ELF_PAGESTART(eppnt->p_vaddr),
1056 (eppnt->p_filesz + 1049 (eppnt->p_filesz +
1057 ELF_PAGEOFFSET(eppnt->p_vaddr)), 1050 ELF_PAGEOFFSET(eppnt->p_vaddr)),
@@ -1059,7 +1052,6 @@ static int load_elf_library(struct file *file)
1059 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE, 1052 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE,
1060 (eppnt->p_offset - 1053 (eppnt->p_offset -
1061 ELF_PAGEOFFSET(eppnt->p_vaddr))); 1054 ELF_PAGEOFFSET(eppnt->p_vaddr)));
1062 up_write(&current->mm->mmap_sem);
1063 if (error != ELF_PAGESTART(eppnt->p_vaddr)) 1055 if (error != ELF_PAGESTART(eppnt->p_vaddr))
1064 goto out_free_ph; 1056 goto out_free_ph;
1065 1057
@@ -1072,11 +1064,8 @@ static int load_elf_library(struct file *file)
1072 len = ELF_PAGESTART(eppnt->p_filesz + eppnt->p_vaddr + 1064 len = ELF_PAGESTART(eppnt->p_filesz + eppnt->p_vaddr +
1073 ELF_MIN_ALIGN - 1); 1065 ELF_MIN_ALIGN - 1);
1074 bss = eppnt->p_memsz + eppnt->p_vaddr; 1066 bss = eppnt->p_memsz + eppnt->p_vaddr;
1075 if (bss > len) { 1067 if (bss > len)
1076 down_write(&current->mm->mmap_sem); 1068 vm_brk(len, bss - len);
1077 do_brk(len, bss - len);
1078 up_write(&current->mm->mmap_sem);
1079 }
1080 error = 0; 1069 error = 0;
1081 1070
1082out_free_ph: 1071out_free_ph:
diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c
index 9bd5612a8224..d390a0fffc65 100644
--- a/fs/binfmt_elf_fdpic.c
+++ b/fs/binfmt_elf_fdpic.c
@@ -390,21 +390,17 @@ static int load_elf_fdpic_binary(struct linux_binprm *bprm,
390 (executable_stack == EXSTACK_DEFAULT && VM_STACK_FLAGS & VM_EXEC)) 390 (executable_stack == EXSTACK_DEFAULT && VM_STACK_FLAGS & VM_EXEC))
391 stack_prot |= PROT_EXEC; 391 stack_prot |= PROT_EXEC;
392 392
393 down_write(&current->mm->mmap_sem); 393 current->mm->start_brk = vm_mmap(NULL, 0, stack_size, stack_prot,
394 current->mm->start_brk = do_mmap(NULL, 0, stack_size, stack_prot,
395 MAP_PRIVATE | MAP_ANONYMOUS | 394 MAP_PRIVATE | MAP_ANONYMOUS |
396 MAP_UNINITIALIZED | MAP_GROWSDOWN, 395 MAP_UNINITIALIZED | MAP_GROWSDOWN,
397 0); 396 0);
398 397
399 if (IS_ERR_VALUE(current->mm->start_brk)) { 398 if (IS_ERR_VALUE(current->mm->start_brk)) {
400 up_write(&current->mm->mmap_sem);
401 retval = current->mm->start_brk; 399 retval = current->mm->start_brk;
402 current->mm->start_brk = 0; 400 current->mm->start_brk = 0;
403 goto error_kill; 401 goto error_kill;
404 } 402 }
405 403
406 up_write(&current->mm->mmap_sem);
407
408 current->mm->brk = current->mm->start_brk; 404 current->mm->brk = current->mm->start_brk;
409 current->mm->context.end_brk = current->mm->start_brk; 405 current->mm->context.end_brk = current->mm->start_brk;
410 current->mm->context.end_brk += 406 current->mm->context.end_brk +=
@@ -955,10 +951,8 @@ static int elf_fdpic_map_file_constdisp_on_uclinux(
955 if (params->flags & ELF_FDPIC_FLAG_EXECUTABLE) 951 if (params->flags & ELF_FDPIC_FLAG_EXECUTABLE)
956 mflags |= MAP_EXECUTABLE; 952 mflags |= MAP_EXECUTABLE;
957 953
958 down_write(&mm->mmap_sem); 954 maddr = vm_mmap(NULL, load_addr, top - base,
959 maddr = do_mmap(NULL, load_addr, top - base,
960 PROT_READ | PROT_WRITE | PROT_EXEC, mflags, 0); 955 PROT_READ | PROT_WRITE | PROT_EXEC, mflags, 0);
961 up_write(&mm->mmap_sem);
962 if (IS_ERR_VALUE(maddr)) 956 if (IS_ERR_VALUE(maddr))
963 return (int) maddr; 957 return (int) maddr;
964 958
@@ -1096,10 +1090,8 @@ static int elf_fdpic_map_file_by_direct_mmap(struct elf_fdpic_params *params,
1096 1090
1097 /* create the mapping */ 1091 /* create the mapping */
1098 disp = phdr->p_vaddr & ~PAGE_MASK; 1092 disp = phdr->p_vaddr & ~PAGE_MASK;
1099 down_write(&mm->mmap_sem); 1093 maddr = vm_mmap(file, maddr, phdr->p_memsz + disp, prot, flags,
1100 maddr = do_mmap(file, maddr, phdr->p_memsz + disp, prot, flags,
1101 phdr->p_offset - disp); 1094 phdr->p_offset - disp);
1102 up_write(&mm->mmap_sem);
1103 1095
1104 kdebug("mmap[%d] <file> sz=%lx pr=%x fl=%x of=%lx --> %08lx", 1096 kdebug("mmap[%d] <file> sz=%lx pr=%x fl=%x of=%lx --> %08lx",
1105 loop, phdr->p_memsz + disp, prot, flags, 1097 loop, phdr->p_memsz + disp, prot, flags,
@@ -1143,10 +1135,8 @@ static int elf_fdpic_map_file_by_direct_mmap(struct elf_fdpic_params *params,
1143 unsigned long xmaddr; 1135 unsigned long xmaddr;
1144 1136
1145 flags |= MAP_FIXED | MAP_ANONYMOUS; 1137 flags |= MAP_FIXED | MAP_ANONYMOUS;
1146 down_write(&mm->mmap_sem); 1138 xmaddr = vm_mmap(NULL, xaddr, excess - excess1,
1147 xmaddr = do_mmap(NULL, xaddr, excess - excess1,
1148 prot, flags, 0); 1139 prot, flags, 0);
1149 up_write(&mm->mmap_sem);
1150 1140
1151 kdebug("mmap[%d] <anon>" 1141 kdebug("mmap[%d] <anon>"
1152 " ad=%lx sz=%lx pr=%x fl=%x of=0 --> %08lx", 1142 " ad=%lx sz=%lx pr=%x fl=%x of=0 --> %08lx",
diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
index 024d20ee3ca3..6b2daf99fab8 100644
--- a/fs/binfmt_flat.c
+++ b/fs/binfmt_flat.c
@@ -542,10 +542,8 @@ static int load_flat_file(struct linux_binprm * bprm,
542 */ 542 */
543 DBG_FLT("BINFMT_FLAT: ROM mapping of file (we hope)\n"); 543 DBG_FLT("BINFMT_FLAT: ROM mapping of file (we hope)\n");
544 544
545 down_write(&current->mm->mmap_sem); 545 textpos = vm_mmap(bprm->file, 0, text_len, PROT_READ|PROT_EXEC,
546 textpos = do_mmap(bprm->file, 0, text_len, PROT_READ|PROT_EXEC,
547 MAP_PRIVATE|MAP_EXECUTABLE, 0); 546 MAP_PRIVATE|MAP_EXECUTABLE, 0);
548 up_write(&current->mm->mmap_sem);
549 if (!textpos || IS_ERR_VALUE(textpos)) { 547 if (!textpos || IS_ERR_VALUE(textpos)) {
550 if (!textpos) 548 if (!textpos)
551 textpos = (unsigned long) -ENOMEM; 549 textpos = (unsigned long) -ENOMEM;
@@ -556,10 +554,8 @@ static int load_flat_file(struct linux_binprm * bprm,
556 554
557 len = data_len + extra + MAX_SHARED_LIBS * sizeof(unsigned long); 555 len = data_len + extra + MAX_SHARED_LIBS * sizeof(unsigned long);
558 len = PAGE_ALIGN(len); 556 len = PAGE_ALIGN(len);
559 down_write(&current->mm->mmap_sem); 557 realdatastart = vm_mmap(0, 0, len,
560 realdatastart = do_mmap(0, 0, len,
561 PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE, 0); 558 PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE, 0);
562 up_write(&current->mm->mmap_sem);
563 559
564 if (realdatastart == 0 || IS_ERR_VALUE(realdatastart)) { 560 if (realdatastart == 0 || IS_ERR_VALUE(realdatastart)) {
565 if (!realdatastart) 561 if (!realdatastart)
@@ -603,10 +599,8 @@ static int load_flat_file(struct linux_binprm * bprm,
603 599
604 len = text_len + data_len + extra + MAX_SHARED_LIBS * sizeof(unsigned long); 600 len = text_len + data_len + extra + MAX_SHARED_LIBS * sizeof(unsigned long);
605 len = PAGE_ALIGN(len); 601 len = PAGE_ALIGN(len);
606 down_write(&current->mm->mmap_sem); 602 textpos = vm_mmap(0, 0, len,
607 textpos = do_mmap(0, 0, len,
608 PROT_READ | PROT_EXEC | PROT_WRITE, MAP_PRIVATE, 0); 603 PROT_READ | PROT_EXEC | PROT_WRITE, MAP_PRIVATE, 0);
609 up_write(&current->mm->mmap_sem);
610 604
611 if (!textpos || IS_ERR_VALUE(textpos)) { 605 if (!textpos || IS_ERR_VALUE(textpos)) {
612 if (!textpos) 606 if (!textpos)
diff --git a/fs/binfmt_som.c b/fs/binfmt_som.c
index e4fc746629a7..4517aaff61b4 100644
--- a/fs/binfmt_som.c
+++ b/fs/binfmt_som.c
@@ -147,10 +147,8 @@ static int map_som_binary(struct file *file,
147 code_size = SOM_PAGEALIGN(hpuxhdr->exec_tsize); 147 code_size = SOM_PAGEALIGN(hpuxhdr->exec_tsize);
148 current->mm->start_code = code_start; 148 current->mm->start_code = code_start;
149 current->mm->end_code = code_start + code_size; 149 current->mm->end_code = code_start + code_size;
150 down_write(&current->mm->mmap_sem); 150 retval = vm_mmap(file, code_start, code_size, prot,
151 retval = do_mmap(file, code_start, code_size, prot,
152 flags, SOM_PAGESTART(hpuxhdr->exec_tfile)); 151 flags, SOM_PAGESTART(hpuxhdr->exec_tfile));
153 up_write(&current->mm->mmap_sem);
154 if (retval < 0 && retval > -1024) 152 if (retval < 0 && retval > -1024)
155 goto out; 153 goto out;
156 154
@@ -158,20 +156,16 @@ static int map_som_binary(struct file *file,
158 data_size = SOM_PAGEALIGN(hpuxhdr->exec_dsize); 156 data_size = SOM_PAGEALIGN(hpuxhdr->exec_dsize);
159 current->mm->start_data = data_start; 157 current->mm->start_data = data_start;
160 current->mm->end_data = bss_start = data_start + data_size; 158 current->mm->end_data = bss_start = data_start + data_size;
161 down_write(&current->mm->mmap_sem); 159 retval = vm_mmap(file, data_start, data_size,
162 retval = do_mmap(file, data_start, data_size,
163 prot | PROT_WRITE, flags, 160 prot | PROT_WRITE, flags,
164 SOM_PAGESTART(hpuxhdr->exec_dfile)); 161 SOM_PAGESTART(hpuxhdr->exec_dfile));
165 up_write(&current->mm->mmap_sem);
166 if (retval < 0 && retval > -1024) 162 if (retval < 0 && retval > -1024)
167 goto out; 163 goto out;
168 164
169 som_brk = bss_start + SOM_PAGEALIGN(hpuxhdr->exec_bsize); 165 som_brk = bss_start + SOM_PAGEALIGN(hpuxhdr->exec_bsize);
170 current->mm->start_brk = current->mm->brk = som_brk; 166 current->mm->start_brk = current->mm->brk = som_brk;
171 down_write(&current->mm->mmap_sem); 167 retval = vm_mmap(NULL, bss_start, som_brk - bss_start,
172 retval = do_mmap(NULL, bss_start, som_brk - bss_start,
173 prot | PROT_WRITE, MAP_FIXED | MAP_PRIVATE, 0); 168 prot | PROT_WRITE, MAP_FIXED | MAP_PRIVATE, 0);
174 up_write(&current->mm->mmap_sem);
175 if (retval > 0 || retval < -1024) 169 if (retval > 0 || retval < -1024)
176 retval = 0; 170 retval = 0;
177out: 171out:
diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c
index f4e90748940a..bcec06750232 100644
--- a/fs/btrfs/backref.c
+++ b/fs/btrfs/backref.c
@@ -22,6 +22,7 @@
22#include "ulist.h" 22#include "ulist.h"
23#include "transaction.h" 23#include "transaction.h"
24#include "delayed-ref.h" 24#include "delayed-ref.h"
25#include "locking.h"
25 26
26/* 27/*
27 * this structure records all encountered refs on the way up to the root 28 * this structure records all encountered refs on the way up to the root
@@ -893,18 +894,22 @@ static char *iref_to_path(struct btrfs_root *fs_root, struct btrfs_path *path,
893 s64 bytes_left = size - 1; 894 s64 bytes_left = size - 1;
894 struct extent_buffer *eb = eb_in; 895 struct extent_buffer *eb = eb_in;
895 struct btrfs_key found_key; 896 struct btrfs_key found_key;
897 int leave_spinning = path->leave_spinning;
896 898
897 if (bytes_left >= 0) 899 if (bytes_left >= 0)
898 dest[bytes_left] = '\0'; 900 dest[bytes_left] = '\0';
899 901
902 path->leave_spinning = 1;
900 while (1) { 903 while (1) {
901 len = btrfs_inode_ref_name_len(eb, iref); 904 len = btrfs_inode_ref_name_len(eb, iref);
902 bytes_left -= len; 905 bytes_left -= len;
903 if (bytes_left >= 0) 906 if (bytes_left >= 0)
904 read_extent_buffer(eb, dest + bytes_left, 907 read_extent_buffer(eb, dest + bytes_left,
905 (unsigned long)(iref + 1), len); 908 (unsigned long)(iref + 1), len);
906 if (eb != eb_in) 909 if (eb != eb_in) {
910 btrfs_tree_read_unlock_blocking(eb);
907 free_extent_buffer(eb); 911 free_extent_buffer(eb);
912 }
908 ret = inode_ref_info(parent, 0, fs_root, path, &found_key); 913 ret = inode_ref_info(parent, 0, fs_root, path, &found_key);
909 if (ret > 0) 914 if (ret > 0)
910 ret = -ENOENT; 915 ret = -ENOENT;
@@ -919,8 +924,11 @@ static char *iref_to_path(struct btrfs_root *fs_root, struct btrfs_path *path,
919 slot = path->slots[0]; 924 slot = path->slots[0];
920 eb = path->nodes[0]; 925 eb = path->nodes[0];
921 /* make sure we can use eb after releasing the path */ 926 /* make sure we can use eb after releasing the path */
922 if (eb != eb_in) 927 if (eb != eb_in) {
923 atomic_inc(&eb->refs); 928 atomic_inc(&eb->refs);
929 btrfs_tree_read_lock(eb);
930 btrfs_set_lock_blocking_rw(eb, BTRFS_READ_LOCK);
931 }
924 btrfs_release_path(path); 932 btrfs_release_path(path);
925 933
926 iref = btrfs_item_ptr(eb, slot, struct btrfs_inode_ref); 934 iref = btrfs_item_ptr(eb, slot, struct btrfs_inode_ref);
@@ -931,6 +939,7 @@ static char *iref_to_path(struct btrfs_root *fs_root, struct btrfs_path *path,
931 } 939 }
932 940
933 btrfs_release_path(path); 941 btrfs_release_path(path);
942 path->leave_spinning = leave_spinning;
934 943
935 if (ret) 944 if (ret)
936 return ERR_PTR(ret); 945 return ERR_PTR(ret);
@@ -1247,7 +1256,7 @@ static int iterate_irefs(u64 inum, struct btrfs_root *fs_root,
1247 struct btrfs_path *path, 1256 struct btrfs_path *path,
1248 iterate_irefs_t *iterate, void *ctx) 1257 iterate_irefs_t *iterate, void *ctx)
1249{ 1258{
1250 int ret; 1259 int ret = 0;
1251 int slot; 1260 int slot;
1252 u32 cur; 1261 u32 cur;
1253 u32 len; 1262 u32 len;
@@ -1259,7 +1268,8 @@ static int iterate_irefs(u64 inum, struct btrfs_root *fs_root,
1259 struct btrfs_inode_ref *iref; 1268 struct btrfs_inode_ref *iref;
1260 struct btrfs_key found_key; 1269 struct btrfs_key found_key;
1261 1270
1262 while (1) { 1271 while (!ret) {
1272 path->leave_spinning = 1;
1263 ret = inode_ref_info(inum, parent ? parent+1 : 0, fs_root, path, 1273 ret = inode_ref_info(inum, parent ? parent+1 : 0, fs_root, path,
1264 &found_key); 1274 &found_key);
1265 if (ret < 0) 1275 if (ret < 0)
@@ -1275,6 +1285,8 @@ static int iterate_irefs(u64 inum, struct btrfs_root *fs_root,
1275 eb = path->nodes[0]; 1285 eb = path->nodes[0];
1276 /* make sure we can use eb after releasing the path */ 1286 /* make sure we can use eb after releasing the path */
1277 atomic_inc(&eb->refs); 1287 atomic_inc(&eb->refs);
1288 btrfs_tree_read_lock(eb);
1289 btrfs_set_lock_blocking_rw(eb, BTRFS_READ_LOCK);
1278 btrfs_release_path(path); 1290 btrfs_release_path(path);
1279 1291
1280 item = btrfs_item_nr(eb, slot); 1292 item = btrfs_item_nr(eb, slot);
@@ -1288,13 +1300,12 @@ static int iterate_irefs(u64 inum, struct btrfs_root *fs_root,
1288 (unsigned long long)found_key.objectid, 1300 (unsigned long long)found_key.objectid,
1289 (unsigned long long)fs_root->objectid); 1301 (unsigned long long)fs_root->objectid);
1290 ret = iterate(parent, iref, eb, ctx); 1302 ret = iterate(parent, iref, eb, ctx);
1291 if (ret) { 1303 if (ret)
1292 free_extent_buffer(eb);
1293 break; 1304 break;
1294 }
1295 len = sizeof(*iref) + name_len; 1305 len = sizeof(*iref) + name_len;
1296 iref = (struct btrfs_inode_ref *)((char *)iref + len); 1306 iref = (struct btrfs_inode_ref *)((char *)iref + len);
1297 } 1307 }
1308 btrfs_tree_read_unlock_blocking(eb);
1298 free_extent_buffer(eb); 1309 free_extent_buffer(eb);
1299 } 1310 }
1300 1311
@@ -1414,6 +1425,8 @@ struct inode_fs_paths *init_ipath(s32 total_bytes, struct btrfs_root *fs_root,
1414 1425
1415void free_ipath(struct inode_fs_paths *ipath) 1426void free_ipath(struct inode_fs_paths *ipath)
1416{ 1427{
1428 if (!ipath)
1429 return;
1417 kfree(ipath->fspath); 1430 kfree(ipath->fspath);
1418 kfree(ipath); 1431 kfree(ipath);
1419} 1432}
diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
index d286b40a5671..86eff48dab78 100644
--- a/fs/btrfs/compression.c
+++ b/fs/btrfs/compression.c
@@ -405,6 +405,7 @@ int btrfs_submit_compressed_write(struct inode *inode, u64 start,
405 bio_put(bio); 405 bio_put(bio);
406 406
407 bio = compressed_bio_alloc(bdev, first_byte, GFP_NOFS); 407 bio = compressed_bio_alloc(bdev, first_byte, GFP_NOFS);
408 BUG_ON(!bio);
408 bio->bi_private = cb; 409 bio->bi_private = cb;
409 bio->bi_end_io = end_compressed_bio_write; 410 bio->bi_end_io = end_compressed_bio_write;
410 bio_add_page(bio, page, PAGE_CACHE_SIZE, 0); 411 bio_add_page(bio, page, PAGE_CACHE_SIZE, 0);
@@ -687,6 +688,7 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
687 688
688 comp_bio = compressed_bio_alloc(bdev, cur_disk_byte, 689 comp_bio = compressed_bio_alloc(bdev, cur_disk_byte,
689 GFP_NOFS); 690 GFP_NOFS);
691 BUG_ON(!comp_bio);
690 comp_bio->bi_private = cb; 692 comp_bio->bi_private = cb;
691 comp_bio->bi_end_io = end_compressed_bio_read; 693 comp_bio->bi_end_io = end_compressed_bio_read;
692 694
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index e801f226d7e0..4106264fbc65 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -220,10 +220,12 @@ struct extent_buffer *btrfs_read_lock_root_node(struct btrfs_root *root)
220 */ 220 */
221static void add_root_to_dirty_list(struct btrfs_root *root) 221static void add_root_to_dirty_list(struct btrfs_root *root)
222{ 222{
223 spin_lock(&root->fs_info->trans_lock);
223 if (root->track_dirty && list_empty(&root->dirty_list)) { 224 if (root->track_dirty && list_empty(&root->dirty_list)) {
224 list_add(&root->dirty_list, 225 list_add(&root->dirty_list,
225 &root->fs_info->dirty_cowonly_roots); 226 &root->fs_info->dirty_cowonly_roots);
226 } 227 }
228 spin_unlock(&root->fs_info->trans_lock);
227} 229}
228 230
229/* 231/*
@@ -723,7 +725,7 @@ int btrfs_realloc_node(struct btrfs_trans_handle *trans,
723 725
724 cur = btrfs_find_tree_block(root, blocknr, blocksize); 726 cur = btrfs_find_tree_block(root, blocknr, blocksize);
725 if (cur) 727 if (cur)
726 uptodate = btrfs_buffer_uptodate(cur, gen); 728 uptodate = btrfs_buffer_uptodate(cur, gen, 0);
727 else 729 else
728 uptodate = 0; 730 uptodate = 0;
729 if (!cur || !uptodate) { 731 if (!cur || !uptodate) {
@@ -1358,7 +1360,12 @@ static noinline int reada_for_balance(struct btrfs_root *root,
1358 block1 = btrfs_node_blockptr(parent, slot - 1); 1360 block1 = btrfs_node_blockptr(parent, slot - 1);
1359 gen = btrfs_node_ptr_generation(parent, slot - 1); 1361 gen = btrfs_node_ptr_generation(parent, slot - 1);
1360 eb = btrfs_find_tree_block(root, block1, blocksize); 1362 eb = btrfs_find_tree_block(root, block1, blocksize);
1361 if (eb && btrfs_buffer_uptodate(eb, gen)) 1363 /*
1364 * if we get -eagain from btrfs_buffer_uptodate, we
1365 * don't want to return eagain here. That will loop
1366 * forever
1367 */
1368 if (eb && btrfs_buffer_uptodate(eb, gen, 1) != 0)
1362 block1 = 0; 1369 block1 = 0;
1363 free_extent_buffer(eb); 1370 free_extent_buffer(eb);
1364 } 1371 }
@@ -1366,7 +1373,7 @@ static noinline int reada_for_balance(struct btrfs_root *root,
1366 block2 = btrfs_node_blockptr(parent, slot + 1); 1373 block2 = btrfs_node_blockptr(parent, slot + 1);
1367 gen = btrfs_node_ptr_generation(parent, slot + 1); 1374 gen = btrfs_node_ptr_generation(parent, slot + 1);
1368 eb = btrfs_find_tree_block(root, block2, blocksize); 1375 eb = btrfs_find_tree_block(root, block2, blocksize);
1369 if (eb && btrfs_buffer_uptodate(eb, gen)) 1376 if (eb && btrfs_buffer_uptodate(eb, gen, 1) != 0)
1370 block2 = 0; 1377 block2 = 0;
1371 free_extent_buffer(eb); 1378 free_extent_buffer(eb);
1372 } 1379 }
@@ -1504,8 +1511,9 @@ read_block_for_search(struct btrfs_trans_handle *trans,
1504 1511
1505 tmp = btrfs_find_tree_block(root, blocknr, blocksize); 1512 tmp = btrfs_find_tree_block(root, blocknr, blocksize);
1506 if (tmp) { 1513 if (tmp) {
1507 if (btrfs_buffer_uptodate(tmp, 0)) { 1514 /* first we do an atomic uptodate check */
1508 if (btrfs_buffer_uptodate(tmp, gen)) { 1515 if (btrfs_buffer_uptodate(tmp, 0, 1) > 0) {
1516 if (btrfs_buffer_uptodate(tmp, gen, 1) > 0) {
1509 /* 1517 /*
1510 * we found an up to date block without 1518 * we found an up to date block without
1511 * sleeping, return 1519 * sleeping, return
@@ -1523,8 +1531,9 @@ read_block_for_search(struct btrfs_trans_handle *trans,
1523 free_extent_buffer(tmp); 1531 free_extent_buffer(tmp);
1524 btrfs_set_path_blocking(p); 1532 btrfs_set_path_blocking(p);
1525 1533
1534 /* now we're allowed to do a blocking uptodate check */
1526 tmp = read_tree_block(root, blocknr, blocksize, gen); 1535 tmp = read_tree_block(root, blocknr, blocksize, gen);
1527 if (tmp && btrfs_buffer_uptodate(tmp, gen)) { 1536 if (tmp && btrfs_buffer_uptodate(tmp, gen, 0) > 0) {
1528 *eb_ret = tmp; 1537 *eb_ret = tmp;
1529 return 0; 1538 return 0;
1530 } 1539 }
@@ -1559,7 +1568,7 @@ read_block_for_search(struct btrfs_trans_handle *trans,
1559 * and give up so that our caller doesn't loop forever 1568 * and give up so that our caller doesn't loop forever
1560 * on our EAGAINs. 1569 * on our EAGAINs.
1561 */ 1570 */
1562 if (!btrfs_buffer_uptodate(tmp, 0)) 1571 if (!btrfs_buffer_uptodate(tmp, 0, 0))
1563 ret = -EIO; 1572 ret = -EIO;
1564 free_extent_buffer(tmp); 1573 free_extent_buffer(tmp);
1565 } 1574 }
@@ -4043,7 +4052,7 @@ again:
4043 tmp = btrfs_find_tree_block(root, blockptr, 4052 tmp = btrfs_find_tree_block(root, blockptr,
4044 btrfs_level_size(root, level - 1)); 4053 btrfs_level_size(root, level - 1));
4045 4054
4046 if (tmp && btrfs_buffer_uptodate(tmp, gen)) { 4055 if (tmp && btrfs_buffer_uptodate(tmp, gen, 1) > 0) {
4047 free_extent_buffer(tmp); 4056 free_extent_buffer(tmp);
4048 break; 4057 break;
4049 } 4058 }
@@ -4166,7 +4175,8 @@ next:
4166 struct extent_buffer *cur; 4175 struct extent_buffer *cur;
4167 cur = btrfs_find_tree_block(root, blockptr, 4176 cur = btrfs_find_tree_block(root, blockptr,
4168 btrfs_level_size(root, level - 1)); 4177 btrfs_level_size(root, level - 1));
4169 if (!cur || !btrfs_buffer_uptodate(cur, gen)) { 4178 if (!cur ||
4179 btrfs_buffer_uptodate(cur, gen, 1) <= 0) {
4170 slot++; 4180 slot++;
4171 if (cur) 4181 if (cur)
4172 free_extent_buffer(cur); 4182 free_extent_buffer(cur);
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 5b8ef8eb3521..8fd72331d600 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -1078,7 +1078,7 @@ struct btrfs_fs_info {
1078 * is required instead of the faster short fsync log commits 1078 * is required instead of the faster short fsync log commits
1079 */ 1079 */
1080 u64 last_trans_log_full_commit; 1080 u64 last_trans_log_full_commit;
1081 unsigned long mount_opt:21; 1081 unsigned long mount_opt;
1082 unsigned long compress_type:4; 1082 unsigned long compress_type:4;
1083 u64 max_inline; 1083 u64 max_inline;
1084 u64 alloc_start; 1084 u64 alloc_start;
@@ -2166,7 +2166,7 @@ BTRFS_SETGET_STACK_FUNCS(root_last_snapshot, struct btrfs_root_item,
2166 2166
2167static inline bool btrfs_root_readonly(struct btrfs_root *root) 2167static inline bool btrfs_root_readonly(struct btrfs_root *root)
2168{ 2168{
2169 return root->root_item.flags & BTRFS_ROOT_SUBVOL_RDONLY; 2169 return (root->root_item.flags & cpu_to_le64(BTRFS_ROOT_SUBVOL_RDONLY)) != 0;
2170} 2170}
2171 2171
2172/* struct btrfs_root_backup */ 2172/* struct btrfs_root_backup */
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 20196f411206..a7ffc88a7dbe 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -323,7 +323,8 @@ static int csum_tree_block(struct btrfs_root *root, struct extent_buffer *buf,
323 * in the wrong place. 323 * in the wrong place.
324 */ 324 */
325static int verify_parent_transid(struct extent_io_tree *io_tree, 325static int verify_parent_transid(struct extent_io_tree *io_tree,
326 struct extent_buffer *eb, u64 parent_transid) 326 struct extent_buffer *eb, u64 parent_transid,
327 int atomic)
327{ 328{
328 struct extent_state *cached_state = NULL; 329 struct extent_state *cached_state = NULL;
329 int ret; 330 int ret;
@@ -331,6 +332,9 @@ static int verify_parent_transid(struct extent_io_tree *io_tree,
331 if (!parent_transid || btrfs_header_generation(eb) == parent_transid) 332 if (!parent_transid || btrfs_header_generation(eb) == parent_transid)
332 return 0; 333 return 0;
333 334
335 if (atomic)
336 return -EAGAIN;
337
334 lock_extent_bits(io_tree, eb->start, eb->start + eb->len - 1, 338 lock_extent_bits(io_tree, eb->start, eb->start + eb->len - 1,
335 0, &cached_state); 339 0, &cached_state);
336 if (extent_buffer_uptodate(eb) && 340 if (extent_buffer_uptodate(eb) &&
@@ -372,7 +376,8 @@ static int btree_read_extent_buffer_pages(struct btrfs_root *root,
372 ret = read_extent_buffer_pages(io_tree, eb, start, 376 ret = read_extent_buffer_pages(io_tree, eb, start,
373 WAIT_COMPLETE, 377 WAIT_COMPLETE,
374 btree_get_extent, mirror_num); 378 btree_get_extent, mirror_num);
375 if (!ret && !verify_parent_transid(io_tree, eb, parent_transid)) 379 if (!ret && !verify_parent_transid(io_tree, eb,
380 parent_transid, 0))
376 break; 381 break;
377 382
378 /* 383 /*
@@ -383,17 +388,16 @@ static int btree_read_extent_buffer_pages(struct btrfs_root *root,
383 if (test_bit(EXTENT_BUFFER_CORRUPT, &eb->bflags)) 388 if (test_bit(EXTENT_BUFFER_CORRUPT, &eb->bflags))
384 break; 389 break;
385 390
386 if (!failed_mirror) {
387 failed = 1;
388 printk(KERN_ERR "failed mirror was %d\n", eb->failed_mirror);
389 failed_mirror = eb->failed_mirror;
390 }
391
392 num_copies = btrfs_num_copies(&root->fs_info->mapping_tree, 391 num_copies = btrfs_num_copies(&root->fs_info->mapping_tree,
393 eb->start, eb->len); 392 eb->start, eb->len);
394 if (num_copies == 1) 393 if (num_copies == 1)
395 break; 394 break;
396 395
396 if (!failed_mirror) {
397 failed = 1;
398 failed_mirror = eb->read_mirror;
399 }
400
397 mirror_num++; 401 mirror_num++;
398 if (mirror_num == failed_mirror) 402 if (mirror_num == failed_mirror)
399 mirror_num++; 403 mirror_num++;
@@ -564,7 +568,7 @@ struct extent_buffer *find_eb_for_page(struct extent_io_tree *tree,
564} 568}
565 569
566static int btree_readpage_end_io_hook(struct page *page, u64 start, u64 end, 570static int btree_readpage_end_io_hook(struct page *page, u64 start, u64 end,
567 struct extent_state *state) 571 struct extent_state *state, int mirror)
568{ 572{
569 struct extent_io_tree *tree; 573 struct extent_io_tree *tree;
570 u64 found_start; 574 u64 found_start;
@@ -589,6 +593,7 @@ static int btree_readpage_end_io_hook(struct page *page, u64 start, u64 end,
589 if (!reads_done) 593 if (!reads_done)
590 goto err; 594 goto err;
591 595
596 eb->read_mirror = mirror;
592 if (test_bit(EXTENT_BUFFER_IOERR, &eb->bflags)) { 597 if (test_bit(EXTENT_BUFFER_IOERR, &eb->bflags)) {
593 ret = -EIO; 598 ret = -EIO;
594 goto err; 599 goto err;
@@ -652,7 +657,7 @@ static int btree_io_failed_hook(struct page *page, int failed_mirror)
652 657
653 eb = (struct extent_buffer *)page->private; 658 eb = (struct extent_buffer *)page->private;
654 set_bit(EXTENT_BUFFER_IOERR, &eb->bflags); 659 set_bit(EXTENT_BUFFER_IOERR, &eb->bflags);
655 eb->failed_mirror = failed_mirror; 660 eb->read_mirror = failed_mirror;
656 if (test_and_clear_bit(EXTENT_BUFFER_READAHEAD, &eb->bflags)) 661 if (test_and_clear_bit(EXTENT_BUFFER_READAHEAD, &eb->bflags))
657 btree_readahead_hook(root, eb, eb->start, -EIO); 662 btree_readahead_hook(root, eb, eb->start, -EIO);
658 return -EIO; /* we fixed nothing */ 663 return -EIO; /* we fixed nothing */
@@ -1202,7 +1207,7 @@ static int __must_check find_and_setup_root(struct btrfs_root *tree_root,
1202 root->commit_root = NULL; 1207 root->commit_root = NULL;
1203 root->node = read_tree_block(root, btrfs_root_bytenr(&root->root_item), 1208 root->node = read_tree_block(root, btrfs_root_bytenr(&root->root_item),
1204 blocksize, generation); 1209 blocksize, generation);
1205 if (!root->node || !btrfs_buffer_uptodate(root->node, generation)) { 1210 if (!root->node || !btrfs_buffer_uptodate(root->node, generation, 0)) {
1206 free_extent_buffer(root->node); 1211 free_extent_buffer(root->node);
1207 root->node = NULL; 1212 root->node = NULL;
1208 return -EIO; 1213 return -EIO;
@@ -2254,9 +2259,9 @@ int open_ctree(struct super_block *sb,
2254 goto fail_sb_buffer; 2259 goto fail_sb_buffer;
2255 } 2260 }
2256 2261
2257 if (sectorsize < PAGE_SIZE) { 2262 if (sectorsize != PAGE_SIZE) {
2258 printk(KERN_WARNING "btrfs: Incompatible sector size " 2263 printk(KERN_WARNING "btrfs: Incompatible sector size(%lu) "
2259 "found on %s\n", sb->s_id); 2264 "found on %s\n", (unsigned long)sectorsize, sb->s_id);
2260 goto fail_sb_buffer; 2265 goto fail_sb_buffer;
2261 } 2266 }
2262 2267
@@ -3143,7 +3148,8 @@ int close_ctree(struct btrfs_root *root)
3143 return 0; 3148 return 0;
3144} 3149}
3145 3150
3146int btrfs_buffer_uptodate(struct extent_buffer *buf, u64 parent_transid) 3151int btrfs_buffer_uptodate(struct extent_buffer *buf, u64 parent_transid,
3152 int atomic)
3147{ 3153{
3148 int ret; 3154 int ret;
3149 struct inode *btree_inode = buf->pages[0]->mapping->host; 3155 struct inode *btree_inode = buf->pages[0]->mapping->host;
@@ -3153,7 +3159,9 @@ int btrfs_buffer_uptodate(struct extent_buffer *buf, u64 parent_transid)
3153 return ret; 3159 return ret;
3154 3160
3155 ret = verify_parent_transid(&BTRFS_I(btree_inode)->io_tree, buf, 3161 ret = verify_parent_transid(&BTRFS_I(btree_inode)->io_tree, buf,
3156 parent_transid); 3162 parent_transid, atomic);
3163 if (ret == -EAGAIN)
3164 return ret;
3157 return !ret; 3165 return !ret;
3158} 3166}
3159 3167
diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h
index a7ace1a2dd12..ab1830aaf0ed 100644
--- a/fs/btrfs/disk-io.h
+++ b/fs/btrfs/disk-io.h
@@ -66,7 +66,8 @@ void btrfs_btree_balance_dirty(struct btrfs_root *root, unsigned long nr);
66void __btrfs_btree_balance_dirty(struct btrfs_root *root, unsigned long nr); 66void __btrfs_btree_balance_dirty(struct btrfs_root *root, unsigned long nr);
67void btrfs_free_fs_root(struct btrfs_fs_info *fs_info, struct btrfs_root *root); 67void btrfs_free_fs_root(struct btrfs_fs_info *fs_info, struct btrfs_root *root);
68void btrfs_mark_buffer_dirty(struct extent_buffer *buf); 68void btrfs_mark_buffer_dirty(struct extent_buffer *buf);
69int btrfs_buffer_uptodate(struct extent_buffer *buf, u64 parent_transid); 69int btrfs_buffer_uptodate(struct extent_buffer *buf, u64 parent_transid,
70 int atomic);
70int btrfs_set_buffer_uptodate(struct extent_buffer *buf); 71int btrfs_set_buffer_uptodate(struct extent_buffer *buf);
71int btrfs_read_buffer(struct extent_buffer *buf, u64 parent_transid); 72int btrfs_read_buffer(struct extent_buffer *buf, u64 parent_transid);
72u32 btrfs_csum_data(struct btrfs_root *root, char *data, u32 seed, size_t len); 73u32 btrfs_csum_data(struct btrfs_root *root, char *data, u32 seed, size_t len);
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index a84420491c11..49fd7b66d57b 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -529,9 +529,7 @@ static int cache_block_group(struct btrfs_block_group_cache *cache,
529 * allocate blocks for the tree root we can't do the fast caching since 529 * allocate blocks for the tree root we can't do the fast caching since
530 * we likely hold important locks. 530 * we likely hold important locks.
531 */ 531 */
532 if (trans && (!trans->transaction->in_commit) && 532 if (fs_info->mount_opt & BTRFS_MOUNT_SPACE_CACHE) {
533 (root && root != root->fs_info->tree_root) &&
534 btrfs_test_opt(root, SPACE_CACHE)) {
535 ret = load_free_space_cache(fs_info, cache); 533 ret = load_free_space_cache(fs_info, cache);
536 534
537 spin_lock(&cache->lock); 535 spin_lock(&cache->lock);
@@ -2303,6 +2301,7 @@ static noinline int run_clustered_refs(struct btrfs_trans_handle *trans,
2303 2301
2304 if (ret) { 2302 if (ret) {
2305 printk(KERN_DEBUG "btrfs: run_delayed_extent_op returned %d\n", ret); 2303 printk(KERN_DEBUG "btrfs: run_delayed_extent_op returned %d\n", ret);
2304 spin_lock(&delayed_refs->lock);
2306 return ret; 2305 return ret;
2307 } 2306 }
2308 2307
@@ -2333,6 +2332,7 @@ static noinline int run_clustered_refs(struct btrfs_trans_handle *trans,
2333 2332
2334 if (ret) { 2333 if (ret) {
2335 printk(KERN_DEBUG "btrfs: run_one_delayed_ref returned %d\n", ret); 2334 printk(KERN_DEBUG "btrfs: run_one_delayed_ref returned %d\n", ret);
2335 spin_lock(&delayed_refs->lock);
2336 return ret; 2336 return ret;
2337 } 2337 }
2338 2338
@@ -3152,15 +3152,14 @@ static void set_avail_alloc_bits(struct btrfs_fs_info *fs_info, u64 flags)
3152/* 3152/*
3153 * returns target flags in extended format or 0 if restripe for this 3153 * returns target flags in extended format or 0 if restripe for this
3154 * chunk_type is not in progress 3154 * chunk_type is not in progress
3155 *
3156 * should be called with either volume_mutex or balance_lock held
3155 */ 3157 */
3156static u64 get_restripe_target(struct btrfs_fs_info *fs_info, u64 flags) 3158static u64 get_restripe_target(struct btrfs_fs_info *fs_info, u64 flags)
3157{ 3159{
3158 struct btrfs_balance_control *bctl = fs_info->balance_ctl; 3160 struct btrfs_balance_control *bctl = fs_info->balance_ctl;
3159 u64 target = 0; 3161 u64 target = 0;
3160 3162
3161 BUG_ON(!mutex_is_locked(&fs_info->volume_mutex) &&
3162 !spin_is_locked(&fs_info->balance_lock));
3163
3164 if (!bctl) 3163 if (!bctl)
3165 return 0; 3164 return 0;
3166 3165
@@ -3772,13 +3771,10 @@ again:
3772 */ 3771 */
3773 if (current->journal_info) 3772 if (current->journal_info)
3774 return -EAGAIN; 3773 return -EAGAIN;
3775 ret = wait_event_interruptible(space_info->wait, 3774 ret = wait_event_killable(space_info->wait, !space_info->flush);
3776 !space_info->flush); 3775 /* Must have been killed, return */
3777 /* Must have been interrupted, return */ 3776 if (ret)
3778 if (ret) {
3779 printk(KERN_DEBUG "btrfs: %s returning -EINTR\n", __func__);
3780 return -EINTR; 3777 return -EINTR;
3781 }
3782 3778
3783 spin_lock(&space_info->lock); 3779 spin_lock(&space_info->lock);
3784 } 3780 }
@@ -4205,7 +4201,7 @@ static u64 calc_global_metadata_size(struct btrfs_fs_info *fs_info)
4205 num_bytes += div64_u64(data_used + meta_used, 50); 4201 num_bytes += div64_u64(data_used + meta_used, 50);
4206 4202
4207 if (num_bytes * 3 > meta_used) 4203 if (num_bytes * 3 > meta_used)
4208 num_bytes = div64_u64(meta_used, 3) * 2; 4204 num_bytes = div64_u64(meta_used, 3);
4209 4205
4210 return ALIGN(num_bytes, fs_info->extent_root->leafsize << 10); 4206 return ALIGN(num_bytes, fs_info->extent_root->leafsize << 10);
4211} 4207}
@@ -4218,8 +4214,8 @@ static void update_global_block_rsv(struct btrfs_fs_info *fs_info)
4218 4214
4219 num_bytes = calc_global_metadata_size(fs_info); 4215 num_bytes = calc_global_metadata_size(fs_info);
4220 4216
4221 spin_lock(&block_rsv->lock);
4222 spin_lock(&sinfo->lock); 4217 spin_lock(&sinfo->lock);
4218 spin_lock(&block_rsv->lock);
4223 4219
4224 block_rsv->size = num_bytes; 4220 block_rsv->size = num_bytes;
4225 4221
@@ -4245,8 +4241,8 @@ static void update_global_block_rsv(struct btrfs_fs_info *fs_info)
4245 block_rsv->full = 1; 4241 block_rsv->full = 1;
4246 } 4242 }
4247 4243
4248 spin_unlock(&sinfo->lock);
4249 spin_unlock(&block_rsv->lock); 4244 spin_unlock(&block_rsv->lock);
4245 spin_unlock(&sinfo->lock);
4250} 4246}
4251 4247
4252static void init_global_block_rsv(struct btrfs_fs_info *fs_info) 4248static void init_global_block_rsv(struct btrfs_fs_info *fs_info)
@@ -6572,7 +6568,7 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans,
6572 goto skip; 6568 goto skip;
6573 } 6569 }
6574 6570
6575 if (!btrfs_buffer_uptodate(next, generation)) { 6571 if (!btrfs_buffer_uptodate(next, generation, 0)) {
6576 btrfs_tree_unlock(next); 6572 btrfs_tree_unlock(next);
6577 free_extent_buffer(next); 6573 free_extent_buffer(next);
6578 next = NULL; 6574 next = NULL;
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 8d904dd7ea9f..c9018a05036e 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -402,20 +402,28 @@ static int split_state(struct extent_io_tree *tree, struct extent_state *orig,
402 return 0; 402 return 0;
403} 403}
404 404
405static struct extent_state *next_state(struct extent_state *state)
406{
407 struct rb_node *next = rb_next(&state->rb_node);
408 if (next)
409 return rb_entry(next, struct extent_state, rb_node);
410 else
411 return NULL;
412}
413
405/* 414/*
406 * utility function to clear some bits in an extent state struct. 415 * utility function to clear some bits in an extent state struct.
407 * it will optionally wake up any one waiting on this state (wake == 1), or 416 * it will optionally wake up any one waiting on this state (wake == 1)
408 * forcibly remove the state from the tree (delete == 1).
409 * 417 *
410 * If no bits are set on the state struct after clearing things, the 418 * If no bits are set on the state struct after clearing things, the
411 * struct is freed and removed from the tree 419 * struct is freed and removed from the tree
412 */ 420 */
413static int clear_state_bit(struct extent_io_tree *tree, 421static struct extent_state *clear_state_bit(struct extent_io_tree *tree,
414 struct extent_state *state, 422 struct extent_state *state,
415 int *bits, int wake) 423 int *bits, int wake)
416{ 424{
425 struct extent_state *next;
417 int bits_to_clear = *bits & ~EXTENT_CTLBITS; 426 int bits_to_clear = *bits & ~EXTENT_CTLBITS;
418 int ret = state->state & bits_to_clear;
419 427
420 if ((bits_to_clear & EXTENT_DIRTY) && (state->state & EXTENT_DIRTY)) { 428 if ((bits_to_clear & EXTENT_DIRTY) && (state->state & EXTENT_DIRTY)) {
421 u64 range = state->end - state->start + 1; 429 u64 range = state->end - state->start + 1;
@@ -427,6 +435,7 @@ static int clear_state_bit(struct extent_io_tree *tree,
427 if (wake) 435 if (wake)
428 wake_up(&state->wq); 436 wake_up(&state->wq);
429 if (state->state == 0) { 437 if (state->state == 0) {
438 next = next_state(state);
430 if (state->tree) { 439 if (state->tree) {
431 rb_erase(&state->rb_node, &tree->state); 440 rb_erase(&state->rb_node, &tree->state);
432 state->tree = NULL; 441 state->tree = NULL;
@@ -436,8 +445,9 @@ static int clear_state_bit(struct extent_io_tree *tree,
436 } 445 }
437 } else { 446 } else {
438 merge_state(tree, state); 447 merge_state(tree, state);
448 next = next_state(state);
439 } 449 }
440 return ret; 450 return next;
441} 451}
442 452
443static struct extent_state * 453static struct extent_state *
@@ -476,7 +486,6 @@ int clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
476 struct extent_state *state; 486 struct extent_state *state;
477 struct extent_state *cached; 487 struct extent_state *cached;
478 struct extent_state *prealloc = NULL; 488 struct extent_state *prealloc = NULL;
479 struct rb_node *next_node;
480 struct rb_node *node; 489 struct rb_node *node;
481 u64 last_end; 490 u64 last_end;
482 int err; 491 int err;
@@ -528,14 +537,11 @@ hit_next:
528 WARN_ON(state->end < start); 537 WARN_ON(state->end < start);
529 last_end = state->end; 538 last_end = state->end;
530 539
531 if (state->end < end && !need_resched())
532 next_node = rb_next(&state->rb_node);
533 else
534 next_node = NULL;
535
536 /* the state doesn't have the wanted bits, go ahead */ 540 /* the state doesn't have the wanted bits, go ahead */
537 if (!(state->state & bits)) 541 if (!(state->state & bits)) {
542 state = next_state(state);
538 goto next; 543 goto next;
544 }
539 545
540 /* 546 /*
541 * | ---- desired range ---- | 547 * | ---- desired range ---- |
@@ -593,16 +599,13 @@ hit_next:
593 goto out; 599 goto out;
594 } 600 }
595 601
596 clear_state_bit(tree, state, &bits, wake); 602 state = clear_state_bit(tree, state, &bits, wake);
597next: 603next:
598 if (last_end == (u64)-1) 604 if (last_end == (u64)-1)
599 goto out; 605 goto out;
600 start = last_end + 1; 606 start = last_end + 1;
601 if (start <= end && next_node) { 607 if (start <= end && state && !need_resched())
602 state = rb_entry(next_node, struct extent_state,
603 rb_node);
604 goto hit_next; 608 goto hit_next;
605 }
606 goto search_again; 609 goto search_again;
607 610
608out: 611out:
@@ -1937,7 +1940,7 @@ int repair_eb_io_failure(struct btrfs_root *root, struct extent_buffer *eb,
1937 struct btrfs_mapping_tree *map_tree = &root->fs_info->mapping_tree; 1940 struct btrfs_mapping_tree *map_tree = &root->fs_info->mapping_tree;
1938 u64 start = eb->start; 1941 u64 start = eb->start;
1939 unsigned long i, num_pages = num_extent_pages(eb->start, eb->len); 1942 unsigned long i, num_pages = num_extent_pages(eb->start, eb->len);
1940 int ret; 1943 int ret = 0;
1941 1944
1942 for (i = 0; i < num_pages; i++) { 1945 for (i = 0; i < num_pages; i++) {
1943 struct page *p = extent_buffer_page(eb, i); 1946 struct page *p = extent_buffer_page(eb, i);
@@ -2180,6 +2183,10 @@ static int bio_readpage_error(struct bio *failed_bio, struct page *page,
2180 } 2183 }
2181 2184
2182 bio = bio_alloc(GFP_NOFS, 1); 2185 bio = bio_alloc(GFP_NOFS, 1);
2186 if (!bio) {
2187 free_io_failure(inode, failrec, 0);
2188 return -EIO;
2189 }
2183 bio->bi_private = state; 2190 bio->bi_private = state;
2184 bio->bi_end_io = failed_bio->bi_end_io; 2191 bio->bi_end_io = failed_bio->bi_end_io;
2185 bio->bi_sector = failrec->logical >> 9; 2192 bio->bi_sector = failrec->logical >> 9;
@@ -2297,7 +2304,7 @@ static void end_bio_extent_readpage(struct bio *bio, int err)
2297 u64 start; 2304 u64 start;
2298 u64 end; 2305 u64 end;
2299 int whole_page; 2306 int whole_page;
2300 int failed_mirror; 2307 int mirror;
2301 int ret; 2308 int ret;
2302 2309
2303 if (err) 2310 if (err)
@@ -2336,20 +2343,18 @@ static void end_bio_extent_readpage(struct bio *bio, int err)
2336 } 2343 }
2337 spin_unlock(&tree->lock); 2344 spin_unlock(&tree->lock);
2338 2345
2346 mirror = (int)(unsigned long)bio->bi_bdev;
2339 if (uptodate && tree->ops && tree->ops->readpage_end_io_hook) { 2347 if (uptodate && tree->ops && tree->ops->readpage_end_io_hook) {
2340 ret = tree->ops->readpage_end_io_hook(page, start, end, 2348 ret = tree->ops->readpage_end_io_hook(page, start, end,
2341 state); 2349 state, mirror);
2342 if (ret) 2350 if (ret)
2343 uptodate = 0; 2351 uptodate = 0;
2344 else 2352 else
2345 clean_io_failure(start, page); 2353 clean_io_failure(start, page);
2346 } 2354 }
2347 2355
2348 if (!uptodate)
2349 failed_mirror = (int)(unsigned long)bio->bi_bdev;
2350
2351 if (!uptodate && tree->ops && tree->ops->readpage_io_failed_hook) { 2356 if (!uptodate && tree->ops && tree->ops->readpage_io_failed_hook) {
2352 ret = tree->ops->readpage_io_failed_hook(page, failed_mirror); 2357 ret = tree->ops->readpage_io_failed_hook(page, mirror);
2353 if (!ret && !err && 2358 if (!ret && !err &&
2354 test_bit(BIO_UPTODATE, &bio->bi_flags)) 2359 test_bit(BIO_UPTODATE, &bio->bi_flags))
2355 uptodate = 1; 2360 uptodate = 1;
@@ -2364,8 +2369,7 @@ static void end_bio_extent_readpage(struct bio *bio, int err)
2364 * can't handle the error it will return -EIO and we 2369 * can't handle the error it will return -EIO and we
2365 * remain responsible for that page. 2370 * remain responsible for that page.
2366 */ 2371 */
2367 ret = bio_readpage_error(bio, page, start, end, 2372 ret = bio_readpage_error(bio, page, start, end, mirror, NULL);
2368 failed_mirror, NULL);
2369 if (ret == 0) { 2373 if (ret == 0) {
2370 uptodate = 2374 uptodate =
2371 test_bit(BIO_UPTODATE, &bio->bi_flags); 2375 test_bit(BIO_UPTODATE, &bio->bi_flags);
@@ -4116,6 +4120,7 @@ struct extent_buffer *alloc_extent_buffer(struct extent_io_tree *tree,
4116 if (atomic_inc_not_zero(&exists->refs)) { 4120 if (atomic_inc_not_zero(&exists->refs)) {
4117 spin_unlock(&mapping->private_lock); 4121 spin_unlock(&mapping->private_lock);
4118 unlock_page(p); 4122 unlock_page(p);
4123 page_cache_release(p);
4119 mark_extent_buffer_accessed(exists); 4124 mark_extent_buffer_accessed(exists);
4120 goto free_eb; 4125 goto free_eb;
4121 } 4126 }
@@ -4195,8 +4200,7 @@ free_eb:
4195 unlock_page(eb->pages[i]); 4200 unlock_page(eb->pages[i]);
4196 } 4201 }
4197 4202
4198 if (!atomic_dec_and_test(&eb->refs)) 4203 WARN_ON(!atomic_dec_and_test(&eb->refs));
4199 return exists;
4200 btrfs_release_extent_buffer(eb); 4204 btrfs_release_extent_buffer(eb);
4201 return exists; 4205 return exists;
4202} 4206}
@@ -4458,7 +4462,7 @@ int read_extent_buffer_pages(struct extent_io_tree *tree,
4458 } 4462 }
4459 4463
4460 clear_bit(EXTENT_BUFFER_IOERR, &eb->bflags); 4464 clear_bit(EXTENT_BUFFER_IOERR, &eb->bflags);
4461 eb->failed_mirror = 0; 4465 eb->read_mirror = 0;
4462 atomic_set(&eb->io_pages, num_reads); 4466 atomic_set(&eb->io_pages, num_reads);
4463 for (i = start_i; i < num_pages; i++) { 4467 for (i = start_i; i < num_pages; i++) {
4464 page = extent_buffer_page(eb, i); 4468 page = extent_buffer_page(eb, i);
diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h
index faf10eb57f75..b516c3b8dec6 100644
--- a/fs/btrfs/extent_io.h
+++ b/fs/btrfs/extent_io.h
@@ -79,7 +79,7 @@ struct extent_io_ops {
79 u64 start, u64 end, 79 u64 start, u64 end,
80 struct extent_state *state); 80 struct extent_state *state);
81 int (*readpage_end_io_hook)(struct page *page, u64 start, u64 end, 81 int (*readpage_end_io_hook)(struct page *page, u64 start, u64 end,
82 struct extent_state *state); 82 struct extent_state *state, int mirror);
83 int (*writepage_end_io_hook)(struct page *page, u64 start, u64 end, 83 int (*writepage_end_io_hook)(struct page *page, u64 start, u64 end,
84 struct extent_state *state, int uptodate); 84 struct extent_state *state, int uptodate);
85 void (*set_bit_hook)(struct inode *inode, struct extent_state *state, 85 void (*set_bit_hook)(struct inode *inode, struct extent_state *state,
@@ -135,7 +135,7 @@ struct extent_buffer {
135 spinlock_t refs_lock; 135 spinlock_t refs_lock;
136 atomic_t refs; 136 atomic_t refs;
137 atomic_t io_pages; 137 atomic_t io_pages;
138 int failed_mirror; 138 int read_mirror;
139 struct list_head leak_list; 139 struct list_head leak_list;
140 struct rcu_head rcu_head; 140 struct rcu_head rcu_head;
141 pid_t lock_owner; 141 pid_t lock_owner;
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index d83260d7498f..53bf2d764bbc 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -567,6 +567,7 @@ int btrfs_drop_extents(struct btrfs_trans_handle *trans, struct inode *inode,
567 int extent_type; 567 int extent_type;
568 int recow; 568 int recow;
569 int ret; 569 int ret;
570 int modify_tree = -1;
570 571
571 if (drop_cache) 572 if (drop_cache)
572 btrfs_drop_extent_cache(inode, start, end - 1, 0); 573 btrfs_drop_extent_cache(inode, start, end - 1, 0);
@@ -575,10 +576,13 @@ int btrfs_drop_extents(struct btrfs_trans_handle *trans, struct inode *inode,
575 if (!path) 576 if (!path)
576 return -ENOMEM; 577 return -ENOMEM;
577 578
579 if (start >= BTRFS_I(inode)->disk_i_size)
580 modify_tree = 0;
581
578 while (1) { 582 while (1) {
579 recow = 0; 583 recow = 0;
580 ret = btrfs_lookup_file_extent(trans, root, path, ino, 584 ret = btrfs_lookup_file_extent(trans, root, path, ino,
581 search_start, -1); 585 search_start, modify_tree);
582 if (ret < 0) 586 if (ret < 0)
583 break; 587 break;
584 if (ret > 0 && path->slots[0] > 0 && search_start == start) { 588 if (ret > 0 && path->slots[0] > 0 && search_start == start) {
@@ -634,7 +638,8 @@ next_slot:
634 } 638 }
635 639
636 search_start = max(key.offset, start); 640 search_start = max(key.offset, start);
637 if (recow) { 641 if (recow || !modify_tree) {
642 modify_tree = -1;
638 btrfs_release_path(path); 643 btrfs_release_path(path);
639 continue; 644 continue;
640 } 645 }
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
index e88330d3df52..202008ec367d 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
@@ -748,13 +748,6 @@ int load_free_space_cache(struct btrfs_fs_info *fs_info,
748 u64 used = btrfs_block_group_used(&block_group->item); 748 u64 used = btrfs_block_group_used(&block_group->item);
749 749
750 /* 750 /*
751 * If we're unmounting then just return, since this does a search on the
752 * normal root and not the commit root and we could deadlock.
753 */
754 if (btrfs_fs_closing(fs_info))
755 return 0;
756
757 /*
758 * If this block group has been marked to be cleared for one reason or 751 * If this block group has been marked to be cleared for one reason or
759 * another then we can't trust the on disk cache, so just return. 752 * another then we can't trust the on disk cache, so just return.
760 */ 753 */
@@ -768,6 +761,8 @@ int load_free_space_cache(struct btrfs_fs_info *fs_info,
768 path = btrfs_alloc_path(); 761 path = btrfs_alloc_path();
769 if (!path) 762 if (!path)
770 return 0; 763 return 0;
764 path->search_commit_root = 1;
765 path->skip_locking = 1;
771 766
772 inode = lookup_free_space_inode(root, block_group, path); 767 inode = lookup_free_space_inode(root, block_group, path);
773 if (IS_ERR(inode)) { 768 if (IS_ERR(inode)) {
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 115bc05e42b0..61b16c641ce0 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -1947,7 +1947,7 @@ static int btrfs_writepage_end_io_hook(struct page *page, u64 start, u64 end,
1947 * extent_io.c will try to find good copies for us. 1947 * extent_io.c will try to find good copies for us.
1948 */ 1948 */
1949static int btrfs_readpage_end_io_hook(struct page *page, u64 start, u64 end, 1949static int btrfs_readpage_end_io_hook(struct page *page, u64 start, u64 end,
1950 struct extent_state *state) 1950 struct extent_state *state, int mirror)
1951{ 1951{
1952 size_t offset = start - ((u64)page->index << PAGE_CACHE_SHIFT); 1952 size_t offset = start - ((u64)page->index << PAGE_CACHE_SHIFT);
1953 struct inode *inode = page->mapping->host; 1953 struct inode *inode = page->mapping->host;
@@ -4069,7 +4069,7 @@ static struct inode *new_simple_dir(struct super_block *s,
4069 BTRFS_I(inode)->dummy_inode = 1; 4069 BTRFS_I(inode)->dummy_inode = 1;
4070 4070
4071 inode->i_ino = BTRFS_EMPTY_SUBVOL_DIR_OBJECTID; 4071 inode->i_ino = BTRFS_EMPTY_SUBVOL_DIR_OBJECTID;
4072 inode->i_op = &simple_dir_inode_operations; 4072 inode->i_op = &btrfs_dir_ro_inode_operations;
4073 inode->i_fop = &simple_dir_operations; 4073 inode->i_fop = &simple_dir_operations;
4074 inode->i_mode = S_IFDIR | S_IRUGO | S_IWUSR | S_IXUGO; 4074 inode->i_mode = S_IFDIR | S_IRUGO | S_IWUSR | S_IXUGO;
4075 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; 4075 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
@@ -4140,14 +4140,18 @@ struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry)
4140static int btrfs_dentry_delete(const struct dentry *dentry) 4140static int btrfs_dentry_delete(const struct dentry *dentry)
4141{ 4141{
4142 struct btrfs_root *root; 4142 struct btrfs_root *root;
4143 struct inode *inode = dentry->d_inode;
4143 4144
4144 if (!dentry->d_inode && !IS_ROOT(dentry)) 4145 if (!inode && !IS_ROOT(dentry))
4145 dentry = dentry->d_parent; 4146 inode = dentry->d_parent->d_inode;
4146 4147
4147 if (dentry->d_inode) { 4148 if (inode) {
4148 root = BTRFS_I(dentry->d_inode)->root; 4149 root = BTRFS_I(inode)->root;
4149 if (btrfs_root_refs(&root->root_item) == 0) 4150 if (btrfs_root_refs(&root->root_item) == 0)
4150 return 1; 4151 return 1;
4152
4153 if (btrfs_ino(inode) == BTRFS_EMPTY_SUBVOL_DIR_OBJECTID)
4154 return 1;
4151 } 4155 }
4152 return 0; 4156 return 0;
4153} 4157}
@@ -4188,7 +4192,6 @@ static int btrfs_real_readdir(struct file *filp, void *dirent,
4188 struct btrfs_path *path; 4192 struct btrfs_path *path;
4189 struct list_head ins_list; 4193 struct list_head ins_list;
4190 struct list_head del_list; 4194 struct list_head del_list;
4191 struct qstr q;
4192 int ret; 4195 int ret;
4193 struct extent_buffer *leaf; 4196 struct extent_buffer *leaf;
4194 int slot; 4197 int slot;
@@ -4279,7 +4282,6 @@ static int btrfs_real_readdir(struct file *filp, void *dirent,
4279 4282
4280 while (di_cur < di_total) { 4283 while (di_cur < di_total) {
4281 struct btrfs_key location; 4284 struct btrfs_key location;
4282 struct dentry *tmp;
4283 4285
4284 if (verify_dir_item(root, leaf, di)) 4286 if (verify_dir_item(root, leaf, di))
4285 break; 4287 break;
@@ -4300,35 +4302,15 @@ static int btrfs_real_readdir(struct file *filp, void *dirent,
4300 d_type = btrfs_filetype_table[btrfs_dir_type(leaf, di)]; 4302 d_type = btrfs_filetype_table[btrfs_dir_type(leaf, di)];
4301 btrfs_dir_item_key_to_cpu(leaf, di, &location); 4303 btrfs_dir_item_key_to_cpu(leaf, di, &location);
4302 4304
4303 q.name = name_ptr; 4305
4304 q.len = name_len;
4305 q.hash = full_name_hash(q.name, q.len);
4306 tmp = d_lookup(filp->f_dentry, &q);
4307 if (!tmp) {
4308 struct btrfs_key *newkey;
4309
4310 newkey = kzalloc(sizeof(struct btrfs_key),
4311 GFP_NOFS);
4312 if (!newkey)
4313 goto no_dentry;
4314 tmp = d_alloc(filp->f_dentry, &q);
4315 if (!tmp) {
4316 kfree(newkey);
4317 dput(tmp);
4318 goto no_dentry;
4319 }
4320 memcpy(newkey, &location,
4321 sizeof(struct btrfs_key));
4322 tmp->d_fsdata = newkey;
4323 tmp->d_flags |= DCACHE_NEED_LOOKUP;
4324 d_rehash(tmp);
4325 dput(tmp);
4326 } else {
4327 dput(tmp);
4328 }
4329no_dentry:
4330 /* is this a reference to our own snapshot? If so 4306 /* is this a reference to our own snapshot? If so
4331 * skip it 4307 * skip it.
4308 *
4309 * In contrast to old kernels, we insert the snapshot's
4310 * dir item and dir index after it has been created, so
4311 * we won't find a reference to our own snapshot. We
4312 * still keep the following code for backward
4313 * compatibility.
4332 */ 4314 */
4333 if (location.type == BTRFS_ROOT_ITEM_KEY && 4315 if (location.type == BTRFS_ROOT_ITEM_KEY &&
4334 location.objectid == root->root_key.objectid) { 4316 location.objectid == root->root_key.objectid) {
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 18cc23d164a8..14f8e1faa46e 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -2262,7 +2262,10 @@ static long btrfs_ioctl_dev_info(struct btrfs_root *root, void __user *arg)
2262 di_args->bytes_used = dev->bytes_used; 2262 di_args->bytes_used = dev->bytes_used;
2263 di_args->total_bytes = dev->total_bytes; 2263 di_args->total_bytes = dev->total_bytes;
2264 memcpy(di_args->uuid, dev->uuid, sizeof(di_args->uuid)); 2264 memcpy(di_args->uuid, dev->uuid, sizeof(di_args->uuid));
2265 strncpy(di_args->path, dev->name, sizeof(di_args->path)); 2265 if (dev->name)
2266 strncpy(di_args->path, dev->name, sizeof(di_args->path));
2267 else
2268 di_args->path[0] = '\0';
2266 2269
2267out: 2270out:
2268 if (ret == 0 && copy_to_user(arg, di_args, sizeof(*di_args))) 2271 if (ret == 0 && copy_to_user(arg, di_args, sizeof(*di_args)))
diff --git a/fs/btrfs/ioctl.h b/fs/btrfs/ioctl.h
index 4f69028a68c4..086e6bdae1c4 100644
--- a/fs/btrfs/ioctl.h
+++ b/fs/btrfs/ioctl.h
@@ -252,7 +252,7 @@ struct btrfs_data_container {
252 252
253struct btrfs_ioctl_ino_path_args { 253struct btrfs_ioctl_ino_path_args {
254 __u64 inum; /* in */ 254 __u64 inum; /* in */
255 __u32 size; /* in */ 255 __u64 size; /* in */
256 __u64 reserved[4]; 256 __u64 reserved[4];
257 /* struct btrfs_data_container *fspath; out */ 257 /* struct btrfs_data_container *fspath; out */
258 __u64 fspath; /* out */ 258 __u64 fspath; /* out */
@@ -260,7 +260,7 @@ struct btrfs_ioctl_ino_path_args {
260 260
261struct btrfs_ioctl_logical_ino_args { 261struct btrfs_ioctl_logical_ino_args {
262 __u64 logical; /* in */ 262 __u64 logical; /* in */
263 __u32 size; /* in */ 263 __u64 size; /* in */
264 __u64 reserved[4]; 264 __u64 reserved[4];
265 /* struct btrfs_data_container *inodes; out */ 265 /* struct btrfs_data_container *inodes; out */
266 __u64 inodes; 266 __u64 inodes;
diff --git a/fs/btrfs/reada.c b/fs/btrfs/reada.c
index dc5d33146fdb..ac5d01085884 100644
--- a/fs/btrfs/reada.c
+++ b/fs/btrfs/reada.c
@@ -250,14 +250,12 @@ static struct reada_zone *reada_find_zone(struct btrfs_fs_info *fs_info,
250 struct btrfs_bio *bbio) 250 struct btrfs_bio *bbio)
251{ 251{
252 int ret; 252 int ret;
253 int looped = 0;
254 struct reada_zone *zone; 253 struct reada_zone *zone;
255 struct btrfs_block_group_cache *cache = NULL; 254 struct btrfs_block_group_cache *cache = NULL;
256 u64 start; 255 u64 start;
257 u64 end; 256 u64 end;
258 int i; 257 int i;
259 258
260again:
261 zone = NULL; 259 zone = NULL;
262 spin_lock(&fs_info->reada_lock); 260 spin_lock(&fs_info->reada_lock);
263 ret = radix_tree_gang_lookup(&dev->reada_zones, (void **)&zone, 261 ret = radix_tree_gang_lookup(&dev->reada_zones, (void **)&zone,
@@ -274,9 +272,6 @@ again:
274 spin_unlock(&fs_info->reada_lock); 272 spin_unlock(&fs_info->reada_lock);
275 } 273 }
276 274
277 if (looped)
278 return NULL;
279
280 cache = btrfs_lookup_block_group(fs_info, logical); 275 cache = btrfs_lookup_block_group(fs_info, logical);
281 if (!cache) 276 if (!cache)
282 return NULL; 277 return NULL;
@@ -307,13 +302,15 @@ again:
307 ret = radix_tree_insert(&dev->reada_zones, 302 ret = radix_tree_insert(&dev->reada_zones,
308 (unsigned long)(zone->end >> PAGE_CACHE_SHIFT), 303 (unsigned long)(zone->end >> PAGE_CACHE_SHIFT),
309 zone); 304 zone);
310 spin_unlock(&fs_info->reada_lock);
311 305
312 if (ret) { 306 if (ret == -EEXIST) {
313 kfree(zone); 307 kfree(zone);
314 looped = 1; 308 ret = radix_tree_gang_lookup(&dev->reada_zones, (void **)&zone,
315 goto again; 309 logical >> PAGE_CACHE_SHIFT, 1);
310 if (ret == 1)
311 kref_get(&zone->refcnt);
316 } 312 }
313 spin_unlock(&fs_info->reada_lock);
317 314
318 return zone; 315 return zone;
319} 316}
@@ -323,26 +320,26 @@ static struct reada_extent *reada_find_extent(struct btrfs_root *root,
323 struct btrfs_key *top, int level) 320 struct btrfs_key *top, int level)
324{ 321{
325 int ret; 322 int ret;
326 int looped = 0;
327 struct reada_extent *re = NULL; 323 struct reada_extent *re = NULL;
324 struct reada_extent *re_exist = NULL;
328 struct btrfs_fs_info *fs_info = root->fs_info; 325 struct btrfs_fs_info *fs_info = root->fs_info;
329 struct btrfs_mapping_tree *map_tree = &fs_info->mapping_tree; 326 struct btrfs_mapping_tree *map_tree = &fs_info->mapping_tree;
330 struct btrfs_bio *bbio = NULL; 327 struct btrfs_bio *bbio = NULL;
331 struct btrfs_device *dev; 328 struct btrfs_device *dev;
329 struct btrfs_device *prev_dev;
332 u32 blocksize; 330 u32 blocksize;
333 u64 length; 331 u64 length;
334 int nzones = 0; 332 int nzones = 0;
335 int i; 333 int i;
336 unsigned long index = logical >> PAGE_CACHE_SHIFT; 334 unsigned long index = logical >> PAGE_CACHE_SHIFT;
337 335
338again:
339 spin_lock(&fs_info->reada_lock); 336 spin_lock(&fs_info->reada_lock);
340 re = radix_tree_lookup(&fs_info->reada_tree, index); 337 re = radix_tree_lookup(&fs_info->reada_tree, index);
341 if (re) 338 if (re)
342 kref_get(&re->refcnt); 339 kref_get(&re->refcnt);
343 spin_unlock(&fs_info->reada_lock); 340 spin_unlock(&fs_info->reada_lock);
344 341
345 if (re || looped) 342 if (re)
346 return re; 343 return re;
347 344
348 re = kzalloc(sizeof(*re), GFP_NOFS); 345 re = kzalloc(sizeof(*re), GFP_NOFS);
@@ -398,16 +395,31 @@ again:
398 /* insert extent in reada_tree + all per-device trees, all or nothing */ 395 /* insert extent in reada_tree + all per-device trees, all or nothing */
399 spin_lock(&fs_info->reada_lock); 396 spin_lock(&fs_info->reada_lock);
400 ret = radix_tree_insert(&fs_info->reada_tree, index, re); 397 ret = radix_tree_insert(&fs_info->reada_tree, index, re);
398 if (ret == -EEXIST) {
399 re_exist = radix_tree_lookup(&fs_info->reada_tree, index);
400 BUG_ON(!re_exist);
401 kref_get(&re_exist->refcnt);
402 spin_unlock(&fs_info->reada_lock);
403 goto error;
404 }
401 if (ret) { 405 if (ret) {
402 spin_unlock(&fs_info->reada_lock); 406 spin_unlock(&fs_info->reada_lock);
403 if (ret != -ENOMEM) {
404 /* someone inserted the extent in the meantime */
405 looped = 1;
406 }
407 goto error; 407 goto error;
408 } 408 }
409 prev_dev = NULL;
409 for (i = 0; i < nzones; ++i) { 410 for (i = 0; i < nzones; ++i) {
410 dev = bbio->stripes[i].dev; 411 dev = bbio->stripes[i].dev;
412 if (dev == prev_dev) {
413 /*
414 * in case of DUP, just add the first zone. As both
415 * are on the same device, there's nothing to gain
416 * from adding both.
417 * Also, it wouldn't work, as the tree is per device
418 * and adding would fail with EEXIST
419 */
420 continue;
421 }
422 prev_dev = dev;
411 ret = radix_tree_insert(&dev->reada_extents, index, re); 423 ret = radix_tree_insert(&dev->reada_extents, index, re);
412 if (ret) { 424 if (ret) {
413 while (--i >= 0) { 425 while (--i >= 0) {
@@ -450,9 +462,7 @@ error:
450 } 462 }
451 kfree(bbio); 463 kfree(bbio);
452 kfree(re); 464 kfree(re);
453 if (looped) 465 return re_exist;
454 goto again;
455 return NULL;
456} 466}
457 467
458static void reada_kref_dummy(struct kref *kr) 468static void reada_kref_dummy(struct kref *kr)
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 017281dbb2a7..646ee21bb035 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -1279,7 +1279,9 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
1279 if (rb_node) 1279 if (rb_node)
1280 backref_tree_panic(rb_node, -EEXIST, node->bytenr); 1280 backref_tree_panic(rb_node, -EEXIST, node->bytenr);
1281 } else { 1281 } else {
1282 spin_lock(&root->fs_info->trans_lock);
1282 list_del_init(&root->root_list); 1283 list_del_init(&root->root_list);
1284 spin_unlock(&root->fs_info->trans_lock);
1283 kfree(node); 1285 kfree(node);
1284 } 1286 }
1285 return 0; 1287 return 0;
@@ -3811,7 +3813,7 @@ restart:
3811 3813
3812 ret = btrfs_block_rsv_check(rc->extent_root, rc->block_rsv, 5); 3814 ret = btrfs_block_rsv_check(rc->extent_root, rc->block_rsv, 5);
3813 if (ret < 0) { 3815 if (ret < 0) {
3814 if (ret != -EAGAIN) { 3816 if (ret != -ENOSPC) {
3815 err = ret; 3817 err = ret;
3816 WARN_ON(1); 3818 WARN_ON(1);
3817 break; 3819 break;
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index 90acc82046c3..2f3d6f917fb3 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -998,6 +998,7 @@ static int scrub_setup_recheck_block(struct scrub_dev *sdev,
998 page = sblock->pagev + page_index; 998 page = sblock->pagev + page_index;
999 page->logical = logical; 999 page->logical = logical;
1000 page->physical = bbio->stripes[mirror_index].physical; 1000 page->physical = bbio->stripes[mirror_index].physical;
1001 /* for missing devices, bdev is NULL */
1001 page->bdev = bbio->stripes[mirror_index].dev->bdev; 1002 page->bdev = bbio->stripes[mirror_index].dev->bdev;
1002 page->mirror_num = mirror_index + 1; 1003 page->mirror_num = mirror_index + 1;
1003 page->page = alloc_page(GFP_NOFS); 1004 page->page = alloc_page(GFP_NOFS);
@@ -1042,8 +1043,16 @@ static int scrub_recheck_block(struct btrfs_fs_info *fs_info,
1042 struct scrub_page *page = sblock->pagev + page_num; 1043 struct scrub_page *page = sblock->pagev + page_num;
1043 DECLARE_COMPLETION_ONSTACK(complete); 1044 DECLARE_COMPLETION_ONSTACK(complete);
1044 1045
1046 if (page->bdev == NULL) {
1047 page->io_error = 1;
1048 sblock->no_io_error_seen = 0;
1049 continue;
1050 }
1051
1045 BUG_ON(!page->page); 1052 BUG_ON(!page->page);
1046 bio = bio_alloc(GFP_NOFS, 1); 1053 bio = bio_alloc(GFP_NOFS, 1);
1054 if (!bio)
1055 return -EIO;
1047 bio->bi_bdev = page->bdev; 1056 bio->bi_bdev = page->bdev;
1048 bio->bi_sector = page->physical >> 9; 1057 bio->bi_sector = page->physical >> 9;
1049 bio->bi_end_io = scrub_complete_bio_end_io; 1058 bio->bi_end_io = scrub_complete_bio_end_io;
@@ -1171,6 +1180,8 @@ static int scrub_repair_page_from_good_copy(struct scrub_block *sblock_bad,
1171 DECLARE_COMPLETION_ONSTACK(complete); 1180 DECLARE_COMPLETION_ONSTACK(complete);
1172 1181
1173 bio = bio_alloc(GFP_NOFS, 1); 1182 bio = bio_alloc(GFP_NOFS, 1);
1183 if (!bio)
1184 return -EIO;
1174 bio->bi_bdev = page_bad->bdev; 1185 bio->bi_bdev = page_bad->bdev;
1175 bio->bi_sector = page_bad->physical >> 9; 1186 bio->bi_sector = page_bad->physical >> 9;
1176 bio->bi_end_io = scrub_complete_bio_end_io; 1187 bio->bi_end_io = scrub_complete_bio_end_io;
@@ -1253,12 +1264,6 @@ static int scrub_checksum_data(struct scrub_block *sblock)
1253 if (memcmp(csum, on_disk_csum, sdev->csum_size)) 1264 if (memcmp(csum, on_disk_csum, sdev->csum_size))
1254 fail = 1; 1265 fail = 1;
1255 1266
1256 if (fail) {
1257 spin_lock(&sdev->stat_lock);
1258 ++sdev->stat.csum_errors;
1259 spin_unlock(&sdev->stat_lock);
1260 }
1261
1262 return fail; 1267 return fail;
1263} 1268}
1264 1269
@@ -1331,15 +1336,6 @@ static int scrub_checksum_tree_block(struct scrub_block *sblock)
1331 if (memcmp(calculated_csum, on_disk_csum, sdev->csum_size)) 1336 if (memcmp(calculated_csum, on_disk_csum, sdev->csum_size))
1332 ++crc_fail; 1337 ++crc_fail;
1333 1338
1334 if (crc_fail || fail) {
1335 spin_lock(&sdev->stat_lock);
1336 if (crc_fail)
1337 ++sdev->stat.csum_errors;
1338 if (fail)
1339 ++sdev->stat.verify_errors;
1340 spin_unlock(&sdev->stat_lock);
1341 }
1342
1343 return fail || crc_fail; 1339 return fail || crc_fail;
1344} 1340}
1345 1341
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 8d5d380f7bdb..c5f8fca4195f 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -815,7 +815,6 @@ int btrfs_sync_fs(struct super_block *sb, int wait)
815 return 0; 815 return 0;
816 } 816 }
817 817
818 btrfs_start_delalloc_inodes(root, 0);
819 btrfs_wait_ordered_extents(root, 0, 0); 818 btrfs_wait_ordered_extents(root, 0, 0);
820 819
821 trans = btrfs_start_transaction(root, 0); 820 trans = btrfs_start_transaction(root, 0);
@@ -1148,13 +1147,15 @@ static int btrfs_remount(struct super_block *sb, int *flags, char *data)
1148 if (ret) 1147 if (ret)
1149 goto restore; 1148 goto restore;
1150 } else { 1149 } else {
1151 if (fs_info->fs_devices->rw_devices == 0) 1150 if (fs_info->fs_devices->rw_devices == 0) {
1152 ret = -EACCES; 1151 ret = -EACCES;
1153 goto restore; 1152 goto restore;
1153 }
1154 1154
1155 if (btrfs_super_log_root(fs_info->super_copy) != 0) 1155 if (btrfs_super_log_root(fs_info->super_copy) != 0) {
1156 ret = -EINVAL; 1156 ret = -EINVAL;
1157 goto restore; 1157 goto restore;
1158 }
1158 1159
1159 ret = btrfs_cleanup_fs_roots(fs_info); 1160 ret = btrfs_cleanup_fs_roots(fs_info);
1160 if (ret) 1161 if (ret)
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index 8da29e8e4de1..36422254ef67 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -73,8 +73,10 @@ loop:
73 73
74 cur_trans = root->fs_info->running_transaction; 74 cur_trans = root->fs_info->running_transaction;
75 if (cur_trans) { 75 if (cur_trans) {
76 if (cur_trans->aborted) 76 if (cur_trans->aborted) {
77 spin_unlock(&root->fs_info->trans_lock);
77 return cur_trans->aborted; 78 return cur_trans->aborted;
79 }
78 atomic_inc(&cur_trans->use_count); 80 atomic_inc(&cur_trans->use_count);
79 atomic_inc(&cur_trans->num_writers); 81 atomic_inc(&cur_trans->num_writers);
80 cur_trans->num_joined++; 82 cur_trans->num_joined++;
@@ -480,6 +482,7 @@ static int __btrfs_end_transaction(struct btrfs_trans_handle *trans,
480 struct btrfs_transaction *cur_trans = trans->transaction; 482 struct btrfs_transaction *cur_trans = trans->transaction;
481 struct btrfs_fs_info *info = root->fs_info; 483 struct btrfs_fs_info *info = root->fs_info;
482 int count = 0; 484 int count = 0;
485 int err = 0;
483 486
484 if (--trans->use_count) { 487 if (--trans->use_count) {
485 trans->block_rsv = trans->orig_rsv; 488 trans->block_rsv = trans->orig_rsv;
@@ -532,18 +535,18 @@ static int __btrfs_end_transaction(struct btrfs_trans_handle *trans,
532 535
533 if (current->journal_info == trans) 536 if (current->journal_info == trans)
534 current->journal_info = NULL; 537 current->journal_info = NULL;
535 memset(trans, 0, sizeof(*trans));
536 kmem_cache_free(btrfs_trans_handle_cachep, trans);
537 538
538 if (throttle) 539 if (throttle)
539 btrfs_run_delayed_iputs(root); 540 btrfs_run_delayed_iputs(root);
540 541
541 if (trans->aborted || 542 if (trans->aborted ||
542 root->fs_info->fs_state & BTRFS_SUPER_FLAG_ERROR) { 543 root->fs_info->fs_state & BTRFS_SUPER_FLAG_ERROR) {
543 return -EIO; 544 err = -EIO;
544 } 545 }
545 546
546 return 0; 547 memset(trans, 0, sizeof(*trans));
548 kmem_cache_free(btrfs_trans_handle_cachep, trans);
549 return err;
547} 550}
548 551
549int btrfs_end_transaction(struct btrfs_trans_handle *trans, 552int btrfs_end_transaction(struct btrfs_trans_handle *trans,
@@ -1399,6 +1402,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans,
1399 ret = commit_fs_roots(trans, root); 1402 ret = commit_fs_roots(trans, root);
1400 if (ret) { 1403 if (ret) {
1401 mutex_unlock(&root->fs_info->tree_log_mutex); 1404 mutex_unlock(&root->fs_info->tree_log_mutex);
1405 mutex_unlock(&root->fs_info->reloc_mutex);
1402 goto cleanup_transaction; 1406 goto cleanup_transaction;
1403 } 1407 }
1404 1408
@@ -1410,6 +1414,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans,
1410 ret = commit_cowonly_roots(trans, root); 1414 ret = commit_cowonly_roots(trans, root);
1411 if (ret) { 1415 if (ret) {
1412 mutex_unlock(&root->fs_info->tree_log_mutex); 1416 mutex_unlock(&root->fs_info->tree_log_mutex);
1417 mutex_unlock(&root->fs_info->reloc_mutex);
1413 goto cleanup_transaction; 1418 goto cleanup_transaction;
1414 } 1419 }
1415 1420
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index d017283ae6f5..eb1ae908582c 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -279,7 +279,7 @@ static int process_one_buffer(struct btrfs_root *log,
279 log->fs_info->extent_root, 279 log->fs_info->extent_root,
280 eb->start, eb->len); 280 eb->start, eb->len);
281 281
282 if (btrfs_buffer_uptodate(eb, gen)) { 282 if (btrfs_buffer_uptodate(eb, gen, 0)) {
283 if (wc->write) 283 if (wc->write)
284 btrfs_write_tree_block(eb); 284 btrfs_write_tree_block(eb);
285 if (wc->wait) 285 if (wc->wait)
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index a872b48be0ae..1411b99555a4 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -3324,12 +3324,14 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
3324 stripe_size = devices_info[ndevs-1].max_avail; 3324 stripe_size = devices_info[ndevs-1].max_avail;
3325 num_stripes = ndevs * dev_stripes; 3325 num_stripes = ndevs * dev_stripes;
3326 3326
3327 if (stripe_size * num_stripes > max_chunk_size * ncopies) { 3327 if (stripe_size * ndevs > max_chunk_size * ncopies) {
3328 stripe_size = max_chunk_size * ncopies; 3328 stripe_size = max_chunk_size * ncopies;
3329 do_div(stripe_size, num_stripes); 3329 do_div(stripe_size, ndevs);
3330 } 3330 }
3331 3331
3332 do_div(stripe_size, dev_stripes); 3332 do_div(stripe_size, dev_stripes);
3333
3334 /* align to BTRFS_STRIPE_LEN */
3333 do_div(stripe_size, BTRFS_STRIPE_LEN); 3335 do_div(stripe_size, BTRFS_STRIPE_LEN);
3334 stripe_size *= BTRFS_STRIPE_LEN; 3336 stripe_size *= BTRFS_STRIPE_LEN;
3335 3337
@@ -3805,10 +3807,11 @@ static int __btrfs_map_block(struct btrfs_mapping_tree *map_tree, int rw,
3805 else if (mirror_num) 3807 else if (mirror_num)
3806 stripe_index += mirror_num - 1; 3808 stripe_index += mirror_num - 1;
3807 else { 3809 else {
3810 int old_stripe_index = stripe_index;
3808 stripe_index = find_live_mirror(map, stripe_index, 3811 stripe_index = find_live_mirror(map, stripe_index,
3809 map->sub_stripes, stripe_index + 3812 map->sub_stripes, stripe_index +
3810 current->pid % map->sub_stripes); 3813 current->pid % map->sub_stripes);
3811 mirror_num = stripe_index + 1; 3814 mirror_num = stripe_index - old_stripe_index + 1;
3812 } 3815 }
3813 } else { 3816 } else {
3814 /* 3817 /*
@@ -3833,6 +3836,7 @@ static int __btrfs_map_block(struct btrfs_mapping_tree *map_tree, int rw,
3833 int sub_stripes = 0; 3836 int sub_stripes = 0;
3834 u64 stripes_per_dev = 0; 3837 u64 stripes_per_dev = 0;
3835 u32 remaining_stripes = 0; 3838 u32 remaining_stripes = 0;
3839 u32 last_stripe = 0;
3836 3840
3837 if (map->type & 3841 if (map->type &
3838 (BTRFS_BLOCK_GROUP_RAID0 | BTRFS_BLOCK_GROUP_RAID10)) { 3842 (BTRFS_BLOCK_GROUP_RAID0 | BTRFS_BLOCK_GROUP_RAID10)) {
@@ -3846,6 +3850,8 @@ static int __btrfs_map_block(struct btrfs_mapping_tree *map_tree, int rw,
3846 stripe_nr_orig, 3850 stripe_nr_orig,
3847 factor, 3851 factor,
3848 &remaining_stripes); 3852 &remaining_stripes);
3853 div_u64_rem(stripe_nr_end - 1, factor, &last_stripe);
3854 last_stripe *= sub_stripes;
3849 } 3855 }
3850 3856
3851 for (i = 0; i < num_stripes; i++) { 3857 for (i = 0; i < num_stripes; i++) {
@@ -3858,16 +3864,29 @@ static int __btrfs_map_block(struct btrfs_mapping_tree *map_tree, int rw,
3858 BTRFS_BLOCK_GROUP_RAID10)) { 3864 BTRFS_BLOCK_GROUP_RAID10)) {
3859 bbio->stripes[i].length = stripes_per_dev * 3865 bbio->stripes[i].length = stripes_per_dev *
3860 map->stripe_len; 3866 map->stripe_len;
3867
3861 if (i / sub_stripes < remaining_stripes) 3868 if (i / sub_stripes < remaining_stripes)
3862 bbio->stripes[i].length += 3869 bbio->stripes[i].length +=
3863 map->stripe_len; 3870 map->stripe_len;
3871
3872 /*
3873 * Special for the first stripe and
3874 * the last stripe:
3875 *
3876 * |-------|...|-------|
3877 * |----------|
3878 * off end_off
3879 */
3864 if (i < sub_stripes) 3880 if (i < sub_stripes)
3865 bbio->stripes[i].length -= 3881 bbio->stripes[i].length -=
3866 stripe_offset; 3882 stripe_offset;
3867 if ((i / sub_stripes + 1) % 3883
3868 sub_stripes == remaining_stripes) 3884 if (stripe_index >= last_stripe &&
3885 stripe_index <= (last_stripe +
3886 sub_stripes - 1))
3869 bbio->stripes[i].length -= 3887 bbio->stripes[i].length -=
3870 stripe_end_offset; 3888 stripe_end_offset;
3889
3871 if (i == sub_stripes - 1) 3890 if (i == sub_stripes - 1)
3872 stripe_offset = 0; 3891 stripe_offset = 0;
3873 } else 3892 } else
@@ -4334,8 +4353,10 @@ static int open_seed_devices(struct btrfs_root *root, u8 *fsid)
4334 4353
4335 ret = __btrfs_open_devices(fs_devices, FMODE_READ, 4354 ret = __btrfs_open_devices(fs_devices, FMODE_READ,
4336 root->fs_info->bdev_holder); 4355 root->fs_info->bdev_holder);
4337 if (ret) 4356 if (ret) {
4357 free_fs_devices(fs_devices);
4338 goto out; 4358 goto out;
4359 }
4339 4360
4340 if (!fs_devices->seeding) { 4361 if (!fs_devices->seeding) {
4341 __btrfs_close_devices(fs_devices); 4362 __btrfs_close_devices(fs_devices);
diff --git a/fs/buffer.c b/fs/buffer.c
index 36d66653b931..351e18ea2e53 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -985,7 +985,6 @@ grow_dev_page(struct block_device *bdev, sector_t block,
985 return page; 985 return page;
986 986
987failed: 987failed:
988 BUG();
989 unlock_page(page); 988 unlock_page(page);
990 page_cache_release(page); 989 page_cache_release(page);
991 return NULL; 990 return NULL;
diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
index d34212822444..541ef81f6ae8 100644
--- a/fs/cifs/cifsfs.c
+++ b/fs/cifs/cifsfs.c
@@ -370,13 +370,13 @@ cifs_show_options(struct seq_file *s, struct dentry *root)
370 (int)(srcaddr->sa_family)); 370 (int)(srcaddr->sa_family));
371 } 371 }
372 372
373 seq_printf(s, ",uid=%d", cifs_sb->mnt_uid); 373 seq_printf(s, ",uid=%u", cifs_sb->mnt_uid);
374 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_UID) 374 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_UID)
375 seq_printf(s, ",forceuid"); 375 seq_printf(s, ",forceuid");
376 else 376 else
377 seq_printf(s, ",noforceuid"); 377 seq_printf(s, ",noforceuid");
378 378
379 seq_printf(s, ",gid=%d", cifs_sb->mnt_gid); 379 seq_printf(s, ",gid=%u", cifs_sb->mnt_gid);
380 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_GID) 380 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_GID)
381 seq_printf(s, ",forcegid"); 381 seq_printf(s, ",forcegid");
382 else 382 else
@@ -434,11 +434,15 @@ cifs_show_options(struct seq_file *s, struct dentry *root)
434 seq_printf(s, ",noperm"); 434 seq_printf(s, ",noperm");
435 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO) 435 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO)
436 seq_printf(s, ",strictcache"); 436 seq_printf(s, ",strictcache");
437 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_BACKUPUID)
438 seq_printf(s, ",backupuid=%u", cifs_sb->mnt_backupuid);
439 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_BACKUPGID)
440 seq_printf(s, ",backupgid=%u", cifs_sb->mnt_backupgid);
437 441
438 seq_printf(s, ",rsize=%d", cifs_sb->rsize); 442 seq_printf(s, ",rsize=%u", cifs_sb->rsize);
439 seq_printf(s, ",wsize=%d", cifs_sb->wsize); 443 seq_printf(s, ",wsize=%u", cifs_sb->wsize);
440 /* convert actimeo and display it in seconds */ 444 /* convert actimeo and display it in seconds */
441 seq_printf(s, ",actimeo=%lu", cifs_sb->actimeo / HZ); 445 seq_printf(s, ",actimeo=%lu", cifs_sb->actimeo / HZ);
442 446
443 return 0; 447 return 0;
444} 448}
@@ -695,7 +699,7 @@ static loff_t cifs_llseek(struct file *file, loff_t offset, int origin)
695 * origin == SEEK_END || SEEK_DATA || SEEK_HOLE => we must revalidate 699 * origin == SEEK_END || SEEK_DATA || SEEK_HOLE => we must revalidate
696 * the cached file length 700 * the cached file length
697 */ 701 */
698 if (origin != SEEK_SET || origin != SEEK_CUR) { 702 if (origin != SEEK_SET && origin != SEEK_CUR) {
699 int rc; 703 int rc;
700 struct inode *inode = file->f_path.dentry->d_inode; 704 struct inode *inode = file->f_path.dentry->d_inode;
701 705
diff --git a/fs/cifs/cifsfs.h b/fs/cifs/cifsfs.h
index d1389bb33ceb..65365358c976 100644
--- a/fs/cifs/cifsfs.h
+++ b/fs/cifs/cifsfs.h
@@ -125,5 +125,5 @@ extern long cifs_ioctl(struct file *filep, unsigned int cmd, unsigned long arg);
125extern const struct export_operations cifs_export_ops; 125extern const struct export_operations cifs_export_ops;
126#endif /* CONFIG_CIFS_NFSD_EXPORT */ 126#endif /* CONFIG_CIFS_NFSD_EXPORT */
127 127
128#define CIFS_VERSION "1.77" 128#define CIFS_VERSION "1.78"
129#endif /* _CIFSFS_H */ 129#endif /* _CIFSFS_H */
diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c
index 8fecc99be344..da2f5446fa7a 100644
--- a/fs/cifs/cifssmb.c
+++ b/fs/cifs/cifssmb.c
@@ -3892,13 +3892,12 @@ CIFSSMBSetCIFSACL(const int xid, struct cifs_tcon *tcon, __u16 fid,
3892 int rc = 0; 3892 int rc = 0;
3893 int bytes_returned = 0; 3893 int bytes_returned = 0;
3894 SET_SEC_DESC_REQ *pSMB = NULL; 3894 SET_SEC_DESC_REQ *pSMB = NULL;
3895 NTRANSACT_RSP *pSMBr = NULL; 3895 void *pSMBr;
3896 3896
3897setCifsAclRetry: 3897setCifsAclRetry:
3898 rc = smb_init(SMB_COM_NT_TRANSACT, 19, tcon, (void **) &pSMB, 3898 rc = smb_init(SMB_COM_NT_TRANSACT, 19, tcon, (void **) &pSMB, &pSMBr);
3899 (void **) &pSMBr);
3900 if (rc) 3899 if (rc)
3901 return (rc); 3900 return rc;
3902 3901
3903 pSMB->MaxSetupCount = 0; 3902 pSMB->MaxSetupCount = 0;
3904 pSMB->Reserved = 0; 3903 pSMB->Reserved = 0;
@@ -3926,9 +3925,8 @@ setCifsAclRetry:
3926 pSMB->AclFlags = cpu_to_le32(aclflag); 3925 pSMB->AclFlags = cpu_to_le32(aclflag);
3927 3926
3928 if (pntsd && acllen) { 3927 if (pntsd && acllen) {
3929 memcpy((char *) &pSMBr->hdr.Protocol + data_offset, 3928 memcpy((char *)pSMBr + offsetof(struct smb_hdr, Protocol) +
3930 (char *) pntsd, 3929 data_offset, pntsd, acllen);
3931 acllen);
3932 inc_rfc1001_len(pSMB, byte_count + data_count); 3930 inc_rfc1001_len(pSMB, byte_count + data_count);
3933 } else 3931 } else
3934 inc_rfc1001_len(pSMB, byte_count); 3932 inc_rfc1001_len(pSMB, byte_count);
@@ -4846,8 +4844,12 @@ parse_DFS_referrals(TRANSACTION2_GET_DFS_REFER_RSP *pSMBr,
4846 max_len = data_end - temp; 4844 max_len = data_end - temp;
4847 node->node_name = cifs_strndup_from_utf16(temp, max_len, 4845 node->node_name = cifs_strndup_from_utf16(temp, max_len,
4848 is_unicode, nls_codepage); 4846 is_unicode, nls_codepage);
4849 if (!node->node_name) 4847 if (!node->node_name) {
4850 rc = -ENOMEM; 4848 rc = -ENOMEM;
4849 goto parse_DFS_referrals_exit;
4850 }
4851
4852 ref++;
4851 } 4853 }
4852 4854
4853parse_DFS_referrals_exit: 4855parse_DFS_referrals_exit:
@@ -5708,7 +5710,8 @@ CIFSSMBSetFileInfo(const int xid, struct cifs_tcon *tcon,
5708 param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; 5710 param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4;
5709 offset = param_offset + params; 5711 offset = param_offset + params;
5710 5712
5711 data_offset = (char *) (&pSMB->hdr.Protocol) + offset; 5713 data_offset = (char *)pSMB +
5714 offsetof(struct smb_hdr, Protocol) + offset;
5712 5715
5713 count = sizeof(FILE_BASIC_INFO); 5716 count = sizeof(FILE_BASIC_INFO);
5714 pSMB->MaxParameterCount = cpu_to_le16(2); 5717 pSMB->MaxParameterCount = cpu_to_le16(2);
@@ -5977,7 +5980,7 @@ CIFSSMBUnixSetFileInfo(const int xid, struct cifs_tcon *tcon,
5977 u16 fid, u32 pid_of_opener) 5980 u16 fid, u32 pid_of_opener)
5978{ 5981{
5979 struct smb_com_transaction2_sfi_req *pSMB = NULL; 5982 struct smb_com_transaction2_sfi_req *pSMB = NULL;
5980 FILE_UNIX_BASIC_INFO *data_offset; 5983 char *data_offset;
5981 int rc = 0; 5984 int rc = 0;
5982 u16 params, param_offset, offset, byte_count, count; 5985 u16 params, param_offset, offset, byte_count, count;
5983 5986
@@ -5999,8 +6002,9 @@ CIFSSMBUnixSetFileInfo(const int xid, struct cifs_tcon *tcon,
5999 param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; 6002 param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4;
6000 offset = param_offset + params; 6003 offset = param_offset + params;
6001 6004
6002 data_offset = (FILE_UNIX_BASIC_INFO *) 6005 data_offset = (char *)pSMB +
6003 ((char *)(&pSMB->hdr.Protocol) + offset); 6006 offsetof(struct smb_hdr, Protocol) + offset;
6007
6004 count = sizeof(FILE_UNIX_BASIC_INFO); 6008 count = sizeof(FILE_UNIX_BASIC_INFO);
6005 6009
6006 pSMB->MaxParameterCount = cpu_to_le16(2); 6010 pSMB->MaxParameterCount = cpu_to_le16(2);
@@ -6022,7 +6026,7 @@ CIFSSMBUnixSetFileInfo(const int xid, struct cifs_tcon *tcon,
6022 inc_rfc1001_len(pSMB, byte_count); 6026 inc_rfc1001_len(pSMB, byte_count);
6023 pSMB->ByteCount = cpu_to_le16(byte_count); 6027 pSMB->ByteCount = cpu_to_le16(byte_count);
6024 6028
6025 cifs_fill_unix_set_info(data_offset, args); 6029 cifs_fill_unix_set_info((FILE_UNIX_BASIC_INFO *)data_offset, args);
6026 6030
6027 rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); 6031 rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0);
6028 if (rc) 6032 if (rc)
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index 302a15c505a9..5dcc55197fb3 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -109,6 +109,8 @@ enum {
109 109
110 /* Options which could be blank */ 110 /* Options which could be blank */
111 Opt_blank_pass, 111 Opt_blank_pass,
112 Opt_blank_user,
113 Opt_blank_ip,
112 114
113 Opt_err 115 Opt_err
114}; 116};
@@ -183,11 +185,15 @@ static const match_table_t cifs_mount_option_tokens = {
183 { Opt_wsize, "wsize=%s" }, 185 { Opt_wsize, "wsize=%s" },
184 { Opt_actimeo, "actimeo=%s" }, 186 { Opt_actimeo, "actimeo=%s" },
185 187
188 { Opt_blank_user, "user=" },
189 { Opt_blank_user, "username=" },
186 { Opt_user, "user=%s" }, 190 { Opt_user, "user=%s" },
187 { Opt_user, "username=%s" }, 191 { Opt_user, "username=%s" },
188 { Opt_blank_pass, "pass=" }, 192 { Opt_blank_pass, "pass=" },
189 { Opt_pass, "pass=%s" }, 193 { Opt_pass, "pass=%s" },
190 { Opt_pass, "password=%s" }, 194 { Opt_pass, "password=%s" },
195 { Opt_blank_ip, "ip=" },
196 { Opt_blank_ip, "addr=" },
191 { Opt_ip, "ip=%s" }, 197 { Opt_ip, "ip=%s" },
192 { Opt_ip, "addr=%s" }, 198 { Opt_ip, "addr=%s" },
193 { Opt_unc, "unc=%s" }, 199 { Opt_unc, "unc=%s" },
@@ -209,6 +215,8 @@ static const match_table_t cifs_mount_option_tokens = {
209 215
210 { Opt_ignore, "cred" }, 216 { Opt_ignore, "cred" },
211 { Opt_ignore, "credentials" }, 217 { Opt_ignore, "credentials" },
218 { Opt_ignore, "cred=%s" },
219 { Opt_ignore, "credentials=%s" },
212 { Opt_ignore, "guest" }, 220 { Opt_ignore, "guest" },
213 { Opt_ignore, "rw" }, 221 { Opt_ignore, "rw" },
214 { Opt_ignore, "ro" }, 222 { Opt_ignore, "ro" },
@@ -1117,7 +1125,7 @@ static int get_option_ul(substring_t args[], unsigned long *option)
1117 string = match_strdup(args); 1125 string = match_strdup(args);
1118 if (string == NULL) 1126 if (string == NULL)
1119 return -ENOMEM; 1127 return -ENOMEM;
1120 rc = kstrtoul(string, 10, option); 1128 rc = kstrtoul(string, 0, option);
1121 kfree(string); 1129 kfree(string);
1122 1130
1123 return rc; 1131 return rc;
@@ -1534,15 +1542,17 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
1534 1542
1535 /* String Arguments */ 1543 /* String Arguments */
1536 1544
1545 case Opt_blank_user:
1546 /* null user, ie. anonymous authentication */
1547 vol->nullauth = 1;
1548 vol->username = NULL;
1549 break;
1537 case Opt_user: 1550 case Opt_user:
1538 string = match_strdup(args); 1551 string = match_strdup(args);
1539 if (string == NULL) 1552 if (string == NULL)
1540 goto out_nomem; 1553 goto out_nomem;
1541 1554
1542 if (!*string) { 1555 if (strnlen(string, MAX_USERNAME_SIZE) >
1543 /* null user, ie. anonymous authentication */
1544 vol->nullauth = 1;
1545 } else if (strnlen(string, MAX_USERNAME_SIZE) >
1546 MAX_USERNAME_SIZE) { 1556 MAX_USERNAME_SIZE) {
1547 printk(KERN_WARNING "CIFS: username too long\n"); 1557 printk(KERN_WARNING "CIFS: username too long\n");
1548 goto cifs_parse_mount_err; 1558 goto cifs_parse_mount_err;
@@ -1565,8 +1575,7 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
1565 1575
1566 /* Obtain the value string */ 1576 /* Obtain the value string */
1567 value = strchr(data, '='); 1577 value = strchr(data, '=');
1568 if (value != NULL) 1578 value++;
1569 *value++ = '\0';
1570 1579
1571 /* Set tmp_end to end of the string */ 1580 /* Set tmp_end to end of the string */
1572 tmp_end = (char *) value + strlen(value); 1581 tmp_end = (char *) value + strlen(value);
@@ -1612,14 +1621,15 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
1612 } 1621 }
1613 vol->password[j] = '\0'; 1622 vol->password[j] = '\0';
1614 break; 1623 break;
1624 case Opt_blank_ip:
1625 vol->UNCip = NULL;
1626 break;
1615 case Opt_ip: 1627 case Opt_ip:
1616 string = match_strdup(args); 1628 string = match_strdup(args);
1617 if (string == NULL) 1629 if (string == NULL)
1618 goto out_nomem; 1630 goto out_nomem;
1619 1631
1620 if (!*string) { 1632 if (strnlen(string, INET6_ADDRSTRLEN) >
1621 vol->UNCip = NULL;
1622 } else if (strnlen(string, INET6_ADDRSTRLEN) >
1623 INET6_ADDRSTRLEN) { 1633 INET6_ADDRSTRLEN) {
1624 printk(KERN_WARNING "CIFS: ip address " 1634 printk(KERN_WARNING "CIFS: ip address "
1625 "too long\n"); 1635 "too long\n");
@@ -1637,18 +1647,19 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
1637 if (string == NULL) 1647 if (string == NULL)
1638 goto out_nomem; 1648 goto out_nomem;
1639 1649
1640 if (!*string) {
1641 printk(KERN_WARNING "CIFS: invalid path to "
1642 "network resource\n");
1643 goto cifs_parse_mount_err;
1644 }
1645
1646 temp_len = strnlen(string, 300); 1650 temp_len = strnlen(string, 300);
1647 if (temp_len == 300) { 1651 if (temp_len == 300) {
1648 printk(KERN_WARNING "CIFS: UNC name too long\n"); 1652 printk(KERN_WARNING "CIFS: UNC name too long\n");
1649 goto cifs_parse_mount_err; 1653 goto cifs_parse_mount_err;
1650 } 1654 }
1651 1655
1656 vol->UNC = kmalloc(temp_len+1, GFP_KERNEL);
1657 if (vol->UNC == NULL) {
1658 printk(KERN_WARNING "CIFS: no memory for UNC\n");
1659 goto cifs_parse_mount_err;
1660 }
1661 strcpy(vol->UNC, string);
1662
1652 if (strncmp(string, "//", 2) == 0) { 1663 if (strncmp(string, "//", 2) == 0) {
1653 vol->UNC[0] = '\\'; 1664 vol->UNC[0] = '\\';
1654 vol->UNC[1] = '\\'; 1665 vol->UNC[1] = '\\';
@@ -1658,24 +1669,13 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
1658 goto cifs_parse_mount_err; 1669 goto cifs_parse_mount_err;
1659 } 1670 }
1660 1671
1661 vol->UNC = kmalloc(temp_len+1, GFP_KERNEL);
1662 if (vol->UNC == NULL) {
1663 printk(KERN_WARNING "CIFS: no memory "
1664 "for UNC\n");
1665 goto cifs_parse_mount_err;
1666 }
1667 strcpy(vol->UNC, string);
1668 break; 1672 break;
1669 case Opt_domain: 1673 case Opt_domain:
1670 string = match_strdup(args); 1674 string = match_strdup(args);
1671 if (string == NULL) 1675 if (string == NULL)
1672 goto out_nomem; 1676 goto out_nomem;
1673 1677
1674 if (!*string) { 1678 if (strnlen(string, 256) == 256) {
1675 printk(KERN_WARNING "CIFS: invalid domain"
1676 " name\n");
1677 goto cifs_parse_mount_err;
1678 } else if (strnlen(string, 256) == 256) {
1679 printk(KERN_WARNING "CIFS: domain name too" 1679 printk(KERN_WARNING "CIFS: domain name too"
1680 " long\n"); 1680 " long\n");
1681 goto cifs_parse_mount_err; 1681 goto cifs_parse_mount_err;
@@ -1694,11 +1694,7 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
1694 if (string == NULL) 1694 if (string == NULL)
1695 goto out_nomem; 1695 goto out_nomem;
1696 1696
1697 if (!*string) { 1697 if (!cifs_convert_address(
1698 printk(KERN_WARNING "CIFS: srcaddr value not"
1699 " specified\n");
1700 goto cifs_parse_mount_err;
1701 } else if (!cifs_convert_address(
1702 (struct sockaddr *)&vol->srcaddr, 1698 (struct sockaddr *)&vol->srcaddr,
1703 string, strlen(string))) { 1699 string, strlen(string))) {
1704 printk(KERN_WARNING "CIFS: Could not parse" 1700 printk(KERN_WARNING "CIFS: Could not parse"
@@ -1711,11 +1707,6 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
1711 if (string == NULL) 1707 if (string == NULL)
1712 goto out_nomem; 1708 goto out_nomem;
1713 1709
1714 if (!*string) {
1715 printk(KERN_WARNING "CIFS: Invalid path"
1716 " prefix\n");
1717 goto cifs_parse_mount_err;
1718 }
1719 temp_len = strnlen(string, 1024); 1710 temp_len = strnlen(string, 1024);
1720 if (string[0] != '/') 1711 if (string[0] != '/')
1721 temp_len++; /* missing leading slash */ 1712 temp_len++; /* missing leading slash */
@@ -1743,11 +1734,7 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
1743 if (string == NULL) 1734 if (string == NULL)
1744 goto out_nomem; 1735 goto out_nomem;
1745 1736
1746 if (!*string) { 1737 if (strnlen(string, 1024) >= 65) {
1747 printk(KERN_WARNING "CIFS: Invalid iocharset"
1748 " specified\n");
1749 goto cifs_parse_mount_err;
1750 } else if (strnlen(string, 1024) >= 65) {
1751 printk(KERN_WARNING "CIFS: iocharset name " 1738 printk(KERN_WARNING "CIFS: iocharset name "
1752 "too long.\n"); 1739 "too long.\n");
1753 goto cifs_parse_mount_err; 1740 goto cifs_parse_mount_err;
@@ -1772,11 +1759,6 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
1772 if (string == NULL) 1759 if (string == NULL)
1773 goto out_nomem; 1760 goto out_nomem;
1774 1761
1775 if (!*string) {
1776 printk(KERN_WARNING "CIFS: No socket option"
1777 " specified\n");
1778 goto cifs_parse_mount_err;
1779 }
1780 if (strnicmp(string, "TCP_NODELAY", 11) == 0) 1762 if (strnicmp(string, "TCP_NODELAY", 11) == 0)
1781 vol->sockopt_tcp_nodelay = 1; 1763 vol->sockopt_tcp_nodelay = 1;
1782 break; 1764 break;
@@ -1785,12 +1767,6 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
1785 if (string == NULL) 1767 if (string == NULL)
1786 goto out_nomem; 1768 goto out_nomem;
1787 1769
1788 if (!*string) {
1789 printk(KERN_WARNING "CIFS: Invalid (empty)"
1790 " netbiosname\n");
1791 break;
1792 }
1793
1794 memset(vol->source_rfc1001_name, 0x20, 1770 memset(vol->source_rfc1001_name, 0x20,
1795 RFC1001_NAME_LEN); 1771 RFC1001_NAME_LEN);
1796 /* 1772 /*
@@ -1818,11 +1794,6 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
1818 if (string == NULL) 1794 if (string == NULL)
1819 goto out_nomem; 1795 goto out_nomem;
1820 1796
1821 if (!*string) {
1822 printk(KERN_WARNING "CIFS: Empty server"
1823 " netbiosname specified\n");
1824 break;
1825 }
1826 /* last byte, type, is 0x20 for servr type */ 1797 /* last byte, type, is 0x20 for servr type */
1827 memset(vol->target_rfc1001_name, 0x20, 1798 memset(vol->target_rfc1001_name, 0x20,
1828 RFC1001_NAME_LEN_WITH_NULL); 1799 RFC1001_NAME_LEN_WITH_NULL);
@@ -1849,12 +1820,6 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
1849 if (string == NULL) 1820 if (string == NULL)
1850 goto out_nomem; 1821 goto out_nomem;
1851 1822
1852 if (!*string) {
1853 cERROR(1, "no protocol version specified"
1854 " after vers= mount option");
1855 goto cifs_parse_mount_err;
1856 }
1857
1858 if (strnicmp(string, "cifs", 4) == 0 || 1823 if (strnicmp(string, "cifs", 4) == 0 ||
1859 strnicmp(string, "1", 1) == 0) { 1824 strnicmp(string, "1", 1) == 0) {
1860 /* This is the default */ 1825 /* This is the default */
@@ -1869,12 +1834,6 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
1869 if (string == NULL) 1834 if (string == NULL)
1870 goto out_nomem; 1835 goto out_nomem;
1871 1836
1872 if (!*string) {
1873 printk(KERN_WARNING "CIFS: no security flavor"
1874 " specified\n");
1875 break;
1876 }
1877
1878 if (cifs_parse_security_flavors(string, vol) != 0) 1837 if (cifs_parse_security_flavors(string, vol) != 0)
1879 goto cifs_parse_mount_err; 1838 goto cifs_parse_mount_err;
1880 break; 1839 break;
@@ -2226,6 +2185,7 @@ cifs_get_tcp_session(struct smb_vol *volume_info)
2226 tcp_ses->session_estab = false; 2185 tcp_ses->session_estab = false;
2227 tcp_ses->sequence_number = 0; 2186 tcp_ses->sequence_number = 0;
2228 tcp_ses->lstrp = jiffies; 2187 tcp_ses->lstrp = jiffies;
2188 spin_lock_init(&tcp_ses->req_lock);
2229 INIT_LIST_HEAD(&tcp_ses->tcp_ses_list); 2189 INIT_LIST_HEAD(&tcp_ses->tcp_ses_list);
2230 INIT_LIST_HEAD(&tcp_ses->smb_ses_list); 2190 INIT_LIST_HEAD(&tcp_ses->smb_ses_list);
2231 INIT_DELAYED_WORK(&tcp_ses->echo, cifs_echo_request); 2191 INIT_DELAYED_WORK(&tcp_ses->echo, cifs_echo_request);
@@ -3271,10 +3231,6 @@ void cifs_setup_cifs_sb(struct smb_vol *pvolume_info,
3271 3231
3272 cifs_sb->mnt_uid = pvolume_info->linux_uid; 3232 cifs_sb->mnt_uid = pvolume_info->linux_uid;
3273 cifs_sb->mnt_gid = pvolume_info->linux_gid; 3233 cifs_sb->mnt_gid = pvolume_info->linux_gid;
3274 if (pvolume_info->backupuid_specified)
3275 cifs_sb->mnt_backupuid = pvolume_info->backupuid;
3276 if (pvolume_info->backupgid_specified)
3277 cifs_sb->mnt_backupgid = pvolume_info->backupgid;
3278 cifs_sb->mnt_file_mode = pvolume_info->file_mode; 3234 cifs_sb->mnt_file_mode = pvolume_info->file_mode;
3279 cifs_sb->mnt_dir_mode = pvolume_info->dir_mode; 3235 cifs_sb->mnt_dir_mode = pvolume_info->dir_mode;
3280 cFYI(1, "file mode: 0x%hx dir mode: 0x%hx", 3236 cFYI(1, "file mode: 0x%hx dir mode: 0x%hx",
@@ -3305,10 +3261,14 @@ void cifs_setup_cifs_sb(struct smb_vol *pvolume_info,
3305 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_RWPIDFORWARD; 3261 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_RWPIDFORWARD;
3306 if (pvolume_info->cifs_acl) 3262 if (pvolume_info->cifs_acl)
3307 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_CIFS_ACL; 3263 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_CIFS_ACL;
3308 if (pvolume_info->backupuid_specified) 3264 if (pvolume_info->backupuid_specified) {
3309 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_CIFS_BACKUPUID; 3265 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_CIFS_BACKUPUID;
3310 if (pvolume_info->backupgid_specified) 3266 cifs_sb->mnt_backupuid = pvolume_info->backupuid;
3267 }
3268 if (pvolume_info->backupgid_specified) {
3311 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_CIFS_BACKUPGID; 3269 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_CIFS_BACKUPGID;
3270 cifs_sb->mnt_backupgid = pvolume_info->backupgid;
3271 }
3312 if (pvolume_info->override_uid) 3272 if (pvolume_info->override_uid)
3313 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_OVERR_UID; 3273 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_OVERR_UID;
3314 if (pvolume_info->override_gid) 3274 if (pvolume_info->override_gid)
@@ -3657,22 +3617,6 @@ cifs_get_volume_info(char *mount_data, const char *devname)
3657 return volume_info; 3617 return volume_info;
3658} 3618}
3659 3619
3660/* make sure ra_pages is a multiple of rsize */
3661static inline unsigned int
3662cifs_ra_pages(struct cifs_sb_info *cifs_sb)
3663{
3664 unsigned int reads;
3665 unsigned int rsize_pages = cifs_sb->rsize / PAGE_CACHE_SIZE;
3666
3667 if (rsize_pages >= default_backing_dev_info.ra_pages)
3668 return default_backing_dev_info.ra_pages;
3669 else if (rsize_pages == 0)
3670 return rsize_pages;
3671
3672 reads = default_backing_dev_info.ra_pages / rsize_pages;
3673 return reads * rsize_pages;
3674}
3675
3676int 3620int
3677cifs_mount(struct cifs_sb_info *cifs_sb, struct smb_vol *volume_info) 3621cifs_mount(struct cifs_sb_info *cifs_sb, struct smb_vol *volume_info)
3678{ 3622{
@@ -3760,7 +3704,7 @@ try_mount_again:
3760 cifs_sb->rsize = cifs_negotiate_rsize(tcon, volume_info); 3704 cifs_sb->rsize = cifs_negotiate_rsize(tcon, volume_info);
3761 3705
3762 /* tune readahead according to rsize */ 3706 /* tune readahead according to rsize */
3763 cifs_sb->bdi.ra_pages = cifs_ra_pages(cifs_sb); 3707 cifs_sb->bdi.ra_pages = cifs_sb->rsize / PAGE_CACHE_SIZE;
3764 3708
3765remote_path_check: 3709remote_path_check:
3766#ifdef CONFIG_CIFS_DFS_UPCALL 3710#ifdef CONFIG_CIFS_DFS_UPCALL
diff --git a/fs/cifs/dir.c b/fs/cifs/dir.c
index d172c8ed9017..ec4e9a2a12f8 100644
--- a/fs/cifs/dir.c
+++ b/fs/cifs/dir.c
@@ -668,12 +668,19 @@ cifs_d_revalidate(struct dentry *direntry, struct nameidata *nd)
668 return 0; 668 return 0;
669 else { 669 else {
670 /* 670 /*
671 * Forcibly invalidate automounting directory inodes 671 * If the inode wasn't known to be a dfs entry when
672 * (remote DFS directories) so to have them 672 * the dentry was instantiated, such as when created
673 * instantiated again for automount 673 * via ->readdir(), it needs to be set now since the
674 * attributes will have been updated by
675 * cifs_revalidate_dentry().
674 */ 676 */
675 if (IS_AUTOMOUNT(direntry->d_inode)) 677 if (IS_AUTOMOUNT(direntry->d_inode) &&
676 return 0; 678 !(direntry->d_flags & DCACHE_NEED_AUTOMOUNT)) {
679 spin_lock(&direntry->d_lock);
680 direntry->d_flags |= DCACHE_NEED_AUTOMOUNT;
681 spin_unlock(&direntry->d_lock);
682 }
683
677 return 1; 684 return 1;
678 } 685 }
679 } 686 }
diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index 460d87b7cda0..81725e9286e9 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -835,13 +835,21 @@ cifs_posix_lock_set(struct file *file, struct file_lock *flock)
835 if ((flock->fl_flags & FL_POSIX) == 0) 835 if ((flock->fl_flags & FL_POSIX) == 0)
836 return rc; 836 return rc;
837 837
838try_again:
838 mutex_lock(&cinode->lock_mutex); 839 mutex_lock(&cinode->lock_mutex);
839 if (!cinode->can_cache_brlcks) { 840 if (!cinode->can_cache_brlcks) {
840 mutex_unlock(&cinode->lock_mutex); 841 mutex_unlock(&cinode->lock_mutex);
841 return rc; 842 return rc;
842 } 843 }
843 rc = posix_lock_file_wait(file, flock); 844
845 rc = posix_lock_file(file, flock, NULL);
844 mutex_unlock(&cinode->lock_mutex); 846 mutex_unlock(&cinode->lock_mutex);
847 if (rc == FILE_LOCK_DEFERRED) {
848 rc = wait_event_interruptible(flock->fl_wait, !flock->fl_next);
849 if (!rc)
850 goto try_again;
851 locks_delete_block(flock);
852 }
845 return rc; 853 return rc;
846} 854}
847 855
@@ -2170,7 +2178,7 @@ cifs_iovec_write(struct file *file, const struct iovec *iov,
2170 unsigned long nr_pages, i; 2178 unsigned long nr_pages, i;
2171 size_t copied, len, cur_len; 2179 size_t copied, len, cur_len;
2172 ssize_t total_written = 0; 2180 ssize_t total_written = 0;
2173 loff_t offset = *poffset; 2181 loff_t offset;
2174 struct iov_iter it; 2182 struct iov_iter it;
2175 struct cifsFileInfo *open_file; 2183 struct cifsFileInfo *open_file;
2176 struct cifs_tcon *tcon; 2184 struct cifs_tcon *tcon;
@@ -2192,6 +2200,7 @@ cifs_iovec_write(struct file *file, const struct iovec *iov,
2192 cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); 2200 cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
2193 open_file = file->private_data; 2201 open_file = file->private_data;
2194 tcon = tlink_tcon(open_file->tlink); 2202 tcon = tlink_tcon(open_file->tlink);
2203 offset = *poffset;
2195 2204
2196 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD) 2205 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD)
2197 pid = open_file->pid; 2206 pid = open_file->pid;
diff --git a/fs/cifs/netmisc.c b/fs/cifs/netmisc.c
index dd23a321bdda..581c225f7f50 100644
--- a/fs/cifs/netmisc.c
+++ b/fs/cifs/netmisc.c
@@ -197,8 +197,7 @@ cifs_convert_address(struct sockaddr *dst, const char *src, int len)
197 memcpy(scope_id, pct + 1, slen); 197 memcpy(scope_id, pct + 1, slen);
198 scope_id[slen] = '\0'; 198 scope_id[slen] = '\0';
199 199
200 rc = strict_strtoul(scope_id, 0, 200 rc = kstrtouint(scope_id, 0, &s6->sin6_scope_id);
201 (unsigned long *)&s6->sin6_scope_id);
202 rc = (rc == 0) ? 1 : 0; 201 rc = (rc == 0) ? 1 : 0;
203 } 202 }
204 203
diff --git a/fs/dcache.c b/fs/dcache.c
index b60ddc41d783..b80531c91779 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -141,18 +141,29 @@ int proc_nr_dentry(ctl_table *table, int write, void __user *buffer,
141 * Compare 2 name strings, return 0 if they match, otherwise non-zero. 141 * Compare 2 name strings, return 0 if they match, otherwise non-zero.
142 * The strings are both count bytes long, and count is non-zero. 142 * The strings are both count bytes long, and count is non-zero.
143 */ 143 */
144#ifdef CONFIG_DCACHE_WORD_ACCESS
145
146#include <asm/word-at-a-time.h>
147/*
148 * NOTE! 'cs' and 'scount' come from a dentry, so it has a
149 * aligned allocation for this particular component. We don't
150 * strictly need the load_unaligned_zeropad() safety, but it
151 * doesn't hurt either.
152 *
153 * In contrast, 'ct' and 'tcount' can be from a pathname, and do
154 * need the careful unaligned handling.
155 */
144static inline int dentry_cmp(const unsigned char *cs, size_t scount, 156static inline int dentry_cmp(const unsigned char *cs, size_t scount,
145 const unsigned char *ct, size_t tcount) 157 const unsigned char *ct, size_t tcount)
146{ 158{
147#ifdef CONFIG_DCACHE_WORD_ACCESS
148 unsigned long a,b,mask; 159 unsigned long a,b,mask;
149 160
150 if (unlikely(scount != tcount)) 161 if (unlikely(scount != tcount))
151 return 1; 162 return 1;
152 163
153 for (;;) { 164 for (;;) {
154 a = *(unsigned long *)cs; 165 a = load_unaligned_zeropad(cs);
155 b = *(unsigned long *)ct; 166 b = load_unaligned_zeropad(ct);
156 if (tcount < sizeof(unsigned long)) 167 if (tcount < sizeof(unsigned long))
157 break; 168 break;
158 if (unlikely(a != b)) 169 if (unlikely(a != b))
@@ -165,7 +176,13 @@ static inline int dentry_cmp(const unsigned char *cs, size_t scount,
165 } 176 }
166 mask = ~(~0ul << tcount*8); 177 mask = ~(~0ul << tcount*8);
167 return unlikely(!!((a ^ b) & mask)); 178 return unlikely(!!((a ^ b) & mask));
179}
180
168#else 181#else
182
183static inline int dentry_cmp(const unsigned char *cs, size_t scount,
184 const unsigned char *ct, size_t tcount)
185{
169 if (scount != tcount) 186 if (scount != tcount)
170 return 1; 187 return 1;
171 188
@@ -177,9 +194,10 @@ static inline int dentry_cmp(const unsigned char *cs, size_t scount,
177 tcount--; 194 tcount--;
178 } while (tcount); 195 } while (tcount);
179 return 0; 196 return 0;
180#endif
181} 197}
182 198
199#endif
200
183static void __d_free(struct rcu_head *head) 201static void __d_free(struct rcu_head *head)
184{ 202{
185 struct dentry *dentry = container_of(head, struct dentry, d_u.d_rcu); 203 struct dentry *dentry = container_of(head, struct dentry, d_u.d_rcu);
diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c
index 21e93605161c..5dfafdd1dbd3 100644
--- a/fs/debugfs/file.c
+++ b/fs/debugfs/file.c
@@ -33,18 +33,10 @@ static ssize_t default_write_file(struct file *file, const char __user *buf,
33 return count; 33 return count;
34} 34}
35 35
36static int default_open(struct inode *inode, struct file *file)
37{
38 if (inode->i_private)
39 file->private_data = inode->i_private;
40
41 return 0;
42}
43
44const struct file_operations debugfs_file_operations = { 36const struct file_operations debugfs_file_operations = {
45 .read = default_read_file, 37 .read = default_read_file,
46 .write = default_write_file, 38 .write = default_write_file,
47 .open = default_open, 39 .open = simple_open,
48 .llseek = noop_llseek, 40 .llseek = noop_llseek,
49}; 41};
50 42
@@ -447,7 +439,7 @@ static ssize_t write_file_bool(struct file *file, const char __user *user_buf,
447static const struct file_operations fops_bool = { 439static const struct file_operations fops_bool = {
448 .read = read_file_bool, 440 .read = read_file_bool,
449 .write = write_file_bool, 441 .write = write_file_bool,
450 .open = default_open, 442 .open = simple_open,
451 .llseek = default_llseek, 443 .llseek = default_llseek,
452}; 444};
453 445
@@ -492,7 +484,7 @@ static ssize_t read_file_blob(struct file *file, char __user *user_buf,
492 484
493static const struct file_operations fops_blob = { 485static const struct file_operations fops_blob = {
494 .read = read_file_blob, 486 .read = read_file_blob,
495 .open = default_open, 487 .open = simple_open,
496 .llseek = default_llseek, 488 .llseek = default_llseek,
497}; 489};
498 490
diff --git a/fs/dlm/debug_fs.c b/fs/dlm/debug_fs.c
index 3dca2b39e83f..1c9b08095f98 100644
--- a/fs/dlm/debug_fs.c
+++ b/fs/dlm/debug_fs.c
@@ -609,13 +609,6 @@ static const struct file_operations format3_fops = {
609/* 609/*
610 * dump lkb's on the ls_waiters list 610 * dump lkb's on the ls_waiters list
611 */ 611 */
612
613static int waiters_open(struct inode *inode, struct file *file)
614{
615 file->private_data = inode->i_private;
616 return 0;
617}
618
619static ssize_t waiters_read(struct file *file, char __user *userbuf, 612static ssize_t waiters_read(struct file *file, char __user *userbuf,
620 size_t count, loff_t *ppos) 613 size_t count, loff_t *ppos)
621{ 614{
@@ -644,7 +637,7 @@ static ssize_t waiters_read(struct file *file, char __user *userbuf,
644 637
645static const struct file_operations waiters_fops = { 638static const struct file_operations waiters_fops = {
646 .owner = THIS_MODULE, 639 .owner = THIS_MODULE,
647 .open = waiters_open, 640 .open = simple_open,
648 .read = waiters_read, 641 .read = waiters_read,
649 .llseek = default_llseek, 642 .llseek = default_llseek,
650}; 643};
diff --git a/fs/dlm/lock.c b/fs/dlm/lock.c
index fa5c07d51dcc..4c58d4a3adc4 100644
--- a/fs/dlm/lock.c
+++ b/fs/dlm/lock.c
@@ -1737,6 +1737,18 @@ static int _can_be_granted(struct dlm_rsb *r, struct dlm_lkb *lkb, int now)
1737 return 1; 1737 return 1;
1738 1738
1739 /* 1739 /*
1740 * Even if the convert is compat with all granted locks,
1741 * QUECVT forces it behind other locks on the convert queue.
1742 */
1743
1744 if (now && conv && (lkb->lkb_exflags & DLM_LKF_QUECVT)) {
1745 if (list_empty(&r->res_convertqueue))
1746 return 1;
1747 else
1748 goto out;
1749 }
1750
1751 /*
1740 * The NOORDER flag is set to avoid the standard vms rules on grant 1752 * The NOORDER flag is set to avoid the standard vms rules on grant
1741 * order. 1753 * order.
1742 */ 1754 */
diff --git a/fs/eventpoll.c b/fs/eventpoll.c
index 739b0985b398..c0b3c70ee87a 100644
--- a/fs/eventpoll.c
+++ b/fs/eventpoll.c
@@ -1663,8 +1663,10 @@ SYSCALL_DEFINE4(epoll_ctl, int, epfd, int, op, int, fd,
1663 if (op == EPOLL_CTL_ADD) { 1663 if (op == EPOLL_CTL_ADD) {
1664 if (is_file_epoll(tfile)) { 1664 if (is_file_epoll(tfile)) {
1665 error = -ELOOP; 1665 error = -ELOOP;
1666 if (ep_loop_check(ep, tfile) != 0) 1666 if (ep_loop_check(ep, tfile) != 0) {
1667 clear_tfile_check_list();
1667 goto error_tgt_fput; 1668 goto error_tgt_fput;
1669 }
1668 } else 1670 } else
1669 list_add(&tfile->f_tfile_llink, &tfile_check_list); 1671 list_add(&tfile->f_tfile_llink, &tfile_check_list);
1670 } 1672 }
diff --git a/fs/exec.c b/fs/exec.c
index 9a1d9f0a60ab..b1fd2025e59a 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1371,7 +1371,7 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
1371 unsigned int depth = bprm->recursion_depth; 1371 unsigned int depth = bprm->recursion_depth;
1372 int try,retval; 1372 int try,retval;
1373 struct linux_binfmt *fmt; 1373 struct linux_binfmt *fmt;
1374 pid_t old_pid; 1374 pid_t old_pid, old_vpid;
1375 1375
1376 retval = security_bprm_check(bprm); 1376 retval = security_bprm_check(bprm);
1377 if (retval) 1377 if (retval)
@@ -1382,8 +1382,9 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
1382 return retval; 1382 return retval;
1383 1383
1384 /* Need to fetch pid before load_binary changes it */ 1384 /* Need to fetch pid before load_binary changes it */
1385 old_pid = current->pid;
1385 rcu_read_lock(); 1386 rcu_read_lock();
1386 old_pid = task_pid_nr_ns(current, task_active_pid_ns(current->parent)); 1387 old_vpid = task_pid_nr_ns(current, task_active_pid_ns(current->parent));
1387 rcu_read_unlock(); 1388 rcu_read_unlock();
1388 1389
1389 retval = -ENOENT; 1390 retval = -ENOENT;
@@ -1406,7 +1407,7 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
1406 if (retval >= 0) { 1407 if (retval >= 0) {
1407 if (depth == 0) { 1408 if (depth == 0) {
1408 trace_sched_process_exec(current, old_pid, bprm); 1409 trace_sched_process_exec(current, old_pid, bprm);
1409 ptrace_event(PTRACE_EVENT_EXEC, old_pid); 1410 ptrace_event(PTRACE_EVENT_EXEC, old_vpid);
1410 } 1411 }
1411 put_binfmt(fmt); 1412 put_binfmt(fmt);
1412 allow_write_access(bprm->file); 1413 allow_write_access(bprm->file);
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index ab2594a30f86..0e01e90add8b 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -1203,9 +1203,6 @@ struct ext4_sb_info {
1203 unsigned long s_ext_blocks; 1203 unsigned long s_ext_blocks;
1204 unsigned long s_ext_extents; 1204 unsigned long s_ext_extents;
1205#endif 1205#endif
1206 /* ext4 extent cache stats */
1207 unsigned long extent_cache_hits;
1208 unsigned long extent_cache_misses;
1209 1206
1210 /* for buddy allocator */ 1207 /* for buddy allocator */
1211 struct ext4_group_info ***s_group_info; 1208 struct ext4_group_info ***s_group_info;
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index 1421938e6792..abcdeab67f52 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -2066,10 +2066,6 @@ static int ext4_ext_check_cache(struct inode *inode, ext4_lblk_t block,
2066 ret = 1; 2066 ret = 1;
2067 } 2067 }
2068errout: 2068errout:
2069 if (!ret)
2070 sbi->extent_cache_misses++;
2071 else
2072 sbi->extent_cache_hits++;
2073 trace_ext4_ext_in_cache(inode, block, ret); 2069 trace_ext4_ext_in_cache(inode, block, ret);
2074 spin_unlock(&EXT4_I(inode)->i_block_reservation_lock); 2070 spin_unlock(&EXT4_I(inode)->i_block_reservation_lock);
2075 return ret; 2071 return ret;
@@ -2882,7 +2878,7 @@ static int ext4_split_extent_at(handle_t *handle,
2882 if (err) 2878 if (err)
2883 goto fix_extent_len; 2879 goto fix_extent_len;
2884 /* update the extent length and mark as initialized */ 2880 /* update the extent length and mark as initialized */
2885 ex->ee_len = cpu_to_le32(ee_len); 2881 ex->ee_len = cpu_to_le16(ee_len);
2886 ext4_ext_try_to_merge(inode, path, ex); 2882 ext4_ext_try_to_merge(inode, path, ex);
2887 err = ext4_ext_dirty(handle, inode, path + depth); 2883 err = ext4_ext_dirty(handle, inode, path + depth);
2888 goto out; 2884 goto out;
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index ceebaf853beb..e1fb1d5de58e 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -1305,20 +1305,20 @@ static int set_qf_name(struct super_block *sb, int qtype, substring_t *args)
1305 ext4_msg(sb, KERN_ERR, 1305 ext4_msg(sb, KERN_ERR,
1306 "Cannot change journaled " 1306 "Cannot change journaled "
1307 "quota options when quota turned on"); 1307 "quota options when quota turned on");
1308 return 0; 1308 return -1;
1309 } 1309 }
1310 qname = match_strdup(args); 1310 qname = match_strdup(args);
1311 if (!qname) { 1311 if (!qname) {
1312 ext4_msg(sb, KERN_ERR, 1312 ext4_msg(sb, KERN_ERR,
1313 "Not enough memory for storing quotafile name"); 1313 "Not enough memory for storing quotafile name");
1314 return 0; 1314 return -1;
1315 } 1315 }
1316 if (sbi->s_qf_names[qtype] && 1316 if (sbi->s_qf_names[qtype] &&
1317 strcmp(sbi->s_qf_names[qtype], qname)) { 1317 strcmp(sbi->s_qf_names[qtype], qname)) {
1318 ext4_msg(sb, KERN_ERR, 1318 ext4_msg(sb, KERN_ERR,
1319 "%s quota file already specified", QTYPE2NAME(qtype)); 1319 "%s quota file already specified", QTYPE2NAME(qtype));
1320 kfree(qname); 1320 kfree(qname);
1321 return 0; 1321 return -1;
1322 } 1322 }
1323 sbi->s_qf_names[qtype] = qname; 1323 sbi->s_qf_names[qtype] = qname;
1324 if (strchr(sbi->s_qf_names[qtype], '/')) { 1324 if (strchr(sbi->s_qf_names[qtype], '/')) {
@@ -1326,7 +1326,7 @@ static int set_qf_name(struct super_block *sb, int qtype, substring_t *args)
1326 "quotafile must be on filesystem root"); 1326 "quotafile must be on filesystem root");
1327 kfree(sbi->s_qf_names[qtype]); 1327 kfree(sbi->s_qf_names[qtype]);
1328 sbi->s_qf_names[qtype] = NULL; 1328 sbi->s_qf_names[qtype] = NULL;
1329 return 0; 1329 return -1;
1330 } 1330 }
1331 set_opt(sb, QUOTA); 1331 set_opt(sb, QUOTA);
1332 return 1; 1332 return 1;
@@ -1341,7 +1341,7 @@ static int clear_qf_name(struct super_block *sb, int qtype)
1341 sbi->s_qf_names[qtype]) { 1341 sbi->s_qf_names[qtype]) {
1342 ext4_msg(sb, KERN_ERR, "Cannot change journaled quota options" 1342 ext4_msg(sb, KERN_ERR, "Cannot change journaled quota options"
1343 " when quota turned on"); 1343 " when quota turned on");
1344 return 0; 1344 return -1;
1345 } 1345 }
1346 /* 1346 /*
1347 * The space will be released later when all options are confirmed 1347 * The space will be released later when all options are confirmed
@@ -1450,6 +1450,16 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token,
1450 const struct mount_opts *m; 1450 const struct mount_opts *m;
1451 int arg = 0; 1451 int arg = 0;
1452 1452
1453#ifdef CONFIG_QUOTA
1454 if (token == Opt_usrjquota)
1455 return set_qf_name(sb, USRQUOTA, &args[0]);
1456 else if (token == Opt_grpjquota)
1457 return set_qf_name(sb, GRPQUOTA, &args[0]);
1458 else if (token == Opt_offusrjquota)
1459 return clear_qf_name(sb, USRQUOTA);
1460 else if (token == Opt_offgrpjquota)
1461 return clear_qf_name(sb, GRPQUOTA);
1462#endif
1453 if (args->from && match_int(args, &arg)) 1463 if (args->from && match_int(args, &arg))
1454 return -1; 1464 return -1;
1455 switch (token) { 1465 switch (token) {
@@ -1549,18 +1559,6 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token,
1549 sbi->s_mount_opt |= m->mount_opt; 1559 sbi->s_mount_opt |= m->mount_opt;
1550 } 1560 }
1551#ifdef CONFIG_QUOTA 1561#ifdef CONFIG_QUOTA
1552 } else if (token == Opt_usrjquota) {
1553 if (!set_qf_name(sb, USRQUOTA, &args[0]))
1554 return -1;
1555 } else if (token == Opt_grpjquota) {
1556 if (!set_qf_name(sb, GRPQUOTA, &args[0]))
1557 return -1;
1558 } else if (token == Opt_offusrjquota) {
1559 if (!clear_qf_name(sb, USRQUOTA))
1560 return -1;
1561 } else if (token == Opt_offgrpjquota) {
1562 if (!clear_qf_name(sb, GRPQUOTA))
1563 return -1;
1564 } else if (m->flags & MOPT_QFMT) { 1562 } else if (m->flags & MOPT_QFMT) {
1565 if (sb_any_quota_loaded(sb) && 1563 if (sb_any_quota_loaded(sb) &&
1566 sbi->s_jquota_fmt != m->mount_opt) { 1564 sbi->s_jquota_fmt != m->mount_opt) {
@@ -1599,7 +1597,9 @@ static int parse_options(char *options, struct super_block *sb,
1599 unsigned int *journal_ioprio, 1597 unsigned int *journal_ioprio,
1600 int is_remount) 1598 int is_remount)
1601{ 1599{
1600#ifdef CONFIG_QUOTA
1602 struct ext4_sb_info *sbi = EXT4_SB(sb); 1601 struct ext4_sb_info *sbi = EXT4_SB(sb);
1602#endif
1603 char *p; 1603 char *p;
1604 substring_t args[MAX_OPT_ARGS]; 1604 substring_t args[MAX_OPT_ARGS];
1605 int token; 1605 int token;
@@ -2366,18 +2366,6 @@ static ssize_t lifetime_write_kbytes_show(struct ext4_attr *a,
2366 EXT4_SB(sb)->s_sectors_written_start) >> 1))); 2366 EXT4_SB(sb)->s_sectors_written_start) >> 1)));
2367} 2367}
2368 2368
2369static ssize_t extent_cache_hits_show(struct ext4_attr *a,
2370 struct ext4_sb_info *sbi, char *buf)
2371{
2372 return snprintf(buf, PAGE_SIZE, "%lu\n", sbi->extent_cache_hits);
2373}
2374
2375static ssize_t extent_cache_misses_show(struct ext4_attr *a,
2376 struct ext4_sb_info *sbi, char *buf)
2377{
2378 return snprintf(buf, PAGE_SIZE, "%lu\n", sbi->extent_cache_misses);
2379}
2380
2381static ssize_t inode_readahead_blks_store(struct ext4_attr *a, 2369static ssize_t inode_readahead_blks_store(struct ext4_attr *a,
2382 struct ext4_sb_info *sbi, 2370 struct ext4_sb_info *sbi,
2383 const char *buf, size_t count) 2371 const char *buf, size_t count)
@@ -2435,8 +2423,6 @@ static struct ext4_attr ext4_attr_##name = __ATTR(name, mode, show, store)
2435EXT4_RO_ATTR(delayed_allocation_blocks); 2423EXT4_RO_ATTR(delayed_allocation_blocks);
2436EXT4_RO_ATTR(session_write_kbytes); 2424EXT4_RO_ATTR(session_write_kbytes);
2437EXT4_RO_ATTR(lifetime_write_kbytes); 2425EXT4_RO_ATTR(lifetime_write_kbytes);
2438EXT4_RO_ATTR(extent_cache_hits);
2439EXT4_RO_ATTR(extent_cache_misses);
2440EXT4_ATTR_OFFSET(inode_readahead_blks, 0644, sbi_ui_show, 2426EXT4_ATTR_OFFSET(inode_readahead_blks, 0644, sbi_ui_show,
2441 inode_readahead_blks_store, s_inode_readahead_blks); 2427 inode_readahead_blks_store, s_inode_readahead_blks);
2442EXT4_RW_ATTR_SBI_UI(inode_goal, s_inode_goal); 2428EXT4_RW_ATTR_SBI_UI(inode_goal, s_inode_goal);
@@ -2452,8 +2438,6 @@ static struct attribute *ext4_attrs[] = {
2452 ATTR_LIST(delayed_allocation_blocks), 2438 ATTR_LIST(delayed_allocation_blocks),
2453 ATTR_LIST(session_write_kbytes), 2439 ATTR_LIST(session_write_kbytes),
2454 ATTR_LIST(lifetime_write_kbytes), 2440 ATTR_LIST(lifetime_write_kbytes),
2455 ATTR_LIST(extent_cache_hits),
2456 ATTR_LIST(extent_cache_misses),
2457 ATTR_LIST(inode_readahead_blks), 2441 ATTR_LIST(inode_readahead_blks),
2458 ATTR_LIST(inode_goal), 2442 ATTR_LIST(inode_goal),
2459 ATTR_LIST(mb_stats), 2443 ATTR_LIST(mb_stats),
diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index 206632887bb4..df5ac048dc74 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -387,9 +387,6 @@ static int fuse_create_open(struct inode *dir, struct dentry *entry,
387 if (fc->no_create) 387 if (fc->no_create)
388 return -ENOSYS; 388 return -ENOSYS;
389 389
390 if (flags & O_DIRECT)
391 return -EINVAL;
392
393 forget = fuse_alloc_forget(); 390 forget = fuse_alloc_forget();
394 if (!forget) 391 if (!forget)
395 return -ENOMEM; 392 return -ENOMEM;
@@ -644,13 +641,12 @@ static int fuse_unlink(struct inode *dir, struct dentry *entry)
644 fuse_put_request(fc, req); 641 fuse_put_request(fc, req);
645 if (!err) { 642 if (!err) {
646 struct inode *inode = entry->d_inode; 643 struct inode *inode = entry->d_inode;
644 struct fuse_inode *fi = get_fuse_inode(inode);
647 645
648 /* 646 spin_lock(&fc->lock);
649 * Set nlink to zero so the inode can be cleared, if the inode 647 fi->attr_version = ++fc->attr_version;
650 * does have more links this will be discovered at the next 648 drop_nlink(inode);
651 * lookup/getattr. 649 spin_unlock(&fc->lock);
652 */
653 clear_nlink(inode);
654 fuse_invalidate_attr(inode); 650 fuse_invalidate_attr(inode);
655 fuse_invalidate_attr(dir); 651 fuse_invalidate_attr(dir);
656 fuse_invalidate_entry_cache(entry); 652 fuse_invalidate_entry_cache(entry);
@@ -762,8 +758,17 @@ static int fuse_link(struct dentry *entry, struct inode *newdir,
762 will reflect changes in the backing inode (link count, 758 will reflect changes in the backing inode (link count,
763 etc.) 759 etc.)
764 */ 760 */
765 if (!err || err == -EINTR) 761 if (!err) {
762 struct fuse_inode *fi = get_fuse_inode(inode);
763
764 spin_lock(&fc->lock);
765 fi->attr_version = ++fc->attr_version;
766 inc_nlink(inode);
767 spin_unlock(&fc->lock);
768 fuse_invalidate_attr(inode);
769 } else if (err == -EINTR) {
766 fuse_invalidate_attr(inode); 770 fuse_invalidate_attr(inode);
771 }
767 return err; 772 return err;
768} 773}
769 774
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index a841868bf9ce..504e61b7fd75 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -194,10 +194,6 @@ int fuse_open_common(struct inode *inode, struct file *file, bool isdir)
194 struct fuse_conn *fc = get_fuse_conn(inode); 194 struct fuse_conn *fc = get_fuse_conn(inode);
195 int err; 195 int err;
196 196
197 /* VFS checks this, but only _after_ ->open() */
198 if (file->f_flags & O_DIRECT)
199 return -EINVAL;
200
201 err = generic_file_open(inode, file); 197 err = generic_file_open(inode, file);
202 if (err) 198 if (err)
203 return err; 199 return err;
@@ -932,17 +928,23 @@ static ssize_t fuse_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
932 struct file *file = iocb->ki_filp; 928 struct file *file = iocb->ki_filp;
933 struct address_space *mapping = file->f_mapping; 929 struct address_space *mapping = file->f_mapping;
934 size_t count = 0; 930 size_t count = 0;
931 size_t ocount = 0;
935 ssize_t written = 0; 932 ssize_t written = 0;
933 ssize_t written_buffered = 0;
936 struct inode *inode = mapping->host; 934 struct inode *inode = mapping->host;
937 ssize_t err; 935 ssize_t err;
938 struct iov_iter i; 936 struct iov_iter i;
937 loff_t endbyte = 0;
939 938
940 WARN_ON(iocb->ki_pos != pos); 939 WARN_ON(iocb->ki_pos != pos);
941 940
942 err = generic_segment_checks(iov, &nr_segs, &count, VERIFY_READ); 941 ocount = 0;
942 err = generic_segment_checks(iov, &nr_segs, &ocount, VERIFY_READ);
943 if (err) 943 if (err)
944 return err; 944 return err;
945 945
946 count = ocount;
947
946 mutex_lock(&inode->i_mutex); 948 mutex_lock(&inode->i_mutex);
947 vfs_check_frozen(inode->i_sb, SB_FREEZE_WRITE); 949 vfs_check_frozen(inode->i_sb, SB_FREEZE_WRITE);
948 950
@@ -962,11 +964,41 @@ static ssize_t fuse_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
962 964
963 file_update_time(file); 965 file_update_time(file);
964 966
965 iov_iter_init(&i, iov, nr_segs, count, 0); 967 if (file->f_flags & O_DIRECT) {
966 written = fuse_perform_write(file, mapping, &i, pos); 968 written = generic_file_direct_write(iocb, iov, &nr_segs,
967 if (written >= 0) 969 pos, &iocb->ki_pos,
968 iocb->ki_pos = pos + written; 970 count, ocount);
971 if (written < 0 || written == count)
972 goto out;
973
974 pos += written;
975 count -= written;
969 976
977 iov_iter_init(&i, iov, nr_segs, count, written);
978 written_buffered = fuse_perform_write(file, mapping, &i, pos);
979 if (written_buffered < 0) {
980 err = written_buffered;
981 goto out;
982 }
983 endbyte = pos + written_buffered - 1;
984
985 err = filemap_write_and_wait_range(file->f_mapping, pos,
986 endbyte);
987 if (err)
988 goto out;
989
990 invalidate_mapping_pages(file->f_mapping,
991 pos >> PAGE_CACHE_SHIFT,
992 endbyte >> PAGE_CACHE_SHIFT);
993
994 written += written_buffered;
995 iocb->ki_pos = pos + written_buffered;
996 } else {
997 iov_iter_init(&i, iov, nr_segs, count, 0);
998 written = fuse_perform_write(file, mapping, &i, pos);
999 if (written >= 0)
1000 iocb->ki_pos = pos + written;
1001 }
970out: 1002out:
971 current->backing_dev_info = NULL; 1003 current->backing_dev_info = NULL;
972 mutex_unlock(&inode->i_mutex); 1004 mutex_unlock(&inode->i_mutex);
@@ -1101,30 +1133,41 @@ static ssize_t fuse_direct_read(struct file *file, char __user *buf,
1101 return res; 1133 return res;
1102} 1134}
1103 1135
1104static ssize_t fuse_direct_write(struct file *file, const char __user *buf, 1136static ssize_t __fuse_direct_write(struct file *file, const char __user *buf,
1105 size_t count, loff_t *ppos) 1137 size_t count, loff_t *ppos)
1106{ 1138{
1107 struct inode *inode = file->f_path.dentry->d_inode; 1139 struct inode *inode = file->f_path.dentry->d_inode;
1108 ssize_t res; 1140 ssize_t res;
1109 1141
1110 if (is_bad_inode(inode))
1111 return -EIO;
1112
1113 /* Don't allow parallel writes to the same file */
1114 mutex_lock(&inode->i_mutex);
1115 res = generic_write_checks(file, ppos, &count, 0); 1142 res = generic_write_checks(file, ppos, &count, 0);
1116 if (!res) { 1143 if (!res) {
1117 res = fuse_direct_io(file, buf, count, ppos, 1); 1144 res = fuse_direct_io(file, buf, count, ppos, 1);
1118 if (res > 0) 1145 if (res > 0)
1119 fuse_write_update_size(inode, *ppos); 1146 fuse_write_update_size(inode, *ppos);
1120 } 1147 }
1121 mutex_unlock(&inode->i_mutex);
1122 1148
1123 fuse_invalidate_attr(inode); 1149 fuse_invalidate_attr(inode);
1124 1150
1125 return res; 1151 return res;
1126} 1152}
1127 1153
1154static ssize_t fuse_direct_write(struct file *file, const char __user *buf,
1155 size_t count, loff_t *ppos)
1156{
1157 struct inode *inode = file->f_path.dentry->d_inode;
1158 ssize_t res;
1159
1160 if (is_bad_inode(inode))
1161 return -EIO;
1162
1163 /* Don't allow parallel writes to the same file */
1164 mutex_lock(&inode->i_mutex);
1165 res = __fuse_direct_write(file, buf, count, ppos);
1166 mutex_unlock(&inode->i_mutex);
1167
1168 return res;
1169}
1170
1128static void fuse_writepage_free(struct fuse_conn *fc, struct fuse_req *req) 1171static void fuse_writepage_free(struct fuse_conn *fc, struct fuse_req *req)
1129{ 1172{
1130 __free_page(req->pages[0]); 1173 __free_page(req->pages[0]);
@@ -2077,6 +2120,57 @@ int fuse_notify_poll_wakeup(struct fuse_conn *fc,
2077 return 0; 2120 return 0;
2078} 2121}
2079 2122
2123static ssize_t fuse_loop_dio(struct file *filp, const struct iovec *iov,
2124 unsigned long nr_segs, loff_t *ppos, int rw)
2125{
2126 const struct iovec *vector = iov;
2127 ssize_t ret = 0;
2128
2129 while (nr_segs > 0) {
2130 void __user *base;
2131 size_t len;
2132 ssize_t nr;
2133
2134 base = vector->iov_base;
2135 len = vector->iov_len;
2136 vector++;
2137 nr_segs--;
2138
2139 if (rw == WRITE)
2140 nr = __fuse_direct_write(filp, base, len, ppos);
2141 else
2142 nr = fuse_direct_read(filp, base, len, ppos);
2143
2144 if (nr < 0) {
2145 if (!ret)
2146 ret = nr;
2147 break;
2148 }
2149 ret += nr;
2150 if (nr != len)
2151 break;
2152 }
2153
2154 return ret;
2155}
2156
2157
2158static ssize_t
2159fuse_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov,
2160 loff_t offset, unsigned long nr_segs)
2161{
2162 ssize_t ret = 0;
2163 struct file *file = NULL;
2164 loff_t pos = 0;
2165
2166 file = iocb->ki_filp;
2167 pos = offset;
2168
2169 ret = fuse_loop_dio(file, iov, nr_segs, &pos, rw);
2170
2171 return ret;
2172}
2173
2080static const struct file_operations fuse_file_operations = { 2174static const struct file_operations fuse_file_operations = {
2081 .llseek = fuse_file_llseek, 2175 .llseek = fuse_file_llseek,
2082 .read = do_sync_read, 2176 .read = do_sync_read,
@@ -2120,6 +2214,7 @@ static const struct address_space_operations fuse_file_aops = {
2120 .readpages = fuse_readpages, 2214 .readpages = fuse_readpages,
2121 .set_page_dirty = __set_page_dirty_nobuffers, 2215 .set_page_dirty = __set_page_dirty_nobuffers,
2122 .bmap = fuse_bmap, 2216 .bmap = fuse_bmap,
2217 .direct_IO = fuse_direct_IO,
2123}; 2218};
2124 2219
2125void fuse_init_file_inode(struct inode *inode) 2220void fuse_init_file_inode(struct inode *inode)
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index 4aec5995867e..26783eb2b1fc 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -947,6 +947,7 @@ static int fuse_fill_super(struct super_block *sb, void *data, int silent)
947 sb->s_magic = FUSE_SUPER_MAGIC; 947 sb->s_magic = FUSE_SUPER_MAGIC;
948 sb->s_op = &fuse_super_operations; 948 sb->s_op = &fuse_super_operations;
949 sb->s_maxbytes = MAX_LFS_FILESIZE; 949 sb->s_maxbytes = MAX_LFS_FILESIZE;
950 sb->s_time_gran = 1;
950 sb->s_export_op = &fuse_export_operations; 951 sb->s_export_op = &fuse_export_operations;
951 952
952 file = fget(d.fd); 953 file = fget(d.fd);
diff --git a/fs/gfs2/Kconfig b/fs/gfs2/Kconfig
index c465ae066c62..eb08c9e43c2a 100644
--- a/fs/gfs2/Kconfig
+++ b/fs/gfs2/Kconfig
@@ -1,10 +1,6 @@
1config GFS2_FS 1config GFS2_FS
2 tristate "GFS2 file system support" 2 tristate "GFS2 file system support"
3 depends on (64BIT || LBDAF) 3 depends on (64BIT || LBDAF)
4 select DLM if GFS2_FS_LOCKING_DLM
5 select CONFIGFS_FS if GFS2_FS_LOCKING_DLM
6 select SYSFS if GFS2_FS_LOCKING_DLM
7 select IP_SCTP if DLM_SCTP
8 select FS_POSIX_ACL 4 select FS_POSIX_ACL
9 select CRC32 5 select CRC32
10 select QUOTACTL 6 select QUOTACTL
@@ -29,7 +25,8 @@ config GFS2_FS
29 25
30config GFS2_FS_LOCKING_DLM 26config GFS2_FS_LOCKING_DLM
31 bool "GFS2 DLM locking" 27 bool "GFS2 DLM locking"
32 depends on (GFS2_FS!=n) && NET && INET && (IPV6 || IPV6=n) && HOTPLUG 28 depends on (GFS2_FS!=n) && NET && INET && (IPV6 || IPV6=n) && \
29 HOTPLUG && DLM && CONFIGFS_FS && SYSFS
33 help 30 help
34 Multiple node locking module for GFS2 31 Multiple node locking module for GFS2
35 32
diff --git a/fs/gfs2/aops.c b/fs/gfs2/aops.c
index 38b7a74a0f91..9b2ff0e851b1 100644
--- a/fs/gfs2/aops.c
+++ b/fs/gfs2/aops.c
@@ -807,7 +807,7 @@ static int gfs2_stuffed_write_end(struct inode *inode, struct buffer_head *dibh,
807 807
808 if (inode == sdp->sd_rindex) { 808 if (inode == sdp->sd_rindex) {
809 adjust_fs_space(inode); 809 adjust_fs_space(inode);
810 ip->i_gh.gh_flags |= GL_NOCACHE; 810 sdp->sd_rindex_uptodate = 0;
811 } 811 }
812 812
813 brelse(dibh); 813 brelse(dibh);
@@ -873,7 +873,7 @@ static int gfs2_write_end(struct file *file, struct address_space *mapping,
873 873
874 if (inode == sdp->sd_rindex) { 874 if (inode == sdp->sd_rindex) {
875 adjust_fs_space(inode); 875 adjust_fs_space(inode);
876 ip->i_gh.gh_flags |= GL_NOCACHE; 876 sdp->sd_rindex_uptodate = 0;
877 } 877 }
878 878
879 brelse(dibh); 879 brelse(dibh);
diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c
index 197c5c47e577..03c04febe26f 100644
--- a/fs/gfs2/bmap.c
+++ b/fs/gfs2/bmap.c
@@ -724,7 +724,11 @@ static int do_strip(struct gfs2_inode *ip, struct buffer_head *dibh,
724 int metadata; 724 int metadata;
725 unsigned int revokes = 0; 725 unsigned int revokes = 0;
726 int x; 726 int x;
727 int error = 0; 727 int error;
728
729 error = gfs2_rindex_update(sdp);
730 if (error)
731 return error;
728 732
729 if (!*top) 733 if (!*top)
730 sm->sm_first = 0; 734 sm->sm_first = 0;
diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c
index c35573abd371..a836056343f0 100644
--- a/fs/gfs2/dir.c
+++ b/fs/gfs2/dir.c
@@ -1844,6 +1844,10 @@ static int leaf_dealloc(struct gfs2_inode *dip, u32 index, u32 len,
1844 unsigned int x, size = len * sizeof(u64); 1844 unsigned int x, size = len * sizeof(u64);
1845 int error; 1845 int error;
1846 1846
1847 error = gfs2_rindex_update(sdp);
1848 if (error)
1849 return error;
1850
1847 memset(&rlist, 0, sizeof(struct gfs2_rgrp_list)); 1851 memset(&rlist, 0, sizeof(struct gfs2_rgrp_list));
1848 1852
1849 ht = kzalloc(size, GFP_NOFS); 1853 ht = kzalloc(size, GFP_NOFS);
diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
index c98a60ee6dfd..a9ba2444e077 100644
--- a/fs/gfs2/inode.c
+++ b/fs/gfs2/inode.c
@@ -1031,7 +1031,13 @@ static int gfs2_unlink(struct inode *dir, struct dentry *dentry)
1031 struct buffer_head *bh; 1031 struct buffer_head *bh;
1032 struct gfs2_holder ghs[3]; 1032 struct gfs2_holder ghs[3];
1033 struct gfs2_rgrpd *rgd; 1033 struct gfs2_rgrpd *rgd;
1034 int error = -EROFS; 1034 int error;
1035
1036 error = gfs2_rindex_update(sdp);
1037 if (error)
1038 return error;
1039
1040 error = -EROFS;
1035 1041
1036 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs); 1042 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
1037 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1); 1043 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
@@ -1224,6 +1230,10 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
1224 return 0; 1230 return 0;
1225 } 1231 }
1226 1232
1233 error = gfs2_rindex_update(sdp);
1234 if (error)
1235 return error;
1236
1227 if (odip != ndip) { 1237 if (odip != ndip) {
1228 error = gfs2_glock_nq_init(sdp->sd_rename_gl, LM_ST_EXCLUSIVE, 1238 error = gfs2_glock_nq_init(sdp->sd_rename_gl, LM_ST_EXCLUSIVE,
1229 0, &r_gh); 1239 0, &r_gh);
@@ -1345,7 +1355,6 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
1345 error = alloc_required; 1355 error = alloc_required;
1346 if (error < 0) 1356 if (error < 0)
1347 goto out_gunlock; 1357 goto out_gunlock;
1348 error = 0;
1349 1358
1350 if (alloc_required) { 1359 if (alloc_required) {
1351 struct gfs2_qadata *qa = gfs2_qadata_get(ndip); 1360 struct gfs2_qadata *qa = gfs2_qadata_get(ndip);
diff --git a/fs/gfs2/lock_dlm.c b/fs/gfs2/lock_dlm.c
index f8411bd1b805..5f5e70e047dc 100644
--- a/fs/gfs2/lock_dlm.c
+++ b/fs/gfs2/lock_dlm.c
@@ -200,10 +200,11 @@ static int make_mode(const unsigned int lmstate)
200 return -1; 200 return -1;
201} 201}
202 202
203static u32 make_flags(const u32 lkid, const unsigned int gfs_flags, 203static u32 make_flags(struct gfs2_glock *gl, const unsigned int gfs_flags,
204 const int req) 204 const int req)
205{ 205{
206 u32 lkf = DLM_LKF_VALBLK; 206 u32 lkf = DLM_LKF_VALBLK;
207 u32 lkid = gl->gl_lksb.sb_lkid;
207 208
208 if (gfs_flags & LM_FLAG_TRY) 209 if (gfs_flags & LM_FLAG_TRY)
209 lkf |= DLM_LKF_NOQUEUE; 210 lkf |= DLM_LKF_NOQUEUE;
@@ -227,8 +228,11 @@ static u32 make_flags(const u32 lkid, const unsigned int gfs_flags,
227 BUG(); 228 BUG();
228 } 229 }
229 230
230 if (lkid != 0) 231 if (lkid != 0) {
231 lkf |= DLM_LKF_CONVERT; 232 lkf |= DLM_LKF_CONVERT;
233 if (test_bit(GLF_BLOCKING, &gl->gl_flags))
234 lkf |= DLM_LKF_QUECVT;
235 }
232 236
233 return lkf; 237 return lkf;
234} 238}
@@ -250,7 +254,7 @@ static int gdlm_lock(struct gfs2_glock *gl, unsigned int req_state,
250 char strname[GDLM_STRNAME_BYTES] = ""; 254 char strname[GDLM_STRNAME_BYTES] = "";
251 255
252 req = make_mode(req_state); 256 req = make_mode(req_state);
253 lkf = make_flags(gl->gl_lksb.sb_lkid, flags, req); 257 lkf = make_flags(gl, flags, req);
254 gfs2_glstats_inc(gl, GFS2_LKS_DCOUNT); 258 gfs2_glstats_inc(gl, GFS2_LKS_DCOUNT);
255 gfs2_sbstats_inc(gl, GFS2_LKS_DCOUNT); 259 gfs2_sbstats_inc(gl, GFS2_LKS_DCOUNT);
256 if (gl->gl_lksb.sb_lkid) { 260 if (gl->gl_lksb.sb_lkid) {
diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c
index 19bde40b4864..3df65c9ab73b 100644
--- a/fs/gfs2/rgrp.c
+++ b/fs/gfs2/rgrp.c
@@ -332,9 +332,6 @@ struct gfs2_rgrpd *gfs2_blk2rgrpd(struct gfs2_sbd *sdp, u64 blk, bool exact)
332 struct rb_node *n, *next; 332 struct rb_node *n, *next;
333 struct gfs2_rgrpd *cur; 333 struct gfs2_rgrpd *cur;
334 334
335 if (gfs2_rindex_update(sdp))
336 return NULL;
337
338 spin_lock(&sdp->sd_rindex_spin); 335 spin_lock(&sdp->sd_rindex_spin);
339 n = sdp->sd_rindex_tree.rb_node; 336 n = sdp->sd_rindex_tree.rb_node;
340 while (n) { 337 while (n) {
@@ -640,6 +637,7 @@ static int read_rindex_entry(struct gfs2_inode *ip,
640 return 0; 637 return 0;
641 638
642 error = 0; /* someone else read in the rgrp; free it and ignore it */ 639 error = 0; /* someone else read in the rgrp; free it and ignore it */
640 gfs2_glock_put(rgd->rd_gl);
643 641
644fail: 642fail:
645 kfree(rgd->rd_bits); 643 kfree(rgd->rd_bits);
@@ -927,6 +925,10 @@ int gfs2_fitrim(struct file *filp, void __user *argp)
927 } else if (copy_from_user(&r, argp, sizeof(r))) 925 } else if (copy_from_user(&r, argp, sizeof(r)))
928 return -EFAULT; 926 return -EFAULT;
929 927
928 ret = gfs2_rindex_update(sdp);
929 if (ret)
930 return ret;
931
930 rgd = gfs2_blk2rgrpd(sdp, r.start, 0); 932 rgd = gfs2_blk2rgrpd(sdp, r.start, 0);
931 rgd_end = gfs2_blk2rgrpd(sdp, r.start + r.len, 0); 933 rgd_end = gfs2_blk2rgrpd(sdp, r.start + r.len, 0);
932 934
diff --git a/fs/gfs2/xattr.c b/fs/gfs2/xattr.c
index 2e5ba425cae7..927f4df874ae 100644
--- a/fs/gfs2/xattr.c
+++ b/fs/gfs2/xattr.c
@@ -238,6 +238,10 @@ static int ea_dealloc_unstuffed(struct gfs2_inode *ip, struct buffer_head *bh,
238 unsigned int x; 238 unsigned int x;
239 int error; 239 int error;
240 240
241 error = gfs2_rindex_update(sdp);
242 if (error)
243 return error;
244
241 if (GFS2_EA_IS_STUFFED(ea)) 245 if (GFS2_EA_IS_STUFFED(ea))
242 return 0; 246 return 0;
243 247
@@ -1330,6 +1334,10 @@ static int ea_dealloc_indirect(struct gfs2_inode *ip)
1330 unsigned int x; 1334 unsigned int x;
1331 int error; 1335 int error;
1332 1336
1337 error = gfs2_rindex_update(sdp);
1338 if (error)
1339 return error;
1340
1333 memset(&rlist, 0, sizeof(struct gfs2_rgrp_list)); 1341 memset(&rlist, 0, sizeof(struct gfs2_rgrp_list));
1334 1342
1335 error = gfs2_meta_read(ip->i_gl, ip->i_eattr, DIO_WAIT, &indbh); 1343 error = gfs2_meta_read(ip->i_gl, ip->i_eattr, DIO_WAIT, &indbh);
@@ -1439,6 +1447,10 @@ static int ea_dealloc_block(struct gfs2_inode *ip)
1439 struct gfs2_holder gh; 1447 struct gfs2_holder gh;
1440 int error; 1448 int error;
1441 1449
1450 error = gfs2_rindex_update(sdp);
1451 if (error)
1452 return error;
1453
1442 rgd = gfs2_blk2rgrpd(sdp, ip->i_eattr, 1); 1454 rgd = gfs2_blk2rgrpd(sdp, ip->i_eattr, 1);
1443 if (!rgd) { 1455 if (!rgd) {
1444 gfs2_consist_inode(ip); 1456 gfs2_consist_inode(ip);
diff --git a/fs/hfsplus/catalog.c b/fs/hfsplus/catalog.c
index 4dfbfec357e8..ec2a9c23f0c9 100644
--- a/fs/hfsplus/catalog.c
+++ b/fs/hfsplus/catalog.c
@@ -366,6 +366,10 @@ int hfsplus_rename_cat(u32 cnid,
366 err = hfs_brec_find(&src_fd); 366 err = hfs_brec_find(&src_fd);
367 if (err) 367 if (err)
368 goto out; 368 goto out;
369 if (src_fd.entrylength > sizeof(entry) || src_fd.entrylength < 0) {
370 err = -EIO;
371 goto out;
372 }
369 373
370 hfs_bnode_read(src_fd.bnode, &entry, src_fd.entryoffset, 374 hfs_bnode_read(src_fd.bnode, &entry, src_fd.entryoffset,
371 src_fd.entrylength); 375 src_fd.entrylength);
diff --git a/fs/hfsplus/dir.c b/fs/hfsplus/dir.c
index 88e155f895c6..26b53fb09f68 100644
--- a/fs/hfsplus/dir.c
+++ b/fs/hfsplus/dir.c
@@ -150,6 +150,11 @@ static int hfsplus_readdir(struct file *filp, void *dirent, filldir_t filldir)
150 filp->f_pos++; 150 filp->f_pos++;
151 /* fall through */ 151 /* fall through */
152 case 1: 152 case 1:
153 if (fd.entrylength > sizeof(entry) || fd.entrylength < 0) {
154 err = -EIO;
155 goto out;
156 }
157
153 hfs_bnode_read(fd.bnode, &entry, fd.entryoffset, 158 hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
154 fd.entrylength); 159 fd.entrylength);
155 if (be16_to_cpu(entry.type) != HFSPLUS_FOLDER_THREAD) { 160 if (be16_to_cpu(entry.type) != HFSPLUS_FOLDER_THREAD) {
@@ -181,6 +186,12 @@ static int hfsplus_readdir(struct file *filp, void *dirent, filldir_t filldir)
181 err = -EIO; 186 err = -EIO;
182 goto out; 187 goto out;
183 } 188 }
189
190 if (fd.entrylength > sizeof(entry) || fd.entrylength < 0) {
191 err = -EIO;
192 goto out;
193 }
194
184 hfs_bnode_read(fd.bnode, &entry, fd.entryoffset, 195 hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
185 fd.entrylength); 196 fd.entrylength);
186 type = be16_to_cpu(entry.type); 197 type = be16_to_cpu(entry.type);
diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index ea251749d9d5..001ef01d2fe2 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -485,6 +485,7 @@ static struct inode *hugetlbfs_get_root(struct super_block *sb,
485 inode->i_fop = &simple_dir_operations; 485 inode->i_fop = &simple_dir_operations;
486 /* directory inodes start off with i_nlink == 2 (for "." entry) */ 486 /* directory inodes start off with i_nlink == 2 (for "." entry) */
487 inc_nlink(inode); 487 inc_nlink(inode);
488 lockdep_annotate_inode_mutex_key(inode);
488 } 489 }
489 return inode; 490 return inode;
490} 491}
@@ -1031,7 +1032,6 @@ static int __init init_hugetlbfs_fs(void)
1031 } 1032 }
1032 1033
1033 error = PTR_ERR(vfsmount); 1034 error = PTR_ERR(vfsmount);
1034 unregister_filesystem(&hugetlbfs_fs_type);
1035 1035
1036 out: 1036 out:
1037 kmem_cache_destroy(hugetlbfs_inode_cachep); 1037 kmem_cache_destroy(hugetlbfs_inode_cachep);
diff --git a/fs/jbd2/commit.c b/fs/jbd2/commit.c
index 806525a7269c..840f70f50792 100644
--- a/fs/jbd2/commit.c
+++ b/fs/jbd2/commit.c
@@ -723,7 +723,7 @@ start_journal_io:
723 if (commit_transaction->t_need_data_flush && 723 if (commit_transaction->t_need_data_flush &&
724 (journal->j_fs_dev != journal->j_dev) && 724 (journal->j_fs_dev != journal->j_dev) &&
725 (journal->j_flags & JBD2_BARRIER)) 725 (journal->j_flags & JBD2_BARRIER))
726 blkdev_issue_flush(journal->j_fs_dev, GFP_KERNEL, NULL); 726 blkdev_issue_flush(journal->j_fs_dev, GFP_NOFS, NULL);
727 727
728 /* Done it all: now write the commit record asynchronously. */ 728 /* Done it all: now write the commit record asynchronously. */
729 if (JBD2_HAS_INCOMPAT_FEATURE(journal, 729 if (JBD2_HAS_INCOMPAT_FEATURE(journal,
@@ -859,7 +859,7 @@ wait_for_iobuf:
859 if (JBD2_HAS_INCOMPAT_FEATURE(journal, 859 if (JBD2_HAS_INCOMPAT_FEATURE(journal,
860 JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT) && 860 JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT) &&
861 journal->j_flags & JBD2_BARRIER) { 861 journal->j_flags & JBD2_BARRIER) {
862 blkdev_issue_flush(journal->j_dev, GFP_KERNEL, NULL); 862 blkdev_issue_flush(journal->j_dev, GFP_NOFS, NULL);
863 } 863 }
864 864
865 if (err) 865 if (err)
diff --git a/fs/libfs.c b/fs/libfs.c
index 4a0d1f06da57..18d08f5db53a 100644
--- a/fs/libfs.c
+++ b/fs/libfs.c
@@ -264,6 +264,13 @@ Enomem:
264 return ERR_PTR(-ENOMEM); 264 return ERR_PTR(-ENOMEM);
265} 265}
266 266
267int simple_open(struct inode *inode, struct file *file)
268{
269 if (inode->i_private)
270 file->private_data = inode->i_private;
271 return 0;
272}
273
267int simple_link(struct dentry *old_dentry, struct inode *dir, struct dentry *dentry) 274int simple_link(struct dentry *old_dentry, struct inode *dir, struct dentry *dentry)
268{ 275{
269 struct inode *inode = old_dentry->d_inode; 276 struct inode *inode = old_dentry->d_inode;
@@ -522,6 +529,7 @@ int simple_fill_super(struct super_block *s, unsigned long magic,
522 return 0; 529 return 0;
523out: 530out:
524 d_genocide(root); 531 d_genocide(root);
532 shrink_dcache_parent(root);
525 dput(root); 533 dput(root);
526 return -ENOMEM; 534 return -ENOMEM;
527} 535}
@@ -984,6 +992,7 @@ EXPORT_SYMBOL(simple_dir_operations);
984EXPORT_SYMBOL(simple_empty); 992EXPORT_SYMBOL(simple_empty);
985EXPORT_SYMBOL(simple_fill_super); 993EXPORT_SYMBOL(simple_fill_super);
986EXPORT_SYMBOL(simple_getattr); 994EXPORT_SYMBOL(simple_getattr);
995EXPORT_SYMBOL(simple_open);
987EXPORT_SYMBOL(simple_link); 996EXPORT_SYMBOL(simple_link);
988EXPORT_SYMBOL(simple_lookup); 997EXPORT_SYMBOL(simple_lookup);
989EXPORT_SYMBOL(simple_pin_fs); 998EXPORT_SYMBOL(simple_pin_fs);
diff --git a/fs/lockd/clnt4xdr.c b/fs/lockd/clnt4xdr.c
index 3ddcbb1c0a43..13ad1539fbf2 100644
--- a/fs/lockd/clnt4xdr.c
+++ b/fs/lockd/clnt4xdr.c
@@ -241,7 +241,7 @@ static int decode_nlm4_stat(struct xdr_stream *xdr, __be32 *stat)
241 p = xdr_inline_decode(xdr, 4); 241 p = xdr_inline_decode(xdr, 4);
242 if (unlikely(p == NULL)) 242 if (unlikely(p == NULL))
243 goto out_overflow; 243 goto out_overflow;
244 if (unlikely(*p > nlm4_failed)) 244 if (unlikely(ntohl(*p) > ntohl(nlm4_failed)))
245 goto out_bad_xdr; 245 goto out_bad_xdr;
246 *stat = *p; 246 *stat = *p;
247 return 0; 247 return 0;
diff --git a/fs/lockd/clntxdr.c b/fs/lockd/clntxdr.c
index 3d35e3e80c1c..d269ada7670e 100644
--- a/fs/lockd/clntxdr.c
+++ b/fs/lockd/clntxdr.c
@@ -236,7 +236,7 @@ static int decode_nlm_stat(struct xdr_stream *xdr,
236 p = xdr_inline_decode(xdr, 4); 236 p = xdr_inline_decode(xdr, 4);
237 if (unlikely(p == NULL)) 237 if (unlikely(p == NULL))
238 goto out_overflow; 238 goto out_overflow;
239 if (unlikely(*p > nlm_lck_denied_grace_period)) 239 if (unlikely(ntohl(*p) > ntohl(nlm_lck_denied_grace_period)))
240 goto out_enum; 240 goto out_enum;
241 *stat = *p; 241 *stat = *p;
242 return 0; 242 return 0;
diff --git a/fs/locks.c b/fs/locks.c
index 637694bf3a03..0d68f1f81799 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -510,12 +510,13 @@ static void __locks_delete_block(struct file_lock *waiter)
510 510
511/* 511/*
512 */ 512 */
513static void locks_delete_block(struct file_lock *waiter) 513void locks_delete_block(struct file_lock *waiter)
514{ 514{
515 lock_flocks(); 515 lock_flocks();
516 __locks_delete_block(waiter); 516 __locks_delete_block(waiter);
517 unlock_flocks(); 517 unlock_flocks();
518} 518}
519EXPORT_SYMBOL(locks_delete_block);
519 520
520/* Insert waiter into blocker's block list. 521/* Insert waiter into blocker's block list.
521 * We use a circular list so that processes can be easily woken up in 522 * We use a circular list so that processes can be easily woken up in
diff --git a/fs/namei.c b/fs/namei.c
index 1898198abc3d..c42791914f82 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -1407,18 +1407,9 @@ static inline int can_lookup(struct inode *inode)
1407 */ 1407 */
1408#ifdef CONFIG_DCACHE_WORD_ACCESS 1408#ifdef CONFIG_DCACHE_WORD_ACCESS
1409 1409
1410#ifdef CONFIG_64BIT 1410#include <asm/word-at-a-time.h>
1411 1411
1412/* 1412#ifdef CONFIG_64BIT
1413 * Jan Achrenius on G+: microoptimized version of
1414 * the simpler "(mask & ONEBYTES) * ONEBYTES >> 56"
1415 * that works for the bytemasks without having to
1416 * mask them first.
1417 */
1418static inline long count_masked_bytes(unsigned long mask)
1419{
1420 return mask*0x0001020304050608ul >> 56;
1421}
1422 1413
1423static inline unsigned int fold_hash(unsigned long hash) 1414static inline unsigned int fold_hash(unsigned long hash)
1424{ 1415{
@@ -1428,15 +1419,6 @@ static inline unsigned int fold_hash(unsigned long hash)
1428 1419
1429#else /* 32-bit case */ 1420#else /* 32-bit case */
1430 1421
1431/* Carl Chatfield / Jan Achrenius G+ version for 32-bit */
1432static inline long count_masked_bytes(long mask)
1433{
1434 /* (000000 0000ff 00ffff ffffff) -> ( 1 1 2 3 ) */
1435 long a = (0x0ff0001+mask) >> 23;
1436 /* Fix the 1 for 00 case */
1437 return a & mask;
1438}
1439
1440#define fold_hash(x) (x) 1422#define fold_hash(x) (x)
1441 1423
1442#endif 1424#endif
@@ -1447,7 +1429,7 @@ unsigned int full_name_hash(const unsigned char *name, unsigned int len)
1447 unsigned long hash = 0; 1429 unsigned long hash = 0;
1448 1430
1449 for (;;) { 1431 for (;;) {
1450 a = *(unsigned long *)name; 1432 a = load_unaligned_zeropad(name);
1451 if (len < sizeof(unsigned long)) 1433 if (len < sizeof(unsigned long))
1452 break; 1434 break;
1453 hash += a; 1435 hash += a;
@@ -1464,17 +1446,6 @@ done:
1464} 1446}
1465EXPORT_SYMBOL(full_name_hash); 1447EXPORT_SYMBOL(full_name_hash);
1466 1448
1467#define REPEAT_BYTE(x) ((~0ul / 0xff) * (x))
1468#define ONEBYTES REPEAT_BYTE(0x01)
1469#define SLASHBYTES REPEAT_BYTE('/')
1470#define HIGHBITS REPEAT_BYTE(0x80)
1471
1472/* Return the high bit set in the first byte that is a zero */
1473static inline unsigned long has_zero(unsigned long a)
1474{
1475 return ((a - ONEBYTES) & ~a) & HIGHBITS;
1476}
1477
1478/* 1449/*
1479 * Calculate the length and hash of the path component, and 1450 * Calculate the length and hash of the path component, and
1480 * return the length of the component; 1451 * return the length of the component;
@@ -1488,9 +1459,9 @@ static inline unsigned long hash_name(const char *name, unsigned int *hashp)
1488 do { 1459 do {
1489 hash = (hash + a) * 9; 1460 hash = (hash + a) * 9;
1490 len += sizeof(unsigned long); 1461 len += sizeof(unsigned long);
1491 a = *(unsigned long *)(name+len); 1462 a = load_unaligned_zeropad(name+len);
1492 /* Do we have any NUL or '/' bytes in this word? */ 1463 /* Do we have any NUL or '/' bytes in this word? */
1493 mask = has_zero(a) | has_zero(a ^ SLASHBYTES); 1464 mask = has_zero(a) | has_zero(a ^ REPEAT_BYTE('/'));
1494 } while (!mask); 1465 } while (!mask);
1495 1466
1496 /* The mask *below* the first high bit set */ 1467 /* The mask *below* the first high bit set */
diff --git a/fs/nfs/blocklayout/blocklayout.c b/fs/nfs/blocklayout/blocklayout.c
index 9c94297bb70e..7f6a23f0244e 100644
--- a/fs/nfs/blocklayout/blocklayout.c
+++ b/fs/nfs/blocklayout/blocklayout.c
@@ -38,6 +38,8 @@
38#include <linux/buffer_head.h> /* various write calls */ 38#include <linux/buffer_head.h> /* various write calls */
39#include <linux/prefetch.h> 39#include <linux/prefetch.h>
40 40
41#include "../pnfs.h"
42#include "../internal.h"
41#include "blocklayout.h" 43#include "blocklayout.h"
42 44
43#define NFSDBG_FACILITY NFSDBG_PNFS_LD 45#define NFSDBG_FACILITY NFSDBG_PNFS_LD
@@ -868,7 +870,7 @@ nfs4_blk_get_deviceinfo(struct nfs_server *server, const struct nfs_fh *fh,
868 * GETDEVICEINFO's maxcount 870 * GETDEVICEINFO's maxcount
869 */ 871 */
870 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; 872 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz;
871 max_pages = max_resp_sz >> PAGE_SHIFT; 873 max_pages = nfs_page_array_len(0, max_resp_sz);
872 dprintk("%s max_resp_sz %u max_pages %d\n", 874 dprintk("%s max_resp_sz %u max_pages %d\n",
873 __func__, max_resp_sz, max_pages); 875 __func__, max_resp_sz, max_pages);
874 876
diff --git a/fs/nfs/client.c b/fs/nfs/client.c
index da7b5e4ff9ec..60f7e4ec842c 100644
--- a/fs/nfs/client.c
+++ b/fs/nfs/client.c
@@ -1729,7 +1729,8 @@ error:
1729 */ 1729 */
1730struct nfs_server *nfs_clone_server(struct nfs_server *source, 1730struct nfs_server *nfs_clone_server(struct nfs_server *source,
1731 struct nfs_fh *fh, 1731 struct nfs_fh *fh,
1732 struct nfs_fattr *fattr) 1732 struct nfs_fattr *fattr,
1733 rpc_authflavor_t flavor)
1733{ 1734{
1734 struct nfs_server *server; 1735 struct nfs_server *server;
1735 struct nfs_fattr *fattr_fsinfo; 1736 struct nfs_fattr *fattr_fsinfo;
@@ -1758,7 +1759,7 @@ struct nfs_server *nfs_clone_server(struct nfs_server *source,
1758 1759
1759 error = nfs_init_server_rpcclient(server, 1760 error = nfs_init_server_rpcclient(server,
1760 source->client->cl_timeout, 1761 source->client->cl_timeout,
1761 source->client->cl_auth->au_flavor); 1762 flavor);
1762 if (error < 0) 1763 if (error < 0)
1763 goto out_free_server; 1764 goto out_free_server;
1764 if (!IS_ERR(source->client_acl)) 1765 if (!IS_ERR(source->client_acl))
diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
index 4aaf0316d76a..8789210c6905 100644
--- a/fs/nfs/dir.c
+++ b/fs/nfs/dir.c
@@ -1429,7 +1429,7 @@ static struct dentry *nfs_atomic_lookup(struct inode *dir, struct dentry *dentry
1429 } 1429 }
1430 1430
1431 open_flags = nd->intent.open.flags; 1431 open_flags = nd->intent.open.flags;
1432 attr.ia_valid = 0; 1432 attr.ia_valid = ATTR_OPEN;
1433 1433
1434 ctx = create_nfs_open_context(dentry, open_flags); 1434 ctx = create_nfs_open_context(dentry, open_flags);
1435 res = ERR_CAST(ctx); 1435 res = ERR_CAST(ctx);
@@ -1536,7 +1536,7 @@ static int nfs_open_revalidate(struct dentry *dentry, struct nameidata *nd)
1536 if (IS_ERR(ctx)) 1536 if (IS_ERR(ctx))
1537 goto out; 1537 goto out;
1538 1538
1539 attr.ia_valid = 0; 1539 attr.ia_valid = ATTR_OPEN;
1540 if (openflags & O_TRUNC) { 1540 if (openflags & O_TRUNC) {
1541 attr.ia_valid |= ATTR_SIZE; 1541 attr.ia_valid |= ATTR_SIZE;
1542 attr.ia_size = 0; 1542 attr.ia_size = 0;
diff --git a/fs/nfs/idmap.c b/fs/nfs/idmap.c
index b7f348bb618b..ba3019f5934c 100644
--- a/fs/nfs/idmap.c
+++ b/fs/nfs/idmap.c
@@ -554,12 +554,16 @@ static int rpc_pipefs_event(struct notifier_block *nb, unsigned long event,
554 struct nfs_client *clp; 554 struct nfs_client *clp;
555 int error = 0; 555 int error = 0;
556 556
557 if (!try_module_get(THIS_MODULE))
558 return 0;
559
557 while ((clp = nfs_get_client_for_event(sb->s_fs_info, event))) { 560 while ((clp = nfs_get_client_for_event(sb->s_fs_info, event))) {
558 error = __rpc_pipefs_event(clp, event, sb); 561 error = __rpc_pipefs_event(clp, event, sb);
559 nfs_put_client(clp); 562 nfs_put_client(clp);
560 if (error) 563 if (error)
561 break; 564 break;
562 } 565 }
566 module_put(THIS_MODULE);
563 return error; 567 return error;
564} 568}
565 569
diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h
index 2476dc69365f..b777bdaba4c5 100644
--- a/fs/nfs/internal.h
+++ b/fs/nfs/internal.h
@@ -165,7 +165,8 @@ extern struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *,
165extern void nfs_free_server(struct nfs_server *server); 165extern void nfs_free_server(struct nfs_server *server);
166extern struct nfs_server *nfs_clone_server(struct nfs_server *, 166extern struct nfs_server *nfs_clone_server(struct nfs_server *,
167 struct nfs_fh *, 167 struct nfs_fh *,
168 struct nfs_fattr *); 168 struct nfs_fattr *,
169 rpc_authflavor_t);
169extern void nfs_mark_client_ready(struct nfs_client *clp, int state); 170extern void nfs_mark_client_ready(struct nfs_client *clp, int state);
170extern int nfs4_check_client_ready(struct nfs_client *clp); 171extern int nfs4_check_client_ready(struct nfs_client *clp);
171extern struct nfs_client *nfs4_set_ds_client(struct nfs_client* mds_clp, 172extern struct nfs_client *nfs4_set_ds_client(struct nfs_client* mds_clp,
@@ -186,10 +187,10 @@ static inline void nfs_fs_proc_exit(void)
186 187
187/* nfs4namespace.c */ 188/* nfs4namespace.c */
188#ifdef CONFIG_NFS_V4 189#ifdef CONFIG_NFS_V4
189extern struct vfsmount *nfs_do_refmount(struct dentry *dentry); 190extern struct vfsmount *nfs_do_refmount(struct rpc_clnt *client, struct dentry *dentry);
190#else 191#else
191static inline 192static inline
192struct vfsmount *nfs_do_refmount(struct dentry *dentry) 193struct vfsmount *nfs_do_refmount(struct rpc_clnt *client, struct dentry *dentry)
193{ 194{
194 return ERR_PTR(-ENOENT); 195 return ERR_PTR(-ENOENT);
195} 196}
@@ -234,7 +235,6 @@ extern const u32 nfs41_maxwrite_overhead;
234/* nfs4proc.c */ 235/* nfs4proc.c */
235#ifdef CONFIG_NFS_V4 236#ifdef CONFIG_NFS_V4
236extern struct rpc_procinfo nfs4_procedures[]; 237extern struct rpc_procinfo nfs4_procedures[];
237void nfs_fixup_secinfo_attributes(struct nfs_fattr *, struct nfs_fh *);
238#endif 238#endif
239 239
240extern int nfs4_init_ds_session(struct nfs_client *clp); 240extern int nfs4_init_ds_session(struct nfs_client *clp);
diff --git a/fs/nfs/namespace.c b/fs/nfs/namespace.c
index 1807866bb3ab..d51868e5683c 100644
--- a/fs/nfs/namespace.c
+++ b/fs/nfs/namespace.c
@@ -148,66 +148,31 @@ rpc_authflavor_t nfs_find_best_sec(struct nfs4_secinfo_flavors *flavors)
148 return pseudoflavor; 148 return pseudoflavor;
149} 149}
150 150
151static int nfs_negotiate_security(const struct dentry *parent, 151static struct rpc_clnt *nfs_lookup_mountpoint(struct inode *dir,
152 const struct dentry *dentry, 152 struct qstr *name,
153 rpc_authflavor_t *flavor) 153 struct nfs_fh *fh,
154 struct nfs_fattr *fattr)
154{ 155{
155 struct page *page;
156 struct nfs4_secinfo_flavors *flavors;
157 int (*secinfo)(struct inode *, const struct qstr *, struct nfs4_secinfo_flavors *);
158 int ret = -EPERM;
159
160 secinfo = NFS_PROTO(parent->d_inode)->secinfo;
161 if (secinfo != NULL) {
162 page = alloc_page(GFP_KERNEL);
163 if (!page) {
164 ret = -ENOMEM;
165 goto out;
166 }
167 flavors = page_address(page);
168 ret = secinfo(parent->d_inode, &dentry->d_name, flavors);
169 *flavor = nfs_find_best_sec(flavors);
170 put_page(page);
171 }
172
173out:
174 return ret;
175}
176
177static int nfs_lookup_with_sec(struct nfs_server *server, struct dentry *parent,
178 struct dentry *dentry, struct path *path,
179 struct nfs_fh *fh, struct nfs_fattr *fattr,
180 rpc_authflavor_t *flavor)
181{
182 struct rpc_clnt *clone;
183 struct rpc_auth *auth;
184 int err; 156 int err;
185 157
186 err = nfs_negotiate_security(parent, path->dentry, flavor); 158 if (NFS_PROTO(dir)->version == 4)
187 if (err < 0) 159 return nfs4_proc_lookup_mountpoint(dir, name, fh, fattr);
188 goto out; 160
189 clone = rpc_clone_client(server->client); 161 err = NFS_PROTO(dir)->lookup(NFS_SERVER(dir)->client, dir, name, fh, fattr);
190 auth = rpcauth_create(*flavor, clone); 162 if (err)
191 if (!auth) { 163 return ERR_PTR(err);
192 err = -EIO; 164 return rpc_clone_client(NFS_SERVER(dir)->client);
193 goto out_shutdown;
194 }
195 err = server->nfs_client->rpc_ops->lookup(clone, parent->d_inode,
196 &path->dentry->d_name,
197 fh, fattr);
198out_shutdown:
199 rpc_shutdown_client(clone);
200out:
201 return err;
202} 165}
203#else /* CONFIG_NFS_V4 */ 166#else /* CONFIG_NFS_V4 */
204static inline int nfs_lookup_with_sec(struct nfs_server *server, 167static inline struct rpc_clnt *nfs_lookup_mountpoint(struct inode *dir,
205 struct dentry *parent, struct dentry *dentry, 168 struct qstr *name,
206 struct path *path, struct nfs_fh *fh, 169 struct nfs_fh *fh,
207 struct nfs_fattr *fattr, 170 struct nfs_fattr *fattr)
208 rpc_authflavor_t *flavor)
209{ 171{
210 return -EPERM; 172 int err = NFS_PROTO(dir)->lookup(NFS_SERVER(dir)->client, dir, name, fh, fattr);
173 if (err)
174 return ERR_PTR(err);
175 return rpc_clone_client(NFS_SERVER(dir)->client);
211} 176}
212#endif /* CONFIG_NFS_V4 */ 177#endif /* CONFIG_NFS_V4 */
213 178
@@ -226,12 +191,10 @@ static inline int nfs_lookup_with_sec(struct nfs_server *server,
226struct vfsmount *nfs_d_automount(struct path *path) 191struct vfsmount *nfs_d_automount(struct path *path)
227{ 192{
228 struct vfsmount *mnt; 193 struct vfsmount *mnt;
229 struct nfs_server *server = NFS_SERVER(path->dentry->d_inode);
230 struct dentry *parent; 194 struct dentry *parent;
231 struct nfs_fh *fh = NULL; 195 struct nfs_fh *fh = NULL;
232 struct nfs_fattr *fattr = NULL; 196 struct nfs_fattr *fattr = NULL;
233 int err; 197 struct rpc_clnt *client;
234 rpc_authflavor_t flavor = RPC_AUTH_UNIX;
235 198
236 dprintk("--> nfs_d_automount()\n"); 199 dprintk("--> nfs_d_automount()\n");
237 200
@@ -249,21 +212,19 @@ struct vfsmount *nfs_d_automount(struct path *path)
249 212
250 /* Look it up again to get its attributes */ 213 /* Look it up again to get its attributes */
251 parent = dget_parent(path->dentry); 214 parent = dget_parent(path->dentry);
252 err = server->nfs_client->rpc_ops->lookup(server->client, parent->d_inode, 215 client = nfs_lookup_mountpoint(parent->d_inode, &path->dentry->d_name, fh, fattr);
253 &path->dentry->d_name,
254 fh, fattr);
255 if (err == -EPERM && NFS_PROTO(parent->d_inode)->secinfo != NULL)
256 err = nfs_lookup_with_sec(server, parent, path->dentry, path, fh, fattr, &flavor);
257 dput(parent); 216 dput(parent);
258 if (err != 0) { 217 if (IS_ERR(client)) {
259 mnt = ERR_PTR(err); 218 mnt = ERR_CAST(client);
260 goto out; 219 goto out;
261 } 220 }
262 221
263 if (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL) 222 if (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL)
264 mnt = nfs_do_refmount(path->dentry); 223 mnt = nfs_do_refmount(client, path->dentry);
265 else 224 else
266 mnt = nfs_do_submount(path->dentry, fh, fattr, flavor); 225 mnt = nfs_do_submount(path->dentry, fh, fattr, client->cl_auth->au_flavor);
226 rpc_shutdown_client(client);
227
267 if (IS_ERR(mnt)) 228 if (IS_ERR(mnt))
268 goto out; 229 goto out;
269 230
diff --git a/fs/nfs/nfs4_fs.h b/fs/nfs/nfs4_fs.h
index 97ecc863dd76..8d75021020b3 100644
--- a/fs/nfs/nfs4_fs.h
+++ b/fs/nfs/nfs4_fs.h
@@ -59,6 +59,7 @@ struct nfs_unique_id {
59 59
60#define NFS_SEQID_CONFIRMED 1 60#define NFS_SEQID_CONFIRMED 1
61struct nfs_seqid_counter { 61struct nfs_seqid_counter {
62 ktime_t create_time;
62 int owner_id; 63 int owner_id;
63 int flags; 64 int flags;
64 u32 counter; 65 u32 counter;
@@ -204,6 +205,9 @@ struct nfs4_state_maintenance_ops {
204extern const struct dentry_operations nfs4_dentry_operations; 205extern const struct dentry_operations nfs4_dentry_operations;
205extern const struct inode_operations nfs4_dir_inode_operations; 206extern const struct inode_operations nfs4_dir_inode_operations;
206 207
208/* nfs4namespace.c */
209struct rpc_clnt *nfs4_create_sec_client(struct rpc_clnt *, struct inode *, struct qstr *);
210
207/* nfs4proc.c */ 211/* nfs4proc.c */
208extern int nfs4_proc_setclientid(struct nfs_client *, u32, unsigned short, struct rpc_cred *, struct nfs4_setclientid_res *); 212extern int nfs4_proc_setclientid(struct nfs_client *, u32, unsigned short, struct rpc_cred *, struct nfs4_setclientid_res *);
209extern int nfs4_proc_setclientid_confirm(struct nfs_client *, struct nfs4_setclientid_res *arg, struct rpc_cred *); 213extern int nfs4_proc_setclientid_confirm(struct nfs_client *, struct nfs4_setclientid_res *arg, struct rpc_cred *);
@@ -212,8 +216,11 @@ extern int nfs4_init_clientid(struct nfs_client *, struct rpc_cred *);
212extern int nfs41_init_clientid(struct nfs_client *, struct rpc_cred *); 216extern int nfs41_init_clientid(struct nfs_client *, struct rpc_cred *);
213extern int nfs4_do_close(struct nfs4_state *state, gfp_t gfp_mask, int wait, bool roc); 217extern int nfs4_do_close(struct nfs4_state *state, gfp_t gfp_mask, int wait, bool roc);
214extern int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle); 218extern int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle);
215extern int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name, 219extern int nfs4_proc_fs_locations(struct rpc_clnt *, struct inode *, const struct qstr *,
216 struct nfs4_fs_locations *fs_locations, struct page *page); 220 struct nfs4_fs_locations *, struct page *);
221extern struct rpc_clnt *nfs4_proc_lookup_mountpoint(struct inode *, struct qstr *,
222 struct nfs_fh *, struct nfs_fattr *);
223extern int nfs4_proc_secinfo(struct inode *, const struct qstr *, struct nfs4_secinfo_flavors *);
217extern int nfs4_release_lockowner(struct nfs4_lock_state *); 224extern int nfs4_release_lockowner(struct nfs4_lock_state *);
218extern const struct xattr_handler *nfs4_xattr_handlers[]; 225extern const struct xattr_handler *nfs4_xattr_handlers[];
219 226
diff --git a/fs/nfs/nfs4filelayoutdev.c b/fs/nfs/nfs4filelayoutdev.c
index a866bbd2890a..c9cff9adb2d3 100644
--- a/fs/nfs/nfs4filelayoutdev.c
+++ b/fs/nfs/nfs4filelayoutdev.c
@@ -699,7 +699,7 @@ get_device_info(struct inode *inode, struct nfs4_deviceid *dev_id, gfp_t gfp_fla
699 * GETDEVICEINFO's maxcount 699 * GETDEVICEINFO's maxcount
700 */ 700 */
701 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; 701 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz;
702 max_pages = max_resp_sz >> PAGE_SHIFT; 702 max_pages = nfs_page_array_len(0, max_resp_sz);
703 dprintk("%s inode %p max_resp_sz %u max_pages %d\n", 703 dprintk("%s inode %p max_resp_sz %u max_pages %d\n",
704 __func__, inode, max_resp_sz, max_pages); 704 __func__, inode, max_resp_sz, max_pages);
705 705
diff --git a/fs/nfs/nfs4namespace.c b/fs/nfs/nfs4namespace.c
index 9c8eca315f43..a7f3dedc4ec7 100644
--- a/fs/nfs/nfs4namespace.c
+++ b/fs/nfs/nfs4namespace.c
@@ -52,6 +52,30 @@ Elong:
52} 52}
53 53
54/* 54/*
55 * return the path component of "<server>:<path>"
56 * nfspath - the "<server>:<path>" string
57 * end - one past the last char that could contain "<server>:"
58 * returns NULL on failure
59 */
60static char *nfs_path_component(const char *nfspath, const char *end)
61{
62 char *p;
63
64 if (*nfspath == '[') {
65 /* parse [] escaped IPv6 addrs */
66 p = strchr(nfspath, ']');
67 if (p != NULL && ++p < end && *p == ':')
68 return p + 1;
69 } else {
70 /* otherwise split on first colon */
71 p = strchr(nfspath, ':');
72 if (p != NULL && p < end)
73 return p + 1;
74 }
75 return NULL;
76}
77
78/*
55 * Determine the mount path as a string 79 * Determine the mount path as a string
56 */ 80 */
57static char *nfs4_path(struct dentry *dentry, char *buffer, ssize_t buflen) 81static char *nfs4_path(struct dentry *dentry, char *buffer, ssize_t buflen)
@@ -59,9 +83,9 @@ static char *nfs4_path(struct dentry *dentry, char *buffer, ssize_t buflen)
59 char *limit; 83 char *limit;
60 char *path = nfs_path(&limit, dentry, buffer, buflen); 84 char *path = nfs_path(&limit, dentry, buffer, buflen);
61 if (!IS_ERR(path)) { 85 if (!IS_ERR(path)) {
62 char *colon = strchr(path, ':'); 86 char *path_component = nfs_path_component(path, limit);
63 if (colon && colon < limit) 87 if (path_component)
64 path = colon + 1; 88 return path_component;
65 } 89 }
66 return path; 90 return path;
67} 91}
@@ -108,6 +132,58 @@ static size_t nfs_parse_server_name(char *string, size_t len,
108 return ret; 132 return ret;
109} 133}
110 134
135static rpc_authflavor_t nfs4_negotiate_security(struct inode *inode, struct qstr *name)
136{
137 struct page *page;
138 struct nfs4_secinfo_flavors *flavors;
139 rpc_authflavor_t flavor;
140 int err;
141
142 page = alloc_page(GFP_KERNEL);
143 if (!page)
144 return -ENOMEM;
145 flavors = page_address(page);
146
147 err = nfs4_proc_secinfo(inode, name, flavors);
148 if (err < 0) {
149 flavor = err;
150 goto out;
151 }
152
153 flavor = nfs_find_best_sec(flavors);
154
155out:
156 put_page(page);
157 return flavor;
158}
159
160/*
161 * Please call rpc_shutdown_client() when you are done with this client.
162 */
163struct rpc_clnt *nfs4_create_sec_client(struct rpc_clnt *clnt, struct inode *inode,
164 struct qstr *name)
165{
166 struct rpc_clnt *clone;
167 struct rpc_auth *auth;
168 rpc_authflavor_t flavor;
169
170 flavor = nfs4_negotiate_security(inode, name);
171 if (flavor < 0)
172 return ERR_PTR(flavor);
173
174 clone = rpc_clone_client(clnt);
175 if (IS_ERR(clone))
176 return clone;
177
178 auth = rpcauth_create(flavor, clone);
179 if (!auth) {
180 rpc_shutdown_client(clone);
181 clone = ERR_PTR(-EIO);
182 }
183
184 return clone;
185}
186
111static struct vfsmount *try_location(struct nfs_clone_mount *mountdata, 187static struct vfsmount *try_location(struct nfs_clone_mount *mountdata,
112 char *page, char *page2, 188 char *page, char *page2,
113 const struct nfs4_fs_location *location) 189 const struct nfs4_fs_location *location)
@@ -224,7 +300,7 @@ out:
224 * @dentry - dentry of referral 300 * @dentry - dentry of referral
225 * 301 *
226 */ 302 */
227struct vfsmount *nfs_do_refmount(struct dentry *dentry) 303struct vfsmount *nfs_do_refmount(struct rpc_clnt *client, struct dentry *dentry)
228{ 304{
229 struct vfsmount *mnt = ERR_PTR(-ENOMEM); 305 struct vfsmount *mnt = ERR_PTR(-ENOMEM);
230 struct dentry *parent; 306 struct dentry *parent;
@@ -250,7 +326,7 @@ struct vfsmount *nfs_do_refmount(struct dentry *dentry)
250 dprintk("%s: getting locations for %s/%s\n", 326 dprintk("%s: getting locations for %s/%s\n",
251 __func__, parent->d_name.name, dentry->d_name.name); 327 __func__, parent->d_name.name, dentry->d_name.name);
252 328
253 err = nfs4_proc_fs_locations(parent->d_inode, &dentry->d_name, fs_locations, page); 329 err = nfs4_proc_fs_locations(client, parent->d_inode, &dentry->d_name, fs_locations, page);
254 dput(parent); 330 dput(parent);
255 if (err != 0 || 331 if (err != 0 ||
256 fs_locations->nlocations <= 0 || 332 fs_locations->nlocations <= 0 ||
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index f82bde005a82..99650aaf8937 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -838,7 +838,8 @@ static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry,
838 p->o_arg.open_flags = flags; 838 p->o_arg.open_flags = flags;
839 p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); 839 p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE);
840 p->o_arg.clientid = server->nfs_client->cl_clientid; 840 p->o_arg.clientid = server->nfs_client->cl_clientid;
841 p->o_arg.id = sp->so_seqid.owner_id; 841 p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time);
842 p->o_arg.id.uniquifier = sp->so_seqid.owner_id;
842 p->o_arg.name = &dentry->d_name; 843 p->o_arg.name = &dentry->d_name;
843 p->o_arg.server = server; 844 p->o_arg.server = server;
844 p->o_arg.bitmask = server->attr_bitmask; 845 p->o_arg.bitmask = server->attr_bitmask;
@@ -1466,8 +1467,7 @@ static void nfs4_open_prepare(struct rpc_task *task, void *calldata)
1466 goto unlock_no_action; 1467 goto unlock_no_action;
1467 rcu_read_unlock(); 1468 rcu_read_unlock();
1468 } 1469 }
1469 /* Update sequence id. */ 1470 /* Update client id. */
1470 data->o_arg.id = sp->so_seqid.owner_id;
1471 data->o_arg.clientid = sp->so_server->nfs_client->cl_clientid; 1471 data->o_arg.clientid = sp->so_server->nfs_client->cl_clientid;
1472 if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) { 1472 if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) {
1473 task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; 1473 task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR];
@@ -1954,10 +1954,19 @@ static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
1954 }; 1954 };
1955 int err; 1955 int err;
1956 do { 1956 do {
1957 err = nfs4_handle_exception(server, 1957 err = _nfs4_do_setattr(inode, cred, fattr, sattr, state);
1958 _nfs4_do_setattr(inode, cred, fattr, sattr, state), 1958 switch (err) {
1959 &exception); 1959 case -NFS4ERR_OPENMODE:
1960 if (state && !(state->state & FMODE_WRITE)) {
1961 err = -EBADF;
1962 if (sattr->ia_valid & ATTR_OPEN)
1963 err = -EACCES;
1964 goto out;
1965 }
1966 }
1967 err = nfs4_handle_exception(server, err, &exception);
1960 } while (exception.retry); 1968 } while (exception.retry);
1969out:
1961 return err; 1970 return err;
1962} 1971}
1963 1972
@@ -2368,8 +2377,9 @@ static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle,
2368 * Note that we'll actually follow the referral later when 2377 * Note that we'll actually follow the referral later when
2369 * we detect fsid mismatch in inode revalidation 2378 * we detect fsid mismatch in inode revalidation
2370 */ 2379 */
2371static int nfs4_get_referral(struct inode *dir, const struct qstr *name, 2380static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir,
2372 struct nfs_fattr *fattr, struct nfs_fh *fhandle) 2381 const struct qstr *name, struct nfs_fattr *fattr,
2382 struct nfs_fh *fhandle)
2373{ 2383{
2374 int status = -ENOMEM; 2384 int status = -ENOMEM;
2375 struct page *page = NULL; 2385 struct page *page = NULL;
@@ -2382,7 +2392,7 @@ static int nfs4_get_referral(struct inode *dir, const struct qstr *name,
2382 if (locations == NULL) 2392 if (locations == NULL)
2383 goto out; 2393 goto out;
2384 2394
2385 status = nfs4_proc_fs_locations(dir, name, locations, page); 2395 status = nfs4_proc_fs_locations(client, dir, name, locations, page);
2386 if (status != 0) 2396 if (status != 0)
2387 goto out; 2397 goto out;
2388 /* Make sure server returned a different fsid for the referral */ 2398 /* Make sure server returned a different fsid for the referral */
@@ -2519,39 +2529,84 @@ static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir,
2519 return status; 2529 return status;
2520} 2530}
2521 2531
2522void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr, struct nfs_fh *fh) 2532static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr)
2523{ 2533{
2524 memset(fh, 0, sizeof(struct nfs_fh));
2525 fattr->fsid.major = 1;
2526 fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | 2534 fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE |
2527 NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_FSID | NFS_ATTR_FATTR_MOUNTPOINT; 2535 NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT;
2528 fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; 2536 fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO;
2529 fattr->nlink = 2; 2537 fattr->nlink = 2;
2530} 2538}
2531 2539
2532static int nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, struct qstr *name, 2540static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir,
2533 struct nfs_fh *fhandle, struct nfs_fattr *fattr) 2541 struct qstr *name, struct nfs_fh *fhandle,
2542 struct nfs_fattr *fattr)
2534{ 2543{
2535 struct nfs4_exception exception = { }; 2544 struct nfs4_exception exception = { };
2545 struct rpc_clnt *client = *clnt;
2536 int err; 2546 int err;
2537 do { 2547 do {
2538 int status; 2548 err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr);
2539 2549 switch (err) {
2540 status = _nfs4_proc_lookup(clnt, dir, name, fhandle, fattr);
2541 switch (status) {
2542 case -NFS4ERR_BADNAME: 2550 case -NFS4ERR_BADNAME:
2543 return -ENOENT; 2551 err = -ENOENT;
2552 goto out;
2544 case -NFS4ERR_MOVED: 2553 case -NFS4ERR_MOVED:
2545 return nfs4_get_referral(dir, name, fattr, fhandle); 2554 err = nfs4_get_referral(client, dir, name, fattr, fhandle);
2555 goto out;
2546 case -NFS4ERR_WRONGSEC: 2556 case -NFS4ERR_WRONGSEC:
2547 nfs_fixup_secinfo_attributes(fattr, fhandle); 2557 err = -EPERM;
2558 if (client != *clnt)
2559 goto out;
2560
2561 client = nfs4_create_sec_client(client, dir, name);
2562 if (IS_ERR(client))
2563 return PTR_ERR(client);
2564
2565 exception.retry = 1;
2566 break;
2567 default:
2568 err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception);
2548 } 2569 }
2549 err = nfs4_handle_exception(NFS_SERVER(dir),
2550 status, &exception);
2551 } while (exception.retry); 2570 } while (exception.retry);
2571
2572out:
2573 if (err == 0)
2574 *clnt = client;
2575 else if (client != *clnt)
2576 rpc_shutdown_client(client);
2577
2552 return err; 2578 return err;
2553} 2579}
2554 2580
2581static int nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, struct qstr *name,
2582 struct nfs_fh *fhandle, struct nfs_fattr *fattr)
2583{
2584 int status;
2585 struct rpc_clnt *client = NFS_CLIENT(dir);
2586
2587 status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr);
2588 if (client != NFS_CLIENT(dir)) {
2589 rpc_shutdown_client(client);
2590 nfs_fixup_secinfo_attributes(fattr);
2591 }
2592 return status;
2593}
2594
2595struct rpc_clnt *
2596nfs4_proc_lookup_mountpoint(struct inode *dir, struct qstr *name,
2597 struct nfs_fh *fhandle, struct nfs_fattr *fattr)
2598{
2599 int status;
2600 struct rpc_clnt *client = rpc_clone_client(NFS_CLIENT(dir));
2601
2602 status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr);
2603 if (status < 0) {
2604 rpc_shutdown_client(client);
2605 return ERR_PTR(status);
2606 }
2607 return client;
2608}
2609
2555static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) 2610static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry)
2556{ 2611{
2557 struct nfs_server *server = NFS_SERVER(inode); 2612 struct nfs_server *server = NFS_SERVER(inode);
@@ -3619,16 +3674,16 @@ out:
3619 return ret; 3674 return ret;
3620} 3675}
3621 3676
3622static void nfs4_write_cached_acl(struct inode *inode, const char *buf, size_t acl_len) 3677static void nfs4_write_cached_acl(struct inode *inode, struct page **pages, size_t pgbase, size_t acl_len)
3623{ 3678{
3624 struct nfs4_cached_acl *acl; 3679 struct nfs4_cached_acl *acl;
3625 3680
3626 if (buf && acl_len <= PAGE_SIZE) { 3681 if (pages && acl_len <= PAGE_SIZE) {
3627 acl = kmalloc(sizeof(*acl) + acl_len, GFP_KERNEL); 3682 acl = kmalloc(sizeof(*acl) + acl_len, GFP_KERNEL);
3628 if (acl == NULL) 3683 if (acl == NULL)
3629 goto out; 3684 goto out;
3630 acl->cached = 1; 3685 acl->cached = 1;
3631 memcpy(acl->data, buf, acl_len); 3686 _copy_from_pages(acl->data, pages, pgbase, acl_len);
3632 } else { 3687 } else {
3633 acl = kmalloc(sizeof(*acl), GFP_KERNEL); 3688 acl = kmalloc(sizeof(*acl), GFP_KERNEL);
3634 if (acl == NULL) 3689 if (acl == NULL)
@@ -3661,7 +3716,6 @@ static ssize_t __nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t bu
3661 struct nfs_getaclres res = { 3716 struct nfs_getaclres res = {
3662 .acl_len = buflen, 3717 .acl_len = buflen,
3663 }; 3718 };
3664 void *resp_buf;
3665 struct rpc_message msg = { 3719 struct rpc_message msg = {
3666 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], 3720 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL],
3667 .rpc_argp = &args, 3721 .rpc_argp = &args,
@@ -3675,24 +3729,27 @@ static ssize_t __nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t bu
3675 if (npages == 0) 3729 if (npages == 0)
3676 npages = 1; 3730 npages = 1;
3677 3731
3732 /* Add an extra page to handle the bitmap returned */
3733 npages++;
3734
3678 for (i = 0; i < npages; i++) { 3735 for (i = 0; i < npages; i++) {
3679 pages[i] = alloc_page(GFP_KERNEL); 3736 pages[i] = alloc_page(GFP_KERNEL);
3680 if (!pages[i]) 3737 if (!pages[i])
3681 goto out_free; 3738 goto out_free;
3682 } 3739 }
3683 if (npages > 1) { 3740
3684 /* for decoding across pages */ 3741 /* for decoding across pages */
3685 res.acl_scratch = alloc_page(GFP_KERNEL); 3742 res.acl_scratch = alloc_page(GFP_KERNEL);
3686 if (!res.acl_scratch) 3743 if (!res.acl_scratch)
3687 goto out_free; 3744 goto out_free;
3688 } 3745
3689 args.acl_len = npages * PAGE_SIZE; 3746 args.acl_len = npages * PAGE_SIZE;
3690 args.acl_pgbase = 0; 3747 args.acl_pgbase = 0;
3748
3691 /* Let decode_getfacl know not to fail if the ACL data is larger than 3749 /* Let decode_getfacl know not to fail if the ACL data is larger than
3692 * the page we send as a guess */ 3750 * the page we send as a guess */
3693 if (buf == NULL) 3751 if (buf == NULL)
3694 res.acl_flags |= NFS4_ACL_LEN_REQUEST; 3752 res.acl_flags |= NFS4_ACL_LEN_REQUEST;
3695 resp_buf = page_address(pages[0]);
3696 3753
3697 dprintk("%s buf %p buflen %zu npages %d args.acl_len %zu\n", 3754 dprintk("%s buf %p buflen %zu npages %d args.acl_len %zu\n",
3698 __func__, buf, buflen, npages, args.acl_len); 3755 __func__, buf, buflen, npages, args.acl_len);
@@ -3703,9 +3760,9 @@ static ssize_t __nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t bu
3703 3760
3704 acl_len = res.acl_len - res.acl_data_offset; 3761 acl_len = res.acl_len - res.acl_data_offset;
3705 if (acl_len > args.acl_len) 3762 if (acl_len > args.acl_len)
3706 nfs4_write_cached_acl(inode, NULL, acl_len); 3763 nfs4_write_cached_acl(inode, NULL, 0, acl_len);
3707 else 3764 else
3708 nfs4_write_cached_acl(inode, resp_buf + res.acl_data_offset, 3765 nfs4_write_cached_acl(inode, pages, res.acl_data_offset,
3709 acl_len); 3766 acl_len);
3710 if (buf) { 3767 if (buf) {
3711 ret = -ERANGE; 3768 ret = -ERANGE;
@@ -4558,7 +4615,9 @@ static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *f
4558static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) 4615static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request)
4559{ 4616{
4560 struct nfs_server *server = NFS_SERVER(state->inode); 4617 struct nfs_server *server = NFS_SERVER(state->inode);
4561 struct nfs4_exception exception = { }; 4618 struct nfs4_exception exception = {
4619 .inode = state->inode,
4620 };
4562 int err; 4621 int err;
4563 4622
4564 do { 4623 do {
@@ -4576,7 +4635,9 @@ static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request
4576static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) 4635static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request)
4577{ 4636{
4578 struct nfs_server *server = NFS_SERVER(state->inode); 4637 struct nfs_server *server = NFS_SERVER(state->inode);
4579 struct nfs4_exception exception = { }; 4638 struct nfs4_exception exception = {
4639 .inode = state->inode,
4640 };
4580 int err; 4641 int err;
4581 4642
4582 err = nfs4_set_lock_state(state, request); 4643 err = nfs4_set_lock_state(state, request);
@@ -4676,6 +4737,7 @@ static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *
4676{ 4737{
4677 struct nfs4_exception exception = { 4738 struct nfs4_exception exception = {
4678 .state = state, 4739 .state = state,
4740 .inode = state->inode,
4679 }; 4741 };
4680 int err; 4742 int err;
4681 4743
@@ -4721,6 +4783,20 @@ nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request)
4721 4783
4722 if (state == NULL) 4784 if (state == NULL)
4723 return -ENOLCK; 4785 return -ENOLCK;
4786 /*
4787 * Don't rely on the VFS having checked the file open mode,
4788 * since it won't do this for flock() locks.
4789 */
4790 switch (request->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) {
4791 case F_RDLCK:
4792 if (!(filp->f_mode & FMODE_READ))
4793 return -EBADF;
4794 break;
4795 case F_WRLCK:
4796 if (!(filp->f_mode & FMODE_WRITE))
4797 return -EBADF;
4798 }
4799
4724 do { 4800 do {
4725 status = nfs4_proc_setlk(state, cmd, request); 4801 status = nfs4_proc_setlk(state, cmd, request);
4726 if ((status != -EAGAIN) || IS_SETLK(cmd)) 4802 if ((status != -EAGAIN) || IS_SETLK(cmd))
@@ -4891,8 +4967,10 @@ static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr)
4891 fattr->nlink = 2; 4967 fattr->nlink = 2;
4892} 4968}
4893 4969
4894int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name, 4970static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir,
4895 struct nfs4_fs_locations *fs_locations, struct page *page) 4971 const struct qstr *name,
4972 struct nfs4_fs_locations *fs_locations,
4973 struct page *page)
4896{ 4974{
4897 struct nfs_server *server = NFS_SERVER(dir); 4975 struct nfs_server *server = NFS_SERVER(dir);
4898 u32 bitmask[2] = { 4976 u32 bitmask[2] = {
@@ -4926,11 +5004,26 @@ int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name,
4926 nfs_fattr_init(&fs_locations->fattr); 5004 nfs_fattr_init(&fs_locations->fattr);
4927 fs_locations->server = server; 5005 fs_locations->server = server;
4928 fs_locations->nlocations = 0; 5006 fs_locations->nlocations = 0;
4929 status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); 5007 status = nfs4_call_sync(client, server, &msg, &args.seq_args, &res.seq_res, 0);
4930 dprintk("%s: returned status = %d\n", __func__, status); 5008 dprintk("%s: returned status = %d\n", __func__, status);
4931 return status; 5009 return status;
4932} 5010}
4933 5011
5012int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir,
5013 const struct qstr *name,
5014 struct nfs4_fs_locations *fs_locations,
5015 struct page *page)
5016{
5017 struct nfs4_exception exception = { };
5018 int err;
5019 do {
5020 err = nfs4_handle_exception(NFS_SERVER(dir),
5021 _nfs4_proc_fs_locations(client, dir, name, fs_locations, page),
5022 &exception);
5023 } while (exception.retry);
5024 return err;
5025}
5026
4934static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) 5027static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors)
4935{ 5028{
4936 int status; 5029 int status;
@@ -4953,8 +5046,8 @@ static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct
4953 return status; 5046 return status;
4954} 5047}
4955 5048
4956static int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, 5049int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name,
4957 struct nfs4_secinfo_flavors *flavors) 5050 struct nfs4_secinfo_flavors *flavors)
4958{ 5051{
4959 struct nfs4_exception exception = { }; 5052 struct nfs4_exception exception = { };
4960 int err; 5053 int err;
@@ -5029,10 +5122,9 @@ int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred)
5029 nfs4_construct_boot_verifier(clp, &verifier); 5122 nfs4_construct_boot_verifier(clp, &verifier);
5030 5123
5031 args.id_len = scnprintf(args.id, sizeof(args.id), 5124 args.id_len = scnprintf(args.id, sizeof(args.id),
5032 "%s/%s.%s/%u", 5125 "%s/%s/%u",
5033 clp->cl_ipaddr, 5126 clp->cl_ipaddr,
5034 init_utsname()->nodename, 5127 clp->cl_rpcclient->cl_nodename,
5035 init_utsname()->domainname,
5036 clp->cl_rpcclient->cl_auth->au_flavor); 5128 clp->cl_rpcclient->cl_auth->au_flavor);
5037 5129
5038 res.server_scope = kzalloc(sizeof(struct server_scope), GFP_KERNEL); 5130 res.server_scope = kzalloc(sizeof(struct server_scope), GFP_KERNEL);
diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c
index 0f43414eb25a..7f0fcfc1fe9d 100644
--- a/fs/nfs/nfs4state.c
+++ b/fs/nfs/nfs4state.c
@@ -393,6 +393,7 @@ nfs4_remove_state_owner_locked(struct nfs4_state_owner *sp)
393static void 393static void
394nfs4_init_seqid_counter(struct nfs_seqid_counter *sc) 394nfs4_init_seqid_counter(struct nfs_seqid_counter *sc)
395{ 395{
396 sc->create_time = ktime_get();
396 sc->flags = 0; 397 sc->flags = 0;
397 sc->counter = 0; 398 sc->counter = 0;
398 spin_lock_init(&sc->lock); 399 spin_lock_init(&sc->lock);
@@ -434,13 +435,17 @@ nfs4_alloc_state_owner(struct nfs_server *server,
434static void 435static void
435nfs4_drop_state_owner(struct nfs4_state_owner *sp) 436nfs4_drop_state_owner(struct nfs4_state_owner *sp)
436{ 437{
437 if (!RB_EMPTY_NODE(&sp->so_server_node)) { 438 struct rb_node *rb_node = &sp->so_server_node;
439
440 if (!RB_EMPTY_NODE(rb_node)) {
438 struct nfs_server *server = sp->so_server; 441 struct nfs_server *server = sp->so_server;
439 struct nfs_client *clp = server->nfs_client; 442 struct nfs_client *clp = server->nfs_client;
440 443
441 spin_lock(&clp->cl_lock); 444 spin_lock(&clp->cl_lock);
442 rb_erase(&sp->so_server_node, &server->state_owners); 445 if (!RB_EMPTY_NODE(rb_node)) {
443 RB_CLEAR_NODE(&sp->so_server_node); 446 rb_erase(rb_node, &server->state_owners);
447 RB_CLEAR_NODE(rb_node);
448 }
444 spin_unlock(&clp->cl_lock); 449 spin_unlock(&clp->cl_lock);
445 } 450 }
446} 451}
@@ -516,6 +521,14 @@ out:
516/** 521/**
517 * nfs4_put_state_owner - Release a nfs4_state_owner 522 * nfs4_put_state_owner - Release a nfs4_state_owner
518 * @sp: state owner data to release 523 * @sp: state owner data to release
524 *
525 * Note that we keep released state owners on an LRU
526 * list.
527 * This caches valid state owners so that they can be
528 * reused, to avoid the OPEN_CONFIRM on minor version 0.
529 * It also pins the uniquifier of dropped state owners for
530 * a while, to ensure that those state owner names are
531 * never reused.
519 */ 532 */
520void nfs4_put_state_owner(struct nfs4_state_owner *sp) 533void nfs4_put_state_owner(struct nfs4_state_owner *sp)
521{ 534{
@@ -525,15 +538,9 @@ void nfs4_put_state_owner(struct nfs4_state_owner *sp)
525 if (!atomic_dec_and_lock(&sp->so_count, &clp->cl_lock)) 538 if (!atomic_dec_and_lock(&sp->so_count, &clp->cl_lock))
526 return; 539 return;
527 540
528 if (!RB_EMPTY_NODE(&sp->so_server_node)) { 541 sp->so_expires = jiffies;
529 sp->so_expires = jiffies; 542 list_add_tail(&sp->so_lru, &server->state_owners_lru);
530 list_add_tail(&sp->so_lru, &server->state_owners_lru); 543 spin_unlock(&clp->cl_lock);
531 spin_unlock(&clp->cl_lock);
532 } else {
533 nfs4_remove_state_owner_locked(sp);
534 spin_unlock(&clp->cl_lock);
535 nfs4_free_state_owner(sp);
536 }
537} 544}
538 545
539/** 546/**
diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
index c74fdb114b48..c54aae364bee 100644
--- a/fs/nfs/nfs4xdr.c
+++ b/fs/nfs/nfs4xdr.c
@@ -74,7 +74,7 @@ static int nfs4_stat_to_errno(int);
74/* lock,open owner id: 74/* lock,open owner id:
75 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2) 75 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
76 */ 76 */
77#define open_owner_id_maxsz (1 + 1 + 4) 77#define open_owner_id_maxsz (1 + 2 + 1 + 1 + 2)
78#define lock_owner_id_maxsz (1 + 1 + 4) 78#define lock_owner_id_maxsz (1 + 1 + 4)
79#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) 79#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
80#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2)) 80#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
@@ -1340,12 +1340,13 @@ static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_opena
1340 */ 1340 */
1341 encode_nfs4_seqid(xdr, arg->seqid); 1341 encode_nfs4_seqid(xdr, arg->seqid);
1342 encode_share_access(xdr, arg->fmode); 1342 encode_share_access(xdr, arg->fmode);
1343 p = reserve_space(xdr, 32); 1343 p = reserve_space(xdr, 36);
1344 p = xdr_encode_hyper(p, arg->clientid); 1344 p = xdr_encode_hyper(p, arg->clientid);
1345 *p++ = cpu_to_be32(20); 1345 *p++ = cpu_to_be32(24);
1346 p = xdr_encode_opaque_fixed(p, "open id:", 8); 1346 p = xdr_encode_opaque_fixed(p, "open id:", 8);
1347 *p++ = cpu_to_be32(arg->server->s_dev); 1347 *p++ = cpu_to_be32(arg->server->s_dev);
1348 xdr_encode_hyper(p, arg->id); 1348 *p++ = cpu_to_be32(arg->id.uniquifier);
1349 xdr_encode_hyper(p, arg->id.create_time);
1349} 1350}
1350 1351
1351static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg) 1352static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
@@ -4257,8 +4258,6 @@ static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4257 status = decode_attr_error(xdr, bitmap, &err); 4258 status = decode_attr_error(xdr, bitmap, &err);
4258 if (status < 0) 4259 if (status < 0)
4259 goto xdr_error; 4260 goto xdr_error;
4260 if (err == -NFS4ERR_WRONGSEC)
4261 nfs_fixup_secinfo_attributes(fattr, fh);
4262 4261
4263 status = decode_attr_filehandle(xdr, bitmap, fh); 4262 status = decode_attr_filehandle(xdr, bitmap, fh);
4264 if (status < 0) 4263 if (status < 0)
@@ -4901,11 +4900,19 @@ static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
4901 bitmap[3] = {0}; 4900 bitmap[3] = {0};
4902 struct kvec *iov = req->rq_rcv_buf.head; 4901 struct kvec *iov = req->rq_rcv_buf.head;
4903 int status; 4902 int status;
4903 size_t page_len = xdr->buf->page_len;
4904 4904
4905 res->acl_len = 0; 4905 res->acl_len = 0;
4906 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 4906 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4907 goto out; 4907 goto out;
4908
4908 bm_p = xdr->p; 4909 bm_p = xdr->p;
4910 res->acl_data_offset = be32_to_cpup(bm_p) + 2;
4911 res->acl_data_offset <<= 2;
4912 /* Check if the acl data starts beyond the allocated buffer */
4913 if (res->acl_data_offset > page_len)
4914 return -ERANGE;
4915
4909 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 4916 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4910 goto out; 4917 goto out;
4911 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 4918 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
@@ -4915,28 +4922,24 @@ static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
4915 return -EIO; 4922 return -EIO;
4916 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) { 4923 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
4917 size_t hdrlen; 4924 size_t hdrlen;
4918 u32 recvd;
4919 4925
4920 /* The bitmap (xdr len + bitmaps) and the attr xdr len words 4926 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
4921 * are stored with the acl data to handle the problem of 4927 * are stored with the acl data to handle the problem of
4922 * variable length bitmaps.*/ 4928 * variable length bitmaps.*/
4923 xdr->p = bm_p; 4929 xdr->p = bm_p;
4924 res->acl_data_offset = be32_to_cpup(bm_p) + 2;
4925 res->acl_data_offset <<= 2;
4926 4930
4927 /* We ignore &savep and don't do consistency checks on 4931 /* We ignore &savep and don't do consistency checks on
4928 * the attr length. Let userspace figure it out.... */ 4932 * the attr length. Let userspace figure it out.... */
4929 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base; 4933 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
4930 attrlen += res->acl_data_offset; 4934 attrlen += res->acl_data_offset;
4931 recvd = req->rq_rcv_buf.len - hdrlen; 4935 if (attrlen > page_len) {
4932 if (attrlen > recvd) {
4933 if (res->acl_flags & NFS4_ACL_LEN_REQUEST) { 4936 if (res->acl_flags & NFS4_ACL_LEN_REQUEST) {
4934 /* getxattr interface called with a NULL buf */ 4937 /* getxattr interface called with a NULL buf */
4935 res->acl_len = attrlen; 4938 res->acl_len = attrlen;
4936 goto out; 4939 goto out;
4937 } 4940 }
4938 dprintk("NFS: acl reply: attrlen %u > recvd %u\n", 4941 dprintk("NFS: acl reply: attrlen %u > page_len %zu\n",
4939 attrlen, recvd); 4942 attrlen, page_len);
4940 return -EINVAL; 4943 return -EINVAL;
4941 } 4944 }
4942 xdr_read_pages(xdr, attrlen); 4945 xdr_read_pages(xdr, attrlen);
@@ -5089,16 +5092,13 @@ out_err:
5089 return -EINVAL; 5092 return -EINVAL;
5090} 5093}
5091 5094
5092static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res) 5095static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5093{ 5096{
5094 struct nfs4_secinfo_flavor *sec_flavor; 5097 struct nfs4_secinfo_flavor *sec_flavor;
5095 int status; 5098 int status;
5096 __be32 *p; 5099 __be32 *p;
5097 int i, num_flavors; 5100 int i, num_flavors;
5098 5101
5099 status = decode_op_hdr(xdr, OP_SECINFO);
5100 if (status)
5101 goto out;
5102 p = xdr_inline_decode(xdr, 4); 5102 p = xdr_inline_decode(xdr, 4);
5103 if (unlikely(!p)) 5103 if (unlikely(!p))
5104 goto out_overflow; 5104 goto out_overflow;
@@ -5124,6 +5124,7 @@ static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5124 res->flavors->num_flavors++; 5124 res->flavors->num_flavors++;
5125 } 5125 }
5126 5126
5127 status = 0;
5127out: 5128out:
5128 return status; 5129 return status;
5129out_overflow: 5130out_overflow:
@@ -5131,7 +5132,23 @@ out_overflow:
5131 return -EIO; 5132 return -EIO;
5132} 5133}
5133 5134
5135static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5136{
5137 int status = decode_op_hdr(xdr, OP_SECINFO);
5138 if (status)
5139 return status;
5140 return decode_secinfo_common(xdr, res);
5141}
5142
5134#if defined(CONFIG_NFS_V4_1) 5143#if defined(CONFIG_NFS_V4_1)
5144static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5145{
5146 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5147 if (status)
5148 return status;
5149 return decode_secinfo_common(xdr, res);
5150}
5151
5135static int decode_exchange_id(struct xdr_stream *xdr, 5152static int decode_exchange_id(struct xdr_stream *xdr,
5136 struct nfs41_exchange_id_res *res) 5153 struct nfs41_exchange_id_res *res)
5137{ 5154{
@@ -6816,7 +6833,7 @@ static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
6816 status = decode_putrootfh(xdr); 6833 status = decode_putrootfh(xdr);
6817 if (status) 6834 if (status)
6818 goto out; 6835 goto out;
6819 status = decode_secinfo(xdr, res); 6836 status = decode_secinfo_no_name(xdr, res);
6820out: 6837out:
6821 return status; 6838 return status;
6822} 6839}
diff --git a/fs/nfs/objlayout/objlayout.c b/fs/nfs/objlayout/objlayout.c
index 8d45f1c318ce..595c5fc21a19 100644
--- a/fs/nfs/objlayout/objlayout.c
+++ b/fs/nfs/objlayout/objlayout.c
@@ -604,7 +604,6 @@ int objlayout_get_deviceinfo(struct pnfs_layout_hdr *pnfslay,
604{ 604{
605 struct objlayout_deviceinfo *odi; 605 struct objlayout_deviceinfo *odi;
606 struct pnfs_device pd; 606 struct pnfs_device pd;
607 struct super_block *sb;
608 struct page *page, **pages; 607 struct page *page, **pages;
609 u32 *p; 608 u32 *p;
610 int err; 609 int err;
@@ -623,7 +622,6 @@ int objlayout_get_deviceinfo(struct pnfs_layout_hdr *pnfslay,
623 pd.pglen = PAGE_SIZE; 622 pd.pglen = PAGE_SIZE;
624 pd.mincount = 0; 623 pd.mincount = 0;
625 624
626 sb = pnfslay->plh_inode->i_sb;
627 err = nfs4_proc_getdeviceinfo(NFS_SERVER(pnfslay->plh_inode), &pd); 625 err = nfs4_proc_getdeviceinfo(NFS_SERVER(pnfslay->plh_inode), &pd);
628 dprintk("%s nfs_getdeviceinfo returned %d\n", __func__, err); 626 dprintk("%s nfs_getdeviceinfo returned %d\n", __func__, err);
629 if (err) 627 if (err)
diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c
index b5d451586943..38512bcd2e98 100644
--- a/fs/nfs/pnfs.c
+++ b/fs/nfs/pnfs.c
@@ -587,7 +587,7 @@ send_layoutget(struct pnfs_layout_hdr *lo,
587 587
588 /* allocate pages for xdr post processing */ 588 /* allocate pages for xdr post processing */
589 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; 589 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz;
590 max_pages = max_resp_sz >> PAGE_SHIFT; 590 max_pages = nfs_page_array_len(0, max_resp_sz);
591 591
592 pages = kcalloc(max_pages, sizeof(struct page *), gfp_flags); 592 pages = kcalloc(max_pages, sizeof(struct page *), gfp_flags);
593 if (!pages) 593 if (!pages)
diff --git a/fs/nfs/read.c b/fs/nfs/read.c
index 9a0e8ef4a409..0a4be28c2ea3 100644
--- a/fs/nfs/read.c
+++ b/fs/nfs/read.c
@@ -322,7 +322,7 @@ out_bad:
322 while (!list_empty(res)) { 322 while (!list_empty(res)) {
323 data = list_entry(res->next, struct nfs_read_data, list); 323 data = list_entry(res->next, struct nfs_read_data, list);
324 list_del(&data->list); 324 list_del(&data->list);
325 nfs_readdata_free(data); 325 nfs_readdata_release(data);
326 } 326 }
327 nfs_readpage_release(req); 327 nfs_readpage_release(req);
328 return -ENOMEM; 328 return -ENOMEM;
diff --git a/fs/nfs/super.c b/fs/nfs/super.c
index 37412f706b32..4ac7fca7e4bf 100644
--- a/fs/nfs/super.c
+++ b/fs/nfs/super.c
@@ -2428,7 +2428,7 @@ nfs_xdev_mount(struct file_system_type *fs_type, int flags,
2428 dprintk("--> nfs_xdev_mount()\n"); 2428 dprintk("--> nfs_xdev_mount()\n");
2429 2429
2430 /* create a new volume representation */ 2430 /* create a new volume representation */
2431 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr); 2431 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr, data->authflavor);
2432 if (IS_ERR(server)) { 2432 if (IS_ERR(server)) {
2433 error = PTR_ERR(server); 2433 error = PTR_ERR(server);
2434 goto out_err_noserver; 2434 goto out_err_noserver;
@@ -2767,11 +2767,15 @@ static struct vfsmount *nfs_do_root_mount(struct file_system_type *fs_type,
2767 char *root_devname; 2767 char *root_devname;
2768 size_t len; 2768 size_t len;
2769 2769
2770 len = strlen(hostname) + 3; 2770 len = strlen(hostname) + 5;
2771 root_devname = kmalloc(len, GFP_KERNEL); 2771 root_devname = kmalloc(len, GFP_KERNEL);
2772 if (root_devname == NULL) 2772 if (root_devname == NULL)
2773 return ERR_PTR(-ENOMEM); 2773 return ERR_PTR(-ENOMEM);
2774 snprintf(root_devname, len, "%s:/", hostname); 2774 /* Does hostname needs to be enclosed in brackets? */
2775 if (strchr(hostname, ':'))
2776 snprintf(root_devname, len, "[%s]:/", hostname);
2777 else
2778 snprintf(root_devname, len, "%s:/", hostname);
2775 root_mnt = vfs_kern_mount(fs_type, flags, root_devname, data); 2779 root_mnt = vfs_kern_mount(fs_type, flags, root_devname, data);
2776 kfree(root_devname); 2780 kfree(root_devname);
2777 return root_mnt; 2781 return root_mnt;
@@ -2951,7 +2955,7 @@ nfs4_xdev_mount(struct file_system_type *fs_type, int flags,
2951 dprintk("--> nfs4_xdev_mount()\n"); 2955 dprintk("--> nfs4_xdev_mount()\n");
2952 2956
2953 /* create a new volume representation */ 2957 /* create a new volume representation */
2954 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr); 2958 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr, data->authflavor);
2955 if (IS_ERR(server)) { 2959 if (IS_ERR(server)) {
2956 error = PTR_ERR(server); 2960 error = PTR_ERR(server);
2957 goto out_err_noserver; 2961 goto out_err_noserver;
diff --git a/fs/nfs/write.c b/fs/nfs/write.c
index 2c68818f68ac..c07462320f6b 100644
--- a/fs/nfs/write.c
+++ b/fs/nfs/write.c
@@ -682,7 +682,8 @@ static struct nfs_page *nfs_try_to_update_request(struct inode *inode,
682 req->wb_bytes = rqend - req->wb_offset; 682 req->wb_bytes = rqend - req->wb_offset;
683out_unlock: 683out_unlock:
684 spin_unlock(&inode->i_lock); 684 spin_unlock(&inode->i_lock);
685 nfs_clear_request_commit(req); 685 if (req)
686 nfs_clear_request_commit(req);
686 return req; 687 return req;
687out_flushme: 688out_flushme:
688 spin_unlock(&inode->i_lock); 689 spin_unlock(&inode->i_lock);
@@ -1018,7 +1019,7 @@ out_bad:
1018 while (!list_empty(res)) { 1019 while (!list_empty(res)) {
1019 data = list_entry(res->next, struct nfs_write_data, list); 1020 data = list_entry(res->next, struct nfs_write_data, list);
1020 list_del(&data->list); 1021 list_del(&data->list);
1021 nfs_writedata_free(data); 1022 nfs_writedata_release(data);
1022 } 1023 }
1023 nfs_redirty_request(req); 1024 nfs_redirty_request(req);
1024 return -ENOMEM; 1025 return -ENOMEM;
diff --git a/fs/nfsd/nfs3xdr.c b/fs/nfsd/nfs3xdr.c
index 08c6e36ab2eb..43f46cd9edea 100644
--- a/fs/nfsd/nfs3xdr.c
+++ b/fs/nfsd/nfs3xdr.c
@@ -803,13 +803,13 @@ encode_entry_baggage(struct nfsd3_readdirres *cd, __be32 *p, const char *name,
803 return p; 803 return p;
804} 804}
805 805
806static int 806static __be32
807compose_entry_fh(struct nfsd3_readdirres *cd, struct svc_fh *fhp, 807compose_entry_fh(struct nfsd3_readdirres *cd, struct svc_fh *fhp,
808 const char *name, int namlen) 808 const char *name, int namlen)
809{ 809{
810 struct svc_export *exp; 810 struct svc_export *exp;
811 struct dentry *dparent, *dchild; 811 struct dentry *dparent, *dchild;
812 int rv = 0; 812 __be32 rv = nfserr_noent;
813 813
814 dparent = cd->fh.fh_dentry; 814 dparent = cd->fh.fh_dentry;
815 exp = cd->fh.fh_export; 815 exp = cd->fh.fh_export;
@@ -817,26 +817,20 @@ compose_entry_fh(struct nfsd3_readdirres *cd, struct svc_fh *fhp,
817 if (isdotent(name, namlen)) { 817 if (isdotent(name, namlen)) {
818 if (namlen == 2) { 818 if (namlen == 2) {
819 dchild = dget_parent(dparent); 819 dchild = dget_parent(dparent);
820 if (dchild == dparent) { 820 /* filesystem root - cannot return filehandle for ".." */
821 /* filesystem root - cannot return filehandle for ".." */ 821 if (dchild == dparent)
822 dput(dchild); 822 goto out;
823 return -ENOENT;
824 }
825 } else 823 } else
826 dchild = dget(dparent); 824 dchild = dget(dparent);
827 } else 825 } else
828 dchild = lookup_one_len(name, dparent, namlen); 826 dchild = lookup_one_len(name, dparent, namlen);
829 if (IS_ERR(dchild)) 827 if (IS_ERR(dchild))
830 return -ENOENT; 828 return rv;
831 rv = -ENOENT;
832 if (d_mountpoint(dchild)) 829 if (d_mountpoint(dchild))
833 goto out; 830 goto out;
834 rv = fh_compose(fhp, exp, dchild, &cd->fh);
835 if (rv)
836 goto out;
837 if (!dchild->d_inode) 831 if (!dchild->d_inode)
838 goto out; 832 goto out;
839 rv = 0; 833 rv = fh_compose(fhp, exp, dchild, &cd->fh);
840out: 834out:
841 dput(dchild); 835 dput(dchild);
842 return rv; 836 return rv;
@@ -845,7 +839,7 @@ out:
845static __be32 *encode_entryplus_baggage(struct nfsd3_readdirres *cd, __be32 *p, const char *name, int namlen) 839static __be32 *encode_entryplus_baggage(struct nfsd3_readdirres *cd, __be32 *p, const char *name, int namlen)
846{ 840{
847 struct svc_fh fh; 841 struct svc_fh fh;
848 int err; 842 __be32 err;
849 843
850 fh_init(&fh, NFS3_FHSIZE); 844 fh_init(&fh, NFS3_FHSIZE);
851 err = compose_entry_fh(cd, &fh, name, namlen); 845 err = compose_entry_fh(cd, &fh, name, namlen);
diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
index 2ed14dfd00a2..987e719fbae8 100644
--- a/fs/nfsd/nfs4proc.c
+++ b/fs/nfsd/nfs4proc.c
@@ -235,17 +235,17 @@ do_open_lookup(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_o
235 */ 235 */
236 if (open->op_createmode == NFS4_CREATE_EXCLUSIVE && status == 0) 236 if (open->op_createmode == NFS4_CREATE_EXCLUSIVE && status == 0)
237 open->op_bmval[1] = (FATTR4_WORD1_TIME_ACCESS | 237 open->op_bmval[1] = (FATTR4_WORD1_TIME_ACCESS |
238 FATTR4_WORD1_TIME_MODIFY); 238 FATTR4_WORD1_TIME_MODIFY);
239 } else { 239 } else {
240 status = nfsd_lookup(rqstp, current_fh, 240 status = nfsd_lookup(rqstp, current_fh,
241 open->op_fname.data, open->op_fname.len, resfh); 241 open->op_fname.data, open->op_fname.len, resfh);
242 fh_unlock(current_fh); 242 fh_unlock(current_fh);
243 if (status)
244 goto out;
245 status = nfsd_check_obj_isreg(resfh);
246 } 243 }
247 if (status) 244 if (status)
248 goto out; 245 goto out;
246 status = nfsd_check_obj_isreg(resfh);
247 if (status)
248 goto out;
249 249
250 if (is_create_with_attrs(open) && open->op_acl != NULL) 250 if (is_create_with_attrs(open) && open->op_acl != NULL)
251 do_set_nfs4_acl(rqstp, resfh, open->op_acl, open->op_bmval); 251 do_set_nfs4_acl(rqstp, resfh, open->op_acl, open->op_bmval);
@@ -841,6 +841,7 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
841 struct nfsd4_setattr *setattr) 841 struct nfsd4_setattr *setattr)
842{ 842{
843 __be32 status = nfs_ok; 843 __be32 status = nfs_ok;
844 int err;
844 845
845 if (setattr->sa_iattr.ia_valid & ATTR_SIZE) { 846 if (setattr->sa_iattr.ia_valid & ATTR_SIZE) {
846 nfs4_lock_state(); 847 nfs4_lock_state();
@@ -852,9 +853,9 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
852 return status; 853 return status;
853 } 854 }
854 } 855 }
855 status = fh_want_write(&cstate->current_fh); 856 err = fh_want_write(&cstate->current_fh);
856 if (status) 857 if (err)
857 return status; 858 return nfserrno(err);
858 status = nfs_ok; 859 status = nfs_ok;
859 860
860 status = check_attr_support(rqstp, cstate, setattr->sa_bmval, 861 status = check_attr_support(rqstp, cstate, setattr->sa_bmval,
diff --git a/fs/nfsd/nfs4recover.c b/fs/nfsd/nfs4recover.c
index 4767429264a2..ed3f9206a0ee 100644
--- a/fs/nfsd/nfs4recover.c
+++ b/fs/nfsd/nfs4recover.c
@@ -577,7 +577,7 @@ cld_pipe_downcall(struct file *filp, const char __user *src, size_t mlen)
577 struct cld_net *cn = nn->cld_net; 577 struct cld_net *cn = nn->cld_net;
578 578
579 if (mlen != sizeof(*cmsg)) { 579 if (mlen != sizeof(*cmsg)) {
580 dprintk("%s: got %lu bytes, expected %lu\n", __func__, mlen, 580 dprintk("%s: got %zu bytes, expected %zu\n", __func__, mlen,
581 sizeof(*cmsg)); 581 sizeof(*cmsg));
582 return -EINVAL; 582 return -EINVAL;
583 } 583 }
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 1841f8bf845e..7f71c69cdcdf 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -4211,16 +4211,14 @@ out:
4211 * vfs_test_lock. (Arguably perhaps test_lock should be done with an 4211 * vfs_test_lock. (Arguably perhaps test_lock should be done with an
4212 * inode operation.) 4212 * inode operation.)
4213 */ 4213 */
4214static int nfsd_test_lock(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file_lock *lock) 4214static __be32 nfsd_test_lock(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file_lock *lock)
4215{ 4215{
4216 struct file *file; 4216 struct file *file;
4217 int err; 4217 __be32 err = nfsd_open(rqstp, fhp, S_IFREG, NFSD_MAY_READ, &file);
4218 4218 if (!err) {
4219 err = nfsd_open(rqstp, fhp, S_IFREG, NFSD_MAY_READ, &file); 4219 err = nfserrno(vfs_test_lock(file, lock));
4220 if (err) 4220 nfsd_close(file);
4221 return err; 4221 }
4222 err = vfs_test_lock(file, lock);
4223 nfsd_close(file);
4224 return err; 4222 return err;
4225} 4223}
4226 4224
@@ -4234,7 +4232,6 @@ nfsd4_lockt(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
4234 struct inode *inode; 4232 struct inode *inode;
4235 struct file_lock file_lock; 4233 struct file_lock file_lock;
4236 struct nfs4_lockowner *lo; 4234 struct nfs4_lockowner *lo;
4237 int error;
4238 __be32 status; 4235 __be32 status;
4239 4236
4240 if (locks_in_grace()) 4237 if (locks_in_grace())
@@ -4280,12 +4277,10 @@ nfsd4_lockt(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
4280 4277
4281 nfs4_transform_lock_offset(&file_lock); 4278 nfs4_transform_lock_offset(&file_lock);
4282 4279
4283 status = nfs_ok; 4280 status = nfsd_test_lock(rqstp, &cstate->current_fh, &file_lock);
4284 error = nfsd_test_lock(rqstp, &cstate->current_fh, &file_lock); 4281 if (status)
4285 if (error) {
4286 status = nfserrno(error);
4287 goto out; 4282 goto out;
4288 } 4283
4289 if (file_lock.fl_type != F_UNLCK) { 4284 if (file_lock.fl_type != F_UNLCK) {
4290 status = nfserr_denied; 4285 status = nfserr_denied;
4291 nfs4_set_lock_denied(&file_lock, &lockt->lt_denied); 4286 nfs4_set_lock_denied(&file_lock, &lockt->lt_denied);
diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index bcd8904ab1e3..74c00bc92b9a 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -1392,7 +1392,7 @@ nfsd4_decode_test_stateid(struct nfsd4_compoundargs *argp, struct nfsd4_test_sta
1392 for (i = 0; i < test_stateid->ts_num_ids; i++) { 1392 for (i = 0; i < test_stateid->ts_num_ids; i++) {
1393 stateid = kmalloc(sizeof(struct nfsd4_test_stateid_id), GFP_KERNEL); 1393 stateid = kmalloc(sizeof(struct nfsd4_test_stateid_id), GFP_KERNEL);
1394 if (!stateid) { 1394 if (!stateid) {
1395 status = PTR_ERR(stateid); 1395 status = nfserrno(-ENOMEM);
1396 goto out; 1396 goto out;
1397 } 1397 }
1398 1398
@@ -3410,7 +3410,7 @@ nfsd4_encode_test_stateid(struct nfsd4_compoundres *resp, int nfserr,
3410 *p++ = htonl(test_stateid->ts_num_ids); 3410 *p++ = htonl(test_stateid->ts_num_ids);
3411 3411
3412 list_for_each_entry_safe(stateid, next, &test_stateid->ts_stateid_list, ts_id_list) { 3412 list_for_each_entry_safe(stateid, next, &test_stateid->ts_stateid_list, ts_id_list) {
3413 *p++ = htonl(stateid->ts_id_status); 3413 *p++ = stateid->ts_id_status;
3414 } 3414 }
3415 3415
3416 ADJUST_ARGS(); 3416 ADJUST_ARGS();
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index 296d671654d6..568666156ea4 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -1458,7 +1458,7 @@ do_nfsd_create(struct svc_rqst *rqstp, struct svc_fh *fhp,
1458 switch (createmode) { 1458 switch (createmode) {
1459 case NFS3_CREATE_UNCHECKED: 1459 case NFS3_CREATE_UNCHECKED:
1460 if (! S_ISREG(dchild->d_inode->i_mode)) 1460 if (! S_ISREG(dchild->d_inode->i_mode))
1461 err = nfserr_exist; 1461 goto out;
1462 else if (truncp) { 1462 else if (truncp) {
1463 /* in nfsv4, we need to treat this case a little 1463 /* in nfsv4, we need to treat this case a little
1464 * differently. we don't want to truncate the 1464 * differently. we don't want to truncate the
diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c
index 3165aebb43c8..31b9463fba1f 100644
--- a/fs/ocfs2/alloc.c
+++ b/fs/ocfs2/alloc.c
@@ -1134,7 +1134,7 @@ static int ocfs2_adjust_rightmost_branch(handle_t *handle,
1134 } 1134 }
1135 1135
1136 el = path_leaf_el(path); 1136 el = path_leaf_el(path);
1137 rec = &el->l_recs[le32_to_cpu(el->l_next_free_rec) - 1]; 1137 rec = &el->l_recs[le16_to_cpu(el->l_next_free_rec) - 1];
1138 1138
1139 ocfs2_adjust_rightmost_records(handle, et, path, rec); 1139 ocfs2_adjust_rightmost_records(handle, et, path, rec);
1140 1140
diff --git a/fs/ocfs2/refcounttree.c b/fs/ocfs2/refcounttree.c
index cf7823382664..9f32d7cbb7a3 100644
--- a/fs/ocfs2/refcounttree.c
+++ b/fs/ocfs2/refcounttree.c
@@ -1036,14 +1036,14 @@ static int ocfs2_get_refcount_cpos_end(struct ocfs2_caching_info *ci,
1036 1036
1037 tmp_el = left_path->p_node[subtree_root].el; 1037 tmp_el = left_path->p_node[subtree_root].el;
1038 blkno = left_path->p_node[subtree_root+1].bh->b_blocknr; 1038 blkno = left_path->p_node[subtree_root+1].bh->b_blocknr;
1039 for (i = 0; i < le32_to_cpu(tmp_el->l_next_free_rec); i++) { 1039 for (i = 0; i < le16_to_cpu(tmp_el->l_next_free_rec); i++) {
1040 if (le64_to_cpu(tmp_el->l_recs[i].e_blkno) == blkno) { 1040 if (le64_to_cpu(tmp_el->l_recs[i].e_blkno) == blkno) {
1041 *cpos_end = le32_to_cpu(tmp_el->l_recs[i+1].e_cpos); 1041 *cpos_end = le32_to_cpu(tmp_el->l_recs[i+1].e_cpos);
1042 break; 1042 break;
1043 } 1043 }
1044 } 1044 }
1045 1045
1046 BUG_ON(i == le32_to_cpu(tmp_el->l_next_free_rec)); 1046 BUG_ON(i == le16_to_cpu(tmp_el->l_next_free_rec));
1047 1047
1048out: 1048out:
1049 ocfs2_free_path(left_path); 1049 ocfs2_free_path(left_path);
@@ -1468,7 +1468,7 @@ static int ocfs2_divide_leaf_refcount_block(struct buffer_head *ref_leaf_bh,
1468 1468
1469 trace_ocfs2_divide_leaf_refcount_block( 1469 trace_ocfs2_divide_leaf_refcount_block(
1470 (unsigned long long)ref_leaf_bh->b_blocknr, 1470 (unsigned long long)ref_leaf_bh->b_blocknr,
1471 le32_to_cpu(rl->rl_count), le32_to_cpu(rl->rl_used)); 1471 le16_to_cpu(rl->rl_count), le16_to_cpu(rl->rl_used));
1472 1472
1473 /* 1473 /*
1474 * XXX: Improvement later. 1474 * XXX: Improvement later.
@@ -2411,7 +2411,7 @@ static int ocfs2_calc_refcount_meta_credits(struct super_block *sb,
2411 rb = (struct ocfs2_refcount_block *) 2411 rb = (struct ocfs2_refcount_block *)
2412 prev_bh->b_data; 2412 prev_bh->b_data;
2413 2413
2414 if (le64_to_cpu(rb->rf_records.rl_used) + 2414 if (le16_to_cpu(rb->rf_records.rl_used) +
2415 recs_add > 2415 recs_add >
2416 le16_to_cpu(rb->rf_records.rl_count)) 2416 le16_to_cpu(rb->rf_records.rl_count))
2417 ref_blocks++; 2417 ref_blocks++;
@@ -2476,7 +2476,7 @@ static int ocfs2_calc_refcount_meta_credits(struct super_block *sb,
2476 if (prev_bh) { 2476 if (prev_bh) {
2477 rb = (struct ocfs2_refcount_block *)prev_bh->b_data; 2477 rb = (struct ocfs2_refcount_block *)prev_bh->b_data;
2478 2478
2479 if (le64_to_cpu(rb->rf_records.rl_used) + recs_add > 2479 if (le16_to_cpu(rb->rf_records.rl_used) + recs_add >
2480 le16_to_cpu(rb->rf_records.rl_count)) 2480 le16_to_cpu(rb->rf_records.rl_count))
2481 ref_blocks++; 2481 ref_blocks++;
2482 2482
@@ -3629,7 +3629,7 @@ int ocfs2_refcounted_xattr_delete_need(struct inode *inode,
3629 * one will split a refcount rec, so totally we need 3629 * one will split a refcount rec, so totally we need
3630 * clusters * 2 new refcount rec. 3630 * clusters * 2 new refcount rec.
3631 */ 3631 */
3632 if (le64_to_cpu(rb->rf_records.rl_used) + clusters * 2 > 3632 if (le16_to_cpu(rb->rf_records.rl_used) + clusters * 2 >
3633 le16_to_cpu(rb->rf_records.rl_count)) 3633 le16_to_cpu(rb->rf_records.rl_count))
3634 ref_blocks++; 3634 ref_blocks++;
3635 3635
diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
index ba5d97e4a73e..f169da4624fd 100644
--- a/fs/ocfs2/suballoc.c
+++ b/fs/ocfs2/suballoc.c
@@ -600,7 +600,7 @@ static void ocfs2_bg_alloc_cleanup(handle_t *handle,
600 ret = ocfs2_free_clusters(handle, cluster_ac->ac_inode, 600 ret = ocfs2_free_clusters(handle, cluster_ac->ac_inode,
601 cluster_ac->ac_bh, 601 cluster_ac->ac_bh,
602 le64_to_cpu(rec->e_blkno), 602 le64_to_cpu(rec->e_blkno),
603 le32_to_cpu(rec->e_leaf_clusters)); 603 le16_to_cpu(rec->e_leaf_clusters));
604 if (ret) 604 if (ret)
605 mlog_errno(ret); 605 mlog_errno(ret);
606 /* Try all the clusters to free */ 606 /* Try all the clusters to free */
@@ -1628,7 +1628,7 @@ static int ocfs2_bg_discontig_fix_by_rec(struct ocfs2_suballoc_result *res,
1628{ 1628{
1629 unsigned int bpc = le16_to_cpu(cl->cl_bpc); 1629 unsigned int bpc = le16_to_cpu(cl->cl_bpc);
1630 unsigned int bitoff = le32_to_cpu(rec->e_cpos) * bpc; 1630 unsigned int bitoff = le32_to_cpu(rec->e_cpos) * bpc;
1631 unsigned int bitcount = le32_to_cpu(rec->e_leaf_clusters) * bpc; 1631 unsigned int bitcount = le16_to_cpu(rec->e_leaf_clusters) * bpc;
1632 1632
1633 if (res->sr_bit_offset < bitoff) 1633 if (res->sr_bit_offset < bitoff)
1634 return 0; 1634 return 0;
diff --git a/fs/pipe.c b/fs/pipe.c
index 25feaa3faac0..fec5e4ad071a 100644
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -346,6 +346,16 @@ static const struct pipe_buf_operations anon_pipe_buf_ops = {
346 .get = generic_pipe_buf_get, 346 .get = generic_pipe_buf_get,
347}; 347};
348 348
349static const struct pipe_buf_operations packet_pipe_buf_ops = {
350 .can_merge = 0,
351 .map = generic_pipe_buf_map,
352 .unmap = generic_pipe_buf_unmap,
353 .confirm = generic_pipe_buf_confirm,
354 .release = anon_pipe_buf_release,
355 .steal = generic_pipe_buf_steal,
356 .get = generic_pipe_buf_get,
357};
358
349static ssize_t 359static ssize_t
350pipe_read(struct kiocb *iocb, const struct iovec *_iov, 360pipe_read(struct kiocb *iocb, const struct iovec *_iov,
351 unsigned long nr_segs, loff_t pos) 361 unsigned long nr_segs, loff_t pos)
@@ -407,6 +417,13 @@ redo:
407 ret += chars; 417 ret += chars;
408 buf->offset += chars; 418 buf->offset += chars;
409 buf->len -= chars; 419 buf->len -= chars;
420
421 /* Was it a packet buffer? Clean up and exit */
422 if (buf->flags & PIPE_BUF_FLAG_PACKET) {
423 total_len = chars;
424 buf->len = 0;
425 }
426
410 if (!buf->len) { 427 if (!buf->len) {
411 buf->ops = NULL; 428 buf->ops = NULL;
412 ops->release(pipe, buf); 429 ops->release(pipe, buf);
@@ -459,6 +476,11 @@ redo:
459 return ret; 476 return ret;
460} 477}
461 478
479static inline int is_packetized(struct file *file)
480{
481 return (file->f_flags & O_DIRECT) != 0;
482}
483
462static ssize_t 484static ssize_t
463pipe_write(struct kiocb *iocb, const struct iovec *_iov, 485pipe_write(struct kiocb *iocb, const struct iovec *_iov,
464 unsigned long nr_segs, loff_t ppos) 486 unsigned long nr_segs, loff_t ppos)
@@ -593,6 +615,11 @@ redo2:
593 buf->ops = &anon_pipe_buf_ops; 615 buf->ops = &anon_pipe_buf_ops;
594 buf->offset = 0; 616 buf->offset = 0;
595 buf->len = chars; 617 buf->len = chars;
618 buf->flags = 0;
619 if (is_packetized(filp)) {
620 buf->ops = &packet_pipe_buf_ops;
621 buf->flags = PIPE_BUF_FLAG_PACKET;
622 }
596 pipe->nrbufs = ++bufs; 623 pipe->nrbufs = ++bufs;
597 pipe->tmp_page = NULL; 624 pipe->tmp_page = NULL;
598 625
@@ -1013,7 +1040,7 @@ struct file *create_write_pipe(int flags)
1013 goto err_dentry; 1040 goto err_dentry;
1014 f->f_mapping = inode->i_mapping; 1041 f->f_mapping = inode->i_mapping;
1015 1042
1016 f->f_flags = O_WRONLY | (flags & O_NONBLOCK); 1043 f->f_flags = O_WRONLY | (flags & (O_NONBLOCK | O_DIRECT));
1017 f->f_version = 0; 1044 f->f_version = 0;
1018 1045
1019 return f; 1046 return f;
@@ -1057,7 +1084,7 @@ int do_pipe_flags(int *fd, int flags)
1057 int error; 1084 int error;
1058 int fdw, fdr; 1085 int fdw, fdr;
1059 1086
1060 if (flags & ~(O_CLOEXEC | O_NONBLOCK)) 1087 if (flags & ~(O_CLOEXEC | O_NONBLOCK | O_DIRECT))
1061 return -EINVAL; 1088 return -EINVAL;
1062 1089
1063 fw = create_write_pipe(flags); 1090 fw = create_write_pipe(flags);
diff --git a/fs/proc/root.c b/fs/proc/root.c
index 46a15d8a29ca..eed44bfc85db 100644
--- a/fs/proc/root.c
+++ b/fs/proc/root.c
@@ -115,12 +115,13 @@ static struct dentry *proc_mount(struct file_system_type *fs_type,
115 if (IS_ERR(sb)) 115 if (IS_ERR(sb))
116 return ERR_CAST(sb); 116 return ERR_CAST(sb);
117 117
118 if (!proc_parse_options(options, ns)) {
119 deactivate_locked_super(sb);
120 return ERR_PTR(-EINVAL);
121 }
122
118 if (!sb->s_root) { 123 if (!sb->s_root) {
119 sb->s_flags = flags; 124 sb->s_flags = flags;
120 if (!proc_parse_options(options, ns)) {
121 deactivate_locked_super(sb);
122 return ERR_PTR(-EINVAL);
123 }
124 err = proc_fill_super(sb); 125 err = proc_fill_super(sb);
125 if (err) { 126 if (err) {
126 deactivate_locked_super(sb); 127 deactivate_locked_super(sb);
diff --git a/fs/proc/stat.c b/fs/proc/stat.c
index 6a0c62d6e442..64c3b3172367 100644
--- a/fs/proc/stat.c
+++ b/fs/proc/stat.c
@@ -18,19 +18,39 @@
18#ifndef arch_irq_stat 18#ifndef arch_irq_stat
19#define arch_irq_stat() 0 19#define arch_irq_stat() 0
20#endif 20#endif
21#ifndef arch_idle_time 21
22#define arch_idle_time(cpu) 0 22#ifdef arch_idle_time
23#endif 23
24static cputime64_t get_idle_time(int cpu)
25{
26 cputime64_t idle;
27
28 idle = kcpustat_cpu(cpu).cpustat[CPUTIME_IDLE];
29 if (cpu_online(cpu) && !nr_iowait_cpu(cpu))
30 idle += arch_idle_time(cpu);
31 return idle;
32}
33
34static cputime64_t get_iowait_time(int cpu)
35{
36 cputime64_t iowait;
37
38 iowait = kcpustat_cpu(cpu).cpustat[CPUTIME_IOWAIT];
39 if (cpu_online(cpu) && nr_iowait_cpu(cpu))
40 iowait += arch_idle_time(cpu);
41 return iowait;
42}
43
44#else
24 45
25static u64 get_idle_time(int cpu) 46static u64 get_idle_time(int cpu)
26{ 47{
27 u64 idle, idle_time = get_cpu_idle_time_us(cpu, NULL); 48 u64 idle, idle_time = get_cpu_idle_time_us(cpu, NULL);
28 49
29 if (idle_time == -1ULL) { 50 if (idle_time == -1ULL)
30 /* !NO_HZ so we can rely on cpustat.idle */ 51 /* !NO_HZ so we can rely on cpustat.idle */
31 idle = kcpustat_cpu(cpu).cpustat[CPUTIME_IDLE]; 52 idle = kcpustat_cpu(cpu).cpustat[CPUTIME_IDLE];
32 idle += arch_idle_time(cpu); 53 else
33 } else
34 idle = usecs_to_cputime64(idle_time); 54 idle = usecs_to_cputime64(idle_time);
35 55
36 return idle; 56 return idle;
@@ -49,6 +69,8 @@ static u64 get_iowait_time(int cpu)
49 return iowait; 69 return iowait;
50} 70}
51 71
72#endif
73
52static int show_stat(struct seq_file *p, void *v) 74static int show_stat(struct seq_file *p, void *v)
53{ 75{
54 int i, j; 76 int i, j;
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 2b9a7607cbd5..1030a716d155 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -597,9 +597,6 @@ static int clear_refs_pte_range(pmd_t *pmd, unsigned long addr,
597 if (!page) 597 if (!page)
598 continue; 598 continue;
599 599
600 if (PageReserved(page))
601 continue;
602
603 /* Clear accessed and referenced bits. */ 600 /* Clear accessed and referenced bits. */
604 ptep_test_and_clear_young(vma, addr, pte); 601 ptep_test_and_clear_young(vma, addr, pte);
605 ClearPageReferenced(page); 602 ClearPageReferenced(page);
@@ -750,6 +747,8 @@ static void pte_to_pagemap_entry(pagemap_entry_t *pme, pte_t pte)
750 else if (pte_present(pte)) 747 else if (pte_present(pte))
751 *pme = make_pme(PM_PFRAME(pte_pfn(pte)) 748 *pme = make_pme(PM_PFRAME(pte_pfn(pte))
752 | PM_PSHIFT(PAGE_SHIFT) | PM_PRESENT); 749 | PM_PSHIFT(PAGE_SHIFT) | PM_PRESENT);
750 else
751 *pme = make_pme(PM_NOT_PRESENT);
753} 752}
754 753
755#ifdef CONFIG_TRANSPARENT_HUGEPAGE 754#ifdef CONFIG_TRANSPARENT_HUGEPAGE
@@ -764,6 +763,8 @@ static void thp_pmd_to_pagemap_entry(pagemap_entry_t *pme,
764 if (pmd_present(pmd)) 763 if (pmd_present(pmd))
765 *pme = make_pme(PM_PFRAME(pmd_pfn(pmd) + offset) 764 *pme = make_pme(PM_PFRAME(pmd_pfn(pmd) + offset)
766 | PM_PSHIFT(PAGE_SHIFT) | PM_PRESENT); 765 | PM_PSHIFT(PAGE_SHIFT) | PM_PRESENT);
766 else
767 *pme = make_pme(PM_NOT_PRESENT);
767} 768}
768#else 769#else
769static inline void thp_pmd_to_pagemap_entry(pagemap_entry_t *pme, 770static inline void thp_pmd_to_pagemap_entry(pagemap_entry_t *pme,
@@ -804,8 +805,10 @@ static int pagemap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,
804 805
805 /* check to see if we've left 'vma' behind 806 /* check to see if we've left 'vma' behind
806 * and need a new, higher one */ 807 * and need a new, higher one */
807 if (vma && (addr >= vma->vm_end)) 808 if (vma && (addr >= vma->vm_end)) {
808 vma = find_vma(walk->mm, addr); 809 vma = find_vma(walk->mm, addr);
810 pme = make_pme(PM_NOT_PRESENT);
811 }
809 812
810 /* check that 'vma' actually covers this address, 813 /* check that 'vma' actually covers this address,
811 * and that it isn't a huge page vma */ 814 * and that it isn't a huge page vma */
@@ -833,6 +836,8 @@ static void huge_pte_to_pagemap_entry(pagemap_entry_t *pme,
833 if (pte_present(pte)) 836 if (pte_present(pte))
834 *pme = make_pme(PM_PFRAME(pte_pfn(pte) + offset) 837 *pme = make_pme(PM_PFRAME(pte_pfn(pte) + offset)
835 | PM_PSHIFT(PAGE_SHIFT) | PM_PRESENT); 838 | PM_PSHIFT(PAGE_SHIFT) | PM_PRESENT);
839 else
840 *pme = make_pme(PM_NOT_PRESENT);
836} 841}
837 842
838/* This function walks within one hugetlb entry in the single call */ 843/* This function walks within one hugetlb entry in the single call */
@@ -842,7 +847,7 @@ static int pagemap_hugetlb_range(pte_t *pte, unsigned long hmask,
842{ 847{
843 struct pagemapread *pm = walk->private; 848 struct pagemapread *pm = walk->private;
844 int err = 0; 849 int err = 0;
845 pagemap_entry_t pme = make_pme(PM_NOT_PRESENT); 850 pagemap_entry_t pme;
846 851
847 for (; addr != end; addr += PAGE_SIZE) { 852 for (; addr != end; addr += PAGE_SIZE) {
848 int offset = (addr & ~hmask) >> PAGE_SHIFT; 853 int offset = (addr & ~hmask) >> PAGE_SHIFT;
diff --git a/fs/pstore/inode.c b/fs/pstore/inode.c
index 50952c9bd06c..19507889bb7f 100644
--- a/fs/pstore/inode.c
+++ b/fs/pstore/inode.c
@@ -52,12 +52,6 @@ struct pstore_private {
52 char data[]; 52 char data[];
53}; 53};
54 54
55static int pstore_file_open(struct inode *inode, struct file *file)
56{
57 file->private_data = inode->i_private;
58 return 0;
59}
60
61static ssize_t pstore_file_read(struct file *file, char __user *userbuf, 55static ssize_t pstore_file_read(struct file *file, char __user *userbuf,
62 size_t count, loff_t *ppos) 56 size_t count, loff_t *ppos)
63{ 57{
@@ -67,7 +61,7 @@ static ssize_t pstore_file_read(struct file *file, char __user *userbuf,
67} 61}
68 62
69static const struct file_operations pstore_file_operations = { 63static const struct file_operations pstore_file_operations = {
70 .open = pstore_file_open, 64 .open = simple_open,
71 .read = pstore_file_read, 65 .read = pstore_file_read,
72 .llseek = default_llseek, 66 .llseek = default_llseek,
73}; 67};
diff --git a/fs/splice.c b/fs/splice.c
index 5f883de7ef3a..f8476841eb04 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -30,6 +30,7 @@
30#include <linux/uio.h> 30#include <linux/uio.h>
31#include <linux/security.h> 31#include <linux/security.h>
32#include <linux/gfp.h> 32#include <linux/gfp.h>
33#include <linux/socket.h>
33 34
34/* 35/*
35 * Attempt to steal a page from a pipe buffer. This should perhaps go into 36 * Attempt to steal a page from a pipe buffer. This should perhaps go into
@@ -690,7 +691,9 @@ static int pipe_to_sendpage(struct pipe_inode_info *pipe,
690 if (!likely(file->f_op && file->f_op->sendpage)) 691 if (!likely(file->f_op && file->f_op->sendpage))
691 return -EINVAL; 692 return -EINVAL;
692 693
693 more = (sd->flags & SPLICE_F_MORE) || sd->len < sd->total_len; 694 more = (sd->flags & SPLICE_F_MORE) ? MSG_MORE : 0;
695 if (sd->len < sd->total_len)
696 more |= MSG_SENDPAGE_NOTLAST;
694 return file->f_op->sendpage(file, buf->page, buf->offset, 697 return file->f_op->sendpage(file, buf->page, buf->offset,
695 sd->len, &pos, more); 698 sd->len, &pos, more);
696} 699}
diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
index 2a7a3f5d1ca6..35a36d39fa2c 100644
--- a/fs/sysfs/dir.c
+++ b/fs/sysfs/dir.c
@@ -729,6 +729,9 @@ int sysfs_create_dir(struct kobject * kobj)
729 else 729 else
730 parent_sd = &sysfs_root; 730 parent_sd = &sysfs_root;
731 731
732 if (!parent_sd)
733 return -ENOENT;
734
732 if (sysfs_ns_type(parent_sd)) 735 if (sysfs_ns_type(parent_sd))
733 ns = kobj->ktype->namespace(kobj); 736 ns = kobj->ktype->namespace(kobj);
734 type = sysfs_read_ns_type(kobj); 737 type = sysfs_read_ns_type(kobj);
@@ -878,7 +881,6 @@ int sysfs_rename(struct sysfs_dirent *sd,
878 881
879 dup_name = sd->s_name; 882 dup_name = sd->s_name;
880 sd->s_name = new_name; 883 sd->s_name = new_name;
881 sd->s_hash = sysfs_name_hash(sd->s_ns, sd->s_name);
882 } 884 }
883 885
884 /* Move to the appropriate place in the appropriate directories rbtree. */ 886 /* Move to the appropriate place in the appropriate directories rbtree. */
@@ -886,6 +888,7 @@ int sysfs_rename(struct sysfs_dirent *sd,
886 sysfs_get(new_parent_sd); 888 sysfs_get(new_parent_sd);
887 sysfs_put(sd->s_parent); 889 sysfs_put(sd->s_parent);
888 sd->s_ns = new_ns; 890 sd->s_ns = new_ns;
891 sd->s_hash = sysfs_name_hash(sd->s_ns, sd->s_name);
889 sd->s_parent = new_parent_sd; 892 sd->s_parent = new_parent_sd;
890 sysfs_link_sibling(sd); 893 sysfs_link_sibling(sd);
891 894
diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c
index dd1701caecc9..2df555c66d57 100644
--- a/fs/sysfs/group.c
+++ b/fs/sysfs/group.c
@@ -67,7 +67,11 @@ static int internal_create_group(struct kobject *kobj, int update,
67 /* Updates may happen before the object has been instantiated */ 67 /* Updates may happen before the object has been instantiated */
68 if (unlikely(update && !kobj->sd)) 68 if (unlikely(update && !kobj->sd))
69 return -EINVAL; 69 return -EINVAL;
70 70 if (!grp->attrs) {
71 WARN(1, "sysfs: attrs not set by subsystem for group: %s/%s\n",
72 kobj->name, grp->name ? "" : grp->name);
73 return -EINVAL;
74 }
71 if (grp->name) { 75 if (grp->name) {
72 error = sysfs_create_subdir(kobj, grp->name, &sd); 76 error = sysfs_create_subdir(kobj, grp->name, &sd);
73 if (error) 77 if (error)
diff --git a/fs/xattr.c b/fs/xattr.c
index d6dfd247bb2f..3c8c1cc333c7 100644
--- a/fs/xattr.c
+++ b/fs/xattr.c
@@ -19,8 +19,9 @@
19#include <linux/export.h> 19#include <linux/export.h>
20#include <linux/fsnotify.h> 20#include <linux/fsnotify.h>
21#include <linux/audit.h> 21#include <linux/audit.h>
22#include <asm/uaccess.h> 22#include <linux/vmalloc.h>
23 23
24#include <asm/uaccess.h>
24 25
25/* 26/*
26 * Check permissions for extended attribute access. This is a bit complicated 27 * Check permissions for extended attribute access. This is a bit complicated
@@ -320,6 +321,7 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
320{ 321{
321 int error; 322 int error;
322 void *kvalue = NULL; 323 void *kvalue = NULL;
324 void *vvalue = NULL; /* If non-NULL, we used vmalloc() */
323 char kname[XATTR_NAME_MAX + 1]; 325 char kname[XATTR_NAME_MAX + 1];
324 326
325 if (flags & ~(XATTR_CREATE|XATTR_REPLACE)) 327 if (flags & ~(XATTR_CREATE|XATTR_REPLACE))
@@ -334,13 +336,25 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
334 if (size) { 336 if (size) {
335 if (size > XATTR_SIZE_MAX) 337 if (size > XATTR_SIZE_MAX)
336 return -E2BIG; 338 return -E2BIG;
337 kvalue = memdup_user(value, size); 339 kvalue = kmalloc(size, GFP_KERNEL | __GFP_NOWARN);
338 if (IS_ERR(kvalue)) 340 if (!kvalue) {
339 return PTR_ERR(kvalue); 341 vvalue = vmalloc(size);
342 if (!vvalue)
343 return -ENOMEM;
344 kvalue = vvalue;
345 }
346 if (copy_from_user(kvalue, value, size)) {
347 error = -EFAULT;
348 goto out;
349 }
340 } 350 }
341 351
342 error = vfs_setxattr(d, kname, kvalue, size, flags); 352 error = vfs_setxattr(d, kname, kvalue, size, flags);
343 kfree(kvalue); 353out:
354 if (vvalue)
355 vfree(vvalue);
356 else
357 kfree(kvalue);
344 return error; 358 return error;
345} 359}
346 360
@@ -492,13 +506,18 @@ listxattr(struct dentry *d, char __user *list, size_t size)
492{ 506{
493 ssize_t error; 507 ssize_t error;
494 char *klist = NULL; 508 char *klist = NULL;
509 char *vlist = NULL; /* If non-NULL, we used vmalloc() */
495 510
496 if (size) { 511 if (size) {
497 if (size > XATTR_LIST_MAX) 512 if (size > XATTR_LIST_MAX)
498 size = XATTR_LIST_MAX; 513 size = XATTR_LIST_MAX;
499 klist = kmalloc(size, GFP_KERNEL); 514 klist = kmalloc(size, __GFP_NOWARN | GFP_KERNEL);
500 if (!klist) 515 if (!klist) {
501 return -ENOMEM; 516 vlist = vmalloc(size);
517 if (!vlist)
518 return -ENOMEM;
519 klist = vlist;
520 }
502 } 521 }
503 522
504 error = vfs_listxattr(d, klist, size); 523 error = vfs_listxattr(d, klist, size);
@@ -510,7 +529,10 @@ listxattr(struct dentry *d, char __user *list, size_t size)
510 than XATTR_LIST_MAX bytes. Not possible. */ 529 than XATTR_LIST_MAX bytes. Not possible. */
511 error = -E2BIG; 530 error = -E2BIG;
512 } 531 }
513 kfree(klist); 532 if (vlist)
533 vfree(vlist);
534 else
535 kfree(klist);
514 return error; 536 return error;
515} 537}
516 538
diff --git a/include/acpi/actypes.h b/include/acpi/actypes.h
index eba66043cf1b..e8bcc4742e0e 100644
--- a/include/acpi/actypes.h
+++ b/include/acpi/actypes.h
@@ -499,9 +499,10 @@ typedef u64 acpi_integer;
499#define ACPI_STATE_D0 (u8) 0 499#define ACPI_STATE_D0 (u8) 0
500#define ACPI_STATE_D1 (u8) 1 500#define ACPI_STATE_D1 (u8) 1
501#define ACPI_STATE_D2 (u8) 2 501#define ACPI_STATE_D2 (u8) 2
502#define ACPI_STATE_D3 (u8) 3 502#define ACPI_STATE_D3_HOT (u8) 3
503#define ACPI_STATE_D3_COLD (u8) 4 503#define ACPI_STATE_D3 (u8) 4
504#define ACPI_D_STATES_MAX ACPI_STATE_D3_COLD 504#define ACPI_STATE_D3_COLD ACPI_STATE_D3
505#define ACPI_D_STATES_MAX ACPI_STATE_D3
505#define ACPI_D_STATE_COUNT 5 506#define ACPI_D_STATE_COUNT 5
506 507
507#define ACPI_STATE_C0 (u8) 0 508#define ACPI_STATE_C0 (u8) 0
diff --git a/include/asm-generic/cmpxchg.h b/include/asm-generic/cmpxchg.h
index 8a361834dc25..14883026015d 100644
--- a/include/asm-generic/cmpxchg.h
+++ b/include/asm-generic/cmpxchg.h
@@ -10,6 +10,7 @@
10#error "Cannot use generic cmpxchg on SMP" 10#error "Cannot use generic cmpxchg on SMP"
11#endif 11#endif
12 12
13#include <linux/types.h>
13#include <linux/irqflags.h> 14#include <linux/irqflags.h>
14 15
15#ifndef xchg 16#ifndef xchg
diff --git a/include/asm-generic/siginfo.h b/include/asm-generic/siginfo.h
index 0dd4e87f6fba..5e5e3865f1ed 100644
--- a/include/asm-generic/siginfo.h
+++ b/include/asm-generic/siginfo.h
@@ -35,6 +35,14 @@ typedef union sigval {
35#define __ARCH_SI_BAND_T long 35#define __ARCH_SI_BAND_T long
36#endif 36#endif
37 37
38#ifndef __ARCH_SI_CLOCK_T
39#define __ARCH_SI_CLOCK_T __kernel_clock_t
40#endif
41
42#ifndef __ARCH_SI_ATTRIBUTES
43#define __ARCH_SI_ATTRIBUTES
44#endif
45
38#ifndef HAVE_ARCH_SIGINFO_T 46#ifndef HAVE_ARCH_SIGINFO_T
39 47
40typedef struct siginfo { 48typedef struct siginfo {
@@ -72,8 +80,8 @@ typedef struct siginfo {
72 __kernel_pid_t _pid; /* which child */ 80 __kernel_pid_t _pid; /* which child */
73 __ARCH_SI_UID_T _uid; /* sender's uid */ 81 __ARCH_SI_UID_T _uid; /* sender's uid */
74 int _status; /* exit code */ 82 int _status; /* exit code */
75 __kernel_clock_t _utime; 83 __ARCH_SI_CLOCK_T _utime;
76 __kernel_clock_t _stime; 84 __ARCH_SI_CLOCK_T _stime;
77 } _sigchld; 85 } _sigchld;
78 86
79 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS */ 87 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS */
@@ -91,7 +99,7 @@ typedef struct siginfo {
91 int _fd; 99 int _fd;
92 } _sigpoll; 100 } _sigpoll;
93 } _sifields; 101 } _sifields;
94} siginfo_t; 102} __ARCH_SI_ATTRIBUTES siginfo_t;
95 103
96#endif 104#endif
97 105
diff --git a/include/asm-generic/statfs.h b/include/asm-generic/statfs.h
index 0fd28e028de1..c749af9c0983 100644
--- a/include/asm-generic/statfs.h
+++ b/include/asm-generic/statfs.h
@@ -15,7 +15,7 @@ typedef __kernel_fsid_t fsid_t;
15 * with a 10' pole. 15 * with a 10' pole.
16 */ 16 */
17#ifndef __statfs_word 17#ifndef __statfs_word
18#if BITS_PER_LONG == 64 18#if __BITS_PER_LONG == 64
19#define __statfs_word long 19#define __statfs_word long
20#else 20#else
21#define __statfs_word __u32 21#define __statfs_word __u32
diff --git a/include/crypto/internal/aead.h b/include/crypto/internal/aead.h
index d838c945575a..2eba340230a7 100644
--- a/include/crypto/internal/aead.h
+++ b/include/crypto/internal/aead.h
@@ -31,6 +31,8 @@ static inline void crypto_set_aead_spawn(
31 crypto_set_spawn(&spawn->base, inst); 31 crypto_set_spawn(&spawn->base, inst);
32} 32}
33 33
34struct crypto_alg *crypto_lookup_aead(const char *name, u32 type, u32 mask);
35
34int crypto_grab_aead(struct crypto_aead_spawn *spawn, const char *name, 36int crypto_grab_aead(struct crypto_aead_spawn *spawn, const char *name,
35 u32 type, u32 mask); 37 u32 type, u32 mask);
36 38
diff --git a/include/crypto/internal/skcipher.h b/include/crypto/internal/skcipher.h
index 3a748a6bf772..06e8b32d541c 100644
--- a/include/crypto/internal/skcipher.h
+++ b/include/crypto/internal/skcipher.h
@@ -34,6 +34,8 @@ static inline void crypto_set_skcipher_spawn(
34int crypto_grab_skcipher(struct crypto_skcipher_spawn *spawn, const char *name, 34int crypto_grab_skcipher(struct crypto_skcipher_spawn *spawn, const char *name,
35 u32 type, u32 mask); 35 u32 type, u32 mask);
36 36
37struct crypto_alg *crypto_lookup_skcipher(const char *name, u32 type, u32 mask);
38
37static inline void crypto_drop_skcipher(struct crypto_skcipher_spawn *spawn) 39static inline void crypto_drop_skcipher(struct crypto_skcipher_spawn *spawn)
38{ 40{
39 crypto_drop_spawn(&spawn->base); 41 crypto_drop_spawn(&spawn->base);
diff --git a/include/drm/drm.h b/include/drm/drm.h
index 34a7b89fd006..64ff02d5b730 100644
--- a/include/drm/drm.h
+++ b/include/drm/drm.h
@@ -617,6 +617,17 @@ struct drm_get_cap {
617 __u64 value; 617 __u64 value;
618}; 618};
619 619
620#define DRM_CLOEXEC O_CLOEXEC
621struct drm_prime_handle {
622 __u32 handle;
623
624 /** Flags.. only applicable for handle->fd */
625 __u32 flags;
626
627 /** Returned dmabuf file descriptor */
628 __s32 fd;
629};
630
620#include "drm_mode.h" 631#include "drm_mode.h"
621 632
622#define DRM_IOCTL_BASE 'd' 633#define DRM_IOCTL_BASE 'd'
@@ -673,7 +684,8 @@ struct drm_get_cap {
673#define DRM_IOCTL_UNLOCK DRM_IOW( 0x2b, struct drm_lock) 684#define DRM_IOCTL_UNLOCK DRM_IOW( 0x2b, struct drm_lock)
674#define DRM_IOCTL_FINISH DRM_IOW( 0x2c, struct drm_lock) 685#define DRM_IOCTL_FINISH DRM_IOW( 0x2c, struct drm_lock)
675 686
676#define DRM_IOCTL_GEM_PRIME_OPEN DRM_IOWR(0x2e, struct drm_gem_open) 687#define DRM_IOCTL_PRIME_HANDLE_TO_FD DRM_IOWR(0x2d, struct drm_prime_handle)
688#define DRM_IOCTL_PRIME_FD_TO_HANDLE DRM_IOWR(0x2e, struct drm_prime_handle)
677 689
678#define DRM_IOCTL_AGP_ACQUIRE DRM_IO( 0x30) 690#define DRM_IOCTL_AGP_ACQUIRE DRM_IO( 0x30)
679#define DRM_IOCTL_AGP_RELEASE DRM_IO( 0x31) 691#define DRM_IOCTL_AGP_RELEASE DRM_IO( 0x31)
diff --git a/include/drm/drmP.h b/include/drm/drmP.h
index 574bd1c81ebd..dd731043fecd 100644
--- a/include/drm/drmP.h
+++ b/include/drm/drmP.h
@@ -91,6 +91,7 @@ struct drm_device;
91#define DRM_UT_CORE 0x01 91#define DRM_UT_CORE 0x01
92#define DRM_UT_DRIVER 0x02 92#define DRM_UT_DRIVER 0x02
93#define DRM_UT_KMS 0x04 93#define DRM_UT_KMS 0x04
94#define DRM_UT_PRIME 0x08
94/* 95/*
95 * Three debug levels are defined. 96 * Three debug levels are defined.
96 * drm_core, drm_driver, drm_kms 97 * drm_core, drm_driver, drm_kms
@@ -150,6 +151,7 @@ int drm_err(const char *func, const char *format, ...);
150#define DRIVER_IRQ_VBL2 0x800 151#define DRIVER_IRQ_VBL2 0x800
151#define DRIVER_GEM 0x1000 152#define DRIVER_GEM 0x1000
152#define DRIVER_MODESET 0x2000 153#define DRIVER_MODESET 0x2000
154#define DRIVER_PRIME 0x4000
153 155
154#define DRIVER_BUS_PCI 0x1 156#define DRIVER_BUS_PCI 0x1
155#define DRIVER_BUS_PLATFORM 0x2 157#define DRIVER_BUS_PLATFORM 0x2
@@ -215,6 +217,11 @@ int drm_err(const char *func, const char *format, ...);
215 drm_ut_debug_printk(DRM_UT_KMS, DRM_NAME, \ 217 drm_ut_debug_printk(DRM_UT_KMS, DRM_NAME, \
216 __func__, fmt, ##args); \ 218 __func__, fmt, ##args); \
217 } while (0) 219 } while (0)
220#define DRM_DEBUG_PRIME(fmt, args...) \
221 do { \
222 drm_ut_debug_printk(DRM_UT_PRIME, DRM_NAME, \
223 __func__, fmt, ##args); \
224 } while (0)
218#define DRM_LOG(fmt, args...) \ 225#define DRM_LOG(fmt, args...) \
219 do { \ 226 do { \
220 drm_ut_debug_printk(DRM_UT_CORE, NULL, \ 227 drm_ut_debug_printk(DRM_UT_CORE, NULL, \
@@ -238,6 +245,7 @@ int drm_err(const char *func, const char *format, ...);
238#else 245#else
239#define DRM_DEBUG_DRIVER(fmt, args...) do { } while (0) 246#define DRM_DEBUG_DRIVER(fmt, args...) do { } while (0)
240#define DRM_DEBUG_KMS(fmt, args...) do { } while (0) 247#define DRM_DEBUG_KMS(fmt, args...) do { } while (0)
248#define DRM_DEBUG_PRIME(fmt, args...) do { } while (0)
241#define DRM_DEBUG(fmt, arg...) do { } while (0) 249#define DRM_DEBUG(fmt, arg...) do { } while (0)
242#define DRM_LOG(fmt, arg...) do { } while (0) 250#define DRM_LOG(fmt, arg...) do { } while (0)
243#define DRM_LOG_KMS(fmt, args...) do { } while (0) 251#define DRM_LOG_KMS(fmt, args...) do { } while (0)
@@ -410,6 +418,12 @@ struct drm_pending_event {
410 void (*destroy)(struct drm_pending_event *event); 418 void (*destroy)(struct drm_pending_event *event);
411}; 419};
412 420
421/* initial implementaton using a linked list - todo hashtab */
422struct drm_prime_file_private {
423 struct list_head head;
424 struct mutex lock;
425};
426
413/** File private data */ 427/** File private data */
414struct drm_file { 428struct drm_file {
415 int authenticated; 429 int authenticated;
@@ -437,6 +451,8 @@ struct drm_file {
437 wait_queue_head_t event_wait; 451 wait_queue_head_t event_wait;
438 struct list_head event_list; 452 struct list_head event_list;
439 int event_space; 453 int event_space;
454
455 struct drm_prime_file_private prime;
440}; 456};
441 457
442/** Wait queue */ 458/** Wait queue */
@@ -652,6 +668,12 @@ struct drm_gem_object {
652 uint32_t pending_write_domain; 668 uint32_t pending_write_domain;
653 669
654 void *driver_private; 670 void *driver_private;
671
672 /* dma buf exported from this GEM object */
673 struct dma_buf *export_dma_buf;
674
675 /* dma buf attachment backing this object */
676 struct dma_buf_attachment *import_attach;
655}; 677};
656 678
657#include "drm_crtc.h" 679#include "drm_crtc.h"
@@ -890,6 +912,20 @@ struct drm_driver {
890 int (*gem_open_object) (struct drm_gem_object *, struct drm_file *); 912 int (*gem_open_object) (struct drm_gem_object *, struct drm_file *);
891 void (*gem_close_object) (struct drm_gem_object *, struct drm_file *); 913 void (*gem_close_object) (struct drm_gem_object *, struct drm_file *);
892 914
915 /* prime: */
916 /* export handle -> fd (see drm_gem_prime_handle_to_fd() helper) */
917 int (*prime_handle_to_fd)(struct drm_device *dev, struct drm_file *file_priv,
918 uint32_t handle, uint32_t flags, int *prime_fd);
919 /* import fd -> handle (see drm_gem_prime_fd_to_handle() helper) */
920 int (*prime_fd_to_handle)(struct drm_device *dev, struct drm_file *file_priv,
921 int prime_fd, uint32_t *handle);
922 /* export GEM -> dmabuf */
923 struct dma_buf * (*gem_prime_export)(struct drm_device *dev,
924 struct drm_gem_object *obj, int flags);
925 /* import dmabuf -> GEM */
926 struct drm_gem_object * (*gem_prime_import)(struct drm_device *dev,
927 struct dma_buf *dma_buf);
928
893 /* vga arb irq handler */ 929 /* vga arb irq handler */
894 void (*vgaarb_irq)(struct drm_device *dev, bool state); 930 void (*vgaarb_irq)(struct drm_device *dev, bool state);
895 931
@@ -1509,6 +1545,32 @@ extern int drm_vblank_info(struct seq_file *m, void *data);
1509extern int drm_clients_info(struct seq_file *m, void* data); 1545extern int drm_clients_info(struct seq_file *m, void* data);
1510extern int drm_gem_name_info(struct seq_file *m, void *data); 1546extern int drm_gem_name_info(struct seq_file *m, void *data);
1511 1547
1548
1549extern int drm_gem_prime_handle_to_fd(struct drm_device *dev,
1550 struct drm_file *file_priv, uint32_t handle, uint32_t flags,
1551 int *prime_fd);
1552extern int drm_gem_prime_fd_to_handle(struct drm_device *dev,
1553 struct drm_file *file_priv, int prime_fd, uint32_t *handle);
1554
1555extern int drm_prime_handle_to_fd_ioctl(struct drm_device *dev, void *data,
1556 struct drm_file *file_priv);
1557extern int drm_prime_fd_to_handle_ioctl(struct drm_device *dev, void *data,
1558 struct drm_file *file_priv);
1559
1560extern struct sg_table *drm_prime_pages_to_sg(struct page **pages, int nr_pages);
1561extern void drm_prime_gem_destroy(struct drm_gem_object *obj, struct sg_table *sg);
1562
1563
1564void drm_prime_init_file_private(struct drm_prime_file_private *prime_fpriv);
1565void drm_prime_destroy_file_private(struct drm_prime_file_private *prime_fpriv);
1566int drm_prime_add_imported_buf_handle(struct drm_prime_file_private *prime_fpriv, struct dma_buf *dma_buf, uint32_t handle);
1567int drm_prime_lookup_imported_buf_handle(struct drm_prime_file_private *prime_fpriv, struct dma_buf *dma_buf, uint32_t *handle);
1568void drm_prime_remove_imported_buf_handle(struct drm_prime_file_private *prime_fpriv, struct dma_buf *dma_buf);
1569
1570int drm_prime_add_dma_buf(struct drm_device *dev, struct drm_gem_object *obj);
1571int drm_prime_lookup_obj(struct drm_device *dev, struct dma_buf *buf,
1572 struct drm_gem_object **obj);
1573
1512#if DRM_DEBUG_CODE 1574#if DRM_DEBUG_CODE
1513extern int drm_vma_info(struct seq_file *m, void *data); 1575extern int drm_vma_info(struct seq_file *m, void *data);
1514#endif 1576#endif
diff --git a/include/drm/exynos_drm.h b/include/drm/exynos_drm.h
index 3963116083ae..e478de4e5d56 100644
--- a/include/drm/exynos_drm.h
+++ b/include/drm/exynos_drm.h
@@ -85,7 +85,7 @@ struct drm_exynos_gem_mmap {
85struct drm_exynos_vidi_connection { 85struct drm_exynos_vidi_connection {
86 unsigned int connection; 86 unsigned int connection;
87 unsigned int extensions; 87 unsigned int extensions;
88 uint64_t *edid; 88 uint64_t edid;
89}; 89};
90 90
91struct drm_exynos_plane_set_zpos { 91struct drm_exynos_plane_set_zpos {
@@ -96,7 +96,8 @@ struct drm_exynos_plane_set_zpos {
96/* memory type definitions. */ 96/* memory type definitions. */
97enum e_drm_exynos_gem_mem_type { 97enum e_drm_exynos_gem_mem_type {
98 /* Physically Non-Continuous memory. */ 98 /* Physically Non-Continuous memory. */
99 EXYNOS_BO_NONCONTIG = 1 << 0 99 EXYNOS_BO_NONCONTIG = 1 << 0,
100 EXYNOS_BO_MASK = EXYNOS_BO_NONCONTIG
100}; 101};
101 102
102#define DRM_EXYNOS_GEM_CREATE 0x00 103#define DRM_EXYNOS_GEM_CREATE 0x00
diff --git a/include/drm/intel-gtt.h b/include/drm/intel-gtt.h
index 0a0001b9dc78..923afb5dcf0c 100644
--- a/include/drm/intel-gtt.h
+++ b/include/drm/intel-gtt.h
@@ -44,4 +44,8 @@ void intel_gtt_insert_pages(unsigned int first_entry, unsigned int num_entries,
44/* flag for GFDT type */ 44/* flag for GFDT type */
45#define AGP_USER_CACHED_MEMORY_GFDT (1 << 3) 45#define AGP_USER_CACHED_MEMORY_GFDT (1 << 3)
46 46
47#ifdef CONFIG_INTEL_IOMMU
48extern int intel_iommu_gfx_mapped;
49#endif
50
47#endif 51#endif
diff --git a/include/linux/Kbuild b/include/linux/Kbuild
index d05df2810354..3c9b616c834a 100644
--- a/include/linux/Kbuild
+++ b/include/linux/Kbuild
@@ -3,6 +3,7 @@ header-y += can/
3header-y += caif/ 3header-y += caif/
4header-y += dvb/ 4header-y += dvb/
5header-y += hdlc/ 5header-y += hdlc/
6header-y += hsi/
6header-y += isdn/ 7header-y += isdn/
7header-y += mmc/ 8header-y += mmc/
8header-y += nfsd/ 9header-y += nfsd/
diff --git a/include/linux/amba/bus.h b/include/linux/amba/bus.h
index 7847e197730a..8d54f79457ba 100644
--- a/include/linux/amba/bus.h
+++ b/include/linux/amba/bus.h
@@ -30,7 +30,6 @@ struct amba_device {
30 struct device dev; 30 struct device dev;
31 struct resource res; 31 struct resource res;
32 struct clk *pclk; 32 struct clk *pclk;
33 struct regulator *vcore;
34 u64 dma_mask; 33 u64 dma_mask;
35 unsigned int periphid; 34 unsigned int periphid;
36 unsigned int irq[AMBA_NR_IRQS]; 35 unsigned int irq[AMBA_NR_IRQS];
@@ -75,12 +74,6 @@ void amba_release_regions(struct amba_device *);
75#define amba_pclk_disable(d) \ 74#define amba_pclk_disable(d) \
76 do { if (!IS_ERR((d)->pclk)) clk_disable((d)->pclk); } while (0) 75 do { if (!IS_ERR((d)->pclk)) clk_disable((d)->pclk); } while (0)
77 76
78#define amba_vcore_enable(d) \
79 (IS_ERR((d)->vcore) ? 0 : regulator_enable((d)->vcore))
80
81#define amba_vcore_disable(d) \
82 do { if (!IS_ERR((d)->vcore)) regulator_disable((d)->vcore); } while (0)
83
84/* Some drivers don't use the struct amba_device */ 77/* Some drivers don't use the struct amba_device */
85#define AMBA_CONFIG_BITS(a) (((a) >> 24) & 0xff) 78#define AMBA_CONFIG_BITS(a) (((a) >> 24) & 0xff)
86#define AMBA_REV_BITS(a) (((a) >> 20) & 0x0f) 79#define AMBA_REV_BITS(a) (((a) >> 20) & 0x0f)
diff --git a/include/linux/amba/pl022.h b/include/linux/amba/pl022.h
index b8c51124ed19..76dd1b199a1b 100644
--- a/include/linux/amba/pl022.h
+++ b/include/linux/amba/pl022.h
@@ -25,6 +25,8 @@
25#ifndef _SSP_PL022_H 25#ifndef _SSP_PL022_H
26#define _SSP_PL022_H 26#define _SSP_PL022_H
27 27
28#include <linux/types.h>
29
28/** 30/**
29 * whether SSP is in loopback mode or not 31 * whether SSP is in loopback mode or not
30 */ 32 */
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 606cf339bb56..2aa24664a5b5 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -426,14 +426,10 @@ struct request_queue {
426 (1 << QUEUE_FLAG_SAME_COMP) | \ 426 (1 << QUEUE_FLAG_SAME_COMP) | \
427 (1 << QUEUE_FLAG_ADD_RANDOM)) 427 (1 << QUEUE_FLAG_ADD_RANDOM))
428 428
429static inline int queue_is_locked(struct request_queue *q) 429static inline void queue_lockdep_assert_held(struct request_queue *q)
430{ 430{
431#ifdef CONFIG_SMP 431 if (q->queue_lock)
432 spinlock_t *lock = q->queue_lock; 432 lockdep_assert_held(q->queue_lock);
433 return lock && spin_is_locked(lock);
434#else
435 return 1;
436#endif
437} 433}
438 434
439static inline void queue_flag_set_unlocked(unsigned int flag, 435static inline void queue_flag_set_unlocked(unsigned int flag,
@@ -445,7 +441,7 @@ static inline void queue_flag_set_unlocked(unsigned int flag,
445static inline int queue_flag_test_and_clear(unsigned int flag, 441static inline int queue_flag_test_and_clear(unsigned int flag,
446 struct request_queue *q) 442 struct request_queue *q)
447{ 443{
448 WARN_ON_ONCE(!queue_is_locked(q)); 444 queue_lockdep_assert_held(q);
449 445
450 if (test_bit(flag, &q->queue_flags)) { 446 if (test_bit(flag, &q->queue_flags)) {
451 __clear_bit(flag, &q->queue_flags); 447 __clear_bit(flag, &q->queue_flags);
@@ -458,7 +454,7 @@ static inline int queue_flag_test_and_clear(unsigned int flag,
458static inline int queue_flag_test_and_set(unsigned int flag, 454static inline int queue_flag_test_and_set(unsigned int flag,
459 struct request_queue *q) 455 struct request_queue *q)
460{ 456{
461 WARN_ON_ONCE(!queue_is_locked(q)); 457 queue_lockdep_assert_held(q);
462 458
463 if (!test_bit(flag, &q->queue_flags)) { 459 if (!test_bit(flag, &q->queue_flags)) {
464 __set_bit(flag, &q->queue_flags); 460 __set_bit(flag, &q->queue_flags);
@@ -470,7 +466,7 @@ static inline int queue_flag_test_and_set(unsigned int flag,
470 466
471static inline void queue_flag_set(unsigned int flag, struct request_queue *q) 467static inline void queue_flag_set(unsigned int flag, struct request_queue *q)
472{ 468{
473 WARN_ON_ONCE(!queue_is_locked(q)); 469 queue_lockdep_assert_held(q);
474 __set_bit(flag, &q->queue_flags); 470 __set_bit(flag, &q->queue_flags);
475} 471}
476 472
@@ -487,7 +483,7 @@ static inline int queue_in_flight(struct request_queue *q)
487 483
488static inline void queue_flag_clear(unsigned int flag, struct request_queue *q) 484static inline void queue_flag_clear(unsigned int flag, struct request_queue *q)
489{ 485{
490 WARN_ON_ONCE(!queue_is_locked(q)); 486 queue_lockdep_assert_held(q);
491 __clear_bit(flag, &q->queue_flags); 487 __clear_bit(flag, &q->queue_flags);
492} 488}
493 489
diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
index 1ffdb9856bb9..a2c819d3c96e 100644
--- a/include/linux/cpumask.h
+++ b/include/linux/cpumask.h
@@ -764,12 +764,6 @@ static inline const struct cpumask *get_cpu_mask(unsigned int cpu)
764 * 764 *
765 */ 765 */
766#ifndef CONFIG_DISABLE_OBSOLETE_CPUMASK_FUNCTIONS 766#ifndef CONFIG_DISABLE_OBSOLETE_CPUMASK_FUNCTIONS
767/* These strip const, as traditionally they weren't const. */
768#define cpu_possible_map (*(cpumask_t *)cpu_possible_mask)
769#define cpu_online_map (*(cpumask_t *)cpu_online_mask)
770#define cpu_present_map (*(cpumask_t *)cpu_present_mask)
771#define cpu_active_map (*(cpumask_t *)cpu_active_mask)
772
773#define cpumask_of_cpu(cpu) (*get_cpu_mask(cpu)) 767#define cpumask_of_cpu(cpu) (*get_cpu_mask(cpu))
774 768
775#define CPU_MASK_LAST_WORD BITMAP_LAST_WORD_MASK(NR_CPUS) 769#define CPU_MASK_LAST_WORD BITMAP_LAST_WORD_MASK(NR_CPUS)
diff --git a/include/linux/cryptouser.h b/include/linux/cryptouser.h
index 532fb58f16bf..4abf2ea6a887 100644
--- a/include/linux/cryptouser.h
+++ b/include/linux/cryptouser.h
@@ -100,3 +100,6 @@ struct crypto_report_rng {
100 char type[CRYPTO_MAX_NAME]; 100 char type[CRYPTO_MAX_NAME];
101 unsigned int seedsize; 101 unsigned int seedsize;
102}; 102};
103
104#define CRYPTO_REPORT_MAXSIZE (sizeof(struct crypto_user_alg) + \
105 sizeof(struct crypto_report_blkcipher))
diff --git a/include/linux/dma-attrs.h b/include/linux/dma-attrs.h
index 71ad34eca6e3..547ab568d3ae 100644
--- a/include/linux/dma-attrs.h
+++ b/include/linux/dma-attrs.h
@@ -13,6 +13,8 @@
13enum dma_attr { 13enum dma_attr {
14 DMA_ATTR_WRITE_BARRIER, 14 DMA_ATTR_WRITE_BARRIER,
15 DMA_ATTR_WEAK_ORDERING, 15 DMA_ATTR_WEAK_ORDERING,
16 DMA_ATTR_WRITE_COMBINE,
17 DMA_ATTR_NON_CONSISTENT,
16 DMA_ATTR_MAX, 18 DMA_ATTR_MAX,
17}; 19};
18 20
diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
index 5a736af3cc7a..dfc099e56a66 100644
--- a/include/linux/dma-mapping.h
+++ b/include/linux/dma-mapping.h
@@ -9,10 +9,15 @@
9#include <linux/scatterlist.h> 9#include <linux/scatterlist.h>
10 10
11struct dma_map_ops { 11struct dma_map_ops {
12 void* (*alloc_coherent)(struct device *dev, size_t size, 12 void* (*alloc)(struct device *dev, size_t size,
13 dma_addr_t *dma_handle, gfp_t gfp); 13 dma_addr_t *dma_handle, gfp_t gfp,
14 void (*free_coherent)(struct device *dev, size_t size, 14 struct dma_attrs *attrs);
15 void *vaddr, dma_addr_t dma_handle); 15 void (*free)(struct device *dev, size_t size,
16 void *vaddr, dma_addr_t dma_handle,
17 struct dma_attrs *attrs);
18 int (*mmap)(struct device *, struct vm_area_struct *,
19 void *, dma_addr_t, size_t, struct dma_attrs *attrs);
20
16 dma_addr_t (*map_page)(struct device *dev, struct page *page, 21 dma_addr_t (*map_page)(struct device *dev, struct page *page,
17 unsigned long offset, size_t size, 22 unsigned long offset, size_t size,
18 enum dma_data_direction dir, 23 enum dma_data_direction dir,
diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
index 676f967390ae..f9a2e5e67a54 100644
--- a/include/linux/dmaengine.h
+++ b/include/linux/dmaengine.h
@@ -974,6 +974,7 @@ int dma_async_device_register(struct dma_device *device);
974void dma_async_device_unregister(struct dma_device *device); 974void dma_async_device_unregister(struct dma_device *device);
975void dma_run_dependencies(struct dma_async_tx_descriptor *tx); 975void dma_run_dependencies(struct dma_async_tx_descriptor *tx);
976struct dma_chan *dma_find_channel(enum dma_transaction_type tx_type); 976struct dma_chan *dma_find_channel(enum dma_transaction_type tx_type);
977struct dma_chan *net_dma_find_channel(void);
977#define dma_request_channel(mask, x, y) __dma_request_channel(&(mask), x, y) 978#define dma_request_channel(mask, x, y) __dma_request_channel(&(mask), x, y)
978 979
979/* --- Helper iov-locking functions --- */ 980/* --- Helper iov-locking functions --- */
diff --git a/include/linux/efi.h b/include/linux/efi.h
index 88ec80670d5f..ec45ccd8708a 100644
--- a/include/linux/efi.h
+++ b/include/linux/efi.h
@@ -554,7 +554,18 @@ extern int __init efi_setup_pcdp_console(char *);
554#define EFI_VARIABLE_NON_VOLATILE 0x0000000000000001 554#define EFI_VARIABLE_NON_VOLATILE 0x0000000000000001
555#define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x0000000000000002 555#define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x0000000000000002
556#define EFI_VARIABLE_RUNTIME_ACCESS 0x0000000000000004 556#define EFI_VARIABLE_RUNTIME_ACCESS 0x0000000000000004
557 557#define EFI_VARIABLE_HARDWARE_ERROR_RECORD 0x0000000000000008
558#define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS 0x0000000000000010
559#define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS 0x0000000000000020
560#define EFI_VARIABLE_APPEND_WRITE 0x0000000000000040
561
562#define EFI_VARIABLE_MASK (EFI_VARIABLE_NON_VOLATILE | \
563 EFI_VARIABLE_BOOTSERVICE_ACCESS | \
564 EFI_VARIABLE_RUNTIME_ACCESS | \
565 EFI_VARIABLE_HARDWARE_ERROR_RECORD | \
566 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS | \
567 EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS | \
568 EFI_VARIABLE_APPEND_WRITE)
558/* 569/*
559 * The type of search to perform when calling boottime->locate_handle 570 * The type of search to perform when calling boottime->locate_handle
560 */ 571 */
diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h
index 8a1835855faa..fe5136d81454 100644
--- a/include/linux/etherdevice.h
+++ b/include/linux/etherdevice.h
@@ -159,7 +159,8 @@ static inline void eth_hw_addr_random(struct net_device *dev)
159 * @addr1: Pointer to a six-byte array containing the Ethernet address 159 * @addr1: Pointer to a six-byte array containing the Ethernet address
160 * @addr2: Pointer other six-byte array containing the Ethernet address 160 * @addr2: Pointer other six-byte array containing the Ethernet address
161 * 161 *
162 * Compare two ethernet addresses, returns 0 if equal 162 * Compare two ethernet addresses, returns 0 if equal, non-zero otherwise.
163 * Unlike memcmp(), it doesn't return a value suitable for sorting.
163 */ 164 */
164static inline unsigned compare_ether_addr(const u8 *addr1, const u8 *addr2) 165static inline unsigned compare_ether_addr(const u8 *addr1, const u8 *addr2)
165{ 166{
@@ -184,10 +185,10 @@ static inline unsigned long zap_last_2bytes(unsigned long value)
184 * @addr1: Pointer to an array of 8 bytes 185 * @addr1: Pointer to an array of 8 bytes
185 * @addr2: Pointer to an other array of 8 bytes 186 * @addr2: Pointer to an other array of 8 bytes
186 * 187 *
187 * Compare two ethernet addresses, returns 0 if equal. 188 * Compare two ethernet addresses, returns 0 if equal, non-zero otherwise.
188 * Same result than "memcmp(addr1, addr2, ETH_ALEN)" but without conditional 189 * Unlike memcmp(), it doesn't return a value suitable for sorting.
189 * branches, and possibly long word memory accesses on CPU allowing cheap 190 * The function doesn't need any conditional branches and possibly uses
190 * unaligned memory reads. 191 * word memory accesses on CPU allowing cheap unaligned memory reads.
191 * arrays = { byte1, byte2, byte3, byte4, byte6, byte7, pad1, pad2} 192 * arrays = { byte1, byte2, byte3, byte4, byte6, byte7, pad1, pad2}
192 * 193 *
193 * Please note that alignment of addr1 & addr2 is only guaranted to be 16 bits. 194 * Please note that alignment of addr1 & addr2 is only guaranted to be 16 bits.
diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h
index e1d9e0ede309..f5647b59a90e 100644
--- a/include/linux/ethtool.h
+++ b/include/linux/ethtool.h
@@ -896,8 +896,7 @@ static inline u32 ethtool_rxfh_indir_default(u32 index, u32 n_rx_rings)
896 * 896 *
897 * All operations are optional (i.e. the function pointer may be set 897 * All operations are optional (i.e. the function pointer may be set
898 * to %NULL) and callers must take this into account. Callers must 898 * to %NULL) and callers must take this into account. Callers must
899 * hold the RTNL, except that for @get_drvinfo the caller may or may 899 * hold the RTNL lock.
900 * not hold the RTNL.
901 * 900 *
902 * See the structures used by these operations for further documentation. 901 * See the structures used by these operations for further documentation.
903 * 902 *
diff --git a/include/linux/firewire.h b/include/linux/firewire.h
index 4db7b68f0582..cdc9b719e9c7 100644
--- a/include/linux/firewire.h
+++ b/include/linux/firewire.h
@@ -2,6 +2,7 @@
2#define _LINUX_FIREWIRE_H 2#define _LINUX_FIREWIRE_H
3 3
4#include <linux/completion.h> 4#include <linux/completion.h>
5#include <linux/device.h>
5#include <linux/dma-mapping.h> 6#include <linux/dma-mapping.h>
6#include <linux/kernel.h> 7#include <linux/kernel.h>
7#include <linux/kref.h> 8#include <linux/kref.h>
@@ -64,8 +65,6 @@
64#define CSR_MODEL 0x17 65#define CSR_MODEL 0x17
65#define CSR_DIRECTORY_ID 0x20 66#define CSR_DIRECTORY_ID 0x20
66 67
67struct device;
68
69struct fw_csr_iterator { 68struct fw_csr_iterator {
70 const u32 *p; 69 const u32 *p;
71 const u32 *end; 70 const u32 *end;
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 135693e79f2b..8de675523e46 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1215,6 +1215,7 @@ extern int vfs_setlease(struct file *, long, struct file_lock **);
1215extern int lease_modify(struct file_lock **, int); 1215extern int lease_modify(struct file_lock **, int);
1216extern int lock_may_read(struct inode *, loff_t start, unsigned long count); 1216extern int lock_may_read(struct inode *, loff_t start, unsigned long count);
1217extern int lock_may_write(struct inode *, loff_t start, unsigned long count); 1217extern int lock_may_write(struct inode *, loff_t start, unsigned long count);
1218extern void locks_delete_block(struct file_lock *waiter);
1218extern void lock_flocks(void); 1219extern void lock_flocks(void);
1219extern void unlock_flocks(void); 1220extern void unlock_flocks(void);
1220#else /* !CONFIG_FILE_LOCKING */ 1221#else /* !CONFIG_FILE_LOCKING */
@@ -1359,6 +1360,10 @@ static inline int lock_may_write(struct inode *inode, loff_t start,
1359 return 1; 1360 return 1;
1360} 1361}
1361 1362
1363static inline void locks_delete_block(struct file_lock *waiter)
1364{
1365}
1366
1362static inline void lock_flocks(void) 1367static inline void lock_flocks(void)
1363{ 1368{
1364} 1369}
@@ -2506,6 +2511,7 @@ extern int dcache_readdir(struct file *, void *, filldir_t);
2506extern int simple_setattr(struct dentry *, struct iattr *); 2511extern int simple_setattr(struct dentry *, struct iattr *);
2507extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *); 2512extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
2508extern int simple_statfs(struct dentry *, struct kstatfs *); 2513extern int simple_statfs(struct dentry *, struct kstatfs *);
2514extern int simple_open(struct inode *inode, struct file *file);
2509extern int simple_link(struct dentry *, struct inode *, struct dentry *); 2515extern int simple_link(struct dentry *, struct inode *, struct dentry *);
2510extern int simple_unlink(struct inode *, struct dentry *); 2516extern int simple_unlink(struct inode *, struct dentry *);
2511extern int simple_rmdir(struct inode *, struct dentry *); 2517extern int simple_rmdir(struct inode *, struct dentry *);
diff --git a/include/linux/fuse.h b/include/linux/fuse.h
index 8ba2c9460b28..8f2ab8fef929 100644
--- a/include/linux/fuse.h
+++ b/include/linux/fuse.h
@@ -593,7 +593,7 @@ struct fuse_dirent {
593 __u64 off; 593 __u64 off;
594 __u32 namelen; 594 __u32 namelen;
595 __u32 type; 595 __u32 type;
596 char name[0]; 596 char name[];
597}; 597};
598 598
599#define FUSE_NAME_OFFSET offsetof(struct fuse_dirent, name) 599#define FUSE_NAME_OFFSET offsetof(struct fuse_dirent, name)
diff --git a/include/linux/gpio-pxa.h b/include/linux/gpio-pxa.h
index 05071ee34c3f..d755b28ba635 100644
--- a/include/linux/gpio-pxa.h
+++ b/include/linux/gpio-pxa.h
@@ -13,4 +13,8 @@ extern int pxa_last_gpio;
13 13
14extern int pxa_irq_to_gpio(int irq); 14extern int pxa_irq_to_gpio(int irq);
15 15
16struct pxa_gpio_platform_data {
17 int (*gpio_set_wake)(unsigned int gpio, unsigned int on);
18};
19
16#endif /* __GPIO_PXA_H */ 20#endif /* __GPIO_PXA_H */
diff --git a/include/linux/hsi/Kbuild b/include/linux/hsi/Kbuild
new file mode 100644
index 000000000000..271a770b4784
--- /dev/null
+++ b/include/linux/hsi/Kbuild
@@ -0,0 +1 @@
header-y += hsi_char.h
diff --git a/include/linux/hsi/hsi.h b/include/linux/hsi/hsi.h
new file mode 100644
index 000000000000..56fae865e272
--- /dev/null
+++ b/include/linux/hsi/hsi.h
@@ -0,0 +1,413 @@
1/*
2 * HSI core header file.
3 *
4 * Copyright (C) 2010 Nokia Corporation. All rights reserved.
5 *
6 * Contact: Carlos Chinea <carlos.chinea@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 */
22
23#ifndef __LINUX_HSI_H__
24#define __LINUX_HSI_H__
25
26#include <linux/device.h>
27#include <linux/mutex.h>
28#include <linux/scatterlist.h>
29#include <linux/list.h>
30#include <linux/module.h>
31#include <linux/notifier.h>
32
33/* HSI message ttype */
34#define HSI_MSG_READ 0
35#define HSI_MSG_WRITE 1
36
37/* HSI configuration values */
38enum {
39 HSI_MODE_STREAM = 1,
40 HSI_MODE_FRAME,
41};
42
43enum {
44 HSI_FLOW_SYNC, /* Synchronized flow */
45 HSI_FLOW_PIPE, /* Pipelined flow */
46};
47
48enum {
49 HSI_ARB_RR, /* Round-robin arbitration */
50 HSI_ARB_PRIO, /* Channel priority arbitration */
51};
52
53#define HSI_MAX_CHANNELS 16
54
55/* HSI message status codes */
56enum {
57 HSI_STATUS_COMPLETED, /* Message transfer is completed */
58 HSI_STATUS_PENDING, /* Message pending to be read/write (POLL) */
59 HSI_STATUS_PROCEEDING, /* Message transfer is ongoing */
60 HSI_STATUS_QUEUED, /* Message waiting to be served */
61 HSI_STATUS_ERROR, /* Error when message transfer was ongoing */
62};
63
64/* HSI port event codes */
65enum {
66 HSI_EVENT_START_RX,
67 HSI_EVENT_STOP_RX,
68};
69
70/**
71 * struct hsi_config - Configuration for RX/TX HSI modules
72 * @mode: Bit transmission mode (STREAM or FRAME)
73 * @channels: Number of channels to use [1..16]
74 * @speed: Max bit transmission speed (Kbit/s)
75 * @flow: RX flow type (SYNCHRONIZED or PIPELINE)
76 * @arb_mode: Arbitration mode for TX frame (Round robin, priority)
77 */
78struct hsi_config {
79 unsigned int mode;
80 unsigned int channels;
81 unsigned int speed;
82 union {
83 unsigned int flow; /* RX only */
84 unsigned int arb_mode; /* TX only */
85 };
86};
87
88/**
89 * struct hsi_board_info - HSI client board info
90 * @name: Name for the HSI device
91 * @hsi_id: HSI controller id where the client sits
92 * @port: Port number in the controller where the client sits
93 * @tx_cfg: HSI TX configuration
94 * @rx_cfg: HSI RX configuration
95 * @platform_data: Platform related data
96 * @archdata: Architecture-dependent device data
97 */
98struct hsi_board_info {
99 const char *name;
100 unsigned int hsi_id;
101 unsigned int port;
102 struct hsi_config tx_cfg;
103 struct hsi_config rx_cfg;
104 void *platform_data;
105 struct dev_archdata *archdata;
106};
107
108#ifdef CONFIG_HSI_BOARDINFO
109extern int hsi_register_board_info(struct hsi_board_info const *info,
110 unsigned int len);
111#else
112static inline int hsi_register_board_info(struct hsi_board_info const *info,
113 unsigned int len)
114{
115 return 0;
116}
117#endif /* CONFIG_HSI_BOARDINFO */
118
119/**
120 * struct hsi_client - HSI client attached to an HSI port
121 * @device: Driver model representation of the device
122 * @tx_cfg: HSI TX configuration
123 * @rx_cfg: HSI RX configuration
124 * @e_handler: Callback for handling port events (RX Wake High/Low)
125 * @pclaimed: Keeps tracks if the clients claimed its associated HSI port
126 * @nb: Notifier block for port events
127 */
128struct hsi_client {
129 struct device device;
130 struct hsi_config tx_cfg;
131 struct hsi_config rx_cfg;
132 /* private: */
133 void (*ehandler)(struct hsi_client *, unsigned long);
134 unsigned int pclaimed:1;
135 struct notifier_block nb;
136};
137
138#define to_hsi_client(dev) container_of(dev, struct hsi_client, device)
139
140static inline void hsi_client_set_drvdata(struct hsi_client *cl, void *data)
141{
142 dev_set_drvdata(&cl->device, data);
143}
144
145static inline void *hsi_client_drvdata(struct hsi_client *cl)
146{
147 return dev_get_drvdata(&cl->device);
148}
149
150int hsi_register_port_event(struct hsi_client *cl,
151 void (*handler)(struct hsi_client *, unsigned long));
152int hsi_unregister_port_event(struct hsi_client *cl);
153
154/**
155 * struct hsi_client_driver - Driver associated to an HSI client
156 * @driver: Driver model representation of the driver
157 */
158struct hsi_client_driver {
159 struct device_driver driver;
160};
161
162#define to_hsi_client_driver(drv) container_of(drv, struct hsi_client_driver,\
163 driver)
164
165int hsi_register_client_driver(struct hsi_client_driver *drv);
166
167static inline void hsi_unregister_client_driver(struct hsi_client_driver *drv)
168{
169 driver_unregister(&drv->driver);
170}
171
172/**
173 * struct hsi_msg - HSI message descriptor
174 * @link: Free to use by the current descriptor owner
175 * @cl: HSI device client that issues the transfer
176 * @sgt: Head of the scatterlist array
177 * @context: Client context data associated to the transfer
178 * @complete: Transfer completion callback
179 * @destructor: Destructor to free resources when flushing
180 * @status: Status of the transfer when completed
181 * @actual_len: Actual length of data transfered on completion
182 * @channel: Channel were to TX/RX the message
183 * @ttype: Transfer type (TX if set, RX otherwise)
184 * @break_frame: if true HSI will send/receive a break frame. Data buffers are
185 * ignored in the request.
186 */
187struct hsi_msg {
188 struct list_head link;
189 struct hsi_client *cl;
190 struct sg_table sgt;
191 void *context;
192
193 void (*complete)(struct hsi_msg *msg);
194 void (*destructor)(struct hsi_msg *msg);
195
196 int status;
197 unsigned int actual_len;
198 unsigned int channel;
199 unsigned int ttype:1;
200 unsigned int break_frame:1;
201};
202
203struct hsi_msg *hsi_alloc_msg(unsigned int n_frag, gfp_t flags);
204void hsi_free_msg(struct hsi_msg *msg);
205
206/**
207 * struct hsi_port - HSI port device
208 * @device: Driver model representation of the device
209 * @tx_cfg: Current TX path configuration
210 * @rx_cfg: Current RX path configuration
211 * @num: Port number
212 * @shared: Set when port can be shared by different clients
213 * @claimed: Reference count of clients which claimed the port
214 * @lock: Serialize port claim
215 * @async: Asynchronous transfer callback
216 * @setup: Callback to set the HSI client configuration
217 * @flush: Callback to clean the HW state and destroy all pending transfers
218 * @start_tx: Callback to inform that a client wants to TX data
219 * @stop_tx: Callback to inform that a client no longer wishes to TX data
220 * @release: Callback to inform that a client no longer uses the port
221 * @n_head: Notifier chain for signaling port events to the clients.
222 */
223struct hsi_port {
224 struct device device;
225 struct hsi_config tx_cfg;
226 struct hsi_config rx_cfg;
227 unsigned int num;
228 unsigned int shared:1;
229 int claimed;
230 struct mutex lock;
231 int (*async)(struct hsi_msg *msg);
232 int (*setup)(struct hsi_client *cl);
233 int (*flush)(struct hsi_client *cl);
234 int (*start_tx)(struct hsi_client *cl);
235 int (*stop_tx)(struct hsi_client *cl);
236 int (*release)(struct hsi_client *cl);
237 /* private */
238 struct atomic_notifier_head n_head;
239};
240
241#define to_hsi_port(dev) container_of(dev, struct hsi_port, device)
242#define hsi_get_port(cl) to_hsi_port((cl)->device.parent)
243
244int hsi_event(struct hsi_port *port, unsigned long event);
245int hsi_claim_port(struct hsi_client *cl, unsigned int share);
246void hsi_release_port(struct hsi_client *cl);
247
248static inline int hsi_port_claimed(struct hsi_client *cl)
249{
250 return cl->pclaimed;
251}
252
253static inline void hsi_port_set_drvdata(struct hsi_port *port, void *data)
254{
255 dev_set_drvdata(&port->device, data);
256}
257
258static inline void *hsi_port_drvdata(struct hsi_port *port)
259{
260 return dev_get_drvdata(&port->device);
261}
262
263/**
264 * struct hsi_controller - HSI controller device
265 * @device: Driver model representation of the device
266 * @owner: Pointer to the module owning the controller
267 * @id: HSI controller ID
268 * @num_ports: Number of ports in the HSI controller
269 * @port: Array of HSI ports
270 */
271struct hsi_controller {
272 struct device device;
273 struct module *owner;
274 unsigned int id;
275 unsigned int num_ports;
276 struct hsi_port **port;
277};
278
279#define to_hsi_controller(dev) container_of(dev, struct hsi_controller, device)
280
281struct hsi_controller *hsi_alloc_controller(unsigned int n_ports, gfp_t flags);
282void hsi_put_controller(struct hsi_controller *hsi);
283int hsi_register_controller(struct hsi_controller *hsi);
284void hsi_unregister_controller(struct hsi_controller *hsi);
285
286static inline void hsi_controller_set_drvdata(struct hsi_controller *hsi,
287 void *data)
288{
289 dev_set_drvdata(&hsi->device, data);
290}
291
292static inline void *hsi_controller_drvdata(struct hsi_controller *hsi)
293{
294 return dev_get_drvdata(&hsi->device);
295}
296
297static inline struct hsi_port *hsi_find_port_num(struct hsi_controller *hsi,
298 unsigned int num)
299{
300 return (num < hsi->num_ports) ? hsi->port[num] : NULL;
301}
302
303/*
304 * API for HSI clients
305 */
306int hsi_async(struct hsi_client *cl, struct hsi_msg *msg);
307
308/**
309 * hsi_id - Get HSI controller ID associated to a client
310 * @cl: Pointer to a HSI client
311 *
312 * Return the controller id where the client is attached to
313 */
314static inline unsigned int hsi_id(struct hsi_client *cl)
315{
316 return to_hsi_controller(cl->device.parent->parent)->id;
317}
318
319/**
320 * hsi_port_id - Gets the port number a client is attached to
321 * @cl: Pointer to HSI client
322 *
323 * Return the port number associated to the client
324 */
325static inline unsigned int hsi_port_id(struct hsi_client *cl)
326{
327 return to_hsi_port(cl->device.parent)->num;
328}
329
330/**
331 * hsi_setup - Configure the client's port
332 * @cl: Pointer to the HSI client
333 *
334 * When sharing ports, clients should either relay on a single
335 * client setup or have the same setup for all of them.
336 *
337 * Return -errno on failure, 0 on success
338 */
339static inline int hsi_setup(struct hsi_client *cl)
340{
341 if (!hsi_port_claimed(cl))
342 return -EACCES;
343 return hsi_get_port(cl)->setup(cl);
344}
345
346/**
347 * hsi_flush - Flush all pending transactions on the client's port
348 * @cl: Pointer to the HSI client
349 *
350 * This function will destroy all pending hsi_msg in the port and reset
351 * the HW port so it is ready to receive and transmit from a clean state.
352 *
353 * Return -errno on failure, 0 on success
354 */
355static inline int hsi_flush(struct hsi_client *cl)
356{
357 if (!hsi_port_claimed(cl))
358 return -EACCES;
359 return hsi_get_port(cl)->flush(cl);
360}
361
362/**
363 * hsi_async_read - Submit a read transfer
364 * @cl: Pointer to the HSI client
365 * @msg: HSI message descriptor of the transfer
366 *
367 * Return -errno on failure, 0 on success
368 */
369static inline int hsi_async_read(struct hsi_client *cl, struct hsi_msg *msg)
370{
371 msg->ttype = HSI_MSG_READ;
372 return hsi_async(cl, msg);
373}
374
375/**
376 * hsi_async_write - Submit a write transfer
377 * @cl: Pointer to the HSI client
378 * @msg: HSI message descriptor of the transfer
379 *
380 * Return -errno on failure, 0 on success
381 */
382static inline int hsi_async_write(struct hsi_client *cl, struct hsi_msg *msg)
383{
384 msg->ttype = HSI_MSG_WRITE;
385 return hsi_async(cl, msg);
386}
387
388/**
389 * hsi_start_tx - Signal the port that the client wants to start a TX
390 * @cl: Pointer to the HSI client
391 *
392 * Return -errno on failure, 0 on success
393 */
394static inline int hsi_start_tx(struct hsi_client *cl)
395{
396 if (!hsi_port_claimed(cl))
397 return -EACCES;
398 return hsi_get_port(cl)->start_tx(cl);
399}
400
401/**
402 * hsi_stop_tx - Signal the port that the client no longer wants to transmit
403 * @cl: Pointer to the HSI client
404 *
405 * Return -errno on failure, 0 on success
406 */
407static inline int hsi_stop_tx(struct hsi_client *cl)
408{
409 if (!hsi_port_claimed(cl))
410 return -EACCES;
411 return hsi_get_port(cl)->stop_tx(cl);
412}
413#endif /* __LINUX_HSI_H__ */
diff --git a/include/linux/hsi/hsi_char.h b/include/linux/hsi/hsi_char.h
new file mode 100644
index 000000000000..76160b4f455d
--- /dev/null
+++ b/include/linux/hsi/hsi_char.h
@@ -0,0 +1,63 @@
1/*
2 * Part of the HSI character device driver.
3 *
4 * Copyright (C) 2010 Nokia Corporation. All rights reserved.
5 *
6 * Contact: Andras Domokos <andras.domokos at nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 */
22
23
24#ifndef __HSI_CHAR_H
25#define __HSI_CHAR_H
26
27#define HSI_CHAR_MAGIC 'k'
28#define HSC_IOW(num, dtype) _IOW(HSI_CHAR_MAGIC, num, dtype)
29#define HSC_IOR(num, dtype) _IOR(HSI_CHAR_MAGIC, num, dtype)
30#define HSC_IOWR(num, dtype) _IOWR(HSI_CHAR_MAGIC, num, dtype)
31#define HSC_IO(num) _IO(HSI_CHAR_MAGIC, num)
32
33#define HSC_RESET HSC_IO(16)
34#define HSC_SET_PM HSC_IO(17)
35#define HSC_SEND_BREAK HSC_IO(18)
36#define HSC_SET_RX HSC_IOW(19, struct hsc_rx_config)
37#define HSC_GET_RX HSC_IOW(20, struct hsc_rx_config)
38#define HSC_SET_TX HSC_IOW(21, struct hsc_tx_config)
39#define HSC_GET_TX HSC_IOW(22, struct hsc_tx_config)
40
41#define HSC_PM_DISABLE 0
42#define HSC_PM_ENABLE 1
43
44#define HSC_MODE_STREAM 1
45#define HSC_MODE_FRAME 2
46#define HSC_FLOW_SYNC 0
47#define HSC_ARB_RR 0
48#define HSC_ARB_PRIO 1
49
50struct hsc_rx_config {
51 uint32_t mode;
52 uint32_t flow;
53 uint32_t channels;
54};
55
56struct hsc_tx_config {
57 uint32_t mode;
58 uint32_t channels;
59 uint32_t speed;
60 uint32_t arb_mode;
61};
62
63#endif /* __HSI_CHAR_H */
diff --git a/include/linux/i2c/twl.h b/include/linux/i2c/twl.h
index 2463b6100333..1f90de0cfdbe 100644
--- a/include/linux/i2c/twl.h
+++ b/include/linux/i2c/twl.h
@@ -666,23 +666,11 @@ struct twl4030_codec_data {
666 unsigned int check_defaults:1; 666 unsigned int check_defaults:1;
667 unsigned int reset_registers:1; 667 unsigned int reset_registers:1;
668 unsigned int hs_extmute:1; 668 unsigned int hs_extmute:1;
669 u16 hs_left_step;
670 u16 hs_right_step;
671 u16 hf_left_step;
672 u16 hf_right_step;
673 void (*set_hs_extmute)(int mute); 669 void (*set_hs_extmute)(int mute);
674}; 670};
675 671
676struct twl4030_vibra_data { 672struct twl4030_vibra_data {
677 unsigned int coexist; 673 unsigned int coexist;
678
679 /* twl6040 */
680 unsigned int vibldrv_res; /* left driver resistance */
681 unsigned int vibrdrv_res; /* right driver resistance */
682 unsigned int viblmotor_res; /* left motor resistance */
683 unsigned int vibrmotor_res; /* right motor resistance */
684 int vddvibl_uV; /* VDDVIBL volt, set 0 for fixed reg */
685 int vddvibr_uV; /* VDDVIBR volt, set 0 for fixed reg */
686}; 674};
687 675
688struct twl4030_audio_data { 676struct twl4030_audio_data {
diff --git a/include/linux/if_eql.h b/include/linux/if_eql.h
index 79c4f268410d..18a5d02a8644 100644
--- a/include/linux/if_eql.h
+++ b/include/linux/if_eql.h
@@ -22,7 +22,7 @@
22#define EQL_DEFAULT_SLAVE_PRIORITY 28800 22#define EQL_DEFAULT_SLAVE_PRIORITY 28800
23#define EQL_DEFAULT_MAX_SLAVES 4 23#define EQL_DEFAULT_MAX_SLAVES 4
24#define EQL_DEFAULT_MTU 576 24#define EQL_DEFAULT_MTU 576
25#define EQL_DEFAULT_RESCHED_IVAL 100 25#define EQL_DEFAULT_RESCHED_IVAL HZ
26 26
27#define EQL_ENSLAVE (SIOCDEVPRIVATE) 27#define EQL_ENSLAVE (SIOCDEVPRIVATE)
28#define EQL_EMANCIPATE (SIOCDEVPRIVATE + 1) 28#define EQL_EMANCIPATE (SIOCDEVPRIVATE + 1)
diff --git a/include/linux/irq.h b/include/linux/irq.h
index bff29c58da23..b27cfcfd3a59 100644
--- a/include/linux/irq.h
+++ b/include/linux/irq.h
@@ -49,6 +49,12 @@ typedef void (*irq_preflow_handler_t)(struct irq_data *data);
49 * IRQ_TYPE_LEVEL_LOW - low level triggered 49 * IRQ_TYPE_LEVEL_LOW - low level triggered
50 * IRQ_TYPE_LEVEL_MASK - Mask to filter out the level bits 50 * IRQ_TYPE_LEVEL_MASK - Mask to filter out the level bits
51 * IRQ_TYPE_SENSE_MASK - Mask for all the above bits 51 * IRQ_TYPE_SENSE_MASK - Mask for all the above bits
52 * IRQ_TYPE_DEFAULT - For use by some PICs to ask irq_set_type
53 * to setup the HW to a sane default (used
54 * by irqdomain map() callbacks to synchronize
55 * the HW state and SW flags for a newly
56 * allocated descriptor).
57 *
52 * IRQ_TYPE_PROBE - Special flag for probing in progress 58 * IRQ_TYPE_PROBE - Special flag for probing in progress
53 * 59 *
54 * Bits which can be modified via irq_set/clear/modify_status_flags() 60 * Bits which can be modified via irq_set/clear/modify_status_flags()
@@ -77,6 +83,7 @@ enum {
77 IRQ_TYPE_LEVEL_LOW = 0x00000008, 83 IRQ_TYPE_LEVEL_LOW = 0x00000008,
78 IRQ_TYPE_LEVEL_MASK = (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH), 84 IRQ_TYPE_LEVEL_MASK = (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH),
79 IRQ_TYPE_SENSE_MASK = 0x0000000f, 85 IRQ_TYPE_SENSE_MASK = 0x0000000f,
86 IRQ_TYPE_DEFAULT = IRQ_TYPE_SENSE_MASK,
80 87
81 IRQ_TYPE_PROBE = 0x00000010, 88 IRQ_TYPE_PROBE = 0x00000010,
82 89
@@ -263,6 +270,11 @@ static inline void irqd_clr_chained_irq_inprogress(struct irq_data *d)
263 d->state_use_accessors &= ~IRQD_IRQ_INPROGRESS; 270 d->state_use_accessors &= ~IRQD_IRQ_INPROGRESS;
264} 271}
265 272
273static inline irq_hw_number_t irqd_to_hwirq(struct irq_data *d)
274{
275 return d->hwirq;
276}
277
266/** 278/**
267 * struct irq_chip - hardware interrupt chip descriptor 279 * struct irq_chip - hardware interrupt chip descriptor
268 * 280 *
diff --git a/include/linux/irqdomain.h b/include/linux/irqdomain.h
index ead4a4215797..c65740d76e66 100644
--- a/include/linux/irqdomain.h
+++ b/include/linux/irqdomain.h
@@ -42,12 +42,6 @@ struct of_device_id;
42/* Number of irqs reserved for a legacy isa controller */ 42/* Number of irqs reserved for a legacy isa controller */
43#define NUM_ISA_INTERRUPTS 16 43#define NUM_ISA_INTERRUPTS 16
44 44
45/* This type is the placeholder for a hardware interrupt number. It has to
46 * be big enough to enclose whatever representation is used by a given
47 * platform.
48 */
49typedef unsigned long irq_hw_number_t;
50
51/** 45/**
52 * struct irq_domain_ops - Methods for irq_domain objects 46 * struct irq_domain_ops - Methods for irq_domain objects
53 * @match: Match an interrupt controller device node to a host, returns 47 * @match: Match an interrupt controller device node to a host, returns
@@ -104,6 +98,9 @@ struct irq_domain {
104 unsigned int size; 98 unsigned int size;
105 unsigned int *revmap; 99 unsigned int *revmap;
106 } linear; 100 } linear;
101 struct {
102 unsigned int max_irq;
103 } nomap;
107 struct radix_tree_root tree; 104 struct radix_tree_root tree;
108 } revmap_data; 105 } revmap_data;
109 const struct irq_domain_ops *ops; 106 const struct irq_domain_ops *ops;
@@ -126,6 +123,7 @@ struct irq_domain *irq_domain_add_linear(struct device_node *of_node,
126 const struct irq_domain_ops *ops, 123 const struct irq_domain_ops *ops,
127 void *host_data); 124 void *host_data);
128struct irq_domain *irq_domain_add_nomap(struct device_node *of_node, 125struct irq_domain *irq_domain_add_nomap(struct device_node *of_node,
126 unsigned int max_irq,
129 const struct irq_domain_ops *ops, 127 const struct irq_domain_ops *ops,
130 void *host_data); 128 void *host_data);
131struct irq_domain *irq_domain_add_tree(struct device_node *of_node, 129struct irq_domain *irq_domain_add_tree(struct device_node *of_node,
@@ -134,7 +132,6 @@ struct irq_domain *irq_domain_add_tree(struct device_node *of_node,
134 132
135extern struct irq_domain *irq_find_host(struct device_node *node); 133extern struct irq_domain *irq_find_host(struct device_node *node);
136extern void irq_set_default_host(struct irq_domain *host); 134extern void irq_set_default_host(struct irq_domain *host);
137extern void irq_set_virq_count(unsigned int count);
138 135
139static inline struct irq_domain *irq_domain_add_legacy_isa( 136static inline struct irq_domain *irq_domain_add_legacy_isa(
140 struct device_node *of_node, 137 struct device_node *of_node,
@@ -146,7 +143,6 @@ static inline struct irq_domain *irq_domain_add_legacy_isa(
146} 143}
147extern struct irq_domain *irq_find_host(struct device_node *node); 144extern struct irq_domain *irq_find_host(struct device_node *node);
148extern void irq_set_default_host(struct irq_domain *host); 145extern void irq_set_default_host(struct irq_domain *host);
149extern void irq_set_virq_count(unsigned int count);
150 146
151 147
152extern unsigned int irq_create_mapping(struct irq_domain *host, 148extern unsigned int irq_create_mapping(struct irq_domain *host,
diff --git a/include/linux/kconfig.h b/include/linux/kconfig.h
index 067eda0e4b32..be342b94c640 100644
--- a/include/linux/kconfig.h
+++ b/include/linux/kconfig.h
@@ -4,29 +4,43 @@
4#include <generated/autoconf.h> 4#include <generated/autoconf.h>
5 5
6/* 6/*
7 * Helper macros to use CONFIG_ options in C expressions. Note that 7 * Helper macros to use CONFIG_ options in C/CPP expressions. Note that
8 * these only work with boolean and tristate options. 8 * these only work with boolean and tristate options.
9 */ 9 */
10 10
11/* 11/*
12 * Getting something that works in C and CPP for an arg that may or may
13 * not be defined is tricky. Here, if we have "#define CONFIG_BOOGER 1"
14 * we match on the placeholder define, insert the "0," for arg1 and generate
15 * the triplet (0, 1, 0). Then the last step cherry picks the 2nd arg (a one).
16 * When CONFIG_BOOGER is not defined, we generate a (... 1, 0) pair, and when
17 * the last step cherry picks the 2nd arg, we get a zero.
18 */
19#define __ARG_PLACEHOLDER_1 0,
20#define config_enabled(cfg) _config_enabled(cfg)
21#define _config_enabled(value) __config_enabled(__ARG_PLACEHOLDER_##value)
22#define __config_enabled(arg1_or_junk) ___config_enabled(arg1_or_junk 1, 0)
23#define ___config_enabled(__ignored, val, ...) val
24
25/*
12 * IS_ENABLED(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'y' or 'm', 26 * IS_ENABLED(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'y' or 'm',
13 * 0 otherwise. 27 * 0 otherwise.
14 * 28 *
15 */ 29 */
16#define IS_ENABLED(option) \ 30#define IS_ENABLED(option) \
17 (__enabled_ ## option || __enabled_ ## option ## _MODULE) 31 (config_enabled(option) || config_enabled(option##_MODULE))
18 32
19/* 33/*
20 * IS_BUILTIN(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'y', 0 34 * IS_BUILTIN(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'y', 0
21 * otherwise. For boolean options, this is equivalent to 35 * otherwise. For boolean options, this is equivalent to
22 * IS_ENABLED(CONFIG_FOO). 36 * IS_ENABLED(CONFIG_FOO).
23 */ 37 */
24#define IS_BUILTIN(option) __enabled_ ## option 38#define IS_BUILTIN(option) config_enabled(option)
25 39
26/* 40/*
27 * IS_MODULE(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'm', 0 41 * IS_MODULE(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'm', 0
28 * otherwise. 42 * otherwise.
29 */ 43 */
30#define IS_MODULE(option) __enabled_ ## option ## _MODULE 44#define IS_MODULE(option) config_enabled(option##_MODULE)
31 45
32#endif /* __LINUX_KCONFIG_H */ 46#endif /* __LINUX_KCONFIG_H */
diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
index fa391835508d..c4d2fc194ede 100644
--- a/include/linux/kgdb.h
+++ b/include/linux/kgdb.h
@@ -63,7 +63,8 @@ enum kgdb_bptype {
63 BP_HARDWARE_BREAKPOINT, 63 BP_HARDWARE_BREAKPOINT,
64 BP_WRITE_WATCHPOINT, 64 BP_WRITE_WATCHPOINT,
65 BP_READ_WATCHPOINT, 65 BP_READ_WATCHPOINT,
66 BP_ACCESS_WATCHPOINT 66 BP_ACCESS_WATCHPOINT,
67 BP_POKE_BREAKPOINT,
67}; 68};
68 69
69enum kgdb_bpstate { 70enum kgdb_bpstate {
@@ -207,8 +208,8 @@ extern void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long pc);
207 208
208/* Optional functions. */ 209/* Optional functions. */
209extern int kgdb_validate_break_address(unsigned long addr); 210extern int kgdb_validate_break_address(unsigned long addr);
210extern int kgdb_arch_set_breakpoint(unsigned long addr, char *saved_instr); 211extern int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt);
211extern int kgdb_arch_remove_breakpoint(unsigned long addr, char *bundle); 212extern int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt);
212 213
213/** 214/**
214 * kgdb_arch_late - Perform any architecture specific initalization. 215 * kgdb_arch_late - Perform any architecture specific initalization.
diff --git a/include/linux/kmod.h b/include/linux/kmod.h
index 9efeae679106..dd99c329e161 100644
--- a/include/linux/kmod.h
+++ b/include/linux/kmod.h
@@ -110,12 +110,29 @@ call_usermodehelper(char *path, char **argv, char **envp, int wait)
110 110
111extern struct ctl_table usermodehelper_table[]; 111extern struct ctl_table usermodehelper_table[];
112 112
113enum umh_disable_depth {
114 UMH_ENABLED = 0,
115 UMH_FREEZING,
116 UMH_DISABLED,
117};
118
113extern void usermodehelper_init(void); 119extern void usermodehelper_init(void);
114 120
115extern int usermodehelper_disable(void); 121extern int __usermodehelper_disable(enum umh_disable_depth depth);
116extern void usermodehelper_enable(void); 122extern void __usermodehelper_set_disable_depth(enum umh_disable_depth depth);
117extern bool usermodehelper_is_disabled(void); 123
118extern void read_lock_usermodehelper(void); 124static inline int usermodehelper_disable(void)
119extern void read_unlock_usermodehelper(void); 125{
126 return __usermodehelper_disable(UMH_DISABLED);
127}
128
129static inline void usermodehelper_enable(void)
130{
131 __usermodehelper_set_disable_depth(UMH_ENABLED);
132}
133
134extern int usermodehelper_read_trylock(void);
135extern long usermodehelper_read_lock_wait(long timeout);
136extern void usermodehelper_read_unlock(void);
120 137
121#endif /* __LINUX_KMOD_H__ */ 138#endif /* __LINUX_KMOD_H__ */
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 665a260c7e09..72cbf08d45fb 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -596,6 +596,7 @@ void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id);
596 596
597#ifdef CONFIG_IOMMU_API 597#ifdef CONFIG_IOMMU_API
598int kvm_iommu_map_pages(struct kvm *kvm, struct kvm_memory_slot *slot); 598int kvm_iommu_map_pages(struct kvm *kvm, struct kvm_memory_slot *slot);
599void kvm_iommu_unmap_pages(struct kvm *kvm, struct kvm_memory_slot *slot);
599int kvm_iommu_map_guest(struct kvm *kvm); 600int kvm_iommu_map_guest(struct kvm *kvm);
600int kvm_iommu_unmap_guest(struct kvm *kvm); 601int kvm_iommu_unmap_guest(struct kvm *kvm);
601int kvm_assign_device(struct kvm *kvm, 602int kvm_assign_device(struct kvm *kvm,
@@ -609,6 +610,11 @@ static inline int kvm_iommu_map_pages(struct kvm *kvm,
609 return 0; 610 return 0;
610} 611}
611 612
613static inline void kvm_iommu_unmap_pages(struct kvm *kvm,
614 struct kvm_memory_slot *slot)
615{
616}
617
612static inline int kvm_iommu_map_guest(struct kvm *kvm) 618static inline int kvm_iommu_map_guest(struct kvm *kvm)
613{ 619{
614 return -ENODEV; 620 return -ENODEV;
diff --git a/include/linux/libata.h b/include/linux/libata.h
index 42378d637ffb..e926df7b54c9 100644
--- a/include/linux/libata.h
+++ b/include/linux/libata.h
@@ -996,7 +996,8 @@ extern int ata_sas_scsi_ioctl(struct ata_port *ap, struct scsi_device *dev,
996extern void ata_sas_port_destroy(struct ata_port *); 996extern void ata_sas_port_destroy(struct ata_port *);
997extern struct ata_port *ata_sas_port_alloc(struct ata_host *, 997extern struct ata_port *ata_sas_port_alloc(struct ata_host *,
998 struct ata_port_info *, struct Scsi_Host *); 998 struct ata_port_info *, struct Scsi_Host *);
999extern int ata_sas_async_port_init(struct ata_port *); 999extern void ata_sas_async_probe(struct ata_port *ap);
1000extern int ata_sas_sync_probe(struct ata_port *ap);
1000extern int ata_sas_port_init(struct ata_port *); 1001extern int ata_sas_port_init(struct ata_port *);
1001extern int ata_sas_port_start(struct ata_port *ap); 1002extern int ata_sas_port_start(struct ata_port *ap);
1002extern void ata_sas_port_stop(struct ata_port *ap); 1003extern void ata_sas_port_stop(struct ata_port *ap);
diff --git a/include/linux/lsm_audit.h b/include/linux/lsm_audit.h
index eab507f2b1cb..fad48aab893b 100644
--- a/include/linux/lsm_audit.h
+++ b/include/linux/lsm_audit.h
@@ -22,6 +22,23 @@
22#include <linux/key.h> 22#include <linux/key.h>
23#include <linux/skbuff.h> 23#include <linux/skbuff.h>
24 24
25struct lsm_network_audit {
26 int netif;
27 struct sock *sk;
28 u16 family;
29 __be16 dport;
30 __be16 sport;
31 union {
32 struct {
33 __be32 daddr;
34 __be32 saddr;
35 } v4;
36 struct {
37 struct in6_addr daddr;
38 struct in6_addr saddr;
39 } v6;
40 } fam;
41};
25 42
26/* Auxiliary data to use in generating the audit record. */ 43/* Auxiliary data to use in generating the audit record. */
27struct common_audit_data { 44struct common_audit_data {
@@ -41,23 +58,7 @@ struct common_audit_data {
41 struct path path; 58 struct path path;
42 struct dentry *dentry; 59 struct dentry *dentry;
43 struct inode *inode; 60 struct inode *inode;
44 struct { 61 struct lsm_network_audit *net;
45 int netif;
46 struct sock *sk;
47 u16 family;
48 __be16 dport;
49 __be16 sport;
50 union {
51 struct {
52 __be32 daddr;
53 __be32 saddr;
54 } v4;
55 struct {
56 struct in6_addr daddr;
57 struct in6_addr saddr;
58 } v6;
59 } fam;
60 } net;
61 int cap; 62 int cap;
62 int ipc_id; 63 int ipc_id;
63 struct task_struct *tsk; 64 struct task_struct *tsk;
@@ -72,64 +73,15 @@ struct common_audit_data {
72 /* this union contains LSM specific data */ 73 /* this union contains LSM specific data */
73 union { 74 union {
74#ifdef CONFIG_SECURITY_SMACK 75#ifdef CONFIG_SECURITY_SMACK
75 /* SMACK data */ 76 struct smack_audit_data *smack_audit_data;
76 struct smack_audit_data {
77 const char *function;
78 char *subject;
79 char *object;
80 char *request;
81 int result;
82 } smack_audit_data;
83#endif 77#endif
84#ifdef CONFIG_SECURITY_SELINUX 78#ifdef CONFIG_SECURITY_SELINUX
85 /* SELinux data */ 79 struct selinux_audit_data *selinux_audit_data;
86 struct {
87 u32 ssid;
88 u32 tsid;
89 u16 tclass;
90 u32 requested;
91 u32 audited;
92 u32 denied;
93 /*
94 * auditdeny is a bit tricky and unintuitive. See the
95 * comments in avc.c for it's meaning and usage.
96 */
97 u32 auditdeny;
98 struct av_decision *avd;
99 int result;
100 } selinux_audit_data;
101#endif 80#endif
102#ifdef CONFIG_SECURITY_APPARMOR 81#ifdef CONFIG_SECURITY_APPARMOR
103 struct { 82 struct apparmor_audit_data *apparmor_audit_data;
104 int error;
105 int op;
106 int type;
107 void *profile;
108 const char *name;
109 const char *info;
110 union {
111 void *target;
112 struct {
113 long pos;
114 void *target;
115 } iface;
116 struct {
117 int rlim;
118 unsigned long max;
119 } rlim;
120 struct {
121 const char *target;
122 u32 request;
123 u32 denied;
124 uid_t ouid;
125 } fs;
126 };
127 } apparmor_audit_data;
128#endif 83#endif
129 }; 84 }; /* per LSM data pointer union */
130 /* these callback will be implemented by a specific LSM */
131 void (*lsm_pre_audit)(struct audit_buffer *, void *);
132 void (*lsm_post_audit)(struct audit_buffer *, void *);
133}; 85};
134 86
135#define v4info fam.v4 87#define v4info fam.v4
@@ -146,6 +98,8 @@ int ipv6_skb_to_auditdata(struct sk_buff *skb,
146 { memset((_d), 0, sizeof(struct common_audit_data)); \ 98 { memset((_d), 0, sizeof(struct common_audit_data)); \
147 (_d)->type = LSM_AUDIT_DATA_##_t; } 99 (_d)->type = LSM_AUDIT_DATA_##_t; }
148 100
149void common_lsm_audit(struct common_audit_data *a); 101void common_lsm_audit(struct common_audit_data *a,
102 void (*pre_audit)(struct audit_buffer *, void *),
103 void (*post_audit)(struct audit_buffer *, void *));
150 104
151#endif 105#endif
diff --git a/include/linux/mfd/db5500-prcmu.h b/include/linux/mfd/db5500-prcmu.h
index 9890687f582d..5a049dfaf153 100644
--- a/include/linux/mfd/db5500-prcmu.h
+++ b/include/linux/mfd/db5500-prcmu.h
@@ -8,41 +8,14 @@
8#ifndef __MFD_DB5500_PRCMU_H 8#ifndef __MFD_DB5500_PRCMU_H
9#define __MFD_DB5500_PRCMU_H 9#define __MFD_DB5500_PRCMU_H
10 10
11#ifdef CONFIG_MFD_DB5500_PRCMU 11static inline int prcmu_resetout(u8 resoutn, u8 state)
12
13void db5500_prcmu_early_init(void);
14int db5500_prcmu_set_epod(u16 epod_id, u8 epod_state);
15int db5500_prcmu_set_display_clocks(void);
16int db5500_prcmu_disable_dsipll(void);
17int db5500_prcmu_enable_dsipll(void);
18int db5500_prcmu_abb_read(u8 slave, u8 reg, u8 *value, u8 size);
19int db5500_prcmu_abb_write(u8 slave, u8 reg, u8 *value, u8 size);
20void db5500_prcmu_enable_wakeups(u32 wakeups);
21int db5500_prcmu_request_clock(u8 clock, bool enable);
22void db5500_prcmu_config_abb_event_readout(u32 abb_events);
23void db5500_prcmu_get_abb_event_buffer(void __iomem **buf);
24int prcmu_resetout(u8 resoutn, u8 state);
25int db5500_prcmu_set_power_state(u8 state, bool keep_ulp_clk,
26 bool keep_ap_pll);
27int db5500_prcmu_config_esram0_deep_sleep(u8 state);
28void db5500_prcmu_system_reset(u16 reset_code);
29u16 db5500_prcmu_get_reset_code(void);
30bool db5500_prcmu_is_ac_wake_requested(void);
31int db5500_prcmu_set_arm_opp(u8 opp);
32int db5500_prcmu_get_arm_opp(void);
33
34#else /* !CONFIG_UX500_SOC_DB5500 */
35
36static inline void db5500_prcmu_early_init(void) {}
37
38static inline int db5500_prcmu_abb_read(u8 slave, u8 reg, u8 *value, u8 size)
39{ 12{
40 return -ENOSYS; 13 return 0;
41} 14}
42 15
43static inline int db5500_prcmu_abb_write(u8 slave, u8 reg, u8 *value, u8 size) 16static inline int db5500_prcmu_set_epod(u16 epod_id, u8 epod_state)
44{ 17{
45 return -ENOSYS; 18 return 0;
46} 19}
47 20
48static inline int db5500_prcmu_request_clock(u8 clock, bool enable) 21static inline int db5500_prcmu_request_clock(u8 clock, bool enable)
@@ -50,69 +23,82 @@ static inline int db5500_prcmu_request_clock(u8 clock, bool enable)
50 return 0; 23 return 0;
51} 24}
52 25
53static inline int db5500_prcmu_set_display_clocks(void) 26static inline int db5500_prcmu_set_power_state(u8 state, bool keep_ulp_clk,
27 bool keep_ap_pll)
54{ 28{
55 return 0; 29 return 0;
56} 30}
57 31
58static inline int db5500_prcmu_disable_dsipll(void) 32static inline int db5500_prcmu_config_esram0_deep_sleep(u8 state)
59{ 33{
60 return 0; 34 return 0;
61} 35}
62 36
63static inline int db5500_prcmu_enable_dsipll(void) 37static inline u16 db5500_prcmu_get_reset_code(void)
64{ 38{
65 return 0; 39 return 0;
66} 40}
67 41
68static inline int db5500_prcmu_config_esram0_deep_sleep(u8 state) 42static inline bool db5500_prcmu_is_ac_wake_requested(void)
69{ 43{
70 return 0; 44 return 0;
71} 45}
72 46
73static inline void db5500_prcmu_enable_wakeups(u32 wakeups) {} 47static inline int db5500_prcmu_set_arm_opp(u8 opp)
74
75static inline int prcmu_resetout(u8 resoutn, u8 state)
76{ 48{
77 return 0; 49 return 0;
78} 50}
79 51
80static inline int db5500_prcmu_set_epod(u16 epod_id, u8 epod_state) 52static inline int db5500_prcmu_get_arm_opp(void)
81{ 53{
82 return 0; 54 return 0;
83} 55}
84 56
85static inline void db5500_prcmu_get_abb_event_buffer(void __iomem **buf) {}
86static inline void db5500_prcmu_config_abb_event_readout(u32 abb_events) {} 57static inline void db5500_prcmu_config_abb_event_readout(u32 abb_events) {}
87 58
88static inline int db5500_prcmu_set_power_state(u8 state, bool keep_ulp_clk, 59static inline void db5500_prcmu_get_abb_event_buffer(void __iomem **buf) {}
89 bool keep_ap_pll)
90{
91 return 0;
92}
93 60
94static inline void db5500_prcmu_system_reset(u16 reset_code) {} 61static inline void db5500_prcmu_system_reset(u16 reset_code) {}
95 62
96static inline u16 db5500_prcmu_get_reset_code(void) 63static inline void db5500_prcmu_enable_wakeups(u32 wakeups) {}
64
65#ifdef CONFIG_MFD_DB5500_PRCMU
66
67void db5500_prcmu_early_init(void);
68int db5500_prcmu_set_display_clocks(void);
69int db5500_prcmu_disable_dsipll(void);
70int db5500_prcmu_enable_dsipll(void);
71int db5500_prcmu_abb_read(u8 slave, u8 reg, u8 *value, u8 size);
72int db5500_prcmu_abb_write(u8 slave, u8 reg, u8 *value, u8 size);
73
74#else /* !CONFIG_UX500_SOC_DB5500 */
75
76static inline void db5500_prcmu_early_init(void) {}
77
78static inline int db5500_prcmu_abb_read(u8 slave, u8 reg, u8 *value, u8 size)
97{ 79{
98 return 0; 80 return -ENOSYS;
99} 81}
100 82
101static inline bool db5500_prcmu_is_ac_wake_requested(void) 83static inline int db5500_prcmu_abb_write(u8 slave, u8 reg, u8 *value, u8 size)
102{ 84{
103 return 0; 85 return -ENOSYS;
104} 86}
105 87
106static inline int db5500_prcmu_set_arm_opp(u8 opp) 88static inline int db5500_prcmu_set_display_clocks(void)
107{ 89{
108 return 0; 90 return 0;
109} 91}
110 92
111static inline int db5500_prcmu_get_arm_opp(void) 93static inline int db5500_prcmu_disable_dsipll(void)
112{ 94{
113 return 0; 95 return 0;
114} 96}
115 97
98static inline int db5500_prcmu_enable_dsipll(void)
99{
100 return 0;
101}
116 102
117#endif /* CONFIG_MFD_DB5500_PRCMU */ 103#endif /* CONFIG_MFD_DB5500_PRCMU */
118 104
diff --git a/include/linux/mfd/mc13xxx.h b/include/linux/mfd/mc13xxx.h
index 10e038bac8dd..bf070755982e 100644
--- a/include/linux/mfd/mc13xxx.h
+++ b/include/linux/mfd/mc13xxx.h
@@ -170,6 +170,16 @@ struct mc13xxx_ts_platform_data {
170 bool atox; 170 bool atox;
171}; 171};
172 172
173enum mc13783_ssi_port {
174 MC13783_SSI1_PORT,
175 MC13783_SSI2_PORT,
176};
177
178struct mc13xxx_codec_platform_data {
179 enum mc13783_ssi_port adc_ssi_port;
180 enum mc13783_ssi_port dac_ssi_port;
181};
182
173struct mc13xxx_platform_data { 183struct mc13xxx_platform_data {
174#define MC13XXX_USE_TOUCHSCREEN (1 << 0) 184#define MC13XXX_USE_TOUCHSCREEN (1 << 0)
175#define MC13XXX_USE_CODEC (1 << 1) 185#define MC13XXX_USE_CODEC (1 << 1)
@@ -181,6 +191,7 @@ struct mc13xxx_platform_data {
181 struct mc13xxx_leds_platform_data *leds; 191 struct mc13xxx_leds_platform_data *leds;
182 struct mc13xxx_buttons_platform_data *buttons; 192 struct mc13xxx_buttons_platform_data *buttons;
183 struct mc13xxx_ts_platform_data touch; 193 struct mc13xxx_ts_platform_data touch;
194 struct mc13xxx_codec_platform_data *codec;
184}; 195};
185 196
186#define MC13XXX_ADC_MODE_TS 1 197#define MC13XXX_ADC_MODE_TS 1
diff --git a/include/linux/mfd/rc5t583.h b/include/linux/mfd/rc5t583.h
index a2c61609d21d..0b64b19d81ab 100644
--- a/include/linux/mfd/rc5t583.h
+++ b/include/linux/mfd/rc5t583.h
@@ -26,6 +26,7 @@
26 26
27#include <linux/mutex.h> 27#include <linux/mutex.h>
28#include <linux/types.h> 28#include <linux/types.h>
29#include <linux/regmap.h>
29 30
30#define RC5T583_MAX_REGS 0xF8 31#define RC5T583_MAX_REGS 0xF8
31 32
@@ -279,14 +280,44 @@ struct rc5t583_platform_data {
279 bool enable_shutdown; 280 bool enable_shutdown;
280}; 281};
281 282
282int rc5t583_write(struct device *dev, u8 reg, uint8_t val); 283static inline int rc5t583_write(struct device *dev, uint8_t reg, uint8_t val)
283int rc5t583_read(struct device *dev, uint8_t reg, uint8_t *val); 284{
284int rc5t583_set_bits(struct device *dev, unsigned int reg, 285 struct rc5t583 *rc5t583 = dev_get_drvdata(dev);
285 unsigned int bit_mask); 286 return regmap_write(rc5t583->regmap, reg, val);
286int rc5t583_clear_bits(struct device *dev, unsigned int reg, 287}
287 unsigned int bit_mask); 288
288int rc5t583_update(struct device *dev, unsigned int reg, 289static inline int rc5t583_read(struct device *dev, uint8_t reg, uint8_t *val)
289 unsigned int val, unsigned int mask); 290{
291 struct rc5t583 *rc5t583 = dev_get_drvdata(dev);
292 unsigned int ival;
293 int ret;
294 ret = regmap_read(rc5t583->regmap, reg, &ival);
295 if (!ret)
296 *val = (uint8_t)ival;
297 return ret;
298}
299
300static inline int rc5t583_set_bits(struct device *dev, unsigned int reg,
301 unsigned int bit_mask)
302{
303 struct rc5t583 *rc5t583 = dev_get_drvdata(dev);
304 return regmap_update_bits(rc5t583->regmap, reg, bit_mask, bit_mask);
305}
306
307static inline int rc5t583_clear_bits(struct device *dev, unsigned int reg,
308 unsigned int bit_mask)
309{
310 struct rc5t583 *rc5t583 = dev_get_drvdata(dev);
311 return regmap_update_bits(rc5t583->regmap, reg, bit_mask, 0);
312}
313
314static inline int rc5t583_update(struct device *dev, unsigned int reg,
315 unsigned int val, unsigned int mask)
316{
317 struct rc5t583 *rc5t583 = dev_get_drvdata(dev);
318 return regmap_update_bits(rc5t583->regmap, reg, mask, val);
319}
320
290int rc5t583_ext_power_req_config(struct device *dev, int deepsleep_id, 321int rc5t583_ext_power_req_config(struct device *dev, int deepsleep_id,
291 int ext_pwr_req, int deepsleep_slot_nr); 322 int ext_pwr_req, int deepsleep_slot_nr);
292int rc5t583_irq_init(struct rc5t583 *rc5t583, int irq, int irq_base); 323int rc5t583_irq_init(struct rc5t583 *rc5t583, int irq, int irq_base);
diff --git a/include/linux/mfd/twl6040.h b/include/linux/mfd/twl6040.h
index 9bc9ac651dad..b15b5f03f5c4 100644
--- a/include/linux/mfd/twl6040.h
+++ b/include/linux/mfd/twl6040.h
@@ -174,8 +174,35 @@
174#define TWL6040_SYSCLK_SEL_LPPLL 0 174#define TWL6040_SYSCLK_SEL_LPPLL 0
175#define TWL6040_SYSCLK_SEL_HPPLL 1 175#define TWL6040_SYSCLK_SEL_HPPLL 1
176 176
177struct twl6040_codec_data {
178 u16 hs_left_step;
179 u16 hs_right_step;
180 u16 hf_left_step;
181 u16 hf_right_step;
182};
183
184struct twl6040_vibra_data {
185 unsigned int vibldrv_res; /* left driver resistance */
186 unsigned int vibrdrv_res; /* right driver resistance */
187 unsigned int viblmotor_res; /* left motor resistance */
188 unsigned int vibrmotor_res; /* right motor resistance */
189 int vddvibl_uV; /* VDDVIBL volt, set 0 for fixed reg */
190 int vddvibr_uV; /* VDDVIBR volt, set 0 for fixed reg */
191};
192
193struct twl6040_platform_data {
194 int audpwron_gpio; /* audio power-on gpio */
195 unsigned int irq_base;
196
197 struct twl6040_codec_data *codec;
198 struct twl6040_vibra_data *vibra;
199};
200
201struct regmap;
202
177struct twl6040 { 203struct twl6040 {
178 struct device *dev; 204 struct device *dev;
205 struct regmap *regmap;
179 struct mutex mutex; 206 struct mutex mutex;
180 struct mutex io_mutex; 207 struct mutex io_mutex;
181 struct mutex irq_mutex; 208 struct mutex irq_mutex;
diff --git a/include/linux/mm.h b/include/linux/mm.h
index d8738a464b94..74aa71bea1e4 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -1393,29 +1393,20 @@ extern int install_special_mapping(struct mm_struct *mm,
1393 1393
1394extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long); 1394extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
1395 1395
1396extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
1397 unsigned long len, unsigned long prot,
1398 unsigned long flag, unsigned long pgoff);
1399extern unsigned long mmap_region(struct file *file, unsigned long addr, 1396extern unsigned long mmap_region(struct file *file, unsigned long addr,
1400 unsigned long len, unsigned long flags, 1397 unsigned long len, unsigned long flags,
1401 vm_flags_t vm_flags, unsigned long pgoff); 1398 vm_flags_t vm_flags, unsigned long pgoff);
1402 1399extern unsigned long do_mmap(struct file *, unsigned long,
1403static inline unsigned long do_mmap(struct file *file, unsigned long addr, 1400 unsigned long, unsigned long,
1404 unsigned long len, unsigned long prot, 1401 unsigned long, unsigned long);
1405 unsigned long flag, unsigned long offset)
1406{
1407 unsigned long ret = -EINVAL;
1408 if ((offset + PAGE_ALIGN(len)) < offset)
1409 goto out;
1410 if (!(offset & ~PAGE_MASK))
1411 ret = do_mmap_pgoff(file, addr, len, prot, flag, offset >> PAGE_SHIFT);
1412out:
1413 return ret;
1414}
1415
1416extern int do_munmap(struct mm_struct *, unsigned long, size_t); 1402extern int do_munmap(struct mm_struct *, unsigned long, size_t);
1417 1403
1418extern unsigned long do_brk(unsigned long, unsigned long); 1404/* These take the mm semaphore themselves */
1405extern unsigned long vm_brk(unsigned long, unsigned long);
1406extern int vm_munmap(unsigned long, size_t);
1407extern unsigned long vm_mmap(struct file *, unsigned long,
1408 unsigned long, unsigned long,
1409 unsigned long, unsigned long);
1419 1410
1420/* truncate.c */ 1411/* truncate.c */
1421extern void truncate_inode_pages(struct address_space *, loff_t); 1412extern void truncate_inode_pages(struct address_space *, loff_t);
diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h
index 01beae78f079..629b823f8836 100644
--- a/include/linux/mmc/card.h
+++ b/include/linux/mmc/card.h
@@ -481,7 +481,7 @@ struct mmc_driver {
481 struct device_driver drv; 481 struct device_driver drv;
482 int (*probe)(struct mmc_card *); 482 int (*probe)(struct mmc_card *);
483 void (*remove)(struct mmc_card *); 483 void (*remove)(struct mmc_card *);
484 int (*suspend)(struct mmc_card *, pm_message_t); 484 int (*suspend)(struct mmc_card *);
485 int (*resume)(struct mmc_card *); 485 int (*resume)(struct mmc_card *);
486}; 486};
487 487
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 1f77540bdc95..33900a53c990 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -1403,15 +1403,6 @@ static inline bool netdev_uses_dsa_tags(struct net_device *dev)
1403 return 0; 1403 return 0;
1404} 1404}
1405 1405
1406#ifndef CONFIG_NET_NS
1407static inline void skb_set_dev(struct sk_buff *skb, struct net_device *dev)
1408{
1409 skb->dev = dev;
1410}
1411#else /* CONFIG_NET_NS */
1412void skb_set_dev(struct sk_buff *skb, struct net_device *dev);
1413#endif
1414
1415static inline bool netdev_uses_trailer_tags(struct net_device *dev) 1406static inline bool netdev_uses_trailer_tags(struct net_device *dev)
1416{ 1407{
1417#ifdef CONFIG_NET_DSA_TAG_TRAILER 1408#ifdef CONFIG_NET_DSA_TAG_TRAILER
@@ -2604,8 +2595,6 @@ extern void net_disable_timestamp(void);
2604extern void *dev_seq_start(struct seq_file *seq, loff_t *pos); 2595extern void *dev_seq_start(struct seq_file *seq, loff_t *pos);
2605extern void *dev_seq_next(struct seq_file *seq, void *v, loff_t *pos); 2596extern void *dev_seq_next(struct seq_file *seq, void *v, loff_t *pos);
2606extern void dev_seq_stop(struct seq_file *seq, void *v); 2597extern void dev_seq_stop(struct seq_file *seq, void *v);
2607extern int dev_seq_open_ops(struct inode *inode, struct file *file,
2608 const struct seq_operations *ops);
2609#endif 2598#endif
2610 2599
2611extern int netdev_class_create_file(struct class_attribute *class_attr); 2600extern int netdev_class_create_file(struct class_attribute *class_attr);
diff --git a/include/linux/netfilter/xt_set.h b/include/linux/netfilter/xt_set.h
index c0405ac92870..e3a9978f259f 100644
--- a/include/linux/netfilter/xt_set.h
+++ b/include/linux/netfilter/xt_set.h
@@ -58,8 +58,8 @@ struct xt_set_info_target_v1 {
58struct xt_set_info_target_v2 { 58struct xt_set_info_target_v2 {
59 struct xt_set_info add_set; 59 struct xt_set_info add_set;
60 struct xt_set_info del_set; 60 struct xt_set_info del_set;
61 u32 flags; 61 __u32 flags;
62 u32 timeout; 62 __u32 timeout;
63}; 63};
64 64
65#endif /*_XT_SET_H*/ 65#endif /*_XT_SET_H*/
diff --git a/include/linux/netfilter_bridge.h b/include/linux/netfilter_bridge.h
index 0ddd161f3b06..31d2844e6572 100644
--- a/include/linux/netfilter_bridge.h
+++ b/include/linux/netfilter_bridge.h
@@ -104,9 +104,18 @@ struct bridge_skb_cb {
104 } daddr; 104 } daddr;
105}; 105};
106 106
107static inline void br_drop_fake_rtable(struct sk_buff *skb)
108{
109 struct dst_entry *dst = skb_dst(skb);
110
111 if (dst && (dst->flags & DST_FAKE_RTABLE))
112 skb_dst_drop(skb);
113}
114
107#else 115#else
108#define nf_bridge_maybe_copy_header(skb) (0) 116#define nf_bridge_maybe_copy_header(skb) (0)
109#define nf_bridge_pad(skb) (0) 117#define nf_bridge_pad(skb) (0)
118#define br_drop_fake_rtable(skb) do { } while (0)
110#endif /* CONFIG_BRIDGE_NETFILTER */ 119#endif /* CONFIG_BRIDGE_NETFILTER */
111 120
112#endif /* __KERNEL__ */ 121#endif /* __KERNEL__ */
diff --git a/include/linux/netfilter_ipv6/ip6_tables.h b/include/linux/netfilter_ipv6/ip6_tables.h
index f549adccc94c..1bc898b14a80 100644
--- a/include/linux/netfilter_ipv6/ip6_tables.h
+++ b/include/linux/netfilter_ipv6/ip6_tables.h
@@ -287,7 +287,17 @@ extern unsigned int ip6t_do_table(struct sk_buff *skb,
287 struct xt_table *table); 287 struct xt_table *table);
288 288
289/* Check for an extension */ 289/* Check for an extension */
290extern int ip6t_ext_hdr(u8 nexthdr); 290static inline int
291ip6t_ext_hdr(u8 nexthdr)
292{ return (nexthdr == IPPROTO_HOPOPTS) ||
293 (nexthdr == IPPROTO_ROUTING) ||
294 (nexthdr == IPPROTO_FRAGMENT) ||
295 (nexthdr == IPPROTO_ESP) ||
296 (nexthdr == IPPROTO_AH) ||
297 (nexthdr == IPPROTO_NONE) ||
298 (nexthdr == IPPROTO_DSTOPTS);
299}
300
291/* find specified header and get offset to it */ 301/* find specified header and get offset to it */
292extern int ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset, 302extern int ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset,
293 int target, unsigned short *fragoff); 303 int target, unsigned short *fragoff);
diff --git a/include/linux/nfs_xdr.h b/include/linux/nfs_xdr.h
index bfd0d1bf6707..7ba3551a0414 100644
--- a/include/linux/nfs_xdr.h
+++ b/include/linux/nfs_xdr.h
@@ -312,6 +312,11 @@ struct nfs4_layoutreturn {
312 int rpc_status; 312 int rpc_status;
313}; 313};
314 314
315struct stateowner_id {
316 __u64 create_time;
317 __u32 uniquifier;
318};
319
315/* 320/*
316 * Arguments to the open call. 321 * Arguments to the open call.
317 */ 322 */
@@ -321,7 +326,7 @@ struct nfs_openargs {
321 int open_flags; 326 int open_flags;
322 fmode_t fmode; 327 fmode_t fmode;
323 __u64 clientid; 328 __u64 clientid;
324 __u64 id; 329 struct stateowner_id id;
325 union { 330 union {
326 struct { 331 struct {
327 struct iattr * attrs; /* UNCHECKED, GUARDED */ 332 struct iattr * attrs; /* UNCHECKED, GUARDED */
diff --git a/include/linux/nfsd/Kbuild b/include/linux/nfsd/Kbuild
index b8d4001212b3..5b7d84ac954a 100644
--- a/include/linux/nfsd/Kbuild
+++ b/include/linux/nfsd/Kbuild
@@ -1,3 +1,4 @@
1header-y += cld.h
1header-y += debug.h 2header-y += debug.h
2header-y += export.h 3header-y += export.h
3header-y += nfsfh.h 4header-y += nfsfh.h
diff --git a/include/linux/pinctrl/machine.h b/include/linux/pinctrl/machine.h
index fee4349364f7..e4d1de742502 100644
--- a/include/linux/pinctrl/machine.h
+++ b/include/linux/pinctrl/machine.h
@@ -12,6 +12,8 @@
12#ifndef __LINUX_PINCTRL_MACHINE_H 12#ifndef __LINUX_PINCTRL_MACHINE_H
13#define __LINUX_PINCTRL_MACHINE_H 13#define __LINUX_PINCTRL_MACHINE_H
14 14
15#include <linux/bug.h>
16
15#include "pinctrl-state.h" 17#include "pinctrl-state.h"
16 18
17enum pinctrl_map_type { 19enum pinctrl_map_type {
@@ -148,7 +150,7 @@ struct pinctrl_map {
148#define PIN_MAP_CONFIGS_GROUP_HOG_DEFAULT(dev, grp, cfgs) \ 150#define PIN_MAP_CONFIGS_GROUP_HOG_DEFAULT(dev, grp, cfgs) \
149 PIN_MAP_CONFIGS_GROUP(dev, PINCTRL_STATE_DEFAULT, dev, grp, cfgs) 151 PIN_MAP_CONFIGS_GROUP(dev, PINCTRL_STATE_DEFAULT, dev, grp, cfgs)
150 152
151#ifdef CONFIG_PINMUX 153#ifdef CONFIG_PINCTRL
152 154
153extern int pinctrl_register_mappings(struct pinctrl_map const *map, 155extern int pinctrl_register_mappings(struct pinctrl_map const *map,
154 unsigned num_maps); 156 unsigned num_maps);
diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
index 6d626ff0cfd0..e1ac1ce16fb0 100644
--- a/include/linux/pipe_fs_i.h
+++ b/include/linux/pipe_fs_i.h
@@ -6,6 +6,7 @@
6#define PIPE_BUF_FLAG_LRU 0x01 /* page is on the LRU */ 6#define PIPE_BUF_FLAG_LRU 0x01 /* page is on the LRU */
7#define PIPE_BUF_FLAG_ATOMIC 0x02 /* was atomically mapped */ 7#define PIPE_BUF_FLAG_ATOMIC 0x02 /* was atomically mapped */
8#define PIPE_BUF_FLAG_GIFT 0x04 /* page is a gift */ 8#define PIPE_BUF_FLAG_GIFT 0x04 /* page is a gift */
9#define PIPE_BUF_FLAG_PACKET 0x08 /* read() as a packet */
9 10
10/** 11/**
11 * struct pipe_buffer - a linux kernel pipe buffer 12 * struct pipe_buffer - a linux kernel pipe buffer
diff --git a/include/linux/platform_data/atmel.h b/include/linux/platform_data/atmel.h
index d056263545b1..b0f2c56a8ea2 100644
--- a/include/linux/platform_data/atmel.h
+++ b/include/linux/platform_data/atmel.h
@@ -4,8 +4,8 @@
4 * GPL v2 Only 4 * GPL v2 Only
5 */ 5 */
6 6
7#ifndef __ATMEL_NAND_H__ 7#ifndef __ATMEL_H__
8#define __ATMEL_NAND_H__ 8#define __ATMEL_H__
9 9
10#include <linux/mtd/nand.h> 10#include <linux/mtd/nand.h>
11 11
@@ -24,4 +24,4 @@ struct atmel_nand_data {
24 unsigned int num_parts; 24 unsigned int num_parts;
25}; 25};
26 26
27#endif /* __ATMEL_NAND_H__ */ 27#endif /* __ATMEL_H__ */
diff --git a/include/linux/pm_qos.h b/include/linux/pm_qos.h
index 2e9191a712f3..233149cb19f4 100644
--- a/include/linux/pm_qos.h
+++ b/include/linux/pm_qos.h
@@ -8,6 +8,7 @@
8#include <linux/notifier.h> 8#include <linux/notifier.h>
9#include <linux/miscdevice.h> 9#include <linux/miscdevice.h>
10#include <linux/device.h> 10#include <linux/device.h>
11#include <linux/workqueue.h>
11 12
12enum { 13enum {
13 PM_QOS_RESERVED = 0, 14 PM_QOS_RESERVED = 0,
@@ -29,6 +30,7 @@ enum {
29struct pm_qos_request { 30struct pm_qos_request {
30 struct plist_node node; 31 struct plist_node node;
31 int pm_qos_class; 32 int pm_qos_class;
33 struct delayed_work work; /* for pm_qos_update_request_timeout */
32}; 34};
33 35
34struct dev_pm_qos_request { 36struct dev_pm_qos_request {
@@ -73,6 +75,8 @@ void pm_qos_add_request(struct pm_qos_request *req, int pm_qos_class,
73 s32 value); 75 s32 value);
74void pm_qos_update_request(struct pm_qos_request *req, 76void pm_qos_update_request(struct pm_qos_request *req,
75 s32 new_value); 77 s32 new_value);
78void pm_qos_update_request_timeout(struct pm_qos_request *req,
79 s32 new_value, unsigned long timeout_us);
76void pm_qos_remove_request(struct pm_qos_request *req); 80void pm_qos_remove_request(struct pm_qos_request *req);
77 81
78int pm_qos_request(int pm_qos_class); 82int pm_qos_request(int pm_qos_class);
diff --git a/include/linux/regmap.h b/include/linux/regmap.h
index a90abb6bfa64..0258bcd6258d 100644
--- a/include/linux/regmap.h
+++ b/include/linux/regmap.h
@@ -46,7 +46,13 @@ struct reg_default {
46/** 46/**
47 * Configuration for the register map of a device. 47 * Configuration for the register map of a device.
48 * 48 *
49 * @name: Optional name of the regmap. Useful when a device has multiple
50 * register regions.
51 *
49 * @reg_bits: Number of bits in a register address, mandatory. 52 * @reg_bits: Number of bits in a register address, mandatory.
53 * @reg_stride: The register address stride. Valid register addresses are a
54 * multiple of this value. If set to 0, a value of 1 will be
55 * used.
50 * @pad_bits: Number of bits of padding between register and value. 56 * @pad_bits: Number of bits of padding between register and value.
51 * @val_bits: Number of bits in a register value, mandatory. 57 * @val_bits: Number of bits in a register value, mandatory.
52 * 58 *
@@ -77,7 +83,10 @@ struct reg_default {
77 * @num_reg_defaults_raw: Number of elements in reg_defaults_raw. 83 * @num_reg_defaults_raw: Number of elements in reg_defaults_raw.
78 */ 84 */
79struct regmap_config { 85struct regmap_config {
86 const char *name;
87
80 int reg_bits; 88 int reg_bits;
89 int reg_stride;
81 int pad_bits; 90 int pad_bits;
82 int val_bits; 91 int val_bits;
83 92
@@ -97,18 +106,21 @@ struct regmap_config {
97 u8 write_flag_mask; 106 u8 write_flag_mask;
98}; 107};
99 108
100typedef int (*regmap_hw_write)(struct device *dev, const void *data, 109typedef int (*regmap_hw_write)(void *context, const void *data,
101 size_t count); 110 size_t count);
102typedef int (*regmap_hw_gather_write)(struct device *dev, 111typedef int (*regmap_hw_gather_write)(void *context,
103 const void *reg, size_t reg_len, 112 const void *reg, size_t reg_len,
104 const void *val, size_t val_len); 113 const void *val, size_t val_len);
105typedef int (*regmap_hw_read)(struct device *dev, 114typedef int (*regmap_hw_read)(void *context,
106 const void *reg_buf, size_t reg_size, 115 const void *reg_buf, size_t reg_size,
107 void *val_buf, size_t val_size); 116 void *val_buf, size_t val_size);
117typedef void (*regmap_hw_free_context)(void *context);
108 118
109/** 119/**
110 * Description of a hardware bus for the register map infrastructure. 120 * Description of a hardware bus for the register map infrastructure.
111 * 121 *
122 * @fast_io: Register IO is fast. Use a spinlock instead of a mutex
123 * to perform locking.
112 * @write: Write operation. 124 * @write: Write operation.
113 * @gather_write: Write operation with split register/value, return -ENOTSUPP 125 * @gather_write: Write operation with split register/value, return -ENOTSUPP
114 * if not implemented on a given device. 126 * if not implemented on a given device.
@@ -118,27 +130,37 @@ typedef int (*regmap_hw_read)(struct device *dev,
118 * a read. 130 * a read.
119 */ 131 */
120struct regmap_bus { 132struct regmap_bus {
133 bool fast_io;
121 regmap_hw_write write; 134 regmap_hw_write write;
122 regmap_hw_gather_write gather_write; 135 regmap_hw_gather_write gather_write;
123 regmap_hw_read read; 136 regmap_hw_read read;
137 regmap_hw_free_context free_context;
124 u8 read_flag_mask; 138 u8 read_flag_mask;
125}; 139};
126 140
127struct regmap *regmap_init(struct device *dev, 141struct regmap *regmap_init(struct device *dev,
128 const struct regmap_bus *bus, 142 const struct regmap_bus *bus,
143 void *bus_context,
129 const struct regmap_config *config); 144 const struct regmap_config *config);
130struct regmap *regmap_init_i2c(struct i2c_client *i2c, 145struct regmap *regmap_init_i2c(struct i2c_client *i2c,
131 const struct regmap_config *config); 146 const struct regmap_config *config);
132struct regmap *regmap_init_spi(struct spi_device *dev, 147struct regmap *regmap_init_spi(struct spi_device *dev,
133 const struct regmap_config *config); 148 const struct regmap_config *config);
149struct regmap *regmap_init_mmio(struct device *dev,
150 void __iomem *regs,
151 const struct regmap_config *config);
134 152
135struct regmap *devm_regmap_init(struct device *dev, 153struct regmap *devm_regmap_init(struct device *dev,
136 const struct regmap_bus *bus, 154 const struct regmap_bus *bus,
155 void *bus_context,
137 const struct regmap_config *config); 156 const struct regmap_config *config);
138struct regmap *devm_regmap_init_i2c(struct i2c_client *i2c, 157struct regmap *devm_regmap_init_i2c(struct i2c_client *i2c,
139 const struct regmap_config *config); 158 const struct regmap_config *config);
140struct regmap *devm_regmap_init_spi(struct spi_device *dev, 159struct regmap *devm_regmap_init_spi(struct spi_device *dev,
141 const struct regmap_config *config); 160 const struct regmap_config *config);
161struct regmap *devm_regmap_init_mmio(struct device *dev,
162 void __iomem *regs,
163 const struct regmap_config *config);
142 164
143void regmap_exit(struct regmap *map); 165void regmap_exit(struct regmap *map);
144int regmap_reinit_cache(struct regmap *map, 166int regmap_reinit_cache(struct regmap *map,
diff --git a/include/linux/regulator/machine.h b/include/linux/regulator/machine.h
index 7abb16093312..b02108446be7 100644
--- a/include/linux/regulator/machine.h
+++ b/include/linux/regulator/machine.h
@@ -71,7 +71,7 @@ struct regulator_state {
71 * @uV_offset: Offset applied to voltages from consumer to compensate for 71 * @uV_offset: Offset applied to voltages from consumer to compensate for
72 * voltage drops. 72 * voltage drops.
73 * 73 *
74 * @min_uA: Smallest consumers consumers may set. 74 * @min_uA: Smallest current consumers may set.
75 * @max_uA: Largest current consumers may set. 75 * @max_uA: Largest current consumers may set.
76 * 76 *
77 * @valid_modes_mask: Mask of modes which may be configured by consumers. 77 * @valid_modes_mask: Mask of modes which may be configured by consumers.
@@ -134,10 +134,8 @@ struct regulation_constraints {
134/** 134/**
135 * struct regulator_consumer_supply - supply -> device mapping 135 * struct regulator_consumer_supply - supply -> device mapping
136 * 136 *
137 * This maps a supply name to a device. Only one of dev or dev_name 137 * This maps a supply name to a device. Use of dev_name allows support for
138 * can be specified. Use of dev_name allows support for buses which 138 * buses which make struct device available late such as I2C.
139 * make struct device available late such as I2C and is the preferred
140 * form.
141 * 139 *
142 * @dev_name: Result of dev_name() for the consumer. 140 * @dev_name: Result of dev_name() for the consumer.
143 * @supply: Name for the supply. 141 * @supply: Name for the supply.
diff --git a/include/linux/seqlock.h b/include/linux/seqlock.h
index c6db9fb33c44..600060e25ec6 100644
--- a/include/linux/seqlock.h
+++ b/include/linux/seqlock.h
@@ -141,7 +141,7 @@ static inline unsigned __read_seqcount_begin(const seqcount_t *s)
141 unsigned ret; 141 unsigned ret;
142 142
143repeat: 143repeat:
144 ret = s->sequence; 144 ret = ACCESS_ONCE(s->sequence);
145 if (unlikely(ret & 1)) { 145 if (unlikely(ret & 1)) {
146 cpu_relax(); 146 cpu_relax();
147 goto repeat; 147 goto repeat;
@@ -166,6 +166,27 @@ static inline unsigned read_seqcount_begin(const seqcount_t *s)
166} 166}
167 167
168/** 168/**
169 * raw_seqcount_begin - begin a seq-read critical section
170 * @s: pointer to seqcount_t
171 * Returns: count to be passed to read_seqcount_retry
172 *
173 * raw_seqcount_begin opens a read critical section of the given seqcount.
174 * Validity of the critical section is tested by checking read_seqcount_retry
175 * function.
176 *
177 * Unlike read_seqcount_begin(), this function will not wait for the count
178 * to stabilize. If a writer is active when we begin, we will fail the
179 * read_seqcount_retry() instead of stabilizing at the beginning of the
180 * critical section.
181 */
182static inline unsigned raw_seqcount_begin(const seqcount_t *s)
183{
184 unsigned ret = ACCESS_ONCE(s->sequence);
185 smp_rmb();
186 return ret & ~1;
187}
188
189/**
169 * __read_seqcount_retry - end a seq-read critical section (without barrier) 190 * __read_seqcount_retry - end a seq-read critical section (without barrier)
170 * @s: pointer to seqcount_t 191 * @s: pointer to seqcount_t
171 * @start: count, from read_seqcount_begin 192 * @start: count, from read_seqcount_begin
diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
index f51bf2e70c69..2db407a40051 100644
--- a/include/linux/serial_core.h
+++ b/include/linux/serial_core.h
@@ -357,7 +357,7 @@ struct uart_port {
357#define UPF_CONS_FLOW ((__force upf_t) (1 << 23)) 357#define UPF_CONS_FLOW ((__force upf_t) (1 << 23))
358#define UPF_SHARE_IRQ ((__force upf_t) (1 << 24)) 358#define UPF_SHARE_IRQ ((__force upf_t) (1 << 24))
359#define UPF_EXAR_EFR ((__force upf_t) (1 << 25)) 359#define UPF_EXAR_EFR ((__force upf_t) (1 << 25))
360#define UPF_IIR_ONCE ((__force upf_t) (1 << 26)) 360#define UPF_BUG_THRE ((__force upf_t) (1 << 26))
361/* The exact UART type is known and should not be probed. */ 361/* The exact UART type is known and should not be probed. */
362#define UPF_FIXED_TYPE ((__force upf_t) (1 << 27)) 362#define UPF_FIXED_TYPE ((__force upf_t) (1 << 27))
363#define UPF_BOOT_AUTOCONF ((__force upf_t) (1 << 28)) 363#define UPF_BOOT_AUTOCONF ((__force upf_t) (1 << 28))
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 33370271b8b2..111f26b6e28b 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -238,11 +238,12 @@ enum {
238/* 238/*
239 * The callback notifies userspace to release buffers when skb DMA is done in 239 * The callback notifies userspace to release buffers when skb DMA is done in
240 * lower device, the skb last reference should be 0 when calling this. 240 * lower device, the skb last reference should be 0 when calling this.
241 * The desc is used to track userspace buffer index. 241 * The ctx field is used to track device context.
242 * The desc field is used to track userspace buffer index.
242 */ 243 */
243struct ubuf_info { 244struct ubuf_info {
244 void (*callback)(void *); 245 void (*callback)(struct ubuf_info *);
245 void *arg; 246 void *ctx;
246 unsigned long desc; 247 unsigned long desc;
247}; 248};
248 249
@@ -481,6 +482,7 @@ struct sk_buff {
481 union { 482 union {
482 __u32 mark; 483 __u32 mark;
483 __u32 dropcount; 484 __u32 dropcount;
485 __u32 avail_size;
484 }; 486 };
485 487
486 sk_buff_data_t transport_header; 488 sk_buff_data_t transport_header;
@@ -1018,7 +1020,7 @@ static inline void skb_queue_splice(const struct sk_buff_head *list,
1018} 1020}
1019 1021
1020/** 1022/**
1021 * skb_queue_splice - join two skb lists and reinitialise the emptied list 1023 * skb_queue_splice_init - join two skb lists and reinitialise the emptied list
1022 * @list: the new list to add 1024 * @list: the new list to add
1023 * @head: the place to add it in the first list 1025 * @head: the place to add it in the first list
1024 * 1026 *
@@ -1049,7 +1051,7 @@ static inline void skb_queue_splice_tail(const struct sk_buff_head *list,
1049} 1051}
1050 1052
1051/** 1053/**
1052 * skb_queue_splice_tail - join two skb lists and reinitialise the emptied list 1054 * skb_queue_splice_tail_init - join two skb lists and reinitialise the emptied list
1053 * @list: the new list to add 1055 * @list: the new list to add
1054 * @head: the place to add it in the first list 1056 * @head: the place to add it in the first list
1055 * 1057 *
@@ -1366,6 +1368,18 @@ static inline int skb_tailroom(const struct sk_buff *skb)
1366} 1368}
1367 1369
1368/** 1370/**
1371 * skb_availroom - bytes at buffer end
1372 * @skb: buffer to check
1373 *
1374 * Return the number of bytes of free space at the tail of an sk_buff
1375 * allocated by sk_stream_alloc()
1376 */
1377static inline int skb_availroom(const struct sk_buff *skb)
1378{
1379 return skb_is_nonlinear(skb) ? 0 : skb->avail_size - skb->len;
1380}
1381
1382/**
1369 * skb_reserve - adjust headroom 1383 * skb_reserve - adjust headroom
1370 * @skb: buffer to alter 1384 * @skb: buffer to alter
1371 * @len: bytes to move 1385 * @len: bytes to move
diff --git a/include/linux/socket.h b/include/linux/socket.h
index da2d3e2543f3..b84bbd48b874 100644
--- a/include/linux/socket.h
+++ b/include/linux/socket.h
@@ -265,7 +265,7 @@ struct ucred {
265#define MSG_NOSIGNAL 0x4000 /* Do not generate SIGPIPE */ 265#define MSG_NOSIGNAL 0x4000 /* Do not generate SIGPIPE */
266#define MSG_MORE 0x8000 /* Sender will send more */ 266#define MSG_MORE 0x8000 /* Sender will send more */
267#define MSG_WAITFORONE 0x10000 /* recvmmsg(): block until 1+ packets avail */ 267#define MSG_WAITFORONE 0x10000 /* recvmmsg(): block until 1+ packets avail */
268 268#define MSG_SENDPAGE_NOTLAST 0x20000 /* sendpage() internal : not the last page */
269#define MSG_EOF MSG_FIN 269#define MSG_EOF MSG_FIN
270 270
271#define MSG_CMSG_CLOEXEC 0x40000000 /* Set close_on_exit for file 271#define MSG_CMSG_CLOEXEC 0x40000000 /* Set close_on_exit for file
diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index 98679b061b63..fa702aeb5038 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -254,7 +254,7 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv)
254 * driver is finished with this message, it must call 254 * driver is finished with this message, it must call
255 * spi_finalize_current_message() so the subsystem can issue the next 255 * spi_finalize_current_message() so the subsystem can issue the next
256 * transfer 256 * transfer
257 * @prepare_transfer_hardware: there are currently no more messages on the 257 * @unprepare_transfer_hardware: there are currently no more messages on the
258 * queue so the subsystem notifies the driver that it may relax the 258 * queue so the subsystem notifies the driver that it may relax the
259 * hardware by issuing this call 259 * hardware by issuing this call
260 * 260 *
diff --git a/include/linux/stddef.h b/include/linux/stddef.h
index 6a40c76bdcf1..1747b6787b9e 100644
--- a/include/linux/stddef.h
+++ b/include/linux/stddef.h
@@ -3,14 +3,10 @@
3 3
4#include <linux/compiler.h> 4#include <linux/compiler.h>
5 5
6#ifdef __KERNEL__
7
6#undef NULL 8#undef NULL
7#if defined(__cplusplus)
8#define NULL 0
9#else
10#define NULL ((void *)0) 9#define NULL ((void *)0)
11#endif
12
13#ifdef __KERNEL__
14 10
15enum { 11enum {
16 false = 0, 12 false = 0,
diff --git a/include/linux/swap.h b/include/linux/swap.h
index 8dc0ea7caf02..b1fd5c7925fe 100644
--- a/include/linux/swap.h
+++ b/include/linux/swap.h
@@ -305,6 +305,13 @@ static inline int mem_cgroup_swappiness(struct mem_cgroup *mem)
305 return vm_swappiness; 305 return vm_swappiness;
306} 306}
307#endif 307#endif
308#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
309extern void mem_cgroup_uncharge_swap(swp_entry_t ent);
310#else
311static inline void mem_cgroup_uncharge_swap(swp_entry_t ent)
312{
313}
314#endif
308#ifdef CONFIG_SWAP 315#ifdef CONFIG_SWAP
309/* linux/mm/page_io.c */ 316/* linux/mm/page_io.c */
310extern int swap_readpage(struct page *); 317extern int swap_readpage(struct page *);
@@ -375,13 +382,6 @@ mem_cgroup_uncharge_swapcache(struct page *page, swp_entry_t ent, bool swapout)
375{ 382{
376} 383}
377#endif 384#endif
378#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
379extern void mem_cgroup_uncharge_swap(swp_entry_t ent);
380#else
381static inline void mem_cgroup_uncharge_swap(swp_entry_t ent)
382{
383}
384#endif
385 385
386#else /* CONFIG_SWAP */ 386#else /* CONFIG_SWAP */
387 387
diff --git a/include/linux/types.h b/include/linux/types.h
index e5fa50345516..7f480db60231 100644
--- a/include/linux/types.h
+++ b/include/linux/types.h
@@ -210,6 +210,12 @@ typedef u32 phys_addr_t;
210 210
211typedef phys_addr_t resource_size_t; 211typedef phys_addr_t resource_size_t;
212 212
213/*
214 * This type is the placeholder for a hardware interrupt number. It has to be
215 * big enough to enclose whatever representation is used by a given platform.
216 */
217typedef unsigned long irq_hw_number_t;
218
213typedef struct { 219typedef struct {
214 int counter; 220 int counter;
215} atomic_t; 221} atomic_t;
diff --git a/include/linux/usb/hcd.h b/include/linux/usb/hcd.h
index 5de415707c23..d28cc78a38e4 100644
--- a/include/linux/usb/hcd.h
+++ b/include/linux/usb/hcd.h
@@ -126,6 +126,8 @@ struct usb_hcd {
126 unsigned wireless:1; /* Wireless USB HCD */ 126 unsigned wireless:1; /* Wireless USB HCD */
127 unsigned authorized_default:1; 127 unsigned authorized_default:1;
128 unsigned has_tt:1; /* Integrated TT in root hub */ 128 unsigned has_tt:1; /* Integrated TT in root hub */
129 unsigned broken_pci_sleep:1; /* Don't put the
130 controller in PCI-D3 for system sleep */
129 131
130 unsigned int irq; /* irq allocated */ 132 unsigned int irq; /* irq allocated */
131 void __iomem *regs; /* device memory/io */ 133 void __iomem *regs; /* device memory/io */
diff --git a/include/linux/usb/otg.h b/include/linux/usb/otg.h
index f67810f8f21b..38ab3f46346f 100644
--- a/include/linux/usb/otg.h
+++ b/include/linux/usb/otg.h
@@ -94,6 +94,7 @@ struct usb_phy {
94 94
95 struct usb_otg *otg; 95 struct usb_otg *otg;
96 96
97 struct device *io_dev;
97 struct usb_phy_io_ops *io_ops; 98 struct usb_phy_io_ops *io_ops;
98 void __iomem *io_priv; 99 void __iomem *io_priv;
99 100
diff --git a/include/linux/usb/serial.h b/include/linux/usb/serial.h
index fbb666b1b670..474283888233 100644
--- a/include/linux/usb/serial.h
+++ b/include/linux/usb/serial.h
@@ -28,13 +28,6 @@
28/* parity check flag */ 28/* parity check flag */
29#define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK)) 29#define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
30 30
31enum port_dev_state {
32 PORT_UNREGISTERED,
33 PORT_REGISTERING,
34 PORT_REGISTERED,
35 PORT_UNREGISTERING,
36};
37
38/* USB serial flags */ 31/* USB serial flags */
39#define USB_SERIAL_WRITE_BUSY 0 32#define USB_SERIAL_WRITE_BUSY 0
40 33
@@ -124,7 +117,6 @@ struct usb_serial_port {
124 char throttle_req; 117 char throttle_req;
125 unsigned long sysrq; /* sysrq timeout */ 118 unsigned long sysrq; /* sysrq timeout */
126 struct device dev; 119 struct device dev;
127 enum port_dev_state dev_state;
128}; 120};
129#define to_usb_serial_port(d) container_of(d, struct usb_serial_port, dev) 121#define to_usb_serial_port(d) container_of(d, struct usb_serial_port, dev)
130 122
diff --git a/include/linux/vgaarb.h b/include/linux/vgaarb.h
index 9c3120dca294..b572f80bdfd5 100644
--- a/include/linux/vgaarb.h
+++ b/include/linux/vgaarb.h
@@ -47,6 +47,8 @@
47 */ 47 */
48#define VGA_DEFAULT_DEVICE (NULL) 48#define VGA_DEFAULT_DEVICE (NULL)
49 49
50struct pci_dev;
51
50/* For use by clients */ 52/* For use by clients */
51 53
52/** 54/**
diff --git a/include/linux/vm_event_item.h b/include/linux/vm_event_item.h
index 03b90cdc1921..06f8e3858251 100644
--- a/include/linux/vm_event_item.h
+++ b/include/linux/vm_event_item.h
@@ -26,13 +26,14 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,
26 PGFREE, PGACTIVATE, PGDEACTIVATE, 26 PGFREE, PGACTIVATE, PGDEACTIVATE,
27 PGFAULT, PGMAJFAULT, 27 PGFAULT, PGMAJFAULT,
28 FOR_ALL_ZONES(PGREFILL), 28 FOR_ALL_ZONES(PGREFILL),
29 FOR_ALL_ZONES(PGSTEAL), 29 FOR_ALL_ZONES(PGSTEAL_KSWAPD),
30 FOR_ALL_ZONES(PGSTEAL_DIRECT),
30 FOR_ALL_ZONES(PGSCAN_KSWAPD), 31 FOR_ALL_ZONES(PGSCAN_KSWAPD),
31 FOR_ALL_ZONES(PGSCAN_DIRECT), 32 FOR_ALL_ZONES(PGSCAN_DIRECT),
32#ifdef CONFIG_NUMA 33#ifdef CONFIG_NUMA
33 PGSCAN_ZONE_RECLAIM_FAILED, 34 PGSCAN_ZONE_RECLAIM_FAILED,
34#endif 35#endif
35 PGINODESTEAL, SLABS_SCANNED, KSWAPD_STEAL, KSWAPD_INODESTEAL, 36 PGINODESTEAL, SLABS_SCANNED, KSWAPD_INODESTEAL,
36 KSWAPD_LOW_WMARK_HIT_QUICKLY, KSWAPD_HIGH_WMARK_HIT_QUICKLY, 37 KSWAPD_LOW_WMARK_HIT_QUICKLY, KSWAPD_HIGH_WMARK_HIT_QUICKLY,
37 KSWAPD_SKIP_CONGESTION_WAIT, 38 KSWAPD_SKIP_CONGESTION_WAIT,
38 PAGEOUTRUN, ALLOCSTALL, PGROTATED, 39 PAGEOUTRUN, ALLOCSTALL, PGROTATED,
diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index 344b0f972828..d47e523c9d83 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -92,6 +92,7 @@ enum {
92 HCI_SERVICE_CACHE, 92 HCI_SERVICE_CACHE,
93 HCI_LINK_KEYS, 93 HCI_LINK_KEYS,
94 HCI_DEBUG_KEYS, 94 HCI_DEBUG_KEYS,
95 HCI_UNREGISTER,
95 96
96 HCI_LE_SCAN, 97 HCI_LE_SCAN,
97 HCI_SSP_ENABLED, 98 HCI_SSP_ENABLED,
@@ -1327,8 +1328,8 @@ struct sockaddr_hci {
1327#define HCI_DEV_NONE 0xffff 1328#define HCI_DEV_NONE 0xffff
1328 1329
1329#define HCI_CHANNEL_RAW 0 1330#define HCI_CHANNEL_RAW 0
1330#define HCI_CHANNEL_CONTROL 1
1331#define HCI_CHANNEL_MONITOR 2 1331#define HCI_CHANNEL_MONITOR 2
1332#define HCI_CHANNEL_CONTROL 3
1332 1333
1333struct hci_filter { 1334struct hci_filter {
1334 unsigned long type_mask; 1335 unsigned long type_mask;
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index daefaac51131..db1c5df45224 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -314,6 +314,7 @@ struct hci_conn {
314 314
315 __u8 remote_cap; 315 __u8 remote_cap;
316 __u8 remote_auth; 316 __u8 remote_auth;
317 bool flush_key;
317 318
318 unsigned int sent; 319 unsigned int sent;
319 320
@@ -427,7 +428,7 @@ enum {
427static inline bool hci_conn_ssp_enabled(struct hci_conn *conn) 428static inline bool hci_conn_ssp_enabled(struct hci_conn *conn)
428{ 429{
429 struct hci_dev *hdev = conn->hdev; 430 struct hci_dev *hdev = conn->hdev;
430 return (test_bit(HCI_SSP_ENABLED, &hdev->flags) && 431 return (test_bit(HCI_SSP_ENABLED, &hdev->dev_flags) &&
431 test_bit(HCI_CONN_SSP_ENABLED, &conn->flags)); 432 test_bit(HCI_CONN_SSP_ENABLED, &conn->flags));
432} 433}
433 434
@@ -907,11 +908,13 @@ static inline void hci_role_switch_cfm(struct hci_conn *conn, __u8 status,
907 908
908static inline bool eir_has_data_type(u8 *data, size_t data_len, u8 type) 909static inline bool eir_has_data_type(u8 *data, size_t data_len, u8 type)
909{ 910{
910 u8 field_len; 911 size_t parsed = 0;
911 size_t parsed;
912 912
913 for (parsed = 0; parsed < data_len - 1; parsed += field_len) { 913 if (data_len < 2)
914 field_len = data[0]; 914 return false;
915
916 while (parsed < data_len - 1) {
917 u8 field_len = data[0];
915 918
916 if (field_len == 0) 919 if (field_len == 0)
917 break; 920 break;
@@ -978,7 +981,7 @@ int mgmt_discoverable(struct hci_dev *hdev, u8 discoverable);
978int mgmt_connectable(struct hci_dev *hdev, u8 connectable); 981int mgmt_connectable(struct hci_dev *hdev, u8 connectable);
979int mgmt_write_scan_failed(struct hci_dev *hdev, u8 scan, u8 status); 982int mgmt_write_scan_failed(struct hci_dev *hdev, u8 scan, u8 status);
980int mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key, 983int mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key,
981 u8 persistent); 984 bool persistent);
982int mgmt_device_connected(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, 985int mgmt_device_connected(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
983 u8 addr_type, u32 flags, u8 *name, u8 name_len, 986 u8 addr_type, u32 flags, u8 *name, u8 name_len,
984 u8 *dev_class); 987 u8 *dev_class);
diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h
index ffc1377e092e..ebfd91fc20f8 100644
--- a/include/net/bluetooth/mgmt.h
+++ b/include/net/bluetooth/mgmt.h
@@ -117,7 +117,7 @@ struct mgmt_mode {
117#define MGMT_OP_SET_DISCOVERABLE 0x0006 117#define MGMT_OP_SET_DISCOVERABLE 0x0006
118struct mgmt_cp_set_discoverable { 118struct mgmt_cp_set_discoverable {
119 __u8 val; 119 __u8 val;
120 __u16 timeout; 120 __le16 timeout;
121} __packed; 121} __packed;
122#define MGMT_SET_DISCOVERABLE_SIZE 3 122#define MGMT_SET_DISCOVERABLE_SIZE 3
123 123
diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
index 248fb05feb63..83d800c31e3c 100644
--- a/include/net/cfg80211.h
+++ b/include/net/cfg80211.h
@@ -620,8 +620,10 @@ struct sta_bss_parameters {
620 * @llid: mesh local link id 620 * @llid: mesh local link id
621 * @plid: mesh peer link id 621 * @plid: mesh peer link id
622 * @plink_state: mesh peer link state 622 * @plink_state: mesh peer link state
623 * @signal: signal strength of last received packet in dBm 623 * @signal: the signal strength, type depends on the wiphy's signal_type
624 * @signal_avg: signal strength average in dBm 624 NOTE: For CFG80211_SIGNAL_TYPE_MBM, value is expressed in _dBm_.
625 * @signal_avg: avg signal strength, type depends on the wiphy's signal_type
626 NOTE: For CFG80211_SIGNAL_TYPE_MBM, value is expressed in _dBm_.
625 * @txrate: current unicast bitrate from this station 627 * @txrate: current unicast bitrate from this station
626 * @rxrate: current unicast bitrate to this station 628 * @rxrate: current unicast bitrate to this station
627 * @rx_packets: packets received from this station 629 * @rx_packets: packets received from this station
diff --git a/include/net/dst.h b/include/net/dst.h
index 59c5d18cc385..bed833d9796a 100644
--- a/include/net/dst.h
+++ b/include/net/dst.h
@@ -36,7 +36,11 @@ struct dst_entry {
36 struct net_device *dev; 36 struct net_device *dev;
37 struct dst_ops *ops; 37 struct dst_ops *ops;
38 unsigned long _metrics; 38 unsigned long _metrics;
39 unsigned long expires; 39 union {
40 unsigned long expires;
41 /* point to where the dst_entry copied from */
42 struct dst_entry *from;
43 };
40 struct dst_entry *path; 44 struct dst_entry *path;
41 struct neighbour __rcu *_neighbour; 45 struct neighbour __rcu *_neighbour;
42#ifdef CONFIG_XFRM 46#ifdef CONFIG_XFRM
@@ -55,6 +59,7 @@ struct dst_entry {
55#define DST_NOCACHE 0x0010 59#define DST_NOCACHE 0x0010
56#define DST_NOCOUNT 0x0020 60#define DST_NOCOUNT 0x0020
57#define DST_NOPEER 0x0040 61#define DST_NOPEER 0x0040
62#define DST_FAKE_RTABLE 0x0080
58 63
59 short error; 64 short error;
60 short obsolete; 65 short obsolete;
diff --git a/include/net/ip6_fib.h b/include/net/ip6_fib.h
index b26bb8101981..0ae759a6c76e 100644
--- a/include/net/ip6_fib.h
+++ b/include/net/ip6_fib.h
@@ -123,6 +123,54 @@ static inline struct inet6_dev *ip6_dst_idev(struct dst_entry *dst)
123 return ((struct rt6_info *)dst)->rt6i_idev; 123 return ((struct rt6_info *)dst)->rt6i_idev;
124} 124}
125 125
126static inline void rt6_clean_expires(struct rt6_info *rt)
127{
128 if (!(rt->rt6i_flags & RTF_EXPIRES) && rt->dst.from)
129 dst_release(rt->dst.from);
130
131 rt->rt6i_flags &= ~RTF_EXPIRES;
132 rt->dst.from = NULL;
133}
134
135static inline void rt6_set_expires(struct rt6_info *rt, unsigned long expires)
136{
137 if (!(rt->rt6i_flags & RTF_EXPIRES) && rt->dst.from)
138 dst_release(rt->dst.from);
139
140 rt->rt6i_flags |= RTF_EXPIRES;
141 rt->dst.expires = expires;
142}
143
144static inline void rt6_update_expires(struct rt6_info *rt, int timeout)
145{
146 if (!(rt->rt6i_flags & RTF_EXPIRES)) {
147 if (rt->dst.from)
148 dst_release(rt->dst.from);
149 /* dst_set_expires relies on expires == 0
150 * if it has not been set previously.
151 */
152 rt->dst.expires = 0;
153 }
154
155 dst_set_expires(&rt->dst, timeout);
156 rt->rt6i_flags |= RTF_EXPIRES;
157}
158
159static inline void rt6_set_from(struct rt6_info *rt, struct rt6_info *from)
160{
161 struct dst_entry *new = (struct dst_entry *) from;
162
163 if (!(rt->rt6i_flags & RTF_EXPIRES) && rt->dst.from) {
164 if (new == rt->dst.from)
165 return;
166 dst_release(rt->dst.from);
167 }
168
169 rt->rt6i_flags &= ~RTF_EXPIRES;
170 rt->dst.from = new;
171 dst_hold(new);
172}
173
126struct fib6_walker_t { 174struct fib6_walker_t {
127 struct list_head lh; 175 struct list_head lh;
128 struct fib6_node *root, *node; 176 struct fib6_node *root, *node;
diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
index 2bdee51ba30d..72522f087375 100644
--- a/include/net/ip_vs.h
+++ b/include/net/ip_vs.h
@@ -393,7 +393,7 @@ struct ip_vs_protocol {
393 393
394 void (*exit)(struct ip_vs_protocol *pp); 394 void (*exit)(struct ip_vs_protocol *pp);
395 395
396 void (*init_netns)(struct net *net, struct ip_vs_proto_data *pd); 396 int (*init_netns)(struct net *net, struct ip_vs_proto_data *pd);
397 397
398 void (*exit_netns)(struct net *net, struct ip_vs_proto_data *pd); 398 void (*exit_netns)(struct net *net, struct ip_vs_proto_data *pd);
399 399
@@ -1203,6 +1203,8 @@ ip_vs_lookup_real_service(struct net *net, int af, __u16 protocol,
1203 1203
1204extern int ip_vs_use_count_inc(void); 1204extern int ip_vs_use_count_inc(void);
1205extern void ip_vs_use_count_dec(void); 1205extern void ip_vs_use_count_dec(void);
1206extern int ip_vs_register_nl_ioctl(void);
1207extern void ip_vs_unregister_nl_ioctl(void);
1206extern int ip_vs_control_init(void); 1208extern int ip_vs_control_init(void);
1207extern void ip_vs_control_cleanup(void); 1209extern void ip_vs_control_cleanup(void);
1208extern struct ip_vs_dest * 1210extern struct ip_vs_dest *
diff --git a/include/net/mac80211.h b/include/net/mac80211.h
index 87d203ff7a8a..9210bdc7bd8d 100644
--- a/include/net/mac80211.h
+++ b/include/net/mac80211.h
@@ -1327,7 +1327,7 @@ static inline struct ieee80211_rate *
1327ieee80211_get_tx_rate(const struct ieee80211_hw *hw, 1327ieee80211_get_tx_rate(const struct ieee80211_hw *hw,
1328 const struct ieee80211_tx_info *c) 1328 const struct ieee80211_tx_info *c)
1329{ 1329{
1330 if (WARN_ON(c->control.rates[0].idx < 0)) 1330 if (WARN_ON_ONCE(c->control.rates[0].idx < 0))
1331 return NULL; 1331 return NULL;
1332 return &hw->wiphy->bands[c->band]->bitrates[c->control.rates[0].idx]; 1332 return &hw->wiphy->bands[c->band]->bitrates[c->control.rates[0].idx];
1333} 1333}
diff --git a/include/net/netfilter/xt_log.h b/include/net/netfilter/xt_log.h
index 7e1544e8f70d..9d9756cca013 100644
--- a/include/net/netfilter/xt_log.h
+++ b/include/net/netfilter/xt_log.h
@@ -47,7 +47,7 @@ static void sb_close(struct sbuff *m)
47 if (likely(m != &emergency)) 47 if (likely(m != &emergency))
48 kfree(m); 48 kfree(m);
49 else { 49 else {
50 xchg(&emergency_ptr, m); 50 emergency_ptr = m;
51 local_bh_enable(); 51 local_bh_enable();
52 } 52 }
53} 53}
diff --git a/include/net/red.h b/include/net/red.h
index 77d4c3745cb5..ef46058d35bf 100644
--- a/include/net/red.h
+++ b/include/net/red.h
@@ -245,7 +245,7 @@ static inline unsigned long red_calc_qavg_from_idle_time(const struct red_parms
245 * 245 *
246 * dummy packets as a burst after idle time, i.e. 246 * dummy packets as a burst after idle time, i.e.
247 * 247 *
248 * p->qavg *= (1-W)^m 248 * v->qavg *= (1-W)^m
249 * 249 *
250 * This is an apparently overcomplicated solution (f.e. we have to 250 * This is an apparently overcomplicated solution (f.e. we have to
251 * precompute a table to make this calculation in reasonable time) 251 * precompute a table to make this calculation in reasonable time)
@@ -279,7 +279,7 @@ static inline unsigned long red_calc_qavg_no_idle_time(const struct red_parms *p
279 unsigned int backlog) 279 unsigned int backlog)
280{ 280{
281 /* 281 /*
282 * NOTE: p->qavg is fixed point number with point at Wlog. 282 * NOTE: v->qavg is fixed point number with point at Wlog.
283 * The formula below is equvalent to floating point 283 * The formula below is equvalent to floating point
284 * version: 284 * version:
285 * 285 *
@@ -390,7 +390,7 @@ static inline void red_adaptative_algo(struct red_parms *p, struct red_vars *v)
390 if (red_is_idling(v)) 390 if (red_is_idling(v))
391 qavg = red_calc_qavg_from_idle_time(p, v); 391 qavg = red_calc_qavg_from_idle_time(p, v);
392 392
393 /* p->qavg is fixed point number with point at Wlog */ 393 /* v->qavg is fixed point number with point at Wlog */
394 qavg >>= p->Wlog; 394 qavg >>= p->Wlog;
395 395
396 if (qavg > p->target_max && p->max_P <= MAX_P_MAX) 396 if (qavg > p->target_max && p->max_P <= MAX_P_MAX)
diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
index 6ee44b24864a..a2ef81466b00 100644
--- a/include/net/sctp/sctp.h
+++ b/include/net/sctp/sctp.h
@@ -704,4 +704,17 @@ static inline void sctp_v4_map_v6(union sctp_addr *addr)
704 addr->v6.sin6_addr.s6_addr32[2] = htonl(0x0000ffff); 704 addr->v6.sin6_addr.s6_addr32[2] = htonl(0x0000ffff);
705} 705}
706 706
707/* The cookie is always 0 since this is how it's used in the
708 * pmtu code.
709 */
710static inline struct dst_entry *sctp_transport_dst_check(struct sctp_transport *t)
711{
712 if (t->dst && !dst_check(t->dst, 0)) {
713 dst_release(t->dst);
714 t->dst = NULL;
715 }
716
717 return t->dst;
718}
719
707#endif /* __net_sctp_h__ */ 720#endif /* __net_sctp_h__ */
diff --git a/include/net/sock.h b/include/net/sock.h
index a6ba1f8871fd..5a0a58ac4126 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -246,6 +246,7 @@ struct cg_proto;
246 * @sk_user_data: RPC layer private data 246 * @sk_user_data: RPC layer private data
247 * @sk_sndmsg_page: cached page for sendmsg 247 * @sk_sndmsg_page: cached page for sendmsg
248 * @sk_sndmsg_off: cached offset for sendmsg 248 * @sk_sndmsg_off: cached offset for sendmsg
249 * @sk_peek_off: current peek_offset value
249 * @sk_send_head: front of stuff to transmit 250 * @sk_send_head: front of stuff to transmit
250 * @sk_security: used by security modules 251 * @sk_security: used by security modules
251 * @sk_mark: generic packet mark 252 * @sk_mark: generic packet mark
@@ -1128,9 +1129,9 @@ sk_sockets_allocated_read_positive(struct sock *sk)
1128 struct proto *prot = sk->sk_prot; 1129 struct proto *prot = sk->sk_prot;
1129 1130
1130 if (mem_cgroup_sockets_enabled && sk->sk_cgrp) 1131 if (mem_cgroup_sockets_enabled && sk->sk_cgrp)
1131 return percpu_counter_sum_positive(sk->sk_cgrp->sockets_allocated); 1132 return percpu_counter_read_positive(sk->sk_cgrp->sockets_allocated);
1132 1133
1133 return percpu_counter_sum_positive(prot->sockets_allocated); 1134 return percpu_counter_read_positive(prot->sockets_allocated);
1134} 1135}
1135 1136
1136static inline int 1137static inline int
diff --git a/include/scsi/libsas.h b/include/scsi/libsas.h
index 5f5ed1b8b41b..f4f1c96dca72 100644
--- a/include/scsi/libsas.h
+++ b/include/scsi/libsas.h
@@ -217,11 +217,29 @@ struct domain_device {
217 struct kref kref; 217 struct kref kref;
218}; 218};
219 219
220struct sas_discovery_event { 220struct sas_work {
221 struct list_head drain_node;
221 struct work_struct work; 222 struct work_struct work;
223};
224
225static inline void INIT_SAS_WORK(struct sas_work *sw, void (*fn)(struct work_struct *))
226{
227 INIT_WORK(&sw->work, fn);
228 INIT_LIST_HEAD(&sw->drain_node);
229}
230
231struct sas_discovery_event {
232 struct sas_work work;
222 struct asd_sas_port *port; 233 struct asd_sas_port *port;
223}; 234};
224 235
236static inline struct sas_discovery_event *to_sas_discovery_event(struct work_struct *work)
237{
238 struct sas_discovery_event *ev = container_of(work, typeof(*ev), work.work);
239
240 return ev;
241}
242
225struct sas_discovery { 243struct sas_discovery {
226 struct sas_discovery_event disc_work[DISC_NUM_EVENTS]; 244 struct sas_discovery_event disc_work[DISC_NUM_EVENTS];
227 unsigned long pending; 245 unsigned long pending;
@@ -244,7 +262,7 @@ struct asd_sas_port {
244 struct list_head destroy_list; 262 struct list_head destroy_list;
245 enum sas_linkrate linkrate; 263 enum sas_linkrate linkrate;
246 264
247 struct work_struct work; 265 struct sas_work work;
248 266
249/* public: */ 267/* public: */
250 int id; 268 int id;
@@ -270,10 +288,17 @@ struct asd_sas_port {
270}; 288};
271 289
272struct asd_sas_event { 290struct asd_sas_event {
273 struct work_struct work; 291 struct sas_work work;
274 struct asd_sas_phy *phy; 292 struct asd_sas_phy *phy;
275}; 293};
276 294
295static inline struct asd_sas_event *to_asd_sas_event(struct work_struct *work)
296{
297 struct asd_sas_event *ev = container_of(work, typeof(*ev), work.work);
298
299 return ev;
300}
301
277/* The phy pretty much is controlled by the LLDD. 302/* The phy pretty much is controlled by the LLDD.
278 * The class only reads those fields. 303 * The class only reads those fields.
279 */ 304 */
@@ -333,10 +358,17 @@ struct scsi_core {
333}; 358};
334 359
335struct sas_ha_event { 360struct sas_ha_event {
336 struct work_struct work; 361 struct sas_work work;
337 struct sas_ha_struct *ha; 362 struct sas_ha_struct *ha;
338}; 363};
339 364
365static inline struct sas_ha_event *to_sas_ha_event(struct work_struct *work)
366{
367 struct sas_ha_event *ev = container_of(work, typeof(*ev), work.work);
368
369 return ev;
370}
371
340enum sas_ha_state { 372enum sas_ha_state {
341 SAS_HA_REGISTERED, 373 SAS_HA_REGISTERED,
342 SAS_HA_DRAINING, 374 SAS_HA_DRAINING,
diff --git a/include/scsi/sas_ata.h b/include/scsi/sas_ata.h
index cdccd2eb7b6c..77670e823ed8 100644
--- a/include/scsi/sas_ata.h
+++ b/include/scsi/sas_ata.h
@@ -37,7 +37,7 @@ static inline int dev_is_sata(struct domain_device *dev)
37} 37}
38 38
39int sas_get_ata_info(struct domain_device *dev, struct ex_phy *phy); 39int sas_get_ata_info(struct domain_device *dev, struct ex_phy *phy);
40int sas_ata_init_host_and_port(struct domain_device *found_dev); 40int sas_ata_init(struct domain_device *dev);
41void sas_ata_task_abort(struct sas_task *task); 41void sas_ata_task_abort(struct sas_task *task);
42void sas_ata_strategy_handler(struct Scsi_Host *shost); 42void sas_ata_strategy_handler(struct Scsi_Host *shost);
43void sas_ata_eh(struct Scsi_Host *shost, struct list_head *work_q, 43void sas_ata_eh(struct Scsi_Host *shost, struct list_head *work_q,
@@ -52,7 +52,7 @@ static inline int dev_is_sata(struct domain_device *dev)
52{ 52{
53 return 0; 53 return 0;
54} 54}
55static inline int sas_ata_init_host_and_port(struct domain_device *found_dev) 55static inline int sas_ata_init(struct domain_device *dev)
56{ 56{
57 return 0; 57 return 0;
58} 58}
diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h
index 377df4a28512..1e1198546c72 100644
--- a/include/scsi/scsi_cmnd.h
+++ b/include/scsi/scsi_cmnd.h
@@ -134,6 +134,9 @@ struct scsi_cmnd {
134 134
135static inline struct scsi_driver *scsi_cmd_to_driver(struct scsi_cmnd *cmd) 135static inline struct scsi_driver *scsi_cmd_to_driver(struct scsi_cmnd *cmd)
136{ 136{
137 if (!cmd->request->rq_disk)
138 return NULL;
139
137 return *(struct scsi_driver **)cmd->request->rq_disk->private_data; 140 return *(struct scsi_driver **)cmd->request->rq_disk->private_data;
138} 141}
139 142
diff --git a/include/sound/cs42l52.h b/include/sound/cs42l52.h
new file mode 100644
index 000000000000..4c68955f7330
--- /dev/null
+++ b/include/sound/cs42l52.h
@@ -0,0 +1,36 @@
1/*
2 * linux/sound/cs42l52.h -- Platform data for CS42L52
3 *
4 * Copyright (c) 2012 Cirrus Logic Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#ifndef __CS42L52_H
12#define __CS42L52_H
13
14struct cs42l52_platform_data {
15
16 /* MICBIAS Level. Check datasheet Pg48 */
17 unsigned int micbias_lvl;
18
19 /* MICA mode selection 0=Single 1=Differential */
20 unsigned int mica_cfg;
21
22 /* MICB mode selection 0=Single 1=Differential */
23 unsigned int micb_cfg;
24
25 /* MICA Select 0=MIC1A 1=MIC2A */
26 unsigned int mica_sel;
27
28 /* MICB Select 0=MIC2A 1=MIC2B */
29 unsigned int micb_sel;
30
31 /* Charge Pump Freq. Check datasheet Pg73 */
32 unsigned int chgfreq;
33
34};
35
36#endif /* __CS42L52_H */
diff --git a/include/sound/max98095.h b/include/sound/max98095.h
index 7513a42dd4aa..e87ae67b0a55 100644
--- a/include/sound/max98095.h
+++ b/include/sound/max98095.h
@@ -49,6 +49,18 @@ struct max98095_pdata {
49 */ 49 */
50 unsigned int digmic_left_mode:1; 50 unsigned int digmic_left_mode:1;
51 unsigned int digmic_right_mode:1; 51 unsigned int digmic_right_mode:1;
52
53 /* Pin5 is the mechanical method of sensing jack insertion
54 * but it is something that might not be supported.
55 * 0 = PIN5 not supported
56 * 1 = PIN5 supported
57 */
58 unsigned int jack_detect_pin5en:1;
59
60 /* Slew amount for jack detection. Calculated as 4 * (delay + 1).
61 * Default delay is 24 to get a time of 100ms.
62 */
63 unsigned int jack_detect_delay;
52}; 64};
53 65
54#endif 66#endif
diff --git a/include/sound/sh_fsi.h b/include/sound/sh_fsi.h
index b457e87fbd08..956e30e89ea8 100644
--- a/include/sound/sh_fsi.h
+++ b/include/sound/sh_fsi.h
@@ -84,16 +84,4 @@ struct sh_fsi_platform_info {
84 struct sh_fsi_port_info port_b; 84 struct sh_fsi_port_info port_b;
85}; 85};
86 86
87/*
88 * for fsi-ak4642
89 */
90struct fsi_ak4642_info {
91 const char *name;
92 const char *card;
93 const char *cpu_dai;
94 const char *codec;
95 const char *platform;
96 int id;
97};
98
99#endif /* __SOUND_FSI_H */ 87#endif /* __SOUND_FSI_H */
diff --git a/include/sound/simple_card.h b/include/sound/simple_card.h
new file mode 100644
index 000000000000..4b62b8dc6a4f
--- /dev/null
+++ b/include/sound/simple_card.h
@@ -0,0 +1,38 @@
1/*
2 * ASoC simple sound card support
3 *
4 * Copyright (C) 2012 Renesas Solutions Corp.
5 * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#ifndef __SIMPLE_CARD_H
13#define __SIMPLE_CARD_H
14
15#include <sound/soc.h>
16
17struct asoc_simple_dai_init_info {
18 unsigned int fmt;
19 unsigned int cpu_daifmt;
20 unsigned int codec_daifmt;
21 unsigned int sysclk;
22};
23
24struct asoc_simple_card_info {
25 const char *name;
26 const char *card;
27 const char *cpu_dai;
28 const char *codec;
29 const char *platform;
30 const char *codec_dai;
31 struct asoc_simple_dai_init_info *init; /* for snd_link.init */
32
33 /* used in simple-card.c */
34 struct snd_soc_dai_link snd_link;
35 struct snd_soc_card snd_card;
36};
37
38#endif /* __SIMPLE_CARD_H */
diff --git a/include/sound/soc-dai.h b/include/sound/soc-dai.h
index c429f248cf4e..1f69e0af2941 100644
--- a/include/sound/soc-dai.h
+++ b/include/sound/soc-dai.h
@@ -173,6 +173,8 @@ struct snd_soc_dai_ops {
173 struct snd_soc_dai *); 173 struct snd_soc_dai *);
174 int (*trigger)(struct snd_pcm_substream *, int, 174 int (*trigger)(struct snd_pcm_substream *, int,
175 struct snd_soc_dai *); 175 struct snd_soc_dai *);
176 int (*bespoke_trigger)(struct snd_pcm_substream *, int,
177 struct snd_soc_dai *);
176 /* 178 /*
177 * For hardware based FIFO caused delay reporting. 179 * For hardware based FIFO caused delay reporting.
178 * Optional. 180 * Optional.
@@ -196,6 +198,7 @@ struct snd_soc_dai_driver {
196 const char *name; 198 const char *name;
197 unsigned int id; 199 unsigned int id;
198 int ac97_control; 200 int ac97_control;
201 unsigned int base;
199 202
200 /* DAI driver callbacks */ 203 /* DAI driver callbacks */
201 int (*probe)(struct snd_soc_dai *dai); 204 int (*probe)(struct snd_soc_dai *dai);
@@ -241,6 +244,7 @@ struct snd_soc_dai {
241 244
242 struct snd_soc_dapm_widget *playback_widget; 245 struct snd_soc_dapm_widget *playback_widget;
243 struct snd_soc_dapm_widget *capture_widget; 246 struct snd_soc_dapm_widget *capture_widget;
247 struct snd_soc_dapm_context dapm;
244 248
245 /* DAI DMA data */ 249 /* DAI DMA data */
246 void *playback_dma_data; 250 void *playback_dma_data;
diff --git a/include/sound/soc-dapm.h b/include/sound/soc-dapm.h
index 8da3c2409060..e3833d9f1914 100644
--- a/include/sound/soc-dapm.h
+++ b/include/sound/soc-dapm.h
@@ -141,10 +141,6 @@ struct device;
141{ .id = snd_soc_dapm_mixer, .name = wname, .reg = wreg, .shift = wshift, \ 141{ .id = snd_soc_dapm_mixer, .name = wname, .reg = wreg, .shift = wshift, \
142 .invert = winvert, .kcontrol_news = wcontrols, \ 142 .invert = winvert, .kcontrol_news = wcontrols, \
143 .num_kcontrols = wncontrols, .event = wevent, .event_flags = wflags} 143 .num_kcontrols = wncontrols, .event = wevent, .event_flags = wflags}
144#define SND_SOC_DAPM_MICBIAS_E(wname, wreg, wshift, winvert, wevent, wflags) \
145{ .id = snd_soc_dapm_micbias, .name = wname, .reg = wreg, .shift = wshift, \
146 .invert = winvert, .kcontrol_news = NULL, .num_kcontrols = 0, \
147 .event = wevent, .event_flags = wflags}
148#define SND_SOC_DAPM_SWITCH_E(wname, wreg, wshift, winvert, wcontrols, \ 144#define SND_SOC_DAPM_SWITCH_E(wname, wreg, wshift, winvert, wcontrols, \
149 wevent, wflags) \ 145 wevent, wflags) \
150{ .id = snd_soc_dapm_switch, .name = wname, .reg = wreg, .shift = wshift, \ 146{ .id = snd_soc_dapm_switch, .name = wname, .reg = wreg, .shift = wshift, \
@@ -324,6 +320,8 @@ struct snd_soc_dapm_path;
324struct snd_soc_dapm_pin; 320struct snd_soc_dapm_pin;
325struct snd_soc_dapm_route; 321struct snd_soc_dapm_route;
326struct snd_soc_dapm_context; 322struct snd_soc_dapm_context;
323struct regulator;
324struct snd_soc_dapm_widget_list;
327 325
328int dapm_reg_event(struct snd_soc_dapm_widget *w, 326int dapm_reg_event(struct snd_soc_dapm_widget *w,
329 struct snd_kcontrol *kcontrol, int event); 327 struct snd_kcontrol *kcontrol, int event);
@@ -359,6 +357,10 @@ int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm,
359int snd_soc_dapm_new_dai_widgets(struct snd_soc_dapm_context *dapm, 357int snd_soc_dapm_new_dai_widgets(struct snd_soc_dapm_context *dapm,
360 struct snd_soc_dai *dai); 358 struct snd_soc_dai *dai);
361int snd_soc_dapm_link_dai_widgets(struct snd_soc_card *card); 359int snd_soc_dapm_link_dai_widgets(struct snd_soc_card *card);
360int snd_soc_dapm_new_pcm(struct snd_soc_card *card,
361 const struct snd_soc_pcm_stream *params,
362 struct snd_soc_dapm_widget *source,
363 struct snd_soc_dapm_widget *sink);
362 364
363/* dapm path setup */ 365/* dapm path setup */
364int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context *dapm); 366int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context *dapm);
@@ -369,8 +371,8 @@ int snd_soc_dapm_weak_routes(struct snd_soc_dapm_context *dapm,
369 const struct snd_soc_dapm_route *route, int num); 371 const struct snd_soc_dapm_route *route, int num);
370 372
371/* dapm events */ 373/* dapm events */
372int snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream, 374void snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream,
373 struct snd_soc_dai *dai, int event); 375 int event);
374void snd_soc_dapm_shutdown(struct snd_soc_card *card); 376void snd_soc_dapm_shutdown(struct snd_soc_card *card);
375 377
376/* external DAPM widget events */ 378/* external DAPM widget events */
@@ -402,6 +404,10 @@ void snd_soc_dapm_auto_nc_codec_pins(struct snd_soc_codec *codec);
402/* Mostly internal - should not normally be used */ 404/* Mostly internal - should not normally be used */
403void dapm_mark_dirty(struct snd_soc_dapm_widget *w, const char *reason); 405void dapm_mark_dirty(struct snd_soc_dapm_widget *w, const char *reason);
404 406
407/* dapm path query */
408int snd_soc_dapm_dai_get_connected_widgets(struct snd_soc_dai *dai, int stream,
409 struct snd_soc_dapm_widget_list **list);
410
405/* dapm widget types */ 411/* dapm widget types */
406enum snd_soc_dapm_type { 412enum snd_soc_dapm_type {
407 snd_soc_dapm_input = 0, /* input pin */ 413 snd_soc_dapm_input = 0, /* input pin */
@@ -430,6 +436,12 @@ enum snd_soc_dapm_type {
430 snd_soc_dapm_aif_out, /* audio interface output */ 436 snd_soc_dapm_aif_out, /* audio interface output */
431 snd_soc_dapm_siggen, /* signal generator */ 437 snd_soc_dapm_siggen, /* signal generator */
432 snd_soc_dapm_dai, /* link to DAI structure */ 438 snd_soc_dapm_dai, /* link to DAI structure */
439 snd_soc_dapm_dai_link, /* link between two DAI structures */
440};
441
442enum snd_soc_dapm_subclass {
443 SND_SOC_DAPM_CLASS_INIT = 0,
444 SND_SOC_DAPM_CLASS_RUNTIME = 1,
433}; 445};
434 446
435/* 447/*
@@ -482,9 +494,11 @@ struct snd_soc_dapm_widget {
482 struct snd_soc_dapm_context *dapm; 494 struct snd_soc_dapm_context *dapm;
483 495
484 void *priv; /* widget specific data */ 496 void *priv; /* widget specific data */
497 struct regulator *regulator; /* attached regulator */
498 const struct snd_soc_pcm_stream *params; /* params for dai links */
485 499
486 /* dapm control */ 500 /* dapm control */
487 short reg; /* negative reg = no direct dapm */ 501 int reg; /* negative reg = no direct dapm */
488 unsigned char shift; /* bits to shift */ 502 unsigned char shift; /* bits to shift */
489 unsigned int saved_value; /* widget saved value */ 503 unsigned int saved_value; /* widget saved value */
490 unsigned int value; /* widget current value */ 504 unsigned int value; /* widget current value */
diff --git a/include/sound/soc-dpcm.h b/include/sound/soc-dpcm.h
new file mode 100644
index 000000000000..04598f1efd77
--- /dev/null
+++ b/include/sound/soc-dpcm.h
@@ -0,0 +1,138 @@
1/*
2 * linux/sound/soc-dpcm.h -- ALSA SoC Dynamic PCM Support
3 *
4 * Author: Liam Girdwood <lrg@ti.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#ifndef __LINUX_SND_SOC_DPCM_H
12#define __LINUX_SND_SOC_DPCM_H
13
14#include <linux/list.h>
15#include <sound/pcm.h>
16
17struct snd_soc_pcm_runtime;
18
19/*
20 * Types of runtime_update to perform. e.g. originated from FE PCM ops
21 * or audio route changes triggered by muxes/mixers.
22 */
23enum snd_soc_dpcm_update {
24 SND_SOC_DPCM_UPDATE_NO = 0,
25 SND_SOC_DPCM_UPDATE_BE,
26 SND_SOC_DPCM_UPDATE_FE,
27};
28
29/*
30 * Dynamic PCM Frontend -> Backend link management states.
31 */
32enum snd_soc_dpcm_link_state {
33 SND_SOC_DPCM_LINK_STATE_NEW = 0, /* newly created link */
34 SND_SOC_DPCM_LINK_STATE_FREE, /* link to be dismantled */
35};
36
37/*
38 * Dynamic PCM Frontend -> Backend link PCM states.
39 */
40enum snd_soc_dpcm_state {
41 SND_SOC_DPCM_STATE_NEW = 0,
42 SND_SOC_DPCM_STATE_OPEN,
43 SND_SOC_DPCM_STATE_HW_PARAMS,
44 SND_SOC_DPCM_STATE_PREPARE,
45 SND_SOC_DPCM_STATE_START,
46 SND_SOC_DPCM_STATE_STOP,
47 SND_SOC_DPCM_STATE_PAUSED,
48 SND_SOC_DPCM_STATE_SUSPEND,
49 SND_SOC_DPCM_STATE_HW_FREE,
50 SND_SOC_DPCM_STATE_CLOSE,
51};
52
53/*
54 * Dynamic PCM trigger ordering. Triggering flexibility is required as some
55 * DSPs require triggering before/after their CPU platform and DAIs.
56 *
57 * i.e. some clients may want to manually order this call in their PCM
58 * trigger() whilst others will just use the regular core ordering.
59 */
60enum snd_soc_dpcm_trigger {
61 SND_SOC_DPCM_TRIGGER_PRE = 0,
62 SND_SOC_DPCM_TRIGGER_POST,
63 SND_SOC_DPCM_TRIGGER_BESPOKE,
64};
65
66/*
67 * Dynamic PCM link
68 * This links together a FE and BE DAI at runtime and stores the link
69 * state information and the hw_params configuration.
70 */
71struct snd_soc_dpcm {
72 /* FE and BE DAIs*/
73 struct snd_soc_pcm_runtime *be;
74 struct snd_soc_pcm_runtime *fe;
75
76 /* link state */
77 enum snd_soc_dpcm_link_state state;
78
79 /* list of BE and FE for this DPCM link */
80 struct list_head list_be;
81 struct list_head list_fe;
82
83 /* hw params for this link - may be different for each link */
84 struct snd_pcm_hw_params hw_params;
85#ifdef CONFIG_DEBUG_FS
86 struct dentry *debugfs_state;
87#endif
88};
89
90/*
91 * Dynamic PCM runtime data.
92 */
93struct snd_soc_dpcm_runtime {
94 struct list_head be_clients;
95 struct list_head fe_clients;
96
97 int users;
98 struct snd_pcm_runtime *runtime;
99 struct snd_pcm_hw_params hw_params;
100
101 /* state and update */
102 enum snd_soc_dpcm_update runtime_update;
103 enum snd_soc_dpcm_state state;
104};
105
106/* can this BE stop and free */
107int snd_soc_dpcm_can_be_free_stop(struct snd_soc_pcm_runtime *fe,
108 struct snd_soc_pcm_runtime *be, int stream);
109
110/* can this BE perform a hw_params() */
111int snd_soc_dpcm_can_be_params(struct snd_soc_pcm_runtime *fe,
112 struct snd_soc_pcm_runtime *be, int stream);
113
114/* is the current PCM operation for this FE ? */
115int snd_soc_dpcm_fe_can_update(struct snd_soc_pcm_runtime *fe, int stream);
116
117/* is the current PCM operation for this BE ? */
118int snd_soc_dpcm_be_can_update(struct snd_soc_pcm_runtime *fe,
119 struct snd_soc_pcm_runtime *be, int stream);
120
121/* get the substream for this BE */
122struct snd_pcm_substream *
123 snd_soc_dpcm_get_substream(struct snd_soc_pcm_runtime *be, int stream);
124
125/* get the BE runtime state */
126enum snd_soc_dpcm_state
127 snd_soc_dpcm_be_get_state(struct snd_soc_pcm_runtime *be, int stream);
128
129/* set the BE runtime state */
130void snd_soc_dpcm_be_set_state(struct snd_soc_pcm_runtime *be, int stream,
131 enum snd_soc_dpcm_state state);
132
133/* internal use only */
134int soc_dpcm_be_digital_mute(struct snd_soc_pcm_runtime *fe, int mute);
135int soc_dpcm_debugfs_add(struct snd_soc_pcm_runtime *rtd);
136int soc_dpcm_runtime_update(struct snd_soc_dapm_widget *);
137
138#endif
diff --git a/include/sound/soc.h b/include/sound/soc.h
index 2ebf7877c148..c703871f5f65 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -55,6 +55,18 @@
55 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\ 55 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
56 .put = snd_soc_put_volsw, \ 56 .put = snd_soc_put_volsw, \
57 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) } 57 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) }
58#define SOC_SINGLE_SX_TLV(xname, xreg, xshift, xmin, xmax, tlv_array) \
59{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
60 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
61 SNDRV_CTL_ELEM_ACCESS_READWRITE, \
62 .tlv.p = (tlv_array),\
63 .info = snd_soc_info_volsw, \
64 .get = snd_soc_get_volsw_sx,\
65 .put = snd_soc_put_volsw_sx, \
66 .private_value = (unsigned long)&(struct soc_mixer_control) \
67 {.reg = xreg, .rreg = xreg, \
68 .shift = xshift, .rshift = xshift, \
69 .max = xmax, .min = xmin} }
58#define SOC_DOUBLE(xname, reg, shift_left, shift_right, max, invert) \ 70#define SOC_DOUBLE(xname, reg, shift_left, shift_right, max, invert) \
59{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\ 71{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
60 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \ 72 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
@@ -85,6 +97,18 @@
85 .get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \ 97 .get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \
86 .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, xshift, \ 98 .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, xshift, \
87 xmax, xinvert) } 99 xmax, xinvert) }
100#define SOC_DOUBLE_R_SX_TLV(xname, xreg, xrreg, xshift, xmin, xmax, tlv_array) \
101{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
102 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
103 SNDRV_CTL_ELEM_ACCESS_READWRITE, \
104 .tlv.p = (tlv_array), \
105 .info = snd_soc_info_volsw, \
106 .get = snd_soc_get_volsw_sx, \
107 .put = snd_soc_put_volsw_sx, \
108 .private_value = (unsigned long)&(struct soc_mixer_control) \
109 {.reg = xreg, .rreg = xrreg, \
110 .shift = xshift, .rshift = xshift, \
111 .max = xmax, .min = xmin} }
88#define SOC_DOUBLE_S8_TLV(xname, xreg, xmin, xmax, tlv_array) \ 112#define SOC_DOUBLE_S8_TLV(xname, xreg, xmin, xmax, tlv_array) \
89{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \ 113{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
90 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \ 114 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
@@ -171,20 +195,6 @@
171 .get = xhandler_get, .put = xhandler_put, \ 195 .get = xhandler_get, .put = xhandler_put, \
172 .private_value = (unsigned long)&xenum } 196 .private_value = (unsigned long)&xenum }
173 197
174#define SOC_DOUBLE_R_SX_TLV(xname, xreg_left, xreg_right, xshift,\
175 xmin, xmax, tlv_array) \
176{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
177 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
178 SNDRV_CTL_ELEM_ACCESS_READWRITE, \
179 .tlv.p = (tlv_array), \
180 .info = snd_soc_info_volsw_2r_sx, \
181 .get = snd_soc_get_volsw_2r_sx, \
182 .put = snd_soc_put_volsw_2r_sx, \
183 .private_value = (unsigned long)&(struct soc_mixer_control) \
184 {.reg = xreg_left, \
185 .rreg = xreg_right, .shift = xshift, \
186 .min = xmin, .max = xmax} }
187
188#define SND_SOC_BYTES(xname, xbase, xregs) \ 198#define SND_SOC_BYTES(xname, xbase, xregs) \
189{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ 199{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
190 .info = snd_soc_bytes_info, .get = snd_soc_bytes_get, \ 200 .info = snd_soc_bytes_info, .get = snd_soc_bytes_get, \
@@ -200,6 +210,19 @@
200 {.base = xbase, .num_regs = xregs, \ 210 {.base = xbase, .num_regs = xregs, \
201 .mask = xmask }) } 211 .mask = xmask }) }
202 212
213#define SOC_SINGLE_XR_SX(xname, xregbase, xregcount, xnbits, \
214 xmin, xmax, xinvert) \
215{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
216 .info = snd_soc_info_xr_sx, .get = snd_soc_get_xr_sx, \
217 .put = snd_soc_put_xr_sx, \
218 .private_value = (unsigned long)&(struct soc_mreg_control) \
219 {.regbase = xregbase, .regcount = xregcount, .nbits = xnbits, \
220 .invert = xinvert, .min = xmin, .max = xmax} }
221
222#define SOC_SINGLE_STROBE(xname, xreg, xshift, xinvert) \
223 SOC_SINGLE_EXT(xname, xreg, xshift, 1, xinvert, \
224 snd_soc_get_strobe, snd_soc_put_strobe)
225
203/* 226/*
204 * Simplified versions of above macros, declaring a struct and calculating 227 * Simplified versions of above macros, declaring a struct and calculating
205 * ARRAY_SIZE internally 228 * ARRAY_SIZE internally
@@ -264,6 +287,7 @@ struct snd_soc_jack_zone;
264struct snd_soc_jack_pin; 287struct snd_soc_jack_pin;
265struct snd_soc_cache_ops; 288struct snd_soc_cache_ops;
266#include <sound/soc-dapm.h> 289#include <sound/soc-dapm.h>
290#include <sound/soc-dpcm.h>
267 291
268#ifdef CONFIG_GPIOLIB 292#ifdef CONFIG_GPIOLIB
269struct snd_soc_jack_gpio; 293struct snd_soc_jack_gpio;
@@ -288,6 +312,11 @@ enum snd_soc_pcm_subclass {
288 SND_SOC_PCM_CLASS_BE = 1, 312 SND_SOC_PCM_CLASS_BE = 1,
289}; 313};
290 314
315enum snd_soc_card_subclass {
316 SND_SOC_CARD_CLASS_INIT = 0,
317 SND_SOC_CARD_CLASS_RUNTIME = 1,
318};
319
291int snd_soc_codec_set_sysclk(struct snd_soc_codec *codec, int clk_id, 320int snd_soc_codec_set_sysclk(struct snd_soc_codec *codec, int clk_id,
292 int source, unsigned int freq, int dir); 321 int source, unsigned int freq, int dir);
293int snd_soc_codec_set_pll(struct snd_soc_codec *codec, int pll_id, int source, 322int snd_soc_codec_set_pll(struct snd_soc_codec *codec, int pll_id, int source,
@@ -333,6 +362,11 @@ int snd_soc_platform_write(struct snd_soc_platform *platform,
333 unsigned int reg, unsigned int val); 362 unsigned int reg, unsigned int val);
334int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num); 363int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num);
335 364
365struct snd_pcm_substream *snd_soc_get_dai_substream(struct snd_soc_card *card,
366 const char *dai_link, int stream);
367struct snd_soc_pcm_runtime *snd_soc_get_pcm_runtime(struct snd_soc_card *card,
368 const char *dai_link);
369
336/* Utility functions to get clock rates from various things */ 370/* Utility functions to get clock rates from various things */
337int snd_soc_calc_frame_size(int sample_size, int channels, int tdm_slots); 371int snd_soc_calc_frame_size(int sample_size, int channels, int tdm_slots);
338int snd_soc_params_to_frame_size(struct snd_pcm_hw_params *params); 372int snd_soc_params_to_frame_size(struct snd_pcm_hw_params *params);
@@ -343,6 +377,9 @@ int snd_soc_params_to_bclk(struct snd_pcm_hw_params *parms);
343int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream, 377int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
344 const struct snd_pcm_hardware *hw); 378 const struct snd_pcm_hardware *hw);
345 379
380int snd_soc_platform_trigger(struct snd_pcm_substream *substream,
381 int cmd, struct snd_soc_platform *platform);
382
346/* Jack reporting */ 383/* Jack reporting */
347int snd_soc_jack_new(struct snd_soc_codec *codec, const char *id, int type, 384int snd_soc_jack_new(struct snd_soc_codec *codec, const char *id, int type,
348 struct snd_soc_jack *jack); 385 struct snd_soc_jack *jack);
@@ -413,6 +450,10 @@ int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
413 struct snd_ctl_elem_value *ucontrol); 450 struct snd_ctl_elem_value *ucontrol);
414#define snd_soc_get_volsw_2r snd_soc_get_volsw 451#define snd_soc_get_volsw_2r snd_soc_get_volsw
415#define snd_soc_put_volsw_2r snd_soc_put_volsw 452#define snd_soc_put_volsw_2r snd_soc_put_volsw
453int snd_soc_get_volsw_sx(struct snd_kcontrol *kcontrol,
454 struct snd_ctl_elem_value *ucontrol);
455int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol,
456 struct snd_ctl_elem_value *ucontrol);
416int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol, 457int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol,
417 struct snd_ctl_elem_info *uinfo); 458 struct snd_ctl_elem_info *uinfo);
418int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol, 459int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol,
@@ -421,19 +462,22 @@ int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
421 struct snd_ctl_elem_value *ucontrol); 462 struct snd_ctl_elem_value *ucontrol);
422int snd_soc_limit_volume(struct snd_soc_codec *codec, 463int snd_soc_limit_volume(struct snd_soc_codec *codec,
423 const char *name, int max); 464 const char *name, int max);
424int snd_soc_info_volsw_2r_sx(struct snd_kcontrol *kcontrol,
425 struct snd_ctl_elem_info *uinfo);
426int snd_soc_get_volsw_2r_sx(struct snd_kcontrol *kcontrol,
427 struct snd_ctl_elem_value *ucontrol);
428int snd_soc_put_volsw_2r_sx(struct snd_kcontrol *kcontrol,
429 struct snd_ctl_elem_value *ucontrol);
430int snd_soc_bytes_info(struct snd_kcontrol *kcontrol, 465int snd_soc_bytes_info(struct snd_kcontrol *kcontrol,
431 struct snd_ctl_elem_info *uinfo); 466 struct snd_ctl_elem_info *uinfo);
432int snd_soc_bytes_get(struct snd_kcontrol *kcontrol, 467int snd_soc_bytes_get(struct snd_kcontrol *kcontrol,
433 struct snd_ctl_elem_value *ucontrol); 468 struct snd_ctl_elem_value *ucontrol);
434int snd_soc_bytes_put(struct snd_kcontrol *kcontrol, 469int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
435 struct snd_ctl_elem_value *ucontrol); 470 struct snd_ctl_elem_value *ucontrol);
436 471int snd_soc_info_xr_sx(struct snd_kcontrol *kcontrol,
472 struct snd_ctl_elem_info *uinfo);
473int snd_soc_get_xr_sx(struct snd_kcontrol *kcontrol,
474 struct snd_ctl_elem_value *ucontrol);
475int snd_soc_put_xr_sx(struct snd_kcontrol *kcontrol,
476 struct snd_ctl_elem_value *ucontrol);
477int snd_soc_get_strobe(struct snd_kcontrol *kcontrol,
478 struct snd_ctl_elem_value *ucontrol);
479int snd_soc_put_strobe(struct snd_kcontrol *kcontrol,
480 struct snd_ctl_elem_value *ucontrol);
437 481
438/** 482/**
439 * struct snd_soc_reg_access - Describes whether a given register is 483 * struct snd_soc_reg_access - Describes whether a given register is
@@ -513,6 +557,7 @@ struct snd_soc_jack_gpio {
513#endif 557#endif
514 558
515struct snd_soc_jack { 559struct snd_soc_jack {
560 struct mutex mutex;
516 struct snd_jack *jack; 561 struct snd_jack *jack;
517 struct snd_soc_codec *codec; 562 struct snd_soc_codec *codec;
518 struct list_head pins; 563 struct list_head pins;
@@ -711,6 +756,7 @@ struct snd_soc_platform_driver {
711 /* platform IO - used for platform DAPM */ 756 /* platform IO - used for platform DAPM */
712 unsigned int (*read)(struct snd_soc_platform *, unsigned int); 757 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
713 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int); 758 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
759 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
714}; 760};
715 761
716struct snd_soc_platform { 762struct snd_soc_platform {
@@ -746,21 +792,36 @@ struct snd_soc_dai_link {
746 const char *cpu_dai_name; 792 const char *cpu_dai_name;
747 const struct device_node *cpu_dai_of_node; 793 const struct device_node *cpu_dai_of_node;
748 const char *codec_dai_name; 794 const char *codec_dai_name;
795 int be_id; /* optional ID for machine driver BE identification */
796
797 const struct snd_soc_pcm_stream *params;
749 798
750 unsigned int dai_fmt; /* format to set on init */ 799 unsigned int dai_fmt; /* format to set on init */
751 800
801 enum snd_soc_dpcm_trigger trigger[2]; /* trigger type for DPCM */
802
752 /* Keep DAI active over suspend */ 803 /* Keep DAI active over suspend */
753 unsigned int ignore_suspend:1; 804 unsigned int ignore_suspend:1;
754 805
755 /* Symmetry requirements */ 806 /* Symmetry requirements */
756 unsigned int symmetric_rates:1; 807 unsigned int symmetric_rates:1;
757 808
809 /* Do not create a PCM for this DAI link (Backend link) */
810 unsigned int no_pcm:1;
811
812 /* This DAI link can route to other DAI links at runtime (Frontend)*/
813 unsigned int dynamic:1;
814
758 /* pmdown_time is ignored at stop */ 815 /* pmdown_time is ignored at stop */
759 unsigned int ignore_pmdown_time:1; 816 unsigned int ignore_pmdown_time:1;
760 817
761 /* codec/machine specific init - e.g. add machine controls */ 818 /* codec/machine specific init - e.g. add machine controls */
762 int (*init)(struct snd_soc_pcm_runtime *rtd); 819 int (*init)(struct snd_soc_pcm_runtime *rtd);
763 820
821 /* optional hw_params re-writing for BE and FE sync */
822 int (*be_hw_params_fixup)(struct snd_soc_pcm_runtime *rtd,
823 struct snd_pcm_hw_params *params);
824
764 /* machine stream operations */ 825 /* machine stream operations */
765 struct snd_soc_ops *ops; 826 struct snd_soc_ops *ops;
766}; 827};
@@ -800,6 +861,7 @@ struct snd_soc_card {
800 861
801 struct list_head list; 862 struct list_head list;
802 struct mutex mutex; 863 struct mutex mutex;
864 struct mutex dapm_mutex;
803 865
804 bool instantiated; 866 bool instantiated;
805 867
@@ -889,9 +951,11 @@ struct snd_soc_pcm_runtime {
889 enum snd_soc_pcm_subclass pcm_subclass; 951 enum snd_soc_pcm_subclass pcm_subclass;
890 struct snd_pcm_ops ops; 952 struct snd_pcm_ops ops;
891 953
892 unsigned int complete:1;
893 unsigned int dev_registered:1; 954 unsigned int dev_registered:1;
894 955
956 /* Dynamic PCM BE runtime data */
957 struct snd_soc_dpcm_runtime dpcm[2];
958
895 long pmdown_time; 959 long pmdown_time;
896 960
897 /* runtime devices */ 961 /* runtime devices */
@@ -902,6 +966,10 @@ struct snd_soc_pcm_runtime {
902 struct snd_soc_dai *cpu_dai; 966 struct snd_soc_dai *cpu_dai;
903 967
904 struct delayed_work delayed_work; 968 struct delayed_work delayed_work;
969#ifdef CONFIG_DEBUG_FS
970 struct dentry *debugfs_dpcm_root;
971 struct dentry *debugfs_dpcm_state;
972#endif
905}; 973};
906 974
907/* mixer control */ 975/* mixer control */
@@ -916,6 +984,12 @@ struct soc_bytes {
916 u32 mask; 984 u32 mask;
917}; 985};
918 986
987/* multi register control */
988struct soc_mreg_control {
989 long min, max;
990 unsigned int regbase, regcount, nbits, invert;
991};
992
919/* enumerated kcontrol */ 993/* enumerated kcontrol */
920struct soc_enum { 994struct soc_enum {
921 unsigned short reg; 995 unsigned short reg;
diff --git a/include/trace/events/asoc.h b/include/trace/events/asoc.h
index ab26f8aa3c78..5fc2dcdd21cd 100644
--- a/include/trace/events/asoc.h
+++ b/include/trace/events/asoc.h
@@ -7,6 +7,8 @@
7#include <linux/ktime.h> 7#include <linux/ktime.h>
8#include <linux/tracepoint.h> 8#include <linux/tracepoint.h>
9 9
10#define DAPM_DIRECT "(direct)"
11
10struct snd_soc_jack; 12struct snd_soc_jack;
11struct snd_soc_codec; 13struct snd_soc_codec;
12struct snd_soc_platform; 14struct snd_soc_platform;
@@ -241,6 +243,84 @@ TRACE_EVENT(snd_soc_dapm_walk_done,
241 (int)__entry->path_checks, (int)__entry->neighbour_checks) 243 (int)__entry->path_checks, (int)__entry->neighbour_checks)
242); 244);
243 245
246TRACE_EVENT(snd_soc_dapm_output_path,
247
248 TP_PROTO(struct snd_soc_dapm_widget *widget,
249 struct snd_soc_dapm_path *path),
250
251 TP_ARGS(widget, path),
252
253 TP_STRUCT__entry(
254 __string( wname, widget->name )
255 __string( pname, path->name ? path->name : DAPM_DIRECT)
256 __string( psname, path->sink->name )
257 __field( int, path_sink )
258 __field( int, path_connect )
259 ),
260
261 TP_fast_assign(
262 __assign_str(wname, widget->name);
263 __assign_str(pname, path->name ? path->name : DAPM_DIRECT);
264 __assign_str(psname, path->sink->name);
265 __entry->path_connect = path->connect;
266 __entry->path_sink = (long)path->sink;
267 ),
268
269 TP_printk("%c%s -> %s -> %s\n",
270 (int) __entry->path_sink &&
271 (int) __entry->path_connect ? '*' : ' ',
272 __get_str(wname), __get_str(pname), __get_str(psname))
273);
274
275TRACE_EVENT(snd_soc_dapm_input_path,
276
277 TP_PROTO(struct snd_soc_dapm_widget *widget,
278 struct snd_soc_dapm_path *path),
279
280 TP_ARGS(widget, path),
281
282 TP_STRUCT__entry(
283 __string( wname, widget->name )
284 __string( pname, path->name ? path->name : DAPM_DIRECT)
285 __string( psname, path->source->name )
286 __field( int, path_source )
287 __field( int, path_connect )
288 ),
289
290 TP_fast_assign(
291 __assign_str(wname, widget->name);
292 __assign_str(pname, path->name ? path->name : DAPM_DIRECT);
293 __assign_str(psname, path->source->name);
294 __entry->path_connect = path->connect;
295 __entry->path_source = (long)path->source;
296 ),
297
298 TP_printk("%c%s <- %s <- %s\n",
299 (int) __entry->path_source &&
300 (int) __entry->path_connect ? '*' : ' ',
301 __get_str(wname), __get_str(pname), __get_str(psname))
302);
303
304TRACE_EVENT(snd_soc_dapm_connected,
305
306 TP_PROTO(int paths, int stream),
307
308 TP_ARGS(paths, stream),
309
310 TP_STRUCT__entry(
311 __field( int, paths )
312 __field( int, stream )
313 ),
314
315 TP_fast_assign(
316 __entry->paths = paths;
317 __entry->stream = stream;
318 ),
319
320 TP_printk("%s: found %d paths\n",
321 __entry->stream ? "capture" : "playback", __entry->paths)
322);
323
244TRACE_EVENT(snd_soc_jack_irq, 324TRACE_EVENT(snd_soc_jack_irq,
245 325
246 TP_PROTO(const char *name), 326 TP_PROTO(const char *name),
diff --git a/include/trace/events/sched.h b/include/trace/events/sched.h
index fbc7b1ad929b..ea7a2035456d 100644
--- a/include/trace/events/sched.h
+++ b/include/trace/events/sched.h
@@ -295,7 +295,7 @@ TRACE_EVENT(sched_process_exec,
295 TP_fast_assign( 295 TP_fast_assign(
296 __assign_str(filename, bprm->filename); 296 __assign_str(filename, bprm->filename);
297 __entry->pid = p->pid; 297 __entry->pid = p->pid;
298 __entry->old_pid = p->pid; 298 __entry->old_pid = old_pid;
299 ), 299 ),
300 300
301 TP_printk("filename=%s pid=%d old_pid=%d", __get_str(filename), 301 TP_printk("filename=%s pid=%d old_pid=%d", __get_str(filename),
diff --git a/include/xen/swiotlb-xen.h b/include/xen/swiotlb-xen.h
index 2ea2fdc79c16..4f4d449f00f6 100644
--- a/include/xen/swiotlb-xen.h
+++ b/include/xen/swiotlb-xen.h
@@ -7,11 +7,13 @@ extern void xen_swiotlb_init(int verbose);
7 7
8extern void 8extern void
9*xen_swiotlb_alloc_coherent(struct device *hwdev, size_t size, 9*xen_swiotlb_alloc_coherent(struct device *hwdev, size_t size,
10 dma_addr_t *dma_handle, gfp_t flags); 10 dma_addr_t *dma_handle, gfp_t flags,
11 struct dma_attrs *attrs);
11 12
12extern void 13extern void
13xen_swiotlb_free_coherent(struct device *hwdev, size_t size, 14xen_swiotlb_free_coherent(struct device *hwdev, size_t size,
14 void *vaddr, dma_addr_t dma_handle); 15 void *vaddr, dma_addr_t dma_handle,
16 struct dma_attrs *attrs);
15 17
16extern dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page, 18extern dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page,
17 unsigned long offset, size_t size, 19 unsigned long offset, size_t size,
diff --git a/init/Kconfig b/init/Kconfig
index 72f33faca44f..6cfd71d06463 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -1414,8 +1414,8 @@ endif # MODULES
1414config INIT_ALL_POSSIBLE 1414config INIT_ALL_POSSIBLE
1415 bool 1415 bool
1416 help 1416 help
1417 Back when each arch used to define their own cpu_online_map and 1417 Back when each arch used to define their own cpu_online_mask and
1418 cpu_possible_map, some of them chose to initialize cpu_possible_map 1418 cpu_possible_mask, some of them chose to initialize cpu_possible_mask
1419 with all 1s, and others with all 0s. When they were centralised, 1419 with all 1s, and others with all 0s. When they were centralised,
1420 it was better to provide this option than to break all the archs 1420 it was better to provide this option than to break all the archs
1421 and have several arch maintainers pursuing me down dark alleys. 1421 and have several arch maintainers pursuing me down dark alleys.
diff --git a/init/do_mounts.c b/init/do_mounts.c
index 0e93f92a0345..42b0707c3481 100644
--- a/init/do_mounts.c
+++ b/init/do_mounts.c
@@ -472,7 +472,7 @@ void __init change_floppy(char *fmt, ...)
472void __init mount_root(void) 472void __init mount_root(void)
473{ 473{
474#ifdef CONFIG_ROOT_NFS 474#ifdef CONFIG_ROOT_NFS
475 if (MAJOR(ROOT_DEV) == UNNAMED_MAJOR) { 475 if (ROOT_DEV == Root_NFS) {
476 if (mount_nfs_root()) 476 if (mount_nfs_root())
477 return; 477 return;
478 478
diff --git a/init/main.c b/init/main.c
index 9d454f09f3b1..44b2433334c7 100644
--- a/init/main.c
+++ b/init/main.c
@@ -225,13 +225,9 @@ static int __init loglevel(char *str)
225 225
226early_param("loglevel", loglevel); 226early_param("loglevel", loglevel);
227 227
228/* 228/* Change NUL term back to "=", to make "param" the whole string. */
229 * Unknown boot options get handed to init, unless they look like 229static int __init repair_env_string(char *param, char *val)
230 * unused parameters (modprobe will find them in /proc/cmdline).
231 */
232static int __init unknown_bootoption(char *param, char *val)
233{ 230{
234 /* Change NUL term back to "=", to make "param" the whole string. */
235 if (val) { 231 if (val) {
236 /* param=val or param="val"? */ 232 /* param=val or param="val"? */
237 if (val == param+strlen(param)+1) 233 if (val == param+strlen(param)+1)
@@ -243,6 +239,16 @@ static int __init unknown_bootoption(char *param, char *val)
243 } else 239 } else
244 BUG(); 240 BUG();
245 } 241 }
242 return 0;
243}
244
245/*
246 * Unknown boot options get handed to init, unless they look like
247 * unused parameters (modprobe will find them in /proc/cmdline).
248 */
249static int __init unknown_bootoption(char *param, char *val)
250{
251 repair_env_string(param, val);
246 252
247 /* Handle obsolete-style parameters */ 253 /* Handle obsolete-style parameters */
248 if (obsolete_checksetup(param)) 254 if (obsolete_checksetup(param))
@@ -732,11 +738,6 @@ static char *initcall_level_names[] __initdata = {
732 "late parameters", 738 "late parameters",
733}; 739};
734 740
735static int __init ignore_unknown_bootoption(char *param, char *val)
736{
737 return 0;
738}
739
740static void __init do_initcall_level(int level) 741static void __init do_initcall_level(int level)
741{ 742{
742 extern const struct kernel_param __start___param[], __stop___param[]; 743 extern const struct kernel_param __start___param[], __stop___param[];
@@ -747,7 +748,7 @@ static void __init do_initcall_level(int level)
747 static_command_line, __start___param, 748 static_command_line, __start___param,
748 __stop___param - __start___param, 749 __stop___param - __start___param,
749 level, level, 750 level, level,
750 ignore_unknown_bootoption); 751 repair_env_string);
751 752
752 for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) 753 for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
753 do_one_initcall(*fn); 754 do_one_initcall(*fn);
diff --git a/kernel/compat.c b/kernel/compat.c
index 74ff8498809a..d2c67aa49ae6 100644
--- a/kernel/compat.c
+++ b/kernel/compat.c
@@ -372,25 +372,54 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
372 372
373#ifdef __ARCH_WANT_SYS_SIGPROCMASK 373#ifdef __ARCH_WANT_SYS_SIGPROCMASK
374 374
375asmlinkage long compat_sys_sigprocmask(int how, compat_old_sigset_t __user *set, 375/*
376 compat_old_sigset_t __user *oset) 376 * sys_sigprocmask SIG_SETMASK sets the first (compat) word of the
377 * blocked set of signals to the supplied signal set
378 */
379static inline void compat_sig_setmask(sigset_t *blocked, compat_sigset_word set)
377{ 380{
378 old_sigset_t s; 381 memcpy(blocked->sig, &set, sizeof(set));
379 long ret; 382}
380 mm_segment_t old_fs;
381 383
382 if (set && get_user(s, set)) 384asmlinkage long compat_sys_sigprocmask(int how,
383 return -EFAULT; 385 compat_old_sigset_t __user *nset,
384 old_fs = get_fs(); 386 compat_old_sigset_t __user *oset)
385 set_fs(KERNEL_DS); 387{
386 ret = sys_sigprocmask(how, 388 old_sigset_t old_set, new_set;
387 set ? (old_sigset_t __user *) &s : NULL, 389 sigset_t new_blocked;
388 oset ? (old_sigset_t __user *) &s : NULL); 390
389 set_fs(old_fs); 391 old_set = current->blocked.sig[0];
390 if (ret == 0) 392
391 if (oset) 393 if (nset) {
392 ret = put_user(s, oset); 394 if (get_user(new_set, nset))
393 return ret; 395 return -EFAULT;
396 new_set &= ~(sigmask(SIGKILL) | sigmask(SIGSTOP));
397
398 new_blocked = current->blocked;
399
400 switch (how) {
401 case SIG_BLOCK:
402 sigaddsetmask(&new_blocked, new_set);
403 break;
404 case SIG_UNBLOCK:
405 sigdelsetmask(&new_blocked, new_set);
406 break;
407 case SIG_SETMASK:
408 compat_sig_setmask(&new_blocked, new_set);
409 break;
410 default:
411 return -EINVAL;
412 }
413
414 set_current_blocked(&new_blocked);
415 }
416
417 if (oset) {
418 if (put_user(old_set, oset))
419 return -EFAULT;
420 }
421
422 return 0;
394} 423}
395 424
396#endif 425#endif
diff --git a/kernel/cpuset.c b/kernel/cpuset.c
index b96ad75b7e64..14f7070b4ba2 100644
--- a/kernel/cpuset.c
+++ b/kernel/cpuset.c
@@ -270,11 +270,11 @@ static struct file_system_type cpuset_fs_type = {
270 * are online. If none are online, walk up the cpuset hierarchy 270 * are online. If none are online, walk up the cpuset hierarchy
271 * until we find one that does have some online cpus. If we get 271 * until we find one that does have some online cpus. If we get
272 * all the way to the top and still haven't found any online cpus, 272 * all the way to the top and still haven't found any online cpus,
273 * return cpu_online_map. Or if passed a NULL cs from an exit'ing 273 * return cpu_online_mask. Or if passed a NULL cs from an exit'ing
274 * task, return cpu_online_map. 274 * task, return cpu_online_mask.
275 * 275 *
276 * One way or another, we guarantee to return some non-empty subset 276 * One way or another, we guarantee to return some non-empty subset
277 * of cpu_online_map. 277 * of cpu_online_mask.
278 * 278 *
279 * Call with callback_mutex held. 279 * Call with callback_mutex held.
280 */ 280 */
@@ -867,7 +867,7 @@ static int update_cpumask(struct cpuset *cs, struct cpuset *trialcs,
867 int retval; 867 int retval;
868 int is_load_balanced; 868 int is_load_balanced;
869 869
870 /* top_cpuset.cpus_allowed tracks cpu_online_map; it's read-only */ 870 /* top_cpuset.cpus_allowed tracks cpu_online_mask; it's read-only */
871 if (cs == &top_cpuset) 871 if (cs == &top_cpuset)
872 return -EACCES; 872 return -EACCES;
873 873
@@ -2149,7 +2149,7 @@ void __init cpuset_init_smp(void)
2149 * 2149 *
2150 * Description: Returns the cpumask_var_t cpus_allowed of the cpuset 2150 * Description: Returns the cpumask_var_t cpus_allowed of the cpuset
2151 * attached to the specified @tsk. Guaranteed to return some non-empty 2151 * attached to the specified @tsk. Guaranteed to return some non-empty
2152 * subset of cpu_online_map, even if this means going outside the 2152 * subset of cpu_online_mask, even if this means going outside the
2153 * tasks cpuset. 2153 * tasks cpuset.
2154 **/ 2154 **/
2155 2155
diff --git a/kernel/cred.c b/kernel/cred.c
index 97b36eeca4c9..e70683d9ec32 100644
--- a/kernel/cred.c
+++ b/kernel/cred.c
@@ -386,6 +386,8 @@ int copy_creds(struct task_struct *p, unsigned long clone_flags)
386 struct cred *new; 386 struct cred *new;
387 int ret; 387 int ret;
388 388
389 p->replacement_session_keyring = NULL;
390
389 if ( 391 if (
390#ifdef CONFIG_KEYS 392#ifdef CONFIG_KEYS
391 !p->cred->thread_keyring && 393 !p->cred->thread_keyring &&
diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
index 1dc53bae56e1..0557f24c6bca 100644
--- a/kernel/debug/debug_core.c
+++ b/kernel/debug/debug_core.c
@@ -160,37 +160,39 @@ early_param("nokgdbroundup", opt_nokgdbroundup);
160 * Weak aliases for breakpoint management, 160 * Weak aliases for breakpoint management,
161 * can be overriden by architectures when needed: 161 * can be overriden by architectures when needed:
162 */ 162 */
163int __weak kgdb_arch_set_breakpoint(unsigned long addr, char *saved_instr) 163int __weak kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
164{ 164{
165 int err; 165 int err;
166 166
167 err = probe_kernel_read(saved_instr, (char *)addr, BREAK_INSTR_SIZE); 167 err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
168 BREAK_INSTR_SIZE);
168 if (err) 169 if (err)
169 return err; 170 return err;
170 171 err = probe_kernel_write((char *)bpt->bpt_addr,
171 return probe_kernel_write((char *)addr, arch_kgdb_ops.gdb_bpt_instr, 172 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
172 BREAK_INSTR_SIZE); 173 return err;
173} 174}
174 175
175int __weak kgdb_arch_remove_breakpoint(unsigned long addr, char *bundle) 176int __weak kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
176{ 177{
177 return probe_kernel_write((char *)addr, 178 return probe_kernel_write((char *)bpt->bpt_addr,
178 (char *)bundle, BREAK_INSTR_SIZE); 179 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
179} 180}
180 181
181int __weak kgdb_validate_break_address(unsigned long addr) 182int __weak kgdb_validate_break_address(unsigned long addr)
182{ 183{
183 char tmp_variable[BREAK_INSTR_SIZE]; 184 struct kgdb_bkpt tmp;
184 int err; 185 int err;
185 /* Validate setting the breakpoint and then removing it. In the 186 /* Validate setting the breakpoint and then removing it. If the
186 * remove fails, the kernel needs to emit a bad message because we 187 * remove fails, the kernel needs to emit a bad message because we
187 * are deep trouble not being able to put things back the way we 188 * are deep trouble not being able to put things back the way we
188 * found them. 189 * found them.
189 */ 190 */
190 err = kgdb_arch_set_breakpoint(addr, tmp_variable); 191 tmp.bpt_addr = addr;
192 err = kgdb_arch_set_breakpoint(&tmp);
191 if (err) 193 if (err)
192 return err; 194 return err;
193 err = kgdb_arch_remove_breakpoint(addr, tmp_variable); 195 err = kgdb_arch_remove_breakpoint(&tmp);
194 if (err) 196 if (err)
195 printk(KERN_ERR "KGDB: Critical breakpoint error, kernel " 197 printk(KERN_ERR "KGDB: Critical breakpoint error, kernel "
196 "memory destroyed at: %lx", addr); 198 "memory destroyed at: %lx", addr);
@@ -234,7 +236,6 @@ static void kgdb_flush_swbreak_addr(unsigned long addr)
234 */ 236 */
235int dbg_activate_sw_breakpoints(void) 237int dbg_activate_sw_breakpoints(void)
236{ 238{
237 unsigned long addr;
238 int error; 239 int error;
239 int ret = 0; 240 int ret = 0;
240 int i; 241 int i;
@@ -243,16 +244,15 @@ int dbg_activate_sw_breakpoints(void)
243 if (kgdb_break[i].state != BP_SET) 244 if (kgdb_break[i].state != BP_SET)
244 continue; 245 continue;
245 246
246 addr = kgdb_break[i].bpt_addr; 247 error = kgdb_arch_set_breakpoint(&kgdb_break[i]);
247 error = kgdb_arch_set_breakpoint(addr,
248 kgdb_break[i].saved_instr);
249 if (error) { 248 if (error) {
250 ret = error; 249 ret = error;
251 printk(KERN_INFO "KGDB: BP install failed: %lx", addr); 250 printk(KERN_INFO "KGDB: BP install failed: %lx",
251 kgdb_break[i].bpt_addr);
252 continue; 252 continue;
253 } 253 }
254 254
255 kgdb_flush_swbreak_addr(addr); 255 kgdb_flush_swbreak_addr(kgdb_break[i].bpt_addr);
256 kgdb_break[i].state = BP_ACTIVE; 256 kgdb_break[i].state = BP_ACTIVE;
257 } 257 }
258 return ret; 258 return ret;
@@ -301,7 +301,6 @@ int dbg_set_sw_break(unsigned long addr)
301 301
302int dbg_deactivate_sw_breakpoints(void) 302int dbg_deactivate_sw_breakpoints(void)
303{ 303{
304 unsigned long addr;
305 int error; 304 int error;
306 int ret = 0; 305 int ret = 0;
307 int i; 306 int i;
@@ -309,15 +308,14 @@ int dbg_deactivate_sw_breakpoints(void)
309 for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) { 308 for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) {
310 if (kgdb_break[i].state != BP_ACTIVE) 309 if (kgdb_break[i].state != BP_ACTIVE)
311 continue; 310 continue;
312 addr = kgdb_break[i].bpt_addr; 311 error = kgdb_arch_remove_breakpoint(&kgdb_break[i]);
313 error = kgdb_arch_remove_breakpoint(addr,
314 kgdb_break[i].saved_instr);
315 if (error) { 312 if (error) {
316 printk(KERN_INFO "KGDB: BP remove failed: %lx\n", addr); 313 printk(KERN_INFO "KGDB: BP remove failed: %lx\n",
314 kgdb_break[i].bpt_addr);
317 ret = error; 315 ret = error;
318 } 316 }
319 317
320 kgdb_flush_swbreak_addr(addr); 318 kgdb_flush_swbreak_addr(kgdb_break[i].bpt_addr);
321 kgdb_break[i].state = BP_SET; 319 kgdb_break[i].state = BP_SET;
322 } 320 }
323 return ret; 321 return ret;
@@ -351,7 +349,6 @@ int kgdb_isremovedbreak(unsigned long addr)
351 349
352int dbg_remove_all_break(void) 350int dbg_remove_all_break(void)
353{ 351{
354 unsigned long addr;
355 int error; 352 int error;
356 int i; 353 int i;
357 354
@@ -359,12 +356,10 @@ int dbg_remove_all_break(void)
359 for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) { 356 for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) {
360 if (kgdb_break[i].state != BP_ACTIVE) 357 if (kgdb_break[i].state != BP_ACTIVE)
361 goto setundefined; 358 goto setundefined;
362 addr = kgdb_break[i].bpt_addr; 359 error = kgdb_arch_remove_breakpoint(&kgdb_break[i]);
363 error = kgdb_arch_remove_breakpoint(addr,
364 kgdb_break[i].saved_instr);
365 if (error) 360 if (error)
366 printk(KERN_ERR "KGDB: breakpoint remove failed: %lx\n", 361 printk(KERN_ERR "KGDB: breakpoint remove failed: %lx\n",
367 addr); 362 kgdb_break[i].bpt_addr);
368setundefined: 363setundefined:
369 kgdb_break[i].state = BP_UNDEFINED; 364 kgdb_break[i].state = BP_UNDEFINED;
370 } 365 }
diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c
index 9b5f17da1c56..bb9520f0f6ff 100644
--- a/kernel/debug/kdb/kdb_io.c
+++ b/kernel/debug/kdb/kdb_io.c
@@ -743,7 +743,7 @@ kdb_printit:
743 kdb_input_flush(); 743 kdb_input_flush();
744 c = console_drivers; 744 c = console_drivers;
745 745
746 if (!dbg_io_ops->is_console) { 746 if (dbg_io_ops && !dbg_io_ops->is_console) {
747 len = strlen(moreprompt); 747 len = strlen(moreprompt);
748 cp = moreprompt; 748 cp = moreprompt;
749 while (len--) { 749 while (len--) {
diff --git a/kernel/events/core.c b/kernel/events/core.c
index a6a9ec4cd8f5..fd126f82b57c 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -3183,7 +3183,7 @@ static void perf_event_for_each(struct perf_event *event,
3183 perf_event_for_each_child(event, func); 3183 perf_event_for_each_child(event, func);
3184 func(event); 3184 func(event);
3185 list_for_each_entry(sibling, &event->sibling_list, group_entry) 3185 list_for_each_entry(sibling, &event->sibling_list, group_entry)
3186 perf_event_for_each_child(event, func); 3186 perf_event_for_each_child(sibling, func);
3187 mutex_unlock(&ctx->mutex); 3187 mutex_unlock(&ctx->mutex);
3188} 3188}
3189 3189
diff --git a/kernel/fork.c b/kernel/fork.c
index b9372a0bff18..687a15d56243 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -47,6 +47,7 @@
47#include <linux/audit.h> 47#include <linux/audit.h>
48#include <linux/memcontrol.h> 48#include <linux/memcontrol.h>
49#include <linux/ftrace.h> 49#include <linux/ftrace.h>
50#include <linux/proc_fs.h>
50#include <linux/profile.h> 51#include <linux/profile.h>
51#include <linux/rmap.h> 52#include <linux/rmap.h>
52#include <linux/ksm.h> 53#include <linux/ksm.h>
@@ -1464,6 +1465,8 @@ bad_fork_cleanup_io:
1464 if (p->io_context) 1465 if (p->io_context)
1465 exit_io_context(p); 1466 exit_io_context(p);
1466bad_fork_cleanup_namespaces: 1467bad_fork_cleanup_namespaces:
1468 if (unlikely(clone_flags & CLONE_NEWPID))
1469 pid_ns_release_proc(p->nsproxy->pid_ns);
1467 exit_task_namespaces(p); 1470 exit_task_namespaces(p);
1468bad_fork_cleanup_mm: 1471bad_fork_cleanup_mm:
1469 if (p->mm) 1472 if (p->mm)
diff --git a/kernel/irq/Kconfig b/kernel/irq/Kconfig
index cf1a4a68ce44..d1a758bc972a 100644
--- a/kernel/irq/Kconfig
+++ b/kernel/irq/Kconfig
@@ -62,7 +62,7 @@ config IRQ_DOMAIN_DEBUG
62 help 62 help
63 This option will show the mapping relationship between hardware irq 63 This option will show the mapping relationship between hardware irq
64 numbers and Linux irq numbers. The mapping is exposed via debugfs 64 numbers and Linux irq numbers. The mapping is exposed via debugfs
65 in the file "virq_mapping". 65 in the file "irq_domain_mapping".
66 66
67 If you don't know what this means you don't need it. 67 If you don't know what this means you don't need it.
68 68
diff --git a/kernel/irq/debug.h b/kernel/irq/debug.h
index 97a8bfadc88a..e75e29e4434a 100644
--- a/kernel/irq/debug.h
+++ b/kernel/irq/debug.h
@@ -4,10 +4,10 @@
4 4
5#include <linux/kallsyms.h> 5#include <linux/kallsyms.h>
6 6
7#define P(f) if (desc->status_use_accessors & f) printk("%14s set\n", #f) 7#define ___P(f) if (desc->status_use_accessors & f) printk("%14s set\n", #f)
8#define PS(f) if (desc->istate & f) printk("%14s set\n", #f) 8#define ___PS(f) if (desc->istate & f) printk("%14s set\n", #f)
9/* FIXME */ 9/* FIXME */
10#define PD(f) do { } while (0) 10#define ___PD(f) do { } while (0)
11 11
12static inline void print_irq_desc(unsigned int irq, struct irq_desc *desc) 12static inline void print_irq_desc(unsigned int irq, struct irq_desc *desc)
13{ 13{
@@ -23,23 +23,23 @@ static inline void print_irq_desc(unsigned int irq, struct irq_desc *desc)
23 print_symbol("%s\n", (unsigned long)desc->action->handler); 23 print_symbol("%s\n", (unsigned long)desc->action->handler);
24 } 24 }
25 25
26 P(IRQ_LEVEL); 26 ___P(IRQ_LEVEL);
27 P(IRQ_PER_CPU); 27 ___P(IRQ_PER_CPU);
28 P(IRQ_NOPROBE); 28 ___P(IRQ_NOPROBE);
29 P(IRQ_NOREQUEST); 29 ___P(IRQ_NOREQUEST);
30 P(IRQ_NOTHREAD); 30 ___P(IRQ_NOTHREAD);
31 P(IRQ_NOAUTOEN); 31 ___P(IRQ_NOAUTOEN);
32 32
33 PS(IRQS_AUTODETECT); 33 ___PS(IRQS_AUTODETECT);
34 PS(IRQS_REPLAY); 34 ___PS(IRQS_REPLAY);
35 PS(IRQS_WAITING); 35 ___PS(IRQS_WAITING);
36 PS(IRQS_PENDING); 36 ___PS(IRQS_PENDING);
37 37
38 PD(IRQS_INPROGRESS); 38 ___PD(IRQS_INPROGRESS);
39 PD(IRQS_DISABLED); 39 ___PD(IRQS_DISABLED);
40 PD(IRQS_MASKED); 40 ___PD(IRQS_MASKED);
41} 41}
42 42
43#undef P 43#undef ___P
44#undef PS 44#undef ___PS
45#undef PD 45#undef ___PD
diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c
index 3601f3fbf67c..0e0ba5f840b2 100644
--- a/kernel/irq/irqdomain.c
+++ b/kernel/irq/irqdomain.c
@@ -23,7 +23,6 @@ static LIST_HEAD(irq_domain_list);
23static DEFINE_MUTEX(irq_domain_mutex); 23static DEFINE_MUTEX(irq_domain_mutex);
24 24
25static DEFINE_MUTEX(revmap_trees_mutex); 25static DEFINE_MUTEX(revmap_trees_mutex);
26static unsigned int irq_virq_count = NR_IRQS;
27static struct irq_domain *irq_default_domain; 26static struct irq_domain *irq_default_domain;
28 27
29/** 28/**
@@ -184,13 +183,16 @@ struct irq_domain *irq_domain_add_linear(struct device_node *of_node,
184} 183}
185 184
186struct irq_domain *irq_domain_add_nomap(struct device_node *of_node, 185struct irq_domain *irq_domain_add_nomap(struct device_node *of_node,
186 unsigned int max_irq,
187 const struct irq_domain_ops *ops, 187 const struct irq_domain_ops *ops,
188 void *host_data) 188 void *host_data)
189{ 189{
190 struct irq_domain *domain = irq_domain_alloc(of_node, 190 struct irq_domain *domain = irq_domain_alloc(of_node,
191 IRQ_DOMAIN_MAP_NOMAP, ops, host_data); 191 IRQ_DOMAIN_MAP_NOMAP, ops, host_data);
192 if (domain) 192 if (domain) {
193 domain->revmap_data.nomap.max_irq = max_irq ? max_irq : ~0;
193 irq_domain_add(domain); 194 irq_domain_add(domain);
195 }
194 return domain; 196 return domain;
195} 197}
196 198
@@ -262,22 +264,6 @@ void irq_set_default_host(struct irq_domain *domain)
262 irq_default_domain = domain; 264 irq_default_domain = domain;
263} 265}
264 266
265/**
266 * irq_set_virq_count() - Set the maximum number of linux irqs
267 * @count: number of linux irqs, capped with NR_IRQS
268 *
269 * This is mainly for use by platforms like iSeries who want to program
270 * the virtual irq number in the controller to avoid the reverse mapping
271 */
272void irq_set_virq_count(unsigned int count)
273{
274 pr_debug("irq: Trying to set virq count to %d\n", count);
275
276 BUG_ON(count < NUM_ISA_INTERRUPTS);
277 if (count < NR_IRQS)
278 irq_virq_count = count;
279}
280
281static int irq_setup_virq(struct irq_domain *domain, unsigned int virq, 267static int irq_setup_virq(struct irq_domain *domain, unsigned int virq,
282 irq_hw_number_t hwirq) 268 irq_hw_number_t hwirq)
283{ 269{
@@ -320,13 +306,12 @@ unsigned int irq_create_direct_mapping(struct irq_domain *domain)
320 pr_debug("irq: create_direct virq allocation failed\n"); 306 pr_debug("irq: create_direct virq allocation failed\n");
321 return 0; 307 return 0;
322 } 308 }
323 if (virq >= irq_virq_count) { 309 if (virq >= domain->revmap_data.nomap.max_irq) {
324 pr_err("ERROR: no free irqs available below %i maximum\n", 310 pr_err("ERROR: no free irqs available below %i maximum\n",
325 irq_virq_count); 311 domain->revmap_data.nomap.max_irq);
326 irq_free_desc(virq); 312 irq_free_desc(virq);
327 return 0; 313 return 0;
328 } 314 }
329
330 pr_debug("irq: create_direct obtained virq %d\n", virq); 315 pr_debug("irq: create_direct obtained virq %d\n", virq);
331 316
332 if (irq_setup_virq(domain, virq, virq)) { 317 if (irq_setup_virq(domain, virq, virq)) {
@@ -350,7 +335,8 @@ unsigned int irq_create_direct_mapping(struct irq_domain *domain)
350unsigned int irq_create_mapping(struct irq_domain *domain, 335unsigned int irq_create_mapping(struct irq_domain *domain,
351 irq_hw_number_t hwirq) 336 irq_hw_number_t hwirq)
352{ 337{
353 unsigned int virq, hint; 338 unsigned int hint;
339 int virq;
354 340
355 pr_debug("irq: irq_create_mapping(0x%p, 0x%lx)\n", domain, hwirq); 341 pr_debug("irq: irq_create_mapping(0x%p, 0x%lx)\n", domain, hwirq);
356 342
@@ -377,13 +363,13 @@ unsigned int irq_create_mapping(struct irq_domain *domain,
377 return irq_domain_legacy_revmap(domain, hwirq); 363 return irq_domain_legacy_revmap(domain, hwirq);
378 364
379 /* Allocate a virtual interrupt number */ 365 /* Allocate a virtual interrupt number */
380 hint = hwirq % irq_virq_count; 366 hint = hwirq % nr_irqs;
381 if (hint == 0) 367 if (hint == 0)
382 hint++; 368 hint++;
383 virq = irq_alloc_desc_from(hint, 0); 369 virq = irq_alloc_desc_from(hint, 0);
384 if (!virq) 370 if (virq <= 0)
385 virq = irq_alloc_desc_from(1, 0); 371 virq = irq_alloc_desc_from(1, 0);
386 if (!virq) { 372 if (virq <= 0) {
387 pr_debug("irq: -> virq allocation failed\n"); 373 pr_debug("irq: -> virq allocation failed\n");
388 return 0; 374 return 0;
389 } 375 }
@@ -515,7 +501,7 @@ unsigned int irq_find_mapping(struct irq_domain *domain,
515 irq_hw_number_t hwirq) 501 irq_hw_number_t hwirq)
516{ 502{
517 unsigned int i; 503 unsigned int i;
518 unsigned int hint = hwirq % irq_virq_count; 504 unsigned int hint = hwirq % nr_irqs;
519 505
520 /* Look for default domain if nececssary */ 506 /* Look for default domain if nececssary */
521 if (domain == NULL) 507 if (domain == NULL)
@@ -536,7 +522,7 @@ unsigned int irq_find_mapping(struct irq_domain *domain,
536 if (data && (data->domain == domain) && (data->hwirq == hwirq)) 522 if (data && (data->domain == domain) && (data->hwirq == hwirq))
537 return i; 523 return i;
538 i++; 524 i++;
539 if (i >= irq_virq_count) 525 if (i >= nr_irqs)
540 i = 1; 526 i = 1;
541 } while(i != hint); 527 } while(i != hint);
542 return 0; 528 return 0;
@@ -642,8 +628,9 @@ static int virq_debug_show(struct seq_file *m, void *private)
642 void *data; 628 void *data;
643 int i; 629 int i;
644 630
645 seq_printf(m, "%-5s %-7s %-15s %-18s %s\n", "virq", "hwirq", 631 seq_printf(m, "%-5s %-7s %-15s %-*s %s\n", "irq", "hwirq",
646 "chip name", "chip data", "domain name"); 632 "chip name", (int)(2 * sizeof(void *) + 2), "chip data",
633 "domain name");
647 634
648 for (i = 1; i < nr_irqs; i++) { 635 for (i = 1; i < nr_irqs; i++) {
649 desc = irq_to_desc(i); 636 desc = irq_to_desc(i);
@@ -666,7 +653,7 @@ static int virq_debug_show(struct seq_file *m, void *private)
666 seq_printf(m, "%-15s ", p); 653 seq_printf(m, "%-15s ", p);
667 654
668 data = irq_desc_get_chip_data(desc); 655 data = irq_desc_get_chip_data(desc);
669 seq_printf(m, "0x%16p ", data); 656 seq_printf(m, data ? "0x%p " : " %p ", data);
670 657
671 if (desc->irq_data.domain && desc->irq_data.domain->of_node) 658 if (desc->irq_data.domain && desc->irq_data.domain->of_node)
672 p = desc->irq_data.domain->of_node->full_name; 659 p = desc->irq_data.domain->of_node->full_name;
diff --git a/kernel/irq_work.c b/kernel/irq_work.c
index c3c46c72046e..1588e3b2871b 100644
--- a/kernel/irq_work.c
+++ b/kernel/irq_work.c
@@ -5,11 +5,13 @@
5 * context. The enqueueing is NMI-safe. 5 * context. The enqueueing is NMI-safe.
6 */ 6 */
7 7
8#include <linux/bug.h>
8#include <linux/kernel.h> 9#include <linux/kernel.h>
9#include <linux/export.h> 10#include <linux/export.h>
10#include <linux/irq_work.h> 11#include <linux/irq_work.h>
11#include <linux/percpu.h> 12#include <linux/percpu.h>
12#include <linux/hardirq.h> 13#include <linux/hardirq.h>
14#include <linux/irqflags.h>
13#include <asm/processor.h> 15#include <asm/processor.h>
14 16
15/* 17/*
diff --git a/kernel/itimer.c b/kernel/itimer.c
index 22000c3db0dd..8d262b467573 100644
--- a/kernel/itimer.c
+++ b/kernel/itimer.c
@@ -284,8 +284,12 @@ SYSCALL_DEFINE3(setitimer, int, which, struct itimerval __user *, value,
284 if (value) { 284 if (value) {
285 if(copy_from_user(&set_buffer, value, sizeof(set_buffer))) 285 if(copy_from_user(&set_buffer, value, sizeof(set_buffer)))
286 return -EFAULT; 286 return -EFAULT;
287 } else 287 } else {
288 memset((char *) &set_buffer, 0, sizeof(set_buffer)); 288 memset(&set_buffer, 0, sizeof(set_buffer));
289 printk_once(KERN_WARNING "%s calls setitimer() with new_value NULL pointer."
290 " Misfeature support will be removed\n",
291 current->comm);
292 }
289 293
290 error = do_setitimer(which, &set_buffer, ovalue ? &get_buffer : NULL); 294 error = do_setitimer(which, &set_buffer, ovalue ? &get_buffer : NULL);
291 if (error || !ovalue) 295 if (error || !ovalue)
diff --git a/kernel/kmod.c b/kernel/kmod.c
index 957a7aab8ebc..05698a7415fe 100644
--- a/kernel/kmod.c
+++ b/kernel/kmod.c
@@ -322,7 +322,7 @@ static void __call_usermodehelper(struct work_struct *work)
322 * land has been frozen during a system-wide hibernation or suspend operation). 322 * land has been frozen during a system-wide hibernation or suspend operation).
323 * Should always be manipulated under umhelper_sem acquired for write. 323 * Should always be manipulated under umhelper_sem acquired for write.
324 */ 324 */
325static int usermodehelper_disabled = 1; 325static enum umh_disable_depth usermodehelper_disabled = UMH_DISABLED;
326 326
327/* Number of helpers running */ 327/* Number of helpers running */
328static atomic_t running_helpers = ATOMIC_INIT(0); 328static atomic_t running_helpers = ATOMIC_INIT(0);
@@ -334,32 +334,110 @@ static atomic_t running_helpers = ATOMIC_INIT(0);
334static DECLARE_WAIT_QUEUE_HEAD(running_helpers_waitq); 334static DECLARE_WAIT_QUEUE_HEAD(running_helpers_waitq);
335 335
336/* 336/*
337 * Used by usermodehelper_read_lock_wait() to wait for usermodehelper_disabled
338 * to become 'false'.
339 */
340static DECLARE_WAIT_QUEUE_HEAD(usermodehelper_disabled_waitq);
341
342/*
337 * Time to wait for running_helpers to become zero before the setting of 343 * Time to wait for running_helpers to become zero before the setting of
338 * usermodehelper_disabled in usermodehelper_disable() fails 344 * usermodehelper_disabled in usermodehelper_disable() fails
339 */ 345 */
340#define RUNNING_HELPERS_TIMEOUT (5 * HZ) 346#define RUNNING_HELPERS_TIMEOUT (5 * HZ)
341 347
342void read_lock_usermodehelper(void) 348int usermodehelper_read_trylock(void)
343{ 349{
350 DEFINE_WAIT(wait);
351 int ret = 0;
352
344 down_read(&umhelper_sem); 353 down_read(&umhelper_sem);
354 for (;;) {
355 prepare_to_wait(&usermodehelper_disabled_waitq, &wait,
356 TASK_INTERRUPTIBLE);
357 if (!usermodehelper_disabled)
358 break;
359
360 if (usermodehelper_disabled == UMH_DISABLED)
361 ret = -EAGAIN;
362
363 up_read(&umhelper_sem);
364
365 if (ret)
366 break;
367
368 schedule();
369 try_to_freeze();
370
371 down_read(&umhelper_sem);
372 }
373 finish_wait(&usermodehelper_disabled_waitq, &wait);
374 return ret;
375}
376EXPORT_SYMBOL_GPL(usermodehelper_read_trylock);
377
378long usermodehelper_read_lock_wait(long timeout)
379{
380 DEFINE_WAIT(wait);
381
382 if (timeout < 0)
383 return -EINVAL;
384
385 down_read(&umhelper_sem);
386 for (;;) {
387 prepare_to_wait(&usermodehelper_disabled_waitq, &wait,
388 TASK_UNINTERRUPTIBLE);
389 if (!usermodehelper_disabled)
390 break;
391
392 up_read(&umhelper_sem);
393
394 timeout = schedule_timeout(timeout);
395 if (!timeout)
396 break;
397
398 down_read(&umhelper_sem);
399 }
400 finish_wait(&usermodehelper_disabled_waitq, &wait);
401 return timeout;
345} 402}
346EXPORT_SYMBOL_GPL(read_lock_usermodehelper); 403EXPORT_SYMBOL_GPL(usermodehelper_read_lock_wait);
347 404
348void read_unlock_usermodehelper(void) 405void usermodehelper_read_unlock(void)
349{ 406{
350 up_read(&umhelper_sem); 407 up_read(&umhelper_sem);
351} 408}
352EXPORT_SYMBOL_GPL(read_unlock_usermodehelper); 409EXPORT_SYMBOL_GPL(usermodehelper_read_unlock);
353 410
354/** 411/**
355 * usermodehelper_disable - prevent new helpers from being started 412 * __usermodehelper_set_disable_depth - Modify usermodehelper_disabled.
413 * depth: New value to assign to usermodehelper_disabled.
414 *
415 * Change the value of usermodehelper_disabled (under umhelper_sem locked for
416 * writing) and wakeup tasks waiting for it to change.
356 */ 417 */
357int usermodehelper_disable(void) 418void __usermodehelper_set_disable_depth(enum umh_disable_depth depth)
419{
420 down_write(&umhelper_sem);
421 usermodehelper_disabled = depth;
422 wake_up(&usermodehelper_disabled_waitq);
423 up_write(&umhelper_sem);
424}
425
426/**
427 * __usermodehelper_disable - Prevent new helpers from being started.
428 * @depth: New value to assign to usermodehelper_disabled.
429 *
430 * Set usermodehelper_disabled to @depth and wait for running helpers to exit.
431 */
432int __usermodehelper_disable(enum umh_disable_depth depth)
358{ 433{
359 long retval; 434 long retval;
360 435
436 if (!depth)
437 return -EINVAL;
438
361 down_write(&umhelper_sem); 439 down_write(&umhelper_sem);
362 usermodehelper_disabled = 1; 440 usermodehelper_disabled = depth;
363 up_write(&umhelper_sem); 441 up_write(&umhelper_sem);
364 442
365 /* 443 /*
@@ -374,31 +452,10 @@ int usermodehelper_disable(void)
374 if (retval) 452 if (retval)
375 return 0; 453 return 0;
376 454
377 down_write(&umhelper_sem); 455 __usermodehelper_set_disable_depth(UMH_ENABLED);
378 usermodehelper_disabled = 0;
379 up_write(&umhelper_sem);
380 return -EAGAIN; 456 return -EAGAIN;
381} 457}
382 458
383/**
384 * usermodehelper_enable - allow new helpers to be started again
385 */
386void usermodehelper_enable(void)
387{
388 down_write(&umhelper_sem);
389 usermodehelper_disabled = 0;
390 up_write(&umhelper_sem);
391}
392
393/**
394 * usermodehelper_is_disabled - check if new helpers are allowed to be started
395 */
396bool usermodehelper_is_disabled(void)
397{
398 return usermodehelper_disabled;
399}
400EXPORT_SYMBOL_GPL(usermodehelper_is_disabled);
401
402static void helper_lock(void) 459static void helper_lock(void)
403{ 460{
404 atomic_inc(&running_helpers); 461 atomic_inc(&running_helpers);
diff --git a/kernel/padata.c b/kernel/padata.c
index 6f10eb285ece..89fe3d1b9efb 100644
--- a/kernel/padata.c
+++ b/kernel/padata.c
@@ -1,6 +1,8 @@
1/* 1/*
2 * padata.c - generic interface to process data streams in parallel 2 * padata.c - generic interface to process data streams in parallel
3 * 3 *
4 * See Documentation/padata.txt for an api documentation.
5 *
4 * Copyright (C) 2008, 2009 secunet Security Networks AG 6 * Copyright (C) 2008, 2009 secunet Security Networks AG
5 * Copyright (C) 2008, 2009 Steffen Klassert <steffen.klassert@secunet.com> 7 * Copyright (C) 2008, 2009 Steffen Klassert <steffen.klassert@secunet.com>
6 * 8 *
@@ -354,13 +356,13 @@ static int padata_setup_cpumasks(struct parallel_data *pd,
354 if (!alloc_cpumask_var(&pd->cpumask.pcpu, GFP_KERNEL)) 356 if (!alloc_cpumask_var(&pd->cpumask.pcpu, GFP_KERNEL))
355 return -ENOMEM; 357 return -ENOMEM;
356 358
357 cpumask_and(pd->cpumask.pcpu, pcpumask, cpu_active_mask); 359 cpumask_and(pd->cpumask.pcpu, pcpumask, cpu_online_mask);
358 if (!alloc_cpumask_var(&pd->cpumask.cbcpu, GFP_KERNEL)) { 360 if (!alloc_cpumask_var(&pd->cpumask.cbcpu, GFP_KERNEL)) {
359 free_cpumask_var(pd->cpumask.cbcpu); 361 free_cpumask_var(pd->cpumask.cbcpu);
360 return -ENOMEM; 362 return -ENOMEM;
361 } 363 }
362 364
363 cpumask_and(pd->cpumask.cbcpu, cbcpumask, cpu_active_mask); 365 cpumask_and(pd->cpumask.cbcpu, cbcpumask, cpu_online_mask);
364 return 0; 366 return 0;
365} 367}
366 368
@@ -564,7 +566,7 @@ EXPORT_SYMBOL(padata_unregister_cpumask_notifier);
564static bool padata_validate_cpumask(struct padata_instance *pinst, 566static bool padata_validate_cpumask(struct padata_instance *pinst,
565 const struct cpumask *cpumask) 567 const struct cpumask *cpumask)
566{ 568{
567 if (!cpumask_intersects(cpumask, cpu_active_mask)) { 569 if (!cpumask_intersects(cpumask, cpu_online_mask)) {
568 pinst->flags |= PADATA_INVALID; 570 pinst->flags |= PADATA_INVALID;
569 return false; 571 return false;
570 } 572 }
@@ -678,7 +680,7 @@ static int __padata_add_cpu(struct padata_instance *pinst, int cpu)
678{ 680{
679 struct parallel_data *pd; 681 struct parallel_data *pd;
680 682
681 if (cpumask_test_cpu(cpu, cpu_active_mask)) { 683 if (cpumask_test_cpu(cpu, cpu_online_mask)) {
682 pd = padata_alloc_pd(pinst, pinst->cpumask.pcpu, 684 pd = padata_alloc_pd(pinst, pinst->cpumask.pcpu,
683 pinst->cpumask.cbcpu); 685 pinst->cpumask.cbcpu);
684 if (!pd) 686 if (!pd)
@@ -746,6 +748,9 @@ static int __padata_remove_cpu(struct padata_instance *pinst, int cpu)
746 return -ENOMEM; 748 return -ENOMEM;
747 749
748 padata_replace(pinst, pd); 750 padata_replace(pinst, pd);
751
752 cpumask_clear_cpu(cpu, pd->cpumask.cbcpu);
753 cpumask_clear_cpu(cpu, pd->cpumask.pcpu);
749 } 754 }
750 755
751 return 0; 756 return 0;
diff --git a/kernel/panic.c b/kernel/panic.c
index 80aed44e345a..8ed89a175d79 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -97,7 +97,7 @@ void panic(const char *fmt, ...)
97 /* 97 /*
98 * Avoid nested stack-dumping if a panic occurs during oops processing 98 * Avoid nested stack-dumping if a panic occurs during oops processing
99 */ 99 */
100 if (!oops_in_progress) 100 if (!test_taint(TAINT_DIE) && oops_in_progress <= 1)
101 dump_stack(); 101 dump_stack();
102#endif 102#endif
103 103
diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index 0a186cfde788..e09dfbfeecee 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -16,7 +16,6 @@
16#include <linux/string.h> 16#include <linux/string.h>
17#include <linux/device.h> 17#include <linux/device.h>
18#include <linux/async.h> 18#include <linux/async.h>
19#include <linux/kmod.h>
20#include <linux/delay.h> 19#include <linux/delay.h>
21#include <linux/fs.h> 20#include <linux/fs.h>
22#include <linux/mount.h> 21#include <linux/mount.h>
@@ -611,14 +610,10 @@ int hibernate(void)
611 if (error) 610 if (error)
612 goto Exit; 611 goto Exit;
613 612
614 error = usermodehelper_disable();
615 if (error)
616 goto Exit;
617
618 /* Allocate memory management structures */ 613 /* Allocate memory management structures */
619 error = create_basic_memory_bitmaps(); 614 error = create_basic_memory_bitmaps();
620 if (error) 615 if (error)
621 goto Enable_umh; 616 goto Exit;
622 617
623 printk(KERN_INFO "PM: Syncing filesystems ... "); 618 printk(KERN_INFO "PM: Syncing filesystems ... ");
624 sys_sync(); 619 sys_sync();
@@ -661,8 +656,6 @@ int hibernate(void)
661 656
662 Free_bitmaps: 657 Free_bitmaps:
663 free_basic_memory_bitmaps(); 658 free_basic_memory_bitmaps();
664 Enable_umh:
665 usermodehelper_enable();
666 Exit: 659 Exit:
667 pm_notifier_call_chain(PM_POST_HIBERNATION); 660 pm_notifier_call_chain(PM_POST_HIBERNATION);
668 pm_restore_console(); 661 pm_restore_console();
@@ -777,15 +770,9 @@ static int software_resume(void)
777 if (error) 770 if (error)
778 goto close_finish; 771 goto close_finish;
779 772
780 error = usermodehelper_disable();
781 if (error)
782 goto close_finish;
783
784 error = create_basic_memory_bitmaps(); 773 error = create_basic_memory_bitmaps();
785 if (error) { 774 if (error)
786 usermodehelper_enable();
787 goto close_finish; 775 goto close_finish;
788 }
789 776
790 pr_debug("PM: Preparing processes for restore.\n"); 777 pr_debug("PM: Preparing processes for restore.\n");
791 error = freeze_processes(); 778 error = freeze_processes();
@@ -806,7 +793,6 @@ static int software_resume(void)
806 thaw_processes(); 793 thaw_processes();
807 Done: 794 Done:
808 free_basic_memory_bitmaps(); 795 free_basic_memory_bitmaps();
809 usermodehelper_enable();
810 Finish: 796 Finish:
811 pm_notifier_call_chain(PM_POST_RESTORE); 797 pm_notifier_call_chain(PM_POST_RESTORE);
812 pm_restore_console(); 798 pm_restore_console();
diff --git a/kernel/power/process.c b/kernel/power/process.c
index 0d2aeb226108..19db29f67558 100644
--- a/kernel/power/process.c
+++ b/kernel/power/process.c
@@ -16,6 +16,7 @@
16#include <linux/freezer.h> 16#include <linux/freezer.h>
17#include <linux/delay.h> 17#include <linux/delay.h>
18#include <linux/workqueue.h> 18#include <linux/workqueue.h>
19#include <linux/kmod.h>
19 20
20/* 21/*
21 * Timeout for stopping processes 22 * Timeout for stopping processes
@@ -122,6 +123,10 @@ int freeze_processes(void)
122{ 123{
123 int error; 124 int error;
124 125
126 error = __usermodehelper_disable(UMH_FREEZING);
127 if (error)
128 return error;
129
125 if (!pm_freezing) 130 if (!pm_freezing)
126 atomic_inc(&system_freezing_cnt); 131 atomic_inc(&system_freezing_cnt);
127 132
@@ -130,6 +135,7 @@ int freeze_processes(void)
130 error = try_to_freeze_tasks(true); 135 error = try_to_freeze_tasks(true);
131 if (!error) { 136 if (!error) {
132 printk("done."); 137 printk("done.");
138 __usermodehelper_set_disable_depth(UMH_DISABLED);
133 oom_killer_disable(); 139 oom_killer_disable();
134 } 140 }
135 printk("\n"); 141 printk("\n");
@@ -187,6 +193,8 @@ void thaw_processes(void)
187 } while_each_thread(g, p); 193 } while_each_thread(g, p);
188 read_unlock(&tasklist_lock); 194 read_unlock(&tasklist_lock);
189 195
196 usermodehelper_enable();
197
190 schedule(); 198 schedule();
191 printk("done.\n"); 199 printk("done.\n");
192} 200}
diff --git a/kernel/power/qos.c b/kernel/power/qos.c
index d6d6dbd1ecc0..6a031e684026 100644
--- a/kernel/power/qos.c
+++ b/kernel/power/qos.c
@@ -230,6 +230,21 @@ int pm_qos_request_active(struct pm_qos_request *req)
230EXPORT_SYMBOL_GPL(pm_qos_request_active); 230EXPORT_SYMBOL_GPL(pm_qos_request_active);
231 231
232/** 232/**
233 * pm_qos_work_fn - the timeout handler of pm_qos_update_request_timeout
234 * @work: work struct for the delayed work (timeout)
235 *
236 * This cancels the timeout request by falling back to the default at timeout.
237 */
238static void pm_qos_work_fn(struct work_struct *work)
239{
240 struct pm_qos_request *req = container_of(to_delayed_work(work),
241 struct pm_qos_request,
242 work);
243
244 pm_qos_update_request(req, PM_QOS_DEFAULT_VALUE);
245}
246
247/**
233 * pm_qos_add_request - inserts new qos request into the list 248 * pm_qos_add_request - inserts new qos request into the list
234 * @req: pointer to a preallocated handle 249 * @req: pointer to a preallocated handle
235 * @pm_qos_class: identifies which list of qos request to use 250 * @pm_qos_class: identifies which list of qos request to use
@@ -253,6 +268,7 @@ void pm_qos_add_request(struct pm_qos_request *req,
253 return; 268 return;
254 } 269 }
255 req->pm_qos_class = pm_qos_class; 270 req->pm_qos_class = pm_qos_class;
271 INIT_DELAYED_WORK(&req->work, pm_qos_work_fn);
256 pm_qos_update_target(pm_qos_array[pm_qos_class]->constraints, 272 pm_qos_update_target(pm_qos_array[pm_qos_class]->constraints,
257 &req->node, PM_QOS_ADD_REQ, value); 273 &req->node, PM_QOS_ADD_REQ, value);
258} 274}
@@ -279,6 +295,9 @@ void pm_qos_update_request(struct pm_qos_request *req,
279 return; 295 return;
280 } 296 }
281 297
298 if (delayed_work_pending(&req->work))
299 cancel_delayed_work_sync(&req->work);
300
282 if (new_value != req->node.prio) 301 if (new_value != req->node.prio)
283 pm_qos_update_target( 302 pm_qos_update_target(
284 pm_qos_array[req->pm_qos_class]->constraints, 303 pm_qos_array[req->pm_qos_class]->constraints,
@@ -287,6 +306,34 @@ void pm_qos_update_request(struct pm_qos_request *req,
287EXPORT_SYMBOL_GPL(pm_qos_update_request); 306EXPORT_SYMBOL_GPL(pm_qos_update_request);
288 307
289/** 308/**
309 * pm_qos_update_request_timeout - modifies an existing qos request temporarily.
310 * @req : handle to list element holding a pm_qos request to use
311 * @new_value: defines the temporal qos request
312 * @timeout_us: the effective duration of this qos request in usecs.
313 *
314 * After timeout_us, this qos request is cancelled automatically.
315 */
316void pm_qos_update_request_timeout(struct pm_qos_request *req, s32 new_value,
317 unsigned long timeout_us)
318{
319 if (!req)
320 return;
321 if (WARN(!pm_qos_request_active(req),
322 "%s called for unknown object.", __func__))
323 return;
324
325 if (delayed_work_pending(&req->work))
326 cancel_delayed_work_sync(&req->work);
327
328 if (new_value != req->node.prio)
329 pm_qos_update_target(
330 pm_qos_array[req->pm_qos_class]->constraints,
331 &req->node, PM_QOS_UPDATE_REQ, new_value);
332
333 schedule_delayed_work(&req->work, usecs_to_jiffies(timeout_us));
334}
335
336/**
290 * pm_qos_remove_request - modifies an existing qos request 337 * pm_qos_remove_request - modifies an existing qos request
291 * @req: handle to request list element 338 * @req: handle to request list element
292 * 339 *
@@ -305,6 +352,9 @@ void pm_qos_remove_request(struct pm_qos_request *req)
305 return; 352 return;
306 } 353 }
307 354
355 if (delayed_work_pending(&req->work))
356 cancel_delayed_work_sync(&req->work);
357
308 pm_qos_update_target(pm_qos_array[req->pm_qos_class]->constraints, 358 pm_qos_update_target(pm_qos_array[req->pm_qos_class]->constraints,
309 &req->node, PM_QOS_REMOVE_REQ, 359 &req->node, PM_QOS_REMOVE_REQ,
310 PM_QOS_DEFAULT_VALUE); 360 PM_QOS_DEFAULT_VALUE);
diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c
index 88e5c967370d..396d262b8fd0 100644
--- a/kernel/power/suspend.c
+++ b/kernel/power/suspend.c
@@ -12,7 +12,6 @@
12#include <linux/delay.h> 12#include <linux/delay.h>
13#include <linux/errno.h> 13#include <linux/errno.h>
14#include <linux/init.h> 14#include <linux/init.h>
15#include <linux/kmod.h>
16#include <linux/console.h> 15#include <linux/console.h>
17#include <linux/cpu.h> 16#include <linux/cpu.h>
18#include <linux/syscalls.h> 17#include <linux/syscalls.h>
@@ -102,17 +101,12 @@ static int suspend_prepare(void)
102 if (error) 101 if (error)
103 goto Finish; 102 goto Finish;
104 103
105 error = usermodehelper_disable();
106 if (error)
107 goto Finish;
108
109 error = suspend_freeze_processes(); 104 error = suspend_freeze_processes();
110 if (!error) 105 if (!error)
111 return 0; 106 return 0;
112 107
113 suspend_stats.failed_freeze++; 108 suspend_stats.failed_freeze++;
114 dpm_save_failed_step(SUSPEND_FREEZE); 109 dpm_save_failed_step(SUSPEND_FREEZE);
115 usermodehelper_enable();
116 Finish: 110 Finish:
117 pm_notifier_call_chain(PM_POST_SUSPEND); 111 pm_notifier_call_chain(PM_POST_SUSPEND);
118 pm_restore_console(); 112 pm_restore_console();
@@ -259,7 +253,6 @@ int suspend_devices_and_enter(suspend_state_t state)
259static void suspend_finish(void) 253static void suspend_finish(void)
260{ 254{
261 suspend_thaw_processes(); 255 suspend_thaw_processes();
262 usermodehelper_enable();
263 pm_notifier_call_chain(PM_POST_SUSPEND); 256 pm_notifier_call_chain(PM_POST_SUSPEND);
264 pm_restore_console(); 257 pm_restore_console();
265} 258}
diff --git a/kernel/power/swap.c b/kernel/power/swap.c
index 8742fd013a94..eef311a58a64 100644
--- a/kernel/power/swap.c
+++ b/kernel/power/swap.c
@@ -51,6 +51,23 @@
51 51
52#define MAP_PAGE_ENTRIES (PAGE_SIZE / sizeof(sector_t) - 1) 52#define MAP_PAGE_ENTRIES (PAGE_SIZE / sizeof(sector_t) - 1)
53 53
54/*
55 * Number of free pages that are not high.
56 */
57static inline unsigned long low_free_pages(void)
58{
59 return nr_free_pages() - nr_free_highpages();
60}
61
62/*
63 * Number of pages required to be kept free while writing the image. Always
64 * half of all available low pages before the writing starts.
65 */
66static inline unsigned long reqd_free_pages(void)
67{
68 return low_free_pages() / 2;
69}
70
54struct swap_map_page { 71struct swap_map_page {
55 sector_t entries[MAP_PAGE_ENTRIES]; 72 sector_t entries[MAP_PAGE_ENTRIES];
56 sector_t next_swap; 73 sector_t next_swap;
@@ -72,7 +89,7 @@ struct swap_map_handle {
72 sector_t cur_swap; 89 sector_t cur_swap;
73 sector_t first_sector; 90 sector_t first_sector;
74 unsigned int k; 91 unsigned int k;
75 unsigned long nr_free_pages, written; 92 unsigned long reqd_free_pages;
76 u32 crc32; 93 u32 crc32;
77}; 94};
78 95
@@ -316,8 +333,7 @@ static int get_swap_writer(struct swap_map_handle *handle)
316 goto err_rel; 333 goto err_rel;
317 } 334 }
318 handle->k = 0; 335 handle->k = 0;
319 handle->nr_free_pages = nr_free_pages() >> 1; 336 handle->reqd_free_pages = reqd_free_pages();
320 handle->written = 0;
321 handle->first_sector = handle->cur_swap; 337 handle->first_sector = handle->cur_swap;
322 return 0; 338 return 0;
323err_rel: 339err_rel:
@@ -352,11 +368,11 @@ static int swap_write_page(struct swap_map_handle *handle, void *buf,
352 handle->cur_swap = offset; 368 handle->cur_swap = offset;
353 handle->k = 0; 369 handle->k = 0;
354 } 370 }
355 if (bio_chain && ++handle->written > handle->nr_free_pages) { 371 if (bio_chain && low_free_pages() <= handle->reqd_free_pages) {
356 error = hib_wait_on_bio_chain(bio_chain); 372 error = hib_wait_on_bio_chain(bio_chain);
357 if (error) 373 if (error)
358 goto out; 374 goto out;
359 handle->written = 0; 375 handle->reqd_free_pages = reqd_free_pages();
360 } 376 }
361 out: 377 out:
362 return error; 378 return error;
@@ -618,7 +634,7 @@ static int save_image_lzo(struct swap_map_handle *handle,
618 * Adjust number of free pages after all allocations have been done. 634 * Adjust number of free pages after all allocations have been done.
619 * We don't want to run out of pages when writing. 635 * We don't want to run out of pages when writing.
620 */ 636 */
621 handle->nr_free_pages = nr_free_pages() >> 1; 637 handle->reqd_free_pages = reqd_free_pages();
622 638
623 /* 639 /*
624 * Start the CRC32 thread. 640 * Start the CRC32 thread.
diff --git a/kernel/power/user.c b/kernel/power/user.c
index 33c4329205af..91b0fd021a95 100644
--- a/kernel/power/user.c
+++ b/kernel/power/user.c
@@ -12,7 +12,6 @@
12#include <linux/suspend.h> 12#include <linux/suspend.h>
13#include <linux/syscalls.h> 13#include <linux/syscalls.h>
14#include <linux/reboot.h> 14#include <linux/reboot.h>
15#include <linux/kmod.h>
16#include <linux/string.h> 15#include <linux/string.h>
17#include <linux/device.h> 16#include <linux/device.h>
18#include <linux/miscdevice.h> 17#include <linux/miscdevice.h>
@@ -222,14 +221,8 @@ static long snapshot_ioctl(struct file *filp, unsigned int cmd,
222 sys_sync(); 221 sys_sync();
223 printk("done.\n"); 222 printk("done.\n");
224 223
225 error = usermodehelper_disable();
226 if (error)
227 break;
228
229 error = freeze_processes(); 224 error = freeze_processes();
230 if (error) 225 if (!error)
231 usermodehelper_enable();
232 else
233 data->frozen = 1; 226 data->frozen = 1;
234 break; 227 break;
235 228
@@ -238,7 +231,6 @@ static long snapshot_ioctl(struct file *filp, unsigned int cmd,
238 break; 231 break;
239 pm_restore_gfp_mask(); 232 pm_restore_gfp_mask();
240 thaw_processes(); 233 thaw_processes();
241 usermodehelper_enable();
242 data->frozen = 0; 234 data->frozen = 0;
243 break; 235 break;
244 236
diff --git a/kernel/rcutree.c b/kernel/rcutree.c
index 1050d6d3922c..d0c5baf1ab18 100644
--- a/kernel/rcutree.c
+++ b/kernel/rcutree.c
@@ -1820,7 +1820,6 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
1820 * a quiescent state betweentimes. 1820 * a quiescent state betweentimes.
1821 */ 1821 */
1822 local_irq_save(flags); 1822 local_irq_save(flags);
1823 WARN_ON_ONCE(cpu_is_offline(smp_processor_id()));
1824 rdp = this_cpu_ptr(rsp->rda); 1823 rdp = this_cpu_ptr(rsp->rda);
1825 1824
1826 /* Add the callback to our list. */ 1825 /* Add the callback to our list. */
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 4603b9d8f30a..0533a688ce22 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -6405,16 +6405,26 @@ static void __sdt_free(const struct cpumask *cpu_map)
6405 struct sd_data *sdd = &tl->data; 6405 struct sd_data *sdd = &tl->data;
6406 6406
6407 for_each_cpu(j, cpu_map) { 6407 for_each_cpu(j, cpu_map) {
6408 struct sched_domain *sd = *per_cpu_ptr(sdd->sd, j); 6408 struct sched_domain *sd;
6409 if (sd && (sd->flags & SD_OVERLAP)) 6409
6410 free_sched_groups(sd->groups, 0); 6410 if (sdd->sd) {
6411 kfree(*per_cpu_ptr(sdd->sd, j)); 6411 sd = *per_cpu_ptr(sdd->sd, j);
6412 kfree(*per_cpu_ptr(sdd->sg, j)); 6412 if (sd && (sd->flags & SD_OVERLAP))
6413 kfree(*per_cpu_ptr(sdd->sgp, j)); 6413 free_sched_groups(sd->groups, 0);
6414 kfree(*per_cpu_ptr(sdd->sd, j));
6415 }
6416
6417 if (sdd->sg)
6418 kfree(*per_cpu_ptr(sdd->sg, j));
6419 if (sdd->sgp)
6420 kfree(*per_cpu_ptr(sdd->sgp, j));
6414 } 6421 }
6415 free_percpu(sdd->sd); 6422 free_percpu(sdd->sd);
6423 sdd->sd = NULL;
6416 free_percpu(sdd->sg); 6424 free_percpu(sdd->sg);
6425 sdd->sg = NULL;
6417 free_percpu(sdd->sgp); 6426 free_percpu(sdd->sgp);
6427 sdd->sgp = NULL;
6418 } 6428 }
6419} 6429}
6420 6430
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 0d97ebdc58f0..e9553640c1c3 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -784,7 +784,7 @@ account_entity_enqueue(struct cfs_rq *cfs_rq, struct sched_entity *se)
784 update_load_add(&rq_of(cfs_rq)->load, se->load.weight); 784 update_load_add(&rq_of(cfs_rq)->load, se->load.weight);
785#ifdef CONFIG_SMP 785#ifdef CONFIG_SMP
786 if (entity_is_task(se)) 786 if (entity_is_task(se))
787 list_add_tail(&se->group_node, &rq_of(cfs_rq)->cfs_tasks); 787 list_add(&se->group_node, &rq_of(cfs_rq)->cfs_tasks);
788#endif 788#endif
789 cfs_rq->nr_running++; 789 cfs_rq->nr_running++;
790} 790}
@@ -3215,6 +3215,8 @@ static int move_one_task(struct lb_env *env)
3215 3215
3216static unsigned long task_h_load(struct task_struct *p); 3216static unsigned long task_h_load(struct task_struct *p);
3217 3217
3218static const unsigned int sched_nr_migrate_break = 32;
3219
3218/* 3220/*
3219 * move_tasks tries to move up to load_move weighted load from busiest to 3221 * move_tasks tries to move up to load_move weighted load from busiest to
3220 * this_rq, as part of a balancing operation within domain "sd". 3222 * this_rq, as part of a balancing operation within domain "sd".
@@ -3242,7 +3244,7 @@ static int move_tasks(struct lb_env *env)
3242 3244
3243 /* take a breather every nr_migrate tasks */ 3245 /* take a breather every nr_migrate tasks */
3244 if (env->loop > env->loop_break) { 3246 if (env->loop > env->loop_break) {
3245 env->loop_break += sysctl_sched_nr_migrate; 3247 env->loop_break += sched_nr_migrate_break;
3246 env->flags |= LBF_NEED_BREAK; 3248 env->flags |= LBF_NEED_BREAK;
3247 break; 3249 break;
3248 } 3250 }
@@ -3252,7 +3254,7 @@ static int move_tasks(struct lb_env *env)
3252 3254
3253 load = task_h_load(p); 3255 load = task_h_load(p);
3254 3256
3255 if (load < 16 && !env->sd->nr_balance_failed) 3257 if (sched_feat(LB_MIN) && load < 16 && !env->sd->nr_balance_failed)
3256 goto next; 3258 goto next;
3257 3259
3258 if ((load / 2) > env->load_move) 3260 if ((load / 2) > env->load_move)
@@ -4407,7 +4409,7 @@ static int load_balance(int this_cpu, struct rq *this_rq,
4407 .dst_cpu = this_cpu, 4409 .dst_cpu = this_cpu,
4408 .dst_rq = this_rq, 4410 .dst_rq = this_rq,
4409 .idle = idle, 4411 .idle = idle,
4410 .loop_break = sysctl_sched_nr_migrate, 4412 .loop_break = sched_nr_migrate_break,
4411 }; 4413 };
4412 4414
4413 cpumask_copy(cpus, cpu_active_mask); 4415 cpumask_copy(cpus, cpu_active_mask);
@@ -4445,10 +4447,10 @@ redo:
4445 * correctly treated as an imbalance. 4447 * correctly treated as an imbalance.
4446 */ 4448 */
4447 env.flags |= LBF_ALL_PINNED; 4449 env.flags |= LBF_ALL_PINNED;
4448 env.load_move = imbalance; 4450 env.load_move = imbalance;
4449 env.src_cpu = busiest->cpu; 4451 env.src_cpu = busiest->cpu;
4450 env.src_rq = busiest; 4452 env.src_rq = busiest;
4451 env.loop_max = busiest->nr_running; 4453 env.loop_max = min_t(unsigned long, sysctl_sched_nr_migrate, busiest->nr_running);
4452 4454
4453more_balance: 4455more_balance:
4454 local_irq_save(flags); 4456 local_irq_save(flags);
diff --git a/kernel/sched/features.h b/kernel/sched/features.h
index e61fd73913d0..de00a486c5c6 100644
--- a/kernel/sched/features.h
+++ b/kernel/sched/features.h
@@ -68,3 +68,4 @@ SCHED_FEAT(TTWU_QUEUE, true)
68 68
69SCHED_FEAT(FORCE_SD_OVERLAP, false) 69SCHED_FEAT(FORCE_SD_OVERLAP, false)
70SCHED_FEAT(RT_RUNTIME_SHARE, true) 70SCHED_FEAT(RT_RUNTIME_SHARE, true)
71SCHED_FEAT(LB_MIN, false)
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 52b3a06a02f8..4ab11879aeb4 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -170,7 +170,7 @@ static int proc_taint(struct ctl_table *table, int write,
170#endif 170#endif
171 171
172#ifdef CONFIG_PRINTK 172#ifdef CONFIG_PRINTK
173static int proc_dmesg_restrict(struct ctl_table *table, int write, 173static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
174 void __user *buffer, size_t *lenp, loff_t *ppos); 174 void __user *buffer, size_t *lenp, loff_t *ppos);
175#endif 175#endif
176 176
@@ -703,7 +703,7 @@ static struct ctl_table kern_table[] = {
703 .data = &dmesg_restrict, 703 .data = &dmesg_restrict,
704 .maxlen = sizeof(int), 704 .maxlen = sizeof(int),
705 .mode = 0644, 705 .mode = 0644,
706 .proc_handler = proc_dointvec_minmax, 706 .proc_handler = proc_dointvec_minmax_sysadmin,
707 .extra1 = &zero, 707 .extra1 = &zero,
708 .extra2 = &one, 708 .extra2 = &one,
709 }, 709 },
@@ -712,7 +712,7 @@ static struct ctl_table kern_table[] = {
712 .data = &kptr_restrict, 712 .data = &kptr_restrict,
713 .maxlen = sizeof(int), 713 .maxlen = sizeof(int),
714 .mode = 0644, 714 .mode = 0644,
715 .proc_handler = proc_dmesg_restrict, 715 .proc_handler = proc_dointvec_minmax_sysadmin,
716 .extra1 = &zero, 716 .extra1 = &zero,
717 .extra2 = &two, 717 .extra2 = &two,
718 }, 718 },
@@ -1943,7 +1943,7 @@ static int proc_taint(struct ctl_table *table, int write,
1943} 1943}
1944 1944
1945#ifdef CONFIG_PRINTK 1945#ifdef CONFIG_PRINTK
1946static int proc_dmesg_restrict(struct ctl_table *table, int write, 1946static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
1947 void __user *buffer, size_t *lenp, loff_t *ppos) 1947 void __user *buffer, size_t *lenp, loff_t *ppos)
1948{ 1948{
1949 if (write && !capable(CAP_SYS_ADMIN)) 1949 if (write && !capable(CAP_SYS_ADMIN))
diff --git a/kernel/time/Kconfig b/kernel/time/Kconfig
index 2cf9cc7aa103..a20dc8a3c949 100644
--- a/kernel/time/Kconfig
+++ b/kernel/time/Kconfig
@@ -1,6 +1,10 @@
1# 1#
2# Timer subsystem related configuration options 2# Timer subsystem related configuration options
3# 3#
4
5# Core internal switch. Selected by NO_HZ / HIGH_RES_TIMERS. This is
6# only related to the tick functionality. Oneshot clockevent devices
7# are supported independ of this.
4config TICK_ONESHOT 8config TICK_ONESHOT
5 bool 9 bool
6 10
diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
index e883f57a3cd3..f113755695e2 100644
--- a/kernel/time/tick-broadcast.c
+++ b/kernel/time/tick-broadcast.c
@@ -346,7 +346,8 @@ int tick_resume_broadcast(void)
346 tick_get_broadcast_mask()); 346 tick_get_broadcast_mask());
347 break; 347 break;
348 case TICKDEV_MODE_ONESHOT: 348 case TICKDEV_MODE_ONESHOT:
349 broadcast = tick_resume_broadcast_oneshot(bc); 349 if (!cpumask_empty(tick_get_broadcast_mask()))
350 broadcast = tick_resume_broadcast_oneshot(bc);
350 break; 351 break;
351 } 352 }
352 } 353 }
@@ -373,6 +374,9 @@ static int tick_broadcast_set_event(ktime_t expires, int force)
373{ 374{
374 struct clock_event_device *bc = tick_broadcast_device.evtdev; 375 struct clock_event_device *bc = tick_broadcast_device.evtdev;
375 376
377 if (bc->mode != CLOCK_EVT_MODE_ONESHOT)
378 clockevents_set_mode(bc, CLOCK_EVT_MODE_ONESHOT);
379
376 return clockevents_program_event(bc, expires, force); 380 return clockevents_program_event(bc, expires, force);
377} 381}
378 382
@@ -531,7 +535,6 @@ void tick_broadcast_setup_oneshot(struct clock_event_device *bc)
531 int was_periodic = bc->mode == CLOCK_EVT_MODE_PERIODIC; 535 int was_periodic = bc->mode == CLOCK_EVT_MODE_PERIODIC;
532 536
533 bc->event_handler = tick_handle_oneshot_broadcast; 537 bc->event_handler = tick_handle_oneshot_broadcast;
534 clockevents_set_mode(bc, CLOCK_EVT_MODE_ONESHOT);
535 538
536 /* Take the do_timer update */ 539 /* Take the do_timer update */
537 tick_do_timer_cpu = cpu; 540 tick_do_timer_cpu = cpu;
@@ -549,6 +552,7 @@ void tick_broadcast_setup_oneshot(struct clock_event_device *bc)
549 to_cpumask(tmpmask)); 552 to_cpumask(tmpmask));
550 553
551 if (was_periodic && !cpumask_empty(to_cpumask(tmpmask))) { 554 if (was_periodic && !cpumask_empty(to_cpumask(tmpmask))) {
555 clockevents_set_mode(bc, CLOCK_EVT_MODE_ONESHOT);
552 tick_broadcast_init_next_event(to_cpumask(tmpmask), 556 tick_broadcast_init_next_event(to_cpumask(tmpmask),
553 tick_next_period); 557 tick_next_period);
554 tick_broadcast_set_event(tick_next_period, 1); 558 tick_broadcast_set_event(tick_next_period, 1);
@@ -575,15 +579,12 @@ void tick_broadcast_switch_to_oneshot(void)
575 unsigned long flags; 579 unsigned long flags;
576 580
577 raw_spin_lock_irqsave(&tick_broadcast_lock, flags); 581 raw_spin_lock_irqsave(&tick_broadcast_lock, flags);
578 if (cpumask_empty(tick_get_broadcast_mask()))
579 goto end;
580 582
581 tick_broadcast_device.mode = TICKDEV_MODE_ONESHOT; 583 tick_broadcast_device.mode = TICKDEV_MODE_ONESHOT;
582 bc = tick_broadcast_device.evtdev; 584 bc = tick_broadcast_device.evtdev;
583 if (bc) 585 if (bc)
584 tick_broadcast_setup_oneshot(bc); 586 tick_broadcast_setup_oneshot(bc);
585 587
586end:
587 raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags); 588 raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags);
588} 589}
589 590
diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c
index 3526038f2836..6a3a5b9ff561 100644
--- a/kernel/time/tick-sched.c
+++ b/kernel/time/tick-sched.c
@@ -534,9 +534,9 @@ static void tick_nohz_restart(struct tick_sched *ts, ktime_t now)
534 hrtimer_get_expires(&ts->sched_timer), 0)) 534 hrtimer_get_expires(&ts->sched_timer), 0))
535 break; 535 break;
536 } 536 }
537 /* Update jiffies and reread time */ 537 /* Reread time and update jiffies */
538 tick_do_update_jiffies64(now);
539 now = ktime_get(); 538 now = ktime_get();
539 tick_do_update_jiffies64(now);
540 } 540 }
541} 541}
542 542
diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index cdea7b56b0c9..c0bd0308741c 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -311,13 +311,6 @@ int blk_trace_remove(struct request_queue *q)
311} 311}
312EXPORT_SYMBOL_GPL(blk_trace_remove); 312EXPORT_SYMBOL_GPL(blk_trace_remove);
313 313
314static int blk_dropped_open(struct inode *inode, struct file *filp)
315{
316 filp->private_data = inode->i_private;
317
318 return 0;
319}
320
321static ssize_t blk_dropped_read(struct file *filp, char __user *buffer, 314static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
322 size_t count, loff_t *ppos) 315 size_t count, loff_t *ppos)
323{ 316{
@@ -331,18 +324,11 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
331 324
332static const struct file_operations blk_dropped_fops = { 325static const struct file_operations blk_dropped_fops = {
333 .owner = THIS_MODULE, 326 .owner = THIS_MODULE,
334 .open = blk_dropped_open, 327 .open = simple_open,
335 .read = blk_dropped_read, 328 .read = blk_dropped_read,
336 .llseek = default_llseek, 329 .llseek = default_llseek,
337}; 330};
338 331
339static int blk_msg_open(struct inode *inode, struct file *filp)
340{
341 filp->private_data = inode->i_private;
342
343 return 0;
344}
345
346static ssize_t blk_msg_write(struct file *filp, const char __user *buffer, 332static ssize_t blk_msg_write(struct file *filp, const char __user *buffer,
347 size_t count, loff_t *ppos) 333 size_t count, loff_t *ppos)
348{ 334{
@@ -371,7 +357,7 @@ static ssize_t blk_msg_write(struct file *filp, const char __user *buffer,
371 357
372static const struct file_operations blk_msg_fops = { 358static const struct file_operations blk_msg_fops = {
373 .owner = THIS_MODULE, 359 .owner = THIS_MODULE,
374 .open = blk_msg_open, 360 .open = simple_open,
375 .write = blk_msg_write, 361 .write = blk_msg_write,
376 .llseek = noop_llseek, 362 .llseek = noop_llseek,
377}; 363};
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index ed7b5d1e12f4..2a22255c1010 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -4629,7 +4629,8 @@ static ssize_t
4629rb_simple_read(struct file *filp, char __user *ubuf, 4629rb_simple_read(struct file *filp, char __user *ubuf,
4630 size_t cnt, loff_t *ppos) 4630 size_t cnt, loff_t *ppos)
4631{ 4631{
4632 struct ring_buffer *buffer = filp->private_data; 4632 struct trace_array *tr = filp->private_data;
4633 struct ring_buffer *buffer = tr->buffer;
4633 char buf[64]; 4634 char buf[64];
4634 int r; 4635 int r;
4635 4636
@@ -4647,7 +4648,8 @@ static ssize_t
4647rb_simple_write(struct file *filp, const char __user *ubuf, 4648rb_simple_write(struct file *filp, const char __user *ubuf,
4648 size_t cnt, loff_t *ppos) 4649 size_t cnt, loff_t *ppos)
4649{ 4650{
4650 struct ring_buffer *buffer = filp->private_data; 4651 struct trace_array *tr = filp->private_data;
4652 struct ring_buffer *buffer = tr->buffer;
4651 unsigned long val; 4653 unsigned long val;
4652 int ret; 4654 int ret;
4653 4655
@@ -4734,7 +4736,7 @@ static __init int tracer_init_debugfs(void)
4734 &trace_clock_fops); 4736 &trace_clock_fops);
4735 4737
4736 trace_create_file("tracing_on", 0644, d_tracer, 4738 trace_create_file("tracing_on", 0644, d_tracer,
4737 global_trace.buffer, &rb_simple_fops); 4739 &global_trace, &rb_simple_fops);
4738 4740
4739#ifdef CONFIG_DYNAMIC_FTRACE 4741#ifdef CONFIG_DYNAMIC_FTRACE
4740 trace_create_file("dyn_ftrace_total_info", 0444, d_tracer, 4742 trace_create_file("dyn_ftrace_total_info", 0444, d_tracer,
diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
index 95059f091a24..f95d65da6db8 100644
--- a/kernel/trace/trace.h
+++ b/kernel/trace/trace.h
@@ -836,11 +836,11 @@ extern const char *__stop___trace_bprintk_fmt[];
836 filter) 836 filter)
837#include "trace_entries.h" 837#include "trace_entries.h"
838 838
839#ifdef CONFIG_FUNCTION_TRACER 839#if defined(CONFIG_PERF_EVENTS) && defined(CONFIG_FUNCTION_TRACER)
840int perf_ftrace_event_register(struct ftrace_event_call *call, 840int perf_ftrace_event_register(struct ftrace_event_call *call,
841 enum trace_reg type, void *data); 841 enum trace_reg type, void *data);
842#else 842#else
843#define perf_ftrace_event_register NULL 843#define perf_ftrace_event_register NULL
844#endif /* CONFIG_FUNCTION_TRACER */ 844#endif
845 845
846#endif /* _LINUX_KERNEL_TRACE_H */ 846#endif /* _LINUX_KERNEL_TRACE_H */
diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
index 859fae6b1825..df611a0e76c5 100644
--- a/kernel/trace/trace_output.c
+++ b/kernel/trace/trace_output.c
@@ -652,6 +652,8 @@ int trace_print_lat_context(struct trace_iterator *iter)
652{ 652{
653 u64 next_ts; 653 u64 next_ts;
654 int ret; 654 int ret;
655 /* trace_find_next_entry will reset ent_size */
656 int ent_size = iter->ent_size;
655 struct trace_seq *s = &iter->seq; 657 struct trace_seq *s = &iter->seq;
656 struct trace_entry *entry = iter->ent, 658 struct trace_entry *entry = iter->ent,
657 *next_entry = trace_find_next_entry(iter, NULL, 659 *next_entry = trace_find_next_entry(iter, NULL,
@@ -660,6 +662,9 @@ int trace_print_lat_context(struct trace_iterator *iter)
660 unsigned long abs_usecs = ns2usecs(iter->ts - iter->tr->time_start); 662 unsigned long abs_usecs = ns2usecs(iter->ts - iter->tr->time_start);
661 unsigned long rel_usecs; 663 unsigned long rel_usecs;
662 664
665 /* Restore the original ent_size */
666 iter->ent_size = ent_size;
667
663 if (!next_entry) 668 if (!next_entry)
664 next_ts = iter->ts; 669 next_ts = iter->ts;
665 rel_usecs = ns2usecs(next_ts - iter->ts); 670 rel_usecs = ns2usecs(next_ts - iter->ts);
diff --git a/lib/kobject.c b/lib/kobject.c
index 21dee7c19afd..aeefa8bc8b1c 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -192,14 +192,14 @@ static int kobject_add_internal(struct kobject *kobj)
192 192
193 /* be noisy on error issues */ 193 /* be noisy on error issues */
194 if (error == -EEXIST) 194 if (error == -EEXIST)
195 printk(KERN_ERR "%s failed for %s with " 195 WARN(1, "%s failed for %s with "
196 "-EEXIST, don't try to register things with " 196 "-EEXIST, don't try to register things with "
197 "the same name in the same directory.\n", 197 "the same name in the same directory.\n",
198 __func__, kobject_name(kobj)); 198 __func__, kobject_name(kobj));
199 else 199 else
200 printk(KERN_ERR "%s failed for %s (%d)\n", 200 WARN(1, "%s failed for %s (error: %d parent: %s)\n",
201 __func__, kobject_name(kobj), error); 201 __func__, kobject_name(kobj), error,
202 dump_stack(); 202 parent ? kobject_name(parent) : "'none'");
203 } else 203 } else
204 kobj->state_in_sysfs = 1; 204 kobj->state_in_sysfs = 1;
205 205
diff --git a/lib/mpi/mpi-bit.c b/lib/mpi/mpi-bit.c
index 2f526627e4f5..0c505361da19 100644
--- a/lib/mpi/mpi-bit.c
+++ b/lib/mpi/mpi-bit.c
@@ -177,8 +177,8 @@ int mpi_rshift(MPI x, MPI a, unsigned n)
177 */ 177 */
178int mpi_lshift_limbs(MPI a, unsigned int count) 178int mpi_lshift_limbs(MPI a, unsigned int count)
179{ 179{
180 mpi_ptr_t ap = a->d; 180 const int n = a->nlimbs;
181 int n = a->nlimbs; 181 mpi_ptr_t ap;
182 int i; 182 int i;
183 183
184 if (!count || !n) 184 if (!count || !n)
@@ -187,6 +187,7 @@ int mpi_lshift_limbs(MPI a, unsigned int count)
187 if (RESIZE_IF_NEEDED(a, n + count) < 0) 187 if (RESIZE_IF_NEEDED(a, n + count) < 0)
188 return -ENOMEM; 188 return -ENOMEM;
189 189
190 ap = a->d;
190 for (i = n - 1; i >= 0; i--) 191 for (i = n - 1; i >= 0; i--)
191 ap[i + count] = ap[i]; 192 ap[i + count] = ap[i];
192 for (i = 0; i < count; i++) 193 for (i = 0; i < count; i++)
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index b8ce6f450956..ae8f708e3d75 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -532,7 +532,7 @@ static struct page *dequeue_huge_page_vma(struct hstate *h,
532 struct vm_area_struct *vma, 532 struct vm_area_struct *vma,
533 unsigned long address, int avoid_reserve) 533 unsigned long address, int avoid_reserve)
534{ 534{
535 struct page *page; 535 struct page *page = NULL;
536 struct mempolicy *mpol; 536 struct mempolicy *mpol;
537 nodemask_t *nodemask; 537 nodemask_t *nodemask;
538 struct zonelist *zonelist; 538 struct zonelist *zonelist;
@@ -2498,7 +2498,6 @@ retry_avoidcopy:
2498 if (outside_reserve) { 2498 if (outside_reserve) {
2499 BUG_ON(huge_pte_none(pte)); 2499 BUG_ON(huge_pte_none(pte));
2500 if (unmap_ref_private(mm, vma, old_page, address)) { 2500 if (unmap_ref_private(mm, vma, old_page, address)) {
2501 BUG_ON(page_count(old_page) != 1);
2502 BUG_ON(huge_pte_none(pte)); 2501 BUG_ON(huge_pte_none(pte));
2503 spin_lock(&mm->page_table_lock); 2502 spin_lock(&mm->page_table_lock);
2504 ptep = huge_pte_offset(mm, address & huge_page_mask(h)); 2503 ptep = huge_pte_offset(mm, address & huge_page_mask(h));
@@ -2791,6 +2790,7 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
2791 * so no worry about deadlock. 2790 * so no worry about deadlock.
2792 */ 2791 */
2793 page = pte_page(entry); 2792 page = pte_page(entry);
2793 get_page(page);
2794 if (page != pagecache_page) 2794 if (page != pagecache_page)
2795 lock_page(page); 2795 lock_page(page);
2796 2796
@@ -2822,6 +2822,7 @@ out_page_table_lock:
2822 } 2822 }
2823 if (page != pagecache_page) 2823 if (page != pagecache_page)
2824 unlock_page(page); 2824 unlock_page(page);
2825 put_page(page);
2825 2826
2826out_mutex: 2827out_mutex:
2827 mutex_unlock(&hugetlb_instantiation_mutex); 2828 mutex_unlock(&hugetlb_instantiation_mutex);
diff --git a/mm/memblock.c b/mm/memblock.c
index 99f285599501..a44eab3157f8 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -330,6 +330,9 @@ static int __init_memblock memblock_add_region(struct memblock_type *type,
330 phys_addr_t end = base + memblock_cap_size(base, &size); 330 phys_addr_t end = base + memblock_cap_size(base, &size);
331 int i, nr_new; 331 int i, nr_new;
332 332
333 if (!size)
334 return 0;
335
333 /* special case for empty array */ 336 /* special case for empty array */
334 if (type->regions[0].size == 0) { 337 if (type->regions[0].size == 0) {
335 WARN_ON(type->cnt != 1 || type->total_size); 338 WARN_ON(type->cnt != 1 || type->total_size);
@@ -430,6 +433,9 @@ static int __init_memblock memblock_isolate_range(struct memblock_type *type,
430 433
431 *start_rgn = *end_rgn = 0; 434 *start_rgn = *end_rgn = 0;
432 435
436 if (!size)
437 return 0;
438
433 /* we'll create at most two more regions */ 439 /* we'll create at most two more regions */
434 while (type->cnt + 2 > type->max) 440 while (type->cnt + 2 > type->max)
435 if (memblock_double_array(type) < 0) 441 if (memblock_double_array(type) < 0)
@@ -514,7 +520,6 @@ int __init_memblock memblock_reserve(phys_addr_t base, phys_addr_t size)
514 (unsigned long long)base, 520 (unsigned long long)base,
515 (unsigned long long)base + size, 521 (unsigned long long)base + size,
516 (void *)_RET_IP_); 522 (void *)_RET_IP_);
517 BUG_ON(0 == size);
518 523
519 return memblock_add_region(_rgn, base, size, MAX_NUMNODES); 524 return memblock_add_region(_rgn, base, size, MAX_NUMNODES);
520} 525}
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 7d698df4a067..b659260c56ad 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -2165,7 +2165,7 @@ static int __cpuinit memcg_cpu_hotplug_callback(struct notifier_block *nb,
2165 if (action == CPU_ONLINE) 2165 if (action == CPU_ONLINE)
2166 return NOTIFY_OK; 2166 return NOTIFY_OK;
2167 2167
2168 if ((action != CPU_DEAD) || action != CPU_DEAD_FROZEN) 2168 if (action != CPU_DEAD && action != CPU_DEAD_FROZEN)
2169 return NOTIFY_OK; 2169 return NOTIFY_OK;
2170 2170
2171 for_each_mem_cgroup(iter) 2171 for_each_mem_cgroup(iter)
@@ -2476,10 +2476,10 @@ struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page)
2476static void __mem_cgroup_commit_charge(struct mem_cgroup *memcg, 2476static void __mem_cgroup_commit_charge(struct mem_cgroup *memcg,
2477 struct page *page, 2477 struct page *page,
2478 unsigned int nr_pages, 2478 unsigned int nr_pages,
2479 struct page_cgroup *pc,
2480 enum charge_type ctype, 2479 enum charge_type ctype,
2481 bool lrucare) 2480 bool lrucare)
2482{ 2481{
2482 struct page_cgroup *pc = lookup_page_cgroup(page);
2483 struct zone *uninitialized_var(zone); 2483 struct zone *uninitialized_var(zone);
2484 bool was_on_lru = false; 2484 bool was_on_lru = false;
2485 bool anon; 2485 bool anon;
@@ -2716,7 +2716,6 @@ static int mem_cgroup_charge_common(struct page *page, struct mm_struct *mm,
2716{ 2716{
2717 struct mem_cgroup *memcg = NULL; 2717 struct mem_cgroup *memcg = NULL;
2718 unsigned int nr_pages = 1; 2718 unsigned int nr_pages = 1;
2719 struct page_cgroup *pc;
2720 bool oom = true; 2719 bool oom = true;
2721 int ret; 2720 int ret;
2722 2721
@@ -2730,11 +2729,10 @@ static int mem_cgroup_charge_common(struct page *page, struct mm_struct *mm,
2730 oom = false; 2729 oom = false;
2731 } 2730 }
2732 2731
2733 pc = lookup_page_cgroup(page);
2734 ret = __mem_cgroup_try_charge(mm, gfp_mask, nr_pages, &memcg, oom); 2732 ret = __mem_cgroup_try_charge(mm, gfp_mask, nr_pages, &memcg, oom);
2735 if (ret == -ENOMEM) 2733 if (ret == -ENOMEM)
2736 return ret; 2734 return ret;
2737 __mem_cgroup_commit_charge(memcg, page, nr_pages, pc, ctype, false); 2735 __mem_cgroup_commit_charge(memcg, page, nr_pages, ctype, false);
2738 return 0; 2736 return 0;
2739} 2737}
2740 2738
@@ -2831,16 +2829,13 @@ static void
2831__mem_cgroup_commit_charge_swapin(struct page *page, struct mem_cgroup *memcg, 2829__mem_cgroup_commit_charge_swapin(struct page *page, struct mem_cgroup *memcg,
2832 enum charge_type ctype) 2830 enum charge_type ctype)
2833{ 2831{
2834 struct page_cgroup *pc;
2835
2836 if (mem_cgroup_disabled()) 2832 if (mem_cgroup_disabled())
2837 return; 2833 return;
2838 if (!memcg) 2834 if (!memcg)
2839 return; 2835 return;
2840 cgroup_exclude_rmdir(&memcg->css); 2836 cgroup_exclude_rmdir(&memcg->css);
2841 2837
2842 pc = lookup_page_cgroup(page); 2838 __mem_cgroup_commit_charge(memcg, page, 1, ctype, true);
2843 __mem_cgroup_commit_charge(memcg, page, 1, pc, ctype, true);
2844 /* 2839 /*
2845 * Now swap is on-memory. This means this page may be 2840 * Now swap is on-memory. This means this page may be
2846 * counted both as mem and swap....double count. 2841 * counted both as mem and swap....double count.
@@ -3298,14 +3293,13 @@ int mem_cgroup_prepare_migration(struct page *page,
3298 * page. In the case new page is migrated but not remapped, new page's 3293 * page. In the case new page is migrated but not remapped, new page's
3299 * mapcount will be finally 0 and we call uncharge in end_migration(). 3294 * mapcount will be finally 0 and we call uncharge in end_migration().
3300 */ 3295 */
3301 pc = lookup_page_cgroup(newpage);
3302 if (PageAnon(page)) 3296 if (PageAnon(page))
3303 ctype = MEM_CGROUP_CHARGE_TYPE_MAPPED; 3297 ctype = MEM_CGROUP_CHARGE_TYPE_MAPPED;
3304 else if (page_is_file_cache(page)) 3298 else if (page_is_file_cache(page))
3305 ctype = MEM_CGROUP_CHARGE_TYPE_CACHE; 3299 ctype = MEM_CGROUP_CHARGE_TYPE_CACHE;
3306 else 3300 else
3307 ctype = MEM_CGROUP_CHARGE_TYPE_SHMEM; 3301 ctype = MEM_CGROUP_CHARGE_TYPE_SHMEM;
3308 __mem_cgroup_commit_charge(memcg, newpage, 1, pc, ctype, false); 3302 __mem_cgroup_commit_charge(memcg, newpage, 1, ctype, false);
3309 return ret; 3303 return ret;
3310} 3304}
3311 3305
@@ -3392,7 +3386,7 @@ void mem_cgroup_replace_page_cache(struct page *oldpage,
3392 * the newpage may be on LRU(or pagevec for LRU) already. We lock 3386 * the newpage may be on LRU(or pagevec for LRU) already. We lock
3393 * LRU while we overwrite pc->mem_cgroup. 3387 * LRU while we overwrite pc->mem_cgroup.
3394 */ 3388 */
3395 __mem_cgroup_commit_charge(memcg, newpage, 1, pc, type, true); 3389 __mem_cgroup_commit_charge(memcg, newpage, 1, type, true);
3396} 3390}
3397 3391
3398#ifdef CONFIG_DEBUG_VM 3392#ifdef CONFIG_DEBUG_VM
@@ -3763,7 +3757,7 @@ move_account:
3763 goto try_to_free; 3757 goto try_to_free;
3764 cond_resched(); 3758 cond_resched();
3765 /* "ret" should also be checked to ensure all lists are empty. */ 3759 /* "ret" should also be checked to ensure all lists are empty. */
3766 } while (memcg->res.usage > 0 || ret); 3760 } while (res_counter_read_u64(&memcg->res, RES_USAGE) > 0 || ret);
3767out: 3761out:
3768 css_put(&memcg->css); 3762 css_put(&memcg->css);
3769 return ret; 3763 return ret;
@@ -3778,7 +3772,7 @@ try_to_free:
3778 lru_add_drain_all(); 3772 lru_add_drain_all();
3779 /* try to free all pages in this cgroup */ 3773 /* try to free all pages in this cgroup */
3780 shrink = 1; 3774 shrink = 1;
3781 while (nr_retries && memcg->res.usage > 0) { 3775 while (nr_retries && res_counter_read_u64(&memcg->res, RES_USAGE) > 0) {
3782 int progress; 3776 int progress;
3783 3777
3784 if (signal_pending(current)) { 3778 if (signal_pending(current)) {
@@ -4513,6 +4507,12 @@ static void mem_cgroup_usage_unregister_event(struct cgroup *cgrp,
4513swap_buffers: 4507swap_buffers:
4514 /* Swap primary and spare array */ 4508 /* Swap primary and spare array */
4515 thresholds->spare = thresholds->primary; 4509 thresholds->spare = thresholds->primary;
4510 /* If all events are unregistered, free the spare array */
4511 if (!new) {
4512 kfree(thresholds->spare);
4513 thresholds->spare = NULL;
4514 }
4515
4516 rcu_assign_pointer(thresholds->primary, new); 4516 rcu_assign_pointer(thresholds->primary, new);
4517 4517
4518 /* To be sure that nobody uses thresholds */ 4518 /* To be sure that nobody uses thresholds */
diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index cfb6c8678754..b19569137529 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -1361,11 +1361,14 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
1361 1361
1362 mm = get_task_mm(task); 1362 mm = get_task_mm(task);
1363 put_task_struct(task); 1363 put_task_struct(task);
1364 if (mm) 1364
1365 err = do_migrate_pages(mm, old, new, 1365 if (!mm) {
1366 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
1367 else
1368 err = -EINVAL; 1366 err = -EINVAL;
1367 goto out;
1368 }
1369
1370 err = do_migrate_pages(mm, old, new,
1371 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
1369 1372
1370 mmput(mm); 1373 mmput(mm);
1371out: 1374out:
diff --git a/mm/migrate.c b/mm/migrate.c
index 51c08a0c6f68..11072383ae12 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -1388,14 +1388,14 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
1388 mm = get_task_mm(task); 1388 mm = get_task_mm(task);
1389 put_task_struct(task); 1389 put_task_struct(task);
1390 1390
1391 if (mm) { 1391 if (!mm)
1392 if (nodes) 1392 return -EINVAL;
1393 err = do_pages_move(mm, task_nodes, nr_pages, pages, 1393
1394 nodes, status, flags); 1394 if (nodes)
1395 else 1395 err = do_pages_move(mm, task_nodes, nr_pages, pages,
1396 err = do_pages_stat(mm, nr_pages, pages, status); 1396 nodes, status, flags);
1397 } else 1397 else
1398 err = -EINVAL; 1398 err = do_pages_stat(mm, nr_pages, pages, status);
1399 1399
1400 mmput(mm); 1400 mmput(mm);
1401 return err; 1401 return err;
diff --git a/mm/mmap.c b/mm/mmap.c
index a7bf6a31c9f6..848ef52d9603 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -240,6 +240,8 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
240 return next; 240 return next;
241} 241}
242 242
243static unsigned long do_brk(unsigned long addr, unsigned long len);
244
243SYSCALL_DEFINE1(brk, unsigned long, brk) 245SYSCALL_DEFINE1(brk, unsigned long, brk)
244{ 246{
245 unsigned long rlim, retval; 247 unsigned long rlim, retval;
@@ -951,7 +953,7 @@ static inline unsigned long round_hint_to_min(unsigned long hint)
951 * The caller must hold down_write(&current->mm->mmap_sem). 953 * The caller must hold down_write(&current->mm->mmap_sem).
952 */ 954 */
953 955
954unsigned long do_mmap_pgoff(struct file *file, unsigned long addr, 956static unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
955 unsigned long len, unsigned long prot, 957 unsigned long len, unsigned long prot,
956 unsigned long flags, unsigned long pgoff) 958 unsigned long flags, unsigned long pgoff)
957{ 959{
@@ -1087,7 +1089,32 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
1087 1089
1088 return mmap_region(file, addr, len, flags, vm_flags, pgoff); 1090 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
1089} 1091}
1090EXPORT_SYMBOL(do_mmap_pgoff); 1092
1093unsigned long do_mmap(struct file *file, unsigned long addr,
1094 unsigned long len, unsigned long prot,
1095 unsigned long flag, unsigned long offset)
1096{
1097 if (unlikely(offset + PAGE_ALIGN(len) < offset))
1098 return -EINVAL;
1099 if (unlikely(offset & ~PAGE_MASK))
1100 return -EINVAL;
1101 return do_mmap_pgoff(file, addr, len, prot, flag, offset >> PAGE_SHIFT);
1102}
1103EXPORT_SYMBOL(do_mmap);
1104
1105unsigned long vm_mmap(struct file *file, unsigned long addr,
1106 unsigned long len, unsigned long prot,
1107 unsigned long flag, unsigned long offset)
1108{
1109 unsigned long ret;
1110 struct mm_struct *mm = current->mm;
1111
1112 down_write(&mm->mmap_sem);
1113 ret = do_mmap(file, addr, len, prot, flag, offset);
1114 up_write(&mm->mmap_sem);
1115 return ret;
1116}
1117EXPORT_SYMBOL(vm_mmap);
1091 1118
1092SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len, 1119SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len,
1093 unsigned long, prot, unsigned long, flags, 1120 unsigned long, prot, unsigned long, flags,
@@ -2105,21 +2132,25 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
2105 2132
2106 return 0; 2133 return 0;
2107} 2134}
2108
2109EXPORT_SYMBOL(do_munmap); 2135EXPORT_SYMBOL(do_munmap);
2110 2136
2111SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len) 2137int vm_munmap(unsigned long start, size_t len)
2112{ 2138{
2113 int ret; 2139 int ret;
2114 struct mm_struct *mm = current->mm; 2140 struct mm_struct *mm = current->mm;
2115 2141
2116 profile_munmap(addr);
2117
2118 down_write(&mm->mmap_sem); 2142 down_write(&mm->mmap_sem);
2119 ret = do_munmap(mm, addr, len); 2143 ret = do_munmap(mm, start, len);
2120 up_write(&mm->mmap_sem); 2144 up_write(&mm->mmap_sem);
2121 return ret; 2145 return ret;
2122} 2146}
2147EXPORT_SYMBOL(vm_munmap);
2148
2149SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
2150{
2151 profile_munmap(addr);
2152 return vm_munmap(addr, len);
2153}
2123 2154
2124static inline void verify_mm_writelocked(struct mm_struct *mm) 2155static inline void verify_mm_writelocked(struct mm_struct *mm)
2125{ 2156{
@@ -2136,7 +2167,7 @@ static inline void verify_mm_writelocked(struct mm_struct *mm)
2136 * anonymous maps. eventually we may be able to do some 2167 * anonymous maps. eventually we may be able to do some
2137 * brk-specific accounting here. 2168 * brk-specific accounting here.
2138 */ 2169 */
2139unsigned long do_brk(unsigned long addr, unsigned long len) 2170static unsigned long do_brk(unsigned long addr, unsigned long len)
2140{ 2171{
2141 struct mm_struct * mm = current->mm; 2172 struct mm_struct * mm = current->mm;
2142 struct vm_area_struct * vma, * prev; 2173 struct vm_area_struct * vma, * prev;
@@ -2232,7 +2263,17 @@ out:
2232 return addr; 2263 return addr;
2233} 2264}
2234 2265
2235EXPORT_SYMBOL(do_brk); 2266unsigned long vm_brk(unsigned long addr, unsigned long len)
2267{
2268 struct mm_struct *mm = current->mm;
2269 unsigned long ret;
2270
2271 down_write(&mm->mmap_sem);
2272 ret = do_brk(addr, len);
2273 up_write(&mm->mmap_sem);
2274 return ret;
2275}
2276EXPORT_SYMBOL(vm_brk);
2236 2277
2237/* Release all mmaps. */ 2278/* Release all mmaps. */
2238void exit_mmap(struct mm_struct *mm) 2279void exit_mmap(struct mm_struct *mm)
diff --git a/mm/nobootmem.c b/mm/nobootmem.c
index 24f0fc1a56d6..1983fb1c7026 100644
--- a/mm/nobootmem.c
+++ b/mm/nobootmem.c
@@ -82,8 +82,7 @@ void __init free_bootmem_late(unsigned long addr, unsigned long size)
82 82
83static void __init __free_pages_memory(unsigned long start, unsigned long end) 83static void __init __free_pages_memory(unsigned long start, unsigned long end)
84{ 84{
85 int i; 85 unsigned long i, start_aligned, end_aligned;
86 unsigned long start_aligned, end_aligned;
87 int order = ilog2(BITS_PER_LONG); 86 int order = ilog2(BITS_PER_LONG);
88 87
89 start_aligned = (start + (BITS_PER_LONG - 1)) & ~(BITS_PER_LONG - 1); 88 start_aligned = (start + (BITS_PER_LONG - 1)) & ~(BITS_PER_LONG - 1);
@@ -298,13 +297,19 @@ void * __init __alloc_bootmem_node(pg_data_t *pgdat, unsigned long size,
298 if (WARN_ON_ONCE(slab_is_available())) 297 if (WARN_ON_ONCE(slab_is_available()))
299 return kzalloc_node(size, GFP_NOWAIT, pgdat->node_id); 298 return kzalloc_node(size, GFP_NOWAIT, pgdat->node_id);
300 299
300again:
301 ptr = __alloc_memory_core_early(pgdat->node_id, size, align, 301 ptr = __alloc_memory_core_early(pgdat->node_id, size, align,
302 goal, -1ULL); 302 goal, -1ULL);
303 if (ptr) 303 if (ptr)
304 return ptr; 304 return ptr;
305 305
306 return __alloc_memory_core_early(MAX_NUMNODES, size, align, 306 ptr = __alloc_memory_core_early(MAX_NUMNODES, size, align,
307 goal, -1ULL); 307 goal, -1ULL);
308 if (!ptr && goal) {
309 goal = 0;
310 goto again;
311 }
312 return ptr;
308} 313}
309 314
310void * __init __alloc_bootmem_node_high(pg_data_t *pgdat, unsigned long size, 315void * __init __alloc_bootmem_node_high(pg_data_t *pgdat, unsigned long size,
diff --git a/mm/nommu.c b/mm/nommu.c
index f59e170fceb4..bb8f4f004a82 100644
--- a/mm/nommu.c
+++ b/mm/nommu.c
@@ -1233,7 +1233,7 @@ enomem:
1233/* 1233/*
1234 * handle mapping creation for uClinux 1234 * handle mapping creation for uClinux
1235 */ 1235 */
1236unsigned long do_mmap_pgoff(struct file *file, 1236static unsigned long do_mmap_pgoff(struct file *file,
1237 unsigned long addr, 1237 unsigned long addr,
1238 unsigned long len, 1238 unsigned long len,
1239 unsigned long prot, 1239 unsigned long prot,
@@ -1470,7 +1470,32 @@ error_getting_region:
1470 show_free_areas(0); 1470 show_free_areas(0);
1471 return -ENOMEM; 1471 return -ENOMEM;
1472} 1472}
1473EXPORT_SYMBOL(do_mmap_pgoff); 1473
1474unsigned long do_mmap(struct file *file, unsigned long addr,
1475 unsigned long len, unsigned long prot,
1476 unsigned long flag, unsigned long offset)
1477{
1478 if (unlikely(offset + PAGE_ALIGN(len) < offset))
1479 return -EINVAL;
1480 if (unlikely(offset & ~PAGE_MASK))
1481 return -EINVAL;
1482 return do_mmap_pgoff(file, addr, len, prot, flag, offset >> PAGE_SHIFT);
1483}
1484EXPORT_SYMBOL(do_mmap);
1485
1486unsigned long vm_mmap(struct file *file, unsigned long addr,
1487 unsigned long len, unsigned long prot,
1488 unsigned long flag, unsigned long offset)
1489{
1490 unsigned long ret;
1491 struct mm_struct *mm = current->mm;
1492
1493 down_write(&mm->mmap_sem);
1494 ret = do_mmap(file, addr, len, prot, flag, offset);
1495 up_write(&mm->mmap_sem);
1496 return ret;
1497}
1498EXPORT_SYMBOL(vm_mmap);
1474 1499
1475SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len, 1500SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len,
1476 unsigned long, prot, unsigned long, flags, 1501 unsigned long, prot, unsigned long, flags,
@@ -1709,16 +1734,22 @@ erase_whole_vma:
1709} 1734}
1710EXPORT_SYMBOL(do_munmap); 1735EXPORT_SYMBOL(do_munmap);
1711 1736
1712SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len) 1737int vm_munmap(unsigned long addr, size_t len)
1713{ 1738{
1714 int ret;
1715 struct mm_struct *mm = current->mm; 1739 struct mm_struct *mm = current->mm;
1740 int ret;
1716 1741
1717 down_write(&mm->mmap_sem); 1742 down_write(&mm->mmap_sem);
1718 ret = do_munmap(mm, addr, len); 1743 ret = do_munmap(mm, addr, len);
1719 up_write(&mm->mmap_sem); 1744 up_write(&mm->mmap_sem);
1720 return ret; 1745 return ret;
1721} 1746}
1747EXPORT_SYMBOL(vm_munmap);
1748
1749SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
1750{
1751 return vm_munmap(addr, len);
1752}
1722 1753
1723/* 1754/*
1724 * release all the mappings made in a process's VM space 1755 * release all the mappings made in a process's VM space
@@ -1744,7 +1775,7 @@ void exit_mmap(struct mm_struct *mm)
1744 kleave(""); 1775 kleave("");
1745} 1776}
1746 1777
1747unsigned long do_brk(unsigned long addr, unsigned long len) 1778unsigned long vm_brk(unsigned long addr, unsigned long len)
1748{ 1779{
1749 return -ENOMEM; 1780 return -ENOMEM;
1750} 1781}
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index a712fb9e04ce..918330f71dba 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -5203,7 +5203,7 @@ int percpu_pagelist_fraction_sysctl_handler(ctl_table *table, int write,
5203 int ret; 5203 int ret;
5204 5204
5205 ret = proc_dointvec_minmax(table, write, buffer, length, ppos); 5205 ret = proc_dointvec_minmax(table, write, buffer, length, ppos);
5206 if (!write || (ret == -EINVAL)) 5206 if (!write || (ret < 0))
5207 return ret; 5207 return ret;
5208 for_each_populated_zone(zone) { 5208 for_each_populated_zone(zone) {
5209 for_each_possible_cpu(cpu) { 5209 for_each_possible_cpu(cpu) {
diff --git a/mm/percpu.c b/mm/percpu.c
index f47af9123af7..bb4be7435ce3 100644
--- a/mm/percpu.c
+++ b/mm/percpu.c
@@ -1132,20 +1132,20 @@ static void pcpu_dump_alloc_info(const char *lvl,
1132 for (alloc_end += gi->nr_units / upa; 1132 for (alloc_end += gi->nr_units / upa;
1133 alloc < alloc_end; alloc++) { 1133 alloc < alloc_end; alloc++) {
1134 if (!(alloc % apl)) { 1134 if (!(alloc % apl)) {
1135 printk("\n"); 1135 printk(KERN_CONT "\n");
1136 printk("%spcpu-alloc: ", lvl); 1136 printk("%spcpu-alloc: ", lvl);
1137 } 1137 }
1138 printk("[%0*d] ", group_width, group); 1138 printk(KERN_CONT "[%0*d] ", group_width, group);
1139 1139
1140 for (unit_end += upa; unit < unit_end; unit++) 1140 for (unit_end += upa; unit < unit_end; unit++)
1141 if (gi->cpu_map[unit] != NR_CPUS) 1141 if (gi->cpu_map[unit] != NR_CPUS)
1142 printk("%0*d ", cpu_width, 1142 printk(KERN_CONT "%0*d ", cpu_width,
1143 gi->cpu_map[unit]); 1143 gi->cpu_map[unit]);
1144 else 1144 else
1145 printk("%s ", empty_str); 1145 printk(KERN_CONT "%s ", empty_str);
1146 } 1146 }
1147 } 1147 }
1148 printk("\n"); 1148 printk(KERN_CONT "\n");
1149} 1149}
1150 1150
1151/** 1151/**
@@ -1650,6 +1650,16 @@ int __init pcpu_embed_first_chunk(size_t reserved_size, size_t dyn_size,
1650 areas[group] = ptr; 1650 areas[group] = ptr;
1651 1651
1652 base = min(ptr, base); 1652 base = min(ptr, base);
1653 }
1654
1655 /*
1656 * Copy data and free unused parts. This should happen after all
1657 * allocations are complete; otherwise, we may end up with
1658 * overlapping groups.
1659 */
1660 for (group = 0; group < ai->nr_groups; group++) {
1661 struct pcpu_group_info *gi = &ai->groups[group];
1662 void *ptr = areas[group];
1653 1663
1654 for (i = 0; i < gi->nr_units; i++, ptr += ai->unit_size) { 1664 for (i = 0; i < gi->nr_units; i++, ptr += ai->unit_size) {
1655 if (gi->cpu_map[i] == NR_CPUS) { 1665 if (gi->cpu_map[i] == NR_CPUS) {
@@ -1885,6 +1895,8 @@ void __init setup_per_cpu_areas(void)
1885 fc = __alloc_bootmem(unit_size, PAGE_SIZE, __pa(MAX_DMA_ADDRESS)); 1895 fc = __alloc_bootmem(unit_size, PAGE_SIZE, __pa(MAX_DMA_ADDRESS));
1886 if (!ai || !fc) 1896 if (!ai || !fc)
1887 panic("Failed to allocate memory for percpu areas."); 1897 panic("Failed to allocate memory for percpu areas.");
1898 /* kmemleak tracks the percpu allocations separately */
1899 kmemleak_free(fc);
1888 1900
1889 ai->dyn_size = unit_size; 1901 ai->dyn_size = unit_size;
1890 ai->unit_size = unit_size; 1902 ai->unit_size = unit_size;
diff --git a/mm/swap_state.c b/mm/swap_state.c
index 9d3dd3763cf7..4c5ff7f284d9 100644
--- a/mm/swap_state.c
+++ b/mm/swap_state.c
@@ -26,7 +26,7 @@
26 */ 26 */
27static const struct address_space_operations swap_aops = { 27static const struct address_space_operations swap_aops = {
28 .writepage = swap_writepage, 28 .writepage = swap_writepage,
29 .set_page_dirty = __set_page_dirty_nobuffers, 29 .set_page_dirty = __set_page_dirty_no_writeback,
30 .migratepage = migrate_page, 30 .migratepage = migrate_page,
31}; 31};
32 32
diff --git a/mm/vmscan.c b/mm/vmscan.c
index 33c332bbab73..33dc256033b5 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -1568,9 +1568,14 @@ shrink_inactive_list(unsigned long nr_to_scan, struct mem_cgroup_zone *mz,
1568 reclaim_stat->recent_scanned[0] += nr_anon; 1568 reclaim_stat->recent_scanned[0] += nr_anon;
1569 reclaim_stat->recent_scanned[1] += nr_file; 1569 reclaim_stat->recent_scanned[1] += nr_file;
1570 1570
1571 if (current_is_kswapd()) 1571 if (global_reclaim(sc)) {
1572 __count_vm_events(KSWAPD_STEAL, nr_reclaimed); 1572 if (current_is_kswapd())
1573 __count_zone_vm_events(PGSTEAL, zone, nr_reclaimed); 1573 __count_zone_vm_events(PGSTEAL_KSWAPD, zone,
1574 nr_reclaimed);
1575 else
1576 __count_zone_vm_events(PGSTEAL_DIRECT, zone,
1577 nr_reclaimed);
1578 }
1574 1579
1575 putback_inactive_pages(mz, &page_list); 1580 putback_inactive_pages(mz, &page_list);
1576 1581
@@ -2107,12 +2112,7 @@ restart:
2107 * with multiple processes reclaiming pages, the total 2112 * with multiple processes reclaiming pages, the total
2108 * freeing target can get unreasonably large. 2113 * freeing target can get unreasonably large.
2109 */ 2114 */
2110 if (nr_reclaimed >= nr_to_reclaim) 2115 if (nr_reclaimed >= nr_to_reclaim && priority < DEF_PRIORITY)
2111 nr_to_reclaim = 0;
2112 else
2113 nr_to_reclaim -= nr_reclaimed;
2114
2115 if (!nr_to_reclaim && priority < DEF_PRIORITY)
2116 break; 2116 break;
2117 } 2117 }
2118 blk_finish_plug(&plug); 2118 blk_finish_plug(&plug);
diff --git a/mm/vmstat.c b/mm/vmstat.c
index f600557a7659..7db1b9bab492 100644
--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -738,7 +738,8 @@ const char * const vmstat_text[] = {
738 "pgmajfault", 738 "pgmajfault",
739 739
740 TEXTS_FOR_ZONES("pgrefill") 740 TEXTS_FOR_ZONES("pgrefill")
741 TEXTS_FOR_ZONES("pgsteal") 741 TEXTS_FOR_ZONES("pgsteal_kswapd")
742 TEXTS_FOR_ZONES("pgsteal_direct")
742 TEXTS_FOR_ZONES("pgscan_kswapd") 743 TEXTS_FOR_ZONES("pgscan_kswapd")
743 TEXTS_FOR_ZONES("pgscan_direct") 744 TEXTS_FOR_ZONES("pgscan_direct")
744 745
@@ -747,7 +748,6 @@ const char * const vmstat_text[] = {
747#endif 748#endif
748 "pginodesteal", 749 "pginodesteal",
749 "slabs_scanned", 750 "slabs_scanned",
750 "kswapd_steal",
751 "kswapd_inodesteal", 751 "kswapd_inodesteal",
752 "kswapd_low_wmark_hit_quickly", 752 "kswapd_low_wmark_hit_quickly",
753 "kswapd_high_wmark_hit_quickly", 753 "kswapd_high_wmark_hit_quickly",
diff --git a/net/802/garp.c b/net/802/garp.c
index 8e21b6db3981..a5c224830439 100644
--- a/net/802/garp.c
+++ b/net/802/garp.c
@@ -167,7 +167,8 @@ static struct garp_attr *garp_attr_lookup(const struct garp_applicant *app,
167 return NULL; 167 return NULL;
168} 168}
169 169
170static void garp_attr_insert(struct garp_applicant *app, struct garp_attr *new) 170static struct garp_attr *garp_attr_create(struct garp_applicant *app,
171 const void *data, u8 len, u8 type)
171{ 172{
172 struct rb_node *parent = NULL, **p = &app->gid.rb_node; 173 struct rb_node *parent = NULL, **p = &app->gid.rb_node;
173 struct garp_attr *attr; 174 struct garp_attr *attr;
@@ -176,21 +177,16 @@ static void garp_attr_insert(struct garp_applicant *app, struct garp_attr *new)
176 while (*p) { 177 while (*p) {
177 parent = *p; 178 parent = *p;
178 attr = rb_entry(parent, struct garp_attr, node); 179 attr = rb_entry(parent, struct garp_attr, node);
179 d = garp_attr_cmp(attr, new->data, new->dlen, new->type); 180 d = garp_attr_cmp(attr, data, len, type);
180 if (d < 0) 181 if (d < 0)
181 p = &parent->rb_left; 182 p = &parent->rb_left;
182 else if (d > 0) 183 else if (d > 0)
183 p = &parent->rb_right; 184 p = &parent->rb_right;
185 else {
186 /* The attribute already exists; re-use it. */
187 return attr;
188 }
184 } 189 }
185 rb_link_node(&new->node, parent, p);
186 rb_insert_color(&new->node, &app->gid);
187}
188
189static struct garp_attr *garp_attr_create(struct garp_applicant *app,
190 const void *data, u8 len, u8 type)
191{
192 struct garp_attr *attr;
193
194 attr = kmalloc(sizeof(*attr) + len, GFP_ATOMIC); 190 attr = kmalloc(sizeof(*attr) + len, GFP_ATOMIC);
195 if (!attr) 191 if (!attr)
196 return attr; 192 return attr;
@@ -198,7 +194,9 @@ static struct garp_attr *garp_attr_create(struct garp_applicant *app,
198 attr->type = type; 194 attr->type = type;
199 attr->dlen = len; 195 attr->dlen = len;
200 memcpy(attr->data, data, len); 196 memcpy(attr->data, data, len);
201 garp_attr_insert(app, attr); 197
198 rb_link_node(&attr->node, parent, p);
199 rb_insert_color(&attr->node, &app->gid);
202 return attr; 200 return attr;
203} 201}
204 202
diff --git a/net/8021q/vlan_dev.c b/net/8021q/vlan_dev.c
index 9988d4abb372..9757c193c86b 100644
--- a/net/8021q/vlan_dev.c
+++ b/net/8021q/vlan_dev.c
@@ -157,7 +157,7 @@ static netdev_tx_t vlan_dev_hard_start_xmit(struct sk_buff *skb,
157 skb = __vlan_hwaccel_put_tag(skb, vlan_tci); 157 skb = __vlan_hwaccel_put_tag(skb, vlan_tci);
158 } 158 }
159 159
160 skb_set_dev(skb, vlan_dev_priv(dev)->real_dev); 160 skb->dev = vlan_dev_priv(dev)->real_dev;
161 len = skb->len; 161 len = skb->len;
162 if (netpoll_tx_running(dev)) 162 if (netpoll_tx_running(dev))
163 return skb->dev->netdev_ops->ndo_start_xmit(skb, skb->dev); 163 return skb->dev->netdev_ops->ndo_start_xmit(skb, skb->dev);
diff --git a/net/ax25/af_ax25.c b/net/ax25/af_ax25.c
index 0906c194a413..9d9a6a3edbd5 100644
--- a/net/ax25/af_ax25.c
+++ b/net/ax25/af_ax25.c
@@ -2011,16 +2011,17 @@ static void __exit ax25_exit(void)
2011 proc_net_remove(&init_net, "ax25_route"); 2011 proc_net_remove(&init_net, "ax25_route");
2012 proc_net_remove(&init_net, "ax25"); 2012 proc_net_remove(&init_net, "ax25");
2013 proc_net_remove(&init_net, "ax25_calls"); 2013 proc_net_remove(&init_net, "ax25_calls");
2014 ax25_rt_free();
2015 ax25_uid_free();
2016 ax25_dev_free();
2017 2014
2018 ax25_unregister_sysctl();
2019 unregister_netdevice_notifier(&ax25_dev_notifier); 2015 unregister_netdevice_notifier(&ax25_dev_notifier);
2016 ax25_unregister_sysctl();
2020 2017
2021 dev_remove_pack(&ax25_packet_type); 2018 dev_remove_pack(&ax25_packet_type);
2022 2019
2023 sock_unregister(PF_AX25); 2020 sock_unregister(PF_AX25);
2024 proto_unregister(&ax25_proto); 2021 proto_unregister(&ax25_proto);
2022
2023 ax25_rt_free();
2024 ax25_uid_free();
2025 ax25_dev_free();
2025} 2026}
2026module_exit(ax25_exit); 2027module_exit(ax25_exit);
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index e33af63a884a..edfd61addcec 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -665,6 +665,11 @@ int hci_dev_open(__u16 dev)
665 665
666 hci_req_lock(hdev); 666 hci_req_lock(hdev);
667 667
668 if (test_bit(HCI_UNREGISTER, &hdev->dev_flags)) {
669 ret = -ENODEV;
670 goto done;
671 }
672
668 if (hdev->rfkill && rfkill_blocked(hdev->rfkill)) { 673 if (hdev->rfkill && rfkill_blocked(hdev->rfkill)) {
669 ret = -ERFKILL; 674 ret = -ERFKILL;
670 goto done; 675 goto done;
@@ -1210,40 +1215,40 @@ struct link_key *hci_find_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr)
1210 return NULL; 1215 return NULL;
1211} 1216}
1212 1217
1213static int hci_persistent_key(struct hci_dev *hdev, struct hci_conn *conn, 1218static bool hci_persistent_key(struct hci_dev *hdev, struct hci_conn *conn,
1214 u8 key_type, u8 old_key_type) 1219 u8 key_type, u8 old_key_type)
1215{ 1220{
1216 /* Legacy key */ 1221 /* Legacy key */
1217 if (key_type < 0x03) 1222 if (key_type < 0x03)
1218 return 1; 1223 return true;
1219 1224
1220 /* Debug keys are insecure so don't store them persistently */ 1225 /* Debug keys are insecure so don't store them persistently */
1221 if (key_type == HCI_LK_DEBUG_COMBINATION) 1226 if (key_type == HCI_LK_DEBUG_COMBINATION)
1222 return 0; 1227 return false;
1223 1228
1224 /* Changed combination key and there's no previous one */ 1229 /* Changed combination key and there's no previous one */
1225 if (key_type == HCI_LK_CHANGED_COMBINATION && old_key_type == 0xff) 1230 if (key_type == HCI_LK_CHANGED_COMBINATION && old_key_type == 0xff)
1226 return 0; 1231 return false;
1227 1232
1228 /* Security mode 3 case */ 1233 /* Security mode 3 case */
1229 if (!conn) 1234 if (!conn)
1230 return 1; 1235 return true;
1231 1236
1232 /* Neither local nor remote side had no-bonding as requirement */ 1237 /* Neither local nor remote side had no-bonding as requirement */
1233 if (conn->auth_type > 0x01 && conn->remote_auth > 0x01) 1238 if (conn->auth_type > 0x01 && conn->remote_auth > 0x01)
1234 return 1; 1239 return true;
1235 1240
1236 /* Local side had dedicated bonding as requirement */ 1241 /* Local side had dedicated bonding as requirement */
1237 if (conn->auth_type == 0x02 || conn->auth_type == 0x03) 1242 if (conn->auth_type == 0x02 || conn->auth_type == 0x03)
1238 return 1; 1243 return true;
1239 1244
1240 /* Remote side had dedicated bonding as requirement */ 1245 /* Remote side had dedicated bonding as requirement */
1241 if (conn->remote_auth == 0x02 || conn->remote_auth == 0x03) 1246 if (conn->remote_auth == 0x02 || conn->remote_auth == 0x03)
1242 return 1; 1247 return true;
1243 1248
1244 /* If none of the above criteria match, then don't store the key 1249 /* If none of the above criteria match, then don't store the key
1245 * persistently */ 1250 * persistently */
1246 return 0; 1251 return false;
1247} 1252}
1248 1253
1249struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, __le16 ediv, u8 rand[8]) 1254struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, __le16 ediv, u8 rand[8])
@@ -1280,7 +1285,8 @@ int hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn, int new_key,
1280 bdaddr_t *bdaddr, u8 *val, u8 type, u8 pin_len) 1285 bdaddr_t *bdaddr, u8 *val, u8 type, u8 pin_len)
1281{ 1286{
1282 struct link_key *key, *old_key; 1287 struct link_key *key, *old_key;
1283 u8 old_key_type, persistent; 1288 u8 old_key_type;
1289 bool persistent;
1284 1290
1285 old_key = hci_find_link_key(hdev, bdaddr); 1291 old_key = hci_find_link_key(hdev, bdaddr);
1286 if (old_key) { 1292 if (old_key) {
@@ -1323,10 +1329,8 @@ int hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn, int new_key,
1323 1329
1324 mgmt_new_link_key(hdev, key, persistent); 1330 mgmt_new_link_key(hdev, key, persistent);
1325 1331
1326 if (!persistent) { 1332 if (conn)
1327 list_del(&key->list); 1333 conn->flush_key = !persistent;
1328 kfree(key);
1329 }
1330 1334
1331 return 0; 1335 return 0;
1332} 1336}
@@ -1849,6 +1853,8 @@ void hci_unregister_dev(struct hci_dev *hdev)
1849 1853
1850 BT_DBG("%p name %s bus %d", hdev, hdev->name, hdev->bus); 1854 BT_DBG("%p name %s bus %d", hdev, hdev->name, hdev->bus);
1851 1855
1856 set_bit(HCI_UNREGISTER, &hdev->dev_flags);
1857
1852 write_lock(&hci_dev_list_lock); 1858 write_lock(&hci_dev_list_lock);
1853 list_del(&hdev->list); 1859 list_del(&hdev->list);
1854 write_unlock(&hci_dev_list_lock); 1860 write_unlock(&hci_dev_list_lock);
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index b37531094c49..6c065254afc0 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -1901,6 +1901,8 @@ static inline void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff
1901 } 1901 }
1902 1902
1903 if (ev->status == 0) { 1903 if (ev->status == 0) {
1904 if (conn->type == ACL_LINK && conn->flush_key)
1905 hci_remove_link_key(hdev, &conn->dst);
1904 hci_proto_disconn_cfm(conn, ev->reason); 1906 hci_proto_disconn_cfm(conn, ev->reason);
1905 hci_conn_del(conn); 1907 hci_conn_del(conn);
1906 } 1908 }
@@ -2311,6 +2313,7 @@ static inline void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *sk
2311 2313
2312 case HCI_OP_USER_PASSKEY_NEG_REPLY: 2314 case HCI_OP_USER_PASSKEY_NEG_REPLY:
2313 hci_cc_user_passkey_neg_reply(hdev, skb); 2315 hci_cc_user_passkey_neg_reply(hdev, skb);
2316 break;
2314 2317
2315 case HCI_OP_LE_SET_SCAN_PARAM: 2318 case HCI_OP_LE_SET_SCAN_PARAM:
2316 hci_cc_le_set_scan_param(hdev, skb); 2319 hci_cc_le_set_scan_param(hdev, skb);
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index b8e17e4dac8b..94552b33d528 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -1308,6 +1308,7 @@ static void l2cap_monitor_timeout(struct work_struct *work)
1308 if (chan->retry_count >= chan->remote_max_tx) { 1308 if (chan->retry_count >= chan->remote_max_tx) {
1309 l2cap_send_disconn_req(chan->conn, chan, ECONNABORTED); 1309 l2cap_send_disconn_req(chan->conn, chan, ECONNABORTED);
1310 l2cap_chan_unlock(chan); 1310 l2cap_chan_unlock(chan);
1311 l2cap_chan_put(chan);
1311 return; 1312 return;
1312 } 1313 }
1313 1314
@@ -1316,6 +1317,7 @@ static void l2cap_monitor_timeout(struct work_struct *work)
1316 1317
1317 l2cap_send_rr_or_rnr(chan, L2CAP_CTRL_POLL); 1318 l2cap_send_rr_or_rnr(chan, L2CAP_CTRL_POLL);
1318 l2cap_chan_unlock(chan); 1319 l2cap_chan_unlock(chan);
1320 l2cap_chan_put(chan);
1319} 1321}
1320 1322
1321static void l2cap_retrans_timeout(struct work_struct *work) 1323static void l2cap_retrans_timeout(struct work_struct *work)
@@ -1335,6 +1337,7 @@ static void l2cap_retrans_timeout(struct work_struct *work)
1335 l2cap_send_rr_or_rnr(chan, L2CAP_CTRL_POLL); 1337 l2cap_send_rr_or_rnr(chan, L2CAP_CTRL_POLL);
1336 1338
1337 l2cap_chan_unlock(chan); 1339 l2cap_chan_unlock(chan);
1340 l2cap_chan_put(chan);
1338} 1341}
1339 1342
1340static void l2cap_drop_acked_frames(struct l2cap_chan *chan) 1343static void l2cap_drop_acked_frames(struct l2cap_chan *chan)
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index c4fe583b0af6..29122ed28ea9 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -82,7 +82,7 @@ static int l2cap_sock_bind(struct socket *sock, struct sockaddr *addr, int alen)
82 } 82 }
83 83
84 if (la.l2_cid) 84 if (la.l2_cid)
85 err = l2cap_add_scid(chan, la.l2_cid); 85 err = l2cap_add_scid(chan, __le16_to_cpu(la.l2_cid));
86 else 86 else
87 err = l2cap_add_psm(chan, &la.l2_bdaddr, la.l2_psm); 87 err = l2cap_add_psm(chan, &la.l2_bdaddr, la.l2_psm);
88 88
@@ -123,7 +123,8 @@ static int l2cap_sock_connect(struct socket *sock, struct sockaddr *addr, int al
123 if (la.l2_cid && la.l2_psm) 123 if (la.l2_cid && la.l2_psm)
124 return -EINVAL; 124 return -EINVAL;
125 125
126 err = l2cap_chan_connect(chan, la.l2_psm, la.l2_cid, &la.l2_bdaddr); 126 err = l2cap_chan_connect(chan, la.l2_psm, __le16_to_cpu(la.l2_cid),
127 &la.l2_bdaddr);
127 if (err) 128 if (err)
128 return err; 129 return err;
129 130
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 7fcff8887131..4bb03b111122 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -2523,13 +2523,18 @@ static int set_fast_connectable(struct sock *sk, struct hci_dev *hdev,
2523 2523
2524 if (cp->val) { 2524 if (cp->val) {
2525 type = PAGE_SCAN_TYPE_INTERLACED; 2525 type = PAGE_SCAN_TYPE_INTERLACED;
2526 acp.interval = 0x0024; /* 22.5 msec page scan interval */ 2526
2527 /* 22.5 msec page scan interval */
2528 acp.interval = __constant_cpu_to_le16(0x0024);
2527 } else { 2529 } else {
2528 type = PAGE_SCAN_TYPE_STANDARD; /* default */ 2530 type = PAGE_SCAN_TYPE_STANDARD; /* default */
2529 acp.interval = 0x0800; /* default 1.28 sec page scan */ 2531
2532 /* default 1.28 sec page scan */
2533 acp.interval = __constant_cpu_to_le16(0x0800);
2530 } 2534 }
2531 2535
2532 acp.window = 0x0012; /* default 11.25 msec page scan window */ 2536 /* default 11.25 msec page scan window */
2537 acp.window = __constant_cpu_to_le16(0x0012);
2533 2538
2534 err = hci_send_cmd(hdev, HCI_OP_WRITE_PAGE_SCAN_ACTIVITY, sizeof(acp), 2539 err = hci_send_cmd(hdev, HCI_OP_WRITE_PAGE_SCAN_ACTIVITY, sizeof(acp),
2535 &acp); 2540 &acp);
@@ -2879,7 +2884,7 @@ int mgmt_write_scan_failed(struct hci_dev *hdev, u8 scan, u8 status)
2879 return 0; 2884 return 0;
2880} 2885}
2881 2886
2882int mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key, u8 persistent) 2887int mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key, bool persistent)
2883{ 2888{
2884 struct mgmt_ev_new_link_key ev; 2889 struct mgmt_ev_new_link_key ev;
2885 2890
@@ -2936,7 +2941,7 @@ int mgmt_device_connected(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
2936 name, name_len); 2941 name, name_len);
2937 2942
2938 if (dev_class && memcmp(dev_class, "\0\0\0", 3) != 0) 2943 if (dev_class && memcmp(dev_class, "\0\0\0", 3) != 0)
2939 eir_len = eir_append_data(&ev->eir[eir_len], eir_len, 2944 eir_len = eir_append_data(ev->eir, eir_len,
2940 EIR_CLASS_OF_DEV, dev_class, 3); 2945 EIR_CLASS_OF_DEV, dev_class, 3);
2941 2946
2942 put_unaligned_le16(eir_len, &ev->eir_len); 2947 put_unaligned_le16(eir_len, &ev->eir_len);
diff --git a/net/bridge/br_forward.c b/net/bridge/br_forward.c
index 61f65344e711..a2098e3de500 100644
--- a/net/bridge/br_forward.c
+++ b/net/bridge/br_forward.c
@@ -47,6 +47,7 @@ int br_dev_queue_push_xmit(struct sk_buff *skb)
47 kfree_skb(skb); 47 kfree_skb(skb);
48 } else { 48 } else {
49 skb_push(skb, ETH_HLEN); 49 skb_push(skb, ETH_HLEN);
50 br_drop_fake_rtable(skb);
50 dev_queue_xmit(skb); 51 dev_queue_xmit(skb);
51 } 52 }
52 53
diff --git a/net/bridge/br_multicast.c b/net/bridge/br_multicast.c
index 702a1ae9220b..27ca25ed7021 100644
--- a/net/bridge/br_multicast.c
+++ b/net/bridge/br_multicast.c
@@ -241,7 +241,6 @@ static void br_multicast_group_expired(unsigned long data)
241 hlist_del_rcu(&mp->hlist[mdb->ver]); 241 hlist_del_rcu(&mp->hlist[mdb->ver]);
242 mdb->size--; 242 mdb->size--;
243 243
244 del_timer(&mp->query_timer);
245 call_rcu_bh(&mp->rcu, br_multicast_free_group); 244 call_rcu_bh(&mp->rcu, br_multicast_free_group);
246 245
247out: 246out:
@@ -271,7 +270,6 @@ static void br_multicast_del_pg(struct net_bridge *br,
271 rcu_assign_pointer(*pp, p->next); 270 rcu_assign_pointer(*pp, p->next);
272 hlist_del_init(&p->mglist); 271 hlist_del_init(&p->mglist);
273 del_timer(&p->timer); 272 del_timer(&p->timer);
274 del_timer(&p->query_timer);
275 call_rcu_bh(&p->rcu, br_multicast_free_pg); 273 call_rcu_bh(&p->rcu, br_multicast_free_pg);
276 274
277 if (!mp->ports && !mp->mglist && 275 if (!mp->ports && !mp->mglist &&
@@ -507,74 +505,6 @@ static struct sk_buff *br_multicast_alloc_query(struct net_bridge *br,
507 return NULL; 505 return NULL;
508} 506}
509 507
510static void br_multicast_send_group_query(struct net_bridge_mdb_entry *mp)
511{
512 struct net_bridge *br = mp->br;
513 struct sk_buff *skb;
514
515 skb = br_multicast_alloc_query(br, &mp->addr);
516 if (!skb)
517 goto timer;
518
519 netif_rx(skb);
520
521timer:
522 if (++mp->queries_sent < br->multicast_last_member_count)
523 mod_timer(&mp->query_timer,
524 jiffies + br->multicast_last_member_interval);
525}
526
527static void br_multicast_group_query_expired(unsigned long data)
528{
529 struct net_bridge_mdb_entry *mp = (void *)data;
530 struct net_bridge *br = mp->br;
531
532 spin_lock(&br->multicast_lock);
533 if (!netif_running(br->dev) || !mp->mglist ||
534 mp->queries_sent >= br->multicast_last_member_count)
535 goto out;
536
537 br_multicast_send_group_query(mp);
538
539out:
540 spin_unlock(&br->multicast_lock);
541}
542
543static void br_multicast_send_port_group_query(struct net_bridge_port_group *pg)
544{
545 struct net_bridge_port *port = pg->port;
546 struct net_bridge *br = port->br;
547 struct sk_buff *skb;
548
549 skb = br_multicast_alloc_query(br, &pg->addr);
550 if (!skb)
551 goto timer;
552
553 br_deliver(port, skb);
554
555timer:
556 if (++pg->queries_sent < br->multicast_last_member_count)
557 mod_timer(&pg->query_timer,
558 jiffies + br->multicast_last_member_interval);
559}
560
561static void br_multicast_port_group_query_expired(unsigned long data)
562{
563 struct net_bridge_port_group *pg = (void *)data;
564 struct net_bridge_port *port = pg->port;
565 struct net_bridge *br = port->br;
566
567 spin_lock(&br->multicast_lock);
568 if (!netif_running(br->dev) || hlist_unhashed(&pg->mglist) ||
569 pg->queries_sent >= br->multicast_last_member_count)
570 goto out;
571
572 br_multicast_send_port_group_query(pg);
573
574out:
575 spin_unlock(&br->multicast_lock);
576}
577
578static struct net_bridge_mdb_entry *br_multicast_get_group( 508static struct net_bridge_mdb_entry *br_multicast_get_group(
579 struct net_bridge *br, struct net_bridge_port *port, 509 struct net_bridge *br, struct net_bridge_port *port,
580 struct br_ip *group, int hash) 510 struct br_ip *group, int hash)
@@ -690,8 +620,6 @@ rehash:
690 mp->addr = *group; 620 mp->addr = *group;
691 setup_timer(&mp->timer, br_multicast_group_expired, 621 setup_timer(&mp->timer, br_multicast_group_expired,
692 (unsigned long)mp); 622 (unsigned long)mp);
693 setup_timer(&mp->query_timer, br_multicast_group_query_expired,
694 (unsigned long)mp);
695 623
696 hlist_add_head_rcu(&mp->hlist[mdb->ver], &mdb->mhash[hash]); 624 hlist_add_head_rcu(&mp->hlist[mdb->ver], &mdb->mhash[hash]);
697 mdb->size++; 625 mdb->size++;
@@ -746,8 +674,6 @@ static int br_multicast_add_group(struct net_bridge *br,
746 hlist_add_head(&p->mglist, &port->mglist); 674 hlist_add_head(&p->mglist, &port->mglist);
747 setup_timer(&p->timer, br_multicast_port_group_expired, 675 setup_timer(&p->timer, br_multicast_port_group_expired,
748 (unsigned long)p); 676 (unsigned long)p);
749 setup_timer(&p->query_timer, br_multicast_port_group_query_expired,
750 (unsigned long)p);
751 677
752 rcu_assign_pointer(*pp, p); 678 rcu_assign_pointer(*pp, p);
753 679
@@ -1291,9 +1217,6 @@ static void br_multicast_leave_group(struct net_bridge *br,
1291 time_after(mp->timer.expires, time) : 1217 time_after(mp->timer.expires, time) :
1292 try_to_del_timer_sync(&mp->timer) >= 0)) { 1218 try_to_del_timer_sync(&mp->timer) >= 0)) {
1293 mod_timer(&mp->timer, time); 1219 mod_timer(&mp->timer, time);
1294
1295 mp->queries_sent = 0;
1296 mod_timer(&mp->query_timer, now);
1297 } 1220 }
1298 1221
1299 goto out; 1222 goto out;
@@ -1310,9 +1233,6 @@ static void br_multicast_leave_group(struct net_bridge *br,
1310 time_after(p->timer.expires, time) : 1233 time_after(p->timer.expires, time) :
1311 try_to_del_timer_sync(&p->timer) >= 0)) { 1234 try_to_del_timer_sync(&p->timer) >= 0)) {
1312 mod_timer(&p->timer, time); 1235 mod_timer(&p->timer, time);
1313
1314 p->queries_sent = 0;
1315 mod_timer(&p->query_timer, now);
1316 } 1236 }
1317 1237
1318 break; 1238 break;
@@ -1681,7 +1601,6 @@ void br_multicast_stop(struct net_bridge *br)
1681 hlist_for_each_entry_safe(mp, p, n, &mdb->mhash[i], 1601 hlist_for_each_entry_safe(mp, p, n, &mdb->mhash[i],
1682 hlist[ver]) { 1602 hlist[ver]) {
1683 del_timer(&mp->timer); 1603 del_timer(&mp->timer);
1684 del_timer(&mp->query_timer);
1685 call_rcu_bh(&mp->rcu, br_multicast_free_group); 1604 call_rcu_bh(&mp->rcu, br_multicast_free_group);
1686 } 1605 }
1687 } 1606 }
diff --git a/net/bridge/br_netfilter.c b/net/bridge/br_netfilter.c
index dec4f3817133..d7f49b63ab0f 100644
--- a/net/bridge/br_netfilter.c
+++ b/net/bridge/br_netfilter.c
@@ -156,7 +156,7 @@ void br_netfilter_rtable_init(struct net_bridge *br)
156 rt->dst.dev = br->dev; 156 rt->dst.dev = br->dev;
157 rt->dst.path = &rt->dst; 157 rt->dst.path = &rt->dst;
158 dst_init_metrics(&rt->dst, br_dst_default_metrics, true); 158 dst_init_metrics(&rt->dst, br_dst_default_metrics, true);
159 rt->dst.flags = DST_NOXFRM | DST_NOPEER; 159 rt->dst.flags = DST_NOXFRM | DST_NOPEER | DST_FAKE_RTABLE;
160 rt->dst.ops = &fake_dst_ops; 160 rt->dst.ops = &fake_dst_ops;
161} 161}
162 162
@@ -694,11 +694,7 @@ static unsigned int br_nf_local_in(unsigned int hook, struct sk_buff *skb,
694 const struct net_device *out, 694 const struct net_device *out,
695 int (*okfn)(struct sk_buff *)) 695 int (*okfn)(struct sk_buff *))
696{ 696{
697 struct rtable *rt = skb_rtable(skb); 697 br_drop_fake_rtable(skb);
698
699 if (rt && rt == bridge_parent_rtable(in))
700 skb_dst_drop(skb);
701
702 return NF_ACCEPT; 698 return NF_ACCEPT;
703} 699}
704 700
diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h
index 0b67a63ad7a8..e1d882257877 100644
--- a/net/bridge/br_private.h
+++ b/net/bridge/br_private.h
@@ -82,9 +82,7 @@ struct net_bridge_port_group {
82 struct hlist_node mglist; 82 struct hlist_node mglist;
83 struct rcu_head rcu; 83 struct rcu_head rcu;
84 struct timer_list timer; 84 struct timer_list timer;
85 struct timer_list query_timer;
86 struct br_ip addr; 85 struct br_ip addr;
87 u32 queries_sent;
88}; 86};
89 87
90struct net_bridge_mdb_entry 88struct net_bridge_mdb_entry
@@ -94,10 +92,8 @@ struct net_bridge_mdb_entry
94 struct net_bridge_port_group __rcu *ports; 92 struct net_bridge_port_group __rcu *ports;
95 struct rcu_head rcu; 93 struct rcu_head rcu;
96 struct timer_list timer; 94 struct timer_list timer;
97 struct timer_list query_timer;
98 struct br_ip addr; 95 struct br_ip addr;
99 bool mglist; 96 bool mglist;
100 u32 queries_sent;
101}; 97};
102 98
103struct net_bridge_mdb_htable 99struct net_bridge_mdb_htable
diff --git a/net/caif/chnl_net.c b/net/caif/chnl_net.c
index 20618dd3088b..d09340e1523f 100644
--- a/net/caif/chnl_net.c
+++ b/net/caif/chnl_net.c
@@ -103,6 +103,7 @@ static int chnl_recv_cb(struct cflayer *layr, struct cfpkt *pkt)
103 skb->protocol = htons(ETH_P_IPV6); 103 skb->protocol = htons(ETH_P_IPV6);
104 break; 104 break;
105 default: 105 default:
106 kfree_skb(skb);
106 priv->netdev->stats.rx_errors++; 107 priv->netdev->stats.rx_errors++;
107 return -EINVAL; 108 return -EINVAL;
108 } 109 }
@@ -220,14 +221,16 @@ static int chnl_net_start_xmit(struct sk_buff *skb, struct net_device *dev)
220 221
221 if (skb->len > priv->netdev->mtu) { 222 if (skb->len > priv->netdev->mtu) {
222 pr_warn("Size of skb exceeded MTU\n"); 223 pr_warn("Size of skb exceeded MTU\n");
224 kfree_skb(skb);
223 dev->stats.tx_errors++; 225 dev->stats.tx_errors++;
224 return -ENOSPC; 226 return NETDEV_TX_OK;
225 } 227 }
226 228
227 if (!priv->flowenabled) { 229 if (!priv->flowenabled) {
228 pr_debug("dropping packets flow off\n"); 230 pr_debug("dropping packets flow off\n");
231 kfree_skb(skb);
229 dev->stats.tx_dropped++; 232 dev->stats.tx_dropped++;
230 return NETDEV_TX_BUSY; 233 return NETDEV_TX_OK;
231 } 234 }
232 235
233 if (priv->conn_req.protocol == CAIFPROTO_DATAGRAM_LOOP) 236 if (priv->conn_req.protocol == CAIFPROTO_DATAGRAM_LOOP)
@@ -242,7 +245,7 @@ static int chnl_net_start_xmit(struct sk_buff *skb, struct net_device *dev)
242 result = priv->chnl.dn->transmit(priv->chnl.dn, pkt); 245 result = priv->chnl.dn->transmit(priv->chnl.dn, pkt);
243 if (result) { 246 if (result) {
244 dev->stats.tx_dropped++; 247 dev->stats.tx_dropped++;
245 return result; 248 return NETDEV_TX_OK;
246 } 249 }
247 250
248 /* Update statistics. */ 251 /* Update statistics. */
diff --git a/net/core/dev.c b/net/core/dev.c
index 5d59155adf2a..99e1d759f41e 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -1409,14 +1409,34 @@ EXPORT_SYMBOL(register_netdevice_notifier);
1409 * register_netdevice_notifier(). The notifier is unlinked into the 1409 * register_netdevice_notifier(). The notifier is unlinked into the
1410 * kernel structures and may then be reused. A negative errno code 1410 * kernel structures and may then be reused. A negative errno code
1411 * is returned on a failure. 1411 * is returned on a failure.
1412 *
1413 * After unregistering unregister and down device events are synthesized
1414 * for all devices on the device list to the removed notifier to remove
1415 * the need for special case cleanup code.
1412 */ 1416 */
1413 1417
1414int unregister_netdevice_notifier(struct notifier_block *nb) 1418int unregister_netdevice_notifier(struct notifier_block *nb)
1415{ 1419{
1420 struct net_device *dev;
1421 struct net *net;
1416 int err; 1422 int err;
1417 1423
1418 rtnl_lock(); 1424 rtnl_lock();
1419 err = raw_notifier_chain_unregister(&netdev_chain, nb); 1425 err = raw_notifier_chain_unregister(&netdev_chain, nb);
1426 if (err)
1427 goto unlock;
1428
1429 for_each_net(net) {
1430 for_each_netdev(net, dev) {
1431 if (dev->flags & IFF_UP) {
1432 nb->notifier_call(nb, NETDEV_GOING_DOWN, dev);
1433 nb->notifier_call(nb, NETDEV_DOWN, dev);
1434 }
1435 nb->notifier_call(nb, NETDEV_UNREGISTER, dev);
1436 nb->notifier_call(nb, NETDEV_UNREGISTER_BATCH, dev);
1437 }
1438 }
1439unlock:
1420 rtnl_unlock(); 1440 rtnl_unlock();
1421 return err; 1441 return err;
1422} 1442}
@@ -1596,10 +1616,15 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
1596 kfree_skb(skb); 1616 kfree_skb(skb);
1597 return NET_RX_DROP; 1617 return NET_RX_DROP;
1598 } 1618 }
1599 skb_set_dev(skb, dev); 1619 skb->skb_iif = 0;
1620 skb->dev = dev;
1621 skb_dst_drop(skb);
1600 skb->tstamp.tv64 = 0; 1622 skb->tstamp.tv64 = 0;
1601 skb->pkt_type = PACKET_HOST; 1623 skb->pkt_type = PACKET_HOST;
1602 skb->protocol = eth_type_trans(skb, dev); 1624 skb->protocol = eth_type_trans(skb, dev);
1625 skb->mark = 0;
1626 secpath_reset(skb);
1627 nf_reset(skb);
1603 return netif_rx(skb); 1628 return netif_rx(skb);
1604} 1629}
1605EXPORT_SYMBOL_GPL(dev_forward_skb); 1630EXPORT_SYMBOL_GPL(dev_forward_skb);
@@ -1848,36 +1873,6 @@ void netif_device_attach(struct net_device *dev)
1848} 1873}
1849EXPORT_SYMBOL(netif_device_attach); 1874EXPORT_SYMBOL(netif_device_attach);
1850 1875
1851/**
1852 * skb_dev_set -- assign a new device to a buffer
1853 * @skb: buffer for the new device
1854 * @dev: network device
1855 *
1856 * If an skb is owned by a device already, we have to reset
1857 * all data private to the namespace a device belongs to
1858 * before assigning it a new device.
1859 */
1860#ifdef CONFIG_NET_NS
1861void skb_set_dev(struct sk_buff *skb, struct net_device *dev)
1862{
1863 skb_dst_drop(skb);
1864 if (skb->dev && !net_eq(dev_net(skb->dev), dev_net(dev))) {
1865 secpath_reset(skb);
1866 nf_reset(skb);
1867 skb_init_secmark(skb);
1868 skb->mark = 0;
1869 skb->priority = 0;
1870 skb->nf_trace = 0;
1871 skb->ipvs_property = 0;
1872#ifdef CONFIG_NET_SCHED
1873 skb->tc_index = 0;
1874#endif
1875 }
1876 skb->dev = dev;
1877}
1878EXPORT_SYMBOL(skb_set_dev);
1879#endif /* CONFIG_NET_NS */
1880
1881static void skb_warn_bad_offload(const struct sk_buff *skb) 1876static void skb_warn_bad_offload(const struct sk_buff *skb)
1882{ 1877{
1883 static const netdev_features_t null_features = 0; 1878 static const netdev_features_t null_features = 0;
@@ -4027,54 +4022,41 @@ static int dev_ifconf(struct net *net, char __user *arg)
4027 4022
4028#ifdef CONFIG_PROC_FS 4023#ifdef CONFIG_PROC_FS
4029 4024
4030#define BUCKET_SPACE (32 - NETDEV_HASHBITS) 4025#define BUCKET_SPACE (32 - NETDEV_HASHBITS - 1)
4031
4032struct dev_iter_state {
4033 struct seq_net_private p;
4034 unsigned int pos; /* bucket << BUCKET_SPACE + offset */
4035};
4036 4026
4037#define get_bucket(x) ((x) >> BUCKET_SPACE) 4027#define get_bucket(x) ((x) >> BUCKET_SPACE)
4038#define get_offset(x) ((x) & ((1 << BUCKET_SPACE) - 1)) 4028#define get_offset(x) ((x) & ((1 << BUCKET_SPACE) - 1))
4039#define set_bucket_offset(b, o) ((b) << BUCKET_SPACE | (o)) 4029#define set_bucket_offset(b, o) ((b) << BUCKET_SPACE | (o))
4040 4030
4041static inline struct net_device *dev_from_same_bucket(struct seq_file *seq) 4031static inline struct net_device *dev_from_same_bucket(struct seq_file *seq, loff_t *pos)
4042{ 4032{
4043 struct dev_iter_state *state = seq->private;
4044 struct net *net = seq_file_net(seq); 4033 struct net *net = seq_file_net(seq);
4045 struct net_device *dev; 4034 struct net_device *dev;
4046 struct hlist_node *p; 4035 struct hlist_node *p;
4047 struct hlist_head *h; 4036 struct hlist_head *h;
4048 unsigned int count, bucket, offset; 4037 unsigned int count = 0, offset = get_offset(*pos);
4049 4038
4050 bucket = get_bucket(state->pos); 4039 h = &net->dev_name_head[get_bucket(*pos)];
4051 offset = get_offset(state->pos);
4052 h = &net->dev_name_head[bucket];
4053 count = 0;
4054 hlist_for_each_entry_rcu(dev, p, h, name_hlist) { 4040 hlist_for_each_entry_rcu(dev, p, h, name_hlist) {
4055 if (count++ == offset) { 4041 if (++count == offset)
4056 state->pos = set_bucket_offset(bucket, count);
4057 return dev; 4042 return dev;
4058 }
4059 } 4043 }
4060 4044
4061 return NULL; 4045 return NULL;
4062} 4046}
4063 4047
4064static inline struct net_device *dev_from_new_bucket(struct seq_file *seq) 4048static inline struct net_device *dev_from_bucket(struct seq_file *seq, loff_t *pos)
4065{ 4049{
4066 struct dev_iter_state *state = seq->private;
4067 struct net_device *dev; 4050 struct net_device *dev;
4068 unsigned int bucket; 4051 unsigned int bucket;
4069 4052
4070 bucket = get_bucket(state->pos);
4071 do { 4053 do {
4072 dev = dev_from_same_bucket(seq); 4054 dev = dev_from_same_bucket(seq, pos);
4073 if (dev) 4055 if (dev)
4074 return dev; 4056 return dev;
4075 4057
4076 bucket++; 4058 bucket = get_bucket(*pos) + 1;
4077 state->pos = set_bucket_offset(bucket, 0); 4059 *pos = set_bucket_offset(bucket, 1);
4078 } while (bucket < NETDEV_HASHENTRIES); 4060 } while (bucket < NETDEV_HASHENTRIES);
4079 4061
4080 return NULL; 4062 return NULL;
@@ -4087,33 +4069,20 @@ static inline struct net_device *dev_from_new_bucket(struct seq_file *seq)
4087void *dev_seq_start(struct seq_file *seq, loff_t *pos) 4069void *dev_seq_start(struct seq_file *seq, loff_t *pos)
4088 __acquires(RCU) 4070 __acquires(RCU)
4089{ 4071{
4090 struct dev_iter_state *state = seq->private;
4091
4092 rcu_read_lock(); 4072 rcu_read_lock();
4093 if (!*pos) 4073 if (!*pos)
4094 return SEQ_START_TOKEN; 4074 return SEQ_START_TOKEN;
4095 4075
4096 /* check for end of the hash */ 4076 if (get_bucket(*pos) >= NETDEV_HASHENTRIES)
4097 if (state->pos == 0 && *pos > 1)
4098 return NULL; 4077 return NULL;
4099 4078
4100 return dev_from_new_bucket(seq); 4079 return dev_from_bucket(seq, pos);
4101} 4080}
4102 4081
4103void *dev_seq_next(struct seq_file *seq, void *v, loff_t *pos) 4082void *dev_seq_next(struct seq_file *seq, void *v, loff_t *pos)
4104{ 4083{
4105 struct net_device *dev;
4106
4107 ++*pos; 4084 ++*pos;
4108 4085 return dev_from_bucket(seq, pos);
4109 if (v == SEQ_START_TOKEN)
4110 return dev_from_new_bucket(seq);
4111
4112 dev = dev_from_same_bucket(seq);
4113 if (dev)
4114 return dev;
4115
4116 return dev_from_new_bucket(seq);
4117} 4086}
4118 4087
4119void dev_seq_stop(struct seq_file *seq, void *v) 4088void dev_seq_stop(struct seq_file *seq, void *v)
@@ -4212,13 +4181,7 @@ static const struct seq_operations dev_seq_ops = {
4212static int dev_seq_open(struct inode *inode, struct file *file) 4181static int dev_seq_open(struct inode *inode, struct file *file)
4213{ 4182{
4214 return seq_open_net(inode, file, &dev_seq_ops, 4183 return seq_open_net(inode, file, &dev_seq_ops,
4215 sizeof(struct dev_iter_state)); 4184 sizeof(struct seq_net_private));
4216}
4217
4218int dev_seq_open_ops(struct inode *inode, struct file *file,
4219 const struct seq_operations *ops)
4220{
4221 return seq_open_net(inode, file, ops, sizeof(struct dev_iter_state));
4222} 4185}
4223 4186
4224static const struct file_operations dev_seq_fops = { 4187static const struct file_operations dev_seq_fops = {
diff --git a/net/core/dev_addr_lists.c b/net/core/dev_addr_lists.c
index 29c07fef9228..626698f0db8b 100644
--- a/net/core/dev_addr_lists.c
+++ b/net/core/dev_addr_lists.c
@@ -696,7 +696,8 @@ static const struct seq_operations dev_mc_seq_ops = {
696 696
697static int dev_mc_seq_open(struct inode *inode, struct file *file) 697static int dev_mc_seq_open(struct inode *inode, struct file *file)
698{ 698{
699 return dev_seq_open_ops(inode, file, &dev_mc_seq_ops); 699 return seq_open_net(inode, file, &dev_mc_seq_ops,
700 sizeof(struct seq_net_private));
700} 701}
701 702
702static const struct file_operations dev_mc_seq_fops = { 703static const struct file_operations dev_mc_seq_fops = {
diff --git a/net/core/drop_monitor.c b/net/core/drop_monitor.c
index 7f36b38e060f..a7cad741df01 100644
--- a/net/core/drop_monitor.c
+++ b/net/core/drop_monitor.c
@@ -42,13 +42,14 @@ static void send_dm_alert(struct work_struct *unused);
42 * netlink alerts 42 * netlink alerts
43 */ 43 */
44static int trace_state = TRACE_OFF; 44static int trace_state = TRACE_OFF;
45static DEFINE_SPINLOCK(trace_state_lock); 45static DEFINE_MUTEX(trace_state_mutex);
46 46
47struct per_cpu_dm_data { 47struct per_cpu_dm_data {
48 struct work_struct dm_alert_work; 48 struct work_struct dm_alert_work;
49 struct sk_buff *skb; 49 struct sk_buff __rcu *skb;
50 atomic_t dm_hit_count; 50 atomic_t dm_hit_count;
51 struct timer_list send_timer; 51 struct timer_list send_timer;
52 int cpu;
52}; 53};
53 54
54struct dm_hw_stat_delta { 55struct dm_hw_stat_delta {
@@ -79,29 +80,53 @@ static void reset_per_cpu_data(struct per_cpu_dm_data *data)
79 size_t al; 80 size_t al;
80 struct net_dm_alert_msg *msg; 81 struct net_dm_alert_msg *msg;
81 struct nlattr *nla; 82 struct nlattr *nla;
83 struct sk_buff *skb;
84 struct sk_buff *oskb = rcu_dereference_protected(data->skb, 1);
82 85
83 al = sizeof(struct net_dm_alert_msg); 86 al = sizeof(struct net_dm_alert_msg);
84 al += dm_hit_limit * sizeof(struct net_dm_drop_point); 87 al += dm_hit_limit * sizeof(struct net_dm_drop_point);
85 al += sizeof(struct nlattr); 88 al += sizeof(struct nlattr);
86 89
87 data->skb = genlmsg_new(al, GFP_KERNEL); 90 skb = genlmsg_new(al, GFP_KERNEL);
88 genlmsg_put(data->skb, 0, 0, &net_drop_monitor_family, 91
89 0, NET_DM_CMD_ALERT); 92 if (skb) {
90 nla = nla_reserve(data->skb, NLA_UNSPEC, sizeof(struct net_dm_alert_msg)); 93 genlmsg_put(skb, 0, 0, &net_drop_monitor_family,
91 msg = nla_data(nla); 94 0, NET_DM_CMD_ALERT);
92 memset(msg, 0, al); 95 nla = nla_reserve(skb, NLA_UNSPEC,
93 atomic_set(&data->dm_hit_count, dm_hit_limit); 96 sizeof(struct net_dm_alert_msg));
97 msg = nla_data(nla);
98 memset(msg, 0, al);
99 } else
100 schedule_work_on(data->cpu, &data->dm_alert_work);
101
102 /*
103 * Don't need to lock this, since we are guaranteed to only
104 * run this on a single cpu at a time.
105 * Note also that we only update data->skb if the old and new skb
106 * pointers don't match. This ensures that we don't continually call
107 * synchornize_rcu if we repeatedly fail to alloc a new netlink message.
108 */
109 if (skb != oskb) {
110 rcu_assign_pointer(data->skb, skb);
111
112 synchronize_rcu();
113
114 atomic_set(&data->dm_hit_count, dm_hit_limit);
115 }
116
94} 117}
95 118
96static void send_dm_alert(struct work_struct *unused) 119static void send_dm_alert(struct work_struct *unused)
97{ 120{
98 struct sk_buff *skb; 121 struct sk_buff *skb;
99 struct per_cpu_dm_data *data = &__get_cpu_var(dm_cpu_data); 122 struct per_cpu_dm_data *data = &get_cpu_var(dm_cpu_data);
123
124 WARN_ON_ONCE(data->cpu != smp_processor_id());
100 125
101 /* 126 /*
102 * Grab the skb we're about to send 127 * Grab the skb we're about to send
103 */ 128 */
104 skb = data->skb; 129 skb = rcu_dereference_protected(data->skb, 1);
105 130
106 /* 131 /*
107 * Replace it with a new one 132 * Replace it with a new one
@@ -111,8 +136,10 @@ static void send_dm_alert(struct work_struct *unused)
111 /* 136 /*
112 * Ship it! 137 * Ship it!
113 */ 138 */
114 genlmsg_multicast(skb, 0, NET_DM_GRP_ALERT, GFP_KERNEL); 139 if (skb)
140 genlmsg_multicast(skb, 0, NET_DM_GRP_ALERT, GFP_KERNEL);
115 141
142 put_cpu_var(dm_cpu_data);
116} 143}
117 144
118/* 145/*
@@ -123,9 +150,11 @@ static void send_dm_alert(struct work_struct *unused)
123 */ 150 */
124static void sched_send_work(unsigned long unused) 151static void sched_send_work(unsigned long unused)
125{ 152{
126 struct per_cpu_dm_data *data = &__get_cpu_var(dm_cpu_data); 153 struct per_cpu_dm_data *data = &get_cpu_var(dm_cpu_data);
154
155 schedule_work_on(smp_processor_id(), &data->dm_alert_work);
127 156
128 schedule_work(&data->dm_alert_work); 157 put_cpu_var(dm_cpu_data);
129} 158}
130 159
131static void trace_drop_common(struct sk_buff *skb, void *location) 160static void trace_drop_common(struct sk_buff *skb, void *location)
@@ -134,8 +163,15 @@ static void trace_drop_common(struct sk_buff *skb, void *location)
134 struct nlmsghdr *nlh; 163 struct nlmsghdr *nlh;
135 struct nlattr *nla; 164 struct nlattr *nla;
136 int i; 165 int i;
137 struct per_cpu_dm_data *data = &__get_cpu_var(dm_cpu_data); 166 struct sk_buff *dskb;
167 struct per_cpu_dm_data *data = &get_cpu_var(dm_cpu_data);
168
169
170 rcu_read_lock();
171 dskb = rcu_dereference(data->skb);
138 172
173 if (!dskb)
174 goto out;
139 175
140 if (!atomic_add_unless(&data->dm_hit_count, -1, 0)) { 176 if (!atomic_add_unless(&data->dm_hit_count, -1, 0)) {
141 /* 177 /*
@@ -144,12 +180,13 @@ static void trace_drop_common(struct sk_buff *skb, void *location)
144 goto out; 180 goto out;
145 } 181 }
146 182
147 nlh = (struct nlmsghdr *)data->skb->data; 183 nlh = (struct nlmsghdr *)dskb->data;
148 nla = genlmsg_data(nlmsg_data(nlh)); 184 nla = genlmsg_data(nlmsg_data(nlh));
149 msg = nla_data(nla); 185 msg = nla_data(nla);
150 for (i = 0; i < msg->entries; i++) { 186 for (i = 0; i < msg->entries; i++) {
151 if (!memcmp(&location, msg->points[i].pc, sizeof(void *))) { 187 if (!memcmp(&location, msg->points[i].pc, sizeof(void *))) {
152 msg->points[i].count++; 188 msg->points[i].count++;
189 atomic_inc(&data->dm_hit_count);
153 goto out; 190 goto out;
154 } 191 }
155 } 192 }
@@ -157,7 +194,7 @@ static void trace_drop_common(struct sk_buff *skb, void *location)
157 /* 194 /*
158 * We need to create a new entry 195 * We need to create a new entry
159 */ 196 */
160 __nla_reserve_nohdr(data->skb, sizeof(struct net_dm_drop_point)); 197 __nla_reserve_nohdr(dskb, sizeof(struct net_dm_drop_point));
161 nla->nla_len += NLA_ALIGN(sizeof(struct net_dm_drop_point)); 198 nla->nla_len += NLA_ALIGN(sizeof(struct net_dm_drop_point));
162 memcpy(msg->points[msg->entries].pc, &location, sizeof(void *)); 199 memcpy(msg->points[msg->entries].pc, &location, sizeof(void *));
163 msg->points[msg->entries].count = 1; 200 msg->points[msg->entries].count = 1;
@@ -169,6 +206,8 @@ static void trace_drop_common(struct sk_buff *skb, void *location)
169 } 206 }
170 207
171out: 208out:
209 rcu_read_unlock();
210 put_cpu_var(dm_cpu_data);
172 return; 211 return;
173} 212}
174 213
@@ -213,7 +252,7 @@ static int set_all_monitor_traces(int state)
213 struct dm_hw_stat_delta *new_stat = NULL; 252 struct dm_hw_stat_delta *new_stat = NULL;
214 struct dm_hw_stat_delta *temp; 253 struct dm_hw_stat_delta *temp;
215 254
216 spin_lock(&trace_state_lock); 255 mutex_lock(&trace_state_mutex);
217 256
218 if (state == trace_state) { 257 if (state == trace_state) {
219 rc = -EAGAIN; 258 rc = -EAGAIN;
@@ -252,7 +291,7 @@ static int set_all_monitor_traces(int state)
252 rc = -EINPROGRESS; 291 rc = -EINPROGRESS;
253 292
254out_unlock: 293out_unlock:
255 spin_unlock(&trace_state_lock); 294 mutex_unlock(&trace_state_mutex);
256 295
257 return rc; 296 return rc;
258} 297}
@@ -295,12 +334,12 @@ static int dropmon_net_event(struct notifier_block *ev_block,
295 334
296 new_stat->dev = dev; 335 new_stat->dev = dev;
297 new_stat->last_rx = jiffies; 336 new_stat->last_rx = jiffies;
298 spin_lock(&trace_state_lock); 337 mutex_lock(&trace_state_mutex);
299 list_add_rcu(&new_stat->list, &hw_stats_list); 338 list_add_rcu(&new_stat->list, &hw_stats_list);
300 spin_unlock(&trace_state_lock); 339 mutex_unlock(&trace_state_mutex);
301 break; 340 break;
302 case NETDEV_UNREGISTER: 341 case NETDEV_UNREGISTER:
303 spin_lock(&trace_state_lock); 342 mutex_lock(&trace_state_mutex);
304 list_for_each_entry_safe(new_stat, tmp, &hw_stats_list, list) { 343 list_for_each_entry_safe(new_stat, tmp, &hw_stats_list, list) {
305 if (new_stat->dev == dev) { 344 if (new_stat->dev == dev) {
306 new_stat->dev = NULL; 345 new_stat->dev = NULL;
@@ -311,7 +350,7 @@ static int dropmon_net_event(struct notifier_block *ev_block,
311 } 350 }
312 } 351 }
313 } 352 }
314 spin_unlock(&trace_state_lock); 353 mutex_unlock(&trace_state_mutex);
315 break; 354 break;
316 } 355 }
317out: 356out:
@@ -367,13 +406,15 @@ static int __init init_net_drop_monitor(void)
367 406
368 for_each_present_cpu(cpu) { 407 for_each_present_cpu(cpu) {
369 data = &per_cpu(dm_cpu_data, cpu); 408 data = &per_cpu(dm_cpu_data, cpu);
370 reset_per_cpu_data(data); 409 data->cpu = cpu;
371 INIT_WORK(&data->dm_alert_work, send_dm_alert); 410 INIT_WORK(&data->dm_alert_work, send_dm_alert);
372 init_timer(&data->send_timer); 411 init_timer(&data->send_timer);
373 data->send_timer.data = cpu; 412 data->send_timer.data = cpu;
374 data->send_timer.function = sched_send_work; 413 data->send_timer.function = sched_send_work;
414 reset_per_cpu_data(data);
375 } 415 }
376 416
417
377 goto out; 418 goto out;
378 419
379out_unreg: 420out_unreg:
diff --git a/net/core/filter.c b/net/core/filter.c
index cf4989ac503b..6f755cca4520 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -39,8 +39,11 @@
39#include <linux/reciprocal_div.h> 39#include <linux/reciprocal_div.h>
40#include <linux/ratelimit.h> 40#include <linux/ratelimit.h>
41 41
42/* No hurry in this branch */ 42/* No hurry in this branch
43static void *__load_pointer(const struct sk_buff *skb, int k, unsigned int size) 43 *
44 * Exported for the bpf jit load helper.
45 */
46void *bpf_internal_load_pointer_neg_helper(const struct sk_buff *skb, int k, unsigned int size)
44{ 47{
45 u8 *ptr = NULL; 48 u8 *ptr = NULL;
46 49
@@ -59,7 +62,7 @@ static inline void *load_pointer(const struct sk_buff *skb, int k,
59{ 62{
60 if (k >= 0) 63 if (k >= 0)
61 return skb_header_pointer(skb, k, size, buffer); 64 return skb_header_pointer(skb, k, size, buffer);
62 return __load_pointer(skb, k, size); 65 return bpf_internal_load_pointer_neg_helper(skb, k, size);
63} 66}
64 67
65/** 68/**
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
index 0e950fda9a0a..31a5ae51a45c 100644
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -83,21 +83,29 @@ assign:
83 83
84static int ops_init(const struct pernet_operations *ops, struct net *net) 84static int ops_init(const struct pernet_operations *ops, struct net *net)
85{ 85{
86 int err; 86 int err = -ENOMEM;
87 void *data = NULL;
88
87 if (ops->id && ops->size) { 89 if (ops->id && ops->size) {
88 void *data = kzalloc(ops->size, GFP_KERNEL); 90 data = kzalloc(ops->size, GFP_KERNEL);
89 if (!data) 91 if (!data)
90 return -ENOMEM; 92 goto out;
91 93
92 err = net_assign_generic(net, *ops->id, data); 94 err = net_assign_generic(net, *ops->id, data);
93 if (err) { 95 if (err)
94 kfree(data); 96 goto cleanup;
95 return err;
96 }
97 } 97 }
98 err = 0;
98 if (ops->init) 99 if (ops->init)
99 return ops->init(net); 100 err = ops->init(net);
100 return 0; 101 if (!err)
102 return 0;
103
104cleanup:
105 kfree(data);
106
107out:
108 return err;
101} 109}
102 110
103static void ops_free(const struct pernet_operations *ops, struct net *net) 111static void ops_free(const struct pernet_operations *ops, struct net *net)
@@ -448,12 +456,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
448static int __register_pernet_operations(struct list_head *list, 456static int __register_pernet_operations(struct list_head *list,
449 struct pernet_operations *ops) 457 struct pernet_operations *ops)
450{ 458{
451 int err = 0; 459 return ops_init(ops, &init_net);
452 err = ops_init(ops, &init_net);
453 if (err)
454 ops_free(ops, &init_net);
455 return err;
456
457} 460}
458 461
459static void __unregister_pernet_operations(struct pernet_operations *ops) 462static void __unregister_pernet_operations(struct pernet_operations *ops)
diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index 4d8ce93cd503..77a59980b579 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -1931,7 +1931,7 @@ static int pktgen_device_event(struct notifier_block *unused,
1931{ 1931{
1932 struct net_device *dev = ptr; 1932 struct net_device *dev = ptr;
1933 1933
1934 if (!net_eq(dev_net(dev), &init_net)) 1934 if (!net_eq(dev_net(dev), &init_net) || pktgen_exiting)
1935 return NOTIFY_DONE; 1935 return NOTIFY_DONE;
1936 1936
1937 /* It is OK that we do not hold the group lock right now, 1937 /* It is OK that we do not hold the group lock right now,
@@ -3755,12 +3755,18 @@ static void __exit pg_cleanup(void)
3755{ 3755{
3756 struct pktgen_thread *t; 3756 struct pktgen_thread *t;
3757 struct list_head *q, *n; 3757 struct list_head *q, *n;
3758 struct list_head list;
3758 3759
3759 /* Stop all interfaces & threads */ 3760 /* Stop all interfaces & threads */
3760 pktgen_exiting = true; 3761 pktgen_exiting = true;
3761 3762
3762 list_for_each_safe(q, n, &pktgen_threads) { 3763 mutex_lock(&pktgen_thread_lock);
3764 list_splice(&list, &pktgen_threads);
3765 mutex_unlock(&pktgen_thread_lock);
3766
3767 list_for_each_safe(q, n, &list) {
3763 t = list_entry(q, struct pktgen_thread, th_list); 3768 t = list_entry(q, struct pktgen_thread, th_list);
3769 list_del(&t->th_list);
3764 kthread_stop(t->tsk); 3770 kthread_stop(t->tsk);
3765 kfree(t); 3771 kfree(t);
3766 } 3772 }
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index f223cdc75da6..e59840010d45 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -952,9 +952,11 @@ int pskb_expand_head(struct sk_buff *skb, int nhead, int ntail,
952 goto adjust_others; 952 goto adjust_others;
953 } 953 }
954 954
955 data = kmalloc(size + sizeof(struct skb_shared_info), gfp_mask); 955 data = kmalloc(size + SKB_DATA_ALIGN(sizeof(struct skb_shared_info)),
956 gfp_mask);
956 if (!data) 957 if (!data)
957 goto nodata; 958 goto nodata;
959 size = SKB_WITH_OVERHEAD(ksize(data));
958 960
959 /* Copy only real data... and, alas, header. This should be 961 /* Copy only real data... and, alas, header. This should be
960 * optimized for the cases when header is void. 962 * optimized for the cases when header is void.
@@ -3161,6 +3163,8 @@ static void sock_rmem_free(struct sk_buff *skb)
3161 */ 3163 */
3162int sock_queue_err_skb(struct sock *sk, struct sk_buff *skb) 3164int sock_queue_err_skb(struct sock *sk, struct sk_buff *skb)
3163{ 3165{
3166 int len = skb->len;
3167
3164 if (atomic_read(&sk->sk_rmem_alloc) + skb->truesize >= 3168 if (atomic_read(&sk->sk_rmem_alloc) + skb->truesize >=
3165 (unsigned)sk->sk_rcvbuf) 3169 (unsigned)sk->sk_rcvbuf)
3166 return -ENOMEM; 3170 return -ENOMEM;
@@ -3175,7 +3179,7 @@ int sock_queue_err_skb(struct sock *sk, struct sk_buff *skb)
3175 3179
3176 skb_queue_tail(&sk->sk_error_queue, skb); 3180 skb_queue_tail(&sk->sk_error_queue, skb);
3177 if (!sock_flag(sk, SOCK_DEAD)) 3181 if (!sock_flag(sk, SOCK_DEAD))
3178 sk->sk_data_ready(sk, skb->len); 3182 sk->sk_data_ready(sk, len);
3179 return 0; 3183 return 0;
3180} 3184}
3181EXPORT_SYMBOL(sock_queue_err_skb); 3185EXPORT_SYMBOL(sock_queue_err_skb);
diff --git a/net/ieee802154/6lowpan.c b/net/ieee802154/6lowpan.c
index 368515885368..840821b90bcd 100644
--- a/net/ieee802154/6lowpan.c
+++ b/net/ieee802154/6lowpan.c
@@ -1044,6 +1044,24 @@ static void lowpan_dev_free(struct net_device *dev)
1044 free_netdev(dev); 1044 free_netdev(dev);
1045} 1045}
1046 1046
1047static struct wpan_phy *lowpan_get_phy(const struct net_device *dev)
1048{
1049 struct net_device *real_dev = lowpan_dev_info(dev)->real_dev;
1050 return ieee802154_mlme_ops(real_dev)->get_phy(real_dev);
1051}
1052
1053static u16 lowpan_get_pan_id(const struct net_device *dev)
1054{
1055 struct net_device *real_dev = lowpan_dev_info(dev)->real_dev;
1056 return ieee802154_mlme_ops(real_dev)->get_pan_id(real_dev);
1057}
1058
1059static u16 lowpan_get_short_addr(const struct net_device *dev)
1060{
1061 struct net_device *real_dev = lowpan_dev_info(dev)->real_dev;
1062 return ieee802154_mlme_ops(real_dev)->get_short_addr(real_dev);
1063}
1064
1047static struct header_ops lowpan_header_ops = { 1065static struct header_ops lowpan_header_ops = {
1048 .create = lowpan_header_create, 1066 .create = lowpan_header_create,
1049}; 1067};
@@ -1053,6 +1071,12 @@ static const struct net_device_ops lowpan_netdev_ops = {
1053 .ndo_set_mac_address = eth_mac_addr, 1071 .ndo_set_mac_address = eth_mac_addr,
1054}; 1072};
1055 1073
1074static struct ieee802154_mlme_ops lowpan_mlme = {
1075 .get_pan_id = lowpan_get_pan_id,
1076 .get_phy = lowpan_get_phy,
1077 .get_short_addr = lowpan_get_short_addr,
1078};
1079
1056static void lowpan_setup(struct net_device *dev) 1080static void lowpan_setup(struct net_device *dev)
1057{ 1081{
1058 pr_debug("(%s)\n", __func__); 1082 pr_debug("(%s)\n", __func__);
@@ -1070,6 +1094,7 @@ static void lowpan_setup(struct net_device *dev)
1070 1094
1071 dev->netdev_ops = &lowpan_netdev_ops; 1095 dev->netdev_ops = &lowpan_netdev_ops;
1072 dev->header_ops = &lowpan_header_ops; 1096 dev->header_ops = &lowpan_header_ops;
1097 dev->ml_priv = &lowpan_mlme;
1073 dev->destructor = lowpan_dev_free; 1098 dev->destructor = lowpan_dev_free;
1074} 1099}
1075 1100
@@ -1143,6 +1168,8 @@ static int lowpan_newlink(struct net *src_net, struct net_device *dev,
1143 list_add_tail(&entry->list, &lowpan_devices); 1168 list_add_tail(&entry->list, &lowpan_devices);
1144 mutex_unlock(&lowpan_dev_info(dev)->dev_list_mtx); 1169 mutex_unlock(&lowpan_dev_info(dev)->dev_list_mtx);
1145 1170
1171 spin_lock_init(&flist_lock);
1172
1146 register_netdevice(dev); 1173 register_netdevice(dev);
1147 1174
1148 return 0; 1175 return 0;
@@ -1152,11 +1179,20 @@ static void lowpan_dellink(struct net_device *dev, struct list_head *head)
1152{ 1179{
1153 struct lowpan_dev_info *lowpan_dev = lowpan_dev_info(dev); 1180 struct lowpan_dev_info *lowpan_dev = lowpan_dev_info(dev);
1154 struct net_device *real_dev = lowpan_dev->real_dev; 1181 struct net_device *real_dev = lowpan_dev->real_dev;
1155 struct lowpan_dev_record *entry; 1182 struct lowpan_dev_record *entry, *tmp;
1156 struct lowpan_dev_record *tmp; 1183 struct lowpan_fragment *frame, *tframe;
1157 1184
1158 ASSERT_RTNL(); 1185 ASSERT_RTNL();
1159 1186
1187 spin_lock(&flist_lock);
1188 list_for_each_entry_safe(frame, tframe, &lowpan_fragments, list) {
1189 del_timer(&frame->timer);
1190 list_del(&frame->list);
1191 dev_kfree_skb(frame->skb);
1192 kfree(frame);
1193 }
1194 spin_unlock(&flist_lock);
1195
1160 mutex_lock(&lowpan_dev_info(dev)->dev_list_mtx); 1196 mutex_lock(&lowpan_dev_info(dev)->dev_list_mtx);
1161 list_for_each_entry_safe(entry, tmp, &lowpan_devices, list) { 1197 list_for_each_entry_safe(entry, tmp, &lowpan_devices, list) {
1162 if (entry->ldev == dev) { 1198 if (entry->ldev == dev) {
diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c
index bce36f1a37b4..30b88d7b4bd6 100644
--- a/net/ipv4/fib_trie.c
+++ b/net/ipv4/fib_trie.c
@@ -1370,6 +1370,8 @@ static int check_leaf(struct fib_table *tb, struct trie *t, struct leaf *l,
1370 1370
1371 if (fa->fa_tos && fa->fa_tos != flp->flowi4_tos) 1371 if (fa->fa_tos && fa->fa_tos != flp->flowi4_tos)
1372 continue; 1372 continue;
1373 if (fi->fib_dead)
1374 continue;
1373 if (fa->fa_info->fib_scope < flp->flowi4_scope) 1375 if (fa->fa_info->fib_scope < flp->flowi4_scope)
1374 continue; 1376 continue;
1375 fib_alias_accessed(fa); 1377 fib_alias_accessed(fa);
diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c
index 8d25a1c557eb..8f8db724bfaf 100644
--- a/net/ipv4/inet_diag.c
+++ b/net/ipv4/inet_diag.c
@@ -141,7 +141,7 @@ int inet_sk_diag_fill(struct sock *sk, struct inet_connection_sock *icsk,
141 goto rtattr_failure; 141 goto rtattr_failure;
142 142
143 if (icsk == NULL) { 143 if (icsk == NULL) {
144 r->idiag_rqueue = r->idiag_wqueue = 0; 144 handler->idiag_get_info(sk, r, NULL);
145 goto out; 145 goto out;
146 } 146 }
147 147
diff --git a/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c b/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
index de9da21113a1..cf73cc70ed2d 100644
--- a/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
+++ b/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
@@ -74,16 +74,24 @@ static int ipv4_get_l4proto(const struct sk_buff *skb, unsigned int nhoff,
74 74
75 iph = skb_header_pointer(skb, nhoff, sizeof(_iph), &_iph); 75 iph = skb_header_pointer(skb, nhoff, sizeof(_iph), &_iph);
76 if (iph == NULL) 76 if (iph == NULL)
77 return -NF_DROP; 77 return -NF_ACCEPT;
78 78
79 /* Conntrack defragments packets, we might still see fragments 79 /* Conntrack defragments packets, we might still see fragments
80 * inside ICMP packets though. */ 80 * inside ICMP packets though. */
81 if (iph->frag_off & htons(IP_OFFSET)) 81 if (iph->frag_off & htons(IP_OFFSET))
82 return -NF_DROP; 82 return -NF_ACCEPT;
83 83
84 *dataoff = nhoff + (iph->ihl << 2); 84 *dataoff = nhoff + (iph->ihl << 2);
85 *protonum = iph->protocol; 85 *protonum = iph->protocol;
86 86
87 /* Check bogus IP headers */
88 if (*dataoff > skb->len) {
89 pr_debug("nf_conntrack_ipv4: bogus IPv4 packet: "
90 "nhoff %u, ihl %u, skblen %u\n",
91 nhoff, iph->ihl << 2, skb->len);
92 return -NF_ACCEPT;
93 }
94
87 return NF_ACCEPT; 95 return NF_ACCEPT;
88} 96}
89 97
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 4dc1c104c942..167ea10b521a 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -2041,7 +2041,7 @@ static int ip_route_input_mc(struct sk_buff *skb, __be32 daddr, __be32 saddr,
2041 if (err < 0) 2041 if (err < 0)
2042 goto e_err; 2042 goto e_err;
2043 } 2043 }
2044 rth = rt_dst_alloc(init_net.loopback_dev, 2044 rth = rt_dst_alloc(dev_net(dev)->loopback_dev,
2045 IN_DEV_CONF_GET(in_dev, NOPOLICY), false); 2045 IN_DEV_CONF_GET(in_dev, NOPOLICY), false);
2046 if (!rth) 2046 if (!rth)
2047 goto e_nobufs; 2047 goto e_nobufs;
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index cfd7edda0a8e..1272a88c2a63 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -701,11 +701,12 @@ struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp)
701 skb = alloc_skb_fclone(size + sk->sk_prot->max_header, gfp); 701 skb = alloc_skb_fclone(size + sk->sk_prot->max_header, gfp);
702 if (skb) { 702 if (skb) {
703 if (sk_wmem_schedule(sk, skb->truesize)) { 703 if (sk_wmem_schedule(sk, skb->truesize)) {
704 skb_reserve(skb, sk->sk_prot->max_header);
704 /* 705 /*
705 * Make sure that we have exactly size bytes 706 * Make sure that we have exactly size bytes
706 * available to the caller, no more, no less. 707 * available to the caller, no more, no less.
707 */ 708 */
708 skb_reserve(skb, skb_tailroom(skb) - size); 709 skb->avail_size = size;
709 return skb; 710 return skb;
710 } 711 }
711 __kfree_skb(skb); 712 __kfree_skb(skb);
@@ -860,7 +861,7 @@ wait_for_memory:
860 } 861 }
861 862
862out: 863out:
863 if (copied) 864 if (copied && !(flags & MSG_SENDPAGE_NOTLAST))
864 tcp_push(sk, flags, mss_now, tp->nonagle); 865 tcp_push(sk, flags, mss_now, tp->nonagle);
865 return copied; 866 return copied;
866 867
@@ -995,10 +996,9 @@ new_segment:
995 copy = seglen; 996 copy = seglen;
996 997
997 /* Where to copy to? */ 998 /* Where to copy to? */
998 if (skb_tailroom(skb) > 0) { 999 if (skb_availroom(skb) > 0) {
999 /* We have some space in skb head. Superb! */ 1000 /* We have some space in skb head. Superb! */
1000 if (copy > skb_tailroom(skb)) 1001 copy = min_t(int, copy, skb_availroom(skb));
1001 copy = skb_tailroom(skb);
1002 err = skb_add_data_nocache(sk, skb, from, copy); 1002 err = skb_add_data_nocache(sk, skb, from, copy);
1003 if (err) 1003 if (err)
1004 goto do_fault; 1004 goto do_fault;
@@ -1452,7 +1452,7 @@ int tcp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
1452 if ((available < target) && 1452 if ((available < target) &&
1453 (len > sysctl_tcp_dma_copybreak) && !(flags & MSG_PEEK) && 1453 (len > sysctl_tcp_dma_copybreak) && !(flags & MSG_PEEK) &&
1454 !sysctl_tcp_low_latency && 1454 !sysctl_tcp_low_latency &&
1455 dma_find_channel(DMA_MEMCPY)) { 1455 net_dma_find_channel()) {
1456 preempt_enable_no_resched(); 1456 preempt_enable_no_resched();
1457 tp->ucopy.pinned_list = 1457 tp->ucopy.pinned_list =
1458 dma_pin_iovec_pages(msg->msg_iov, len); 1458 dma_pin_iovec_pages(msg->msg_iov, len);
@@ -1667,7 +1667,7 @@ do_prequeue:
1667 if (!(flags & MSG_TRUNC)) { 1667 if (!(flags & MSG_TRUNC)) {
1668#ifdef CONFIG_NET_DMA 1668#ifdef CONFIG_NET_DMA
1669 if (!tp->ucopy.dma_chan && tp->ucopy.pinned_list) 1669 if (!tp->ucopy.dma_chan && tp->ucopy.pinned_list)
1670 tp->ucopy.dma_chan = dma_find_channel(DMA_MEMCPY); 1670 tp->ucopy.dma_chan = net_dma_find_channel();
1671 1671
1672 if (tp->ucopy.dma_chan) { 1672 if (tp->ucopy.dma_chan) {
1673 tp->ucopy.dma_cookie = dma_skb_copy_datagram_iovec( 1673 tp->ucopy.dma_cookie = dma_skb_copy_datagram_iovec(
@@ -3243,7 +3243,7 @@ void __init tcp_init(void)
3243{ 3243{
3244 struct sk_buff *skb = NULL; 3244 struct sk_buff *skb = NULL;
3245 unsigned long limit; 3245 unsigned long limit;
3246 int max_share, cnt; 3246 int max_rshare, max_wshare, cnt;
3247 unsigned int i; 3247 unsigned int i;
3248 unsigned long jiffy = jiffies; 3248 unsigned long jiffy = jiffies;
3249 3249
@@ -3302,17 +3302,17 @@ void __init tcp_init(void)
3302 3302
3303 tcp_init_mem(&init_net); 3303 tcp_init_mem(&init_net);
3304 /* Set per-socket limits to no more than 1/128 the pressure threshold */ 3304 /* Set per-socket limits to no more than 1/128 the pressure threshold */
3305 limit = nr_free_buffer_pages() << (PAGE_SHIFT - 10); 3305 limit = nr_free_buffer_pages() << (PAGE_SHIFT - 7);
3306 limit = max(limit, 128UL); 3306 max_wshare = min(4UL*1024*1024, limit);
3307 max_share = min(4UL*1024*1024, limit); 3307 max_rshare = min(6UL*1024*1024, limit);
3308 3308
3309 sysctl_tcp_wmem[0] = SK_MEM_QUANTUM; 3309 sysctl_tcp_wmem[0] = SK_MEM_QUANTUM;
3310 sysctl_tcp_wmem[1] = 16*1024; 3310 sysctl_tcp_wmem[1] = 16*1024;
3311 sysctl_tcp_wmem[2] = max(64*1024, max_share); 3311 sysctl_tcp_wmem[2] = max(64*1024, max_wshare);
3312 3312
3313 sysctl_tcp_rmem[0] = SK_MEM_QUANTUM; 3313 sysctl_tcp_rmem[0] = SK_MEM_QUANTUM;
3314 sysctl_tcp_rmem[1] = 87380; 3314 sysctl_tcp_rmem[1] = 87380;
3315 sysctl_tcp_rmem[2] = max(87380, max_share); 3315 sysctl_tcp_rmem[2] = max(87380, max_rshare);
3316 3316
3317 pr_info("Hash tables configured (established %u bind %u)\n", 3317 pr_info("Hash tables configured (established %u bind %u)\n",
3318 tcp_hashinfo.ehash_mask + 1, tcp_hashinfo.bhash_size); 3318 tcp_hashinfo.ehash_mask + 1, tcp_hashinfo.bhash_size);
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index e886e2f7fa8d..257b61789eeb 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -85,7 +85,7 @@ int sysctl_tcp_ecn __read_mostly = 2;
85EXPORT_SYMBOL(sysctl_tcp_ecn); 85EXPORT_SYMBOL(sysctl_tcp_ecn);
86int sysctl_tcp_dsack __read_mostly = 1; 86int sysctl_tcp_dsack __read_mostly = 1;
87int sysctl_tcp_app_win __read_mostly = 31; 87int sysctl_tcp_app_win __read_mostly = 31;
88int sysctl_tcp_adv_win_scale __read_mostly = 2; 88int sysctl_tcp_adv_win_scale __read_mostly = 1;
89EXPORT_SYMBOL(sysctl_tcp_adv_win_scale); 89EXPORT_SYMBOL(sysctl_tcp_adv_win_scale);
90 90
91int sysctl_tcp_stdurg __read_mostly; 91int sysctl_tcp_stdurg __read_mostly;
@@ -335,6 +335,7 @@ static void tcp_grow_window(struct sock *sk, const struct sk_buff *skb)
335 incr = __tcp_grow_window(sk, skb); 335 incr = __tcp_grow_window(sk, skb);
336 336
337 if (incr) { 337 if (incr) {
338 incr = max_t(int, incr, 2 * skb->len);
338 tp->rcv_ssthresh = min(tp->rcv_ssthresh + incr, 339 tp->rcv_ssthresh = min(tp->rcv_ssthresh + incr,
339 tp->window_clamp); 340 tp->window_clamp);
340 inet_csk(sk)->icsk_ack.quick |= 1; 341 inet_csk(sk)->icsk_ack.quick |= 1;
@@ -474,8 +475,11 @@ static void tcp_rcv_rtt_update(struct tcp_sock *tp, u32 sample, int win_dep)
474 if (!win_dep) { 475 if (!win_dep) {
475 m -= (new_sample >> 3); 476 m -= (new_sample >> 3);
476 new_sample += m; 477 new_sample += m;
477 } else if (m < new_sample) 478 } else {
478 new_sample = m << 3; 479 m <<= 3;
480 if (m < new_sample)
481 new_sample = m;
482 }
479 } else { 483 } else {
480 /* No previous measure. */ 484 /* No previous measure. */
481 new_sample = m << 3; 485 new_sample = m << 3;
@@ -491,7 +495,7 @@ static inline void tcp_rcv_rtt_measure(struct tcp_sock *tp)
491 goto new_measure; 495 goto new_measure;
492 if (before(tp->rcv_nxt, tp->rcv_rtt_est.seq)) 496 if (before(tp->rcv_nxt, tp->rcv_rtt_est.seq))
493 return; 497 return;
494 tcp_rcv_rtt_update(tp, jiffies - tp->rcv_rtt_est.time, 1); 498 tcp_rcv_rtt_update(tp, tcp_time_stamp - tp->rcv_rtt_est.time, 1);
495 499
496new_measure: 500new_measure:
497 tp->rcv_rtt_est.seq = tp->rcv_nxt + tp->rcv_wnd; 501 tp->rcv_rtt_est.seq = tp->rcv_nxt + tp->rcv_wnd;
@@ -2864,11 +2868,14 @@ static inline void tcp_complete_cwr(struct sock *sk)
2864 2868
2865 /* Do not moderate cwnd if it's already undone in cwr or recovery. */ 2869 /* Do not moderate cwnd if it's already undone in cwr or recovery. */
2866 if (tp->undo_marker) { 2870 if (tp->undo_marker) {
2867 if (inet_csk(sk)->icsk_ca_state == TCP_CA_CWR) 2871 if (inet_csk(sk)->icsk_ca_state == TCP_CA_CWR) {
2868 tp->snd_cwnd = min(tp->snd_cwnd, tp->snd_ssthresh); 2872 tp->snd_cwnd = min(tp->snd_cwnd, tp->snd_ssthresh);
2869 else /* PRR */ 2873 tp->snd_cwnd_stamp = tcp_time_stamp;
2874 } else if (tp->snd_ssthresh < TCP_INFINITE_SSTHRESH) {
2875 /* PRR algorithm. */
2870 tp->snd_cwnd = tp->snd_ssthresh; 2876 tp->snd_cwnd = tp->snd_ssthresh;
2871 tp->snd_cwnd_stamp = tcp_time_stamp; 2877 tp->snd_cwnd_stamp = tcp_time_stamp;
2878 }
2872 } 2879 }
2873 tcp_ca_event(sk, CA_EVENT_COMPLETE_CWR); 2880 tcp_ca_event(sk, CA_EVENT_COMPLETE_CWR);
2874} 2881}
@@ -5225,7 +5232,7 @@ static int tcp_dma_try_early_copy(struct sock *sk, struct sk_buff *skb,
5225 return 0; 5232 return 0;
5226 5233
5227 if (!tp->ucopy.dma_chan && tp->ucopy.pinned_list) 5234 if (!tp->ucopy.dma_chan && tp->ucopy.pinned_list)
5228 tp->ucopy.dma_chan = dma_find_channel(DMA_MEMCPY); 5235 tp->ucopy.dma_chan = net_dma_find_channel();
5229 5236
5230 if (tp->ucopy.dma_chan && skb_csum_unnecessary(skb)) { 5237 if (tp->ucopy.dma_chan && skb_csum_unnecessary(skb)) {
5231 5238
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 3a25cf743f8b..0cb86ceb652f 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -1730,7 +1730,7 @@ process:
1730#ifdef CONFIG_NET_DMA 1730#ifdef CONFIG_NET_DMA
1731 struct tcp_sock *tp = tcp_sk(sk); 1731 struct tcp_sock *tp = tcp_sk(sk);
1732 if (!tp->ucopy.dma_chan && tp->ucopy.pinned_list) 1732 if (!tp->ucopy.dma_chan && tp->ucopy.pinned_list)
1733 tp->ucopy.dma_chan = dma_find_channel(DMA_MEMCPY); 1733 tp->ucopy.dma_chan = net_dma_find_channel();
1734 if (tp->ucopy.dma_chan) 1734 if (tp->ucopy.dma_chan)
1735 ret = tcp_v4_do_rcv(sk, skb); 1735 ret = tcp_v4_do_rcv(sk, skb);
1736 else 1736 else
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index 364784a91939..7ac6423117ad 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -1096,6 +1096,7 @@ static void __pskb_trim_head(struct sk_buff *skb, int len)
1096 eat = min_t(int, len, skb_headlen(skb)); 1096 eat = min_t(int, len, skb_headlen(skb));
1097 if (eat) { 1097 if (eat) {
1098 __skb_pull(skb, eat); 1098 __skb_pull(skb, eat);
1099 skb->avail_size -= eat;
1099 len -= eat; 1100 len -= eat;
1100 if (!len) 1101 if (!len)
1101 return; 1102 return;
@@ -2060,7 +2061,7 @@ static void tcp_retrans_try_collapse(struct sock *sk, struct sk_buff *to,
2060 /* Punt if not enough space exists in the first SKB for 2061 /* Punt if not enough space exists in the first SKB for
2061 * the data in the second 2062 * the data in the second
2062 */ 2063 */
2063 if (skb->len > skb_tailroom(to)) 2064 if (skb->len > skb_availroom(to))
2064 break; 2065 break;
2065 2066
2066 if (after(TCP_SKB_CB(skb)->end_seq, tcp_wnd_end(tp))) 2067 if (after(TCP_SKB_CB(skb)->end_seq, tcp_wnd_end(tp)))
diff --git a/net/ipv4/udp_diag.c b/net/ipv4/udp_diag.c
index 8a949f19deb6..a7f86a3cd502 100644
--- a/net/ipv4/udp_diag.c
+++ b/net/ipv4/udp_diag.c
@@ -146,9 +146,17 @@ static int udp_diag_dump_one(struct sk_buff *in_skb, const struct nlmsghdr *nlh,
146 return udp_dump_one(&udp_table, in_skb, nlh, req); 146 return udp_dump_one(&udp_table, in_skb, nlh, req);
147} 147}
148 148
149static void udp_diag_get_info(struct sock *sk, struct inet_diag_msg *r,
150 void *info)
151{
152 r->idiag_rqueue = sk_rmem_alloc_get(sk);
153 r->idiag_wqueue = sk_wmem_alloc_get(sk);
154}
155
149static const struct inet_diag_handler udp_diag_handler = { 156static const struct inet_diag_handler udp_diag_handler = {
150 .dump = udp_diag_dump, 157 .dump = udp_diag_dump,
151 .dump_one = udp_diag_dump_one, 158 .dump_one = udp_diag_dump_one,
159 .idiag_get_info = udp_diag_get_info,
152 .idiag_type = IPPROTO_UDP, 160 .idiag_type = IPPROTO_UDP,
153}; 161};
154 162
@@ -167,6 +175,7 @@ static int udplite_diag_dump_one(struct sk_buff *in_skb, const struct nlmsghdr *
167static const struct inet_diag_handler udplite_diag_handler = { 175static const struct inet_diag_handler udplite_diag_handler = {
168 .dump = udplite_diag_dump, 176 .dump = udplite_diag_dump,
169 .dump_one = udplite_diag_dump_one, 177 .dump_one = udplite_diag_dump_one,
178 .idiag_get_info = udp_diag_get_info,
170 .idiag_type = IPPROTO_UDPLITE, 179 .idiag_type = IPPROTO_UDPLITE,
171}; 180};
172 181
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index 6a3bb6077e19..7d5cb975cc6f 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -803,8 +803,7 @@ static void ipv6_del_addr(struct inet6_ifaddr *ifp)
803 ip6_del_rt(rt); 803 ip6_del_rt(rt);
804 rt = NULL; 804 rt = NULL;
805 } else if (!(rt->rt6i_flags & RTF_EXPIRES)) { 805 } else if (!(rt->rt6i_flags & RTF_EXPIRES)) {
806 rt->dst.expires = expires; 806 rt6_set_expires(rt, expires);
807 rt->rt6i_flags |= RTF_EXPIRES;
808 } 807 }
809 } 808 }
810 dst_release(&rt->dst); 809 dst_release(&rt->dst);
@@ -1887,11 +1886,9 @@ void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len, bool sllao)
1887 rt = NULL; 1886 rt = NULL;
1888 } else if (addrconf_finite_timeout(rt_expires)) { 1887 } else if (addrconf_finite_timeout(rt_expires)) {
1889 /* not infinity */ 1888 /* not infinity */
1890 rt->dst.expires = jiffies + rt_expires; 1889 rt6_set_expires(rt, jiffies + rt_expires);
1891 rt->rt6i_flags |= RTF_EXPIRES;
1892 } else { 1890 } else {
1893 rt->rt6i_flags &= ~RTF_EXPIRES; 1891 rt6_clean_expires(rt);
1894 rt->dst.expires = 0;
1895 } 1892 }
1896 } else if (valid_lft) { 1893 } else if (valid_lft) {
1897 clock_t expires = 0; 1894 clock_t expires = 0;
diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
index 5b27fbcae346..93717435013e 100644
--- a/net/ipv6/ip6_fib.c
+++ b/net/ipv6/ip6_fib.c
@@ -673,11 +673,10 @@ static int fib6_add_rt2node(struct fib6_node *fn, struct rt6_info *rt,
673 &rt->rt6i_gateway)) { 673 &rt->rt6i_gateway)) {
674 if (!(iter->rt6i_flags & RTF_EXPIRES)) 674 if (!(iter->rt6i_flags & RTF_EXPIRES))
675 return -EEXIST; 675 return -EEXIST;
676 iter->dst.expires = rt->dst.expires; 676 if (!(rt->rt6i_flags & RTF_EXPIRES))
677 if (!(rt->rt6i_flags & RTF_EXPIRES)) { 677 rt6_clean_expires(iter);
678 iter->rt6i_flags &= ~RTF_EXPIRES; 678 else
679 iter->dst.expires = 0; 679 rt6_set_expires(iter, rt->dst.expires);
680 }
681 return -EEXIST; 680 return -EEXIST;
682 } 681 }
683 } 682 }
diff --git a/net/ipv6/mcast.c b/net/ipv6/mcast.c
index 16c33e308121..b2869cab2092 100644
--- a/net/ipv6/mcast.c
+++ b/net/ipv6/mcast.c
@@ -2044,7 +2044,7 @@ static int ip6_mc_add_src(struct inet6_dev *idev, const struct in6_addr *pmca,
2044 if (!delta) 2044 if (!delta)
2045 pmc->mca_sfcount[sfmode]--; 2045 pmc->mca_sfcount[sfmode]--;
2046 for (j=0; j<i; j++) 2046 for (j=0; j<i; j++)
2047 (void) ip6_mc_del1_src(pmc, sfmode, &psfsrc[i]); 2047 ip6_mc_del1_src(pmc, sfmode, &psfsrc[j]);
2048 } else if (isexclude != (pmc->mca_sfcount[MCAST_EXCLUDE] != 0)) { 2048 } else if (isexclude != (pmc->mca_sfcount[MCAST_EXCLUDE] != 0)) {
2049 struct ip6_sf_list *psf; 2049 struct ip6_sf_list *psf;
2050 2050
diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c
index 3dcdb81ec3e8..176b469322ac 100644
--- a/net/ipv6/ndisc.c
+++ b/net/ipv6/ndisc.c
@@ -1264,8 +1264,7 @@ static void ndisc_router_discovery(struct sk_buff *skb)
1264 } 1264 }
1265 1265
1266 if (rt) 1266 if (rt)
1267 rt->dst.expires = jiffies + (HZ * lifetime); 1267 rt6_set_expires(rt, jiffies + (HZ * lifetime));
1268
1269 if (ra_msg->icmph.icmp6_hop_limit) { 1268 if (ra_msg->icmph.icmp6_hop_limit) {
1270 in6_dev->cnf.hop_limit = ra_msg->icmph.icmp6_hop_limit; 1269 in6_dev->cnf.hop_limit = ra_msg->icmph.icmp6_hop_limit;
1271 if (rt) 1270 if (rt)
diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
index 94874b0bdcdc..9d4e15559319 100644
--- a/net/ipv6/netfilter/ip6_tables.c
+++ b/net/ipv6/netfilter/ip6_tables.c
@@ -78,19 +78,6 @@ EXPORT_SYMBOL_GPL(ip6t_alloc_initial_table);
78 78
79 Hence the start of any table is given by get_table() below. */ 79 Hence the start of any table is given by get_table() below. */
80 80
81/* Check for an extension */
82int
83ip6t_ext_hdr(u8 nexthdr)
84{
85 return (nexthdr == IPPROTO_HOPOPTS) ||
86 (nexthdr == IPPROTO_ROUTING) ||
87 (nexthdr == IPPROTO_FRAGMENT) ||
88 (nexthdr == IPPROTO_ESP) ||
89 (nexthdr == IPPROTO_AH) ||
90 (nexthdr == IPPROTO_NONE) ||
91 (nexthdr == IPPROTO_DSTOPTS);
92}
93
94/* Returns whether matches rule or not. */ 81/* Returns whether matches rule or not. */
95/* Performance critical - called for every packet */ 82/* Performance critical - called for every packet */
96static inline bool 83static inline bool
@@ -2366,7 +2353,6 @@ int ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset,
2366EXPORT_SYMBOL(ip6t_register_table); 2353EXPORT_SYMBOL(ip6t_register_table);
2367EXPORT_SYMBOL(ip6t_unregister_table); 2354EXPORT_SYMBOL(ip6t_unregister_table);
2368EXPORT_SYMBOL(ip6t_do_table); 2355EXPORT_SYMBOL(ip6t_do_table);
2369EXPORT_SYMBOL(ip6t_ext_hdr);
2370EXPORT_SYMBOL(ipv6_find_hdr); 2356EXPORT_SYMBOL(ipv6_find_hdr);
2371 2357
2372module_init(ip6_tables_init); 2358module_init(ip6_tables_init);
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 496b62712fe8..bc4888d902b2 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -62,7 +62,7 @@
62#include <linux/sysctl.h> 62#include <linux/sysctl.h>
63#endif 63#endif
64 64
65static struct rt6_info *ip6_rt_copy(const struct rt6_info *ort, 65static struct rt6_info *ip6_rt_copy(struct rt6_info *ort,
66 const struct in6_addr *dest); 66 const struct in6_addr *dest);
67static struct dst_entry *ip6_dst_check(struct dst_entry *dst, u32 cookie); 67static struct dst_entry *ip6_dst_check(struct dst_entry *dst, u32 cookie);
68static unsigned int ip6_default_advmss(const struct dst_entry *dst); 68static unsigned int ip6_default_advmss(const struct dst_entry *dst);
@@ -285,6 +285,10 @@ static void ip6_dst_destroy(struct dst_entry *dst)
285 rt->rt6i_idev = NULL; 285 rt->rt6i_idev = NULL;
286 in6_dev_put(idev); 286 in6_dev_put(idev);
287 } 287 }
288
289 if (!(rt->rt6i_flags & RTF_EXPIRES) && dst->from)
290 dst_release(dst->from);
291
288 if (peer) { 292 if (peer) {
289 rt->rt6i_peer = NULL; 293 rt->rt6i_peer = NULL;
290 inet_putpeer(peer); 294 inet_putpeer(peer);
@@ -329,8 +333,17 @@ static void ip6_dst_ifdown(struct dst_entry *dst, struct net_device *dev,
329 333
330static __inline__ int rt6_check_expired(const struct rt6_info *rt) 334static __inline__ int rt6_check_expired(const struct rt6_info *rt)
331{ 335{
332 return (rt->rt6i_flags & RTF_EXPIRES) && 336 struct rt6_info *ort = NULL;
333 time_after(jiffies, rt->dst.expires); 337
338 if (rt->rt6i_flags & RTF_EXPIRES) {
339 if (time_after(jiffies, rt->dst.expires))
340 return 1;
341 } else if (rt->dst.from) {
342 ort = (struct rt6_info *) rt->dst.from;
343 return (ort->rt6i_flags & RTF_EXPIRES) &&
344 time_after(jiffies, ort->dst.expires);
345 }
346 return 0;
334} 347}
335 348
336static inline int rt6_need_strict(const struct in6_addr *daddr) 349static inline int rt6_need_strict(const struct in6_addr *daddr)
@@ -620,12 +633,11 @@ int rt6_route_rcv(struct net_device *dev, u8 *opt, int len,
620 (rt->rt6i_flags & ~RTF_PREF_MASK) | RTF_PREF(pref); 633 (rt->rt6i_flags & ~RTF_PREF_MASK) | RTF_PREF(pref);
621 634
622 if (rt) { 635 if (rt) {
623 if (!addrconf_finite_timeout(lifetime)) { 636 if (!addrconf_finite_timeout(lifetime))
624 rt->rt6i_flags &= ~RTF_EXPIRES; 637 rt6_clean_expires(rt);
625 } else { 638 else
626 rt->dst.expires = jiffies + HZ * lifetime; 639 rt6_set_expires(rt, jiffies + HZ * lifetime);
627 rt->rt6i_flags |= RTF_EXPIRES; 640
628 }
629 dst_release(&rt->dst); 641 dst_release(&rt->dst);
630 } 642 }
631 return 0; 643 return 0;
@@ -730,7 +742,7 @@ int ip6_ins_rt(struct rt6_info *rt)
730 return __ip6_ins_rt(rt, &info); 742 return __ip6_ins_rt(rt, &info);
731} 743}
732 744
733static struct rt6_info *rt6_alloc_cow(const struct rt6_info *ort, 745static struct rt6_info *rt6_alloc_cow(struct rt6_info *ort,
734 const struct in6_addr *daddr, 746 const struct in6_addr *daddr,
735 const struct in6_addr *saddr) 747 const struct in6_addr *saddr)
736{ 748{
@@ -881,6 +893,16 @@ static struct rt6_info *ip6_pol_route_input(struct net *net, struct fib6_table *
881 return ip6_pol_route(net, table, fl6->flowi6_iif, fl6, flags); 893 return ip6_pol_route(net, table, fl6->flowi6_iif, fl6, flags);
882} 894}
883 895
896static struct dst_entry *ip6_route_input_lookup(struct net *net,
897 struct net_device *dev,
898 struct flowi6 *fl6, int flags)
899{
900 if (rt6_need_strict(&fl6->daddr) && dev->type != ARPHRD_PIMREG)
901 flags |= RT6_LOOKUP_F_IFACE;
902
903 return fib6_rule_lookup(net, fl6, flags, ip6_pol_route_input);
904}
905
884void ip6_route_input(struct sk_buff *skb) 906void ip6_route_input(struct sk_buff *skb)
885{ 907{
886 const struct ipv6hdr *iph = ipv6_hdr(skb); 908 const struct ipv6hdr *iph = ipv6_hdr(skb);
@@ -895,10 +917,7 @@ void ip6_route_input(struct sk_buff *skb)
895 .flowi6_proto = iph->nexthdr, 917 .flowi6_proto = iph->nexthdr,
896 }; 918 };
897 919
898 if (rt6_need_strict(&iph->daddr) && skb->dev->type != ARPHRD_PIMREG) 920 skb_dst_set(skb, ip6_route_input_lookup(net, skb->dev, &fl6, flags));
899 flags |= RT6_LOOKUP_F_IFACE;
900
901 skb_dst_set(skb, fib6_rule_lookup(net, &fl6, flags, ip6_pol_route_input));
902} 921}
903 922
904static struct rt6_info *ip6_pol_route_output(struct net *net, struct fib6_table *table, 923static struct rt6_info *ip6_pol_route_output(struct net *net, struct fib6_table *table,
@@ -947,10 +966,10 @@ struct dst_entry *ip6_blackhole_route(struct net *net, struct dst_entry *dst_ori
947 rt->rt6i_idev = ort->rt6i_idev; 966 rt->rt6i_idev = ort->rt6i_idev;
948 if (rt->rt6i_idev) 967 if (rt->rt6i_idev)
949 in6_dev_hold(rt->rt6i_idev); 968 in6_dev_hold(rt->rt6i_idev);
950 rt->dst.expires = 0;
951 969
952 rt->rt6i_gateway = ort->rt6i_gateway; 970 rt->rt6i_gateway = ort->rt6i_gateway;
953 rt->rt6i_flags = ort->rt6i_flags & ~RTF_EXPIRES; 971 rt->rt6i_flags = ort->rt6i_flags;
972 rt6_clean_expires(rt);
954 rt->rt6i_metric = 0; 973 rt->rt6i_metric = 0;
955 974
956 memcpy(&rt->rt6i_dst, &ort->rt6i_dst, sizeof(struct rt6key)); 975 memcpy(&rt->rt6i_dst, &ort->rt6i_dst, sizeof(struct rt6key));
@@ -1012,10 +1031,9 @@ static void ip6_link_failure(struct sk_buff *skb)
1012 1031
1013 rt = (struct rt6_info *) skb_dst(skb); 1032 rt = (struct rt6_info *) skb_dst(skb);
1014 if (rt) { 1033 if (rt) {
1015 if (rt->rt6i_flags & RTF_CACHE) { 1034 if (rt->rt6i_flags & RTF_CACHE)
1016 dst_set_expires(&rt->dst, 0); 1035 rt6_update_expires(rt, 0);
1017 rt->rt6i_flags |= RTF_EXPIRES; 1036 else if (rt->rt6i_node && (rt->rt6i_flags & RTF_DEFAULT))
1018 } else if (rt->rt6i_node && (rt->rt6i_flags & RTF_DEFAULT))
1019 rt->rt6i_node->fn_sernum = -1; 1037 rt->rt6i_node->fn_sernum = -1;
1020 } 1038 }
1021} 1039}
@@ -1282,9 +1300,12 @@ int ip6_route_add(struct fib6_config *cfg)
1282 } 1300 }
1283 1301
1284 rt->dst.obsolete = -1; 1302 rt->dst.obsolete = -1;
1285 rt->dst.expires = (cfg->fc_flags & RTF_EXPIRES) ? 1303
1286 jiffies + clock_t_to_jiffies(cfg->fc_expires) : 1304 if (cfg->fc_flags & RTF_EXPIRES)
1287 0; 1305 rt6_set_expires(rt, jiffies +
1306 clock_t_to_jiffies(cfg->fc_expires));
1307 else
1308 rt6_clean_expires(rt);
1288 1309
1289 if (cfg->fc_protocol == RTPROT_UNSPEC) 1310 if (cfg->fc_protocol == RTPROT_UNSPEC)
1290 cfg->fc_protocol = RTPROT_BOOT; 1311 cfg->fc_protocol = RTPROT_BOOT;
@@ -1729,8 +1750,8 @@ again:
1729 features |= RTAX_FEATURE_ALLFRAG; 1750 features |= RTAX_FEATURE_ALLFRAG;
1730 dst_metric_set(&rt->dst, RTAX_FEATURES, features); 1751 dst_metric_set(&rt->dst, RTAX_FEATURES, features);
1731 } 1752 }
1732 dst_set_expires(&rt->dst, net->ipv6.sysctl.ip6_rt_mtu_expires); 1753 rt6_update_expires(rt, net->ipv6.sysctl.ip6_rt_mtu_expires);
1733 rt->rt6i_flags |= RTF_MODIFIED|RTF_EXPIRES; 1754 rt->rt6i_flags |= RTF_MODIFIED;
1734 goto out; 1755 goto out;
1735 } 1756 }
1736 1757
@@ -1758,9 +1779,8 @@ again:
1758 * which is 10 mins. After 10 mins the decreased pmtu is expired 1779 * which is 10 mins. After 10 mins the decreased pmtu is expired
1759 * and detecting PMTU increase will be automatically happened. 1780 * and detecting PMTU increase will be automatically happened.
1760 */ 1781 */
1761 dst_set_expires(&nrt->dst, net->ipv6.sysctl.ip6_rt_mtu_expires); 1782 rt6_update_expires(nrt, net->ipv6.sysctl.ip6_rt_mtu_expires);
1762 nrt->rt6i_flags |= RTF_DYNAMIC|RTF_EXPIRES; 1783 nrt->rt6i_flags |= RTF_DYNAMIC;
1763
1764 ip6_ins_rt(nrt); 1784 ip6_ins_rt(nrt);
1765 } 1785 }
1766out: 1786out:
@@ -1792,7 +1812,7 @@ void rt6_pmtu_discovery(const struct in6_addr *daddr, const struct in6_addr *sad
1792 * Misc support functions 1812 * Misc support functions
1793 */ 1813 */
1794 1814
1795static struct rt6_info *ip6_rt_copy(const struct rt6_info *ort, 1815static struct rt6_info *ip6_rt_copy(struct rt6_info *ort,
1796 const struct in6_addr *dest) 1816 const struct in6_addr *dest)
1797{ 1817{
1798 struct net *net = dev_net(ort->dst.dev); 1818 struct net *net = dev_net(ort->dst.dev);
@@ -1812,10 +1832,14 @@ static struct rt6_info *ip6_rt_copy(const struct rt6_info *ort,
1812 if (rt->rt6i_idev) 1832 if (rt->rt6i_idev)
1813 in6_dev_hold(rt->rt6i_idev); 1833 in6_dev_hold(rt->rt6i_idev);
1814 rt->dst.lastuse = jiffies; 1834 rt->dst.lastuse = jiffies;
1815 rt->dst.expires = 0;
1816 1835
1817 rt->rt6i_gateway = ort->rt6i_gateway; 1836 rt->rt6i_gateway = ort->rt6i_gateway;
1818 rt->rt6i_flags = ort->rt6i_flags & ~RTF_EXPIRES; 1837 rt->rt6i_flags = ort->rt6i_flags;
1838 if ((ort->rt6i_flags & (RTF_DEFAULT | RTF_ADDRCONF)) ==
1839 (RTF_DEFAULT | RTF_ADDRCONF))
1840 rt6_set_from(rt, ort);
1841 else
1842 rt6_clean_expires(rt);
1819 rt->rt6i_metric = 0; 1843 rt->rt6i_metric = 0;
1820 1844
1821#ifdef CONFIG_IPV6_SUBTREES 1845#ifdef CONFIG_IPV6_SUBTREES
@@ -2537,7 +2561,7 @@ static int inet6_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr* nlh, void
2537 struct sk_buff *skb; 2561 struct sk_buff *skb;
2538 struct rtmsg *rtm; 2562 struct rtmsg *rtm;
2539 struct flowi6 fl6; 2563 struct flowi6 fl6;
2540 int err, iif = 0; 2564 int err, iif = 0, oif = 0;
2541 2565
2542 err = nlmsg_parse(nlh, sizeof(*rtm), tb, RTA_MAX, rtm_ipv6_policy); 2566 err = nlmsg_parse(nlh, sizeof(*rtm), tb, RTA_MAX, rtm_ipv6_policy);
2543 if (err < 0) 2567 if (err < 0)
@@ -2564,15 +2588,29 @@ static int inet6_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr* nlh, void
2564 iif = nla_get_u32(tb[RTA_IIF]); 2588 iif = nla_get_u32(tb[RTA_IIF]);
2565 2589
2566 if (tb[RTA_OIF]) 2590 if (tb[RTA_OIF])
2567 fl6.flowi6_oif = nla_get_u32(tb[RTA_OIF]); 2591 oif = nla_get_u32(tb[RTA_OIF]);
2568 2592
2569 if (iif) { 2593 if (iif) {
2570 struct net_device *dev; 2594 struct net_device *dev;
2595 int flags = 0;
2596
2571 dev = __dev_get_by_index(net, iif); 2597 dev = __dev_get_by_index(net, iif);
2572 if (!dev) { 2598 if (!dev) {
2573 err = -ENODEV; 2599 err = -ENODEV;
2574 goto errout; 2600 goto errout;
2575 } 2601 }
2602
2603 fl6.flowi6_iif = iif;
2604
2605 if (!ipv6_addr_any(&fl6.saddr))
2606 flags |= RT6_LOOKUP_F_HAS_SADDR;
2607
2608 rt = (struct rt6_info *)ip6_route_input_lookup(net, dev, &fl6,
2609 flags);
2610 } else {
2611 fl6.flowi6_oif = oif;
2612
2613 rt = (struct rt6_info *)ip6_route_output(net, NULL, &fl6);
2576 } 2614 }
2577 2615
2578 skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL); 2616 skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
@@ -2587,7 +2625,6 @@ static int inet6_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr* nlh, void
2587 skb_reset_mac_header(skb); 2625 skb_reset_mac_header(skb);
2588 skb_reserve(skb, MAX_HEADER + sizeof(struct ipv6hdr)); 2626 skb_reserve(skb, MAX_HEADER + sizeof(struct ipv6hdr));
2589 2627
2590 rt = (struct rt6_info*) ip6_route_output(net, NULL, &fl6);
2591 skb_dst_set(skb, &rt->dst); 2628 skb_dst_set(skb, &rt->dst);
2592 2629
2593 err = rt6_fill_node(net, skb, rt, &fl6.daddr, &fl6.saddr, iif, 2630 err = rt6_fill_node(net, skb, rt, &fl6.daddr, &fl6.saddr, iif,
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index 12c6ece67f39..98256cf72f9d 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -1383,6 +1383,10 @@ static struct sock * tcp_v6_syn_recv_sock(struct sock *sk, struct sk_buff *skb,
1383 tcp_mtup_init(newsk); 1383 tcp_mtup_init(newsk);
1384 tcp_sync_mss(newsk, dst_mtu(dst)); 1384 tcp_sync_mss(newsk, dst_mtu(dst));
1385 newtp->advmss = dst_metric_advmss(dst); 1385 newtp->advmss = dst_metric_advmss(dst);
1386 if (tcp_sk(sk)->rx_opt.user_mss &&
1387 tcp_sk(sk)->rx_opt.user_mss < newtp->advmss)
1388 newtp->advmss = tcp_sk(sk)->rx_opt.user_mss;
1389
1386 tcp_initialize_rcv_mss(newsk); 1390 tcp_initialize_rcv_mss(newsk);
1387 if (tcp_rsk(req)->snt_synack) 1391 if (tcp_rsk(req)->snt_synack)
1388 tcp_valid_rtt_meas(newsk, 1392 tcp_valid_rtt_meas(newsk,
@@ -1645,7 +1649,7 @@ process:
1645#ifdef CONFIG_NET_DMA 1649#ifdef CONFIG_NET_DMA
1646 struct tcp_sock *tp = tcp_sk(sk); 1650 struct tcp_sock *tp = tcp_sk(sk);
1647 if (!tp->ucopy.dma_chan && tp->ucopy.pinned_list) 1651 if (!tp->ucopy.dma_chan && tp->ucopy.pinned_list)
1648 tp->ucopy.dma_chan = dma_find_channel(DMA_MEMCPY); 1652 tp->ucopy.dma_chan = net_dma_find_channel();
1649 if (tp->ucopy.dma_chan) 1653 if (tp->ucopy.dma_chan)
1650 ret = tcp_v6_do_rcv(sk, skb); 1654 ret = tcp_v6_do_rcv(sk, skb);
1651 else 1655 else
diff --git a/net/key/af_key.c b/net/key/af_key.c
index 11dbb2255ccb..7e5d927b576f 100644
--- a/net/key/af_key.c
+++ b/net/key/af_key.c
@@ -3480,7 +3480,7 @@ static int pfkey_send_migrate(const struct xfrm_selector *sel, u8 dir, u8 type,
3480 3480
3481 /* Addresses to be used by KM for negotiation, if ext is available */ 3481 /* Addresses to be used by KM for negotiation, if ext is available */
3482 if (k != NULL && (set_sadb_kmaddress(skb, k) < 0)) 3482 if (k != NULL && (set_sadb_kmaddress(skb, k) < 0))
3483 return -EINVAL; 3483 goto err;
3484 3484
3485 /* selector src */ 3485 /* selector src */
3486 set_sadb_address(skb, sasize_sel, SADB_EXT_ADDRESS_SRC, sel); 3486 set_sadb_address(skb, sasize_sel, SADB_EXT_ADDRESS_SRC, sel);
diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
index 55670ec3cd0f..6274f0be82b0 100644
--- a/net/l2tp/l2tp_ip.c
+++ b/net/l2tp/l2tp_ip.c
@@ -232,7 +232,7 @@ static void l2tp_ip_close(struct sock *sk, long timeout)
232{ 232{
233 write_lock_bh(&l2tp_ip_lock); 233 write_lock_bh(&l2tp_ip_lock);
234 hlist_del_init(&sk->sk_bind_node); 234 hlist_del_init(&sk->sk_bind_node);
235 hlist_del_init(&sk->sk_node); 235 sk_del_node_init(sk);
236 write_unlock_bh(&l2tp_ip_lock); 236 write_unlock_bh(&l2tp_ip_lock);
237 sk_common_release(sk); 237 sk_common_release(sk);
238} 238}
@@ -271,7 +271,8 @@ static int l2tp_ip_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
271 chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST) 271 chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
272 goto out; 272 goto out;
273 273
274 inet->inet_rcv_saddr = inet->inet_saddr = addr->l2tp_addr.s_addr; 274 if (addr->l2tp_addr.s_addr)
275 inet->inet_rcv_saddr = inet->inet_saddr = addr->l2tp_addr.s_addr;
275 if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST) 276 if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
276 inet->inet_saddr = 0; /* Use device */ 277 inet->inet_saddr = 0; /* Use device */
277 sk_dst_reset(sk); 278 sk_dst_reset(sk);
@@ -441,8 +442,9 @@ static int l2tp_ip_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
441 442
442 daddr = lip->l2tp_addr.s_addr; 443 daddr = lip->l2tp_addr.s_addr;
443 } else { 444 } else {
445 rc = -EDESTADDRREQ;
444 if (sk->sk_state != TCP_ESTABLISHED) 446 if (sk->sk_state != TCP_ESTABLISHED)
445 return -EDESTADDRREQ; 447 goto out;
446 448
447 daddr = inet->inet_daddr; 449 daddr = inet->inet_daddr;
448 connected = 1; 450 connected = 1;
diff --git a/net/mac80211/agg-rx.c b/net/mac80211/agg-rx.c
index 1068f668ac4e..64d3ce5ea1a0 100644
--- a/net/mac80211/agg-rx.c
+++ b/net/mac80211/agg-rx.c
@@ -49,6 +49,8 @@ static void ieee80211_free_tid_rx(struct rcu_head *h)
49 container_of(h, struct tid_ampdu_rx, rcu_head); 49 container_of(h, struct tid_ampdu_rx, rcu_head);
50 int i; 50 int i;
51 51
52 del_timer_sync(&tid_rx->reorder_timer);
53
52 for (i = 0; i < tid_rx->buf_size; i++) 54 for (i = 0; i < tid_rx->buf_size; i++)
53 dev_kfree_skb(tid_rx->reorder_buf[i]); 55 dev_kfree_skb(tid_rx->reorder_buf[i]);
54 kfree(tid_rx->reorder_buf); 56 kfree(tid_rx->reorder_buf);
@@ -91,7 +93,6 @@ void ___ieee80211_stop_rx_ba_session(struct sta_info *sta, u16 tid,
91 tid, WLAN_BACK_RECIPIENT, reason); 93 tid, WLAN_BACK_RECIPIENT, reason);
92 94
93 del_timer_sync(&tid_rx->session_timer); 95 del_timer_sync(&tid_rx->session_timer);
94 del_timer_sync(&tid_rx->reorder_timer);
95 96
96 call_rcu(&tid_rx->rcu_head, ieee80211_free_tid_rx); 97 call_rcu(&tid_rx->rcu_head, ieee80211_free_tid_rx);
97} 98}
diff --git a/net/mac80211/debugfs.c b/net/mac80211/debugfs.c
index cc5b7a6e7e0b..778e5916d7c3 100644
--- a/net/mac80211/debugfs.c
+++ b/net/mac80211/debugfs.c
@@ -15,12 +15,6 @@
15#include "rate.h" 15#include "rate.h"
16#include "debugfs.h" 16#include "debugfs.h"
17 17
18int mac80211_open_file_generic(struct inode *inode, struct file *file)
19{
20 file->private_data = inode->i_private;
21 return 0;
22}
23
24#define DEBUGFS_FORMAT_BUFFER_SIZE 100 18#define DEBUGFS_FORMAT_BUFFER_SIZE 100
25 19
26int mac80211_format_buffer(char __user *userbuf, size_t count, 20int mac80211_format_buffer(char __user *userbuf, size_t count,
@@ -50,7 +44,7 @@ static ssize_t name## _read(struct file *file, char __user *userbuf, \
50#define DEBUGFS_READONLY_FILE_OPS(name) \ 44#define DEBUGFS_READONLY_FILE_OPS(name) \
51static const struct file_operations name## _ops = { \ 45static const struct file_operations name## _ops = { \
52 .read = name## _read, \ 46 .read = name## _read, \
53 .open = mac80211_open_file_generic, \ 47 .open = simple_open, \
54 .llseek = generic_file_llseek, \ 48 .llseek = generic_file_llseek, \
55}; 49};
56 50
@@ -93,7 +87,7 @@ static ssize_t reset_write(struct file *file, const char __user *user_buf,
93 87
94static const struct file_operations reset_ops = { 88static const struct file_operations reset_ops = {
95 .write = reset_write, 89 .write = reset_write,
96 .open = mac80211_open_file_generic, 90 .open = simple_open,
97 .llseek = noop_llseek, 91 .llseek = noop_llseek,
98}; 92};
99 93
@@ -254,7 +248,7 @@ static ssize_t stats_ ##name## _read(struct file *file, \
254 \ 248 \
255static const struct file_operations stats_ ##name## _ops = { \ 249static const struct file_operations stats_ ##name## _ops = { \
256 .read = stats_ ##name## _read, \ 250 .read = stats_ ##name## _read, \
257 .open = mac80211_open_file_generic, \ 251 .open = simple_open, \
258 .llseek = generic_file_llseek, \ 252 .llseek = generic_file_llseek, \
259}; 253};
260 254
diff --git a/net/mac80211/debugfs.h b/net/mac80211/debugfs.h
index 7c87529630f5..9be4e6d71d00 100644
--- a/net/mac80211/debugfs.h
+++ b/net/mac80211/debugfs.h
@@ -3,7 +3,6 @@
3 3
4#ifdef CONFIG_MAC80211_DEBUGFS 4#ifdef CONFIG_MAC80211_DEBUGFS
5extern void debugfs_hw_add(struct ieee80211_local *local); 5extern void debugfs_hw_add(struct ieee80211_local *local);
6extern int mac80211_open_file_generic(struct inode *inode, struct file *file);
7extern int mac80211_format_buffer(char __user *userbuf, size_t count, 6extern int mac80211_format_buffer(char __user *userbuf, size_t count,
8 loff_t *ppos, char *fmt, ...); 7 loff_t *ppos, char *fmt, ...);
9#else 8#else
diff --git a/net/mac80211/debugfs_key.c b/net/mac80211/debugfs_key.c
index 59edcd95a58d..7932767bb482 100644
--- a/net/mac80211/debugfs_key.c
+++ b/net/mac80211/debugfs_key.c
@@ -30,7 +30,7 @@ static ssize_t key_##name##_read(struct file *file, \
30#define KEY_OPS(name) \ 30#define KEY_OPS(name) \
31static const struct file_operations key_ ##name## _ops = { \ 31static const struct file_operations key_ ##name## _ops = { \
32 .read = key_##name##_read, \ 32 .read = key_##name##_read, \
33 .open = mac80211_open_file_generic, \ 33 .open = simple_open, \
34 .llseek = generic_file_llseek, \ 34 .llseek = generic_file_llseek, \
35} 35}
36 36
@@ -45,7 +45,7 @@ static const struct file_operations key_ ##name## _ops = { \
45#define KEY_CONF_OPS(name) \ 45#define KEY_CONF_OPS(name) \
46static const struct file_operations key_ ##name## _ops = { \ 46static const struct file_operations key_ ##name## _ops = { \
47 .read = key_conf_##name##_read, \ 47 .read = key_conf_##name##_read, \
48 .open = mac80211_open_file_generic, \ 48 .open = simple_open, \
49 .llseek = generic_file_llseek, \ 49 .llseek = generic_file_llseek, \
50} 50}
51 51
diff --git a/net/mac80211/debugfs_netdev.c b/net/mac80211/debugfs_netdev.c
index a32eeda04aa3..30f99c344847 100644
--- a/net/mac80211/debugfs_netdev.c
+++ b/net/mac80211/debugfs_netdev.c
@@ -135,7 +135,7 @@ static ssize_t ieee80211_if_read_##name(struct file *file, \
135static const struct file_operations name##_ops = { \ 135static const struct file_operations name##_ops = { \
136 .read = ieee80211_if_read_##name, \ 136 .read = ieee80211_if_read_##name, \
137 .write = (_write), \ 137 .write = (_write), \
138 .open = mac80211_open_file_generic, \ 138 .open = simple_open, \
139 .llseek = generic_file_llseek, \ 139 .llseek = generic_file_llseek, \
140} 140}
141 141
diff --git a/net/mac80211/debugfs_sta.c b/net/mac80211/debugfs_sta.c
index 6d45804d09bc..832b2da5e4cd 100644
--- a/net/mac80211/debugfs_sta.c
+++ b/net/mac80211/debugfs_sta.c
@@ -33,7 +33,7 @@ static ssize_t sta_ ##name## _read(struct file *file, \
33#define STA_OPS(name) \ 33#define STA_OPS(name) \
34static const struct file_operations sta_ ##name## _ops = { \ 34static const struct file_operations sta_ ##name## _ops = { \
35 .read = sta_##name##_read, \ 35 .read = sta_##name##_read, \
36 .open = mac80211_open_file_generic, \ 36 .open = simple_open, \
37 .llseek = generic_file_llseek, \ 37 .llseek = generic_file_llseek, \
38} 38}
39 39
@@ -41,7 +41,7 @@ static const struct file_operations sta_ ##name## _ops = { \
41static const struct file_operations sta_ ##name## _ops = { \ 41static const struct file_operations sta_ ##name## _ops = { \
42 .read = sta_##name##_read, \ 42 .read = sta_##name##_read, \
43 .write = sta_##name##_write, \ 43 .write = sta_##name##_write, \
44 .open = mac80211_open_file_generic, \ 44 .open = simple_open, \
45 .llseek = generic_file_llseek, \ 45 .llseek = generic_file_llseek, \
46} 46}
47 47
diff --git a/net/mac80211/ibss.c b/net/mac80211/ibss.c
index 33fd8d9f714e..cef7c29214a8 100644
--- a/net/mac80211/ibss.c
+++ b/net/mac80211/ibss.c
@@ -457,8 +457,8 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
457 * fall back to HT20 if we don't use or use 457 * fall back to HT20 if we don't use or use
458 * the other extension channel 458 * the other extension channel
459 */ 459 */
460 if ((channel_type == NL80211_CHAN_HT40MINUS || 460 if (!(channel_type == NL80211_CHAN_HT40MINUS ||
461 channel_type == NL80211_CHAN_HT40PLUS) && 461 channel_type == NL80211_CHAN_HT40PLUS) ||
462 channel_type != sdata->u.ibss.channel_type) 462 channel_type != sdata->u.ibss.channel_type)
463 sta_ht_cap_new.cap &= 463 sta_ht_cap_new.cap &=
464 ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; 464 ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
index d9798a307f20..db8fae51714c 100644
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -1210,7 +1210,7 @@ void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
1210 struct sk_buff *skb); 1210 struct sk_buff *skb);
1211void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data *sdata); 1211void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data *sdata);
1212void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data *sdata); 1212void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data *sdata);
1213void ieee80211_mgd_teardown(struct ieee80211_sub_if_data *sdata); 1213void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata);
1214 1214
1215/* IBSS code */ 1215/* IBSS code */
1216void ieee80211_ibss_notify_scan_completed(struct ieee80211_local *local); 1216void ieee80211_ibss_notify_scan_completed(struct ieee80211_local *local);
diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
index 401c01f0731e..c20051b7ffcd 100644
--- a/net/mac80211/iface.c
+++ b/net/mac80211/iface.c
@@ -486,6 +486,8 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
486 /* free all potentially still buffered bcast frames */ 486 /* free all potentially still buffered bcast frames */
487 local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps_bc_buf); 487 local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps_bc_buf);
488 skb_queue_purge(&sdata->u.ap.ps_bc_buf); 488 skb_queue_purge(&sdata->u.ap.ps_bc_buf);
489 } else if (sdata->vif.type == NL80211_IFTYPE_STATION) {
490 ieee80211_mgd_stop(sdata);
489 } 491 }
490 492
491 if (going_down) 493 if (going_down)
@@ -644,8 +646,6 @@ static void ieee80211_teardown_sdata(struct net_device *dev)
644 646
645 if (ieee80211_vif_is_mesh(&sdata->vif)) 647 if (ieee80211_vif_is_mesh(&sdata->vif))
646 mesh_rmc_free(sdata); 648 mesh_rmc_free(sdata);
647 else if (sdata->vif.type == NL80211_IFTYPE_STATION)
648 ieee80211_mgd_teardown(sdata);
649 649
650 flushed = sta_info_flush(local, sdata); 650 flushed = sta_info_flush(local, sdata);
651 WARN_ON(flushed); 651 WARN_ON(flushed);
diff --git a/net/mac80211/main.c b/net/mac80211/main.c
index b581a24fa15c..16336480c631 100644
--- a/net/mac80211/main.c
+++ b/net/mac80211/main.c
@@ -102,9 +102,6 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
102 102
103 might_sleep(); 103 might_sleep();
104 104
105 /* If this off-channel logic ever changes, ieee80211_on_oper_channel
106 * may need to change as well.
107 */
108 offchannel_flag = local->hw.conf.flags & IEEE80211_CONF_OFFCHANNEL; 105 offchannel_flag = local->hw.conf.flags & IEEE80211_CONF_OFFCHANNEL;
109 if (local->scan_channel) { 106 if (local->scan_channel) {
110 chan = local->scan_channel; 107 chan = local->scan_channel;
diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
index 576fb25456dd..20c680bfc3ae 100644
--- a/net/mac80211/mlme.c
+++ b/net/mac80211/mlme.c
@@ -3387,8 +3387,7 @@ int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
3387 */ 3387 */
3388 printk(KERN_DEBUG "%s: waiting for beacon from %pM\n", 3388 printk(KERN_DEBUG "%s: waiting for beacon from %pM\n",
3389 sdata->name, ifmgd->bssid); 3389 sdata->name, ifmgd->bssid);
3390 assoc_data->timeout = jiffies + 3390 assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval);
3391 TU_TO_EXP_TIME(req->bss->beacon_interval);
3392 } else { 3391 } else {
3393 assoc_data->have_beacon = true; 3392 assoc_data->have_beacon = true;
3394 assoc_data->sent_assoc = false; 3393 assoc_data->sent_assoc = false;
@@ -3498,7 +3497,7 @@ int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
3498 return 0; 3497 return 0;
3499} 3498}
3500 3499
3501void ieee80211_mgd_teardown(struct ieee80211_sub_if_data *sdata) 3500void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata)
3502{ 3501{
3503 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 3502 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3504 3503
diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
index b4f7600a3e36..3313c117b322 100644
--- a/net/mac80211/rate.c
+++ b/net/mac80211/rate.c
@@ -145,7 +145,7 @@ static ssize_t rcname_read(struct file *file, char __user *userbuf,
145 145
146static const struct file_operations rcname_ops = { 146static const struct file_operations rcname_ops = {
147 .read = rcname_read, 147 .read = rcname_read,
148 .open = mac80211_open_file_generic, 148 .open = simple_open,
149 .llseek = default_llseek, 149 .llseek = default_llseek,
150}; 150};
151#endif 151#endif
diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
index bcfe8c77c839..d64e285400aa 100644
--- a/net/mac80211/rx.c
+++ b/net/mac80211/rx.c
@@ -103,7 +103,7 @@ static void
103ieee80211_add_rx_radiotap_header(struct ieee80211_local *local, 103ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
104 struct sk_buff *skb, 104 struct sk_buff *skb,
105 struct ieee80211_rate *rate, 105 struct ieee80211_rate *rate,
106 int rtap_len) 106 int rtap_len, bool has_fcs)
107{ 107{
108 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); 108 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
109 struct ieee80211_radiotap_header *rthdr; 109 struct ieee80211_radiotap_header *rthdr;
@@ -134,7 +134,7 @@ ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
134 } 134 }
135 135
136 /* IEEE80211_RADIOTAP_FLAGS */ 136 /* IEEE80211_RADIOTAP_FLAGS */
137 if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS) 137 if (has_fcs && (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS))
138 *pos |= IEEE80211_RADIOTAP_F_FCS; 138 *pos |= IEEE80211_RADIOTAP_F_FCS;
139 if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC)) 139 if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
140 *pos |= IEEE80211_RADIOTAP_F_BADFCS; 140 *pos |= IEEE80211_RADIOTAP_F_BADFCS;
@@ -294,7 +294,8 @@ ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
294 } 294 }
295 295
296 /* prepend radiotap information */ 296 /* prepend radiotap information */
297 ieee80211_add_rx_radiotap_header(local, skb, rate, needed_headroom); 297 ieee80211_add_rx_radiotap_header(local, skb, rate, needed_headroom,
298 true);
298 299
299 skb_reset_mac_header(skb); 300 skb_reset_mac_header(skb);
300 skb->ip_summed = CHECKSUM_UNNECESSARY; 301 skb->ip_summed = CHECKSUM_UNNECESSARY;
@@ -2571,7 +2572,8 @@ static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data *rx,
2571 goto out_free_skb; 2572 goto out_free_skb;
2572 2573
2573 /* prepend radiotap information */ 2574 /* prepend radiotap information */
2574 ieee80211_add_rx_radiotap_header(local, skb, rate, needed_headroom); 2575 ieee80211_add_rx_radiotap_header(local, skb, rate, needed_headroom,
2576 false);
2575 2577
2576 skb_set_mac_header(skb, 0); 2578 skb_set_mac_header(skb, 0);
2577 skb->ip_summed = CHECKSUM_UNNECESSARY; 2579 skb->ip_summed = CHECKSUM_UNNECESSARY;
diff --git a/net/mac80211/scan.c b/net/mac80211/scan.c
index 33cd16901378..c70e17677135 100644
--- a/net/mac80211/scan.c
+++ b/net/mac80211/scan.c
@@ -370,7 +370,7 @@ static int ieee80211_start_sw_scan(struct ieee80211_local *local)
370 */ 370 */
371 drv_sw_scan_start(local); 371 drv_sw_scan_start(local);
372 372
373 local->leave_oper_channel_time = 0; 373 local->leave_oper_channel_time = jiffies;
374 local->next_scan_state = SCAN_DECISION; 374 local->next_scan_state = SCAN_DECISION;
375 local->scan_channel_idx = 0; 375 local->scan_channel_idx = 0;
376 376
diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
index 782a60198df4..e76facc69e95 100644
--- a/net/mac80211/tx.c
+++ b/net/mac80211/tx.c
@@ -1158,7 +1158,8 @@ ieee80211_tx_prepare(struct ieee80211_sub_if_data *sdata,
1158 tx->sta = rcu_dereference(sdata->u.vlan.sta); 1158 tx->sta = rcu_dereference(sdata->u.vlan.sta);
1159 if (!tx->sta && sdata->dev->ieee80211_ptr->use_4addr) 1159 if (!tx->sta && sdata->dev->ieee80211_ptr->use_4addr)
1160 return TX_DROP; 1160 return TX_DROP;
1161 } else if (info->flags & IEEE80211_TX_CTL_INJECTED) { 1161 } else if (info->flags & IEEE80211_TX_CTL_INJECTED ||
1162 tx->sdata->control_port_protocol == tx->skb->protocol) {
1162 tx->sta = sta_info_get_bss(sdata, hdr->addr1); 1163 tx->sta = sta_info_get_bss(sdata, hdr->addr1);
1163 } 1164 }
1164 if (!tx->sta) 1165 if (!tx->sta)
diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
index 2555816e7788..00bdb1d9d690 100644
--- a/net/netfilter/ipvs/ip_vs_core.c
+++ b/net/netfilter/ipvs/ip_vs_core.c
@@ -1924,6 +1924,7 @@ protocol_fail:
1924control_fail: 1924control_fail:
1925 ip_vs_estimator_net_cleanup(net); 1925 ip_vs_estimator_net_cleanup(net);
1926estimator_fail: 1926estimator_fail:
1927 net->ipvs = NULL;
1927 return -ENOMEM; 1928 return -ENOMEM;
1928} 1929}
1929 1930
@@ -1936,6 +1937,7 @@ static void __net_exit __ip_vs_cleanup(struct net *net)
1936 ip_vs_control_net_cleanup(net); 1937 ip_vs_control_net_cleanup(net);
1937 ip_vs_estimator_net_cleanup(net); 1938 ip_vs_estimator_net_cleanup(net);
1938 IP_VS_DBG(2, "ipvs netns %d released\n", net_ipvs(net)->gen); 1939 IP_VS_DBG(2, "ipvs netns %d released\n", net_ipvs(net)->gen);
1940 net->ipvs = NULL;
1939} 1941}
1940 1942
1941static void __net_exit __ip_vs_dev_cleanup(struct net *net) 1943static void __net_exit __ip_vs_dev_cleanup(struct net *net)
@@ -1993,10 +1995,18 @@ static int __init ip_vs_init(void)
1993 goto cleanup_dev; 1995 goto cleanup_dev;
1994 } 1996 }
1995 1997
1998 ret = ip_vs_register_nl_ioctl();
1999 if (ret < 0) {
2000 pr_err("can't register netlink/ioctl.\n");
2001 goto cleanup_hooks;
2002 }
2003
1996 pr_info("ipvs loaded.\n"); 2004 pr_info("ipvs loaded.\n");
1997 2005
1998 return ret; 2006 return ret;
1999 2007
2008cleanup_hooks:
2009 nf_unregister_hooks(ip_vs_ops, ARRAY_SIZE(ip_vs_ops));
2000cleanup_dev: 2010cleanup_dev:
2001 unregister_pernet_device(&ipvs_core_dev_ops); 2011 unregister_pernet_device(&ipvs_core_dev_ops);
2002cleanup_sub: 2012cleanup_sub:
@@ -2012,6 +2022,7 @@ exit:
2012 2022
2013static void __exit ip_vs_cleanup(void) 2023static void __exit ip_vs_cleanup(void)
2014{ 2024{
2025 ip_vs_unregister_nl_ioctl();
2015 nf_unregister_hooks(ip_vs_ops, ARRAY_SIZE(ip_vs_ops)); 2026 nf_unregister_hooks(ip_vs_ops, ARRAY_SIZE(ip_vs_ops));
2016 unregister_pernet_device(&ipvs_core_dev_ops); 2027 unregister_pernet_device(&ipvs_core_dev_ops);
2017 unregister_pernet_subsys(&ipvs_core_ops); /* free ip_vs struct */ 2028 unregister_pernet_subsys(&ipvs_core_ops); /* free ip_vs struct */
diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
index b3afe189af61..f5589987fc80 100644
--- a/net/netfilter/ipvs/ip_vs_ctl.c
+++ b/net/netfilter/ipvs/ip_vs_ctl.c
@@ -3680,7 +3680,7 @@ int __net_init ip_vs_control_net_init_sysctl(struct net *net)
3680 return 0; 3680 return 0;
3681} 3681}
3682 3682
3683void __net_init ip_vs_control_net_cleanup_sysctl(struct net *net) 3683void __net_exit ip_vs_control_net_cleanup_sysctl(struct net *net)
3684{ 3684{
3685 struct netns_ipvs *ipvs = net_ipvs(net); 3685 struct netns_ipvs *ipvs = net_ipvs(net);
3686 3686
@@ -3692,7 +3692,7 @@ void __net_init ip_vs_control_net_cleanup_sysctl(struct net *net)
3692#else 3692#else
3693 3693
3694int __net_init ip_vs_control_net_init_sysctl(struct net *net) { return 0; } 3694int __net_init ip_vs_control_net_init_sysctl(struct net *net) { return 0; }
3695void __net_init ip_vs_control_net_cleanup_sysctl(struct net *net) { } 3695void __net_exit ip_vs_control_net_cleanup_sysctl(struct net *net) { }
3696 3696
3697#endif 3697#endif
3698 3698
@@ -3750,21 +3750,10 @@ void __net_exit ip_vs_control_net_cleanup(struct net *net)
3750 free_percpu(ipvs->tot_stats.cpustats); 3750 free_percpu(ipvs->tot_stats.cpustats);
3751} 3751}
3752 3752
3753int __init ip_vs_control_init(void) 3753int __init ip_vs_register_nl_ioctl(void)
3754{ 3754{
3755 int idx;
3756 int ret; 3755 int ret;
3757 3756
3758 EnterFunction(2);
3759
3760 /* Initialize svc_table, ip_vs_svc_fwm_table, rs_table */
3761 for(idx = 0; idx < IP_VS_SVC_TAB_SIZE; idx++) {
3762 INIT_LIST_HEAD(&ip_vs_svc_table[idx]);
3763 INIT_LIST_HEAD(&ip_vs_svc_fwm_table[idx]);
3764 }
3765
3766 smp_wmb(); /* Do we really need it now ? */
3767
3768 ret = nf_register_sockopt(&ip_vs_sockopts); 3757 ret = nf_register_sockopt(&ip_vs_sockopts);
3769 if (ret) { 3758 if (ret) {
3770 pr_err("cannot register sockopt.\n"); 3759 pr_err("cannot register sockopt.\n");
@@ -3776,28 +3765,47 @@ int __init ip_vs_control_init(void)
3776 pr_err("cannot register Generic Netlink interface.\n"); 3765 pr_err("cannot register Generic Netlink interface.\n");
3777 goto err_genl; 3766 goto err_genl;
3778 } 3767 }
3779
3780 ret = register_netdevice_notifier(&ip_vs_dst_notifier);
3781 if (ret < 0)
3782 goto err_notf;
3783
3784 LeaveFunction(2);
3785 return 0; 3768 return 0;
3786 3769
3787err_notf:
3788 ip_vs_genl_unregister();
3789err_genl: 3770err_genl:
3790 nf_unregister_sockopt(&ip_vs_sockopts); 3771 nf_unregister_sockopt(&ip_vs_sockopts);
3791err_sock: 3772err_sock:
3792 return ret; 3773 return ret;
3793} 3774}
3794 3775
3776void ip_vs_unregister_nl_ioctl(void)
3777{
3778 ip_vs_genl_unregister();
3779 nf_unregister_sockopt(&ip_vs_sockopts);
3780}
3781
3782int __init ip_vs_control_init(void)
3783{
3784 int idx;
3785 int ret;
3786
3787 EnterFunction(2);
3788
3789 /* Initialize svc_table, ip_vs_svc_fwm_table, rs_table */
3790 for (idx = 0; idx < IP_VS_SVC_TAB_SIZE; idx++) {
3791 INIT_LIST_HEAD(&ip_vs_svc_table[idx]);
3792 INIT_LIST_HEAD(&ip_vs_svc_fwm_table[idx]);
3793 }
3794
3795 smp_wmb(); /* Do we really need it now ? */
3796
3797 ret = register_netdevice_notifier(&ip_vs_dst_notifier);
3798 if (ret < 0)
3799 return ret;
3800
3801 LeaveFunction(2);
3802 return 0;
3803}
3804
3795 3805
3796void ip_vs_control_cleanup(void) 3806void ip_vs_control_cleanup(void)
3797{ 3807{
3798 EnterFunction(2); 3808 EnterFunction(2);
3799 unregister_netdevice_notifier(&ip_vs_dst_notifier); 3809 unregister_netdevice_notifier(&ip_vs_dst_notifier);
3800 ip_vs_genl_unregister();
3801 nf_unregister_sockopt(&ip_vs_sockopts);
3802 LeaveFunction(2); 3810 LeaveFunction(2);
3803} 3811}
diff --git a/net/netfilter/ipvs/ip_vs_ftp.c b/net/netfilter/ipvs/ip_vs_ftp.c
index 538d74ee4f68..e39f693dd3e4 100644
--- a/net/netfilter/ipvs/ip_vs_ftp.c
+++ b/net/netfilter/ipvs/ip_vs_ftp.c
@@ -439,6 +439,8 @@ static int __net_init __ip_vs_ftp_init(struct net *net)
439 struct ip_vs_app *app; 439 struct ip_vs_app *app;
440 struct netns_ipvs *ipvs = net_ipvs(net); 440 struct netns_ipvs *ipvs = net_ipvs(net);
441 441
442 if (!ipvs)
443 return -ENOENT;
442 app = kmemdup(&ip_vs_ftp, sizeof(struct ip_vs_app), GFP_KERNEL); 444 app = kmemdup(&ip_vs_ftp, sizeof(struct ip_vs_app), GFP_KERNEL);
443 if (!app) 445 if (!app)
444 return -ENOMEM; 446 return -ENOMEM;
diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
index 0f16283fd058..caa43704e55e 100644
--- a/net/netfilter/ipvs/ip_vs_lblc.c
+++ b/net/netfilter/ipvs/ip_vs_lblc.c
@@ -551,6 +551,9 @@ static int __net_init __ip_vs_lblc_init(struct net *net)
551{ 551{
552 struct netns_ipvs *ipvs = net_ipvs(net); 552 struct netns_ipvs *ipvs = net_ipvs(net);
553 553
554 if (!ipvs)
555 return -ENOENT;
556
554 if (!net_eq(net, &init_net)) { 557 if (!net_eq(net, &init_net)) {
555 ipvs->lblc_ctl_table = kmemdup(vs_vars_table, 558 ipvs->lblc_ctl_table = kmemdup(vs_vars_table,
556 sizeof(vs_vars_table), 559 sizeof(vs_vars_table),
diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
index eec797f8cce7..548bf37aa29e 100644
--- a/net/netfilter/ipvs/ip_vs_lblcr.c
+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
@@ -745,6 +745,9 @@ static int __net_init __ip_vs_lblcr_init(struct net *net)
745{ 745{
746 struct netns_ipvs *ipvs = net_ipvs(net); 746 struct netns_ipvs *ipvs = net_ipvs(net);
747 747
748 if (!ipvs)
749 return -ENOENT;
750
748 if (!net_eq(net, &init_net)) { 751 if (!net_eq(net, &init_net)) {
749 ipvs->lblcr_ctl_table = kmemdup(vs_vars_table, 752 ipvs->lblcr_ctl_table = kmemdup(vs_vars_table,
750 sizeof(vs_vars_table), 753 sizeof(vs_vars_table),
diff --git a/net/netfilter/ipvs/ip_vs_proto.c b/net/netfilter/ipvs/ip_vs_proto.c
index f843a8833250..ed835e67a07e 100644
--- a/net/netfilter/ipvs/ip_vs_proto.c
+++ b/net/netfilter/ipvs/ip_vs_proto.c
@@ -59,9 +59,6 @@ static int __used __init register_ip_vs_protocol(struct ip_vs_protocol *pp)
59 return 0; 59 return 0;
60} 60}
61 61
62#if defined(CONFIG_IP_VS_PROTO_TCP) || defined(CONFIG_IP_VS_PROTO_UDP) || \
63 defined(CONFIG_IP_VS_PROTO_SCTP) || defined(CONFIG_IP_VS_PROTO_AH) || \
64 defined(CONFIG_IP_VS_PROTO_ESP)
65/* 62/*
66 * register an ipvs protocols netns related data 63 * register an ipvs protocols netns related data
67 */ 64 */
@@ -81,12 +78,18 @@ register_ip_vs_proto_netns(struct net *net, struct ip_vs_protocol *pp)
81 ipvs->proto_data_table[hash] = pd; 78 ipvs->proto_data_table[hash] = pd;
82 atomic_set(&pd->appcnt, 0); /* Init app counter */ 79 atomic_set(&pd->appcnt, 0); /* Init app counter */
83 80
84 if (pp->init_netns != NULL) 81 if (pp->init_netns != NULL) {
85 pp->init_netns(net, pd); 82 int ret = pp->init_netns(net, pd);
83 if (ret) {
84 /* unlink an free proto data */
85 ipvs->proto_data_table[hash] = pd->next;
86 kfree(pd);
87 return ret;
88 }
89 }
86 90
87 return 0; 91 return 0;
88} 92}
89#endif
90 93
91/* 94/*
92 * unregister an ipvs protocol 95 * unregister an ipvs protocol
@@ -316,22 +319,35 @@ ip_vs_tcpudp_debug_packet(int af, struct ip_vs_protocol *pp,
316 */ 319 */
317int __net_init ip_vs_protocol_net_init(struct net *net) 320int __net_init ip_vs_protocol_net_init(struct net *net)
318{ 321{
322 int i, ret;
323 static struct ip_vs_protocol *protos[] = {
319#ifdef CONFIG_IP_VS_PROTO_TCP 324#ifdef CONFIG_IP_VS_PROTO_TCP
320 register_ip_vs_proto_netns(net, &ip_vs_protocol_tcp); 325 &ip_vs_protocol_tcp,
321#endif 326#endif
322#ifdef CONFIG_IP_VS_PROTO_UDP 327#ifdef CONFIG_IP_VS_PROTO_UDP
323 register_ip_vs_proto_netns(net, &ip_vs_protocol_udp); 328 &ip_vs_protocol_udp,
324#endif 329#endif
325#ifdef CONFIG_IP_VS_PROTO_SCTP 330#ifdef CONFIG_IP_VS_PROTO_SCTP
326 register_ip_vs_proto_netns(net, &ip_vs_protocol_sctp); 331 &ip_vs_protocol_sctp,
327#endif 332#endif
328#ifdef CONFIG_IP_VS_PROTO_AH 333#ifdef CONFIG_IP_VS_PROTO_AH
329 register_ip_vs_proto_netns(net, &ip_vs_protocol_ah); 334 &ip_vs_protocol_ah,
330#endif 335#endif
331#ifdef CONFIG_IP_VS_PROTO_ESP 336#ifdef CONFIG_IP_VS_PROTO_ESP
332 register_ip_vs_proto_netns(net, &ip_vs_protocol_esp); 337 &ip_vs_protocol_esp,
333#endif 338#endif
339 };
340
341 for (i = 0; i < ARRAY_SIZE(protos); i++) {
342 ret = register_ip_vs_proto_netns(net, protos[i]);
343 if (ret < 0)
344 goto cleanup;
345 }
334 return 0; 346 return 0;
347
348cleanup:
349 ip_vs_protocol_net_cleanup(net);
350 return ret;
335} 351}
336 352
337void __net_exit ip_vs_protocol_net_cleanup(struct net *net) 353void __net_exit ip_vs_protocol_net_cleanup(struct net *net)
diff --git a/net/netfilter/ipvs/ip_vs_proto_sctp.c b/net/netfilter/ipvs/ip_vs_proto_sctp.c
index 1fbf7a2816f5..9f3fb751c491 100644
--- a/net/netfilter/ipvs/ip_vs_proto_sctp.c
+++ b/net/netfilter/ipvs/ip_vs_proto_sctp.c
@@ -1090,7 +1090,7 @@ out:
1090 * timeouts is netns related now. 1090 * timeouts is netns related now.
1091 * --------------------------------------------- 1091 * ---------------------------------------------
1092 */ 1092 */
1093static void __ip_vs_sctp_init(struct net *net, struct ip_vs_proto_data *pd) 1093static int __ip_vs_sctp_init(struct net *net, struct ip_vs_proto_data *pd)
1094{ 1094{
1095 struct netns_ipvs *ipvs = net_ipvs(net); 1095 struct netns_ipvs *ipvs = net_ipvs(net);
1096 1096
@@ -1098,6 +1098,9 @@ static void __ip_vs_sctp_init(struct net *net, struct ip_vs_proto_data *pd)
1098 spin_lock_init(&ipvs->sctp_app_lock); 1098 spin_lock_init(&ipvs->sctp_app_lock);
1099 pd->timeout_table = ip_vs_create_timeout_table((int *)sctp_timeouts, 1099 pd->timeout_table = ip_vs_create_timeout_table((int *)sctp_timeouts,
1100 sizeof(sctp_timeouts)); 1100 sizeof(sctp_timeouts));
1101 if (!pd->timeout_table)
1102 return -ENOMEM;
1103 return 0;
1101} 1104}
1102 1105
1103static void __ip_vs_sctp_exit(struct net *net, struct ip_vs_proto_data *pd) 1106static void __ip_vs_sctp_exit(struct net *net, struct ip_vs_proto_data *pd)
diff --git a/net/netfilter/ipvs/ip_vs_proto_tcp.c b/net/netfilter/ipvs/ip_vs_proto_tcp.c
index ef8641f7af83..cd609cc62721 100644
--- a/net/netfilter/ipvs/ip_vs_proto_tcp.c
+++ b/net/netfilter/ipvs/ip_vs_proto_tcp.c
@@ -677,7 +677,7 @@ void ip_vs_tcp_conn_listen(struct net *net, struct ip_vs_conn *cp)
677 * timeouts is netns related now. 677 * timeouts is netns related now.
678 * --------------------------------------------- 678 * ---------------------------------------------
679 */ 679 */
680static void __ip_vs_tcp_init(struct net *net, struct ip_vs_proto_data *pd) 680static int __ip_vs_tcp_init(struct net *net, struct ip_vs_proto_data *pd)
681{ 681{
682 struct netns_ipvs *ipvs = net_ipvs(net); 682 struct netns_ipvs *ipvs = net_ipvs(net);
683 683
@@ -685,7 +685,10 @@ static void __ip_vs_tcp_init(struct net *net, struct ip_vs_proto_data *pd)
685 spin_lock_init(&ipvs->tcp_app_lock); 685 spin_lock_init(&ipvs->tcp_app_lock);
686 pd->timeout_table = ip_vs_create_timeout_table((int *)tcp_timeouts, 686 pd->timeout_table = ip_vs_create_timeout_table((int *)tcp_timeouts,
687 sizeof(tcp_timeouts)); 687 sizeof(tcp_timeouts));
688 if (!pd->timeout_table)
689 return -ENOMEM;
688 pd->tcp_state_table = tcp_states; 690 pd->tcp_state_table = tcp_states;
691 return 0;
689} 692}
690 693
691static void __ip_vs_tcp_exit(struct net *net, struct ip_vs_proto_data *pd) 694static void __ip_vs_tcp_exit(struct net *net, struct ip_vs_proto_data *pd)
diff --git a/net/netfilter/ipvs/ip_vs_proto_udp.c b/net/netfilter/ipvs/ip_vs_proto_udp.c
index f4b7262896bb..2fedb2dcb3d1 100644
--- a/net/netfilter/ipvs/ip_vs_proto_udp.c
+++ b/net/netfilter/ipvs/ip_vs_proto_udp.c
@@ -467,7 +467,7 @@ udp_state_transition(struct ip_vs_conn *cp, int direction,
467 cp->timeout = pd->timeout_table[IP_VS_UDP_S_NORMAL]; 467 cp->timeout = pd->timeout_table[IP_VS_UDP_S_NORMAL];
468} 468}
469 469
470static void __udp_init(struct net *net, struct ip_vs_proto_data *pd) 470static int __udp_init(struct net *net, struct ip_vs_proto_data *pd)
471{ 471{
472 struct netns_ipvs *ipvs = net_ipvs(net); 472 struct netns_ipvs *ipvs = net_ipvs(net);
473 473
@@ -475,6 +475,9 @@ static void __udp_init(struct net *net, struct ip_vs_proto_data *pd)
475 spin_lock_init(&ipvs->udp_app_lock); 475 spin_lock_init(&ipvs->udp_app_lock);
476 pd->timeout_table = ip_vs_create_timeout_table((int *)udp_timeouts, 476 pd->timeout_table = ip_vs_create_timeout_table((int *)udp_timeouts,
477 sizeof(udp_timeouts)); 477 sizeof(udp_timeouts));
478 if (!pd->timeout_table)
479 return -ENOMEM;
480 return 0;
478} 481}
479 482
480static void __udp_exit(struct net *net, struct ip_vs_proto_data *pd) 483static void __udp_exit(struct net *net, struct ip_vs_proto_data *pd)
diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
index cbdb754dbb10..729f157a0efa 100644
--- a/net/netfilter/nf_conntrack_core.c
+++ b/net/netfilter/nf_conntrack_core.c
@@ -735,6 +735,7 @@ __nf_conntrack_alloc(struct net *net, u16 zone,
735 735
736#ifdef CONFIG_NF_CONNTRACK_ZONES 736#ifdef CONFIG_NF_CONNTRACK_ZONES
737out_free: 737out_free:
738 atomic_dec(&net->ct.count);
738 kmem_cache_free(net->ct.nf_conntrack_cachep, ct); 739 kmem_cache_free(net->ct.nf_conntrack_cachep, ct);
739 return ERR_PTR(-ENOMEM); 740 return ERR_PTR(-ENOMEM);
740#endif 741#endif
@@ -1591,7 +1592,7 @@ static int nf_conntrack_init_net(struct net *net)
1591 return 0; 1592 return 0;
1592 1593
1593err_timeout: 1594err_timeout:
1594 nf_conntrack_timeout_fini(net); 1595 nf_conntrack_ecache_fini(net);
1595err_ecache: 1596err_ecache:
1596 nf_conntrack_tstamp_fini(net); 1597 nf_conntrack_tstamp_fini(net);
1597err_tstamp: 1598err_tstamp:
diff --git a/net/netfilter/nf_conntrack_proto_tcp.c b/net/netfilter/nf_conntrack_proto_tcp.c
index 361eade62a09..0d07a1dcf605 100644
--- a/net/netfilter/nf_conntrack_proto_tcp.c
+++ b/net/netfilter/nf_conntrack_proto_tcp.c
@@ -584,8 +584,8 @@ static bool tcp_in_window(const struct nf_conn *ct,
584 * Let's try to use the data from the packet. 584 * Let's try to use the data from the packet.
585 */ 585 */
586 sender->td_end = end; 586 sender->td_end = end;
587 win <<= sender->td_scale; 587 swin = win << sender->td_scale;
588 sender->td_maxwin = (win == 0 ? 1 : win); 588 sender->td_maxwin = (swin == 0 ? 1 : swin);
589 sender->td_maxend = end + sender->td_maxwin; 589 sender->td_maxend = end + sender->td_maxwin;
590 /* 590 /*
591 * We haven't seen traffic in the other direction yet 591 * We haven't seen traffic in the other direction yet
diff --git a/net/netfilter/nfnetlink_acct.c b/net/netfilter/nfnetlink_acct.c
index 3eb348bfc4fb..d98c868c148b 100644
--- a/net/netfilter/nfnetlink_acct.c
+++ b/net/netfilter/nfnetlink_acct.c
@@ -10,6 +10,7 @@
10#include <linux/module.h> 10#include <linux/module.h>
11#include <linux/kernel.h> 11#include <linux/kernel.h>
12#include <linux/skbuff.h> 12#include <linux/skbuff.h>
13#include <linux/atomic.h>
13#include <linux/netlink.h> 14#include <linux/netlink.h>
14#include <linux/rculist.h> 15#include <linux/rculist.h>
15#include <linux/slab.h> 16#include <linux/slab.h>
@@ -17,7 +18,6 @@
17#include <linux/errno.h> 18#include <linux/errno.h>
18#include <net/netlink.h> 19#include <net/netlink.h>
19#include <net/sock.h> 20#include <net/sock.h>
20#include <asm/atomic.h>
21 21
22#include <linux/netfilter.h> 22#include <linux/netfilter.h>
23#include <linux/netfilter/nfnetlink.h> 23#include <linux/netfilter/nfnetlink.h>
diff --git a/net/netfilter/xt_CT.c b/net/netfilter/xt_CT.c
index 0c8e43810ce3..3746d8b9a478 100644
--- a/net/netfilter/xt_CT.c
+++ b/net/netfilter/xt_CT.c
@@ -150,6 +150,17 @@ err1:
150 return ret; 150 return ret;
151} 151}
152 152
153#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
154static void __xt_ct_tg_timeout_put(struct ctnl_timeout *timeout)
155{
156 typeof(nf_ct_timeout_put_hook) timeout_put;
157
158 timeout_put = rcu_dereference(nf_ct_timeout_put_hook);
159 if (timeout_put)
160 timeout_put(timeout);
161}
162#endif
163
153static int xt_ct_tg_check_v1(const struct xt_tgchk_param *par) 164static int xt_ct_tg_check_v1(const struct xt_tgchk_param *par)
154{ 165{
155 struct xt_ct_target_info_v1 *info = par->targinfo; 166 struct xt_ct_target_info_v1 *info = par->targinfo;
@@ -158,7 +169,9 @@ static int xt_ct_tg_check_v1(const struct xt_tgchk_param *par)
158 struct nf_conn *ct; 169 struct nf_conn *ct;
159 int ret = 0; 170 int ret = 0;
160 u8 proto; 171 u8 proto;
161 172#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
173 struct ctnl_timeout *timeout;
174#endif
162 if (info->flags & ~XT_CT_NOTRACK) 175 if (info->flags & ~XT_CT_NOTRACK)
163 return -EINVAL; 176 return -EINVAL;
164 177
@@ -214,9 +227,8 @@ static int xt_ct_tg_check_v1(const struct xt_tgchk_param *par)
214 } 227 }
215 228
216#ifdef CONFIG_NF_CONNTRACK_TIMEOUT 229#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
217 if (info->timeout) { 230 if (info->timeout[0]) {
218 typeof(nf_ct_timeout_find_get_hook) timeout_find_get; 231 typeof(nf_ct_timeout_find_get_hook) timeout_find_get;
219 struct ctnl_timeout *timeout;
220 struct nf_conn_timeout *timeout_ext; 232 struct nf_conn_timeout *timeout_ext;
221 233
222 rcu_read_lock(); 234 rcu_read_lock();
@@ -245,7 +257,7 @@ static int xt_ct_tg_check_v1(const struct xt_tgchk_param *par)
245 pr_info("Timeout policy `%s' can only be " 257 pr_info("Timeout policy `%s' can only be "
246 "used by L3 protocol number %d\n", 258 "used by L3 protocol number %d\n",
247 info->timeout, timeout->l3num); 259 info->timeout, timeout->l3num);
248 goto err4; 260 goto err5;
249 } 261 }
250 /* Make sure the timeout policy matches any existing 262 /* Make sure the timeout policy matches any existing
251 * protocol tracker, otherwise default to generic. 263 * protocol tracker, otherwise default to generic.
@@ -258,13 +270,13 @@ static int xt_ct_tg_check_v1(const struct xt_tgchk_param *par)
258 "used by L4 protocol number %d\n", 270 "used by L4 protocol number %d\n",
259 info->timeout, 271 info->timeout,
260 timeout->l4proto->l4proto); 272 timeout->l4proto->l4proto);
261 goto err4; 273 goto err5;
262 } 274 }
263 timeout_ext = nf_ct_timeout_ext_add(ct, timeout, 275 timeout_ext = nf_ct_timeout_ext_add(ct, timeout,
264 GFP_KERNEL); 276 GFP_ATOMIC);
265 if (timeout_ext == NULL) { 277 if (timeout_ext == NULL) {
266 ret = -ENOMEM; 278 ret = -ENOMEM;
267 goto err4; 279 goto err5;
268 } 280 }
269 } else { 281 } else {
270 ret = -ENOENT; 282 ret = -ENOENT;
@@ -281,8 +293,12 @@ out:
281 info->ct = ct; 293 info->ct = ct;
282 return 0; 294 return 0;
283 295
296#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
297err5:
298 __xt_ct_tg_timeout_put(timeout);
284err4: 299err4:
285 rcu_read_unlock(); 300 rcu_read_unlock();
301#endif
286err3: 302err3:
287 nf_conntrack_free(ct); 303 nf_conntrack_free(ct);
288err2: 304err2:
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index 32bb75324e76..faa48f70b7c9 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -829,12 +829,19 @@ int netlink_attachskb(struct sock *sk, struct sk_buff *skb,
829 return 0; 829 return 0;
830} 830}
831 831
832int netlink_sendskb(struct sock *sk, struct sk_buff *skb) 832static int __netlink_sendskb(struct sock *sk, struct sk_buff *skb)
833{ 833{
834 int len = skb->len; 834 int len = skb->len;
835 835
836 skb_queue_tail(&sk->sk_receive_queue, skb); 836 skb_queue_tail(&sk->sk_receive_queue, skb);
837 sk->sk_data_ready(sk, len); 837 sk->sk_data_ready(sk, len);
838 return len;
839}
840
841int netlink_sendskb(struct sock *sk, struct sk_buff *skb)
842{
843 int len = __netlink_sendskb(sk, skb);
844
838 sock_put(sk); 845 sock_put(sk);
839 return len; 846 return len;
840} 847}
@@ -957,8 +964,7 @@ static int netlink_broadcast_deliver(struct sock *sk, struct sk_buff *skb)
957 if (atomic_read(&sk->sk_rmem_alloc) <= sk->sk_rcvbuf && 964 if (atomic_read(&sk->sk_rmem_alloc) <= sk->sk_rcvbuf &&
958 !test_bit(0, &nlk->state)) { 965 !test_bit(0, &nlk->state)) {
959 skb_set_owner_r(skb, sk); 966 skb_set_owner_r(skb, sk);
960 skb_queue_tail(&sk->sk_receive_queue, skb); 967 __netlink_sendskb(sk, skb);
961 sk->sk_data_ready(sk, skb->len);
962 return atomic_read(&sk->sk_rmem_alloc) > (sk->sk_rcvbuf >> 1); 968 return atomic_read(&sk->sk_rmem_alloc) > (sk->sk_rcvbuf >> 1);
963 } 969 }
964 return -1; 970 return -1;
@@ -1698,10 +1704,8 @@ static int netlink_dump(struct sock *sk)
1698 1704
1699 if (sk_filter(sk, skb)) 1705 if (sk_filter(sk, skb))
1700 kfree_skb(skb); 1706 kfree_skb(skb);
1701 else { 1707 else
1702 skb_queue_tail(&sk->sk_receive_queue, skb); 1708 __netlink_sendskb(sk, skb);
1703 sk->sk_data_ready(sk, skb->len);
1704 }
1705 return 0; 1709 return 0;
1706 } 1710 }
1707 1711
@@ -1715,10 +1719,8 @@ static int netlink_dump(struct sock *sk)
1715 1719
1716 if (sk_filter(sk, skb)) 1720 if (sk_filter(sk, skb))
1717 kfree_skb(skb); 1721 kfree_skb(skb);
1718 else { 1722 else
1719 skb_queue_tail(&sk->sk_receive_queue, skb); 1723 __netlink_sendskb(sk, skb);
1720 sk->sk_data_ready(sk, skb->len);
1721 }
1722 1724
1723 if (cb->done) 1725 if (cb->done)
1724 cb->done(cb); 1726 cb->done(cb);
diff --git a/net/nfc/llcp/commands.c b/net/nfc/llcp/commands.c
index 7b76eb7192f3..ef10ffcb4b6f 100644
--- a/net/nfc/llcp/commands.c
+++ b/net/nfc/llcp/commands.c
@@ -474,7 +474,7 @@ int nfc_llcp_send_i_frame(struct nfc_llcp_sock *sock,
474 474
475 while (remaining_len > 0) { 475 while (remaining_len > 0) {
476 476
477 frag_len = min_t(u16, local->remote_miu, remaining_len); 477 frag_len = min_t(size_t, local->remote_miu, remaining_len);
478 478
479 pr_debug("Fragment %zd bytes remaining %zd", 479 pr_debug("Fragment %zd bytes remaining %zd",
480 frag_len, remaining_len); 480 frag_len, remaining_len);
@@ -497,7 +497,7 @@ int nfc_llcp_send_i_frame(struct nfc_llcp_sock *sock,
497 release_sock(sk); 497 release_sock(sk);
498 498
499 remaining_len -= frag_len; 499 remaining_len -= frag_len;
500 msg_ptr += len; 500 msg_ptr += frag_len;
501 } 501 }
502 502
503 kfree(msg_data); 503 kfree(msg_data);
diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c
index e44e631ea952..777716bc80f7 100644
--- a/net/openvswitch/datapath.c
+++ b/net/openvswitch/datapath.c
@@ -421,6 +421,19 @@ static int validate_sample(const struct nlattr *attr,
421 return validate_actions(actions, key, depth + 1); 421 return validate_actions(actions, key, depth + 1);
422} 422}
423 423
424static int validate_tp_port(const struct sw_flow_key *flow_key)
425{
426 if (flow_key->eth.type == htons(ETH_P_IP)) {
427 if (flow_key->ipv4.tp.src && flow_key->ipv4.tp.dst)
428 return 0;
429 } else if (flow_key->eth.type == htons(ETH_P_IPV6)) {
430 if (flow_key->ipv6.tp.src && flow_key->ipv6.tp.dst)
431 return 0;
432 }
433
434 return -EINVAL;
435}
436
424static int validate_set(const struct nlattr *a, 437static int validate_set(const struct nlattr *a,
425 const struct sw_flow_key *flow_key) 438 const struct sw_flow_key *flow_key)
426{ 439{
@@ -462,18 +475,13 @@ static int validate_set(const struct nlattr *a,
462 if (flow_key->ip.proto != IPPROTO_TCP) 475 if (flow_key->ip.proto != IPPROTO_TCP)
463 return -EINVAL; 476 return -EINVAL;
464 477
465 if (!flow_key->ipv4.tp.src || !flow_key->ipv4.tp.dst) 478 return validate_tp_port(flow_key);
466 return -EINVAL;
467
468 break;
469 479
470 case OVS_KEY_ATTR_UDP: 480 case OVS_KEY_ATTR_UDP:
471 if (flow_key->ip.proto != IPPROTO_UDP) 481 if (flow_key->ip.proto != IPPROTO_UDP)
472 return -EINVAL; 482 return -EINVAL;
473 483
474 if (!flow_key->ipv4.tp.src || !flow_key->ipv4.tp.dst) 484 return validate_tp_port(flow_key);
475 return -EINVAL;
476 break;
477 485
478 default: 486 default:
479 return -EINVAL; 487 return -EINVAL;
@@ -1641,10 +1649,9 @@ static int ovs_vport_cmd_set(struct sk_buff *skb, struct genl_info *info)
1641 reply = ovs_vport_cmd_build_info(vport, info->snd_pid, info->snd_seq, 1649 reply = ovs_vport_cmd_build_info(vport, info->snd_pid, info->snd_seq,
1642 OVS_VPORT_CMD_NEW); 1650 OVS_VPORT_CMD_NEW);
1643 if (IS_ERR(reply)) { 1651 if (IS_ERR(reply)) {
1644 err = PTR_ERR(reply);
1645 netlink_set_err(init_net.genl_sock, 0, 1652 netlink_set_err(init_net.genl_sock, 0,
1646 ovs_dp_vport_multicast_group.id, err); 1653 ovs_dp_vport_multicast_group.id, PTR_ERR(reply));
1647 return 0; 1654 goto exit_unlock;
1648 } 1655 }
1649 1656
1650 genl_notify(reply, genl_info_net(info), info->snd_pid, 1657 genl_notify(reply, genl_info_net(info), info->snd_pid,
diff --git a/net/openvswitch/flow.c b/net/openvswitch/flow.c
index 1252c3081ef1..2a11ec2383ee 100644
--- a/net/openvswitch/flow.c
+++ b/net/openvswitch/flow.c
@@ -183,7 +183,8 @@ void ovs_flow_used(struct sw_flow *flow, struct sk_buff *skb)
183 u8 tcp_flags = 0; 183 u8 tcp_flags = 0;
184 184
185 if (flow->key.eth.type == htons(ETH_P_IP) && 185 if (flow->key.eth.type == htons(ETH_P_IP) &&
186 flow->key.ip.proto == IPPROTO_TCP) { 186 flow->key.ip.proto == IPPROTO_TCP &&
187 likely(skb->len >= skb_transport_offset(skb) + sizeof(struct tcphdr))) {
187 u8 *tcp = (u8 *)tcp_hdr(skb); 188 u8 *tcp = (u8 *)tcp_hdr(skb);
188 tcp_flags = *(tcp + TCP_FLAGS_OFFSET) & TCP_FLAG_MASK; 189 tcp_flags = *(tcp + TCP_FLAGS_OFFSET) & TCP_FLAG_MASK;
189 } 190 }
diff --git a/net/phonet/pep.c b/net/phonet/pep.c
index 9f60008740e3..9726fe684ab8 100644
--- a/net/phonet/pep.c
+++ b/net/phonet/pep.c
@@ -1130,6 +1130,9 @@ static int pep_sendmsg(struct kiocb *iocb, struct sock *sk,
1130 int flags = msg->msg_flags; 1130 int flags = msg->msg_flags;
1131 int err, done; 1131 int err, done;
1132 1132
1133 if (len > USHRT_MAX)
1134 return -EMSGSIZE;
1135
1133 if ((msg->msg_flags & ~(MSG_DONTWAIT|MSG_EOR|MSG_NOSIGNAL| 1136 if ((msg->msg_flags & ~(MSG_DONTWAIT|MSG_EOR|MSG_NOSIGNAL|
1134 MSG_CMSG_COMPAT)) || 1137 MSG_CMSG_COMPAT)) ||
1135 !(msg->msg_flags & MSG_EOR)) 1138 !(msg->msg_flags & MSG_EOR))
diff --git a/net/phonet/pn_dev.c b/net/phonet/pn_dev.c
index 9b9a85ecc4c7..bf5cf69c820a 100644
--- a/net/phonet/pn_dev.c
+++ b/net/phonet/pn_dev.c
@@ -331,23 +331,6 @@ static int __net_init phonet_init_net(struct net *net)
331 331
332static void __net_exit phonet_exit_net(struct net *net) 332static void __net_exit phonet_exit_net(struct net *net)
333{ 333{
334 struct phonet_net *pnn = phonet_pernet(net);
335 struct net_device *dev;
336 unsigned i;
337
338 rtnl_lock();
339 for_each_netdev(net, dev)
340 phonet_device_destroy(dev);
341
342 for (i = 0; i < 64; i++) {
343 dev = pnn->routes.table[i];
344 if (dev) {
345 rtm_phonet_notify(RTM_DELROUTE, dev, i);
346 dev_put(dev);
347 }
348 }
349 rtnl_unlock();
350
351 proc_net_remove(net, "phonet"); 334 proc_net_remove(net, "phonet");
352} 335}
353 336
@@ -361,7 +344,7 @@ static struct pernet_operations phonet_net_ops = {
361/* Initialize Phonet devices list */ 344/* Initialize Phonet devices list */
362int __init phonet_device_init(void) 345int __init phonet_device_init(void)
363{ 346{
364 int err = register_pernet_device(&phonet_net_ops); 347 int err = register_pernet_subsys(&phonet_net_ops);
365 if (err) 348 if (err)
366 return err; 349 return err;
367 350
@@ -377,7 +360,7 @@ void phonet_device_exit(void)
377{ 360{
378 rtnl_unregister_all(PF_PHONET); 361 rtnl_unregister_all(PF_PHONET);
379 unregister_netdevice_notifier(&phonet_device_notifier); 362 unregister_netdevice_notifier(&phonet_device_notifier);
380 unregister_pernet_device(&phonet_net_ops); 363 unregister_pernet_subsys(&phonet_net_ops);
381 proc_net_remove(&init_net, "pnresource"); 364 proc_net_remove(&init_net, "pnresource");
382} 365}
383 366
diff --git a/net/rose/rose_dev.c b/net/rose/rose_dev.c
index 1ab8689726ec..906cc05bba63 100644
--- a/net/rose/rose_dev.c
+++ b/net/rose/rose_dev.c
@@ -95,11 +95,11 @@ static int rose_set_mac_address(struct net_device *dev, void *addr)
95 struct sockaddr *sa = addr; 95 struct sockaddr *sa = addr;
96 int err; 96 int err;
97 97
98 if (!memcpy(dev->dev_addr, sa->sa_data, dev->addr_len)) 98 if (!memcmp(dev->dev_addr, sa->sa_data, dev->addr_len))
99 return 0; 99 return 0;
100 100
101 if (dev->flags & IFF_UP) { 101 if (dev->flags & IFF_UP) {
102 err = rose_add_loopback_node((rose_address *)dev->dev_addr); 102 err = rose_add_loopback_node((rose_address *)sa->sa_data);
103 if (err) 103 if (err)
104 return err; 104 return err;
105 105
diff --git a/net/sched/sch_gred.c b/net/sched/sch_gred.c
index 0b15236be7b6..8179494c269a 100644
--- a/net/sched/sch_gred.c
+++ b/net/sched/sch_gred.c
@@ -565,11 +565,8 @@ static int gred_dump(struct Qdisc *sch, struct sk_buff *skb)
565 opt.packets = q->packetsin; 565 opt.packets = q->packetsin;
566 opt.bytesin = q->bytesin; 566 opt.bytesin = q->bytesin;
567 567
568 if (gred_wred_mode(table)) { 568 if (gred_wred_mode(table))
569 q->vars.qidlestart = 569 gred_load_wred_set(table, q);
570 table->tab[table->def]->vars.qidlestart;
571 q->vars.qavg = table->tab[table->def]->vars.qavg;
572 }
573 570
574 opt.qave = red_calc_qavg(&q->parms, &q->vars, q->vars.qavg); 571 opt.qave = red_calc_qavg(&q->parms, &q->vars, q->vars.qavg);
575 572
diff --git a/net/sched/sch_netem.c b/net/sched/sch_netem.c
index 5da548fa7ae9..ebd22966f748 100644
--- a/net/sched/sch_netem.c
+++ b/net/sched/sch_netem.c
@@ -408,10 +408,8 @@ static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch)
408 if (q->corrupt && q->corrupt >= get_crandom(&q->corrupt_cor)) { 408 if (q->corrupt && q->corrupt >= get_crandom(&q->corrupt_cor)) {
409 if (!(skb = skb_unshare(skb, GFP_ATOMIC)) || 409 if (!(skb = skb_unshare(skb, GFP_ATOMIC)) ||
410 (skb->ip_summed == CHECKSUM_PARTIAL && 410 (skb->ip_summed == CHECKSUM_PARTIAL &&
411 skb_checksum_help(skb))) { 411 skb_checksum_help(skb)))
412 sch->qstats.drops++; 412 return qdisc_drop(skb, sch);
413 return NET_XMIT_DROP;
414 }
415 413
416 skb->data[net_random() % skb_headlen(skb)] ^= 1<<(net_random() % 8); 414 skb->data[net_random() % skb_headlen(skb)] ^= 1<<(net_random() % 8);
417 } 415 }
diff --git a/net/sctp/output.c b/net/sctp/output.c
index 817174eb5f41..8fc4dcd294ab 100644
--- a/net/sctp/output.c
+++ b/net/sctp/output.c
@@ -377,9 +377,7 @@ int sctp_packet_transmit(struct sctp_packet *packet)
377 */ 377 */
378 skb_set_owner_w(nskb, sk); 378 skb_set_owner_w(nskb, sk);
379 379
380 /* The 'obsolete' field of dst is set to 2 when a dst is freed. */ 380 if (!sctp_transport_dst_check(tp)) {
381 if (!dst || (dst->obsolete > 1)) {
382 dst_release(dst);
383 sctp_transport_route(tp, NULL, sctp_sk(sk)); 381 sctp_transport_route(tp, NULL, sctp_sk(sk));
384 if (asoc && (asoc->param_flags & SPP_PMTUD_ENABLE)) { 382 if (asoc && (asoc->param_flags & SPP_PMTUD_ENABLE)) {
385 sctp_assoc_sync_pmtu(asoc); 383 sctp_assoc_sync_pmtu(asoc);
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index 06b42b7f5a02..92ba71dfe080 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -4133,9 +4133,10 @@ static int sctp_getsockopt_disable_fragments(struct sock *sk, int len,
4133static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval, 4133static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
4134 int __user *optlen) 4134 int __user *optlen)
4135{ 4135{
4136 if (len < sizeof(struct sctp_event_subscribe)) 4136 if (len <= 0)
4137 return -EINVAL; 4137 return -EINVAL;
4138 len = sizeof(struct sctp_event_subscribe); 4138 if (len > sizeof(struct sctp_event_subscribe))
4139 len = sizeof(struct sctp_event_subscribe);
4139 if (put_user(len, optlen)) 4140 if (put_user(len, optlen))
4140 return -EFAULT; 4141 return -EFAULT;
4141 if (copy_to_user(optval, &sctp_sk(sk)->subscribe, len)) 4142 if (copy_to_user(optval, &sctp_sk(sk)->subscribe, len))
diff --git a/net/sctp/transport.c b/net/sctp/transport.c
index 3889330b7b04..b026ba0c6992 100644
--- a/net/sctp/transport.c
+++ b/net/sctp/transport.c
@@ -226,23 +226,6 @@ void sctp_transport_pmtu(struct sctp_transport *transport, struct sock *sk)
226 transport->pathmtu = SCTP_DEFAULT_MAXSEGMENT; 226 transport->pathmtu = SCTP_DEFAULT_MAXSEGMENT;
227} 227}
228 228
229/* this is a complete rip-off from __sk_dst_check
230 * the cookie is always 0 since this is how it's used in the
231 * pmtu code
232 */
233static struct dst_entry *sctp_transport_dst_check(struct sctp_transport *t)
234{
235 struct dst_entry *dst = t->dst;
236
237 if (dst && dst->obsolete && dst->ops->check(dst, 0) == NULL) {
238 dst_release(t->dst);
239 t->dst = NULL;
240 return NULL;
241 }
242
243 return dst;
244}
245
246void sctp_transport_update_pmtu(struct sctp_transport *t, u32 pmtu) 229void sctp_transport_update_pmtu(struct sctp_transport *t, u32 pmtu)
247{ 230{
248 struct dst_entry *dst; 231 struct dst_entry *dst;
diff --git a/net/socket.c b/net/socket.c
index 484cc6953fc6..851edcd6b098 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -811,9 +811,9 @@ static ssize_t sock_sendpage(struct file *file, struct page *page,
811 811
812 sock = file->private_data; 812 sock = file->private_data;
813 813
814 flags = !(file->f_flags & O_NONBLOCK) ? 0 : MSG_DONTWAIT; 814 flags = (file->f_flags & O_NONBLOCK) ? MSG_DONTWAIT : 0;
815 if (more) 815 /* more is a combination of MSG_MORE and MSG_SENDPAGE_NOTLAST */
816 flags |= MSG_MORE; 816 flags |= more;
817 817
818 return kernel_sendpage(sock, page, offset, size, flags); 818 return kernel_sendpage(sock, page, offset, size, flags);
819} 819}
diff --git a/net/sunrpc/auth_gss/gss_mech_switch.c b/net/sunrpc/auth_gss/gss_mech_switch.c
index ca8cad8251c7..782bfe1b6465 100644
--- a/net/sunrpc/auth_gss/gss_mech_switch.c
+++ b/net/sunrpc/auth_gss/gss_mech_switch.c
@@ -242,12 +242,13 @@ EXPORT_SYMBOL_GPL(gss_mech_get_by_pseudoflavor);
242int gss_mech_list_pseudoflavors(rpc_authflavor_t *array_ptr) 242int gss_mech_list_pseudoflavors(rpc_authflavor_t *array_ptr)
243{ 243{
244 struct gss_api_mech *pos = NULL; 244 struct gss_api_mech *pos = NULL;
245 int i = 0; 245 int j, i = 0;
246 246
247 spin_lock(&registered_mechs_lock); 247 spin_lock(&registered_mechs_lock);
248 list_for_each_entry(pos, &registered_mechs, gm_list) { 248 list_for_each_entry(pos, &registered_mechs, gm_list) {
249 array_ptr[i] = pos->gm_pfs->pseudoflavor; 249 for (j=0; j < pos->gm_pf_num; j++) {
250 i++; 250 array_ptr[i++] = pos->gm_pfs[j].pseudoflavor;
251 }
251 } 252 }
252 spin_unlock(&registered_mechs_lock); 253 spin_unlock(&registered_mechs_lock);
253 return i; 254 return i;
diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
index 67972462a543..adf2990acebf 100644
--- a/net/sunrpc/clnt.c
+++ b/net/sunrpc/clnt.c
@@ -176,16 +176,22 @@ rpc_setup_pipedir(struct rpc_clnt *clnt, const char *dir_name)
176 return 0; 176 return 0;
177} 177}
178 178
179static int __rpc_pipefs_event(struct rpc_clnt *clnt, unsigned long event, 179static inline int rpc_clnt_skip_event(struct rpc_clnt *clnt, unsigned long event)
180 struct super_block *sb) 180{
181 if (((event == RPC_PIPEFS_MOUNT) && clnt->cl_dentry) ||
182 ((event == RPC_PIPEFS_UMOUNT) && !clnt->cl_dentry))
183 return 1;
184 return 0;
185}
186
187static int __rpc_clnt_handle_event(struct rpc_clnt *clnt, unsigned long event,
188 struct super_block *sb)
181{ 189{
182 struct dentry *dentry; 190 struct dentry *dentry;
183 int err = 0; 191 int err = 0;
184 192
185 switch (event) { 193 switch (event) {
186 case RPC_PIPEFS_MOUNT: 194 case RPC_PIPEFS_MOUNT:
187 if (clnt->cl_program->pipe_dir_name == NULL)
188 break;
189 dentry = rpc_setup_pipedir_sb(sb, clnt, 195 dentry = rpc_setup_pipedir_sb(sb, clnt,
190 clnt->cl_program->pipe_dir_name); 196 clnt->cl_program->pipe_dir_name);
191 BUG_ON(dentry == NULL); 197 BUG_ON(dentry == NULL);
@@ -208,6 +214,20 @@ static int __rpc_pipefs_event(struct rpc_clnt *clnt, unsigned long event,
208 return err; 214 return err;
209} 215}
210 216
217static int __rpc_pipefs_event(struct rpc_clnt *clnt, unsigned long event,
218 struct super_block *sb)
219{
220 int error = 0;
221
222 for (;; clnt = clnt->cl_parent) {
223 if (!rpc_clnt_skip_event(clnt, event))
224 error = __rpc_clnt_handle_event(clnt, event, sb);
225 if (error || clnt == clnt->cl_parent)
226 break;
227 }
228 return error;
229}
230
211static struct rpc_clnt *rpc_get_client_for_event(struct net *net, int event) 231static struct rpc_clnt *rpc_get_client_for_event(struct net *net, int event)
212{ 232{
213 struct sunrpc_net *sn = net_generic(net, sunrpc_net_id); 233 struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
@@ -215,10 +235,12 @@ static struct rpc_clnt *rpc_get_client_for_event(struct net *net, int event)
215 235
216 spin_lock(&sn->rpc_client_lock); 236 spin_lock(&sn->rpc_client_lock);
217 list_for_each_entry(clnt, &sn->all_clients, cl_clients) { 237 list_for_each_entry(clnt, &sn->all_clients, cl_clients) {
218 if (((event == RPC_PIPEFS_MOUNT) && clnt->cl_dentry) || 238 if (clnt->cl_program->pipe_dir_name == NULL)
219 ((event == RPC_PIPEFS_UMOUNT) && !clnt->cl_dentry)) 239 break;
240 if (rpc_clnt_skip_event(clnt, event))
241 continue;
242 if (atomic_inc_not_zero(&clnt->cl_count) == 0)
220 continue; 243 continue;
221 atomic_inc(&clnt->cl_count);
222 spin_unlock(&sn->rpc_client_lock); 244 spin_unlock(&sn->rpc_client_lock);
223 return clnt; 245 return clnt;
224 } 246 }
@@ -257,6 +279,14 @@ void rpc_clients_notifier_unregister(void)
257 return rpc_pipefs_notifier_unregister(&rpc_clients_block); 279 return rpc_pipefs_notifier_unregister(&rpc_clients_block);
258} 280}
259 281
282static void rpc_clnt_set_nodename(struct rpc_clnt *clnt, const char *nodename)
283{
284 clnt->cl_nodelen = strlen(nodename);
285 if (clnt->cl_nodelen > UNX_MAXNODENAME)
286 clnt->cl_nodelen = UNX_MAXNODENAME;
287 memcpy(clnt->cl_nodename, nodename, clnt->cl_nodelen);
288}
289
260static struct rpc_clnt * rpc_new_client(const struct rpc_create_args *args, struct rpc_xprt *xprt) 290static struct rpc_clnt * rpc_new_client(const struct rpc_create_args *args, struct rpc_xprt *xprt)
261{ 291{
262 const struct rpc_program *program = args->program; 292 const struct rpc_program *program = args->program;
@@ -337,10 +367,7 @@ static struct rpc_clnt * rpc_new_client(const struct rpc_create_args *args, stru
337 } 367 }
338 368
339 /* save the nodename */ 369 /* save the nodename */
340 clnt->cl_nodelen = strlen(init_utsname()->nodename); 370 rpc_clnt_set_nodename(clnt, utsname()->nodename);
341 if (clnt->cl_nodelen > UNX_MAXNODENAME)
342 clnt->cl_nodelen = UNX_MAXNODENAME;
343 memcpy(clnt->cl_nodename, init_utsname()->nodename, clnt->cl_nodelen);
344 rpc_register_client(clnt); 371 rpc_register_client(clnt);
345 return clnt; 372 return clnt;
346 373
@@ -499,6 +526,7 @@ rpc_clone_client(struct rpc_clnt *clnt)
499 err = rpc_setup_pipedir(new, clnt->cl_program->pipe_dir_name); 526 err = rpc_setup_pipedir(new, clnt->cl_program->pipe_dir_name);
500 if (err != 0) 527 if (err != 0)
501 goto out_no_path; 528 goto out_no_path;
529 rpc_clnt_set_nodename(new, utsname()->nodename);
502 if (new->cl_auth) 530 if (new->cl_auth)
503 atomic_inc(&new->cl_auth->au_count); 531 atomic_inc(&new->cl_auth->au_count);
504 atomic_inc(&clnt->cl_count); 532 atomic_inc(&clnt->cl_count);
diff --git a/net/sunrpc/rpc_pipe.c b/net/sunrpc/rpc_pipe.c
index 0af37fc46818..3b62cf288031 100644
--- a/net/sunrpc/rpc_pipe.c
+++ b/net/sunrpc/rpc_pipe.c
@@ -1126,19 +1126,20 @@ rpc_fill_super(struct super_block *sb, void *data, int silent)
1126 return -ENOMEM; 1126 return -ENOMEM;
1127 dprintk("RPC: sending pipefs MOUNT notification for net %p%s\n", net, 1127 dprintk("RPC: sending pipefs MOUNT notification for net %p%s\n", net,
1128 NET_NAME(net)); 1128 NET_NAME(net));
1129 sn->pipefs_sb = sb;
1129 err = blocking_notifier_call_chain(&rpc_pipefs_notifier_list, 1130 err = blocking_notifier_call_chain(&rpc_pipefs_notifier_list,
1130 RPC_PIPEFS_MOUNT, 1131 RPC_PIPEFS_MOUNT,
1131 sb); 1132 sb);
1132 if (err) 1133 if (err)
1133 goto err_depopulate; 1134 goto err_depopulate;
1134 sb->s_fs_info = get_net(net); 1135 sb->s_fs_info = get_net(net);
1135 sn->pipefs_sb = sb;
1136 return 0; 1136 return 0;
1137 1137
1138err_depopulate: 1138err_depopulate:
1139 blocking_notifier_call_chain(&rpc_pipefs_notifier_list, 1139 blocking_notifier_call_chain(&rpc_pipefs_notifier_list,
1140 RPC_PIPEFS_UMOUNT, 1140 RPC_PIPEFS_UMOUNT,
1141 sb); 1141 sb);
1142 sn->pipefs_sb = NULL;
1142 __rpc_depopulate(root, files, RPCAUTH_lockd, RPCAUTH_RootEOF); 1143 __rpc_depopulate(root, files, RPCAUTH_lockd, RPCAUTH_RootEOF);
1143 return err; 1144 return err;
1144} 1145}
diff --git a/net/sunrpc/sunrpc_syms.c b/net/sunrpc/sunrpc_syms.c
index 8adfc88e793a..3d6498af9adc 100644
--- a/net/sunrpc/sunrpc_syms.c
+++ b/net/sunrpc/sunrpc_syms.c
@@ -75,20 +75,21 @@ static struct pernet_operations sunrpc_net_ops = {
75static int __init 75static int __init
76init_sunrpc(void) 76init_sunrpc(void)
77{ 77{
78 int err = register_rpc_pipefs(); 78 int err = rpc_init_mempool();
79 if (err) 79 if (err)
80 goto out; 80 goto out;
81 err = rpc_init_mempool();
82 if (err)
83 goto out2;
84 err = rpcauth_init_module(); 81 err = rpcauth_init_module();
85 if (err) 82 if (err)
86 goto out3; 83 goto out2;
87 84
88 cache_initialize(); 85 cache_initialize();
89 86
90 err = register_pernet_subsys(&sunrpc_net_ops); 87 err = register_pernet_subsys(&sunrpc_net_ops);
91 if (err) 88 if (err)
89 goto out3;
90
91 err = register_rpc_pipefs();
92 if (err)
92 goto out4; 93 goto out4;
93#ifdef RPC_DEBUG 94#ifdef RPC_DEBUG
94 rpc_register_sysctl(); 95 rpc_register_sysctl();
@@ -98,11 +99,11 @@ init_sunrpc(void)
98 return 0; 99 return 0;
99 100
100out4: 101out4:
101 rpcauth_remove_module(); 102 unregister_pernet_subsys(&sunrpc_net_ops);
102out3: 103out3:
103 rpc_destroy_mempool(); 104 rpcauth_remove_module();
104out2: 105out2:
105 unregister_rpc_pipefs(); 106 rpc_destroy_mempool();
106out: 107out:
107 return err; 108 return err;
108} 109}
diff --git a/net/wireless/debugfs.c b/net/wireless/debugfs.c
index 39765bcfb472..920cabe0461b 100644
--- a/net/wireless/debugfs.c
+++ b/net/wireless/debugfs.c
@@ -13,12 +13,6 @@
13#include "core.h" 13#include "core.h"
14#include "debugfs.h" 14#include "debugfs.h"
15 15
16static int cfg80211_open_file_generic(struct inode *inode, struct file *file)
17{
18 file->private_data = inode->i_private;
19 return 0;
20}
21
22#define DEBUGFS_READONLY_FILE(name, buflen, fmt, value...) \ 16#define DEBUGFS_READONLY_FILE(name, buflen, fmt, value...) \
23static ssize_t name## _read(struct file *file, char __user *userbuf, \ 17static ssize_t name## _read(struct file *file, char __user *userbuf, \
24 size_t count, loff_t *ppos) \ 18 size_t count, loff_t *ppos) \
@@ -33,7 +27,7 @@ static ssize_t name## _read(struct file *file, char __user *userbuf, \
33 \ 27 \
34static const struct file_operations name## _ops = { \ 28static const struct file_operations name## _ops = { \
35 .read = name## _read, \ 29 .read = name## _read, \
36 .open = cfg80211_open_file_generic, \ 30 .open = simple_open, \
37 .llseek = generic_file_llseek, \ 31 .llseek = generic_file_llseek, \
38}; 32};
39 33
@@ -102,7 +96,7 @@ static ssize_t ht40allow_map_read(struct file *file,
102 96
103static const struct file_operations ht40allow_map_ops = { 97static const struct file_operations ht40allow_map_ops = {
104 .read = ht40allow_map_read, 98 .read = ht40allow_map_read,
105 .open = cfg80211_open_file_generic, 99 .open = simple_open,
106 .llseek = default_llseek, 100 .llseek = default_llseek,
107}; 101};
108 102
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index 4c1eb9472ddb..f432c57af05d 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -1294,6 +1294,11 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1294 goto bad_res; 1294 goto bad_res;
1295 } 1295 }
1296 1296
1297 if (!netif_running(netdev)) {
1298 result = -ENETDOWN;
1299 goto bad_res;
1300 }
1301
1297 nla_for_each_nested(nl_txq_params, 1302 nla_for_each_nested(nl_txq_params,
1298 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], 1303 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
1299 rem_txq_params) { 1304 rem_txq_params) {
@@ -2386,7 +2391,9 @@ nla_put_failure:
2386} 2391}
2387 2392
2388static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq, 2393static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq,
2389 int flags, struct net_device *dev, 2394 int flags,
2395 struct cfg80211_registered_device *rdev,
2396 struct net_device *dev,
2390 const u8 *mac_addr, struct station_info *sinfo) 2397 const u8 *mac_addr, struct station_info *sinfo)
2391{ 2398{
2392 void *hdr; 2399 void *hdr;
@@ -2425,12 +2432,18 @@ static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq,
2425 if (sinfo->filled & STATION_INFO_PLINK_STATE) 2432 if (sinfo->filled & STATION_INFO_PLINK_STATE)
2426 NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE, 2433 NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE,
2427 sinfo->plink_state); 2434 sinfo->plink_state);
2428 if (sinfo->filled & STATION_INFO_SIGNAL) 2435 switch (rdev->wiphy.signal_type) {
2429 NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL, 2436 case CFG80211_SIGNAL_TYPE_MBM:
2430 sinfo->signal); 2437 if (sinfo->filled & STATION_INFO_SIGNAL)
2431 if (sinfo->filled & STATION_INFO_SIGNAL_AVG) 2438 NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL,
2432 NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL_AVG, 2439 sinfo->signal);
2433 sinfo->signal_avg); 2440 if (sinfo->filled & STATION_INFO_SIGNAL_AVG)
2441 NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL_AVG,
2442 sinfo->signal_avg);
2443 break;
2444 default:
2445 break;
2446 }
2434 if (sinfo->filled & STATION_INFO_TX_BITRATE) { 2447 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
2435 if (!nl80211_put_sta_rate(msg, &sinfo->txrate, 2448 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
2436 NL80211_STA_INFO_TX_BITRATE)) 2449 NL80211_STA_INFO_TX_BITRATE))
@@ -2523,7 +2536,7 @@ static int nl80211_dump_station(struct sk_buff *skb,
2523 if (nl80211_send_station(skb, 2536 if (nl80211_send_station(skb,
2524 NETLINK_CB(cb->skb).pid, 2537 NETLINK_CB(cb->skb).pid,
2525 cb->nlh->nlmsg_seq, NLM_F_MULTI, 2538 cb->nlh->nlmsg_seq, NLM_F_MULTI,
2526 netdev, mac_addr, 2539 dev, netdev, mac_addr,
2527 &sinfo) < 0) 2540 &sinfo) < 0)
2528 goto out; 2541 goto out;
2529 2542
@@ -2568,7 +2581,7 @@ static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
2568 return -ENOMEM; 2581 return -ENOMEM;
2569 2582
2570 if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0, 2583 if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0,
2571 dev, mac_addr, &sinfo) < 0) { 2584 rdev, dev, mac_addr, &sinfo) < 0) {
2572 nlmsg_free(msg); 2585 nlmsg_free(msg);
2573 return -ENOBUFS; 2586 return -ENOBUFS;
2574 } 2587 }
@@ -6376,7 +6389,7 @@ static struct genl_ops nl80211_ops[] = {
6376 .doit = nl80211_get_key, 6389 .doit = nl80211_get_key,
6377 .policy = nl80211_policy, 6390 .policy = nl80211_policy,
6378 .flags = GENL_ADMIN_PERM, 6391 .flags = GENL_ADMIN_PERM,
6379 .internal_flags = NL80211_FLAG_NEED_NETDEV | 6392 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6380 NL80211_FLAG_NEED_RTNL, 6393 NL80211_FLAG_NEED_RTNL,
6381 }, 6394 },
6382 { 6395 {
@@ -6408,7 +6421,7 @@ static struct genl_ops nl80211_ops[] = {
6408 .policy = nl80211_policy, 6421 .policy = nl80211_policy,
6409 .flags = GENL_ADMIN_PERM, 6422 .flags = GENL_ADMIN_PERM,
6410 .doit = nl80211_set_beacon, 6423 .doit = nl80211_set_beacon,
6411 .internal_flags = NL80211_FLAG_NEED_NETDEV | 6424 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6412 NL80211_FLAG_NEED_RTNL, 6425 NL80211_FLAG_NEED_RTNL,
6413 }, 6426 },
6414 { 6427 {
@@ -6416,7 +6429,7 @@ static struct genl_ops nl80211_ops[] = {
6416 .policy = nl80211_policy, 6429 .policy = nl80211_policy,
6417 .flags = GENL_ADMIN_PERM, 6430 .flags = GENL_ADMIN_PERM,
6418 .doit = nl80211_start_ap, 6431 .doit = nl80211_start_ap,
6419 .internal_flags = NL80211_FLAG_NEED_NETDEV | 6432 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6420 NL80211_FLAG_NEED_RTNL, 6433 NL80211_FLAG_NEED_RTNL,
6421 }, 6434 },
6422 { 6435 {
@@ -6424,7 +6437,7 @@ static struct genl_ops nl80211_ops[] = {
6424 .policy = nl80211_policy, 6437 .policy = nl80211_policy,
6425 .flags = GENL_ADMIN_PERM, 6438 .flags = GENL_ADMIN_PERM,
6426 .doit = nl80211_stop_ap, 6439 .doit = nl80211_stop_ap,
6427 .internal_flags = NL80211_FLAG_NEED_NETDEV | 6440 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6428 NL80211_FLAG_NEED_RTNL, 6441 NL80211_FLAG_NEED_RTNL,
6429 }, 6442 },
6430 { 6443 {
@@ -6440,7 +6453,7 @@ static struct genl_ops nl80211_ops[] = {
6440 .doit = nl80211_set_station, 6453 .doit = nl80211_set_station,
6441 .policy = nl80211_policy, 6454 .policy = nl80211_policy,
6442 .flags = GENL_ADMIN_PERM, 6455 .flags = GENL_ADMIN_PERM,
6443 .internal_flags = NL80211_FLAG_NEED_NETDEV | 6456 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6444 NL80211_FLAG_NEED_RTNL, 6457 NL80211_FLAG_NEED_RTNL,
6445 }, 6458 },
6446 { 6459 {
@@ -6456,7 +6469,7 @@ static struct genl_ops nl80211_ops[] = {
6456 .doit = nl80211_del_station, 6469 .doit = nl80211_del_station,
6457 .policy = nl80211_policy, 6470 .policy = nl80211_policy,
6458 .flags = GENL_ADMIN_PERM, 6471 .flags = GENL_ADMIN_PERM,
6459 .internal_flags = NL80211_FLAG_NEED_NETDEV | 6472 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6460 NL80211_FLAG_NEED_RTNL, 6473 NL80211_FLAG_NEED_RTNL,
6461 }, 6474 },
6462 { 6475 {
@@ -6489,7 +6502,7 @@ static struct genl_ops nl80211_ops[] = {
6489 .doit = nl80211_del_mpath, 6502 .doit = nl80211_del_mpath,
6490 .policy = nl80211_policy, 6503 .policy = nl80211_policy,
6491 .flags = GENL_ADMIN_PERM, 6504 .flags = GENL_ADMIN_PERM,
6492 .internal_flags = NL80211_FLAG_NEED_NETDEV | 6505 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6493 NL80211_FLAG_NEED_RTNL, 6506 NL80211_FLAG_NEED_RTNL,
6494 }, 6507 },
6495 { 6508 {
@@ -6497,7 +6510,7 @@ static struct genl_ops nl80211_ops[] = {
6497 .doit = nl80211_set_bss, 6510 .doit = nl80211_set_bss,
6498 .policy = nl80211_policy, 6511 .policy = nl80211_policy,
6499 .flags = GENL_ADMIN_PERM, 6512 .flags = GENL_ADMIN_PERM,
6500 .internal_flags = NL80211_FLAG_NEED_NETDEV | 6513 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6501 NL80211_FLAG_NEED_RTNL, 6514 NL80211_FLAG_NEED_RTNL,
6502 }, 6515 },
6503 { 6516 {
@@ -6523,7 +6536,7 @@ static struct genl_ops nl80211_ops[] = {
6523 .doit = nl80211_get_mesh_config, 6536 .doit = nl80211_get_mesh_config,
6524 .policy = nl80211_policy, 6537 .policy = nl80211_policy,
6525 /* can be retrieved by unprivileged users */ 6538 /* can be retrieved by unprivileged users */
6526 .internal_flags = NL80211_FLAG_NEED_NETDEV | 6539 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6527 NL80211_FLAG_NEED_RTNL, 6540 NL80211_FLAG_NEED_RTNL,
6528 }, 6541 },
6529 { 6542 {
@@ -6656,7 +6669,7 @@ static struct genl_ops nl80211_ops[] = {
6656 .doit = nl80211_setdel_pmksa, 6669 .doit = nl80211_setdel_pmksa,
6657 .policy = nl80211_policy, 6670 .policy = nl80211_policy,
6658 .flags = GENL_ADMIN_PERM, 6671 .flags = GENL_ADMIN_PERM,
6659 .internal_flags = NL80211_FLAG_NEED_NETDEV | 6672 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6660 NL80211_FLAG_NEED_RTNL, 6673 NL80211_FLAG_NEED_RTNL,
6661 }, 6674 },
6662 { 6675 {
@@ -6664,7 +6677,7 @@ static struct genl_ops nl80211_ops[] = {
6664 .doit = nl80211_setdel_pmksa, 6677 .doit = nl80211_setdel_pmksa,
6665 .policy = nl80211_policy, 6678 .policy = nl80211_policy,
6666 .flags = GENL_ADMIN_PERM, 6679 .flags = GENL_ADMIN_PERM,
6667 .internal_flags = NL80211_FLAG_NEED_NETDEV | 6680 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6668 NL80211_FLAG_NEED_RTNL, 6681 NL80211_FLAG_NEED_RTNL,
6669 }, 6682 },
6670 { 6683 {
@@ -6672,7 +6685,7 @@ static struct genl_ops nl80211_ops[] = {
6672 .doit = nl80211_flush_pmksa, 6685 .doit = nl80211_flush_pmksa,
6673 .policy = nl80211_policy, 6686 .policy = nl80211_policy,
6674 .flags = GENL_ADMIN_PERM, 6687 .flags = GENL_ADMIN_PERM,
6675 .internal_flags = NL80211_FLAG_NEED_NETDEV | 6688 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6676 NL80211_FLAG_NEED_RTNL, 6689 NL80211_FLAG_NEED_RTNL,
6677 }, 6690 },
6678 { 6691 {
@@ -6832,7 +6845,7 @@ static struct genl_ops nl80211_ops[] = {
6832 .doit = nl80211_probe_client, 6845 .doit = nl80211_probe_client,
6833 .policy = nl80211_policy, 6846 .policy = nl80211_policy,
6834 .flags = GENL_ADMIN_PERM, 6847 .flags = GENL_ADMIN_PERM,
6835 .internal_flags = NL80211_FLAG_NEED_NETDEV | 6848 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6836 NL80211_FLAG_NEED_RTNL, 6849 NL80211_FLAG_NEED_RTNL,
6837 }, 6850 },
6838 { 6851 {
@@ -7596,7 +7609,8 @@ void nl80211_send_sta_event(struct cfg80211_registered_device *rdev,
7596 if (!msg) 7609 if (!msg)
7597 return; 7610 return;
7598 7611
7599 if (nl80211_send_station(msg, 0, 0, 0, dev, mac_addr, sinfo) < 0) { 7612 if (nl80211_send_station(msg, 0, 0, 0,
7613 rdev, dev, mac_addr, sinfo) < 0) {
7600 nlmsg_free(msg); 7614 nlmsg_free(msg);
7601 return; 7615 return;
7602 } 7616 }
diff --git a/net/wireless/util.c b/net/wireless/util.c
index 1b7a08df933c..957f25621617 100644
--- a/net/wireless/util.c
+++ b/net/wireless/util.c
@@ -989,7 +989,7 @@ int cfg80211_can_change_interface(struct cfg80211_registered_device *rdev,
989 if (rdev->wiphy.software_iftypes & BIT(iftype)) 989 if (rdev->wiphy.software_iftypes & BIT(iftype))
990 continue; 990 continue;
991 for (j = 0; j < c->n_limits; j++) { 991 for (j = 0; j < c->n_limits; j++) {
992 if (!(limits[j].types & iftype)) 992 if (!(limits[j].types & BIT(iftype)))
993 continue; 993 continue;
994 if (limits[j].max < num[iftype]) 994 if (limits[j].max < num[iftype])
995 goto cont; 995 goto cont;
diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
index 0af7f54e4f61..af648e08e61b 100644
--- a/net/wireless/wext-core.c
+++ b/net/wireless/wext-core.c
@@ -780,8 +780,10 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
780 if (cmd == SIOCSIWENCODEEXT) { 780 if (cmd == SIOCSIWENCODEEXT) {
781 struct iw_encode_ext *ee = (void *) extra; 781 struct iw_encode_ext *ee = (void *) extra;
782 782
783 if (iwp->length < sizeof(*ee) + ee->key_len) 783 if (iwp->length < sizeof(*ee) + ee->key_len) {
784 return -EFAULT; 784 err = -EFAULT;
785 goto out;
786 }
785 } 787 }
786 } 788 }
787 789
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index de639eeeed50..faea0ec612bf 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -1869,12 +1869,6 @@ sub process {
1869 "No space is necessary after a cast\n" . $hereprev); 1869 "No space is necessary after a cast\n" . $hereprev);
1870 } 1870 }
1871 1871
1872 if ($rawline =~ /^\+[ \t]*\/\*[ \t]*$/ &&
1873 $prevrawline =~ /^\+[ \t]*$/) {
1874 CHK("BLOCK_COMMENT_STYLE",
1875 "Don't begin block comments with only a /* line, use /* comment...\n" . $hereprev);
1876 }
1877
1878# check for spaces at the beginning of a line. 1872# check for spaces at the beginning of a line.
1879# Exceptions: 1873# Exceptions:
1880# 1) within comments 1874# 1) within comments
diff --git a/scripts/coccinelle/api/simple_open.cocci b/scripts/coccinelle/api/simple_open.cocci
new file mode 100644
index 000000000000..05962f7be155
--- /dev/null
+++ b/scripts/coccinelle/api/simple_open.cocci
@@ -0,0 +1,70 @@
1/// This removes an open coded simple_open() function
2/// and replaces file operations references to the function
3/// with simple_open() instead.
4///
5// Confidence: High
6// Comments:
7// Options: -no_includes -include_headers
8
9virtual patch
10virtual report
11
12@ open depends on patch @
13identifier open_f != simple_open;
14identifier i, f;
15@@
16-int open_f(struct inode *i, struct file *f)
17-{
18(
19-if (i->i_private)
20-f->private_data = i->i_private;
21|
22-f->private_data = i->i_private;
23)
24-return 0;
25-}
26
27@ has_open depends on open @
28identifier fops;
29identifier open.open_f;
30@@
31struct file_operations fops = {
32...,
33-.open = open_f,
34+.open = simple_open,
35...
36};
37
38@ openr depends on report @
39identifier open_f != simple_open;
40identifier i, f;
41position p;
42@@
43int open_f@p(struct inode *i, struct file *f)
44{
45(
46if (i->i_private)
47f->private_data = i->i_private;
48|
49f->private_data = i->i_private;
50)
51return 0;
52}
53
54@ has_openr depends on openr @
55identifier fops;
56identifier openr.open_f;
57position p;
58@@
59struct file_operations fops = {
60...,
61.open = open_f@p,
62...
63};
64
65@script:python@
66pf << openr.p;
67ps << has_openr.p;
68@@
69
70coccilib.report.print_report(pf[0],"WARNING opportunity for simple_open, see also structure on line %s"%(ps[0].line))
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index 0586085136d1..52577f052bc1 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -540,35 +540,6 @@ static struct conf_printer header_printer_cb =
540}; 540};
541 541
542/* 542/*
543 * Generate the __enabled_CONFIG_* and __enabled_CONFIG_*_MODULE macros for
544 * use by the IS_{ENABLED,BUILTIN,MODULE} macros. The _MODULE variant is
545 * generated even for booleans so that the IS_ENABLED() macro works.
546 */
547static void
548header_print__enabled_symbol(FILE *fp, struct symbol *sym, const char *value, void *arg)
549{
550
551 switch (sym->type) {
552 case S_BOOLEAN:
553 case S_TRISTATE: {
554 fprintf(fp, "#define __enabled_" CONFIG_ "%s %d\n",
555 sym->name, (*value == 'y'));
556 fprintf(fp, "#define __enabled_" CONFIG_ "%s_MODULE %d\n",
557 sym->name, (*value == 'm'));
558 break;
559 }
560 default:
561 break;
562 }
563}
564
565static struct conf_printer header__enabled_printer_cb =
566{
567 .print_symbol = header_print__enabled_symbol,
568 .print_comment = header_print_comment,
569};
570
571/*
572 * Tristate printer 543 * Tristate printer
573 * 544 *
574 * This printer is used when generating the `include/config/tristate.conf' file. 545 * This printer is used when generating the `include/config/tristate.conf' file.
@@ -949,16 +920,11 @@ int conf_write_autoconf(void)
949 conf_write_heading(out_h, &header_printer_cb, NULL); 920 conf_write_heading(out_h, &header_printer_cb, NULL);
950 921
951 for_all_symbols(i, sym) { 922 for_all_symbols(i, sym) {
952 if (!sym->name)
953 continue;
954
955 sym_calc_value(sym); 923 sym_calc_value(sym);
956 924 if (!(sym->flags & SYMBOL_WRITE) || !sym->name)
957 conf_write_symbol(out_h, sym, &header__enabled_printer_cb, NULL);
958
959 if (!(sym->flags & SYMBOL_WRITE))
960 continue; 925 continue;
961 926
927 /* write symbol to auto.conf, tristate and header files */
962 conf_write_symbol(out, sym, &kconfig_printer_cb, (void *)1); 928 conf_write_symbol(out, sym, &kconfig_printer_cb, (void *)1);
963 929
964 conf_write_symbol(tristate, sym, &tristate_printer_cb, (void *)1); 930 conf_write_symbol(tristate, sym, &tristate_printer_cb, (void *)1);
diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
index 8e730ccc3f2b..44ddaa542db6 100644
--- a/scripts/mod/file2alias.c
+++ b/scripts/mod/file2alias.c
@@ -1100,6 +1100,10 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
1100 if (!sym->st_shndx || get_secindex(info, sym) >= info->num_sections) 1100 if (!sym->st_shndx || get_secindex(info, sym) >= info->num_sections)
1101 return; 1101 return;
1102 1102
1103 /* We're looking for an object */
1104 if (ELF_ST_TYPE(sym->st_info) != STT_OBJECT)
1105 return;
1106
1103 /* All our symbols are of form <prefix>__mod_XXX_device_table. */ 1107 /* All our symbols are of form <prefix>__mod_XXX_device_table. */
1104 name = strstr(symname, "__mod_"); 1108 name = strstr(symname, "__mod_");
1105 if (!name) 1109 if (!name)
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 3f01fd908730..c4e7d1510f9d 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -132,8 +132,10 @@ static struct module *new_module(char *modname)
132 /* strip trailing .o */ 132 /* strip trailing .o */
133 s = strrchr(p, '.'); 133 s = strrchr(p, '.');
134 if (s != NULL) 134 if (s != NULL)
135 if (strcmp(s, ".o") == 0) 135 if (strcmp(s, ".o") == 0) {
136 *s = '\0'; 136 *s = '\0';
137 mod->is_dot_o = 1;
138 }
137 139
138 /* add to list */ 140 /* add to list */
139 mod->name = p; 141 mod->name = p;
@@ -587,7 +589,8 @@ static void handle_modversions(struct module *mod, struct elf_info *info,
587 unsigned int crc; 589 unsigned int crc;
588 enum export export; 590 enum export export;
589 591
590 if (!is_vmlinux(mod->name) && strncmp(symname, "__ksymtab", 9) == 0) 592 if ((!is_vmlinux(mod->name) || mod->is_dot_o) &&
593 strncmp(symname, "__ksymtab", 9) == 0)
591 export = export_from_secname(info, get_secindex(info, sym)); 594 export = export_from_secname(info, get_secindex(info, sym));
592 else 595 else
593 export = export_from_sec(info, get_secindex(info, sym)); 596 export = export_from_sec(info, get_secindex(info, sym));
diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
index 2031119080dc..51207e4d5f8b 100644
--- a/scripts/mod/modpost.h
+++ b/scripts/mod/modpost.h
@@ -113,6 +113,7 @@ struct module {
113 int has_cleanup; 113 int has_cleanup;
114 struct buffer dev_table_buf; 114 struct buffer dev_table_buf;
115 char srcversion[25]; 115 char srcversion[25];
116 int is_dot_o;
116}; 117};
117 118
118struct elf_info { 119struct elf_info {
diff --git a/scripts/tags.sh b/scripts/tags.sh
index 0d6004e20658..cf7b12fee573 100755
--- a/scripts/tags.sh
+++ b/scripts/tags.sh
@@ -254,6 +254,6 @@ case "$1" in
254esac 254esac
255 255
256# Remove structure forward declarations. 256# Remove structure forward declarations.
257if [ -n $remove_structs ]; then 257if [ -n "$remove_structs" ]; then
258 LANG=C sed -i -e '/^\([a-zA-Z_][a-zA-Z0-9_]*\)\t.*\t\/\^struct \1;.*\$\/;"\tx$/d' $1 258 LANG=C sed -i -e '/^\([a-zA-Z_][a-zA-Z0-9_]*\)\t.*\t\/\^struct \1;.*\$\/;"\tx$/d' $1
259fi 259fi
diff --git a/scripts/xz_wrap.sh b/scripts/xz_wrap.sh
index 17a5798c29da..7a2d372f4885 100644
--- a/scripts/xz_wrap.sh
+++ b/scripts/xz_wrap.sh
@@ -12,8 +12,8 @@
12BCJ= 12BCJ=
13LZMA2OPTS= 13LZMA2OPTS=
14 14
15case $ARCH in 15case $SRCARCH in
16 x86|x86_64) BCJ=--x86 ;; 16 x86) BCJ=--x86 ;;
17 powerpc) BCJ=--powerpc ;; 17 powerpc) BCJ=--powerpc ;;
18 ia64) BCJ=--ia64; LZMA2OPTS=pb=4 ;; 18 ia64) BCJ=--ia64; LZMA2OPTS=pb=4 ;;
19 arm) BCJ=--arm ;; 19 arm) BCJ=--arm ;;
diff --git a/security/apparmor/audit.c b/security/apparmor/audit.c
index 5ff67776a5ad..cc3520d39a78 100644
--- a/security/apparmor/audit.c
+++ b/security/apparmor/audit.c
@@ -115,23 +115,23 @@ static void audit_pre(struct audit_buffer *ab, void *ca)
115 115
116 if (aa_g_audit_header) { 116 if (aa_g_audit_header) {
117 audit_log_format(ab, "apparmor="); 117 audit_log_format(ab, "apparmor=");
118 audit_log_string(ab, aa_audit_type[sa->aad.type]); 118 audit_log_string(ab, aa_audit_type[sa->aad->type]);
119 } 119 }
120 120
121 if (sa->aad.op) { 121 if (sa->aad->op) {
122 audit_log_format(ab, " operation="); 122 audit_log_format(ab, " operation=");
123 audit_log_string(ab, op_table[sa->aad.op]); 123 audit_log_string(ab, op_table[sa->aad->op]);
124 } 124 }
125 125
126 if (sa->aad.info) { 126 if (sa->aad->info) {
127 audit_log_format(ab, " info="); 127 audit_log_format(ab, " info=");
128 audit_log_string(ab, sa->aad.info); 128 audit_log_string(ab, sa->aad->info);
129 if (sa->aad.error) 129 if (sa->aad->error)
130 audit_log_format(ab, " error=%d", sa->aad.error); 130 audit_log_format(ab, " error=%d", sa->aad->error);
131 } 131 }
132 132
133 if (sa->aad.profile) { 133 if (sa->aad->profile) {
134 struct aa_profile *profile = sa->aad.profile; 134 struct aa_profile *profile = sa->aad->profile;
135 pid_t pid; 135 pid_t pid;
136 rcu_read_lock(); 136 rcu_read_lock();
137 pid = rcu_dereference(tsk->real_parent)->pid; 137 pid = rcu_dereference(tsk->real_parent)->pid;
@@ -145,9 +145,9 @@ static void audit_pre(struct audit_buffer *ab, void *ca)
145 audit_log_untrustedstring(ab, profile->base.hname); 145 audit_log_untrustedstring(ab, profile->base.hname);
146 } 146 }
147 147
148 if (sa->aad.name) { 148 if (sa->aad->name) {
149 audit_log_format(ab, " name="); 149 audit_log_format(ab, " name=");
150 audit_log_untrustedstring(ab, sa->aad.name); 150 audit_log_untrustedstring(ab, sa->aad->name);
151 } 151 }
152} 152}
153 153
@@ -159,10 +159,8 @@ static void audit_pre(struct audit_buffer *ab, void *ca)
159void aa_audit_msg(int type, struct common_audit_data *sa, 159void aa_audit_msg(int type, struct common_audit_data *sa,
160 void (*cb) (struct audit_buffer *, void *)) 160 void (*cb) (struct audit_buffer *, void *))
161{ 161{
162 sa->aad.type = type; 162 sa->aad->type = type;
163 sa->lsm_pre_audit = audit_pre; 163 common_lsm_audit(sa, audit_pre, cb);
164 sa->lsm_post_audit = cb;
165 common_lsm_audit(sa);
166} 164}
167 165
168/** 166/**
@@ -184,7 +182,7 @@ int aa_audit(int type, struct aa_profile *profile, gfp_t gfp,
184 BUG_ON(!profile); 182 BUG_ON(!profile);
185 183
186 if (type == AUDIT_APPARMOR_AUTO) { 184 if (type == AUDIT_APPARMOR_AUTO) {
187 if (likely(!sa->aad.error)) { 185 if (likely(!sa->aad->error)) {
188 if (AUDIT_MODE(profile) != AUDIT_ALL) 186 if (AUDIT_MODE(profile) != AUDIT_ALL)
189 return 0; 187 return 0;
190 type = AUDIT_APPARMOR_AUDIT; 188 type = AUDIT_APPARMOR_AUDIT;
@@ -196,21 +194,21 @@ int aa_audit(int type, struct aa_profile *profile, gfp_t gfp,
196 if (AUDIT_MODE(profile) == AUDIT_QUIET || 194 if (AUDIT_MODE(profile) == AUDIT_QUIET ||
197 (type == AUDIT_APPARMOR_DENIED && 195 (type == AUDIT_APPARMOR_DENIED &&
198 AUDIT_MODE(profile) == AUDIT_QUIET)) 196 AUDIT_MODE(profile) == AUDIT_QUIET))
199 return sa->aad.error; 197 return sa->aad->error;
200 198
201 if (KILL_MODE(profile) && type == AUDIT_APPARMOR_DENIED) 199 if (KILL_MODE(profile) && type == AUDIT_APPARMOR_DENIED)
202 type = AUDIT_APPARMOR_KILL; 200 type = AUDIT_APPARMOR_KILL;
203 201
204 if (!unconfined(profile)) 202 if (!unconfined(profile))
205 sa->aad.profile = profile; 203 sa->aad->profile = profile;
206 204
207 aa_audit_msg(type, sa, cb); 205 aa_audit_msg(type, sa, cb);
208 206
209 if (sa->aad.type == AUDIT_APPARMOR_KILL) 207 if (sa->aad->type == AUDIT_APPARMOR_KILL)
210 (void)send_sig_info(SIGKILL, NULL, sa->tsk ? sa->tsk : current); 208 (void)send_sig_info(SIGKILL, NULL, sa->tsk ? sa->tsk : current);
211 209
212 if (sa->aad.type == AUDIT_APPARMOR_ALLOWED) 210 if (sa->aad->type == AUDIT_APPARMOR_ALLOWED)
213 return complain_error(sa->aad.error); 211 return complain_error(sa->aad->error);
214 212
215 return sa->aad.error; 213 return sa->aad->error;
216} 214}
diff --git a/security/apparmor/capability.c b/security/apparmor/capability.c
index 9982c48def4e..088dba3bf7dc 100644
--- a/security/apparmor/capability.c
+++ b/security/apparmor/capability.c
@@ -64,11 +64,13 @@ static int audit_caps(struct aa_profile *profile, struct task_struct *task,
64 struct audit_cache *ent; 64 struct audit_cache *ent;
65 int type = AUDIT_APPARMOR_AUTO; 65 int type = AUDIT_APPARMOR_AUTO;
66 struct common_audit_data sa; 66 struct common_audit_data sa;
67 struct apparmor_audit_data aad = {0,};
67 COMMON_AUDIT_DATA_INIT(&sa, CAP); 68 COMMON_AUDIT_DATA_INIT(&sa, CAP);
69 sa.aad = &aad;
68 sa.tsk = task; 70 sa.tsk = task;
69 sa.u.cap = cap; 71 sa.u.cap = cap;
70 sa.aad.op = OP_CAPABLE; 72 sa.aad->op = OP_CAPABLE;
71 sa.aad.error = error; 73 sa.aad->error = error;
72 74
73 if (likely(!error)) { 75 if (likely(!error)) {
74 /* test if auditing is being forced */ 76 /* test if auditing is being forced */
diff --git a/security/apparmor/file.c b/security/apparmor/file.c
index 5d176f2530c9..2f8fcba9ce4b 100644
--- a/security/apparmor/file.c
+++ b/security/apparmor/file.c
@@ -67,22 +67,22 @@ static void file_audit_cb(struct audit_buffer *ab, void *va)
67 struct common_audit_data *sa = va; 67 struct common_audit_data *sa = va;
68 uid_t fsuid = current_fsuid(); 68 uid_t fsuid = current_fsuid();
69 69
70 if (sa->aad.fs.request & AA_AUDIT_FILE_MASK) { 70 if (sa->aad->fs.request & AA_AUDIT_FILE_MASK) {
71 audit_log_format(ab, " requested_mask="); 71 audit_log_format(ab, " requested_mask=");
72 audit_file_mask(ab, sa->aad.fs.request); 72 audit_file_mask(ab, sa->aad->fs.request);
73 } 73 }
74 if (sa->aad.fs.denied & AA_AUDIT_FILE_MASK) { 74 if (sa->aad->fs.denied & AA_AUDIT_FILE_MASK) {
75 audit_log_format(ab, " denied_mask="); 75 audit_log_format(ab, " denied_mask=");
76 audit_file_mask(ab, sa->aad.fs.denied); 76 audit_file_mask(ab, sa->aad->fs.denied);
77 } 77 }
78 if (sa->aad.fs.request & AA_AUDIT_FILE_MASK) { 78 if (sa->aad->fs.request & AA_AUDIT_FILE_MASK) {
79 audit_log_format(ab, " fsuid=%d", fsuid); 79 audit_log_format(ab, " fsuid=%d", fsuid);
80 audit_log_format(ab, " ouid=%d", sa->aad.fs.ouid); 80 audit_log_format(ab, " ouid=%d", sa->aad->fs.ouid);
81 } 81 }
82 82
83 if (sa->aad.fs.target) { 83 if (sa->aad->fs.target) {
84 audit_log_format(ab, " target="); 84 audit_log_format(ab, " target=");
85 audit_log_untrustedstring(ab, sa->aad.fs.target); 85 audit_log_untrustedstring(ab, sa->aad->fs.target);
86 } 86 }
87} 87}
88 88
@@ -107,45 +107,47 @@ int aa_audit_file(struct aa_profile *profile, struct file_perms *perms,
107{ 107{
108 int type = AUDIT_APPARMOR_AUTO; 108 int type = AUDIT_APPARMOR_AUTO;
109 struct common_audit_data sa; 109 struct common_audit_data sa;
110 struct apparmor_audit_data aad = {0,};
110 COMMON_AUDIT_DATA_INIT(&sa, NONE); 111 COMMON_AUDIT_DATA_INIT(&sa, NONE);
111 sa.aad.op = op, 112 sa.aad = &aad;
112 sa.aad.fs.request = request; 113 aad.op = op,
113 sa.aad.name = name; 114 aad.fs.request = request;
114 sa.aad.fs.target = target; 115 aad.name = name;
115 sa.aad.fs.ouid = ouid; 116 aad.fs.target = target;
116 sa.aad.info = info; 117 aad.fs.ouid = ouid;
117 sa.aad.error = error; 118 aad.info = info;
118 119 aad.error = error;
119 if (likely(!sa.aad.error)) { 120
121 if (likely(!sa.aad->error)) {
120 u32 mask = perms->audit; 122 u32 mask = perms->audit;
121 123
122 if (unlikely(AUDIT_MODE(profile) == AUDIT_ALL)) 124 if (unlikely(AUDIT_MODE(profile) == AUDIT_ALL))
123 mask = 0xffff; 125 mask = 0xffff;
124 126
125 /* mask off perms that are not being force audited */ 127 /* mask off perms that are not being force audited */
126 sa.aad.fs.request &= mask; 128 sa.aad->fs.request &= mask;
127 129
128 if (likely(!sa.aad.fs.request)) 130 if (likely(!sa.aad->fs.request))
129 return 0; 131 return 0;
130 type = AUDIT_APPARMOR_AUDIT; 132 type = AUDIT_APPARMOR_AUDIT;
131 } else { 133 } else {
132 /* only report permissions that were denied */ 134 /* only report permissions that were denied */
133 sa.aad.fs.request = sa.aad.fs.request & ~perms->allow; 135 sa.aad->fs.request = sa.aad->fs.request & ~perms->allow;
134 136
135 if (sa.aad.fs.request & perms->kill) 137 if (sa.aad->fs.request & perms->kill)
136 type = AUDIT_APPARMOR_KILL; 138 type = AUDIT_APPARMOR_KILL;
137 139
138 /* quiet known rejects, assumes quiet and kill do not overlap */ 140 /* quiet known rejects, assumes quiet and kill do not overlap */
139 if ((sa.aad.fs.request & perms->quiet) && 141 if ((sa.aad->fs.request & perms->quiet) &&
140 AUDIT_MODE(profile) != AUDIT_NOQUIET && 142 AUDIT_MODE(profile) != AUDIT_NOQUIET &&
141 AUDIT_MODE(profile) != AUDIT_ALL) 143 AUDIT_MODE(profile) != AUDIT_ALL)
142 sa.aad.fs.request &= ~perms->quiet; 144 sa.aad->fs.request &= ~perms->quiet;
143 145
144 if (!sa.aad.fs.request) 146 if (!sa.aad->fs.request)
145 return COMPLAIN_MODE(profile) ? 0 : sa.aad.error; 147 return COMPLAIN_MODE(profile) ? 0 : sa.aad->error;
146 } 148 }
147 149
148 sa.aad.fs.denied = sa.aad.fs.request & ~perms->allow; 150 sa.aad->fs.denied = sa.aad->fs.request & ~perms->allow;
149 return aa_audit(type, profile, gfp, &sa, file_audit_cb); 151 return aa_audit(type, profile, gfp, &sa, file_audit_cb);
150} 152}
151 153
diff --git a/security/apparmor/include/audit.h b/security/apparmor/include/audit.h
index 4ba78c203af1..3868b1e5d5ba 100644
--- a/security/apparmor/include/audit.h
+++ b/security/apparmor/include/audit.h
@@ -103,7 +103,33 @@ enum aa_ops {
103}; 103};
104 104
105 105
106/* define a short hand for apparmor_audit_data portion of common_audit_data */ 106struct apparmor_audit_data {
107 int error;
108 int op;
109 int type;
110 void *profile;
111 const char *name;
112 const char *info;
113 union {
114 void *target;
115 struct {
116 long pos;
117 void *target;
118 } iface;
119 struct {
120 int rlim;
121 unsigned long max;
122 } rlim;
123 struct {
124 const char *target;
125 u32 request;
126 u32 denied;
127 uid_t ouid;
128 } fs;
129 };
130};
131
132/* define a short hand for apparmor_audit_data structure */
107#define aad apparmor_audit_data 133#define aad apparmor_audit_data
108 134
109void aa_audit_msg(int type, struct common_audit_data *sa, 135void aa_audit_msg(int type, struct common_audit_data *sa,
diff --git a/security/apparmor/ipc.c b/security/apparmor/ipc.c
index 7ee05c6f3c64..c3da93a5150d 100644
--- a/security/apparmor/ipc.c
+++ b/security/apparmor/ipc.c
@@ -26,7 +26,7 @@ static void audit_cb(struct audit_buffer *ab, void *va)
26{ 26{
27 struct common_audit_data *sa = va; 27 struct common_audit_data *sa = va;
28 audit_log_format(ab, " target="); 28 audit_log_format(ab, " target=");
29 audit_log_untrustedstring(ab, sa->aad.target); 29 audit_log_untrustedstring(ab, sa->aad->target);
30} 30}
31 31
32/** 32/**
@@ -41,10 +41,12 @@ static int aa_audit_ptrace(struct aa_profile *profile,
41 struct aa_profile *target, int error) 41 struct aa_profile *target, int error)
42{ 42{
43 struct common_audit_data sa; 43 struct common_audit_data sa;
44 struct apparmor_audit_data aad = {0,};
44 COMMON_AUDIT_DATA_INIT(&sa, NONE); 45 COMMON_AUDIT_DATA_INIT(&sa, NONE);
45 sa.aad.op = OP_PTRACE; 46 sa.aad = &aad;
46 sa.aad.target = target; 47 aad.op = OP_PTRACE;
47 sa.aad.error = error; 48 aad.target = target;
49 aad.error = error;
48 50
49 return aa_audit(AUDIT_APPARMOR_AUTO, profile, GFP_ATOMIC, &sa, 51 return aa_audit(AUDIT_APPARMOR_AUTO, profile, GFP_ATOMIC, &sa,
50 audit_cb); 52 audit_cb);
diff --git a/security/apparmor/lib.c b/security/apparmor/lib.c
index 9516948041ad..e75829ba0ff9 100644
--- a/security/apparmor/lib.c
+++ b/security/apparmor/lib.c
@@ -65,8 +65,10 @@ void aa_info_message(const char *str)
65{ 65{
66 if (audit_enabled) { 66 if (audit_enabled) {
67 struct common_audit_data sa; 67 struct common_audit_data sa;
68 struct apparmor_audit_data aad = {0,};
68 COMMON_AUDIT_DATA_INIT(&sa, NONE); 69 COMMON_AUDIT_DATA_INIT(&sa, NONE);
69 sa.aad.info = str; 70 sa.aad = &aad;
71 aad.info = str;
70 aa_audit_msg(AUDIT_APPARMOR_STATUS, &sa, NULL); 72 aa_audit_msg(AUDIT_APPARMOR_STATUS, &sa, NULL);
71 } 73 }
72 printk(KERN_INFO "AppArmor: %s\n", str); 74 printk(KERN_INFO "AppArmor: %s\n", str);
diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
index 97ce8fae49b3..ad05d391974d 100644
--- a/security/apparmor/lsm.c
+++ b/security/apparmor/lsm.c
@@ -588,10 +588,12 @@ static int apparmor_setprocattr(struct task_struct *task, char *name,
588 error = aa_setprocattr_permipc(args); 588 error = aa_setprocattr_permipc(args);
589 } else { 589 } else {
590 struct common_audit_data sa; 590 struct common_audit_data sa;
591 struct apparmor_audit_data aad = {0,};
591 COMMON_AUDIT_DATA_INIT(&sa, NONE); 592 COMMON_AUDIT_DATA_INIT(&sa, NONE);
592 sa.aad.op = OP_SETPROCATTR; 593 sa.aad = &aad;
593 sa.aad.info = name; 594 aad.op = OP_SETPROCATTR;
594 sa.aad.error = -EINVAL; 595 aad.info = name;
596 aad.error = -EINVAL;
595 return aa_audit(AUDIT_APPARMOR_DENIED, 597 return aa_audit(AUDIT_APPARMOR_DENIED,
596 __aa_current_profile(), GFP_KERNEL, 598 __aa_current_profile(), GFP_KERNEL,
597 &sa, NULL); 599 &sa, NULL);
diff --git a/security/apparmor/policy.c b/security/apparmor/policy.c
index 906414383022..f1f7506a464d 100644
--- a/security/apparmor/policy.c
+++ b/security/apparmor/policy.c
@@ -964,11 +964,13 @@ static int audit_policy(int op, gfp_t gfp, const char *name, const char *info,
964 int error) 964 int error)
965{ 965{
966 struct common_audit_data sa; 966 struct common_audit_data sa;
967 struct apparmor_audit_data aad = {0,};
967 COMMON_AUDIT_DATA_INIT(&sa, NONE); 968 COMMON_AUDIT_DATA_INIT(&sa, NONE);
968 sa.aad.op = op; 969 sa.aad = &aad;
969 sa.aad.name = name; 970 aad.op = op;
970 sa.aad.info = info; 971 aad.name = name;
971 sa.aad.error = error; 972 aad.info = info;
973 aad.error = error;
972 974
973 return aa_audit(AUDIT_APPARMOR_STATUS, __aa_current_profile(), gfp, 975 return aa_audit(AUDIT_APPARMOR_STATUS, __aa_current_profile(), gfp,
974 &sa, NULL); 976 &sa, NULL);
diff --git a/security/apparmor/policy_unpack.c b/security/apparmor/policy_unpack.c
index 25fd51edc8da..deab7c7e8dc0 100644
--- a/security/apparmor/policy_unpack.c
+++ b/security/apparmor/policy_unpack.c
@@ -70,13 +70,13 @@ struct aa_ext {
70static void audit_cb(struct audit_buffer *ab, void *va) 70static void audit_cb(struct audit_buffer *ab, void *va)
71{ 71{
72 struct common_audit_data *sa = va; 72 struct common_audit_data *sa = va;
73 if (sa->aad.iface.target) { 73 if (sa->aad->iface.target) {
74 struct aa_profile *name = sa->aad.iface.target; 74 struct aa_profile *name = sa->aad->iface.target;
75 audit_log_format(ab, " name="); 75 audit_log_format(ab, " name=");
76 audit_log_untrustedstring(ab, name->base.hname); 76 audit_log_untrustedstring(ab, name->base.hname);
77 } 77 }
78 if (sa->aad.iface.pos) 78 if (sa->aad->iface.pos)
79 audit_log_format(ab, " offset=%ld", sa->aad.iface.pos); 79 audit_log_format(ab, " offset=%ld", sa->aad->iface.pos);
80} 80}
81 81
82/** 82/**
@@ -94,13 +94,15 @@ static int audit_iface(struct aa_profile *new, const char *name,
94{ 94{
95 struct aa_profile *profile = __aa_current_profile(); 95 struct aa_profile *profile = __aa_current_profile();
96 struct common_audit_data sa; 96 struct common_audit_data sa;
97 struct apparmor_audit_data aad = {0,};
97 COMMON_AUDIT_DATA_INIT(&sa, NONE); 98 COMMON_AUDIT_DATA_INIT(&sa, NONE);
99 sa.aad = &aad;
98 if (e) 100 if (e)
99 sa.aad.iface.pos = e->pos - e->start; 101 aad.iface.pos = e->pos - e->start;
100 sa.aad.iface.target = new; 102 aad.iface.target = new;
101 sa.aad.name = name; 103 aad.name = name;
102 sa.aad.info = info; 104 aad.info = info;
103 sa.aad.error = error; 105 aad.error = error;
104 106
105 return aa_audit(AUDIT_APPARMOR_STATUS, profile, GFP_KERNEL, &sa, 107 return aa_audit(AUDIT_APPARMOR_STATUS, profile, GFP_KERNEL, &sa,
106 audit_cb); 108 audit_cb);
diff --git a/security/apparmor/resource.c b/security/apparmor/resource.c
index 72c25a4f2cfd..2fe8613efe33 100644
--- a/security/apparmor/resource.c
+++ b/security/apparmor/resource.c
@@ -34,7 +34,7 @@ static void audit_cb(struct audit_buffer *ab, void *va)
34 struct common_audit_data *sa = va; 34 struct common_audit_data *sa = va;
35 35
36 audit_log_format(ab, " rlimit=%s value=%lu", 36 audit_log_format(ab, " rlimit=%s value=%lu",
37 rlim_names[sa->aad.rlim.rlim], sa->aad.rlim.max); 37 rlim_names[sa->aad->rlim.rlim], sa->aad->rlim.max);
38} 38}
39 39
40/** 40/**
@@ -50,12 +50,14 @@ static int audit_resource(struct aa_profile *profile, unsigned int resource,
50 unsigned long value, int error) 50 unsigned long value, int error)
51{ 51{
52 struct common_audit_data sa; 52 struct common_audit_data sa;
53 struct apparmor_audit_data aad = {0,};
53 54
54 COMMON_AUDIT_DATA_INIT(&sa, NONE); 55 COMMON_AUDIT_DATA_INIT(&sa, NONE);
55 sa.aad.op = OP_SETRLIMIT, 56 sa.aad = &aad;
56 sa.aad.rlim.rlim = resource; 57 aad.op = OP_SETRLIMIT,
57 sa.aad.rlim.max = value; 58 aad.rlim.rlim = resource;
58 sa.aad.error = error; 59 aad.rlim.max = value;
60 aad.error = error;
59 return aa_audit(AUDIT_APPARMOR_AUTO, profile, GFP_KERNEL, &sa, 61 return aa_audit(AUDIT_APPARMOR_AUTO, profile, GFP_KERNEL, &sa,
60 audit_cb); 62 audit_cb);
61} 63}
diff --git a/security/commoncap.c b/security/commoncap.c
index 0cf4b53480a7..71a166a05975 100644
--- a/security/commoncap.c
+++ b/security/commoncap.c
@@ -29,6 +29,7 @@
29#include <linux/securebits.h> 29#include <linux/securebits.h>
30#include <linux/user_namespace.h> 30#include <linux/user_namespace.h>
31#include <linux/binfmts.h> 31#include <linux/binfmts.h>
32#include <linux/personality.h>
32 33
33/* 34/*
34 * If a non-root user executes a setuid-root binary in 35 * If a non-root user executes a setuid-root binary in
@@ -505,6 +506,11 @@ int cap_bprm_set_creds(struct linux_binprm *bprm)
505 } 506 }
506skip: 507skip:
507 508
509 /* if we have fs caps, clear dangerous personality flags */
510 if (!cap_issubset(new->cap_permitted, old->cap_permitted))
511 bprm->per_clear |= PER_CLEAR_ON_SETID;
512
513
508 /* Don't let someone trace a set[ug]id/setpcap binary with the revised 514 /* Don't let someone trace a set[ug]id/setpcap binary with the revised
509 * credentials unless they have the appropriate permit 515 * credentials unless they have the appropriate permit
510 */ 516 */
diff --git a/security/lsm_audit.c b/security/lsm_audit.c
index 8b8f0902f6e5..90c129b0102f 100644
--- a/security/lsm_audit.c
+++ b/security/lsm_audit.c
@@ -49,8 +49,8 @@ int ipv4_skb_to_auditdata(struct sk_buff *skb,
49 if (ih == NULL) 49 if (ih == NULL)
50 return -EINVAL; 50 return -EINVAL;
51 51
52 ad->u.net.v4info.saddr = ih->saddr; 52 ad->u.net->v4info.saddr = ih->saddr;
53 ad->u.net.v4info.daddr = ih->daddr; 53 ad->u.net->v4info.daddr = ih->daddr;
54 54
55 if (proto) 55 if (proto)
56 *proto = ih->protocol; 56 *proto = ih->protocol;
@@ -64,8 +64,8 @@ int ipv4_skb_to_auditdata(struct sk_buff *skb,
64 if (th == NULL) 64 if (th == NULL)
65 break; 65 break;
66 66
67 ad->u.net.sport = th->source; 67 ad->u.net->sport = th->source;
68 ad->u.net.dport = th->dest; 68 ad->u.net->dport = th->dest;
69 break; 69 break;
70 } 70 }
71 case IPPROTO_UDP: { 71 case IPPROTO_UDP: {
@@ -73,8 +73,8 @@ int ipv4_skb_to_auditdata(struct sk_buff *skb,
73 if (uh == NULL) 73 if (uh == NULL)
74 break; 74 break;
75 75
76 ad->u.net.sport = uh->source; 76 ad->u.net->sport = uh->source;
77 ad->u.net.dport = uh->dest; 77 ad->u.net->dport = uh->dest;
78 break; 78 break;
79 } 79 }
80 case IPPROTO_DCCP: { 80 case IPPROTO_DCCP: {
@@ -82,16 +82,16 @@ int ipv4_skb_to_auditdata(struct sk_buff *skb,
82 if (dh == NULL) 82 if (dh == NULL)
83 break; 83 break;
84 84
85 ad->u.net.sport = dh->dccph_sport; 85 ad->u.net->sport = dh->dccph_sport;
86 ad->u.net.dport = dh->dccph_dport; 86 ad->u.net->dport = dh->dccph_dport;
87 break; 87 break;
88 } 88 }
89 case IPPROTO_SCTP: { 89 case IPPROTO_SCTP: {
90 struct sctphdr *sh = sctp_hdr(skb); 90 struct sctphdr *sh = sctp_hdr(skb);
91 if (sh == NULL) 91 if (sh == NULL)
92 break; 92 break;
93 ad->u.net.sport = sh->source; 93 ad->u.net->sport = sh->source;
94 ad->u.net.dport = sh->dest; 94 ad->u.net->dport = sh->dest;
95 break; 95 break;
96 } 96 }
97 default: 97 default:
@@ -119,8 +119,8 @@ int ipv6_skb_to_auditdata(struct sk_buff *skb,
119 ip6 = ipv6_hdr(skb); 119 ip6 = ipv6_hdr(skb);
120 if (ip6 == NULL) 120 if (ip6 == NULL)
121 return -EINVAL; 121 return -EINVAL;
122 ad->u.net.v6info.saddr = ip6->saddr; 122 ad->u.net->v6info.saddr = ip6->saddr;
123 ad->u.net.v6info.daddr = ip6->daddr; 123 ad->u.net->v6info.daddr = ip6->daddr;
124 ret = 0; 124 ret = 0;
125 /* IPv6 can have several extension header before the Transport header 125 /* IPv6 can have several extension header before the Transport header
126 * skip them */ 126 * skip them */
@@ -140,8 +140,8 @@ int ipv6_skb_to_auditdata(struct sk_buff *skb,
140 if (th == NULL) 140 if (th == NULL)
141 break; 141 break;
142 142
143 ad->u.net.sport = th->source; 143 ad->u.net->sport = th->source;
144 ad->u.net.dport = th->dest; 144 ad->u.net->dport = th->dest;
145 break; 145 break;
146 } 146 }
147 case IPPROTO_UDP: { 147 case IPPROTO_UDP: {
@@ -151,8 +151,8 @@ int ipv6_skb_to_auditdata(struct sk_buff *skb,
151 if (uh == NULL) 151 if (uh == NULL)
152 break; 152 break;
153 153
154 ad->u.net.sport = uh->source; 154 ad->u.net->sport = uh->source;
155 ad->u.net.dport = uh->dest; 155 ad->u.net->dport = uh->dest;
156 break; 156 break;
157 } 157 }
158 case IPPROTO_DCCP: { 158 case IPPROTO_DCCP: {
@@ -162,8 +162,8 @@ int ipv6_skb_to_auditdata(struct sk_buff *skb,
162 if (dh == NULL) 162 if (dh == NULL)
163 break; 163 break;
164 164
165 ad->u.net.sport = dh->dccph_sport; 165 ad->u.net->sport = dh->dccph_sport;
166 ad->u.net.dport = dh->dccph_dport; 166 ad->u.net->dport = dh->dccph_dport;
167 break; 167 break;
168 } 168 }
169 case IPPROTO_SCTP: { 169 case IPPROTO_SCTP: {
@@ -172,8 +172,8 @@ int ipv6_skb_to_auditdata(struct sk_buff *skb,
172 sh = skb_header_pointer(skb, offset, sizeof(_sctph), &_sctph); 172 sh = skb_header_pointer(skb, offset, sizeof(_sctph), &_sctph);
173 if (sh == NULL) 173 if (sh == NULL)
174 break; 174 break;
175 ad->u.net.sport = sh->source; 175 ad->u.net->sport = sh->source;
176 ad->u.net.dport = sh->dest; 176 ad->u.net->dport = sh->dest;
177 break; 177 break;
178 } 178 }
179 default: 179 default:
@@ -281,8 +281,8 @@ static void dump_common_audit_data(struct audit_buffer *ab,
281 } 281 }
282 break; 282 break;
283 case LSM_AUDIT_DATA_NET: 283 case LSM_AUDIT_DATA_NET:
284 if (a->u.net.sk) { 284 if (a->u.net->sk) {
285 struct sock *sk = a->u.net.sk; 285 struct sock *sk = a->u.net->sk;
286 struct unix_sock *u; 286 struct unix_sock *u;
287 int len = 0; 287 int len = 0;
288 char *p = NULL; 288 char *p = NULL;
@@ -330,29 +330,29 @@ static void dump_common_audit_data(struct audit_buffer *ab,
330 } 330 }
331 } 331 }
332 332
333 switch (a->u.net.family) { 333 switch (a->u.net->family) {
334 case AF_INET: 334 case AF_INET:
335 print_ipv4_addr(ab, a->u.net.v4info.saddr, 335 print_ipv4_addr(ab, a->u.net->v4info.saddr,
336 a->u.net.sport, 336 a->u.net->sport,
337 "saddr", "src"); 337 "saddr", "src");
338 print_ipv4_addr(ab, a->u.net.v4info.daddr, 338 print_ipv4_addr(ab, a->u.net->v4info.daddr,
339 a->u.net.dport, 339 a->u.net->dport,
340 "daddr", "dest"); 340 "daddr", "dest");
341 break; 341 break;
342 case AF_INET6: 342 case AF_INET6:
343 print_ipv6_addr(ab, &a->u.net.v6info.saddr, 343 print_ipv6_addr(ab, &a->u.net->v6info.saddr,
344 a->u.net.sport, 344 a->u.net->sport,
345 "saddr", "src"); 345 "saddr", "src");
346 print_ipv6_addr(ab, &a->u.net.v6info.daddr, 346 print_ipv6_addr(ab, &a->u.net->v6info.daddr,
347 a->u.net.dport, 347 a->u.net->dport,
348 "daddr", "dest"); 348 "daddr", "dest");
349 break; 349 break;
350 } 350 }
351 if (a->u.net.netif > 0) { 351 if (a->u.net->netif > 0) {
352 struct net_device *dev; 352 struct net_device *dev;
353 353
354 /* NOTE: we always use init's namespace */ 354 /* NOTE: we always use init's namespace */
355 dev = dev_get_by_index(&init_net, a->u.net.netif); 355 dev = dev_get_by_index(&init_net, a->u.net->netif);
356 if (dev) { 356 if (dev) {
357 audit_log_format(ab, " netif=%s", dev->name); 357 audit_log_format(ab, " netif=%s", dev->name);
358 dev_put(dev); 358 dev_put(dev);
@@ -378,11 +378,15 @@ static void dump_common_audit_data(struct audit_buffer *ab,
378/** 378/**
379 * common_lsm_audit - generic LSM auditing function 379 * common_lsm_audit - generic LSM auditing function
380 * @a: auxiliary audit data 380 * @a: auxiliary audit data
381 * @pre_audit: lsm-specific pre-audit callback
382 * @post_audit: lsm-specific post-audit callback
381 * 383 *
382 * setup the audit buffer for common security information 384 * setup the audit buffer for common security information
383 * uses callback to print LSM specific information 385 * uses callback to print LSM specific information
384 */ 386 */
385void common_lsm_audit(struct common_audit_data *a) 387void common_lsm_audit(struct common_audit_data *a,
388 void (*pre_audit)(struct audit_buffer *, void *),
389 void (*post_audit)(struct audit_buffer *, void *))
386{ 390{
387 struct audit_buffer *ab; 391 struct audit_buffer *ab;
388 392
@@ -394,13 +398,13 @@ void common_lsm_audit(struct common_audit_data *a)
394 if (ab == NULL) 398 if (ab == NULL)
395 return; 399 return;
396 400
397 if (a->lsm_pre_audit) 401 if (pre_audit)
398 a->lsm_pre_audit(ab, a); 402 pre_audit(ab, a);
399 403
400 dump_common_audit_data(ab, a); 404 dump_common_audit_data(ab, a);
401 405
402 if (a->lsm_post_audit) 406 if (post_audit)
403 a->lsm_post_audit(ab, a); 407 post_audit(ab, a);
404 408
405 audit_log_end(ab); 409 audit_log_end(ab);
406} 410}
diff --git a/security/selinux/avc.c b/security/selinux/avc.c
index 1a70fa26da72..8ee42b2a5f19 100644
--- a/security/selinux/avc.c
+++ b/security/selinux/avc.c
@@ -436,9 +436,9 @@ static void avc_audit_pre_callback(struct audit_buffer *ab, void *a)
436{ 436{
437 struct common_audit_data *ad = a; 437 struct common_audit_data *ad = a;
438 audit_log_format(ab, "avc: %s ", 438 audit_log_format(ab, "avc: %s ",
439 ad->selinux_audit_data.denied ? "denied" : "granted"); 439 ad->selinux_audit_data->slad->denied ? "denied" : "granted");
440 avc_dump_av(ab, ad->selinux_audit_data.tclass, 440 avc_dump_av(ab, ad->selinux_audit_data->slad->tclass,
441 ad->selinux_audit_data.audited); 441 ad->selinux_audit_data->slad->audited);
442 audit_log_format(ab, " for "); 442 audit_log_format(ab, " for ");
443} 443}
444 444
@@ -452,22 +452,25 @@ static void avc_audit_post_callback(struct audit_buffer *ab, void *a)
452{ 452{
453 struct common_audit_data *ad = a; 453 struct common_audit_data *ad = a;
454 audit_log_format(ab, " "); 454 audit_log_format(ab, " ");
455 avc_dump_query(ab, ad->selinux_audit_data.ssid, 455 avc_dump_query(ab, ad->selinux_audit_data->slad->ssid,
456 ad->selinux_audit_data.tsid, 456 ad->selinux_audit_data->slad->tsid,
457 ad->selinux_audit_data.tclass); 457 ad->selinux_audit_data->slad->tclass);
458} 458}
459 459
460/* This is the slow part of avc audit with big stack footprint */ 460/* This is the slow part of avc audit with big stack footprint */
461static noinline int slow_avc_audit(u32 ssid, u32 tsid, u16 tclass, 461static noinline int slow_avc_audit(u32 ssid, u32 tsid, u16 tclass,
462 u32 requested, u32 audited, u32 denied, 462 u32 requested, u32 audited, u32 denied,
463 struct av_decision *avd, struct common_audit_data *a, 463 struct common_audit_data *a,
464 unsigned flags) 464 unsigned flags)
465{ 465{
466 struct common_audit_data stack_data; 466 struct common_audit_data stack_data;
467 struct selinux_audit_data sad = {0,};
468 struct selinux_late_audit_data slad;
467 469
468 if (!a) { 470 if (!a) {
469 a = &stack_data; 471 a = &stack_data;
470 COMMON_AUDIT_DATA_INIT(a, NONE); 472 COMMON_AUDIT_DATA_INIT(a, NONE);
473 a->selinux_audit_data = &sad;
471 } 474 }
472 475
473 /* 476 /*
@@ -481,15 +484,15 @@ static noinline int slow_avc_audit(u32 ssid, u32 tsid, u16 tclass,
481 (flags & MAY_NOT_BLOCK)) 484 (flags & MAY_NOT_BLOCK))
482 return -ECHILD; 485 return -ECHILD;
483 486
484 a->selinux_audit_data.tclass = tclass; 487 slad.tclass = tclass;
485 a->selinux_audit_data.requested = requested; 488 slad.requested = requested;
486 a->selinux_audit_data.ssid = ssid; 489 slad.ssid = ssid;
487 a->selinux_audit_data.tsid = tsid; 490 slad.tsid = tsid;
488 a->selinux_audit_data.audited = audited; 491 slad.audited = audited;
489 a->selinux_audit_data.denied = denied; 492 slad.denied = denied;
490 a->lsm_pre_audit = avc_audit_pre_callback; 493
491 a->lsm_post_audit = avc_audit_post_callback; 494 a->selinux_audit_data->slad = &slad;
492 common_lsm_audit(a); 495 common_lsm_audit(a, avc_audit_pre_callback, avc_audit_post_callback);
493 return 0; 496 return 0;
494} 497}
495 498
@@ -523,7 +526,7 @@ inline int avc_audit(u32 ssid, u32 tsid,
523 if (unlikely(denied)) { 526 if (unlikely(denied)) {
524 audited = denied & avd->auditdeny; 527 audited = denied & avd->auditdeny;
525 /* 528 /*
526 * a->selinux_audit_data.auditdeny is TRICKY! Setting a bit in 529 * a->selinux_audit_data->auditdeny is TRICKY! Setting a bit in
527 * this field means that ANY denials should NOT be audited if 530 * this field means that ANY denials should NOT be audited if
528 * the policy contains an explicit dontaudit rule for that 531 * the policy contains an explicit dontaudit rule for that
529 * permission. Take notice that this is unrelated to the 532 * permission. Take notice that this is unrelated to the
@@ -532,15 +535,15 @@ inline int avc_audit(u32 ssid, u32 tsid,
532 * 535 *
533 * denied == READ 536 * denied == READ
534 * avd.auditdeny & ACCESS == 0 (not set means explicit rule) 537 * avd.auditdeny & ACCESS == 0 (not set means explicit rule)
535 * selinux_audit_data.auditdeny & ACCESS == 1 538 * selinux_audit_data->auditdeny & ACCESS == 1
536 * 539 *
537 * We will NOT audit the denial even though the denied 540 * We will NOT audit the denial even though the denied
538 * permission was READ and the auditdeny checks were for 541 * permission was READ and the auditdeny checks were for
539 * ACCESS 542 * ACCESS
540 */ 543 */
541 if (a && 544 if (a &&
542 a->selinux_audit_data.auditdeny && 545 a->selinux_audit_data->auditdeny &&
543 !(a->selinux_audit_data.auditdeny & avd->auditdeny)) 546 !(a->selinux_audit_data->auditdeny & avd->auditdeny))
544 audited = 0; 547 audited = 0;
545 } else if (result) 548 } else if (result)
546 audited = denied = requested; 549 audited = denied = requested;
@@ -551,7 +554,7 @@ inline int avc_audit(u32 ssid, u32 tsid,
551 554
552 return slow_avc_audit(ssid, tsid, tclass, 555 return slow_avc_audit(ssid, tsid, tclass,
553 requested, audited, denied, 556 requested, audited, denied,
554 avd, a, flags); 557 a, flags);
555} 558}
556 559
557/** 560/**
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 28482f9e15b8..d85b793c9321 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -1420,6 +1420,7 @@ static int cred_has_capability(const struct cred *cred,
1420 int cap, int audit) 1420 int cap, int audit)
1421{ 1421{
1422 struct common_audit_data ad; 1422 struct common_audit_data ad;
1423 struct selinux_audit_data sad = {0,};
1423 struct av_decision avd; 1424 struct av_decision avd;
1424 u16 sclass; 1425 u16 sclass;
1425 u32 sid = cred_sid(cred); 1426 u32 sid = cred_sid(cred);
@@ -1427,6 +1428,7 @@ static int cred_has_capability(const struct cred *cred,
1427 int rc; 1428 int rc;
1428 1429
1429 COMMON_AUDIT_DATA_INIT(&ad, CAP); 1430 COMMON_AUDIT_DATA_INIT(&ad, CAP);
1431 ad.selinux_audit_data = &sad;
1430 ad.tsk = current; 1432 ad.tsk = current;
1431 ad.u.cap = cap; 1433 ad.u.cap = cap;
1432 1434
@@ -1492,9 +1494,11 @@ static int inode_has_perm_noadp(const struct cred *cred,
1492 unsigned flags) 1494 unsigned flags)
1493{ 1495{
1494 struct common_audit_data ad; 1496 struct common_audit_data ad;
1497 struct selinux_audit_data sad = {0,};
1495 1498
1496 COMMON_AUDIT_DATA_INIT(&ad, INODE); 1499 COMMON_AUDIT_DATA_INIT(&ad, INODE);
1497 ad.u.inode = inode; 1500 ad.u.inode = inode;
1501 ad.selinux_audit_data = &sad;
1498 return inode_has_perm(cred, inode, perms, &ad, flags); 1502 return inode_has_perm(cred, inode, perms, &ad, flags);
1499} 1503}
1500 1504
@@ -1507,9 +1511,11 @@ static inline int dentry_has_perm(const struct cred *cred,
1507{ 1511{
1508 struct inode *inode = dentry->d_inode; 1512 struct inode *inode = dentry->d_inode;
1509 struct common_audit_data ad; 1513 struct common_audit_data ad;
1514 struct selinux_audit_data sad = {0,};
1510 1515
1511 COMMON_AUDIT_DATA_INIT(&ad, DENTRY); 1516 COMMON_AUDIT_DATA_INIT(&ad, DENTRY);
1512 ad.u.dentry = dentry; 1517 ad.u.dentry = dentry;
1518 ad.selinux_audit_data = &sad;
1513 return inode_has_perm(cred, inode, av, &ad, 0); 1519 return inode_has_perm(cred, inode, av, &ad, 0);
1514} 1520}
1515 1521
@@ -1522,9 +1528,11 @@ static inline int path_has_perm(const struct cred *cred,
1522{ 1528{
1523 struct inode *inode = path->dentry->d_inode; 1529 struct inode *inode = path->dentry->d_inode;
1524 struct common_audit_data ad; 1530 struct common_audit_data ad;
1531 struct selinux_audit_data sad = {0,};
1525 1532
1526 COMMON_AUDIT_DATA_INIT(&ad, PATH); 1533 COMMON_AUDIT_DATA_INIT(&ad, PATH);
1527 ad.u.path = *path; 1534 ad.u.path = *path;
1535 ad.selinux_audit_data = &sad;
1528 return inode_has_perm(cred, inode, av, &ad, 0); 1536 return inode_has_perm(cred, inode, av, &ad, 0);
1529} 1537}
1530 1538
@@ -1543,11 +1551,13 @@ static int file_has_perm(const struct cred *cred,
1543 struct file_security_struct *fsec = file->f_security; 1551 struct file_security_struct *fsec = file->f_security;
1544 struct inode *inode = file->f_path.dentry->d_inode; 1552 struct inode *inode = file->f_path.dentry->d_inode;
1545 struct common_audit_data ad; 1553 struct common_audit_data ad;
1554 struct selinux_audit_data sad = {0,};
1546 u32 sid = cred_sid(cred); 1555 u32 sid = cred_sid(cred);
1547 int rc; 1556 int rc;
1548 1557
1549 COMMON_AUDIT_DATA_INIT(&ad, PATH); 1558 COMMON_AUDIT_DATA_INIT(&ad, PATH);
1550 ad.u.path = file->f_path; 1559 ad.u.path = file->f_path;
1560 ad.selinux_audit_data = &sad;
1551 1561
1552 if (sid != fsec->sid) { 1562 if (sid != fsec->sid) {
1553 rc = avc_has_perm(sid, fsec->sid, 1563 rc = avc_has_perm(sid, fsec->sid,
@@ -1577,6 +1587,7 @@ static int may_create(struct inode *dir,
1577 struct superblock_security_struct *sbsec; 1587 struct superblock_security_struct *sbsec;
1578 u32 sid, newsid; 1588 u32 sid, newsid;
1579 struct common_audit_data ad; 1589 struct common_audit_data ad;
1590 struct selinux_audit_data sad = {0,};
1580 int rc; 1591 int rc;
1581 1592
1582 dsec = dir->i_security; 1593 dsec = dir->i_security;
@@ -1587,6 +1598,7 @@ static int may_create(struct inode *dir,
1587 1598
1588 COMMON_AUDIT_DATA_INIT(&ad, DENTRY); 1599 COMMON_AUDIT_DATA_INIT(&ad, DENTRY);
1589 ad.u.dentry = dentry; 1600 ad.u.dentry = dentry;
1601 ad.selinux_audit_data = &sad;
1590 1602
1591 rc = avc_has_perm(sid, dsec->sid, SECCLASS_DIR, 1603 rc = avc_has_perm(sid, dsec->sid, SECCLASS_DIR,
1592 DIR__ADD_NAME | DIR__SEARCH, 1604 DIR__ADD_NAME | DIR__SEARCH,
@@ -1631,6 +1643,7 @@ static int may_link(struct inode *dir,
1631{ 1643{
1632 struct inode_security_struct *dsec, *isec; 1644 struct inode_security_struct *dsec, *isec;
1633 struct common_audit_data ad; 1645 struct common_audit_data ad;
1646 struct selinux_audit_data sad = {0,};
1634 u32 sid = current_sid(); 1647 u32 sid = current_sid();
1635 u32 av; 1648 u32 av;
1636 int rc; 1649 int rc;
@@ -1640,6 +1653,7 @@ static int may_link(struct inode *dir,
1640 1653
1641 COMMON_AUDIT_DATA_INIT(&ad, DENTRY); 1654 COMMON_AUDIT_DATA_INIT(&ad, DENTRY);
1642 ad.u.dentry = dentry; 1655 ad.u.dentry = dentry;
1656 ad.selinux_audit_data = &sad;
1643 1657
1644 av = DIR__SEARCH; 1658 av = DIR__SEARCH;
1645 av |= (kind ? DIR__REMOVE_NAME : DIR__ADD_NAME); 1659 av |= (kind ? DIR__REMOVE_NAME : DIR__ADD_NAME);
@@ -1674,6 +1688,7 @@ static inline int may_rename(struct inode *old_dir,
1674{ 1688{
1675 struct inode_security_struct *old_dsec, *new_dsec, *old_isec, *new_isec; 1689 struct inode_security_struct *old_dsec, *new_dsec, *old_isec, *new_isec;
1676 struct common_audit_data ad; 1690 struct common_audit_data ad;
1691 struct selinux_audit_data sad = {0,};
1677 u32 sid = current_sid(); 1692 u32 sid = current_sid();
1678 u32 av; 1693 u32 av;
1679 int old_is_dir, new_is_dir; 1694 int old_is_dir, new_is_dir;
@@ -1685,6 +1700,7 @@ static inline int may_rename(struct inode *old_dir,
1685 new_dsec = new_dir->i_security; 1700 new_dsec = new_dir->i_security;
1686 1701
1687 COMMON_AUDIT_DATA_INIT(&ad, DENTRY); 1702 COMMON_AUDIT_DATA_INIT(&ad, DENTRY);
1703 ad.selinux_audit_data = &sad;
1688 1704
1689 ad.u.dentry = old_dentry; 1705 ad.u.dentry = old_dentry;
1690 rc = avc_has_perm(sid, old_dsec->sid, SECCLASS_DIR, 1706 rc = avc_has_perm(sid, old_dsec->sid, SECCLASS_DIR,
@@ -1970,6 +1986,7 @@ static int selinux_bprm_set_creds(struct linux_binprm *bprm)
1970 struct task_security_struct *new_tsec; 1986 struct task_security_struct *new_tsec;
1971 struct inode_security_struct *isec; 1987 struct inode_security_struct *isec;
1972 struct common_audit_data ad; 1988 struct common_audit_data ad;
1989 struct selinux_audit_data sad = {0,};
1973 struct inode *inode = bprm->file->f_path.dentry->d_inode; 1990 struct inode *inode = bprm->file->f_path.dentry->d_inode;
1974 int rc; 1991 int rc;
1975 1992
@@ -2009,6 +2026,7 @@ static int selinux_bprm_set_creds(struct linux_binprm *bprm)
2009 } 2026 }
2010 2027
2011 COMMON_AUDIT_DATA_INIT(&ad, PATH); 2028 COMMON_AUDIT_DATA_INIT(&ad, PATH);
2029 ad.selinux_audit_data = &sad;
2012 ad.u.path = bprm->file->f_path; 2030 ad.u.path = bprm->file->f_path;
2013 2031
2014 if (bprm->file->f_path.mnt->mnt_flags & MNT_NOSUID) 2032 if (bprm->file->f_path.mnt->mnt_flags & MNT_NOSUID)
@@ -2098,6 +2116,7 @@ static inline void flush_unauthorized_files(const struct cred *cred,
2098 struct files_struct *files) 2116 struct files_struct *files)
2099{ 2117{
2100 struct common_audit_data ad; 2118 struct common_audit_data ad;
2119 struct selinux_audit_data sad = {0,};
2101 struct file *file, *devnull = NULL; 2120 struct file *file, *devnull = NULL;
2102 struct tty_struct *tty; 2121 struct tty_struct *tty;
2103 struct fdtable *fdt; 2122 struct fdtable *fdt;
@@ -2135,6 +2154,7 @@ static inline void flush_unauthorized_files(const struct cred *cred,
2135 /* Revalidate access to inherited open files. */ 2154 /* Revalidate access to inherited open files. */
2136 2155
2137 COMMON_AUDIT_DATA_INIT(&ad, INODE); 2156 COMMON_AUDIT_DATA_INIT(&ad, INODE);
2157 ad.selinux_audit_data = &sad;
2138 2158
2139 spin_lock(&files->file_lock); 2159 spin_lock(&files->file_lock);
2140 for (;;) { 2160 for (;;) {
@@ -2472,6 +2492,7 @@ static int selinux_sb_kern_mount(struct super_block *sb, int flags, void *data)
2472{ 2492{
2473 const struct cred *cred = current_cred(); 2493 const struct cred *cred = current_cred();
2474 struct common_audit_data ad; 2494 struct common_audit_data ad;
2495 struct selinux_audit_data sad = {0,};
2475 int rc; 2496 int rc;
2476 2497
2477 rc = superblock_doinit(sb, data); 2498 rc = superblock_doinit(sb, data);
@@ -2483,6 +2504,7 @@ static int selinux_sb_kern_mount(struct super_block *sb, int flags, void *data)
2483 return 0; 2504 return 0;
2484 2505
2485 COMMON_AUDIT_DATA_INIT(&ad, DENTRY); 2506 COMMON_AUDIT_DATA_INIT(&ad, DENTRY);
2507 ad.selinux_audit_data = &sad;
2486 ad.u.dentry = sb->s_root; 2508 ad.u.dentry = sb->s_root;
2487 return superblock_has_perm(cred, sb, FILESYSTEM__MOUNT, &ad); 2509 return superblock_has_perm(cred, sb, FILESYSTEM__MOUNT, &ad);
2488} 2510}
@@ -2491,8 +2513,10 @@ static int selinux_sb_statfs(struct dentry *dentry)
2491{ 2513{
2492 const struct cred *cred = current_cred(); 2514 const struct cred *cred = current_cred();
2493 struct common_audit_data ad; 2515 struct common_audit_data ad;
2516 struct selinux_audit_data sad = {0,};
2494 2517
2495 COMMON_AUDIT_DATA_INIT(&ad, DENTRY); 2518 COMMON_AUDIT_DATA_INIT(&ad, DENTRY);
2519 ad.selinux_audit_data = &sad;
2496 ad.u.dentry = dentry->d_sb->s_root; 2520 ad.u.dentry = dentry->d_sb->s_root;
2497 return superblock_has_perm(cred, dentry->d_sb, FILESYSTEM__GETATTR, &ad); 2521 return superblock_has_perm(cred, dentry->d_sb, FILESYSTEM__GETATTR, &ad);
2498} 2522}
@@ -2656,6 +2680,7 @@ static int selinux_inode_permission(struct inode *inode, int mask)
2656{ 2680{
2657 const struct cred *cred = current_cred(); 2681 const struct cred *cred = current_cred();
2658 struct common_audit_data ad; 2682 struct common_audit_data ad;
2683 struct selinux_audit_data sad = {0,};
2659 u32 perms; 2684 u32 perms;
2660 bool from_access; 2685 bool from_access;
2661 unsigned flags = mask & MAY_NOT_BLOCK; 2686 unsigned flags = mask & MAY_NOT_BLOCK;
@@ -2668,10 +2693,11 @@ static int selinux_inode_permission(struct inode *inode, int mask)
2668 return 0; 2693 return 0;
2669 2694
2670 COMMON_AUDIT_DATA_INIT(&ad, INODE); 2695 COMMON_AUDIT_DATA_INIT(&ad, INODE);
2696 ad.selinux_audit_data = &sad;
2671 ad.u.inode = inode; 2697 ad.u.inode = inode;
2672 2698
2673 if (from_access) 2699 if (from_access)
2674 ad.selinux_audit_data.auditdeny |= FILE__AUDIT_ACCESS; 2700 ad.selinux_audit_data->auditdeny |= FILE__AUDIT_ACCESS;
2675 2701
2676 perms = file_mask_to_av(inode->i_mode, mask); 2702 perms = file_mask_to_av(inode->i_mode, mask);
2677 2703
@@ -2737,6 +2763,7 @@ static int selinux_inode_setxattr(struct dentry *dentry, const char *name,
2737 struct inode_security_struct *isec = inode->i_security; 2763 struct inode_security_struct *isec = inode->i_security;
2738 struct superblock_security_struct *sbsec; 2764 struct superblock_security_struct *sbsec;
2739 struct common_audit_data ad; 2765 struct common_audit_data ad;
2766 struct selinux_audit_data sad = {0,};
2740 u32 newsid, sid = current_sid(); 2767 u32 newsid, sid = current_sid();
2741 int rc = 0; 2768 int rc = 0;
2742 2769
@@ -2751,6 +2778,7 @@ static int selinux_inode_setxattr(struct dentry *dentry, const char *name,
2751 return -EPERM; 2778 return -EPERM;
2752 2779
2753 COMMON_AUDIT_DATA_INIT(&ad, DENTRY); 2780 COMMON_AUDIT_DATA_INIT(&ad, DENTRY);
2781 ad.selinux_audit_data = &sad;
2754 ad.u.dentry = dentry; 2782 ad.u.dentry = dentry;
2755 2783
2756 rc = avc_has_perm(sid, isec->sid, isec->sclass, 2784 rc = avc_has_perm(sid, isec->sid, isec->sclass,
@@ -3345,10 +3373,12 @@ static int selinux_kernel_module_request(char *kmod_name)
3345{ 3373{
3346 u32 sid; 3374 u32 sid;
3347 struct common_audit_data ad; 3375 struct common_audit_data ad;
3376 struct selinux_audit_data sad = {0,};
3348 3377
3349 sid = task_sid(current); 3378 sid = task_sid(current);
3350 3379
3351 COMMON_AUDIT_DATA_INIT(&ad, KMOD); 3380 COMMON_AUDIT_DATA_INIT(&ad, KMOD);
3381 ad.selinux_audit_data = &sad;
3352 ad.u.kmod_name = kmod_name; 3382 ad.u.kmod_name = kmod_name;
3353 3383
3354 return avc_has_perm(sid, SECINITSID_KERNEL, SECCLASS_SYSTEM, 3384 return avc_has_perm(sid, SECINITSID_KERNEL, SECCLASS_SYSTEM,
@@ -3487,8 +3517,8 @@ static int selinux_parse_skb_ipv4(struct sk_buff *skb,
3487 if (ihlen < sizeof(_iph)) 3517 if (ihlen < sizeof(_iph))
3488 goto out; 3518 goto out;
3489 3519
3490 ad->u.net.v4info.saddr = ih->saddr; 3520 ad->u.net->v4info.saddr = ih->saddr;
3491 ad->u.net.v4info.daddr = ih->daddr; 3521 ad->u.net->v4info.daddr = ih->daddr;
3492 ret = 0; 3522 ret = 0;
3493 3523
3494 if (proto) 3524 if (proto)
@@ -3506,8 +3536,8 @@ static int selinux_parse_skb_ipv4(struct sk_buff *skb,
3506 if (th == NULL) 3536 if (th == NULL)
3507 break; 3537 break;
3508 3538
3509 ad->u.net.sport = th->source; 3539 ad->u.net->sport = th->source;
3510 ad->u.net.dport = th->dest; 3540 ad->u.net->dport = th->dest;
3511 break; 3541 break;
3512 } 3542 }
3513 3543
@@ -3522,8 +3552,8 @@ static int selinux_parse_skb_ipv4(struct sk_buff *skb,
3522 if (uh == NULL) 3552 if (uh == NULL)
3523 break; 3553 break;
3524 3554
3525 ad->u.net.sport = uh->source; 3555 ad->u.net->sport = uh->source;
3526 ad->u.net.dport = uh->dest; 3556 ad->u.net->dport = uh->dest;
3527 break; 3557 break;
3528 } 3558 }
3529 3559
@@ -3538,8 +3568,8 @@ static int selinux_parse_skb_ipv4(struct sk_buff *skb,
3538 if (dh == NULL) 3568 if (dh == NULL)
3539 break; 3569 break;
3540 3570
3541 ad->u.net.sport = dh->dccph_sport; 3571 ad->u.net->sport = dh->dccph_sport;
3542 ad->u.net.dport = dh->dccph_dport; 3572 ad->u.net->dport = dh->dccph_dport;
3543 break; 3573 break;
3544 } 3574 }
3545 3575
@@ -3566,8 +3596,8 @@ static int selinux_parse_skb_ipv6(struct sk_buff *skb,
3566 if (ip6 == NULL) 3596 if (ip6 == NULL)
3567 goto out; 3597 goto out;
3568 3598
3569 ad->u.net.v6info.saddr = ip6->saddr; 3599 ad->u.net->v6info.saddr = ip6->saddr;
3570 ad->u.net.v6info.daddr = ip6->daddr; 3600 ad->u.net->v6info.daddr = ip6->daddr;
3571 ret = 0; 3601 ret = 0;
3572 3602
3573 nexthdr = ip6->nexthdr; 3603 nexthdr = ip6->nexthdr;
@@ -3587,8 +3617,8 @@ static int selinux_parse_skb_ipv6(struct sk_buff *skb,
3587 if (th == NULL) 3617 if (th == NULL)
3588 break; 3618 break;
3589 3619
3590 ad->u.net.sport = th->source; 3620 ad->u.net->sport = th->source;
3591 ad->u.net.dport = th->dest; 3621 ad->u.net->dport = th->dest;
3592 break; 3622 break;
3593 } 3623 }
3594 3624
@@ -3599,8 +3629,8 @@ static int selinux_parse_skb_ipv6(struct sk_buff *skb,
3599 if (uh == NULL) 3629 if (uh == NULL)
3600 break; 3630 break;
3601 3631
3602 ad->u.net.sport = uh->source; 3632 ad->u.net->sport = uh->source;
3603 ad->u.net.dport = uh->dest; 3633 ad->u.net->dport = uh->dest;
3604 break; 3634 break;
3605 } 3635 }
3606 3636
@@ -3611,8 +3641,8 @@ static int selinux_parse_skb_ipv6(struct sk_buff *skb,
3611 if (dh == NULL) 3641 if (dh == NULL)
3612 break; 3642 break;
3613 3643
3614 ad->u.net.sport = dh->dccph_sport; 3644 ad->u.net->sport = dh->dccph_sport;
3615 ad->u.net.dport = dh->dccph_dport; 3645 ad->u.net->dport = dh->dccph_dport;
3616 break; 3646 break;
3617 } 3647 }
3618 3648
@@ -3632,13 +3662,13 @@ static int selinux_parse_skb(struct sk_buff *skb, struct common_audit_data *ad,
3632 char *addrp; 3662 char *addrp;
3633 int ret; 3663 int ret;
3634 3664
3635 switch (ad->u.net.family) { 3665 switch (ad->u.net->family) {
3636 case PF_INET: 3666 case PF_INET:
3637 ret = selinux_parse_skb_ipv4(skb, ad, proto); 3667 ret = selinux_parse_skb_ipv4(skb, ad, proto);
3638 if (ret) 3668 if (ret)
3639 goto parse_error; 3669 goto parse_error;
3640 addrp = (char *)(src ? &ad->u.net.v4info.saddr : 3670 addrp = (char *)(src ? &ad->u.net->v4info.saddr :
3641 &ad->u.net.v4info.daddr); 3671 &ad->u.net->v4info.daddr);
3642 goto okay; 3672 goto okay;
3643 3673
3644#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) 3674#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
@@ -3646,8 +3676,8 @@ static int selinux_parse_skb(struct sk_buff *skb, struct common_audit_data *ad,
3646 ret = selinux_parse_skb_ipv6(skb, ad, proto); 3676 ret = selinux_parse_skb_ipv6(skb, ad, proto);
3647 if (ret) 3677 if (ret)
3648 goto parse_error; 3678 goto parse_error;
3649 addrp = (char *)(src ? &ad->u.net.v6info.saddr : 3679 addrp = (char *)(src ? &ad->u.net->v6info.saddr :
3650 &ad->u.net.v6info.daddr); 3680 &ad->u.net->v6info.daddr);
3651 goto okay; 3681 goto okay;
3652#endif /* IPV6 */ 3682#endif /* IPV6 */
3653 default: 3683 default:
@@ -3721,13 +3751,17 @@ static int sock_has_perm(struct task_struct *task, struct sock *sk, u32 perms)
3721{ 3751{
3722 struct sk_security_struct *sksec = sk->sk_security; 3752 struct sk_security_struct *sksec = sk->sk_security;
3723 struct common_audit_data ad; 3753 struct common_audit_data ad;
3754 struct selinux_audit_data sad = {0,};
3755 struct lsm_network_audit net = {0,};
3724 u32 tsid = task_sid(task); 3756 u32 tsid = task_sid(task);
3725 3757
3726 if (sksec->sid == SECINITSID_KERNEL) 3758 if (sksec->sid == SECINITSID_KERNEL)
3727 return 0; 3759 return 0;
3728 3760
3729 COMMON_AUDIT_DATA_INIT(&ad, NET); 3761 COMMON_AUDIT_DATA_INIT(&ad, NET);
3730 ad.u.net.sk = sk; 3762 ad.selinux_audit_data = &sad;
3763 ad.u.net = &net;
3764 ad.u.net->sk = sk;
3731 3765
3732 return avc_has_perm(tsid, sksec->sid, sksec->sclass, perms, &ad); 3766 return avc_has_perm(tsid, sksec->sid, sksec->sclass, perms, &ad);
3733} 3767}
@@ -3805,6 +3839,8 @@ static int selinux_socket_bind(struct socket *sock, struct sockaddr *address, in
3805 char *addrp; 3839 char *addrp;
3806 struct sk_security_struct *sksec = sk->sk_security; 3840 struct sk_security_struct *sksec = sk->sk_security;
3807 struct common_audit_data ad; 3841 struct common_audit_data ad;
3842 struct selinux_audit_data sad = {0,};
3843 struct lsm_network_audit net = {0,};
3808 struct sockaddr_in *addr4 = NULL; 3844 struct sockaddr_in *addr4 = NULL;
3809 struct sockaddr_in6 *addr6 = NULL; 3845 struct sockaddr_in6 *addr6 = NULL;
3810 unsigned short snum; 3846 unsigned short snum;
@@ -3831,8 +3867,10 @@ static int selinux_socket_bind(struct socket *sock, struct sockaddr *address, in
3831 if (err) 3867 if (err)
3832 goto out; 3868 goto out;
3833 COMMON_AUDIT_DATA_INIT(&ad, NET); 3869 COMMON_AUDIT_DATA_INIT(&ad, NET);
3834 ad.u.net.sport = htons(snum); 3870 ad.selinux_audit_data = &sad;
3835 ad.u.net.family = family; 3871 ad.u.net = &net;
3872 ad.u.net->sport = htons(snum);
3873 ad.u.net->family = family;
3836 err = avc_has_perm(sksec->sid, sid, 3874 err = avc_has_perm(sksec->sid, sid,
3837 sksec->sclass, 3875 sksec->sclass,
3838 SOCKET__NAME_BIND, &ad); 3876 SOCKET__NAME_BIND, &ad);
@@ -3864,13 +3902,15 @@ static int selinux_socket_bind(struct socket *sock, struct sockaddr *address, in
3864 goto out; 3902 goto out;
3865 3903
3866 COMMON_AUDIT_DATA_INIT(&ad, NET); 3904 COMMON_AUDIT_DATA_INIT(&ad, NET);
3867 ad.u.net.sport = htons(snum); 3905 ad.selinux_audit_data = &sad;
3868 ad.u.net.family = family; 3906 ad.u.net = &net;
3907 ad.u.net->sport = htons(snum);
3908 ad.u.net->family = family;
3869 3909
3870 if (family == PF_INET) 3910 if (family == PF_INET)
3871 ad.u.net.v4info.saddr = addr4->sin_addr.s_addr; 3911 ad.u.net->v4info.saddr = addr4->sin_addr.s_addr;
3872 else 3912 else
3873 ad.u.net.v6info.saddr = addr6->sin6_addr; 3913 ad.u.net->v6info.saddr = addr6->sin6_addr;
3874 3914
3875 err = avc_has_perm(sksec->sid, sid, 3915 err = avc_has_perm(sksec->sid, sid,
3876 sksec->sclass, node_perm, &ad); 3916 sksec->sclass, node_perm, &ad);
@@ -3897,6 +3937,8 @@ static int selinux_socket_connect(struct socket *sock, struct sockaddr *address,
3897 if (sksec->sclass == SECCLASS_TCP_SOCKET || 3937 if (sksec->sclass == SECCLASS_TCP_SOCKET ||
3898 sksec->sclass == SECCLASS_DCCP_SOCKET) { 3938 sksec->sclass == SECCLASS_DCCP_SOCKET) {
3899 struct common_audit_data ad; 3939 struct common_audit_data ad;
3940 struct selinux_audit_data sad = {0,};
3941 struct lsm_network_audit net = {0,};
3900 struct sockaddr_in *addr4 = NULL; 3942 struct sockaddr_in *addr4 = NULL;
3901 struct sockaddr_in6 *addr6 = NULL; 3943 struct sockaddr_in6 *addr6 = NULL;
3902 unsigned short snum; 3944 unsigned short snum;
@@ -3922,8 +3964,10 @@ static int selinux_socket_connect(struct socket *sock, struct sockaddr *address,
3922 TCP_SOCKET__NAME_CONNECT : DCCP_SOCKET__NAME_CONNECT; 3964 TCP_SOCKET__NAME_CONNECT : DCCP_SOCKET__NAME_CONNECT;
3923 3965
3924 COMMON_AUDIT_DATA_INIT(&ad, NET); 3966 COMMON_AUDIT_DATA_INIT(&ad, NET);
3925 ad.u.net.dport = htons(snum); 3967 ad.selinux_audit_data = &sad;
3926 ad.u.net.family = sk->sk_family; 3968 ad.u.net = &net;
3969 ad.u.net->dport = htons(snum);
3970 ad.u.net->family = sk->sk_family;
3927 err = avc_has_perm(sksec->sid, sid, sksec->sclass, perm, &ad); 3971 err = avc_has_perm(sksec->sid, sid, sksec->sclass, perm, &ad);
3928 if (err) 3972 if (err)
3929 goto out; 3973 goto out;
@@ -4012,10 +4056,14 @@ static int selinux_socket_unix_stream_connect(struct sock *sock,
4012 struct sk_security_struct *sksec_other = other->sk_security; 4056 struct sk_security_struct *sksec_other = other->sk_security;
4013 struct sk_security_struct *sksec_new = newsk->sk_security; 4057 struct sk_security_struct *sksec_new = newsk->sk_security;
4014 struct common_audit_data ad; 4058 struct common_audit_data ad;
4059 struct selinux_audit_data sad = {0,};
4060 struct lsm_network_audit net = {0,};
4015 int err; 4061 int err;
4016 4062
4017 COMMON_AUDIT_DATA_INIT(&ad, NET); 4063 COMMON_AUDIT_DATA_INIT(&ad, NET);
4018 ad.u.net.sk = other; 4064 ad.selinux_audit_data = &sad;
4065 ad.u.net = &net;
4066 ad.u.net->sk = other;
4019 4067
4020 err = avc_has_perm(sksec_sock->sid, sksec_other->sid, 4068 err = avc_has_perm(sksec_sock->sid, sksec_other->sid,
4021 sksec_other->sclass, 4069 sksec_other->sclass,
@@ -4042,9 +4090,13 @@ static int selinux_socket_unix_may_send(struct socket *sock,
4042 struct sk_security_struct *ssec = sock->sk->sk_security; 4090 struct sk_security_struct *ssec = sock->sk->sk_security;
4043 struct sk_security_struct *osec = other->sk->sk_security; 4091 struct sk_security_struct *osec = other->sk->sk_security;
4044 struct common_audit_data ad; 4092 struct common_audit_data ad;
4093 struct selinux_audit_data sad = {0,};
4094 struct lsm_network_audit net = {0,};
4045 4095
4046 COMMON_AUDIT_DATA_INIT(&ad, NET); 4096 COMMON_AUDIT_DATA_INIT(&ad, NET);
4047 ad.u.net.sk = other->sk; 4097 ad.selinux_audit_data = &sad;
4098 ad.u.net = &net;
4099 ad.u.net->sk = other->sk;
4048 4100
4049 return avc_has_perm(ssec->sid, osec->sid, osec->sclass, SOCKET__SENDTO, 4101 return avc_has_perm(ssec->sid, osec->sid, osec->sclass, SOCKET__SENDTO,
4050 &ad); 4102 &ad);
@@ -4080,11 +4132,15 @@ static int selinux_sock_rcv_skb_compat(struct sock *sk, struct sk_buff *skb,
4080 struct sk_security_struct *sksec = sk->sk_security; 4132 struct sk_security_struct *sksec = sk->sk_security;
4081 u32 sk_sid = sksec->sid; 4133 u32 sk_sid = sksec->sid;
4082 struct common_audit_data ad; 4134 struct common_audit_data ad;
4135 struct selinux_audit_data sad = {0,};
4136 struct lsm_network_audit net = {0,};
4083 char *addrp; 4137 char *addrp;
4084 4138
4085 COMMON_AUDIT_DATA_INIT(&ad, NET); 4139 COMMON_AUDIT_DATA_INIT(&ad, NET);
4086 ad.u.net.netif = skb->skb_iif; 4140 ad.selinux_audit_data = &sad;
4087 ad.u.net.family = family; 4141 ad.u.net = &net;
4142 ad.u.net->netif = skb->skb_iif;
4143 ad.u.net->family = family;
4088 err = selinux_parse_skb(skb, &ad, &addrp, 1, NULL); 4144 err = selinux_parse_skb(skb, &ad, &addrp, 1, NULL);
4089 if (err) 4145 if (err)
4090 return err; 4146 return err;
@@ -4111,6 +4167,8 @@ static int selinux_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
4111 u16 family = sk->sk_family; 4167 u16 family = sk->sk_family;
4112 u32 sk_sid = sksec->sid; 4168 u32 sk_sid = sksec->sid;
4113 struct common_audit_data ad; 4169 struct common_audit_data ad;
4170 struct selinux_audit_data sad = {0,};
4171 struct lsm_network_audit net = {0,};
4114 char *addrp; 4172 char *addrp;
4115 u8 secmark_active; 4173 u8 secmark_active;
4116 u8 peerlbl_active; 4174 u8 peerlbl_active;
@@ -4135,8 +4193,10 @@ static int selinux_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
4135 return 0; 4193 return 0;
4136 4194
4137 COMMON_AUDIT_DATA_INIT(&ad, NET); 4195 COMMON_AUDIT_DATA_INIT(&ad, NET);
4138 ad.u.net.netif = skb->skb_iif; 4196 ad.selinux_audit_data = &sad;
4139 ad.u.net.family = family; 4197 ad.u.net = &net;
4198 ad.u.net->netif = skb->skb_iif;
4199 ad.u.net->family = family;
4140 err = selinux_parse_skb(skb, &ad, &addrp, 1, NULL); 4200 err = selinux_parse_skb(skb, &ad, &addrp, 1, NULL);
4141 if (err) 4201 if (err)
4142 return err; 4202 return err;
@@ -4471,6 +4531,8 @@ static unsigned int selinux_ip_forward(struct sk_buff *skb, int ifindex,
4471 char *addrp; 4531 char *addrp;
4472 u32 peer_sid; 4532 u32 peer_sid;
4473 struct common_audit_data ad; 4533 struct common_audit_data ad;
4534 struct selinux_audit_data sad = {0,};
4535 struct lsm_network_audit net = {0,};
4474 u8 secmark_active; 4536 u8 secmark_active;
4475 u8 netlbl_active; 4537 u8 netlbl_active;
4476 u8 peerlbl_active; 4538 u8 peerlbl_active;
@@ -4488,8 +4550,10 @@ static unsigned int selinux_ip_forward(struct sk_buff *skb, int ifindex,
4488 return NF_DROP; 4550 return NF_DROP;
4489 4551
4490 COMMON_AUDIT_DATA_INIT(&ad, NET); 4552 COMMON_AUDIT_DATA_INIT(&ad, NET);
4491 ad.u.net.netif = ifindex; 4553 ad.selinux_audit_data = &sad;
4492 ad.u.net.family = family; 4554 ad.u.net = &net;
4555 ad.u.net->netif = ifindex;
4556 ad.u.net->family = family;
4493 if (selinux_parse_skb(skb, &ad, &addrp, 1, NULL) != 0) 4557 if (selinux_parse_skb(skb, &ad, &addrp, 1, NULL) != 0)
4494 return NF_DROP; 4558 return NF_DROP;
4495 4559
@@ -4576,6 +4640,8 @@ static unsigned int selinux_ip_postroute_compat(struct sk_buff *skb,
4576 struct sock *sk = skb->sk; 4640 struct sock *sk = skb->sk;
4577 struct sk_security_struct *sksec; 4641 struct sk_security_struct *sksec;
4578 struct common_audit_data ad; 4642 struct common_audit_data ad;
4643 struct selinux_audit_data sad = {0,};
4644 struct lsm_network_audit net = {0,};
4579 char *addrp; 4645 char *addrp;
4580 u8 proto; 4646 u8 proto;
4581 4647
@@ -4584,8 +4650,10 @@ static unsigned int selinux_ip_postroute_compat(struct sk_buff *skb,
4584 sksec = sk->sk_security; 4650 sksec = sk->sk_security;
4585 4651
4586 COMMON_AUDIT_DATA_INIT(&ad, NET); 4652 COMMON_AUDIT_DATA_INIT(&ad, NET);
4587 ad.u.net.netif = ifindex; 4653 ad.selinux_audit_data = &sad;
4588 ad.u.net.family = family; 4654 ad.u.net = &net;
4655 ad.u.net->netif = ifindex;
4656 ad.u.net->family = family;
4589 if (selinux_parse_skb(skb, &ad, &addrp, 0, &proto)) 4657 if (selinux_parse_skb(skb, &ad, &addrp, 0, &proto))
4590 return NF_DROP; 4658 return NF_DROP;
4591 4659
@@ -4607,6 +4675,8 @@ static unsigned int selinux_ip_postroute(struct sk_buff *skb, int ifindex,
4607 u32 peer_sid; 4675 u32 peer_sid;
4608 struct sock *sk; 4676 struct sock *sk;
4609 struct common_audit_data ad; 4677 struct common_audit_data ad;
4678 struct selinux_audit_data sad = {0,};
4679 struct lsm_network_audit net = {0,};
4610 char *addrp; 4680 char *addrp;
4611 u8 secmark_active; 4681 u8 secmark_active;
4612 u8 peerlbl_active; 4682 u8 peerlbl_active;
@@ -4653,8 +4723,10 @@ static unsigned int selinux_ip_postroute(struct sk_buff *skb, int ifindex,
4653 } 4723 }
4654 4724
4655 COMMON_AUDIT_DATA_INIT(&ad, NET); 4725 COMMON_AUDIT_DATA_INIT(&ad, NET);
4656 ad.u.net.netif = ifindex; 4726 ad.selinux_audit_data = &sad;
4657 ad.u.net.family = family; 4727 ad.u.net = &net;
4728 ad.u.net->netif = ifindex;
4729 ad.u.net->family = family;
4658 if (selinux_parse_skb(skb, &ad, &addrp, 0, NULL)) 4730 if (selinux_parse_skb(skb, &ad, &addrp, 0, NULL))
4659 return NF_DROP; 4731 return NF_DROP;
4660 4732
@@ -4769,11 +4841,13 @@ static int ipc_has_perm(struct kern_ipc_perm *ipc_perms,
4769{ 4841{
4770 struct ipc_security_struct *isec; 4842 struct ipc_security_struct *isec;
4771 struct common_audit_data ad; 4843 struct common_audit_data ad;
4844 struct selinux_audit_data sad = {0,};
4772 u32 sid = current_sid(); 4845 u32 sid = current_sid();
4773 4846
4774 isec = ipc_perms->security; 4847 isec = ipc_perms->security;
4775 4848
4776 COMMON_AUDIT_DATA_INIT(&ad, IPC); 4849 COMMON_AUDIT_DATA_INIT(&ad, IPC);
4850 ad.selinux_audit_data = &sad;
4777 ad.u.ipc_id = ipc_perms->key; 4851 ad.u.ipc_id = ipc_perms->key;
4778 4852
4779 return avc_has_perm(sid, isec->sid, isec->sclass, perms, &ad); 4853 return avc_has_perm(sid, isec->sid, isec->sclass, perms, &ad);
@@ -4794,6 +4868,7 @@ static int selinux_msg_queue_alloc_security(struct msg_queue *msq)
4794{ 4868{
4795 struct ipc_security_struct *isec; 4869 struct ipc_security_struct *isec;
4796 struct common_audit_data ad; 4870 struct common_audit_data ad;
4871 struct selinux_audit_data sad = {0,};
4797 u32 sid = current_sid(); 4872 u32 sid = current_sid();
4798 int rc; 4873 int rc;
4799 4874
@@ -4804,6 +4879,7 @@ static int selinux_msg_queue_alloc_security(struct msg_queue *msq)
4804 isec = msq->q_perm.security; 4879 isec = msq->q_perm.security;
4805 4880
4806 COMMON_AUDIT_DATA_INIT(&ad, IPC); 4881 COMMON_AUDIT_DATA_INIT(&ad, IPC);
4882 ad.selinux_audit_data = &sad;
4807 ad.u.ipc_id = msq->q_perm.key; 4883 ad.u.ipc_id = msq->q_perm.key;
4808 4884
4809 rc = avc_has_perm(sid, isec->sid, SECCLASS_MSGQ, 4885 rc = avc_has_perm(sid, isec->sid, SECCLASS_MSGQ,
@@ -4824,11 +4900,13 @@ static int selinux_msg_queue_associate(struct msg_queue *msq, int msqflg)
4824{ 4900{
4825 struct ipc_security_struct *isec; 4901 struct ipc_security_struct *isec;
4826 struct common_audit_data ad; 4902 struct common_audit_data ad;
4903 struct selinux_audit_data sad = {0,};
4827 u32 sid = current_sid(); 4904 u32 sid = current_sid();
4828 4905
4829 isec = msq->q_perm.security; 4906 isec = msq->q_perm.security;
4830 4907
4831 COMMON_AUDIT_DATA_INIT(&ad, IPC); 4908 COMMON_AUDIT_DATA_INIT(&ad, IPC);
4909 ad.selinux_audit_data = &sad;
4832 ad.u.ipc_id = msq->q_perm.key; 4910 ad.u.ipc_id = msq->q_perm.key;
4833 4911
4834 return avc_has_perm(sid, isec->sid, SECCLASS_MSGQ, 4912 return avc_has_perm(sid, isec->sid, SECCLASS_MSGQ,
@@ -4868,6 +4946,7 @@ static int selinux_msg_queue_msgsnd(struct msg_queue *msq, struct msg_msg *msg,
4868 struct ipc_security_struct *isec; 4946 struct ipc_security_struct *isec;
4869 struct msg_security_struct *msec; 4947 struct msg_security_struct *msec;
4870 struct common_audit_data ad; 4948 struct common_audit_data ad;
4949 struct selinux_audit_data sad = {0,};
4871 u32 sid = current_sid(); 4950 u32 sid = current_sid();
4872 int rc; 4951 int rc;
4873 4952
@@ -4889,6 +4968,7 @@ static int selinux_msg_queue_msgsnd(struct msg_queue *msq, struct msg_msg *msg,
4889 } 4968 }
4890 4969
4891 COMMON_AUDIT_DATA_INIT(&ad, IPC); 4970 COMMON_AUDIT_DATA_INIT(&ad, IPC);
4971 ad.selinux_audit_data = &sad;
4892 ad.u.ipc_id = msq->q_perm.key; 4972 ad.u.ipc_id = msq->q_perm.key;
4893 4973
4894 /* Can this process write to the queue? */ 4974 /* Can this process write to the queue? */
@@ -4913,6 +4993,7 @@ static int selinux_msg_queue_msgrcv(struct msg_queue *msq, struct msg_msg *msg,
4913 struct ipc_security_struct *isec; 4993 struct ipc_security_struct *isec;
4914 struct msg_security_struct *msec; 4994 struct msg_security_struct *msec;
4915 struct common_audit_data ad; 4995 struct common_audit_data ad;
4996 struct selinux_audit_data sad = {0,};
4916 u32 sid = task_sid(target); 4997 u32 sid = task_sid(target);
4917 int rc; 4998 int rc;
4918 4999
@@ -4920,6 +5001,7 @@ static int selinux_msg_queue_msgrcv(struct msg_queue *msq, struct msg_msg *msg,
4920 msec = msg->security; 5001 msec = msg->security;
4921 5002
4922 COMMON_AUDIT_DATA_INIT(&ad, IPC); 5003 COMMON_AUDIT_DATA_INIT(&ad, IPC);
5004 ad.selinux_audit_data = &sad;
4923 ad.u.ipc_id = msq->q_perm.key; 5005 ad.u.ipc_id = msq->q_perm.key;
4924 5006
4925 rc = avc_has_perm(sid, isec->sid, 5007 rc = avc_has_perm(sid, isec->sid,
@@ -4935,6 +5017,7 @@ static int selinux_shm_alloc_security(struct shmid_kernel *shp)
4935{ 5017{
4936 struct ipc_security_struct *isec; 5018 struct ipc_security_struct *isec;
4937 struct common_audit_data ad; 5019 struct common_audit_data ad;
5020 struct selinux_audit_data sad = {0,};
4938 u32 sid = current_sid(); 5021 u32 sid = current_sid();
4939 int rc; 5022 int rc;
4940 5023
@@ -4945,6 +5028,7 @@ static int selinux_shm_alloc_security(struct shmid_kernel *shp)
4945 isec = shp->shm_perm.security; 5028 isec = shp->shm_perm.security;
4946 5029
4947 COMMON_AUDIT_DATA_INIT(&ad, IPC); 5030 COMMON_AUDIT_DATA_INIT(&ad, IPC);
5031 ad.selinux_audit_data = &sad;
4948 ad.u.ipc_id = shp->shm_perm.key; 5032 ad.u.ipc_id = shp->shm_perm.key;
4949 5033
4950 rc = avc_has_perm(sid, isec->sid, SECCLASS_SHM, 5034 rc = avc_has_perm(sid, isec->sid, SECCLASS_SHM,
@@ -4965,11 +5049,13 @@ static int selinux_shm_associate(struct shmid_kernel *shp, int shmflg)
4965{ 5049{
4966 struct ipc_security_struct *isec; 5050 struct ipc_security_struct *isec;
4967 struct common_audit_data ad; 5051 struct common_audit_data ad;
5052 struct selinux_audit_data sad = {0,};
4968 u32 sid = current_sid(); 5053 u32 sid = current_sid();
4969 5054
4970 isec = shp->shm_perm.security; 5055 isec = shp->shm_perm.security;
4971 5056
4972 COMMON_AUDIT_DATA_INIT(&ad, IPC); 5057 COMMON_AUDIT_DATA_INIT(&ad, IPC);
5058 ad.selinux_audit_data = &sad;
4973 ad.u.ipc_id = shp->shm_perm.key; 5059 ad.u.ipc_id = shp->shm_perm.key;
4974 5060
4975 return avc_has_perm(sid, isec->sid, SECCLASS_SHM, 5061 return avc_has_perm(sid, isec->sid, SECCLASS_SHM,
@@ -5027,6 +5113,7 @@ static int selinux_sem_alloc_security(struct sem_array *sma)
5027{ 5113{
5028 struct ipc_security_struct *isec; 5114 struct ipc_security_struct *isec;
5029 struct common_audit_data ad; 5115 struct common_audit_data ad;
5116 struct selinux_audit_data sad = {0,};
5030 u32 sid = current_sid(); 5117 u32 sid = current_sid();
5031 int rc; 5118 int rc;
5032 5119
@@ -5037,6 +5124,7 @@ static int selinux_sem_alloc_security(struct sem_array *sma)
5037 isec = sma->sem_perm.security; 5124 isec = sma->sem_perm.security;
5038 5125
5039 COMMON_AUDIT_DATA_INIT(&ad, IPC); 5126 COMMON_AUDIT_DATA_INIT(&ad, IPC);
5127 ad.selinux_audit_data = &sad;
5040 ad.u.ipc_id = sma->sem_perm.key; 5128 ad.u.ipc_id = sma->sem_perm.key;
5041 5129
5042 rc = avc_has_perm(sid, isec->sid, SECCLASS_SEM, 5130 rc = avc_has_perm(sid, isec->sid, SECCLASS_SEM,
@@ -5057,11 +5145,13 @@ static int selinux_sem_associate(struct sem_array *sma, int semflg)
5057{ 5145{
5058 struct ipc_security_struct *isec; 5146 struct ipc_security_struct *isec;
5059 struct common_audit_data ad; 5147 struct common_audit_data ad;
5148 struct selinux_audit_data sad = {0,};
5060 u32 sid = current_sid(); 5149 u32 sid = current_sid();
5061 5150
5062 isec = sma->sem_perm.security; 5151 isec = sma->sem_perm.security;
5063 5152
5064 COMMON_AUDIT_DATA_INIT(&ad, IPC); 5153 COMMON_AUDIT_DATA_INIT(&ad, IPC);
5154 ad.selinux_audit_data = &sad;
5065 ad.u.ipc_id = sma->sem_perm.key; 5155 ad.u.ipc_id = sma->sem_perm.key;
5066 5156
5067 return avc_has_perm(sid, isec->sid, SECCLASS_SEM, 5157 return avc_has_perm(sid, isec->sid, SECCLASS_SEM,
diff --git a/security/selinux/include/avc.h b/security/selinux/include/avc.h
index 005a91bcb200..1931370233d7 100644
--- a/security/selinux/include/avc.h
+++ b/security/selinux/include/avc.h
@@ -47,6 +47,31 @@ struct avc_cache_stats {
47}; 47};
48 48
49/* 49/*
50 * We only need this data after we have decided to send an audit message.
51 */
52struct selinux_late_audit_data {
53 u32 ssid;
54 u32 tsid;
55 u16 tclass;
56 u32 requested;
57 u32 audited;
58 u32 denied;
59 int result;
60};
61
62/*
63 * We collect this at the beginning or during an selinux security operation
64 */
65struct selinux_audit_data {
66 /*
67 * auditdeny is a bit tricky and unintuitive. See the
68 * comments in avc.c for it's meaning and usage.
69 */
70 u32 auditdeny;
71 struct selinux_late_audit_data *slad;
72};
73
74/*
50 * AVC operations 75 * AVC operations
51 */ 76 */
52 77
diff --git a/security/smack/smack.h b/security/smack/smack.h
index 2ad00657b801..4ede719922ed 100644
--- a/security/smack/smack.h
+++ b/security/smack/smack.h
@@ -185,6 +185,15 @@ struct smack_known {
185 */ 185 */
186#define SMK_NUM_ACCESS_TYPE 5 186#define SMK_NUM_ACCESS_TYPE 5
187 187
188/* SMACK data */
189struct smack_audit_data {
190 const char *function;
191 char *subject;
192 char *object;
193 char *request;
194 int result;
195};
196
188/* 197/*
189 * Smack audit data; is empty if CONFIG_AUDIT not set 198 * Smack audit data; is empty if CONFIG_AUDIT not set
190 * to save some stack 199 * to save some stack
@@ -192,6 +201,7 @@ struct smack_known {
192struct smk_audit_info { 201struct smk_audit_info {
193#ifdef CONFIG_AUDIT 202#ifdef CONFIG_AUDIT
194 struct common_audit_data a; 203 struct common_audit_data a;
204 struct smack_audit_data sad;
195#endif 205#endif
196}; 206};
197/* 207/*
@@ -311,7 +321,16 @@ static inline void smk_ad_init(struct smk_audit_info *a, const char *func,
311{ 321{
312 memset(a, 0, sizeof(*a)); 322 memset(a, 0, sizeof(*a));
313 a->a.type = type; 323 a->a.type = type;
314 a->a.smack_audit_data.function = func; 324 a->a.smack_audit_data = &a->sad;
325 a->a.smack_audit_data->function = func;
326}
327
328static inline void smk_ad_init_net(struct smk_audit_info *a, const char *func,
329 char type, struct lsm_network_audit *net)
330{
331 smk_ad_init(a, func, type);
332 memset(net, 0, sizeof(*net));
333 a->a.u.net = net;
315} 334}
316 335
317static inline void smk_ad_setfield_u_tsk(struct smk_audit_info *a, 336static inline void smk_ad_setfield_u_tsk(struct smk_audit_info *a,
@@ -337,7 +356,7 @@ static inline void smk_ad_setfield_u_fs_path(struct smk_audit_info *a,
337static inline void smk_ad_setfield_u_net_sk(struct smk_audit_info *a, 356static inline void smk_ad_setfield_u_net_sk(struct smk_audit_info *a,
338 struct sock *sk) 357 struct sock *sk)
339{ 358{
340 a->a.u.net.sk = sk; 359 a->a.u.net->sk = sk;
341} 360}
342 361
343#else /* no AUDIT */ 362#else /* no AUDIT */
diff --git a/security/smack/smack_access.c b/security/smack/smack_access.c
index cc7cb6edba08..c8115f7308f8 100644
--- a/security/smack/smack_access.c
+++ b/security/smack/smack_access.c
@@ -275,9 +275,9 @@ static inline void smack_str_from_perm(char *string, int access)
275static void smack_log_callback(struct audit_buffer *ab, void *a) 275static void smack_log_callback(struct audit_buffer *ab, void *a)
276{ 276{
277 struct common_audit_data *ad = a; 277 struct common_audit_data *ad = a;
278 struct smack_audit_data *sad = &ad->smack_audit_data; 278 struct smack_audit_data *sad = ad->smack_audit_data;
279 audit_log_format(ab, "lsm=SMACK fn=%s action=%s", 279 audit_log_format(ab, "lsm=SMACK fn=%s action=%s",
280 ad->smack_audit_data.function, 280 ad->smack_audit_data->function,
281 sad->result ? "denied" : "granted"); 281 sad->result ? "denied" : "granted");
282 audit_log_format(ab, " subject="); 282 audit_log_format(ab, " subject=");
283 audit_log_untrustedstring(ab, sad->subject); 283 audit_log_untrustedstring(ab, sad->subject);
@@ -310,19 +310,19 @@ void smack_log(char *subject_label, char *object_label, int request,
310 if (result == 0 && (log_policy & SMACK_AUDIT_ACCEPT) == 0) 310 if (result == 0 && (log_policy & SMACK_AUDIT_ACCEPT) == 0)
311 return; 311 return;
312 312
313 if (a->smack_audit_data.function == NULL) 313 sad = a->smack_audit_data;
314 a->smack_audit_data.function = "unknown"; 314
315 if (sad->function == NULL)
316 sad->function = "unknown";
315 317
316 /* end preparing the audit data */ 318 /* end preparing the audit data */
317 sad = &a->smack_audit_data;
318 smack_str_from_perm(request_buffer, request); 319 smack_str_from_perm(request_buffer, request);
319 sad->subject = subject_label; 320 sad->subject = subject_label;
320 sad->object = object_label; 321 sad->object = object_label;
321 sad->request = request_buffer; 322 sad->request = request_buffer;
322 sad->result = result; 323 sad->result = result;
323 a->lsm_pre_audit = smack_log_callback;
324 324
325 common_lsm_audit(a); 325 common_lsm_audit(a, smack_log_callback, NULL);
326} 326}
327#else /* #ifdef CONFIG_AUDIT */ 327#else /* #ifdef CONFIG_AUDIT */
328void smack_log(char *subject_label, char *object_label, int request, 328void smack_log(char *subject_label, char *object_label, int request,
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index cd667b4089a5..45c32f074166 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -1943,13 +1943,15 @@ static int smack_netlabel_send(struct sock *sk, struct sockaddr_in *sap)
1943 rcu_read_lock(); 1943 rcu_read_lock();
1944 hostsp = smack_host_label(sap); 1944 hostsp = smack_host_label(sap);
1945 if (hostsp != NULL) { 1945 if (hostsp != NULL) {
1946 sk_lbl = SMACK_UNLABELED_SOCKET;
1947#ifdef CONFIG_AUDIT 1946#ifdef CONFIG_AUDIT
1948 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_NET); 1947 struct lsm_network_audit net;
1949 ad.a.u.net.family = sap->sin_family; 1948
1950 ad.a.u.net.dport = sap->sin_port; 1949 smk_ad_init_net(&ad, __func__, LSM_AUDIT_DATA_NET, &net);
1951 ad.a.u.net.v4info.daddr = sap->sin_addr.s_addr; 1950 ad.a.u.net->family = sap->sin_family;
1951 ad.a.u.net->dport = sap->sin_port;
1952 ad.a.u.net->v4info.daddr = sap->sin_addr.s_addr;
1952#endif 1953#endif
1954 sk_lbl = SMACK_UNLABELED_SOCKET;
1953 rc = smk_access(ssp->smk_out, hostsp, MAY_WRITE, &ad); 1955 rc = smk_access(ssp->smk_out, hostsp, MAY_WRITE, &ad);
1954 } else { 1956 } else {
1955 sk_lbl = SMACK_CIPSO_SOCKET; 1957 sk_lbl = SMACK_CIPSO_SOCKET;
@@ -2810,8 +2812,12 @@ static int smack_unix_stream_connect(struct sock *sock,
2810 struct smk_audit_info ad; 2812 struct smk_audit_info ad;
2811 int rc = 0; 2813 int rc = 0;
2812 2814
2813 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_NET); 2815#ifdef CONFIG_AUDIT
2816 struct lsm_network_audit net;
2817
2818 smk_ad_init_net(&ad, __func__, LSM_AUDIT_DATA_NET, &net);
2814 smk_ad_setfield_u_net_sk(&ad, other); 2819 smk_ad_setfield_u_net_sk(&ad, other);
2820#endif
2815 2821
2816 if (!capable(CAP_MAC_OVERRIDE)) 2822 if (!capable(CAP_MAC_OVERRIDE))
2817 rc = smk_access(ssp->smk_out, osp->smk_in, MAY_WRITE, &ad); 2823 rc = smk_access(ssp->smk_out, osp->smk_in, MAY_WRITE, &ad);
@@ -2842,8 +2848,12 @@ static int smack_unix_may_send(struct socket *sock, struct socket *other)
2842 struct smk_audit_info ad; 2848 struct smk_audit_info ad;
2843 int rc = 0; 2849 int rc = 0;
2844 2850
2845 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_NET); 2851#ifdef CONFIG_AUDIT
2852 struct lsm_network_audit net;
2853
2854 smk_ad_init_net(&ad, __func__, LSM_AUDIT_DATA_NET, &net);
2846 smk_ad_setfield_u_net_sk(&ad, other->sk); 2855 smk_ad_setfield_u_net_sk(&ad, other->sk);
2856#endif
2847 2857
2848 if (!capable(CAP_MAC_OVERRIDE)) 2858 if (!capable(CAP_MAC_OVERRIDE))
2849 rc = smk_access(ssp->smk_out, osp->smk_in, MAY_WRITE, &ad); 2859 rc = smk_access(ssp->smk_out, osp->smk_in, MAY_WRITE, &ad);
@@ -2990,6 +3000,9 @@ static int smack_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
2990 char *csp; 3000 char *csp;
2991 int rc; 3001 int rc;
2992 struct smk_audit_info ad; 3002 struct smk_audit_info ad;
3003#ifdef CONFIG_AUDIT
3004 struct lsm_network_audit net;
3005#endif
2993 if (sk->sk_family != PF_INET && sk->sk_family != PF_INET6) 3006 if (sk->sk_family != PF_INET && sk->sk_family != PF_INET6)
2994 return 0; 3007 return 0;
2995 3008
@@ -3007,9 +3020,9 @@ static int smack_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
3007 netlbl_secattr_destroy(&secattr); 3020 netlbl_secattr_destroy(&secattr);
3008 3021
3009#ifdef CONFIG_AUDIT 3022#ifdef CONFIG_AUDIT
3010 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_NET); 3023 smk_ad_init_net(&ad, __func__, LSM_AUDIT_DATA_NET, &net);
3011 ad.a.u.net.family = sk->sk_family; 3024 ad.a.u.net->family = sk->sk_family;
3012 ad.a.u.net.netif = skb->skb_iif; 3025 ad.a.u.net->netif = skb->skb_iif;
3013 ipv4_skb_to_auditdata(skb, &ad.a, NULL); 3026 ipv4_skb_to_auditdata(skb, &ad.a, NULL);
3014#endif 3027#endif
3015 /* 3028 /*
@@ -3152,6 +3165,9 @@ static int smack_inet_conn_request(struct sock *sk, struct sk_buff *skb,
3152 char *sp; 3165 char *sp;
3153 int rc; 3166 int rc;
3154 struct smk_audit_info ad; 3167 struct smk_audit_info ad;
3168#ifdef CONFIG_AUDIT
3169 struct lsm_network_audit net;
3170#endif
3155 3171
3156 /* handle mapped IPv4 packets arriving via IPv6 sockets */ 3172 /* handle mapped IPv4 packets arriving via IPv6 sockets */
3157 if (family == PF_INET6 && skb->protocol == htons(ETH_P_IP)) 3173 if (family == PF_INET6 && skb->protocol == htons(ETH_P_IP))
@@ -3166,9 +3182,9 @@ static int smack_inet_conn_request(struct sock *sk, struct sk_buff *skb,
3166 netlbl_secattr_destroy(&secattr); 3182 netlbl_secattr_destroy(&secattr);
3167 3183
3168#ifdef CONFIG_AUDIT 3184#ifdef CONFIG_AUDIT
3169 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_NET); 3185 smk_ad_init_net(&ad, __func__, LSM_AUDIT_DATA_NET, &net);
3170 ad.a.u.net.family = family; 3186 ad.a.u.net->family = family;
3171 ad.a.u.net.netif = skb->skb_iif; 3187 ad.a.u.net->netif = skb->skb_iif;
3172 ipv4_skb_to_auditdata(skb, &ad.a, NULL); 3188 ipv4_skb_to_auditdata(skb, &ad.a, NULL);
3173#endif 3189#endif
3174 /* 3190 /*
@@ -3624,8 +3640,38 @@ struct security_operations smack_ops = {
3624}; 3640};
3625 3641
3626 3642
3627static __init void init_smack_know_list(void) 3643static __init void init_smack_known_list(void)
3628{ 3644{
3645 /*
3646 * Initialize CIPSO locks
3647 */
3648 spin_lock_init(&smack_known_huh.smk_cipsolock);
3649 spin_lock_init(&smack_known_hat.smk_cipsolock);
3650 spin_lock_init(&smack_known_star.smk_cipsolock);
3651 spin_lock_init(&smack_known_floor.smk_cipsolock);
3652 spin_lock_init(&smack_known_invalid.smk_cipsolock);
3653 spin_lock_init(&smack_known_web.smk_cipsolock);
3654 /*
3655 * Initialize rule list locks
3656 */
3657 mutex_init(&smack_known_huh.smk_rules_lock);
3658 mutex_init(&smack_known_hat.smk_rules_lock);
3659 mutex_init(&smack_known_floor.smk_rules_lock);
3660 mutex_init(&smack_known_star.smk_rules_lock);
3661 mutex_init(&smack_known_invalid.smk_rules_lock);
3662 mutex_init(&smack_known_web.smk_rules_lock);
3663 /*
3664 * Initialize rule lists
3665 */
3666 INIT_LIST_HEAD(&smack_known_huh.smk_rules);
3667 INIT_LIST_HEAD(&smack_known_hat.smk_rules);
3668 INIT_LIST_HEAD(&smack_known_star.smk_rules);
3669 INIT_LIST_HEAD(&smack_known_floor.smk_rules);
3670 INIT_LIST_HEAD(&smack_known_invalid.smk_rules);
3671 INIT_LIST_HEAD(&smack_known_web.smk_rules);
3672 /*
3673 * Create the known labels list
3674 */
3629 list_add(&smack_known_huh.list, &smack_known_list); 3675 list_add(&smack_known_huh.list, &smack_known_list);
3630 list_add(&smack_known_hat.list, &smack_known_list); 3676 list_add(&smack_known_hat.list, &smack_known_list);
3631 list_add(&smack_known_star.list, &smack_known_list); 3677 list_add(&smack_known_star.list, &smack_known_list);
@@ -3660,16 +3706,8 @@ static __init int smack_init(void)
3660 cred = (struct cred *) current->cred; 3706 cred = (struct cred *) current->cred;
3661 cred->security = tsp; 3707 cred->security = tsp;
3662 3708
3663 /* initialize the smack_know_list */ 3709 /* initialize the smack_known_list */
3664 init_smack_know_list(); 3710 init_smack_known_list();
3665 /*
3666 * Initialize locks
3667 */
3668 spin_lock_init(&smack_known_huh.smk_cipsolock);
3669 spin_lock_init(&smack_known_hat.smk_cipsolock);
3670 spin_lock_init(&smack_known_star.smk_cipsolock);
3671 spin_lock_init(&smack_known_floor.smk_cipsolock);
3672 spin_lock_init(&smack_known_invalid.smk_cipsolock);
3673 3711
3674 /* 3712 /*
3675 * Register with LSM 3713 * Register with LSM
diff --git a/security/smack/smackfs.c b/security/smack/smackfs.c
index 5c32f36ff706..038811cb7e62 100644
--- a/security/smack/smackfs.c
+++ b/security/smack/smackfs.c
@@ -1614,20 +1614,6 @@ static int __init init_smk_fs(void)
1614 smk_cipso_doi(); 1614 smk_cipso_doi();
1615 smk_unlbl_ambient(NULL); 1615 smk_unlbl_ambient(NULL);
1616 1616
1617 mutex_init(&smack_known_floor.smk_rules_lock);
1618 mutex_init(&smack_known_hat.smk_rules_lock);
1619 mutex_init(&smack_known_huh.smk_rules_lock);
1620 mutex_init(&smack_known_invalid.smk_rules_lock);
1621 mutex_init(&smack_known_star.smk_rules_lock);
1622 mutex_init(&smack_known_web.smk_rules_lock);
1623
1624 INIT_LIST_HEAD(&smack_known_floor.smk_rules);
1625 INIT_LIST_HEAD(&smack_known_hat.smk_rules);
1626 INIT_LIST_HEAD(&smack_known_huh.smk_rules);
1627 INIT_LIST_HEAD(&smack_known_invalid.smk_rules);
1628 INIT_LIST_HEAD(&smack_known_star.smk_rules);
1629 INIT_LIST_HEAD(&smack_known_web.smk_rules);
1630
1631 return err; 1617 return err;
1632} 1618}
1633 1619
diff --git a/sound/pci/Kconfig b/sound/pci/Kconfig
index 88168044375f..5ca0939e4223 100644
--- a/sound/pci/Kconfig
+++ b/sound/pci/Kconfig
@@ -2,8 +2,8 @@
2 2
3config SND_TEA575X 3config SND_TEA575X
4 tristate 4 tristate
5 depends on SND_FM801_TEA575X_BOOL || SND_ES1968_RADIO || RADIO_SF16FMR2 5 depends on SND_FM801_TEA575X_BOOL || SND_ES1968_RADIO || RADIO_SF16FMR2 || RADIO_MAXIRADIO
6 default SND_FM801 || SND_ES1968 || RADIO_SF16FMR2 6 default SND_FM801 || SND_ES1968 || RADIO_SF16FMR2 || RADIO_MAXIRADIO
7 7
8menuconfig SND_PCI 8menuconfig SND_PCI
9 bool "PCI sound devices" 9 bool "PCI sound devices"
diff --git a/sound/soc/Kconfig b/sound/soc/Kconfig
index 91c985599d32..40b2ad1bb1cd 100644
--- a/sound/soc/Kconfig
+++ b/sound/soc/Kconfig
@@ -35,7 +35,6 @@ source "sound/soc/blackfin/Kconfig"
35source "sound/soc/davinci/Kconfig" 35source "sound/soc/davinci/Kconfig"
36source "sound/soc/ep93xx/Kconfig" 36source "sound/soc/ep93xx/Kconfig"
37source "sound/soc/fsl/Kconfig" 37source "sound/soc/fsl/Kconfig"
38source "sound/soc/imx/Kconfig"
39source "sound/soc/jz4740/Kconfig" 38source "sound/soc/jz4740/Kconfig"
40source "sound/soc/nuc900/Kconfig" 39source "sound/soc/nuc900/Kconfig"
41source "sound/soc/omap/Kconfig" 40source "sound/soc/omap/Kconfig"
@@ -48,9 +47,13 @@ source "sound/soc/s6000/Kconfig"
48source "sound/soc/sh/Kconfig" 47source "sound/soc/sh/Kconfig"
49source "sound/soc/tegra/Kconfig" 48source "sound/soc/tegra/Kconfig"
50source "sound/soc/txx9/Kconfig" 49source "sound/soc/txx9/Kconfig"
50source "sound/soc/ux500/Kconfig"
51 51
52# Supported codecs 52# Supported codecs
53source "sound/soc/codecs/Kconfig" 53source "sound/soc/codecs/Kconfig"
54 54
55# generic frame-work
56source "sound/soc/generic/Kconfig"
57
55endif # SND_SOC 58endif # SND_SOC
56 59
diff --git a/sound/soc/Makefile b/sound/soc/Makefile
index 2feaf376e94b..70990f4017f4 100644
--- a/sound/soc/Makefile
+++ b/sound/soc/Makefile
@@ -6,13 +6,13 @@ obj-$(CONFIG_SND_SOC_DMAENGINE_PCM) += snd-soc-dmaengine-pcm.o
6 6
7obj-$(CONFIG_SND_SOC) += snd-soc-core.o 7obj-$(CONFIG_SND_SOC) += snd-soc-core.o
8obj-$(CONFIG_SND_SOC) += codecs/ 8obj-$(CONFIG_SND_SOC) += codecs/
9obj-$(CONFIG_SND_SOC) += generic/
9obj-$(CONFIG_SND_SOC) += atmel/ 10obj-$(CONFIG_SND_SOC) += atmel/
10obj-$(CONFIG_SND_SOC) += au1x/ 11obj-$(CONFIG_SND_SOC) += au1x/
11obj-$(CONFIG_SND_SOC) += blackfin/ 12obj-$(CONFIG_SND_SOC) += blackfin/
12obj-$(CONFIG_SND_SOC) += davinci/ 13obj-$(CONFIG_SND_SOC) += davinci/
13obj-$(CONFIG_SND_SOC) += ep93xx/ 14obj-$(CONFIG_SND_SOC) += ep93xx/
14obj-$(CONFIG_SND_SOC) += fsl/ 15obj-$(CONFIG_SND_SOC) += fsl/
15obj-$(CONFIG_SND_SOC) += imx/
16obj-$(CONFIG_SND_SOC) += jz4740/ 16obj-$(CONFIG_SND_SOC) += jz4740/
17obj-$(CONFIG_SND_SOC) += mid-x86/ 17obj-$(CONFIG_SND_SOC) += mid-x86/
18obj-$(CONFIG_SND_SOC) += mxs/ 18obj-$(CONFIG_SND_SOC) += mxs/
@@ -25,3 +25,4 @@ obj-$(CONFIG_SND_SOC) += s6000/
25obj-$(CONFIG_SND_SOC) += sh/ 25obj-$(CONFIG_SND_SOC) += sh/
26obj-$(CONFIG_SND_SOC) += tegra/ 26obj-$(CONFIG_SND_SOC) += tegra/
27obj-$(CONFIG_SND_SOC) += txx9/ 27obj-$(CONFIG_SND_SOC) += txx9/
28obj-$(CONFIG_SND_SOC) += ux500/
diff --git a/sound/soc/blackfin/bf5xx-ssm2602.c b/sound/soc/blackfin/bf5xx-ssm2602.c
index b39ad356b92b..7dbeef1099b4 100644
--- a/sound/soc/blackfin/bf5xx-ssm2602.c
+++ b/sound/soc/blackfin/bf5xx-ssm2602.c
@@ -44,16 +44,8 @@
44 44
45static struct snd_soc_card bf5xx_ssm2602; 45static struct snd_soc_card bf5xx_ssm2602;
46 46
47static int bf5xx_ssm2602_hw_params(struct snd_pcm_substream *substream, 47static int bf5xx_ssm2602_dai_init(struct snd_soc_pcm_runtime *rtd)
48 struct snd_pcm_hw_params *params)
49{ 48{
50 struct snd_soc_pcm_runtime *rtd = substream->private_data;
51 struct snd_soc_dai *codec_dai = rtd->codec_dai;
52 unsigned int clk = 0;
53 int ret = 0;
54
55 pr_debug("%s rate %d format %x\n", __func__, params_rate(params),
56 params_format(params));
57 /* 49 /*
58 * If you are using a crystal source which frequency is not 12MHz 50 * If you are using a crystal source which frequency is not 12MHz
59 * then modify the below case statement with frequency of the crystal. 51 * then modify the below case statement with frequency of the crystal.
@@ -61,31 +53,10 @@ static int bf5xx_ssm2602_hw_params(struct snd_pcm_substream *substream,
61 * If you are using the SPORT to generate clocking then this is 53 * If you are using the SPORT to generate clocking then this is
62 * where to do it. 54 * where to do it.
63 */ 55 */
64 56 return snd_soc_dai_set_sysclk(rtd->codec_dai, SSM2602_SYSCLK, 12000000,
65 switch (params_rate(params)) {
66 case 8000:
67 case 16000:
68 case 48000:
69 case 96000:
70 case 11025:
71 case 22050:
72 case 44100:
73 clk = 12000000;
74 break;
75 }
76
77 ret = snd_soc_dai_set_sysclk(codec_dai, SSM2602_SYSCLK, clk,
78 SND_SOC_CLOCK_IN); 57 SND_SOC_CLOCK_IN);
79 if (ret < 0)
80 return ret;
81
82 return 0;
83} 58}
84 59
85static struct snd_soc_ops bf5xx_ssm2602_ops = {
86 .hw_params = bf5xx_ssm2602_hw_params,
87};
88
89/* CODEC is master for BCLK and LRC in this configuration. */ 60/* CODEC is master for BCLK and LRC in this configuration. */
90#define BF5XX_SSM2602_DAIFMT (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | \ 61#define BF5XX_SSM2602_DAIFMT (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | \
91 SND_SOC_DAIFMT_CBM_CFM) 62 SND_SOC_DAIFMT_CBM_CFM)
@@ -98,7 +69,7 @@ static struct snd_soc_dai_link bf5xx_ssm2602_dai[] = {
98 .codec_dai_name = "ssm2602-hifi", 69 .codec_dai_name = "ssm2602-hifi",
99 .platform_name = "bfin-i2s-pcm-audio", 70 .platform_name = "bfin-i2s-pcm-audio",
100 .codec_name = "ssm2602.0-001b", 71 .codec_name = "ssm2602.0-001b",
101 .ops = &bf5xx_ssm2602_ops, 72 .init = bf5xx_ssm2602_dai_init,
102 .dai_fmt = BF5XX_SSM2602_DAIFMT, 73 .dai_fmt = BF5XX_SSM2602_DAIFMT,
103 }, 74 },
104 { 75 {
@@ -108,7 +79,7 @@ static struct snd_soc_dai_link bf5xx_ssm2602_dai[] = {
108 .codec_dai_name = "ssm2602-hifi", 79 .codec_dai_name = "ssm2602-hifi",
109 .platform_name = "bfin-i2s-pcm-audio", 80 .platform_name = "bfin-i2s-pcm-audio",
110 .codec_name = "ssm2602.0-001b", 81 .codec_name = "ssm2602.0-001b",
111 .ops = &bf5xx_ssm2602_ops, 82 .init = bf5xx_ssm2602_dai_init,
112 .dai_fmt = BF5XX_SSM2602_DAIFMT, 83 .dai_fmt = BF5XX_SSM2602_DAIFMT,
113 }, 84 },
114}; 85};
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index 6508e8b790bb..22c686444633 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -29,6 +29,7 @@ config SND_SOC_ALL_CODECS
29 select SND_SOC_ALC5632 if I2C 29 select SND_SOC_ALC5632 if I2C
30 select SND_SOC_CQ0093VC if MFD_DAVINCI_VOICECODEC 30 select SND_SOC_CQ0093VC if MFD_DAVINCI_VOICECODEC
31 select SND_SOC_CS42L51 if I2C 31 select SND_SOC_CS42L51 if I2C
32 select SND_SOC_CS42L52 if I2C
32 select SND_SOC_CS42L73 if I2C 33 select SND_SOC_CS42L73 if I2C
33 select SND_SOC_CS4270 if I2C 34 select SND_SOC_CS4270 if I2C
34 select SND_SOC_CS4271 if SND_SOC_I2C_AND_SPI 35 select SND_SOC_CS4271 if SND_SOC_I2C_AND_SPI
@@ -37,11 +38,14 @@ config SND_SOC_ALL_CODECS
37 select SND_SOC_DFBMCS320 38 select SND_SOC_DFBMCS320
38 select SND_SOC_JZ4740_CODEC 39 select SND_SOC_JZ4740_CODEC
39 select SND_SOC_LM4857 if I2C 40 select SND_SOC_LM4857 if I2C
41 select SND_SOC_LM49453 if I2C
40 select SND_SOC_MAX98088 if I2C 42 select SND_SOC_MAX98088 if I2C
41 select SND_SOC_MAX98095 if I2C 43 select SND_SOC_MAX98095 if I2C
42 select SND_SOC_MAX9850 if I2C 44 select SND_SOC_MAX9850 if I2C
43 select SND_SOC_MAX9768 if I2C 45 select SND_SOC_MAX9768 if I2C
44 select SND_SOC_MAX9877 if I2C 46 select SND_SOC_MAX9877 if I2C
47 select SND_SOC_MC13783 if MFD_MC13XXX
48 select SND_SOC_ML26124 if I2C
45 select SND_SOC_PCM3008 49 select SND_SOC_PCM3008
46 select SND_SOC_RT5631 if I2C 50 select SND_SOC_RT5631 if I2C
47 select SND_SOC_SGTL5000 if I2C 51 select SND_SOC_SGTL5000 if I2C
@@ -57,7 +61,7 @@ config SND_SOC_ALL_CODECS
57 select SND_SOC_TPA6130A2 if I2C 61 select SND_SOC_TPA6130A2 if I2C
58 select SND_SOC_TLV320DAC33 if I2C 62 select SND_SOC_TLV320DAC33 if I2C
59 select SND_SOC_TWL4030 if TWL4030_CORE 63 select SND_SOC_TWL4030 if TWL4030_CORE
60 select SND_SOC_TWL6040 if TWL4030_CORE 64 select SND_SOC_TWL6040 if TWL6040_CORE
61 select SND_SOC_UDA134X 65 select SND_SOC_UDA134X
62 select SND_SOC_UDA1380 if I2C 66 select SND_SOC_UDA1380 if I2C
63 select SND_SOC_WL1273 if MFD_WL1273_CORE 67 select SND_SOC_WL1273 if MFD_WL1273_CORE
@@ -181,6 +185,9 @@ config SND_SOC_CQ0093VC
181config SND_SOC_CS42L51 185config SND_SOC_CS42L51
182 tristate 186 tristate
183 187
188config SND_SOC_CS42L52
189 tristate
190
184config SND_SOC_CS42L73 191config SND_SOC_CS42L73
185 tristate 192 tristate
186 193
@@ -217,6 +224,9 @@ config SND_SOC_DFBMCS320
217config SND_SOC_DMIC 224config SND_SOC_DMIC
218 tristate 225 tristate
219 226
227config SND_SOC_LM49453
228 tristate
229
220config SND_SOC_MAX98088 230config SND_SOC_MAX98088
221 tristate 231 tristate
222 232
@@ -276,7 +286,6 @@ config SND_SOC_TWL4030
276 tristate 286 tristate
277 287
278config SND_SOC_TWL6040 288config SND_SOC_TWL6040
279 select TWL6040_CORE
280 tristate 289 tristate
281 290
282config SND_SOC_UDA134X 291config SND_SOC_UDA134X
@@ -436,5 +445,11 @@ config SND_SOC_MAX9768
436config SND_SOC_MAX9877 445config SND_SOC_MAX9877
437 tristate 446 tristate
438 447
448config SND_SOC_MC13783
449 tristate
450
451config SND_SOC_ML26124
452 tristate
453
439config SND_SOC_TPA6130A2 454config SND_SOC_TPA6130A2
440 tristate 455 tristate
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index 6662eb0cdcc0..a9663e9c375b 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -15,6 +15,7 @@ snd-soc-ak4642-objs := ak4642.o
15snd-soc-ak4671-objs := ak4671.o 15snd-soc-ak4671-objs := ak4671.o
16snd-soc-cq93vc-objs := cq93vc.o 16snd-soc-cq93vc-objs := cq93vc.o
17snd-soc-cs42l51-objs := cs42l51.o 17snd-soc-cs42l51-objs := cs42l51.o
18snd-soc-cs42l52-objs := cs42l52.o
18snd-soc-cs42l73-objs := cs42l73.o 19snd-soc-cs42l73-objs := cs42l73.o
19snd-soc-cs4270-objs := cs4270.o 20snd-soc-cs4270-objs := cs4270.o
20snd-soc-cs4271-objs := cs4271.o 21snd-soc-cs4271-objs := cs4271.o
@@ -25,10 +26,13 @@ snd-soc-dmic-objs := dmic.o
25snd-soc-jz4740-codec-objs := jz4740.o 26snd-soc-jz4740-codec-objs := jz4740.o
26snd-soc-l3-objs := l3.o 27snd-soc-l3-objs := l3.o
27snd-soc-lm4857-objs := lm4857.o 28snd-soc-lm4857-objs := lm4857.o
29snd-soc-lm49453-objs := lm49453.o
28snd-soc-max9768-objs := max9768.o 30snd-soc-max9768-objs := max9768.o
29snd-soc-max98088-objs := max98088.o 31snd-soc-max98088-objs := max98088.o
30snd-soc-max98095-objs := max98095.o 32snd-soc-max98095-objs := max98095.o
31snd-soc-max9850-objs := max9850.o 33snd-soc-max9850-objs := max9850.o
34snd-soc-mc13783-objs := mc13783.o
35snd-soc-ml26124-objs := ml26124.o
32snd-soc-pcm3008-objs := pcm3008.o 36snd-soc-pcm3008-objs := pcm3008.o
33snd-soc-rt5631-objs := rt5631.o 37snd-soc-rt5631-objs := rt5631.o
34snd-soc-sgtl5000-objs := sgtl5000.o 38snd-soc-sgtl5000-objs := sgtl5000.o
@@ -121,6 +125,7 @@ obj-$(CONFIG_SND_SOC_ALC5623) += snd-soc-alc5623.o
121obj-$(CONFIG_SND_SOC_ALC5632) += snd-soc-alc5632.o 125obj-$(CONFIG_SND_SOC_ALC5632) += snd-soc-alc5632.o
122obj-$(CONFIG_SND_SOC_CQ0093VC) += snd-soc-cq93vc.o 126obj-$(CONFIG_SND_SOC_CQ0093VC) += snd-soc-cq93vc.o
123obj-$(CONFIG_SND_SOC_CS42L51) += snd-soc-cs42l51.o 127obj-$(CONFIG_SND_SOC_CS42L51) += snd-soc-cs42l51.o
128obj-$(CONFIG_SND_SOC_CS42L52) += snd-soc-cs42l52.o
124obj-$(CONFIG_SND_SOC_CS42L73) += snd-soc-cs42l73.o 129obj-$(CONFIG_SND_SOC_CS42L73) += snd-soc-cs42l73.o
125obj-$(CONFIG_SND_SOC_CS4270) += snd-soc-cs4270.o 130obj-$(CONFIG_SND_SOC_CS4270) += snd-soc-cs4270.o
126obj-$(CONFIG_SND_SOC_CS4271) += snd-soc-cs4271.o 131obj-$(CONFIG_SND_SOC_CS4271) += snd-soc-cs4271.o
@@ -128,13 +133,16 @@ obj-$(CONFIG_SND_SOC_CX20442) += snd-soc-cx20442.o
128obj-$(CONFIG_SND_SOC_DA7210) += snd-soc-da7210.o 133obj-$(CONFIG_SND_SOC_DA7210) += snd-soc-da7210.o
129obj-$(CONFIG_SND_SOC_DFBMCS320) += snd-soc-dfbmcs320.o 134obj-$(CONFIG_SND_SOC_DFBMCS320) += snd-soc-dfbmcs320.o
130obj-$(CONFIG_SND_SOC_DMIC) += snd-soc-dmic.o 135obj-$(CONFIG_SND_SOC_DMIC) += snd-soc-dmic.o
136obj-$(CONFIG_SND_SOC_JZ4740_CODEC) += snd-soc-jz4740-codec.o
131obj-$(CONFIG_SND_SOC_L3) += snd-soc-l3.o 137obj-$(CONFIG_SND_SOC_L3) += snd-soc-l3.o
132obj-$(CONFIG_SND_SOC_LM4857) += snd-soc-lm4857.o 138obj-$(CONFIG_SND_SOC_LM4857) += snd-soc-lm4857.o
133obj-$(CONFIG_SND_SOC_JZ4740_CODEC) += snd-soc-jz4740-codec.o 139obj-$(CONFIG_SND_SOC_LM49453) += snd-soc-lm49453.o
134obj-$(CONFIG_SND_SOC_MAX9768) += snd-soc-max9768.o 140obj-$(CONFIG_SND_SOC_MAX9768) += snd-soc-max9768.o
135obj-$(CONFIG_SND_SOC_MAX98088) += snd-soc-max98088.o 141obj-$(CONFIG_SND_SOC_MAX98088) += snd-soc-max98088.o
136obj-$(CONFIG_SND_SOC_MAX98095) += snd-soc-max98095.o 142obj-$(CONFIG_SND_SOC_MAX98095) += snd-soc-max98095.o
137obj-$(CONFIG_SND_SOC_MAX9850) += snd-soc-max9850.o 143obj-$(CONFIG_SND_SOC_MAX9850) += snd-soc-max9850.o
144obj-$(CONFIG_SND_SOC_MC13783) += snd-soc-mc13783.o
145obj-$(CONFIG_SND_SOC_ML26124) += snd-soc-ml26124.o
138obj-$(CONFIG_SND_SOC_PCM3008) += snd-soc-pcm3008.o 146obj-$(CONFIG_SND_SOC_PCM3008) += snd-soc-pcm3008.o
139obj-$(CONFIG_SND_SOC_RT5631) += snd-soc-rt5631.o 147obj-$(CONFIG_SND_SOC_RT5631) += snd-soc-rt5631.o
140obj-$(CONFIG_SND_SOC_SGTL5000) += snd-soc-sgtl5000.o 148obj-$(CONFIG_SND_SOC_SGTL5000) += snd-soc-sgtl5000.o
diff --git a/sound/soc/codecs/ac97.c b/sound/soc/codecs/ac97.c
index 1bbad4c16d28..2023c749f232 100644
--- a/sound/soc/codecs/ac97.c
+++ b/sound/soc/codecs/ac97.c
@@ -26,13 +26,11 @@
26static int ac97_prepare(struct snd_pcm_substream *substream, 26static int ac97_prepare(struct snd_pcm_substream *substream,
27 struct snd_soc_dai *dai) 27 struct snd_soc_dai *dai)
28{ 28{
29 struct snd_pcm_runtime *runtime = substream->runtime; 29 struct snd_soc_codec *codec = dai->codec;
30 struct snd_soc_pcm_runtime *rtd = substream->private_data;
31 struct snd_soc_codec *codec = rtd->codec;
32 30
33 int reg = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ? 31 int reg = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
34 AC97_PCM_FRONT_DAC_RATE : AC97_PCM_LR_ADC_RATE; 32 AC97_PCM_FRONT_DAC_RATE : AC97_PCM_LR_ADC_RATE;
35 return snd_ac97_set_rate(codec->ac97, reg, runtime->rate); 33 return snd_ac97_set_rate(codec->ac97, reg, substream->runtime->rate);
36} 34}
37 35
38#define STD_AC97_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\ 36#define STD_AC97_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
diff --git a/sound/soc/codecs/ad1836.c b/sound/soc/codecs/ad1836.c
index 12e3b4118557..c67b50d8b317 100644
--- a/sound/soc/codecs/ad1836.c
+++ b/sound/soc/codecs/ad1836.c
@@ -162,9 +162,7 @@ static int ad1836_hw_params(struct snd_pcm_substream *substream,
162 struct snd_soc_dai *dai) 162 struct snd_soc_dai *dai)
163{ 163{
164 int word_len = 0; 164 int word_len = 0;
165 165 struct snd_soc_codec *codec = dai->codec;
166 struct snd_soc_pcm_runtime *rtd = substream->private_data;
167 struct snd_soc_codec *codec = rtd->codec;
168 166
169 /* bit size */ 167 /* bit size */
170 switch (params_format(params)) { 168 switch (params_format(params)) {
diff --git a/sound/soc/codecs/ad193x.c b/sound/soc/codecs/ad193x.c
index a4a6bef2c0bb..13e62be4f990 100644
--- a/sound/soc/codecs/ad193x.c
+++ b/sound/soc/codecs/ad193x.c
@@ -245,9 +245,7 @@ static int ad193x_hw_params(struct snd_pcm_substream *substream,
245 struct snd_soc_dai *dai) 245 struct snd_soc_dai *dai)
246{ 246{
247 int word_len = 0, master_rate = 0; 247 int word_len = 0, master_rate = 0;
248 248 struct snd_soc_codec *codec = dai->codec;
249 struct snd_soc_pcm_runtime *rtd = substream->private_data;
250 struct snd_soc_codec *codec = rtd->codec;
251 struct ad193x_priv *ad193x = snd_soc_codec_get_drvdata(codec); 249 struct ad193x_priv *ad193x = snd_soc_codec_get_drvdata(codec);
252 250
253 /* bit size */ 251 /* bit size */
diff --git a/sound/soc/codecs/adau1701.c b/sound/soc/codecs/adau1701.c
index 78e9ce48bb99..3d50fc8646b6 100644
--- a/sound/soc/codecs/adau1701.c
+++ b/sound/soc/codecs/adau1701.c
@@ -258,8 +258,7 @@ static int adau1701_set_playback_pcm_format(struct snd_soc_codec *codec,
258static int adau1701_hw_params(struct snd_pcm_substream *substream, 258static int adau1701_hw_params(struct snd_pcm_substream *substream,
259 struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) 259 struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
260{ 260{
261 struct snd_soc_pcm_runtime *rtd = substream->private_data; 261 struct snd_soc_codec *codec = dai->codec;
262 struct snd_soc_codec *codec = rtd->codec;
263 snd_pcm_format_t format; 262 snd_pcm_format_t format;
264 unsigned int val; 263 unsigned int val;
265 264
diff --git a/sound/soc/codecs/ak4104.c b/sound/soc/codecs/ak4104.c
index ceb96ecf5588..31d4483245d0 100644
--- a/sound/soc/codecs/ak4104.c
+++ b/sound/soc/codecs/ak4104.c
@@ -88,8 +88,7 @@ static int ak4104_hw_params(struct snd_pcm_substream *substream,
88 struct snd_pcm_hw_params *params, 88 struct snd_pcm_hw_params *params,
89 struct snd_soc_dai *dai) 89 struct snd_soc_dai *dai)
90{ 90{
91 struct snd_soc_pcm_runtime *rtd = substream->private_data; 91 struct snd_soc_codec *codec = dai->codec;
92 struct snd_soc_codec *codec = rtd->codec;
93 int val = 0; 92 int val = 0;
94 93
95 /* set the IEC958 bits: consumer mode, no copyright bit */ 94 /* set the IEC958 bits: consumer mode, no copyright bit */
diff --git a/sound/soc/codecs/ak4535.c b/sound/soc/codecs/ak4535.c
index 838ae8b22b50..618fdc30f73e 100644
--- a/sound/soc/codecs/ak4535.c
+++ b/sound/soc/codecs/ak4535.c
@@ -262,8 +262,7 @@ static int ak4535_hw_params(struct snd_pcm_substream *substream,
262 struct snd_pcm_hw_params *params, 262 struct snd_pcm_hw_params *params,
263 struct snd_soc_dai *dai) 263 struct snd_soc_dai *dai)
264{ 264{
265 struct snd_soc_pcm_runtime *rtd = substream->private_data; 265 struct snd_soc_codec *codec = dai->codec;
266 struct snd_soc_codec *codec = rtd->codec;
267 struct ak4535_priv *ak4535 = snd_soc_codec_get_drvdata(codec); 266 struct ak4535_priv *ak4535 = snd_soc_codec_get_drvdata(codec);
268 u8 mode2 = snd_soc_read(codec, AK4535_MODE2) & ~(0x3 << 5); 267 u8 mode2 = snd_soc_read(codec, AK4535_MODE2) & ~(0x3 << 5);
269 int rate = params_rate(params), fs = 256; 268 int rate = params_rate(params), fs = 256;
diff --git a/sound/soc/codecs/ak4641.c b/sound/soc/codecs/ak4641.c
index c4d165a4bddf..543a12f471be 100644
--- a/sound/soc/codecs/ak4641.c
+++ b/sound/soc/codecs/ak4641.c
@@ -296,8 +296,7 @@ static int ak4641_i2s_hw_params(struct snd_pcm_substream *substream,
296 struct snd_pcm_hw_params *params, 296 struct snd_pcm_hw_params *params,
297 struct snd_soc_dai *dai) 297 struct snd_soc_dai *dai)
298{ 298{
299 struct snd_soc_pcm_runtime *rtd = substream->private_data; 299 struct snd_soc_codec *codec = dai->codec;
300 struct snd_soc_codec *codec = rtd->codec;
301 struct ak4641_priv *ak4641 = snd_soc_codec_get_drvdata(codec); 300 struct ak4641_priv *ak4641 = snd_soc_codec_get_drvdata(codec);
302 int rate = params_rate(params), fs = 256; 301 int rate = params_rate(params), fs = 256;
303 u8 mode2; 302 u8 mode2;
@@ -517,67 +516,24 @@ static int ak4641_resume(struct snd_soc_codec *codec)
517 516
518static int ak4641_probe(struct snd_soc_codec *codec) 517static int ak4641_probe(struct snd_soc_codec *codec)
519{ 518{
520 struct ak4641_platform_data *pdata = codec->dev->platform_data;
521 int ret; 519 int ret;
522 520
523
524 if (pdata) {
525 if (gpio_is_valid(pdata->gpio_power)) {
526 ret = gpio_request_one(pdata->gpio_power,
527 GPIOF_OUT_INIT_LOW, "ak4641 power");
528 if (ret)
529 goto err_out;
530 }
531 if (gpio_is_valid(pdata->gpio_npdn)) {
532 ret = gpio_request_one(pdata->gpio_npdn,
533 GPIOF_OUT_INIT_LOW, "ak4641 npdn");
534 if (ret)
535 goto err_gpio;
536
537 udelay(1); /* > 150 ns */
538 gpio_set_value(pdata->gpio_npdn, 1);
539 }
540 }
541
542 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_I2C); 521 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_I2C);
543 if (ret != 0) { 522 if (ret != 0) {
544 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); 523 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
545 goto err_register; 524 return ret;
546 } 525 }
547 526
548 /* power on device */ 527 /* power on device */
549 ak4641_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 528 ak4641_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
550 529
551 return 0; 530 return 0;
552
553err_register:
554 if (pdata) {
555 if (gpio_is_valid(pdata->gpio_power))
556 gpio_set_value(pdata->gpio_power, 0);
557 if (gpio_is_valid(pdata->gpio_npdn))
558 gpio_free(pdata->gpio_npdn);
559 }
560err_gpio:
561 if (pdata && gpio_is_valid(pdata->gpio_power))
562 gpio_free(pdata->gpio_power);
563err_out:
564 return ret;
565} 531}
566 532
567static int ak4641_remove(struct snd_soc_codec *codec) 533static int ak4641_remove(struct snd_soc_codec *codec)
568{ 534{
569 struct ak4641_platform_data *pdata = codec->dev->platform_data;
570
571 ak4641_set_bias_level(codec, SND_SOC_BIAS_OFF); 535 ak4641_set_bias_level(codec, SND_SOC_BIAS_OFF);
572 536
573 if (pdata) {
574 if (gpio_is_valid(pdata->gpio_power)) {
575 gpio_set_value(pdata->gpio_power, 0);
576 gpio_free(pdata->gpio_power);
577 }
578 if (gpio_is_valid(pdata->gpio_npdn))
579 gpio_free(pdata->gpio_npdn);
580 }
581 return 0; 537 return 0;
582} 538}
583 539
@@ -604,6 +560,7 @@ static struct snd_soc_codec_driver soc_codec_dev_ak4641 = {
604static int __devinit ak4641_i2c_probe(struct i2c_client *i2c, 560static int __devinit ak4641_i2c_probe(struct i2c_client *i2c,
605 const struct i2c_device_id *id) 561 const struct i2c_device_id *id)
606{ 562{
563 struct ak4641_platform_data *pdata = i2c->dev.platform_data;
607 struct ak4641_priv *ak4641; 564 struct ak4641_priv *ak4641;
608 int ret; 565 int ret;
609 566
@@ -612,16 +569,62 @@ static int __devinit ak4641_i2c_probe(struct i2c_client *i2c,
612 if (!ak4641) 569 if (!ak4641)
613 return -ENOMEM; 570 return -ENOMEM;
614 571
572 if (pdata) {
573 if (gpio_is_valid(pdata->gpio_power)) {
574 ret = gpio_request_one(pdata->gpio_power,
575 GPIOF_OUT_INIT_LOW, "ak4641 power");
576 if (ret)
577 goto err_out;
578 }
579 if (gpio_is_valid(pdata->gpio_npdn)) {
580 ret = gpio_request_one(pdata->gpio_npdn,
581 GPIOF_OUT_INIT_LOW, "ak4641 npdn");
582 if (ret)
583 goto err_gpio;
584
585 udelay(1); /* > 150 ns */
586 gpio_set_value(pdata->gpio_npdn, 1);
587 }
588 }
589
615 i2c_set_clientdata(i2c, ak4641); 590 i2c_set_clientdata(i2c, ak4641);
616 591
617 ret = snd_soc_register_codec(&i2c->dev, &soc_codec_dev_ak4641, 592 ret = snd_soc_register_codec(&i2c->dev, &soc_codec_dev_ak4641,
618 ak4641_dai, ARRAY_SIZE(ak4641_dai)); 593 ak4641_dai, ARRAY_SIZE(ak4641_dai));
594 if (ret != 0)
595 goto err_gpio2;
596
597 return 0;
598
599err_gpio2:
600 if (pdata) {
601 if (gpio_is_valid(pdata->gpio_power))
602 gpio_set_value(pdata->gpio_power, 0);
603 if (gpio_is_valid(pdata->gpio_npdn))
604 gpio_free(pdata->gpio_npdn);
605 }
606err_gpio:
607 if (pdata && gpio_is_valid(pdata->gpio_power))
608 gpio_free(pdata->gpio_power);
609err_out:
619 return ret; 610 return ret;
620} 611}
621 612
622static int __devexit ak4641_i2c_remove(struct i2c_client *i2c) 613static int __devexit ak4641_i2c_remove(struct i2c_client *i2c)
623{ 614{
615 struct ak4641_platform_data *pdata = i2c->dev.platform_data;
616
624 snd_soc_unregister_codec(&i2c->dev); 617 snd_soc_unregister_codec(&i2c->dev);
618
619 if (pdata) {
620 if (gpio_is_valid(pdata->gpio_power)) {
621 gpio_set_value(pdata->gpio_power, 0);
622 gpio_free(pdata->gpio_power);
623 }
624 if (gpio_is_valid(pdata->gpio_npdn))
625 gpio_free(pdata->gpio_npdn);
626 }
627
625 return 0; 628 return 0;
626} 629}
627 630
@@ -641,23 +644,7 @@ static struct i2c_driver ak4641_i2c_driver = {
641 .id_table = ak4641_i2c_id, 644 .id_table = ak4641_i2c_id,
642}; 645};
643 646
644static int __init ak4641_modinit(void) 647module_i2c_driver(ak4641_i2c_driver);
645{
646 int ret;
647
648 ret = i2c_add_driver(&ak4641_i2c_driver);
649 if (ret != 0)
650 pr_err("Failed to register AK4641 I2C driver: %d\n", ret);
651
652 return ret;
653}
654module_init(ak4641_modinit);
655
656static void __exit ak4641_exit(void)
657{
658 i2c_del_driver(&ak4641_i2c_driver);
659}
660module_exit(ak4641_exit);
661 648
662MODULE_DESCRIPTION("SoC AK4641 driver"); 649MODULE_DESCRIPTION("SoC AK4641 driver");
663MODULE_AUTHOR("Harald Welte <laforge@gnufiish.org>"); 650MODULE_AUTHOR("Harald Welte <laforge@gnufiish.org>");
diff --git a/sound/soc/codecs/alc5623.c b/sound/soc/codecs/alc5623.c
index d47b62ddb210..1960478ce6bb 100644
--- a/sound/soc/codecs/alc5623.c
+++ b/sound/soc/codecs/alc5623.c
@@ -705,8 +705,7 @@ static int alc5623_set_dai_fmt(struct snd_soc_dai *codec_dai,
705static int alc5623_pcm_hw_params(struct snd_pcm_substream *substream, 705static int alc5623_pcm_hw_params(struct snd_pcm_substream *substream,
706 struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) 706 struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
707{ 707{
708 struct snd_soc_pcm_runtime *rtd = substream->private_data; 708 struct snd_soc_codec *codec = dai->codec;
709 struct snd_soc_codec *codec = rtd->codec;
710 struct alc5623_priv *alc5623 = snd_soc_codec_get_drvdata(codec); 709 struct alc5623_priv *alc5623 = snd_soc_codec_get_drvdata(codec);
711 int coeff, rate; 710 int coeff, rate;
712 u16 iface; 711 u16 iface;
@@ -1084,25 +1083,7 @@ static struct i2c_driver alc5623_i2c_driver = {
1084 .id_table = alc5623_i2c_table, 1083 .id_table = alc5623_i2c_table,
1085}; 1084};
1086 1085
1087static int __init alc5623_modinit(void) 1086module_i2c_driver(alc5623_i2c_driver);
1088{
1089 int ret;
1090
1091 ret = i2c_add_driver(&alc5623_i2c_driver);
1092 if (ret != 0) {
1093 printk(KERN_ERR "%s: can't add i2c driver", __func__);
1094 return ret;
1095 }
1096
1097 return ret;
1098}
1099module_init(alc5623_modinit);
1100
1101static void __exit alc5623_modexit(void)
1102{
1103 i2c_del_driver(&alc5623_i2c_driver);
1104}
1105module_exit(alc5623_modexit);
1106 1087
1107MODULE_DESCRIPTION("ASoC alc5621/2/3 driver"); 1088MODULE_DESCRIPTION("ASoC alc5621/2/3 driver");
1108MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>"); 1089MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>");
diff --git a/sound/soc/codecs/alc5632.c b/sound/soc/codecs/alc5632.c
index e2111e0ccad7..7dd02420b36d 100644
--- a/sound/soc/codecs/alc5632.c
+++ b/sound/soc/codecs/alc5632.c
@@ -861,8 +861,7 @@ static int alc5632_set_dai_fmt(struct snd_soc_dai *codec_dai,
861static int alc5632_pcm_hw_params(struct snd_pcm_substream *substream, 861static int alc5632_pcm_hw_params(struct snd_pcm_substream *substream,
862 struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) 862 struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
863{ 863{
864 struct snd_soc_pcm_runtime *rtd = substream->private_data; 864 struct snd_soc_codec *codec = dai->codec;
865 struct snd_soc_codec *codec = rtd->codec;
866 int coeff, rate; 865 int coeff, rate;
867 u16 iface; 866 u16 iface;
868 867
@@ -1131,7 +1130,7 @@ static __devinit int alc5632_i2c_probe(struct i2c_client *client,
1131 1130
1132 i2c_set_clientdata(client, alc5632); 1131 i2c_set_clientdata(client, alc5632);
1133 1132
1134 alc5632->regmap = regmap_init_i2c(client, &alc5632_regmap); 1133 alc5632->regmap = devm_regmap_init_i2c(client, &alc5632_regmap);
1135 if (IS_ERR(alc5632->regmap)) { 1134 if (IS_ERR(alc5632->regmap)) {
1136 ret = PTR_ERR(alc5632->regmap); 1135 ret = PTR_ERR(alc5632->regmap);
1137 dev_err(&client->dev, "regmap_init() failed: %d\n", ret); 1136 dev_err(&client->dev, "regmap_init() failed: %d\n", ret);
@@ -1143,7 +1142,6 @@ static __devinit int alc5632_i2c_probe(struct i2c_client *client,
1143 if (ret1 != 0 || ret2 != 0) { 1142 if (ret1 != 0 || ret2 != 0) {
1144 dev_err(&client->dev, 1143 dev_err(&client->dev,
1145 "Failed to read chip ID: ret1=%d, ret2=%d\n", ret1, ret2); 1144 "Failed to read chip ID: ret1=%d, ret2=%d\n", ret1, ret2);
1146 regmap_exit(alc5632->regmap);
1147 return -EIO; 1145 return -EIO;
1148 } 1146 }
1149 1147
@@ -1152,14 +1150,12 @@ static __devinit int alc5632_i2c_probe(struct i2c_client *client,
1152 if ((vid1 != 0x10EC) || (vid2 != id->driver_data)) { 1150 if ((vid1 != 0x10EC) || (vid2 != id->driver_data)) {
1153 dev_err(&client->dev, 1151 dev_err(&client->dev,
1154 "Device is not a ALC5632: VID1=0x%x, VID2=0x%x\n", vid1, vid2); 1152 "Device is not a ALC5632: VID1=0x%x, VID2=0x%x\n", vid1, vid2);
1155 regmap_exit(alc5632->regmap);
1156 return -EINVAL; 1153 return -EINVAL;
1157 } 1154 }
1158 1155
1159 ret = alc5632_reset(alc5632->regmap); 1156 ret = alc5632_reset(alc5632->regmap);
1160 if (ret < 0) { 1157 if (ret < 0) {
1161 dev_err(&client->dev, "Failed to issue reset\n"); 1158 dev_err(&client->dev, "Failed to issue reset\n");
1162 regmap_exit(alc5632->regmap);
1163 return ret; 1159 return ret;
1164 } 1160 }
1165 1161
@@ -1177,7 +1173,6 @@ static __devinit int alc5632_i2c_probe(struct i2c_client *client,
1177 1173
1178 if (ret < 0) { 1174 if (ret < 0) {
1179 dev_err(&client->dev, "Failed to register codec: %d\n", ret); 1175 dev_err(&client->dev, "Failed to register codec: %d\n", ret);
1180 regmap_exit(alc5632->regmap);
1181 return ret; 1176 return ret;
1182 } 1177 }
1183 1178
@@ -1186,9 +1181,7 @@ static __devinit int alc5632_i2c_probe(struct i2c_client *client,
1186 1181
1187static __devexit int alc5632_i2c_remove(struct i2c_client *client) 1182static __devexit int alc5632_i2c_remove(struct i2c_client *client)
1188{ 1183{
1189 struct alc5632_priv *alc5632 = i2c_get_clientdata(client);
1190 snd_soc_unregister_codec(&client->dev); 1184 snd_soc_unregister_codec(&client->dev);
1191 regmap_exit(alc5632->regmap);
1192 return 0; 1185 return 0;
1193} 1186}
1194 1187
@@ -1209,25 +1202,7 @@ static struct i2c_driver alc5632_i2c_driver = {
1209 .id_table = alc5632_i2c_table, 1202 .id_table = alc5632_i2c_table,
1210}; 1203};
1211 1204
1212static int __init alc5632_modinit(void) 1205module_i2c_driver(alc5632_i2c_driver);
1213{
1214 int ret;
1215
1216 ret = i2c_add_driver(&alc5632_i2c_driver);
1217 if (ret != 0) {
1218 printk(KERN_ERR "%s: can't add i2c driver", __func__);
1219 return ret;
1220 }
1221
1222 return ret;
1223}
1224module_init(alc5632_modinit);
1225
1226static void __exit alc5632_modexit(void)
1227{
1228 i2c_del_driver(&alc5632_i2c_driver);
1229}
1230module_exit(alc5632_modexit);
1231 1206
1232MODULE_DESCRIPTION("ASoC ALC5632 driver"); 1207MODULE_DESCRIPTION("ASoC ALC5632 driver");
1233MODULE_AUTHOR("Leon Romanovsky <leon@leon.nu>"); 1208MODULE_AUTHOR("Leon Romanovsky <leon@leon.nu>");
diff --git a/sound/soc/codecs/cs4270.c b/sound/soc/codecs/cs4270.c
index 1d672f528662..047917f0b8ae 100644
--- a/sound/soc/codecs/cs4270.c
+++ b/sound/soc/codecs/cs4270.c
@@ -307,8 +307,7 @@ static int cs4270_hw_params(struct snd_pcm_substream *substream,
307 struct snd_pcm_hw_params *params, 307 struct snd_pcm_hw_params *params,
308 struct snd_soc_dai *dai) 308 struct snd_soc_dai *dai)
309{ 309{
310 struct snd_soc_pcm_runtime *rtd = substream->private_data; 310 struct snd_soc_codec *codec = dai->codec;
311 struct snd_soc_codec *codec = rtd->codec;
312 struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec); 311 struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec);
313 int ret; 312 int ret;
314 unsigned int i; 313 unsigned int i;
@@ -600,10 +599,12 @@ static int cs4270_soc_suspend(struct snd_soc_codec *codec)
600static int cs4270_soc_resume(struct snd_soc_codec *codec) 599static int cs4270_soc_resume(struct snd_soc_codec *codec)
601{ 600{
602 struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec); 601 struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec);
603 int reg; 602 int reg, ret;
604 603
605 regulator_bulk_enable(ARRAY_SIZE(cs4270->supplies), 604 ret = regulator_bulk_enable(ARRAY_SIZE(cs4270->supplies),
606 cs4270->supplies); 605 cs4270->supplies);
606 if (ret != 0)
607 return ret;
607 608
608 /* In case the device was put to hard reset during sleep, we need to 609 /* In case the device was put to hard reset during sleep, we need to
609 * wait 500ns here before any I2C communication. */ 610 * wait 500ns here before any I2C communication. */
diff --git a/sound/soc/codecs/cs4271.c b/sound/soc/codecs/cs4271.c
index bf7141280a74..9eb01d7d58a3 100644
--- a/sound/soc/codecs/cs4271.c
+++ b/sound/soc/codecs/cs4271.c
@@ -318,8 +318,7 @@ static int cs4271_hw_params(struct snd_pcm_substream *substream,
318 struct snd_pcm_hw_params *params, 318 struct snd_pcm_hw_params *params,
319 struct snd_soc_dai *dai) 319 struct snd_soc_dai *dai)
320{ 320{
321 struct snd_soc_pcm_runtime *rtd = substream->private_data; 321 struct snd_soc_codec *codec = dai->codec;
322 struct snd_soc_codec *codec = rtd->codec;
323 struct cs4271_private *cs4271 = snd_soc_codec_get_drvdata(codec); 322 struct cs4271_private *cs4271 = snd_soc_codec_get_drvdata(codec);
324 int i, ret; 323 int i, ret;
325 unsigned int ratio, val; 324 unsigned int ratio, val;
diff --git a/sound/soc/codecs/cs42l51.c b/sound/soc/codecs/cs42l51.c
index a8bf588e8740..091d0193f507 100644
--- a/sound/soc/codecs/cs42l51.c
+++ b/sound/soc/codecs/cs42l51.c
@@ -141,15 +141,15 @@ static const struct soc_enum cs42l51_chan_mix =
141static const struct snd_kcontrol_new cs42l51_snd_controls[] = { 141static const struct snd_kcontrol_new cs42l51_snd_controls[] = {
142 SOC_DOUBLE_R_SX_TLV("PCM Playback Volume", 142 SOC_DOUBLE_R_SX_TLV("PCM Playback Volume",
143 CS42L51_PCMA_VOL, CS42L51_PCMB_VOL, 143 CS42L51_PCMA_VOL, CS42L51_PCMB_VOL,
144 7, 0xffffff99, 0x18, adc_pcm_tlv), 144 6, 0x19, 0x7F, adc_pcm_tlv),
145 SOC_DOUBLE_R("PCM Playback Switch", 145 SOC_DOUBLE_R("PCM Playback Switch",
146 CS42L51_PCMA_VOL, CS42L51_PCMB_VOL, 7, 1, 1), 146 CS42L51_PCMA_VOL, CS42L51_PCMB_VOL, 7, 1, 1),
147 SOC_DOUBLE_R_SX_TLV("Analog Playback Volume", 147 SOC_DOUBLE_R_SX_TLV("Analog Playback Volume",
148 CS42L51_AOUTA_VOL, CS42L51_AOUTB_VOL, 148 CS42L51_AOUTA_VOL, CS42L51_AOUTB_VOL,
149 8, 0xffffff19, 0x18, aout_tlv), 149 0, 0x34, 0xE4, aout_tlv),
150 SOC_DOUBLE_R_SX_TLV("ADC Mixer Volume", 150 SOC_DOUBLE_R_SX_TLV("ADC Mixer Volume",
151 CS42L51_ADCA_VOL, CS42L51_ADCB_VOL, 151 CS42L51_ADCA_VOL, CS42L51_ADCB_VOL,
152 7, 0xffffff99, 0x18, adc_pcm_tlv), 152 6, 0x19, 0x7F, adc_pcm_tlv),
153 SOC_DOUBLE_R("ADC Mixer Switch", 153 SOC_DOUBLE_R("ADC Mixer Switch",
154 CS42L51_ADCA_VOL, CS42L51_ADCB_VOL, 7, 1, 1), 154 CS42L51_ADCA_VOL, CS42L51_ADCB_VOL, 7, 1, 1),
155 SOC_SINGLE("Playback Deemphasis Switch", CS42L51_DAC_CTL, 3, 1, 0), 155 SOC_SINGLE("Playback Deemphasis Switch", CS42L51_DAC_CTL, 3, 1, 0),
@@ -356,8 +356,7 @@ static int cs42l51_hw_params(struct snd_pcm_substream *substream,
356 struct snd_pcm_hw_params *params, 356 struct snd_pcm_hw_params *params,
357 struct snd_soc_dai *dai) 357 struct snd_soc_dai *dai)
358{ 358{
359 struct snd_soc_pcm_runtime *rtd = substream->private_data; 359 struct snd_soc_codec *codec = dai->codec;
360 struct snd_soc_codec *codec = rtd->codec;
361 struct cs42l51_private *cs42l51 = snd_soc_codec_get_drvdata(codec); 360 struct cs42l51_private *cs42l51 = snd_soc_codec_get_drvdata(codec);
362 int ret; 361 int ret;
363 unsigned int i; 362 unsigned int i;
diff --git a/sound/soc/codecs/cs42l52.c b/sound/soc/codecs/cs42l52.c
new file mode 100644
index 000000000000..a7109413aef1
--- /dev/null
+++ b/sound/soc/codecs/cs42l52.c
@@ -0,0 +1,1295 @@
1/*
2 * cs42l52.c -- CS42L52 ALSA SoC audio driver
3 *
4 * Copyright 2012 CirrusLogic, Inc.
5 *
6 * Author: Georgi Vlaev <joe@nucleusys.com>
7 * Author: Brian Austin <brian.austin@cirrus.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 *
13 */
14
15#include <linux/module.h>
16#include <linux/moduleparam.h>
17#include <linux/version.h>
18#include <linux/kernel.h>
19#include <linux/init.h>
20#include <linux/delay.h>
21#include <linux/pm.h>
22#include <linux/i2c.h>
23#include <linux/input.h>
24#include <linux/regmap.h>
25#include <linux/slab.h>
26#include <linux/workqueue.h>
27#include <linux/platform_device.h>
28#include <linux/slab.h>
29#include <sound/core.h>
30#include <sound/pcm.h>
31#include <sound/pcm_params.h>
32#include <sound/soc.h>
33#include <sound/soc-dapm.h>
34#include <sound/initval.h>
35#include <sound/tlv.h>
36#include <sound/cs42l52.h>
37#include "cs42l52.h"
38
39struct sp_config {
40 u8 spc, format, spfs;
41 u32 srate;
42};
43
44struct cs42l52_private {
45 struct regmap *regmap;
46 struct snd_soc_codec *codec;
47 struct device *dev;
48 struct sp_config config;
49 struct cs42l52_platform_data pdata;
50 u32 sysclk;
51 u8 mclksel;
52 u32 mclk;
53 u8 flags;
54#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
55 struct input_dev *beep;
56 struct work_struct beep_work;
57 int beep_rate;
58#endif
59};
60
61static const struct reg_default cs42l52_reg_defaults[] = {
62 { CS42L52_PWRCTL1, 0x9F }, /* r02 PWRCTL 1 */
63 { CS42L52_PWRCTL2, 0x07 }, /* r03 PWRCTL 2 */
64 { CS42L52_PWRCTL3, 0xFF }, /* r04 PWRCTL 3 */
65 { CS42L52_CLK_CTL, 0xA0 }, /* r05 Clocking Ctl */
66 { CS42L52_IFACE_CTL1, 0x00 }, /* r06 Interface Ctl 1 */
67 { CS42L52_ADC_PGA_A, 0x80 }, /* r08 Input A Select */
68 { CS42L52_ADC_PGA_B, 0x80 }, /* r09 Input B Select */
69 { CS42L52_ANALOG_HPF_CTL, 0xA5 }, /* r0A Analog HPF Ctl */
70 { CS42L52_ADC_HPF_FREQ, 0x00 }, /* r0B ADC HPF Corner Freq */
71 { CS42L52_ADC_MISC_CTL, 0x00 }, /* r0C Misc. ADC Ctl */
72 { CS42L52_PB_CTL1, 0x60 }, /* r0D Playback Ctl 1 */
73 { CS42L52_MISC_CTL, 0x02 }, /* r0E Misc. Ctl */
74 { CS42L52_PB_CTL2, 0x00 }, /* r0F Playback Ctl 2 */
75 { CS42L52_MICA_CTL, 0x00 }, /* r10 MICA Amp Ctl */
76 { CS42L52_MICB_CTL, 0x00 }, /* r11 MICB Amp Ctl */
77 { CS42L52_PGAA_CTL, 0x00 }, /* r12 PGAA Vol, Misc. */
78 { CS42L52_PGAB_CTL, 0x00 }, /* r13 PGAB Vol, Misc. */
79 { CS42L52_PASSTHRUA_VOL, 0x00 }, /* r14 Bypass A Vol */
80 { CS42L52_PASSTHRUB_VOL, 0x00 }, /* r15 Bypass B Vol */
81 { CS42L52_ADCA_VOL, 0x00 }, /* r16 ADCA Volume */
82 { CS42L52_ADCB_VOL, 0x00 }, /* r17 ADCB Volume */
83 { CS42L52_ADCA_MIXER_VOL, 0x80 }, /* r18 ADCA Mixer Volume */
84 { CS42L52_ADCB_MIXER_VOL, 0x80 }, /* r19 ADCB Mixer Volume */
85 { CS42L52_PCMA_MIXER_VOL, 0x00 }, /* r1A PCMA Mixer Volume */
86 { CS42L52_PCMB_MIXER_VOL, 0x00 }, /* r1B PCMB Mixer Volume */
87 { CS42L52_BEEP_FREQ, 0x00 }, /* r1C Beep Freq on Time */
88 { CS42L52_BEEP_VOL, 0x00 }, /* r1D Beep Volume off Time */
89 { CS42L52_BEEP_TONE_CTL, 0x00 }, /* r1E Beep Tone Cfg. */
90 { CS42L52_TONE_CTL, 0x00 }, /* r1F Tone Ctl */
91 { CS42L52_MASTERA_VOL, 0x88 }, /* r20 Master A Volume */
92 { CS42L52_MASTERB_VOL, 0x00 }, /* r21 Master B Volume */
93 { CS42L52_HPA_VOL, 0x00 }, /* r22 Headphone A Volume */
94 { CS42L52_HPB_VOL, 0x00 }, /* r23 Headphone B Volume */
95 { CS42L52_SPKA_VOL, 0x00 }, /* r24 Speaker A Volume */
96 { CS42L52_SPKB_VOL, 0x00 }, /* r25 Speaker B Volume */
97 { CS42L52_ADC_PCM_MIXER, 0x00 }, /* r26 Channel Mixer and Swap */
98 { CS42L52_LIMITER_CTL1, 0x00 }, /* r27 Limit Ctl 1 Thresholds */
99 { CS42L52_LIMITER_CTL2, 0x7F }, /* r28 Limit Ctl 2 Release Rate */
100 { CS42L52_LIMITER_AT_RATE, 0xC0 }, /* r29 Limiter Attack Rate */
101 { CS42L52_ALC_CTL, 0x00 }, /* r2A ALC Ctl 1 Attack Rate */
102 { CS42L52_ALC_RATE, 0x3F }, /* r2B ALC Release Rate */
103 { CS42L52_ALC_THRESHOLD, 0x3f }, /* r2C ALC Thresholds */
104 { CS42L52_NOISE_GATE_CTL, 0x00 }, /* r2D Noise Gate Ctl */
105 { CS42L52_CLK_STATUS, 0x00 }, /* r2E Overflow and Clock Status */
106 { CS42L52_BATT_COMPEN, 0x00 }, /* r2F battery Compensation */
107 { CS42L52_BATT_LEVEL, 0x00 }, /* r30 VP Battery Level */
108 { CS42L52_SPK_STATUS, 0x00 }, /* r31 Speaker Status */
109 { CS42L52_TEM_CTL, 0x3B }, /* r32 Temp Ctl */
110 { CS42L52_THE_FOLDBACK, 0x00 }, /* r33 Foldback */
111};
112
113static bool cs42l52_readable_register(struct device *dev, unsigned int reg)
114{
115 switch (reg) {
116 case CS42L52_CHIP:
117 case CS42L52_PWRCTL1:
118 case CS42L52_PWRCTL2:
119 case CS42L52_PWRCTL3:
120 case CS42L52_CLK_CTL:
121 case CS42L52_IFACE_CTL1:
122 case CS42L52_IFACE_CTL2:
123 case CS42L52_ADC_PGA_A:
124 case CS42L52_ADC_PGA_B:
125 case CS42L52_ANALOG_HPF_CTL:
126 case CS42L52_ADC_HPF_FREQ:
127 case CS42L52_ADC_MISC_CTL:
128 case CS42L52_PB_CTL1:
129 case CS42L52_MISC_CTL:
130 case CS42L52_PB_CTL2:
131 case CS42L52_MICA_CTL:
132 case CS42L52_MICB_CTL:
133 case CS42L52_PGAA_CTL:
134 case CS42L52_PGAB_CTL:
135 case CS42L52_PASSTHRUA_VOL:
136 case CS42L52_PASSTHRUB_VOL:
137 case CS42L52_ADCA_VOL:
138 case CS42L52_ADCB_VOL:
139 case CS42L52_ADCA_MIXER_VOL:
140 case CS42L52_ADCB_MIXER_VOL:
141 case CS42L52_PCMA_MIXER_VOL:
142 case CS42L52_PCMB_MIXER_VOL:
143 case CS42L52_BEEP_FREQ:
144 case CS42L52_BEEP_VOL:
145 case CS42L52_BEEP_TONE_CTL:
146 case CS42L52_TONE_CTL:
147 case CS42L52_MASTERA_VOL:
148 case CS42L52_MASTERB_VOL:
149 case CS42L52_HPA_VOL:
150 case CS42L52_HPB_VOL:
151 case CS42L52_SPKA_VOL:
152 case CS42L52_SPKB_VOL:
153 case CS42L52_ADC_PCM_MIXER:
154 case CS42L52_LIMITER_CTL1:
155 case CS42L52_LIMITER_CTL2:
156 case CS42L52_LIMITER_AT_RATE:
157 case CS42L52_ALC_CTL:
158 case CS42L52_ALC_RATE:
159 case CS42L52_ALC_THRESHOLD:
160 case CS42L52_NOISE_GATE_CTL:
161 case CS42L52_CLK_STATUS:
162 case CS42L52_BATT_COMPEN:
163 case CS42L52_BATT_LEVEL:
164 case CS42L52_SPK_STATUS:
165 case CS42L52_TEM_CTL:
166 case CS42L52_THE_FOLDBACK:
167 case CS42L52_CHARGE_PUMP:
168 return true;
169 default:
170 return false;
171 }
172}
173
174static bool cs42l52_volatile_register(struct device *dev, unsigned int reg)
175{
176 switch (reg) {
177 case CS42L52_IFACE_CTL2:
178 case CS42L52_CLK_STATUS:
179 case CS42L52_BATT_LEVEL:
180 case CS42L52_SPK_STATUS:
181 case CS42L52_CHARGE_PUMP:
182 return 1;
183 default:
184 return 0;
185 }
186}
187
188static DECLARE_TLV_DB_SCALE(hl_tlv, -10200, 50, 0);
189
190static DECLARE_TLV_DB_SCALE(hpd_tlv, -9600, 50, 1);
191
192static DECLARE_TLV_DB_SCALE(ipd_tlv, -9600, 100, 0);
193
194static DECLARE_TLV_DB_SCALE(mic_tlv, 1600, 100, 0);
195
196static DECLARE_TLV_DB_SCALE(pga_tlv, -600, 50, 0);
197
198static const unsigned int limiter_tlv[] = {
199 TLV_DB_RANGE_HEAD(2),
200 0, 2, TLV_DB_SCALE_ITEM(-3000, 600, 0),
201 3, 7, TLV_DB_SCALE_ITEM(-1200, 300, 0),
202};
203
204static const char * const cs42l52_adca_text[] = {
205 "Input1A", "Input2A", "Input3A", "Input4A", "PGA Input Left"};
206
207static const char * const cs42l52_adcb_text[] = {
208 "Input1B", "Input2B", "Input3B", "Input4B", "PGA Input Right"};
209
210static const struct soc_enum adca_enum =
211 SOC_ENUM_SINGLE(CS42L52_ADC_PGA_A, 5,
212 ARRAY_SIZE(cs42l52_adca_text), cs42l52_adca_text);
213
214static const struct soc_enum adcb_enum =
215 SOC_ENUM_SINGLE(CS42L52_ADC_PGA_B, 5,
216 ARRAY_SIZE(cs42l52_adcb_text), cs42l52_adcb_text);
217
218static const struct snd_kcontrol_new adca_mux =
219 SOC_DAPM_ENUM("Left ADC Input Capture Mux", adca_enum);
220
221static const struct snd_kcontrol_new adcb_mux =
222 SOC_DAPM_ENUM("Right ADC Input Capture Mux", adcb_enum);
223
224static const char * const mic_bias_level_text[] = {
225 "0.5 +VA", "0.6 +VA", "0.7 +VA",
226 "0.8 +VA", "0.83 +VA", "0.91 +VA"
227};
228
229static const struct soc_enum mic_bias_level_enum =
230 SOC_ENUM_SINGLE(CS42L52_IFACE_CTL1, 0,
231 ARRAY_SIZE(mic_bias_level_text), mic_bias_level_text);
232
233static const char * const cs42l52_mic_text[] = { "Single", "Differential" };
234
235static const struct soc_enum mica_enum =
236 SOC_ENUM_SINGLE(CS42L52_MICA_CTL, 5,
237 ARRAY_SIZE(cs42l52_mic_text), cs42l52_mic_text);
238
239static const struct soc_enum micb_enum =
240 SOC_ENUM_SINGLE(CS42L52_MICB_CTL, 5,
241 ARRAY_SIZE(cs42l52_mic_text), cs42l52_mic_text);
242
243static const struct snd_kcontrol_new mica_mux =
244 SOC_DAPM_ENUM("Left Mic Input Capture Mux", mica_enum);
245
246static const struct snd_kcontrol_new micb_mux =
247 SOC_DAPM_ENUM("Right Mic Input Capture Mux", micb_enum);
248
249static const char * const digital_output_mux_text[] = {"ADC", "DSP"};
250
251static const struct soc_enum digital_output_mux_enum =
252 SOC_ENUM_SINGLE(CS42L52_ADC_MISC_CTL, 6,
253 ARRAY_SIZE(digital_output_mux_text),
254 digital_output_mux_text);
255
256static const struct snd_kcontrol_new digital_output_mux =
257 SOC_DAPM_ENUM("Digital Output Mux", digital_output_mux_enum);
258
259static const char * const hp_gain_num_text[] = {
260 "0.3959", "0.4571", "0.5111", "0.6047",
261 "0.7099", "0.8399", "1.000", "1.1430"
262};
263
264static const struct soc_enum hp_gain_enum =
265 SOC_ENUM_SINGLE(CS42L52_PB_CTL1, 4,
266 ARRAY_SIZE(hp_gain_num_text), hp_gain_num_text);
267
268static const char * const beep_pitch_text[] = {
269 "C4", "C5", "D5", "E5", "F5", "G5", "A5", "B5",
270 "C6", "D6", "E6", "F6", "G6", "A6", "B6", "C7"
271};
272
273static const struct soc_enum beep_pitch_enum =
274 SOC_ENUM_SINGLE(CS42L52_BEEP_FREQ, 4,
275 ARRAY_SIZE(beep_pitch_text), beep_pitch_text);
276
277static const char * const beep_ontime_text[] = {
278 "86 ms", "430 ms", "780 ms", "1.20 s", "1.50 s",
279 "1.80 s", "2.20 s", "2.50 s", "2.80 s", "3.20 s",
280 "3.50 s", "3.80 s", "4.20 s", "4.50 s", "4.80 s", "5.20 s"
281};
282
283static const struct soc_enum beep_ontime_enum =
284 SOC_ENUM_SINGLE(CS42L52_BEEP_FREQ, 0,
285 ARRAY_SIZE(beep_ontime_text), beep_ontime_text);
286
287static const char * const beep_offtime_text[] = {
288 "1.23 s", "2.58 s", "3.90 s", "5.20 s",
289 "6.60 s", "8.05 s", "9.35 s", "10.80 s"
290};
291
292static const struct soc_enum beep_offtime_enum =
293 SOC_ENUM_SINGLE(CS42L52_BEEP_VOL, 5,
294 ARRAY_SIZE(beep_offtime_text), beep_offtime_text);
295
296static const char * const beep_config_text[] = {
297 "Off", "Single", "Multiple", "Continuous"
298};
299
300static const struct soc_enum beep_config_enum =
301 SOC_ENUM_SINGLE(CS42L52_BEEP_TONE_CTL, 6,
302 ARRAY_SIZE(beep_config_text), beep_config_text);
303
304static const char * const beep_bass_text[] = {
305 "50 Hz", "100 Hz", "200 Hz", "250 Hz"
306};
307
308static const struct soc_enum beep_bass_enum =
309 SOC_ENUM_SINGLE(CS42L52_BEEP_TONE_CTL, 1,
310 ARRAY_SIZE(beep_bass_text), beep_bass_text);
311
312static const char * const beep_treble_text[] = {
313 "5 kHz", "7 kHz", "10 kHz", " 15 kHz"
314};
315
316static const struct soc_enum beep_treble_enum =
317 SOC_ENUM_SINGLE(CS42L52_BEEP_TONE_CTL, 3,
318 ARRAY_SIZE(beep_treble_text), beep_treble_text);
319
320static const char * const ng_threshold_text[] = {
321 "-34dB", "-37dB", "-40dB", "-43dB",
322 "-46dB", "-52dB", "-58dB", "-64dB"
323};
324
325static const struct soc_enum ng_threshold_enum =
326 SOC_ENUM_SINGLE(CS42L52_NOISE_GATE_CTL, 2,
327 ARRAY_SIZE(ng_threshold_text), ng_threshold_text);
328
329static const char * const cs42l52_ng_delay_text[] = {
330 "50ms", "100ms", "150ms", "200ms"};
331
332static const struct soc_enum ng_delay_enum =
333 SOC_ENUM_SINGLE(CS42L52_NOISE_GATE_CTL, 0,
334 ARRAY_SIZE(cs42l52_ng_delay_text), cs42l52_ng_delay_text);
335
336static const char * const cs42l52_ng_type_text[] = {
337 "Apply Specific", "Apply All"
338};
339
340static const struct soc_enum ng_type_enum =
341 SOC_ENUM_SINGLE(CS42L52_NOISE_GATE_CTL, 6,
342 ARRAY_SIZE(cs42l52_ng_type_text), cs42l52_ng_type_text);
343
344static const char * const left_swap_text[] = {
345 "Left", "LR 2", "Right"};
346
347static const char * const right_swap_text[] = {
348 "Right", "LR 2", "Left"};
349
350static const unsigned int swap_values[] = { 0, 1, 3 };
351
352static const struct soc_enum adca_swap_enum =
353 SOC_VALUE_ENUM_SINGLE(CS42L52_ADC_PCM_MIXER, 2, 1,
354 ARRAY_SIZE(left_swap_text),
355 left_swap_text,
356 swap_values);
357
358static const struct snd_kcontrol_new adca_mixer =
359 SOC_DAPM_ENUM("Route", adca_swap_enum);
360
361static const struct soc_enum pcma_swap_enum =
362 SOC_VALUE_ENUM_SINGLE(CS42L52_ADC_PCM_MIXER, 6, 1,
363 ARRAY_SIZE(left_swap_text),
364 left_swap_text,
365 swap_values);
366
367static const struct snd_kcontrol_new pcma_mixer =
368 SOC_DAPM_ENUM("Route", pcma_swap_enum);
369
370static const struct soc_enum adcb_swap_enum =
371 SOC_VALUE_ENUM_SINGLE(CS42L52_ADC_PCM_MIXER, 0, 1,
372 ARRAY_SIZE(right_swap_text),
373 right_swap_text,
374 swap_values);
375
376static const struct snd_kcontrol_new adcb_mixer =
377 SOC_DAPM_ENUM("Route", adcb_swap_enum);
378
379static const struct soc_enum pcmb_swap_enum =
380 SOC_VALUE_ENUM_SINGLE(CS42L52_ADC_PCM_MIXER, 4, 1,
381 ARRAY_SIZE(right_swap_text),
382 right_swap_text,
383 swap_values);
384
385static const struct snd_kcontrol_new pcmb_mixer =
386 SOC_DAPM_ENUM("Route", pcmb_swap_enum);
387
388
389static const struct snd_kcontrol_new passthrul_ctl =
390 SOC_DAPM_SINGLE("Switch", CS42L52_MISC_CTL, 6, 1, 0);
391
392static const struct snd_kcontrol_new passthrur_ctl =
393 SOC_DAPM_SINGLE("Switch", CS42L52_MISC_CTL, 7, 1, 0);
394
395static const struct snd_kcontrol_new spkl_ctl =
396 SOC_DAPM_SINGLE("Switch", CS42L52_PWRCTL3, 0, 1, 1);
397
398static const struct snd_kcontrol_new spkr_ctl =
399 SOC_DAPM_SINGLE("Switch", CS42L52_PWRCTL3, 2, 1, 1);
400
401static const struct snd_kcontrol_new hpl_ctl =
402 SOC_DAPM_SINGLE("Switch", CS42L52_PWRCTL3, 4, 1, 1);
403
404static const struct snd_kcontrol_new hpr_ctl =
405 SOC_DAPM_SINGLE("Switch", CS42L52_PWRCTL3, 6, 1, 1);
406
407static const struct snd_kcontrol_new cs42l52_snd_controls[] = {
408
409 SOC_DOUBLE_R_SX_TLV("Master Volume", CS42L52_MASTERA_VOL,
410 CS42L52_MASTERB_VOL, 0, 0x34, 0xE4, hl_tlv),
411
412 SOC_DOUBLE_R_SX_TLV("Headphone Volume", CS42L52_HPA_VOL,
413 CS42L52_HPB_VOL, 0, 0x34, 0xCC, hpd_tlv),
414
415 SOC_ENUM("Headphone Analog Gain", hp_gain_enum),
416
417 SOC_DOUBLE_R_SX_TLV("Speaker Volume", CS42L52_SPKA_VOL,
418 CS42L52_SPKB_VOL, 7, 0x1, 0xff, hl_tlv),
419
420 SOC_DOUBLE_R_SX_TLV("Bypass Volume", CS42L52_PASSTHRUA_VOL,
421 CS42L52_PASSTHRUB_VOL, 6, 0x18, 0x90, pga_tlv),
422
423 SOC_DOUBLE("Bypass Mute", CS42L52_MISC_CTL, 4, 5, 1, 0),
424
425 SOC_DOUBLE_R_TLV("MIC Gain Volume", CS42L52_MICA_CTL,
426 CS42L52_MICB_CTL, 0, 0x10, 0, mic_tlv),
427
428 SOC_ENUM("MIC Bias Level", mic_bias_level_enum),
429
430 SOC_DOUBLE_R_SX_TLV("ADC Volume", CS42L52_ADCA_VOL,
431 CS42L52_ADCB_VOL, 7, 0x80, 0xA0, ipd_tlv),
432 SOC_DOUBLE_R_SX_TLV("ADC Mixer Volume",
433 CS42L52_ADCA_MIXER_VOL, CS42L52_ADCB_MIXER_VOL,
434 6, 0x7f, 0x19, ipd_tlv),
435
436 SOC_DOUBLE("ADC Switch", CS42L52_ADC_MISC_CTL, 0, 1, 1, 0),
437
438 SOC_DOUBLE_R("ADC Mixer Switch", CS42L52_ADCA_MIXER_VOL,
439 CS42L52_ADCB_MIXER_VOL, 7, 1, 1),
440
441 SOC_DOUBLE_R_SX_TLV("PGA Volume", CS42L52_PGAA_CTL,
442 CS42L52_PGAB_CTL, 0, 0x28, 0x30, pga_tlv),
443
444 SOC_DOUBLE_R_SX_TLV("PCM Mixer Volume",
445 CS42L52_PCMA_MIXER_VOL, CS42L52_PCMB_MIXER_VOL,
446 6, 0x7f, 0x19, hl_tlv),
447 SOC_DOUBLE_R("PCM Mixer Switch",
448 CS42L52_PCMA_MIXER_VOL, CS42L52_PCMB_MIXER_VOL, 7, 1, 1),
449
450 SOC_ENUM("Beep Config", beep_config_enum),
451 SOC_ENUM("Beep Pitch", beep_pitch_enum),
452 SOC_ENUM("Beep on Time", beep_ontime_enum),
453 SOC_ENUM("Beep off Time", beep_offtime_enum),
454 SOC_SINGLE_TLV("Beep Volume", CS42L52_BEEP_VOL, 0, 0x1f, 0x07, hl_tlv),
455 SOC_SINGLE("Beep Mixer Switch", CS42L52_BEEP_TONE_CTL, 5, 1, 1),
456 SOC_ENUM("Beep Treble Corner Freq", beep_treble_enum),
457 SOC_ENUM("Beep Bass Corner Freq", beep_bass_enum),
458
459 SOC_SINGLE("Tone Control Switch", CS42L52_BEEP_TONE_CTL, 0, 1, 1),
460 SOC_SINGLE_TLV("Treble Gain Volume",
461 CS42L52_TONE_CTL, 4, 15, 1, hl_tlv),
462 SOC_SINGLE_TLV("Bass Gain Volume",
463 CS42L52_TONE_CTL, 0, 15, 1, hl_tlv),
464
465 /* Limiter */
466 SOC_SINGLE_TLV("Limiter Max Threshold Volume",
467 CS42L52_LIMITER_CTL1, 5, 7, 0, limiter_tlv),
468 SOC_SINGLE_TLV("Limiter Cushion Threshold Volume",
469 CS42L52_LIMITER_CTL1, 2, 7, 0, limiter_tlv),
470 SOC_SINGLE_TLV("Limiter Release Rate Volume",
471 CS42L52_LIMITER_CTL2, 0, 63, 0, limiter_tlv),
472 SOC_SINGLE_TLV("Limiter Attack Rate Volume",
473 CS42L52_LIMITER_AT_RATE, 0, 63, 0, limiter_tlv),
474
475 SOC_SINGLE("Limiter SR Switch", CS42L52_LIMITER_CTL1, 1, 1, 0),
476 SOC_SINGLE("Limiter ZC Switch", CS42L52_LIMITER_CTL1, 0, 1, 0),
477 SOC_SINGLE("Limiter Switch", CS42L52_LIMITER_CTL2, 7, 1, 0),
478
479 /* ALC */
480 SOC_SINGLE_TLV("ALC Attack Rate Volume", CS42L52_ALC_CTL,
481 0, 63, 0, limiter_tlv),
482 SOC_SINGLE_TLV("ALC Release Rate Volume", CS42L52_ALC_RATE,
483 0, 63, 0, limiter_tlv),
484 SOC_SINGLE_TLV("ALC Max Threshold Volume", CS42L52_ALC_THRESHOLD,
485 5, 7, 0, limiter_tlv),
486 SOC_SINGLE_TLV("ALC Min Threshold Volume", CS42L52_ALC_THRESHOLD,
487 2, 7, 0, limiter_tlv),
488
489 SOC_DOUBLE_R("ALC SR Capture Switch", CS42L52_PGAA_CTL,
490 CS42L52_PGAB_CTL, 7, 1, 1),
491 SOC_DOUBLE_R("ALC ZC Capture Switch", CS42L52_PGAA_CTL,
492 CS42L52_PGAB_CTL, 6, 1, 1),
493 SOC_DOUBLE("ALC Capture Switch", CS42L52_ALC_CTL, 6, 7, 1, 0),
494
495 /* Noise gate */
496 SOC_ENUM("NG Type Switch", ng_type_enum),
497 SOC_SINGLE("NG Enable Switch", CS42L52_NOISE_GATE_CTL, 6, 1, 0),
498 SOC_SINGLE("NG Boost Switch", CS42L52_NOISE_GATE_CTL, 5, 1, 1),
499 SOC_ENUM("NG Threshold", ng_threshold_enum),
500 SOC_ENUM("NG Delay", ng_delay_enum),
501
502 SOC_DOUBLE("HPF Switch", CS42L52_ANALOG_HPF_CTL, 5, 7, 1, 0),
503
504 SOC_DOUBLE("Analog SR Switch", CS42L52_ANALOG_HPF_CTL, 1, 3, 1, 1),
505 SOC_DOUBLE("Analog ZC Switch", CS42L52_ANALOG_HPF_CTL, 0, 2, 1, 1),
506 SOC_SINGLE("Digital SR Switch", CS42L52_MISC_CTL, 1, 1, 0),
507 SOC_SINGLE("Digital ZC Switch", CS42L52_MISC_CTL, 0, 1, 0),
508 SOC_SINGLE("Deemphasis Switch", CS42L52_MISC_CTL, 2, 1, 0),
509
510 SOC_SINGLE("Batt Compensation Switch", CS42L52_BATT_COMPEN, 7, 1, 0),
511 SOC_SINGLE("Batt VP Monitor Switch", CS42L52_BATT_COMPEN, 6, 1, 0),
512 SOC_SINGLE("Batt VP ref", CS42L52_BATT_COMPEN, 0, 0x0f, 0),
513
514 SOC_SINGLE("PGA AIN1L Switch", CS42L52_ADC_PGA_A, 0, 1, 0),
515 SOC_SINGLE("PGA AIN1R Switch", CS42L52_ADC_PGA_B, 0, 1, 0),
516 SOC_SINGLE("PGA AIN2L Switch", CS42L52_ADC_PGA_A, 1, 1, 0),
517 SOC_SINGLE("PGA AIN2R Switch", CS42L52_ADC_PGA_B, 1, 1, 0),
518
519 SOC_SINGLE("PGA AIN3L Switch", CS42L52_ADC_PGA_A, 2, 1, 0),
520 SOC_SINGLE("PGA AIN3R Switch", CS42L52_ADC_PGA_B, 2, 1, 0),
521
522 SOC_SINGLE("PGA AIN4L Switch", CS42L52_ADC_PGA_A, 3, 1, 0),
523 SOC_SINGLE("PGA AIN4R Switch", CS42L52_ADC_PGA_B, 3, 1, 0),
524
525 SOC_SINGLE("PGA MICA Switch", CS42L52_ADC_PGA_A, 4, 1, 0),
526 SOC_SINGLE("PGA MICB Switch", CS42L52_ADC_PGA_B, 4, 1, 0),
527
528};
529
530static const struct snd_soc_dapm_widget cs42l52_dapm_widgets[] = {
531
532 SND_SOC_DAPM_INPUT("AIN1L"),
533 SND_SOC_DAPM_INPUT("AIN1R"),
534 SND_SOC_DAPM_INPUT("AIN2L"),
535 SND_SOC_DAPM_INPUT("AIN2R"),
536 SND_SOC_DAPM_INPUT("AIN3L"),
537 SND_SOC_DAPM_INPUT("AIN3R"),
538 SND_SOC_DAPM_INPUT("AIN4L"),
539 SND_SOC_DAPM_INPUT("AIN4R"),
540 SND_SOC_DAPM_INPUT("MICA"),
541 SND_SOC_DAPM_INPUT("MICB"),
542 SND_SOC_DAPM_SIGGEN("Beep"),
543
544 SND_SOC_DAPM_AIF_OUT("AIFOUTL", NULL, 0,
545 SND_SOC_NOPM, 0, 0),
546 SND_SOC_DAPM_AIF_OUT("AIFOUTR", NULL, 0,
547 SND_SOC_NOPM, 0, 0),
548
549 SND_SOC_DAPM_MUX("MICA Mux", SND_SOC_NOPM, 0, 0, &mica_mux),
550 SND_SOC_DAPM_MUX("MICB Mux", SND_SOC_NOPM, 0, 0, &micb_mux),
551
552 SND_SOC_DAPM_ADC("ADC Left", NULL, CS42L52_PWRCTL1, 1, 1),
553 SND_SOC_DAPM_ADC("ADC Right", NULL, CS42L52_PWRCTL1, 2, 1),
554 SND_SOC_DAPM_PGA("PGA Left", CS42L52_PWRCTL1, 3, 1, NULL, 0),
555 SND_SOC_DAPM_PGA("PGA Right", CS42L52_PWRCTL1, 4, 1, NULL, 0),
556
557 SND_SOC_DAPM_MUX("ADC Left Mux", SND_SOC_NOPM, 0, 0, &adca_mux),
558 SND_SOC_DAPM_MUX("ADC Right Mux", SND_SOC_NOPM, 0, 0, &adcb_mux),
559
560 SND_SOC_DAPM_MUX("ADC Left Swap", SND_SOC_NOPM,
561 0, 0, &adca_mixer),
562 SND_SOC_DAPM_MUX("ADC Right Swap", SND_SOC_NOPM,
563 0, 0, &adcb_mixer),
564
565 SND_SOC_DAPM_MUX("Output Mux", SND_SOC_NOPM,
566 0, 0, &digital_output_mux),
567
568 SND_SOC_DAPM_PGA("PGA MICA", CS42L52_PWRCTL2, 1, 1, NULL, 0),
569 SND_SOC_DAPM_PGA("PGA MICB", CS42L52_PWRCTL2, 2, 1, NULL, 0),
570
571 SND_SOC_DAPM_SUPPLY("Mic Bias", CS42L52_PWRCTL2, 0, 1, NULL, 0),
572 SND_SOC_DAPM_SUPPLY("Charge Pump", CS42L52_PWRCTL1, 7, 1, NULL, 0),
573
574 SND_SOC_DAPM_AIF_IN("AIFINL", NULL, 0,
575 SND_SOC_NOPM, 0, 0),
576 SND_SOC_DAPM_AIF_IN("AIFINR", NULL, 0,
577 SND_SOC_NOPM, 0, 0),
578
579 SND_SOC_DAPM_DAC("DAC Left", NULL, SND_SOC_NOPM, 0, 0),
580 SND_SOC_DAPM_DAC("DAC Right", NULL, SND_SOC_NOPM, 0, 0),
581
582 SND_SOC_DAPM_SWITCH("Bypass Left", CS42L52_MISC_CTL,
583 6, 0, &passthrul_ctl),
584 SND_SOC_DAPM_SWITCH("Bypass Right", CS42L52_MISC_CTL,
585 7, 0, &passthrur_ctl),
586
587 SND_SOC_DAPM_MUX("PCM Left Swap", SND_SOC_NOPM,
588 0, 0, &pcma_mixer),
589 SND_SOC_DAPM_MUX("PCM Right Swap", SND_SOC_NOPM,
590 0, 0, &pcmb_mixer),
591
592 SND_SOC_DAPM_SWITCH("HP Left Amp", SND_SOC_NOPM, 0, 0, &hpl_ctl),
593 SND_SOC_DAPM_SWITCH("HP Right Amp", SND_SOC_NOPM, 0, 0, &hpr_ctl),
594
595 SND_SOC_DAPM_SWITCH("SPK Left Amp", SND_SOC_NOPM, 0, 0, &spkl_ctl),
596 SND_SOC_DAPM_SWITCH("SPK Right Amp", SND_SOC_NOPM, 0, 0, &spkr_ctl),
597
598 SND_SOC_DAPM_OUTPUT("HPOUTA"),
599 SND_SOC_DAPM_OUTPUT("HPOUTB"),
600 SND_SOC_DAPM_OUTPUT("SPKOUTA"),
601 SND_SOC_DAPM_OUTPUT("SPKOUTB"),
602
603};
604
605static const struct snd_soc_dapm_route cs42l52_audio_map[] = {
606
607 {"Capture", NULL, "AIFOUTL"},
608 {"Capture", NULL, "AIFOUTL"},
609
610 {"AIFOUTL", NULL, "Output Mux"},
611 {"AIFOUTR", NULL, "Output Mux"},
612
613 {"Output Mux", "ADC", "ADC Left"},
614 {"Output Mux", "ADC", "ADC Right"},
615
616 {"ADC Left", NULL, "Charge Pump"},
617 {"ADC Right", NULL, "Charge Pump"},
618
619 {"Charge Pump", NULL, "ADC Left Mux"},
620 {"Charge Pump", NULL, "ADC Right Mux"},
621
622 {"ADC Left Mux", "Input1A", "AIN1L"},
623 {"ADC Right Mux", "Input1B", "AIN1R"},
624 {"ADC Left Mux", "Input2A", "AIN2L"},
625 {"ADC Right Mux", "Input2B", "AIN2R"},
626 {"ADC Left Mux", "Input3A", "AIN3L"},
627 {"ADC Right Mux", "Input3B", "AIN3R"},
628 {"ADC Left Mux", "Input4A", "AIN4L"},
629 {"ADC Right Mux", "Input4B", "AIN4R"},
630 {"ADC Left Mux", "PGA Input Left", "PGA Left"},
631 {"ADC Right Mux", "PGA Input Right" , "PGA Right"},
632
633 {"PGA Left", "Switch", "AIN1L"},
634 {"PGA Right", "Switch", "AIN1R"},
635 {"PGA Left", "Switch", "AIN2L"},
636 {"PGA Right", "Switch", "AIN2R"},
637 {"PGA Left", "Switch", "AIN3L"},
638 {"PGA Right", "Switch", "AIN3R"},
639 {"PGA Left", "Switch", "AIN4L"},
640 {"PGA Right", "Switch", "AIN4R"},
641
642 {"PGA Left", "Switch", "PGA MICA"},
643 {"PGA MICA", NULL, "MICA"},
644
645 {"PGA Right", "Switch", "PGA MICB"},
646 {"PGA MICB", NULL, "MICB"},
647
648 {"HPOUTA", NULL, "HP Left Amp"},
649 {"HPOUTB", NULL, "HP Right Amp"},
650 {"HP Left Amp", NULL, "Bypass Left"},
651 {"HP Right Amp", NULL, "Bypass Right"},
652 {"Bypass Left", "Switch", "PGA Left"},
653 {"Bypass Right", "Switch", "PGA Right"},
654 {"HP Left Amp", "Switch", "DAC Left"},
655 {"HP Right Amp", "Switch", "DAC Right"},
656
657 {"SPKOUTA", NULL, "SPK Left Amp"},
658 {"SPKOUTB", NULL, "SPK Right Amp"},
659
660 {"SPK Left Amp", NULL, "Beep"},
661 {"SPK Right Amp", NULL, "Beep"},
662 {"SPK Left Amp", "Switch", "Playback"},
663 {"SPK Right Amp", "Switch", "Playback"},
664
665 {"DAC Left", NULL, "Beep"},
666 {"DAC Right", NULL, "Beep"},
667 {"DAC Left", NULL, "Playback"},
668 {"DAC Right", NULL, "Playback"},
669
670 {"Output Mux", "DSP", "Playback"},
671 {"Output Mux", "DSP", "Playback"},
672
673 {"AIFINL", NULL, "Playback"},
674 {"AIFINR", NULL, "Playback"},
675
676};
677
678struct cs42l52_clk_para {
679 u32 mclk;
680 u32 rate;
681 u8 speed;
682 u8 group;
683 u8 videoclk;
684 u8 ratio;
685 u8 mclkdiv2;
686};
687
688static const struct cs42l52_clk_para clk_map_table[] = {
689 /*8k*/
690 {12288000, 8000, CLK_QS_MODE, CLK_32K, CLK_NO_27M, CLK_R_128, 0},
691 {18432000, 8000, CLK_QS_MODE, CLK_32K, CLK_NO_27M, CLK_R_128, 0},
692 {12000000, 8000, CLK_QS_MODE, CLK_32K, CLK_NO_27M, CLK_R_125, 0},
693 {24000000, 8000, CLK_QS_MODE, CLK_32K, CLK_NO_27M, CLK_R_125, 1},
694 {27000000, 8000, CLK_QS_MODE, CLK_32K, CLK_27M_MCLK, CLK_R_125, 0},
695
696 /*11.025k*/
697 {11289600, 11025, CLK_QS_MODE, CLK_NO_32K, CLK_NO_27M, CLK_R_128, 0},
698 {16934400, 11025, CLK_QS_MODE, CLK_NO_32K, CLK_NO_27M, CLK_R_128, 0},
699
700 /*16k*/
701 {12288000, 16000, CLK_HS_MODE, CLK_32K, CLK_NO_27M, CLK_R_128, 0},
702 {18432000, 16000, CLK_HS_MODE, CLK_32K, CLK_NO_27M, CLK_R_128, 0},
703 {12000000, 16000, CLK_HS_MODE, CLK_32K, CLK_NO_27M, CLK_R_125, 0},
704 {24000000, 16000, CLK_HS_MODE, CLK_32K, CLK_NO_27M, CLK_R_125, 1},
705 {27000000, 16000, CLK_HS_MODE, CLK_32K, CLK_27M_MCLK, CLK_R_125, 1},
706
707 /*22.05k*/
708 {11289600, 22050, CLK_HS_MODE, CLK_NO_32K, CLK_NO_27M, CLK_R_128, 0},
709 {16934400, 22050, CLK_HS_MODE, CLK_NO_32K, CLK_NO_27M, CLK_R_128, 0},
710
711 /* 32k */
712 {12288000, 32000, CLK_SS_MODE, CLK_32K, CLK_NO_27M, CLK_R_128, 0},
713 {18432000, 32000, CLK_SS_MODE, CLK_32K, CLK_NO_27M, CLK_R_128, 0},
714 {12000000, 32000, CLK_SS_MODE, CLK_32K, CLK_NO_27M, CLK_R_125, 0},
715 {24000000, 32000, CLK_SS_MODE, CLK_32K, CLK_NO_27M, CLK_R_125, 1},
716 {27000000, 32000, CLK_SS_MODE, CLK_32K, CLK_27M_MCLK, CLK_R_125, 0},
717
718 /* 44.1k */
719 {11289600, 44100, CLK_SS_MODE, CLK_NO_32K, CLK_NO_27M, CLK_R_128, 0},
720 {16934400, 44100, CLK_SS_MODE, CLK_NO_32K, CLK_NO_27M, CLK_R_128, 0},
721
722 /* 48k */
723 {12288000, 48000, CLK_SS_MODE, CLK_NO_32K, CLK_NO_27M, CLK_R_128, 0},
724 {18432000, 48000, CLK_SS_MODE, CLK_NO_32K, CLK_NO_27M, CLK_R_128, 0},
725 {12000000, 48000, CLK_SS_MODE, CLK_NO_32K, CLK_NO_27M, CLK_R_125, 0},
726 {24000000, 48000, CLK_SS_MODE, CLK_NO_32K, CLK_NO_27M, CLK_R_125, 1},
727 {27000000, 48000, CLK_SS_MODE, CLK_NO_32K, CLK_27M_MCLK, CLK_R_125, 1},
728
729 /* 88.2k */
730 {11289600, 88200, CLK_DS_MODE, CLK_NO_32K, CLK_NO_27M, CLK_R_128, 0},
731 {16934400, 88200, CLK_DS_MODE, CLK_NO_32K, CLK_NO_27M, CLK_R_128, 0},
732
733 /* 96k */
734 {12288000, 96000, CLK_DS_MODE, CLK_NO_32K, CLK_NO_27M, CLK_R_128, 0},
735 {18432000, 96000, CLK_DS_MODE, CLK_NO_32K, CLK_NO_27M, CLK_R_128, 0},
736 {12000000, 96000, CLK_DS_MODE, CLK_NO_32K, CLK_NO_27M, CLK_R_125, 0},
737 {24000000, 96000, CLK_DS_MODE, CLK_NO_32K, CLK_NO_27M, CLK_R_125, 1},
738};
739
740static int cs42l52_get_clk(int mclk, int rate)
741{
742 int i, ret = 0;
743 u_int mclk1, mclk2 = 0;
744
745 for (i = 0; i < ARRAY_SIZE(clk_map_table); i++) {
746 if (clk_map_table[i].rate == rate) {
747 mclk1 = clk_map_table[i].mclk;
748 if (abs(mclk - mclk1) < abs(mclk - mclk2)) {
749 mclk2 = mclk1;
750 ret = i;
751 }
752 }
753 }
754 if (ret > ARRAY_SIZE(clk_map_table))
755 return -EINVAL;
756 return ret;
757}
758
759static int cs42l52_set_sysclk(struct snd_soc_dai *codec_dai,
760 int clk_id, unsigned int freq, int dir)
761{
762 struct snd_soc_codec *codec = codec_dai->codec;
763 struct cs42l52_private *cs42l52 = snd_soc_codec_get_drvdata(codec);
764
765 if ((freq >= CS42L52_MIN_CLK) && (freq <= CS42L52_MAX_CLK)) {
766 cs42l52->sysclk = freq;
767 } else {
768 dev_err(codec->dev, "Invalid freq paramter\n");
769 return -EINVAL;
770 }
771 return 0;
772}
773
774static int cs42l52_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
775{
776 struct snd_soc_codec *codec = codec_dai->codec;
777 struct cs42l52_private *cs42l52 = snd_soc_codec_get_drvdata(codec);
778 int ret = 0;
779 u8 iface = 0;
780
781 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
782 case SND_SOC_DAIFMT_CBM_CFM:
783 iface = CS42L52_IFACE_CTL1_MASTER;
784 break;
785 case SND_SOC_DAIFMT_CBS_CFS:
786 iface = CS42L52_IFACE_CTL1_SLAVE;
787 break;
788 default:
789 return -EINVAL;
790 }
791
792 /* interface format */
793 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
794 case SND_SOC_DAIFMT_I2S:
795 iface |= CS42L52_IFACE_CTL1_ADC_FMT_I2S |
796 CS42L52_IFACE_CTL1_DAC_FMT_I2S;
797 break;
798 case SND_SOC_DAIFMT_RIGHT_J:
799 iface |= CS42L52_IFACE_CTL1_DAC_FMT_RIGHT_J;
800 break;
801 case SND_SOC_DAIFMT_LEFT_J:
802 iface |= CS42L52_IFACE_CTL1_ADC_FMT_LEFT_J |
803 CS42L52_IFACE_CTL1_DAC_FMT_LEFT_J;
804 break;
805 case SND_SOC_DAIFMT_DSP_A:
806 iface |= CS42L52_IFACE_CTL1_DSP_MODE_EN;
807 break;
808 case SND_SOC_DAIFMT_DSP_B:
809 break;
810 default:
811 return -EINVAL;
812 }
813
814 /* clock inversion */
815 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
816 case SND_SOC_DAIFMT_NB_NF:
817 break;
818 case SND_SOC_DAIFMT_IB_IF:
819 iface |= CS42L52_IFACE_CTL1_INV_SCLK;
820 break;
821 case SND_SOC_DAIFMT_IB_NF:
822 iface |= CS42L52_IFACE_CTL1_INV_SCLK;
823 break;
824 case SND_SOC_DAIFMT_NB_IF:
825 break;
826 default:
827 ret = -EINVAL;
828 }
829 cs42l52->config.format = iface;
830 snd_soc_write(codec, CS42L52_IFACE_CTL1, cs42l52->config.format);
831
832 return 0;
833}
834
835static int cs42l52_digital_mute(struct snd_soc_dai *dai, int mute)
836{
837 struct snd_soc_codec *codec = dai->codec;
838
839 if (mute)
840 snd_soc_update_bits(codec, CS42L52_PB_CTL1,
841 CS42L52_PB_CTL1_MUTE_MASK,
842 CS42L52_PB_CTL1_MUTE);
843 else
844 snd_soc_update_bits(codec, CS42L52_PB_CTL1,
845 CS42L52_PB_CTL1_MUTE_MASK,
846 CS42L52_PB_CTL1_UNMUTE);
847
848 return 0;
849}
850
851static int cs42l52_pcm_hw_params(struct snd_pcm_substream *substream,
852 struct snd_pcm_hw_params *params,
853 struct snd_soc_dai *dai)
854{
855 struct snd_soc_codec *codec = dai->codec;
856 struct cs42l52_private *cs42l52 = snd_soc_codec_get_drvdata(codec);
857 u32 clk = 0;
858 int index;
859
860 index = cs42l52_get_clk(cs42l52->sysclk, params_rate(params));
861 if (index >= 0) {
862 cs42l52->sysclk = clk_map_table[index].mclk;
863
864 clk |= (clk_map_table[index].speed << CLK_SPEED_SHIFT) |
865 (clk_map_table[index].group << CLK_32K_SR_SHIFT) |
866 (clk_map_table[index].videoclk << CLK_27M_MCLK_SHIFT) |
867 (clk_map_table[index].ratio << CLK_RATIO_SHIFT) |
868 clk_map_table[index].mclkdiv2;
869
870 snd_soc_write(codec, CS42L52_CLK_CTL, clk);
871 } else {
872 dev_err(codec->dev, "can't get correct mclk\n");
873 return -EINVAL;
874 }
875
876 return 0;
877}
878
879static int cs42l52_set_bias_level(struct snd_soc_codec *codec,
880 enum snd_soc_bias_level level)
881{
882 struct cs42l52_private *cs42l52 = snd_soc_codec_get_drvdata(codec);
883
884 switch (level) {
885 case SND_SOC_BIAS_ON:
886 break;
887 case SND_SOC_BIAS_PREPARE:
888 snd_soc_update_bits(codec, CS42L52_PWRCTL1,
889 CS42L52_PWRCTL1_PDN_CODEC, 0);
890 break;
891 case SND_SOC_BIAS_STANDBY:
892 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
893 regcache_cache_only(cs42l52->regmap, false);
894 regcache_sync(cs42l52->regmap);
895 }
896 snd_soc_write(codec, CS42L52_PWRCTL1, CS42L52_PWRCTL1_PDN_ALL);
897 break;
898 case SND_SOC_BIAS_OFF:
899 snd_soc_write(codec, CS42L52_PWRCTL1, CS42L52_PWRCTL1_PDN_ALL);
900 regcache_cache_only(cs42l52->regmap, true);
901 break;
902 }
903 codec->dapm.bias_level = level;
904
905 return 0;
906}
907
908#define CS42L52_RATES (SNDRV_PCM_RATE_8000_96000)
909
910#define CS42L52_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_U16_LE | \
911 SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_U18_3LE | \
912 SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_U20_3LE | \
913 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_U24_LE)
914
915static struct snd_soc_dai_ops cs42l52_ops = {
916 .hw_params = cs42l52_pcm_hw_params,
917 .digital_mute = cs42l52_digital_mute,
918 .set_fmt = cs42l52_set_fmt,
919 .set_sysclk = cs42l52_set_sysclk,
920};
921
922static struct snd_soc_dai_driver cs42l52_dai = {
923 .name = "cs42l52",
924 .playback = {
925 .stream_name = "Playback",
926 .channels_min = 1,
927 .channels_max = 2,
928 .rates = CS42L52_RATES,
929 .formats = CS42L52_FORMATS,
930 },
931 .capture = {
932 .stream_name = "Capture",
933 .channels_min = 1,
934 .channels_max = 2,
935 .rates = CS42L52_RATES,
936 .formats = CS42L52_FORMATS,
937 },
938 .ops = &cs42l52_ops,
939};
940
941static int cs42l52_suspend(struct snd_soc_codec *codec)
942{
943 cs42l52_set_bias_level(codec, SND_SOC_BIAS_OFF);
944
945 return 0;
946}
947
948static int cs42l52_resume(struct snd_soc_codec *codec)
949{
950 cs42l52_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
951
952 return 0;
953}
954
955#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
956static int beep_rates[] = {
957 261, 522, 585, 667, 706, 774, 889, 1000,
958 1043, 1200, 1333, 1412, 1600, 1714, 2000, 2182
959};
960
961static void cs42l52_beep_work(struct work_struct *work)
962{
963 struct cs42l52_private *cs42l52 =
964 container_of(work, struct cs42l52_private, beep_work);
965 struct snd_soc_codec *codec = cs42l52->codec;
966 struct snd_soc_dapm_context *dapm = &codec->dapm;
967 int i;
968 int val = 0;
969 int best = 0;
970
971 if (cs42l52->beep_rate) {
972 for (i = 0; i < ARRAY_SIZE(beep_rates); i++) {
973 if (abs(cs42l52->beep_rate - beep_rates[i]) <
974 abs(cs42l52->beep_rate - beep_rates[best]))
975 best = i;
976 }
977
978 dev_dbg(codec->dev, "Set beep rate %dHz for requested %dHz\n",
979 beep_rates[best], cs42l52->beep_rate);
980
981 val = (best << CS42L52_BEEP_RATE_SHIFT);
982
983 snd_soc_dapm_enable_pin(dapm, "Beep");
984 } else {
985 dev_dbg(codec->dev, "Disabling beep\n");
986 snd_soc_dapm_disable_pin(dapm, "Beep");
987 }
988
989 snd_soc_update_bits(codec, CS42L52_BEEP_FREQ,
990 CS42L52_BEEP_RATE_MASK, val);
991
992 snd_soc_dapm_sync(dapm);
993}
994
995/* For usability define a way of injecting beep events for the device -
996 * many systems will not have a keyboard.
997 */
998static int cs42l52_beep_event(struct input_dev *dev, unsigned int type,
999 unsigned int code, int hz)
1000{
1001 struct snd_soc_codec *codec = input_get_drvdata(dev);
1002 struct cs42l52_private *cs42l52 = snd_soc_codec_get_drvdata(codec);
1003
1004 dev_dbg(codec->dev, "Beep event %x %x\n", code, hz);
1005
1006 switch (code) {
1007 case SND_BELL:
1008 if (hz)
1009 hz = 261;
1010 case SND_TONE:
1011 break;
1012 default:
1013 return -1;
1014 }
1015
1016 /* Kick the beep from a workqueue */
1017 cs42l52->beep_rate = hz;
1018 schedule_work(&cs42l52->beep_work);
1019 return 0;
1020}
1021
1022static ssize_t cs42l52_beep_set(struct device *dev,
1023 struct device_attribute *attr,
1024 const char *buf, size_t count)
1025{
1026 struct cs42l52_private *cs42l52 = dev_get_drvdata(dev);
1027 long int time;
1028 int ret;
1029
1030 ret = kstrtol(buf, 10, &time);
1031 if (ret != 0)
1032 return ret;
1033
1034 input_event(cs42l52->beep, EV_SND, SND_TONE, time);
1035
1036 return count;
1037}
1038
1039static DEVICE_ATTR(beep, 0200, NULL, cs42l52_beep_set);
1040
1041static void cs42l52_init_beep(struct snd_soc_codec *codec)
1042{
1043 struct cs42l52_private *cs42l52 = snd_soc_codec_get_drvdata(codec);
1044 int ret;
1045
1046 cs42l52->beep = input_allocate_device();
1047 if (!cs42l52->beep) {
1048 dev_err(codec->dev, "Failed to allocate beep device\n");
1049 return;
1050 }
1051
1052 INIT_WORK(&cs42l52->beep_work, cs42l52_beep_work);
1053 cs42l52->beep_rate = 0;
1054
1055 cs42l52->beep->name = "CS42L52 Beep Generator";
1056 cs42l52->beep->phys = dev_name(codec->dev);
1057 cs42l52->beep->id.bustype = BUS_I2C;
1058
1059 cs42l52->beep->evbit[0] = BIT_MASK(EV_SND);
1060 cs42l52->beep->sndbit[0] = BIT_MASK(SND_BELL) | BIT_MASK(SND_TONE);
1061 cs42l52->beep->event = cs42l52_beep_event;
1062 cs42l52->beep->dev.parent = codec->dev;
1063 input_set_drvdata(cs42l52->beep, codec);
1064
1065 ret = input_register_device(cs42l52->beep);
1066 if (ret != 0) {
1067 input_free_device(cs42l52->beep);
1068 cs42l52->beep = NULL;
1069 dev_err(codec->dev, "Failed to register beep device\n");
1070 }
1071
1072 ret = device_create_file(codec->dev, &dev_attr_beep);
1073 if (ret != 0) {
1074 dev_err(codec->dev, "Failed to create keyclick file: %d\n",
1075 ret);
1076 }
1077}
1078
1079static void cs42l52_free_beep(struct snd_soc_codec *codec)
1080{
1081 struct cs42l52_private *cs42l52 = snd_soc_codec_get_drvdata(codec);
1082
1083 device_remove_file(codec->dev, &dev_attr_beep);
1084 input_unregister_device(cs42l52->beep);
1085 cancel_work_sync(&cs42l52->beep_work);
1086 cs42l52->beep = NULL;
1087
1088 snd_soc_update_bits(codec, CS42L52_BEEP_TONE_CTL,
1089 CS42L52_BEEP_EN_MASK, 0);
1090}
1091#else
1092static void cs42l52_init_beep(struct snd_soc_codec *codec)
1093{
1094}
1095
1096static void cs42l52_free_beep(struct snd_soc_codec *codec)
1097{
1098}
1099#endif
1100
1101static int cs42l52_probe(struct snd_soc_codec *codec)
1102{
1103 struct cs42l52_private *cs42l52 = snd_soc_codec_get_drvdata(codec);
1104 int ret;
1105
1106 codec->control_data = cs42l52->regmap;
1107 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
1108 if (ret < 0) {
1109 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
1110 return ret;
1111 }
1112 regcache_cache_only(cs42l52->regmap, true);
1113
1114 cs42l52_init_beep(codec);
1115
1116 cs42l52_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1117
1118 cs42l52->sysclk = CS42L52_DEFAULT_CLK;
1119 cs42l52->config.format = CS42L52_DEFAULT_FORMAT;
1120
1121 /* Set Platform MICx CFG */
1122 snd_soc_update_bits(codec, CS42L52_MICA_CTL,
1123 CS42L52_MIC_CTL_TYPE_MASK,
1124 cs42l52->pdata.mica_cfg <<
1125 CS42L52_MIC_CTL_TYPE_SHIFT);
1126
1127 snd_soc_update_bits(codec, CS42L52_MICB_CTL,
1128 CS42L52_MIC_CTL_TYPE_MASK,
1129 cs42l52->pdata.micb_cfg <<
1130 CS42L52_MIC_CTL_TYPE_SHIFT);
1131
1132 /* if Single Ended, Get Mic_Select */
1133 if (cs42l52->pdata.mica_cfg)
1134 snd_soc_update_bits(codec, CS42L52_MICA_CTL,
1135 CS42L52_MIC_CTL_MIC_SEL_MASK,
1136 cs42l52->pdata.mica_sel <<
1137 CS42L52_MIC_CTL_MIC_SEL_SHIFT);
1138 if (cs42l52->pdata.micb_cfg)
1139 snd_soc_update_bits(codec, CS42L52_MICB_CTL,
1140 CS42L52_MIC_CTL_MIC_SEL_MASK,
1141 cs42l52->pdata.micb_sel <<
1142 CS42L52_MIC_CTL_MIC_SEL_SHIFT);
1143
1144 /* Set Platform Charge Pump Freq */
1145 snd_soc_update_bits(codec, CS42L52_CHARGE_PUMP,
1146 CS42L52_CHARGE_PUMP_MASK,
1147 cs42l52->pdata.chgfreq <<
1148 CS42L52_CHARGE_PUMP_SHIFT);
1149
1150 /* Set Platform Bias Level */
1151 snd_soc_update_bits(codec, CS42L52_IFACE_CTL2,
1152 CS42L52_IFACE_CTL2_BIAS_LVL,
1153 cs42l52->pdata.micbias_lvl);
1154
1155 return ret;
1156}
1157
1158static int cs42l52_remove(struct snd_soc_codec *codec)
1159{
1160 cs42l52_free_beep(codec);
1161 cs42l52_set_bias_level(codec, SND_SOC_BIAS_OFF);
1162
1163 return 0;
1164}
1165
1166static struct snd_soc_codec_driver soc_codec_dev_cs42l52 = {
1167 .probe = cs42l52_probe,
1168 .remove = cs42l52_remove,
1169 .suspend = cs42l52_suspend,
1170 .resume = cs42l52_resume,
1171 .set_bias_level = cs42l52_set_bias_level,
1172
1173 .dapm_widgets = cs42l52_dapm_widgets,
1174 .num_dapm_widgets = ARRAY_SIZE(cs42l52_dapm_widgets),
1175 .dapm_routes = cs42l52_audio_map,
1176 .num_dapm_routes = ARRAY_SIZE(cs42l52_audio_map),
1177
1178 .controls = cs42l52_snd_controls,
1179 .num_controls = ARRAY_SIZE(cs42l52_snd_controls),
1180};
1181
1182/* Current and threshold powerup sequence Pg37 */
1183static const struct reg_default cs42l52_threshold_patch[] = {
1184
1185 { 0x00, 0x99 },
1186 { 0x3E, 0xBA },
1187 { 0x47, 0x80 },
1188 { 0x32, 0xBB },
1189 { 0x32, 0x3B },
1190 { 0x00, 0x00 },
1191
1192};
1193
1194static struct regmap_config cs42l52_regmap = {
1195 .reg_bits = 8,
1196 .val_bits = 8,
1197
1198 .max_register = CS42L52_MAX_REGISTER,
1199 .reg_defaults = cs42l52_reg_defaults,
1200 .num_reg_defaults = ARRAY_SIZE(cs42l52_reg_defaults),
1201 .readable_reg = cs42l52_readable_register,
1202 .volatile_reg = cs42l52_volatile_register,
1203 .cache_type = REGCACHE_RBTREE,
1204};
1205
1206static int cs42l52_i2c_probe(struct i2c_client *i2c_client,
1207 const struct i2c_device_id *id)
1208{
1209 struct cs42l52_private *cs42l52;
1210 int ret;
1211 unsigned int devid = 0;
1212 unsigned int reg;
1213
1214 cs42l52 = devm_kzalloc(&i2c_client->dev, sizeof(struct cs42l52_private),
1215 GFP_KERNEL);
1216 if (cs42l52 == NULL)
1217 return -ENOMEM;
1218 cs42l52->dev = &i2c_client->dev;
1219
1220 cs42l52->regmap = regmap_init_i2c(i2c_client, &cs42l52_regmap);
1221 if (IS_ERR(cs42l52->regmap)) {
1222 ret = PTR_ERR(cs42l52->regmap);
1223 dev_err(&i2c_client->dev, "regmap_init() failed: %d\n", ret);
1224 goto err;
1225 }
1226
1227 i2c_set_clientdata(i2c_client, cs42l52);
1228
1229 if (dev_get_platdata(&i2c_client->dev))
1230 memcpy(&cs42l52->pdata, dev_get_platdata(&i2c_client->dev),
1231 sizeof(cs42l52->pdata));
1232
1233 ret = regmap_register_patch(cs42l52->regmap, cs42l52_threshold_patch,
1234 ARRAY_SIZE(cs42l52_threshold_patch));
1235 if (ret != 0)
1236 dev_warn(cs42l52->dev, "Failed to apply regmap patch: %d\n",
1237 ret);
1238
1239 ret = regmap_read(cs42l52->regmap, CS42L52_CHIP, &reg);
1240 devid = reg & CS42L52_CHIP_ID_MASK;
1241 if (devid != CS42L52_CHIP_ID) {
1242 ret = -ENODEV;
1243 dev_err(&i2c_client->dev,
1244 "CS42L52 Device ID (%X). Expected %X\n",
1245 devid, CS42L52_CHIP_ID);
1246 goto err_regmap;
1247 }
1248
1249 regcache_cache_only(cs42l52->regmap, true);
1250
1251 ret = snd_soc_register_codec(&i2c_client->dev,
1252 &soc_codec_dev_cs42l52, &cs42l52_dai, 1);
1253 if (ret < 0)
1254 goto err_regmap;
1255 return 0;
1256
1257err_regmap:
1258 regmap_exit(cs42l52->regmap);
1259
1260err:
1261 return ret;
1262}
1263
1264static int cs42l52_i2c_remove(struct i2c_client *client)
1265{
1266 struct cs42l52_private *cs42l52 = i2c_get_clientdata(client);
1267
1268 snd_soc_unregister_codec(&client->dev);
1269 regmap_exit(cs42l52->regmap);
1270
1271 return 0;
1272}
1273
1274static const struct i2c_device_id cs42l52_id[] = {
1275 { "cs42l52", 0 },
1276 { }
1277};
1278MODULE_DEVICE_TABLE(i2c, cs42l52_id);
1279
1280static struct i2c_driver cs42l52_i2c_driver = {
1281 .driver = {
1282 .name = "cs42l52",
1283 .owner = THIS_MODULE,
1284 },
1285 .id_table = cs42l52_id,
1286 .probe = cs42l52_i2c_probe,
1287 .remove = __devexit_p(cs42l52_i2c_remove),
1288};
1289
1290module_i2c_driver(cs42l52_i2c_driver);
1291
1292MODULE_DESCRIPTION("ASoC CS42L52 driver");
1293MODULE_AUTHOR("Georgi Vlaev, Nucleus Systems Ltd, <joe@nucleusys.com>");
1294MODULE_AUTHOR("Brian Austin, Cirrus Logic Inc, <brian.austin@cirrus.com>");
1295MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/cs42l52.h b/sound/soc/codecs/cs42l52.h
new file mode 100644
index 000000000000..60985c059071
--- /dev/null
+++ b/sound/soc/codecs/cs42l52.h
@@ -0,0 +1,274 @@
1/*
2 * cs42l52.h -- CS42L52 ALSA SoC audio driver
3 *
4 * Copyright 2012 CirrusLogic, Inc.
5 *
6 * Author: Georgi Vlaev <joe@nucleusys.com>
7 * Author: Brian Austin <brian.austin@cirrus.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 *
13 */
14
15#ifndef __CS42L52_H__
16#define __CS42L52_H__
17
18#define CS42L52_NAME "CS42L52"
19#define CS42L52_DEFAULT_CLK 12000000
20#define CS42L52_MIN_CLK 11000000
21#define CS42L52_MAX_CLK 27000000
22#define CS42L52_DEFAULT_FORMAT SNDRV_PCM_FMTBIT_S16_LE
23#define CS42L52_DEFAULT_MAX_CHANS 2
24#define CS42L52_SYSCLK 1
25
26#define CS42L52_CHIP_SWICTH (1 << 17)
27#define CS42L52_ALL_IN_ONE (1 << 16)
28#define CS42L52_CHIP_ONE 0x00
29#define CS42L52_CHIP_TWO 0x01
30#define CS42L52_CHIP_THR 0x02
31#define CS42L52_CHIP_MASK 0x0f
32
33#define CS42L52_FIX_BITS_CTL 0x00
34#define CS42L52_CHIP 0x01
35#define CS42L52_CHIP_ID 0xE0
36#define CS42L52_CHIP_ID_MASK 0xF8
37#define CS42L52_CHIP_REV_A0 0x00
38#define CS42L52_CHIP_REV_A1 0x01
39#define CS42L52_CHIP_REV_B0 0x02
40#define CS42L52_CHIP_REV_MASK 0x03
41
42#define CS42L52_PWRCTL1 0x02
43#define CS42L52_PWRCTL1_PDN_ALL 0x9F
44#define CS42L52_PWRCTL1_PDN_CHRG 0x80
45#define CS42L52_PWRCTL1_PDN_PGAB 0x10
46#define CS42L52_PWRCTL1_PDN_PGAA 0x08
47#define CS42L52_PWRCTL1_PDN_ADCB 0x04
48#define CS42L52_PWRCTL1_PDN_ADCA 0x02
49#define CS42L52_PWRCTL1_PDN_CODEC 0x01
50
51#define CS42L52_PWRCTL2 0x03
52#define CS42L52_PWRCTL2_OVRDB (1 << 4)
53#define CS42L52_PWRCTL2_OVRDA (1 << 3)
54#define CS42L52_PWRCTL2_PDN_MICB (1 << 2)
55#define CS42L52_PWRCTL2_PDN_MICB_SHIFT 2
56#define CS42L52_PWRCTL2_PDN_MICA (1 << 1)
57#define CS42L52_PWRCTL2_PDN_MICA_SHIFT 1
58#define CS42L52_PWRCTL2_PDN_MICBIAS (1 << 0)
59#define CS42L52_PWRCTL2_PDN_MICBIAS_SHIFT 0
60
61#define CS42L52_PWRCTL3 0x04
62#define CS42L52_PWRCTL3_HPB_PDN_SHIFT 6
63#define CS42L52_PWRCTL3_HPB_ON_LOW 0x00
64#define CS42L52_PWRCTL3_HPB_ON_HIGH 0x01
65#define CS42L52_PWRCTL3_HPB_ALWAYS_ON 0x02
66#define CS42L52_PWRCTL3_HPB_ALWAYS_OFF 0x03
67#define CS42L52_PWRCTL3_HPA_PDN_SHIFT 4
68#define CS42L52_PWRCTL3_HPA_ON_LOW 0x00
69#define CS42L52_PWRCTL3_HPA_ON_HIGH 0x01
70#define CS42L52_PWRCTL3_HPA_ALWAYS_ON 0x02
71#define CS42L52_PWRCTL3_HPA_ALWAYS_OFF 0x03
72#define CS42L52_PWRCTL3_SPKB_PDN_SHIFT 2
73#define CS42L52_PWRCTL3_SPKB_ON_LOW 0x00
74#define CS42L52_PWRCTL3_SPKB_ON_HIGH 0x01
75#define CS42L52_PWRCTL3_SPKB_ALWAYS_ON 0x02
76#define CS42L52_PWRCTL3_PDN_SPKB (1 << 2)
77#define CS42L52_PWRCTL3_PDN_SPKA (1 << 0)
78#define CS42L52_PWRCTL3_SPKA_PDN_SHIFT 0
79#define CS42L52_PWRCTL3_SPKA_ON_LOW 0x00
80#define CS42L52_PWRCTL3_SPKA_ON_HIGH 0x01
81#define CS42L52_PWRCTL3_SPKA_ALWAYS_ON 0x02
82
83#define CS42L52_DEFAULT_OUTPUT_STATE 0x05
84#define CS42L52_PWRCTL3_CONF_MASK 0x03
85
86#define CS42L52_CLK_CTL 0x05
87#define CLK_AUTODECT_ENABLE (1 << 7)
88#define CLK_SPEED_SHIFT 5
89#define CLK_DS_MODE 0x00
90#define CLK_SS_MODE 0x01
91#define CLK_HS_MODE 0x02
92#define CLK_QS_MODE 0x03
93#define CLK_32K_SR_SHIFT 4
94#define CLK_32K 0x01
95#define CLK_NO_32K 0x00
96#define CLK_27M_MCLK_SHIFT 3
97#define CLK_27M_MCLK 0x01
98#define CLK_NO_27M 0x00
99#define CLK_RATIO_SHIFT 1
100#define CLK_R_128 0x00
101#define CLK_R_125 0x01
102#define CLK_R_132 0x02
103#define CLK_R_136 0x03
104
105#define CS42L52_IFACE_CTL1 0x06
106#define CS42L52_IFACE_CTL1_MASTER (1 << 7)
107#define CS42L52_IFACE_CTL1_SLAVE (0 << 7)
108#define CS42L52_IFACE_CTL1_INV_SCLK (1 << 6)
109#define CS42L52_IFACE_CTL1_ADC_FMT_I2S (1 << 5)
110#define CS42L52_IFACE_CTL1_ADC_FMT_LEFT_J (0 << 5)
111#define CS42L52_IFACE_CTL1_DSP_MODE_EN (1 << 4)
112#define CS42L52_IFACE_CTL1_DAC_FMT_LEFT_J (0 << 2)
113#define CS42L52_IFACE_CTL1_DAC_FMT_I2S (1 << 2)
114#define CS42L52_IFACE_CTL1_DAC_FMT_RIGHT_J (2 << 2)
115#define CS42L52_IFACE_CTL1_WL_32BIT (0x00)
116#define CS42L52_IFACE_CTL1_WL_24BIT (0x01)
117#define CS42L52_IFACE_CTL1_WL_20BIT (0x02)
118#define CS42L52_IFACE_CTL1_WL_16BIT (0x03)
119#define CS42L52_IFACE_CTL1_WL_MASK 0xFFFF
120
121#define CS42L52_IFACE_CTL2 0x07
122#define CS42L52_IFACE_CTL2_SC_MC_EQ (1 << 6)
123#define CS42L52_IFACE_CTL2_LOOPBACK (1 << 5)
124#define CS42L52_IFACE_CTL2_S_MODE_OUTPUT_EN (0 << 4)
125#define CS42L52_IFACE_CTL2_S_MODE_OUTPUT_HIZ (1 << 4)
126#define CS42L52_IFACE_CTL2_HP_SW_INV (1 << 3)
127#define CS42L52_IFACE_CTL2_BIAS_LVL 0x07
128
129#define CS42L52_ADC_PGA_A 0x08
130#define CS42L52_ADC_PGA_B 0x09
131#define CS42L52_ADC_SEL_SHIFT 5
132#define CS42L52_ADC_SEL_AIN1 0x00
133#define CS42L52_ADC_SEL_AIN2 0x01
134#define CS42L52_ADC_SEL_AIN3 0x02
135#define CS42L52_ADC_SEL_AIN4 0x03
136#define CS42L52_ADC_SEL_PGA 0x04
137
138#define CS42L52_ANALOG_HPF_CTL 0x0A
139#define CS42L52_HPF_CTL_ANLGSFTB (1 << 3)
140#define CS42L52_HPF_CTL_ANLGSFTA (1 << 0)
141
142#define CS42L52_ADC_HPF_FREQ 0x0B
143#define CS42L52_ADC_MISC_CTL 0x0C
144#define CS42L52_ADC_MISC_CTL_SOURCE_DSP (1 << 6)
145
146#define CS42L52_PB_CTL1 0x0D
147#define CS42L52_PB_CTL1_HP_GAIN_SHIFT 5
148#define CS42L52_PB_CTL1_HP_GAIN_03959 0x00
149#define CS42L52_PB_CTL1_HP_GAIN_04571 0x01
150#define CS42L52_PB_CTL1_HP_GAIN_05111 0x02
151#define CS42L52_PB_CTL1_HP_GAIN_06047 0x03
152#define CS42L52_PB_CTL1_HP_GAIN_07099 0x04
153#define CS42L52_PB_CTL1_HP_GAIN_08399 0x05
154#define CS42L52_PB_CTL1_HP_GAIN_10000 0x06
155#define CS42L52_PB_CTL1_HP_GAIN_11430 0x07
156#define CS42L52_PB_CTL1_INV_PCMB (1 << 3)
157#define CS42L52_PB_CTL1_INV_PCMA (1 << 2)
158#define CS42L52_PB_CTL1_MSTB_MUTE (1 << 1)
159#define CS42L52_PB_CTL1_MSTA_MUTE (1 << 0)
160#define CS42L52_PB_CTL1_MUTE_MASK 0xFFFD
161#define CS42L52_PB_CTL1_MUTE 3
162#define CS42L52_PB_CTL1_UNMUTE 0
163
164#define CS42L52_MISC_CTL 0x0E
165#define CS42L52_MISC_CTL_DEEMPH (1 << 2)
166#define CS42L52_MISC_CTL_DIGSFT (1 << 1)
167#define CS42L52_MISC_CTL_DIGZC (1 << 0)
168
169#define CS42L52_PB_CTL2 0x0F
170#define CS42L52_PB_CTL2_HPB_MUTE (1 << 7)
171#define CS42L52_PB_CTL2_HPA_MUTE (1 << 6)
172#define CS42L52_PB_CTL2_SPKB_MUTE (1 << 5)
173#define CS42L52_PB_CTL2_SPKA_MUTE (1 << 4)
174#define CS42L52_PB_CTL2_SPK_SWAP (1 << 2)
175#define CS42L52_PB_CTL2_SPK_MONO (1 << 1)
176#define CS42L52_PB_CTL2_SPK_MUTE50 (1 << 0)
177
178#define CS42L52_MICA_CTL 0x10
179#define CS42L52_MICB_CTL 0x11
180#define CS42L52_MIC_CTL_MIC_SEL_MASK 0xBF
181#define CS42L52_MIC_CTL_MIC_SEL_SHIFT 6
182#define CS42L52_MIC_CTL_TYPE_MASK 0xDF
183#define CS42L52_MIC_CTL_TYPE_SHIFT 5
184
185
186#define CS42L52_PGAA_CTL 0x12
187#define CS42L52_PGAB_CTL 0x13
188#define CS42L52_PGAX_CTL_VOL_12DB 24
189#define CS42L52_PGAX_CTL_VOL_6DB 12 /*step size 0.5db*/
190
191#define CS42L52_PASSTHRUA_VOL 0x14
192#define CS42L52_PASSTHRUB_VOL 0x15
193
194#define CS42L52_ADCA_VOL 0x16
195#define CS42L52_ADCB_VOL 0x17
196#define CS42L52_ADCX_VOL_24DB 24 /*step size 1db*/
197#define CS42L52_ADCX_VOL_12DB 12
198#define CS42L52_ADCX_VOL_6DB 6
199
200#define CS42L52_ADCA_MIXER_VOL 0x18
201#define CS42L52_ADCB_MIXER_VOL 0x19
202#define CS42L52_ADC_MIXER_VOL_12DB 0x18
203
204#define CS42L52_PCMA_MIXER_VOL 0x1A
205#define CS42L52_PCMB_MIXER_VOL 0x1B
206
207#define CS42L52_BEEP_FREQ 0x1C
208#define CS42L52_BEEP_VOL 0x1D
209#define CS42L52_BEEP_TONE_CTL 0x1E
210#define CS42L52_BEEP_RATE_SHIFT 4
211#define CS42L52_BEEP_RATE_MASK 0x0F
212
213#define CS42L52_TONE_CTL 0x1F
214#define CS42L52_BEEP_EN_MASK 0x3F
215
216#define CS42L52_MASTERA_VOL 0x20
217#define CS42L52_MASTERB_VOL 0x21
218
219#define CS42L52_HPA_VOL 0x22
220#define CS42L52_HPB_VOL 0x23
221#define CS42L52_DEFAULT_HP_VOL 0xF0
222
223#define CS42L52_SPKA_VOL 0x24
224#define CS42L52_SPKB_VOL 0x25
225#define CS42L52_DEFAULT_SPK_VOL 0xF0
226
227#define CS42L52_ADC_PCM_MIXER 0x26
228
229#define CS42L52_LIMITER_CTL1 0x27
230#define CS42L52_LIMITER_CTL2 0x28
231#define CS42L52_LIMITER_AT_RATE 0x29
232
233#define CS42L52_ALC_CTL 0x2A
234#define CS42L52_ALC_CTL_ALCB_ENABLE_SHIFT 7
235#define CS42L52_ALC_CTL_ALCA_ENABLE_SHIFT 6
236#define CS42L52_ALC_CTL_FASTEST_ATTACK 0
237
238#define CS42L52_ALC_RATE 0x2B
239#define CS42L52_ALC_SLOWEST_RELEASE 0x3F
240
241#define CS42L52_ALC_THRESHOLD 0x2C
242#define CS42L52_ALC_MAX_RATE_SHIFT 5
243#define CS42L52_ALC_MIN_RATE_SHIFT 2
244#define CS42L52_ALC_RATE_0DB 0
245#define CS42L52_ALC_RATE_3DB 1
246#define CS42L52_ALC_RATE_6DB 2
247
248#define CS42L52_NOISE_GATE_CTL 0x2D
249#define CS42L52_NG_ENABLE_SHIFT 6
250#define CS42L52_NG_THRESHOLD_SHIFT 2
251#define CS42L52_NG_MIN_70DB 2
252#define CS42L52_NG_DELAY_SHIFT 0
253#define CS42L52_NG_DELAY_100MS 1
254
255#define CS42L52_CLK_STATUS 0x2E
256#define CS42L52_BATT_COMPEN 0x2F
257
258#define CS42L52_BATT_LEVEL 0x30
259#define CS42L52_SPK_STATUS 0x31
260#define CS42L52_SPK_STATUS_PIN_SHIFT 3
261#define CS42L52_SPK_STATUS_PIN_HIGH 1
262
263#define CS42L52_TEM_CTL 0x32
264#define CS42L52_TEM_CTL_SET 0x80
265#define CS42L52_THE_FOLDBACK 0x33
266#define CS42L52_CHARGE_PUMP 0x34
267#define CS42L52_CHARGE_PUMP_MASK 0xF0
268#define CS42L52_CHARGE_PUMP_SHIFT 4
269#define CS42L52_FIX_BITS1 0x3E
270#define CS42L52_FIX_BITS2 0x47
271
272#define CS42L52_MAX_REGISTER 0x34
273
274#endif
diff --git a/sound/soc/codecs/cs42l73.c b/sound/soc/codecs/cs42l73.c
index 3686417f5ea5..e0d45fdaa750 100644
--- a/sound/soc/codecs/cs42l73.c
+++ b/sound/soc/codecs/cs42l73.c
@@ -43,9 +43,6 @@ struct cs42l73_private {
43}; 43};
44 44
45static const struct reg_default cs42l73_reg_defaults[] = { 45static const struct reg_default cs42l73_reg_defaults[] = {
46 { 1, 0x42 }, /* r01 - Device ID A&B */
47 { 2, 0xA7 }, /* r02 - Device ID C&D */
48 { 3, 0x30 }, /* r03 - Device ID E */
49 { 6, 0xF1 }, /* r06 - Power Ctl 1 */ 46 { 6, 0xF1 }, /* r06 - Power Ctl 1 */
50 { 7, 0xDF }, /* r07 - Power Ctl 2 */ 47 { 7, 0xDF }, /* r07 - Power Ctl 2 */
51 { 8, 0x3F }, /* r08 - Power Ctl 3 */ 48 { 8, 0x3F }, /* r08 - Power Ctl 3 */
@@ -402,37 +399,37 @@ static const struct snd_kcontrol_new ear_amp_ctl =
402 399
403static const struct snd_kcontrol_new cs42l73_snd_controls[] = { 400static const struct snd_kcontrol_new cs42l73_snd_controls[] = {
404 SOC_DOUBLE_R_SX_TLV("Headphone Analog Playback Volume", 401 SOC_DOUBLE_R_SX_TLV("Headphone Analog Playback Volume",
405 CS42L73_HPAAVOL, CS42L73_HPBAVOL, 7, 402 CS42L73_HPAAVOL, CS42L73_HPBAVOL, 0,
406 0xffffffC1, 0x0C, hpaloa_tlv), 403 0x41, 0x4B, hpaloa_tlv),
407 404
408 SOC_DOUBLE_R_SX_TLV("LineOut Analog Playback Volume", CS42L73_LOAAVOL, 405 SOC_DOUBLE_R_SX_TLV("LineOut Analog Playback Volume", CS42L73_LOAAVOL,
409 CS42L73_LOBAVOL, 7, 0xffffffC1, 0x0C, hpaloa_tlv), 406 CS42L73_LOBAVOL, 0, 0x41, 0x4B, hpaloa_tlv),
410 407
411 SOC_DOUBLE_R_SX_TLV("Input PGA Analog Volume", CS42L73_MICAPREPGAAVOL, 408 SOC_DOUBLE_R_SX_TLV("Input PGA Analog Volume", CS42L73_MICAPREPGAAVOL,
412 CS42L73_MICBPREPGABVOL, 5, 0xffffff35, 409 CS42L73_MICBPREPGABVOL, 5, 0x34,
413 0x34, micpga_tlv), 410 0x24, micpga_tlv),
414 411
415 SOC_DOUBLE_R("MIC Preamp Switch", CS42L73_MICAPREPGAAVOL, 412 SOC_DOUBLE_R("MIC Preamp Switch", CS42L73_MICAPREPGAAVOL,
416 CS42L73_MICBPREPGABVOL, 6, 1, 1), 413 CS42L73_MICBPREPGABVOL, 6, 1, 1),
417 414
418 SOC_DOUBLE_R_SX_TLV("Input Path Digital Volume", CS42L73_IPADVOL, 415 SOC_DOUBLE_R_SX_TLV("Input Path Digital Volume", CS42L73_IPADVOL,
419 CS42L73_IPBDVOL, 7, 0xffffffA0, 0xA0, ipd_tlv), 416 CS42L73_IPBDVOL, 0, 0xA0, 0x6C, ipd_tlv),
420 417
421 SOC_DOUBLE_R_SX_TLV("HL Digital Playback Volume", 418 SOC_DOUBLE_R_SX_TLV("HL Digital Playback Volume",
422 CS42L73_HLADVOL, CS42L73_HLBDVOL, 7, 0xffffffE5, 419 CS42L73_HLADVOL, CS42L73_HLBDVOL,
423 0xE4, hl_tlv), 420 0, 0x34, 0xE4, hl_tlv),
424 421
425 SOC_SINGLE_TLV("ADC A Boost Volume", 422 SOC_SINGLE_TLV("ADC A Boost Volume",
426 CS42L73_ADCIPC, 2, 0x01, 1, adc_boost_tlv), 423 CS42L73_ADCIPC, 2, 0x01, 1, adc_boost_tlv),
427 424
428 SOC_SINGLE_TLV("ADC B Boost Volume", 425 SOC_SINGLE_TLV("ADC B Boost Volume",
429 CS42L73_ADCIPC, 6, 0x01, 1, adc_boost_tlv), 426 CS42L73_ADCIPC, 6, 0x01, 1, adc_boost_tlv),
430 427
431 SOC_SINGLE_TLV("Speakerphone Digital Playback Volume", 428 SOC_SINGLE_SX_TLV("Speakerphone Digital Volume",
432 CS42L73_SPKDVOL, 0, 0xE4, 1, hl_tlv), 429 CS42L73_SPKDVOL, 0, 0x34, 0xE4, hl_tlv),
433 430
434 SOC_SINGLE_TLV("Ear Speaker Digital Playback Volume", 431 SOC_SINGLE_SX_TLV("Ear Speaker Digital Volume",
435 CS42L73_ESLDVOL, 0, 0xE4, 1, hl_tlv), 432 CS42L73_ESLDVOL, 0, 0x34, 0xE4, hl_tlv),
436 433
437 SOC_DOUBLE_R("Headphone Analog Playback Switch", CS42L73_HPAAVOL, 434 SOC_DOUBLE_R("Headphone Analog Playback Switch", CS42L73_HPAAVOL,
438 CS42L73_HPBAVOL, 7, 1, 1), 435 CS42L73_HPBAVOL, 7, 1, 1),
@@ -599,17 +596,17 @@ static const struct snd_soc_dapm_widget cs42l73_dapm_widgets[] = {
599 SND_SOC_DAPM_INPUT("MIC2"), 596 SND_SOC_DAPM_INPUT("MIC2"),
600 SND_SOC_DAPM_SUPPLY("MIC2 Bias", CS42L73_PWRCTL2, 7, 1, NULL, 0), 597 SND_SOC_DAPM_SUPPLY("MIC2 Bias", CS42L73_PWRCTL2, 7, 1, NULL, 0),
601 598
602 SND_SOC_DAPM_AIF_OUT("XSPOUTL", "XSP Capture", 0, 599 SND_SOC_DAPM_AIF_OUT("XSPOUTL", NULL, 0,
603 CS42L73_PWRCTL2, 1, 1), 600 CS42L73_PWRCTL2, 1, 1),
604 SND_SOC_DAPM_AIF_OUT("XSPOUTR", "XSP Capture", 0, 601 SND_SOC_DAPM_AIF_OUT("XSPOUTR", NULL, 0,
605 CS42L73_PWRCTL2, 1, 1), 602 CS42L73_PWRCTL2, 1, 1),
606 SND_SOC_DAPM_AIF_OUT("ASPOUTL", "ASP Capture", 0, 603 SND_SOC_DAPM_AIF_OUT("ASPOUTL", NULL, 0,
607 CS42L73_PWRCTL2, 3, 1), 604 CS42L73_PWRCTL2, 3, 1),
608 SND_SOC_DAPM_AIF_OUT("ASPOUTR", "ASP Capture", 0, 605 SND_SOC_DAPM_AIF_OUT("ASPOUTR", NULL, 0,
609 CS42L73_PWRCTL2, 3, 1), 606 CS42L73_PWRCTL2, 3, 1),
610 SND_SOC_DAPM_AIF_OUT("VSPOUTL", "VSP Capture", 0, 607 SND_SOC_DAPM_AIF_OUT("VSPOUTL", NULL, 0,
611 CS42L73_PWRCTL2, 4, 1), 608 CS42L73_PWRCTL2, 4, 1),
612 SND_SOC_DAPM_AIF_OUT("VSPOUTR", "VSP Capture", 0, 609 SND_SOC_DAPM_AIF_OUT("VSPOUTR", NULL, 0,
613 CS42L73_PWRCTL2, 4, 1), 610 CS42L73_PWRCTL2, 4, 1),
614 611
615 SND_SOC_DAPM_PGA("PGA Left", SND_SOC_NOPM, 0, 0, NULL, 0), 612 SND_SOC_DAPM_PGA("PGA Left", SND_SOC_NOPM, 0, 0, NULL, 0),
@@ -638,21 +635,21 @@ static const struct snd_soc_dapm_widget cs42l73_dapm_widgets[] = {
638 SND_SOC_DAPM_MIXER("VSPL Output Mixer", SND_SOC_NOPM, 0, 0, NULL, 0), 635 SND_SOC_DAPM_MIXER("VSPL Output Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
639 SND_SOC_DAPM_MIXER("VSPR Output Mixer", SND_SOC_NOPM, 0, 0, NULL, 0), 636 SND_SOC_DAPM_MIXER("VSPR Output Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
640 637
641 SND_SOC_DAPM_AIF_IN("XSPINL", "XSP Playback", 0, 638 SND_SOC_DAPM_AIF_IN("XSPINL", NULL, 0,
642 CS42L73_PWRCTL2, 0, 1), 639 CS42L73_PWRCTL2, 0, 1),
643 SND_SOC_DAPM_AIF_IN("XSPINR", "XSP Playback", 0, 640 SND_SOC_DAPM_AIF_IN("XSPINR", NULL, 0,
644 CS42L73_PWRCTL2, 0, 1), 641 CS42L73_PWRCTL2, 0, 1),
645 SND_SOC_DAPM_AIF_IN("XSPINM", "XSP Playback", 0, 642 SND_SOC_DAPM_AIF_IN("XSPINM", NULL, 0,
646 CS42L73_PWRCTL2, 0, 1), 643 CS42L73_PWRCTL2, 0, 1),
647 644
648 SND_SOC_DAPM_AIF_IN("ASPINL", "ASP Playback", 0, 645 SND_SOC_DAPM_AIF_IN("ASPINL", NULL, 0,
649 CS42L73_PWRCTL2, 2, 1), 646 CS42L73_PWRCTL2, 2, 1),
650 SND_SOC_DAPM_AIF_IN("ASPINR", "ASP Playback", 0, 647 SND_SOC_DAPM_AIF_IN("ASPINR", NULL, 0,
651 CS42L73_PWRCTL2, 2, 1), 648 CS42L73_PWRCTL2, 2, 1),
652 SND_SOC_DAPM_AIF_IN("ASPINM", "ASP Playback", 0, 649 SND_SOC_DAPM_AIF_IN("ASPINM", NULL, 0,
653 CS42L73_PWRCTL2, 2, 1), 650 CS42L73_PWRCTL2, 2, 1),
654 651
655 SND_SOC_DAPM_AIF_IN("VSPIN", "VSP Playback", 0, 652 SND_SOC_DAPM_AIF_IN("VSPIN", NULL, 0,
656 CS42L73_PWRCTL2, 4, 1), 653 CS42L73_PWRCTL2, 4, 1),
657 654
658 SND_SOC_DAPM_MIXER("HL Left Mixer", SND_SOC_NOPM, 0, 0, NULL, 0), 655 SND_SOC_DAPM_MIXER("HL Left Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
@@ -776,6 +773,14 @@ static const struct snd_soc_dapm_route cs42l73_audio_map[] = {
776 {"HL Left Mixer", NULL, "VSPIN"}, 773 {"HL Left Mixer", NULL, "VSPIN"},
777 {"HL Right Mixer", NULL, "VSPIN"}, 774 {"HL Right Mixer", NULL, "VSPIN"},
778 775
776 {"ASPINL", NULL, "ASP Playback"},
777 {"ASPINM", NULL, "ASP Playback"},
778 {"ASPINR", NULL, "ASP Playback"},
779 {"XSPINL", NULL, "XSP Playback"},
780 {"XSPINM", NULL, "XSP Playback"},
781 {"XSPINR", NULL, "XSP Playback"},
782 {"VSPIN", NULL, "VSP Playback"},
783
779 /* Capture Paths */ 784 /* Capture Paths */
780 {"MIC1", NULL, "MIC1 Bias"}, 785 {"MIC1", NULL, "MIC1 Bias"},
781 {"PGA Left Mux", "Mic 1", "MIC1"}, 786 {"PGA Left Mux", "Mic 1", "MIC1"},
@@ -822,6 +827,13 @@ static const struct snd_soc_dapm_route cs42l73_audio_map[] = {
822 827
823 {"VSPOUTL", NULL, "VSPL Output Mixer"}, 828 {"VSPOUTL", NULL, "VSPL Output Mixer"},
824 {"VSPOUTR", NULL, "VSPR Output Mixer"}, 829 {"VSPOUTR", NULL, "VSPR Output Mixer"},
830
831 {"ASP Capture", NULL, "ASPOUTL"},
832 {"ASP Capture", NULL, "ASPOUTR"},
833 {"XSP Capture", NULL, "XSPOUTL"},
834 {"XSP Capture", NULL, "XSPOUTR"},
835 {"VSP Capture", NULL, "VSPOUTL"},
836 {"VSP Capture", NULL, "VSPOUTR"},
825}; 837};
826 838
827struct cs42l73_mclk_div { 839struct cs42l73_mclk_div {
@@ -1091,8 +1103,7 @@ static int cs42l73_pcm_hw_params(struct snd_pcm_substream *substream,
1091 struct snd_pcm_hw_params *params, 1103 struct snd_pcm_hw_params *params,
1092 struct snd_soc_dai *dai) 1104 struct snd_soc_dai *dai)
1093{ 1105{
1094 struct snd_soc_pcm_runtime *rtd = substream->private_data; 1106 struct snd_soc_codec *codec = dai->codec;
1095 struct snd_soc_codec *codec = rtd->codec;
1096 struct cs42l73_private *priv = snd_soc_codec_get_drvdata(codec); 1107 struct cs42l73_private *priv = snd_soc_codec_get_drvdata(codec);
1097 int id = dai->id; 1108 int id = dai->id;
1098 int mclk_coeff; 1109 int mclk_coeff;
@@ -1429,25 +1440,7 @@ static struct i2c_driver cs42l73_i2c_driver = {
1429 1440
1430}; 1441};
1431 1442
1432static int __init cs42l73_modinit(void) 1443module_i2c_driver(cs42l73_i2c_driver);
1433{
1434 int ret;
1435 ret = i2c_add_driver(&cs42l73_i2c_driver);
1436 if (ret != 0) {
1437 pr_err("Failed to register CS42L73 I2C driver: %d\n", ret);
1438 return ret;
1439 }
1440 return 0;
1441}
1442
1443module_init(cs42l73_modinit);
1444
1445static void __exit cs42l73_exit(void)
1446{
1447 i2c_del_driver(&cs42l73_i2c_driver);
1448}
1449
1450module_exit(cs42l73_exit);
1451 1444
1452MODULE_DESCRIPTION("ASoC CS42L73 driver"); 1445MODULE_DESCRIPTION("ASoC CS42L73 driver");
1453MODULE_AUTHOR("Georgi Vlaev, Nucleus Systems Ltd, <joe@nucleusys.com>"); 1446MODULE_AUTHOR("Georgi Vlaev, Nucleus Systems Ltd, <joe@nucleusys.com>");
diff --git a/sound/soc/codecs/da7210.c b/sound/soc/codecs/da7210.c
index 7843711729bc..af5db7080519 100644
--- a/sound/soc/codecs/da7210.c
+++ b/sound/soc/codecs/da7210.c
@@ -17,6 +17,7 @@
17 17
18#include <linux/delay.h> 18#include <linux/delay.h>
19#include <linux/i2c.h> 19#include <linux/i2c.h>
20#include <linux/spi/spi.h>
20#include <linux/regmap.h> 21#include <linux/regmap.h>
21#include <linux/slab.h> 22#include <linux/slab.h>
22#include <linux/module.h> 23#include <linux/module.h>
@@ -27,6 +28,7 @@
27#include <sound/tlv.h> 28#include <sound/tlv.h>
28 29
29/* DA7210 register space */ 30/* DA7210 register space */
31#define DA7210_PAGE_CONTROL 0x00
30#define DA7210_CONTROL 0x01 32#define DA7210_CONTROL 0x01
31#define DA7210_STATUS 0x02 33#define DA7210_STATUS 0x02
32#define DA7210_STARTUP1 0x03 34#define DA7210_STARTUP1 0x03
@@ -146,6 +148,7 @@
146#define DA7210_DAI_EN (1 << 7) 148#define DA7210_DAI_EN (1 << 7)
147 149
148/*PLL_DIV3 bit fields */ 150/*PLL_DIV3 bit fields */
151#define DA7210_PLL_DIV_L_MASK (0xF << 0)
149#define DA7210_MCLK_RANGE_10_20_MHZ (1 << 4) 152#define DA7210_MCLK_RANGE_10_20_MHZ (1 << 4)
150#define DA7210_PLL_BYP (1 << 6) 153#define DA7210_PLL_BYP (1 << 6)
151 154
@@ -162,12 +165,16 @@
162#define DA7210_PLL_FS_48000 (0xB << 0) 165#define DA7210_PLL_FS_48000 (0xB << 0)
163#define DA7210_PLL_FS_88200 (0xE << 0) 166#define DA7210_PLL_FS_88200 (0xE << 0)
164#define DA7210_PLL_FS_96000 (0xF << 0) 167#define DA7210_PLL_FS_96000 (0xF << 0)
168#define DA7210_MCLK_DET_EN (0x1 << 5)
169#define DA7210_MCLK_SRM_EN (0x1 << 6)
165#define DA7210_PLL_EN (0x1 << 7) 170#define DA7210_PLL_EN (0x1 << 7)
166 171
167/* SOFTMUTE bit fields */ 172/* SOFTMUTE bit fields */
168#define DA7210_RAMP_EN (1 << 6) 173#define DA7210_RAMP_EN (1 << 6)
169 174
170/* CONTROL bit fields */ 175/* CONTROL bit fields */
176#define DA7210_REG_EN (1 << 0)
177#define DA7210_BIAS_EN (1 << 2)
171#define DA7210_NOISE_SUP_EN (1 << 3) 178#define DA7210_NOISE_SUP_EN (1 << 3)
172 179
173/* IN_GAIN bit fields */ 180/* IN_GAIN bit fields */
@@ -206,6 +213,47 @@
206#define DA7210_OUT2_OUTMIX_L (1 << 6) 213#define DA7210_OUT2_OUTMIX_L (1 << 6)
207#define DA7210_OUT2_EN (1 << 7) 214#define DA7210_OUT2_EN (1 << 7)
208 215
216struct pll_div {
217 int fref;
218 int fout;
219 u8 div1;
220 u8 div2;
221 u8 div3;
222 u8 mode; /* 0 = slave, 1 = master */
223};
224
225/* PLL dividers table */
226static const struct pll_div da7210_pll_div[] = {
227 /* for MASTER mode, fs = 44.1Khz */
228 { 12000000, 2822400, 0xE8, 0x6C, 0x2, 1}, /* MCLK=12Mhz */
229 { 13000000, 2822400, 0xDF, 0x28, 0xC, 1}, /* MCLK=13Mhz */
230 { 13500000, 2822400, 0xDB, 0x0A, 0xD, 1}, /* MCLK=13.5Mhz */
231 { 14400000, 2822400, 0xD4, 0x5A, 0x2, 1}, /* MCLK=14.4Mhz */
232 { 19200000, 2822400, 0xBB, 0x43, 0x9, 1}, /* MCLK=19.2Mhz */
233 { 19680000, 2822400, 0xB9, 0x6D, 0xA, 1}, /* MCLK=19.68Mhz */
234 { 19800000, 2822400, 0xB8, 0xFB, 0xB, 1}, /* MCLK=19.8Mhz */
235 /* for MASTER mode, fs = 48Khz */
236 { 12000000, 3072000, 0xF3, 0x12, 0x7, 1}, /* MCLK=12Mhz */
237 { 13000000, 3072000, 0xE8, 0xFD, 0x5, 1}, /* MCLK=13Mhz */
238 { 13500000, 3072000, 0xE4, 0x82, 0x3, 1}, /* MCLK=13.5Mhz */
239 { 14400000, 3072000, 0xDD, 0x3A, 0x0, 1}, /* MCLK=14.4Mhz */
240 { 19200000, 3072000, 0xC1, 0xEB, 0x8, 1}, /* MCLK=19.2Mhz */
241 { 19680000, 3072000, 0xBF, 0xEC, 0x0, 1}, /* MCLK=19.68Mhz */
242 { 19800000, 3072000, 0xBF, 0x70, 0x0, 1}, /* MCLK=19.8Mhz */
243 /* for SLAVE mode with SRM */
244 { 12000000, 2822400, 0xED, 0xBF, 0x5, 0}, /* MCLK=12Mhz */
245 { 13000000, 2822400, 0xE4, 0x13, 0x0, 0}, /* MCLK=13Mhz */
246 { 13500000, 2822400, 0xDF, 0xC6, 0x8, 0}, /* MCLK=13.5Mhz */
247 { 14400000, 2822400, 0xD8, 0xCA, 0x1, 0}, /* MCLK=14.4Mhz */
248 { 19200000, 2822400, 0xBE, 0x97, 0x9, 0}, /* MCLK=19.2Mhz */
249 { 19680000, 2822400, 0xBC, 0xAC, 0xD, 0}, /* MCLK=19.68Mhz */
250 { 19800000, 2822400, 0xBC, 0x35, 0xE, 0}, /* MCLK=19.8Mhz */
251};
252
253enum clk_src {
254 DA7210_CLKSRC_MCLK
255};
256
209#define DA7210_VERSION "0.0.1" 257#define DA7210_VERSION "0.0.1"
210 258
211/* 259/*
@@ -628,9 +676,12 @@ static const struct snd_soc_dapm_route da7210_audio_map[] = {
628/* Codec private data */ 676/* Codec private data */
629struct da7210_priv { 677struct da7210_priv {
630 struct regmap *regmap; 678 struct regmap *regmap;
679 unsigned int mclk_rate;
680 int master;
631}; 681};
632 682
633static struct reg_default da7210_reg_defaults[] = { 683static struct reg_default da7210_reg_defaults[] = {
684 { 0x00, 0x00 },
634 { 0x01, 0x11 }, 685 { 0x01, 0x11 },
635 { 0x03, 0x00 }, 686 { 0x03, 0x00 },
636 { 0x04, 0x00 }, 687 { 0x04, 0x00 },
@@ -713,10 +764,10 @@ static int da7210_hw_params(struct snd_pcm_substream *substream,
713 struct snd_pcm_hw_params *params, 764 struct snd_pcm_hw_params *params,
714 struct snd_soc_dai *dai) 765 struct snd_soc_dai *dai)
715{ 766{
716 struct snd_soc_pcm_runtime *rtd = substream->private_data; 767 struct snd_soc_codec *codec = dai->codec;
717 struct snd_soc_codec *codec = rtd->codec; 768 struct da7210_priv *da7210 = snd_soc_codec_get_drvdata(codec);
718 u32 dai_cfg1; 769 u32 dai_cfg1;
719 u32 fs, bypass; 770 u32 fs, sysclk;
720 771
721 /* set DAI source to Left and Right ADC */ 772 /* set DAI source to Left and Right ADC */
722 snd_soc_write(codec, DA7210_DAI_SRC_SEL, 773 snd_soc_write(codec, DA7210_DAI_SRC_SEL,
@@ -749,43 +800,43 @@ static int da7210_hw_params(struct snd_pcm_substream *substream,
749 switch (params_rate(params)) { 800 switch (params_rate(params)) {
750 case 8000: 801 case 8000:
751 fs = DA7210_PLL_FS_8000; 802 fs = DA7210_PLL_FS_8000;
752 bypass = DA7210_PLL_BYP; 803 sysclk = 3072000;
753 break; 804 break;
754 case 11025: 805 case 11025:
755 fs = DA7210_PLL_FS_11025; 806 fs = DA7210_PLL_FS_11025;
756 bypass = 0; 807 sysclk = 2822400;
757 break; 808 break;
758 case 12000: 809 case 12000:
759 fs = DA7210_PLL_FS_12000; 810 fs = DA7210_PLL_FS_12000;
760 bypass = DA7210_PLL_BYP; 811 sysclk = 3072000;
761 break; 812 break;
762 case 16000: 813 case 16000:
763 fs = DA7210_PLL_FS_16000; 814 fs = DA7210_PLL_FS_16000;
764 bypass = DA7210_PLL_BYP; 815 sysclk = 3072000;
765 break; 816 break;
766 case 22050: 817 case 22050:
767 fs = DA7210_PLL_FS_22050; 818 fs = DA7210_PLL_FS_22050;
768 bypass = 0; 819 sysclk = 2822400;
769 break; 820 break;
770 case 32000: 821 case 32000:
771 fs = DA7210_PLL_FS_32000; 822 fs = DA7210_PLL_FS_32000;
772 bypass = DA7210_PLL_BYP; 823 sysclk = 3072000;
773 break; 824 break;
774 case 44100: 825 case 44100:
775 fs = DA7210_PLL_FS_44100; 826 fs = DA7210_PLL_FS_44100;
776 bypass = 0; 827 sysclk = 2822400;
777 break; 828 break;
778 case 48000: 829 case 48000:
779 fs = DA7210_PLL_FS_48000; 830 fs = DA7210_PLL_FS_48000;
780 bypass = DA7210_PLL_BYP; 831 sysclk = 3072000;
781 break; 832 break;
782 case 88200: 833 case 88200:
783 fs = DA7210_PLL_FS_88200; 834 fs = DA7210_PLL_FS_88200;
784 bypass = 0; 835 sysclk = 2822400;
785 break; 836 break;
786 case 96000: 837 case 96000:
787 fs = DA7210_PLL_FS_96000; 838 fs = DA7210_PLL_FS_96000;
788 bypass = DA7210_PLL_BYP; 839 sysclk = 3072000;
789 break; 840 break;
790 default: 841 default:
791 return -EINVAL; 842 return -EINVAL;
@@ -795,8 +846,26 @@ static int da7210_hw_params(struct snd_pcm_substream *substream,
795 snd_soc_update_bits(codec, DA7210_STARTUP1, DA7210_SC_MST_EN, 0); 846 snd_soc_update_bits(codec, DA7210_STARTUP1, DA7210_SC_MST_EN, 0);
796 847
797 snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_FS_MASK, fs); 848 snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_FS_MASK, fs);
798 snd_soc_update_bits(codec, DA7210_PLL_DIV3, DA7210_PLL_BYP, bypass);
799 849
850 if (da7210->mclk_rate && (da7210->mclk_rate != sysclk)) {
851 /* PLL mode, disable PLL bypass */
852 snd_soc_update_bits(codec, DA7210_PLL_DIV3, DA7210_PLL_BYP, 0);
853
854 if (!da7210->master) {
855 /* PLL slave mode, also enable SRM */
856 snd_soc_update_bits(codec, DA7210_PLL,
857 (DA7210_MCLK_SRM_EN |
858 DA7210_MCLK_DET_EN),
859 (DA7210_MCLK_SRM_EN |
860 DA7210_MCLK_DET_EN));
861 }
862 } else {
863 /* PLL bypass mode, enable PLL bypass and Auto Detection */
864 snd_soc_update_bits(codec, DA7210_PLL, DA7210_MCLK_DET_EN,
865 DA7210_MCLK_DET_EN);
866 snd_soc_update_bits(codec, DA7210_PLL_DIV3, DA7210_PLL_BYP,
867 DA7210_PLL_BYP);
868 }
800 /* Enable active mode */ 869 /* Enable active mode */
801 snd_soc_update_bits(codec, DA7210_STARTUP1, 870 snd_soc_update_bits(codec, DA7210_STARTUP1,
802 DA7210_SC_MST_EN, DA7210_SC_MST_EN); 871 DA7210_SC_MST_EN, DA7210_SC_MST_EN);
@@ -810,17 +879,24 @@ static int da7210_hw_params(struct snd_pcm_substream *substream,
810static int da7210_set_dai_fmt(struct snd_soc_dai *codec_dai, u32 fmt) 879static int da7210_set_dai_fmt(struct snd_soc_dai *codec_dai, u32 fmt)
811{ 880{
812 struct snd_soc_codec *codec = codec_dai->codec; 881 struct snd_soc_codec *codec = codec_dai->codec;
882 struct da7210_priv *da7210 = snd_soc_codec_get_drvdata(codec);
813 u32 dai_cfg1; 883 u32 dai_cfg1;
814 u32 dai_cfg3; 884 u32 dai_cfg3;
815 885
816 dai_cfg1 = 0x7f & snd_soc_read(codec, DA7210_DAI_CFG1); 886 dai_cfg1 = 0x7f & snd_soc_read(codec, DA7210_DAI_CFG1);
817 dai_cfg3 = 0xfc & snd_soc_read(codec, DA7210_DAI_CFG3); 887 dai_cfg3 = 0xfc & snd_soc_read(codec, DA7210_DAI_CFG3);
818 888
889 if ((snd_soc_read(codec, DA7210_PLL) & DA7210_PLL_EN) &&
890 (!(snd_soc_read(codec, DA7210_PLL_DIV3) & DA7210_PLL_BYP)))
891 return -EINVAL;
892
819 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { 893 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
820 case SND_SOC_DAIFMT_CBM_CFM: 894 case SND_SOC_DAIFMT_CBM_CFM:
895 da7210->master = 1;
821 dai_cfg1 |= DA7210_DAI_MODE_MASTER; 896 dai_cfg1 |= DA7210_DAI_MODE_MASTER;
822 break; 897 break;
823 case SND_SOC_DAIFMT_CBS_CFS: 898 case SND_SOC_DAIFMT_CBS_CFS:
899 da7210->master = 0;
824 dai_cfg1 |= DA7210_DAI_MODE_SLAVE; 900 dai_cfg1 |= DA7210_DAI_MODE_SLAVE;
825 break; 901 break;
826 default: 902 default:
@@ -872,10 +948,101 @@ static int da7210_mute(struct snd_soc_dai *dai, int mute)
872#define DA7210_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ 948#define DA7210_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
873 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE) 949 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
874 950
951static int da7210_set_dai_sysclk(struct snd_soc_dai *codec_dai,
952 int clk_id, unsigned int freq, int dir)
953{
954 struct snd_soc_codec *codec = codec_dai->codec;
955 struct da7210_priv *da7210 = snd_soc_codec_get_drvdata(codec);
956
957 switch (clk_id) {
958 case DA7210_CLKSRC_MCLK:
959 switch (freq) {
960 case 12000000:
961 case 13000000:
962 case 13500000:
963 case 14400000:
964 case 19200000:
965 case 19680000:
966 case 19800000:
967 da7210->mclk_rate = freq;
968 return 0;
969 default:
970 dev_err(codec_dai->dev, "Unsupported MCLK value %d\n",
971 freq);
972 return -EINVAL;
973 }
974 break;
975 default:
976 dev_err(codec_dai->dev, "Unknown clock source %d\n", clk_id);
977 return -EINVAL;
978 }
979}
980
981/**
982 * da7210_set_dai_pll :Configure the codec PLL
983 * @param codec_dai : pointer to codec DAI
984 * @param pll_id : da7210 has only one pll, so pll_id is always zero
985 * @param fref : MCLK frequency, should be < 20MHz
986 * @param fout : FsDM value, Refer page 44 & 45 of datasheet
987 * @return int : Zero for success, negative error code for error
988 *
989 * Note: Supported PLL input frequencies are 12MHz, 13MHz, 13.5MHz, 14.4MHz,
990 * 19.2MHz, 19.6MHz and 19.8MHz
991 */
992static int da7210_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id,
993 int source, unsigned int fref, unsigned int fout)
994{
995 struct snd_soc_codec *codec = codec_dai->codec;
996 struct da7210_priv *da7210 = snd_soc_codec_get_drvdata(codec);
997
998 u8 pll_div1, pll_div2, pll_div3, cnt;
999
1000 /* In slave mode, there is only one set of divisors */
1001 if (!da7210->master)
1002 fout = 2822400;
1003
1004 /* Search pll div array for correct divisors */
1005 for (cnt = 0; cnt < ARRAY_SIZE(da7210_pll_div); cnt++) {
1006 /* check fref, mode and fout */
1007 if ((fref == da7210_pll_div[cnt].fref) &&
1008 (da7210->master == da7210_pll_div[cnt].mode) &&
1009 (fout == da7210_pll_div[cnt].fout)) {
1010 /* all match, pick up divisors */
1011 pll_div1 = da7210_pll_div[cnt].div1;
1012 pll_div2 = da7210_pll_div[cnt].div2;
1013 pll_div3 = da7210_pll_div[cnt].div3;
1014 break;
1015 }
1016 }
1017 if (cnt >= ARRAY_SIZE(da7210_pll_div))
1018 goto err;
1019
1020 /* Disable active mode */
1021 snd_soc_update_bits(codec, DA7210_STARTUP1, DA7210_SC_MST_EN, 0);
1022 /* Write PLL dividers */
1023 snd_soc_write(codec, DA7210_PLL_DIV1, pll_div1);
1024 snd_soc_write(codec, DA7210_PLL_DIV2, pll_div2);
1025 snd_soc_update_bits(codec, DA7210_PLL_DIV3,
1026 DA7210_PLL_DIV_L_MASK, pll_div3);
1027
1028 /* Enable PLL */
1029 snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_EN, DA7210_PLL_EN);
1030
1031 /* Enable active mode */
1032 snd_soc_update_bits(codec, DA7210_STARTUP1, DA7210_SC_MST_EN,
1033 DA7210_SC_MST_EN);
1034 return 0;
1035err:
1036 dev_err(codec_dai->dev, "Unsupported PLL input frequency %d\n", fref);
1037 return -EINVAL;
1038}
1039
875/* DAI operations */ 1040/* DAI operations */
876static const struct snd_soc_dai_ops da7210_dai_ops = { 1041static const struct snd_soc_dai_ops da7210_dai_ops = {
877 .hw_params = da7210_hw_params, 1042 .hw_params = da7210_hw_params,
878 .set_fmt = da7210_set_dai_fmt, 1043 .set_fmt = da7210_set_dai_fmt,
1044 .set_sysclk = da7210_set_dai_sysclk,
1045 .set_pll = da7210_set_dai_pll,
879 .digital_mute = da7210_mute, 1046 .digital_mute = da7210_mute,
880}; 1047};
881 1048
@@ -915,24 +1082,11 @@ static int da7210_probe(struct snd_soc_codec *codec)
915 return ret; 1082 return ret;
916 } 1083 }
917 1084
918 /* FIXME 1085 da7210->mclk_rate = 0; /* This will be set from set_sysclk() */
919 * 1086 da7210->master = 0; /* This will be set from set_fmt() */
920 * This driver use fixed value here
921 * And below settings expects MCLK = 12.288MHz
922 *
923 * When you select different MCLK, please check...
924 * DA7210_PLL_DIV1 val
925 * DA7210_PLL_DIV2 val
926 * DA7210_PLL_DIV3 val
927 * DA7210_PLL_DIV3 :: DA7210_MCLK_RANGExxx
928 */
929 1087
930 /* 1088 /* Enable internal regulator & bias current */
931 * make sure that DA7210 use bypass mode before start up 1089 snd_soc_write(codec, DA7210_CONTROL, DA7210_REG_EN | DA7210_BIAS_EN);
932 */
933 snd_soc_write(codec, DA7210_STARTUP1, 0);
934 snd_soc_write(codec, DA7210_PLL_DIV3,
935 DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP);
936 1090
937 /* 1091 /*
938 * ADC settings 1092 * ADC settings
@@ -1007,34 +1161,13 @@ static int da7210_probe(struct snd_soc_codec *codec)
1007 /* Enable Aux2 */ 1161 /* Enable Aux2 */
1008 snd_soc_write(codec, DA7210_AUX2, DA7210_AUX2_EN); 1162 snd_soc_write(codec, DA7210_AUX2, DA7210_AUX2_EN);
1009 1163
1164 /* Set PLL Master clock range 10-20 MHz, enable PLL bypass */
1165 snd_soc_write(codec, DA7210_PLL_DIV3, DA7210_MCLK_RANGE_10_20_MHZ |
1166 DA7210_PLL_BYP);
1167
1010 /* Diable PLL and bypass it */ 1168 /* Diable PLL and bypass it */
1011 snd_soc_write(codec, DA7210_PLL, DA7210_PLL_FS_48000); 1169 snd_soc_write(codec, DA7210_PLL, DA7210_PLL_FS_48000);
1012 1170
1013 /*
1014 * If 48kHz sound came, it use bypass mode,
1015 * and when it is 44.1kHz, it use PLL.
1016 *
1017 * This time, this driver sets PLL always ON
1018 * and controls bypass/PLL mode by switching
1019 * DA7210_PLL_DIV3 :: DA7210_PLL_BYP bit.
1020 * see da7210_hw_params
1021 */
1022 snd_soc_write(codec, DA7210_PLL_DIV1, 0xE5); /* MCLK = 12.288MHz */
1023 snd_soc_write(codec, DA7210_PLL_DIV2, 0x99);
1024 snd_soc_write(codec, DA7210_PLL_DIV3, 0x0A |
1025 DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP);
1026 snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_EN, DA7210_PLL_EN);
1027
1028 /* As suggested by Dialog */
1029 /* unlock */
1030 regmap_write(da7210->regmap, DA7210_A_HID_UNLOCK, 0x8B);
1031 regmap_write(da7210->regmap, DA7210_A_TEST_UNLOCK, 0xB4);
1032 regmap_write(da7210->regmap, DA7210_A_PLL1, 0x01);
1033 regmap_write(da7210->regmap, DA7210_A_CP_MODE, 0x7C);
1034 /* re-lock */
1035 regmap_write(da7210->regmap, DA7210_A_HID_UNLOCK, 0x00);
1036 regmap_write(da7210->regmap, DA7210_A_TEST_UNLOCK, 0x00);
1037
1038 /* Activate all enabled subsystem */ 1171 /* Activate all enabled subsystem */
1039 snd_soc_write(codec, DA7210_STARTUP1, DA7210_SC_MST_EN); 1172 snd_soc_write(codec, DA7210_STARTUP1, DA7210_SC_MST_EN);
1040 1173
@@ -1055,7 +1188,26 @@ static struct snd_soc_codec_driver soc_codec_dev_da7210 = {
1055 .num_dapm_routes = ARRAY_SIZE(da7210_audio_map), 1188 .num_dapm_routes = ARRAY_SIZE(da7210_audio_map),
1056}; 1189};
1057 1190
1058static struct regmap_config da7210_regmap = { 1191#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1192
1193static struct reg_default da7210_regmap_i2c_patch[] = {
1194
1195 /* System controller master disable */
1196 { DA7210_STARTUP1, 0x00 },
1197 /* Set PLL Master clock range 10-20 MHz */
1198 { DA7210_PLL_DIV3, DA7210_MCLK_RANGE_10_20_MHZ },
1199
1200 /* to unlock */
1201 { DA7210_A_HID_UNLOCK, 0x8B},
1202 { DA7210_A_TEST_UNLOCK, 0xB4},
1203 { DA7210_A_PLL1, 0x01},
1204 { DA7210_A_CP_MODE, 0x7C},
1205 /* to re-lock */
1206 { DA7210_A_HID_UNLOCK, 0x00},
1207 { DA7210_A_TEST_UNLOCK, 0x00},
1208};
1209
1210static const struct regmap_config da7210_regmap_config_i2c = {
1059 .reg_bits = 8, 1211 .reg_bits = 8,
1060 .val_bits = 8, 1212 .val_bits = 8,
1061 1213
@@ -1066,7 +1218,6 @@ static struct regmap_config da7210_regmap = {
1066 .cache_type = REGCACHE_RBTREE, 1218 .cache_type = REGCACHE_RBTREE,
1067}; 1219};
1068 1220
1069#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1070static int __devinit da7210_i2c_probe(struct i2c_client *i2c, 1221static int __devinit da7210_i2c_probe(struct i2c_client *i2c,
1071 const struct i2c_device_id *id) 1222 const struct i2c_device_id *id)
1072{ 1223{
@@ -1080,13 +1231,18 @@ static int __devinit da7210_i2c_probe(struct i2c_client *i2c,
1080 1231
1081 i2c_set_clientdata(i2c, da7210); 1232 i2c_set_clientdata(i2c, da7210);
1082 1233
1083 da7210->regmap = regmap_init_i2c(i2c, &da7210_regmap); 1234 da7210->regmap = regmap_init_i2c(i2c, &da7210_regmap_config_i2c);
1084 if (IS_ERR(da7210->regmap)) { 1235 if (IS_ERR(da7210->regmap)) {
1085 ret = PTR_ERR(da7210->regmap); 1236 ret = PTR_ERR(da7210->regmap);
1086 dev_err(&i2c->dev, "regmap_init() failed: %d\n", ret); 1237 dev_err(&i2c->dev, "regmap_init() failed: %d\n", ret);
1087 return ret; 1238 return ret;
1088 } 1239 }
1089 1240
1241 ret = regmap_register_patch(da7210->regmap, da7210_regmap_i2c_patch,
1242 ARRAY_SIZE(da7210_regmap_i2c_patch));
1243 if (ret != 0)
1244 dev_warn(&i2c->dev, "Failed to apply regmap patch: %d\n", ret);
1245
1090 ret = snd_soc_register_codec(&i2c->dev, 1246 ret = snd_soc_register_codec(&i2c->dev,
1091 &soc_codec_dev_da7210, &da7210_dai, 1); 1247 &soc_codec_dev_da7210, &da7210_dai, 1);
1092 if (ret < 0) { 1248 if (ret < 0) {
@@ -1119,7 +1275,7 @@ MODULE_DEVICE_TABLE(i2c, da7210_i2c_id);
1119/* I2C codec control layer */ 1275/* I2C codec control layer */
1120static struct i2c_driver da7210_i2c_driver = { 1276static struct i2c_driver da7210_i2c_driver = {
1121 .driver = { 1277 .driver = {
1122 .name = "da7210-codec", 1278 .name = "da7210",
1123 .owner = THIS_MODULE, 1279 .owner = THIS_MODULE,
1124 }, 1280 },
1125 .probe = da7210_i2c_probe, 1281 .probe = da7210_i2c_probe,
@@ -1128,12 +1284,112 @@ static struct i2c_driver da7210_i2c_driver = {
1128}; 1284};
1129#endif 1285#endif
1130 1286
1287#if defined(CONFIG_SPI_MASTER)
1288
1289static struct reg_default da7210_regmap_spi_patch[] = {
1290 /* Dummy read to give two pulses over nCS for SPI */
1291 { DA7210_AUX2, 0x00 },
1292 { DA7210_AUX2, 0x00 },
1293
1294 /* System controller master disable */
1295 { DA7210_STARTUP1, 0x00 },
1296 /* Set PLL Master clock range 10-20 MHz */
1297 { DA7210_PLL_DIV3, DA7210_MCLK_RANGE_10_20_MHZ },
1298
1299 /* to set PAGE1 of SPI register space */
1300 { DA7210_PAGE_CONTROL, 0x80 },
1301 /* to unlock */
1302 { DA7210_A_HID_UNLOCK, 0x8B},
1303 { DA7210_A_TEST_UNLOCK, 0xB4},
1304 { DA7210_A_PLL1, 0x01},
1305 { DA7210_A_CP_MODE, 0x7C},
1306 /* to re-lock */
1307 { DA7210_A_HID_UNLOCK, 0x00},
1308 { DA7210_A_TEST_UNLOCK, 0x00},
1309 /* to set back PAGE0 of SPI register space */
1310 { DA7210_PAGE_CONTROL, 0x00 },
1311};
1312
1313static const struct regmap_config da7210_regmap_config_spi = {
1314 .reg_bits = 8,
1315 .val_bits = 8,
1316 .read_flag_mask = 0x01,
1317 .write_flag_mask = 0x00,
1318
1319 .reg_defaults = da7210_reg_defaults,
1320 .num_reg_defaults = ARRAY_SIZE(da7210_reg_defaults),
1321 .volatile_reg = da7210_volatile_register,
1322 .readable_reg = da7210_readable_register,
1323 .cache_type = REGCACHE_RBTREE,
1324};
1325
1326static int __devinit da7210_spi_probe(struct spi_device *spi)
1327{
1328 struct da7210_priv *da7210;
1329 int ret;
1330
1331 da7210 = devm_kzalloc(&spi->dev, sizeof(struct da7210_priv),
1332 GFP_KERNEL);
1333 if (!da7210)
1334 return -ENOMEM;
1335
1336 spi_set_drvdata(spi, da7210);
1337 da7210->regmap = devm_regmap_init_spi(spi, &da7210_regmap_config_spi);
1338 if (IS_ERR(da7210->regmap)) {
1339 ret = PTR_ERR(da7210->regmap);
1340 dev_err(&spi->dev, "Failed to register regmap: %d\n", ret);
1341 return ret;
1342 }
1343
1344 ret = regmap_register_patch(da7210->regmap, da7210_regmap_spi_patch,
1345 ARRAY_SIZE(da7210_regmap_spi_patch));
1346 if (ret != 0)
1347 dev_warn(&spi->dev, "Failed to apply regmap patch: %d\n", ret);
1348
1349 ret = snd_soc_register_codec(&spi->dev,
1350 &soc_codec_dev_da7210, &da7210_dai, 1);
1351 if (ret < 0)
1352 goto err_regmap;
1353
1354 return ret;
1355
1356err_regmap:
1357 regmap_exit(da7210->regmap);
1358
1359 return ret;
1360}
1361
1362static int __devexit da7210_spi_remove(struct spi_device *spi)
1363{
1364 struct da7210_priv *da7210 = spi_get_drvdata(spi);
1365 snd_soc_unregister_codec(&spi->dev);
1366 regmap_exit(da7210->regmap);
1367 return 0;
1368}
1369
1370static struct spi_driver da7210_spi_driver = {
1371 .driver = {
1372 .name = "da7210",
1373 .owner = THIS_MODULE,
1374 },
1375 .probe = da7210_spi_probe,
1376 .remove = __devexit_p(da7210_spi_remove)
1377};
1378#endif
1379
1131static int __init da7210_modinit(void) 1380static int __init da7210_modinit(void)
1132{ 1381{
1133 int ret = 0; 1382 int ret = 0;
1134#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 1383#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1135 ret = i2c_add_driver(&da7210_i2c_driver); 1384 ret = i2c_add_driver(&da7210_i2c_driver);
1136#endif 1385#endif
1386#if defined(CONFIG_SPI_MASTER)
1387 ret = spi_register_driver(&da7210_spi_driver);
1388 if (ret) {
1389 printk(KERN_ERR "Failed to register da7210 SPI driver: %d\n",
1390 ret);
1391 }
1392#endif
1137 return ret; 1393 return ret;
1138} 1394}
1139module_init(da7210_modinit); 1395module_init(da7210_modinit);
@@ -1143,6 +1399,9 @@ static void __exit da7210_exit(void)
1143#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 1399#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1144 i2c_del_driver(&da7210_i2c_driver); 1400 i2c_del_driver(&da7210_i2c_driver);
1145#endif 1401#endif
1402#if defined(CONFIG_SPI_MASTER)
1403 spi_unregister_driver(&da7210_spi_driver);
1404#endif
1146} 1405}
1147module_exit(da7210_exit); 1406module_exit(da7210_exit);
1148 1407
diff --git a/sound/soc/codecs/jz4740.c b/sound/soc/codecs/jz4740.c
index 4624e752a188..85d9cabe6d55 100644
--- a/sound/soc/codecs/jz4740.c
+++ b/sound/soc/codecs/jz4740.c
@@ -164,8 +164,7 @@ static int jz4740_codec_hw_params(struct snd_pcm_substream *substream,
164 struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) 164 struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
165{ 165{
166 uint32_t val; 166 uint32_t val;
167 struct snd_soc_pcm_runtime *rtd = substream->private_data; 167 struct snd_soc_codec *codec = dai->codec;
168 struct snd_soc_codec *codec =rtd->codec;
169 168
170 switch (params_rate(params)) { 169 switch (params_rate(params)) {
171 case 8000: 170 case 8000:
diff --git a/sound/soc/codecs/lm49453.c b/sound/soc/codecs/lm49453.c
new file mode 100644
index 000000000000..802b9f176b16
--- /dev/null
+++ b/sound/soc/codecs/lm49453.c
@@ -0,0 +1,1550 @@
1/*
2 * lm49453.c - LM49453 ALSA Soc Audio driver
3 *
4 * Copyright (c) 2012 Texas Instruments, Inc
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * Initially based on sound/soc/codecs/wm8350.c
11 */
12
13#include <linux/module.h>
14#include <linux/moduleparam.h>
15#include <linux/version.h>
16#include <linux/kernel.h>
17#include <linux/init.h>
18#include <linux/delay.h>
19#include <linux/pm.h>
20#include <linux/i2c.h>
21#include <linux/regmap.h>
22#include <linux/slab.h>
23#include <sound/core.h>
24#include <sound/pcm.h>
25#include <sound/pcm_params.h>
26#include <sound/soc.h>
27#include <sound/soc-dapm.h>
28#include <sound/tlv.h>
29#include <sound/jack.h>
30#include <sound/initval.h>
31#include <asm/div64.h>
32#include "lm49453.h"
33
34static struct reg_default lm49453_reg_defs[] = {
35 { 0, 0x00 },
36 { 1, 0x00 },
37 { 2, 0x00 },
38 { 3, 0x00 },
39 { 4, 0x00 },
40 { 5, 0x00 },
41 { 6, 0x00 },
42 { 7, 0x00 },
43 { 8, 0x00 },
44 { 9, 0x00 },
45 { 10, 0x00 },
46 { 11, 0x00 },
47 { 12, 0x00 },
48 { 13, 0x00 },
49 { 14, 0x00 },
50 { 15, 0x00 },
51 { 16, 0x00 },
52 { 17, 0x00 },
53 { 18, 0x00 },
54 { 19, 0x00 },
55 { 20, 0x00 },
56 { 21, 0x00 },
57 { 22, 0x00 },
58 { 23, 0x00 },
59 { 32, 0x00 },
60 { 33, 0x00 },
61 { 35, 0x00 },
62 { 36, 0x00 },
63 { 37, 0x00 },
64 { 46, 0x00 },
65 { 48, 0x00 },
66 { 49, 0x00 },
67 { 51, 0x00 },
68 { 56, 0x00 },
69 { 58, 0x00 },
70 { 59, 0x00 },
71 { 60, 0x00 },
72 { 61, 0x00 },
73 { 62, 0x00 },
74 { 63, 0x00 },
75 { 64, 0x00 },
76 { 65, 0x00 },
77 { 66, 0x00 },
78 { 67, 0x00 },
79 { 68, 0x00 },
80 { 69, 0x00 },
81 { 70, 0x00 },
82 { 71, 0x00 },
83 { 72, 0x00 },
84 { 73, 0x00 },
85 { 74, 0x00 },
86 { 75, 0x00 },
87 { 76, 0x00 },
88 { 77, 0x00 },
89 { 78, 0x00 },
90 { 79, 0x00 },
91 { 80, 0x00 },
92 { 81, 0x00 },
93 { 82, 0x00 },
94 { 83, 0x00 },
95 { 85, 0x00 },
96 { 85, 0x00 },
97 { 86, 0x00 },
98 { 87, 0x00 },
99 { 88, 0x00 },
100 { 89, 0x00 },
101 { 90, 0x00 },
102 { 91, 0x00 },
103 { 92, 0x00 },
104 { 93, 0x00 },
105 { 94, 0x00 },
106 { 95, 0x00 },
107 { 96, 0x01 },
108 { 97, 0x00 },
109 { 98, 0x00 },
110 { 99, 0x00 },
111 { 100, 0x00 },
112 { 101, 0x00 },
113 { 102, 0x00 },
114 { 103, 0x01 },
115 { 105, 0x01 },
116 { 106, 0x00 },
117 { 107, 0x01 },
118 { 107, 0x00 },
119 { 108, 0x00 },
120 { 109, 0x00 },
121 { 110, 0x00 },
122 { 111, 0x02 },
123 { 112, 0x02 },
124 { 113, 0x00 },
125 { 121, 0x80 },
126 { 122, 0xBB },
127 { 123, 0x80 },
128 { 124, 0xBB },
129 { 128, 0x00 },
130 { 130, 0x00 },
131 { 131, 0x00 },
132 { 132, 0x00 },
133 { 133, 0x0A },
134 { 134, 0x0A },
135 { 135, 0x0A },
136 { 136, 0x0F },
137 { 137, 0x00 },
138 { 138, 0x73 },
139 { 139, 0x33 },
140 { 140, 0x73 },
141 { 141, 0x33 },
142 { 142, 0x73 },
143 { 143, 0x33 },
144 { 144, 0x73 },
145 { 145, 0x33 },
146 { 146, 0x73 },
147 { 147, 0x33 },
148 { 148, 0x73 },
149 { 149, 0x33 },
150 { 150, 0x73 },
151 { 151, 0x33 },
152 { 152, 0x00 },
153 { 153, 0x00 },
154 { 154, 0x00 },
155 { 155, 0x00 },
156 { 176, 0x00 },
157 { 177, 0x00 },
158 { 178, 0x00 },
159 { 179, 0x00 },
160 { 180, 0x00 },
161 { 181, 0x00 },
162 { 182, 0x00 },
163 { 183, 0x00 },
164 { 184, 0x00 },
165 { 185, 0x00 },
166 { 186, 0x00 },
167 { 189, 0x00 },
168 { 188, 0x00 },
169 { 194, 0x00 },
170 { 195, 0x00 },
171 { 196, 0x00 },
172 { 197, 0x00 },
173 { 200, 0x00 },
174 { 201, 0x00 },
175 { 202, 0x00 },
176 { 203, 0x00 },
177 { 204, 0x00 },
178 { 205, 0x00 },
179 { 208, 0x00 },
180 { 209, 0x00 },
181 { 210, 0x00 },
182 { 211, 0x00 },
183 { 213, 0x00 },
184 { 214, 0x00 },
185 { 215, 0x00 },
186 { 216, 0x00 },
187 { 217, 0x00 },
188 { 218, 0x00 },
189 { 219, 0x00 },
190 { 221, 0x00 },
191 { 222, 0x00 },
192 { 224, 0x00 },
193 { 225, 0x00 },
194 { 226, 0x00 },
195 { 227, 0x00 },
196 { 228, 0x00 },
197 { 229, 0x00 },
198 { 230, 0x13 },
199 { 231, 0x00 },
200 { 232, 0x80 },
201 { 233, 0x0C },
202 { 234, 0xDD },
203 { 235, 0x00 },
204 { 236, 0x04 },
205 { 237, 0x00 },
206 { 238, 0x00 },
207 { 239, 0x00 },
208 { 240, 0x00 },
209 { 241, 0x00 },
210 { 242, 0x00 },
211 { 243, 0x00 },
212 { 244, 0x00 },
213 { 245, 0x00 },
214 { 248, 0x00 },
215 { 249, 0x00 },
216 { 254, 0x00 },
217 { 255, 0x00 },
218};
219
220/* codec private data */
221struct lm49453_priv {
222 struct regmap *regmap;
223 int fs_rate;
224};
225
226/* capture path controls */
227
228static const char *lm49453_mic2mode_text[] = {"Single Ended", "Differential"};
229
230static const SOC_ENUM_SINGLE_DECL(lm49453_mic2mode_enum, LM49453_P0_MICR_REG, 5,
231 lm49453_mic2mode_text);
232
233static const char *lm49453_dmic_cfg_text[] = {"DMICDAT1", "DMICDAT2"};
234
235static const SOC_ENUM_SINGLE_DECL(lm49453_dmic12_cfg_enum,
236 LM49453_P0_DIGITAL_MIC1_CONFIG_REG,
237 7, lm49453_dmic_cfg_text);
238
239static const SOC_ENUM_SINGLE_DECL(lm49453_dmic34_cfg_enum,
240 LM49453_P0_DIGITAL_MIC2_CONFIG_REG,
241 7, lm49453_dmic_cfg_text);
242
243/* MUX Controls */
244static const char *lm49453_adcl_mux_text[] = { "MIC1", "Aux_L" };
245
246static const char *lm49453_adcr_mux_text[] = { "MIC2", "Aux_R" };
247
248static const struct soc_enum lm49453_adcl_enum =
249 SOC_ENUM_SINGLE(LM49453_P0_ANALOG_MIXER_ADC_REG, 0,
250 ARRAY_SIZE(lm49453_adcl_mux_text),
251 lm49453_adcl_mux_text);
252
253static const struct soc_enum lm49453_adcr_enum =
254 SOC_ENUM_SINGLE(LM49453_P0_ANALOG_MIXER_ADC_REG, 1,
255 ARRAY_SIZE(lm49453_adcr_mux_text),
256 lm49453_adcr_mux_text);
257
258static const struct snd_kcontrol_new lm49453_adcl_mux_control =
259 SOC_DAPM_ENUM("ADC Left Mux", lm49453_adcl_enum);
260
261static const struct snd_kcontrol_new lm49453_adcr_mux_control =
262 SOC_DAPM_ENUM("ADC Right Mux", lm49453_adcr_enum);
263
264static const struct snd_kcontrol_new lm49453_headset_left_mixer[] = {
265SOC_DAPM_SINGLE("Port1_1 Switch", LM49453_P0_DACHPL1_REG, 0, 1, 0),
266SOC_DAPM_SINGLE("Port1_2 Switch", LM49453_P0_DACHPL1_REG, 1, 1, 0),
267SOC_DAPM_SINGLE("Port1_3 Switch", LM49453_P0_DACHPL1_REG, 2, 1, 0),
268SOC_DAPM_SINGLE("Port1_4 Switch", LM49453_P0_DACHPL1_REG, 3, 1, 0),
269SOC_DAPM_SINGLE("Port1_5 Switch", LM49453_P0_DACHPL1_REG, 4, 1, 0),
270SOC_DAPM_SINGLE("Port1_6 Switch", LM49453_P0_DACHPL1_REG, 5, 1, 0),
271SOC_DAPM_SINGLE("Port1_7 Switch", LM49453_P0_DACHPL1_REG, 6, 1, 0),
272SOC_DAPM_SINGLE("Port1_8 Switch", LM49453_P0_DACHPL1_REG, 7, 1, 0),
273SOC_DAPM_SINGLE("DMIC1L Switch", LM49453_P0_DACHPL2_REG, 0, 1, 0),
274SOC_DAPM_SINGLE("DMIC1R Switch", LM49453_P0_DACHPL2_REG, 1, 1, 0),
275SOC_DAPM_SINGLE("DMIC2L Switch", LM49453_P0_DACHPL2_REG, 2, 1, 0),
276SOC_DAPM_SINGLE("DMIC2R Switch", LM49453_P0_DACHPL2_REG, 3, 1, 0),
277SOC_DAPM_SINGLE("ADCL Switch", LM49453_P0_DACHPL2_REG, 4, 1, 0),
278SOC_DAPM_SINGLE("ADCR Switch", LM49453_P0_DACHPL2_REG, 5, 1, 0),
279SOC_DAPM_SINGLE("Port2_1 Switch", LM49453_P0_DACHPL2_REG, 6, 1, 0),
280SOC_DAPM_SINGLE("Port2_2 Switch", LM49453_P0_DACHPL2_REG, 7, 1, 0),
281SOC_DAPM_SINGLE("Sidetone Switch", LM49453_P0_STN_SEL_REG, 0, 0, 0),
282};
283
284static const struct snd_kcontrol_new lm49453_headset_right_mixer[] = {
285SOC_DAPM_SINGLE("Port1_1 Switch", LM49453_P0_DACHPR1_REG, 0, 1, 0),
286SOC_DAPM_SINGLE("Port1_2 Switch", LM49453_P0_DACHPR1_REG, 1, 1, 0),
287SOC_DAPM_SINGLE("Port1_3 Switch", LM49453_P0_DACHPR1_REG, 2, 1, 0),
288SOC_DAPM_SINGLE("Port1_4 Switch", LM49453_P0_DACHPR1_REG, 3, 1, 0),
289SOC_DAPM_SINGLE("Port1_5 Switch", LM49453_P0_DACHPR1_REG, 4, 1, 0),
290SOC_DAPM_SINGLE("Port1_6 Switch", LM49453_P0_DACHPR1_REG, 5, 1, 0),
291SOC_DAPM_SINGLE("Port1_7 Switch", LM49453_P0_DACHPR1_REG, 6, 1, 0),
292SOC_DAPM_SINGLE("Port1_8 Switch", LM49453_P0_DACHPR1_REG, 7, 1, 0),
293SOC_DAPM_SINGLE("DMIC1L Switch", LM49453_P0_DACHPR2_REG, 0, 1, 0),
294SOC_DAPM_SINGLE("DMIC1R Switch", LM49453_P0_DACHPR2_REG, 1, 1, 0),
295SOC_DAPM_SINGLE("DMIC2L Switch", LM49453_P0_DACHPR2_REG, 2, 1, 0),
296SOC_DAPM_SINGLE("DMIC2R Switch", LM49453_P0_DACHPR2_REG, 3, 1, 0),
297SOC_DAPM_SINGLE("ADCL Switch", LM49453_P0_DACHPR2_REG, 4, 1, 0),
298SOC_DAPM_SINGLE("ADCR Switch", LM49453_P0_DACHPR2_REG, 5, 1, 0),
299SOC_DAPM_SINGLE("Port2_1 Switch", LM49453_P0_DACHPR2_REG, 6, 1, 0),
300SOC_DAPM_SINGLE("Port2_2 Switch", LM49453_P0_DACHPR2_REG, 7, 1, 0),
301SOC_DAPM_SINGLE("Sidetone Switch", LM49453_P0_STN_SEL_REG, 1, 0, 0),
302};
303
304static const struct snd_kcontrol_new lm49453_speaker_left_mixer[] = {
305SOC_DAPM_SINGLE("Port1_1 Switch", LM49453_P0_DACLSL1_REG, 0, 1, 0),
306SOC_DAPM_SINGLE("Port1_2 Switch", LM49453_P0_DACLSL1_REG, 1, 1, 0),
307SOC_DAPM_SINGLE("Port1_3 Switch", LM49453_P0_DACLSL1_REG, 2, 1, 0),
308SOC_DAPM_SINGLE("Port1_4 Switch", LM49453_P0_DACLSL1_REG, 3, 1, 0),
309SOC_DAPM_SINGLE("Port1_5 Switch", LM49453_P0_DACLSL1_REG, 4, 1, 0),
310SOC_DAPM_SINGLE("Port1_6 Switch", LM49453_P0_DACLSL1_REG, 5, 1, 0),
311SOC_DAPM_SINGLE("Port1_7 Switch", LM49453_P0_DACLSL1_REG, 6, 1, 0),
312SOC_DAPM_SINGLE("Port1_8 Switch", LM49453_P0_DACLSL1_REG, 7, 1, 0),
313SOC_DAPM_SINGLE("DMIC1L Switch", LM49453_P0_DACLSL2_REG, 0, 1, 0),
314SOC_DAPM_SINGLE("DMIC1R Switch", LM49453_P0_DACLSL2_REG, 1, 1, 0),
315SOC_DAPM_SINGLE("DMIC2L Switch", LM49453_P0_DACLSL2_REG, 2, 1, 0),
316SOC_DAPM_SINGLE("DMIC2R Switch", LM49453_P0_DACLSL2_REG, 3, 1, 0),
317SOC_DAPM_SINGLE("ADCL Switch", LM49453_P0_DACLSL2_REG, 4, 1, 0),
318SOC_DAPM_SINGLE("ADCR Switch", LM49453_P0_DACLSL2_REG, 5, 1, 0),
319SOC_DAPM_SINGLE("Port2_1 Switch", LM49453_P0_DACLSL2_REG, 6, 1, 0),
320SOC_DAPM_SINGLE("Port2_2 Switch", LM49453_P0_DACLSL2_REG, 7, 1, 0),
321SOC_DAPM_SINGLE("Sidetone Switch", LM49453_P0_STN_SEL_REG, 2, 0, 0),
322};
323
324static const struct snd_kcontrol_new lm49453_speaker_right_mixer[] = {
325SOC_DAPM_SINGLE("Port1_1 Switch", LM49453_P0_DACLSR1_REG, 0, 1, 0),
326SOC_DAPM_SINGLE("Port1_2 Switch", LM49453_P0_DACLSR1_REG, 1, 1, 0),
327SOC_DAPM_SINGLE("Port1_3 Switch", LM49453_P0_DACLSR1_REG, 2, 1, 0),
328SOC_DAPM_SINGLE("Port1_4 Switch", LM49453_P0_DACLSR1_REG, 3, 1, 0),
329SOC_DAPM_SINGLE("Port1_5 Switch", LM49453_P0_DACLSR1_REG, 4, 1, 0),
330SOC_DAPM_SINGLE("Port1_6 Switch", LM49453_P0_DACLSR1_REG, 5, 1, 0),
331SOC_DAPM_SINGLE("Port1_7 Switch", LM49453_P0_DACLSR1_REG, 6, 1, 0),
332SOC_DAPM_SINGLE("Port1_8 Switch", LM49453_P0_DACLSR1_REG, 7, 1, 0),
333SOC_DAPM_SINGLE("DMIC1L Switch", LM49453_P0_DACLSR2_REG, 0, 1, 0),
334SOC_DAPM_SINGLE("DMIC1R Switch", LM49453_P0_DACLSR2_REG, 1, 1, 0),
335SOC_DAPM_SINGLE("DMIC2L Switch", LM49453_P0_DACLSR2_REG, 2, 1, 0),
336SOC_DAPM_SINGLE("DMIC2R Switch", LM49453_P0_DACLSR2_REG, 3, 1, 0),
337SOC_DAPM_SINGLE("ADCL Switch", LM49453_P0_DACLSR2_REG, 4, 1, 0),
338SOC_DAPM_SINGLE("ADCR Switch", LM49453_P0_DACLSR2_REG, 5, 1, 0),
339SOC_DAPM_SINGLE("Port2_1 Switch", LM49453_P0_DACLSR2_REG, 6, 1, 0),
340SOC_DAPM_SINGLE("Port2_2 Switch", LM49453_P0_DACLSR2_REG, 7, 1, 0),
341SOC_DAPM_SINGLE("Sidetone Switch", LM49453_P0_STN_SEL_REG, 3, 0, 0),
342};
343
344static const struct snd_kcontrol_new lm49453_haptic_left_mixer[] = {
345SOC_DAPM_SINGLE("Port1_1 Switch", LM49453_P0_DACHAL1_REG, 0, 1, 0),
346SOC_DAPM_SINGLE("Port1_2 Switch", LM49453_P0_DACHAL1_REG, 1, 1, 0),
347SOC_DAPM_SINGLE("Port1_3 Switch", LM49453_P0_DACHAL1_REG, 2, 1, 0),
348SOC_DAPM_SINGLE("Port1_4 Switch", LM49453_P0_DACHAL1_REG, 3, 1, 0),
349SOC_DAPM_SINGLE("Port1_5 Switch", LM49453_P0_DACHAL1_REG, 4, 1, 0),
350SOC_DAPM_SINGLE("Port1_6 Switch", LM49453_P0_DACHAL1_REG, 5, 1, 0),
351SOC_DAPM_SINGLE("Port1_7 Switch", LM49453_P0_DACHAL1_REG, 6, 1, 0),
352SOC_DAPM_SINGLE("Port1_8 Switch", LM49453_P0_DACHAL1_REG, 7, 1, 0),
353SOC_DAPM_SINGLE("DMIC1L Switch", LM49453_P0_DACHAL2_REG, 0, 1, 0),
354SOC_DAPM_SINGLE("DMIC1R Switch", LM49453_P0_DACHAL2_REG, 1, 1, 0),
355SOC_DAPM_SINGLE("DMIC2L Switch", LM49453_P0_DACHAL2_REG, 2, 1, 0),
356SOC_DAPM_SINGLE("DMIC2R Switch", LM49453_P0_DACHAL2_REG, 3, 1, 0),
357SOC_DAPM_SINGLE("ADCL Switch", LM49453_P0_DACHAL2_REG, 4, 1, 0),
358SOC_DAPM_SINGLE("ADCR Switch", LM49453_P0_DACHAL2_REG, 5, 1, 0),
359SOC_DAPM_SINGLE("Port2_1 Switch", LM49453_P0_DACHAL2_REG, 6, 1, 0),
360SOC_DAPM_SINGLE("Port2_2 Switch", LM49453_P0_DACHAL2_REG, 7, 1, 0),
361SOC_DAPM_SINGLE("Sidetone Switch", LM49453_P0_STN_SEL_REG, 4, 0, 0),
362};
363
364static const struct snd_kcontrol_new lm49453_haptic_right_mixer[] = {
365SOC_DAPM_SINGLE("Port1_1 Switch", LM49453_P0_DACHAR1_REG, 0, 1, 0),
366SOC_DAPM_SINGLE("Port1_2 Switch", LM49453_P0_DACHAR1_REG, 1, 1, 0),
367SOC_DAPM_SINGLE("Port1_3 Switch", LM49453_P0_DACHAR1_REG, 2, 1, 0),
368SOC_DAPM_SINGLE("Port1_4 Switch", LM49453_P0_DACHAR1_REG, 3, 1, 0),
369SOC_DAPM_SINGLE("Port1_5 Switch", LM49453_P0_DACHAR1_REG, 4, 1, 0),
370SOC_DAPM_SINGLE("Port1_6 Switch", LM49453_P0_DACHAR1_REG, 5, 1, 0),
371SOC_DAPM_SINGLE("Port1_7 Switch", LM49453_P0_DACHAR1_REG, 6, 1, 0),
372SOC_DAPM_SINGLE("Port1_8 Switch", LM49453_P0_DACHAR1_REG, 7, 1, 0),
373SOC_DAPM_SINGLE("DMIC1L Switch", LM49453_P0_DACHAR2_REG, 0, 1, 0),
374SOC_DAPM_SINGLE("DMIC1R Switch", LM49453_P0_DACHAR2_REG, 1, 1, 0),
375SOC_DAPM_SINGLE("DMIC2L Switch", LM49453_P0_DACHAR2_REG, 2, 1, 0),
376SOC_DAPM_SINGLE("DMIC2R Switch", LM49453_P0_DACHAR2_REG, 3, 1, 0),
377SOC_DAPM_SINGLE("ADCL Switch", LM49453_P0_DACHAR2_REG, 4, 1, 0),
378SOC_DAPM_SINGLE("ADCR Switch", LM49453_P0_DACHAR2_REG, 5, 1, 0),
379SOC_DAPM_SINGLE("Port2_1 Switch", LM49453_P0_DACHAR2_REG, 6, 1, 0),
380SOC_DAPM_SINGLE("Port2_2 Switch", LM49453_P0_DACHAR2_REG, 7, 1, 0),
381SOC_DAPM_SINGLE("Sidetone Switch", LM49453_P0_STN_SEL_REG, 5, 0, 0),
382};
383
384static const struct snd_kcontrol_new lm49453_lineout_left_mixer[] = {
385SOC_DAPM_SINGLE("Port1_1 Switch", LM49453_P0_DACLOL1_REG, 0, 1, 0),
386SOC_DAPM_SINGLE("Port1_2 Switch", LM49453_P0_DACLOL1_REG, 1, 1, 0),
387SOC_DAPM_SINGLE("Port1_3 Switch", LM49453_P0_DACLOL1_REG, 2, 1, 0),
388SOC_DAPM_SINGLE("Port1_4 Switch", LM49453_P0_DACLOL1_REG, 3, 1, 0),
389SOC_DAPM_SINGLE("Port1_5 Switch", LM49453_P0_DACLOL1_REG, 4, 1, 0),
390SOC_DAPM_SINGLE("Port1_6 Switch", LM49453_P0_DACLOL1_REG, 5, 1, 0),
391SOC_DAPM_SINGLE("Port1_7 Switch", LM49453_P0_DACLOL1_REG, 6, 1, 0),
392SOC_DAPM_SINGLE("Port1_8 Switch", LM49453_P0_DACLOL1_REG, 7, 1, 0),
393SOC_DAPM_SINGLE("DMIC1L Switch", LM49453_P0_DACLOL2_REG, 0, 1, 0),
394SOC_DAPM_SINGLE("DMIC1R Switch", LM49453_P0_DACLOL2_REG, 1, 1, 0),
395SOC_DAPM_SINGLE("DMIC2L Switch", LM49453_P0_DACLOL2_REG, 2, 1, 0),
396SOC_DAPM_SINGLE("DMIC2R Switch", LM49453_P0_DACLOL2_REG, 3, 1, 0),
397SOC_DAPM_SINGLE("ADCL Switch", LM49453_P0_DACLOL2_REG, 4, 1, 0),
398SOC_DAPM_SINGLE("ADCR Switch", LM49453_P0_DACLOL2_REG, 5, 1, 0),
399SOC_DAPM_SINGLE("Port2_1 Switch", LM49453_P0_DACLOL2_REG, 6, 1, 0),
400SOC_DAPM_SINGLE("Port2_2 Switch", LM49453_P0_DACLOL2_REG, 7, 1, 0),
401SOC_DAPM_SINGLE("Sidetone Switch", LM49453_P0_STN_SEL_REG, 6, 0, 0),
402};
403
404static const struct snd_kcontrol_new lm49453_lineout_right_mixer[] = {
405SOC_DAPM_SINGLE("Port1_1 Switch", LM49453_P0_DACLOR1_REG, 0, 1, 0),
406SOC_DAPM_SINGLE("Port1_2 Switch", LM49453_P0_DACLOR1_REG, 1, 1, 0),
407SOC_DAPM_SINGLE("Port1_3 Switch", LM49453_P0_DACLOR1_REG, 2, 1, 0),
408SOC_DAPM_SINGLE("Port1_4 Switch", LM49453_P0_DACLOR1_REG, 3, 1, 0),
409SOC_DAPM_SINGLE("Port1_5 Switch", LM49453_P0_DACLOR1_REG, 4, 1, 0),
410SOC_DAPM_SINGLE("Port1_6 Switch", LM49453_P0_DACLOR1_REG, 5, 1, 0),
411SOC_DAPM_SINGLE("Port1_7 Switch", LM49453_P0_DACLOR1_REG, 6, 1, 0),
412SOC_DAPM_SINGLE("Port1_8 Switch", LM49453_P0_DACLOR1_REG, 7, 1, 0),
413SOC_DAPM_SINGLE("DMIC1L Switch", LM49453_P0_DACLOR2_REG, 0, 1, 0),
414SOC_DAPM_SINGLE("DMIC1R Switch", LM49453_P0_DACLOR2_REG, 1, 1, 0),
415SOC_DAPM_SINGLE("DMIC2L Switch", LM49453_P0_DACLOR2_REG, 2, 1, 0),
416SOC_DAPM_SINGLE("DMIC2R Switch", LM49453_P0_DACLOR2_REG, 3, 1, 0),
417SOC_DAPM_SINGLE("ADCL Switch", LM49453_P0_DACLOR2_REG, 4, 1, 0),
418SOC_DAPM_SINGLE("ADCR Switch", LM49453_P0_DACLOR2_REG, 5, 1, 0),
419SOC_DAPM_SINGLE("Port2_1 Switch", LM49453_P0_DACLOR2_REG, 6, 1, 0),
420SOC_DAPM_SINGLE("Port2_2 Switch", LM49453_P0_DACLOR2_REG, 7, 1, 0),
421SOC_DAPM_SINGLE("Sidetone Switch", LM49453_P0_STN_SEL_REG, 7, 0, 0),
422};
423
424static const struct snd_kcontrol_new lm49453_port1_tx1_mixer[] = {
425SOC_DAPM_SINGLE("DMIC1L Switch", LM49453_P0_PORT1_TX1_REG, 0, 1, 0),
426SOC_DAPM_SINGLE("DMIC1R Switch", LM49453_P0_PORT1_TX1_REG, 1, 1, 0),
427SOC_DAPM_SINGLE("DMIC2L Switch", LM49453_P0_PORT1_TX1_REG, 2, 1, 0),
428SOC_DAPM_SINGLE("DMIC2R Switch", LM49453_P0_PORT1_TX1_REG, 3, 1, 0),
429SOC_DAPM_SINGLE("ADCL Switch", LM49453_P0_PORT1_TX1_REG, 4, 1, 0),
430SOC_DAPM_SINGLE("ADCR Switch", LM49453_P0_PORT1_TX1_REG, 5, 1, 0),
431SOC_DAPM_SINGLE("Port1_1 Switch", LM49453_P0_PORT1_TX1_REG, 6, 1, 0),
432SOC_DAPM_SINGLE("Port2_1 Switch", LM49453_P0_PORT1_TX1_REG, 7, 1, 0),
433};
434
435static const struct snd_kcontrol_new lm49453_port1_tx2_mixer[] = {
436SOC_DAPM_SINGLE("DMIC1L Switch", LM49453_P0_PORT1_TX2_REG, 0, 1, 0),
437SOC_DAPM_SINGLE("DMIC1R Switch", LM49453_P0_PORT1_TX2_REG, 1, 1, 0),
438SOC_DAPM_SINGLE("DMIC2L Switch", LM49453_P0_PORT1_TX2_REG, 2, 1, 0),
439SOC_DAPM_SINGLE("DMIC2R Switch", LM49453_P0_PORT1_TX2_REG, 3, 1, 0),
440SOC_DAPM_SINGLE("ADCL Switch", LM49453_P0_PORT1_TX2_REG, 4, 1, 0),
441SOC_DAPM_SINGLE("ADCR Switch", LM49453_P0_PORT1_TX2_REG, 5, 1, 0),
442SOC_DAPM_SINGLE("Port1_2 Switch", LM49453_P0_PORT1_TX2_REG, 6, 1, 0),
443SOC_DAPM_SINGLE("Port2_2 Switch", LM49453_P0_PORT1_TX2_REG, 7, 1, 0),
444};
445
446static const struct snd_kcontrol_new lm49453_port1_tx3_mixer[] = {
447SOC_DAPM_SINGLE("DMIC1L Switch", LM49453_P0_PORT1_TX3_REG, 0, 1, 0),
448SOC_DAPM_SINGLE("DMIC1R Switch", LM49453_P0_PORT1_TX3_REG, 1, 1, 0),
449SOC_DAPM_SINGLE("DMIC2L Switch", LM49453_P0_PORT1_TX3_REG, 2, 1, 0),
450SOC_DAPM_SINGLE("DMIC2R Switch", LM49453_P0_PORT1_TX3_REG, 3, 1, 0),
451SOC_DAPM_SINGLE("ADCL Switch", LM49453_P0_PORT1_TX3_REG, 4, 1, 0),
452SOC_DAPM_SINGLE("ADCR Switch", LM49453_P0_PORT1_TX3_REG, 5, 1, 0),
453SOC_DAPM_SINGLE("Port1_3 Switch", LM49453_P0_PORT1_TX3_REG, 6, 1, 0),
454};
455
456static const struct snd_kcontrol_new lm49453_port1_tx4_mixer[] = {
457SOC_DAPM_SINGLE("DMIC1L Switch", LM49453_P0_PORT1_TX4_REG, 0, 1, 0),
458SOC_DAPM_SINGLE("DMIC1R Switch", LM49453_P0_PORT1_TX4_REG, 1, 1, 0),
459SOC_DAPM_SINGLE("DMIC2L Switch", LM49453_P0_PORT1_TX4_REG, 2, 1, 0),
460SOC_DAPM_SINGLE("DMIC2R Switch", LM49453_P0_PORT1_TX4_REG, 3, 1, 0),
461SOC_DAPM_SINGLE("ADCL Switch", LM49453_P0_PORT1_TX4_REG, 4, 1, 0),
462SOC_DAPM_SINGLE("ADCR Switch", LM49453_P0_PORT1_TX4_REG, 5, 1, 0),
463SOC_DAPM_SINGLE("Port1_4 Switch", LM49453_P0_PORT1_TX4_REG, 6, 1, 0),
464};
465
466static const struct snd_kcontrol_new lm49453_port1_tx5_mixer[] = {
467SOC_DAPM_SINGLE("DMIC1L Switch", LM49453_P0_PORT1_TX5_REG, 0, 1, 0),
468SOC_DAPM_SINGLE("DMIC1R Switch", LM49453_P0_PORT1_TX5_REG, 1, 1, 0),
469SOC_DAPM_SINGLE("DMIC2L Switch", LM49453_P0_PORT1_TX5_REG, 2, 1, 0),
470SOC_DAPM_SINGLE("DMIC2R Switch", LM49453_P0_PORT1_TX5_REG, 3, 1, 0),
471SOC_DAPM_SINGLE("ADCL Switch", LM49453_P0_PORT1_TX5_REG, 4, 1, 0),
472SOC_DAPM_SINGLE("ADCR Switch", LM49453_P0_PORT1_TX5_REG, 5, 1, 0),
473SOC_DAPM_SINGLE("Port1_5 Switch", LM49453_P0_PORT1_TX5_REG, 6, 1, 0),
474};
475
476static const struct snd_kcontrol_new lm49453_port1_tx6_mixer[] = {
477SOC_DAPM_SINGLE("DMIC1L Switch", LM49453_P0_PORT1_TX6_REG, 0, 1, 0),
478SOC_DAPM_SINGLE("DMIC1R Switch", LM49453_P0_PORT1_TX6_REG, 1, 1, 0),
479SOC_DAPM_SINGLE("DMIC2L Switch", LM49453_P0_PORT1_TX6_REG, 2, 1, 0),
480SOC_DAPM_SINGLE("DMIC2R Switch", LM49453_P0_PORT1_TX6_REG, 3, 1, 0),
481SOC_DAPM_SINGLE("ADCL Switch", LM49453_P0_PORT1_TX6_REG, 4, 1, 0),
482SOC_DAPM_SINGLE("ADCR Switch", LM49453_P0_PORT1_TX6_REG, 5, 1, 0),
483SOC_DAPM_SINGLE("Port1_6 Switch", LM49453_P0_PORT1_TX6_REG, 6, 1, 0),
484};
485
486static const struct snd_kcontrol_new lm49453_port1_tx7_mixer[] = {
487SOC_DAPM_SINGLE("DMIC1L Switch", LM49453_P0_PORT1_TX7_REG, 0, 1, 0),
488SOC_DAPM_SINGLE("DMIC1R Switch", LM49453_P0_PORT1_TX7_REG, 1, 1, 0),
489SOC_DAPM_SINGLE("DMIC2L Switch", LM49453_P0_PORT1_TX7_REG, 2, 1, 0),
490SOC_DAPM_SINGLE("DMIC2R Switch", LM49453_P0_PORT1_TX7_REG, 3, 1, 0),
491SOC_DAPM_SINGLE("ADCL Switch", LM49453_P0_PORT1_TX7_REG, 4, 1, 0),
492SOC_DAPM_SINGLE("ADCR Switch", LM49453_P0_PORT1_TX7_REG, 5, 1, 0),
493SOC_DAPM_SINGLE("Port1_7 Switch", LM49453_P0_PORT1_TX7_REG, 6, 1, 0),
494};
495
496static const struct snd_kcontrol_new lm49453_port1_tx8_mixer[] = {
497SOC_DAPM_SINGLE("DMIC1L Switch", LM49453_P0_PORT1_TX8_REG, 0, 1, 0),
498SOC_DAPM_SINGLE("DMIC1R Switch", LM49453_P0_PORT1_TX8_REG, 1, 1, 0),
499SOC_DAPM_SINGLE("DMIC2L Switch", LM49453_P0_PORT1_TX8_REG, 2, 1, 0),
500SOC_DAPM_SINGLE("DMIC2R Switch", LM49453_P0_PORT1_TX8_REG, 3, 1, 0),
501SOC_DAPM_SINGLE("ADCL Switch", LM49453_P0_PORT1_TX8_REG, 4, 1, 0),
502SOC_DAPM_SINGLE("ADCR Switch", LM49453_P0_PORT1_TX8_REG, 5, 1, 0),
503SOC_DAPM_SINGLE("Port1_8 Switch", LM49453_P0_PORT1_TX8_REG, 6, 1, 0),
504};
505
506static const struct snd_kcontrol_new lm49453_port2_tx1_mixer[] = {
507SOC_DAPM_SINGLE("DMIC1L Switch", LM49453_P0_PORT2_TX1_REG, 0, 1, 0),
508SOC_DAPM_SINGLE("DMIC1R Switch", LM49453_P0_PORT2_TX1_REG, 1, 1, 0),
509SOC_DAPM_SINGLE("DMIC2L Switch", LM49453_P0_PORT2_TX1_REG, 2, 1, 0),
510SOC_DAPM_SINGLE("DMIC2R Switch", LM49453_P0_PORT2_TX1_REG, 3, 1, 0),
511SOC_DAPM_SINGLE("ADCL Switch", LM49453_P0_PORT2_TX1_REG, 4, 1, 0),
512SOC_DAPM_SINGLE("ADCR Switch", LM49453_P0_PORT2_TX1_REG, 5, 1, 0),
513SOC_DAPM_SINGLE("Port1_1 Switch", LM49453_P0_PORT2_TX1_REG, 6, 1, 0),
514SOC_DAPM_SINGLE("Port2_1 Switch", LM49453_P0_PORT2_TX1_REG, 7, 1, 0),
515};
516
517static const struct snd_kcontrol_new lm49453_port2_tx2_mixer[] = {
518SOC_DAPM_SINGLE("DMIC1L Switch", LM49453_P0_PORT2_TX2_REG, 0, 1, 0),
519SOC_DAPM_SINGLE("DMIC1R Switch", LM49453_P0_PORT2_TX2_REG, 1, 1, 0),
520SOC_DAPM_SINGLE("DMIC2L Switch", LM49453_P0_PORT2_TX2_REG, 2, 1, 0),
521SOC_DAPM_SINGLE("DMIC2R Switch", LM49453_P0_PORT2_TX2_REG, 3, 1, 0),
522SOC_DAPM_SINGLE("ADCL Switch", LM49453_P0_PORT2_TX2_REG, 4, 1, 0),
523SOC_DAPM_SINGLE("ADCR Switch", LM49453_P0_PORT2_TX2_REG, 5, 1, 0),
524SOC_DAPM_SINGLE("Port1_2 Switch", LM49453_P0_PORT2_TX2_REG, 6, 1, 0),
525SOC_DAPM_SINGLE("Port2_2 Switch", LM49453_P0_PORT2_TX2_REG, 7, 1, 0),
526};
527
528/* TLV Declarations */
529static const DECLARE_TLV_DB_SCALE(digital_tlv, -7650, 150, 1);
530static const DECLARE_TLV_DB_SCALE(port_tlv, 0, 600, 0);
531
532static const struct snd_kcontrol_new lm49453_sidetone_mixer_controls[] = {
533/* Sidetone supports mono only */
534SOC_DAPM_SINGLE_TLV("Sidetone ADCL Volume", LM49453_P0_STN_VOL_ADCL_REG,
535 0, 0x3F, 0, digital_tlv),
536SOC_DAPM_SINGLE_TLV("Sidetone ADCR Volume", LM49453_P0_STN_VOL_ADCR_REG,
537 0, 0x3F, 0, digital_tlv),
538SOC_DAPM_SINGLE_TLV("Sidetone DMIC1L Volume", LM49453_P0_STN_VOL_DMIC1L_REG,
539 0, 0x3F, 0, digital_tlv),
540SOC_DAPM_SINGLE_TLV("Sidetone DMIC1R Volume", LM49453_P0_STN_VOL_DMIC1R_REG,
541 0, 0x3F, 0, digital_tlv),
542SOC_DAPM_SINGLE_TLV("Sidetone DMIC2L Volume", LM49453_P0_STN_VOL_DMIC2L_REG,
543 0, 0x3F, 0, digital_tlv),
544SOC_DAPM_SINGLE_TLV("Sidetone DMIC2R Volume", LM49453_P0_STN_VOL_DMIC2R_REG,
545 0, 0x3F, 0, digital_tlv),
546};
547
548static const struct snd_kcontrol_new lm49453_snd_controls[] = {
549 /* mic1 and mic2 supports mono only */
550 SOC_SINGLE_TLV("Mic1 Volume", LM49453_P0_ADC_LEVELL_REG, 0, 6,
551 0, digital_tlv),
552 SOC_SINGLE_TLV("Mic2 Volume", LM49453_P0_ADC_LEVELR_REG, 0, 6,
553 0, digital_tlv),
554
555 SOC_DOUBLE_R_TLV("DMIC1 Volume", LM49453_P0_DMIC1_LEVELL_REG,
556 LM49453_P0_DMIC1_LEVELR_REG, 0, 6, 0, digital_tlv),
557 SOC_DOUBLE_R_TLV("DMIC2 Volume", LM49453_P0_DMIC2_LEVELL_REG,
558 LM49453_P0_DMIC2_LEVELR_REG, 0, 6, 0, digital_tlv),
559
560 SOC_DAPM_ENUM("Mic2Mode", lm49453_mic2mode_enum),
561 SOC_DAPM_ENUM("DMIC12 SRC", lm49453_dmic12_cfg_enum),
562 SOC_DAPM_ENUM("DMIC34 SRC", lm49453_dmic34_cfg_enum),
563
564 /* Capture path filter enable */
565 SOC_SINGLE("DMIC1 HPFilter Switch", LM49453_P0_ADC_FX_ENABLES_REG,
566 0, 1, 0),
567 SOC_SINGLE("DMIC2 HPFilter Switch", LM49453_P0_ADC_FX_ENABLES_REG,
568 1, 1, 0),
569 SOC_SINGLE("ADC HPFilter Switch", LM49453_P0_ADC_FX_ENABLES_REG,
570 2, 1, 0),
571
572 SOC_DOUBLE_R_TLV("DAC HP Volume", LM49453_P0_DAC_HP_LEVELL_REG,
573 LM49453_P0_DAC_HP_LEVELR_REG, 0, 6, 0, digital_tlv),
574 SOC_DOUBLE_R_TLV("DAC LO Volume", LM49453_P0_DAC_LO_LEVELL_REG,
575 LM49453_P0_DAC_LO_LEVELR_REG, 0, 6, 0, digital_tlv),
576 SOC_DOUBLE_R_TLV("DAC LS Volume", LM49453_P0_DAC_LS_LEVELL_REG,
577 LM49453_P0_DAC_LS_LEVELR_REG, 0, 6, 0, digital_tlv),
578 SOC_DOUBLE_R_TLV("DAC HA Volume", LM49453_P0_DAC_HA_LEVELL_REG,
579 LM49453_P0_DAC_HA_LEVELR_REG, 0, 6, 0, digital_tlv),
580
581 SOC_SINGLE_TLV("EP Volume", LM49453_P0_DAC_LS_LEVELL_REG,
582 0, 6, 0, digital_tlv),
583
584 SOC_SINGLE_TLV("PORT1_1_RX_LVL Volume", LM49453_P0_PORT1_RX_LVL1_REG,
585 0, 3, 0, port_tlv),
586 SOC_SINGLE_TLV("PORT1_2_RX_LVL Volume", LM49453_P0_PORT1_RX_LVL1_REG,
587 2, 3, 0, port_tlv),
588 SOC_SINGLE_TLV("PORT1_3_RX_LVL Volume", LM49453_P0_PORT1_RX_LVL1_REG,
589 4, 3, 0, port_tlv),
590 SOC_SINGLE_TLV("PORT1_4_RX_LVL Volume", LM49453_P0_PORT1_RX_LVL1_REG,
591 6, 3, 0, port_tlv),
592 SOC_SINGLE_TLV("PORT1_5_RX_LVL Volume", LM49453_P0_PORT1_RX_LVL2_REG,
593 0, 3, 0, port_tlv),
594 SOC_SINGLE_TLV("PORT1_6_RX_LVL Volume", LM49453_P0_PORT1_RX_LVL2_REG,
595 2, 3, 0, port_tlv),
596 SOC_SINGLE_TLV("PORT1_7_RX_LVL Volume", LM49453_P0_PORT1_RX_LVL2_REG,
597 4, 3, 0, port_tlv),
598 SOC_SINGLE_TLV("PORT1_8_RX_LVL Volume", LM49453_P0_PORT1_RX_LVL2_REG,
599 6, 3, 0, port_tlv),
600
601 SOC_SINGLE_TLV("PORT2_1_RX_LVL Volume", LM49453_P0_PORT2_RX_LVL_REG,
602 0, 3, 0, port_tlv),
603 SOC_SINGLE_TLV("PORT2_2_RX_LVL Volume", LM49453_P0_PORT2_RX_LVL_REG,
604 2, 3, 0, port_tlv),
605
606 SOC_SINGLE("Port1 Playback Switch", LM49453_P0_AUDIO_PORT1_BASIC_REG,
607 1, 1, 0),
608 SOC_SINGLE("Port2 Playback Switch", LM49453_P0_AUDIO_PORT2_BASIC_REG,
609 1, 1, 0),
610 SOC_SINGLE("Port1 Capture Switch", LM49453_P0_AUDIO_PORT1_BASIC_REG,
611 2, 1, 0),
612 SOC_SINGLE("Port2 Capture Switch", LM49453_P0_AUDIO_PORT2_BASIC_REG,
613 2, 1, 0)
614
615};
616
617/* DAPM widgets */
618static const struct snd_soc_dapm_widget lm49453_dapm_widgets[] = {
619
620 /* All end points HP,EP, LS, Lineout and Haptic */
621 SND_SOC_DAPM_OUTPUT("HPOUTL"),
622 SND_SOC_DAPM_OUTPUT("HPOUTR"),
623 SND_SOC_DAPM_OUTPUT("EPOUT"),
624 SND_SOC_DAPM_OUTPUT("LSOUTL"),
625 SND_SOC_DAPM_OUTPUT("LSOUTR"),
626 SND_SOC_DAPM_OUTPUT("LOOUTR"),
627 SND_SOC_DAPM_OUTPUT("LOOUTL"),
628 SND_SOC_DAPM_OUTPUT("HAOUTL"),
629 SND_SOC_DAPM_OUTPUT("HAOUTR"),
630
631 SND_SOC_DAPM_INPUT("AMIC1"),
632 SND_SOC_DAPM_INPUT("AMIC2"),
633 SND_SOC_DAPM_INPUT("DMIC1DAT"),
634 SND_SOC_DAPM_INPUT("DMIC2DAT"),
635 SND_SOC_DAPM_INPUT("AUXL"),
636 SND_SOC_DAPM_INPUT("AUXR"),
637
638 SND_SOC_DAPM_PGA("PORT1_1_RX", SND_SOC_NOPM, 0, 0, NULL, 0),
639 SND_SOC_DAPM_PGA("PORT1_2_RX", SND_SOC_NOPM, 0, 0, NULL, 0),
640 SND_SOC_DAPM_PGA("PORT1_3_RX", SND_SOC_NOPM, 0, 0, NULL, 0),
641 SND_SOC_DAPM_PGA("PORT1_4_RX", SND_SOC_NOPM, 0, 0, NULL, 0),
642 SND_SOC_DAPM_PGA("PORT1_5_RX", SND_SOC_NOPM, 0, 0, NULL, 0),
643 SND_SOC_DAPM_PGA("PORT1_6_RX", SND_SOC_NOPM, 0, 0, NULL, 0),
644 SND_SOC_DAPM_PGA("PORT1_7_RX", SND_SOC_NOPM, 0, 0, NULL, 0),
645 SND_SOC_DAPM_PGA("PORT1_8_RX", SND_SOC_NOPM, 0, 0, NULL, 0),
646 SND_SOC_DAPM_PGA("PORT2_1_RX", SND_SOC_NOPM, 0, 0, NULL, 0),
647 SND_SOC_DAPM_PGA("PORT2_2_RX", SND_SOC_NOPM, 0, 0, NULL, 0),
648
649 SND_SOC_DAPM_SUPPLY("AMIC1Bias", LM49453_P0_MICL_REG, 6, 0, NULL, 0),
650 SND_SOC_DAPM_SUPPLY("AMIC2Bias", LM49453_P0_MICR_REG, 6, 0, NULL, 0),
651
652 /* playback path driver enables */
653 SND_SOC_DAPM_OUT_DRV("Headset Switch",
654 LM49453_P0_PMC_SETUP_REG, 0, 0, NULL, 0),
655 SND_SOC_DAPM_OUT_DRV("Earpiece Switch",
656 LM49453_P0_EP_REG, 0, 0, NULL, 0),
657 SND_SOC_DAPM_OUT_DRV("Speaker Left Switch",
658 LM49453_P0_DIS_PKVL_FB_REG, 0, 1, NULL, 0),
659 SND_SOC_DAPM_OUT_DRV("Speaker Right Switch",
660 LM49453_P0_DIS_PKVL_FB_REG, 1, 1, NULL, 0),
661 SND_SOC_DAPM_OUT_DRV("Haptic Left Switch",
662 LM49453_P0_DIS_PKVL_FB_REG, 2, 1, NULL, 0),
663 SND_SOC_DAPM_OUT_DRV("Haptic Right Switch",
664 LM49453_P0_DIS_PKVL_FB_REG, 3, 1, NULL, 0),
665
666 /* DAC */
667 SND_SOC_DAPM_DAC("HPL DAC", "Headset", SND_SOC_NOPM, 0, 0),
668 SND_SOC_DAPM_DAC("HPR DAC", "Headset", SND_SOC_NOPM, 0, 0),
669 SND_SOC_DAPM_DAC("LSL DAC", "Speaker", SND_SOC_NOPM, 0, 0),
670 SND_SOC_DAPM_DAC("LSR DAC", "Speaker", SND_SOC_NOPM, 0, 0),
671 SND_SOC_DAPM_DAC("HAL DAC", "Haptic", SND_SOC_NOPM, 0, 0),
672 SND_SOC_DAPM_DAC("HAR DAC", "Haptic", SND_SOC_NOPM, 0, 0),
673 SND_SOC_DAPM_DAC("LOL DAC", "Lineout", SND_SOC_NOPM, 0, 0),
674 SND_SOC_DAPM_DAC("LOR DAC", "Lineout", SND_SOC_NOPM, 0, 0),
675
676
677 SND_SOC_DAPM_PGA("AUXL Input",
678 LM49453_P0_ANALOG_MIXER_ADC_REG, 2, 0, NULL, 0),
679 SND_SOC_DAPM_PGA("AUXR Input",
680 LM49453_P0_ANALOG_MIXER_ADC_REG, 3, 0, NULL, 0),
681
682 SND_SOC_DAPM_PGA("Sidetone", SND_SOC_NOPM, 0, 0, NULL, 0),
683
684 /* ADC */
685 SND_SOC_DAPM_ADC("DMIC1 Left", "Capture", SND_SOC_NOPM, 1, 0),
686 SND_SOC_DAPM_ADC("DMIC1 Right", "Capture", SND_SOC_NOPM, 1, 0),
687 SND_SOC_DAPM_ADC("DMIC2 Left", "Capture", SND_SOC_NOPM, 1, 0),
688 SND_SOC_DAPM_ADC("DMIC2 Right", "Capture", SND_SOC_NOPM, 1, 0),
689
690 SND_SOC_DAPM_ADC("ADC Left", "Capture", SND_SOC_NOPM, 1, 0),
691 SND_SOC_DAPM_ADC("ADC Right", "Capture", SND_SOC_NOPM, 0, 0),
692
693 SND_SOC_DAPM_MUX("ADCL Mux", SND_SOC_NOPM, 0, 0,
694 &lm49453_adcl_mux_control),
695 SND_SOC_DAPM_MUX("ADCR Mux", SND_SOC_NOPM, 0, 0,
696 &lm49453_adcr_mux_control),
697
698 SND_SOC_DAPM_MUX("Mic1 Input",
699 SND_SOC_NOPM, 0, 0, &lm49453_adcl_mux_control),
700
701 SND_SOC_DAPM_MUX("Mic2 Input",
702 SND_SOC_NOPM, 0, 0, &lm49453_adcr_mux_control),
703
704 /* AIF */
705 SND_SOC_DAPM_AIF_IN("PORT1_SDI", NULL, 0,
706 LM49453_P0_PULL_CONFIG1_REG, 2, 0),
707 SND_SOC_DAPM_AIF_IN("PORT2_SDI", NULL, 0,
708 LM49453_P0_PULL_CONFIG1_REG, 6, 0),
709
710 SND_SOC_DAPM_AIF_OUT("PORT1_SDO", NULL, 0,
711 LM49453_P0_PULL_CONFIG1_REG, 3, 0),
712 SND_SOC_DAPM_AIF_OUT("PORT2_SDO", NULL, 0,
713 LM49453_P0_PULL_CONFIG1_REG, 7, 0),
714
715 /* Port1 TX controls */
716 SND_SOC_DAPM_OUT_DRV("P1_1_TX", SND_SOC_NOPM, 0, 0, NULL, 0),
717 SND_SOC_DAPM_OUT_DRV("P1_2_TX", SND_SOC_NOPM, 0, 0, NULL, 0),
718 SND_SOC_DAPM_OUT_DRV("P1_3_TX", SND_SOC_NOPM, 0, 0, NULL, 0),
719 SND_SOC_DAPM_OUT_DRV("P1_4_TX", SND_SOC_NOPM, 0, 0, NULL, 0),
720 SND_SOC_DAPM_OUT_DRV("P1_5_TX", SND_SOC_NOPM, 0, 0, NULL, 0),
721 SND_SOC_DAPM_OUT_DRV("P1_6_TX", SND_SOC_NOPM, 0, 0, NULL, 0),
722 SND_SOC_DAPM_OUT_DRV("P1_7_TX", SND_SOC_NOPM, 0, 0, NULL, 0),
723 SND_SOC_DAPM_OUT_DRV("P1_8_TX", SND_SOC_NOPM, 0, 0, NULL, 0),
724
725 /* Port2 TX controls */
726 SND_SOC_DAPM_OUT_DRV("P2_1_TX", SND_SOC_NOPM, 0, 0, NULL, 0),
727 SND_SOC_DAPM_OUT_DRV("P2_2_TX", SND_SOC_NOPM, 0, 0, NULL, 0),
728
729 /* Sidetone Mixer */
730 SND_SOC_DAPM_MIXER("Sidetone Mixer", SND_SOC_NOPM, 0, 0,
731 lm49453_sidetone_mixer_controls,
732 ARRAY_SIZE(lm49453_sidetone_mixer_controls)),
733
734 /* DAC MIXERS */
735 SND_SOC_DAPM_MIXER("HPL Mixer", SND_SOC_NOPM, 0, 0,
736 lm49453_headset_left_mixer,
737 ARRAY_SIZE(lm49453_headset_left_mixer)),
738 SND_SOC_DAPM_MIXER("HPR Mixer", SND_SOC_NOPM, 0, 0,
739 lm49453_headset_right_mixer,
740 ARRAY_SIZE(lm49453_headset_right_mixer)),
741 SND_SOC_DAPM_MIXER("LOL Mixer", SND_SOC_NOPM, 0, 0,
742 lm49453_lineout_left_mixer,
743 ARRAY_SIZE(lm49453_lineout_left_mixer)),
744 SND_SOC_DAPM_MIXER("LOR Mixer", SND_SOC_NOPM, 0, 0,
745 lm49453_lineout_right_mixer,
746 ARRAY_SIZE(lm49453_lineout_right_mixer)),
747 SND_SOC_DAPM_MIXER("LSL Mixer", SND_SOC_NOPM, 0, 0,
748 lm49453_speaker_left_mixer,
749 ARRAY_SIZE(lm49453_speaker_left_mixer)),
750 SND_SOC_DAPM_MIXER("LSR Mixer", SND_SOC_NOPM, 0, 0,
751 lm49453_speaker_right_mixer,
752 ARRAY_SIZE(lm49453_speaker_right_mixer)),
753 SND_SOC_DAPM_MIXER("HAL Mixer", SND_SOC_NOPM, 0, 0,
754 lm49453_haptic_left_mixer,
755 ARRAY_SIZE(lm49453_haptic_left_mixer)),
756 SND_SOC_DAPM_MIXER("HAR Mixer", SND_SOC_NOPM, 0, 0,
757 lm49453_haptic_right_mixer,
758 ARRAY_SIZE(lm49453_haptic_right_mixer)),
759
760 /* Capture Mixer */
761 SND_SOC_DAPM_MIXER("Port1_1 Mixer", SND_SOC_NOPM, 0, 0,
762 lm49453_port1_tx1_mixer,
763 ARRAY_SIZE(lm49453_port1_tx1_mixer)),
764 SND_SOC_DAPM_MIXER("Port1_2 Mixer", SND_SOC_NOPM, 0, 0,
765 lm49453_port1_tx2_mixer,
766 ARRAY_SIZE(lm49453_port1_tx2_mixer)),
767 SND_SOC_DAPM_MIXER("Port1_3 Mixer", SND_SOC_NOPM, 0, 0,
768 lm49453_port1_tx3_mixer,
769 ARRAY_SIZE(lm49453_port1_tx3_mixer)),
770 SND_SOC_DAPM_MIXER("Port1_4 Mixer", SND_SOC_NOPM, 0, 0,
771 lm49453_port1_tx4_mixer,
772 ARRAY_SIZE(lm49453_port1_tx4_mixer)),
773 SND_SOC_DAPM_MIXER("Port1_5 Mixer", SND_SOC_NOPM, 0, 0,
774 lm49453_port1_tx5_mixer,
775 ARRAY_SIZE(lm49453_port1_tx5_mixer)),
776 SND_SOC_DAPM_MIXER("Port1_6 Mixer", SND_SOC_NOPM, 0, 0,
777 lm49453_port1_tx6_mixer,
778 ARRAY_SIZE(lm49453_port1_tx6_mixer)),
779 SND_SOC_DAPM_MIXER("Port1_7 Mixer", SND_SOC_NOPM, 0, 0,
780 lm49453_port1_tx7_mixer,
781 ARRAY_SIZE(lm49453_port1_tx7_mixer)),
782 SND_SOC_DAPM_MIXER("Port1_8 Mixer", SND_SOC_NOPM, 0, 0,
783 lm49453_port1_tx8_mixer,
784 ARRAY_SIZE(lm49453_port1_tx8_mixer)),
785
786 SND_SOC_DAPM_MIXER("Port2_1 Mixer", SND_SOC_NOPM, 0, 0,
787 lm49453_port2_tx1_mixer,
788 ARRAY_SIZE(lm49453_port2_tx1_mixer)),
789 SND_SOC_DAPM_MIXER("Port2_2 Mixer", SND_SOC_NOPM, 0, 0,
790 lm49453_port2_tx2_mixer,
791 ARRAY_SIZE(lm49453_port2_tx2_mixer)),
792};
793
794static const struct snd_soc_dapm_route lm49453_audio_map[] = {
795 /* Port SDI mapping */
796 { "PORT1_1_RX", "Port1 Playback Switch", "PORT1_SDI" },
797 { "PORT1_2_RX", "Port1 Playback Switch", "PORT1_SDI" },
798 { "PORT1_3_RX", "Port1 Playback Switch", "PORT1_SDI" },
799 { "PORT1_4_RX", "Port1 Playback Switch", "PORT1_SDI" },
800 { "PORT1_5_RX", "Port1 Playback Switch", "PORT1_SDI" },
801 { "PORT1_6_RX", "Port1 Playback Switch", "PORT1_SDI" },
802 { "PORT1_7_RX", "Port1 Playback Switch", "PORT1_SDI" },
803 { "PORT1_8_RX", "Port1 Playback Switch", "PORT1_SDI" },
804
805 { "PORT2_1_RX", "Port2 Playback Switch", "PORT2_SDI" },
806 { "PORT2_2_RX", "Port2 Playback Switch", "PORT2_SDI" },
807
808 /* HP mapping */
809 { "HPL Mixer", "Port1_1 Switch", "PORT1_1_RX" },
810 { "HPL Mixer", "Port1_2 Switch", "PORT1_2_RX" },
811 { "HPL Mixer", "Port1_3 Switch", "PORT1_3_RX" },
812 { "HPL Mixer", "Port1_4 Switch", "PORT1_4_RX" },
813 { "HPL Mixer", "Port1_5 Switch", "PORT1_5_RX" },
814 { "HPL Mixer", "Port1_6 Switch", "PORT1_6_RX" },
815 { "HPL Mixer", "Port1_7 Switch", "PORT1_7_RX" },
816 { "HPL Mixer", "Port1_8 Switch", "PORT1_8_RX" },
817
818 { "HPL Mixer", "Port2_1 Switch", "PORT2_1_RX" },
819 { "HPL Mixer", "Port2_2 Switch", "PORT2_2_RX" },
820
821 { "HPL Mixer", "ADCL Switch", "ADC Left" },
822 { "HPL Mixer", "ADCR Switch", "ADC Right" },
823 { "HPL Mixer", "DMIC1L Switch", "DMIC1 Left" },
824 { "HPL Mixer", "DMIC1R Switch", "DMIC1 Right" },
825 { "HPL Mixer", "DMIC2L Switch", "DMIC2 Left" },
826 { "HPL Mixer", "DMIC2R Switch", "DMIC2 Right" },
827 { "HPL Mixer", "Sidetone Switch", "Sidetone" },
828
829 { "HPL DAC", NULL, "HPL Mixer" },
830
831 { "HPR Mixer", "Port1_1 Switch", "PORT1_1_RX" },
832 { "HPR Mixer", "Port1_2 Switch", "PORT1_2_RX" },
833 { "HPR Mixer", "Port1_3 Switch", "PORT1_3_RX" },
834 { "HPR Mixer", "Port1_4 Switch", "PORT1_4_RX" },
835 { "HPR Mixer", "Port1_5 Switch", "PORT1_5_RX" },
836 { "HPR Mixer", "Port1_6 Switch", "PORT1_6_RX" },
837 { "HPR Mixer", "Port1_7 Switch", "PORT1_7_RX" },
838 { "HPR Mixer", "Port1_8 Switch", "PORT1_8_RX" },
839
840 /* Port 2 */
841 { "HPR Mixer", "Port2_1 Switch", "PORT2_1_RX" },
842 { "HPR Mixer", "Port2_2 Switch", "PORT2_2_RX" },
843
844 { "HPR Mixer", "ADCL Switch", "ADC Left" },
845 { "HPR Mixer", "ADCR Switch", "ADC Right" },
846 { "HPR Mixer", "DMIC1L Switch", "DMIC1 Left" },
847 { "HPR Mixer", "DMIC1R Switch", "DMIC1 Right" },
848 { "HPR Mixer", "DMIC2L Switch", "DMIC2 Left" },
849 { "HPR Mixer", "DMIC2L Switch", "DMIC2 Right" },
850 { "HPR Mixer", "Sidetone Switch", "Sidetone" },
851
852 { "HPR DAC", NULL, "HPR Mixer" },
853
854 { "HPOUTL", "Headset Switch", "HPL DAC"},
855 { "HPOUTR", "Headset Switch", "HPR DAC"},
856
857 /* EP map */
858 { "EPOUT", "Earpiece Switch", "HPL DAC" },
859
860 /* Speaker map */
861 { "LSL Mixer", "Port1_1 Switch", "PORT1_1_RX" },
862 { "LSL Mixer", "Port1_2 Switch", "PORT1_2_RX" },
863 { "LSL Mixer", "Port1_3 Switch", "PORT1_3_RX" },
864 { "LSL Mixer", "Port1_4 Switch", "PORT1_4_RX" },
865 { "LSL Mixer", "Port1_5 Switch", "PORT1_5_RX" },
866 { "LSL Mixer", "Port1_6 Switch", "PORT1_6_RX" },
867 { "LSL Mixer", "Port1_7 Switch", "PORT1_7_RX" },
868 { "LSL Mixer", "Port1_8 Switch", "PORT1_8_RX" },
869
870 /* Port 2 */
871 { "LSL Mixer", "Port2_1 Switch", "PORT2_1_RX" },
872 { "LSL Mixer", "Port2_2 Switch", "PORT2_2_RX" },
873
874 { "LSL Mixer", "ADCL Switch", "ADC Left" },
875 { "LSL Mixer", "ADCR Switch", "ADC Right" },
876 { "LSL Mixer", "DMIC1L Switch", "DMIC1 Left" },
877 { "LSL Mixer", "DMIC1R Switch", "DMIC1 Right" },
878 { "LSL Mixer", "DMIC2L Switch", "DMIC2 Left" },
879 { "LSL Mixer", "DMIC2R Switch", "DMIC2 Right" },
880 { "LSL Mixer", "Sidetone Switch", "Sidetone" },
881
882 { "LSL DAC", NULL, "LSL Mixer" },
883
884 { "LSR Mixer", "Port1_1 Switch", "PORT1_1_RX" },
885 { "LSR Mixer", "Port1_2 Switch", "PORT1_2_RX" },
886 { "LSR Mixer", "Port1_3 Switch", "PORT1_3_RX" },
887 { "LSR Mixer", "Port1_4 Switch", "PORT1_4_RX" },
888 { "LSR Mixer", "Port1_5 Switch", "PORT1_5_RX" },
889 { "LSR Mixer", "Port1_6 Switch", "PORT1_6_RX" },
890 { "LSR Mixer", "Port1_7 Switch", "PORT1_7_RX" },
891 { "LSR Mixer", "Port1_8 Switch", "PORT1_8_RX" },
892
893 /* Port 2 */
894 { "LSR Mixer", "Port2_1 Switch", "PORT2_1_RX" },
895 { "LSR Mixer", "Port2_2 Switch", "PORT2_2_RX" },
896
897 { "LSR Mixer", "ADCL Switch", "ADC Left" },
898 { "LSR Mixer", "ADCR Switch", "ADC Right" },
899 { "LSR Mixer", "DMIC1L Switch", "DMIC1 Left" },
900 { "LSR Mixer", "DMIC1R Switch", "DMIC1 Right" },
901 { "LSR Mixer", "DMIC2L Switch", "DMIC2 Left" },
902 { "LSR Mixer", "DMIC2R Switch", "DMIC2 Right" },
903 { "LSR Mixer", "Sidetone Switch", "Sidetone" },
904
905 { "LSR DAC", NULL, "LSR Mixer" },
906
907 { "LSOUTL", "Speaker Left Switch", "LSL DAC"},
908 { "LSOUTR", "Speaker Left Switch", "LSR DAC"},
909
910 /* Haptic map */
911 { "HAL Mixer", "Port1_1 Switch", "PORT1_1_RX" },
912 { "HAL Mixer", "Port1_2 Switch", "PORT1_2_RX" },
913 { "HAL Mixer", "Port1_3 Switch", "PORT1_3_RX" },
914 { "HAL Mixer", "Port1_4 Switch", "PORT1_4_RX" },
915 { "HAL Mixer", "Port1_5 Switch", "PORT1_5_RX" },
916 { "HAL Mixer", "Port1_6 Switch", "PORT1_6_RX" },
917 { "HAL Mixer", "Port1_7 Switch", "PORT1_7_RX" },
918 { "HAL Mixer", "Port1_8 Switch", "PORT1_8_RX" },
919
920 /* Port 2 */
921 { "HAL Mixer", "Port2_1 Switch", "PORT2_1_RX" },
922 { "HAL Mixer", "Port2_2 Switch", "PORT2_2_RX" },
923
924 { "HAL Mixer", "ADCL Switch", "ADC Left" },
925 { "HAL Mixer", "ADCR Switch", "ADC Right" },
926 { "HAL Mixer", "DMIC1L Switch", "DMIC1 Left" },
927 { "HAL Mixer", "DMIC1R Switch", "DMIC1 Right" },
928 { "HAL Mixer", "DMIC2L Switch", "DMIC2 Left" },
929 { "HAL Mixer", "DMIC2R Switch", "DMIC2 Right" },
930 { "HAL Mixer", "Sidetone Switch", "Sidetone" },
931
932 { "HAL DAC", NULL, "HAL Mixer" },
933
934 { "HAR Mixer", "Port1_1 Switch", "PORT1_1_RX" },
935 { "HAR Mixer", "Port1_2 Switch", "PORT1_2_RX" },
936 { "HAR Mixer", "Port1_3 Switch", "PORT1_3_RX" },
937 { "HAR Mixer", "Port1_4 Switch", "PORT1_4_RX" },
938 { "HAR Mixer", "Port1_5 Switch", "PORT1_5_RX" },
939 { "HAR Mixer", "Port1_6 Switch", "PORT1_6_RX" },
940 { "HAR Mixer", "Port1_7 Switch", "PORT1_7_RX" },
941 { "HAR Mixer", "Port1_8 Switch", "PORT1_8_RX" },
942
943 /* Port 2 */
944 { "HAR Mixer", "Port2_1 Switch", "PORT2_1_RX" },
945 { "HAR Mixer", "Port2_2 Switch", "PORT2_2_RX" },
946
947 { "HAR Mixer", "ADCL Switch", "ADC Left" },
948 { "HAR Mixer", "ADCR Switch", "ADC Right" },
949 { "HAR Mixer", "DMIC1L Switch", "DMIC1 Left" },
950 { "HAR Mixer", "DMIC1R Switch", "DMIC1 Right" },
951 { "HAR Mixer", "DMIC2L Switch", "DMIC2 Left" },
952 { "HAR Mixer", "DMIC2R Switch", "DMIC2 Right" },
953 { "HAR Mixer", "Sideton Switch", "Sidetone" },
954
955 { "HAR DAC", NULL, "HAR Mixer" },
956
957 { "HAOUTL", "Haptic Left Switch", "HAL DAC" },
958 { "HAOUTR", "Haptic Right Switch", "HAR DAC" },
959
960 /* Lineout map */
961 { "LOL Mixer", "Port1_1 Switch", "PORT1_1_RX" },
962 { "LOL Mixer", "Port1_2 Switch", "PORT1_2_RX" },
963 { "LOL Mixer", "Port1_3 Switch", "PORT1_3_RX" },
964 { "LOL Mixer", "Port1_4 Switch", "PORT1_4_RX" },
965 { "LOL Mixer", "Port1_5 Switch", "PORT1_5_RX" },
966 { "LOL Mixer", "Port1_6 Switch", "PORT1_6_RX" },
967 { "LOL Mixer", "Port1_7 Switch", "PORT1_7_RX" },
968 { "LOL Mixer", "Port1_8 Switch", "PORT1_8_RX" },
969
970 /* Port 2 */
971 { "LOL Mixer", "Port2_1 Switch", "PORT2_1_RX" },
972 { "LOL Mixer", "Port2_2 Switch", "PORT2_2_RX" },
973
974 { "LOL Mixer", "ADCL Switch", "ADC Left" },
975 { "LOL Mixer", "ADCR Switch", "ADC Right" },
976 { "LOL Mixer", "DMIC1L Switch", "DMIC1 Left" },
977 { "LOL Mixer", "DMIC1R Switch", "DMIC1 Right" },
978 { "LOL Mixer", "DMIC2L Switch", "DMIC2 Left" },
979 { "LOL Mixer", "DMIC2R Switch", "DMIC2 Right" },
980 { "LOL Mixer", "Sidetone Switch", "Sidetone" },
981
982 { "LOL DAC", NULL, "LOL Mixer" },
983
984 { "LOR Mixer", "Port1_1 Switch", "PORT1_1_RX" },
985 { "LOR Mixer", "Port1_2 Switch", "PORT1_2_RX" },
986 { "LOR Mixer", "Port1_3 Switch", "PORT1_3_RX" },
987 { "LOR Mixer", "Port1_4 Switch", "PORT1_4_RX" },
988 { "LOR Mixer", "Port1_5 Switch", "PORT1_5_RX" },
989 { "LOR Mixer", "Port1_6 Switch", "PORT1_6_RX" },
990 { "LOR Mixer", "Port1_7 Switch", "PORT1_7_RX" },
991 { "LOR Mixer", "Port1_8 Switch", "PORT1_8_RX" },
992
993 /* Port 2 */
994 { "LOR Mixer", "Port2_1 Switch", "PORT2_1_RX" },
995 { "LOR Mixer", "Port2_2 Switch", "PORT2_2_RX" },
996
997 { "LOR Mixer", "ADCL Switch", "ADC Left" },
998 { "LOR Mixer", "ADCR Switch", "ADC Right" },
999 { "LOR Mixer", "DMIC1L Switch", "DMIC1 Left" },
1000 { "LOR Mixer", "DMIC1R Switch", "DMIC1 Right" },
1001 { "LOR Mixer", "DMIC2L Switch", "DMIC2 Left" },
1002 { "LOR Mixer", "DMIC2R Switch", "DMIC2 Right" },
1003 { "LOR Mixer", "Sidetone Switch", "Sidetone" },
1004
1005 { "LOR DAC", NULL, "LOR Mixer" },
1006
1007 { "LOOUTL", NULL, "LOL DAC" },
1008 { "LOOUTR", NULL, "LOR DAC" },
1009
1010 /* TX map */
1011 /* Port1 mappings */
1012 { "Port1_1 Mixer", "ADCL Switch", "ADC Left" },
1013 { "Port1_1 Mixer", "ADCR Switch", "ADC Right" },
1014 { "Port1_1 Mixer", "DMIC1L Switch", "DMIC1 Left" },
1015 { "Port1_1 Mixer", "DMIC1R Switch", "DMIC1 Right" },
1016 { "Port1_1 Mixer", "DMIC2L Switch", "DMIC2 Left" },
1017 { "Port1_1 Mixer", "DMIC2R Switch", "DMIC2 Right" },
1018
1019 { "Port1_2 Mixer", "ADCL Switch", "ADC Left" },
1020 { "Port1_2 Mixer", "ADCR Switch", "ADC Right" },
1021 { "Port1_2 Mixer", "DMIC1L Switch", "DMIC1 Left" },
1022 { "Port1_2 Mixer", "DMIC1R Switch", "DMIC1 Right" },
1023 { "Port1_2 Mixer", "DMIC2L Switch", "DMIC2 Left" },
1024 { "Port1_2 Mixer", "DMIC2R Switch", "DMIC2 Right" },
1025
1026 { "Port1_3 Mixer", "ADCL Switch", "ADC Left" },
1027 { "Port1_3 Mixer", "ADCR Switch", "ADC Right" },
1028 { "Port1_3 Mixer", "DMIC1L Switch", "DMIC1 Left" },
1029 { "Port1_3 Mixer", "DMIC1R Switch", "DMIC1 Right" },
1030 { "Port1_3 Mixer", "DMIC2L Switch", "DMIC2 Left" },
1031 { "Port1_3 Mixer", "DMIC2R Switch", "DMIC2 Right" },
1032
1033 { "Port1_4 Mixer", "ADCL Switch", "ADC Left" },
1034 { "Port1_4 Mixer", "ADCR Switch", "ADC Right" },
1035 { "Port1_4 Mixer", "DMIC1L Switch", "DMIC1 Left" },
1036 { "Port1_4 Mixer", "DMIC1R Switch", "DMIC1 Right" },
1037 { "Port1_4 Mixer", "DMIC2L Switch", "DMIC2 Left" },
1038 { "Port1_4 Mixer", "DMIC2R Switch", "DMIC2 Right" },
1039
1040 { "Port1_5 Mixer", "ADCL Switch", "ADC Left" },
1041 { "Port1_5 Mixer", "ADCR Switch", "ADC Right" },
1042 { "Port1_5 Mixer", "DMIC1L Switch", "DMIC1 Left" },
1043 { "Port1_5 Mixer", "DMIC1R Switch", "DMIC1 Right" },
1044 { "Port1_5 Mixer", "DMIC2L Switch", "DMIC2 Left" },
1045 { "Port1_5 Mixer", "DMIC2R Switch", "DMIC2 Right" },
1046
1047 { "Port1_6 Mixer", "ADCL Switch", "ADC Left" },
1048 { "Port1_6 Mixer", "ADCR Switch", "ADC Right" },
1049 { "Port1_6 Mixer", "DMIC1L Switch", "DMIC1 Left" },
1050 { "Port1_6 Mixer", "DMIC1R Switch", "DMIC1 Right" },
1051 { "Port1_6 Mixer", "DMIC2L Switch", "DMIC2 Left" },
1052 { "Port1_6 Mixer", "DMIC2R Switch", "DMIC2 Right" },
1053
1054 { "Port1_7 Mixer", "ADCL Switch", "ADC Left" },
1055 { "Port1_7 Mixer", "ADCR Switch", "ADC Right" },
1056 { "Port1_7 Mixer", "DMIC1L Switch", "DMIC1 Left" },
1057 { "Port1_7 Mixer", "DMIC1R Switch", "DMIC1 Right" },
1058 { "Port1_7 Mixer", "DMIC2L Switch", "DMIC2 Left" },
1059 { "Port1_7 Mixer", "DMIC2R Switch", "DMIC2 Right" },
1060
1061 { "Port1_8 Mixer", "ADCL Switch", "ADC Left" },
1062 { "Port1_8 Mixer", "ADCR Switch", "ADC Right" },
1063 { "Port1_8 Mixer", "DMIC1L Switch", "DMIC1 Left" },
1064 { "Port1_8 Mixer", "DMIC1R Switch", "DMIC1 Right" },
1065 { "Port1_8 Mixer", "DMIC2L Switch", "DMIC2 Left" },
1066 { "Port1_8 Mixer", "DMIC2R Switch", "DMIC2 Right" },
1067
1068 { "Port2_1 Mixer", "ADCL Switch", "ADC Left" },
1069 { "Port2_1 Mixer", "ADCR Switch", "ADC Right" },
1070 { "Port2_1 Mixer", "DMIC1L Switch", "DMIC1 Left" },
1071 { "Port2_1 Mixer", "DMIC1R Switch", "DMIC1 Right" },
1072 { "Port2_1 Mixer", "DMIC2L Switch", "DMIC2 Left" },
1073 { "Port2_1 Mixer", "DMIC2R Switch", "DMIC2 Right" },
1074
1075 { "Port2_2 Mixer", "ADCL Switch", "ADC Left" },
1076 { "Port2_2 Mixer", "ADCR Switch", "ADC Right" },
1077 { "Port2_2 Mixer", "DMIC1L Switch", "DMIC1 Left" },
1078 { "Port2_2 Mixer", "DMIC1R Switch", "DMIC1 Right" },
1079 { "Port2_2 Mixer", "DMIC2L Switch", "DMIC2 Left" },
1080 { "Port2_2 Mixer", "DMIC2R Switch", "DMIC2 Right" },
1081
1082 { "P1_1_TX", NULL, "Port1_1 Mixer" },
1083 { "P1_2_TX", NULL, "Port1_2 Mixer" },
1084 { "P1_3_TX", NULL, "Port1_3 Mixer" },
1085 { "P1_4_TX", NULL, "Port1_4 Mixer" },
1086 { "P1_5_TX", NULL, "Port1_5 Mixer" },
1087 { "P1_6_TX", NULL, "Port1_6 Mixer" },
1088 { "P1_7_TX", NULL, "Port1_7 Mixer" },
1089 { "P1_8_TX", NULL, "Port1_8 Mixer" },
1090
1091 { "P2_1_TX", NULL, "Port2_1 Mixer" },
1092 { "P2_2_TX", NULL, "Port2_2 Mixer" },
1093
1094 { "PORT1_SDO", "Port1 Capture Switch", "P1_1_TX"},
1095 { "PORT1_SDO", "Port1 Capture Switch", "P1_2_TX"},
1096 { "PORT1_SDO", "Port1 Capture Switch", "P1_3_TX"},
1097 { "PORT1_SDO", "Port1 Capture Switch", "P1_4_TX"},
1098 { "PORT1_SDO", "Port1 Capture Switch", "P1_5_TX"},
1099 { "PORT1_SDO", "Port1 Capture Switch", "P1_6_TX"},
1100 { "PORT1_SDO", "Port1 Capture Switch", "P1_7_TX"},
1101 { "PORT1_SDO", "Port1 Capture Switch", "P1_8_TX"},
1102
1103 { "PORT2_SDO", "Port2 Capture Switch", "P2_1_TX"},
1104 { "PORT2_SDO", "Port2 Capture Switch", "P2_2_TX"},
1105
1106 { "Mic1 Input", NULL, "AMIC1" },
1107 { "Mic2 Input", NULL, "AMIC2" },
1108
1109 { "AUXL Input", NULL, "AUXL" },
1110 { "AUXR Input", NULL, "AUXR" },
1111
1112 /* AUX connections */
1113 { "ADCL Mux", "Aux_L", "AUXL Input" },
1114 { "ADCL Mux", "MIC1", "Mic1 Input" },
1115
1116 { "ADCR Mux", "Aux_R", "AUXR Input" },
1117 { "ADCR Mux", "MIC2", "Mic2 Input" },
1118
1119 /* ADC connection */
1120 { "ADC Left", NULL, "ADCL Mux"},
1121 { "ADC Right", NULL, "ADCR Mux"},
1122
1123 { "DMIC1 Left", NULL, "DMIC1DAT"},
1124 { "DMIC1 Right", NULL, "DMIC1DAT"},
1125 { "DMIC2 Left", NULL, "DMIC2DAT"},
1126 { "DMIC2 Right", NULL, "DMIC2DAT"},
1127
1128 /* Sidetone map */
1129 { "Sidetone Mixer", NULL, "ADC Left" },
1130 { "Sidetone Mixer", NULL, "ADC Right" },
1131 { "Sidetone Mixer", NULL, "DMIC1 Left" },
1132 { "Sidetone Mixer", NULL, "DMIC1 Right" },
1133 { "Sidetone Mixer", NULL, "DMIC2 Left" },
1134 { "Sidetone Mixer", NULL, "DMIC2 Right" },
1135
1136 { "Sidetone", "Sidetone Switch", "Sidetone Mixer" },
1137};
1138
1139static int lm49453_hw_params(struct snd_pcm_substream *substream,
1140 struct snd_pcm_hw_params *params,
1141 struct snd_soc_dai *dai)
1142{
1143 struct snd_soc_codec *codec = dai->codec;
1144 struct lm49453_priv *lm49453 = snd_soc_codec_get_drvdata(codec);
1145 u16 clk_div = 0;
1146
1147 lm49453->fs_rate = params_rate(params);
1148
1149 /* Setting DAC clock dividers based on substream sample rate. */
1150 switch (lm49453->fs_rate) {
1151 case 8000:
1152 case 16000:
1153 case 32000:
1154 case 24000:
1155 case 48000:
1156 clk_div = 256;
1157 break;
1158 case 11025:
1159 case 22050:
1160 case 44100:
1161 clk_div = 216;
1162 break;
1163 case 96000:
1164 clk_div = 127;
1165 break;
1166 default:
1167 return -EINVAL;
1168 }
1169
1170 snd_soc_write(codec, LM49453_P0_ADC_CLK_DIV_REG, clk_div);
1171 snd_soc_write(codec, LM49453_P0_DAC_HP_CLK_DIV_REG, clk_div);
1172
1173 return 0;
1174}
1175
1176static int lm49453_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
1177{
1178 struct snd_soc_codec *codec = codec_dai->codec;
1179
1180 u16 aif_val;
1181 int mode = 0;
1182 int clk_phase = 0;
1183 int clk_shift = 0;
1184
1185 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
1186 case SND_SOC_DAIFMT_CBS_CFS:
1187 aif_val = 0;
1188 break;
1189 case SND_SOC_DAIFMT_CBS_CFM:
1190 aif_val = LM49453_AUDIO_PORT1_BASIC_SYNC_MS;
1191 break;
1192 case SND_SOC_DAIFMT_CBM_CFS:
1193 aif_val = LM49453_AUDIO_PORT1_BASIC_CLK_MS;
1194 break;
1195 case SND_SOC_DAIFMT_CBM_CFM:
1196 aif_val = LM49453_AUDIO_PORT1_BASIC_CLK_MS |
1197 LM49453_AUDIO_PORT1_BASIC_SYNC_MS;
1198 break;
1199 default:
1200 return -EINVAL;
1201 }
1202
1203
1204 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
1205 case SND_SOC_DAIFMT_I2S:
1206 break;
1207 case SND_SOC_DAIFMT_DSP_A:
1208 mode = 1;
1209 clk_phase = (1 << 5);
1210 clk_shift = 1;
1211 break;
1212 case SND_SOC_DAIFMT_DSP_B:
1213 mode = 1;
1214 clk_phase = (1 << 5);
1215 clk_shift = 0;
1216 break;
1217 default:
1218 return -EINVAL;
1219 }
1220
1221 snd_soc_update_bits(codec, LM49453_P0_AUDIO_PORT1_BASIC_REG,
1222 LM49453_AUDIO_PORT1_BASIC_FMT_MASK|BIT(1)|BIT(5),
1223 (aif_val | mode | clk_phase));
1224
1225 snd_soc_write(codec, LM49453_P0_AUDIO_PORT1_RX_MSB_REG, clk_shift);
1226
1227 return 0;
1228}
1229
1230static int lm49453_set_dai_sysclk(struct snd_soc_dai *dai, int clk_id,
1231 unsigned int freq, int dir)
1232{
1233 struct snd_soc_codec *codec = dai->codec;
1234 u16 pll_clk = 0;
1235
1236 switch (freq) {
1237 case 12288000:
1238 case 26000000:
1239 case 19200000:
1240 /* pll clk slection */
1241 pll_clk = 0;
1242 break;
1243 case 48000:
1244 case 32576:
1245 /* fll clk slection */
1246 pll_clk = BIT(4);
1247 return 0;
1248 default:
1249 return -EINVAL;
1250 }
1251
1252 snd_soc_update_bits(codec, LM49453_P0_PMC_SETUP_REG, BIT(4), pll_clk);
1253
1254 return 0;
1255}
1256
1257static int lm49453_hp_mute(struct snd_soc_dai *dai, int mute)
1258{
1259 snd_soc_update_bits(dai->codec, LM49453_P0_DAC_DSP_REG, BIT(1)|BIT(0),
1260 (mute ? (BIT(1)|BIT(0)) : 0));
1261 return 0;
1262}
1263
1264static int lm49453_lo_mute(struct snd_soc_dai *dai, int mute)
1265{
1266 snd_soc_update_bits(dai->codec, LM49453_P0_DAC_DSP_REG, BIT(3)|BIT(2),
1267 (mute ? (BIT(3)|BIT(2)) : 0));
1268 return 0;
1269}
1270
1271static int lm49453_ls_mute(struct snd_soc_dai *dai, int mute)
1272{
1273 snd_soc_update_bits(dai->codec, LM49453_P0_DAC_DSP_REG, BIT(5)|BIT(4),
1274 (mute ? (BIT(5)|BIT(4)) : 0));
1275 return 0;
1276}
1277
1278static int lm49453_ep_mute(struct snd_soc_dai *dai, int mute)
1279{
1280 snd_soc_update_bits(dai->codec, LM49453_P0_DAC_DSP_REG, BIT(4),
1281 (mute ? BIT(4) : 0));
1282 return 0;
1283}
1284
1285static int lm49453_ha_mute(struct snd_soc_dai *dai, int mute)
1286{
1287 snd_soc_update_bits(dai->codec, LM49453_P0_DAC_DSP_REG, BIT(7)|BIT(6),
1288 (mute ? (BIT(7)|BIT(6)) : 0));
1289 return 0;
1290}
1291
1292static int lm49453_set_bias_level(struct snd_soc_codec *codec,
1293 enum snd_soc_bias_level level)
1294{
1295 struct lm49453_priv *lm49453 = snd_soc_codec_get_drvdata(codec);
1296
1297 switch (level) {
1298 case SND_SOC_BIAS_ON:
1299 case SND_SOC_BIAS_PREPARE:
1300 break;
1301
1302 case SND_SOC_BIAS_STANDBY:
1303 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF)
1304 regcache_sync(lm49453->regmap);
1305
1306 snd_soc_update_bits(codec, LM49453_P0_PMC_SETUP_REG,
1307 LM49453_PMC_SETUP_CHIP_EN, LM49453_CHIP_EN);
1308 break;
1309
1310 case SND_SOC_BIAS_OFF:
1311 snd_soc_update_bits(codec, LM49453_P0_PMC_SETUP_REG,
1312 LM49453_PMC_SETUP_CHIP_EN, 0);
1313 break;
1314 }
1315
1316 codec->dapm.bias_level = level;
1317
1318 return 0;
1319}
1320
1321/* Formates supported by LM49453 driver. */
1322#define LM49453_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
1323 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
1324
1325static struct snd_soc_dai_ops lm49453_headset_dai_ops = {
1326 .hw_params = lm49453_hw_params,
1327 .set_sysclk = lm49453_set_dai_sysclk,
1328 .set_fmt = lm49453_set_dai_fmt,
1329 .digital_mute = lm49453_hp_mute,
1330};
1331
1332static struct snd_soc_dai_ops lm49453_speaker_dai_ops = {
1333 .hw_params = lm49453_hw_params,
1334 .set_sysclk = lm49453_set_dai_sysclk,
1335 .set_fmt = lm49453_set_dai_fmt,
1336 .digital_mute = lm49453_ls_mute,
1337};
1338
1339static struct snd_soc_dai_ops lm49453_haptic_dai_ops = {
1340 .hw_params = lm49453_hw_params,
1341 .set_sysclk = lm49453_set_dai_sysclk,
1342 .set_fmt = lm49453_set_dai_fmt,
1343 .digital_mute = lm49453_ha_mute,
1344};
1345
1346static struct snd_soc_dai_ops lm49453_ep_dai_ops = {
1347 .hw_params = lm49453_hw_params,
1348 .set_sysclk = lm49453_set_dai_sysclk,
1349 .set_fmt = lm49453_set_dai_fmt,
1350 .digital_mute = lm49453_ep_mute,
1351};
1352
1353static struct snd_soc_dai_ops lm49453_lineout_dai_ops = {
1354 .hw_params = lm49453_hw_params,
1355 .set_sysclk = lm49453_set_dai_sysclk,
1356 .set_fmt = lm49453_set_dai_fmt,
1357 .digital_mute = lm49453_lo_mute,
1358};
1359
1360/* LM49453 dai structure. */
1361static const struct snd_soc_dai_driver lm49453_dai[] = {
1362 {
1363 .name = "LM49453 Headset",
1364 .playback = {
1365 .stream_name = "Headset",
1366 .channels_min = 2,
1367 .channels_max = 2,
1368 .rates = SNDRV_PCM_RATE_8000_192000,
1369 .formats = LM49453_FORMATS,
1370 },
1371 .capture = {
1372 .stream_name = "Capture",
1373 .channels_min = 1,
1374 .channels_max = 5,
1375 .rates = SNDRV_PCM_RATE_8000_192000,
1376 .formats = LM49453_FORMATS,
1377 },
1378 .ops = &lm49453_headset_dai_ops,
1379 .symmetric_rates = 1,
1380 },
1381 {
1382 .name = "LM49453 Speaker",
1383 .playback = {
1384 .stream_name = "Speaker",
1385 .channels_min = 2,
1386 .channels_max = 2,
1387 .rates = SNDRV_PCM_RATE_8000_192000,
1388 .formats = LM49453_FORMATS,
1389 },
1390 .ops = &lm49453_speaker_dai_ops,
1391 },
1392 {
1393 .name = "LM49453 Haptic",
1394 .playback = {
1395 .stream_name = "Haptic",
1396 .channels_min = 2,
1397 .channels_max = 2,
1398 .rates = SNDRV_PCM_RATE_8000_192000,
1399 .formats = LM49453_FORMATS,
1400 },
1401 .ops = &lm49453_haptic_dai_ops,
1402 },
1403 {
1404 .name = "LM49453 Earpiece",
1405 .playback = {
1406 .stream_name = "Earpiece",
1407 .channels_min = 1,
1408 .channels_max = 1,
1409 .rates = SNDRV_PCM_RATE_8000_192000,
1410 .formats = LM49453_FORMATS,
1411 },
1412 .ops = &lm49453_ep_dai_ops,
1413 },
1414 {
1415 .name = "LM49453 line out",
1416 .playback = {
1417 .stream_name = "Lineout",
1418 .channels_min = 2,
1419 .channels_max = 2,
1420 .rates = SNDRV_PCM_RATE_8000_192000,
1421 .formats = LM49453_FORMATS,
1422 },
1423 .ops = &lm49453_lineout_dai_ops,
1424 },
1425};
1426
1427static int lm49453_suspend(struct snd_soc_codec *codec)
1428{
1429 lm49453_set_bias_level(codec, SND_SOC_BIAS_OFF);
1430 return 0;
1431}
1432
1433static int lm49453_resume(struct snd_soc_codec *codec)
1434{
1435 lm49453_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1436 return 0;
1437}
1438
1439static int lm49453_probe(struct snd_soc_codec *codec)
1440{
1441 struct lm49453_priv *lm49453 = snd_soc_codec_get_drvdata(codec);
1442 int ret = 0;
1443
1444 codec->control_data = lm49453->regmap;
1445
1446 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
1447 if (ret < 0) {
1448 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
1449 return ret;
1450 }
1451
1452 return 0;
1453}
1454
1455/* power down chip */
1456static int lm49453_remove(struct snd_soc_codec *codec)
1457{
1458 lm49453_set_bias_level(codec, SND_SOC_BIAS_OFF);
1459 return 0;
1460}
1461
1462static struct snd_soc_codec_driver soc_codec_dev_lm49453 = {
1463 .probe = lm49453_probe,
1464 .remove = lm49453_remove,
1465 .suspend = lm49453_suspend,
1466 .resume = lm49453_resume,
1467 .set_bias_level = lm49453_set_bias_level,
1468 .controls = lm49453_snd_controls,
1469 .num_controls = ARRAY_SIZE(lm49453_snd_controls),
1470 .dapm_widgets = lm49453_dapm_widgets,
1471 .num_dapm_widgets = ARRAY_SIZE(lm49453_dapm_widgets),
1472 .dapm_routes = lm49453_audio_map,
1473 .num_dapm_routes = ARRAY_SIZE(lm49453_audio_map),
1474 .idle_bias_off = true,
1475};
1476
1477static const struct regmap_config lm49453_regmap_config = {
1478 .reg_bits = 8,
1479 .val_bits = 8,
1480
1481 .max_register = LM49453_MAX_REGISTER,
1482 .reg_defaults = lm49453_reg_defs,
1483 .num_reg_defaults = ARRAY_SIZE(lm49453_reg_defs),
1484 .cache_type = REGCACHE_RBTREE,
1485};
1486
1487static __devinit int lm49453_i2c_probe(struct i2c_client *i2c,
1488 const struct i2c_device_id *id)
1489{
1490 struct lm49453_priv *lm49453;
1491 int ret = 0;
1492
1493 lm49453 = devm_kzalloc(&i2c->dev, sizeof(struct lm49453_priv),
1494 GFP_KERNEL);
1495
1496 if (lm49453 == NULL)
1497 return -ENOMEM;
1498
1499 i2c_set_clientdata(i2c, lm49453);
1500
1501 lm49453->regmap = regmap_init_i2c(i2c, &lm49453_regmap_config);
1502 if (IS_ERR(lm49453->regmap)) {
1503 ret = PTR_ERR(lm49453->regmap);
1504 dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
1505 ret);
1506 return ret;
1507 }
1508
1509 ret = snd_soc_register_codec(&i2c->dev,
1510 &soc_codec_dev_lm49453,
1511 lm49453_dai, ARRAY_SIZE(lm49453_dai));
1512 if (ret < 0) {
1513 dev_err(&i2c->dev, "Failed to register codec: %d\n", ret);
1514 regmap_exit(lm49453->regmap);
1515 return ret;
1516 }
1517
1518 return ret;
1519}
1520
1521static int __devexit lm49453_i2c_remove(struct i2c_client *client)
1522{
1523 struct lm49453_priv *lm49453 = i2c_get_clientdata(client);
1524
1525 snd_soc_unregister_codec(&client->dev);
1526 regmap_exit(lm49453->regmap);
1527 return 0;
1528}
1529
1530static const struct i2c_device_id lm49453_i2c_id[] = {
1531 { "lm49453", 0 },
1532 { }
1533};
1534MODULE_DEVICE_TABLE(i2c, lm49453_i2c_id);
1535
1536static struct i2c_driver lm49453_i2c_driver = {
1537 .driver = {
1538 .name = "lm49453",
1539 .owner = THIS_MODULE,
1540 },
1541 .probe = lm49453_i2c_probe,
1542 .remove = __devexit_p(lm49453_i2c_remove),
1543 .id_table = lm49453_i2c_id,
1544};
1545
1546module_i2c_driver(lm49453_i2c_driver);
1547
1548MODULE_DESCRIPTION("ASoC LM49453 driver");
1549MODULE_AUTHOR("M R Swami Reddy <MR.Swami.Reddy@ti.com>");
1550MODULE_LICENSE("GPL v2");
diff --git a/sound/soc/codecs/lm49453.h b/sound/soc/codecs/lm49453.h
new file mode 100644
index 000000000000..a63cfa5c0883
--- /dev/null
+++ b/sound/soc/codecs/lm49453.h
@@ -0,0 +1,380 @@
1/*
2 * lm49453.h - LM49453 ALSA Soc Audio drive
3 *
4 * Copyright (c) 2012 Texas Instruments, Inc
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 */
11
12#ifndef _LM49453_H
13#define _LM49453_H
14
15#include <linux/bitops.h>
16
17/* LM49453_P0 register space for page0 */
18#define LM49453_P0_PMC_SETUP_REG 0x00
19#define LM49453_P0_PLL_CLK_SEL1_REG 0x01
20#define LM49453_P0_PLL_CLK_SEL2_REG 0x02
21#define LM49453_P0_PMC_CLK_DIV_REG 0x03
22#define LM49453_P0_HSDET_CLK_DIV_REG 0x04
23#define LM49453_P0_DMIC_CLK_DIV_REG 0x05
24#define LM49453_P0_ADC_CLK_DIV_REG 0x06
25#define LM49453_P0_DAC_OT_CLK_DIV_REG 0x07
26#define LM49453_P0_PLL_HF_M_REG 0x08
27#define LM49453_P0_PLL_LF_M_REG 0x09
28#define LM49453_P0_PLL_NL_REG 0x0A
29#define LM49453_P0_PLL_N_MODL_REG 0x0B
30#define LM49453_P0_PLL_N_MODH_REG 0x0C
31#define LM49453_P0_PLL_P1_REG 0x0D
32#define LM49453_P0_PLL_P2_REG 0x0E
33#define LM49453_P0_FLL_REF_FREQL_REG 0x0F
34#define LM49453_P0_FLL_REF_FREQH_REG 0x10
35#define LM49453_P0_VCO_TARGETLL_REG 0x11
36#define LM49453_P0_VCO_TARGETLH_REG 0x12
37#define LM49453_P0_VCO_TARGETHL_REG 0x13
38#define LM49453_P0_VCO_TARGETHH_REG 0x14
39#define LM49453_P0_PLL_CONFIG_REG 0x15
40#define LM49453_P0_DAC_CLK_SEL_REG 0x16
41#define LM49453_P0_DAC_HP_CLK_DIV_REG 0x17
42
43/* Analog Mixer Input Stages */
44#define LM49453_P0_MICL_REG 0x20
45#define LM49453_P0_MICR_REG 0x21
46#define LM49453_P0_EP_REG 0x24
47#define LM49453_P0_DIS_PKVL_FB_REG 0x25
48
49/* Analog Mixer Output Stages */
50#define LM49453_P0_ANALOG_MIXER_ADC_REG 0x2E
51
52/*ADC or DAC */
53#define LM49453_P0_ADC_DSP_REG 0x30
54#define LM49453_P0_DAC_DSP_REG 0x31
55
56/* EFFECTS ENABLES */
57#define LM49453_P0_ADC_FX_ENABLES_REG 0x33
58
59/* GPIO */
60#define LM49453_P0_GPIO1_REG 0x38
61#define LM49453_P0_GPIO2_REG 0x39
62#define LM49453_P0_GPIO3_REG 0x3A
63#define LM49453_P0_HAP_CTL_REG 0x3B
64#define LM49453_P0_HAP_FREQ_PROG_LEFTL_REG 0x3C
65#define LM49453_P0_HAP_FREQ_PROG_LEFTH_REG 0x3D
66#define LM49453_P0_HAP_FREQ_PROG_RIGHTL_REG 0x3E
67#define LM49453_P0_HAP_FREQ_PROG_RIGHTH_REG 0x3F
68
69/* DIGITAL MIXER */
70#define LM49453_P0_DMIX_CLK_SEL_REG 0x40
71#define LM49453_P0_PORT1_RX_LVL1_REG 0x41
72#define LM49453_P0_PORT1_RX_LVL2_REG 0x42
73#define LM49453_P0_PORT2_RX_LVL_REG 0x43
74#define LM49453_P0_PORT1_TX1_REG 0x44
75#define LM49453_P0_PORT1_TX2_REG 0x45
76#define LM49453_P0_PORT1_TX3_REG 0x46
77#define LM49453_P0_PORT1_TX4_REG 0x47
78#define LM49453_P0_PORT1_TX5_REG 0x48
79#define LM49453_P0_PORT1_TX6_REG 0x49
80#define LM49453_P0_PORT1_TX7_REG 0x4A
81#define LM49453_P0_PORT1_TX8_REG 0x4B
82#define LM49453_P0_PORT2_TX1_REG 0x4C
83#define LM49453_P0_PORT2_TX2_REG 0x4D
84#define LM49453_P0_STN_SEL_REG 0x4F
85#define LM49453_P0_DACHPL1_REG 0x50
86#define LM49453_P0_DACHPL2_REG 0x51
87#define LM49453_P0_DACHPR1_REG 0x52
88#define LM49453_P0_DACHPR2_REG 0x53
89#define LM49453_P0_DACLOL1_REG 0x54
90#define LM49453_P0_DACLOL2_REG 0x55
91#define LM49453_P0_DACLOR1_REG 0x56
92#define LM49453_P0_DACLOR2_REG 0x57
93#define LM49453_P0_DACLSL1_REG 0x58
94#define LM49453_P0_DACLSL2_REG 0x59
95#define LM49453_P0_DACLSR1_REG 0x5A
96#define LM49453_P0_DACLSR2_REG 0x5B
97#define LM49453_P0_DACHAL1_REG 0x5C
98#define LM49453_P0_DACHAL2_REG 0x5D
99#define LM49453_P0_DACHAR1_REG 0x5E
100#define LM49453_P0_DACHAR2_REG 0x5F
101
102/* AUDIO PORT 1 (TDM) */
103#define LM49453_P0_AUDIO_PORT1_BASIC_REG 0x60
104#define LM49453_P0_AUDIO_PORT1_CLK_GEN1_REG 0x61
105#define LM49453_P0_AUDIO_PORT1_CLK_GEN2_REG 0x62
106#define LM49453_P0_AUDIO_PORT1_CLK_GEN3_REG 0x63
107#define LM49453_P0_AUDIO_PORT1_SYNC_RATE_REG 0x64
108#define LM49453_P0_AUDIO_PORT1_SYNC_SDO_SETUP_REG 0x65
109#define LM49453_P0_AUDIO_PORT1_DATA_WIDTH_REG 0x66
110#define LM49453_P0_AUDIO_PORT1_RX_MSB_REG 0x67
111#define LM49453_P0_AUDIO_PORT1_TX_MSB_REG 0x68
112#define LM49453_P0_AUDIO_PORT1_TDM_CHANNELS_REG 0x69
113
114/* AUDIO PORT 2 */
115#define LM49453_P0_AUDIO_PORT2_BASIC_REG 0x6A
116#define LM49453_P0_AUDIO_PORT2_CLK_GEN1_REG 0x6B
117#define LM49453_P0_AUDIO_PORT2_CLK_GEN2_REG 0x6C
118#define LM49453_P0_AUDIO_PORT2_SYNC_GEN_REG 0x6D
119#define LM49453_P0_AUDIO_PORT2_DATA_WIDTH_REG 0x6E
120#define LM49453_P0_AUDIO_PORT2_RX_MODE_REG 0x6F
121#define LM49453_P0_AUDIO_PORT2_TX_MODE_REG 0x70
122
123/* SAMPLE RATE */
124#define LM49453_P0_PORT1_SR_LSB_REG 0x79
125#define LM49453_P0_PORT1_SR_MSB_REG 0x7A
126#define LM49453_P0_PORT2_SR_LSB_REG 0x7B
127#define LM49453_P0_PORT2_SR_MSB_REG 0x7C
128
129/* EFFECTS - HPFs */
130#define LM49453_P0_HPF_REG 0x80
131
132/* EFFECTS ADC ALC */
133#define LM49453_P0_ADC_ALC1_REG 0x82
134#define LM49453_P0_ADC_ALC2_REG 0x83
135#define LM49453_P0_ADC_ALC3_REG 0x84
136#define LM49453_P0_ADC_ALC4_REG 0x85
137#define LM49453_P0_ADC_ALC5_REG 0x86
138#define LM49453_P0_ADC_ALC6_REG 0x87
139#define LM49453_P0_ADC_ALC7_REG 0x88
140#define LM49453_P0_ADC_ALC8_REG 0x89
141#define LM49453_P0_DMIC1_LEVELL_REG 0x8A
142#define LM49453_P0_DMIC1_LEVELR_REG 0x8B
143#define LM49453_P0_DMIC2_LEVELL_REG 0x8C
144#define LM49453_P0_DMIC2_LEVELR_REG 0x8D
145#define LM49453_P0_ADC_LEVELL_REG 0x8E
146#define LM49453_P0_ADC_LEVELR_REG 0x8F
147#define LM49453_P0_DAC_HP_LEVELL_REG 0x90
148#define LM49453_P0_DAC_HP_LEVELR_REG 0x91
149#define LM49453_P0_DAC_LO_LEVELL_REG 0x92
150#define LM49453_P0_DAC_LO_LEVELR_REG 0x93
151#define LM49453_P0_DAC_LS_LEVELL_REG 0x94
152#define LM49453_P0_DAC_LS_LEVELR_REG 0x95
153#define LM49453_P0_DAC_HA_LEVELL_REG 0x96
154#define LM49453_P0_DAC_HA_LEVELR_REG 0x97
155#define LM49453_P0_SOFT_MUTE_REG 0x98
156#define LM49453_P0_DMIC_MUTE_CFG_REG 0x99
157#define LM49453_P0_ADC_MUTE_CFG_REG 0x9A
158#define LM49453_P0_DAC_MUTE_CFG_REG 0x9B
159
160/*DIGITAL MIC1 */
161#define LM49453_P0_DIGITAL_MIC1_CONFIG_REG 0xB0
162#define LM49453_P0_DIGITAL_MIC1_DATA_DELAYL_REG 0xB1
163#define LM49453_P0_DIGITAL_MIC1_DATA_DELAYR_REG 0xB2
164
165/*DIGITAL MIC2 */
166#define LM49453_P0_DIGITAL_MIC2_CONFIG_REG 0xB3
167#define LM49453_P0_DIGITAL_MIC2_DATA_DELAYL_REG 0xB4
168#define LM49453_P0_DIGITAL_MIC2_DATA_DELAYR_REG 0xB5
169
170/* ADC DECIMATOR */
171#define LM49453_P0_ADC_DECIMATOR_REG 0xB6
172
173/* DAC CONFIGURE */
174#define LM49453_P0_DAC_CONFIG_REG 0xB7
175
176/* SIDETONE */
177#define LM49453_P0_STN_VOL_ADCL_REG 0xB8
178#define LM49453_P0_STN_VOL_ADCR_REG 0xB9
179#define LM49453_P0_STN_VOL_DMIC1L_REG 0xBA
180#define LM49453_P0_STN_VOL_DMIC1R_REG 0xBB
181#define LM49453_P0_STN_VOL_DMIC2L_REG 0xBC
182#define LM49453_P0_STN_VOL_DMIC2R_REG 0xBD
183
184/* ADC/DAC CLIPPING MONITORS (Read Only/Write to Clear) */
185#define LM49453_P0_ADC_DEC_CLIP_REG 0xC2
186#define LM49453_P0_ADC_HPF_CLIP_REG 0xC3
187#define LM49453_P0_ADC_LVL_CLIP_REG 0xC4
188#define LM49453_P0_DAC_LVL_CLIP_REG 0xC5
189
190/* ADC ALC EFFECT MONITORS (Read Only) */
191#define LM49453_P0_ADC_LVLMONL_REG 0xC8
192#define LM49453_P0_ADC_LVLMONR_REG 0xC9
193#define LM49453_P0_ADC_ALCMONL_REG 0xCA
194#define LM49453_P0_ADC_ALCMONR_REG 0xCB
195#define LM49453_P0_ADC_MUTED_REG 0xCC
196#define LM49453_P0_DAC_MUTED_REG 0xCD
197
198/* HEADSET DETECT */
199#define LM49453_P0_HSD_PPB_LONG_CNT_LIMITL_REG 0xD0
200#define LM49453_P0_HSD_PPB_LONG_CNT_LIMITR_REG 0xD1
201#define LM49453_P0_HSD_PIN3_4_EX_LOOP_CNT_LIMITL_REG 0xD2
202#define LM49453_P0_HSD_PIN3_4_EX_LOOP_CNT_LIMITH_REG 0xD3
203#define LM49453_P0_HSD_TIMEOUT1_REG 0xD4
204#define LM49453_P0_HSD_TIMEOUT2_REG 0xD5
205#define LM49453_P0_HSD_TIMEOUT3_REG 0xD6
206#define LM49453_P0_HSD_PIN3_4_CFG_REG 0xD7
207#define LM49453_P0_HSD_IRQ1_REG 0xD8
208#define LM49453_P0_HSD_IRQ2_REG 0xD9
209#define LM49453_P0_HSD_IRQ3_REG 0xDA
210#define LM49453_P0_HSD_IRQ4_REG 0xDB
211#define LM49453_P0_HSD_IRQ_MASK1_REG 0xDC
212#define LM49453_P0_HSD_IRQ_MASK2_REG 0xDD
213#define LM49453_P0_HSD_IRQ_MASK3_REG 0xDE
214#define LM49453_P0_HSD_R_HPLL_REG 0xE0
215#define LM49453_P0_HSD_R_HPLH_REG 0xE1
216#define LM49453_P0_HSD_R_HPLU_REG 0xE2
217#define LM49453_P0_HSD_R_HPRL_REG 0xE3
218#define LM49453_P0_HSD_R_HPRH_REG 0xE4
219#define LM49453_P0_HSD_R_HPRU_REG 0xE5
220#define LM49453_P0_HSD_VEL_L_FINALL_REG 0xE6
221#define LM49453_P0_HSD_VEL_L_FINALH_REG 0xE7
222#define LM49453_P0_HSD_VEL_L_FINALU_REG 0xE8
223#define LM49453_P0_HSD_RO_FINALL_REG 0xE9
224#define LM49453_P0_HSD_RO_FINALH_REG 0xEA
225#define LM49453_P0_HSD_RO_FINALU_REG 0xEB
226#define LM49453_P0_HSD_VMIC_BIAS_FINALL_REG 0xEC
227#define LM49453_P0_HSD_VMIC_BIAS_FINALH_REG 0xED
228#define LM49453_P0_HSD_VMIC_BIAS_FINALU_REG 0xEE
229#define LM49453_P0_HSD_PIN_CONFIG_REG 0xEF
230#define LM49453_P0_HSD_PLUG_DETECT_BB_IRQ_STATUS1_REG 0xF1
231#define LM49453_P0_HSD_PLUG_DETECT_BB_IRQ_STATUS2_REG 0xF2
232#define LM49453_P0_HSD_PLUG_DETECT_BB_IRQ_STATUS3_REG 0xF3
233#define LM49453_P0_HSD_PLUG_DETECT_BB_IRQ_STATEL_REG 0xF4
234#define LM49453_P0_HSD_PLUG_DETECT_BB_IRQ_STATEH_REG 0xF5
235
236/* I/O PULLDOWN CONFIG */
237#define LM49453_P0_PULL_CONFIG1_REG 0xF8
238#define LM49453_P0_PULL_CONFIG2_REG 0xF9
239#define LM49453_P0_PULL_CONFIG3_REG 0xFA
240
241/* RESET */
242#define LM49453_P0_RESET_REG 0xFE
243
244/* PAGE */
245#define LM49453_PAGE_REG 0xFF
246
247#define LM49453_MAX_REGISTER (0xFF+1)
248
249/* LM49453_P0_PMC_SETUP_REG (0x00h) */
250#define LM49453_PMC_SETUP_CHIP_EN (BIT(1)|BIT(0))
251#define LM49453_PMC_SETUP_PLL_EN BIT(2)
252#define LM49453_PMC_SETUP_PLL_P2_EN BIT(3)
253#define LM49453_PMC_SETUP_PLL_FLL BIT(4)
254#define LM49453_PMC_SETUP_MCLK_OVER BIT(5)
255#define LM49453_PMC_SETUP_RTC_CLK_OVER BIT(6)
256#define LM49453_PMC_SETUP_CHIP_ACTIVE BIT(7)
257
258/* Chip Enable bits */
259#define LM49453_CHIP_EN_SHUTDOWN 0x00
260#define LM49453_CHIP_EN 0x01
261#define LM49453_CHIP_EN_HSD_DETECT 0x02
262#define LM49453_CHIP_EN_INVALID_HSD 0x03
263
264/* LM49453_P0_PLL_CLK_SEL1_REG (0x01h) */
265#define LM49453_CLK_SEL1_MCLK_SEL 0x11
266#define LM49453_CLK_SEL1_RTC_SEL 0x11
267#define LM49453_CLK_SEL1_PORT1_SEL 0x10
268#define LM49453_CLK_SEL1_PORT2_SEL 0x11
269
270/* LM49453_P0_PLL_CLK_SEL2_REG (0x02h) */
271#define LM49453_CLK_SEL2_ADC_CLK_SEL 0x38
272
273/* LM49453_P0_FLL_REF_FREQL_REG (0x0F) */
274#define LM49453_FLL_REF_FREQ_VAL 0x8ca0001
275
276/* LM49453_P0_VCO_TARGETLL_REG (0x11) */
277#define LM49453_VCO_TARGET_VAL 0x8ca0001
278
279/* LM49453_P0_ADC_DSP_REG (0x30h) */
280#define LM49453_ADC_DSP_ADC_MUTEL BIT(0)
281#define LM49453_ADC_DSP_ADC_MUTER BIT(1)
282#define LM49453_ADC_DSP_DMIC1_MUTEL BIT(2)
283#define LM49453_ADC_DSP_DMIC1_MUTER BIT(3)
284#define LM49453_ADC_DSP_DMIC2_MUTEL BIT(4)
285#define LM49453_ADC_DSP_DMIC2_MUTER BIT(5)
286#define LM49453_ADC_DSP_MUTE_ALL 0x3F
287
288/* LM49453_P0_DAC_DSP_REG (0x31h) */
289#define LM49453_DAC_DSP_MUTE_ALL 0xFF
290
291/* LM49453_P0_AUDIO_PORT1_BASIC_REG (0x60h) */
292#define LM49453_AUDIO_PORT1_BASIC_FMT_MASK (BIT(4)|BIT(3))
293#define LM49453_AUDIO_PORT1_BASIC_CLK_MS BIT(3)
294#define LM49453_AUDIO_PORT1_BASIC_SYNC_MS BIT(4)
295
296/* LM49453_P0_RESET_REG (0xFEh) */
297#define LM49453_RESET_REG_RST BIT(0)
298
299/* Page select register bits (0xFF) */
300#define LM49453_PAGE0_SELECT 0x0
301#define LM49453_PAGE1_SELECT 0x1
302
303/* LM49453_P0_HSD_PIN3_4_CFG_REG (Jack Pin config - 0xD7) */
304#define LM49453_JACK_DISABLE 0x00
305#define LM49453_JACK_CONFIG1 0x01
306#define LM49453_JACK_CONFIG2 0x02
307#define LM49453_JACK_CONFIG3 0x03
308#define LM49453_JACK_CONFIG4 0x04
309#define LM49453_JACK_CONFIG5 0x05
310
311/* Page 1 REGISTERS */
312
313/* SIDETONE */
314#define LM49453_P1_SIDETONE_SA0L_REG 0x80
315#define LM49453_P1_SIDETONE_SA0H_REG 0x81
316#define LM49453_P1_SIDETONE_SAB0U_REG 0x82
317#define LM49453_P1_SIDETONE_SB0L_REG 0x83
318#define LM49453_P1_SIDETONE_SB0H_REG 0x84
319#define LM49453_P1_SIDETONE_SH0L_REG 0x85
320#define LM49453_P1_SIDETONE_SH0H_REG 0x86
321#define LM49453_P1_SIDETONE_SH0U_REG 0x87
322#define LM49453_P1_SIDETONE_SA1L_REG 0x88
323#define LM49453_P1_SIDETONE_SA1H_REG 0x89
324#define LM49453_P1_SIDETONE_SAB1U_REG 0x8A
325#define LM49453_P1_SIDETONE_SB1L_REG 0x8B
326#define LM49453_P1_SIDETONE_SB1H_REG 0x8C
327#define LM49453_P1_SIDETONE_SH1L_REG 0x8D
328#define LM49453_P1_SIDETONE_SH1H_REG 0x8E
329#define LM49453_P1_SIDETONE_SH1U_REG 0x8F
330#define LM49453_P1_SIDETONE_SA2L_REG 0x90
331#define LM49453_P1_SIDETONE_SA2H_REG 0x91
332#define LM49453_P1_SIDETONE_SAB2U_REG 0x92
333#define LM49453_P1_SIDETONE_SB2L_REG 0x93
334#define LM49453_P1_SIDETONE_SB2H_REG 0x94
335#define LM49453_P1_SIDETONE_SH2L_REG 0x95
336#define LM49453_P1_SIDETONE_SH2H_REG 0x96
337#define LM49453_P1_SIDETONE_SH2U_REG 0x97
338#define LM49453_P1_SIDETONE_SA3L_REG 0x98
339#define LM49453_P1_SIDETONE_SA3H_REG 0x99
340#define LM49453_P1_SIDETONE_SAB3U_REG 0x9A
341#define LM49453_P1_SIDETONE_SB3L_REG 0x9B
342#define LM49453_P1_SIDETONE_SB3H_REG 0x9C
343#define LM49453_P1_SIDETONE_SH3L_REG 0x9D
344#define LM49453_P1_SIDETONE_SH3H_REG 0x9E
345#define LM49453_P1_SIDETONE_SH3U_REG 0x9F
346#define LM49453_P1_SIDETONE_SA4L_REG 0xA0
347#define LM49453_P1_SIDETONE_SA4H_REG 0xA1
348#define LM49453_P1_SIDETONE_SAB4U_REG 0xA2
349#define LM49453_P1_SIDETONE_SB4L_REG 0xA3
350#define LM49453_P1_SIDETONE_SB4H_REG 0xA4
351#define LM49453_P1_SIDETONE_SH4L_REG 0xA5
352#define LM49453_P1_SIDETONE_SH4H_REG 0xA6
353#define LM49453_P1_SIDETONE_SH4U_REG 0xA7
354#define LM49453_P1_SIDETONE_SA5L_REG 0xA8
355#define LM49453_P1_SIDETONE_SA5H_REG 0xA9
356#define LM49453_P1_SIDETONE_SAB5U_REG 0xAA
357#define LM49453_P1_SIDETONE_SB5L_REG 0xAB
358#define LM49453_P1_SIDETONE_SB5H_REG 0xAC
359#define LM49453_P1_SIDETONE_SH5L_REG 0xAD
360#define LM49453_P1_SIDETONE_SH5H_REG 0xAE
361#define LM49453_P1_SIDETONE_SH5U_REG 0xAF
362
363/* CHARGE PUMP CONFIG */
364#define LM49453_P1_CP_CONFIG1_REG 0xB0
365#define LM49453_P1_CP_CONFIG2_REG 0xB1
366#define LM49453_P1_CP_CONFIG3_REG 0xB2
367#define LM49453_P1_CP_CONFIG4_REG 0xB3
368#define LM49453_P1_CP_LA_VTH1L_REG 0xB4
369#define LM49453_P1_CP_LA_VTH1M_REG 0xB5
370#define LM49453_P1_CP_LA_VTH2L_REG 0xB6
371#define LM49453_P1_CP_LA_VTH2M_REG 0xB7
372#define LM49453_P1_CP_LA_VTH3L_REG 0xB8
373#define LM49453_P1_CP_LA_VTH3H_REG 0xB9
374#define LM49453_P1_CP_CLK_DIV_REG 0xBA
375
376/* DAC */
377#define LM49453_P1_DAC_CHOP_REG 0xC0
378
379#define LM49453_CLK_SRC_MCLK 1
380#endif
diff --git a/sound/soc/codecs/max98095.c b/sound/soc/codecs/max98095.c
index 0bb511a0388d..35179e2c23c9 100644
--- a/sound/soc/codecs/max98095.c
+++ b/sound/soc/codecs/max98095.c
@@ -24,6 +24,7 @@
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <asm/div64.h> 25#include <asm/div64.h>
26#include <sound/max98095.h> 26#include <sound/max98095.h>
27#include <sound/jack.h>
27#include "max98095.h" 28#include "max98095.h"
28 29
29enum max98095_type { 30enum max98095_type {
@@ -51,6 +52,8 @@ struct max98095_priv {
51 u8 lin_state; 52 u8 lin_state;
52 unsigned int mic1pre; 53 unsigned int mic1pre;
53 unsigned int mic2pre; 54 unsigned int mic2pre;
55 struct snd_soc_jack *headphone_jack;
56 struct snd_soc_jack *mic_jack;
54}; 57};
55 58
56static const u8 max98095_reg_def[M98095_REG_CNT] = { 59static const u8 max98095_reg_def[M98095_REG_CNT] = {
@@ -2173,9 +2176,125 @@ static void max98095_handle_pdata(struct snd_soc_codec *codec)
2173 max98095_handle_bq_pdata(codec); 2176 max98095_handle_bq_pdata(codec);
2174} 2177}
2175 2178
2179static irqreturn_t max98095_report_jack(int irq, void *data)
2180{
2181 struct snd_soc_codec *codec = data;
2182 struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec);
2183 unsigned int value;
2184 int hp_report = 0;
2185 int mic_report = 0;
2186
2187 /* Read the Jack Status Register */
2188 value = snd_soc_read(codec, M98095_007_JACK_AUTO_STS);
2189
2190 /* If ddone is not set, then detection isn't finished yet */
2191 if ((value & M98095_DDONE) == 0)
2192 return IRQ_NONE;
2193
2194 /* if hp, check its bit, and if set, clear it */
2195 if ((value & M98095_HP_IN || value & M98095_LO_IN) &&
2196 max98095->headphone_jack)
2197 hp_report |= SND_JACK_HEADPHONE;
2198
2199 /* if mic, check its bit, and if set, clear it */
2200 if ((value & M98095_MIC_IN) && max98095->mic_jack)
2201 mic_report |= SND_JACK_MICROPHONE;
2202
2203 if (max98095->headphone_jack == max98095->mic_jack) {
2204 snd_soc_jack_report(max98095->headphone_jack,
2205 hp_report | mic_report,
2206 SND_JACK_HEADSET);
2207 } else {
2208 if (max98095->headphone_jack)
2209 snd_soc_jack_report(max98095->headphone_jack,
2210 hp_report, SND_JACK_HEADPHONE);
2211 if (max98095->mic_jack)
2212 snd_soc_jack_report(max98095->mic_jack,
2213 mic_report, SND_JACK_MICROPHONE);
2214 }
2215
2216 return IRQ_HANDLED;
2217}
2218
2219int max98095_jack_detect_enable(struct snd_soc_codec *codec)
2220{
2221 struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec);
2222 int ret = 0;
2223 int detect_enable = M98095_JDEN;
2224 unsigned int slew = M98095_DEFAULT_SLEW_DELAY;
2225
2226 if (max98095->pdata->jack_detect_pin5en)
2227 detect_enable |= M98095_PIN5EN;
2228
2229 if (max98095->pdata->jack_detect_delay)
2230 slew = max98095->pdata->jack_detect_delay;
2231
2232 ret = snd_soc_write(codec, M98095_08E_JACK_DC_SLEW, slew);
2233 if (ret < 0) {
2234 dev_err(codec->dev, "Failed to cfg auto detect %d\n", ret);
2235 return ret;
2236 }
2237
2238 /* configure auto detection to be enabled */
2239 ret = snd_soc_write(codec, M98095_089_JACK_DET_AUTO, detect_enable);
2240 if (ret < 0) {
2241 dev_err(codec->dev, "Failed to cfg auto detect %d\n", ret);
2242 return ret;
2243 }
2244
2245 return ret;
2246}
2247
2248int max98095_jack_detect_disable(struct snd_soc_codec *codec)
2249{
2250 int ret = 0;
2251
2252 /* configure auto detection to be disabled */
2253 ret = snd_soc_write(codec, M98095_089_JACK_DET_AUTO, 0x0);
2254 if (ret < 0) {
2255 dev_err(codec->dev, "Failed to cfg auto detect %d\n", ret);
2256 return ret;
2257 }
2258
2259 return ret;
2260}
2261
2262int max98095_jack_detect(struct snd_soc_codec *codec,
2263 struct snd_soc_jack *hp_jack, struct snd_soc_jack *mic_jack)
2264{
2265 struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec);
2266 struct i2c_client *client = to_i2c_client(codec->dev);
2267 int ret = 0;
2268
2269 max98095->headphone_jack = hp_jack;
2270 max98095->mic_jack = mic_jack;
2271
2272 /* only progress if we have at least 1 jack pointer */
2273 if (!hp_jack && !mic_jack)
2274 return -EINVAL;
2275
2276 max98095_jack_detect_enable(codec);
2277
2278 /* enable interrupts for headphone jack detection */
2279 ret = snd_soc_update_bits(codec, M98095_013_JACK_INT_EN,
2280 M98095_IDDONE, M98095_IDDONE);
2281 if (ret < 0) {
2282 dev_err(codec->dev, "Failed to cfg jack irqs %d\n", ret);
2283 return ret;
2284 }
2285
2286 max98095_report_jack(client->irq, codec);
2287 return 0;
2288}
2289
2176#ifdef CONFIG_PM 2290#ifdef CONFIG_PM
2177static int max98095_suspend(struct snd_soc_codec *codec) 2291static int max98095_suspend(struct snd_soc_codec *codec)
2178{ 2292{
2293 struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec);
2294
2295 if (max98095->headphone_jack || max98095->mic_jack)
2296 max98095_jack_detect_disable(codec);
2297
2179 max98095_set_bias_level(codec, SND_SOC_BIAS_OFF); 2298 max98095_set_bias_level(codec, SND_SOC_BIAS_OFF);
2180 2299
2181 return 0; 2300 return 0;
@@ -2183,8 +2302,16 @@ static int max98095_suspend(struct snd_soc_codec *codec)
2183 2302
2184static int max98095_resume(struct snd_soc_codec *codec) 2303static int max98095_resume(struct snd_soc_codec *codec)
2185{ 2304{
2305 struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec);
2306 struct i2c_client *client = to_i2c_client(codec->dev);
2307
2186 max98095_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 2308 max98095_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
2187 2309
2310 if (max98095->headphone_jack || max98095->mic_jack) {
2311 max98095_jack_detect_enable(codec);
2312 max98095_report_jack(client->irq, codec);
2313 }
2314
2188 return 0; 2315 return 0;
2189} 2316}
2190#else 2317#else
@@ -2227,6 +2354,7 @@ static int max98095_probe(struct snd_soc_codec *codec)
2227{ 2354{
2228 struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); 2355 struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec);
2229 struct max98095_cdata *cdata; 2356 struct max98095_cdata *cdata;
2357 struct i2c_client *client;
2230 int ret = 0; 2358 int ret = 0;
2231 2359
2232 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_I2C); 2360 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_I2C);
@@ -2238,6 +2366,8 @@ static int max98095_probe(struct snd_soc_codec *codec)
2238 /* reset the codec, the DSP core, and disable all interrupts */ 2366 /* reset the codec, the DSP core, and disable all interrupts */
2239 max98095_reset(codec); 2367 max98095_reset(codec);
2240 2368
2369 client = to_i2c_client(codec->dev);
2370
2241 /* initialize private data */ 2371 /* initialize private data */
2242 2372
2243 max98095->sysclk = (unsigned)-1; 2373 max98095->sysclk = (unsigned)-1;
@@ -2266,11 +2396,23 @@ static int max98095_probe(struct snd_soc_codec *codec)
2266 max98095->mic1pre = 0; 2396 max98095->mic1pre = 0;
2267 max98095->mic2pre = 0; 2397 max98095->mic2pre = 0;
2268 2398
2399 if (client->irq) {
2400 /* register an audio interrupt */
2401 ret = request_threaded_irq(client->irq, NULL,
2402 max98095_report_jack,
2403 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
2404 "max98095", codec);
2405 if (ret) {
2406 dev_err(codec->dev, "Failed to request IRQ: %d\n", ret);
2407 goto err_access;
2408 }
2409 }
2410
2269 ret = snd_soc_read(codec, M98095_0FF_REV_ID); 2411 ret = snd_soc_read(codec, M98095_0FF_REV_ID);
2270 if (ret < 0) { 2412 if (ret < 0) {
2271 dev_err(codec->dev, "Failure reading hardware revision: %d\n", 2413 dev_err(codec->dev, "Failure reading hardware revision: %d\n",
2272 ret); 2414 ret);
2273 goto err_access; 2415 goto err_irq;
2274 } 2416 }
2275 dev_info(codec->dev, "Hardware revision: %c\n", ret - 0x40 + 'A'); 2417 dev_info(codec->dev, "Hardware revision: %c\n", ret - 0x40 + 'A');
2276 2418
@@ -2306,14 +2448,28 @@ static int max98095_probe(struct snd_soc_codec *codec)
2306 2448
2307 max98095_add_widgets(codec); 2449 max98095_add_widgets(codec);
2308 2450
2451 return 0;
2452
2453err_irq:
2454 if (client->irq)
2455 free_irq(client->irq, codec);
2309err_access: 2456err_access:
2310 return ret; 2457 return ret;
2311} 2458}
2312 2459
2313static int max98095_remove(struct snd_soc_codec *codec) 2460static int max98095_remove(struct snd_soc_codec *codec)
2314{ 2461{
2462 struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec);
2463 struct i2c_client *client = to_i2c_client(codec->dev);
2464
2315 max98095_set_bias_level(codec, SND_SOC_BIAS_OFF); 2465 max98095_set_bias_level(codec, SND_SOC_BIAS_OFF);
2316 2466
2467 if (max98095->headphone_jack || max98095->mic_jack)
2468 max98095_jack_detect_disable(codec);
2469
2470 if (client->irq)
2471 free_irq(client->irq, codec);
2472
2317 return 0; 2473 return 0;
2318} 2474}
2319 2475
diff --git a/sound/soc/codecs/max98095.h b/sound/soc/codecs/max98095.h
index 891584a0eb03..2ebbe4e894bf 100644
--- a/sound/soc/codecs/max98095.h
+++ b/sound/soc/codecs/max98095.h
@@ -175,11 +175,23 @@
175 175
176/* MAX98095 Registers Bit Fields */ 176/* MAX98095 Registers Bit Fields */
177 177
178/* M98095_007_JACK_AUTO_STS */
179 #define M98095_MIC_IN (1<<3)
180 #define M98095_LO_IN (1<<5)
181 #define M98095_HP_IN (1<<6)
182 #define M98095_DDONE (1<<7)
183
178/* M98095_00F_HOST_CFG */ 184/* M98095_00F_HOST_CFG */
179 #define M98095_SEG (1<<0) 185 #define M98095_SEG (1<<0)
180 #define M98095_XTEN (1<<1) 186 #define M98095_XTEN (1<<1)
181 #define M98095_MDLLEN (1<<2) 187 #define M98095_MDLLEN (1<<2)
182 188
189/* M98095_013_JACK_INT_EN */
190 #define M98095_IMIC_IN (1<<3)
191 #define M98095_ILO_IN (1<<5)
192 #define M98095_IHP_IN (1<<6)
193 #define M98095_IDDONE (1<<7)
194
183/* M98095_027_DAI1_CLKMODE, M98095_031_DAI2_CLKMODE, M98095_03B_DAI3_CLKMODE */ 195/* M98095_027_DAI1_CLKMODE, M98095_031_DAI2_CLKMODE, M98095_03B_DAI3_CLKMODE */
184 #define M98095_CLKMODE_MASK 0xFF 196 #define M98095_CLKMODE_MASK 0xFF
185 197
@@ -255,6 +267,10 @@
255 #define M98095_EQ2EN (1<<1) 267 #define M98095_EQ2EN (1<<1)
256 #define M98095_EQ1EN (1<<0) 268 #define M98095_EQ1EN (1<<0)
257 269
270/* M98095_089_JACK_DET_AUTO */
271 #define M98095_PIN5EN (1<<2)
272 #define M98095_JDEN (1<<7)
273
258/* M98095_090_PWR_EN_IN */ 274/* M98095_090_PWR_EN_IN */
259 #define M98095_INEN (1<<7) 275 #define M98095_INEN (1<<7)
260 #define M98095_MB2EN (1<<3) 276 #define M98095_MB2EN (1<<3)
@@ -296,4 +312,10 @@
296#define M98095_174_DAI1_BQ_BASE 0x74 312#define M98095_174_DAI1_BQ_BASE 0x74
297#define M98095_17E_DAI2_BQ_BASE 0x7E 313#define M98095_17E_DAI2_BQ_BASE 0x7E
298 314
315/* Default Delay used in Slew Rate Calculation for Jack detection */
316#define M98095_DEFAULT_SLEW_DELAY 0x18
317
318extern int max98095_jack_detect(struct snd_soc_codec *codec,
319 struct snd_soc_jack *hp_jack, struct snd_soc_jack *mic_jack);
320
299#endif 321#endif
diff --git a/sound/soc/codecs/mc13783.c b/sound/soc/codecs/mc13783.c
new file mode 100644
index 000000000000..6276e352125f
--- /dev/null
+++ b/sound/soc/codecs/mc13783.c
@@ -0,0 +1,786 @@
1/*
2 * Copyright 2008 Juergen Beisert, kernel@pengutronix.de
3 * Copyright 2009 Sascha Hauer, s.hauer@pengutronix.de
4 * Copyright 2012 Philippe Retornaz, philippe.retornaz@epfl.ch
5 *
6 * Initial development of this code was funded by
7 * Phytec Messtechnik GmbH, http://www.phytec.de
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21 * MA 02110-1301, USA.
22 */
23#include <linux/module.h>
24#include <linux/device.h>
25#include <linux/mfd/mc13xxx.h>
26#include <linux/slab.h>
27#include <sound/core.h>
28#include <sound/control.h>
29#include <sound/pcm.h>
30#include <sound/soc.h>
31#include <sound/initval.h>
32#include <sound/soc-dapm.h>
33
34#include "mc13783.h"
35
36#define MC13783_AUDIO_RX0 36
37#define MC13783_AUDIO_RX1 37
38#define MC13783_AUDIO_TX 38
39#define MC13783_SSI_NETWORK 39
40#define MC13783_AUDIO_CODEC 40
41#define MC13783_AUDIO_DAC 41
42
43#define AUDIO_RX0_ALSPEN (1 << 5)
44#define AUDIO_RX0_ALSPSEL (1 << 7)
45#define AUDIO_RX0_ADDCDC (1 << 21)
46#define AUDIO_RX0_ADDSTDC (1 << 22)
47#define AUDIO_RX0_ADDRXIN (1 << 23)
48
49#define AUDIO_RX1_PGARXEN (1 << 0);
50#define AUDIO_RX1_PGASTEN (1 << 5)
51#define AUDIO_RX1_ARXINEN (1 << 10)
52
53#define AUDIO_TX_AMC1REN (1 << 5)
54#define AUDIO_TX_AMC1LEN (1 << 7)
55#define AUDIO_TX_AMC2EN (1 << 9)
56#define AUDIO_TX_ATXINEN (1 << 11)
57#define AUDIO_TX_RXINREC (1 << 13)
58
59#define SSI_NETWORK_CDCTXRXSLOT(x) (((x) & 0x3) << 2)
60#define SSI_NETWORK_CDCTXSECSLOT(x) (((x) & 0x3) << 4)
61#define SSI_NETWORK_CDCRXSECSLOT(x) (((x) & 0x3) << 6)
62#define SSI_NETWORK_CDCRXSECGAIN(x) (((x) & 0x3) << 8)
63#define SSI_NETWORK_CDCSUMGAIN(x) (1 << 10)
64#define SSI_NETWORK_CDCFSDLY(x) (1 << 11)
65#define SSI_NETWORK_DAC_SLOTS_8 (1 << 12)
66#define SSI_NETWORK_DAC_SLOTS_4 (2 << 12)
67#define SSI_NETWORK_DAC_SLOTS_2 (3 << 12)
68#define SSI_NETWORK_DAC_SLOT_MASK (3 << 12)
69#define SSI_NETWORK_DAC_RXSLOT_0_1 (0 << 14)
70#define SSI_NETWORK_DAC_RXSLOT_2_3 (1 << 14)
71#define SSI_NETWORK_DAC_RXSLOT_4_5 (2 << 14)
72#define SSI_NETWORK_DAC_RXSLOT_6_7 (3 << 14)
73#define SSI_NETWORK_DAC_RXSLOT_MASK (3 << 14)
74#define SSI_NETWORK_STDCRXSECSLOT(x) (((x) & 0x3) << 16)
75#define SSI_NETWORK_STDCRXSECGAIN(x) (((x) & 0x3) << 18)
76#define SSI_NETWORK_STDCSUMGAIN (1 << 20)
77
78/*
79 * MC13783_AUDIO_CODEC and MC13783_AUDIO_DAC mostly share the same
80 * register layout
81 */
82#define AUDIO_SSI_SEL (1 << 0)
83#define AUDIO_CLK_SEL (1 << 1)
84#define AUDIO_CSM (1 << 2)
85#define AUDIO_BCL_INV (1 << 3)
86#define AUDIO_CFS_INV (1 << 4)
87#define AUDIO_CFS(x) (((x) & 0x3) << 5)
88#define AUDIO_CLK(x) (((x) & 0x7) << 7)
89#define AUDIO_C_EN (1 << 11)
90#define AUDIO_C_CLK_EN (1 << 12)
91#define AUDIO_C_RESET (1 << 15)
92
93#define AUDIO_CODEC_CDCFS8K16K (1 << 10)
94#define AUDIO_DAC_CFS_DLY_B (1 << 10)
95
96struct mc13783_priv {
97 struct snd_soc_codec codec;
98 struct mc13xxx *mc13xxx;
99
100 enum mc13783_ssi_port adc_ssi_port;
101 enum mc13783_ssi_port dac_ssi_port;
102};
103
104static unsigned int mc13783_read(struct snd_soc_codec *codec,
105 unsigned int reg)
106{
107 struct mc13783_priv *priv = snd_soc_codec_get_drvdata(codec);
108 unsigned int value = 0;
109
110 mc13xxx_lock(priv->mc13xxx);
111
112 mc13xxx_reg_read(priv->mc13xxx, reg, &value);
113
114 mc13xxx_unlock(priv->mc13xxx);
115
116 return value;
117}
118
119static int mc13783_write(struct snd_soc_codec *codec,
120 unsigned int reg, unsigned int value)
121{
122 struct mc13783_priv *priv = snd_soc_codec_get_drvdata(codec);
123 int ret;
124
125 mc13xxx_lock(priv->mc13xxx);
126
127 ret = mc13xxx_reg_write(priv->mc13xxx, reg, value);
128
129 mc13xxx_unlock(priv->mc13xxx);
130
131 return ret;
132}
133
134/* Mapping between sample rates and register value */
135static unsigned int mc13783_rates[] = {
136 8000, 11025, 12000, 16000,
137 22050, 24000, 32000, 44100,
138 48000, 64000, 96000
139};
140
141static int mc13783_pcm_hw_params_dac(struct snd_pcm_substream *substream,
142 struct snd_pcm_hw_params *params,
143 struct snd_soc_dai *dai)
144{
145 struct snd_soc_pcm_runtime *rtd = substream->private_data;
146 struct snd_soc_codec *codec = rtd->codec;
147 unsigned int rate = params_rate(params);
148 int i;
149
150 for (i = 0; i < ARRAY_SIZE(mc13783_rates); i++) {
151 if (rate == mc13783_rates[i]) {
152 snd_soc_update_bits(codec, MC13783_AUDIO_DAC,
153 0xf << 17, i << 17);
154 return 0;
155 }
156 }
157
158 return -EINVAL;
159}
160
161static int mc13783_pcm_hw_params_codec(struct snd_pcm_substream *substream,
162 struct snd_pcm_hw_params *params,
163 struct snd_soc_dai *dai)
164{
165 struct snd_soc_pcm_runtime *rtd = substream->private_data;
166 struct snd_soc_codec *codec = rtd->codec;
167 unsigned int rate = params_rate(params);
168 unsigned int val;
169
170 switch (rate) {
171 case 8000:
172 val = 0;
173 break;
174 case 16000:
175 val = AUDIO_CODEC_CDCFS8K16K;
176 break;
177 default:
178 return -EINVAL;
179 }
180
181 snd_soc_update_bits(codec, MC13783_AUDIO_CODEC, AUDIO_CODEC_CDCFS8K16K,
182 val);
183
184 return 0;
185}
186
187static int mc13783_pcm_hw_params_sync(struct snd_pcm_substream *substream,
188 struct snd_pcm_hw_params *params,
189 struct snd_soc_dai *dai)
190{
191 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
192 return mc13783_pcm_hw_params_dac(substream, params, dai);
193 else
194 return mc13783_pcm_hw_params_codec(substream, params, dai);
195}
196
197static int mc13783_set_fmt(struct snd_soc_dai *dai, unsigned int fmt,
198 unsigned int reg)
199{
200 struct snd_soc_codec *codec = dai->codec;
201 unsigned int val = 0;
202 unsigned int mask = AUDIO_CFS(3) | AUDIO_BCL_INV | AUDIO_CFS_INV |
203 AUDIO_CSM | AUDIO_C_CLK_EN | AUDIO_C_RESET;
204
205
206 /* DAI mode */
207 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
208 case SND_SOC_DAIFMT_I2S:
209 val |= AUDIO_CFS(2);
210 break;
211 case SND_SOC_DAIFMT_DSP_A:
212 val |= AUDIO_CFS(1);
213 break;
214 default:
215 return -EINVAL;
216 }
217
218 /* DAI clock inversion */
219 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
220 case SND_SOC_DAIFMT_NB_NF:
221 val |= AUDIO_BCL_INV;
222 break;
223 case SND_SOC_DAIFMT_NB_IF:
224 val |= AUDIO_BCL_INV | AUDIO_CFS_INV;
225 break;
226 case SND_SOC_DAIFMT_IB_NF:
227 break;
228 case SND_SOC_DAIFMT_IB_IF:
229 val |= AUDIO_CFS_INV;
230 break;
231 }
232
233 /* DAI clock master masks */
234 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
235 case SND_SOC_DAIFMT_CBM_CFM:
236 val |= AUDIO_C_CLK_EN;
237 break;
238 case SND_SOC_DAIFMT_CBS_CFS:
239 val |= AUDIO_CSM;
240 break;
241 case SND_SOC_DAIFMT_CBM_CFS:
242 case SND_SOC_DAIFMT_CBS_CFM:
243 return -EINVAL;
244 }
245
246 val |= AUDIO_C_RESET;
247
248 snd_soc_update_bits(codec, reg, mask, val);
249
250 return 0;
251}
252
253static int mc13783_set_fmt_async(struct snd_soc_dai *dai, unsigned int fmt)
254{
255 if (dai->id == MC13783_ID_STEREO_DAC)
256 return mc13783_set_fmt(dai, fmt, MC13783_AUDIO_DAC);
257 else
258 return mc13783_set_fmt(dai, fmt, MC13783_AUDIO_CODEC);
259}
260
261static int mc13783_set_fmt_sync(struct snd_soc_dai *dai, unsigned int fmt)
262{
263 int ret;
264
265 ret = mc13783_set_fmt(dai, fmt, MC13783_AUDIO_DAC);
266 if (ret)
267 return ret;
268
269 /*
270 * In synchronous mode force the voice codec into slave mode
271 * so that the clock / framesync from the stereo DAC is used
272 */
273 fmt &= ~SND_SOC_DAIFMT_MASTER_MASK;
274 fmt |= SND_SOC_DAIFMT_CBS_CFS;
275 ret = mc13783_set_fmt(dai, fmt, MC13783_AUDIO_CODEC);
276
277 return ret;
278}
279
280static int mc13783_sysclk[] = {
281 13000000,
282 15360000,
283 16800000,
284 -1,
285 26000000,
286 -1, /* 12000000, invalid for voice codec */
287 -1, /* 3686400, invalid for voice codec */
288 33600000,
289};
290
291static int mc13783_set_sysclk(struct snd_soc_dai *dai,
292 int clk_id, unsigned int freq, int dir,
293 unsigned int reg)
294{
295 struct snd_soc_codec *codec = dai->codec;
296 int clk;
297 unsigned int val = 0;
298 unsigned int mask = AUDIO_CLK(0x7) | AUDIO_CLK_SEL;
299
300 for (clk = 0; clk < ARRAY_SIZE(mc13783_sysclk); clk++) {
301 if (mc13783_sysclk[clk] < 0)
302 continue;
303 if (mc13783_sysclk[clk] == freq)
304 break;
305 }
306
307 if (clk == ARRAY_SIZE(mc13783_sysclk))
308 return -EINVAL;
309
310 if (clk_id == MC13783_CLK_CLIB)
311 val |= AUDIO_CLK_SEL;
312
313 val |= AUDIO_CLK(clk);
314
315 snd_soc_update_bits(codec, reg, mask, val);
316
317 return 0;
318}
319
320static int mc13783_set_sysclk_dac(struct snd_soc_dai *dai,
321 int clk_id, unsigned int freq, int dir)
322{
323 return mc13783_set_sysclk(dai, clk_id, freq, dir, MC13783_AUDIO_DAC);
324}
325
326static int mc13783_set_sysclk_codec(struct snd_soc_dai *dai,
327 int clk_id, unsigned int freq, int dir)
328{
329 return mc13783_set_sysclk(dai, clk_id, freq, dir, MC13783_AUDIO_CODEC);
330}
331
332static int mc13783_set_sysclk_sync(struct snd_soc_dai *dai,
333 int clk_id, unsigned int freq, int dir)
334{
335 int ret;
336
337 ret = mc13783_set_sysclk(dai, clk_id, freq, dir, MC13783_AUDIO_DAC);
338 if (ret)
339 return ret;
340
341 return mc13783_set_sysclk(dai, clk_id, freq, dir, MC13783_AUDIO_CODEC);
342}
343
344static int mc13783_set_tdm_slot_dac(struct snd_soc_dai *dai,
345 unsigned int tx_mask, unsigned int rx_mask, int slots,
346 int slot_width)
347{
348 struct snd_soc_codec *codec = dai->codec;
349 unsigned int val = 0;
350 unsigned int mask = SSI_NETWORK_DAC_SLOT_MASK |
351 SSI_NETWORK_DAC_RXSLOT_MASK;
352
353 switch (slots) {
354 case 2:
355 val |= SSI_NETWORK_DAC_SLOTS_2;
356 break;
357 case 4:
358 val |= SSI_NETWORK_DAC_SLOTS_4;
359 break;
360 case 8:
361 val |= SSI_NETWORK_DAC_SLOTS_8;
362 break;
363 default:
364 return -EINVAL;
365 }
366
367 switch (rx_mask) {
368 case 0xfffffffc:
369 val |= SSI_NETWORK_DAC_RXSLOT_0_1;
370 break;
371 case 0xfffffff3:
372 val |= SSI_NETWORK_DAC_RXSLOT_2_3;
373 break;
374 case 0xffffffcf:
375 val |= SSI_NETWORK_DAC_RXSLOT_4_5;
376 break;
377 case 0xffffff3f:
378 val |= SSI_NETWORK_DAC_RXSLOT_6_7;
379 break;
380 default:
381 return -EINVAL;
382 };
383
384 snd_soc_update_bits(codec, MC13783_SSI_NETWORK, mask, val);
385
386 return 0;
387}
388
389static int mc13783_set_tdm_slot_codec(struct snd_soc_dai *dai,
390 unsigned int tx_mask, unsigned int rx_mask, int slots,
391 int slot_width)
392{
393 struct snd_soc_codec *codec = dai->codec;
394 unsigned int val = 0;
395 unsigned int mask = 0x3f;
396
397 if (slots != 4)
398 return -EINVAL;
399
400 if (tx_mask != 0xfffffffc)
401 return -EINVAL;
402
403 val |= (0x00 << 2); /* primary timeslot RX/TX(?) is 0 */
404 val |= (0x01 << 4); /* secondary timeslot TX is 1 */
405
406 snd_soc_update_bits(codec, MC13783_SSI_NETWORK, mask, val);
407
408 return 0;
409}
410
411static int mc13783_set_tdm_slot_sync(struct snd_soc_dai *dai,
412 unsigned int tx_mask, unsigned int rx_mask, int slots,
413 int slot_width)
414{
415 int ret;
416
417 ret = mc13783_set_tdm_slot_dac(dai, tx_mask, rx_mask, slots,
418 slot_width);
419 if (ret)
420 return ret;
421
422 ret = mc13783_set_tdm_slot_codec(dai, tx_mask, rx_mask, slots,
423 slot_width);
424
425 return ret;
426}
427
428static const struct snd_kcontrol_new mc1l_amp_ctl =
429 SOC_DAPM_SINGLE("Switch", 38, 7, 1, 0);
430
431static const struct snd_kcontrol_new mc1r_amp_ctl =
432 SOC_DAPM_SINGLE("Switch", 38, 5, 1, 0);
433
434static const struct snd_kcontrol_new mc2_amp_ctl =
435 SOC_DAPM_SINGLE("Switch", 38, 9, 1, 0);
436
437static const struct snd_kcontrol_new atx_amp_ctl =
438 SOC_DAPM_SINGLE("Switch", 38, 11, 1, 0);
439
440
441/* Virtual mux. The chip does the input selection automatically
442 * as soon as we enable one input. */
443static const char * const adcl_enum_text[] = {
444 "MC1L", "RXINL",
445};
446
447static const struct soc_enum adcl_enum =
448 SOC_ENUM_SINGLE(0, 0, ARRAY_SIZE(adcl_enum_text), adcl_enum_text);
449
450static const struct snd_kcontrol_new left_input_mux =
451 SOC_DAPM_ENUM_VIRT("Route", adcl_enum);
452
453static const char * const adcr_enum_text[] = {
454 "MC1R", "MC2", "RXINR", "TXIN",
455};
456
457static const struct soc_enum adcr_enum =
458 SOC_ENUM_SINGLE(0, 0, ARRAY_SIZE(adcr_enum_text), adcr_enum_text);
459
460static const struct snd_kcontrol_new right_input_mux =
461 SOC_DAPM_ENUM_VIRT("Route", adcr_enum);
462
463static const struct snd_kcontrol_new samp_ctl =
464 SOC_DAPM_SINGLE("Switch", 36, 3, 1, 0);
465
466static const struct snd_kcontrol_new lamp_ctl =
467 SOC_DAPM_SINGLE("Switch", 36, 5, 1, 0);
468
469static const struct snd_kcontrol_new hlamp_ctl =
470 SOC_DAPM_SINGLE("Switch", 36, 10, 1, 0);
471
472static const struct snd_kcontrol_new hramp_ctl =
473 SOC_DAPM_SINGLE("Switch", 36, 9, 1, 0);
474
475static const struct snd_kcontrol_new llamp_ctl =
476 SOC_DAPM_SINGLE("Switch", 36, 16, 1, 0);
477
478static const struct snd_kcontrol_new lramp_ctl =
479 SOC_DAPM_SINGLE("Switch", 36, 15, 1, 0);
480
481static const struct snd_soc_dapm_widget mc13783_dapm_widgets[] = {
482/* Input */
483 SND_SOC_DAPM_INPUT("MC1LIN"),
484 SND_SOC_DAPM_INPUT("MC1RIN"),
485 SND_SOC_DAPM_INPUT("MC2IN"),
486 SND_SOC_DAPM_INPUT("RXINR"),
487 SND_SOC_DAPM_INPUT("RXINL"),
488 SND_SOC_DAPM_INPUT("TXIN"),
489
490 SND_SOC_DAPM_SUPPLY("MC1 Bias", 38, 0, 0, NULL, 0),
491 SND_SOC_DAPM_SUPPLY("MC2 Bias", 38, 1, 0, NULL, 0),
492
493 SND_SOC_DAPM_SWITCH("MC1L Amp", 38, 7, 0, &mc1l_amp_ctl),
494 SND_SOC_DAPM_SWITCH("MC1R Amp", 38, 5, 0, &mc1r_amp_ctl),
495 SND_SOC_DAPM_SWITCH("MC2 Amp", 38, 9, 0, &mc2_amp_ctl),
496 SND_SOC_DAPM_SWITCH("TXIN Amp", 38, 11, 0, &atx_amp_ctl),
497
498 SND_SOC_DAPM_VIRT_MUX("PGA Left Input Mux", SND_SOC_NOPM, 0, 0,
499 &left_input_mux),
500 SND_SOC_DAPM_VIRT_MUX("PGA Right Input Mux", SND_SOC_NOPM, 0, 0,
501 &right_input_mux),
502
503 SND_SOC_DAPM_PGA("PGA Left Input", SND_SOC_NOPM, 0, 0, NULL, 0),
504 SND_SOC_DAPM_PGA("PGA Right Input", SND_SOC_NOPM, 0, 0, NULL, 0),
505
506 SND_SOC_DAPM_ADC("ADC", "Capture", 40, 11, 0),
507 SND_SOC_DAPM_SUPPLY("ADC_Reset", 40, 15, 0, NULL, 0),
508
509/* Output */
510 SND_SOC_DAPM_SUPPLY("DAC_E", 41, 11, 0, NULL, 0),
511 SND_SOC_DAPM_SUPPLY("DAC_Reset", 41, 15, 0, NULL, 0),
512 SND_SOC_DAPM_OUTPUT("RXOUTL"),
513 SND_SOC_DAPM_OUTPUT("RXOUTR"),
514 SND_SOC_DAPM_OUTPUT("HSL"),
515 SND_SOC_DAPM_OUTPUT("HSR"),
516 SND_SOC_DAPM_OUTPUT("LSP"),
517 SND_SOC_DAPM_OUTPUT("SP"),
518
519 SND_SOC_DAPM_SWITCH("Speaker Amp", 36, 3, 0, &samp_ctl),
520 SND_SOC_DAPM_SWITCH("Loudspeaker Amp", SND_SOC_NOPM, 0, 0, &lamp_ctl),
521 SND_SOC_DAPM_SWITCH("Headset Amp Left", 36, 10, 0, &hlamp_ctl),
522 SND_SOC_DAPM_SWITCH("Headset Amp Right", 36, 9, 0, &hramp_ctl),
523 SND_SOC_DAPM_SWITCH("Line out Amp Left", 36, 16, 0, &llamp_ctl),
524 SND_SOC_DAPM_SWITCH("Line out Amp Right", 36, 15, 0, &lramp_ctl),
525 SND_SOC_DAPM_DAC("DAC", "Playback", 36, 22, 0),
526 SND_SOC_DAPM_PGA("DAC PGA", 37, 5, 0, NULL, 0),
527};
528
529static struct snd_soc_dapm_route mc13783_routes[] = {
530/* Input */
531 { "MC1L Amp", NULL, "MC1LIN"},
532 { "MC1R Amp", NULL, "MC1RIN" },
533 { "MC2 Amp", NULL, "MC2IN" },
534 { "TXIN Amp", NULL, "TXIN"},
535
536 { "PGA Left Input Mux", "MC1L", "MC1L Amp" },
537 { "PGA Left Input Mux", "RXINL", "RXINL"},
538 { "PGA Right Input Mux", "MC1R", "MC1R Amp" },
539 { "PGA Right Input Mux", "MC2", "MC2 Amp"},
540 { "PGA Right Input Mux", "TXIN", "TXIN Amp"},
541 { "PGA Right Input Mux", "RXINR", "RXINR"},
542
543 { "PGA Left Input", NULL, "PGA Left Input Mux"},
544 { "PGA Right Input", NULL, "PGA Right Input Mux"},
545
546 { "ADC", NULL, "PGA Left Input"},
547 { "ADC", NULL, "PGA Right Input"},
548 { "ADC", NULL, "ADC_Reset"},
549
550/* Output */
551 { "HSL", NULL, "Headset Amp Left" },
552 { "HSR", NULL, "Headset Amp Right"},
553 { "RXOUTL", NULL, "Line out Amp Left"},
554 { "RXOUTR", NULL, "Line out Amp Right"},
555 { "SP", NULL, "Speaker Amp"},
556 { "Speaker Amp", NULL, "DAC PGA"},
557 { "LSP", NULL, "DAC PGA"},
558 { "Headset Amp Left", NULL, "DAC PGA"},
559 { "Headset Amp Right", NULL, "DAC PGA"},
560 { "Line out Amp Left", NULL, "DAC PGA"},
561 { "Line out Amp Right", NULL, "DAC PGA"},
562 { "DAC PGA", NULL, "DAC"},
563 { "DAC", NULL, "DAC_E"},
564};
565
566static const char * const mc13783_3d_mixer[] = {"Stereo", "Phase Mix",
567 "Mono", "Mono Mix"};
568
569static const struct soc_enum mc13783_enum_3d_mixer =
570 SOC_ENUM_SINGLE(MC13783_AUDIO_RX1, 16, ARRAY_SIZE(mc13783_3d_mixer),
571 mc13783_3d_mixer);
572
573static struct snd_kcontrol_new mc13783_control_list[] = {
574 SOC_SINGLE("Loudspeaker enable", MC13783_AUDIO_RX0, 5, 1, 0),
575 SOC_SINGLE("PCM Playback Volume", MC13783_AUDIO_RX1, 6, 15, 0),
576 SOC_DOUBLE("PCM Capture Volume", MC13783_AUDIO_TX, 19, 14, 31, 0),
577 SOC_ENUM("3D Control", mc13783_enum_3d_mixer),
578};
579
580static int mc13783_probe(struct snd_soc_codec *codec)
581{
582 struct mc13783_priv *priv = snd_soc_codec_get_drvdata(codec);
583
584 mc13xxx_lock(priv->mc13xxx);
585
586 /* these are the reset values */
587 mc13xxx_reg_write(priv->mc13xxx, MC13783_AUDIO_RX0, 0x25893);
588 mc13xxx_reg_write(priv->mc13xxx, MC13783_AUDIO_RX1, 0x00d35A);
589 mc13xxx_reg_write(priv->mc13xxx, MC13783_AUDIO_TX, 0x420000);
590 mc13xxx_reg_write(priv->mc13xxx, MC13783_SSI_NETWORK, 0x013060);
591 mc13xxx_reg_write(priv->mc13xxx, MC13783_AUDIO_CODEC, 0x180027);
592 mc13xxx_reg_write(priv->mc13xxx, MC13783_AUDIO_DAC, 0x0e0004);
593
594 if (priv->adc_ssi_port == MC13783_SSI1_PORT)
595 mc13xxx_reg_rmw(priv->mc13xxx, MC13783_AUDIO_CODEC,
596 AUDIO_SSI_SEL, 0);
597 else
598 mc13xxx_reg_rmw(priv->mc13xxx, MC13783_AUDIO_CODEC,
599 0, AUDIO_SSI_SEL);
600
601 if (priv->dac_ssi_port == MC13783_SSI1_PORT)
602 mc13xxx_reg_rmw(priv->mc13xxx, MC13783_AUDIO_DAC,
603 AUDIO_SSI_SEL, 0);
604 else
605 mc13xxx_reg_rmw(priv->mc13xxx, MC13783_AUDIO_DAC,
606 0, AUDIO_SSI_SEL);
607
608 mc13xxx_unlock(priv->mc13xxx);
609
610 return 0;
611}
612
613static int mc13783_remove(struct snd_soc_codec *codec)
614{
615 struct mc13783_priv *priv = snd_soc_codec_get_drvdata(codec);
616
617 mc13xxx_lock(priv->mc13xxx);
618
619 /* Make sure VAUDIOON is off */
620 mc13xxx_reg_rmw(priv->mc13xxx, MC13783_AUDIO_RX0, 0x3, 0);
621
622 mc13xxx_unlock(priv->mc13xxx);
623
624 return 0;
625}
626
627#define MC13783_RATES_RECORD (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000)
628
629#define MC13783_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
630 SNDRV_PCM_FMTBIT_S24_LE)
631
632static struct snd_soc_dai_ops mc13783_ops_dac = {
633 .hw_params = mc13783_pcm_hw_params_dac,
634 .set_fmt = mc13783_set_fmt_async,
635 .set_sysclk = mc13783_set_sysclk_dac,
636 .set_tdm_slot = mc13783_set_tdm_slot_dac,
637};
638
639static struct snd_soc_dai_ops mc13783_ops_codec = {
640 .hw_params = mc13783_pcm_hw_params_codec,
641 .set_fmt = mc13783_set_fmt_async,
642 .set_sysclk = mc13783_set_sysclk_codec,
643 .set_tdm_slot = mc13783_set_tdm_slot_codec,
644};
645
646/*
647 * The mc13783 has two SSI ports, both of them can be routed either
648 * to the voice codec or the stereo DAC. When two different SSI ports
649 * are used for the voice codec and the stereo DAC we can do different
650 * formats and sysclock settings for playback and capture
651 * (mc13783-hifi-playback and mc13783-hifi-capture). Using the same port
652 * forces us to use symmetric rates (mc13783-hifi).
653 */
654static struct snd_soc_dai_driver mc13783_dai_async[] = {
655 {
656 .name = "mc13783-hifi-playback",
657 .id = MC13783_ID_STEREO_DAC,
658 .playback = {
659 .stream_name = "Playback",
660 .channels_min = 1,
661 .channels_max = 2,
662 .rates = SNDRV_PCM_RATE_8000_96000,
663 .formats = MC13783_FORMATS,
664 },
665 .ops = &mc13783_ops_dac,
666 }, {
667 .name = "mc13783-hifi-capture",
668 .id = MC13783_ID_STEREO_CODEC,
669 .capture = {
670 .stream_name = "Capture",
671 .channels_min = 1,
672 .channels_max = 2,
673 .rates = MC13783_RATES_RECORD,
674 .formats = MC13783_FORMATS,
675 },
676 .ops = &mc13783_ops_codec,
677 },
678};
679
680static struct snd_soc_dai_ops mc13783_ops_sync = {
681 .hw_params = mc13783_pcm_hw_params_sync,
682 .set_fmt = mc13783_set_fmt_sync,
683 .set_sysclk = mc13783_set_sysclk_sync,
684 .set_tdm_slot = mc13783_set_tdm_slot_sync,
685};
686
687static struct snd_soc_dai_driver mc13783_dai_sync[] = {
688 {
689 .name = "mc13783-hifi",
690 .id = MC13783_ID_SYNC,
691 .playback = {
692 .stream_name = "Playback",
693 .channels_min = 1,
694 .channels_max = 2,
695 .rates = SNDRV_PCM_RATE_8000_96000,
696 .formats = MC13783_FORMATS,
697 },
698 .capture = {
699 .stream_name = "Capture",
700 .channels_min = 1,
701 .channels_max = 2,
702 .rates = MC13783_RATES_RECORD,
703 .formats = MC13783_FORMATS,
704 },
705 .ops = &mc13783_ops_sync,
706 .symmetric_rates = 1,
707 }
708};
709
710static struct snd_soc_codec_driver soc_codec_dev_mc13783 = {
711 .probe = mc13783_probe,
712 .remove = mc13783_remove,
713 .read = mc13783_read,
714 .write = mc13783_write,
715 .controls = mc13783_control_list,
716 .num_controls = ARRAY_SIZE(mc13783_control_list),
717 .dapm_widgets = mc13783_dapm_widgets,
718 .num_dapm_widgets = ARRAY_SIZE(mc13783_dapm_widgets),
719 .dapm_routes = mc13783_routes,
720 .num_dapm_routes = ARRAY_SIZE(mc13783_routes),
721};
722
723static int mc13783_codec_probe(struct platform_device *pdev)
724{
725 struct mc13xxx *mc13xxx;
726 struct mc13783_priv *priv;
727 struct mc13xxx_codec_platform_data *pdata = pdev->dev.platform_data;
728 int ret;
729
730 mc13xxx = dev_get_drvdata(pdev->dev.parent);
731
732
733 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
734 if (priv == NULL)
735 return -ENOMEM;
736
737 dev_set_drvdata(&pdev->dev, priv);
738 priv->mc13xxx = mc13xxx;
739 if (pdata) {
740 priv->adc_ssi_port = pdata->adc_ssi_port;
741 priv->dac_ssi_port = pdata->dac_ssi_port;
742 } else {
743 priv->adc_ssi_port = MC13783_SSI1_PORT;
744 priv->dac_ssi_port = MC13783_SSI2_PORT;
745 }
746
747 if (priv->adc_ssi_port == priv->dac_ssi_port)
748 ret = snd_soc_register_codec(&pdev->dev, &soc_codec_dev_mc13783,
749 mc13783_dai_sync, ARRAY_SIZE(mc13783_dai_sync));
750 else
751 ret = snd_soc_register_codec(&pdev->dev, &soc_codec_dev_mc13783,
752 mc13783_dai_async, ARRAY_SIZE(mc13783_dai_async));
753
754 if (ret)
755 goto err_register_codec;
756
757 return 0;
758
759err_register_codec:
760 dev_err(&pdev->dev, "register codec failed with %d\n", ret);
761
762 return ret;
763}
764
765static int mc13783_codec_remove(struct platform_device *pdev)
766{
767 snd_soc_unregister_codec(&pdev->dev);
768
769 return 0;
770}
771
772static struct platform_driver mc13783_codec_driver = {
773 .driver = {
774 .name = "mc13783-codec",
775 .owner = THIS_MODULE,
776 },
777 .probe = mc13783_codec_probe,
778 .remove = __devexit_p(mc13783_codec_remove),
779};
780
781module_platform_driver(mc13783_codec_driver);
782
783MODULE_DESCRIPTION("ASoC MC13783 driver");
784MODULE_AUTHOR("Sascha Hauer, Pengutronix <s.hauer@pengutronix.de>");
785MODULE_AUTHOR("Philippe Retornaz <philippe.retornaz@epfl.ch>");
786MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/mc13783.h b/sound/soc/codecs/mc13783.h
new file mode 100644
index 000000000000..3a6d1993a217
--- /dev/null
+++ b/sound/soc/codecs/mc13783.h
@@ -0,0 +1,28 @@
1/*
2 * Copyright 2008 Juergen Beisert, kernel@pengutronix.de
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software Foundation, Inc.
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 */
17
18#ifndef MC13783_MIXER_H
19#define MC13783_MIXER_H
20
21#define MC13783_CLK_CLIA 1
22#define MC13783_CLK_CLIB 2
23
24#define MC13783_ID_STEREO_DAC 1
25#define MC13783_ID_STEREO_CODEC 2
26#define MC13783_ID_SYNC 3
27
28#endif /* MC13783_MIXER_H */
diff --git a/sound/soc/codecs/ml26124.c b/sound/soc/codecs/ml26124.c
new file mode 100644
index 000000000000..22cb5bf59273
--- /dev/null
+++ b/sound/soc/codecs/ml26124.c
@@ -0,0 +1,681 @@
1/*
2 * Copyright (C) 2011 LAPIS Semiconductor Co., Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
16 */
17
18#include <linux/module.h>
19#include <linux/moduleparam.h>
20#include <linux/init.h>
21#include <linux/delay.h>
22#include <linux/pm.h>
23#include <linux/i2c.h>
24#include <linux/slab.h>
25#include <linux/platform_device.h>
26#include <linux/regmap.h>
27#include <sound/core.h>
28#include <sound/pcm.h>
29#include <sound/pcm_params.h>
30#include <sound/soc.h>
31#include <sound/tlv.h>
32#include "ml26124.h"
33
34#define DVOL_CTL_DVMUTE_ON BIT(4) /* Digital volume MUTE On */
35#define DVOL_CTL_DVMUTE_OFF 0 /* Digital volume MUTE Off */
36#define ML26124_SAI_NO_DELAY BIT(1)
37#define ML26124_SAI_FRAME_SYNC (BIT(5) | BIT(0)) /* For mono (Telecodec) */
38#define ML26134_CACHESIZE 212
39#define ML26124_VMID BIT(1)
40#define ML26124_RATES (SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_32000 |\
41 SNDRV_PCM_RATE_48000)
42#define ML26124_FORMATS (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE |\
43 SNDRV_PCM_FMTBIT_S32_LE)
44#define ML26124_NUM_REGISTER ML26134_CACHESIZE
45
46struct ml26124_priv {
47 u32 mclk;
48 u32 rate;
49 struct regmap *regmap;
50 int clk_in;
51 struct snd_pcm_substream *substream;
52};
53
54struct clk_coeff {
55 u32 mclk;
56 u32 rate;
57 u8 pllnl;
58 u8 pllnh;
59 u8 pllml;
60 u8 pllmh;
61 u8 plldiv;
62};
63
64/* ML26124 configuration */
65static const DECLARE_TLV_DB_SCALE(digital_tlv, -7150, 50, 0);
66
67static const DECLARE_TLV_DB_SCALE(alclvl, -2250, 150, 0);
68static const DECLARE_TLV_DB_SCALE(mingain, -1200, 600, 0);
69static const DECLARE_TLV_DB_SCALE(maxgain, -675, 600, 0);
70static const DECLARE_TLV_DB_SCALE(boost_vol, -1200, 75, 0);
71static const DECLARE_TLV_DB_SCALE(ngth, -7650, 150, 0);
72
73static const char * const ml26124_companding[] = {"16bit PCM", "u-law",
74 "A-law"};
75
76static const struct soc_enum ml26124_adc_companding_enum
77 = SOC_ENUM_SINGLE(ML26124_SAI_TRANS_CTL, 6, 3, ml26124_companding);
78
79static const struct soc_enum ml26124_dac_companding_enum
80 = SOC_ENUM_SINGLE(ML26124_SAI_RCV_CTL, 6, 3, ml26124_companding);
81
82static const struct snd_kcontrol_new ml26124_snd_controls[] = {
83 SOC_SINGLE_TLV("Capture Digital Volume", ML26124_RECORD_DIG_VOL, 0,
84 0xff, 1, digital_tlv),
85 SOC_SINGLE_TLV("Playback Digital Volume", ML26124_PLBAK_DIG_VOL, 0,
86 0xff, 1, digital_tlv),
87 SOC_SINGLE_TLV("Digital Boost Volume", ML26124_DIGI_BOOST_VOL, 0,
88 0x3f, 0, boost_vol),
89 SOC_SINGLE_TLV("EQ Band0 Volume", ML26124_EQ_GAIN_BRAND0, 0,
90 0xff, 1, digital_tlv),
91 SOC_SINGLE_TLV("EQ Band1 Volume", ML26124_EQ_GAIN_BRAND1, 0,
92 0xff, 1, digital_tlv),
93 SOC_SINGLE_TLV("EQ Band2 Volume", ML26124_EQ_GAIN_BRAND2, 0,
94 0xff, 1, digital_tlv),
95 SOC_SINGLE_TLV("EQ Band3 Volume", ML26124_EQ_GAIN_BRAND3, 0,
96 0xff, 1, digital_tlv),
97 SOC_SINGLE_TLV("EQ Band4 Volume", ML26124_EQ_GAIN_BRAND4, 0,
98 0xff, 1, digital_tlv),
99 SOC_SINGLE_TLV("ALC Target Level", ML26124_ALC_TARGET_LEV, 0,
100 0xf, 1, alclvl),
101 SOC_SINGLE_TLV("ALC Min Input Volume", ML26124_ALC_MAXMIN_GAIN, 0,
102 7, 0, mingain),
103 SOC_SINGLE_TLV("ALC Max Input Volume", ML26124_ALC_MAXMIN_GAIN, 4,
104 7, 1, maxgain),
105 SOC_SINGLE_TLV("Playback Limiter Min Input Volume",
106 ML26124_PL_MAXMIN_GAIN, 0, 7, 0, mingain),
107 SOC_SINGLE_TLV("Playback Limiter Max Input Volume",
108 ML26124_PL_MAXMIN_GAIN, 4, 7, 1, maxgain),
109 SOC_SINGLE_TLV("Playback Boost Volume", ML26124_PLYBAK_BOST_VOL, 0,
110 0x3f, 0, boost_vol),
111 SOC_SINGLE("DC High Pass Filter Switch", ML26124_FILTER_EN, 0, 1, 0),
112 SOC_SINGLE("Noise High Pass Filter Switch", ML26124_FILTER_EN, 1, 1, 0),
113 SOC_SINGLE("ZC Switch", ML26124_PW_ZCCMP_PW_MNG, 1,
114 1, 0),
115 SOC_SINGLE("EQ Band0 Switch", ML26124_FILTER_EN, 2, 1, 0),
116 SOC_SINGLE("EQ Band1 Switch", ML26124_FILTER_EN, 3, 1, 0),
117 SOC_SINGLE("EQ Band2 Switch", ML26124_FILTER_EN, 4, 1, 0),
118 SOC_SINGLE("EQ Band3 Switch", ML26124_FILTER_EN, 5, 1, 0),
119 SOC_SINGLE("EQ Band4 Switch", ML26124_FILTER_EN, 6, 1, 0),
120 SOC_SINGLE("Play Limiter", ML26124_DVOL_CTL, 0, 1, 0),
121 SOC_SINGLE("Capture Limiter", ML26124_DVOL_CTL, 1, 1, 0),
122 SOC_SINGLE("Digital Volume Fade Switch", ML26124_DVOL_CTL, 3, 1, 0),
123 SOC_SINGLE("Digital Switch", ML26124_DVOL_CTL, 4, 1, 0),
124 SOC_ENUM("DAC Companding", ml26124_dac_companding_enum),
125 SOC_ENUM("ADC Companding", ml26124_adc_companding_enum),
126};
127
128static const struct snd_kcontrol_new ml26124_output_mixer_controls[] = {
129 SOC_DAPM_SINGLE("DAC Switch", ML26124_SPK_AMP_OUT, 1, 1, 0),
130 SOC_DAPM_SINGLE("Line in loopback Switch", ML26124_SPK_AMP_OUT, 3, 1,
131 0),
132 SOC_DAPM_SINGLE("PGA Switch", ML26124_SPK_AMP_OUT, 5, 1, 0),
133};
134
135/* Input mux */
136static const char * const ml26124_input_select[] = {"Analog MIC SingleEnded in",
137 "Digital MIC in", "Analog MIC Differential in"};
138
139static const struct soc_enum ml26124_insel_enum =
140 SOC_ENUM_SINGLE(ML26124_MIC_IF_CTL, 0, 3, ml26124_input_select);
141
142static const struct snd_kcontrol_new ml26124_input_mux_controls =
143 SOC_DAPM_ENUM("Input Select", ml26124_insel_enum);
144
145static const struct snd_kcontrol_new ml26124_line_control =
146 SOC_DAPM_SINGLE("Switch", ML26124_PW_LOUT_PW_MNG, 1, 1, 0);
147
148static const struct snd_soc_dapm_widget ml26124_dapm_widgets[] = {
149 SND_SOC_DAPM_SUPPLY("MCLKEN", ML26124_CLK_EN, 0, 0, NULL, 0),
150 SND_SOC_DAPM_SUPPLY("PLLEN", ML26124_CLK_EN, 1, 0, NULL, 0),
151 SND_SOC_DAPM_SUPPLY("PLLOE", ML26124_CLK_EN, 2, 0, NULL, 0),
152 SND_SOC_DAPM_SUPPLY("MICBIAS", ML26124_PW_REF_PW_MNG, 2, 0, NULL, 0),
153 SND_SOC_DAPM_MIXER("Output Mixer", SND_SOC_NOPM, 0, 0,
154 &ml26124_output_mixer_controls[0],
155 ARRAY_SIZE(ml26124_output_mixer_controls)),
156 SND_SOC_DAPM_DAC("DAC", "Playback", ML26124_PW_DAC_PW_MNG, 1, 0),
157 SND_SOC_DAPM_ADC("ADC", "Capture", ML26124_PW_IN_PW_MNG, 1, 0),
158 SND_SOC_DAPM_PGA("PGA", ML26124_PW_IN_PW_MNG, 3, 0, NULL, 0),
159 SND_SOC_DAPM_MUX("Input Mux", SND_SOC_NOPM, 0, 0,
160 &ml26124_input_mux_controls),
161 SND_SOC_DAPM_SWITCH("Line Out Enable", SND_SOC_NOPM, 0, 0,
162 &ml26124_line_control),
163 SND_SOC_DAPM_INPUT("MDIN"),
164 SND_SOC_DAPM_INPUT("MIN"),
165 SND_SOC_DAPM_INPUT("LIN"),
166 SND_SOC_DAPM_OUTPUT("SPOUT"),
167 SND_SOC_DAPM_OUTPUT("LOUT"),
168};
169
170static const struct snd_soc_dapm_route ml26124_intercon[] = {
171 /* Supply */
172 {"DAC", NULL, "MCLKEN"},
173 {"ADC", NULL, "MCLKEN"},
174 {"DAC", NULL, "PLLEN"},
175 {"ADC", NULL, "PLLEN"},
176 {"DAC", NULL, "PLLOE"},
177 {"ADC", NULL, "PLLOE"},
178
179 /* output mixer */
180 {"Output Mixer", "DAC Switch", "DAC"},
181 {"Output Mixer", "Line in loopback Switch", "LIN"},
182
183 /* outputs */
184 {"LOUT", NULL, "Output Mixer"},
185 {"SPOUT", NULL, "Output Mixer"},
186 {"Line Out Enable", NULL, "LOUT"},
187
188 /* input */
189 {"ADC", NULL, "Input Mux"},
190 {"Input Mux", "Analog MIC SingleEnded in", "PGA"},
191 {"Input Mux", "Analog MIC Differential in", "PGA"},
192 {"PGA", NULL, "MIN"},
193};
194
195/* PLLOutputFreq(Hz) = InputMclkFreq(Hz) * PLLM / (PLLN * PLLDIV) */
196static const struct clk_coeff coeff_div[] = {
197 {12288000, 16000, 0xc, 0x0, 0x20, 0x0, 0x4},
198 {12288000, 32000, 0xc, 0x0, 0x20, 0x0, 0x4},
199 {12288000, 48000, 0xc, 0x0, 0x30, 0x0, 0x4},
200};
201
202static struct reg_default ml26124_reg[] = {
203 /* CLOCK control Register */
204 {0x00, 0x00 }, /* Sampling Rate */
205 {0x02, 0x00}, /* PLL NL */
206 {0x04, 0x00}, /* PLLNH */
207 {0x06, 0x00}, /* PLLML */
208 {0x08, 0x00}, /* MLLMH */
209 {0x0a, 0x00}, /* PLLDIV */
210 {0x0c, 0x00}, /* Clock Enable */
211 {0x0e, 0x00}, /* CLK Input/Output Control */
212
213 /* System Control Register */
214 {0x10, 0x00}, /* Software RESET */
215 {0x12, 0x00}, /* Record/Playback Run */
216 {0x14, 0x00}, /* Mic Input/Output control */
217
218 /* Power Management Register */
219 {0x20, 0x00}, /* Reference Power Management */
220 {0x22, 0x00}, /* Input Power Management */
221 {0x24, 0x00}, /* DAC Power Management */
222 {0x26, 0x00}, /* SP-AMP Power Management */
223 {0x28, 0x00}, /* LINEOUT Power Management */
224 {0x2a, 0x00}, /* VIDEO Power Management */
225 {0x2e, 0x00}, /* AC-CMP Power Management */
226
227 /* Analog reference Control Register */
228 {0x30, 0x04}, /* MICBIAS Voltage Control */
229
230 /* Input/Output Amplifier Control Register */
231 {0x32, 0x10}, /* MIC Input Volume */
232 {0x38, 0x00}, /* Mic Boost Volume */
233 {0x3a, 0x33}, /* Speaker AMP Volume */
234 {0x48, 0x00}, /* AMP Volume Control Function Enable */
235 {0x4a, 0x00}, /* Amplifier Volume Fader Control */
236
237 /* Analog Path Control Register */
238 {0x54, 0x00}, /* Speaker AMP Output Control */
239 {0x5a, 0x00}, /* Mic IF Control */
240 {0xe8, 0x01}, /* Mic Select Control */
241
242 /* Audio Interface Control Register */
243 {0x60, 0x00}, /* SAI-Trans Control */
244 {0x62, 0x00}, /* SAI-Receive Control */
245 {0x64, 0x00}, /* SAI Mode select */
246
247 /* DSP Control Register */
248 {0x66, 0x01}, /* Filter Func Enable */
249 {0x68, 0x00}, /* Volume Control Func Enable */
250 {0x6A, 0x00}, /* Mixer & Volume Control*/
251 {0x6C, 0xff}, /* Record Digital Volume */
252 {0x70, 0xff}, /* Playback Digital Volume */
253 {0x72, 0x10}, /* Digital Boost Volume */
254 {0x74, 0xe7}, /* EQ gain Band0 */
255 {0x76, 0xe7}, /* EQ gain Band1 */
256 {0x78, 0xe7}, /* EQ gain Band2 */
257 {0x7A, 0xe7}, /* EQ gain Band3 */
258 {0x7C, 0xe7}, /* EQ gain Band4 */
259 {0x7E, 0x00}, /* HPF2 CutOff*/
260 {0x80, 0x00}, /* EQ Band0 Coef0L */
261 {0x82, 0x00}, /* EQ Band0 Coef0H */
262 {0x84, 0x00}, /* EQ Band0 Coef0L */
263 {0x86, 0x00}, /* EQ Band0 Coef0H */
264 {0x88, 0x00}, /* EQ Band1 Coef0L */
265 {0x8A, 0x00}, /* EQ Band1 Coef0H */
266 {0x8C, 0x00}, /* EQ Band1 Coef0L */
267 {0x8E, 0x00}, /* EQ Band1 Coef0H */
268 {0x90, 0x00}, /* EQ Band2 Coef0L */
269 {0x92, 0x00}, /* EQ Band2 Coef0H */
270 {0x94, 0x00}, /* EQ Band2 Coef0L */
271 {0x96, 0x00}, /* EQ Band2 Coef0H */
272 {0x98, 0x00}, /* EQ Band3 Coef0L */
273 {0x9A, 0x00}, /* EQ Band3 Coef0H */
274 {0x9C, 0x00}, /* EQ Band3 Coef0L */
275 {0x9E, 0x00}, /* EQ Band3 Coef0H */
276 {0xA0, 0x00}, /* EQ Band4 Coef0L */
277 {0xA2, 0x00}, /* EQ Band4 Coef0H */
278 {0xA4, 0x00}, /* EQ Band4 Coef0L */
279 {0xA6, 0x00}, /* EQ Band4 Coef0H */
280
281 /* ALC Control Register */
282 {0xb0, 0x00}, /* ALC Mode */
283 {0xb2, 0x02}, /* ALC Attack Time */
284 {0xb4, 0x03}, /* ALC Decay Time */
285 {0xb6, 0x00}, /* ALC Hold Time */
286 {0xb8, 0x0b}, /* ALC Target Level */
287 {0xba, 0x70}, /* ALC Max/Min Gain */
288 {0xbc, 0x00}, /* Noise Gate Threshold */
289 {0xbe, 0x00}, /* ALC ZeroCross TimeOut */
290
291 /* Playback Limiter Control Register */
292 {0xc0, 0x04}, /* PL Attack Time */
293 {0xc2, 0x05}, /* PL Decay Time */
294 {0xc4, 0x0d}, /* PL Target Level */
295 {0xc6, 0x70}, /* PL Max/Min Gain */
296 {0xc8, 0x10}, /* Playback Boost Volume */
297 {0xca, 0x00}, /* PL ZeroCross TimeOut */
298
299 /* Video Amplifier Control Register */
300 {0xd0, 0x01}, /* VIDEO AMP Gain Control */
301 {0xd2, 0x01}, /* VIDEO AMP Setup 1 */
302 {0xd4, 0x01}, /* VIDEO AMP Control2 */
303};
304
305/* Get sampling rate value of sampling rate setting register (0x0) */
306static inline int get_srate(int rate)
307{
308 int srate;
309
310 switch (rate) {
311 case 16000:
312 srate = 3;
313 break;
314 case 32000:
315 srate = 6;
316 break;
317 case 48000:
318 srate = 8;
319 break;
320 default:
321 return -EINVAL;
322 }
323 return srate;
324}
325
326static inline int get_coeff(int mclk, int rate)
327{
328 int i;
329
330 for (i = 0; i < ARRAY_SIZE(coeff_div); i++) {
331 if (coeff_div[i].rate == rate && coeff_div[i].mclk == mclk)
332 return i;
333 }
334 return -EINVAL;
335}
336
337static int ml26124_hw_params(struct snd_pcm_substream *substream,
338 struct snd_pcm_hw_params *hw_params,
339 struct snd_soc_dai *dai)
340{
341 struct snd_soc_codec *codec = dai->codec;
342 struct ml26124_priv *priv = snd_soc_codec_get_drvdata(codec);
343 int i = get_coeff(priv->mclk, params_rate(hw_params));
344
345 priv->substream = substream;
346 priv->rate = params_rate(hw_params);
347
348 if (priv->clk_in) {
349 switch (priv->mclk / params_rate(hw_params)) {
350 case 256:
351 snd_soc_update_bits(codec, ML26124_CLK_CTL,
352 BIT(0) | BIT(1), 1);
353 break;
354 case 512:
355 snd_soc_update_bits(codec, ML26124_CLK_CTL,
356 BIT(0) | BIT(1), 2);
357 break;
358 case 1024:
359 snd_soc_update_bits(codec, ML26124_CLK_CTL,
360 BIT(0) | BIT(1), 3);
361 break;
362 default:
363 dev_err(codec->dev, "Unsupported MCLKI\n");
364 break;
365 }
366 } else {
367 snd_soc_update_bits(codec, ML26124_CLK_CTL,
368 BIT(0) | BIT(1), 0);
369 }
370
371 switch (params_rate(hw_params)) {
372 case 16000:
373 snd_soc_update_bits(codec, ML26124_SMPLING_RATE, 0xf,
374 get_srate(params_rate(hw_params)));
375 snd_soc_update_bits(codec, ML26124_PLLNL, 0xff,
376 coeff_div[i].pllnl);
377 snd_soc_update_bits(codec, ML26124_PLLNH, 0x1,
378 coeff_div[i].pllnh);
379 snd_soc_update_bits(codec, ML26124_PLLML, 0xff,
380 coeff_div[i].pllml);
381 snd_soc_update_bits(codec, ML26124_PLLMH, 0x3f,
382 coeff_div[i].pllmh);
383 snd_soc_update_bits(codec, ML26124_PLLDIV, 0x1f,
384 coeff_div[i].plldiv);
385 break;
386 case 32000:
387 snd_soc_update_bits(codec, ML26124_SMPLING_RATE, 0xf,
388 get_srate(params_rate(hw_params)));
389 snd_soc_update_bits(codec, ML26124_PLLNL, 0xff,
390 coeff_div[i].pllnl);
391 snd_soc_update_bits(codec, ML26124_PLLNH, 0x1,
392 coeff_div[i].pllnh);
393 snd_soc_update_bits(codec, ML26124_PLLML, 0xff,
394 coeff_div[i].pllml);
395 snd_soc_update_bits(codec, ML26124_PLLMH, 0x3f,
396 coeff_div[i].pllmh);
397 snd_soc_update_bits(codec, ML26124_PLLDIV, 0x1f,
398 coeff_div[i].plldiv);
399 break;
400 case 48000:
401 snd_soc_update_bits(codec, ML26124_SMPLING_RATE, 0xf,
402 get_srate(params_rate(hw_params)));
403 snd_soc_update_bits(codec, ML26124_PLLNL, 0xff,
404 coeff_div[i].pllnl);
405 snd_soc_update_bits(codec, ML26124_PLLNH, 0x1,
406 coeff_div[i].pllnh);
407 snd_soc_update_bits(codec, ML26124_PLLML, 0xff,
408 coeff_div[i].pllml);
409 snd_soc_update_bits(codec, ML26124_PLLMH, 0x3f,
410 coeff_div[i].pllmh);
411 snd_soc_update_bits(codec, ML26124_PLLDIV, 0x1f,
412 coeff_div[i].plldiv);
413 break;
414 default:
415 pr_err("%s:this rate is no support for ml26124\n", __func__);
416 return -EINVAL;
417 }
418
419 return 0;
420}
421
422static int ml26124_mute(struct snd_soc_dai *dai, int mute)
423{
424 struct snd_soc_codec *codec = dai->codec;
425 struct ml26124_priv *priv = snd_soc_codec_get_drvdata(codec);
426
427 switch (priv->substream->stream) {
428 case SNDRV_PCM_STREAM_CAPTURE:
429 snd_soc_update_bits(codec, ML26124_REC_PLYBAK_RUN, BIT(0), 1);
430 break;
431 case SNDRV_PCM_STREAM_PLAYBACK:
432 snd_soc_update_bits(codec, ML26124_REC_PLYBAK_RUN, BIT(1), 2);
433 break;
434 }
435
436 if (mute)
437 snd_soc_update_bits(codec, ML26124_DVOL_CTL, BIT(4),
438 DVOL_CTL_DVMUTE_ON);
439 else
440 snd_soc_update_bits(codec, ML26124_DVOL_CTL, BIT(4),
441 DVOL_CTL_DVMUTE_OFF);
442
443 return 0;
444}
445
446static int ml26124_set_dai_fmt(struct snd_soc_dai *codec_dai,
447 unsigned int fmt)
448{
449 unsigned char mode;
450 struct snd_soc_codec *codec = codec_dai->codec;
451
452 /* set master/slave audio interface */
453 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
454 case SND_SOC_DAIFMT_CBM_CFM:
455 mode = 1;
456 break;
457 case SND_SOC_DAIFMT_CBS_CFS:
458 mode = 0;
459 break;
460 default:
461 return -EINVAL;
462 }
463 snd_soc_update_bits(codec, ML26124_SAI_MODE_SEL, BIT(0), mode);
464
465 /* interface format */
466 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
467 case SND_SOC_DAIFMT_I2S:
468 break;
469 default:
470 return -EINVAL;
471 }
472
473 /* clock inversion */
474 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
475 case SND_SOC_DAIFMT_NB_NF:
476 break;
477 default:
478 return -EINVAL;
479 }
480
481 return 0;
482}
483
484static int ml26124_set_dai_sysclk(struct snd_soc_dai *codec_dai,
485 int clk_id, unsigned int freq, int dir)
486{
487 struct snd_soc_codec *codec = codec_dai->codec;
488 struct ml26124_priv *priv = snd_soc_codec_get_drvdata(codec);
489
490 switch (clk_id) {
491 case ML26124_USE_PLLOUT:
492 priv->clk_in = ML26124_USE_PLLOUT;
493 break;
494 case ML26124_USE_MCLKI:
495 priv->clk_in = ML26124_USE_MCLKI;
496 break;
497 default:
498 return -EINVAL;
499 }
500
501 priv->mclk = freq;
502
503 return 0;
504}
505
506static int ml26124_set_bias_level(struct snd_soc_codec *codec,
507 enum snd_soc_bias_level level)
508{
509 struct ml26124_priv *priv = snd_soc_codec_get_drvdata(codec);
510
511 switch (level) {
512 case SND_SOC_BIAS_ON:
513 snd_soc_update_bits(codec, ML26124_PW_SPAMP_PW_MNG,
514 ML26124_R26_MASK, ML26124_BLT_PREAMP_ON);
515 msleep(100);
516 snd_soc_update_bits(codec, ML26124_PW_SPAMP_PW_MNG,
517 ML26124_R26_MASK,
518 ML26124_MICBEN_ON | ML26124_BLT_ALL_ON);
519 break;
520 case SND_SOC_BIAS_PREPARE:
521 break;
522 case SND_SOC_BIAS_STANDBY:
523 /* VMID ON */
524 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
525 snd_soc_update_bits(codec, ML26124_PW_REF_PW_MNG,
526 ML26124_VMID, ML26124_VMID);
527 msleep(500);
528 regcache_sync(priv->regmap);
529 }
530 break;
531 case SND_SOC_BIAS_OFF:
532 /* VMID OFF */
533 snd_soc_update_bits(codec, ML26124_PW_REF_PW_MNG,
534 ML26124_VMID, 0);
535 break;
536 }
537 codec->dapm.bias_level = level;
538 return 0;
539}
540
541static const struct snd_soc_dai_ops ml26124_dai_ops = {
542 .hw_params = ml26124_hw_params,
543 .digital_mute = ml26124_mute,
544 .set_fmt = ml26124_set_dai_fmt,
545 .set_sysclk = ml26124_set_dai_sysclk,
546};
547
548static struct snd_soc_dai_driver ml26124_dai = {
549 .name = "ml26124-hifi",
550 .playback = {
551 .stream_name = "Playback",
552 .channels_min = 1,
553 .channels_max = 2,
554 .rates = ML26124_RATES,
555 .formats = ML26124_FORMATS,},
556 .capture = {
557 .stream_name = "Capture",
558 .channels_min = 1,
559 .channels_max = 2,
560 .rates = ML26124_RATES,
561 .formats = ML26124_FORMATS,},
562 .ops = &ml26124_dai_ops,
563 .symmetric_rates = 1,
564};
565
566#ifdef CONFIG_PM
567static int ml26124_suspend(struct snd_soc_codec *codec)
568{
569 ml26124_set_bias_level(codec, SND_SOC_BIAS_OFF);
570
571 return 0;
572}
573
574static int ml26124_resume(struct snd_soc_codec *codec)
575{
576 ml26124_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
577
578 return 0;
579}
580#else
581#define ml26124_suspend NULL
582#define ml26124_resume NULL
583#endif
584
585static int ml26124_probe(struct snd_soc_codec *codec)
586{
587 int ret;
588 struct ml26124_priv *priv = snd_soc_codec_get_drvdata(codec);
589 codec->control_data = priv->regmap;
590
591 ret = snd_soc_codec_set_cache_io(codec, 7, 9, SND_SOC_REGMAP);
592 if (ret < 0) {
593 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
594 return ret;
595 }
596
597 /* Software Reset */
598 snd_soc_update_bits(codec, ML26124_SW_RST, 0x01, 1);
599 snd_soc_update_bits(codec, ML26124_SW_RST, 0x01, 0);
600
601 ml26124_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
602
603 return 0;
604}
605
606static struct snd_soc_codec_driver soc_codec_dev_ml26124 = {
607 .probe = ml26124_probe,
608 .suspend = ml26124_suspend,
609 .resume = ml26124_resume,
610 .set_bias_level = ml26124_set_bias_level,
611 .dapm_widgets = ml26124_dapm_widgets,
612 .num_dapm_widgets = ARRAY_SIZE(ml26124_dapm_widgets),
613 .dapm_routes = ml26124_intercon,
614 .num_dapm_routes = ARRAY_SIZE(ml26124_intercon),
615 .controls = ml26124_snd_controls,
616 .num_controls = ARRAY_SIZE(ml26124_snd_controls),
617};
618
619static const struct regmap_config ml26124_i2c_regmap = {
620 .val_bits = 8,
621 .reg_bits = 8,
622 .max_register = ML26124_NUM_REGISTER,
623 .reg_defaults = ml26124_reg,
624 .num_reg_defaults = ARRAY_SIZE(ml26124_reg),
625 .cache_type = REGCACHE_RBTREE,
626 .write_flag_mask = 0x01,
627};
628
629static __devinit int ml26124_i2c_probe(struct i2c_client *i2c,
630 const struct i2c_device_id *id)
631{
632 struct ml26124_priv *priv;
633 int ret;
634
635 priv = devm_kzalloc(&i2c->dev, sizeof(*priv), GFP_KERNEL);
636 if (!priv)
637 return -ENOMEM;
638
639 i2c_set_clientdata(i2c, priv);
640
641 priv->regmap = regmap_init_i2c(i2c, &ml26124_i2c_regmap);
642 if (IS_ERR(priv->regmap)) {
643 ret = PTR_ERR(priv->regmap);
644 dev_err(&i2c->dev, "regmap_init_i2c() failed: %d\n", ret);
645 return ret;
646 }
647
648 return snd_soc_register_codec(&i2c->dev,
649 &soc_codec_dev_ml26124, &ml26124_dai, 1);
650}
651
652static __devexit int ml26124_i2c_remove(struct i2c_client *client)
653{
654 struct ml26124_priv *priv = i2c_get_clientdata(client);
655
656 snd_soc_unregister_codec(&client->dev);
657 regmap_exit(priv->regmap);
658 return 0;
659}
660
661static const struct i2c_device_id ml26124_i2c_id[] = {
662 { "ml26124", 0 },
663 { }
664};
665MODULE_DEVICE_TABLE(i2c, ml26124_i2c_id);
666
667static struct i2c_driver ml26124_i2c_driver = {
668 .driver = {
669 .name = "ml26124",
670 .owner = THIS_MODULE,
671 },
672 .probe = ml26124_i2c_probe,
673 .remove = __devexit_p(ml26124_i2c_remove),
674 .id_table = ml26124_i2c_id,
675};
676
677module_i2c_driver(ml26124_i2c_driver);
678
679MODULE_AUTHOR("Tomoya MORINAGA <tomoya.rohm@gmail.com>");
680MODULE_DESCRIPTION("LAPIS Semiconductor ML26124 ALSA SoC codec driver");
681MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/ml26124.h b/sound/soc/codecs/ml26124.h
new file mode 100644
index 000000000000..5ea0cbb8c46c
--- /dev/null
+++ b/sound/soc/codecs/ml26124.h
@@ -0,0 +1,184 @@
1/*
2 * Copyright (C) 2011 LAPIS Semiconductor Co., Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
16 */
17
18#ifndef ML26124_H
19#define ML26124_H
20
21/* Clock Control Register */
22#define ML26124_SMPLING_RATE 0x00
23#define ML26124_PLLNL 0x02
24#define ML26124_PLLNH 0x04
25#define ML26124_PLLML 0x06
26#define ML26124_PLLMH 0x08
27#define ML26124_PLLDIV 0x0a
28#define ML26124_CLK_EN 0x0c
29#define ML26124_CLK_CTL 0x0e
30
31/* System Control Register */
32#define ML26124_SW_RST 0x10
33#define ML26124_REC_PLYBAK_RUN 0x12
34#define ML26124_MIC_TIM 0x14
35
36/* Power Mnagement Register */
37#define ML26124_PW_REF_PW_MNG 0x20
38#define ML26124_PW_IN_PW_MNG 0x22
39#define ML26124_PW_DAC_PW_MNG 0x24
40#define ML26124_PW_SPAMP_PW_MNG 0x26
41#define ML26124_PW_LOUT_PW_MNG 0x28
42#define ML26124_PW_VOUT_PW_MNG 0x2a
43#define ML26124_PW_ZCCMP_PW_MNG 0x2e
44
45/* Analog Reference Control Register */
46#define ML26124_PW_MICBIAS_VOL 0x30
47
48/* Input/Output Amplifier Control Register */
49#define ML26124_PW_MIC_IN_VOL 0x32
50#define ML26124_PW_MIC_BOST_VOL 0x38
51#define ML26124_PW_SPK_AMP_VOL 0x3a
52#define ML26124_PW_AMP_VOL_FUNC 0x48
53#define ML26124_PW_AMP_VOL_FADE 0x4a
54
55/* Analog Path Control Register */
56#define ML26124_SPK_AMP_OUT 0x54
57#define ML26124_MIC_IF_CTL 0x5a
58#define ML26124_MIC_SELECT 0xe8
59
60/* Audio Interface Control Register */
61#define ML26124_SAI_TRANS_CTL 0x60
62#define ML26124_SAI_RCV_CTL 0x62
63#define ML26124_SAI_MODE_SEL 0x64
64
65/* DSP Control Register */
66#define ML26124_FILTER_EN 0x66
67#define ML26124_DVOL_CTL 0x68
68#define ML26124_MIXER_VOL_CTL 0x6a
69#define ML26124_RECORD_DIG_VOL 0x6c
70#define ML26124_PLBAK_DIG_VOL 0x70
71#define ML26124_DIGI_BOOST_VOL 0x72
72#define ML26124_EQ_GAIN_BRAND0 0x74
73#define ML26124_EQ_GAIN_BRAND1 0x76
74#define ML26124_EQ_GAIN_BRAND2 0x78
75#define ML26124_EQ_GAIN_BRAND3 0x7a
76#define ML26124_EQ_GAIN_BRAND4 0x7c
77#define ML26124_HPF2_CUTOFF 0x7e
78#define ML26124_EQBRAND0_F0L 0x80
79#define ML26124_EQBRAND0_F0H 0x82
80#define ML26124_EQBRAND0_F1L 0x84
81#define ML26124_EQBRAND0_F1H 0x86
82#define ML26124_EQBRAND1_F0L 0x88
83#define ML26124_EQBRAND1_F0H 0x8a
84#define ML26124_EQBRAND1_F1L 0x8c
85#define ML26124_EQBRAND1_F1H 0x8e
86#define ML26124_EQBRAND2_F0L 0x90
87#define ML26124_EQBRAND2_F0H 0x92
88#define ML26124_EQBRAND2_F1L 0x94
89#define ML26124_EQBRAND2_F1H 0x96
90#define ML26124_EQBRAND3_F0L 0x98
91#define ML26124_EQBRAND3_F0H 0x9a
92#define ML26124_EQBRAND3_F1L 0x9c
93#define ML26124_EQBRAND3_F1H 0x9e
94#define ML26124_EQBRAND4_F0L 0xa0
95#define ML26124_EQBRAND4_F0H 0xa2
96#define ML26124_EQBRAND4_F1L 0xa4
97#define ML26124_EQBRAND4_F1H 0xa6
98
99/* ALC Control Register */
100#define ML26124_ALC_MODE 0xb0
101#define ML26124_ALC_ATTACK_TIM 0xb2
102#define ML26124_ALC_DECAY_TIM 0xb4
103#define ML26124_ALC_HOLD_TIM 0xb6
104#define ML26124_ALC_TARGET_LEV 0xb8
105#define ML26124_ALC_MAXMIN_GAIN 0xba
106#define ML26124_NOIS_GATE_THRSH 0xbc
107#define ML26124_ALC_ZERO_TIMOUT 0xbe
108
109/* Playback Limiter Control Register */
110#define ML26124_PL_ATTACKTIME 0xc0
111#define ML26124_PL_DECAYTIME 0xc2
112#define ML26124_PL_TARGETTIME 0xc4
113#define ML26124_PL_MAXMIN_GAIN 0xc6
114#define ML26124_PLYBAK_BOST_VOL 0xc8
115#define ML26124_PL_0CROSS_TIMOUT 0xca
116
117/* Video Amplifer Control Register */
118#define ML26124_VIDEO_AMP_GAIN_CTL 0xd0
119#define ML26124_VIDEO_AMP_SETUP1 0xd2
120#define ML26124_VIDEO_AMP_CTL2 0xd4
121
122/* Clock select for machine driver */
123#define ML26124_USE_PLL 0
124#define ML26124_USE_MCLKI_256FS 1
125#define ML26124_USE_MCLKI_512FS 2
126#define ML26124_USE_MCLKI_1024FS 3
127
128/* Register Mask */
129#define ML26124_R0_MASK 0xf
130#define ML26124_R2_MASK 0xff
131#define ML26124_R4_MASK 0x1
132#define ML26124_R6_MASK 0xf
133#define ML26124_R8_MASK 0x3f
134#define ML26124_Ra_MASK 0x1f
135#define ML26124_Rc_MASK 0x1f
136#define ML26124_Re_MASK 0x7
137#define ML26124_R10_MASK 0x1
138#define ML26124_R12_MASK 0x17
139#define ML26124_R14_MASK 0x3f
140#define ML26124_R20_MASK 0x47
141#define ML26124_R22_MASK 0xa
142#define ML26124_R24_MASK 0x2
143#define ML26124_R26_MASK 0x1f
144#define ML26124_R28_MASK 0x2
145#define ML26124_R2a_MASK 0x2
146#define ML26124_R2e_MASK 0x2
147#define ML26124_R30_MASK 0x7
148#define ML26124_R32_MASK 0x3f
149#define ML26124_R38_MASK 0x38
150#define ML26124_R3a_MASK 0x3f
151#define ML26124_R48_MASK 0x3
152#define ML26124_R4a_MASK 0x7
153#define ML26124_R54_MASK 0x2a
154#define ML26124_R5a_MASK 0x3
155#define ML26124_Re8_MASK 0x3
156#define ML26124_R60_MASK 0xff
157#define ML26124_R62_MASK 0xff
158#define ML26124_R64_MASK 0x1
159#define ML26124_R66_MASK 0xff
160#define ML26124_R68_MASK 0x3b
161#define ML26124_R6a_MASK 0xf3
162#define ML26124_R6c_MASK 0xff
163#define ML26124_R70_MASK 0xff
164
165#define ML26124_MCLKEN BIT(0)
166#define ML26124_PLLEN BIT(1)
167#define ML26124_PLLOE BIT(2)
168#define ML26124_MCLKOE BIT(3)
169
170#define ML26124_BLT_ALL_ON 0x1f
171#define ML26124_BLT_PREAMP_ON 0x13
172
173#define ML26124_MICBEN_ON BIT(2)
174
175enum ml26124_regs {
176 ML26124_MCLK = 0,
177};
178
179enum ml26124_clk_in {
180 ML26124_USE_PLLOUT = 0,
181 ML26124_USE_MCLKI,
182};
183
184#endif
diff --git a/sound/soc/codecs/rt5631.c b/sound/soc/codecs/rt5631.c
index 20c324c7c349..960d0e93cce9 100644
--- a/sound/soc/codecs/rt5631.c
+++ b/sound/soc/codecs/rt5631.c
@@ -18,7 +18,7 @@
18#include <linux/delay.h> 18#include <linux/delay.h>
19#include <linux/pm.h> 19#include <linux/pm.h>
20#include <linux/i2c.h> 20#include <linux/i2c.h>
21#include <linux/spi/spi.h> 21#include <linux/regmap.h>
22#include <sound/core.h> 22#include <sound/core.h>
23#include <sound/pcm.h> 23#include <sound/pcm.h>
24#include <sound/pcm_params.h> 24#include <sound/pcm_params.h>
@@ -30,6 +30,7 @@
30#include "rt5631.h" 30#include "rt5631.h"
31 31
32struct rt5631_priv { 32struct rt5631_priv {
33 struct regmap *regmap;
33 int codec_version; 34 int codec_version;
34 int master; 35 int master;
35 int sysclk; 36 int sysclk;
@@ -38,33 +39,33 @@ struct rt5631_priv {
38 int dmic_used_flag; 39 int dmic_used_flag;
39}; 40};
40 41
41static const u16 rt5631_reg[RT5631_VENDOR_ID2 + 1] = { 42static const struct reg_default rt5631_reg[] = {
42 [RT5631_SPK_OUT_VOL] = 0x8888, 43 { RT5631_SPK_OUT_VOL, 0x8888 },
43 [RT5631_HP_OUT_VOL] = 0x8080, 44 { RT5631_HP_OUT_VOL, 0x8080 },
44 [RT5631_MONO_AXO_1_2_VOL] = 0xa080, 45 { RT5631_MONO_AXO_1_2_VOL, 0xa080 },
45 [RT5631_AUX_IN_VOL] = 0x0808, 46 { RT5631_AUX_IN_VOL, 0x0808 },
46 [RT5631_ADC_REC_MIXER] = 0xf0f0, 47 { RT5631_ADC_REC_MIXER, 0xf0f0 },
47 [RT5631_VDAC_DIG_VOL] = 0x0010, 48 { RT5631_VDAC_DIG_VOL, 0x0010 },
48 [RT5631_OUTMIXER_L_CTRL] = 0xffc0, 49 { RT5631_OUTMIXER_L_CTRL, 0xffc0 },
49 [RT5631_OUTMIXER_R_CTRL] = 0xffc0, 50 { RT5631_OUTMIXER_R_CTRL, 0xffc0 },
50 [RT5631_AXO1MIXER_CTRL] = 0x88c0, 51 { RT5631_AXO1MIXER_CTRL, 0x88c0 },
51 [RT5631_AXO2MIXER_CTRL] = 0x88c0, 52 { RT5631_AXO2MIXER_CTRL, 0x88c0 },
52 [RT5631_DIG_MIC_CTRL] = 0x3000, 53 { RT5631_DIG_MIC_CTRL, 0x3000 },
53 [RT5631_MONO_INPUT_VOL] = 0x8808, 54 { RT5631_MONO_INPUT_VOL, 0x8808 },
54 [RT5631_SPK_MIXER_CTRL] = 0xf8f8, 55 { RT5631_SPK_MIXER_CTRL, 0xf8f8 },
55 [RT5631_SPK_MONO_OUT_CTRL] = 0xfc00, 56 { RT5631_SPK_MONO_OUT_CTRL, 0xfc00 },
56 [RT5631_SPK_MONO_HP_OUT_CTRL] = 0x4440, 57 { RT5631_SPK_MONO_HP_OUT_CTRL, 0x4440 },
57 [RT5631_SDP_CTRL] = 0x8000, 58 { RT5631_SDP_CTRL, 0x8000 },
58 [RT5631_MONO_SDP_CTRL] = 0x8000, 59 { RT5631_MONO_SDP_CTRL, 0x8000 },
59 [RT5631_STEREO_AD_DA_CLK_CTRL] = 0x2010, 60 { RT5631_STEREO_AD_DA_CLK_CTRL, 0x2010 },
60 [RT5631_GEN_PUR_CTRL_REG] = 0x0e00, 61 { RT5631_GEN_PUR_CTRL_REG, 0x0e00 },
61 [RT5631_INT_ST_IRQ_CTRL_2] = 0x071a, 62 { RT5631_INT_ST_IRQ_CTRL_2, 0x071a },
62 [RT5631_MISC_CTRL] = 0x2040, 63 { RT5631_MISC_CTRL, 0x2040 },
63 [RT5631_DEPOP_FUN_CTRL_2] = 0x8000, 64 { RT5631_DEPOP_FUN_CTRL_2, 0x8000 },
64 [RT5631_SOFT_VOL_CTRL] = 0x07e0, 65 { RT5631_SOFT_VOL_CTRL, 0x07e0 },
65 [RT5631_ALC_CTRL_1] = 0x0206, 66 { RT5631_ALC_CTRL_1, 0x0206 },
66 [RT5631_ALC_CTRL_3] = 0x2000, 67 { RT5631_ALC_CTRL_3, 0x2000 },
67 [RT5631_PSEUDO_SPATL_CTRL] = 0x0553, 68 { RT5631_PSEUDO_SPATL_CTRL, 0x0553 },
68}; 69};
69 70
70/** 71/**
@@ -96,8 +97,7 @@ static int rt5631_reset(struct snd_soc_codec *codec)
96 return snd_soc_write(codec, RT5631_RESET, 0); 97 return snd_soc_write(codec, RT5631_RESET, 0);
97} 98}
98 99
99static int rt5631_volatile_register(struct snd_soc_codec *codec, 100static bool rt5631_volatile_register(struct device *dev, unsigned int reg)
100 unsigned int reg)
101{ 101{
102 switch (reg) { 102 switch (reg) {
103 case RT5631_RESET: 103 case RT5631_RESET:
@@ -111,8 +111,7 @@ static int rt5631_volatile_register(struct snd_soc_codec *codec,
111 } 111 }
112} 112}
113 113
114static int rt5631_readable_register(struct snd_soc_codec *codec, 114static bool rt5631_readable_register(struct device *dev, unsigned int reg)
115 unsigned int reg)
116{ 115{
117 switch (reg) { 116 switch (reg) {
118 case RT5631_RESET: 117 case RT5631_RESET:
@@ -1361,8 +1360,7 @@ static int get_coeff(int mclk, int rate, int timesofbclk)
1361static int rt5631_hifi_pcm_params(struct snd_pcm_substream *substream, 1360static int rt5631_hifi_pcm_params(struct snd_pcm_substream *substream,
1362 struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) 1361 struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
1363{ 1362{
1364 struct snd_soc_pcm_runtime *rtd = substream->private_data; 1363 struct snd_soc_codec *codec = dai->codec;
1365 struct snd_soc_codec *codec = rtd->codec;
1366 struct rt5631_priv *rt5631 = snd_soc_codec_get_drvdata(codec); 1364 struct rt5631_priv *rt5631 = snd_soc_codec_get_drvdata(codec);
1367 int timesofbclk = 32, coeff; 1365 int timesofbclk = 32, coeff;
1368 unsigned int iface = 0; 1366 unsigned int iface = 0;
@@ -1544,6 +1542,8 @@ static int rt5631_codec_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id,
1544static int rt5631_set_bias_level(struct snd_soc_codec *codec, 1542static int rt5631_set_bias_level(struct snd_soc_codec *codec,
1545 enum snd_soc_bias_level level) 1543 enum snd_soc_bias_level level)
1546{ 1544{
1545 struct rt5631_priv *rt5631 = snd_soc_codec_get_drvdata(codec);
1546
1547 switch (level) { 1547 switch (level) {
1548 case SND_SOC_BIAS_ON: 1548 case SND_SOC_BIAS_ON:
1549 case SND_SOC_BIAS_PREPARE: 1549 case SND_SOC_BIAS_PREPARE:
@@ -1561,8 +1561,8 @@ static int rt5631_set_bias_level(struct snd_soc_codec *codec,
1561 snd_soc_update_bits(codec, RT5631_PWR_MANAG_ADD3, 1561 snd_soc_update_bits(codec, RT5631_PWR_MANAG_ADD3,
1562 RT5631_PWR_FAST_VREF_CTRL, 1562 RT5631_PWR_FAST_VREF_CTRL,
1563 RT5631_PWR_FAST_VREF_CTRL); 1563 RT5631_PWR_FAST_VREF_CTRL);
1564 codec->cache_only = false; 1564 regcache_cache_only(rt5631->regmap, false);
1565 snd_soc_cache_sync(codec); 1565 regcache_sync(rt5631->regmap);
1566 } 1566 }
1567 break; 1567 break;
1568 1568
@@ -1587,7 +1587,9 @@ static int rt5631_probe(struct snd_soc_codec *codec)
1587 unsigned int val; 1587 unsigned int val;
1588 int ret; 1588 int ret;
1589 1589
1590 ret = snd_soc_codec_set_cache_io(codec, 8, 16, SND_SOC_I2C); 1590 codec->control_data = rt5631->regmap;
1591
1592 ret = snd_soc_codec_set_cache_io(codec, 8, 16, SND_SOC_REGMAP);
1591 if (ret != 0) { 1593 if (ret != 0) {
1592 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); 1594 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
1593 return ret; 1595 return ret;
@@ -1698,12 +1700,6 @@ static struct snd_soc_codec_driver soc_codec_dev_rt5631 = {
1698 .suspend = rt5631_suspend, 1700 .suspend = rt5631_suspend,
1699 .resume = rt5631_resume, 1701 .resume = rt5631_resume,
1700 .set_bias_level = rt5631_set_bias_level, 1702 .set_bias_level = rt5631_set_bias_level,
1701 .reg_cache_size = RT5631_VENDOR_ID2 + 1,
1702 .reg_word_size = sizeof(u16),
1703 .reg_cache_default = rt5631_reg,
1704 .volatile_register = rt5631_volatile_register,
1705 .readable_register = rt5631_readable_register,
1706 .reg_cache_step = 1,
1707 .controls = rt5631_snd_controls, 1703 .controls = rt5631_snd_controls,
1708 .num_controls = ARRAY_SIZE(rt5631_snd_controls), 1704 .num_controls = ARRAY_SIZE(rt5631_snd_controls),
1709 .dapm_widgets = rt5631_dapm_widgets, 1705 .dapm_widgets = rt5631_dapm_widgets,
@@ -1718,6 +1714,18 @@ static const struct i2c_device_id rt5631_i2c_id[] = {
1718}; 1714};
1719MODULE_DEVICE_TABLE(i2c, rt5631_i2c_id); 1715MODULE_DEVICE_TABLE(i2c, rt5631_i2c_id);
1720 1716
1717static const struct regmap_config rt5631_regmap_config = {
1718 .reg_bits = 8,
1719 .val_bits = 16,
1720
1721 .readable_reg = rt5631_readable_register,
1722 .volatile_reg = rt5631_volatile_register,
1723 .max_register = RT5631_VENDOR_ID2,
1724 .reg_defaults = rt5631_reg,
1725 .num_reg_defaults = ARRAY_SIZE(rt5631_reg),
1726 .cache_type = REGCACHE_RBTREE,
1727};
1728
1721static int rt5631_i2c_probe(struct i2c_client *i2c, 1729static int rt5631_i2c_probe(struct i2c_client *i2c,
1722 const struct i2c_device_id *id) 1730 const struct i2c_device_id *id)
1723{ 1731{
@@ -1731,6 +1739,10 @@ static int rt5631_i2c_probe(struct i2c_client *i2c,
1731 1739
1732 i2c_set_clientdata(i2c, rt5631); 1740 i2c_set_clientdata(i2c, rt5631);
1733 1741
1742 rt5631->regmap = devm_regmap_init_i2c(i2c, &rt5631_regmap_config);
1743 if (IS_ERR(rt5631->regmap))
1744 return PTR_ERR(rt5631->regmap);
1745
1734 ret = snd_soc_register_codec(&i2c->dev, &soc_codec_dev_rt5631, 1746 ret = snd_soc_register_codec(&i2c->dev, &soc_codec_dev_rt5631,
1735 rt5631_dai, ARRAY_SIZE(rt5631_dai)); 1747 rt5631_dai, ARRAY_SIZE(rt5631_dai));
1736 return ret; 1748 return ret;
@@ -1752,17 +1764,7 @@ static struct i2c_driver rt5631_i2c_driver = {
1752 .id_table = rt5631_i2c_id, 1764 .id_table = rt5631_i2c_id,
1753}; 1765};
1754 1766
1755static int __init rt5631_modinit(void) 1767module_i2c_driver(rt5631_i2c_driver);
1756{
1757 return i2c_add_driver(&rt5631_i2c_driver);
1758}
1759module_init(rt5631_modinit);
1760
1761static void __exit rt5631_modexit(void)
1762{
1763 i2c_del_driver(&rt5631_i2c_driver);
1764}
1765module_exit(rt5631_modexit);
1766 1768
1767MODULE_DESCRIPTION("ASoC RT5631 driver"); 1769MODULE_DESCRIPTION("ASoC RT5631 driver");
1768MODULE_AUTHOR("flove <flove@realtek.com>"); 1770MODULE_AUTHOR("flove <flove@realtek.com>");
diff --git a/sound/soc/codecs/sgtl5000.c b/sound/soc/codecs/sgtl5000.c
index 8e92fb88ed09..8005fe6db66f 100644
--- a/sound/soc/codecs/sgtl5000.c
+++ b/sound/soc/codecs/sgtl5000.c
@@ -84,8 +84,8 @@ static struct regulator_consumer_supply ldo_consumer[] = {
84 84
85static struct regulator_init_data ldo_init_data = { 85static struct regulator_init_data ldo_init_data = {
86 .constraints = { 86 .constraints = {
87 .min_uV = 850000, 87 .min_uV = 1200000,
88 .max_uV = 1600000, 88 .max_uV = 1200000,
89 .valid_modes_mask = REGULATOR_MODE_NORMAL, 89 .valid_modes_mask = REGULATOR_MODE_NORMAL,
90 .valid_ops_mask = REGULATOR_CHANGE_STATUS, 90 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
91 }, 91 },
@@ -197,9 +197,9 @@ static const struct snd_soc_dapm_widget sgtl5000_dapm_widgets[] = {
197 SND_SOC_DAPM_OUTPUT("HP_OUT"), 197 SND_SOC_DAPM_OUTPUT("HP_OUT"),
198 SND_SOC_DAPM_OUTPUT("LINE_OUT"), 198 SND_SOC_DAPM_OUTPUT("LINE_OUT"),
199 199
200 SND_SOC_DAPM_MICBIAS_E("Mic Bias", SGTL5000_CHIP_MIC_CTRL, 8, 0, 200 SND_SOC_DAPM_SUPPLY("Mic Bias", SGTL5000_CHIP_MIC_CTRL, 8, 0,
201 mic_bias_event, 201 mic_bias_event,
202 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), 202 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
203 203
204 SND_SOC_DAPM_PGA("HP", SGTL5000_CHIP_ANA_POWER, 4, 0, NULL, 0), 204 SND_SOC_DAPM_PGA("HP", SGTL5000_CHIP_ANA_POWER, 4, 0, NULL, 0),
205 SND_SOC_DAPM_PGA("LO", SGTL5000_CHIP_ANA_POWER, 0, 0, NULL, 0), 205 SND_SOC_DAPM_PGA("LO", SGTL5000_CHIP_ANA_POWER, 0, 0, NULL, 0),
@@ -665,8 +665,7 @@ static int sgtl5000_pcm_hw_params(struct snd_pcm_substream *substream,
665 struct snd_pcm_hw_params *params, 665 struct snd_pcm_hw_params *params,
666 struct snd_soc_dai *dai) 666 struct snd_soc_dai *dai)
667{ 667{
668 struct snd_soc_pcm_runtime *rtd = substream->private_data; 668 struct snd_soc_codec *codec = dai->codec;
669 struct snd_soc_codec *codec = rtd->codec;
670 struct sgtl5000_priv *sgtl5000 = snd_soc_codec_get_drvdata(codec); 669 struct sgtl5000_priv *sgtl5000 = snd_soc_codec_get_drvdata(codec);
671 int channels = params_channels(params); 670 int channels = params_channels(params);
672 int i2s_ctl = 0; 671 int i2s_ctl = 0;
@@ -1451,17 +1450,7 @@ static struct i2c_driver sgtl5000_i2c_driver = {
1451 .id_table = sgtl5000_id, 1450 .id_table = sgtl5000_id,
1452}; 1451};
1453 1452
1454static int __init sgtl5000_modinit(void) 1453module_i2c_driver(sgtl5000_i2c_driver);
1455{
1456 return i2c_add_driver(&sgtl5000_i2c_driver);
1457}
1458module_init(sgtl5000_modinit);
1459
1460static void __exit sgtl5000_exit(void)
1461{
1462 i2c_del_driver(&sgtl5000_i2c_driver);
1463}
1464module_exit(sgtl5000_exit);
1465 1454
1466MODULE_DESCRIPTION("Freescale SGTL5000 ALSA SoC Codec Driver"); 1455MODULE_DESCRIPTION("Freescale SGTL5000 ALSA SoC Codec Driver");
1467MODULE_AUTHOR("Zeng Zhaoming <zengzm.kernel@gmail.com>"); 1456MODULE_AUTHOR("Zeng Zhaoming <zengzm.kernel@gmail.com>");
diff --git a/sound/soc/codecs/ssm2602.c b/sound/soc/codecs/ssm2602.c
index de2b20544ceb..079066fef425 100644
--- a/sound/soc/codecs/ssm2602.c
+++ b/sound/soc/codecs/ssm2602.c
@@ -33,6 +33,7 @@
33#include <linux/pm.h> 33#include <linux/pm.h>
34#include <linux/i2c.h> 34#include <linux/i2c.h>
35#include <linux/spi/spi.h> 35#include <linux/spi/spi.h>
36#include <linux/regmap.h>
36#include <linux/slab.h> 37#include <linux/slab.h>
37#include <sound/core.h> 38#include <sound/core.h>
38#include <sound/pcm.h> 39#include <sound/pcm.h>
@@ -43,8 +44,6 @@
43 44
44#include "ssm2602.h" 45#include "ssm2602.h"
45 46
46#define SSM2602_VERSION "0.1"
47
48enum ssm2602_type { 47enum ssm2602_type {
49 SSM2602, 48 SSM2602,
50 SSM2604, 49 SSM2604,
@@ -53,10 +52,12 @@ enum ssm2602_type {
53/* codec private data */ 52/* codec private data */
54struct ssm2602_priv { 53struct ssm2602_priv {
55 unsigned int sysclk; 54 unsigned int sysclk;
56 enum snd_soc_control_type control_type; 55 struct snd_pcm_hw_constraint_list *sysclk_constraints;
57 struct snd_pcm_substream *master_substream; 56 struct snd_pcm_substream *master_substream;
58 struct snd_pcm_substream *slave_substream; 57 struct snd_pcm_substream *slave_substream;
59 58
59 struct regmap *regmap;
60
60 enum ssm2602_type type; 61 enum ssm2602_type type;
61 unsigned int clk_out_pwr; 62 unsigned int clk_out_pwr;
62}; 63};
@@ -73,7 +74,6 @@ static const u16 ssm2602_reg[SSM2602_CACHEREGNUM] = {
73 0x0000, 0x0000 74 0x0000, 0x0000
74}; 75};
75 76
76#define ssm2602_reset(c) snd_soc_write(c, SSM2602_RESET, 0)
77 77
78/*Appending several "None"s just for OSS mixer use*/ 78/*Appending several "None"s just for OSS mixer use*/
79static const char *ssm2602_input_select[] = { 79static const char *ssm2602_input_select[] = {
@@ -195,6 +195,24 @@ static const struct snd_soc_dapm_route ssm2604_routes[] = {
195 {"ADC", NULL, "Line Input"}, 195 {"ADC", NULL, "Line Input"},
196}; 196};
197 197
198static const unsigned int ssm2602_rates_12288000[] = {
199 8000, 32000, 48000, 96000,
200};
201
202static struct snd_pcm_hw_constraint_list ssm2602_constraints_12288000 = {
203 .list = ssm2602_rates_12288000,
204 .count = ARRAY_SIZE(ssm2602_rates_12288000),
205};
206
207static const unsigned int ssm2602_rates_11289600[] = {
208 8000, 44100, 88200,
209};
210
211static struct snd_pcm_hw_constraint_list ssm2602_constraints_11289600 = {
212 .list = ssm2602_rates_11289600,
213 .count = ARRAY_SIZE(ssm2602_rates_11289600),
214};
215
198struct ssm2602_coeff { 216struct ssm2602_coeff {
199 u32 mclk; 217 u32 mclk;
200 u32 rate; 218 u32 rate;
@@ -254,11 +272,10 @@ static int ssm2602_hw_params(struct snd_pcm_substream *substream,
254 struct snd_pcm_hw_params *params, 272 struct snd_pcm_hw_params *params,
255 struct snd_soc_dai *dai) 273 struct snd_soc_dai *dai)
256{ 274{
257 struct snd_soc_pcm_runtime *rtd = substream->private_data; 275 struct snd_soc_codec *codec = dai->codec;
258 struct snd_soc_codec *codec = rtd->codec;
259 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec); 276 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
260 u16 iface = snd_soc_read(codec, SSM2602_IFACE) & 0xfff3;
261 int srate = ssm2602_get_coeff(ssm2602->sysclk, params_rate(params)); 277 int srate = ssm2602_get_coeff(ssm2602->sysclk, params_rate(params));
278 unsigned int iface;
262 279
263 if (substream == ssm2602->slave_substream) { 280 if (substream == ssm2602->slave_substream) {
264 dev_dbg(codec->dev, "Ignoring hw_params for slave substream\n"); 281 dev_dbg(codec->dev, "Ignoring hw_params for slave substream\n");
@@ -268,31 +285,34 @@ static int ssm2602_hw_params(struct snd_pcm_substream *substream,
268 if (srate < 0) 285 if (srate < 0)
269 return srate; 286 return srate;
270 287
271 snd_soc_write(codec, SSM2602_SRATE, srate); 288 regmap_write(ssm2602->regmap, SSM2602_SRATE, srate);
272 289
273 /* bit size */ 290 /* bit size */
274 switch (params_format(params)) { 291 switch (params_format(params)) {
275 case SNDRV_PCM_FORMAT_S16_LE: 292 case SNDRV_PCM_FORMAT_S16_LE:
293 iface = 0x0;
276 break; 294 break;
277 case SNDRV_PCM_FORMAT_S20_3LE: 295 case SNDRV_PCM_FORMAT_S20_3LE:
278 iface |= 0x0004; 296 iface = 0x4;
279 break; 297 break;
280 case SNDRV_PCM_FORMAT_S24_LE: 298 case SNDRV_PCM_FORMAT_S24_LE:
281 iface |= 0x0008; 299 iface = 0x8;
282 break; 300 break;
283 case SNDRV_PCM_FORMAT_S32_LE: 301 case SNDRV_PCM_FORMAT_S32_LE:
284 iface |= 0x000c; 302 iface = 0xc;
285 break; 303 break;
304 default:
305 return -EINVAL;
286 } 306 }
287 snd_soc_write(codec, SSM2602_IFACE, iface); 307 regmap_update_bits(ssm2602->regmap, SSM2602_IFACE,
308 IFACE_AUDIO_DATA_LEN, iface);
288 return 0; 309 return 0;
289} 310}
290 311
291static int ssm2602_startup(struct snd_pcm_substream *substream, 312static int ssm2602_startup(struct snd_pcm_substream *substream,
292 struct snd_soc_dai *dai) 313 struct snd_soc_dai *dai)
293{ 314{
294 struct snd_soc_pcm_runtime *rtd = substream->private_data; 315 struct snd_soc_codec *codec = dai->codec;
295 struct snd_soc_codec *codec = rtd->codec;
296 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec); 316 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
297 struct snd_pcm_runtime *master_runtime; 317 struct snd_pcm_runtime *master_runtime;
298 318
@@ -322,14 +342,19 @@ static int ssm2602_startup(struct snd_pcm_substream *substream,
322 } else 342 } else
323 ssm2602->master_substream = substream; 343 ssm2602->master_substream = substream;
324 344
345 if (ssm2602->sysclk_constraints) {
346 snd_pcm_hw_constraint_list(substream->runtime, 0,
347 SNDRV_PCM_HW_PARAM_RATE,
348 ssm2602->sysclk_constraints);
349 }
350
325 return 0; 351 return 0;
326} 352}
327 353
328static void ssm2602_shutdown(struct snd_pcm_substream *substream, 354static void ssm2602_shutdown(struct snd_pcm_substream *substream,
329 struct snd_soc_dai *dai) 355 struct snd_soc_dai *dai)
330{ 356{
331 struct snd_soc_pcm_runtime *rtd = substream->private_data; 357 struct snd_soc_codec *codec = dai->codec;
332 struct snd_soc_codec *codec = rtd->codec;
333 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec); 358 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
334 359
335 if (ssm2602->master_substream == substream) 360 if (ssm2602->master_substream == substream)
@@ -341,14 +366,14 @@ static void ssm2602_shutdown(struct snd_pcm_substream *substream,
341 366
342static int ssm2602_mute(struct snd_soc_dai *dai, int mute) 367static int ssm2602_mute(struct snd_soc_dai *dai, int mute)
343{ 368{
344 struct snd_soc_codec *codec = dai->codec; 369 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(dai->codec);
345 370
346 if (mute) 371 if (mute)
347 snd_soc_update_bits(codec, SSM2602_APDIGI, 372 regmap_update_bits(ssm2602->regmap, SSM2602_APDIGI,
348 APDIGI_ENABLE_DAC_MUTE, 373 APDIGI_ENABLE_DAC_MUTE,
349 APDIGI_ENABLE_DAC_MUTE); 374 APDIGI_ENABLE_DAC_MUTE);
350 else 375 else
351 snd_soc_update_bits(codec, SSM2602_APDIGI, 376 regmap_update_bits(ssm2602->regmap, SSM2602_APDIGI,
352 APDIGI_ENABLE_DAC_MUTE, 0); 377 APDIGI_ENABLE_DAC_MUTE, 0);
353 return 0; 378 return 0;
354} 379}
@@ -364,16 +389,21 @@ static int ssm2602_set_dai_sysclk(struct snd_soc_dai *codec_dai,
364 return -EINVAL; 389 return -EINVAL;
365 390
366 switch (freq) { 391 switch (freq) {
367 case 11289600:
368 case 12000000:
369 case 12288000: 392 case 12288000:
370 case 16934400:
371 case 18432000: 393 case 18432000:
372 ssm2602->sysclk = freq; 394 ssm2602->sysclk_constraints = &ssm2602_constraints_12288000;
395 break;
396 case 11289600:
397 case 16934400:
398 ssm2602->sysclk_constraints = &ssm2602_constraints_11289600;
399 break;
400 case 12000000:
401 ssm2602->sysclk_constraints = NULL;
373 break; 402 break;
374 default: 403 default:
375 return -EINVAL; 404 return -EINVAL;
376 } 405 }
406 ssm2602->sysclk = freq;
377 } else { 407 } else {
378 unsigned int mask; 408 unsigned int mask;
379 409
@@ -393,7 +423,7 @@ static int ssm2602_set_dai_sysclk(struct snd_soc_dai *codec_dai,
393 else 423 else
394 ssm2602->clk_out_pwr &= ~mask; 424 ssm2602->clk_out_pwr &= ~mask;
395 425
396 snd_soc_update_bits(codec, SSM2602_PWR, 426 regmap_update_bits(ssm2602->regmap, SSM2602_PWR,
397 PWR_CLK_OUT_PDN | PWR_OSC_PDN, ssm2602->clk_out_pwr); 427 PWR_CLK_OUT_PDN | PWR_OSC_PDN, ssm2602->clk_out_pwr);
398 } 428 }
399 429
@@ -403,8 +433,8 @@ static int ssm2602_set_dai_sysclk(struct snd_soc_dai *codec_dai,
403static int ssm2602_set_dai_fmt(struct snd_soc_dai *codec_dai, 433static int ssm2602_set_dai_fmt(struct snd_soc_dai *codec_dai,
404 unsigned int fmt) 434 unsigned int fmt)
405{ 435{
406 struct snd_soc_codec *codec = codec_dai->codec; 436 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec_dai->codec);
407 u16 iface = 0; 437 unsigned int iface = 0;
408 438
409 /* set master/slave audio interface */ 439 /* set master/slave audio interface */
410 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { 440 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
@@ -455,7 +485,7 @@ static int ssm2602_set_dai_fmt(struct snd_soc_dai *codec_dai,
455 } 485 }
456 486
457 /* set iface */ 487 /* set iface */
458 snd_soc_write(codec, SSM2602_IFACE, iface); 488 regmap_write(ssm2602->regmap, SSM2602_IFACE, iface);
459 return 0; 489 return 0;
460} 490}
461 491
@@ -467,7 +497,7 @@ static int ssm2602_set_bias_level(struct snd_soc_codec *codec,
467 switch (level) { 497 switch (level) {
468 case SND_SOC_BIAS_ON: 498 case SND_SOC_BIAS_ON:
469 /* vref/mid on, osc and clkout on if enabled */ 499 /* vref/mid on, osc and clkout on if enabled */
470 snd_soc_update_bits(codec, SSM2602_PWR, 500 regmap_update_bits(ssm2602->regmap, SSM2602_PWR,
471 PWR_POWER_OFF | PWR_CLK_OUT_PDN | PWR_OSC_PDN, 501 PWR_POWER_OFF | PWR_CLK_OUT_PDN | PWR_OSC_PDN,
472 ssm2602->clk_out_pwr); 502 ssm2602->clk_out_pwr);
473 break; 503 break;
@@ -475,13 +505,13 @@ static int ssm2602_set_bias_level(struct snd_soc_codec *codec,
475 break; 505 break;
476 case SND_SOC_BIAS_STANDBY: 506 case SND_SOC_BIAS_STANDBY:
477 /* everything off except vref/vmid, */ 507 /* everything off except vref/vmid, */
478 snd_soc_update_bits(codec, SSM2602_PWR, 508 regmap_update_bits(ssm2602->regmap, SSM2602_PWR,
479 PWR_POWER_OFF | PWR_CLK_OUT_PDN | PWR_OSC_PDN, 509 PWR_POWER_OFF | PWR_CLK_OUT_PDN | PWR_OSC_PDN,
480 PWR_CLK_OUT_PDN | PWR_OSC_PDN); 510 PWR_CLK_OUT_PDN | PWR_OSC_PDN);
481 break; 511 break;
482 case SND_SOC_BIAS_OFF: 512 case SND_SOC_BIAS_OFF:
483 /* everything off */ 513 /* everything off */
484 snd_soc_update_bits(codec, SSM2602_PWR, 514 regmap_update_bits(ssm2602->regmap, SSM2602_PWR,
485 PWR_POWER_OFF, PWR_POWER_OFF); 515 PWR_POWER_OFF, PWR_POWER_OFF);
486 break; 516 break;
487 517
@@ -540,12 +570,13 @@ static int ssm2602_resume(struct snd_soc_codec *codec)
540 570
541static int ssm2602_probe(struct snd_soc_codec *codec) 571static int ssm2602_probe(struct snd_soc_codec *codec)
542{ 572{
573 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
543 struct snd_soc_dapm_context *dapm = &codec->dapm; 574 struct snd_soc_dapm_context *dapm = &codec->dapm;
544 int ret; 575 int ret;
545 576
546 snd_soc_update_bits(codec, SSM2602_LOUT1V, 577 regmap_update_bits(ssm2602->regmap, SSM2602_LOUT1V,
547 LOUT1V_LRHP_BOTH, LOUT1V_LRHP_BOTH); 578 LOUT1V_LRHP_BOTH, LOUT1V_LRHP_BOTH);
548 snd_soc_update_bits(codec, SSM2602_ROUT1V, 579 regmap_update_bits(ssm2602->regmap, SSM2602_ROUT1V,
549 ROUT1V_RLHP_BOTH, ROUT1V_RLHP_BOTH); 580 ROUT1V_RLHP_BOTH, ROUT1V_RLHP_BOTH);
550 581
551 ret = snd_soc_add_codec_controls(codec, ssm2602_snd_controls, 582 ret = snd_soc_add_codec_controls(codec, ssm2602_snd_controls,
@@ -581,27 +612,26 @@ static int ssm260x_probe(struct snd_soc_codec *codec)
581 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec); 612 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
582 int ret; 613 int ret;
583 614
584 pr_info("ssm2602 Audio Codec %s", SSM2602_VERSION); 615 codec->control_data = ssm2602->regmap;
585 616 ret = snd_soc_codec_set_cache_io(codec, 0, 0, SND_SOC_REGMAP);
586 ret = snd_soc_codec_set_cache_io(codec, 7, 9, ssm2602->control_type);
587 if (ret < 0) { 617 if (ret < 0) {
588 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); 618 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
589 return ret; 619 return ret;
590 } 620 }
591 621
592 ret = ssm2602_reset(codec); 622 ret = regmap_write(ssm2602->regmap, SSM2602_RESET, 0);
593 if (ret < 0) { 623 if (ret < 0) {
594 dev_err(codec->dev, "Failed to issue reset: %d\n", ret); 624 dev_err(codec->dev, "Failed to issue reset: %d\n", ret);
595 return ret; 625 return ret;
596 } 626 }
597 627
598 /* set the update bits */ 628 /* set the update bits */
599 snd_soc_update_bits(codec, SSM2602_LINVOL, 629 regmap_update_bits(ssm2602->regmap, SSM2602_LINVOL,
600 LINVOL_LRIN_BOTH, LINVOL_LRIN_BOTH); 630 LINVOL_LRIN_BOTH, LINVOL_LRIN_BOTH);
601 snd_soc_update_bits(codec, SSM2602_RINVOL, 631 regmap_update_bits(ssm2602->regmap, SSM2602_RINVOL,
602 RINVOL_RLIN_BOTH, RINVOL_RLIN_BOTH); 632 RINVOL_RLIN_BOTH, RINVOL_RLIN_BOTH);
603 /*select Line in as default input*/ 633 /*select Line in as default input*/
604 snd_soc_write(codec, SSM2602_APANA, APANA_SELECT_DAC | 634 regmap_write(ssm2602->regmap, SSM2602_APANA, APANA_SELECT_DAC |
605 APANA_ENABLE_MIC_BOOST); 635 APANA_ENABLE_MIC_BOOST);
606 636
607 switch (ssm2602->type) { 637 switch (ssm2602->type) {
@@ -634,9 +664,6 @@ static struct snd_soc_codec_driver soc_codec_dev_ssm2602 = {
634 .suspend = ssm2602_suspend, 664 .suspend = ssm2602_suspend,
635 .resume = ssm2602_resume, 665 .resume = ssm2602_resume,
636 .set_bias_level = ssm2602_set_bias_level, 666 .set_bias_level = ssm2602_set_bias_level,
637 .reg_cache_size = ARRAY_SIZE(ssm2602_reg),
638 .reg_word_size = sizeof(u16),
639 .reg_cache_default = ssm2602_reg,
640 667
641 .controls = ssm260x_snd_controls, 668 .controls = ssm260x_snd_controls,
642 .num_controls = ARRAY_SIZE(ssm260x_snd_controls), 669 .num_controls = ARRAY_SIZE(ssm260x_snd_controls),
@@ -646,6 +673,23 @@ static struct snd_soc_codec_driver soc_codec_dev_ssm2602 = {
646 .num_dapm_routes = ARRAY_SIZE(ssm260x_routes), 673 .num_dapm_routes = ARRAY_SIZE(ssm260x_routes),
647}; 674};
648 675
676static bool ssm2602_register_volatile(struct device *dev, unsigned int reg)
677{
678 return reg == SSM2602_RESET;
679}
680
681static const struct regmap_config ssm2602_regmap_config = {
682 .val_bits = 9,
683 .reg_bits = 7,
684
685 .max_register = SSM2602_RESET,
686 .volatile_reg = ssm2602_register_volatile,
687
688 .cache_type = REGCACHE_RBTREE,
689 .reg_defaults_raw = ssm2602_reg,
690 .num_reg_defaults_raw = ARRAY_SIZE(ssm2602_reg),
691};
692
649#if defined(CONFIG_SPI_MASTER) 693#if defined(CONFIG_SPI_MASTER)
650static int __devinit ssm2602_spi_probe(struct spi_device *spi) 694static int __devinit ssm2602_spi_probe(struct spi_device *spi)
651{ 695{
@@ -658,9 +702,12 @@ static int __devinit ssm2602_spi_probe(struct spi_device *spi)
658 return -ENOMEM; 702 return -ENOMEM;
659 703
660 spi_set_drvdata(spi, ssm2602); 704 spi_set_drvdata(spi, ssm2602);
661 ssm2602->control_type = SND_SOC_SPI;
662 ssm2602->type = SSM2602; 705 ssm2602->type = SSM2602;
663 706
707 ssm2602->regmap = devm_regmap_init_spi(spi, &ssm2602_regmap_config);
708 if (IS_ERR(ssm2602->regmap))
709 return PTR_ERR(ssm2602->regmap);
710
664 ret = snd_soc_register_codec(&spi->dev, 711 ret = snd_soc_register_codec(&spi->dev,
665 &soc_codec_dev_ssm2602, &ssm2602_dai, 1); 712 &soc_codec_dev_ssm2602, &ssm2602_dai, 1);
666 return ret; 713 return ret;
@@ -701,9 +748,12 @@ static int __devinit ssm2602_i2c_probe(struct i2c_client *i2c,
701 return -ENOMEM; 748 return -ENOMEM;
702 749
703 i2c_set_clientdata(i2c, ssm2602); 750 i2c_set_clientdata(i2c, ssm2602);
704 ssm2602->control_type = SND_SOC_I2C;
705 ssm2602->type = id->driver_data; 751 ssm2602->type = id->driver_data;
706 752
753 ssm2602->regmap = devm_regmap_init_i2c(i2c, &ssm2602_regmap_config);
754 if (IS_ERR(ssm2602->regmap))
755 return PTR_ERR(ssm2602->regmap);
756
707 ret = snd_soc_register_codec(&i2c->dev, 757 ret = snd_soc_register_codec(&i2c->dev,
708 &soc_codec_dev_ssm2602, &ssm2602_dai, 1); 758 &soc_codec_dev_ssm2602, &ssm2602_dai, 1);
709 return ret; 759 return ret;
diff --git a/sound/soc/codecs/sta32x.c b/sound/soc/codecs/sta32x.c
index 7db6fa515028..8d717f4b5a87 100644
--- a/sound/soc/codecs/sta32x.c
+++ b/sound/soc/codecs/sta32x.c
@@ -609,8 +609,7 @@ static int sta32x_hw_params(struct snd_pcm_substream *substream,
609 struct snd_pcm_hw_params *params, 609 struct snd_pcm_hw_params *params,
610 struct snd_soc_dai *dai) 610 struct snd_soc_dai *dai)
611{ 611{
612 struct snd_soc_pcm_runtime *rtd = substream->private_data; 612 struct snd_soc_codec *codec = dai->codec;
613 struct snd_soc_codec *codec = rtd->codec;
614 struct sta32x_priv *sta32x = snd_soc_codec_get_drvdata(codec); 613 struct sta32x_priv *sta32x = snd_soc_codec_get_drvdata(codec);
615 unsigned int rate; 614 unsigned int rate;
616 int i, mcs = -1, ir = -1; 615 int i, mcs = -1, ir = -1;
diff --git a/sound/soc/codecs/tlv320aic23.c b/sound/soc/codecs/tlv320aic23.c
index df1e07ffac32..31762ebdd774 100644
--- a/sound/soc/codecs/tlv320aic23.c
+++ b/sound/soc/codecs/tlv320aic23.c
@@ -34,8 +34,6 @@
34 34
35#include "tlv320aic23.h" 35#include "tlv320aic23.h"
36 36
37#define AIC23_VERSION "0.1"
38
39/* 37/*
40 * AIC23 register cache 38 * AIC23 register cache
41 */ 39 */
@@ -325,8 +323,7 @@ static int tlv320aic23_hw_params(struct snd_pcm_substream *substream,
325 struct snd_pcm_hw_params *params, 323 struct snd_pcm_hw_params *params,
326 struct snd_soc_dai *dai) 324 struct snd_soc_dai *dai)
327{ 325{
328 struct snd_soc_pcm_runtime *rtd = substream->private_data; 326 struct snd_soc_codec *codec = dai->codec;
329 struct snd_soc_codec *codec = rtd->codec;
330 u16 iface_reg; 327 u16 iface_reg;
331 int ret; 328 int ret;
332 struct aic23 *aic23 = snd_soc_codec_get_drvdata(codec); 329 struct aic23 *aic23 = snd_soc_codec_get_drvdata(codec);
@@ -371,8 +368,7 @@ static int tlv320aic23_hw_params(struct snd_pcm_substream *substream,
371static int tlv320aic23_pcm_prepare(struct snd_pcm_substream *substream, 368static int tlv320aic23_pcm_prepare(struct snd_pcm_substream *substream,
372 struct snd_soc_dai *dai) 369 struct snd_soc_dai *dai)
373{ 370{
374 struct snd_soc_pcm_runtime *rtd = substream->private_data; 371 struct snd_soc_codec *codec = dai->codec;
375 struct snd_soc_codec *codec = rtd->codec;
376 372
377 /* set active */ 373 /* set active */
378 snd_soc_write(codec, TLV320AIC23_ACTIVE, 0x0001); 374 snd_soc_write(codec, TLV320AIC23_ACTIVE, 0x0001);
@@ -383,8 +379,7 @@ static int tlv320aic23_pcm_prepare(struct snd_pcm_substream *substream,
383static void tlv320aic23_shutdown(struct snd_pcm_substream *substream, 379static void tlv320aic23_shutdown(struct snd_pcm_substream *substream,
384 struct snd_soc_dai *dai) 380 struct snd_soc_dai *dai)
385{ 381{
386 struct snd_soc_pcm_runtime *rtd = substream->private_data; 382 struct snd_soc_codec *codec = dai->codec;
387 struct snd_soc_codec *codec = rtd->codec;
388 struct aic23 *aic23 = snd_soc_codec_get_drvdata(codec); 383 struct aic23 *aic23 = snd_soc_codec_get_drvdata(codec);
389 384
390 /* deactivate */ 385 /* deactivate */
@@ -548,8 +543,6 @@ static int tlv320aic23_probe(struct snd_soc_codec *codec)
548 struct aic23 *aic23 = snd_soc_codec_get_drvdata(codec); 543 struct aic23 *aic23 = snd_soc_codec_get_drvdata(codec);
549 int ret; 544 int ret;
550 545
551 printk(KERN_INFO "AIC23 Audio Codec %s\n", AIC23_VERSION);
552
553 ret = snd_soc_codec_set_cache_io(codec, 7, 9, aic23->control_type); 546 ret = snd_soc_codec_set_cache_io(codec, 7, 9, aic23->control_type);
554 if (ret < 0) { 547 if (ret < 0) {
555 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); 548 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
diff --git a/sound/soc/codecs/tlv320aic26.c b/sound/soc/codecs/tlv320aic26.c
index 802064b5030d..85944e953578 100644
--- a/sound/soc/codecs/tlv320aic26.c
+++ b/sound/soc/codecs/tlv320aic26.c
@@ -126,8 +126,7 @@ static int aic26_hw_params(struct snd_pcm_substream *substream,
126 struct snd_pcm_hw_params *params, 126 struct snd_pcm_hw_params *params,
127 struct snd_soc_dai *dai) 127 struct snd_soc_dai *dai)
128{ 128{
129 struct snd_soc_pcm_runtime *rtd = substream->private_data; 129 struct snd_soc_codec *codec = dai->codec;
130 struct snd_soc_codec *codec = rtd->codec;
131 struct aic26 *aic26 = snd_soc_codec_get_drvdata(codec); 130 struct aic26 *aic26 = snd_soc_codec_get_drvdata(codec);
132 int fsref, divisor, wlen, pval, jval, dval, qval; 131 int fsref, divisor, wlen, pval, jval, dval, qval;
133 u16 reg; 132 u16 reg;
diff --git a/sound/soc/codecs/tlv320aic3x.c b/sound/soc/codecs/tlv320aic3x.c
index 8d20f6ec20f3..64d2a4fa34b2 100644
--- a/sound/soc/codecs/tlv320aic3x.c
+++ b/sound/soc/codecs/tlv320aic3x.c
@@ -802,8 +802,7 @@ static int aic3x_hw_params(struct snd_pcm_substream *substream,
802 struct snd_pcm_hw_params *params, 802 struct snd_pcm_hw_params *params,
803 struct snd_soc_dai *dai) 803 struct snd_soc_dai *dai)
804{ 804{
805 struct snd_soc_pcm_runtime *rtd = substream->private_data; 805 struct snd_soc_codec *codec = dai->codec;
806 struct snd_soc_codec *codec =rtd->codec;
807 struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec); 806 struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
808 int codec_clk = 0, bypass_pll = 0, fsref, last_clk = 0; 807 int codec_clk = 0, bypass_pll = 0, fsref, last_clk = 0;
809 u8 data, j, r, p, pll_q, pll_p = 1, pll_r = 1, pll_j = 1; 808 u8 data, j, r, p, pll_q, pll_p = 1, pll_r = 1, pll_j = 1;
@@ -1161,24 +1160,6 @@ static int aic3x_set_bias_level(struct snd_soc_codec *codec,
1161 return 0; 1160 return 0;
1162} 1161}
1163 1162
1164void aic3x_set_headset_detection(struct snd_soc_codec *codec, int detect,
1165 int headset_debounce, int button_debounce)
1166{
1167 u8 val;
1168
1169 val = ((detect & AIC3X_HEADSET_DETECT_MASK)
1170 << AIC3X_HEADSET_DETECT_SHIFT) |
1171 ((headset_debounce & AIC3X_HEADSET_DEBOUNCE_MASK)
1172 << AIC3X_HEADSET_DEBOUNCE_SHIFT) |
1173 ((button_debounce & AIC3X_BUTTON_DEBOUNCE_MASK)
1174 << AIC3X_BUTTON_DEBOUNCE_SHIFT);
1175
1176 if (detect & AIC3X_HEADSET_DETECT_MASK)
1177 val |= AIC3X_HEADSET_DETECT_ENABLED;
1178
1179 snd_soc_write(codec, AIC3X_HEADSET_DETECT_CTRL_A, val);
1180}
1181
1182#define AIC3X_RATES SNDRV_PCM_RATE_8000_96000 1163#define AIC3X_RATES SNDRV_PCM_RATE_8000_96000
1183#define AIC3X_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \ 1164#define AIC3X_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
1184 SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE) 1165 SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE)
diff --git a/sound/soc/codecs/tlv320dac33.c b/sound/soc/codecs/tlv320dac33.c
index 4587ddd0fbf8..0dd41077ab79 100644
--- a/sound/soc/codecs/tlv320dac33.c
+++ b/sound/soc/codecs/tlv320dac33.c
@@ -62,8 +62,10 @@
62#define UTHR_FROM_PERIOD_SIZE(samples, playrate, burstrate) \ 62#define UTHR_FROM_PERIOD_SIZE(samples, playrate, burstrate) \
63 (((samples)*5000) / (((burstrate)*5000) / ((burstrate) - (playrate)))) 63 (((samples)*5000) / (((burstrate)*5000) / ((burstrate) - (playrate))))
64 64
65static void dac33_calculate_times(struct snd_pcm_substream *substream); 65static void dac33_calculate_times(struct snd_pcm_substream *substream,
66static int dac33_prepare_chip(struct snd_pcm_substream *substream); 66 struct snd_soc_codec *codec);
67static int dac33_prepare_chip(struct snd_pcm_substream *substream,
68 struct snd_soc_codec *codec);
67 69
68enum dac33_state { 70enum dac33_state {
69 DAC33_IDLE = 0, 71 DAC33_IDLE = 0,
@@ -427,8 +429,8 @@ static int dac33_playback_event(struct snd_soc_dapm_widget *w,
427 switch (event) { 429 switch (event) {
428 case SND_SOC_DAPM_PRE_PMU: 430 case SND_SOC_DAPM_PRE_PMU:
429 if (likely(dac33->substream)) { 431 if (likely(dac33->substream)) {
430 dac33_calculate_times(dac33->substream); 432 dac33_calculate_times(dac33->substream, w->codec);
431 dac33_prepare_chip(dac33->substream); 433 dac33_prepare_chip(dac33->substream, w->codec);
432 } 434 }
433 break; 435 break;
434 case SND_SOC_DAPM_POST_PMD: 436 case SND_SOC_DAPM_POST_PMD:
@@ -799,8 +801,7 @@ static void dac33_oscwait(struct snd_soc_codec *codec)
799static int dac33_startup(struct snd_pcm_substream *substream, 801static int dac33_startup(struct snd_pcm_substream *substream,
800 struct snd_soc_dai *dai) 802 struct snd_soc_dai *dai)
801{ 803{
802 struct snd_soc_pcm_runtime *rtd = substream->private_data; 804 struct snd_soc_codec *codec = dai->codec;
803 struct snd_soc_codec *codec = rtd->codec;
804 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); 805 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
805 806
806 /* Stream started, save the substream pointer */ 807 /* Stream started, save the substream pointer */
@@ -812,8 +813,7 @@ static int dac33_startup(struct snd_pcm_substream *substream,
812static void dac33_shutdown(struct snd_pcm_substream *substream, 813static void dac33_shutdown(struct snd_pcm_substream *substream,
813 struct snd_soc_dai *dai) 814 struct snd_soc_dai *dai)
814{ 815{
815 struct snd_soc_pcm_runtime *rtd = substream->private_data; 816 struct snd_soc_codec *codec = dai->codec;
816 struct snd_soc_codec *codec = rtd->codec;
817 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); 817 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
818 818
819 dac33->substream = NULL; 819 dac33->substream = NULL;
@@ -825,8 +825,7 @@ static int dac33_hw_params(struct snd_pcm_substream *substream,
825 struct snd_pcm_hw_params *params, 825 struct snd_pcm_hw_params *params,
826 struct snd_soc_dai *dai) 826 struct snd_soc_dai *dai)
827{ 827{
828 struct snd_soc_pcm_runtime *rtd = substream->private_data; 828 struct snd_soc_codec *codec = dai->codec;
829 struct snd_soc_codec *codec = rtd->codec;
830 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); 829 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
831 830
832 /* Check parameters for validity */ 831 /* Check parameters for validity */
@@ -868,10 +867,9 @@ static int dac33_hw_params(struct snd_pcm_substream *substream,
868 * writes happens in different order, than dac33 might end up in unknown state. 867 * writes happens in different order, than dac33 might end up in unknown state.
869 * Use the known, working sequence of register writes to initialize the dac33. 868 * Use the known, working sequence of register writes to initialize the dac33.
870 */ 869 */
871static int dac33_prepare_chip(struct snd_pcm_substream *substream) 870static int dac33_prepare_chip(struct snd_pcm_substream *substream,
871 struct snd_soc_codec *codec)
872{ 872{
873 struct snd_soc_pcm_runtime *rtd = substream->private_data;
874 struct snd_soc_codec *codec = rtd->codec;
875 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); 873 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
876 unsigned int oscset, ratioset, pwr_ctrl, reg_tmp; 874 unsigned int oscset, ratioset, pwr_ctrl, reg_tmp;
877 u8 aictrl_a, aictrl_b, fifoctrl_a; 875 u8 aictrl_a, aictrl_b, fifoctrl_a;
@@ -1067,10 +1065,9 @@ static int dac33_prepare_chip(struct snd_pcm_substream *substream)
1067 return 0; 1065 return 0;
1068} 1066}
1069 1067
1070static void dac33_calculate_times(struct snd_pcm_substream *substream) 1068static void dac33_calculate_times(struct snd_pcm_substream *substream,
1069 struct snd_soc_codec *codec)
1071{ 1070{
1072 struct snd_soc_pcm_runtime *rtd = substream->private_data;
1073 struct snd_soc_codec *codec = rtd->codec;
1074 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); 1071 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
1075 unsigned int period_size = substream->runtime->period_size; 1072 unsigned int period_size = substream->runtime->period_size;
1076 unsigned int rate = substream->runtime->rate; 1073 unsigned int rate = substream->runtime->rate;
@@ -1128,8 +1125,7 @@ static void dac33_calculate_times(struct snd_pcm_substream *substream)
1128static int dac33_pcm_trigger(struct snd_pcm_substream *substream, int cmd, 1125static int dac33_pcm_trigger(struct snd_pcm_substream *substream, int cmd,
1129 struct snd_soc_dai *dai) 1126 struct snd_soc_dai *dai)
1130{ 1127{
1131 struct snd_soc_pcm_runtime *rtd = substream->private_data; 1128 struct snd_soc_codec *codec = dai->codec;
1132 struct snd_soc_codec *codec = rtd->codec;
1133 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); 1129 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
1134 int ret = 0; 1130 int ret = 0;
1135 1131
@@ -1161,8 +1157,7 @@ static snd_pcm_sframes_t dac33_dai_delay(
1161 struct snd_pcm_substream *substream, 1157 struct snd_pcm_substream *substream,
1162 struct snd_soc_dai *dai) 1158 struct snd_soc_dai *dai)
1163{ 1159{
1164 struct snd_soc_pcm_runtime *rtd = substream->private_data; 1160 struct snd_soc_codec *codec = dai->codec;
1165 struct snd_soc_codec *codec = rtd->codec;
1166 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); 1161 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
1167 unsigned long long t0, t1, t_now; 1162 unsigned long long t0, t1, t_now;
1168 unsigned int time_delta, uthr; 1163 unsigned int time_delta, uthr;
diff --git a/sound/soc/codecs/twl4030.c b/sound/soc/codecs/twl4030.c
index 170cf9a8fc79..391fcfc7b63b 100644
--- a/sound/soc/codecs/twl4030.c
+++ b/sound/soc/codecs/twl4030.c
@@ -1685,8 +1685,7 @@ static void twl4030_tdm_enable(struct snd_soc_codec *codec, int direction,
1685static int twl4030_startup(struct snd_pcm_substream *substream, 1685static int twl4030_startup(struct snd_pcm_substream *substream,
1686 struct snd_soc_dai *dai) 1686 struct snd_soc_dai *dai)
1687{ 1687{
1688 struct snd_soc_pcm_runtime *rtd = substream->private_data; 1688 struct snd_soc_codec *codec = dai->codec;
1689 struct snd_soc_codec *codec = rtd->codec;
1690 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec); 1689 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
1691 1690
1692 if (twl4030->master_substream) { 1691 if (twl4030->master_substream) {
@@ -1715,8 +1714,7 @@ static int twl4030_startup(struct snd_pcm_substream *substream,
1715static void twl4030_shutdown(struct snd_pcm_substream *substream, 1714static void twl4030_shutdown(struct snd_pcm_substream *substream,
1716 struct snd_soc_dai *dai) 1715 struct snd_soc_dai *dai)
1717{ 1716{
1718 struct snd_soc_pcm_runtime *rtd = substream->private_data; 1717 struct snd_soc_codec *codec = dai->codec;
1719 struct snd_soc_codec *codec = rtd->codec;
1720 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec); 1718 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
1721 1719
1722 if (twl4030->master_substream == substream) 1720 if (twl4030->master_substream == substream)
@@ -1740,8 +1738,7 @@ static int twl4030_hw_params(struct snd_pcm_substream *substream,
1740 struct snd_pcm_hw_params *params, 1738 struct snd_pcm_hw_params *params,
1741 struct snd_soc_dai *dai) 1739 struct snd_soc_dai *dai)
1742{ 1740{
1743 struct snd_soc_pcm_runtime *rtd = substream->private_data; 1741 struct snd_soc_codec *codec = dai->codec;
1744 struct snd_soc_codec *codec = rtd->codec;
1745 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec); 1742 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
1746 u8 mode, old_mode, format, old_format; 1743 u8 mode, old_mode, format, old_format;
1747 1744
@@ -1974,8 +1971,7 @@ static void twl4030_voice_enable(struct snd_soc_codec *codec, int direction,
1974static int twl4030_voice_startup(struct snd_pcm_substream *substream, 1971static int twl4030_voice_startup(struct snd_pcm_substream *substream,
1975 struct snd_soc_dai *dai) 1972 struct snd_soc_dai *dai)
1976{ 1973{
1977 struct snd_soc_pcm_runtime *rtd = substream->private_data; 1974 struct snd_soc_codec *codec = dai->codec;
1978 struct snd_soc_codec *codec = rtd->codec;
1979 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec); 1975 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
1980 u8 mode; 1976 u8 mode;
1981 1977
@@ -2007,8 +2003,7 @@ static int twl4030_voice_startup(struct snd_pcm_substream *substream,
2007static void twl4030_voice_shutdown(struct snd_pcm_substream *substream, 2003static void twl4030_voice_shutdown(struct snd_pcm_substream *substream,
2008 struct snd_soc_dai *dai) 2004 struct snd_soc_dai *dai)
2009{ 2005{
2010 struct snd_soc_pcm_runtime *rtd = substream->private_data; 2006 struct snd_soc_codec *codec = dai->codec;
2011 struct snd_soc_codec *codec = rtd->codec;
2012 2007
2013 /* Enable voice digital filters */ 2008 /* Enable voice digital filters */
2014 twl4030_voice_enable(codec, substream->stream, 0); 2009 twl4030_voice_enable(codec, substream->stream, 0);
@@ -2017,8 +2012,7 @@ static void twl4030_voice_shutdown(struct snd_pcm_substream *substream,
2017static int twl4030_voice_hw_params(struct snd_pcm_substream *substream, 2012static int twl4030_voice_hw_params(struct snd_pcm_substream *substream,
2018 struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) 2013 struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
2019{ 2014{
2020 struct snd_soc_pcm_runtime *rtd = substream->private_data; 2015 struct snd_soc_codec *codec = dai->codec;
2021 struct snd_soc_codec *codec = rtd->codec;
2022 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec); 2016 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
2023 u8 old_mode, mode; 2017 u8 old_mode, mode;
2024 2018
diff --git a/sound/soc/codecs/twl6040.c b/sound/soc/codecs/twl6040.c
index 2d8c6b825e57..a36e9fcdf184 100644
--- a/sound/soc/codecs/twl6040.c
+++ b/sound/soc/codecs/twl6040.c
@@ -26,7 +26,6 @@
26#include <linux/pm.h> 26#include <linux/pm.h>
27#include <linux/platform_device.h> 27#include <linux/platform_device.h>
28#include <linux/slab.h> 28#include <linux/slab.h>
29#include <linux/i2c/twl.h>
30#include <linux/mfd/twl6040.h> 29#include <linux/mfd/twl6040.h>
31 30
32#include <sound/core.h> 31#include <sound/core.h>
@@ -47,17 +46,6 @@
47#define TWL6040_OUTHF_0dB 0x03 46#define TWL6040_OUTHF_0dB 0x03
48#define TWL6040_OUTHF_M52dB 0x1D 47#define TWL6040_OUTHF_M52dB 0x1D
49 48
50#define TWL6040_RAMP_NONE 0
51#define TWL6040_RAMP_UP 1
52#define TWL6040_RAMP_DOWN 2
53
54#define TWL6040_HSL_VOL_MASK 0x0F
55#define TWL6040_HSL_VOL_SHIFT 0
56#define TWL6040_HSR_VOL_MASK 0xF0
57#define TWL6040_HSR_VOL_SHIFT 4
58#define TWL6040_HF_VOL_MASK 0x1F
59#define TWL6040_HF_VOL_SHIFT 0
60
61/* Shadow register used by the driver */ 49/* Shadow register used by the driver */
62#define TWL6040_REG_SW_SHADOW 0x2F 50#define TWL6040_REG_SW_SHADOW 0x2F
63#define TWL6040_CACHEREGNUM (TWL6040_REG_SW_SHADOW + 1) 51#define TWL6040_CACHEREGNUM (TWL6040_REG_SW_SHADOW + 1)
@@ -65,18 +53,6 @@
65/* TWL6040_REG_SW_SHADOW (0x2F) fields */ 53/* TWL6040_REG_SW_SHADOW (0x2F) fields */
66#define TWL6040_EAR_PATH_ENABLE 0x01 54#define TWL6040_EAR_PATH_ENABLE 0x01
67 55
68struct twl6040_output {
69 u16 active;
70 u16 left_vol;
71 u16 right_vol;
72 u16 left_step;
73 u16 right_step;
74 unsigned int step_delay;
75 u16 ramp;
76 struct delayed_work work;
77 struct completion ramp_done;
78};
79
80struct twl6040_jack_data { 56struct twl6040_jack_data {
81 struct snd_soc_jack *jack; 57 struct snd_soc_jack *jack;
82 struct delayed_work work; 58 struct delayed_work work;
@@ -101,8 +77,6 @@ struct twl6040_data {
101 struct snd_soc_codec *codec; 77 struct snd_soc_codec *codec;
102 struct workqueue_struct *workqueue; 78 struct workqueue_struct *workqueue;
103 struct mutex mutex; 79 struct mutex mutex;
104 struct twl6040_output headset;
105 struct twl6040_output handsfree;
106}; 80};
107 81
108/* 82/*
@@ -312,318 +286,6 @@ static void twl6040_restore_regs(struct snd_soc_codec *codec)
312 } 286 }
313} 287}
314 288
315/*
316 * Ramp HS PGA volume to minimise pops at stream startup and shutdown.
317 */
318static inline int twl6040_hs_ramp_step(struct snd_soc_codec *codec,
319 unsigned int left_step, unsigned int right_step)
320{
321
322 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
323 struct twl6040_output *headset = &priv->headset;
324 int left_complete = 0, right_complete = 0;
325 u8 reg, val;
326
327 /* left channel */
328 left_step = (left_step > 0xF) ? 0xF : left_step;
329 reg = twl6040_read_reg_cache(codec, TWL6040_REG_HSGAIN);
330 val = (~reg & TWL6040_HSL_VOL_MASK);
331
332 if (headset->ramp == TWL6040_RAMP_UP) {
333 /* ramp step up */
334 if (val < headset->left_vol) {
335 if (val + left_step > headset->left_vol)
336 val = headset->left_vol;
337 else
338 val += left_step;
339
340 reg &= ~TWL6040_HSL_VOL_MASK;
341 twl6040_write(codec, TWL6040_REG_HSGAIN,
342 (reg | (~val & TWL6040_HSL_VOL_MASK)));
343 } else {
344 left_complete = 1;
345 }
346 } else if (headset->ramp == TWL6040_RAMP_DOWN) {
347 /* ramp step down */
348 if (val > 0x0) {
349 if ((int)val - (int)left_step < 0)
350 val = 0;
351 else
352 val -= left_step;
353
354 reg &= ~TWL6040_HSL_VOL_MASK;
355 twl6040_write(codec, TWL6040_REG_HSGAIN, reg |
356 (~val & TWL6040_HSL_VOL_MASK));
357 } else {
358 left_complete = 1;
359 }
360 }
361
362 /* right channel */
363 right_step = (right_step > 0xF) ? 0xF : right_step;
364 reg = twl6040_read_reg_cache(codec, TWL6040_REG_HSGAIN);
365 val = (~reg & TWL6040_HSR_VOL_MASK) >> TWL6040_HSR_VOL_SHIFT;
366
367 if (headset->ramp == TWL6040_RAMP_UP) {
368 /* ramp step up */
369 if (val < headset->right_vol) {
370 if (val + right_step > headset->right_vol)
371 val = headset->right_vol;
372 else
373 val += right_step;
374
375 reg &= ~TWL6040_HSR_VOL_MASK;
376 twl6040_write(codec, TWL6040_REG_HSGAIN,
377 (reg | (~val << TWL6040_HSR_VOL_SHIFT)));
378 } else {
379 right_complete = 1;
380 }
381 } else if (headset->ramp == TWL6040_RAMP_DOWN) {
382 /* ramp step down */
383 if (val > 0x0) {
384 if ((int)val - (int)right_step < 0)
385 val = 0;
386 else
387 val -= right_step;
388
389 reg &= ~TWL6040_HSR_VOL_MASK;
390 twl6040_write(codec, TWL6040_REG_HSGAIN,
391 reg | (~val << TWL6040_HSR_VOL_SHIFT));
392 } else {
393 right_complete = 1;
394 }
395 }
396
397 return left_complete & right_complete;
398}
399
400/*
401 * Ramp HF PGA volume to minimise pops at stream startup and shutdown.
402 */
403static inline int twl6040_hf_ramp_step(struct snd_soc_codec *codec,
404 unsigned int left_step, unsigned int right_step)
405{
406 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
407 struct twl6040_output *handsfree = &priv->handsfree;
408 int left_complete = 0, right_complete = 0;
409 u16 reg, val;
410
411 /* left channel */
412 left_step = (left_step > 0x1D) ? 0x1D : left_step;
413 reg = twl6040_read_reg_cache(codec, TWL6040_REG_HFLGAIN);
414 reg = 0x1D - reg;
415 val = (reg & TWL6040_HF_VOL_MASK);
416 if (handsfree->ramp == TWL6040_RAMP_UP) {
417 /* ramp step up */
418 if (val < handsfree->left_vol) {
419 if (val + left_step > handsfree->left_vol)
420 val = handsfree->left_vol;
421 else
422 val += left_step;
423
424 reg &= ~TWL6040_HF_VOL_MASK;
425 twl6040_write(codec, TWL6040_REG_HFLGAIN,
426 reg | (0x1D - val));
427 } else {
428 left_complete = 1;
429 }
430 } else if (handsfree->ramp == TWL6040_RAMP_DOWN) {
431 /* ramp step down */
432 if (val > 0) {
433 if ((int)val - (int)left_step < 0)
434 val = 0;
435 else
436 val -= left_step;
437
438 reg &= ~TWL6040_HF_VOL_MASK;
439 twl6040_write(codec, TWL6040_REG_HFLGAIN,
440 reg | (0x1D - val));
441 } else {
442 left_complete = 1;
443 }
444 }
445
446 /* right channel */
447 right_step = (right_step > 0x1D) ? 0x1D : right_step;
448 reg = twl6040_read_reg_cache(codec, TWL6040_REG_HFRGAIN);
449 reg = 0x1D - reg;
450 val = (reg & TWL6040_HF_VOL_MASK);
451 if (handsfree->ramp == TWL6040_RAMP_UP) {
452 /* ramp step up */
453 if (val < handsfree->right_vol) {
454 if (val + right_step > handsfree->right_vol)
455 val = handsfree->right_vol;
456 else
457 val += right_step;
458
459 reg &= ~TWL6040_HF_VOL_MASK;
460 twl6040_write(codec, TWL6040_REG_HFRGAIN,
461 reg | (0x1D - val));
462 } else {
463 right_complete = 1;
464 }
465 } else if (handsfree->ramp == TWL6040_RAMP_DOWN) {
466 /* ramp step down */
467 if (val > 0) {
468 if ((int)val - (int)right_step < 0)
469 val = 0;
470 else
471 val -= right_step;
472
473 reg &= ~TWL6040_HF_VOL_MASK;
474 twl6040_write(codec, TWL6040_REG_HFRGAIN,
475 reg | (0x1D - val));
476 }
477 }
478
479 return left_complete & right_complete;
480}
481
482/*
483 * This work ramps both output PGAs at stream start/stop time to
484 * minimise pop associated with DAPM power switching.
485 */
486static void twl6040_pga_hs_work(struct work_struct *work)
487{
488 struct twl6040_data *priv =
489 container_of(work, struct twl6040_data, headset.work.work);
490 struct snd_soc_codec *codec = priv->codec;
491 struct twl6040_output *headset = &priv->headset;
492 int i, headset_complete;
493
494 /* do we need to ramp at all ? */
495 if (headset->ramp == TWL6040_RAMP_NONE)
496 return;
497
498 /* HS PGA gain range: 0x0 - 0xf (0 - 15) */
499 for (i = 0; i < 16; i++) {
500 headset_complete = twl6040_hs_ramp_step(codec,
501 headset->left_step,
502 headset->right_step);
503
504 /* ramp finished ? */
505 if (headset_complete)
506 break;
507
508 schedule_timeout_interruptible(
509 msecs_to_jiffies(headset->step_delay));
510 }
511
512 if (headset->ramp == TWL6040_RAMP_DOWN) {
513 headset->active = 0;
514 complete(&headset->ramp_done);
515 } else {
516 headset->active = 1;
517 }
518 headset->ramp = TWL6040_RAMP_NONE;
519}
520
521static void twl6040_pga_hf_work(struct work_struct *work)
522{
523 struct twl6040_data *priv =
524 container_of(work, struct twl6040_data, handsfree.work.work);
525 struct snd_soc_codec *codec = priv->codec;
526 struct twl6040_output *handsfree = &priv->handsfree;
527 int i, handsfree_complete;
528
529 /* do we need to ramp at all ? */
530 if (handsfree->ramp == TWL6040_RAMP_NONE)
531 return;
532
533 /*
534 * HF PGA gain range: 0x00 - 0x1d (0 - 29) */
535 for (i = 0; i < 30; i++) {
536 handsfree_complete = twl6040_hf_ramp_step(codec,
537 handsfree->left_step,
538 handsfree->right_step);
539
540 /* ramp finished ? */
541 if (handsfree_complete)
542 break;
543
544 schedule_timeout_interruptible(
545 msecs_to_jiffies(handsfree->step_delay));
546 }
547
548
549 if (handsfree->ramp == TWL6040_RAMP_DOWN) {
550 handsfree->active = 0;
551 complete(&handsfree->ramp_done);
552 } else
553 handsfree->active = 1;
554 handsfree->ramp = TWL6040_RAMP_NONE;
555}
556
557static int out_drv_event(struct snd_soc_dapm_widget *w,
558 struct snd_kcontrol *kcontrol, int event)
559{
560 struct snd_soc_codec *codec = w->codec;
561 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
562 struct twl6040_output *out;
563 struct delayed_work *work;
564
565 switch (w->shift) {
566 case 2: /* Headset output driver */
567 out = &priv->headset;
568 work = &out->work;
569 /*
570 * Make sure, that we do not mess up variables for already
571 * executing work.
572 */
573 cancel_delayed_work_sync(work);
574
575 out->left_step = priv->hs_left_step;
576 out->right_step = priv->hs_right_step;
577 out->step_delay = 5; /* 5 ms between volume ramp steps */
578 break;
579 case 4: /* Handsfree output driver */
580 out = &priv->handsfree;
581 work = &out->work;
582 /*
583 * Make sure, that we do not mess up variables for already
584 * executing work.
585 */
586 cancel_delayed_work_sync(work);
587
588 out->left_step = priv->hf_left_step;
589 out->right_step = priv->hf_right_step;
590 out->step_delay = 5; /* 5 ms between volume ramp steps */
591 break;
592 default:
593 return -1;
594 }
595
596 switch (event) {
597 case SND_SOC_DAPM_POST_PMU:
598 if (out->active)
599 break;
600
601 /* don't use volume ramp for power-up */
602 out->ramp = TWL6040_RAMP_UP;
603 out->left_step = out->left_vol;
604 out->right_step = out->right_vol;
605
606 queue_delayed_work(priv->workqueue, work, msecs_to_jiffies(1));
607 break;
608
609 case SND_SOC_DAPM_PRE_PMD:
610 if (!out->active)
611 break;
612
613 /* use volume ramp for power-down */
614 out->ramp = TWL6040_RAMP_DOWN;
615 INIT_COMPLETION(out->ramp_done);
616
617 queue_delayed_work(priv->workqueue, work, msecs_to_jiffies(1));
618
619 wait_for_completion_timeout(&out->ramp_done,
620 msecs_to_jiffies(2000));
621 break;
622 }
623
624 return 0;
625}
626
627/* set headset dac and driver power mode */ 289/* set headset dac and driver power mode */
628static int headset_power_mode(struct snd_soc_codec *codec, int high_perf) 290static int headset_power_mode(struct snd_soc_codec *codec, int high_perf)
629{ 291{
@@ -748,71 +410,6 @@ static irqreturn_t twl6040_audio_handler(int irq, void *data)
748 return IRQ_HANDLED; 410 return IRQ_HANDLED;
749} 411}
750 412
751static int twl6040_put_volsw(struct snd_kcontrol *kcontrol,
752 struct snd_ctl_elem_value *ucontrol)
753{
754 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
755 struct twl6040_data *twl6040_priv = snd_soc_codec_get_drvdata(codec);
756 struct twl6040_output *out = NULL;
757 struct soc_mixer_control *mc =
758 (struct soc_mixer_control *)kcontrol->private_value;
759 int ret;
760
761 /* For HS and HF we shadow the values and only actually write
762 * them out when active in order to ensure the amplifier comes on
763 * as quietly as possible. */
764 switch (mc->reg) {
765 case TWL6040_REG_HSGAIN:
766 out = &twl6040_priv->headset;
767 break;
768 case TWL6040_REG_HFLGAIN:
769 out = &twl6040_priv->handsfree;
770 break;
771 default:
772 dev_warn(codec->dev, "%s: Unexpected register: 0x%02x\n",
773 __func__, mc->reg);
774 return -EINVAL;
775 }
776
777 out->left_vol = ucontrol->value.integer.value[0];
778 out->right_vol = ucontrol->value.integer.value[1];
779 if (!out->active)
780 return 1;
781
782 ret = snd_soc_put_volsw(kcontrol, ucontrol);
783 if (ret < 0)
784 return ret;
785
786 return 1;
787}
788
789static int twl6040_get_volsw(struct snd_kcontrol *kcontrol,
790 struct snd_ctl_elem_value *ucontrol)
791{
792 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
793 struct twl6040_data *twl6040_priv = snd_soc_codec_get_drvdata(codec);
794 struct twl6040_output *out = &twl6040_priv->headset;
795 struct soc_mixer_control *mc =
796 (struct soc_mixer_control *)kcontrol->private_value;
797
798 switch (mc->reg) {
799 case TWL6040_REG_HSGAIN:
800 out = &twl6040_priv->headset;
801 break;
802 case TWL6040_REG_HFLGAIN:
803 out = &twl6040_priv->handsfree;
804 break;
805 default:
806 dev_warn(codec->dev, "%s: Unexpected register: 0x%02x\n",
807 __func__, mc->reg);
808 return -EINVAL;
809 }
810
811 ucontrol->value.integer.value[0] = out->left_vol;
812 ucontrol->value.integer.value[1] = out->right_vol;
813 return 0;
814}
815
816static int twl6040_soc_dapm_put_vibra_enum(struct snd_kcontrol *kcontrol, 413static int twl6040_soc_dapm_put_vibra_enum(struct snd_kcontrol *kcontrol,
817 struct snd_ctl_elem_value *ucontrol) 414 struct snd_ctl_elem_value *ucontrol)
818{ 415{
@@ -1077,12 +674,10 @@ static const struct snd_kcontrol_new twl6040_snd_controls[] = {
1077 TWL6040_REG_LINEGAIN, 0, 3, 7, 0, afm_amp_tlv), 674 TWL6040_REG_LINEGAIN, 0, 3, 7, 0, afm_amp_tlv),
1078 675
1079 /* Playback gains */ 676 /* Playback gains */
1080 SOC_DOUBLE_EXT_TLV("Headset Playback Volume", 677 SOC_DOUBLE_TLV("Headset Playback Volume",
1081 TWL6040_REG_HSGAIN, 0, 4, 0xF, 1, twl6040_get_volsw, 678 TWL6040_REG_HSGAIN, 0, 4, 0xF, 1, hs_tlv),
1082 twl6040_put_volsw, hs_tlv), 679 SOC_DOUBLE_R_TLV("Handsfree Playback Volume",
1083 SOC_DOUBLE_R_EXT_TLV("Handsfree Playback Volume", 680 TWL6040_REG_HFLGAIN, TWL6040_REG_HFRGAIN, 0, 0x1D, 1, hf_tlv),
1084 TWL6040_REG_HFLGAIN, TWL6040_REG_HFRGAIN, 0, 0x1D, 1,
1085 twl6040_get_volsw, twl6040_put_volsw, hf_tlv),
1086 SOC_SINGLE_TLV("Earphone Playback Volume", 681 SOC_SINGLE_TLV("Earphone Playback Volume",
1087 TWL6040_REG_EARCTL, 1, 0xF, 1, ep_tlv), 682 TWL6040_REG_EARCTL, 1, 0xF, 1, ep_tlv),
1088 683
@@ -1181,22 +776,14 @@ static const struct snd_soc_dapm_widget twl6040_dapm_widgets[] = {
1181 &auxr_switch_control), 776 &auxr_switch_control),
1182 777
1183 /* Analog playback drivers */ 778 /* Analog playback drivers */
1184 SND_SOC_DAPM_OUT_DRV_E("HF Left Driver", 779 SND_SOC_DAPM_OUT_DRV("HF Left Driver",
1185 TWL6040_REG_HFLCTL, 4, 0, NULL, 0, 780 TWL6040_REG_HFLCTL, 4, 0, NULL, 0),
1186 out_drv_event, 781 SND_SOC_DAPM_OUT_DRV("HF Right Driver",
1187 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), 782 TWL6040_REG_HFRCTL, 4, 0, NULL, 0),
1188 SND_SOC_DAPM_OUT_DRV_E("HF Right Driver", 783 SND_SOC_DAPM_OUT_DRV("HS Left Driver",
1189 TWL6040_REG_HFRCTL, 4, 0, NULL, 0, 784 TWL6040_REG_HSLCTL, 2, 0, NULL, 0),
1190 out_drv_event, 785 SND_SOC_DAPM_OUT_DRV("HS Right Driver",
1191 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), 786 TWL6040_REG_HSRCTL, 2, 0, NULL, 0),
1192 SND_SOC_DAPM_OUT_DRV_E("HS Left Driver",
1193 TWL6040_REG_HSLCTL, 2, 0, NULL, 0,
1194 out_drv_event,
1195 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
1196 SND_SOC_DAPM_OUT_DRV_E("HS Right Driver",
1197 TWL6040_REG_HSRCTL, 2, 0, NULL, 0,
1198 out_drv_event,
1199 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
1200 SND_SOC_DAPM_OUT_DRV_E("Earphone Driver", 787 SND_SOC_DAPM_OUT_DRV_E("Earphone Driver",
1201 TWL6040_REG_EARCTL, 0, 0, NULL, 0, 788 TWL6040_REG_EARCTL, 0, 0, NULL, 0,
1202 twl6040_ep_drv_event, 789 twl6040_ep_drv_event,
@@ -1340,8 +927,7 @@ static int twl6040_set_bias_level(struct snd_soc_codec *codec,
1340static int twl6040_startup(struct snd_pcm_substream *substream, 927static int twl6040_startup(struct snd_pcm_substream *substream,
1341 struct snd_soc_dai *dai) 928 struct snd_soc_dai *dai)
1342{ 929{
1343 struct snd_soc_pcm_runtime *rtd = substream->private_data; 930 struct snd_soc_codec *codec = dai->codec;
1344 struct snd_soc_codec *codec = rtd->codec;
1345 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); 931 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
1346 932
1347 snd_pcm_hw_constraint_list(substream->runtime, 0, 933 snd_pcm_hw_constraint_list(substream->runtime, 0,
@@ -1355,8 +941,7 @@ static int twl6040_hw_params(struct snd_pcm_substream *substream,
1355 struct snd_pcm_hw_params *params, 941 struct snd_pcm_hw_params *params,
1356 struct snd_soc_dai *dai) 942 struct snd_soc_dai *dai)
1357{ 943{
1358 struct snd_soc_pcm_runtime *rtd = substream->private_data; 944 struct snd_soc_codec *codec = dai->codec;
1359 struct snd_soc_codec *codec = rtd->codec;
1360 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); 945 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
1361 int rate; 946 int rate;
1362 947
@@ -1392,8 +977,7 @@ static int twl6040_hw_params(struct snd_pcm_substream *substream,
1392static int twl6040_prepare(struct snd_pcm_substream *substream, 977static int twl6040_prepare(struct snd_pcm_substream *substream,
1393 struct snd_soc_dai *dai) 978 struct snd_soc_dai *dai)
1394{ 979{
1395 struct snd_soc_pcm_runtime *rtd = substream->private_data; 980 struct snd_soc_codec *codec = dai->codec;
1396 struct snd_soc_codec *codec = rtd->codec;
1397 struct twl6040 *twl6040 = codec->control_data; 981 struct twl6040 *twl6040 = codec->control_data;
1398 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); 982 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
1399 int ret; 983 int ret;
@@ -1528,7 +1112,7 @@ static int twl6040_resume(struct snd_soc_codec *codec)
1528static int twl6040_probe(struct snd_soc_codec *codec) 1112static int twl6040_probe(struct snd_soc_codec *codec)
1529{ 1113{
1530 struct twl6040_data *priv; 1114 struct twl6040_data *priv;
1531 struct twl4030_codec_data *pdata = dev_get_platdata(codec->dev); 1115 struct twl6040_codec_data *pdata = dev_get_platdata(codec->dev);
1532 struct platform_device *pdev = container_of(codec->dev, 1116 struct platform_device *pdev = container_of(codec->dev,
1533 struct platform_device, dev); 1117 struct platform_device, dev);
1534 int ret = 0; 1118 int ret = 0;
@@ -1571,14 +1155,9 @@ static int twl6040_probe(struct snd_soc_codec *codec)
1571 } 1155 }
1572 1156
1573 INIT_DELAYED_WORK(&priv->hs_jack.work, twl6040_accessory_work); 1157 INIT_DELAYED_WORK(&priv->hs_jack.work, twl6040_accessory_work);
1574 INIT_DELAYED_WORK(&priv->headset.work, twl6040_pga_hs_work);
1575 INIT_DELAYED_WORK(&priv->handsfree.work, twl6040_pga_hf_work);
1576 1158
1577 mutex_init(&priv->mutex); 1159 mutex_init(&priv->mutex);
1578 1160
1579 init_completion(&priv->headset.ramp_done);
1580 init_completion(&priv->handsfree.ramp_done);
1581
1582 ret = request_threaded_irq(priv->plug_irq, NULL, twl6040_audio_handler, 1161 ret = request_threaded_irq(priv->plug_irq, NULL, twl6040_audio_handler,
1583 0, "twl6040_irq_plug", codec); 1162 0, "twl6040_irq_plug", codec);
1584 if (ret) { 1163 if (ret) {
diff --git a/sound/soc/codecs/uda134x.c b/sound/soc/codecs/uda134x.c
index 797b0dde2c68..6c3d43b8ee85 100644
--- a/sound/soc/codecs/uda134x.c
+++ b/sound/soc/codecs/uda134x.c
@@ -159,8 +159,7 @@ static int uda134x_mute(struct snd_soc_dai *dai, int mute)
159static int uda134x_startup(struct snd_pcm_substream *substream, 159static int uda134x_startup(struct snd_pcm_substream *substream,
160 struct snd_soc_dai *dai) 160 struct snd_soc_dai *dai)
161{ 161{
162 struct snd_soc_pcm_runtime *rtd = substream->private_data; 162 struct snd_soc_codec *codec = dai->codec;
163 struct snd_soc_codec *codec =rtd->codec;
164 struct uda134x_priv *uda134x = snd_soc_codec_get_drvdata(codec); 163 struct uda134x_priv *uda134x = snd_soc_codec_get_drvdata(codec);
165 struct snd_pcm_runtime *master_runtime; 164 struct snd_pcm_runtime *master_runtime;
166 165
@@ -191,8 +190,7 @@ static int uda134x_startup(struct snd_pcm_substream *substream,
191static void uda134x_shutdown(struct snd_pcm_substream *substream, 190static void uda134x_shutdown(struct snd_pcm_substream *substream,
192 struct snd_soc_dai *dai) 191 struct snd_soc_dai *dai)
193{ 192{
194 struct snd_soc_pcm_runtime *rtd = substream->private_data; 193 struct snd_soc_codec *codec = dai->codec;
195 struct snd_soc_codec *codec = rtd->codec;
196 struct uda134x_priv *uda134x = snd_soc_codec_get_drvdata(codec); 194 struct uda134x_priv *uda134x = snd_soc_codec_get_drvdata(codec);
197 195
198 if (uda134x->master_substream == substream) 196 if (uda134x->master_substream == substream)
diff --git a/sound/soc/codecs/uda1380.c b/sound/soc/codecs/uda1380.c
index 4f1b23d7e404..2502214b84ab 100644
--- a/sound/soc/codecs/uda1380.c
+++ b/sound/soc/codecs/uda1380.c
@@ -502,8 +502,7 @@ static int uda1380_set_dai_fmt_capture(struct snd_soc_dai *codec_dai,
502static int uda1380_trigger(struct snd_pcm_substream *substream, int cmd, 502static int uda1380_trigger(struct snd_pcm_substream *substream, int cmd,
503 struct snd_soc_dai *dai) 503 struct snd_soc_dai *dai)
504{ 504{
505 struct snd_soc_pcm_runtime *rtd = substream->private_data; 505 struct snd_soc_codec *codec = dai->codec;
506 struct snd_soc_codec *codec = rtd->codec;
507 struct uda1380_priv *uda1380 = snd_soc_codec_get_drvdata(codec); 506 struct uda1380_priv *uda1380 = snd_soc_codec_get_drvdata(codec);
508 int mixer = uda1380_read_reg_cache(codec, UDA1380_MIXER); 507 int mixer = uda1380_read_reg_cache(codec, UDA1380_MIXER);
509 508
@@ -528,8 +527,7 @@ static int uda1380_pcm_hw_params(struct snd_pcm_substream *substream,
528 struct snd_pcm_hw_params *params, 527 struct snd_pcm_hw_params *params,
529 struct snd_soc_dai *dai) 528 struct snd_soc_dai *dai)
530{ 529{
531 struct snd_soc_pcm_runtime *rtd = substream->private_data; 530 struct snd_soc_codec *codec = dai->codec;
532 struct snd_soc_codec *codec = rtd->codec;
533 u16 clk = uda1380_read_reg_cache(codec, UDA1380_CLK); 531 u16 clk = uda1380_read_reg_cache(codec, UDA1380_CLK);
534 532
535 /* set WSPLL power and divider if running from this clock */ 533 /* set WSPLL power and divider if running from this clock */
diff --git a/sound/soc/codecs/wl1273.c b/sound/soc/codecs/wl1273.c
index 3d868dc40092..7b24d6d192e1 100644
--- a/sound/soc/codecs/wl1273.c
+++ b/sound/soc/codecs/wl1273.c
@@ -293,8 +293,7 @@ static const struct snd_kcontrol_new wl1273_controls[] = {
293static int wl1273_startup(struct snd_pcm_substream *substream, 293static int wl1273_startup(struct snd_pcm_substream *substream,
294 struct snd_soc_dai *dai) 294 struct snd_soc_dai *dai)
295{ 295{
296 struct snd_soc_pcm_runtime *rtd = substream->private_data; 296 struct snd_soc_codec *codec = dai->codec;
297 struct snd_soc_codec *codec = rtd->codec;
298 struct wl1273_priv *wl1273 = snd_soc_codec_get_drvdata(codec); 297 struct wl1273_priv *wl1273 = snd_soc_codec_get_drvdata(codec);
299 298
300 switch (wl1273->mode) { 299 switch (wl1273->mode) {
@@ -329,8 +328,7 @@ static int wl1273_hw_params(struct snd_pcm_substream *substream,
329 struct snd_pcm_hw_params *params, 328 struct snd_pcm_hw_params *params,
330 struct snd_soc_dai *dai) 329 struct snd_soc_dai *dai)
331{ 330{
332 struct snd_soc_pcm_runtime *rtd = substream->private_data; 331 struct wl1273_priv *wl1273 = snd_soc_codec_get_drvdata(dai->codec);
333 struct wl1273_priv *wl1273 = snd_soc_codec_get_drvdata(rtd->codec);
334 struct wl1273_core *core = wl1273->core; 332 struct wl1273_core *core = wl1273->core;
335 unsigned int rate, width, r; 333 unsigned int rate, width, r;
336 334
diff --git a/sound/soc/codecs/wm1250-ev1.c b/sound/soc/codecs/wm1250-ev1.c
index aefb4f89be0e..e0b51e9f8b12 100644
--- a/sound/soc/codecs/wm1250-ev1.c
+++ b/sound/soc/codecs/wm1250-ev1.c
@@ -79,22 +79,65 @@ static const struct snd_soc_dapm_route wm1250_ev1_dapm_routes[] = {
79 { "WM1250 Output", NULL, "DAC" }, 79 { "WM1250 Output", NULL, "DAC" },
80}; 80};
81 81
82static int wm1250_ev1_hw_params(struct snd_pcm_substream *substream,
83 struct snd_pcm_hw_params *params,
84 struct snd_soc_dai *dai)
85{
86 struct wm1250_priv *wm1250 = snd_soc_codec_get_drvdata(dai->codec);
87
88 switch (params_rate(params)) {
89 case 8000:
90 gpio_set_value(wm1250->gpios[WM1250_EV1_GPIO_CLK_SEL0].gpio,
91 1);
92 gpio_set_value(wm1250->gpios[WM1250_EV1_GPIO_CLK_SEL1].gpio,
93 1);
94 break;
95 case 16000:
96 gpio_set_value(wm1250->gpios[WM1250_EV1_GPIO_CLK_SEL0].gpio,
97 0);
98 gpio_set_value(wm1250->gpios[WM1250_EV1_GPIO_CLK_SEL1].gpio,
99 1);
100 break;
101 case 32000:
102 gpio_set_value(wm1250->gpios[WM1250_EV1_GPIO_CLK_SEL0].gpio,
103 1);
104 gpio_set_value(wm1250->gpios[WM1250_EV1_GPIO_CLK_SEL1].gpio,
105 0);
106 break;
107 case 64000:
108 gpio_set_value(wm1250->gpios[WM1250_EV1_GPIO_CLK_SEL0].gpio,
109 0);
110 gpio_set_value(wm1250->gpios[WM1250_EV1_GPIO_CLK_SEL1].gpio,
111 0);
112 break;
113 default:
114 return -EINVAL;
115 }
116
117 return 0;
118}
119
120static const struct snd_soc_dai_ops wm1250_ev1_ops = {
121 .hw_params = wm1250_ev1_hw_params,
122};
123
82static struct snd_soc_dai_driver wm1250_ev1_dai = { 124static struct snd_soc_dai_driver wm1250_ev1_dai = {
83 .name = "wm1250-ev1", 125 .name = "wm1250-ev1",
84 .playback = { 126 .playback = {
85 .stream_name = "Playback", 127 .stream_name = "Playback",
86 .channels_min = 1, 128 .channels_min = 1,
87 .channels_max = 1, 129 .channels_max = 2,
88 .rates = SNDRV_PCM_RATE_8000, 130 .rates = SNDRV_PCM_RATE_8000,
89 .formats = SNDRV_PCM_FMTBIT_S16_LE, 131 .formats = SNDRV_PCM_FMTBIT_S16_LE,
90 }, 132 },
91 .capture = { 133 .capture = {
92 .stream_name = "Capture", 134 .stream_name = "Capture",
93 .channels_min = 1, 135 .channels_min = 1,
94 .channels_max = 1, 136 .channels_max = 2,
95 .rates = SNDRV_PCM_RATE_8000, 137 .rates = SNDRV_PCM_RATE_8000,
96 .formats = SNDRV_PCM_FMTBIT_S16_LE, 138 .formats = SNDRV_PCM_FMTBIT_S16_LE,
97 }, 139 },
140 .ops = &wm1250_ev1_ops,
98}; 141};
99 142
100static struct snd_soc_codec_driver soc_codec_dev_wm1250_ev1 = { 143static struct snd_soc_codec_driver soc_codec_dev_wm1250_ev1 = {
@@ -215,23 +258,7 @@ static struct i2c_driver wm1250_ev1_i2c_driver = {
215 .id_table = wm1250_ev1_i2c_id, 258 .id_table = wm1250_ev1_i2c_id,
216}; 259};
217 260
218static int __init wm1250_ev1_modinit(void) 261module_i2c_driver(wm1250_ev1_i2c_driver);
219{
220 int ret = 0;
221
222 ret = i2c_add_driver(&wm1250_ev1_i2c_driver);
223 if (ret != 0)
224 pr_err("Failed to register WM1250-EV1 I2C driver: %d\n", ret);
225
226 return ret;
227}
228module_init(wm1250_ev1_modinit);
229
230static void __exit wm1250_ev1_exit(void)
231{
232 i2c_del_driver(&wm1250_ev1_i2c_driver);
233}
234module_exit(wm1250_ev1_exit);
235 262
236MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); 263MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
237MODULE_DESCRIPTION("WM1250-EV1 audio I/O module driver"); 264MODULE_DESCRIPTION("WM1250-EV1 audio I/O module driver");
diff --git a/sound/soc/codecs/wm5100-tables.c b/sound/soc/codecs/wm5100-tables.c
index 9a18fae68204..e167207a19cc 100644
--- a/sound/soc/codecs/wm5100-tables.c
+++ b/sound/soc/codecs/wm5100-tables.c
@@ -32,7 +32,18 @@ bool wm5100_volatile_register(struct device *dev, unsigned int reg)
32 case WM5100_MIC_DETECT_3: 32 case WM5100_MIC_DETECT_3:
33 return 1; 33 return 1;
34 default: 34 default:
35 return 0; 35 if ((reg >= WM5100_DSP1_PM_0 && reg <= WM5100_DSP1_PM_1535) ||
36 (reg >= WM5100_DSP1_ZM_0 && reg <= WM5100_DSP1_ZM_2047) ||
37 (reg >= WM5100_DSP1_DM_0 && reg <= WM5100_DSP1_DM_511) ||
38 (reg >= WM5100_DSP2_PM_0 && reg <= WM5100_DSP2_PM_1535) ||
39 (reg >= WM5100_DSP2_ZM_0 && reg <= WM5100_DSP2_ZM_2047) ||
40 (reg >= WM5100_DSP2_DM_0 && reg <= WM5100_DSP2_DM_511) ||
41 (reg >= WM5100_DSP3_PM_0 && reg <= WM5100_DSP3_PM_1535) ||
42 (reg >= WM5100_DSP3_ZM_0 && reg <= WM5100_DSP3_ZM_2047) ||
43 (reg >= WM5100_DSP3_DM_0 && reg <= WM5100_DSP3_DM_511))
44 return 1;
45 else
46 return 0;
36 } 47 }
37} 48}
38 49
@@ -697,9 +708,110 @@ bool wm5100_readable_register(struct device *dev, unsigned int reg)
697 case WM5100_HPLPF3_2: 708 case WM5100_HPLPF3_2:
698 case WM5100_HPLPF4_1: 709 case WM5100_HPLPF4_1:
699 case WM5100_HPLPF4_2: 710 case WM5100_HPLPF4_2:
711 case WM5100_DSP1_CONTROL_1:
712 case WM5100_DSP1_CONTROL_2:
713 case WM5100_DSP1_CONTROL_3:
714 case WM5100_DSP1_CONTROL_4:
715 case WM5100_DSP1_CONTROL_5:
716 case WM5100_DSP1_CONTROL_6:
717 case WM5100_DSP1_CONTROL_7:
718 case WM5100_DSP1_CONTROL_8:
719 case WM5100_DSP1_CONTROL_9:
720 case WM5100_DSP1_CONTROL_10:
721 case WM5100_DSP1_CONTROL_11:
722 case WM5100_DSP1_CONTROL_12:
723 case WM5100_DSP1_CONTROL_13:
724 case WM5100_DSP1_CONTROL_14:
725 case WM5100_DSP1_CONTROL_15:
726 case WM5100_DSP1_CONTROL_16:
727 case WM5100_DSP1_CONTROL_17:
728 case WM5100_DSP1_CONTROL_18:
729 case WM5100_DSP1_CONTROL_19:
730 case WM5100_DSP1_CONTROL_20:
731 case WM5100_DSP1_CONTROL_21:
732 case WM5100_DSP1_CONTROL_22:
733 case WM5100_DSP1_CONTROL_23:
734 case WM5100_DSP1_CONTROL_24:
735 case WM5100_DSP1_CONTROL_25:
736 case WM5100_DSP1_CONTROL_26:
737 case WM5100_DSP1_CONTROL_27:
738 case WM5100_DSP1_CONTROL_28:
739 case WM5100_DSP1_CONTROL_29:
740 case WM5100_DSP1_CONTROL_30:
741 case WM5100_DSP2_CONTROL_1:
742 case WM5100_DSP2_CONTROL_2:
743 case WM5100_DSP2_CONTROL_3:
744 case WM5100_DSP2_CONTROL_4:
745 case WM5100_DSP2_CONTROL_5:
746 case WM5100_DSP2_CONTROL_6:
747 case WM5100_DSP2_CONTROL_7:
748 case WM5100_DSP2_CONTROL_8:
749 case WM5100_DSP2_CONTROL_9:
750 case WM5100_DSP2_CONTROL_10:
751 case WM5100_DSP2_CONTROL_11:
752 case WM5100_DSP2_CONTROL_12:
753 case WM5100_DSP2_CONTROL_13:
754 case WM5100_DSP2_CONTROL_14:
755 case WM5100_DSP2_CONTROL_15:
756 case WM5100_DSP2_CONTROL_16:
757 case WM5100_DSP2_CONTROL_17:
758 case WM5100_DSP2_CONTROL_18:
759 case WM5100_DSP2_CONTROL_19:
760 case WM5100_DSP2_CONTROL_20:
761 case WM5100_DSP2_CONTROL_21:
762 case WM5100_DSP2_CONTROL_22:
763 case WM5100_DSP2_CONTROL_23:
764 case WM5100_DSP2_CONTROL_24:
765 case WM5100_DSP2_CONTROL_25:
766 case WM5100_DSP2_CONTROL_26:
767 case WM5100_DSP2_CONTROL_27:
768 case WM5100_DSP2_CONTROL_28:
769 case WM5100_DSP2_CONTROL_29:
770 case WM5100_DSP2_CONTROL_30:
771 case WM5100_DSP3_CONTROL_1:
772 case WM5100_DSP3_CONTROL_2:
773 case WM5100_DSP3_CONTROL_3:
774 case WM5100_DSP3_CONTROL_4:
775 case WM5100_DSP3_CONTROL_5:
776 case WM5100_DSP3_CONTROL_6:
777 case WM5100_DSP3_CONTROL_7:
778 case WM5100_DSP3_CONTROL_8:
779 case WM5100_DSP3_CONTROL_9:
780 case WM5100_DSP3_CONTROL_10:
781 case WM5100_DSP3_CONTROL_11:
782 case WM5100_DSP3_CONTROL_12:
783 case WM5100_DSP3_CONTROL_13:
784 case WM5100_DSP3_CONTROL_14:
785 case WM5100_DSP3_CONTROL_15:
786 case WM5100_DSP3_CONTROL_16:
787 case WM5100_DSP3_CONTROL_17:
788 case WM5100_DSP3_CONTROL_18:
789 case WM5100_DSP3_CONTROL_19:
790 case WM5100_DSP3_CONTROL_20:
791 case WM5100_DSP3_CONTROL_21:
792 case WM5100_DSP3_CONTROL_22:
793 case WM5100_DSP3_CONTROL_23:
794 case WM5100_DSP3_CONTROL_24:
795 case WM5100_DSP3_CONTROL_25:
796 case WM5100_DSP3_CONTROL_26:
797 case WM5100_DSP3_CONTROL_27:
798 case WM5100_DSP3_CONTROL_28:
799 case WM5100_DSP3_CONTROL_29:
800 case WM5100_DSP3_CONTROL_30:
700 return 1; 801 return 1;
701 default: 802 default:
702 return 0; 803 if ((reg >= WM5100_DSP1_PM_0 && reg <= WM5100_DSP1_PM_1535) ||
804 (reg >= WM5100_DSP1_ZM_0 && reg <= WM5100_DSP1_ZM_2047) ||
805 (reg >= WM5100_DSP1_DM_0 && reg <= WM5100_DSP1_DM_511) ||
806 (reg >= WM5100_DSP2_PM_0 && reg <= WM5100_DSP2_PM_1535) ||
807 (reg >= WM5100_DSP2_ZM_0 && reg <= WM5100_DSP2_ZM_2047) ||
808 (reg >= WM5100_DSP2_DM_0 && reg <= WM5100_DSP2_DM_511) ||
809 (reg >= WM5100_DSP3_PM_0 && reg <= WM5100_DSP3_PM_1535) ||
810 (reg >= WM5100_DSP3_ZM_0 && reg <= WM5100_DSP3_ZM_2047) ||
811 (reg >= WM5100_DSP3_DM_0 && reg <= WM5100_DSP3_DM_511))
812 return 1;
813 else
814 return 0;
703 } 815 }
704} 816}
705 817
@@ -1361,4 +1473,13 @@ struct reg_default wm5100_reg_defaults[WM5100_REGISTER_COUNT] = {
1361 { 0x0EC9, 0x0000 }, /* R3785 - HPLPF3_2 */ 1473 { 0x0EC9, 0x0000 }, /* R3785 - HPLPF3_2 */
1362 { 0x0ECC, 0x0000 }, /* R3788 - HPLPF4_1 */ 1474 { 0x0ECC, 0x0000 }, /* R3788 - HPLPF4_1 */
1363 { 0x0ECD, 0x0000 }, /* R3789 - HPLPF4_2 */ 1475 { 0x0ECD, 0x0000 }, /* R3789 - HPLPF4_2 */
1476 { 0x0F02, 0x0000 }, /* R3842 - DSP1 Control 2 */
1477 { 0x0F03, 0x0000 }, /* R3843 - DSP1 Control 3 */
1478 { 0x0F04, 0x0000 }, /* R3844 - DSP1 Control 4 */
1479 { 0x1002, 0x0000 }, /* R4098 - DSP2 Control 2 */
1480 { 0x1003, 0x0000 }, /* R4099 - DSP2 Control 3 */
1481 { 0x1004, 0x0000 }, /* R4100 - DSP2 Control 4 */
1482 { 0x1102, 0x0000 }, /* R4354 - DSP3 Control 2 */
1483 { 0x1103, 0x0000 }, /* R4355 - DSP3 Control 3 */
1484 { 0x1104, 0x0000 }, /* R4356 - DSP3 Control 4 */
1364}; 1485};
diff --git a/sound/soc/codecs/wm5100.c b/sound/soc/codecs/wm5100.c
index b9c185ce64e4..cb6d5372103a 100644
--- a/sound/soc/codecs/wm5100.c
+++ b/sound/soc/codecs/wm5100.c
@@ -1265,29 +1265,12 @@ static const __devinitdata struct reg_default wm5100_reva_patches[] = {
1265 { WM5100_AUDIO_IF_3_19, 1 }, 1265 { WM5100_AUDIO_IF_3_19, 1 },
1266}; 1266};
1267 1267
1268static int wm5100_dai_to_base(struct snd_soc_dai *dai)
1269{
1270 switch (dai->id) {
1271 case 0:
1272 return WM5100_AUDIO_IF_1_1 - 1;
1273 case 1:
1274 return WM5100_AUDIO_IF_2_1 - 1;
1275 case 2:
1276 return WM5100_AUDIO_IF_3_1 - 1;
1277 default:
1278 BUG();
1279 return -EINVAL;
1280 }
1281}
1282
1283static int wm5100_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) 1268static int wm5100_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
1284{ 1269{
1285 struct snd_soc_codec *codec = dai->codec; 1270 struct snd_soc_codec *codec = dai->codec;
1286 int lrclk, bclk, mask, base; 1271 int lrclk, bclk, mask, base;
1287 1272
1288 base = wm5100_dai_to_base(dai); 1273 base = dai->driver->base;
1289 if (base < 0)
1290 return base;
1291 1274
1292 lrclk = 0; 1275 lrclk = 0;
1293 bclk = 0; 1276 bclk = 0;
@@ -1414,9 +1397,7 @@ static int wm5100_hw_params(struct snd_pcm_substream *substream,
1414 int i, base, bclk, aif_rate, lrclk, wl, fl, sr; 1397 int i, base, bclk, aif_rate, lrclk, wl, fl, sr;
1415 int *bclk_rates; 1398 int *bclk_rates;
1416 1399
1417 base = wm5100_dai_to_base(dai); 1400 base = dai->driver->base;
1418 if (base < 0)
1419 return base;
1420 1401
1421 /* Data sizes if not using TDM */ 1402 /* Data sizes if not using TDM */
1422 wl = snd_pcm_format_width(params_format(params)); 1403 wl = snd_pcm_format_width(params_format(params));
@@ -1897,6 +1878,7 @@ static int wm5100_set_fll(struct snd_soc_codec *codec, int fll_id, int source,
1897static struct snd_soc_dai_driver wm5100_dai[] = { 1878static struct snd_soc_dai_driver wm5100_dai[] = {
1898 { 1879 {
1899 .name = "wm5100-aif1", 1880 .name = "wm5100-aif1",
1881 .base = WM5100_AUDIO_IF_1_1 - 1,
1900 .playback = { 1882 .playback = {
1901 .stream_name = "AIF1 Playback", 1883 .stream_name = "AIF1 Playback",
1902 .channels_min = 2, 1884 .channels_min = 2,
@@ -1916,6 +1898,7 @@ static struct snd_soc_dai_driver wm5100_dai[] = {
1916 { 1898 {
1917 .name = "wm5100-aif2", 1899 .name = "wm5100-aif2",
1918 .id = 1, 1900 .id = 1,
1901 .base = WM5100_AUDIO_IF_2_1 - 1,
1919 .playback = { 1902 .playback = {
1920 .stream_name = "AIF2 Playback", 1903 .stream_name = "AIF2 Playback",
1921 .channels_min = 2, 1904 .channels_min = 2,
@@ -1935,6 +1918,7 @@ static struct snd_soc_dai_driver wm5100_dai[] = {
1935 { 1918 {
1936 .name = "wm5100-aif3", 1919 .name = "wm5100-aif3",
1937 .id = 2, 1920 .id = 2,
1921 .base = WM5100_AUDIO_IF_3_1 - 1,
1938 .playback = { 1922 .playback = {
1939 .stream_name = "AIF3 Playback", 1923 .stream_name = "AIF3 Playback",
1940 .channels_min = 2, 1924 .channels_min = 2,
@@ -2454,7 +2438,7 @@ static __devinit int wm5100_i2c_probe(struct i2c_client *i2c,
2454 2438
2455 wm5100->dev = &i2c->dev; 2439 wm5100->dev = &i2c->dev;
2456 2440
2457 wm5100->regmap = regmap_init_i2c(i2c, &wm5100_regmap); 2441 wm5100->regmap = devm_regmap_init_i2c(i2c, &wm5100_regmap);
2458 if (IS_ERR(wm5100->regmap)) { 2442 if (IS_ERR(wm5100->regmap)) {
2459 ret = PTR_ERR(wm5100->regmap); 2443 ret = PTR_ERR(wm5100->regmap);
2460 dev_err(&i2c->dev, "Failed to allocate register map: %d\n", 2444 dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
@@ -2479,7 +2463,7 @@ static __devinit int wm5100_i2c_probe(struct i2c_client *i2c,
2479 if (ret != 0) { 2463 if (ret != 0) {
2480 dev_err(&i2c->dev, "Failed to request core supplies: %d\n", 2464 dev_err(&i2c->dev, "Failed to request core supplies: %d\n",
2481 ret); 2465 ret);
2482 goto err_regmap; 2466 goto err;
2483 } 2467 }
2484 2468
2485 ret = regulator_bulk_enable(ARRAY_SIZE(wm5100->core_supplies), 2469 ret = regulator_bulk_enable(ARRAY_SIZE(wm5100->core_supplies),
@@ -2487,7 +2471,7 @@ static __devinit int wm5100_i2c_probe(struct i2c_client *i2c,
2487 if (ret != 0) { 2471 if (ret != 0) {
2488 dev_err(&i2c->dev, "Failed to enable core supplies: %d\n", 2472 dev_err(&i2c->dev, "Failed to enable core supplies: %d\n",
2489 ret); 2473 ret);
2490 goto err_regmap; 2474 goto err;
2491 } 2475 }
2492 2476
2493 if (wm5100->pdata.ldo_ena) { 2477 if (wm5100->pdata.ldo_ena) {
@@ -2660,8 +2644,6 @@ err_ldo:
2660err_enable: 2644err_enable:
2661 regulator_bulk_disable(ARRAY_SIZE(wm5100->core_supplies), 2645 regulator_bulk_disable(ARRAY_SIZE(wm5100->core_supplies),
2662 wm5100->core_supplies); 2646 wm5100->core_supplies);
2663err_regmap:
2664 regmap_exit(wm5100->regmap);
2665err: 2647err:
2666 return ret; 2648 return ret;
2667} 2649}
@@ -2682,7 +2664,6 @@ static __devexit int wm5100_i2c_remove(struct i2c_client *i2c)
2682 gpio_set_value_cansleep(wm5100->pdata.ldo_ena, 0); 2664 gpio_set_value_cansleep(wm5100->pdata.ldo_ena, 0);
2683 gpio_free(wm5100->pdata.ldo_ena); 2665 gpio_free(wm5100->pdata.ldo_ena);
2684 } 2666 }
2685 regmap_exit(wm5100->regmap);
2686 2667
2687 return 0; 2668 return 0;
2688} 2669}
@@ -2749,17 +2730,7 @@ static struct i2c_driver wm5100_i2c_driver = {
2749 .id_table = wm5100_i2c_id, 2730 .id_table = wm5100_i2c_id,
2750}; 2731};
2751 2732
2752static int __init wm5100_modinit(void) 2733module_i2c_driver(wm5100_i2c_driver);
2753{
2754 return i2c_add_driver(&wm5100_i2c_driver);
2755}
2756module_init(wm5100_modinit);
2757
2758static void __exit wm5100_exit(void)
2759{
2760 i2c_del_driver(&wm5100_i2c_driver);
2761}
2762module_exit(wm5100_exit);
2763 2734
2764MODULE_DESCRIPTION("ASoC WM5100 driver"); 2735MODULE_DESCRIPTION("ASoC WM5100 driver");
2765MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); 2736MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
diff --git a/sound/soc/codecs/wm5100.h b/sound/soc/codecs/wm5100.h
index 25cb6016f9d7..935a9b7fb274 100644
--- a/sound/soc/codecs/wm5100.h
+++ b/sound/soc/codecs/wm5100.h
@@ -709,6 +709,96 @@ int wm5100_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack);
709#define WM5100_HPLPF3_2 0xEC9 709#define WM5100_HPLPF3_2 0xEC9
710#define WM5100_HPLPF4_1 0xECC 710#define WM5100_HPLPF4_1 0xECC
711#define WM5100_HPLPF4_2 0xECD 711#define WM5100_HPLPF4_2 0xECD
712#define WM5100_DSP1_CONTROL_1 0xF00
713#define WM5100_DSP1_CONTROL_2 0xF02
714#define WM5100_DSP1_CONTROL_3 0xF03
715#define WM5100_DSP1_CONTROL_4 0xF04
716#define WM5100_DSP1_CONTROL_5 0xF06
717#define WM5100_DSP1_CONTROL_6 0xF07
718#define WM5100_DSP1_CONTROL_7 0xF08
719#define WM5100_DSP1_CONTROL_8 0xF09
720#define WM5100_DSP1_CONTROL_9 0xF0A
721#define WM5100_DSP1_CONTROL_10 0xF0B
722#define WM5100_DSP1_CONTROL_11 0xF0C
723#define WM5100_DSP1_CONTROL_12 0xF0D
724#define WM5100_DSP1_CONTROL_13 0xF0F
725#define WM5100_DSP1_CONTROL_14 0xF10
726#define WM5100_DSP1_CONTROL_15 0xF11
727#define WM5100_DSP1_CONTROL_16 0xF12
728#define WM5100_DSP1_CONTROL_17 0xF13
729#define WM5100_DSP1_CONTROL_18 0xF14
730#define WM5100_DSP1_CONTROL_19 0xF16
731#define WM5100_DSP1_CONTROL_20 0xF17
732#define WM5100_DSP1_CONTROL_21 0xF18
733#define WM5100_DSP1_CONTROL_22 0xF1A
734#define WM5100_DSP1_CONTROL_23 0xF1B
735#define WM5100_DSP1_CONTROL_24 0xF1C
736#define WM5100_DSP1_CONTROL_25 0xF1E
737#define WM5100_DSP1_CONTROL_26 0xF20
738#define WM5100_DSP1_CONTROL_27 0xF21
739#define WM5100_DSP1_CONTROL_28 0xF22
740#define WM5100_DSP1_CONTROL_29 0xF23
741#define WM5100_DSP1_CONTROL_30 0xF24
742#define WM5100_DSP2_CONTROL_1 0x1000
743#define WM5100_DSP2_CONTROL_2 0x1002
744#define WM5100_DSP2_CONTROL_3 0x1003
745#define WM5100_DSP2_CONTROL_4 0x1004
746#define WM5100_DSP2_CONTROL_5 0x1006
747#define WM5100_DSP2_CONTROL_6 0x1007
748#define WM5100_DSP2_CONTROL_7 0x1008
749#define WM5100_DSP2_CONTROL_8 0x1009
750#define WM5100_DSP2_CONTROL_9 0x100A
751#define WM5100_DSP2_CONTROL_10 0x100B
752#define WM5100_DSP2_CONTROL_11 0x100C
753#define WM5100_DSP2_CONTROL_12 0x100D
754#define WM5100_DSP2_CONTROL_13 0x100F
755#define WM5100_DSP2_CONTROL_14 0x1010
756#define WM5100_DSP2_CONTROL_15 0x1011
757#define WM5100_DSP2_CONTROL_16 0x1012
758#define WM5100_DSP2_CONTROL_17 0x1013
759#define WM5100_DSP2_CONTROL_18 0x1014
760#define WM5100_DSP2_CONTROL_19 0x1016
761#define WM5100_DSP2_CONTROL_20 0x1017
762#define WM5100_DSP2_CONTROL_21 0x1018
763#define WM5100_DSP2_CONTROL_22 0x101A
764#define WM5100_DSP2_CONTROL_23 0x101B
765#define WM5100_DSP2_CONTROL_24 0x101C
766#define WM5100_DSP2_CONTROL_25 0x101E
767#define WM5100_DSP2_CONTROL_26 0x1020
768#define WM5100_DSP2_CONTROL_27 0x1021
769#define WM5100_DSP2_CONTROL_28 0x1022
770#define WM5100_DSP2_CONTROL_29 0x1023
771#define WM5100_DSP2_CONTROL_30 0x1024
772#define WM5100_DSP3_CONTROL_1 0x1100
773#define WM5100_DSP3_CONTROL_2 0x1102
774#define WM5100_DSP3_CONTROL_3 0x1103
775#define WM5100_DSP3_CONTROL_4 0x1104
776#define WM5100_DSP3_CONTROL_5 0x1106
777#define WM5100_DSP3_CONTROL_6 0x1107
778#define WM5100_DSP3_CONTROL_7 0x1108
779#define WM5100_DSP3_CONTROL_8 0x1109
780#define WM5100_DSP3_CONTROL_9 0x110A
781#define WM5100_DSP3_CONTROL_10 0x110B
782#define WM5100_DSP3_CONTROL_11 0x110C
783#define WM5100_DSP3_CONTROL_12 0x110D
784#define WM5100_DSP3_CONTROL_13 0x110F
785#define WM5100_DSP3_CONTROL_14 0x1110
786#define WM5100_DSP3_CONTROL_15 0x1111
787#define WM5100_DSP3_CONTROL_16 0x1112
788#define WM5100_DSP3_CONTROL_17 0x1113
789#define WM5100_DSP3_CONTROL_18 0x1114
790#define WM5100_DSP3_CONTROL_19 0x1116
791#define WM5100_DSP3_CONTROL_20 0x1117
792#define WM5100_DSP3_CONTROL_21 0x1118
793#define WM5100_DSP3_CONTROL_22 0x111A
794#define WM5100_DSP3_CONTROL_23 0x111B
795#define WM5100_DSP3_CONTROL_24 0x111C
796#define WM5100_DSP3_CONTROL_25 0x111E
797#define WM5100_DSP3_CONTROL_26 0x1120
798#define WM5100_DSP3_CONTROL_27 0x1121
799#define WM5100_DSP3_CONTROL_28 0x1122
800#define WM5100_DSP3_CONTROL_29 0x1123
801#define WM5100_DSP3_CONTROL_30 0x1124
712#define WM5100_DSP1_DM_0 0x4000 802#define WM5100_DSP1_DM_0 0x4000
713#define WM5100_DSP1_DM_1 0x4001 803#define WM5100_DSP1_DM_1 0x4001
714#define WM5100_DSP1_DM_2 0x4002 804#define WM5100_DSP1_DM_2 0x4002
@@ -4561,6 +4651,75 @@ int wm5100_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack);
4561#define WM5100_LHPF4_COEFF_WIDTH 16 /* LHPF4_COEFF - [15:0] */ 4651#define WM5100_LHPF4_COEFF_WIDTH 16 /* LHPF4_COEFF - [15:0] */
4562 4652
4563/* 4653/*
4654 * R4132 (0x1024) - DSP2 Control 30
4655 */
4656#define WM5100_DSP2_RATE_MASK 0xC000 /* DSP2_RATE - [15:14] */
4657#define WM5100_DSP2_RATE_SHIFT 14 /* DSP2_RATE - [15:14] */
4658#define WM5100_DSP2_RATE_WIDTH 2 /* DSP2_RATE - [15:14] */
4659#define WM5100_DSP2_DBG_CLK_ENA 0x0008 /* DSP2_DBG_CLK_ENA */
4660#define WM5100_DSP2_DBG_CLK_ENA_MASK 0x0008 /* DSP2_DBG_CLK_ENA */
4661#define WM5100_DSP2_DBG_CLK_ENA_SHIFT 3 /* DSP2_DBG_CLK_ENA */
4662#define WM5100_DSP2_DBG_CLK_ENA_WIDTH 1 /* DSP2_DBG_CLK_ENA */
4663#define WM5100_DSP2_SYS_ENA 0x0004 /* DSP2_SYS_ENA */
4664#define WM5100_DSP2_SYS_ENA_MASK 0x0004 /* DSP2_SYS_ENA */
4665#define WM5100_DSP2_SYS_ENA_SHIFT 2 /* DSP2_SYS_ENA */
4666#define WM5100_DSP2_SYS_ENA_WIDTH 1 /* DSP2_SYS_ENA */
4667#define WM5100_DSP2_CORE_ENA 0x0002 /* DSP2_CORE_ENA */
4668#define WM5100_DSP2_CORE_ENA_MASK 0x0002 /* DSP2_CORE_ENA */
4669#define WM5100_DSP2_CORE_ENA_SHIFT 1 /* DSP2_CORE_ENA */
4670#define WM5100_DSP2_CORE_ENA_WIDTH 1 /* DSP2_CORE_ENA */
4671#define WM5100_DSP2_START 0x0001 /* DSP2_START */
4672#define WM5100_DSP2_START_MASK 0x0001 /* DSP2_START */
4673#define WM5100_DSP2_START_SHIFT 0 /* DSP2_START */
4674#define WM5100_DSP2_START_WIDTH 1 /* DSP2_START */
4675
4676/*
4677 * R3876 (0xF24) - DSP1 Control 30
4678 */
4679#define WM5100_DSP1_RATE_MASK 0xC000 /* DSP1_RATE - [15:14] */
4680#define WM5100_DSP1_RATE_SHIFT 14 /* DSP1_RATE - [15:14] */
4681#define WM5100_DSP1_RATE_WIDTH 2 /* DSP1_RATE - [15:14] */
4682#define WM5100_DSP1_DBG_CLK_ENA 0x0008 /* DSP1_DBG_CLK_ENA */
4683#define WM5100_DSP1_DBG_CLK_ENA_MASK 0x0008 /* DSP1_DBG_CLK_ENA */
4684#define WM5100_DSP1_DBG_CLK_ENA_SHIFT 3 /* DSP1_DBG_CLK_ENA */
4685#define WM5100_DSP1_DBG_CLK_ENA_WIDTH 1 /* DSP1_DBG_CLK_ENA */
4686#define WM5100_DSP1_SYS_ENA 0x0004 /* DSP1_SYS_ENA */
4687#define WM5100_DSP1_SYS_ENA_MASK 0x0004 /* DSP1_SYS_ENA */
4688#define WM5100_DSP1_SYS_ENA_SHIFT 2 /* DSP1_SYS_ENA */
4689#define WM5100_DSP1_SYS_ENA_WIDTH 1 /* DSP1_SYS_ENA */
4690#define WM5100_DSP1_CORE_ENA 0x0002 /* DSP1_CORE_ENA */
4691#define WM5100_DSP1_CORE_ENA_MASK 0x0002 /* DSP1_CORE_ENA */
4692#define WM5100_DSP1_CORE_ENA_SHIFT 1 /* DSP1_CORE_ENA */
4693#define WM5100_DSP1_CORE_ENA_WIDTH 1 /* DSP1_CORE_ENA */
4694#define WM5100_DSP1_START 0x0001 /* DSP1_START */
4695#define WM5100_DSP1_START_MASK 0x0001 /* DSP1_START */
4696#define WM5100_DSP1_START_SHIFT 0 /* DSP1_START */
4697#define WM5100_DSP1_START_WIDTH 1 /* DSP1_START */
4698
4699/*
4700 * R4388 (0x1124) - DSP3 Control 30
4701 */
4702#define WM5100_DSP3_RATE_MASK 0xC000 /* DSP3_RATE - [15:14] */
4703#define WM5100_DSP3_RATE_SHIFT 14 /* DSP3_RATE - [15:14] */
4704#define WM5100_DSP3_RATE_WIDTH 2 /* DSP3_RATE - [15:14] */
4705#define WM5100_DSP3_DBG_CLK_ENA 0x0008 /* DSP3_DBG_CLK_ENA */
4706#define WM5100_DSP3_DBG_CLK_ENA_MASK 0x0008 /* DSP3_DBG_CLK_ENA */
4707#define WM5100_DSP3_DBG_CLK_ENA_SHIFT 3 /* DSP3_DBG_CLK_ENA */
4708#define WM5100_DSP3_DBG_CLK_ENA_WIDTH 1 /* DSP3_DBG_CLK_ENA */
4709#define WM5100_DSP3_SYS_ENA 0x0004 /* DSP3_SYS_ENA */
4710#define WM5100_DSP3_SYS_ENA_MASK 0x0004 /* DSP3_SYS_ENA */
4711#define WM5100_DSP3_SYS_ENA_SHIFT 2 /* DSP3_SYS_ENA */
4712#define WM5100_DSP3_SYS_ENA_WIDTH 1 /* DSP3_SYS_ENA */
4713#define WM5100_DSP3_CORE_ENA 0x0002 /* DSP3_CORE_ENA */
4714#define WM5100_DSP3_CORE_ENA_MASK 0x0002 /* DSP3_CORE_ENA */
4715#define WM5100_DSP3_CORE_ENA_SHIFT 1 /* DSP3_CORE_ENA */
4716#define WM5100_DSP3_CORE_ENA_WIDTH 1 /* DSP3_CORE_ENA */
4717#define WM5100_DSP3_START 0x0001 /* DSP3_START */
4718#define WM5100_DSP3_START_MASK 0x0001 /* DSP3_START */
4719#define WM5100_DSP3_START_SHIFT 0 /* DSP3_START */
4720#define WM5100_DSP3_START_WIDTH 1 /* DSP3_START */
4721
4722/*
4564 * R16384 (0x4000) - DSP1 DM 0 4723 * R16384 (0x4000) - DSP1 DM 0
4565 */ 4724 */
4566#define WM5100_DSP1_DM_START_1_MASK 0x00FF /* DSP1_DM_START - [7:0] */ 4725#define WM5100_DSP1_DM_START_1_MASK 0x00FF /* DSP1_DM_START - [7:0] */
diff --git a/sound/soc/codecs/wm8350.c b/sound/soc/codecs/wm8350.c
index aa12c6b6beeb..555ee146ae0d 100644
--- a/sound/soc/codecs/wm8350.c
+++ b/sound/soc/codecs/wm8350.c
@@ -71,13 +71,6 @@ struct wm8350_data {
71 int fll_freq_in; 71 int fll_freq_in;
72}; 72};
73 73
74static unsigned int wm8350_codec_cache_read(struct snd_soc_codec *codec,
75 unsigned int reg)
76{
77 struct wm8350 *wm8350 = codec->control_data;
78 return wm8350->reg_cache[reg];
79}
80
81static unsigned int wm8350_codec_read(struct snd_soc_codec *codec, 74static unsigned int wm8350_codec_read(struct snd_soc_codec *codec,
82 unsigned int reg) 75 unsigned int reg)
83{ 76{
@@ -99,7 +92,7 @@ static inline int wm8350_out1_ramp_step(struct snd_soc_codec *codec)
99{ 92{
100 struct wm8350_data *wm8350_data = snd_soc_codec_get_drvdata(codec); 93 struct wm8350_data *wm8350_data = snd_soc_codec_get_drvdata(codec);
101 struct wm8350_output *out1 = &wm8350_data->out1; 94 struct wm8350_output *out1 = &wm8350_data->out1;
102 struct wm8350 *wm8350 = codec->control_data; 95 struct wm8350 *wm8350 = wm8350_data->wm8350;
103 int left_complete = 0, right_complete = 0; 96 int left_complete = 0, right_complete = 0;
104 u16 reg, val; 97 u16 reg, val;
105 98
@@ -165,7 +158,7 @@ static inline int wm8350_out2_ramp_step(struct snd_soc_codec *codec)
165{ 158{
166 struct wm8350_data *wm8350_data = snd_soc_codec_get_drvdata(codec); 159 struct wm8350_data *wm8350_data = snd_soc_codec_get_drvdata(codec);
167 struct wm8350_output *out2 = &wm8350_data->out2; 160 struct wm8350_output *out2 = &wm8350_data->out2;
168 struct wm8350 *wm8350 = codec->control_data; 161 struct wm8350 *wm8350 = wm8350_data->wm8350;
169 int left_complete = 0, right_complete = 0; 162 int left_complete = 0, right_complete = 0;
170 u16 reg, val; 163 u16 reg, val;
171 164
@@ -360,8 +353,8 @@ static int wm8350_put_volsw_2r_vu(struct snd_kcontrol *kcontrol,
360 return ret; 353 return ret;
361 354
362 /* now hit the volume update bits (always bit 8) */ 355 /* now hit the volume update bits (always bit 8) */
363 val = wm8350_codec_read(codec, reg); 356 val = snd_soc_read(codec, reg);
364 wm8350_codec_write(codec, reg, val | WM8350_OUT1_VU); 357 snd_soc_write(codec, reg, val | WM8350_OUT1_VU);
365 return 1; 358 return 1;
366} 359}
367 360
@@ -781,7 +774,8 @@ static int wm8350_set_dai_sysclk(struct snd_soc_dai *codec_dai,
781 int clk_id, unsigned int freq, int dir) 774 int clk_id, unsigned int freq, int dir)
782{ 775{
783 struct snd_soc_codec *codec = codec_dai->codec; 776 struct snd_soc_codec *codec = codec_dai->codec;
784 struct wm8350 *wm8350 = codec->control_data; 777 struct wm8350_data *wm8350_data = snd_soc_codec_get_drvdata(codec);
778 struct wm8350 *wm8350 = wm8350_data->wm8350;
785 u16 fll_4; 779 u16 fll_4;
786 780
787 switch (clk_id) { 781 switch (clk_id) {
@@ -795,9 +789,9 @@ static int wm8350_set_dai_sysclk(struct snd_soc_dai *codec_dai,
795 case WM8350_MCLK_SEL_PLL_32K: 789 case WM8350_MCLK_SEL_PLL_32K:
796 wm8350_set_bits(wm8350, WM8350_CLOCK_CONTROL_1, 790 wm8350_set_bits(wm8350, WM8350_CLOCK_CONTROL_1,
797 WM8350_MCLK_SEL); 791 WM8350_MCLK_SEL);
798 fll_4 = wm8350_codec_read(codec, WM8350_FLL_CONTROL_4) & 792 fll_4 = snd_soc_read(codec, WM8350_FLL_CONTROL_4) &
799 ~WM8350_FLL_CLK_SRC_MASK; 793 ~WM8350_FLL_CLK_SRC_MASK;
800 wm8350_codec_write(codec, WM8350_FLL_CONTROL_4, fll_4 | clk_id); 794 snd_soc_write(codec, WM8350_FLL_CONTROL_4, fll_4 | clk_id);
801 break; 795 break;
802 } 796 }
803 797
@@ -819,39 +813,39 @@ static int wm8350_set_clkdiv(struct snd_soc_dai *codec_dai, int div_id, int div)
819 813
820 switch (div_id) { 814 switch (div_id) {
821 case WM8350_ADC_CLKDIV: 815 case WM8350_ADC_CLKDIV:
822 val = wm8350_codec_read(codec, WM8350_ADC_DIVIDER) & 816 val = snd_soc_read(codec, WM8350_ADC_DIVIDER) &
823 ~WM8350_ADC_CLKDIV_MASK; 817 ~WM8350_ADC_CLKDIV_MASK;
824 wm8350_codec_write(codec, WM8350_ADC_DIVIDER, val | div); 818 snd_soc_write(codec, WM8350_ADC_DIVIDER, val | div);
825 break; 819 break;
826 case WM8350_DAC_CLKDIV: 820 case WM8350_DAC_CLKDIV:
827 val = wm8350_codec_read(codec, WM8350_DAC_CLOCK_CONTROL) & 821 val = snd_soc_read(codec, WM8350_DAC_CLOCK_CONTROL) &
828 ~WM8350_DAC_CLKDIV_MASK; 822 ~WM8350_DAC_CLKDIV_MASK;
829 wm8350_codec_write(codec, WM8350_DAC_CLOCK_CONTROL, val | div); 823 snd_soc_write(codec, WM8350_DAC_CLOCK_CONTROL, val | div);
830 break; 824 break;
831 case WM8350_BCLK_CLKDIV: 825 case WM8350_BCLK_CLKDIV:
832 val = wm8350_codec_read(codec, WM8350_CLOCK_CONTROL_1) & 826 val = snd_soc_read(codec, WM8350_CLOCK_CONTROL_1) &
833 ~WM8350_BCLK_DIV_MASK; 827 ~WM8350_BCLK_DIV_MASK;
834 wm8350_codec_write(codec, WM8350_CLOCK_CONTROL_1, val | div); 828 snd_soc_write(codec, WM8350_CLOCK_CONTROL_1, val | div);
835 break; 829 break;
836 case WM8350_OPCLK_CLKDIV: 830 case WM8350_OPCLK_CLKDIV:
837 val = wm8350_codec_read(codec, WM8350_CLOCK_CONTROL_1) & 831 val = snd_soc_read(codec, WM8350_CLOCK_CONTROL_1) &
838 ~WM8350_OPCLK_DIV_MASK; 832 ~WM8350_OPCLK_DIV_MASK;
839 wm8350_codec_write(codec, WM8350_CLOCK_CONTROL_1, val | div); 833 snd_soc_write(codec, WM8350_CLOCK_CONTROL_1, val | div);
840 break; 834 break;
841 case WM8350_SYS_CLKDIV: 835 case WM8350_SYS_CLKDIV:
842 val = wm8350_codec_read(codec, WM8350_CLOCK_CONTROL_1) & 836 val = snd_soc_read(codec, WM8350_CLOCK_CONTROL_1) &
843 ~WM8350_MCLK_DIV_MASK; 837 ~WM8350_MCLK_DIV_MASK;
844 wm8350_codec_write(codec, WM8350_CLOCK_CONTROL_1, val | div); 838 snd_soc_write(codec, WM8350_CLOCK_CONTROL_1, val | div);
845 break; 839 break;
846 case WM8350_DACLR_CLKDIV: 840 case WM8350_DACLR_CLKDIV:
847 val = wm8350_codec_read(codec, WM8350_DAC_LR_RATE) & 841 val = snd_soc_read(codec, WM8350_DAC_LR_RATE) &
848 ~WM8350_DACLRC_RATE_MASK; 842 ~WM8350_DACLRC_RATE_MASK;
849 wm8350_codec_write(codec, WM8350_DAC_LR_RATE, val | div); 843 snd_soc_write(codec, WM8350_DAC_LR_RATE, val | div);
850 break; 844 break;
851 case WM8350_ADCLR_CLKDIV: 845 case WM8350_ADCLR_CLKDIV:
852 val = wm8350_codec_read(codec, WM8350_ADC_LR_RATE) & 846 val = snd_soc_read(codec, WM8350_ADC_LR_RATE) &
853 ~WM8350_ADCLRC_RATE_MASK; 847 ~WM8350_ADCLRC_RATE_MASK;
854 wm8350_codec_write(codec, WM8350_ADC_LR_RATE, val | div); 848 snd_soc_write(codec, WM8350_ADC_LR_RATE, val | div);
855 break; 849 break;
856 default: 850 default:
857 return -EINVAL; 851 return -EINVAL;
@@ -863,13 +857,13 @@ static int wm8350_set_clkdiv(struct snd_soc_dai *codec_dai, int div_id, int div)
863static int wm8350_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt) 857static int wm8350_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
864{ 858{
865 struct snd_soc_codec *codec = codec_dai->codec; 859 struct snd_soc_codec *codec = codec_dai->codec;
866 u16 iface = wm8350_codec_read(codec, WM8350_AI_FORMATING) & 860 u16 iface = snd_soc_read(codec, WM8350_AI_FORMATING) &
867 ~(WM8350_AIF_BCLK_INV | WM8350_AIF_LRCLK_INV | WM8350_AIF_FMT_MASK); 861 ~(WM8350_AIF_BCLK_INV | WM8350_AIF_LRCLK_INV | WM8350_AIF_FMT_MASK);
868 u16 master = wm8350_codec_read(codec, WM8350_AI_DAC_CONTROL) & 862 u16 master = snd_soc_read(codec, WM8350_AI_DAC_CONTROL) &
869 ~WM8350_BCLK_MSTR; 863 ~WM8350_BCLK_MSTR;
870 u16 dac_lrc = wm8350_codec_read(codec, WM8350_DAC_LR_RATE) & 864 u16 dac_lrc = snd_soc_read(codec, WM8350_DAC_LR_RATE) &
871 ~WM8350_DACLRC_ENA; 865 ~WM8350_DACLRC_ENA;
872 u16 adc_lrc = wm8350_codec_read(codec, WM8350_ADC_LR_RATE) & 866 u16 adc_lrc = snd_soc_read(codec, WM8350_ADC_LR_RATE) &
873 ~WM8350_ADCLRC_ENA; 867 ~WM8350_ADCLRC_ENA;
874 868
875 /* set master/slave audio interface */ 869 /* set master/slave audio interface */
@@ -922,42 +916,10 @@ static int wm8350_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
922 return -EINVAL; 916 return -EINVAL;
923 } 917 }
924 918
925 wm8350_codec_write(codec, WM8350_AI_FORMATING, iface); 919 snd_soc_write(codec, WM8350_AI_FORMATING, iface);
926 wm8350_codec_write(codec, WM8350_AI_DAC_CONTROL, master); 920 snd_soc_write(codec, WM8350_AI_DAC_CONTROL, master);
927 wm8350_codec_write(codec, WM8350_DAC_LR_RATE, dac_lrc); 921 snd_soc_write(codec, WM8350_DAC_LR_RATE, dac_lrc);
928 wm8350_codec_write(codec, WM8350_ADC_LR_RATE, adc_lrc); 922 snd_soc_write(codec, WM8350_ADC_LR_RATE, adc_lrc);
929 return 0;
930}
931
932static int wm8350_pcm_trigger(struct snd_pcm_substream *substream,
933 int cmd, struct snd_soc_dai *codec_dai)
934{
935 struct snd_soc_codec *codec = codec_dai->codec;
936 int master = wm8350_codec_cache_read(codec, WM8350_AI_DAC_CONTROL) &
937 WM8350_BCLK_MSTR;
938 int enabled = 0;
939
940 /* Check that the DACs or ADCs are enabled since they are
941 * required for LRC in master mode. The DACs or ADCs need a
942 * valid audio path i.e. pin -> ADC or DAC -> pin before
943 * the LRC will be enabled in master mode. */
944 if (!master || cmd != SNDRV_PCM_TRIGGER_START)
945 return 0;
946
947 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
948 enabled = wm8350_codec_cache_read(codec, WM8350_POWER_MGMT_4) &
949 (WM8350_ADCR_ENA | WM8350_ADCL_ENA);
950 } else {
951 enabled = wm8350_codec_cache_read(codec, WM8350_POWER_MGMT_4) &
952 (WM8350_DACR_ENA | WM8350_DACL_ENA);
953 }
954
955 if (!enabled) {
956 dev_err(codec->dev,
957 "%s: invalid audio path - no clocks available\n",
958 __func__);
959 return -EINVAL;
960 }
961 return 0; 923 return 0;
962} 924}
963 925
@@ -966,8 +928,9 @@ static int wm8350_pcm_hw_params(struct snd_pcm_substream *substream,
966 struct snd_soc_dai *codec_dai) 928 struct snd_soc_dai *codec_dai)
967{ 929{
968 struct snd_soc_codec *codec = codec_dai->codec; 930 struct snd_soc_codec *codec = codec_dai->codec;
969 struct wm8350 *wm8350 = codec->control_data; 931 struct wm8350_data *wm8350_data = snd_soc_codec_get_drvdata(codec);
970 u16 iface = wm8350_codec_read(codec, WM8350_AI_FORMATING) & 932 struct wm8350 *wm8350 = wm8350_data->wm8350;
933 u16 iface = snd_soc_read(codec, WM8350_AI_FORMATING) &
971 ~WM8350_AIF_WL_MASK; 934 ~WM8350_AIF_WL_MASK;
972 935
973 /* bit size */ 936 /* bit size */
@@ -985,7 +948,7 @@ static int wm8350_pcm_hw_params(struct snd_pcm_substream *substream,
985 break; 948 break;
986 } 949 }
987 950
988 wm8350_codec_write(codec, WM8350_AI_FORMATING, iface); 951 snd_soc_write(codec, WM8350_AI_FORMATING, iface);
989 952
990 /* The sloping stopband filter is recommended for use with 953 /* The sloping stopband filter is recommended for use with
991 * lower sample rates to improve performance. 954 * lower sample rates to improve performance.
@@ -1005,12 +968,15 @@ static int wm8350_pcm_hw_params(struct snd_pcm_substream *substream,
1005static int wm8350_mute(struct snd_soc_dai *dai, int mute) 968static int wm8350_mute(struct snd_soc_dai *dai, int mute)
1006{ 969{
1007 struct snd_soc_codec *codec = dai->codec; 970 struct snd_soc_codec *codec = dai->codec;
1008 struct wm8350 *wm8350 = codec->control_data; 971 unsigned int val;
1009 972
1010 if (mute) 973 if (mute)
1011 wm8350_set_bits(wm8350, WM8350_DAC_MUTE, WM8350_DAC_MUTE_ENA); 974 val = WM8350_DAC_MUTE_ENA;
1012 else 975 else
1013 wm8350_clear_bits(wm8350, WM8350_DAC_MUTE, WM8350_DAC_MUTE_ENA); 976 val = 0;
977
978 snd_soc_update_bits(codec, WM8350_DAC_MUTE, WM8350_DAC_MUTE_ENA, val);
979
1014 return 0; 980 return 0;
1015} 981}
1016 982
@@ -1079,8 +1045,8 @@ static int wm8350_set_fll(struct snd_soc_dai *codec_dai,
1079 unsigned int freq_out) 1045 unsigned int freq_out)
1080{ 1046{
1081 struct snd_soc_codec *codec = codec_dai->codec; 1047 struct snd_soc_codec *codec = codec_dai->codec;
1082 struct wm8350 *wm8350 = codec->control_data;
1083 struct wm8350_data *priv = snd_soc_codec_get_drvdata(codec); 1048 struct wm8350_data *priv = snd_soc_codec_get_drvdata(codec);
1049 struct wm8350 *wm8350 = priv->wm8350;
1084 struct _fll_div fll_div; 1050 struct _fll_div fll_div;
1085 int ret = 0; 1051 int ret = 0;
1086 u16 fll_1, fll_4; 1052 u16 fll_1, fll_4;
@@ -1104,17 +1070,17 @@ static int wm8350_set_fll(struct snd_soc_dai *codec_dai,
1104 fll_div.ratio); 1070 fll_div.ratio);
1105 1071
1106 /* set up N.K & dividers */ 1072 /* set up N.K & dividers */
1107 fll_1 = wm8350_codec_read(codec, WM8350_FLL_CONTROL_1) & 1073 fll_1 = snd_soc_read(codec, WM8350_FLL_CONTROL_1) &
1108 ~(WM8350_FLL_OUTDIV_MASK | WM8350_FLL_RSP_RATE_MASK | 0xc000); 1074 ~(WM8350_FLL_OUTDIV_MASK | WM8350_FLL_RSP_RATE_MASK | 0xc000);
1109 wm8350_codec_write(codec, WM8350_FLL_CONTROL_1, 1075 snd_soc_write(codec, WM8350_FLL_CONTROL_1,
1110 fll_1 | (fll_div.div << 8) | 0x50); 1076 fll_1 | (fll_div.div << 8) | 0x50);
1111 wm8350_codec_write(codec, WM8350_FLL_CONTROL_2, 1077 snd_soc_write(codec, WM8350_FLL_CONTROL_2,
1112 (fll_div.ratio << 11) | (fll_div. 1078 (fll_div.ratio << 11) | (fll_div.
1113 n & WM8350_FLL_N_MASK)); 1079 n & WM8350_FLL_N_MASK));
1114 wm8350_codec_write(codec, WM8350_FLL_CONTROL_3, fll_div.k); 1080 snd_soc_write(codec, WM8350_FLL_CONTROL_3, fll_div.k);
1115 fll_4 = wm8350_codec_read(codec, WM8350_FLL_CONTROL_4) & 1081 fll_4 = snd_soc_read(codec, WM8350_FLL_CONTROL_4) &
1116 ~(WM8350_FLL_FRAC | WM8350_FLL_SLOW_LOCK_REF); 1082 ~(WM8350_FLL_FRAC | WM8350_FLL_SLOW_LOCK_REF);
1117 wm8350_codec_write(codec, WM8350_FLL_CONTROL_4, 1083 snd_soc_write(codec, WM8350_FLL_CONTROL_4,
1118 fll_4 | (fll_div.k ? WM8350_FLL_FRAC : 0) | 1084 fll_4 | (fll_div.k ? WM8350_FLL_FRAC : 0) |
1119 (fll_div.ratio == 8 ? WM8350_FLL_SLOW_LOCK_REF : 0)); 1085 (fll_div.ratio == 8 ? WM8350_FLL_SLOW_LOCK_REF : 0));
1120 1086
@@ -1131,8 +1097,8 @@ static int wm8350_set_fll(struct snd_soc_dai *codec_dai,
1131static int wm8350_set_bias_level(struct snd_soc_codec *codec, 1097static int wm8350_set_bias_level(struct snd_soc_codec *codec,
1132 enum snd_soc_bias_level level) 1098 enum snd_soc_bias_level level)
1133{ 1099{
1134 struct wm8350 *wm8350 = codec->control_data;
1135 struct wm8350_data *priv = snd_soc_codec_get_drvdata(codec); 1100 struct wm8350_data *priv = snd_soc_codec_get_drvdata(codec);
1101 struct wm8350 *wm8350 = priv->wm8350;
1136 struct wm8350_audio_platform_data *platform = 1102 struct wm8350_audio_platform_data *platform =
1137 wm8350->codec.platform_data; 1103 wm8350->codec.platform_data;
1138 u16 pm1; 1104 u16 pm1;
@@ -1339,35 +1305,36 @@ static void wm8350_hpr_work(struct work_struct *work)
1339 wm8350_hp_work(priv, &priv->hpr, WM8350_JACK_R_LVL); 1305 wm8350_hp_work(priv, &priv->hpr, WM8350_JACK_R_LVL);
1340} 1306}
1341 1307
1342static irqreturn_t wm8350_hp_jack_handler(int irq, void *data) 1308static irqreturn_t wm8350_hpl_jack_handler(int irq, void *data)
1343{ 1309{
1344 struct wm8350_data *priv = data; 1310 struct wm8350_data *priv = data;
1345 struct wm8350 *wm8350 = priv->wm8350; 1311 struct wm8350 *wm8350 = priv->wm8350;
1346 struct wm8350_jack_data *jack = NULL;
1347 1312
1348 switch (irq - wm8350->irq_base) {
1349 case WM8350_IRQ_CODEC_JCK_DET_L:
1350#ifndef CONFIG_SND_SOC_WM8350_MODULE 1313#ifndef CONFIG_SND_SOC_WM8350_MODULE
1351 trace_snd_soc_jack_irq("WM8350 HPL"); 1314 trace_snd_soc_jack_irq("WM8350 HPL");
1352#endif 1315#endif
1353 jack = &priv->hpl;
1354 break;
1355 1316
1356 case WM8350_IRQ_CODEC_JCK_DET_R: 1317 if (device_may_wakeup(wm8350->dev))
1318 pm_wakeup_event(wm8350->dev, 250);
1319
1320 schedule_delayed_work(&priv->hpl.work, 200);
1321
1322 return IRQ_HANDLED;
1323}
1324
1325static irqreturn_t wm8350_hpr_jack_handler(int irq, void *data)
1326{
1327 struct wm8350_data *priv = data;
1328 struct wm8350 *wm8350 = priv->wm8350;
1329
1357#ifndef CONFIG_SND_SOC_WM8350_MODULE 1330#ifndef CONFIG_SND_SOC_WM8350_MODULE
1358 trace_snd_soc_jack_irq("WM8350 HPR"); 1331 trace_snd_soc_jack_irq("WM8350 HPR");
1359#endif 1332#endif
1360 jack = &priv->hpr;
1361 break;
1362
1363 default:
1364 BUG();
1365 }
1366 1333
1367 if (device_may_wakeup(wm8350->dev)) 1334 if (device_may_wakeup(wm8350->dev))
1368 pm_wakeup_event(wm8350->dev, 250); 1335 pm_wakeup_event(wm8350->dev, 250);
1369 1336
1370 schedule_delayed_work(&jack->work, 200); 1337 schedule_delayed_work(&priv->hpr.work, 200);
1371 1338
1372 return IRQ_HANDLED; 1339 return IRQ_HANDLED;
1373} 1340}
@@ -1387,7 +1354,7 @@ int wm8350_hp_jack_detect(struct snd_soc_codec *codec, enum wm8350_jack which,
1387 struct snd_soc_jack *jack, int report) 1354 struct snd_soc_jack *jack, int report)
1388{ 1355{
1389 struct wm8350_data *priv = snd_soc_codec_get_drvdata(codec); 1356 struct wm8350_data *priv = snd_soc_codec_get_drvdata(codec);
1390 struct wm8350 *wm8350 = codec->control_data; 1357 struct wm8350 *wm8350 = priv->wm8350;
1391 int irq; 1358 int irq;
1392 int ena; 1359 int ena;
1393 1360
@@ -1418,7 +1385,14 @@ int wm8350_hp_jack_detect(struct snd_soc_codec *codec, enum wm8350_jack which,
1418 } 1385 }
1419 1386
1420 /* Sync status */ 1387 /* Sync status */
1421 wm8350_hp_jack_handler(irq + wm8350->irq_base, priv); 1388 switch (which) {
1389 case WM8350_JDL:
1390 wm8350_hpl_jack_handler(0, priv);
1391 break;
1392 case WM8350_JDR:
1393 wm8350_hpr_jack_handler(0, priv);
1394 break;
1395 }
1422 1396
1423 return 0; 1397 return 0;
1424} 1398}
@@ -1463,7 +1437,7 @@ int wm8350_mic_jack_detect(struct snd_soc_codec *codec,
1463 int detect_report, int short_report) 1437 int detect_report, int short_report)
1464{ 1438{
1465 struct wm8350_data *priv = snd_soc_codec_get_drvdata(codec); 1439 struct wm8350_data *priv = snd_soc_codec_get_drvdata(codec);
1466 struct wm8350 *wm8350 = codec->control_data; 1440 struct wm8350 *wm8350 = priv->wm8350;
1467 1441
1468 priv->mic.jack = jack; 1442 priv->mic.jack = jack;
1469 priv->mic.report = detect_report; 1443 priv->mic.report = detect_report;
@@ -1491,7 +1465,6 @@ EXPORT_SYMBOL_GPL(wm8350_mic_jack_detect);
1491static const struct snd_soc_dai_ops wm8350_dai_ops = { 1465static const struct snd_soc_dai_ops wm8350_dai_ops = {
1492 .hw_params = wm8350_pcm_hw_params, 1466 .hw_params = wm8350_pcm_hw_params,
1493 .digital_mute = wm8350_mute, 1467 .digital_mute = wm8350_mute,
1494 .trigger = wm8350_pcm_trigger,
1495 .set_fmt = wm8350_set_dai_fmt, 1468 .set_fmt = wm8350_set_dai_fmt,
1496 .set_sysclk = wm8350_set_dai_sysclk, 1469 .set_sysclk = wm8350_set_dai_sysclk,
1497 .set_pll = wm8350_set_fll, 1470 .set_pll = wm8350_set_fll,
@@ -1559,9 +1532,9 @@ static int wm8350_codec_probe(struct snd_soc_codec *codec)
1559 wm8350_set_bits(wm8350, WM8350_POWER_MGMT_5, WM8350_CODEC_ENA); 1532 wm8350_set_bits(wm8350, WM8350_POWER_MGMT_5, WM8350_CODEC_ENA);
1560 1533
1561 /* Enable robust clocking mode in ADC */ 1534 /* Enable robust clocking mode in ADC */
1562 wm8350_codec_write(codec, WM8350_SECURITY, 0xa7); 1535 snd_soc_write(codec, WM8350_SECURITY, 0xa7);
1563 wm8350_codec_write(codec, 0xde, 0x13); 1536 snd_soc_write(codec, 0xde, 0x13);
1564 wm8350_codec_write(codec, WM8350_SECURITY, 0); 1537 snd_soc_write(codec, WM8350_SECURITY, 0);
1565 1538
1566 /* read OUT1 & OUT2 volumes */ 1539 /* read OUT1 & OUT2 volumes */
1567 out1 = &priv->out1; 1540 out1 = &priv->out1;
@@ -1601,10 +1574,10 @@ static int wm8350_codec_probe(struct snd_soc_codec *codec)
1601 WM8350_JDL_ENA | WM8350_JDR_ENA); 1574 WM8350_JDL_ENA | WM8350_JDR_ENA);
1602 1575
1603 wm8350_register_irq(wm8350, WM8350_IRQ_CODEC_JCK_DET_L, 1576 wm8350_register_irq(wm8350, WM8350_IRQ_CODEC_JCK_DET_L,
1604 wm8350_hp_jack_handler, 0, "Left jack detect", 1577 wm8350_hpl_jack_handler, 0, "Left jack detect",
1605 priv); 1578 priv);
1606 wm8350_register_irq(wm8350, WM8350_IRQ_CODEC_JCK_DET_R, 1579 wm8350_register_irq(wm8350, WM8350_IRQ_CODEC_JCK_DET_R,
1607 wm8350_hp_jack_handler, 0, "Right jack detect", 1580 wm8350_hpr_jack_handler, 0, "Right jack detect",
1608 priv); 1581 priv);
1609 wm8350_register_irq(wm8350, WM8350_IRQ_CODEC_MICSCD, 1582 wm8350_register_irq(wm8350, WM8350_IRQ_CODEC_MICSCD,
1610 wm8350_mic_handler, 0, "Microphone short", priv); 1583 wm8350_mic_handler, 0, "Microphone short", priv);
diff --git a/sound/soc/codecs/wm8400.c b/sound/soc/codecs/wm8400.c
index 898979d23010..5dc31ebcd0e7 100644
--- a/sound/soc/codecs/wm8400.c
+++ b/sound/soc/codecs/wm8400.c
@@ -138,8 +138,8 @@ static int wm8400_outpga_put_volsw_vu(struct snd_kcontrol *kcontrol,
138 return ret; 138 return ret;
139 139
140 /* now hit the volume update bits (always bit 8) */ 140 /* now hit the volume update bits (always bit 8) */
141 val = wm8400_read(codec, reg); 141 val = snd_soc_read(codec, reg);
142 return wm8400_write(codec, reg, val | 0x0100); 142 return snd_soc_write(codec, reg, val | 0x0100);
143} 143}
144 144
145#define WM8400_OUTPGA_SINGLE_R_TLV(xname, reg, shift, max, invert, tlv_array) \ 145#define WM8400_OUTPGA_SINGLE_R_TLV(xname, reg, shift, max, invert, tlv_array) \
@@ -362,8 +362,8 @@ static int inmixer_event (struct snd_soc_dapm_widget *w,
362{ 362{
363 u16 reg, fakepower; 363 u16 reg, fakepower;
364 364
365 reg = wm8400_read(w->codec, WM8400_POWER_MANAGEMENT_2); 365 reg = snd_soc_read(w->codec, WM8400_POWER_MANAGEMENT_2);
366 fakepower = wm8400_read(w->codec, WM8400_INTDRIVBITS); 366 fakepower = snd_soc_read(w->codec, WM8400_INTDRIVBITS);
367 367
368 if (fakepower & ((1 << WM8400_INMIXL_PWR) | 368 if (fakepower & ((1 << WM8400_INMIXL_PWR) |
369 (1 << WM8400_AINLMUX_PWR))) { 369 (1 << WM8400_AINLMUX_PWR))) {
@@ -378,7 +378,7 @@ static int inmixer_event (struct snd_soc_dapm_widget *w,
378 } else { 378 } else {
379 reg &= ~WM8400_AINR_ENA; 379 reg &= ~WM8400_AINR_ENA;
380 } 380 }
381 wm8400_write(w->codec, WM8400_POWER_MANAGEMENT_2, reg); 381 snd_soc_write(w->codec, WM8400_POWER_MANAGEMENT_2, reg);
382 382
383 return 0; 383 return 0;
384} 384}
@@ -394,7 +394,7 @@ static int outmixer_event (struct snd_soc_dapm_widget *w,
394 394
395 switch (reg_shift) { 395 switch (reg_shift) {
396 case WM8400_SPEAKER_MIXER | (WM8400_LDSPK << 8) : 396 case WM8400_SPEAKER_MIXER | (WM8400_LDSPK << 8) :
397 reg = wm8400_read(w->codec, WM8400_OUTPUT_MIXER1); 397 reg = snd_soc_read(w->codec, WM8400_OUTPUT_MIXER1);
398 if (reg & WM8400_LDLO) { 398 if (reg & WM8400_LDLO) {
399 printk(KERN_WARNING 399 printk(KERN_WARNING
400 "Cannot set as Output Mixer 1 LDLO Set\n"); 400 "Cannot set as Output Mixer 1 LDLO Set\n");
@@ -402,7 +402,7 @@ static int outmixer_event (struct snd_soc_dapm_widget *w,
402 } 402 }
403 break; 403 break;
404 case WM8400_SPEAKER_MIXER | (WM8400_RDSPK << 8): 404 case WM8400_SPEAKER_MIXER | (WM8400_RDSPK << 8):
405 reg = wm8400_read(w->codec, WM8400_OUTPUT_MIXER2); 405 reg = snd_soc_read(w->codec, WM8400_OUTPUT_MIXER2);
406 if (reg & WM8400_RDRO) { 406 if (reg & WM8400_RDRO) {
407 printk(KERN_WARNING 407 printk(KERN_WARNING
408 "Cannot set as Output Mixer 2 RDRO Set\n"); 408 "Cannot set as Output Mixer 2 RDRO Set\n");
@@ -410,7 +410,7 @@ static int outmixer_event (struct snd_soc_dapm_widget *w,
410 } 410 }
411 break; 411 break;
412 case WM8400_OUTPUT_MIXER1 | (WM8400_LDLO << 8): 412 case WM8400_OUTPUT_MIXER1 | (WM8400_LDLO << 8):
413 reg = wm8400_read(w->codec, WM8400_SPEAKER_MIXER); 413 reg = snd_soc_read(w->codec, WM8400_SPEAKER_MIXER);
414 if (reg & WM8400_LDSPK) { 414 if (reg & WM8400_LDSPK) {
415 printk(KERN_WARNING 415 printk(KERN_WARNING
416 "Cannot set as Speaker Mixer LDSPK Set\n"); 416 "Cannot set as Speaker Mixer LDSPK Set\n");
@@ -418,7 +418,7 @@ static int outmixer_event (struct snd_soc_dapm_widget *w,
418 } 418 }
419 break; 419 break;
420 case WM8400_OUTPUT_MIXER2 | (WM8400_RDRO << 8): 420 case WM8400_OUTPUT_MIXER2 | (WM8400_RDRO << 8):
421 reg = wm8400_read(w->codec, WM8400_SPEAKER_MIXER); 421 reg = snd_soc_read(w->codec, WM8400_SPEAKER_MIXER);
422 if (reg & WM8400_RDSPK) { 422 if (reg & WM8400_RDSPK) {
423 printk(KERN_WARNING 423 printk(KERN_WARNING
424 "Cannot set as Speaker Mixer RDSPK Set\n"); 424 "Cannot set as Speaker Mixer RDSPK Set\n");
@@ -1021,13 +1021,13 @@ static int wm8400_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id,
1021 wm8400->fll_in = freq_in; 1021 wm8400->fll_in = freq_in;
1022 1022
1023 /* We *must* disable the FLL before any changes */ 1023 /* We *must* disable the FLL before any changes */
1024 reg = wm8400_read(codec, WM8400_POWER_MANAGEMENT_2); 1024 reg = snd_soc_read(codec, WM8400_POWER_MANAGEMENT_2);
1025 reg &= ~WM8400_FLL_ENA; 1025 reg &= ~WM8400_FLL_ENA;
1026 wm8400_write(codec, WM8400_POWER_MANAGEMENT_2, reg); 1026 snd_soc_write(codec, WM8400_POWER_MANAGEMENT_2, reg);
1027 1027
1028 reg = wm8400_read(codec, WM8400_FLL_CONTROL_1); 1028 reg = snd_soc_read(codec, WM8400_FLL_CONTROL_1);
1029 reg &= ~WM8400_FLL_OSC_ENA; 1029 reg &= ~WM8400_FLL_OSC_ENA;
1030 wm8400_write(codec, WM8400_FLL_CONTROL_1, reg); 1030 snd_soc_write(codec, WM8400_FLL_CONTROL_1, reg);
1031 1031
1032 if (!freq_out) 1032 if (!freq_out)
1033 return 0; 1033 return 0;
@@ -1035,15 +1035,15 @@ static int wm8400_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id,
1035 reg &= ~(WM8400_FLL_REF_FREQ | WM8400_FLL_FRATIO_MASK); 1035 reg &= ~(WM8400_FLL_REF_FREQ | WM8400_FLL_FRATIO_MASK);
1036 reg |= WM8400_FLL_FRAC | factors.fratio; 1036 reg |= WM8400_FLL_FRAC | factors.fratio;
1037 reg |= factors.freq_ref << WM8400_FLL_REF_FREQ_SHIFT; 1037 reg |= factors.freq_ref << WM8400_FLL_REF_FREQ_SHIFT;
1038 wm8400_write(codec, WM8400_FLL_CONTROL_1, reg); 1038 snd_soc_write(codec, WM8400_FLL_CONTROL_1, reg);
1039 1039
1040 wm8400_write(codec, WM8400_FLL_CONTROL_2, factors.k); 1040 snd_soc_write(codec, WM8400_FLL_CONTROL_2, factors.k);
1041 wm8400_write(codec, WM8400_FLL_CONTROL_3, factors.n); 1041 snd_soc_write(codec, WM8400_FLL_CONTROL_3, factors.n);
1042 1042
1043 reg = wm8400_read(codec, WM8400_FLL_CONTROL_4); 1043 reg = snd_soc_read(codec, WM8400_FLL_CONTROL_4);
1044 reg &= ~WM8400_FLL_OUTDIV_MASK; 1044 reg &= ~WM8400_FLL_OUTDIV_MASK;
1045 reg |= factors.outdiv; 1045 reg |= factors.outdiv;
1046 wm8400_write(codec, WM8400_FLL_CONTROL_4, reg); 1046 snd_soc_write(codec, WM8400_FLL_CONTROL_4, reg);
1047 1047
1048 return 0; 1048 return 0;
1049} 1049}
@@ -1057,8 +1057,8 @@ static int wm8400_set_dai_fmt(struct snd_soc_dai *codec_dai,
1057 struct snd_soc_codec *codec = codec_dai->codec; 1057 struct snd_soc_codec *codec = codec_dai->codec;
1058 u16 audio1, audio3; 1058 u16 audio1, audio3;
1059 1059
1060 audio1 = wm8400_read(codec, WM8400_AUDIO_INTERFACE_1); 1060 audio1 = snd_soc_read(codec, WM8400_AUDIO_INTERFACE_1);
1061 audio3 = wm8400_read(codec, WM8400_AUDIO_INTERFACE_3); 1061 audio3 = snd_soc_read(codec, WM8400_AUDIO_INTERFACE_3);
1062 1062
1063 /* set master/slave audio interface */ 1063 /* set master/slave audio interface */
1064 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { 1064 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
@@ -1099,8 +1099,8 @@ static int wm8400_set_dai_fmt(struct snd_soc_dai *codec_dai,
1099 return -EINVAL; 1099 return -EINVAL;
1100 } 1100 }
1101 1101
1102 wm8400_write(codec, WM8400_AUDIO_INTERFACE_1, audio1); 1102 snd_soc_write(codec, WM8400_AUDIO_INTERFACE_1, audio1);
1103 wm8400_write(codec, WM8400_AUDIO_INTERFACE_3, audio3); 1103 snd_soc_write(codec, WM8400_AUDIO_INTERFACE_3, audio3);
1104 return 0; 1104 return 0;
1105} 1105}
1106 1106
@@ -1112,24 +1112,24 @@ static int wm8400_set_dai_clkdiv(struct snd_soc_dai *codec_dai,
1112 1112
1113 switch (div_id) { 1113 switch (div_id) {
1114 case WM8400_MCLK_DIV: 1114 case WM8400_MCLK_DIV:
1115 reg = wm8400_read(codec, WM8400_CLOCKING_2) & 1115 reg = snd_soc_read(codec, WM8400_CLOCKING_2) &
1116 ~WM8400_MCLK_DIV_MASK; 1116 ~WM8400_MCLK_DIV_MASK;
1117 wm8400_write(codec, WM8400_CLOCKING_2, reg | div); 1117 snd_soc_write(codec, WM8400_CLOCKING_2, reg | div);
1118 break; 1118 break;
1119 case WM8400_DACCLK_DIV: 1119 case WM8400_DACCLK_DIV:
1120 reg = wm8400_read(codec, WM8400_CLOCKING_2) & 1120 reg = snd_soc_read(codec, WM8400_CLOCKING_2) &
1121 ~WM8400_DAC_CLKDIV_MASK; 1121 ~WM8400_DAC_CLKDIV_MASK;
1122 wm8400_write(codec, WM8400_CLOCKING_2, reg | div); 1122 snd_soc_write(codec, WM8400_CLOCKING_2, reg | div);
1123 break; 1123 break;
1124 case WM8400_ADCCLK_DIV: 1124 case WM8400_ADCCLK_DIV:
1125 reg = wm8400_read(codec, WM8400_CLOCKING_2) & 1125 reg = snd_soc_read(codec, WM8400_CLOCKING_2) &
1126 ~WM8400_ADC_CLKDIV_MASK; 1126 ~WM8400_ADC_CLKDIV_MASK;
1127 wm8400_write(codec, WM8400_CLOCKING_2, reg | div); 1127 snd_soc_write(codec, WM8400_CLOCKING_2, reg | div);
1128 break; 1128 break;
1129 case WM8400_BCLK_DIV: 1129 case WM8400_BCLK_DIV:
1130 reg = wm8400_read(codec, WM8400_CLOCKING_1) & 1130 reg = snd_soc_read(codec, WM8400_CLOCKING_1) &
1131 ~WM8400_BCLK_DIV_MASK; 1131 ~WM8400_BCLK_DIV_MASK;
1132 wm8400_write(codec, WM8400_CLOCKING_1, reg | div); 1132 snd_soc_write(codec, WM8400_CLOCKING_1, reg | div);
1133 break; 1133 break;
1134 default: 1134 default:
1135 return -EINVAL; 1135 return -EINVAL;
@@ -1145,9 +1145,8 @@ static int wm8400_hw_params(struct snd_pcm_substream *substream,
1145 struct snd_pcm_hw_params *params, 1145 struct snd_pcm_hw_params *params,
1146 struct snd_soc_dai *dai) 1146 struct snd_soc_dai *dai)
1147{ 1147{
1148 struct snd_soc_pcm_runtime *rtd = substream->private_data; 1148 struct snd_soc_codec *codec = dai->codec;
1149 struct snd_soc_codec *codec = rtd->codec; 1149 u16 audio1 = snd_soc_read(codec, WM8400_AUDIO_INTERFACE_1);
1150 u16 audio1 = wm8400_read(codec, WM8400_AUDIO_INTERFACE_1);
1151 1150
1152 audio1 &= ~WM8400_AIF_WL_MASK; 1151 audio1 &= ~WM8400_AIF_WL_MASK;
1153 /* bit size */ 1152 /* bit size */
@@ -1165,19 +1164,19 @@ static int wm8400_hw_params(struct snd_pcm_substream *substream,
1165 break; 1164 break;
1166 } 1165 }
1167 1166
1168 wm8400_write(codec, WM8400_AUDIO_INTERFACE_1, audio1); 1167 snd_soc_write(codec, WM8400_AUDIO_INTERFACE_1, audio1);
1169 return 0; 1168 return 0;
1170} 1169}
1171 1170
1172static int wm8400_mute(struct snd_soc_dai *dai, int mute) 1171static int wm8400_mute(struct snd_soc_dai *dai, int mute)
1173{ 1172{
1174 struct snd_soc_codec *codec = dai->codec; 1173 struct snd_soc_codec *codec = dai->codec;
1175 u16 val = wm8400_read(codec, WM8400_DAC_CTRL) & ~WM8400_DAC_MUTE; 1174 u16 val = snd_soc_read(codec, WM8400_DAC_CTRL) & ~WM8400_DAC_MUTE;
1176 1175
1177 if (mute) 1176 if (mute)
1178 wm8400_write(codec, WM8400_DAC_CTRL, val | WM8400_DAC_MUTE); 1177 snd_soc_write(codec, WM8400_DAC_CTRL, val | WM8400_DAC_MUTE);
1179 else 1178 else
1180 wm8400_write(codec, WM8400_DAC_CTRL, val); 1179 snd_soc_write(codec, WM8400_DAC_CTRL, val);
1181 1180
1182 return 0; 1181 return 0;
1183} 1182}
@@ -1196,9 +1195,9 @@ static int wm8400_set_bias_level(struct snd_soc_codec *codec,
1196 1195
1197 case SND_SOC_BIAS_PREPARE: 1196 case SND_SOC_BIAS_PREPARE:
1198 /* VMID=2*50k */ 1197 /* VMID=2*50k */
1199 val = wm8400_read(codec, WM8400_POWER_MANAGEMENT_1) & 1198 val = snd_soc_read(codec, WM8400_POWER_MANAGEMENT_1) &
1200 ~WM8400_VMID_MODE_MASK; 1199 ~WM8400_VMID_MODE_MASK;
1201 wm8400_write(codec, WM8400_POWER_MANAGEMENT_1, val | 0x2); 1200 snd_soc_write(codec, WM8400_POWER_MANAGEMENT_1, val | 0x2);
1202 break; 1201 break;
1203 1202
1204 case SND_SOC_BIAS_STANDBY: 1203 case SND_SOC_BIAS_STANDBY:
@@ -1212,74 +1211,74 @@ static int wm8400_set_bias_level(struct snd_soc_codec *codec,
1212 return ret; 1211 return ret;
1213 } 1212 }
1214 1213
1215 wm8400_write(codec, WM8400_POWER_MANAGEMENT_1, 1214 snd_soc_write(codec, WM8400_POWER_MANAGEMENT_1,
1216 WM8400_CODEC_ENA | WM8400_SYSCLK_ENA); 1215 WM8400_CODEC_ENA | WM8400_SYSCLK_ENA);
1217 1216
1218 /* Enable POBCTRL, SOFT_ST, VMIDTOG and BUFDCOPEN */ 1217 /* Enable POBCTRL, SOFT_ST, VMIDTOG and BUFDCOPEN */
1219 wm8400_write(codec, WM8400_ANTIPOP2, WM8400_SOFTST | 1218 snd_soc_write(codec, WM8400_ANTIPOP2, WM8400_SOFTST |
1220 WM8400_BUFDCOPEN | WM8400_POBCTRL); 1219 WM8400_BUFDCOPEN | WM8400_POBCTRL);
1221 1220
1222 msleep(50); 1221 msleep(50);
1223 1222
1224 /* Enable VREF & VMID at 2x50k */ 1223 /* Enable VREF & VMID at 2x50k */
1225 val = wm8400_read(codec, WM8400_POWER_MANAGEMENT_1); 1224 val = snd_soc_read(codec, WM8400_POWER_MANAGEMENT_1);
1226 val |= 0x2 | WM8400_VREF_ENA; 1225 val |= 0x2 | WM8400_VREF_ENA;
1227 wm8400_write(codec, WM8400_POWER_MANAGEMENT_1, val); 1226 snd_soc_write(codec, WM8400_POWER_MANAGEMENT_1, val);
1228 1227
1229 /* Enable BUFIOEN */ 1228 /* Enable BUFIOEN */
1230 wm8400_write(codec, WM8400_ANTIPOP2, WM8400_SOFTST | 1229 snd_soc_write(codec, WM8400_ANTIPOP2, WM8400_SOFTST |
1231 WM8400_BUFDCOPEN | WM8400_POBCTRL | 1230 WM8400_BUFDCOPEN | WM8400_POBCTRL |
1232 WM8400_BUFIOEN); 1231 WM8400_BUFIOEN);
1233 1232
1234 /* disable POBCTRL, SOFT_ST and BUFDCOPEN */ 1233 /* disable POBCTRL, SOFT_ST and BUFDCOPEN */
1235 wm8400_write(codec, WM8400_ANTIPOP2, WM8400_BUFIOEN); 1234 snd_soc_write(codec, WM8400_ANTIPOP2, WM8400_BUFIOEN);
1236 } 1235 }
1237 1236
1238 /* VMID=2*300k */ 1237 /* VMID=2*300k */
1239 val = wm8400_read(codec, WM8400_POWER_MANAGEMENT_1) & 1238 val = snd_soc_read(codec, WM8400_POWER_MANAGEMENT_1) &
1240 ~WM8400_VMID_MODE_MASK; 1239 ~WM8400_VMID_MODE_MASK;
1241 wm8400_write(codec, WM8400_POWER_MANAGEMENT_1, val | 0x4); 1240 snd_soc_write(codec, WM8400_POWER_MANAGEMENT_1, val | 0x4);
1242 break; 1241 break;
1243 1242
1244 case SND_SOC_BIAS_OFF: 1243 case SND_SOC_BIAS_OFF:
1245 /* Enable POBCTRL and SOFT_ST */ 1244 /* Enable POBCTRL and SOFT_ST */
1246 wm8400_write(codec, WM8400_ANTIPOP2, WM8400_SOFTST | 1245 snd_soc_write(codec, WM8400_ANTIPOP2, WM8400_SOFTST |
1247 WM8400_POBCTRL | WM8400_BUFIOEN); 1246 WM8400_POBCTRL | WM8400_BUFIOEN);
1248 1247
1249 /* Enable POBCTRL, SOFT_ST and BUFDCOPEN */ 1248 /* Enable POBCTRL, SOFT_ST and BUFDCOPEN */
1250 wm8400_write(codec, WM8400_ANTIPOP2, WM8400_SOFTST | 1249 snd_soc_write(codec, WM8400_ANTIPOP2, WM8400_SOFTST |
1251 WM8400_BUFDCOPEN | WM8400_POBCTRL | 1250 WM8400_BUFDCOPEN | WM8400_POBCTRL |
1252 WM8400_BUFIOEN); 1251 WM8400_BUFIOEN);
1253 1252
1254 /* mute DAC */ 1253 /* mute DAC */
1255 val = wm8400_read(codec, WM8400_DAC_CTRL); 1254 val = snd_soc_read(codec, WM8400_DAC_CTRL);
1256 wm8400_write(codec, WM8400_DAC_CTRL, val | WM8400_DAC_MUTE); 1255 snd_soc_write(codec, WM8400_DAC_CTRL, val | WM8400_DAC_MUTE);
1257 1256
1258 /* Enable any disabled outputs */ 1257 /* Enable any disabled outputs */
1259 val = wm8400_read(codec, WM8400_POWER_MANAGEMENT_1); 1258 val = snd_soc_read(codec, WM8400_POWER_MANAGEMENT_1);
1260 val |= WM8400_SPK_ENA | WM8400_OUT3_ENA | 1259 val |= WM8400_SPK_ENA | WM8400_OUT3_ENA |
1261 WM8400_OUT4_ENA | WM8400_LOUT_ENA | 1260 WM8400_OUT4_ENA | WM8400_LOUT_ENA |
1262 WM8400_ROUT_ENA; 1261 WM8400_ROUT_ENA;
1263 wm8400_write(codec, WM8400_POWER_MANAGEMENT_1, val); 1262 snd_soc_write(codec, WM8400_POWER_MANAGEMENT_1, val);
1264 1263
1265 /* Disable VMID */ 1264 /* Disable VMID */
1266 val &= ~WM8400_VMID_MODE_MASK; 1265 val &= ~WM8400_VMID_MODE_MASK;
1267 wm8400_write(codec, WM8400_POWER_MANAGEMENT_1, val); 1266 snd_soc_write(codec, WM8400_POWER_MANAGEMENT_1, val);
1268 1267
1269 msleep(300); 1268 msleep(300);
1270 1269
1271 /* Enable all output discharge bits */ 1270 /* Enable all output discharge bits */
1272 wm8400_write(codec, WM8400_ANTIPOP1, WM8400_DIS_LLINE | 1271 snd_soc_write(codec, WM8400_ANTIPOP1, WM8400_DIS_LLINE |
1273 WM8400_DIS_RLINE | WM8400_DIS_OUT3 | 1272 WM8400_DIS_RLINE | WM8400_DIS_OUT3 |
1274 WM8400_DIS_OUT4 | WM8400_DIS_LOUT | 1273 WM8400_DIS_OUT4 | WM8400_DIS_LOUT |
1275 WM8400_DIS_ROUT); 1274 WM8400_DIS_ROUT);
1276 1275
1277 /* Disable VREF */ 1276 /* Disable VREF */
1278 val &= ~WM8400_VREF_ENA; 1277 val &= ~WM8400_VREF_ENA;
1279 wm8400_write(codec, WM8400_POWER_MANAGEMENT_1, val); 1278 snd_soc_write(codec, WM8400_POWER_MANAGEMENT_1, val);
1280 1279
1281 /* disable POBCTRL, SOFT_ST and BUFDCOPEN */ 1280 /* disable POBCTRL, SOFT_ST and BUFDCOPEN */
1282 wm8400_write(codec, WM8400_ANTIPOP2, 0x0); 1281 snd_soc_write(codec, WM8400_ANTIPOP2, 0x0);
1283 1282
1284 ret = regulator_bulk_disable(ARRAY_SIZE(power), 1283 ret = regulator_bulk_disable(ARRAY_SIZE(power),
1285 &power[0]); 1284 &power[0]);
@@ -1385,19 +1384,19 @@ static int wm8400_codec_probe(struct snd_soc_codec *codec)
1385 1384
1386 wm8400_codec_reset(codec); 1385 wm8400_codec_reset(codec);
1387 1386
1388 reg = wm8400_read(codec, WM8400_POWER_MANAGEMENT_1); 1387 reg = snd_soc_read(codec, WM8400_POWER_MANAGEMENT_1);
1389 wm8400_write(codec, WM8400_POWER_MANAGEMENT_1, reg | WM8400_CODEC_ENA); 1388 snd_soc_write(codec, WM8400_POWER_MANAGEMENT_1, reg | WM8400_CODEC_ENA);
1390 1389
1391 /* Latch volume update bits */ 1390 /* Latch volume update bits */
1392 reg = wm8400_read(codec, WM8400_LEFT_LINE_INPUT_1_2_VOLUME); 1391 reg = snd_soc_read(codec, WM8400_LEFT_LINE_INPUT_1_2_VOLUME);
1393 wm8400_write(codec, WM8400_LEFT_LINE_INPUT_1_2_VOLUME, 1392 snd_soc_write(codec, WM8400_LEFT_LINE_INPUT_1_2_VOLUME,
1394 reg & WM8400_IPVU); 1393 reg & WM8400_IPVU);
1395 reg = wm8400_read(codec, WM8400_RIGHT_LINE_INPUT_1_2_VOLUME); 1394 reg = snd_soc_read(codec, WM8400_RIGHT_LINE_INPUT_1_2_VOLUME);
1396 wm8400_write(codec, WM8400_RIGHT_LINE_INPUT_1_2_VOLUME, 1395 snd_soc_write(codec, WM8400_RIGHT_LINE_INPUT_1_2_VOLUME,
1397 reg & WM8400_IPVU); 1396 reg & WM8400_IPVU);
1398 1397
1399 wm8400_write(codec, WM8400_LEFT_OUTPUT_VOLUME, 0x50 | (1<<8)); 1398 snd_soc_write(codec, WM8400_LEFT_OUTPUT_VOLUME, 0x50 | (1<<8));
1400 wm8400_write(codec, WM8400_RIGHT_OUTPUT_VOLUME, 0x50 | (1<<8)); 1399 snd_soc_write(codec, WM8400_RIGHT_OUTPUT_VOLUME, 0x50 | (1<<8));
1401 1400
1402 if (!schedule_work(&priv->work)) { 1401 if (!schedule_work(&priv->work)) {
1403 ret = -EINVAL; 1402 ret = -EINVAL;
@@ -1414,8 +1413,8 @@ static int wm8400_codec_remove(struct snd_soc_codec *codec)
1414{ 1413{
1415 u16 reg; 1414 u16 reg;
1416 1415
1417 reg = wm8400_read(codec, WM8400_POWER_MANAGEMENT_1); 1416 reg = snd_soc_read(codec, WM8400_POWER_MANAGEMENT_1);
1418 wm8400_write(codec, WM8400_POWER_MANAGEMENT_1, 1417 snd_soc_write(codec, WM8400_POWER_MANAGEMENT_1,
1419 reg & (~WM8400_CODEC_ENA)); 1418 reg & (~WM8400_CODEC_ENA));
1420 1419
1421 regulator_bulk_free(ARRAY_SIZE(power), power); 1420 regulator_bulk_free(ARRAY_SIZE(power), power);
@@ -1428,7 +1427,7 @@ static struct snd_soc_codec_driver soc_codec_dev_wm8400 = {
1428 .remove = wm8400_codec_remove, 1427 .remove = wm8400_codec_remove,
1429 .suspend = wm8400_suspend, 1428 .suspend = wm8400_suspend,
1430 .resume = wm8400_resume, 1429 .resume = wm8400_resume,
1431 .read = wm8400_read, 1430 .read = snd_soc_read,
1432 .write = wm8400_write, 1431 .write = wm8400_write,
1433 .set_bias_level = wm8400_set_bias_level, 1432 .set_bias_level = wm8400_set_bias_level,
1434 1433
diff --git a/sound/soc/codecs/wm8510.c b/sound/soc/codecs/wm8510.c
index 9166126bd312..56a049555e2c 100644
--- a/sound/soc/codecs/wm8510.c
+++ b/sound/soc/codecs/wm8510.c
@@ -392,8 +392,7 @@ static int wm8510_pcm_hw_params(struct snd_pcm_substream *substream,
392 struct snd_pcm_hw_params *params, 392 struct snd_pcm_hw_params *params,
393 struct snd_soc_dai *dai) 393 struct snd_soc_dai *dai)
394{ 394{
395 struct snd_soc_pcm_runtime *rtd = substream->private_data; 395 struct snd_soc_codec *codec = dai->codec;
396 struct snd_soc_codec *codec = rtd->codec;
397 u16 iface = snd_soc_read(codec, WM8510_IFACE) & 0x19f; 396 u16 iface = snd_soc_read(codec, WM8510_IFACE) & 0x19f;
398 u16 adn = snd_soc_read(codec, WM8510_ADD) & 0x1f1; 397 u16 adn = snd_soc_read(codec, WM8510_ADD) & 0x1f1;
399 398
diff --git a/sound/soc/codecs/wm8523.c b/sound/soc/codecs/wm8523.c
index 7fea2c3bf7e7..1c3ffb290cdc 100644
--- a/sound/soc/codecs/wm8523.c
+++ b/sound/soc/codecs/wm8523.c
@@ -145,8 +145,7 @@ static int wm8523_hw_params(struct snd_pcm_substream *substream,
145 struct snd_pcm_hw_params *params, 145 struct snd_pcm_hw_params *params,
146 struct snd_soc_dai *dai) 146 struct snd_soc_dai *dai)
147{ 147{
148 struct snd_soc_pcm_runtime *rtd = substream->private_data; 148 struct snd_soc_codec *codec = dai->codec;
149 struct snd_soc_codec *codec = rtd->codec;
150 struct wm8523_priv *wm8523 = snd_soc_codec_get_drvdata(codec); 149 struct wm8523_priv *wm8523 = snd_soc_codec_get_drvdata(codec);
151 int i; 150 int i;
152 u16 aifctrl1 = snd_soc_read(codec, WM8523_AIF_CTRL1); 151 u16 aifctrl1 = snd_soc_read(codec, WM8523_AIF_CTRL1);
diff --git a/sound/soc/codecs/wm8728.c b/sound/soc/codecs/wm8728.c
index fc3d59e49084..1467f97dce21 100644
--- a/sound/soc/codecs/wm8728.c
+++ b/sound/soc/codecs/wm8728.c
@@ -88,8 +88,7 @@ static int wm8728_hw_params(struct snd_pcm_substream *substream,
88 struct snd_pcm_hw_params *params, 88 struct snd_pcm_hw_params *params,
89 struct snd_soc_dai *dai) 89 struct snd_soc_dai *dai)
90{ 90{
91 struct snd_soc_pcm_runtime *rtd = substream->private_data; 91 struct snd_soc_codec *codec = dai->codec;
92 struct snd_soc_codec *codec = rtd->codec;
93 u16 dac = snd_soc_read(codec, WM8728_DACCTL); 92 u16 dac = snd_soc_read(codec, WM8728_DACCTL);
94 93
95 dac &= ~0x18; 94 dac &= ~0x18;
diff --git a/sound/soc/codecs/wm8731.c b/sound/soc/codecs/wm8731.c
index a32caa72bd7d..9d1b9b0271f1 100644
--- a/sound/soc/codecs/wm8731.c
+++ b/sound/soc/codecs/wm8731.c
@@ -635,16 +635,17 @@ static int __devinit wm8731_spi_probe(struct spi_device *spi)
635 struct wm8731_priv *wm8731; 635 struct wm8731_priv *wm8731;
636 int ret; 636 int ret;
637 637
638 wm8731 = kzalloc(sizeof(struct wm8731_priv), GFP_KERNEL); 638 wm8731 = devm_kzalloc(&spi->dev, sizeof(struct wm8731_priv),
639 GFP_KERNEL);
639 if (wm8731 == NULL) 640 if (wm8731 == NULL)
640 return -ENOMEM; 641 return -ENOMEM;
641 642
642 wm8731->regmap = regmap_init_spi(spi, &wm8731_regmap); 643 wm8731->regmap = devm_regmap_init_spi(spi, &wm8731_regmap);
643 if (IS_ERR(wm8731->regmap)) { 644 if (IS_ERR(wm8731->regmap)) {
644 ret = PTR_ERR(wm8731->regmap); 645 ret = PTR_ERR(wm8731->regmap);
645 dev_err(&spi->dev, "Failed to allocate register map: %d\n", 646 dev_err(&spi->dev, "Failed to allocate register map: %d\n",
646 ret); 647 ret);
647 goto err; 648 return ret;
648 } 649 }
649 650
650 spi_set_drvdata(spi, wm8731); 651 spi_set_drvdata(spi, wm8731);
@@ -653,25 +654,15 @@ static int __devinit wm8731_spi_probe(struct spi_device *spi)
653 &soc_codec_dev_wm8731, &wm8731_dai, 1); 654 &soc_codec_dev_wm8731, &wm8731_dai, 1);
654 if (ret != 0) { 655 if (ret != 0) {
655 dev_err(&spi->dev, "Failed to register CODEC: %d\n", ret); 656 dev_err(&spi->dev, "Failed to register CODEC: %d\n", ret);
656 goto err_regmap; 657 return ret;
657 } 658 }
658 659
659 return 0; 660 return 0;
660
661err_regmap:
662 regmap_exit(wm8731->regmap);
663err:
664 kfree(wm8731);
665 return ret;
666} 661}
667 662
668static int __devexit wm8731_spi_remove(struct spi_device *spi) 663static int __devexit wm8731_spi_remove(struct spi_device *spi)
669{ 664{
670 struct wm8731_priv *wm8731 = spi_get_drvdata(spi);
671
672 snd_soc_unregister_codec(&spi->dev); 665 snd_soc_unregister_codec(&spi->dev);
673 regmap_exit(wm8731->regmap);
674 kfree(wm8731);
675 return 0; 666 return 0;
676} 667}
677 668
@@ -693,16 +684,17 @@ static __devinit int wm8731_i2c_probe(struct i2c_client *i2c,
693 struct wm8731_priv *wm8731; 684 struct wm8731_priv *wm8731;
694 int ret; 685 int ret;
695 686
696 wm8731 = kzalloc(sizeof(struct wm8731_priv), GFP_KERNEL); 687 wm8731 = devm_kzalloc(&i2c->dev, sizeof(struct wm8731_priv),
688 GFP_KERNEL);
697 if (wm8731 == NULL) 689 if (wm8731 == NULL)
698 return -ENOMEM; 690 return -ENOMEM;
699 691
700 wm8731->regmap = regmap_init_i2c(i2c, &wm8731_regmap); 692 wm8731->regmap = devm_regmap_init_i2c(i2c, &wm8731_regmap);
701 if (IS_ERR(wm8731->regmap)) { 693 if (IS_ERR(wm8731->regmap)) {
702 ret = PTR_ERR(wm8731->regmap); 694 ret = PTR_ERR(wm8731->regmap);
703 dev_err(&i2c->dev, "Failed to allocate register map: %d\n", 695 dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
704 ret); 696 ret);
705 goto err; 697 return ret;
706 } 698 }
707 699
708 i2c_set_clientdata(i2c, wm8731); 700 i2c_set_clientdata(i2c, wm8731);
@@ -711,24 +703,15 @@ static __devinit int wm8731_i2c_probe(struct i2c_client *i2c,
711 &soc_codec_dev_wm8731, &wm8731_dai, 1); 703 &soc_codec_dev_wm8731, &wm8731_dai, 1);
712 if (ret != 0) { 704 if (ret != 0) {
713 dev_err(&i2c->dev, "Failed to register CODEC: %d\n", ret); 705 dev_err(&i2c->dev, "Failed to register CODEC: %d\n", ret);
714 goto err_regmap; 706 return ret;
715 } 707 }
716 708
717 return 0; 709 return 0;
718
719err_regmap:
720 regmap_exit(wm8731->regmap);
721err:
722 kfree(wm8731);
723 return ret;
724} 710}
725 711
726static __devexit int wm8731_i2c_remove(struct i2c_client *client) 712static __devexit int wm8731_i2c_remove(struct i2c_client *client)
727{ 713{
728 struct wm8731_priv *wm8731 = i2c_get_clientdata(client);
729 snd_soc_unregister_codec(&client->dev); 714 snd_soc_unregister_codec(&client->dev);
730 regmap_exit(wm8731->regmap);
731 kfree(wm8731);
732 return 0; 715 return 0;
733} 716}
734 717
diff --git a/sound/soc/codecs/wm8737.c b/sound/soc/codecs/wm8737.c
index 4fe9d191e277..d0520124616d 100644
--- a/sound/soc/codecs/wm8737.c
+++ b/sound/soc/codecs/wm8737.c
@@ -329,8 +329,7 @@ static int wm8737_hw_params(struct snd_pcm_substream *substream,
329 struct snd_pcm_hw_params *params, 329 struct snd_pcm_hw_params *params,
330 struct snd_soc_dai *dai) 330 struct snd_soc_dai *dai)
331{ 331{
332 struct snd_soc_pcm_runtime *rtd = substream->private_data; 332 struct snd_soc_codec *codec = dai->codec;
333 struct snd_soc_codec *codec = rtd->codec;
334 struct wm8737_priv *wm8737 = snd_soc_codec_get_drvdata(codec); 333 struct wm8737_priv *wm8737 = snd_soc_codec_get_drvdata(codec);
335 int i; 334 int i;
336 u16 clocking = 0; 335 u16 clocking = 0;
diff --git a/sound/soc/codecs/wm8741.c b/sound/soc/codecs/wm8741.c
index 3941f50bf187..6e849cb04243 100644
--- a/sound/soc/codecs/wm8741.c
+++ b/sound/soc/codecs/wm8741.c
@@ -203,8 +203,7 @@ static int wm8741_hw_params(struct snd_pcm_substream *substream,
203 struct snd_pcm_hw_params *params, 203 struct snd_pcm_hw_params *params,
204 struct snd_soc_dai *dai) 204 struct snd_soc_dai *dai)
205{ 205{
206 struct snd_soc_pcm_runtime *rtd = substream->private_data; 206 struct snd_soc_codec *codec = dai->codec;
207 struct snd_soc_codec *codec = rtd->codec;
208 struct wm8741_priv *wm8741 = snd_soc_codec_get_drvdata(codec); 207 struct wm8741_priv *wm8741 = snd_soc_codec_get_drvdata(codec);
209 u16 iface = snd_soc_read(codec, WM8741_FORMAT_CONTROL) & 0x1FC; 208 u16 iface = snd_soc_read(codec, WM8741_FORMAT_CONTROL) & 0x1FC;
210 int i; 209 int i;
diff --git a/sound/soc/codecs/wm8750.c b/sound/soc/codecs/wm8750.c
index e4c50ce7d9c0..89151ca5e776 100644
--- a/sound/soc/codecs/wm8750.c
+++ b/sound/soc/codecs/wm8750.c
@@ -547,8 +547,7 @@ static int wm8750_pcm_hw_params(struct snd_pcm_substream *substream,
547 struct snd_pcm_hw_params *params, 547 struct snd_pcm_hw_params *params,
548 struct snd_soc_dai *dai) 548 struct snd_soc_dai *dai)
549{ 549{
550 struct snd_soc_pcm_runtime *rtd = substream->private_data; 550 struct snd_soc_codec *codec = dai->codec;
551 struct snd_soc_codec *codec = rtd->codec;
552 struct wm8750_priv *wm8750 = snd_soc_codec_get_drvdata(codec); 551 struct wm8750_priv *wm8750 = snd_soc_codec_get_drvdata(codec);
553 u16 iface = snd_soc_read(codec, WM8750_IFACE) & 0x1f3; 552 u16 iface = snd_soc_read(codec, WM8750_IFACE) & 0x1f3;
554 u16 srate = snd_soc_read(codec, WM8750_SRATE) & 0x1c0; 553 u16 srate = snd_soc_read(codec, WM8750_SRATE) & 0x1c0;
diff --git a/sound/soc/codecs/wm8753.c b/sound/soc/codecs/wm8753.c
index e27e7b62b365..a26482cd7654 100644
--- a/sound/soc/codecs/wm8753.c
+++ b/sound/soc/codecs/wm8753.c
@@ -931,8 +931,7 @@ static int wm8753_pcm_hw_params(struct snd_pcm_substream *substream,
931 struct snd_pcm_hw_params *params, 931 struct snd_pcm_hw_params *params,
932 struct snd_soc_dai *dai) 932 struct snd_soc_dai *dai)
933{ 933{
934 struct snd_soc_pcm_runtime *rtd = substream->private_data; 934 struct snd_soc_codec *codec = dai->codec;
935 struct snd_soc_codec *codec = rtd->codec;
936 struct wm8753_priv *wm8753 = snd_soc_codec_get_drvdata(codec); 935 struct wm8753_priv *wm8753 = snd_soc_codec_get_drvdata(codec);
937 u16 voice = snd_soc_read(codec, WM8753_PCM) & 0x01f3; 936 u16 voice = snd_soc_read(codec, WM8753_PCM) & 0x01f3;
938 u16 srate = snd_soc_read(codec, WM8753_SRATE1) & 0x017f; 937 u16 srate = snd_soc_read(codec, WM8753_SRATE1) & 0x017f;
@@ -1161,8 +1160,7 @@ static int wm8753_i2s_hw_params(struct snd_pcm_substream *substream,
1161 struct snd_pcm_hw_params *params, 1160 struct snd_pcm_hw_params *params,
1162 struct snd_soc_dai *dai) 1161 struct snd_soc_dai *dai)
1163{ 1162{
1164 struct snd_soc_pcm_runtime *rtd = substream->private_data; 1163 struct snd_soc_codec *codec = dai->codec;
1165 struct snd_soc_codec *codec = rtd->codec;
1166 struct wm8753_priv *wm8753 = snd_soc_codec_get_drvdata(codec); 1164 struct wm8753_priv *wm8753 = snd_soc_codec_get_drvdata(codec);
1167 u16 srate = snd_soc_read(codec, WM8753_SRATE1) & 0x01c0; 1165 u16 srate = snd_soc_read(codec, WM8753_SRATE1) & 0x01c0;
1168 u16 hifi = snd_soc_read(codec, WM8753_HIFI) & 0x01f3; 1166 u16 hifi = snd_soc_read(codec, WM8753_HIFI) & 0x01f3;
diff --git a/sound/soc/codecs/wm8900.c b/sound/soc/codecs/wm8900.c
index f18c554efc98..077c9628c70d 100644
--- a/sound/soc/codecs/wm8900.c
+++ b/sound/soc/codecs/wm8900.c
@@ -610,8 +610,7 @@ static int wm8900_hw_params(struct snd_pcm_substream *substream,
610 struct snd_pcm_hw_params *params, 610 struct snd_pcm_hw_params *params,
611 struct snd_soc_dai *dai) 611 struct snd_soc_dai *dai)
612{ 612{
613 struct snd_soc_pcm_runtime *rtd = substream->private_data; 613 struct snd_soc_codec *codec = dai->codec;
614 struct snd_soc_codec *codec = rtd->codec;
615 u16 reg; 614 u16 reg;
616 615
617 reg = snd_soc_read(codec, WM8900_REG_AUDIO1) & ~0x60; 616 reg = snd_soc_read(codec, WM8900_REG_AUDIO1) & ~0x60;
diff --git a/sound/soc/codecs/wm8903.c b/sound/soc/codecs/wm8903.c
index c91fb2f99c13..86b8a2926591 100644
--- a/sound/soc/codecs/wm8903.c
+++ b/sound/soc/codecs/wm8903.c
@@ -1432,8 +1432,7 @@ static int wm8903_hw_params(struct snd_pcm_substream *substream,
1432 struct snd_pcm_hw_params *params, 1432 struct snd_pcm_hw_params *params,
1433 struct snd_soc_dai *dai) 1433 struct snd_soc_dai *dai)
1434{ 1434{
1435 struct snd_soc_pcm_runtime *rtd = substream->private_data; 1435 struct snd_soc_codec *codec = dai->codec;
1436 struct snd_soc_codec *codec =rtd->codec;
1437 struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec); 1436 struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec);
1438 int fs = params_rate(params); 1437 int fs = params_rate(params);
1439 int bclk; 1438 int bclk;
diff --git a/sound/soc/codecs/wm8940.c b/sound/soc/codecs/wm8940.c
index d2883affea3b..481a3d9cfe48 100644
--- a/sound/soc/codecs/wm8940.c
+++ b/sound/soc/codecs/wm8940.c
@@ -371,8 +371,7 @@ static int wm8940_i2s_hw_params(struct snd_pcm_substream *substream,
371 struct snd_pcm_hw_params *params, 371 struct snd_pcm_hw_params *params,
372 struct snd_soc_dai *dai) 372 struct snd_soc_dai *dai)
373{ 373{
374 struct snd_soc_pcm_runtime *rtd = substream->private_data; 374 struct snd_soc_codec *codec = dai->codec;
375 struct snd_soc_codec *codec = rtd->codec;
376 u16 iface = snd_soc_read(codec, WM8940_IFACE) & 0xFD9F; 375 u16 iface = snd_soc_read(codec, WM8940_IFACE) & 0xFD9F;
377 u16 addcntrl = snd_soc_read(codec, WM8940_ADDCNTRL) & 0xFFF1; 376 u16 addcntrl = snd_soc_read(codec, WM8940_ADDCNTRL) & 0xFFF1;
378 u16 companding = snd_soc_read(codec, 377 u16 companding = snd_soc_read(codec,
diff --git a/sound/soc/codecs/wm8960.c b/sound/soc/codecs/wm8960.c
index 840d72086d04..8bc659d8dd2e 100644
--- a/sound/soc/codecs/wm8960.c
+++ b/sound/soc/codecs/wm8960.c
@@ -505,8 +505,7 @@ static int wm8960_hw_params(struct snd_pcm_substream *substream,
505 struct snd_pcm_hw_params *params, 505 struct snd_pcm_hw_params *params,
506 struct snd_soc_dai *dai) 506 struct snd_soc_dai *dai)
507{ 507{
508 struct snd_soc_pcm_runtime *rtd = substream->private_data; 508 struct snd_soc_codec *codec = dai->codec;
509 struct snd_soc_codec *codec = rtd->codec;
510 struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); 509 struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
511 u16 iface = snd_soc_read(codec, WM8960_IFACE1) & 0xfff3; 510 u16 iface = snd_soc_read(codec, WM8960_IFACE1) & 0xfff3;
512 int i; 511 int i;
diff --git a/sound/soc/codecs/wm8962.c b/sound/soc/codecs/wm8962.c
index 15d467ff91b4..0cfce9999c89 100644
--- a/sound/soc/codecs/wm8962.c
+++ b/sound/soc/codecs/wm8962.c
@@ -1478,7 +1478,8 @@ static const DECLARE_TLV_DB_SCALE(eq_tlv, -1200, 100, 0);
1478 1478
1479static int wm8962_dsp2_write_config(struct snd_soc_codec *codec) 1479static int wm8962_dsp2_write_config(struct snd_soc_codec *codec)
1480{ 1480{
1481 return 0; 1481 return regcache_sync_region(codec->control_data,
1482 WM8962_HDBASS_AI_1, WM8962_MAX_REGISTER);
1482} 1483}
1483 1484
1484static int wm8962_dsp2_set_enable(struct snd_soc_codec *codec, u16 val) 1485static int wm8962_dsp2_set_enable(struct snd_soc_codec *codec, u16 val)
@@ -1755,10 +1756,22 @@ SOC_DOUBLE_R_TLV("EQ4 Volume", WM8962_EQ3, WM8962_EQ23,
1755SOC_DOUBLE_R_TLV("EQ5 Volume", WM8962_EQ3, WM8962_EQ23, 1756SOC_DOUBLE_R_TLV("EQ5 Volume", WM8962_EQ3, WM8962_EQ23,
1756 WM8962_EQL_B5_GAIN_SHIFT, 31, 0, eq_tlv), 1757 WM8962_EQL_B5_GAIN_SHIFT, 31, 0, eq_tlv),
1757 1758
1759SOC_SINGLE("3D Switch", WM8962_THREED1, 0, 1, 0),
1760SND_SOC_BYTES_MASK("3D Coefficients", WM8962_THREED1, 4, WM8962_THREED_ENA),
1761
1762SOC_SINGLE("DF1 Switch", WM8962_DF1, 0, 1, 0),
1763SND_SOC_BYTES_MASK("DF1 Coefficients", WM8962_DF1, 7, WM8962_DF1_ENA),
1764
1765SOC_SINGLE("DRC Switch", WM8962_DRC_1, 0, 1, 0),
1766SND_SOC_BYTES_MASK("DRC Coefficients", WM8962_DRC_1, 5, WM8962_DRC_ENA),
1767
1758WM8962_DSP2_ENABLE("VSS Switch", WM8962_VSS_ENA_SHIFT), 1768WM8962_DSP2_ENABLE("VSS Switch", WM8962_VSS_ENA_SHIFT),
1769SND_SOC_BYTES("VSS Coefficients", WM8962_VSS_XHD2_1, 148),
1759WM8962_DSP2_ENABLE("HPF1 Switch", WM8962_HPF1_ENA_SHIFT), 1770WM8962_DSP2_ENABLE("HPF1 Switch", WM8962_HPF1_ENA_SHIFT),
1760WM8962_DSP2_ENABLE("HPF2 Switch", WM8962_HPF2_ENA_SHIFT), 1771WM8962_DSP2_ENABLE("HPF2 Switch", WM8962_HPF2_ENA_SHIFT),
1772SND_SOC_BYTES("HPF Coefficients", WM8962_LHPF2, 1),
1761WM8962_DSP2_ENABLE("HD Bass Switch", WM8962_HDBASS_ENA_SHIFT), 1773WM8962_DSP2_ENABLE("HD Bass Switch", WM8962_HDBASS_ENA_SHIFT),
1774SND_SOC_BYTES("HD Bass Coefficients", WM8962_HDBASS_AI_1, 30),
1762}; 1775};
1763 1776
1764static const struct snd_kcontrol_new wm8962_spk_mono_controls[] = { 1777static const struct snd_kcontrol_new wm8962_spk_mono_controls[] = {
@@ -2519,8 +2532,7 @@ static int wm8962_hw_params(struct snd_pcm_substream *substream,
2519 struct snd_pcm_hw_params *params, 2532 struct snd_pcm_hw_params *params,
2520 struct snd_soc_dai *dai) 2533 struct snd_soc_dai *dai)
2521{ 2534{
2522 struct snd_soc_pcm_runtime *rtd = substream->private_data; 2535 struct snd_soc_codec *codec = dai->codec;
2523 struct snd_soc_codec *codec = rtd->codec;
2524 struct wm8962_priv *wm8962 = snd_soc_codec_get_drvdata(codec); 2536 struct wm8962_priv *wm8962 = snd_soc_codec_get_drvdata(codec);
2525 int i; 2537 int i;
2526 int aif0 = 0; 2538 int aif0 = 0;
diff --git a/sound/soc/codecs/wm8971.c b/sound/soc/codecs/wm8971.c
index 28fe59e3ce01..eef783f6b6d6 100644
--- a/sound/soc/codecs/wm8971.c
+++ b/sound/soc/codecs/wm8971.c
@@ -478,8 +478,7 @@ static int wm8971_pcm_hw_params(struct snd_pcm_substream *substream,
478 struct snd_pcm_hw_params *params, 478 struct snd_pcm_hw_params *params,
479 struct snd_soc_dai *dai) 479 struct snd_soc_dai *dai)
480{ 480{
481 struct snd_soc_pcm_runtime *rtd = substream->private_data; 481 struct snd_soc_codec *codec = dai->codec;
482 struct snd_soc_codec *codec = rtd->codec;
483 struct wm8971_priv *wm8971 = snd_soc_codec_get_drvdata(codec); 482 struct wm8971_priv *wm8971 = snd_soc_codec_get_drvdata(codec);
484 u16 iface = snd_soc_read(codec, WM8971_IFACE) & 0x1f3; 483 u16 iface = snd_soc_read(codec, WM8971_IFACE) & 0x1f3;
485 u16 srate = snd_soc_read(codec, WM8971_SRATE) & 0x1c0; 484 u16 srate = snd_soc_read(codec, WM8971_SRATE) & 0x1c0;
diff --git a/sound/soc/codecs/wm8978.c b/sound/soc/codecs/wm8978.c
index 72d5fdcd3cc2..a5be3adecf75 100644
--- a/sound/soc/codecs/wm8978.c
+++ b/sound/soc/codecs/wm8978.c
@@ -723,8 +723,7 @@ static int wm8978_hw_params(struct snd_pcm_substream *substream,
723 struct snd_pcm_hw_params *params, 723 struct snd_pcm_hw_params *params,
724 struct snd_soc_dai *dai) 724 struct snd_soc_dai *dai)
725{ 725{
726 struct snd_soc_pcm_runtime *rtd = substream->private_data; 726 struct snd_soc_codec *codec = dai->codec;
727 struct snd_soc_codec *codec = rtd->codec;
728 struct wm8978_priv *wm8978 = snd_soc_codec_get_drvdata(codec); 727 struct wm8978_priv *wm8978 = snd_soc_codec_get_drvdata(codec);
729 /* Word length mask = 0x60 */ 728 /* Word length mask = 0x60 */
730 u16 iface_ctl = snd_soc_read(codec, WM8978_AUDIO_INTERFACE) & ~0x60; 729 u16 iface_ctl = snd_soc_read(codec, WM8978_AUDIO_INTERFACE) & ~0x60;
diff --git a/sound/soc/codecs/wm8988.c b/sound/soc/codecs/wm8988.c
index 6cdf6a2bc283..1d4c5cf47b06 100644
--- a/sound/soc/codecs/wm8988.c
+++ b/sound/soc/codecs/wm8988.c
@@ -668,8 +668,7 @@ static int wm8988_pcm_hw_params(struct snd_pcm_substream *substream,
668 struct snd_pcm_hw_params *params, 668 struct snd_pcm_hw_params *params,
669 struct snd_soc_dai *dai) 669 struct snd_soc_dai *dai)
670{ 670{
671 struct snd_soc_pcm_runtime *rtd = substream->private_data; 671 struct snd_soc_codec *codec = dai->codec;
672 struct snd_soc_codec *codec = rtd->codec;
673 struct wm8988_priv *wm8988 = snd_soc_codec_get_drvdata(codec); 672 struct wm8988_priv *wm8988 = snd_soc_codec_get_drvdata(codec);
674 u16 iface = snd_soc_read(codec, WM8988_IFACE) & 0x1f3; 673 u16 iface = snd_soc_read(codec, WM8988_IFACE) & 0x1f3;
675 u16 srate = snd_soc_read(codec, WM8988_SRATE) & 0x180; 674 u16 srate = snd_soc_read(codec, WM8988_SRATE) & 0x180;
diff --git a/sound/soc/codecs/wm8990.c b/sound/soc/codecs/wm8990.c
index 9d242351e6e8..db63c97ddf51 100644
--- a/sound/soc/codecs/wm8990.c
+++ b/sound/soc/codecs/wm8990.c
@@ -1112,8 +1112,7 @@ static int wm8990_hw_params(struct snd_pcm_substream *substream,
1112 struct snd_pcm_hw_params *params, 1112 struct snd_pcm_hw_params *params,
1113 struct snd_soc_dai *dai) 1113 struct snd_soc_dai *dai)
1114{ 1114{
1115 struct snd_soc_pcm_runtime *rtd = substream->private_data; 1115 struct snd_soc_codec *codec = dai->codec;
1116 struct snd_soc_codec *codec = rtd->codec;
1117 u16 audio1 = snd_soc_read(codec, WM8990_AUDIO_INTERFACE_1); 1116 u16 audio1 = snd_soc_read(codec, WM8990_AUDIO_INTERFACE_1);
1118 1117
1119 audio1 &= ~WM8990_AIF_WL_MASK; 1118 audio1 &= ~WM8990_AIF_WL_MASK;
diff --git a/sound/soc/codecs/wm8993.c b/sound/soc/codecs/wm8993.c
index d256a9340644..36acfccab999 100644
--- a/sound/soc/codecs/wm8993.c
+++ b/sound/soc/codecs/wm8993.c
@@ -218,7 +218,6 @@ struct wm8993_priv {
218 unsigned int sysclk_rate; 218 unsigned int sysclk_rate;
219 unsigned int fs; 219 unsigned int fs;
220 unsigned int bclk; 220 unsigned int bclk;
221 int class_w_users;
222 unsigned int fll_fref; 221 unsigned int fll_fref;
223 unsigned int fll_fout; 222 unsigned int fll_fout;
224 int fll_src; 223 int fll_src;
@@ -824,84 +823,6 @@ static int clk_sys_event(struct snd_soc_dapm_widget *w,
824 return 0; 823 return 0;
825} 824}
826 825
827/*
828 * When used with DAC outputs only the WM8993 charge pump supports
829 * operation in class W mode, providing very low power consumption
830 * when used with digital sources. Enable and disable this mode
831 * automatically depending on the mixer configuration.
832 *
833 * Currently the only supported paths are the direct DAC->headphone
834 * paths (which provide minimum power consumption anyway).
835 */
836static int class_w_put(struct snd_kcontrol *kcontrol,
837 struct snd_ctl_elem_value *ucontrol)
838{
839 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
840 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
841 struct snd_soc_codec *codec = widget->codec;
842 struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec);
843 int ret;
844
845 /* Turn it off if we're using the main output mixer */
846 if (ucontrol->value.integer.value[0] == 0) {
847 if (wm8993->class_w_users == 0) {
848 dev_dbg(codec->dev, "Disabling Class W\n");
849 snd_soc_update_bits(codec, WM8993_CLASS_W_0,
850 WM8993_CP_DYN_FREQ |
851 WM8993_CP_DYN_V,
852 0);
853 }
854 wm8993->class_w_users++;
855 wm8993->hubs_data.class_w = true;
856 }
857
858 /* Implement the change */
859 ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
860
861 /* Enable it if we're using the direct DAC path */
862 if (ucontrol->value.integer.value[0] == 1) {
863 if (wm8993->class_w_users == 1) {
864 dev_dbg(codec->dev, "Enabling Class W\n");
865 snd_soc_update_bits(codec, WM8993_CLASS_W_0,
866 WM8993_CP_DYN_FREQ |
867 WM8993_CP_DYN_V,
868 WM8993_CP_DYN_FREQ |
869 WM8993_CP_DYN_V);
870 }
871 wm8993->class_w_users--;
872 wm8993->hubs_data.class_w = false;
873 }
874
875 dev_dbg(codec->dev, "Indirect DAC use count now %d\n",
876 wm8993->class_w_users);
877
878 return ret;
879}
880
881#define SOC_DAPM_ENUM_W(xname, xenum) \
882{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
883 .info = snd_soc_info_enum_double, \
884 .get = snd_soc_dapm_get_enum_double, \
885 .put = class_w_put, \
886 .private_value = (unsigned long)&xenum }
887
888static const char *hp_mux_text[] = {
889 "Mixer",
890 "DAC",
891};
892
893static const struct soc_enum hpl_enum =
894 SOC_ENUM_SINGLE(WM8993_OUTPUT_MIXER1, 8, 2, hp_mux_text);
895
896static const struct snd_kcontrol_new hpl_mux =
897 SOC_DAPM_ENUM_W("Left Headphone Mux", hpl_enum);
898
899static const struct soc_enum hpr_enum =
900 SOC_ENUM_SINGLE(WM8993_OUTPUT_MIXER2, 8, 2, hp_mux_text);
901
902static const struct snd_kcontrol_new hpr_mux =
903 SOC_DAPM_ENUM_W("Right Headphone Mux", hpr_enum);
904
905static const struct snd_kcontrol_new left_speaker_mixer[] = { 826static const struct snd_kcontrol_new left_speaker_mixer[] = {
906SOC_DAPM_SINGLE("Input Switch", WM8993_SPEAKER_MIXER, 7, 1, 0), 827SOC_DAPM_SINGLE("Input Switch", WM8993_SPEAKER_MIXER, 7, 1, 0),
907SOC_DAPM_SINGLE("IN1LP Switch", WM8993_SPEAKER_MIXER, 5, 1, 0), 828SOC_DAPM_SINGLE("IN1LP Switch", WM8993_SPEAKER_MIXER, 5, 1, 0),
@@ -988,8 +909,8 @@ SND_SOC_DAPM_MUX("DACR Sidetone", SND_SOC_NOPM, 0, 0, &sidetoner_mux),
988SND_SOC_DAPM_DAC("DACL", NULL, WM8993_POWER_MANAGEMENT_3, 1, 0), 909SND_SOC_DAPM_DAC("DACL", NULL, WM8993_POWER_MANAGEMENT_3, 1, 0),
989SND_SOC_DAPM_DAC("DACR", NULL, WM8993_POWER_MANAGEMENT_3, 0, 0), 910SND_SOC_DAPM_DAC("DACR", NULL, WM8993_POWER_MANAGEMENT_3, 0, 0),
990 911
991SND_SOC_DAPM_MUX("Left Headphone Mux", SND_SOC_NOPM, 0, 0, &hpl_mux), 912SND_SOC_DAPM_MUX("Left Headphone Mux", SND_SOC_NOPM, 0, 0, &wm_hubs_hpl_mux),
992SND_SOC_DAPM_MUX("Right Headphone Mux", SND_SOC_NOPM, 0, 0, &hpr_mux), 913SND_SOC_DAPM_MUX("Right Headphone Mux", SND_SOC_NOPM, 0, 0, &wm_hubs_hpr_mux),
993 914
994SND_SOC_DAPM_MIXER("SPKL", WM8993_POWER_MANAGEMENT_3, 8, 0, 915SND_SOC_DAPM_MIXER("SPKL", WM8993_POWER_MANAGEMENT_3, 8, 0,
995 left_speaker_mixer, ARRAY_SIZE(left_speaker_mixer)), 916 left_speaker_mixer, ARRAY_SIZE(left_speaker_mixer)),
@@ -1579,9 +1500,6 @@ static int wm8993_probe(struct snd_soc_codec *codec)
1579 return ret; 1500 return ret;
1580 } 1501 }
1581 1502
1582 /* By default we're using the output mixers */
1583 wm8993->class_w_users = 2;
1584
1585 /* Latch volume update bits and default ZC on */ 1503 /* Latch volume update bits and default ZC on */
1586 snd_soc_update_bits(codec, WM8993_RIGHT_DAC_DIGITAL_VOLUME, 1504 snd_soc_update_bits(codec, WM8993_RIGHT_DAC_DIGITAL_VOLUME,
1587 WM8993_DAC_VU, WM8993_DAC_VU); 1505 WM8993_DAC_VU, WM8993_DAC_VU);
diff --git a/sound/soc/codecs/wm8994.c b/sound/soc/codecs/wm8994.c
index 2de12ebe43b5..993639d694ce 100644
--- a/sound/soc/codecs/wm8994.c
+++ b/sound/soc/codecs/wm8994.c
@@ -70,8 +70,8 @@ static const struct wm8958_micd_rate micdet_rates[] = {
70static const struct wm8958_micd_rate jackdet_rates[] = { 70static const struct wm8958_micd_rate jackdet_rates[] = {
71 { 32768, true, 0, 1 }, 71 { 32768, true, 0, 1 },
72 { 32768, false, 0, 1 }, 72 { 32768, false, 0, 1 },
73 { 44100 * 256, true, 7, 10 }, 73 { 44100 * 256, true, 10, 10 },
74 { 44100 * 256, false, 7, 10 }, 74 { 44100 * 256, false, 7, 8 },
75}; 75};
76 76
77static void wm8958_micd_set_rate(struct snd_soc_codec *codec) 77static void wm8958_micd_set_rate(struct snd_soc_codec *codec)
@@ -82,7 +82,8 @@ static void wm8958_micd_set_rate(struct snd_soc_codec *codec)
82 const struct wm8958_micd_rate *rates; 82 const struct wm8958_micd_rate *rates;
83 int num_rates; 83 int num_rates;
84 84
85 if (wm8994->jack_cb != wm8958_default_micdet) 85 if (!(wm8994->pdata && wm8994->pdata->micd_rates) &&
86 wm8994->jack_cb != wm8958_default_micdet)
86 return; 87 return;
87 88
88 idle = !wm8994->jack_mic; 89 idle = !wm8994->jack_mic;
@@ -118,6 +119,10 @@ static void wm8958_micd_set_rate(struct snd_soc_codec *codec)
118 val = rates[best].start << WM8958_MICD_BIAS_STARTTIME_SHIFT 119 val = rates[best].start << WM8958_MICD_BIAS_STARTTIME_SHIFT
119 | rates[best].rate << WM8958_MICD_RATE_SHIFT; 120 | rates[best].rate << WM8958_MICD_RATE_SHIFT;
120 121
122 dev_dbg(codec->dev, "MICD rate %d,%d for %dHz %s\n",
123 rates[best].start, rates[best].rate, sysclk,
124 idle ? "idle" : "active");
125
121 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1, 126 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
122 WM8958_MICD_BIAS_STARTTIME_MASK | 127 WM8958_MICD_BIAS_STARTTIME_MASK |
123 WM8958_MICD_RATE_MASK, val); 128 WM8958_MICD_RATE_MASK, val);
@@ -398,7 +403,7 @@ static void wm8994_set_retune_mobile(struct snd_soc_codec *codec, int block)
398 wm8994->dac_rates[iface]); 403 wm8994->dac_rates[iface]);
399 404
400 /* The EQ will be disabled while reconfiguring it, remember the 405 /* The EQ will be disabled while reconfiguring it, remember the
401 * current configuration. 406 * current configuration.
402 */ 407 */
403 save = snd_soc_read(codec, base); 408 save = snd_soc_read(codec, base);
404 save &= WM8994_AIF1DAC1_EQ_ENA; 409 save &= WM8994_AIF1DAC1_EQ_ENA;
@@ -689,6 +694,9 @@ static void wm1811_jackdet_set_mode(struct snd_soc_codec *codec, u16 mode)
689 if (!wm8994->jackdet || !wm8994->jack_cb) 694 if (!wm8994->jackdet || !wm8994->jack_cb)
690 return; 695 return;
691 696
697 if (!wm8994->jackdet || !wm8994->jack_cb)
698 return;
699
692 if (wm8994->active_refcount) 700 if (wm8994->active_refcount)
693 mode = WM1811_JACKDET_MODE_AUDIO; 701 mode = WM1811_JACKDET_MODE_AUDIO;
694 702
@@ -784,7 +792,7 @@ static void vmid_reference(struct snd_soc_codec *codec)
784 792
785 switch (wm8994->vmid_mode) { 793 switch (wm8994->vmid_mode) {
786 default: 794 default:
787 WARN_ON(0 == "Invalid VMID mode"); 795 WARN_ON(NULL == "Invalid VMID mode");
788 case WM8994_VMID_NORMAL: 796 case WM8994_VMID_NORMAL:
789 /* Startup bias, VMID ramp & buffer */ 797 /* Startup bias, VMID ramp & buffer */
790 snd_soc_update_bits(codec, WM8994_ANTIPOP_2, 798 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
@@ -937,27 +945,12 @@ static int vmid_event(struct snd_soc_dapm_widget *w,
937 return 0; 945 return 0;
938} 946}
939 947
940static void wm8994_update_class_w(struct snd_soc_codec *codec) 948static bool wm8994_check_class_w_digital(struct snd_soc_codec *codec)
941{ 949{
942 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
943 int enable = 1;
944 int source = 0; /* GCC flow analysis can't track enable */ 950 int source = 0; /* GCC flow analysis can't track enable */
945 int reg, reg_r; 951 int reg, reg_r;
946 952
947 /* Only support direct DAC->headphone paths */ 953 /* We also need the same AIF source for L/R and only one path */
948 reg = snd_soc_read(codec, WM8994_OUTPUT_MIXER_1);
949 if (!(reg & WM8994_DAC1L_TO_HPOUT1L)) {
950 dev_vdbg(codec->dev, "HPL connected to output mixer\n");
951 enable = 0;
952 }
953
954 reg = snd_soc_read(codec, WM8994_OUTPUT_MIXER_2);
955 if (!(reg & WM8994_DAC1R_TO_HPOUT1R)) {
956 dev_vdbg(codec->dev, "HPR connected to output mixer\n");
957 enable = 0;
958 }
959
960 /* We also need the same setting for L/R and only one path */
961 reg = snd_soc_read(codec, WM8994_DAC1_LEFT_MIXER_ROUTING); 954 reg = snd_soc_read(codec, WM8994_DAC1_LEFT_MIXER_ROUTING);
962 switch (reg) { 955 switch (reg) {
963 case WM8994_AIF2DACL_TO_DAC1L: 956 case WM8994_AIF2DACL_TO_DAC1L:
@@ -974,30 +967,20 @@ static void wm8994_update_class_w(struct snd_soc_codec *codec)
974 break; 967 break;
975 default: 968 default:
976 dev_vdbg(codec->dev, "DAC mixer setting: %x\n", reg); 969 dev_vdbg(codec->dev, "DAC mixer setting: %x\n", reg);
977 enable = 0; 970 return false;
978 break;
979 } 971 }
980 972
981 reg_r = snd_soc_read(codec, WM8994_DAC1_RIGHT_MIXER_ROUTING); 973 reg_r = snd_soc_read(codec, WM8994_DAC1_RIGHT_MIXER_ROUTING);
982 if (reg_r != reg) { 974 if (reg_r != reg) {
983 dev_vdbg(codec->dev, "Left and right DAC mixers different\n"); 975 dev_vdbg(codec->dev, "Left and right DAC mixers different\n");
984 enable = 0; 976 return false;
985 } 977 }
986 978
987 if (enable) { 979 /* Set the source up */
988 dev_dbg(codec->dev, "Class W enabled\n"); 980 snd_soc_update_bits(codec, WM8994_CLASS_W_1,
989 snd_soc_update_bits(codec, WM8994_CLASS_W_1, 981 WM8994_CP_DYN_SRC_SEL_MASK, source);
990 WM8994_CP_DYN_PWR | 982
991 WM8994_CP_DYN_SRC_SEL_MASK, 983 return true;
992 source | WM8994_CP_DYN_PWR);
993 wm8994->hubs.class_w = true;
994
995 } else {
996 dev_dbg(codec->dev, "Class W disabled\n");
997 snd_soc_update_bits(codec, WM8994_CLASS_W_1,
998 WM8994_CP_DYN_PWR, 0);
999 wm8994->hubs.class_w = false;
1000 }
1001} 984}
1002 985
1003static int aif1clk_ev(struct snd_soc_dapm_widget *w, 986static int aif1clk_ev(struct snd_soc_dapm_widget *w,
@@ -1280,45 +1263,6 @@ static int dac_ev(struct snd_soc_dapm_widget *w,
1280 return 0; 1263 return 0;
1281} 1264}
1282 1265
1283static const char *hp_mux_text[] = {
1284 "Mixer",
1285 "DAC",
1286};
1287
1288#define WM8994_HP_ENUM(xname, xenum) \
1289{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1290 .info = snd_soc_info_enum_double, \
1291 .get = snd_soc_dapm_get_enum_double, \
1292 .put = wm8994_put_hp_enum, \
1293 .private_value = (unsigned long)&xenum }
1294
1295static int wm8994_put_hp_enum(struct snd_kcontrol *kcontrol,
1296 struct snd_ctl_elem_value *ucontrol)
1297{
1298 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
1299 struct snd_soc_dapm_widget *w = wlist->widgets[0];
1300 struct snd_soc_codec *codec = w->codec;
1301 int ret;
1302
1303 ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
1304
1305 wm8994_update_class_w(codec);
1306
1307 return ret;
1308}
1309
1310static const struct soc_enum hpl_enum =
1311 SOC_ENUM_SINGLE(WM8994_OUTPUT_MIXER_1, 8, 2, hp_mux_text);
1312
1313static const struct snd_kcontrol_new hpl_mux =
1314 WM8994_HP_ENUM("Left Headphone Mux", hpl_enum);
1315
1316static const struct soc_enum hpr_enum =
1317 SOC_ENUM_SINGLE(WM8994_OUTPUT_MIXER_2, 8, 2, hp_mux_text);
1318
1319static const struct snd_kcontrol_new hpr_mux =
1320 WM8994_HP_ENUM("Right Headphone Mux", hpr_enum);
1321
1322static const char *adc_mux_text[] = { 1266static const char *adc_mux_text[] = {
1323 "ADC", 1267 "ADC",
1324 "DMIC", 1268 "DMIC",
@@ -1430,7 +1374,7 @@ static int wm8994_put_class_w(struct snd_kcontrol *kcontrol,
1430 1374
1431 ret = snd_soc_dapm_put_volsw(kcontrol, ucontrol); 1375 ret = snd_soc_dapm_put_volsw(kcontrol, ucontrol);
1432 1376
1433 wm8994_update_class_w(codec); 1377 wm_hubs_update_class_w(codec);
1434 1378
1435 return ret; 1379 return ret;
1436} 1380}
@@ -1524,7 +1468,7 @@ static const struct snd_kcontrol_new wm8958_aif3adc_mux =
1524 SOC_DAPM_ENUM("AIF3ADC Mux", wm8958_aif3adc_enum); 1468 SOC_DAPM_ENUM("AIF3ADC Mux", wm8958_aif3adc_enum);
1525 1469
1526static const char *mono_pcm_out_text[] = { 1470static const char *mono_pcm_out_text[] = {
1527 "None", "AIF2ADCL", "AIF2ADCR", 1471 "None", "AIF2ADCL", "AIF2ADCR",
1528}; 1472};
1529 1473
1530static const struct soc_enum mono_pcm_out_enum = 1474static const struct soc_enum mono_pcm_out_enum =
@@ -1573,9 +1517,9 @@ SND_SOC_DAPM_MIXER_E("SPKL", WM8994_POWER_MANAGEMENT_3, 8, 0,
1573SND_SOC_DAPM_MIXER_E("SPKR", WM8994_POWER_MANAGEMENT_3, 9, 0, 1517SND_SOC_DAPM_MIXER_E("SPKR", WM8994_POWER_MANAGEMENT_3, 9, 0,
1574 right_speaker_mixer, ARRAY_SIZE(right_speaker_mixer), 1518 right_speaker_mixer, ARRAY_SIZE(right_speaker_mixer),
1575 late_enable_ev, SND_SOC_DAPM_PRE_PMU), 1519 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1576SND_SOC_DAPM_MUX_E("Left Headphone Mux", SND_SOC_NOPM, 0, 0, &hpl_mux, 1520SND_SOC_DAPM_MUX_E("Left Headphone Mux", SND_SOC_NOPM, 0, 0, &wm_hubs_hpl_mux,
1577 late_enable_ev, SND_SOC_DAPM_PRE_PMU), 1521 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1578SND_SOC_DAPM_MUX_E("Right Headphone Mux", SND_SOC_NOPM, 0, 0, &hpr_mux, 1522SND_SOC_DAPM_MUX_E("Right Headphone Mux", SND_SOC_NOPM, 0, 0, &wm_hubs_hpr_mux,
1579 late_enable_ev, SND_SOC_DAPM_PRE_PMU), 1523 late_enable_ev, SND_SOC_DAPM_PRE_PMU),
1580 1524
1581SND_SOC_DAPM_POST("Late Disable PGA", late_disable_ev) 1525SND_SOC_DAPM_POST("Late Disable PGA", late_disable_ev)
@@ -1591,8 +1535,8 @@ SND_SOC_DAPM_MIXER("SPKL", WM8994_POWER_MANAGEMENT_3, 8, 0,
1591 left_speaker_mixer, ARRAY_SIZE(left_speaker_mixer)), 1535 left_speaker_mixer, ARRAY_SIZE(left_speaker_mixer)),
1592SND_SOC_DAPM_MIXER("SPKR", WM8994_POWER_MANAGEMENT_3, 9, 0, 1536SND_SOC_DAPM_MIXER("SPKR", WM8994_POWER_MANAGEMENT_3, 9, 0,
1593 right_speaker_mixer, ARRAY_SIZE(right_speaker_mixer)), 1537 right_speaker_mixer, ARRAY_SIZE(right_speaker_mixer)),
1594SND_SOC_DAPM_MUX("Left Headphone Mux", SND_SOC_NOPM, 0, 0, &hpl_mux), 1538SND_SOC_DAPM_MUX("Left Headphone Mux", SND_SOC_NOPM, 0, 0, &wm_hubs_hpl_mux),
1595SND_SOC_DAPM_MUX("Right Headphone Mux", SND_SOC_NOPM, 0, 0, &hpr_mux), 1539SND_SOC_DAPM_MUX("Right Headphone Mux", SND_SOC_NOPM, 0, 0, &wm_hubs_hpr_mux),
1596}; 1540};
1597 1541
1598static const struct snd_soc_dapm_widget wm8994_dac_revd_widgets[] = { 1542static const struct snd_soc_dapm_widget wm8994_dac_revd_widgets[] = {
@@ -1732,6 +1676,7 @@ SND_SOC_DAPM_MUX("AIF3ADC Mux", SND_SOC_NOPM, 0, 0, &wm8994_aif3adc_mux),
1732}; 1676};
1733 1677
1734static const struct snd_soc_dapm_widget wm8958_dapm_widgets[] = { 1678static const struct snd_soc_dapm_widget wm8958_dapm_widgets[] = {
1679SND_SOC_DAPM_SUPPLY("AIF3", WM8994_POWER_MANAGEMENT_6, 5, 1, NULL, 0),
1735SND_SOC_DAPM_MUX("Mono PCM Out Mux", SND_SOC_NOPM, 0, 0, &mono_pcm_out_mux), 1680SND_SOC_DAPM_MUX("Mono PCM Out Mux", SND_SOC_NOPM, 0, 0, &mono_pcm_out_mux),
1736SND_SOC_DAPM_MUX("AIF2DACL Mux", SND_SOC_NOPM, 0, 0, &aif2dacl_src_mux), 1681SND_SOC_DAPM_MUX("AIF2DACL Mux", SND_SOC_NOPM, 0, 0, &aif2dacl_src_mux),
1737SND_SOC_DAPM_MUX("AIF2DACR Mux", SND_SOC_NOPM, 0, 0, &aif2dacr_src_mux), 1682SND_SOC_DAPM_MUX("AIF2DACR Mux", SND_SOC_NOPM, 0, 0, &aif2dacr_src_mux),
@@ -1972,6 +1917,9 @@ static const struct snd_soc_dapm_route wm8958_intercon[] = {
1972 { "AIF2DACR Mux", "AIF2", "AIF2DAC Mux" }, 1917 { "AIF2DACR Mux", "AIF2", "AIF2DAC Mux" },
1973 { "AIF2DACR Mux", "AIF3", "AIF3DACDAT" }, 1918 { "AIF2DACR Mux", "AIF3", "AIF3DACDAT" },
1974 1919
1920 { "AIF3DACDAT", NULL, "AIF3" },
1921 { "AIF3ADCDAT", NULL, "AIF3" },
1922
1975 { "Mono PCM Out Mux", "AIF2ADCL", "AIF2ADCL" }, 1923 { "Mono PCM Out Mux", "AIF2ADCL", "AIF2ADCL" },
1976 { "Mono PCM Out Mux", "AIF2ADCR", "AIF2ADCR" }, 1924 { "Mono PCM Out Mux", "AIF2ADCR", "AIF2ADCR" },
1977 1925
@@ -2068,24 +2016,20 @@ static int _wm8994_set_fll(struct snd_soc_codec *codec, int id, int src,
2068 struct wm8994 *control = wm8994->wm8994; 2016 struct wm8994 *control = wm8994->wm8994;
2069 int reg_offset, ret; 2017 int reg_offset, ret;
2070 struct fll_div fll; 2018 struct fll_div fll;
2071 u16 reg, aif1, aif2; 2019 u16 reg, clk1, aif_reg, aif_src;
2072 unsigned long timeout; 2020 unsigned long timeout;
2073 bool was_enabled; 2021 bool was_enabled;
2074 2022
2075 aif1 = snd_soc_read(codec, WM8994_AIF1_CLOCKING_1)
2076 & WM8994_AIF1CLK_ENA;
2077
2078 aif2 = snd_soc_read(codec, WM8994_AIF2_CLOCKING_1)
2079 & WM8994_AIF2CLK_ENA;
2080
2081 switch (id) { 2023 switch (id) {
2082 case WM8994_FLL1: 2024 case WM8994_FLL1:
2083 reg_offset = 0; 2025 reg_offset = 0;
2084 id = 0; 2026 id = 0;
2027 aif_src = 0x10;
2085 break; 2028 break;
2086 case WM8994_FLL2: 2029 case WM8994_FLL2:
2087 reg_offset = 0x20; 2030 reg_offset = 0x20;
2088 id = 1; 2031 id = 1;
2032 aif_src = 0x18;
2089 break; 2033 break;
2090 default: 2034 default:
2091 return -EINVAL; 2035 return -EINVAL;
@@ -2127,16 +2071,33 @@ static int _wm8994_set_fll(struct snd_soc_codec *codec, int id, int src,
2127 if (ret < 0) 2071 if (ret < 0)
2128 return ret; 2072 return ret;
2129 2073
2130 /* Gate the AIF clocks while we reclock */ 2074 /* Make sure that we're not providing SYSCLK right now */
2131 snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1, 2075 clk1 = snd_soc_read(codec, WM8994_CLOCKING_1);
2132 WM8994_AIF1CLK_ENA, 0); 2076 if (clk1 & WM8994_SYSCLK_SRC)
2133 snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1, 2077 aif_reg = WM8994_AIF2_CLOCKING_1;
2134 WM8994_AIF2CLK_ENA, 0); 2078 else
2079 aif_reg = WM8994_AIF1_CLOCKING_1;
2080 reg = snd_soc_read(codec, aif_reg);
2081
2082 if ((reg & WM8994_AIF1CLK_ENA) &&
2083 (reg & WM8994_AIF1CLK_SRC_MASK) == aif_src) {
2084 dev_err(codec->dev, "FLL%d is currently providing SYSCLK\n",
2085 id + 1);
2086 return -EBUSY;
2087 }
2135 2088
2136 /* We always need to disable the FLL while reconfiguring */ 2089 /* We always need to disable the FLL while reconfiguring */
2137 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_1 + reg_offset, 2090 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_1 + reg_offset,
2138 WM8994_FLL1_ENA, 0); 2091 WM8994_FLL1_ENA, 0);
2139 2092
2093 if (wm8994->fll_byp && src == WM8994_FLL_SRC_BCLK &&
2094 freq_in == freq_out && freq_out) {
2095 dev_dbg(codec->dev, "Bypassing FLL%d\n", id + 1);
2096 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_5 + reg_offset,
2097 WM8958_FLL1_BYP, WM8958_FLL1_BYP);
2098 goto out;
2099 }
2100
2140 reg = (fll.outdiv << WM8994_FLL1_OUTDIV_SHIFT) | 2101 reg = (fll.outdiv << WM8994_FLL1_OUTDIV_SHIFT) |
2141 (fll.fll_fratio << WM8994_FLL1_FRATIO_SHIFT); 2102 (fll.fll_fratio << WM8994_FLL1_FRATIO_SHIFT);
2142 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_2 + reg_offset, 2103 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_2 + reg_offset,
@@ -2151,6 +2112,7 @@ static int _wm8994_set_fll(struct snd_soc_codec *codec, int id, int src,
2151 fll.n << WM8994_FLL1_N_SHIFT); 2112 fll.n << WM8994_FLL1_N_SHIFT);
2152 2113
2153 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_5 + reg_offset, 2114 snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_5 + reg_offset,
2115 WM8958_FLL1_BYP |
2154 WM8994_FLL1_REFCLK_DIV_MASK | 2116 WM8994_FLL1_REFCLK_DIV_MASK |
2155 WM8994_FLL1_REFCLK_SRC_MASK, 2117 WM8994_FLL1_REFCLK_SRC_MASK,
2156 (fll.clk_ref_div << WM8994_FLL1_REFCLK_DIV_SHIFT) | 2118 (fll.clk_ref_div << WM8994_FLL1_REFCLK_DIV_SHIFT) |
@@ -2213,16 +2175,11 @@ static int _wm8994_set_fll(struct snd_soc_codec *codec, int id, int src,
2213 } 2175 }
2214 } 2176 }
2215 2177
2178out:
2216 wm8994->fll[id].in = freq_in; 2179 wm8994->fll[id].in = freq_in;
2217 wm8994->fll[id].out = freq_out; 2180 wm8994->fll[id].out = freq_out;
2218 wm8994->fll[id].src = src; 2181 wm8994->fll[id].src = src;
2219 2182
2220 /* Enable any gated AIF clocks */
2221 snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1,
2222 WM8994_AIF1CLK_ENA, aif1);
2223 snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1,
2224 WM8994_AIF2CLK_ENA, aif2);
2225
2226 configure_clock(codec); 2183 configure_clock(codec);
2227 2184
2228 return 0; 2185 return 0;
@@ -2290,7 +2247,7 @@ static int wm8994_set_dai_sysclk(struct snd_soc_dai *dai,
2290 2247
2291 case WM8994_SYSCLK_OPCLK: 2248 case WM8994_SYSCLK_OPCLK:
2292 /* Special case - a division (times 10) is given and 2249 /* Special case - a division (times 10) is given and
2293 * no effect on main clocking. 2250 * no effect on main clocking.
2294 */ 2251 */
2295 if (freq) { 2252 if (freq) {
2296 for (i = 0; i < ARRAY_SIZE(opclk_divs); i++) 2253 for (i = 0; i < ARRAY_SIZE(opclk_divs); i++)
@@ -2792,33 +2749,6 @@ static int wm8994_aif3_hw_params(struct snd_pcm_substream *substream,
2792 return snd_soc_update_bits(codec, aif1_reg, WM8994_AIF1_WL_MASK, aif1); 2749 return snd_soc_update_bits(codec, aif1_reg, WM8994_AIF1_WL_MASK, aif1);
2793} 2750}
2794 2751
2795static void wm8994_aif_shutdown(struct snd_pcm_substream *substream,
2796 struct snd_soc_dai *dai)
2797{
2798 struct snd_soc_codec *codec = dai->codec;
2799 int rate_reg = 0;
2800
2801 switch (dai->id) {
2802 case 1:
2803 rate_reg = WM8994_AIF1_RATE;
2804 break;
2805 case 2:
2806 rate_reg = WM8994_AIF2_RATE;
2807 break;
2808 default:
2809 break;
2810 }
2811
2812 /* If the DAI is idle then configure the divider tree for the
2813 * lowest output rate to save a little power if the clock is
2814 * still active (eg, because it is system clock).
2815 */
2816 if (rate_reg && !dai->playback_active && !dai->capture_active)
2817 snd_soc_update_bits(codec, rate_reg,
2818 WM8994_AIF1_SR_MASK |
2819 WM8994_AIF1CLK_RATE_MASK, 0x9);
2820}
2821
2822static int wm8994_aif_mute(struct snd_soc_dai *codec_dai, int mute) 2752static int wm8994_aif_mute(struct snd_soc_dai *codec_dai, int mute)
2823{ 2753{
2824 struct snd_soc_codec *codec = codec_dai->codec; 2754 struct snd_soc_codec *codec = codec_dai->codec;
@@ -2860,10 +2790,6 @@ static int wm8994_set_tristate(struct snd_soc_dai *codec_dai, int tristate)
2860 reg = WM8994_AIF2_MASTER_SLAVE; 2790 reg = WM8994_AIF2_MASTER_SLAVE;
2861 mask = WM8994_AIF2_TRI; 2791 mask = WM8994_AIF2_TRI;
2862 break; 2792 break;
2863 case 3:
2864 reg = WM8994_POWER_MANAGEMENT_6;
2865 mask = WM8994_AIF3_TRI;
2866 break;
2867 default: 2793 default:
2868 return -EINVAL; 2794 return -EINVAL;
2869 } 2795 }
@@ -2900,7 +2826,6 @@ static const struct snd_soc_dai_ops wm8994_aif1_dai_ops = {
2900 .set_sysclk = wm8994_set_dai_sysclk, 2826 .set_sysclk = wm8994_set_dai_sysclk,
2901 .set_fmt = wm8994_set_dai_fmt, 2827 .set_fmt = wm8994_set_dai_fmt,
2902 .hw_params = wm8994_hw_params, 2828 .hw_params = wm8994_hw_params,
2903 .shutdown = wm8994_aif_shutdown,
2904 .digital_mute = wm8994_aif_mute, 2829 .digital_mute = wm8994_aif_mute,
2905 .set_pll = wm8994_set_fll, 2830 .set_pll = wm8994_set_fll,
2906 .set_tristate = wm8994_set_tristate, 2831 .set_tristate = wm8994_set_tristate,
@@ -2910,7 +2835,6 @@ static const struct snd_soc_dai_ops wm8994_aif2_dai_ops = {
2910 .set_sysclk = wm8994_set_dai_sysclk, 2835 .set_sysclk = wm8994_set_dai_sysclk,
2911 .set_fmt = wm8994_set_dai_fmt, 2836 .set_fmt = wm8994_set_dai_fmt,
2912 .hw_params = wm8994_hw_params, 2837 .hw_params = wm8994_hw_params,
2913 .shutdown = wm8994_aif_shutdown,
2914 .digital_mute = wm8994_aif_mute, 2838 .digital_mute = wm8994_aif_mute,
2915 .set_pll = wm8994_set_fll, 2839 .set_pll = wm8994_set_fll,
2916 .set_tristate = wm8994_set_tristate, 2840 .set_tristate = wm8994_set_tristate,
@@ -2918,7 +2842,6 @@ static const struct snd_soc_dai_ops wm8994_aif2_dai_ops = {
2918 2842
2919static const struct snd_soc_dai_ops wm8994_aif3_dai_ops = { 2843static const struct snd_soc_dai_ops wm8994_aif3_dai_ops = {
2920 .hw_params = wm8994_aif3_hw_params, 2844 .hw_params = wm8994_aif3_hw_params,
2921 .set_tristate = wm8994_set_tristate,
2922}; 2845};
2923 2846
2924static struct snd_soc_dai_driver wm8994_dai[] = { 2847static struct snd_soc_dai_driver wm8994_dai[] = {
@@ -3126,14 +3049,14 @@ static void wm8994_handle_retune_mobile_pdata(struct wm8994_priv *wm8994)
3126 3049
3127 /* Expand the array... */ 3050 /* Expand the array... */
3128 t = krealloc(wm8994->retune_mobile_texts, 3051 t = krealloc(wm8994->retune_mobile_texts,
3129 sizeof(char *) * 3052 sizeof(char *) *
3130 (wm8994->num_retune_mobile_texts + 1), 3053 (wm8994->num_retune_mobile_texts + 1),
3131 GFP_KERNEL); 3054 GFP_KERNEL);
3132 if (t == NULL) 3055 if (t == NULL)
3133 continue; 3056 continue;
3134 3057
3135 /* ...store the new entry... */ 3058 /* ...store the new entry... */
3136 t[wm8994->num_retune_mobile_texts] = 3059 t[wm8994->num_retune_mobile_texts] =
3137 pdata->retune_mobile_cfgs[i].name; 3060 pdata->retune_mobile_cfgs[i].name;
3138 3061
3139 /* ...and remember the new version. */ 3062 /* ...and remember the new version. */
@@ -3304,25 +3227,25 @@ int wm8994_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
3304} 3227}
3305EXPORT_SYMBOL_GPL(wm8994_mic_detect); 3228EXPORT_SYMBOL_GPL(wm8994_mic_detect);
3306 3229
3307static irqreturn_t wm8994_mic_irq(int irq, void *data) 3230static void wm8994_mic_work(struct work_struct *work)
3308{ 3231{
3309 struct wm8994_priv *priv = data; 3232 struct wm8994_priv *priv = container_of(work,
3310 struct snd_soc_codec *codec = priv->codec; 3233 struct wm8994_priv,
3311 int reg; 3234 mic_work.work);
3235 struct regmap *regmap = priv->wm8994->regmap;
3236 struct device *dev = priv->wm8994->dev;
3237 unsigned int reg;
3238 int ret;
3312 int report; 3239 int report;
3313 3240
3314#ifndef CONFIG_SND_SOC_WM8994_MODULE 3241 ret = regmap_read(regmap, WM8994_INTERRUPT_RAW_STATUS_2, &reg);
3315 trace_snd_soc_jack_irq(dev_name(codec->dev)); 3242 if (ret < 0) {
3316#endif 3243 dev_err(dev, "Failed to read microphone status: %d\n",
3317 3244 ret);
3318 reg = snd_soc_read(codec, WM8994_INTERRUPT_RAW_STATUS_2); 3245 return;
3319 if (reg < 0) {
3320 dev_err(codec->dev, "Failed to read microphone status: %d\n",
3321 reg);
3322 return IRQ_HANDLED;
3323 } 3246 }
3324 3247
3325 dev_dbg(codec->dev, "Microphone status: %x\n", reg); 3248 dev_dbg(dev, "Microphone status: %x\n", reg);
3326 3249
3327 report = 0; 3250 report = 0;
3328 if (reg & WM8994_MIC1_DET_STS) { 3251 if (reg & WM8994_MIC1_DET_STS) {
@@ -3361,6 +3284,20 @@ static irqreturn_t wm8994_mic_irq(int irq, void *data)
3361 3284
3362 snd_soc_jack_report(priv->micdet[1].jack, report, 3285 snd_soc_jack_report(priv->micdet[1].jack, report,
3363 SND_JACK_HEADSET | SND_JACK_BTN_0); 3286 SND_JACK_HEADSET | SND_JACK_BTN_0);
3287}
3288
3289static irqreturn_t wm8994_mic_irq(int irq, void *data)
3290{
3291 struct wm8994_priv *priv = data;
3292 struct snd_soc_codec *codec = priv->codec;
3293
3294#ifndef CONFIG_SND_SOC_WM8994_MODULE
3295 trace_snd_soc_jack_irq(dev_name(codec->dev));
3296#endif
3297
3298 pm_wakeup_event(codec->dev, 300);
3299
3300 schedule_delayed_work(&priv->mic_work, msecs_to_jiffies(250));
3364 3301
3365 return IRQ_HANDLED; 3302 return IRQ_HANDLED;
3366} 3303}
@@ -3415,9 +3352,6 @@ static void wm8958_default_micdet(u16 status, void *data)
3415 3352
3416 wm8958_micd_set_rate(codec); 3353 wm8958_micd_set_rate(codec);
3417 3354
3418 snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADPHONE,
3419 SND_JACK_HEADSET);
3420
3421 /* If we have jackdet that will detect removal */ 3355 /* If we have jackdet that will detect removal */
3422 if (wm8994->jackdet) { 3356 if (wm8994->jackdet) {
3423 mutex_lock(&wm8994->accdet_lock); 3357 mutex_lock(&wm8994->accdet_lock);
@@ -3430,14 +3364,13 @@ static void wm8958_default_micdet(u16 status, void *data)
3430 3364
3431 mutex_unlock(&wm8994->accdet_lock); 3365 mutex_unlock(&wm8994->accdet_lock);
3432 3366
3433 if (wm8994->pdata->jd_ext_cap) { 3367 if (wm8994->pdata->jd_ext_cap)
3434 mutex_lock(&codec->mutex);
3435 snd_soc_dapm_disable_pin(&codec->dapm, 3368 snd_soc_dapm_disable_pin(&codec->dapm,
3436 "MICBIAS2"); 3369 "MICBIAS2");
3437 snd_soc_dapm_sync(&codec->dapm);
3438 mutex_unlock(&codec->mutex);
3439 }
3440 } 3370 }
3371
3372 snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADPHONE,
3373 SND_JACK_HEADSET);
3441 } 3374 }
3442 3375
3443 /* Report short circuit as a button */ 3376 /* Report short circuit as a button */
@@ -3489,6 +3422,8 @@ static irqreturn_t wm1811_jackdet_irq(int irq, void *data)
3489 if (present) { 3422 if (present) {
3490 dev_dbg(codec->dev, "Jack detected\n"); 3423 dev_dbg(codec->dev, "Jack detected\n");
3491 3424
3425 wm8958_micd_set_rate(codec);
3426
3492 snd_soc_update_bits(codec, WM8958_MICBIAS2, 3427 snd_soc_update_bits(codec, WM8958_MICBIAS2,
3493 WM8958_MICB2_DISCH, 0); 3428 WM8958_MICB2_DISCH, 0);
3494 3429
@@ -3526,16 +3461,11 @@ static irqreturn_t wm1811_jackdet_irq(int irq, void *data)
3526 3461
3527 /* If required for an external cap force MICBIAS on */ 3462 /* If required for an external cap force MICBIAS on */
3528 if (wm8994->pdata->jd_ext_cap) { 3463 if (wm8994->pdata->jd_ext_cap) {
3529 mutex_lock(&codec->mutex);
3530
3531 if (present) 3464 if (present)
3532 snd_soc_dapm_force_enable_pin(&codec->dapm, 3465 snd_soc_dapm_force_enable_pin(&codec->dapm,
3533 "MICBIAS2"); 3466 "MICBIAS2");
3534 else 3467 else
3535 snd_soc_dapm_disable_pin(&codec->dapm, "MICBIAS2"); 3468 snd_soc_dapm_disable_pin(&codec->dapm, "MICBIAS2");
3536
3537 snd_soc_dapm_sync(&codec->dapm);
3538 mutex_unlock(&codec->mutex);
3539 } 3469 }
3540 3470
3541 if (present) 3471 if (present)
@@ -3740,6 +3670,7 @@ static int wm8994_codec_probe(struct snd_soc_codec *codec)
3740 wm8994->codec = codec; 3670 wm8994->codec = codec;
3741 3671
3742 mutex_init(&wm8994->accdet_lock); 3672 mutex_init(&wm8994->accdet_lock);
3673 INIT_DELAYED_WORK(&wm8994->mic_work, wm8994_mic_work);
3743 3674
3744 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++) 3675 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++)
3745 init_completion(&wm8994->fll_locked[i]); 3676 init_completion(&wm8994->fll_locked[i]);
@@ -3783,13 +3714,22 @@ static int wm8994_codec_probe(struct snd_soc_codec *codec)
3783 case WM8958: 3714 case WM8958:
3784 wm8994->hubs.dcs_readback_mode = 1; 3715 wm8994->hubs.dcs_readback_mode = 1;
3785 wm8994->hubs.hp_startup_mode = 1; 3716 wm8994->hubs.hp_startup_mode = 1;
3717
3718 switch (wm8994->revision) {
3719 case 0:
3720 break;
3721 default:
3722 wm8994->fll_byp = true;
3723 break;
3724 }
3786 break; 3725 break;
3787 3726
3788 case WM1811: 3727 case WM1811:
3789 wm8994->hubs.dcs_readback_mode = 2; 3728 wm8994->hubs.dcs_readback_mode = 2;
3790 wm8994->hubs.no_series_update = 1; 3729 wm8994->hubs.no_series_update = 1;
3791 wm8994->hubs.hp_startup_mode = 1; 3730 wm8994->hubs.hp_startup_mode = 1;
3792 wm8994->hubs.no_cache_class_w = true; 3731 wm8994->hubs.no_cache_dac_hp_direct = true;
3732 wm8994->fll_byp = true;
3793 3733
3794 switch (wm8994->revision) { 3734 switch (wm8994->revision) {
3795 case 0: 3735 case 0:
@@ -4010,7 +3950,8 @@ static int wm8994_codec_probe(struct snd_soc_codec *codec)
4010 break; 3950 break;
4011 } 3951 }
4012 3952
4013 wm8994_update_class_w(codec); 3953 wm8994->hubs.check_class_w_digital = wm8994_check_class_w_digital;
3954 wm_hubs_update_class_w(codec);
4014 3955
4015 wm8994_handle_pdata(wm8994); 3956 wm8994_handle_pdata(wm8994);
4016 3957
@@ -4075,7 +4016,6 @@ static int wm8994_codec_probe(struct snd_soc_codec *codec)
4075 ARRAY_SIZE(wm8994_dac_widgets)); 4016 ARRAY_SIZE(wm8994_dac_widgets));
4076 break; 4017 break;
4077 } 4018 }
4078
4079 4019
4080 wm_hubs_add_analogue_routes(codec, 0, 0); 4020 wm_hubs_add_analogue_routes(codec, 0, 0);
4081 snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon)); 4021 snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon));
@@ -4140,7 +4080,7 @@ err_irq:
4140 return ret; 4080 return ret;
4141} 4081}
4142 4082
4143static int wm8994_codec_remove(struct snd_soc_codec *codec) 4083static int wm8994_codec_remove(struct snd_soc_codec *codec)
4144{ 4084{
4145 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); 4085 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
4146 struct wm8994 *control = wm8994->wm8994; 4086 struct wm8994 *control = wm8994->wm8994;
@@ -4181,14 +4121,10 @@ static int wm8994_codec_remove(struct snd_soc_codec *codec)
4181 free_irq(wm8994->micdet_irq, wm8994); 4121 free_irq(wm8994->micdet_irq, wm8994);
4182 break; 4122 break;
4183 } 4123 }
4184 if (wm8994->mbc) 4124 release_firmware(wm8994->mbc);
4185 release_firmware(wm8994->mbc); 4125 release_firmware(wm8994->mbc_vss);
4186 if (wm8994->mbc_vss) 4126 release_firmware(wm8994->enh_eq);
4187 release_firmware(wm8994->mbc_vss);
4188 if (wm8994->enh_eq)
4189 release_firmware(wm8994->enh_eq);
4190 kfree(wm8994->retune_mobile_texts); 4127 kfree(wm8994->retune_mobile_texts);
4191
4192 return 0; 4128 return 0;
4193} 4129}
4194 4130
diff --git a/sound/soc/codecs/wm8994.h b/sound/soc/codecs/wm8994.h
index c724112998d8..d77e06f0a675 100644
--- a/sound/soc/codecs/wm8994.h
+++ b/sound/soc/codecs/wm8994.h
@@ -12,6 +12,7 @@
12#include <sound/soc.h> 12#include <sound/soc.h>
13#include <linux/firmware.h> 13#include <linux/firmware.h>
14#include <linux/completion.h> 14#include <linux/completion.h>
15#include <linux/workqueue.h>
15 16
16#include "wm_hubs.h" 17#include "wm_hubs.h"
17 18
@@ -79,6 +80,7 @@ struct wm8994_priv {
79 struct wm8994_fll_config fll[2], fll_suspend[2]; 80 struct wm8994_fll_config fll[2], fll_suspend[2];
80 struct completion fll_locked[2]; 81 struct completion fll_locked[2];
81 bool fll_locked_irq; 82 bool fll_locked_irq;
83 bool fll_byp;
82 84
83 int vmid_refcount; 85 int vmid_refcount;
84 int active_refcount; 86 int active_refcount;
@@ -126,6 +128,7 @@ struct wm8994_priv {
126 128
127 struct mutex accdet_lock; 129 struct mutex accdet_lock;
128 struct wm8994_micdet micdet[2]; 130 struct wm8994_micdet micdet[2];
131 struct delayed_work mic_work;
129 bool mic_detecting; 132 bool mic_detecting;
130 bool jack_mic; 133 bool jack_mic;
131 int btn_mask; 134 int btn_mask;
diff --git a/sound/soc/codecs/wm8996.c b/sound/soc/codecs/wm8996.c
index 1fd635494045..8af422e38fd0 100644
--- a/sound/soc/codecs/wm8996.c
+++ b/sound/soc/codecs/wm8996.c
@@ -1770,7 +1770,13 @@ static int wm8996_set_bias_level(struct snd_soc_codec *codec,
1770 1770
1771 switch (level) { 1771 switch (level) {
1772 case SND_SOC_BIAS_ON: 1772 case SND_SOC_BIAS_ON:
1773 break;
1773 case SND_SOC_BIAS_PREPARE: 1774 case SND_SOC_BIAS_PREPARE:
1775 /* Put the MICBIASes into regulating mode */
1776 snd_soc_update_bits(codec, WM8996_MICBIAS_1,
1777 WM8996_MICB1_MODE, 0);
1778 snd_soc_update_bits(codec, WM8996_MICBIAS_2,
1779 WM8996_MICB2_MODE, 0);
1774 break; 1780 break;
1775 1781
1776 case SND_SOC_BIAS_STANDBY: 1782 case SND_SOC_BIAS_STANDBY:
@@ -1793,6 +1799,12 @@ static int wm8996_set_bias_level(struct snd_soc_codec *codec,
1793 regcache_cache_only(codec->control_data, false); 1799 regcache_cache_only(codec->control_data, false);
1794 regcache_sync(codec->control_data); 1800 regcache_sync(codec->control_data);
1795 } 1801 }
1802
1803 /* Bypass the MICBIASes for lowest power */
1804 snd_soc_update_bits(codec, WM8996_MICBIAS_1,
1805 WM8996_MICB1_MODE, WM8996_MICB1_MODE);
1806 snd_soc_update_bits(codec, WM8996_MICBIAS_2,
1807 WM8996_MICB2_MODE, WM8996_MICB2_MODE);
1796 break; 1808 break;
1797 1809
1798 case SND_SOC_BIAS_OFF: 1810 case SND_SOC_BIAS_OFF:
diff --git a/sound/soc/codecs/wm9081.c b/sound/soc/codecs/wm9081.c
index 076c126ed9b1..9328270df16c 100644
--- a/sound/soc/codecs/wm9081.c
+++ b/sound/soc/codecs/wm9081.c
@@ -774,7 +774,7 @@ static const struct snd_soc_dapm_widget wm9081_dapm_widgets[] = {
774SND_SOC_DAPM_INPUT("IN1"), 774SND_SOC_DAPM_INPUT("IN1"),
775SND_SOC_DAPM_INPUT("IN2"), 775SND_SOC_DAPM_INPUT("IN2"),
776 776
777SND_SOC_DAPM_DAC("DAC", "HiFi Playback", WM9081_POWER_MANAGEMENT, 0, 0), 777SND_SOC_DAPM_DAC("DAC", NULL, WM9081_POWER_MANAGEMENT, 0, 0),
778 778
779SND_SOC_DAPM_MIXER_NAMED_CTL("Mixer", SND_SOC_NOPM, 0, 0, 779SND_SOC_DAPM_MIXER_NAMED_CTL("Mixer", SND_SOC_NOPM, 0, 0,
780 mixer, ARRAY_SIZE(mixer)), 780 mixer, ARRAY_SIZE(mixer)),
@@ -799,6 +799,7 @@ SND_SOC_DAPM_SUPPLY("TSENSE", WM9081_POWER_MANAGEMENT, 7, 0, NULL, 0),
799static const struct snd_soc_dapm_route wm9081_audio_paths[] = { 799static const struct snd_soc_dapm_route wm9081_audio_paths[] = {
800 { "DAC", NULL, "CLK_SYS" }, 800 { "DAC", NULL, "CLK_SYS" },
801 { "DAC", NULL, "CLK_DSP" }, 801 { "DAC", NULL, "CLK_DSP" },
802 { "DAC", NULL, "AIF" },
802 803
803 { "Mixer", "IN1 Switch", "IN1" }, 804 { "Mixer", "IN1 Switch", "IN1" },
804 { "Mixer", "IN2 Switch", "IN2" }, 805 { "Mixer", "IN2 Switch", "IN2" },
@@ -1252,7 +1253,7 @@ static const struct snd_soc_dai_ops wm9081_dai_ops = {
1252static struct snd_soc_dai_driver wm9081_dai = { 1253static struct snd_soc_dai_driver wm9081_dai = {
1253 .name = "wm9081-hifi", 1254 .name = "wm9081-hifi",
1254 .playback = { 1255 .playback = {
1255 .stream_name = "HiFi Playback", 1256 .stream_name = "AIF",
1256 .channels_min = 1, 1257 .channels_min = 1,
1257 .channels_max = 2, 1258 .channels_max = 2,
1258 .rates = WM9081_RATES, 1259 .rates = WM9081_RATES,
diff --git a/sound/soc/codecs/wm9705.c b/sound/soc/codecs/wm9705.c
index cacc6a86b46f..e8e782a0c78d 100644
--- a/sound/soc/codecs/wm9705.c
+++ b/sound/soc/codecs/wm9705.c
@@ -236,9 +236,7 @@ static int ac97_write(struct snd_soc_codec *codec, unsigned int reg,
236static int ac97_prepare(struct snd_pcm_substream *substream, 236static int ac97_prepare(struct snd_pcm_substream *substream,
237 struct snd_soc_dai *dai) 237 struct snd_soc_dai *dai)
238{ 238{
239 struct snd_pcm_runtime *runtime = substream->runtime; 239 struct snd_soc_codec *codec = dai->codec;
240 struct snd_soc_pcm_runtime *rtd = substream->private_data;
241 struct snd_soc_codec *codec = rtd->codec;
242 int reg; 240 int reg;
243 u16 vra; 241 u16 vra;
244 242
@@ -250,7 +248,7 @@ static int ac97_prepare(struct snd_pcm_substream *substream,
250 else 248 else
251 reg = AC97_PCM_LR_ADC_RATE; 249 reg = AC97_PCM_LR_ADC_RATE;
252 250
253 return ac97_write(codec, reg, runtime->rate); 251 return ac97_write(codec, reg, substream->runtime->rate);
254} 252}
255 253
256#define WM9705_AC97_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | \ 254#define WM9705_AC97_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | \
diff --git a/sound/soc/codecs/wm9712.c b/sound/soc/codecs/wm9712.c
index b342ae50bcd6..a1541414d904 100644
--- a/sound/soc/codecs/wm9712.c
+++ b/sound/soc/codecs/wm9712.c
@@ -467,11 +467,10 @@ static int ac97_write(struct snd_soc_codec *codec, unsigned int reg,
467static int ac97_prepare(struct snd_pcm_substream *substream, 467static int ac97_prepare(struct snd_pcm_substream *substream,
468 struct snd_soc_dai *dai) 468 struct snd_soc_dai *dai)
469{ 469{
470 struct snd_pcm_runtime *runtime = substream->runtime; 470 struct snd_soc_codec *codec = dai->codec;
471 struct snd_soc_pcm_runtime *rtd = substream->private_data;
472 struct snd_soc_codec *codec =rtd->codec;
473 int reg; 471 int reg;
474 u16 vra; 472 u16 vra;
473 struct snd_pcm_runtime *runtime = substream->runtime;
475 474
476 vra = ac97_read(codec, AC97_EXTENDED_STATUS); 475 vra = ac97_read(codec, AC97_EXTENDED_STATUS);
477 ac97_write(codec, AC97_EXTENDED_STATUS, vra | 0x1); 476 ac97_write(codec, AC97_EXTENDED_STATUS, vra | 0x1);
@@ -487,10 +486,9 @@ static int ac97_prepare(struct snd_pcm_substream *substream,
487static int ac97_aux_prepare(struct snd_pcm_substream *substream, 486static int ac97_aux_prepare(struct snd_pcm_substream *substream,
488 struct snd_soc_dai *dai) 487 struct snd_soc_dai *dai)
489{ 488{
490 struct snd_pcm_runtime *runtime = substream->runtime; 489 struct snd_soc_codec *codec = dai->codec;
491 struct snd_soc_pcm_runtime *rtd = substream->private_data;
492 struct snd_soc_codec *codec = rtd->codec;
493 u16 vra, xsle; 490 u16 vra, xsle;
491 struct snd_pcm_runtime *runtime = substream->runtime;
494 492
495 vra = ac97_read(codec, AC97_EXTENDED_STATUS); 493 vra = ac97_read(codec, AC97_EXTENDED_STATUS);
496 ac97_write(codec, AC97_EXTENDED_STATUS, vra | 0x1); 494 ac97_write(codec, AC97_EXTENDED_STATUS, vra | 0x1);
diff --git a/sound/soc/codecs/wm_hubs.c b/sound/soc/codecs/wm_hubs.c
index 6c028c470601..dfe957a47f29 100644
--- a/sound/soc/codecs/wm_hubs.c
+++ b/sound/soc/codecs/wm_hubs.c
@@ -109,12 +109,103 @@ irqreturn_t wm_hubs_dcs_done(int irq, void *data)
109} 109}
110EXPORT_SYMBOL_GPL(wm_hubs_dcs_done); 110EXPORT_SYMBOL_GPL(wm_hubs_dcs_done);
111 111
112static bool wm_hubs_dac_hp_direct(struct snd_soc_codec *codec)
113{
114 int reg;
115
116 /* If we're going via the mixer we'll need to do additional checks */
117 reg = snd_soc_read(codec, WM8993_OUTPUT_MIXER1);
118 if (!(reg & WM8993_DACL_TO_HPOUT1L)) {
119 if (reg & ~WM8993_DACL_TO_MIXOUTL) {
120 dev_vdbg(codec->dev, "Analogue paths connected: %x\n",
121 reg & ~WM8993_DACL_TO_HPOUT1L);
122 return false;
123 } else {
124 dev_vdbg(codec->dev, "HPL connected to mixer\n");
125 }
126 } else {
127 dev_vdbg(codec->dev, "HPL connected to DAC\n");
128 }
129
130 reg = snd_soc_read(codec, WM8993_OUTPUT_MIXER2);
131 if (!(reg & WM8993_DACR_TO_HPOUT1R)) {
132 if (reg & ~WM8993_DACR_TO_MIXOUTR) {
133 dev_vdbg(codec->dev, "Analogue paths connected: %x\n",
134 reg & ~WM8993_DACR_TO_HPOUT1R);
135 return false;
136 } else {
137 dev_vdbg(codec->dev, "HPR connected to mixer\n");
138 }
139 } else {
140 dev_vdbg(codec->dev, "HPR connected to DAC\n");
141 }
142
143 return true;
144}
145
146struct wm_hubs_dcs_cache {
147 struct list_head list;
148 unsigned int left;
149 unsigned int right;
150 u16 dcs_cfg;
151};
152
153static bool wm_hubs_dcs_cache_get(struct snd_soc_codec *codec,
154 struct wm_hubs_dcs_cache **entry)
155{
156 struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec);
157 struct wm_hubs_dcs_cache *cache;
158 unsigned int left, right;
159
160 left = snd_soc_read(codec, WM8993_LEFT_OUTPUT_VOLUME);
161 left &= WM8993_HPOUT1L_VOL_MASK;
162
163 right = snd_soc_read(codec, WM8993_RIGHT_OUTPUT_VOLUME);
164 right &= WM8993_HPOUT1R_VOL_MASK;
165
166 list_for_each_entry(cache, &hubs->dcs_cache, list) {
167 if (cache->left != left || cache->right != right)
168 continue;
169
170 *entry = cache;
171 return true;
172 }
173
174 return false;
175}
176
177static void wm_hubs_dcs_cache_set(struct snd_soc_codec *codec, u16 dcs_cfg)
178{
179 struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec);
180 struct wm_hubs_dcs_cache *cache;
181
182 if (hubs->no_cache_dac_hp_direct)
183 return;
184
185 cache = devm_kzalloc(codec->dev, sizeof(*cache), GFP_KERNEL);
186 if (!cache) {
187 dev_err(codec->dev, "Failed to allocate DCS cache entry\n");
188 return;
189 }
190
191 cache->left = snd_soc_read(codec, WM8993_LEFT_OUTPUT_VOLUME);
192 cache->left &= WM8993_HPOUT1L_VOL_MASK;
193
194 cache->right = snd_soc_read(codec, WM8993_RIGHT_OUTPUT_VOLUME);
195 cache->right &= WM8993_HPOUT1R_VOL_MASK;
196
197 cache->dcs_cfg = dcs_cfg;
198
199 list_add_tail(&cache->list, &hubs->dcs_cache);
200}
201
112/* 202/*
113 * Startup calibration of the DC servo 203 * Startup calibration of the DC servo
114 */ 204 */
115static void calibrate_dc_servo(struct snd_soc_codec *codec) 205static void calibrate_dc_servo(struct snd_soc_codec *codec)
116{ 206{
117 struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec); 207 struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec);
208 struct wm_hubs_dcs_cache *cache;
118 s8 offset; 209 s8 offset;
119 u16 reg, reg_l, reg_r, dcs_cfg, dcs_reg; 210 u16 reg, reg_l, reg_r, dcs_cfg, dcs_reg;
120 211
@@ -129,10 +220,11 @@ static void calibrate_dc_servo(struct snd_soc_codec *codec)
129 220
130 /* If we're using a digital only path and have a previously 221 /* If we're using a digital only path and have a previously
131 * callibrated DC servo offset stored then use that. */ 222 * callibrated DC servo offset stored then use that. */
132 if (hubs->class_w && hubs->class_w_dcs) { 223 if (wm_hubs_dac_hp_direct(codec) &&
133 dev_dbg(codec->dev, "Using cached DC servo offset %x\n", 224 wm_hubs_dcs_cache_get(codec, &cache)) {
134 hubs->class_w_dcs); 225 dev_dbg(codec->dev, "Using cached DCS offset %x for %d,%d\n",
135 snd_soc_write(codec, dcs_reg, hubs->class_w_dcs); 226 cache->dcs_cfg, cache->left, cache->right);
227 snd_soc_write(codec, dcs_reg, cache->dcs_cfg);
136 wait_for_dc_servo(codec, 228 wait_for_dc_servo(codec,
137 WM8993_DCS_TRIG_DAC_WR_0 | 229 WM8993_DCS_TRIG_DAC_WR_0 |
138 WM8993_DCS_TRIG_DAC_WR_1); 230 WM8993_DCS_TRIG_DAC_WR_1);
@@ -207,8 +299,8 @@ static void calibrate_dc_servo(struct snd_soc_codec *codec)
207 299
208 /* Save the callibrated offset if we're in class W mode and 300 /* Save the callibrated offset if we're in class W mode and
209 * therefore don't have any analogue signal mixed in. */ 301 * therefore don't have any analogue signal mixed in. */
210 if (hubs->class_w && !hubs->no_cache_class_w) 302 if (wm_hubs_dac_hp_direct(codec))
211 hubs->class_w_dcs = dcs_cfg; 303 wm_hubs_dcs_cache_set(codec, dcs_cfg);
212} 304}
213 305
214/* 306/*
@@ -223,9 +315,6 @@ static int wm8993_put_dc_servo(struct snd_kcontrol *kcontrol,
223 315
224 ret = snd_soc_put_volsw(kcontrol, ucontrol); 316 ret = snd_soc_put_volsw(kcontrol, ucontrol);
225 317
226 /* Updating the analogue gains invalidates the DC servo cache */
227 hubs->class_w_dcs = 0;
228
229 /* If we're applying an offset correction then updating the 318 /* If we're applying an offset correction then updating the
230 * callibration would be likely to introduce further offsets. */ 319 * callibration would be likely to introduce further offsets. */
231 if (hubs->dcs_codes_l || hubs->dcs_codes_r || hubs->no_series_update) 320 if (hubs->dcs_codes_l || hubs->dcs_codes_r || hubs->no_series_update)
@@ -530,6 +619,86 @@ static int lineout_event(struct snd_soc_dapm_widget *w,
530 return 0; 619 return 0;
531} 620}
532 621
622void wm_hubs_update_class_w(struct snd_soc_codec *codec)
623{
624 struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec);
625 int enable = WM8993_CP_DYN_V | WM8993_CP_DYN_FREQ;
626
627 if (!wm_hubs_dac_hp_direct(codec))
628 enable = false;
629
630 if (hubs->check_class_w_digital && !hubs->check_class_w_digital(codec))
631 enable = false;
632
633 dev_vdbg(codec->dev, "Class W %s\n", enable ? "enabled" : "disabled");
634
635 snd_soc_update_bits(codec, WM8993_CLASS_W_0,
636 WM8993_CP_DYN_V | WM8993_CP_DYN_FREQ, enable);
637}
638EXPORT_SYMBOL_GPL(wm_hubs_update_class_w);
639
640#define WM_HUBS_SINGLE_W(xname, reg, shift, max, invert) \
641{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
642 .info = snd_soc_info_volsw, \
643 .get = snd_soc_dapm_get_volsw, .put = class_w_put_volsw, \
644 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) }
645
646static int class_w_put_volsw(struct snd_kcontrol *kcontrol,
647 struct snd_ctl_elem_value *ucontrol)
648{
649 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
650 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
651 struct snd_soc_codec *codec = widget->codec;
652 int ret;
653
654 ret = snd_soc_dapm_put_volsw(kcontrol, ucontrol);
655
656 wm_hubs_update_class_w(codec);
657
658 return ret;
659}
660
661#define WM_HUBS_ENUM_W(xname, xenum) \
662{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
663 .info = snd_soc_info_enum_double, \
664 .get = snd_soc_dapm_get_enum_double, \
665 .put = class_w_put_double, \
666 .private_value = (unsigned long)&xenum }
667
668static int class_w_put_double(struct snd_kcontrol *kcontrol,
669 struct snd_ctl_elem_value *ucontrol)
670{
671 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
672 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
673 struct snd_soc_codec *codec = widget->codec;
674 int ret;
675
676 ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
677
678 wm_hubs_update_class_w(codec);
679
680 return ret;
681}
682
683static const char *hp_mux_text[] = {
684 "Mixer",
685 "DAC",
686};
687
688static const struct soc_enum hpl_enum =
689 SOC_ENUM_SINGLE(WM8993_OUTPUT_MIXER1, 8, 2, hp_mux_text);
690
691const struct snd_kcontrol_new wm_hubs_hpl_mux =
692 WM_HUBS_ENUM_W("Left Headphone Mux", hpl_enum);
693EXPORT_SYMBOL_GPL(wm_hubs_hpl_mux);
694
695static const struct soc_enum hpr_enum =
696 SOC_ENUM_SINGLE(WM8993_OUTPUT_MIXER2, 8, 2, hp_mux_text);
697
698const struct snd_kcontrol_new wm_hubs_hpr_mux =
699 WM_HUBS_ENUM_W("Right Headphone Mux", hpr_enum);
700EXPORT_SYMBOL_GPL(wm_hubs_hpr_mux);
701
533static const struct snd_kcontrol_new in1l_pga[] = { 702static const struct snd_kcontrol_new in1l_pga[] = {
534SOC_DAPM_SINGLE("IN1LP Switch", WM8993_INPUT_MIXER2, 5, 1, 0), 703SOC_DAPM_SINGLE("IN1LP Switch", WM8993_INPUT_MIXER2, 5, 1, 0),
535SOC_DAPM_SINGLE("IN1LN Switch", WM8993_INPUT_MIXER2, 4, 1, 0), 704SOC_DAPM_SINGLE("IN1LN Switch", WM8993_INPUT_MIXER2, 4, 1, 0),
@@ -561,25 +730,25 @@ SOC_DAPM_SINGLE("IN1R Switch", WM8993_INPUT_MIXER4, 5, 1, 0),
561}; 730};
562 731
563static const struct snd_kcontrol_new left_output_mixer[] = { 732static const struct snd_kcontrol_new left_output_mixer[] = {
564SOC_DAPM_SINGLE("Right Input Switch", WM8993_OUTPUT_MIXER1, 7, 1, 0), 733WM_HUBS_SINGLE_W("Right Input Switch", WM8993_OUTPUT_MIXER1, 7, 1, 0),
565SOC_DAPM_SINGLE("Left Input Switch", WM8993_OUTPUT_MIXER1, 6, 1, 0), 734WM_HUBS_SINGLE_W("Left Input Switch", WM8993_OUTPUT_MIXER1, 6, 1, 0),
566SOC_DAPM_SINGLE("IN2RN Switch", WM8993_OUTPUT_MIXER1, 5, 1, 0), 735WM_HUBS_SINGLE_W("IN2RN Switch", WM8993_OUTPUT_MIXER1, 5, 1, 0),
567SOC_DAPM_SINGLE("IN2LN Switch", WM8993_OUTPUT_MIXER1, 4, 1, 0), 736WM_HUBS_SINGLE_W("IN2LN Switch", WM8993_OUTPUT_MIXER1, 4, 1, 0),
568SOC_DAPM_SINGLE("IN2LP Switch", WM8993_OUTPUT_MIXER1, 1, 1, 0), 737WM_HUBS_SINGLE_W("IN2LP Switch", WM8993_OUTPUT_MIXER1, 1, 1, 0),
569SOC_DAPM_SINGLE("IN1R Switch", WM8993_OUTPUT_MIXER1, 3, 1, 0), 738WM_HUBS_SINGLE_W("IN1R Switch", WM8993_OUTPUT_MIXER1, 3, 1, 0),
570SOC_DAPM_SINGLE("IN1L Switch", WM8993_OUTPUT_MIXER1, 2, 1, 0), 739WM_HUBS_SINGLE_W("IN1L Switch", WM8993_OUTPUT_MIXER1, 2, 1, 0),
571SOC_DAPM_SINGLE("DAC Switch", WM8993_OUTPUT_MIXER1, 0, 1, 0), 740WM_HUBS_SINGLE_W("DAC Switch", WM8993_OUTPUT_MIXER1, 0, 1, 0),
572}; 741};
573 742
574static const struct snd_kcontrol_new right_output_mixer[] = { 743static const struct snd_kcontrol_new right_output_mixer[] = {
575SOC_DAPM_SINGLE("Left Input Switch", WM8993_OUTPUT_MIXER2, 7, 1, 0), 744WM_HUBS_SINGLE_W("Left Input Switch", WM8993_OUTPUT_MIXER2, 7, 1, 0),
576SOC_DAPM_SINGLE("Right Input Switch", WM8993_OUTPUT_MIXER2, 6, 1, 0), 745WM_HUBS_SINGLE_W("Right Input Switch", WM8993_OUTPUT_MIXER2, 6, 1, 0),
577SOC_DAPM_SINGLE("IN2LN Switch", WM8993_OUTPUT_MIXER2, 5, 1, 0), 746WM_HUBS_SINGLE_W("IN2LN Switch", WM8993_OUTPUT_MIXER2, 5, 1, 0),
578SOC_DAPM_SINGLE("IN2RN Switch", WM8993_OUTPUT_MIXER2, 4, 1, 0), 747WM_HUBS_SINGLE_W("IN2RN Switch", WM8993_OUTPUT_MIXER2, 4, 1, 0),
579SOC_DAPM_SINGLE("IN1L Switch", WM8993_OUTPUT_MIXER2, 3, 1, 0), 748WM_HUBS_SINGLE_W("IN1L Switch", WM8993_OUTPUT_MIXER2, 3, 1, 0),
580SOC_DAPM_SINGLE("IN1R Switch", WM8993_OUTPUT_MIXER2, 2, 1, 0), 749WM_HUBS_SINGLE_W("IN1R Switch", WM8993_OUTPUT_MIXER2, 2, 1, 0),
581SOC_DAPM_SINGLE("IN2RP Switch", WM8993_OUTPUT_MIXER2, 1, 1, 0), 750WM_HUBS_SINGLE_W("IN2RP Switch", WM8993_OUTPUT_MIXER2, 1, 1, 0),
582SOC_DAPM_SINGLE("DAC Switch", WM8993_OUTPUT_MIXER2, 0, 1, 0), 751WM_HUBS_SINGLE_W("DAC Switch", WM8993_OUTPUT_MIXER2, 0, 1, 0),
583}; 752};
584 753
585static const struct snd_kcontrol_new earpiece_mixer[] = { 754static const struct snd_kcontrol_new earpiece_mixer[] = {
@@ -943,6 +1112,7 @@ int wm_hubs_add_analogue_routes(struct snd_soc_codec *codec,
943 struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec); 1112 struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec);
944 struct snd_soc_dapm_context *dapm = &codec->dapm; 1113 struct snd_soc_dapm_context *dapm = &codec->dapm;
945 1114
1115 INIT_LIST_HEAD(&hubs->dcs_cache);
946 init_completion(&hubs->dcs_done); 1116 init_completion(&hubs->dcs_done);
947 1117
948 snd_soc_dapm_add_routes(dapm, analogue_routes, 1118 snd_soc_dapm_add_routes(dapm, analogue_routes,
diff --git a/sound/soc/codecs/wm_hubs.h b/sound/soc/codecs/wm_hubs.h
index 5705276f4943..da2dc899ce6d 100644
--- a/sound/soc/codecs/wm_hubs.h
+++ b/sound/soc/codecs/wm_hubs.h
@@ -16,6 +16,8 @@
16 16
17#include <linux/completion.h> 17#include <linux/completion.h>
18#include <linux/interrupt.h> 18#include <linux/interrupt.h>
19#include <linux/list.h>
20#include <sound/control.h>
19 21
20struct snd_soc_codec; 22struct snd_soc_codec;
21 23
@@ -30,9 +32,9 @@ struct wm_hubs_data {
30 int series_startup; 32 int series_startup;
31 int no_series_update; 33 int no_series_update;
32 34
33 bool no_cache_class_w; 35 bool no_cache_dac_hp_direct;
34 bool class_w; 36 struct list_head dcs_cache;
35 u16 class_w_dcs; 37 bool (*check_class_w_digital)(struct snd_soc_codec *);
36 38
37 bool lineout1_se; 39 bool lineout1_se;
38 bool lineout1n_ena; 40 bool lineout1n_ena;
@@ -58,5 +60,9 @@ extern irqreturn_t wm_hubs_dcs_done(int irq, void *data);
58extern void wm_hubs_vmid_ena(struct snd_soc_codec *codec); 60extern void wm_hubs_vmid_ena(struct snd_soc_codec *codec);
59extern void wm_hubs_set_bias_level(struct snd_soc_codec *codec, 61extern void wm_hubs_set_bias_level(struct snd_soc_codec *codec,
60 enum snd_soc_bias_level level); 62 enum snd_soc_bias_level level);
63extern void wm_hubs_update_class_w(struct snd_soc_codec *codec);
64
65extern const struct snd_kcontrol_new wm_hubs_hpl_mux;
66extern const struct snd_kcontrol_new wm_hubs_hpr_mux;
61 67
62#endif 68#endif
diff --git a/sound/soc/ep93xx/ep93xx-ac97.c b/sound/soc/ep93xx/ep93xx-ac97.c
index 0678637abd66..bdffab33e160 100644
--- a/sound/soc/ep93xx/ep93xx-ac97.c
+++ b/sound/soc/ep93xx/ep93xx-ac97.c
@@ -87,17 +87,13 @@
87 * struct ep93xx_ac97_info - EP93xx AC97 controller info structure 87 * struct ep93xx_ac97_info - EP93xx AC97 controller info structure
88 * @lock: mutex serializing access to the bus (slot 1 & 2 ops) 88 * @lock: mutex serializing access to the bus (slot 1 & 2 ops)
89 * @dev: pointer to the platform device dev structure 89 * @dev: pointer to the platform device dev structure
90 * @mem: physical memory resource for the registers
91 * @regs: mapped AC97 controller registers 90 * @regs: mapped AC97 controller registers
92 * @irq: AC97 interrupt number
93 * @done: bus ops wait here for an interrupt 91 * @done: bus ops wait here for an interrupt
94 */ 92 */
95struct ep93xx_ac97_info { 93struct ep93xx_ac97_info {
96 struct mutex lock; 94 struct mutex lock;
97 struct device *dev; 95 struct device *dev;
98 struct resource *mem;
99 void __iomem *regs; 96 void __iomem *regs;
100 int irq;
101 struct completion done; 97 struct completion done;
102}; 98};
103 99
@@ -359,66 +355,50 @@ static struct snd_soc_dai_driver ep93xx_ac97_dai = {
359static int __devinit ep93xx_ac97_probe(struct platform_device *pdev) 355static int __devinit ep93xx_ac97_probe(struct platform_device *pdev)
360{ 356{
361 struct ep93xx_ac97_info *info; 357 struct ep93xx_ac97_info *info;
358 struct resource *res;
359 unsigned int irq;
362 int ret; 360 int ret;
363 361
364 info = kzalloc(sizeof(struct ep93xx_ac97_info), GFP_KERNEL); 362 info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
365 if (!info) 363 if (!info)
366 return -ENOMEM; 364 return -ENOMEM;
367 365
368 dev_set_drvdata(&pdev->dev, info); 366 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
369 367 if (!res)
370 mutex_init(&info->lock); 368 return -ENODEV;
371 init_completion(&info->done);
372 info->dev = &pdev->dev;
373 369
374 info->mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 370 info->regs = devm_request_and_ioremap(&pdev->dev, res);
375 if (!info->mem) { 371 if (!info->regs)
376 ret = -ENXIO; 372 return -ENXIO;
377 goto fail_free_info;
378 }
379 373
380 info->irq = platform_get_irq(pdev, 0); 374 irq = platform_get_irq(pdev, 0);
381 if (!info->irq) { 375 if (!irq)
382 ret = -ENXIO; 376 return -ENODEV;
383 goto fail_free_info;
384 }
385 377
386 if (!request_mem_region(info->mem->start, resource_size(info->mem), 378 ret = devm_request_irq(&pdev->dev, irq, ep93xx_ac97_interrupt,
387 pdev->name)) { 379 IRQF_TRIGGER_HIGH, pdev->name, info);
388 ret = -EBUSY; 380 if (ret)
389 goto fail_free_info; 381 goto fail;
390 }
391 382
392 info->regs = ioremap(info->mem->start, resource_size(info->mem)); 383 dev_set_drvdata(&pdev->dev, info);
393 if (!info->regs) {
394 ret = -ENOMEM;
395 goto fail_release_mem;
396 }
397 384
398 ret = request_irq(info->irq, ep93xx_ac97_interrupt, IRQF_TRIGGER_HIGH, 385 mutex_init(&info->lock);
399 pdev->name, info); 386 init_completion(&info->done);
400 if (ret) 387 info->dev = &pdev->dev;
401 goto fail_unmap_mem;
402 388
403 ep93xx_ac97_info = info; 389 ep93xx_ac97_info = info;
404 platform_set_drvdata(pdev, info); 390 platform_set_drvdata(pdev, info);
405 391
406 ret = snd_soc_register_dai(&pdev->dev, &ep93xx_ac97_dai); 392 ret = snd_soc_register_dai(&pdev->dev, &ep93xx_ac97_dai);
407 if (ret) 393 if (ret)
408 goto fail_free_irq; 394 goto fail;
409 395
410 return 0; 396 return 0;
411 397
412fail_free_irq: 398fail:
413 platform_set_drvdata(pdev, NULL); 399 platform_set_drvdata(pdev, NULL);
414 free_irq(info->irq, info); 400 ep93xx_ac97_info = NULL;
415fail_unmap_mem: 401 dev_set_drvdata(&pdev->dev, NULL);
416 iounmap(info->regs);
417fail_release_mem:
418 release_mem_region(info->mem->start, resource_size(info->mem));
419fail_free_info:
420 kfree(info);
421
422 return ret; 402 return ret;
423} 403}
424 404
@@ -431,11 +411,9 @@ static int __devexit ep93xx_ac97_remove(struct platform_device *pdev)
431 /* disable the AC97 controller */ 411 /* disable the AC97 controller */
432 ep93xx_ac97_write_reg(info, AC97GCR, 0); 412 ep93xx_ac97_write_reg(info, AC97GCR, 0);
433 413
434 free_irq(info->irq, info);
435 iounmap(info->regs);
436 release_mem_region(info->mem->start, resource_size(info->mem));
437 platform_set_drvdata(pdev, NULL); 414 platform_set_drvdata(pdev, NULL);
438 kfree(info); 415 ep93xx_ac97_info = NULL;
416 dev_set_drvdata(&pdev->dev, NULL);
439 417
440 return 0; 418 return 0;
441} 419}
diff --git a/sound/soc/ep93xx/ep93xx-i2s.c b/sound/soc/ep93xx/ep93xx-i2s.c
index f7a62348e3fe..8df8f6dc474f 100644
--- a/sound/soc/ep93xx/ep93xx-i2s.c
+++ b/sound/soc/ep93xx/ep93xx-i2s.c
@@ -63,7 +63,6 @@ struct ep93xx_i2s_info {
63 struct clk *sclk; 63 struct clk *sclk;
64 struct clk *lrclk; 64 struct clk *lrclk;
65 struct ep93xx_pcm_dma_params *dma_params; 65 struct ep93xx_pcm_dma_params *dma_params;
66 struct resource *mem;
67 void __iomem *regs; 66 void __iomem *regs;
68}; 67};
69 68
@@ -373,38 +372,22 @@ static int ep93xx_i2s_probe(struct platform_device *pdev)
373 struct resource *res; 372 struct resource *res;
374 int err; 373 int err;
375 374
376 info = kzalloc(sizeof(struct ep93xx_i2s_info), GFP_KERNEL); 375 info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
377 if (!info) { 376 if (!info)
378 err = -ENOMEM; 377 return -ENOMEM;
379 goto fail;
380 }
381
382 dev_set_drvdata(&pdev->dev, info);
383 info->dma_params = ep93xx_i2s_dma_params;
384 378
385 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 379 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
386 if (!res) { 380 if (!res)
387 err = -ENODEV; 381 return -ENODEV;
388 goto fail_free_info;
389 }
390 382
391 info->mem = request_mem_region(res->start, resource_size(res), 383 info->regs = devm_request_and_ioremap(&pdev->dev, res);
392 pdev->name); 384 if (!info->regs)
393 if (!info->mem) { 385 return -ENXIO;
394 err = -EBUSY;
395 goto fail_free_info;
396 }
397
398 info->regs = ioremap(info->mem->start, resource_size(info->mem));
399 if (!info->regs) {
400 err = -ENXIO;
401 goto fail_release_mem;
402 }
403 386
404 info->mclk = clk_get(&pdev->dev, "mclk"); 387 info->mclk = clk_get(&pdev->dev, "mclk");
405 if (IS_ERR(info->mclk)) { 388 if (IS_ERR(info->mclk)) {
406 err = PTR_ERR(info->mclk); 389 err = PTR_ERR(info->mclk);
407 goto fail_unmap_mem; 390 goto fail;
408 } 391 }
409 392
410 info->sclk = clk_get(&pdev->dev, "sclk"); 393 info->sclk = clk_get(&pdev->dev, "sclk");
@@ -419,6 +402,9 @@ static int ep93xx_i2s_probe(struct platform_device *pdev)
419 goto fail_put_sclk; 402 goto fail_put_sclk;
420 } 403 }
421 404
405 dev_set_drvdata(&pdev->dev, info);
406 info->dma_params = ep93xx_i2s_dma_params;
407
422 err = snd_soc_register_dai(&pdev->dev, &ep93xx_i2s_dai); 408 err = snd_soc_register_dai(&pdev->dev, &ep93xx_i2s_dai);
423 if (err) 409 if (err)
424 goto fail_put_lrclk; 410 goto fail_put_lrclk;
@@ -426,17 +412,12 @@ static int ep93xx_i2s_probe(struct platform_device *pdev)
426 return 0; 412 return 0;
427 413
428fail_put_lrclk: 414fail_put_lrclk:
415 dev_set_drvdata(&pdev->dev, NULL);
429 clk_put(info->lrclk); 416 clk_put(info->lrclk);
430fail_put_sclk: 417fail_put_sclk:
431 clk_put(info->sclk); 418 clk_put(info->sclk);
432fail_put_mclk: 419fail_put_mclk:
433 clk_put(info->mclk); 420 clk_put(info->mclk);
434fail_unmap_mem:
435 iounmap(info->regs);
436fail_release_mem:
437 release_mem_region(info->mem->start, resource_size(info->mem));
438fail_free_info:
439 kfree(info);
440fail: 421fail:
441 return err; 422 return err;
442} 423}
@@ -446,12 +427,10 @@ static int __devexit ep93xx_i2s_remove(struct platform_device *pdev)
446 struct ep93xx_i2s_info *info = dev_get_drvdata(&pdev->dev); 427 struct ep93xx_i2s_info *info = dev_get_drvdata(&pdev->dev);
447 428
448 snd_soc_unregister_dai(&pdev->dev); 429 snd_soc_unregister_dai(&pdev->dev);
430 dev_set_drvdata(&pdev->dev, NULL);
449 clk_put(info->lrclk); 431 clk_put(info->lrclk);
450 clk_put(info->sclk); 432 clk_put(info->sclk);
451 clk_put(info->mclk); 433 clk_put(info->mclk);
452 iounmap(info->regs);
453 release_mem_region(info->mem->start, resource_size(info->mem));
454 kfree(info);
455 return 0; 434 return 0;
456} 435}
457 436
diff --git a/sound/soc/fsl/Kconfig b/sound/soc/fsl/Kconfig
index d754d34d68a6..3f2dd3a0377a 100644
--- a/sound/soc/fsl/Kconfig
+++ b/sound/soc/fsl/Kconfig
@@ -1,18 +1,31 @@
1config SND_MPC52xx_DMA 1config SND_SOC_FSL_SSI
2 tristate 2 tristate
3 3
4# ASoC platform support for the Freescale PowerPC SOCs that have an SSI and 4config SND_SOC_FSL_UTILS
5# an Elo DMA controller, such as the MPC8610 and P1022. You will still need to
6# select a platform driver and a codec driver.
7config SND_SOC_POWERPC_SSI
8 tristate 5 tristate
6
7menuconfig SND_POWERPC_SOC
8 tristate "SoC Audio for Freescale PowerPC CPUs"
9 depends on FSL_SOC 9 depends on FSL_SOC
10 help
11 Say Y or M if you want to add support for codecs attached to
12 the PowerPC CPUs.
13
14if SND_POWERPC_SOC
15
16config SND_MPC52xx_DMA
17 tristate
18
19config SND_SOC_POWERPC_DMA
20 tristate
10 21
11config SND_SOC_MPC8610_HPCD 22config SND_SOC_MPC8610_HPCD
12 tristate "ALSA SoC support for the Freescale MPC8610 HPCD board" 23 tristate "ALSA SoC support for the Freescale MPC8610 HPCD board"
13 # I2C is necessary for the CS4270 driver 24 # I2C is necessary for the CS4270 driver
14 depends on MPC8610_HPCD && I2C 25 depends on MPC8610_HPCD && I2C
15 select SND_SOC_POWERPC_SSI 26 select SND_SOC_FSL_SSI
27 select SND_SOC_FSL_UTILS
28 select SND_SOC_POWERPC_DMA
16 select SND_SOC_CS4270 29 select SND_SOC_CS4270
17 select SND_SOC_CS4270_VD33_ERRATA 30 select SND_SOC_CS4270_VD33_ERRATA
18 default y if MPC8610_HPCD 31 default y if MPC8610_HPCD
@@ -23,7 +36,9 @@ config SND_SOC_P1022_DS
23 tristate "ALSA SoC support for the Freescale P1022 DS board" 36 tristate "ALSA SoC support for the Freescale P1022 DS board"
24 # I2C is necessary for the WM8776 driver 37 # I2C is necessary for the WM8776 driver
25 depends on P1022_DS && I2C 38 depends on P1022_DS && I2C
26 select SND_SOC_POWERPC_SSI 39 select SND_SOC_FSL_SSI
40 select SND_SOC_FSL_UTILS
41 select SND_SOC_POWERPC_DMA
27 select SND_SOC_WM8776 42 select SND_SOC_WM8776
28 default y if P1022_DS 43 default y if P1022_DS
29 help 44 help
@@ -65,3 +80,103 @@ config SND_MPC52xx_SOC_EFIKA
65 help 80 help
66 Say Y if you want to add support for sound on the Efika. 81 Say Y if you want to add support for sound on the Efika.
67 82
83endif # SND_POWERPC_SOC
84
85menuconfig SND_IMX_SOC
86 tristate "SoC Audio for Freescale i.MX CPUs"
87 depends on ARCH_MXC
88 help
89 Say Y or M if you want to add support for codecs attached to
90 the i.MX CPUs.
91
92if SND_IMX_SOC
93
94config SND_SOC_IMX_SSI
95 tristate
96
97config SND_SOC_IMX_PCM
98 tristate
99
100config SND_SOC_IMX_PCM_FIQ
101 tristate
102 select FIQ
103 select SND_SOC_IMX_PCM
104
105config SND_SOC_IMX_PCM_DMA
106 tristate
107 select SND_SOC_DMAENGINE_PCM
108 select SND_SOC_IMX_PCM
109
110config SND_SOC_IMX_AUDMUX
111 tristate
112
113config SND_MXC_SOC_WM1133_EV1
114 tristate "Audio on the the i.MX31ADS with WM1133-EV1 fitted"
115 depends on MACH_MX31ADS_WM1133_EV1 && EXPERIMENTAL
116 select SND_SOC_WM8350
117 select SND_SOC_IMX_PCM_FIQ
118 select SND_SOC_IMX_AUDMUX
119 select SND_SOC_IMX_SSI
120 help
121 Enable support for audio on the i.MX31ADS with the WM1133-EV1
122 PMIC board with WM8835x fitted.
123
124config SND_SOC_MX27VIS_AIC32X4
125 tristate "SoC audio support for Visstrim M10 boards"
126 depends on MACH_IMX27_VISSTRIM_M10 && I2C
127 select SND_SOC_TLV320AIC32X4
128 select SND_SOC_IMX_PCM_DMA
129 select SND_SOC_IMX_AUDMUX
130 select SND_SOC_IMX_SSI
131 help
132 Say Y if you want to add support for SoC audio on Visstrim SM10
133 board with TLV320AIC32X4 codec.
134
135config SND_SOC_PHYCORE_AC97
136 tristate "SoC Audio support for Phytec phyCORE (and phyCARD) boards"
137 depends on MACH_PCM043 || MACH_PCA100
138 select SND_SOC_AC97_BUS
139 select SND_SOC_WM9712
140 select SND_SOC_IMX_PCM_FIQ
141 select SND_SOC_IMX_AUDMUX
142 select SND_SOC_IMX_SSI
143 help
144 Say Y if you want to add support for SoC audio on Phytec phyCORE
145 and phyCARD boards in AC97 mode
146
147config SND_SOC_EUKREA_TLV320
148 tristate "Eukrea TLV320"
149 depends on MACH_EUKREA_MBIMX27_BASEBOARD \
150 || MACH_EUKREA_MBIMXSD25_BASEBOARD \
151 || MACH_EUKREA_MBIMXSD35_BASEBOARD \
152 || MACH_EUKREA_MBIMXSD51_BASEBOARD
153 depends on I2C
154 select SND_SOC_TLV320AIC23
155 select SND_SOC_IMX_PCM_FIQ
156 select SND_SOC_IMX_AUDMUX
157 select SND_SOC_IMX_SSI
158 help
159 Enable I2S based access to the TLV320AIC23B codec attached
160 to the SSI interface
161
162config SND_SOC_IMX_SGTL5000
163 tristate "SoC Audio support for i.MX boards with sgtl5000"
164 depends on OF && I2C
165 select SND_SOC_SGTL5000
166 select SND_SOC_IMX_PCM_DMA
167 select SND_SOC_IMX_AUDMUX
168 select SND_SOC_FSL_SSI
169 select SND_SOC_FSL_UTILS
170 help
171 Say Y if you want to add support for SoC audio on an i.MX board with
172 a sgtl5000 codec.
173
174config SND_SOC_IMX_MC13783
175 tristate "SoC Audio support for I.MX boards with mc13783"
176 depends on MFD_MC13783
177 select SND_SOC_IMX_SSI
178 select SND_SOC_IMX_AUDMUX
179 select SND_SOC_MC13783
180 select SND_SOC_IMX_PCM_DMA
181
182endif # SND_IMX_SOC
diff --git a/sound/soc/fsl/Makefile b/sound/soc/fsl/Makefile
index b4a38c0ac58c..5f3cf3f52ea0 100644
--- a/sound/soc/fsl/Makefile
+++ b/sound/soc/fsl/Makefile
@@ -8,8 +8,11 @@ obj-$(CONFIG_SND_SOC_P1022_DS) += snd-soc-p1022-ds.o
8 8
9# Freescale PowerPC SSI/DMA Platform Support 9# Freescale PowerPC SSI/DMA Platform Support
10snd-soc-fsl-ssi-objs := fsl_ssi.o 10snd-soc-fsl-ssi-objs := fsl_ssi.o
11snd-soc-fsl-utils-objs := fsl_utils.o
11snd-soc-fsl-dma-objs := fsl_dma.o 12snd-soc-fsl-dma-objs := fsl_dma.o
12obj-$(CONFIG_SND_SOC_POWERPC_SSI) += snd-soc-fsl-ssi.o snd-soc-fsl-dma.o 13obj-$(CONFIG_SND_SOC_FSL_SSI) += snd-soc-fsl-ssi.o
14obj-$(CONFIG_SND_SOC_FSL_UTILS) += snd-soc-fsl-utils.o
15obj-$(CONFIG_SND_SOC_POWERPC_DMA) += snd-soc-fsl-dma.o
13 16
14# MPC5200 Platform Support 17# MPC5200 Platform Support
15obj-$(CONFIG_SND_MPC52xx_DMA) += mpc5200_dma.o 18obj-$(CONFIG_SND_MPC52xx_DMA) += mpc5200_dma.o
@@ -20,3 +23,29 @@ obj-$(CONFIG_SND_SOC_MPC5200_AC97) += mpc5200_psc_ac97.o
20obj-$(CONFIG_SND_MPC52xx_SOC_PCM030) += pcm030-audio-fabric.o 23obj-$(CONFIG_SND_MPC52xx_SOC_PCM030) += pcm030-audio-fabric.o
21obj-$(CONFIG_SND_MPC52xx_SOC_EFIKA) += efika-audio-fabric.o 24obj-$(CONFIG_SND_MPC52xx_SOC_EFIKA) += efika-audio-fabric.o
22 25
26# i.MX Platform Support
27snd-soc-imx-ssi-objs := imx-ssi.o
28snd-soc-imx-audmux-objs := imx-audmux.o
29
30obj-$(CONFIG_SND_SOC_IMX_SSI) += snd-soc-imx-ssi.o
31obj-$(CONFIG_SND_SOC_IMX_AUDMUX) += snd-soc-imx-audmux.o
32
33obj-$(CONFIG_SND_SOC_IMX_PCM) += snd-soc-imx-pcm.o
34snd-soc-imx-pcm-y := imx-pcm.o
35snd-soc-imx-pcm-$(CONFIG_SND_SOC_IMX_PCM_FIQ) += imx-pcm-fiq.o
36snd-soc-imx-pcm-$(CONFIG_SND_SOC_IMX_PCM_DMA) += imx-pcm-dma.o
37
38# i.MX Machine Support
39snd-soc-eukrea-tlv320-objs := eukrea-tlv320.o
40snd-soc-phycore-ac97-objs := phycore-ac97.o
41snd-soc-mx27vis-aic32x4-objs := mx27vis-aic32x4.o
42snd-soc-wm1133-ev1-objs := wm1133-ev1.o
43snd-soc-imx-sgtl5000-objs := imx-sgtl5000.o
44snd-soc-imx-mc13783-objs := imx-mc13783.o
45
46obj-$(CONFIG_SND_SOC_EUKREA_TLV320) += snd-soc-eukrea-tlv320.o
47obj-$(CONFIG_SND_SOC_PHYCORE_AC97) += snd-soc-phycore-ac97.o
48obj-$(CONFIG_SND_SOC_MX27VIS_AIC32X4) += snd-soc-mx27vis-aic32x4.o
49obj-$(CONFIG_SND_MXC_SOC_WM1133_EV1) += snd-soc-wm1133-ev1.o
50obj-$(CONFIG_SND_SOC_IMX_SGTL5000) += snd-soc-imx-sgtl5000.o
51obj-$(CONFIG_SND_SOC_IMX_MC13783) += snd-soc-imx-mc13783.o
diff --git a/sound/soc/imx/eukrea-tlv320.c b/sound/soc/fsl/eukrea-tlv320.c
index 7d4475cfdb24..efb9ede01208 100644
--- a/sound/soc/imx/eukrea-tlv320.c
+++ b/sound/soc/fsl/eukrea-tlv320.c
@@ -7,7 +7,7 @@
7 * which is Copyright 2009 Simtec Electronics 7 * which is Copyright 2009 Simtec Electronics
8 * and on sound/soc/imx/phycore-ac97.c which is 8 * and on sound/soc/imx/phycore-ac97.c which is
9 * Copyright 2009 Sascha Hauer, Pengutronix <s.hauer@pengutronix.de> 9 * Copyright 2009 Sascha Hauer, Pengutronix <s.hauer@pengutronix.de>
10 * 10 *
11 * This program is free software; you can redistribute it and/or modify it 11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the 12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your 13 * Free Software Foundation; either version 2 of the License, or (at your
diff --git a/sound/soc/fsl/fsl_ssi.c b/sound/soc/fsl/fsl_ssi.c
index 2eb407fa3b48..4ed2afd47782 100644
--- a/sound/soc/fsl/fsl_ssi.c
+++ b/sound/soc/fsl/fsl_ssi.c
@@ -11,11 +11,15 @@
11 */ 11 */
12 12
13#include <linux/init.h> 13#include <linux/init.h>
14#include <linux/io.h>
14#include <linux/module.h> 15#include <linux/module.h>
15#include <linux/interrupt.h> 16#include <linux/interrupt.h>
17#include <linux/clk.h>
16#include <linux/device.h> 18#include <linux/device.h>
17#include <linux/delay.h> 19#include <linux/delay.h>
18#include <linux/slab.h> 20#include <linux/slab.h>
21#include <linux/of_address.h>
22#include <linux/of_irq.h>
19#include <linux/of_platform.h> 23#include <linux/of_platform.h>
20 24
21#include <sound/core.h> 25#include <sound/core.h>
@@ -25,6 +29,26 @@
25#include <sound/soc.h> 29#include <sound/soc.h>
26 30
27#include "fsl_ssi.h" 31#include "fsl_ssi.h"
32#include "imx-pcm.h"
33
34#ifdef PPC
35#define read_ssi(addr) in_be32(addr)
36#define write_ssi(val, addr) out_be32(addr, val)
37#define write_ssi_mask(addr, clear, set) clrsetbits_be32(addr, clear, set)
38#elif defined ARM
39#define read_ssi(addr) readl(addr)
40#define write_ssi(val, addr) writel(val, addr)
41/*
42 * FIXME: Proper locking should be added at write_ssi_mask caller level
43 * to ensure this register read/modify/write sequence is race free.
44 */
45static inline void write_ssi_mask(u32 __iomem *addr, u32 clear, u32 set)
46{
47 u32 val = readl(addr);
48 val = (val & ~clear) | set;
49 writel(val, addr);
50}
51#endif
28 52
29/** 53/**
30 * FSLSSI_I2S_RATES: sample rates supported by the I2S 54 * FSLSSI_I2S_RATES: sample rates supported by the I2S
@@ -94,6 +118,13 @@ struct fsl_ssi_private {
94 struct device_attribute dev_attr; 118 struct device_attribute dev_attr;
95 struct platform_device *pdev; 119 struct platform_device *pdev;
96 120
121 bool new_binding;
122 bool ssi_on_imx;
123 struct clk *clk;
124 struct platform_device *imx_pcm_pdev;
125 struct imx_pcm_dma_params dma_params_tx;
126 struct imx_pcm_dma_params dma_params_rx;
127
97 struct { 128 struct {
98 unsigned int rfrc; 129 unsigned int rfrc;
99 unsigned int tfrc; 130 unsigned int tfrc;
@@ -145,7 +176,7 @@ static irqreturn_t fsl_ssi_isr(int irq, void *dev_id)
145 were interrupted for. We mask it with the Interrupt Enable register 176 were interrupted for. We mask it with the Interrupt Enable register
146 so that we only check for events that we're interested in. 177 so that we only check for events that we're interested in.
147 */ 178 */
148 sisr = in_be32(&ssi->sisr) & SIER_FLAGS; 179 sisr = read_ssi(&ssi->sisr) & SIER_FLAGS;
149 180
150 if (sisr & CCSR_SSI_SISR_RFRC) { 181 if (sisr & CCSR_SSI_SISR_RFRC) {
151 ssi_private->stats.rfrc++; 182 ssi_private->stats.rfrc++;
@@ -260,7 +291,7 @@ static irqreturn_t fsl_ssi_isr(int irq, void *dev_id)
260 291
261 /* Clear the bits that we set */ 292 /* Clear the bits that we set */
262 if (sisr2) 293 if (sisr2)
263 out_be32(&ssi->sisr, sisr2); 294 write_ssi(sisr2, &ssi->sisr);
264 295
265 return ret; 296 return ret;
266} 297}
@@ -295,7 +326,7 @@ static int fsl_ssi_startup(struct snd_pcm_substream *substream,
295 * SSI needs to be disabled before updating the registers we set 326 * SSI needs to be disabled before updating the registers we set
296 * here. 327 * here.
297 */ 328 */
298 clrbits32(&ssi->scr, CCSR_SSI_SCR_SSIEN); 329 write_ssi_mask(&ssi->scr, CCSR_SSI_SCR_SSIEN, 0);
299 330
300 /* 331 /*
301 * Program the SSI into I2S Slave Non-Network Synchronous mode. 332 * Program the SSI into I2S Slave Non-Network Synchronous mode.
@@ -303,20 +334,18 @@ static int fsl_ssi_startup(struct snd_pcm_substream *substream,
303 * 334 *
304 * FIXME: Little-endian samples require a different shift dir 335 * FIXME: Little-endian samples require a different shift dir
305 */ 336 */
306 clrsetbits_be32(&ssi->scr, 337 write_ssi_mask(&ssi->scr,
307 CCSR_SSI_SCR_I2S_MODE_MASK | CCSR_SSI_SCR_SYN, 338 CCSR_SSI_SCR_I2S_MODE_MASK | CCSR_SSI_SCR_SYN,
308 CCSR_SSI_SCR_TFR_CLK_DIS | CCSR_SSI_SCR_I2S_MODE_SLAVE 339 CCSR_SSI_SCR_TFR_CLK_DIS | CCSR_SSI_SCR_I2S_MODE_SLAVE
309 | (synchronous ? CCSR_SSI_SCR_SYN : 0)); 340 | (synchronous ? CCSR_SSI_SCR_SYN : 0));
310 341
311 out_be32(&ssi->stcr, 342 write_ssi(CCSR_SSI_STCR_TXBIT0 | CCSR_SSI_STCR_TFEN0 |
312 CCSR_SSI_STCR_TXBIT0 | CCSR_SSI_STCR_TFEN0 |
313 CCSR_SSI_STCR_TFSI | CCSR_SSI_STCR_TEFS | 343 CCSR_SSI_STCR_TFSI | CCSR_SSI_STCR_TEFS |
314 CCSR_SSI_STCR_TSCKP); 344 CCSR_SSI_STCR_TSCKP, &ssi->stcr);
315 345
316 out_be32(&ssi->srcr, 346 write_ssi(CCSR_SSI_SRCR_RXBIT0 | CCSR_SSI_SRCR_RFEN0 |
317 CCSR_SSI_SRCR_RXBIT0 | CCSR_SSI_SRCR_RFEN0 |
318 CCSR_SSI_SRCR_RFSI | CCSR_SSI_SRCR_REFS | 347 CCSR_SSI_SRCR_RFSI | CCSR_SSI_SRCR_REFS |
319 CCSR_SSI_SRCR_RSCKP); 348 CCSR_SSI_SRCR_RSCKP, &ssi->srcr);
320 349
321 /* 350 /*
322 * The DC and PM bits are only used if the SSI is the clock 351 * The DC and PM bits are only used if the SSI is the clock
@@ -324,7 +353,7 @@ static int fsl_ssi_startup(struct snd_pcm_substream *substream,
324 */ 353 */
325 354
326 /* Enable the interrupts and DMA requests */ 355 /* Enable the interrupts and DMA requests */
327 out_be32(&ssi->sier, SIER_FLAGS); 356 write_ssi(SIER_FLAGS, &ssi->sier);
328 357
329 /* 358 /*
330 * Set the watermark for transmit FIFI 0 and receive FIFO 0. We 359 * Set the watermark for transmit FIFI 0 and receive FIFO 0. We
@@ -339,9 +368,9 @@ static int fsl_ssi_startup(struct snd_pcm_substream *substream,
339 * make this value larger (and maybe we should), but this way 368 * make this value larger (and maybe we should), but this way
340 * data will be written to memory as soon as it's available. 369 * data will be written to memory as soon as it's available.
341 */ 370 */
342 out_be32(&ssi->sfcsr, 371 write_ssi(CCSR_SSI_SFCSR_TFWM0(ssi_private->fifo_depth - 2) |
343 CCSR_SSI_SFCSR_TFWM0(ssi_private->fifo_depth - 2) | 372 CCSR_SSI_SFCSR_RFWM0(ssi_private->fifo_depth - 2),
344 CCSR_SSI_SFCSR_RFWM0(ssi_private->fifo_depth - 2)); 373 &ssi->sfcsr);
345 374
346 /* 375 /*
347 * We keep the SSI disabled because if we enable it, then the 376 * We keep the SSI disabled because if we enable it, then the
@@ -393,6 +422,12 @@ static int fsl_ssi_startup(struct snd_pcm_substream *substream,
393 ssi_private->second_stream = substream; 422 ssi_private->second_stream = substream;
394 } 423 }
395 424
425 if (ssi_private->ssi_on_imx)
426 snd_soc_dai_set_dma_data(dai, substream,
427 (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
428 &ssi_private->dma_params_tx :
429 &ssi_private->dma_params_rx);
430
396 return 0; 431 return 0;
397} 432}
398 433
@@ -417,7 +452,7 @@ static int fsl_ssi_hw_params(struct snd_pcm_substream *substream,
417 unsigned int sample_size = 452 unsigned int sample_size =
418 snd_pcm_format_width(params_format(hw_params)); 453 snd_pcm_format_width(params_format(hw_params));
419 u32 wl = CCSR_SSI_SxCCR_WL(sample_size); 454 u32 wl = CCSR_SSI_SxCCR_WL(sample_size);
420 int enabled = in_be32(&ssi->scr) & CCSR_SSI_SCR_SSIEN; 455 int enabled = read_ssi(&ssi->scr) & CCSR_SSI_SCR_SSIEN;
421 456
422 /* 457 /*
423 * If we're in synchronous mode, and the SSI is already enabled, 458 * If we're in synchronous mode, and the SSI is already enabled,
@@ -439,9 +474,9 @@ static int fsl_ssi_hw_params(struct snd_pcm_substream *substream,
439 /* In synchronous mode, the SSI uses STCCR for capture */ 474 /* In synchronous mode, the SSI uses STCCR for capture */
440 if ((substream->stream == SNDRV_PCM_STREAM_PLAYBACK) || 475 if ((substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ||
441 ssi_private->cpu_dai_drv.symmetric_rates) 476 ssi_private->cpu_dai_drv.symmetric_rates)
442 clrsetbits_be32(&ssi->stccr, CCSR_SSI_SxCCR_WL_MASK, wl); 477 write_ssi_mask(&ssi->stccr, CCSR_SSI_SxCCR_WL_MASK, wl);
443 else 478 else
444 clrsetbits_be32(&ssi->srccr, CCSR_SSI_SxCCR_WL_MASK, wl); 479 write_ssi_mask(&ssi->srccr, CCSR_SSI_SxCCR_WL_MASK, wl);
445 480
446 return 0; 481 return 0;
447} 482}
@@ -466,19 +501,19 @@ static int fsl_ssi_trigger(struct snd_pcm_substream *substream, int cmd,
466 case SNDRV_PCM_TRIGGER_START: 501 case SNDRV_PCM_TRIGGER_START:
467 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 502 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
468 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 503 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
469 setbits32(&ssi->scr, 504 write_ssi_mask(&ssi->scr, 0,
470 CCSR_SSI_SCR_SSIEN | CCSR_SSI_SCR_TE); 505 CCSR_SSI_SCR_SSIEN | CCSR_SSI_SCR_TE);
471 else 506 else
472 setbits32(&ssi->scr, 507 write_ssi_mask(&ssi->scr, 0,
473 CCSR_SSI_SCR_SSIEN | CCSR_SSI_SCR_RE); 508 CCSR_SSI_SCR_SSIEN | CCSR_SSI_SCR_RE);
474 break; 509 break;
475 510
476 case SNDRV_PCM_TRIGGER_STOP: 511 case SNDRV_PCM_TRIGGER_STOP:
477 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 512 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
478 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 513 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
479 clrbits32(&ssi->scr, CCSR_SSI_SCR_TE); 514 write_ssi_mask(&ssi->scr, CCSR_SSI_SCR_TE, 0);
480 else 515 else
481 clrbits32(&ssi->scr, CCSR_SSI_SCR_RE); 516 write_ssi_mask(&ssi->scr, CCSR_SSI_SCR_RE, 0);
482 break; 517 break;
483 518
484 default: 519 default:
@@ -510,7 +545,7 @@ static void fsl_ssi_shutdown(struct snd_pcm_substream *substream,
510 if (!ssi_private->first_stream) { 545 if (!ssi_private->first_stream) {
511 struct ccsr_ssi __iomem *ssi = ssi_private->ssi; 546 struct ccsr_ssi __iomem *ssi = ssi_private->ssi;
512 547
513 clrbits32(&ssi->scr, CCSR_SSI_SCR_SSIEN); 548 write_ssi_mask(&ssi->scr, CCSR_SSI_SCR_SSIEN, 0);
514 } 549 }
515} 550}
516 551
@@ -622,12 +657,6 @@ static int __devinit fsl_ssi_probe(struct platform_device *pdev)
622 if (!of_device_is_available(np)) 657 if (!of_device_is_available(np))
623 return -ENODEV; 658 return -ENODEV;
624 659
625 /* Check for a codec-handle property. */
626 if (!of_get_property(np, "codec-handle", NULL)) {
627 dev_err(&pdev->dev, "missing codec-handle property\n");
628 return -ENODEV;
629 }
630
631 /* We only support the SSI in "I2S Slave" mode */ 660 /* We only support the SSI in "I2S Slave" mode */
632 sprop = of_get_property(np, "fsl,mode", NULL); 661 sprop = of_get_property(np, "fsl,mode", NULL);
633 if (!sprop || strcmp(sprop, "i2s-slave")) { 662 if (!sprop || strcmp(sprop, "i2s-slave")) {
@@ -692,6 +721,50 @@ static int __devinit fsl_ssi_probe(struct platform_device *pdev)
692 /* Older 8610 DTs didn't have the fifo-depth property */ 721 /* Older 8610 DTs didn't have the fifo-depth property */
693 ssi_private->fifo_depth = 8; 722 ssi_private->fifo_depth = 8;
694 723
724 if (of_device_is_compatible(pdev->dev.of_node, "fsl,imx21-ssi")) {
725 u32 dma_events[2];
726 ssi_private->ssi_on_imx = true;
727
728 ssi_private->clk = clk_get(&pdev->dev, NULL);
729 if (IS_ERR(ssi_private->clk)) {
730 ret = PTR_ERR(ssi_private->clk);
731 dev_err(&pdev->dev, "could not get clock: %d\n", ret);
732 goto error_irq;
733 }
734 clk_prepare_enable(ssi_private->clk);
735
736 /*
737 * We have burstsize be "fifo_depth - 2" to match the SSI
738 * watermark setting in fsl_ssi_startup().
739 */
740 ssi_private->dma_params_tx.burstsize =
741 ssi_private->fifo_depth - 2;
742 ssi_private->dma_params_rx.burstsize =
743 ssi_private->fifo_depth - 2;
744 ssi_private->dma_params_tx.dma_addr =
745 ssi_private->ssi_phys + offsetof(struct ccsr_ssi, stx0);
746 ssi_private->dma_params_rx.dma_addr =
747 ssi_private->ssi_phys + offsetof(struct ccsr_ssi, srx0);
748 /*
749 * TODO: This is a temporary solution and should be changed
750 * to use generic DMA binding later when the helplers get in.
751 */
752 ret = of_property_read_u32_array(pdev->dev.of_node,
753 "fsl,ssi-dma-events", dma_events, 2);
754 if (ret) {
755 dev_err(&pdev->dev, "could not get dma events\n");
756 goto error_clk;
757 }
758 ssi_private->dma_params_tx.dma = dma_events[0];
759 ssi_private->dma_params_rx.dma = dma_events[1];
760
761 ssi_private->dma_params_tx.shared_peripheral =
762 of_device_is_compatible(of_get_parent(np),
763 "fsl,spba-bus");
764 ssi_private->dma_params_rx.shared_peripheral =
765 ssi_private->dma_params_tx.shared_peripheral;
766 }
767
695 /* Initialize the the device_attribute structure */ 768 /* Initialize the the device_attribute structure */
696 dev_attr = &ssi_private->dev_attr; 769 dev_attr = &ssi_private->dev_attr;
697 sysfs_attr_init(&dev_attr->attr); 770 sysfs_attr_init(&dev_attr->attr);
@@ -715,6 +788,26 @@ static int __devinit fsl_ssi_probe(struct platform_device *pdev)
715 goto error_dev; 788 goto error_dev;
716 } 789 }
717 790
791 if (ssi_private->ssi_on_imx) {
792 ssi_private->imx_pcm_pdev =
793 platform_device_register_simple("imx-pcm-audio",
794 -1, NULL, 0);
795 if (IS_ERR(ssi_private->imx_pcm_pdev)) {
796 ret = PTR_ERR(ssi_private->imx_pcm_pdev);
797 goto error_dev;
798 }
799 }
800
801 /*
802 * If codec-handle property is missing from SSI node, we assume
803 * that the machine driver uses new binding which does not require
804 * SSI driver to trigger machine driver's probe.
805 */
806 if (!of_get_property(np, "codec-handle", NULL)) {
807 ssi_private->new_binding = true;
808 goto done;
809 }
810
718 /* Trigger the machine driver's probe function. The platform driver 811 /* Trigger the machine driver's probe function. The platform driver
719 * name of the machine driver is taken from /compatible property of the 812 * name of the machine driver is taken from /compatible property of the
720 * device tree. We also pass the address of the CPU DAI driver 813 * device tree. We also pass the address of the CPU DAI driver
@@ -736,15 +829,24 @@ static int __devinit fsl_ssi_probe(struct platform_device *pdev)
736 goto error_dai; 829 goto error_dai;
737 } 830 }
738 831
832done:
739 return 0; 833 return 0;
740 834
741error_dai: 835error_dai:
836 if (ssi_private->ssi_on_imx)
837 platform_device_unregister(ssi_private->imx_pcm_pdev);
742 snd_soc_unregister_dai(&pdev->dev); 838 snd_soc_unregister_dai(&pdev->dev);
743 839
744error_dev: 840error_dev:
745 dev_set_drvdata(&pdev->dev, NULL); 841 dev_set_drvdata(&pdev->dev, NULL);
746 device_remove_file(&pdev->dev, dev_attr); 842 device_remove_file(&pdev->dev, dev_attr);
747 843
844error_clk:
845 if (ssi_private->ssi_on_imx) {
846 clk_disable_unprepare(ssi_private->clk);
847 clk_put(ssi_private->clk);
848 }
849
748error_irq: 850error_irq:
749 free_irq(ssi_private->irq, ssi_private); 851 free_irq(ssi_private->irq, ssi_private);
750 852
@@ -764,7 +866,13 @@ static int fsl_ssi_remove(struct platform_device *pdev)
764{ 866{
765 struct fsl_ssi_private *ssi_private = dev_get_drvdata(&pdev->dev); 867 struct fsl_ssi_private *ssi_private = dev_get_drvdata(&pdev->dev);
766 868
767 platform_device_unregister(ssi_private->pdev); 869 if (!ssi_private->new_binding)
870 platform_device_unregister(ssi_private->pdev);
871 if (ssi_private->ssi_on_imx) {
872 platform_device_unregister(ssi_private->imx_pcm_pdev);
873 clk_disable_unprepare(ssi_private->clk);
874 clk_put(ssi_private->clk);
875 }
768 snd_soc_unregister_dai(&pdev->dev); 876 snd_soc_unregister_dai(&pdev->dev);
769 device_remove_file(&pdev->dev, &ssi_private->dev_attr); 877 device_remove_file(&pdev->dev, &ssi_private->dev_attr);
770 878
@@ -779,6 +887,7 @@ static int fsl_ssi_remove(struct platform_device *pdev)
779 887
780static const struct of_device_id fsl_ssi_ids[] = { 888static const struct of_device_id fsl_ssi_ids[] = {
781 { .compatible = "fsl,mpc8610-ssi", }, 889 { .compatible = "fsl,mpc8610-ssi", },
890 { .compatible = "fsl,imx21-ssi", },
782 {} 891 {}
783}; 892};
784MODULE_DEVICE_TABLE(of, fsl_ssi_ids); 893MODULE_DEVICE_TABLE(of, fsl_ssi_ids);
diff --git a/sound/soc/fsl/fsl_utils.c b/sound/soc/fsl/fsl_utils.c
new file mode 100644
index 000000000000..b9e42b503a37
--- /dev/null
+++ b/sound/soc/fsl/fsl_utils.c
@@ -0,0 +1,91 @@
1/**
2 * Freescale ALSA SoC Machine driver utility
3 *
4 * Author: Timur Tabi <timur@freescale.com>
5 *
6 * Copyright 2010 Freescale Semiconductor, Inc.
7 *
8 * This file is licensed under the terms of the GNU General Public License
9 * version 2. This program is licensed "as is" without any warranty of any
10 * kind, whether express or implied.
11 */
12
13#include <linux/module.h>
14#include <linux/of_address.h>
15#include <sound/soc.h>
16
17#include "fsl_utils.h"
18
19/**
20 * fsl_asoc_get_dma_channel - determine the dma channel for a SSI node
21 *
22 * @ssi_np: pointer to the SSI device tree node
23 * @name: name of the phandle pointing to the dma channel
24 * @dai: ASoC DAI link pointer to be filled with platform_name
25 * @dma_channel_id: dma channel id to be returned
26 * @dma_id: dma id to be returned
27 *
28 * This function determines the dma and channel id for given SSI node. It
29 * also discovers the platform_name for the ASoC DAI link.
30 */
31int fsl_asoc_get_dma_channel(struct device_node *ssi_np,
32 const char *name,
33 struct snd_soc_dai_link *dai,
34 unsigned int *dma_channel_id,
35 unsigned int *dma_id)
36{
37 struct resource res;
38 struct device_node *dma_channel_np, *dma_np;
39 const u32 *iprop;
40 int ret;
41
42 dma_channel_np = of_parse_phandle(ssi_np, name, 0);
43 if (!dma_channel_np)
44 return -EINVAL;
45
46 if (!of_device_is_compatible(dma_channel_np, "fsl,ssi-dma-channel")) {
47 of_node_put(dma_channel_np);
48 return -EINVAL;
49 }
50
51 /* Determine the dev_name for the device_node. This code mimics the
52 * behavior of of_device_make_bus_id(). We need this because ASoC uses
53 * the dev_name() of the device to match the platform (DMA) device with
54 * the CPU (SSI) device. It's all ugly and hackish, but it works (for
55 * now).
56 *
57 * dai->platform name should already point to an allocated buffer.
58 */
59 ret = of_address_to_resource(dma_channel_np, 0, &res);
60 if (ret) {
61 of_node_put(dma_channel_np);
62 return ret;
63 }
64 snprintf((char *)dai->platform_name, DAI_NAME_SIZE, "%llx.%s",
65 (unsigned long long) res.start, dma_channel_np->name);
66
67 iprop = of_get_property(dma_channel_np, "cell-index", NULL);
68 if (!iprop) {
69 of_node_put(dma_channel_np);
70 return -EINVAL;
71 }
72 *dma_channel_id = be32_to_cpup(iprop);
73
74 dma_np = of_get_parent(dma_channel_np);
75 iprop = of_get_property(dma_np, "cell-index", NULL);
76 if (!iprop) {
77 of_node_put(dma_np);
78 return -EINVAL;
79 }
80 *dma_id = be32_to_cpup(iprop);
81
82 of_node_put(dma_np);
83 of_node_put(dma_channel_np);
84
85 return 0;
86}
87EXPORT_SYMBOL(fsl_asoc_get_dma_channel);
88
89MODULE_AUTHOR("Timur Tabi <timur@freescale.com>");
90MODULE_DESCRIPTION("Freescale ASoC utility code");
91MODULE_LICENSE("GPL v2");
diff --git a/sound/soc/fsl/fsl_utils.h b/sound/soc/fsl/fsl_utils.h
new file mode 100644
index 000000000000..b2951126527c
--- /dev/null
+++ b/sound/soc/fsl/fsl_utils.h
@@ -0,0 +1,26 @@
1/**
2 * Freescale ALSA SoC Machine driver utility
3 *
4 * Author: Timur Tabi <timur@freescale.com>
5 *
6 * Copyright 2010 Freescale Semiconductor, Inc.
7 *
8 * This file is licensed under the terms of the GNU General Public License
9 * version 2. This program is licensed "as is" without any warranty of any
10 * kind, whether express or implied.
11 */
12
13#ifndef _FSL_UTILS_H
14#define _FSL_UTILS_H
15
16#define DAI_NAME_SIZE 32
17
18struct snd_soc_dai_link;
19struct device_node;
20
21int fsl_asoc_get_dma_channel(struct device_node *ssi_np, const char *name,
22 struct snd_soc_dai_link *dai,
23 unsigned int *dma_channel_id,
24 unsigned int *dma_id);
25
26#endif /* _FSL_UTILS_H */
diff --git a/sound/soc/imx/imx-audmux.c b/sound/soc/fsl/imx-audmux.c
index 0fe66c3dde12..f23700359c67 100644
--- a/sound/soc/imx/imx-audmux.c
+++ b/sound/soc/fsl/imx-audmux.c
@@ -40,12 +40,6 @@ static void __iomem *audmux_base;
40#ifdef CONFIG_DEBUG_FS 40#ifdef CONFIG_DEBUG_FS
41static struct dentry *audmux_debugfs_root; 41static struct dentry *audmux_debugfs_root;
42 42
43static int audmux_open_file(struct inode *inode, struct file *file)
44{
45 file->private_data = inode->i_private;
46 return 0;
47}
48
49/* There is an annoying discontinuity in the SSI numbering with regard 43/* There is an annoying discontinuity in the SSI numbering with regard
50 * to the Linux number of the devices */ 44 * to the Linux number of the devices */
51static const char *audmux_port_string(int port) 45static const char *audmux_port_string(int port)
@@ -145,7 +139,7 @@ static ssize_t audmux_read_file(struct file *file, char __user *user_buf,
145} 139}
146 140
147static const struct file_operations audmux_debugfs_fops = { 141static const struct file_operations audmux_debugfs_fops = {
148 .open = audmux_open_file, 142 .open = simple_open,
149 .read = audmux_read_file, 143 .read = audmux_read_file,
150 .llseek = default_llseek, 144 .llseek = default_llseek,
151}; 145};
diff --git a/sound/soc/imx/imx-audmux.h b/sound/soc/fsl/imx-audmux.h
index 04ebbab8d7b9..04ebbab8d7b9 100644
--- a/sound/soc/imx/imx-audmux.h
+++ b/sound/soc/fsl/imx-audmux.h
diff --git a/sound/soc/fsl/imx-mc13783.c b/sound/soc/fsl/imx-mc13783.c
new file mode 100644
index 000000000000..f59c34943662
--- /dev/null
+++ b/sound/soc/fsl/imx-mc13783.c
@@ -0,0 +1,156 @@
1/*
2 * imx-mc13783.c -- SoC audio for imx based boards with mc13783 codec
3 *
4 * Copyright 2012 Philippe Retornaz, <philippe.retornaz@epfl.ch>
5 *
6 * Heavly based on phycore-mc13783:
7 * Copyright 2009 Sascha Hauer, Pengutronix <s.hauer@pengutronix.de>
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
13 *
14 */
15
16#include <linux/module.h>
17#include <linux/moduleparam.h>
18#include <linux/device.h>
19#include <sound/core.h>
20#include <sound/pcm.h>
21#include <sound/soc.h>
22#include <sound/soc-dapm.h>
23#include <asm/mach-types.h>
24
25#include "../codecs/mc13783.h"
26#include "imx-ssi.h"
27#include "imx-audmux.h"
28
29#define FMT_SSI (SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_NB_NF | \
30 SND_SOC_DAIFMT_CBM_CFM)
31
32static int imx_mc13783_hifi_hw_params(struct snd_pcm_substream *substream,
33 struct snd_pcm_hw_params *params)
34{
35 struct snd_soc_pcm_runtime *rtd = substream->private_data;
36 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
37 struct snd_soc_dai *codec_dai = rtd->codec_dai;
38 int ret;
39
40 ret = snd_soc_dai_set_tdm_slot(codec_dai, 0xfffffffc, 0xfffffffc,
41 4, 16);
42 if (ret)
43 return ret;
44
45 ret = snd_soc_dai_set_sysclk(codec_dai, MC13783_CLK_CLIA, 26000000, 0);
46 if (ret)
47 return ret;
48
49 ret = snd_soc_dai_set_tdm_slot(cpu_dai, 0x0, 0xfffffffc, 2, 16);
50 if (ret)
51 return ret;
52
53 return 0;
54}
55
56static struct snd_soc_ops imx_mc13783_hifi_ops = {
57 .hw_params = imx_mc13783_hifi_hw_params,
58};
59
60static struct snd_soc_dai_link imx_mc13783_dai_mc13783[] = {
61 {
62 .name = "MC13783",
63 .stream_name = "Sound",
64 .codec_dai_name = "mc13783-hifi",
65 .codec_name = "mc13783-codec",
66 .cpu_dai_name = "imx-ssi.0",
67 .platform_name = "imx-pcm-audio.0",
68 .ops = &imx_mc13783_hifi_ops,
69 .symmetric_rates = 1,
70 .dai_fmt = FMT_SSI,
71 },
72};
73
74static const struct snd_soc_dapm_widget imx_mc13783_widget[] = {
75 SND_SOC_DAPM_MIC("Mic", NULL),
76 SND_SOC_DAPM_HP("Headphone", NULL),
77 SND_SOC_DAPM_SPK("Speaker", NULL),
78};
79
80static const struct snd_soc_dapm_route imx_mc13783_routes[] = {
81 {"Speaker", NULL, "LSP"},
82 {"Headphone", NULL, "HSL"},
83 {"Headphone", NULL, "HSR"},
84
85 {"MC1LIN", NULL, "MC1 Bias"},
86 {"MC2IN", NULL, "MC2 Bias"},
87 {"MC1 Bias", NULL, "Mic"},
88 {"MC2 Bias", NULL, "Mic"},
89};
90
91static struct snd_soc_card imx_mc13783 = {
92 .name = "imx_mc13783",
93 .dai_link = imx_mc13783_dai_mc13783,
94 .num_links = ARRAY_SIZE(imx_mc13783_dai_mc13783),
95 .dapm_widgets = imx_mc13783_widget,
96 .num_dapm_widgets = ARRAY_SIZE(imx_mc13783_widget),
97 .dapm_routes = imx_mc13783_routes,
98 .num_dapm_routes = ARRAY_SIZE(imx_mc13783_routes),
99};
100
101static int __devinit imx_mc13783_probe(struct platform_device *pdev)
102{
103 int ret;
104
105 imx_mc13783.dev = &pdev->dev;
106
107 ret = snd_soc_register_card(&imx_mc13783);
108 if (ret) {
109 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
110 ret);
111 return ret;
112 }
113
114 imx_audmux_v2_configure_port(MX31_AUDMUX_PORT4_SSI_PINS_4,
115 IMX_AUDMUX_V2_PTCR_SYN,
116 IMX_AUDMUX_V2_PDCR_RXDSEL(MX31_AUDMUX_PORT1_SSI0) |
117 IMX_AUDMUX_V2_PDCR_MODE(1) |
118 IMX_AUDMUX_V2_PDCR_INMMASK(0xfc));
119 imx_audmux_v2_configure_port(MX31_AUDMUX_PORT1_SSI0,
120 IMX_AUDMUX_V2_PTCR_SYN |
121 IMX_AUDMUX_V2_PTCR_TFSDIR |
122 IMX_AUDMUX_V2_PTCR_TFSEL(MX31_AUDMUX_PORT4_SSI_PINS_4) |
123 IMX_AUDMUX_V2_PTCR_TCLKDIR |
124 IMX_AUDMUX_V2_PTCR_TCSEL(MX31_AUDMUX_PORT4_SSI_PINS_4) |
125 IMX_AUDMUX_V2_PTCR_RFSDIR |
126 IMX_AUDMUX_V2_PTCR_RFSEL(MX31_AUDMUX_PORT4_SSI_PINS_4) |
127 IMX_AUDMUX_V2_PTCR_RCLKDIR |
128 IMX_AUDMUX_V2_PTCR_RCSEL(MX31_AUDMUX_PORT4_SSI_PINS_4),
129 IMX_AUDMUX_V2_PDCR_RXDSEL(MX31_AUDMUX_PORT4_SSI_PINS_4));
130
131 return ret;
132}
133
134static int __devexit imx_mc13783_remove(struct platform_device *pdev)
135{
136 snd_soc_unregister_card(&imx_mc13783);
137
138 return 0;
139}
140
141static struct platform_driver imx_mc13783_audio_driver = {
142 .driver = {
143 .name = "imx_mc13783",
144 .owner = THIS_MODULE,
145 },
146 .probe = imx_mc13783_probe,
147 .remove = __devexit_p(imx_mc13783_remove)
148};
149
150module_platform_driver(imx_mc13783_audio_driver);
151
152MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de>");
153MODULE_AUTHOR("Philippe Retornaz <philippe.retornaz@epfl.ch");
154MODULE_DESCRIPTION("imx with mc13783 codec ALSA SoC driver");
155MODULE_LICENSE("GPL");
156MODULE_ALIAS("platform:imx_mc13783");
diff --git a/sound/soc/imx/imx-pcm-dma-mx2.c b/sound/soc/fsl/imx-pcm-dma.c
index 6b818de2fc03..f3c0a5ef35c8 100644
--- a/sound/soc/imx/imx-pcm-dma-mx2.c
+++ b/sound/soc/fsl/imx-pcm-dma.c
@@ -109,7 +109,8 @@ static int snd_imx_open(struct snd_pcm_substream *substream)
109 dma_params = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream); 109 dma_params = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
110 110
111 dma_data = kzalloc(sizeof(*dma_data), GFP_KERNEL); 111 dma_data = kzalloc(sizeof(*dma_data), GFP_KERNEL);
112 dma_data->peripheral_type = IMX_DMATYPE_SSI; 112 dma_data->peripheral_type = dma_params->shared_peripheral ?
113 IMX_DMATYPE_SSI_SP : IMX_DMATYPE_SSI;
113 dma_data->priority = DMA_PRIO_HIGH; 114 dma_data->priority = DMA_PRIO_HIGH;
114 dma_data->dma_request = dma_params->dma; 115 dma_data->dma_request = dma_params->dma;
115 116
diff --git a/sound/soc/imx/imx-pcm-fiq.c b/sound/soc/fsl/imx-pcm-fiq.c
index 456b7d723d66..456b7d723d66 100644
--- a/sound/soc/imx/imx-pcm-fiq.c
+++ b/sound/soc/fsl/imx-pcm-fiq.c
diff --git a/sound/soc/imx/imx-pcm.c b/sound/soc/fsl/imx-pcm.c
index 93dc360b1777..93dc360b1777 100644
--- a/sound/soc/imx/imx-pcm.c
+++ b/sound/soc/fsl/imx-pcm.c
diff --git a/sound/soc/imx/imx-pcm.h b/sound/soc/fsl/imx-pcm.h
index b5f5c3acf34d..83c0ed7d55c9 100644
--- a/sound/soc/imx/imx-pcm.h
+++ b/sound/soc/fsl/imx-pcm.h
@@ -22,6 +22,7 @@ struct imx_pcm_dma_params {
22 int dma; 22 int dma;
23 unsigned long dma_addr; 23 unsigned long dma_addr;
24 int burstsize; 24 int burstsize;
25 bool shared_peripheral; /* The peripheral is on SPBA bus */
25}; 26};
26 27
27int snd_imx_pcm_mmap(struct snd_pcm_substream *substream, 28int snd_imx_pcm_mmap(struct snd_pcm_substream *substream,
diff --git a/sound/soc/fsl/imx-sgtl5000.c b/sound/soc/fsl/imx-sgtl5000.c
new file mode 100644
index 000000000000..3a729caeb8c8
--- /dev/null
+++ b/sound/soc/fsl/imx-sgtl5000.c
@@ -0,0 +1,221 @@
1/*
2 * Copyright 2012 Freescale Semiconductor, Inc.
3 * Copyright 2012 Linaro Ltd.
4 *
5 * The code contained herein is licensed under the GNU General Public
6 * License. You may obtain a copy of the GNU General Public License
7 * Version 2 or later at the following locations:
8 *
9 * http://www.opensource.org/licenses/gpl-license.html
10 * http://www.gnu.org/copyleft/gpl.html
11 */
12
13#include <linux/module.h>
14#include <linux/of.h>
15#include <linux/of_platform.h>
16#include <linux/of_i2c.h>
17#include <linux/clk.h>
18#include <sound/soc.h>
19
20#include "../codecs/sgtl5000.h"
21#include "imx-audmux.h"
22
23#define DAI_NAME_SIZE 32
24
25struct imx_sgtl5000_data {
26 struct snd_soc_dai_link dai;
27 struct snd_soc_card card;
28 char codec_dai_name[DAI_NAME_SIZE];
29 char platform_name[DAI_NAME_SIZE];
30 struct clk *codec_clk;
31 unsigned int clk_frequency;
32};
33
34static int imx_sgtl5000_dai_init(struct snd_soc_pcm_runtime *rtd)
35{
36 struct imx_sgtl5000_data *data = container_of(rtd->card,
37 struct imx_sgtl5000_data, card);
38 struct device *dev = rtd->card->dev;
39 int ret;
40
41 ret = snd_soc_dai_set_sysclk(rtd->codec_dai, SGTL5000_SYSCLK,
42 data->clk_frequency, SND_SOC_CLOCK_IN);
43 if (ret) {
44 dev_err(dev, "could not set codec driver clock params\n");
45 return ret;
46 }
47
48 return 0;
49}
50
51static const struct snd_soc_dapm_widget imx_sgtl5000_dapm_widgets[] = {
52 SND_SOC_DAPM_MIC("Mic Jack", NULL),
53 SND_SOC_DAPM_LINE("Line In Jack", NULL),
54 SND_SOC_DAPM_HP("Headphone Jack", NULL),
55 SND_SOC_DAPM_SPK("Line Out Jack", NULL),
56 SND_SOC_DAPM_SPK("Ext Spk", NULL),
57};
58
59static int __devinit imx_sgtl5000_probe(struct platform_device *pdev)
60{
61 struct device_node *np = pdev->dev.of_node;
62 struct device_node *ssi_np, *codec_np;
63 struct platform_device *ssi_pdev;
64 struct i2c_client *codec_dev;
65 struct imx_sgtl5000_data *data;
66 int int_port, ext_port;
67 int ret;
68
69 ret = of_property_read_u32(np, "mux-int-port", &int_port);
70 if (ret) {
71 dev_err(&pdev->dev, "mux-int-port missing or invalid\n");
72 return ret;
73 }
74 ret = of_property_read_u32(np, "mux-ext-port", &ext_port);
75 if (ret) {
76 dev_err(&pdev->dev, "mux-ext-port missing or invalid\n");
77 return ret;
78 }
79
80 /*
81 * The port numbering in the hardware manual starts at 1, while
82 * the audmux API expects it starts at 0.
83 */
84 int_port--;
85 ext_port--;
86 ret = imx_audmux_v2_configure_port(int_port,
87 IMX_AUDMUX_V2_PTCR_SYN |
88 IMX_AUDMUX_V2_PTCR_TFSEL(ext_port) |
89 IMX_AUDMUX_V2_PTCR_TCSEL(ext_port) |
90 IMX_AUDMUX_V2_PTCR_TFSDIR |
91 IMX_AUDMUX_V2_PTCR_TCLKDIR,
92 IMX_AUDMUX_V2_PDCR_RXDSEL(ext_port));
93 if (ret) {
94 dev_err(&pdev->dev, "audmux internal port setup failed\n");
95 return ret;
96 }
97 imx_audmux_v2_configure_port(ext_port,
98 IMX_AUDMUX_V2_PTCR_SYN |
99 IMX_AUDMUX_V2_PTCR_TCSEL(int_port),
100 IMX_AUDMUX_V2_PDCR_RXDSEL(int_port));
101 if (ret) {
102 dev_err(&pdev->dev, "audmux external port setup failed\n");
103 return ret;
104 }
105
106 ssi_np = of_parse_phandle(pdev->dev.of_node, "ssi-controller", 0);
107 codec_np = of_parse_phandle(pdev->dev.of_node, "audio-codec", 0);
108 if (!ssi_np || !codec_np) {
109 dev_err(&pdev->dev, "phandle missing or invalid\n");
110 ret = -EINVAL;
111 goto fail;
112 }
113
114 ssi_pdev = of_find_device_by_node(ssi_np);
115 if (!ssi_pdev) {
116 dev_err(&pdev->dev, "failed to find SSI platform device\n");
117 ret = -EINVAL;
118 goto fail;
119 }
120 codec_dev = of_find_i2c_device_by_node(codec_np);
121 if (!codec_dev) {
122 dev_err(&pdev->dev, "failed to find codec platform device\n");
123 return -EINVAL;
124 }
125
126 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
127 if (!data) {
128 ret = -ENOMEM;
129 goto fail;
130 }
131
132 data->codec_clk = clk_get(&codec_dev->dev, NULL);
133 if (IS_ERR(data->codec_clk)) {
134 /* assuming clock enabled by default */
135 data->codec_clk = NULL;
136 ret = of_property_read_u32(codec_np, "clock-frequency",
137 &data->clk_frequency);
138 if (ret) {
139 dev_err(&codec_dev->dev,
140 "clock-frequency missing or invalid\n");
141 goto fail;
142 }
143 } else {
144 data->clk_frequency = clk_get_rate(data->codec_clk);
145 clk_prepare_enable(data->codec_clk);
146 }
147
148 data->dai.name = "HiFi";
149 data->dai.stream_name = "HiFi";
150 data->dai.codec_dai_name = "sgtl5000";
151 data->dai.codec_of_node = codec_np;
152 data->dai.cpu_dai_name = dev_name(&ssi_pdev->dev);
153 data->dai.platform_name = "imx-pcm-audio";
154 data->dai.init = &imx_sgtl5000_dai_init;
155 data->dai.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
156 SND_SOC_DAIFMT_CBM_CFM;
157
158 data->card.dev = &pdev->dev;
159 ret = snd_soc_of_parse_card_name(&data->card, "model");
160 if (ret)
161 goto clk_fail;
162 ret = snd_soc_of_parse_audio_routing(&data->card, "audio-routing");
163 if (ret)
164 goto clk_fail;
165 data->card.num_links = 1;
166 data->card.dai_link = &data->dai;
167 data->card.dapm_widgets = imx_sgtl5000_dapm_widgets;
168 data->card.num_dapm_widgets = ARRAY_SIZE(imx_sgtl5000_dapm_widgets);
169
170 ret = snd_soc_register_card(&data->card);
171 if (ret) {
172 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
173 goto clk_fail;
174 }
175
176 platform_set_drvdata(pdev, data);
177clk_fail:
178 clk_put(data->codec_clk);
179fail:
180 if (ssi_np)
181 of_node_put(ssi_np);
182 if (codec_np)
183 of_node_put(codec_np);
184
185 return ret;
186}
187
188static int __devexit imx_sgtl5000_remove(struct platform_device *pdev)
189{
190 struct imx_sgtl5000_data *data = platform_get_drvdata(pdev);
191
192 if (data->codec_clk) {
193 clk_disable_unprepare(data->codec_clk);
194 clk_put(data->codec_clk);
195 }
196 snd_soc_unregister_card(&data->card);
197
198 return 0;
199}
200
201static const struct of_device_id imx_sgtl5000_dt_ids[] = {
202 { .compatible = "fsl,imx-audio-sgtl5000", },
203 { /* sentinel */ }
204};
205MODULE_DEVICE_TABLE(of, imx_sgtl5000_dt_ids);
206
207static struct platform_driver imx_sgtl5000_driver = {
208 .driver = {
209 .name = "imx-sgtl5000",
210 .owner = THIS_MODULE,
211 .of_match_table = imx_sgtl5000_dt_ids,
212 },
213 .probe = imx_sgtl5000_probe,
214 .remove = __devexit_p(imx_sgtl5000_remove),
215};
216module_platform_driver(imx_sgtl5000_driver);
217
218MODULE_AUTHOR("Shawn Guo <shawn.guo@linaro.org>");
219MODULE_DESCRIPTION("Freescale i.MX SGTL5000 ASoC machine driver");
220MODULE_LICENSE("GPL v2");
221MODULE_ALIAS("platform:imx-sgtl5000");
diff --git a/sound/soc/imx/imx-ssi.c b/sound/soc/fsl/imx-ssi.c
index 4f81ed456325..cf3ed0362c9c 100644
--- a/sound/soc/imx/imx-ssi.c
+++ b/sound/soc/fsl/imx-ssi.c
@@ -28,7 +28,7 @@
28 * value. When we read the same register two times (and the register still 28 * value. When we read the same register two times (and the register still
29 * contains the same value) these status bits are not set. We work 29 * contains the same value) these status bits are not set. We work
30 * around this by not polling these bits but only wait a fixed delay. 30 * around this by not polling these bits but only wait a fixed delay.
31 * 31 *
32 */ 32 */
33 33
34#include <linux/clk.h> 34#include <linux/clk.h>
diff --git a/sound/soc/imx/imx-ssi.h b/sound/soc/fsl/imx-ssi.h
index 5744e86ca878..5744e86ca878 100644
--- a/sound/soc/imx/imx-ssi.h
+++ b/sound/soc/fsl/imx-ssi.h
diff --git a/sound/soc/fsl/mpc8610_hpcd.c b/sound/soc/fsl/mpc8610_hpcd.c
index afbabf427f27..60bcba1bc30e 100644
--- a/sound/soc/fsl/mpc8610_hpcd.c
+++ b/sound/soc/fsl/mpc8610_hpcd.c
@@ -14,18 +14,16 @@
14#include <linux/interrupt.h> 14#include <linux/interrupt.h>
15#include <linux/of_device.h> 15#include <linux/of_device.h>
16#include <linux/slab.h> 16#include <linux/slab.h>
17#include <linux/of_i2c.h>
18#include <sound/soc.h> 17#include <sound/soc.h>
19#include <asm/fsl_guts.h> 18#include <asm/fsl_guts.h>
20 19
21#include "fsl_dma.h" 20#include "fsl_dma.h"
22#include "fsl_ssi.h" 21#include "fsl_ssi.h"
22#include "fsl_utils.h"
23 23
24/* There's only one global utilities register */ 24/* There's only one global utilities register */
25static phys_addr_t guts_phys; 25static phys_addr_t guts_phys;
26 26
27#define DAI_NAME_SIZE 32
28
29/** 27/**
30 * mpc8610_hpcd_data: machine-specific ASoC device data 28 * mpc8610_hpcd_data: machine-specific ASoC device data
31 * 29 *
@@ -43,7 +41,6 @@ struct mpc8610_hpcd_data {
43 unsigned int dma_id[2]; /* 0 = DMA1, 1 = DMA2, etc */ 41 unsigned int dma_id[2]; /* 0 = DMA1, 1 = DMA2, etc */
44 unsigned int dma_channel_id[2]; /* 0 = ch 0, 1 = ch 1, etc*/ 42 unsigned int dma_channel_id[2]; /* 0 = ch 0, 1 = ch 1, etc*/
45 char codec_dai_name[DAI_NAME_SIZE]; 43 char codec_dai_name[DAI_NAME_SIZE];
46 char codec_name[DAI_NAME_SIZE];
47 char platform_name[2][DAI_NAME_SIZE]; /* One for each DMA channel */ 44 char platform_name[2][DAI_NAME_SIZE]; /* One for each DMA channel */
48}; 45};
49 46
@@ -58,9 +55,9 @@ static int mpc8610_hpcd_machine_probe(struct snd_soc_card *card)
58{ 55{
59 struct mpc8610_hpcd_data *machine_data = 56 struct mpc8610_hpcd_data *machine_data =
60 container_of(card, struct mpc8610_hpcd_data, card); 57 container_of(card, struct mpc8610_hpcd_data, card);
61 struct ccsr_guts_86xx __iomem *guts; 58 struct ccsr_guts __iomem *guts;
62 59
63 guts = ioremap(guts_phys, sizeof(struct ccsr_guts_86xx)); 60 guts = ioremap(guts_phys, sizeof(struct ccsr_guts));
64 if (!guts) { 61 if (!guts) {
65 dev_err(card->dev, "could not map global utilities\n"); 62 dev_err(card->dev, "could not map global utilities\n");
66 return -ENOMEM; 63 return -ENOMEM;
@@ -142,9 +139,9 @@ static int mpc8610_hpcd_machine_remove(struct snd_soc_card *card)
142{ 139{
143 struct mpc8610_hpcd_data *machine_data = 140 struct mpc8610_hpcd_data *machine_data =
144 container_of(card, struct mpc8610_hpcd_data, card); 141 container_of(card, struct mpc8610_hpcd_data, card);
145 struct ccsr_guts_86xx __iomem *guts; 142 struct ccsr_guts __iomem *guts;
146 143
147 guts = ioremap(guts_phys, sizeof(struct ccsr_guts_86xx)); 144 guts = ioremap(guts_phys, sizeof(struct ccsr_guts));
148 if (!guts) { 145 if (!guts) {
149 dev_err(card->dev, "could not map global utilities\n"); 146 dev_err(card->dev, "could not map global utilities\n");
150 return -ENOMEM; 147 return -ENOMEM;
@@ -181,141 +178,6 @@ static struct snd_soc_ops mpc8610_hpcd_ops = {
181}; 178};
182 179
183/** 180/**
184 * get_node_by_phandle_name - get a node by its phandle name
185 *
186 * This function takes a node, the name of a property in that node, and a
187 * compatible string. Assuming the property is a phandle to another node,
188 * it returns that node, (optionally) if that node is compatible.
189 *
190 * If the property is not a phandle, or the node it points to is not compatible
191 * with the specific string, then NULL is returned.
192 */
193static struct device_node *get_node_by_phandle_name(struct device_node *np,
194 const char *name,
195 const char *compatible)
196{
197 const phandle *ph;
198 int len;
199
200 ph = of_get_property(np, name, &len);
201 if (!ph || (len != sizeof(phandle)))
202 return NULL;
203
204 np = of_find_node_by_phandle(*ph);
205 if (!np)
206 return NULL;
207
208 if (compatible && !of_device_is_compatible(np, compatible)) {
209 of_node_put(np);
210 return NULL;
211 }
212
213 return np;
214}
215
216/**
217 * get_parent_cell_index -- return the cell-index of the parent of a node
218 *
219 * Return the value of the cell-index property of the parent of the given
220 * node. This is used for DMA channel nodes that need to know the DMA ID
221 * of the controller they are on.
222 */
223static int get_parent_cell_index(struct device_node *np)
224{
225 struct device_node *parent = of_get_parent(np);
226 const u32 *iprop;
227
228 if (!parent)
229 return -1;
230
231 iprop = of_get_property(parent, "cell-index", NULL);
232 of_node_put(parent);
233
234 if (!iprop)
235 return -1;
236
237 return be32_to_cpup(iprop);
238}
239
240/**
241 * codec_node_dev_name - determine the dev_name for a codec node
242 *
243 * This function determines the dev_name for an I2C node. This is the name
244 * that would be returned by dev_name() if this device_node were part of a
245 * 'struct device' It's ugly and hackish, but it works.
246 *
247 * The dev_name for such devices include the bus number and I2C address. For
248 * example, "cs4270.0-004f".
249 */
250static int codec_node_dev_name(struct device_node *np, char *buf, size_t len)
251{
252 const u32 *iprop;
253 int addr;
254 char temp[DAI_NAME_SIZE];
255 struct i2c_client *i2c;
256
257 of_modalias_node(np, temp, DAI_NAME_SIZE);
258
259 iprop = of_get_property(np, "reg", NULL);
260 if (!iprop)
261 return -EINVAL;
262
263 addr = be32_to_cpup(iprop);
264
265 /* We need the adapter number */
266 i2c = of_find_i2c_device_by_node(np);
267 if (!i2c)
268 return -ENODEV;
269
270 snprintf(buf, len, "%s.%u-%04x", temp, i2c->adapter->nr, addr);
271
272 return 0;
273}
274
275static int get_dma_channel(struct device_node *ssi_np,
276 const char *name,
277 struct snd_soc_dai_link *dai,
278 unsigned int *dma_channel_id,
279 unsigned int *dma_id)
280{
281 struct resource res;
282 struct device_node *dma_channel_np;
283 const u32 *iprop;
284 int ret;
285
286 dma_channel_np = get_node_by_phandle_name(ssi_np, name,
287 "fsl,ssi-dma-channel");
288 if (!dma_channel_np)
289 return -EINVAL;
290
291 /* Determine the dev_name for the device_node. This code mimics the
292 * behavior of of_device_make_bus_id(). We need this because ASoC uses
293 * the dev_name() of the device to match the platform (DMA) device with
294 * the CPU (SSI) device. It's all ugly and hackish, but it works (for
295 * now).
296 *
297 * dai->platform name should already point to an allocated buffer.
298 */
299 ret = of_address_to_resource(dma_channel_np, 0, &res);
300 if (ret)
301 return ret;
302 snprintf((char *)dai->platform_name, DAI_NAME_SIZE, "%llx.%s",
303 (unsigned long long) res.start, dma_channel_np->name);
304
305 iprop = of_get_property(dma_channel_np, "cell-index", NULL);
306 if (!iprop) {
307 of_node_put(dma_channel_np);
308 return -EINVAL;
309 }
310
311 *dma_channel_id = be32_to_cpup(iprop);
312 *dma_id = get_parent_cell_index(dma_channel_np);
313 of_node_put(dma_channel_np);
314
315 return 0;
316}
317
318/**
319 * mpc8610_hpcd_probe: platform probe function for the machine driver 181 * mpc8610_hpcd_probe: platform probe function for the machine driver
320 * 182 *
321 * Although this is a machine driver, the SSI node is the "master" node with 183 * Although this is a machine driver, the SSI node is the "master" node with
@@ -352,16 +214,8 @@ static int mpc8610_hpcd_probe(struct platform_device *pdev)
352 machine_data->dai[0].cpu_dai_name = dev_name(&ssi_pdev->dev); 214 machine_data->dai[0].cpu_dai_name = dev_name(&ssi_pdev->dev);
353 machine_data->dai[0].ops = &mpc8610_hpcd_ops; 215 machine_data->dai[0].ops = &mpc8610_hpcd_ops;
354 216
355 /* Determine the codec name, it will be used as the codec DAI name */ 217 /* ASoC core can match codec with device node */
356 ret = codec_node_dev_name(codec_np, machine_data->codec_name, 218 machine_data->dai[0].codec_of_node = codec_np;
357 DAI_NAME_SIZE);
358 if (ret) {
359 dev_err(&pdev->dev, "invalid codec node %s\n",
360 codec_np->full_name);
361 ret = -EINVAL;
362 goto error;
363 }
364 machine_data->dai[0].codec_name = machine_data->codec_name;
365 219
366 /* The DAI name from the codec (snd_soc_dai_driver.name) */ 220 /* The DAI name from the codec (snd_soc_dai_driver.name) */
367 machine_data->dai[0].codec_dai_name = "cs4270-hifi"; 221 machine_data->dai[0].codec_dai_name = "cs4270-hifi";
@@ -458,9 +312,10 @@ static int mpc8610_hpcd_probe(struct platform_device *pdev)
458 312
459 /* Find the playback DMA channel to use. */ 313 /* Find the playback DMA channel to use. */
460 machine_data->dai[0].platform_name = machine_data->platform_name[0]; 314 machine_data->dai[0].platform_name = machine_data->platform_name[0];
461 ret = get_dma_channel(np, "fsl,playback-dma", &machine_data->dai[0], 315 ret = fsl_asoc_get_dma_channel(np, "fsl,playback-dma",
462 &machine_data->dma_channel_id[0], 316 &machine_data->dai[0],
463 &machine_data->dma_id[0]); 317 &machine_data->dma_channel_id[0],
318 &machine_data->dma_id[0]);
464 if (ret) { 319 if (ret) {
465 dev_err(&pdev->dev, "missing/invalid playback DMA phandle\n"); 320 dev_err(&pdev->dev, "missing/invalid playback DMA phandle\n");
466 goto error; 321 goto error;
@@ -468,9 +323,10 @@ static int mpc8610_hpcd_probe(struct platform_device *pdev)
468 323
469 /* Find the capture DMA channel to use. */ 324 /* Find the capture DMA channel to use. */
470 machine_data->dai[1].platform_name = machine_data->platform_name[1]; 325 machine_data->dai[1].platform_name = machine_data->platform_name[1];
471 ret = get_dma_channel(np, "fsl,capture-dma", &machine_data->dai[1], 326 ret = fsl_asoc_get_dma_channel(np, "fsl,capture-dma",
472 &machine_data->dma_channel_id[1], 327 &machine_data->dai[1],
473 &machine_data->dma_id[1]); 328 &machine_data->dma_channel_id[1],
329 &machine_data->dma_id[1]);
474 if (ret) { 330 if (ret) {
475 dev_err(&pdev->dev, "missing/invalid capture DMA phandle\n"); 331 dev_err(&pdev->dev, "missing/invalid capture DMA phandle\n");
476 goto error; 332 goto error;
diff --git a/sound/soc/imx/mx27vis-aic32x4.c b/sound/soc/fsl/mx27vis-aic32x4.c
index f6d04ad4bb39..f6d04ad4bb39 100644
--- a/sound/soc/imx/mx27vis-aic32x4.c
+++ b/sound/soc/fsl/mx27vis-aic32x4.c
diff --git a/sound/soc/fsl/p1022_ds.c b/sound/soc/fsl/p1022_ds.c
index 46623405a2ce..50adf4032bcc 100644
--- a/sound/soc/fsl/p1022_ds.c
+++ b/sound/soc/fsl/p1022_ds.c
@@ -14,12 +14,12 @@
14#include <linux/interrupt.h> 14#include <linux/interrupt.h>
15#include <linux/of_device.h> 15#include <linux/of_device.h>
16#include <linux/slab.h> 16#include <linux/slab.h>
17#include <linux/of_i2c.h>
18#include <sound/soc.h> 17#include <sound/soc.h>
19#include <asm/fsl_guts.h> 18#include <asm/fsl_guts.h>
20 19
21#include "fsl_dma.h" 20#include "fsl_dma.h"
22#include "fsl_ssi.h" 21#include "fsl_ssi.h"
22#include "fsl_utils.h"
23 23
24/* P1022-specific PMUXCR and DMUXCR bit definitions */ 24/* P1022-specific PMUXCR and DMUXCR bit definitions */
25 25
@@ -46,7 +46,7 @@
46 * ch: The channel on the DMA controller (0, 1, 2, or 3) 46 * ch: The channel on the DMA controller (0, 1, 2, or 3)
47 * device: The device to set as the target (CCSR_GUTS_DMUXCR_xxx) 47 * device: The device to set as the target (CCSR_GUTS_DMUXCR_xxx)
48 */ 48 */
49static inline void guts_set_dmuxcr(struct ccsr_guts_85xx __iomem *guts, 49static inline void guts_set_dmuxcr(struct ccsr_guts __iomem *guts,
50 unsigned int co, unsigned int ch, unsigned int device) 50 unsigned int co, unsigned int ch, unsigned int device)
51{ 51{
52 unsigned int shift = 16 + (8 * (1 - co) + 2 * (3 - ch)); 52 unsigned int shift = 16 + (8 * (1 - co) + 2 * (3 - ch));
@@ -57,8 +57,6 @@ static inline void guts_set_dmuxcr(struct ccsr_guts_85xx __iomem *guts,
57/* There's only one global utilities register */ 57/* There's only one global utilities register */
58static phys_addr_t guts_phys; 58static phys_addr_t guts_phys;
59 59
60#define DAI_NAME_SIZE 32
61
62/** 60/**
63 * machine_data: machine-specific ASoC device data 61 * machine_data: machine-specific ASoC device data
64 * 62 *
@@ -75,7 +73,6 @@ struct machine_data {
75 unsigned int ssi_id; /* 0 = SSI1, 1 = SSI2, etc */ 73 unsigned int ssi_id; /* 0 = SSI1, 1 = SSI2, etc */
76 unsigned int dma_id[2]; /* 0 = DMA1, 1 = DMA2, etc */ 74 unsigned int dma_id[2]; /* 0 = DMA1, 1 = DMA2, etc */
77 unsigned int dma_channel_id[2]; /* 0 = ch 0, 1 = ch 1, etc*/ 75 unsigned int dma_channel_id[2]; /* 0 = ch 0, 1 = ch 1, etc*/
78 char codec_name[DAI_NAME_SIZE];
79 char platform_name[2][DAI_NAME_SIZE]; /* One for each DMA channel */ 76 char platform_name[2][DAI_NAME_SIZE]; /* One for each DMA channel */
80}; 77};
81 78
@@ -90,9 +87,9 @@ static int p1022_ds_machine_probe(struct snd_soc_card *card)
90{ 87{
91 struct machine_data *mdata = 88 struct machine_data *mdata =
92 container_of(card, struct machine_data, card); 89 container_of(card, struct machine_data, card);
93 struct ccsr_guts_85xx __iomem *guts; 90 struct ccsr_guts __iomem *guts;
94 91
95 guts = ioremap(guts_phys, sizeof(struct ccsr_guts_85xx)); 92 guts = ioremap(guts_phys, sizeof(struct ccsr_guts));
96 if (!guts) { 93 if (!guts) {
97 dev_err(card->dev, "could not map global utilities\n"); 94 dev_err(card->dev, "could not map global utilities\n");
98 return -ENOMEM; 95 return -ENOMEM;
@@ -164,9 +161,9 @@ static int p1022_ds_machine_remove(struct snd_soc_card *card)
164{ 161{
165 struct machine_data *mdata = 162 struct machine_data *mdata =
166 container_of(card, struct machine_data, card); 163 container_of(card, struct machine_data, card);
167 struct ccsr_guts_85xx __iomem *guts; 164 struct ccsr_guts __iomem *guts;
168 165
169 guts = ioremap(guts_phys, sizeof(struct ccsr_guts_85xx)); 166 guts = ioremap(guts_phys, sizeof(struct ccsr_guts));
170 if (!guts) { 167 if (!guts) {
171 dev_err(card->dev, "could not map global utilities\n"); 168 dev_err(card->dev, "could not map global utilities\n");
172 return -ENOMEM; 169 return -ENOMEM;
@@ -191,136 +188,6 @@ static struct snd_soc_ops p1022_ds_ops = {
191}; 188};
192 189
193/** 190/**
194 * get_node_by_phandle_name - get a node by its phandle name
195 *
196 * This function takes a node, the name of a property in that node, and a
197 * compatible string. Assuming the property is a phandle to another node,
198 * it returns that node, (optionally) if that node is compatible.
199 *
200 * If the property is not a phandle, or the node it points to is not compatible
201 * with the specific string, then NULL is returned.
202 */
203static struct device_node *get_node_by_phandle_name(struct device_node *np,
204 const char *name, const char *compatible)
205{
206 np = of_parse_phandle(np, name, 0);
207 if (!np)
208 return NULL;
209
210 if (!of_device_is_compatible(np, compatible)) {
211 of_node_put(np);
212 return NULL;
213 }
214
215 return np;
216}
217
218/**
219 * get_parent_cell_index -- return the cell-index of the parent of a node
220 *
221 * Return the value of the cell-index property of the parent of the given
222 * node. This is used for DMA channel nodes that need to know the DMA ID
223 * of the controller they are on.
224 */
225static int get_parent_cell_index(struct device_node *np)
226{
227 struct device_node *parent = of_get_parent(np);
228 const u32 *iprop;
229 int ret = -1;
230
231 if (!parent)
232 return -1;
233
234 iprop = of_get_property(parent, "cell-index", NULL);
235 if (iprop)
236 ret = be32_to_cpup(iprop);
237
238 of_node_put(parent);
239
240 return ret;
241}
242
243/**
244 * codec_node_dev_name - determine the dev_name for a codec node
245 *
246 * This function determines the dev_name for an I2C node. This is the name
247 * that would be returned by dev_name() if this device_node were part of a
248 * 'struct device' It's ugly and hackish, but it works.
249 *
250 * The dev_name for such devices include the bus number and I2C address. For
251 * example, "cs4270-codec.0-004f".
252 */
253static int codec_node_dev_name(struct device_node *np, char *buf, size_t len)
254{
255 const u32 *iprop;
256 int addr;
257 char temp[DAI_NAME_SIZE];
258 struct i2c_client *i2c;
259
260 of_modalias_node(np, temp, DAI_NAME_SIZE);
261
262 iprop = of_get_property(np, "reg", NULL);
263 if (!iprop)
264 return -EINVAL;
265
266 addr = be32_to_cpup(iprop);
267
268 /* We need the adapter number */
269 i2c = of_find_i2c_device_by_node(np);
270 if (!i2c)
271 return -ENODEV;
272
273 snprintf(buf, len, "%s.%u-%04x", temp, i2c->adapter->nr, addr);
274
275 return 0;
276}
277
278static int get_dma_channel(struct device_node *ssi_np,
279 const char *name,
280 struct snd_soc_dai_link *dai,
281 unsigned int *dma_channel_id,
282 unsigned int *dma_id)
283{
284 struct resource res;
285 struct device_node *dma_channel_np;
286 const u32 *iprop;
287 int ret;
288
289 dma_channel_np = get_node_by_phandle_name(ssi_np, name,
290 "fsl,ssi-dma-channel");
291 if (!dma_channel_np)
292 return -EINVAL;
293
294 /* Determine the dev_name for the device_node. This code mimics the
295 * behavior of of_device_make_bus_id(). We need this because ASoC uses
296 * the dev_name() of the device to match the platform (DMA) device with
297 * the CPU (SSI) device. It's all ugly and hackish, but it works (for
298 * now).
299 *
300 * dai->platform name should already point to an allocated buffer.
301 */
302 ret = of_address_to_resource(dma_channel_np, 0, &res);
303 if (ret) {
304 of_node_put(dma_channel_np);
305 return ret;
306 }
307 snprintf((char *)dai->platform_name, DAI_NAME_SIZE, "%llx.%s",
308 (unsigned long long) res.start, dma_channel_np->name);
309
310 iprop = of_get_property(dma_channel_np, "cell-index", NULL);
311 if (!iprop) {
312 of_node_put(dma_channel_np);
313 return -EINVAL;
314 }
315
316 *dma_channel_id = be32_to_cpup(iprop);
317 *dma_id = get_parent_cell_index(dma_channel_np);
318 of_node_put(dma_channel_np);
319
320 return 0;
321}
322
323/**
324 * p1022_ds_probe: platform probe function for the machine driver 191 * p1022_ds_probe: platform probe function for the machine driver
325 * 192 *
326 * Although this is a machine driver, the SSI node is the "master" node with 193 * Although this is a machine driver, the SSI node is the "master" node with
@@ -357,15 +224,8 @@ static int p1022_ds_probe(struct platform_device *pdev)
357 mdata->dai[0].cpu_dai_name = dev_name(&ssi_pdev->dev); 224 mdata->dai[0].cpu_dai_name = dev_name(&ssi_pdev->dev);
358 mdata->dai[0].ops = &p1022_ds_ops; 225 mdata->dai[0].ops = &p1022_ds_ops;
359 226
360 /* Determine the codec name, it will be used as the codec DAI name */ 227 /* ASoC core can match codec with device node */
361 ret = codec_node_dev_name(codec_np, mdata->codec_name, DAI_NAME_SIZE); 228 mdata->dai[0].codec_of_node = codec_np;
362 if (ret) {
363 dev_err(&pdev->dev, "invalid codec node %s\n",
364 codec_np->full_name);
365 ret = -EINVAL;
366 goto error;
367 }
368 mdata->dai[0].codec_name = mdata->codec_name;
369 229
370 /* We register two DAIs per SSI, one for playback and the other for 230 /* We register two DAIs per SSI, one for playback and the other for
371 * capture. We support codecs that have separate DAIs for both playback 231 * capture. We support codecs that have separate DAIs for both playback
@@ -462,9 +322,9 @@ static int p1022_ds_probe(struct platform_device *pdev)
462 322
463 /* Find the playback DMA channel to use. */ 323 /* Find the playback DMA channel to use. */
464 mdata->dai[0].platform_name = mdata->platform_name[0]; 324 mdata->dai[0].platform_name = mdata->platform_name[0];
465 ret = get_dma_channel(np, "fsl,playback-dma", &mdata->dai[0], 325 ret = fsl_asoc_get_dma_channel(np, "fsl,playback-dma", &mdata->dai[0],
466 &mdata->dma_channel_id[0], 326 &mdata->dma_channel_id[0],
467 &mdata->dma_id[0]); 327 &mdata->dma_id[0]);
468 if (ret) { 328 if (ret) {
469 dev_err(&pdev->dev, "missing/invalid playback DMA phandle\n"); 329 dev_err(&pdev->dev, "missing/invalid playback DMA phandle\n");
470 goto error; 330 goto error;
@@ -472,9 +332,9 @@ static int p1022_ds_probe(struct platform_device *pdev)
472 332
473 /* Find the capture DMA channel to use. */ 333 /* Find the capture DMA channel to use. */
474 mdata->dai[1].platform_name = mdata->platform_name[1]; 334 mdata->dai[1].platform_name = mdata->platform_name[1];
475 ret = get_dma_channel(np, "fsl,capture-dma", &mdata->dai[1], 335 ret = fsl_asoc_get_dma_channel(np, "fsl,capture-dma", &mdata->dai[1],
476 &mdata->dma_channel_id[1], 336 &mdata->dma_channel_id[1],
477 &mdata->dma_id[1]); 337 &mdata->dma_id[1]);
478 if (ret) { 338 if (ret) {
479 dev_err(&pdev->dev, "missing/invalid capture DMA phandle\n"); 339 dev_err(&pdev->dev, "missing/invalid capture DMA phandle\n");
480 goto error; 340 goto error;
diff --git a/sound/soc/imx/phycore-ac97.c b/sound/soc/fsl/phycore-ac97.c
index f8da6dd115ed..f8da6dd115ed 100644
--- a/sound/soc/imx/phycore-ac97.c
+++ b/sound/soc/fsl/phycore-ac97.c
diff --git a/sound/soc/imx/wm1133-ev1.c b/sound/soc/fsl/wm1133-ev1.c
index fe54a69073e5..fe54a69073e5 100644
--- a/sound/soc/imx/wm1133-ev1.c
+++ b/sound/soc/fsl/wm1133-ev1.c
diff --git a/sound/soc/generic/Kconfig b/sound/soc/generic/Kconfig
new file mode 100644
index 000000000000..610f61251640
--- /dev/null
+++ b/sound/soc/generic/Kconfig
@@ -0,0 +1,4 @@
1config SND_SIMPLE_CARD
2 tristate "ASoC Simple sound card support"
3 help
4 This option enables generic simple sound card support
diff --git a/sound/soc/generic/Makefile b/sound/soc/generic/Makefile
new file mode 100644
index 000000000000..9c3b246792bf
--- /dev/null
+++ b/sound/soc/generic/Makefile
@@ -0,0 +1,3 @@
1snd-soc-simple-card-objs := simple-card.o
2
3obj-$(CONFIG_SND_SIMPLE_CARD) += snd-soc-simple-card.o
diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c
new file mode 100644
index 000000000000..b4b4cab30232
--- /dev/null
+++ b/sound/soc/generic/simple-card.c
@@ -0,0 +1,114 @@
1/*
2 * ASoC simple sound card support
3 *
4 * Copyright (C) 2012 Renesas Solutions Corp.
5 * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/platform_device.h>
13#include <linux/module.h>
14#include <sound/simple_card.h>
15
16#define asoc_simple_get_card_info(p) \
17 container_of(p->dai_link, struct asoc_simple_card_info, snd_link)
18
19static int asoc_simple_card_dai_init(struct snd_soc_pcm_runtime *rtd)
20{
21 struct asoc_simple_card_info *cinfo = asoc_simple_get_card_info(rtd);
22 struct asoc_simple_dai_init_info *iinfo = cinfo->init;
23 struct snd_soc_dai *codec = rtd->codec_dai;
24 struct snd_soc_dai *cpu = rtd->cpu_dai;
25 unsigned int cpu_daifmt = iinfo->fmt | iinfo->cpu_daifmt;
26 unsigned int codec_daifmt = iinfo->fmt | iinfo->codec_daifmt;
27 int ret;
28
29 if (codec_daifmt) {
30 ret = snd_soc_dai_set_fmt(codec, codec_daifmt);
31 if (ret < 0)
32 return ret;
33 }
34
35 if (iinfo->sysclk) {
36 ret = snd_soc_dai_set_sysclk(codec, 0, iinfo->sysclk, 0);
37 if (ret < 0)
38 return ret;
39 }
40
41 if (cpu_daifmt) {
42 ret = snd_soc_dai_set_fmt(cpu, cpu_daifmt);
43 if (ret < 0)
44 return ret;
45 }
46
47 return 0;
48}
49
50static int asoc_simple_card_probe(struct platform_device *pdev)
51{
52 struct asoc_simple_card_info *cinfo = pdev->dev.platform_data;
53
54 if (!cinfo) {
55 dev_err(&pdev->dev, "no info for asoc-simple-card\n");
56 return -EINVAL;
57 }
58
59 if (!cinfo->name ||
60 !cinfo->card ||
61 !cinfo->cpu_dai ||
62 !cinfo->codec ||
63 !cinfo->platform ||
64 !cinfo->codec_dai) {
65 dev_err(&pdev->dev, "insufficient asoc_simple_card_info settings\n");
66 return -EINVAL;
67 }
68
69 /*
70 * init snd_soc_dai_link
71 */
72 cinfo->snd_link.name = cinfo->name;
73 cinfo->snd_link.stream_name = cinfo->name;
74 cinfo->snd_link.cpu_dai_name = cinfo->cpu_dai;
75 cinfo->snd_link.platform_name = cinfo->platform;
76 cinfo->snd_link.codec_name = cinfo->codec;
77 cinfo->snd_link.codec_dai_name = cinfo->codec_dai;
78
79 /* enable snd_link.init if cinfo has settings */
80 if (cinfo->init)
81 cinfo->snd_link.init = asoc_simple_card_dai_init;
82
83 /*
84 * init snd_soc_card
85 */
86 cinfo->snd_card.name = cinfo->card;
87 cinfo->snd_card.owner = THIS_MODULE;
88 cinfo->snd_card.dai_link = &cinfo->snd_link;
89 cinfo->snd_card.num_links = 1;
90 cinfo->snd_card.dev = &pdev->dev;
91
92 return snd_soc_register_card(&cinfo->snd_card);
93}
94
95static int asoc_simple_card_remove(struct platform_device *pdev)
96{
97 struct asoc_simple_card_info *cinfo = pdev->dev.platform_data;
98
99 return snd_soc_unregister_card(&cinfo->snd_card);
100}
101
102static struct platform_driver asoc_simple_card = {
103 .driver = {
104 .name = "asoc-simple-card",
105 },
106 .probe = asoc_simple_card_probe,
107 .remove = asoc_simple_card_remove,
108};
109
110module_platform_driver(asoc_simple_card);
111
112MODULE_LICENSE("GPL");
113MODULE_DESCRIPTION("ASoC Simple Sound Card");
114MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>");
diff --git a/sound/soc/imx/Kconfig b/sound/soc/imx/Kconfig
deleted file mode 100644
index 810acaa09009..000000000000
--- a/sound/soc/imx/Kconfig
+++ /dev/null
@@ -1,79 +0,0 @@
1menuconfig SND_IMX_SOC
2 tristate "SoC Audio for Freescale i.MX CPUs"
3 depends on ARCH_MXC
4 help
5 Say Y or M if you want to add support for codecs attached to
6 the i.MX SSI interface.
7
8
9if SND_IMX_SOC
10
11config SND_SOC_IMX_SSI
12 tristate
13
14config SND_SOC_IMX_PCM
15 tristate
16
17config SND_MXC_SOC_FIQ
18 tristate
19 select FIQ
20 select SND_SOC_IMX_PCM
21
22config SND_MXC_SOC_MX2
23 select SND_SOC_DMAENGINE_PCM
24 tristate
25 select SND_SOC_IMX_PCM
26
27config SND_SOC_IMX_AUDMUX
28 tristate
29
30config SND_MXC_SOC_WM1133_EV1
31 tristate "Audio on the the i.MX31ADS with WM1133-EV1 fitted"
32 depends on MACH_MX31ADS_WM1133_EV1 && EXPERIMENTAL
33 select SND_SOC_WM8350
34 select SND_MXC_SOC_FIQ
35 select SND_SOC_IMX_AUDMUX
36 select SND_SOC_IMX_SSI
37 help
38 Enable support for audio on the i.MX31ADS with the WM1133-EV1
39 PMIC board with WM8835x fitted.
40
41config SND_SOC_MX27VIS_AIC32X4
42 tristate "SoC audio support for Visstrim M10 boards"
43 depends on MACH_IMX27_VISSTRIM_M10 && I2C
44 select SND_SOC_TLV320AIC32X4
45 select SND_MXC_SOC_MX2
46 select SND_SOC_IMX_AUDMUX
47 select SND_SOC_IMX_SSI
48 help
49 Say Y if you want to add support for SoC audio on Visstrim SM10
50 board with TLV320AIC32X4 codec.
51
52config SND_SOC_PHYCORE_AC97
53 tristate "SoC Audio support for Phytec phyCORE (and phyCARD) boards"
54 depends on MACH_PCM043 || MACH_PCA100
55 select SND_SOC_AC97_BUS
56 select SND_SOC_WM9712
57 select SND_MXC_SOC_FIQ
58 select SND_SOC_IMX_AUDMUX
59 select SND_SOC_IMX_SSI
60 help
61 Say Y if you want to add support for SoC audio on Phytec phyCORE
62 and phyCARD boards in AC97 mode
63
64config SND_SOC_EUKREA_TLV320
65 tristate "Eukrea TLV320"
66 depends on MACH_EUKREA_MBIMX27_BASEBOARD \
67 || MACH_EUKREA_MBIMXSD25_BASEBOARD \
68 || MACH_EUKREA_MBIMXSD35_BASEBOARD \
69 || MACH_EUKREA_MBIMXSD51_BASEBOARD
70 depends on I2C
71 select SND_SOC_TLV320AIC23
72 select SND_MXC_SOC_FIQ
73 select SND_SOC_IMX_AUDMUX
74 select SND_SOC_IMX_SSI
75 help
76 Enable I2S based access to the TLV320AIC23B codec attached
77 to the SSI interface
78
79endif # SND_IMX_SOC
diff --git a/sound/soc/imx/Makefile b/sound/soc/imx/Makefile
deleted file mode 100644
index f5db3e92d0d1..000000000000
--- a/sound/soc/imx/Makefile
+++ /dev/null
@@ -1,22 +0,0 @@
1# i.MX Platform Support
2snd-soc-imx-ssi-objs := imx-ssi.o
3snd-soc-imx-audmux-objs := imx-audmux.o
4
5obj-$(CONFIG_SND_SOC_IMX_SSI) += snd-soc-imx-ssi.o
6obj-$(CONFIG_SND_SOC_IMX_AUDMUX) += snd-soc-imx-audmux.o
7
8obj-$(CONFIG_SND_SOC_IMX_PCM) += snd-soc-imx-pcm.o
9snd-soc-imx-pcm-y := imx-pcm.o
10snd-soc-imx-pcm-$(CONFIG_SND_MXC_SOC_FIQ) += imx-pcm-fiq.o
11snd-soc-imx-pcm-$(CONFIG_SND_MXC_SOC_MX2) += imx-pcm-dma-mx2.o
12
13# i.MX Machine Support
14snd-soc-eukrea-tlv320-objs := eukrea-tlv320.o
15snd-soc-phycore-ac97-objs := phycore-ac97.o
16snd-soc-mx27vis-aic32x4-objs := mx27vis-aic32x4.o
17snd-soc-wm1133-ev1-objs := wm1133-ev1.o
18
19obj-$(CONFIG_SND_SOC_EUKREA_TLV320) += snd-soc-eukrea-tlv320.o
20obj-$(CONFIG_SND_SOC_PHYCORE_AC97) += snd-soc-phycore-ac97.o
21obj-$(CONFIG_SND_SOC_MX27VIS_AIC32X4) += snd-soc-mx27vis-aic32x4.o
22obj-$(CONFIG_SND_MXC_SOC_WM1133_EV1) += snd-soc-wm1133-ev1.o
diff --git a/sound/soc/jz4740/jz4740-i2s.c b/sound/soc/jz4740/jz4740-i2s.c
index a5af7c42e62b..41349670adab 100644
--- a/sound/soc/jz4740/jz4740-i2s.c
+++ b/sound/soc/jz4740/jz4740-i2s.c
@@ -346,7 +346,7 @@ static void jz4740_i2c_init_pcm_config(struct jz4740_i2s *i2s)
346 346
347 /* Playback */ 347 /* Playback */
348 dma_config = &i2s->pcm_config_playback.dma_config; 348 dma_config = &i2s->pcm_config_playback.dma_config;
349 dma_config->src_width = JZ4740_DMA_WIDTH_32BIT, 349 dma_config->src_width = JZ4740_DMA_WIDTH_32BIT;
350 dma_config->transfer_size = JZ4740_DMA_TRANSFER_SIZE_16BYTE; 350 dma_config->transfer_size = JZ4740_DMA_TRANSFER_SIZE_16BYTE;
351 dma_config->request_type = JZ4740_DMA_TYPE_AIC_TRANSMIT; 351 dma_config->request_type = JZ4740_DMA_TYPE_AIC_TRANSMIT;
352 dma_config->flags = JZ4740_DMA_SRC_AUTOINC; 352 dma_config->flags = JZ4740_DMA_SRC_AUTOINC;
@@ -355,7 +355,7 @@ static void jz4740_i2c_init_pcm_config(struct jz4740_i2s *i2s)
355 355
356 /* Capture */ 356 /* Capture */
357 dma_config = &i2s->pcm_config_capture.dma_config; 357 dma_config = &i2s->pcm_config_capture.dma_config;
358 dma_config->dst_width = JZ4740_DMA_WIDTH_32BIT, 358 dma_config->dst_width = JZ4740_DMA_WIDTH_32BIT;
359 dma_config->transfer_size = JZ4740_DMA_TRANSFER_SIZE_16BYTE; 359 dma_config->transfer_size = JZ4740_DMA_TRANSFER_SIZE_16BYTE;
360 dma_config->request_type = JZ4740_DMA_TYPE_AIC_RECEIVE; 360 dma_config->request_type = JZ4740_DMA_TYPE_AIC_RECEIVE;
361 dma_config->flags = JZ4740_DMA_DST_AUTOINC; 361 dma_config->flags = JZ4740_DMA_DST_AUTOINC;
diff --git a/sound/soc/mxs/mxs-pcm.c b/sound/soc/mxs/mxs-pcm.c
index e373fbbc97a0..373dec90579f 100644
--- a/sound/soc/mxs/mxs-pcm.c
+++ b/sound/soc/mxs/mxs-pcm.c
@@ -220,28 +220,16 @@ static struct snd_soc_platform_driver mxs_soc_platform = {
220 .pcm_free = mxs_pcm_free, 220 .pcm_free = mxs_pcm_free,
221}; 221};
222 222
223static int __devinit mxs_soc_platform_probe(struct platform_device *pdev) 223int __devinit mxs_pcm_platform_register(struct device *dev)
224{ 224{
225 return snd_soc_register_platform(&pdev->dev, &mxs_soc_platform); 225 return snd_soc_register_platform(dev, &mxs_soc_platform);
226} 226}
227EXPORT_SYMBOL_GPL(mxs_pcm_platform_register);
227 228
228static int __devexit mxs_soc_platform_remove(struct platform_device *pdev) 229void __devexit mxs_pcm_platform_unregister(struct device *dev)
229{ 230{
230 snd_soc_unregister_platform(&pdev->dev); 231 snd_soc_unregister_platform(dev);
231
232 return 0;
233} 232}
234 233EXPORT_SYMBOL_GPL(mxs_pcm_platform_unregister);
235static struct platform_driver mxs_pcm_driver = {
236 .driver = {
237 .name = "mxs-pcm-audio",
238 .owner = THIS_MODULE,
239 },
240 .probe = mxs_soc_platform_probe,
241 .remove = __devexit_p(mxs_soc_platform_remove),
242};
243
244module_platform_driver(mxs_pcm_driver);
245 234
246MODULE_LICENSE("GPL"); 235MODULE_LICENSE("GPL");
247MODULE_ALIAS("platform:mxs-pcm-audio");
diff --git a/sound/soc/mxs/mxs-pcm.h b/sound/soc/mxs/mxs-pcm.h
index 5f01a9124b3d..35ba2ca42384 100644
--- a/sound/soc/mxs/mxs-pcm.h
+++ b/sound/soc/mxs/mxs-pcm.h
@@ -24,4 +24,7 @@ struct mxs_pcm_dma_params {
24 int chan_num; 24 int chan_num;
25}; 25};
26 26
27int mxs_pcm_platform_register(struct device *dev);
28void mxs_pcm_platform_unregister(struct device *dev);
29
27#endif 30#endif
diff --git a/sound/soc/mxs/mxs-saif.c b/sound/soc/mxs/mxs-saif.c
index 53f4fd8feced..064274880673 100644
--- a/sound/soc/mxs/mxs-saif.c
+++ b/sound/soc/mxs/mxs-saif.c
@@ -18,6 +18,8 @@
18 18
19#include <linux/module.h> 19#include <linux/module.h>
20#include <linux/init.h> 20#include <linux/init.h>
21#include <linux/of.h>
22#include <linux/of_device.h>
21#include <linux/platform_device.h> 23#include <linux/platform_device.h>
22#include <linux/slab.h> 24#include <linux/slab.h>
23#include <linux/dma-mapping.h> 25#include <linux/dma-mapping.h>
@@ -620,36 +622,56 @@ static irqreturn_t mxs_saif_irq(int irq, void *dev_id)
620 return IRQ_HANDLED; 622 return IRQ_HANDLED;
621} 623}
622 624
623static int mxs_saif_probe(struct platform_device *pdev) 625static int __devinit mxs_saif_probe(struct platform_device *pdev)
624{ 626{
627 struct device_node *np = pdev->dev.of_node;
625 struct resource *iores, *dmares; 628 struct resource *iores, *dmares;
626 struct mxs_saif *saif; 629 struct mxs_saif *saif;
627 struct mxs_saif_platform_data *pdata; 630 struct mxs_saif_platform_data *pdata;
628 int ret = 0; 631 int ret = 0;
629 632
630 if (pdev->id >= ARRAY_SIZE(mxs_saif)) 633
634 if (!np && pdev->id >= ARRAY_SIZE(mxs_saif))
631 return -EINVAL; 635 return -EINVAL;
632 636
633 saif = devm_kzalloc(&pdev->dev, sizeof(*saif), GFP_KERNEL); 637 saif = devm_kzalloc(&pdev->dev, sizeof(*saif), GFP_KERNEL);
634 if (!saif) 638 if (!saif)
635 return -ENOMEM; 639 return -ENOMEM;
636 640
637 mxs_saif[pdev->id] = saif; 641 if (np) {
638 saif->id = pdev->id; 642 struct device_node *master;
639 643 saif->id = of_alias_get_id(np, "saif");
640 pdata = pdev->dev.platform_data; 644 if (saif->id < 0)
641 if (pdata && !pdata->master_mode) { 645 return saif->id;
642 saif->master_id = pdata->master_id; 646 /*
643 if (saif->master_id < 0 || 647 * If there is no "fsl,saif-master" phandle, it's a saif
644 saif->master_id >= ARRAY_SIZE(mxs_saif) || 648 * master. Otherwise, it's a slave and its phandle points
645 saif->master_id == saif->id) { 649 * to the master.
646 dev_err(&pdev->dev, "get wrong master id\n"); 650 */
647 return -EINVAL; 651 master = of_parse_phandle(np, "fsl,saif-master", 0);
652 if (!master) {
653 saif->master_id = saif->id;
654 } else {
655 saif->master_id = of_alias_get_id(master, "saif");
656 if (saif->master_id < 0)
657 return saif->master_id;
648 } 658 }
649 } else { 659 } else {
650 saif->master_id = saif->id; 660 saif->id = pdev->id;
661 pdata = pdev->dev.platform_data;
662 if (pdata && !pdata->master_mode)
663 saif->master_id = pdata->master_id;
664 else
665 saif->master_id = saif->id;
666 }
667
668 if (saif->master_id < 0 || saif->master_id >= ARRAY_SIZE(mxs_saif)) {
669 dev_err(&pdev->dev, "get wrong master id\n");
670 return -EINVAL;
651 } 671 }
652 672
673 mxs_saif[saif->id] = saif;
674
653 saif->clk = clk_get(&pdev->dev, NULL); 675 saif->clk = clk_get(&pdev->dev, NULL);
654 if (IS_ERR(saif->clk)) { 676 if (IS_ERR(saif->clk)) {
655 ret = PTR_ERR(saif->clk); 677 ret = PTR_ERR(saif->clk);
@@ -669,12 +691,19 @@ static int mxs_saif_probe(struct platform_device *pdev)
669 691
670 dmares = platform_get_resource(pdev, IORESOURCE_DMA, 0); 692 dmares = platform_get_resource(pdev, IORESOURCE_DMA, 0);
671 if (!dmares) { 693 if (!dmares) {
672 ret = -ENODEV; 694 /*
673 dev_err(&pdev->dev, "failed to get dma resource: %d\n", 695 * TODO: This is a temporary solution and should be changed
674 ret); 696 * to use generic DMA binding later when the helplers get in.
675 goto failed_get_resource; 697 */
698 ret = of_property_read_u32(np, "fsl,saif-dma-channel",
699 &saif->dma_param.chan_num);
700 if (ret) {
701 dev_err(&pdev->dev, "failed to get dma channel\n");
702 goto failed_get_resource;
703 }
704 } else {
705 saif->dma_param.chan_num = dmares->start;
676 } 706 }
677 saif->dma_param.chan_num = dmares->start;
678 707
679 saif->irq = platform_get_irq(pdev, 0); 708 saif->irq = platform_get_irq(pdev, 0);
680 if (saif->irq < 0) { 709 if (saif->irq < 0) {
@@ -708,24 +737,14 @@ static int mxs_saif_probe(struct platform_device *pdev)
708 goto failed_get_resource; 737 goto failed_get_resource;
709 } 738 }
710 739
711 saif->soc_platform_pdev = platform_device_alloc( 740 ret = mxs_pcm_platform_register(&pdev->dev);
712 "mxs-pcm-audio", pdev->id);
713 if (!saif->soc_platform_pdev) {
714 ret = -ENOMEM;
715 goto failed_pdev_alloc;
716 }
717
718 platform_set_drvdata(saif->soc_platform_pdev, saif);
719 ret = platform_device_add(saif->soc_platform_pdev);
720 if (ret) { 741 if (ret) {
721 dev_err(&pdev->dev, "failed to add soc platform device\n"); 742 dev_err(&pdev->dev, "register PCM failed: %d\n", ret);
722 goto failed_pdev_add; 743 goto failed_pdev_alloc;
723 } 744 }
724 745
725 return 0; 746 return 0;
726 747
727failed_pdev_add:
728 platform_device_put(saif->soc_platform_pdev);
729failed_pdev_alloc: 748failed_pdev_alloc:
730 snd_soc_unregister_dai(&pdev->dev); 749 snd_soc_unregister_dai(&pdev->dev);
731failed_get_resource: 750failed_get_resource:
@@ -738,13 +757,19 @@ static int __devexit mxs_saif_remove(struct platform_device *pdev)
738{ 757{
739 struct mxs_saif *saif = platform_get_drvdata(pdev); 758 struct mxs_saif *saif = platform_get_drvdata(pdev);
740 759
741 platform_device_unregister(saif->soc_platform_pdev); 760 mxs_pcm_platform_unregister(&pdev->dev);
742 snd_soc_unregister_dai(&pdev->dev); 761 snd_soc_unregister_dai(&pdev->dev);
743 clk_put(saif->clk); 762 clk_put(saif->clk);
744 763
745 return 0; 764 return 0;
746} 765}
747 766
767static const struct of_device_id mxs_saif_dt_ids[] = {
768 { .compatible = "fsl,imx28-saif", },
769 { /* sentinel */ }
770};
771MODULE_DEVICE_TABLE(of, mxs_saif_dt_ids);
772
748static struct platform_driver mxs_saif_driver = { 773static struct platform_driver mxs_saif_driver = {
749 .probe = mxs_saif_probe, 774 .probe = mxs_saif_probe,
750 .remove = __devexit_p(mxs_saif_remove), 775 .remove = __devexit_p(mxs_saif_remove),
@@ -752,6 +777,7 @@ static struct platform_driver mxs_saif_driver = {
752 .driver = { 777 .driver = {
753 .name = "mxs-saif", 778 .name = "mxs-saif",
754 .owner = THIS_MODULE, 779 .owner = THIS_MODULE,
780 .of_match_table = mxs_saif_dt_ids,
755 }, 781 },
756}; 782};
757 783
diff --git a/sound/soc/mxs/mxs-saif.h b/sound/soc/mxs/mxs-saif.h
index 12c91e4eb941..3cb342e5bc90 100644
--- a/sound/soc/mxs/mxs-saif.h
+++ b/sound/soc/mxs/mxs-saif.h
@@ -123,7 +123,6 @@ struct mxs_saif {
123 unsigned int cur_rate; 123 unsigned int cur_rate;
124 unsigned int ongoing; 124 unsigned int ongoing;
125 125
126 struct platform_device *soc_platform_pdev;
127 u32 fifo_underrun; 126 u32 fifo_underrun;
128 u32 fifo_overrun; 127 u32 fifo_overrun;
129}; 128};
diff --git a/sound/soc/mxs/mxs-sgtl5000.c b/sound/soc/mxs/mxs-sgtl5000.c
index 60f052b7cf22..3e6e8764b2e6 100644
--- a/sound/soc/mxs/mxs-sgtl5000.c
+++ b/sound/soc/mxs/mxs-sgtl5000.c
@@ -18,6 +18,8 @@
18 18
19#include <linux/module.h> 19#include <linux/module.h>
20#include <linux/device.h> 20#include <linux/device.h>
21#include <linux/of.h>
22#include <linux/of_device.h>
21#include <sound/core.h> 23#include <sound/core.h>
22#include <sound/pcm.h> 24#include <sound/pcm.h>
23#include <sound/soc.h> 25#include <sound/soc.h>
@@ -90,7 +92,7 @@ static struct snd_soc_dai_link mxs_sgtl5000_dai[] = {
90 .codec_dai_name = "sgtl5000", 92 .codec_dai_name = "sgtl5000",
91 .codec_name = "sgtl5000.0-000a", 93 .codec_name = "sgtl5000.0-000a",
92 .cpu_dai_name = "mxs-saif.0", 94 .cpu_dai_name = "mxs-saif.0",
93 .platform_name = "mxs-pcm-audio.0", 95 .platform_name = "mxs-saif.0",
94 .ops = &mxs_sgtl5000_hifi_ops, 96 .ops = &mxs_sgtl5000_hifi_ops,
95 }, { 97 }, {
96 .name = "HiFi Rx", 98 .name = "HiFi Rx",
@@ -98,7 +100,7 @@ static struct snd_soc_dai_link mxs_sgtl5000_dai[] = {
98 .codec_dai_name = "sgtl5000", 100 .codec_dai_name = "sgtl5000",
99 .codec_name = "sgtl5000.0-000a", 101 .codec_name = "sgtl5000.0-000a",
100 .cpu_dai_name = "mxs-saif.1", 102 .cpu_dai_name = "mxs-saif.1",
101 .platform_name = "mxs-pcm-audio.1", 103 .platform_name = "mxs-saif.1",
102 .ops = &mxs_sgtl5000_hifi_ops, 104 .ops = &mxs_sgtl5000_hifi_ops,
103 }, 105 },
104}; 106};
@@ -110,11 +112,48 @@ static struct snd_soc_card mxs_sgtl5000 = {
110 .num_links = ARRAY_SIZE(mxs_sgtl5000_dai), 112 .num_links = ARRAY_SIZE(mxs_sgtl5000_dai),
111}; 113};
112 114
115static int __devinit mxs_sgtl5000_probe_dt(struct platform_device *pdev)
116{
117 struct device_node *np = pdev->dev.of_node;
118 struct device_node *saif_np[2], *codec_np;
119 int i, ret = 0;
120
121 if (!np)
122 return 1; /* no device tree */
123
124 saif_np[0] = of_parse_phandle(np, "saif-controllers", 0);
125 saif_np[1] = of_parse_phandle(np, "saif-controllers", 1);
126 codec_np = of_parse_phandle(np, "audio-codec", 0);
127 if (!saif_np[0] || !saif_np[1] || !codec_np) {
128 dev_err(&pdev->dev, "phandle missing or invalid\n");
129 return -EINVAL;
130 }
131
132 for (i = 0; i < 2; i++) {
133 mxs_sgtl5000_dai[i].codec_name = NULL;
134 mxs_sgtl5000_dai[i].codec_of_node = codec_np;
135 mxs_sgtl5000_dai[i].cpu_dai_name = NULL;
136 mxs_sgtl5000_dai[i].cpu_dai_of_node = saif_np[i];
137 mxs_sgtl5000_dai[i].platform_name = NULL;
138 mxs_sgtl5000_dai[i].platform_of_node = saif_np[i];
139 }
140
141 of_node_put(codec_np);
142 of_node_put(saif_np[0]);
143 of_node_put(saif_np[1]);
144
145 return ret;
146}
147
113static int __devinit mxs_sgtl5000_probe(struct platform_device *pdev) 148static int __devinit mxs_sgtl5000_probe(struct platform_device *pdev)
114{ 149{
115 struct snd_soc_card *card = &mxs_sgtl5000; 150 struct snd_soc_card *card = &mxs_sgtl5000;
116 int ret; 151 int ret;
117 152
153 ret = mxs_sgtl5000_probe_dt(pdev);
154 if (ret < 0)
155 return ret;
156
118 /* 157 /*
119 * Set an init clock(11.28Mhz) for sgtl5000 initialization(i2c r/w). 158 * Set an init clock(11.28Mhz) for sgtl5000 initialization(i2c r/w).
120 * The Sgtl5000 sysclk is derived from saif0 mclk and it's range 159 * The Sgtl5000 sysclk is derived from saif0 mclk and it's range
@@ -148,10 +187,17 @@ static int __devexit mxs_sgtl5000_remove(struct platform_device *pdev)
148 return 0; 187 return 0;
149} 188}
150 189
190static const struct of_device_id mxs_sgtl5000_dt_ids[] = {
191 { .compatible = "fsl,mxs-audio-sgtl5000", },
192 { /* sentinel */ }
193};
194MODULE_DEVICE_TABLE(of, mxs_sgtl5000_dt_ids);
195
151static struct platform_driver mxs_sgtl5000_audio_driver = { 196static struct platform_driver mxs_sgtl5000_audio_driver = {
152 .driver = { 197 .driver = {
153 .name = "mxs-sgtl5000", 198 .name = "mxs-sgtl5000",
154 .owner = THIS_MODULE, 199 .owner = THIS_MODULE,
200 .of_match_table = mxs_sgtl5000_dt_ids,
155 }, 201 },
156 .probe = mxs_sgtl5000_probe, 202 .probe = mxs_sgtl5000_probe,
157 .remove = __devexit_p(mxs_sgtl5000_remove), 203 .remove = __devexit_p(mxs_sgtl5000_remove),
diff --git a/sound/soc/omap/Kconfig b/sound/soc/omap/Kconfig
index e00dd0b1139c..deafbfaacdbf 100644
--- a/sound/soc/omap/Kconfig
+++ b/sound/soc/omap/Kconfig
@@ -97,7 +97,7 @@ config SND_OMAP_SOC_SDP3430
97 97
98config SND_OMAP_SOC_OMAP_ABE_TWL6040 98config SND_OMAP_SOC_OMAP_ABE_TWL6040
99 tristate "SoC Audio support for OMAP boards using ABE and twl6040 codec" 99 tristate "SoC Audio support for OMAP boards using ABE and twl6040 codec"
100 depends on TWL4030_CORE && SND_OMAP_SOC && ARCH_OMAP4 100 depends on TWL6040_CORE && SND_OMAP_SOC && ARCH_OMAP4
101 select SND_OMAP_SOC_DMIC 101 select SND_OMAP_SOC_DMIC
102 select SND_OMAP_SOC_MCPDM 102 select SND_OMAP_SOC_MCPDM
103 select SND_SOC_TWL6040 103 select SND_SOC_TWL6040
diff --git a/sound/soc/pxa/pxa-ssp.c b/sound/soc/pxa/pxa-ssp.c
index fd04ce139031..1c2aa7fab3fd 100644
--- a/sound/soc/pxa/pxa-ssp.c
+++ b/sound/soc/pxa/pxa-ssp.c
@@ -85,14 +85,12 @@ struct pxa2xx_pcm_dma_data {
85 char name[20]; 85 char name[20];
86}; 86};
87 87
88static struct pxa2xx_pcm_dma_params * 88static void pxa_ssp_set_dma_params(struct ssp_device *ssp, int width4,
89pxa_ssp_get_dma_params(struct ssp_device *ssp, int width4, int out) 89 int out, struct pxa2xx_pcm_dma_params *dma_data)
90{ 90{
91 struct pxa2xx_pcm_dma_data *dma; 91 struct pxa2xx_pcm_dma_data *dma;
92 92
93 dma = kzalloc(sizeof(struct pxa2xx_pcm_dma_data), GFP_KERNEL); 93 dma = container_of(dma_data, struct pxa2xx_pcm_dma_data, params);
94 if (dma == NULL)
95 return NULL;
96 94
97 snprintf(dma->name, 20, "SSP%d PCM %s %s", ssp->port_id, 95 snprintf(dma->name, 20, "SSP%d PCM %s %s", ssp->port_id,
98 width4 ? "32-bit" : "16-bit", out ? "out" : "in"); 96 width4 ? "32-bit" : "16-bit", out ? "out" : "in");
@@ -103,8 +101,6 @@ pxa_ssp_get_dma_params(struct ssp_device *ssp, int width4, int out)
103 (DCMD_INCTRGADDR | DCMD_FLOWSRC)) | 101 (DCMD_INCTRGADDR | DCMD_FLOWSRC)) |
104 (width4 ? DCMD_WIDTH4 : DCMD_WIDTH2) | DCMD_BURST16; 102 (width4 ? DCMD_WIDTH4 : DCMD_WIDTH2) | DCMD_BURST16;
105 dma->params.dev_addr = ssp->phys_base + SSDR; 103 dma->params.dev_addr = ssp->phys_base + SSDR;
106
107 return &dma->params;
108} 104}
109 105
110static int pxa_ssp_startup(struct snd_pcm_substream *substream, 106static int pxa_ssp_startup(struct snd_pcm_substream *substream,
@@ -112,6 +108,7 @@ static int pxa_ssp_startup(struct snd_pcm_substream *substream,
112{ 108{
113 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai); 109 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
114 struct ssp_device *ssp = priv->ssp; 110 struct ssp_device *ssp = priv->ssp;
111 struct pxa2xx_pcm_dma_data *dma;
115 int ret = 0; 112 int ret = 0;
116 113
117 if (!cpu_dai->active) { 114 if (!cpu_dai->active) {
@@ -119,8 +116,10 @@ static int pxa_ssp_startup(struct snd_pcm_substream *substream,
119 pxa_ssp_disable(ssp); 116 pxa_ssp_disable(ssp);
120 } 117 }
121 118
122 kfree(snd_soc_dai_get_dma_data(cpu_dai, substream)); 119 dma = kzalloc(sizeof(struct pxa2xx_pcm_dma_data), GFP_KERNEL);
123 snd_soc_dai_set_dma_data(cpu_dai, substream, NULL); 120 if (!dma)
121 return -ENOMEM;
122 snd_soc_dai_set_dma_data(cpu_dai, substream, &dma->params);
124 123
125 return ret; 124 return ret;
126} 125}
@@ -573,18 +572,13 @@ static int pxa_ssp_hw_params(struct snd_pcm_substream *substream,
573 572
574 dma_data = snd_soc_dai_get_dma_data(cpu_dai, substream); 573 dma_data = snd_soc_dai_get_dma_data(cpu_dai, substream);
575 574
576 /* generate correct DMA params */
577 kfree(dma_data);
578
579 /* Network mode with one active slot (ttsa == 1) can be used 575 /* Network mode with one active slot (ttsa == 1) can be used
580 * to force 16-bit frame width on the wire (for S16_LE), even 576 * to force 16-bit frame width on the wire (for S16_LE), even
581 * with two channels. Use 16-bit DMA transfers for this case. 577 * with two channels. Use 16-bit DMA transfers for this case.
582 */ 578 */
583 dma_data = pxa_ssp_get_dma_params(ssp, 579 pxa_ssp_set_dma_params(ssp,
584 ((chn == 2) && (ttsa != 1)) || (width == 32), 580 ((chn == 2) && (ttsa != 1)) || (width == 32),
585 substream->stream == SNDRV_PCM_STREAM_PLAYBACK); 581 substream->stream == SNDRV_PCM_STREAM_PLAYBACK, dma_data);
586
587 snd_soc_dai_set_dma_data(cpu_dai, substream, dma_data);
588 582
589 /* we can only change the settings if the port is not in use */ 583 /* we can only change the settings if the port is not in use */
590 if (pxa_ssp_read_reg(ssp, SSCR0) & SSCR0_SSE) 584 if (pxa_ssp_read_reg(ssp, SSCR0) & SSCR0_SSE)
diff --git a/sound/soc/pxa/pxa2xx-i2s.c b/sound/soc/pxa/pxa2xx-i2s.c
index d08583790d23..3075a426124c 100644
--- a/sound/soc/pxa/pxa2xx-i2s.c
+++ b/sound/soc/pxa/pxa2xx-i2s.c
@@ -166,7 +166,7 @@ static int pxa2xx_i2s_hw_params(struct snd_pcm_substream *substream,
166 struct pxa2xx_pcm_dma_params *dma_data; 166 struct pxa2xx_pcm_dma_params *dma_data;
167 167
168 BUG_ON(IS_ERR(clk_i2s)); 168 BUG_ON(IS_ERR(clk_i2s));
169 clk_enable(clk_i2s); 169 clk_prepare_enable(clk_i2s);
170 clk_ena = 1; 170 clk_ena = 1;
171 pxa_i2s_wait(); 171 pxa_i2s_wait();
172 172
@@ -259,7 +259,7 @@ static void pxa2xx_i2s_shutdown(struct snd_pcm_substream *substream,
259 SACR0 &= ~SACR0_ENB; 259 SACR0 &= ~SACR0_ENB;
260 pxa_i2s_wait(); 260 pxa_i2s_wait();
261 if (clk_ena) { 261 if (clk_ena) {
262 clk_disable(clk_i2s); 262 clk_disable_unprepare(clk_i2s);
263 clk_ena = 0; 263 clk_ena = 0;
264 } 264 }
265 } 265 }
diff --git a/sound/soc/samsung/littlemill.c b/sound/soc/samsung/littlemill.c
index e7416851bf7d..c82c646b8a08 100644
--- a/sound/soc/samsung/littlemill.c
+++ b/sound/soc/samsung/littlemill.c
@@ -23,10 +23,10 @@ static int littlemill_set_bias_level(struct snd_soc_card *card,
23 struct snd_soc_dapm_context *dapm, 23 struct snd_soc_dapm_context *dapm,
24 enum snd_soc_bias_level level) 24 enum snd_soc_bias_level level)
25{ 25{
26 struct snd_soc_dai *codec_dai = card->rtd[0].codec_dai; 26 struct snd_soc_dai *aif1_dai = card->rtd[0].codec_dai;
27 int ret; 27 int ret;
28 28
29 if (dapm->dev != codec_dai->dev) 29 if (dapm->dev != aif1_dai->dev)
30 return 0; 30 return 0;
31 31
32 switch (level) { 32 switch (level) {
@@ -36,7 +36,7 @@ static int littlemill_set_bias_level(struct snd_soc_card *card,
36 * then do so now, otherwise these are noops. 36 * then do so now, otherwise these are noops.
37 */ 37 */
38 if (dapm->bias_level == SND_SOC_BIAS_STANDBY) { 38 if (dapm->bias_level == SND_SOC_BIAS_STANDBY) {
39 ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL1, 39 ret = snd_soc_dai_set_pll(aif1_dai, WM8994_FLL1,
40 WM8994_FLL_SRC_MCLK2, 32768, 40 WM8994_FLL_SRC_MCLK2, 32768,
41 sample_rate * 512); 41 sample_rate * 512);
42 if (ret < 0) { 42 if (ret < 0) {
@@ -44,7 +44,7 @@ static int littlemill_set_bias_level(struct snd_soc_card *card,
44 return ret; 44 return ret;
45 } 45 }
46 46
47 ret = snd_soc_dai_set_sysclk(codec_dai, 47 ret = snd_soc_dai_set_sysclk(aif1_dai,
48 WM8994_SYSCLK_FLL1, 48 WM8994_SYSCLK_FLL1,
49 sample_rate * 512, 49 sample_rate * 512,
50 SND_SOC_CLOCK_IN); 50 SND_SOC_CLOCK_IN);
@@ -66,25 +66,25 @@ static int littlemill_set_bias_level_post(struct snd_soc_card *card,
66 struct snd_soc_dapm_context *dapm, 66 struct snd_soc_dapm_context *dapm,
67 enum snd_soc_bias_level level) 67 enum snd_soc_bias_level level)
68{ 68{
69 struct snd_soc_dai *codec_dai = card->rtd[0].codec_dai; 69 struct snd_soc_dai *aif1_dai = card->rtd[0].codec_dai;
70 int ret; 70 int ret;
71 71
72 if (dapm->dev != codec_dai->dev) 72 if (dapm->dev != aif1_dai->dev)
73 return 0; 73 return 0;
74 74
75 switch (level) { 75 switch (level) {
76 case SND_SOC_BIAS_STANDBY: 76 case SND_SOC_BIAS_STANDBY:
77 ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_MCLK2, 77 ret = snd_soc_dai_set_sysclk(aif1_dai, WM8994_SYSCLK_MCLK2,
78 32768, SND_SOC_CLOCK_IN); 78 32768, SND_SOC_CLOCK_IN);
79 if (ret < 0) { 79 if (ret < 0) {
80 pr_err("Failed to switch away from FLL: %d\n", ret); 80 pr_err("Failed to switch away from FLL1: %d\n", ret);
81 return ret; 81 return ret;
82 } 82 }
83 83
84 ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL1, 84 ret = snd_soc_dai_set_pll(aif1_dai, WM8994_FLL1,
85 0, 0, 0); 85 0, 0, 0);
86 if (ret < 0) { 86 if (ret < 0) {
87 pr_err("Failed to stop FLL: %d\n", ret); 87 pr_err("Failed to stop FLL1: %d\n", ret);
88 return ret; 88 return ret;
89 } 89 }
90 break; 90 break;
@@ -131,6 +131,14 @@ static struct snd_soc_ops littlemill_ops = {
131 .hw_params = littlemill_hw_params, 131 .hw_params = littlemill_hw_params,
132}; 132};
133 133
134static const struct snd_soc_pcm_stream baseband_params = {
135 .formats = SNDRV_PCM_FMTBIT_S32_LE,
136 .rate_min = 8000,
137 .rate_max = 8000,
138 .channels_min = 2,
139 .channels_max = 2,
140};
141
134static struct snd_soc_dai_link littlemill_dai[] = { 142static struct snd_soc_dai_link littlemill_dai[] = {
135 { 143 {
136 .name = "CPU", 144 .name = "CPU",
@@ -143,13 +151,75 @@ static struct snd_soc_dai_link littlemill_dai[] = {
143 | SND_SOC_DAIFMT_CBM_CFM, 151 | SND_SOC_DAIFMT_CBM_CFM,
144 .ops = &littlemill_ops, 152 .ops = &littlemill_ops,
145 }, 153 },
154 {
155 .name = "Baseband",
156 .stream_name = "Baseband",
157 .cpu_dai_name = "wm8994-aif2",
158 .codec_dai_name = "wm1250-ev1",
159 .codec_name = "wm1250-ev1.1-0027",
160 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
161 | SND_SOC_DAIFMT_CBM_CFM,
162 .ignore_suspend = 1,
163 .params = &baseband_params,
164 },
146}; 165};
147 166
167static int bbclk_ev(struct snd_soc_dapm_widget *w,
168 struct snd_kcontrol *kcontrol, int event)
169{
170 struct snd_soc_card *card = w->dapm->card;
171 struct snd_soc_dai *aif2_dai = card->rtd[1].cpu_dai;
172 int ret;
173
174 switch (event) {
175 case SND_SOC_DAPM_PRE_PMU:
176 ret = snd_soc_dai_set_pll(aif2_dai, WM8994_FLL2,
177 WM8994_FLL_SRC_BCLK, 64 * 8000,
178 8000 * 256);
179 if (ret < 0) {
180 pr_err("Failed to start FLL: %d\n", ret);
181 return ret;
182 }
183
184 ret = snd_soc_dai_set_sysclk(aif2_dai, WM8994_SYSCLK_FLL2,
185 8000 * 256,
186 SND_SOC_CLOCK_IN);
187 if (ret < 0) {
188 pr_err("Failed to set SYSCLK: %d\n", ret);
189 return ret;
190 }
191 break;
192 case SND_SOC_DAPM_POST_PMD:
193 ret = snd_soc_dai_set_sysclk(aif2_dai, WM8994_SYSCLK_MCLK2,
194 32768, SND_SOC_CLOCK_IN);
195 if (ret < 0) {
196 pr_err("Failed to switch away from FLL2: %d\n", ret);
197 return ret;
198 }
199
200 ret = snd_soc_dai_set_pll(aif2_dai, WM8994_FLL2,
201 0, 0, 0);
202 if (ret < 0) {
203 pr_err("Failed to stop FLL2: %d\n", ret);
204 return ret;
205 }
206 break;
207 default:
208 return -EINVAL;
209 }
210
211 return 0;
212}
213
148static struct snd_soc_dapm_widget widgets[] = { 214static struct snd_soc_dapm_widget widgets[] = {
149 SND_SOC_DAPM_HP("Headphone", NULL), 215 SND_SOC_DAPM_HP("Headphone", NULL),
150 216
151 SND_SOC_DAPM_MIC("AMIC", NULL), 217 SND_SOC_DAPM_MIC("AMIC", NULL),
152 SND_SOC_DAPM_MIC("DMIC", NULL), 218 SND_SOC_DAPM_MIC("DMIC", NULL),
219
220 SND_SOC_DAPM_SUPPLY_S("Baseband Clock", -1, SND_SOC_NOPM, 0, 0,
221 bbclk_ev,
222 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
153}; 223};
154 224
155static struct snd_soc_dapm_route audio_paths[] = { 225static struct snd_soc_dapm_route audio_paths[] = {
@@ -162,6 +232,8 @@ static struct snd_soc_dapm_route audio_paths[] = {
162 { "DMIC", NULL, "MICBIAS2" }, /* Default for DMICBIAS jumper */ 232 { "DMIC", NULL, "MICBIAS2" }, /* Default for DMICBIAS jumper */
163 { "DMIC1DAT", NULL, "DMIC" }, 233 { "DMIC1DAT", NULL, "DMIC" },
164 { "DMIC2DAT", NULL, "DMIC" }, 234 { "DMIC2DAT", NULL, "DMIC" },
235
236 { "AIF2CLK", NULL, "Baseband Clock" },
165}; 237};
166 238
167static struct snd_soc_jack littlemill_headset; 239static struct snd_soc_jack littlemill_headset;
@@ -169,10 +241,16 @@ static struct snd_soc_jack littlemill_headset;
169static int littlemill_late_probe(struct snd_soc_card *card) 241static int littlemill_late_probe(struct snd_soc_card *card)
170{ 242{
171 struct snd_soc_codec *codec = card->rtd[0].codec; 243 struct snd_soc_codec *codec = card->rtd[0].codec;
172 struct snd_soc_dai *codec_dai = card->rtd[0].codec_dai; 244 struct snd_soc_dai *aif1_dai = card->rtd[0].codec_dai;
245 struct snd_soc_dai *aif2_dai = card->rtd[1].cpu_dai;
173 int ret; 246 int ret;
174 247
175 ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_MCLK2, 248 ret = snd_soc_dai_set_sysclk(aif1_dai, WM8994_SYSCLK_MCLK2,
249 32768, SND_SOC_CLOCK_IN);
250 if (ret < 0)
251 return ret;
252
253 ret = snd_soc_dai_set_sysclk(aif2_dai, WM8994_SYSCLK_MCLK2,
176 32768, SND_SOC_CLOCK_IN); 254 32768, SND_SOC_CLOCK_IN);
177 if (ret < 0) 255 if (ret < 0)
178 return ret; 256 return ret;
diff --git a/sound/soc/samsung/lowland.c b/sound/soc/samsung/lowland.c
index 4adff934f771..6abf341c4a2a 100644
--- a/sound/soc/samsung/lowland.c
+++ b/sound/soc/samsung/lowland.c
@@ -21,33 +21,6 @@
21#define MCLK1_RATE (44100 * 512) 21#define MCLK1_RATE (44100 * 512)
22#define CLKOUT_RATE (44100 * 256) 22#define CLKOUT_RATE (44100 * 256)
23 23
24static int lowland_hw_params(struct snd_pcm_substream *substream,
25 struct snd_pcm_hw_params *params)
26{
27 struct snd_soc_pcm_runtime *rtd = substream->private_data;
28 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
29 struct snd_soc_dai *codec_dai = rtd->codec_dai;
30 int ret;
31
32 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
33 | SND_SOC_DAIFMT_NB_NF
34 | SND_SOC_DAIFMT_CBM_CFM);
35 if (ret < 0)
36 return ret;
37
38 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S
39 | SND_SOC_DAIFMT_NB_NF
40 | SND_SOC_DAIFMT_CBM_CFM);
41 if (ret < 0)
42 return ret;
43
44 return 0;
45}
46
47static struct snd_soc_ops lowland_ops = {
48 .hw_params = lowland_hw_params,
49};
50
51static struct snd_soc_jack lowland_headset; 24static struct snd_soc_jack lowland_headset;
52 25
53/* Headset jack detection DAPM pins */ 26/* Headset jack detection DAPM pins */
@@ -101,6 +74,25 @@ static int lowland_wm5100_init(struct snd_soc_pcm_runtime *rtd)
101 return 0; 74 return 0;
102} 75}
103 76
77static int lowland_wm9081_init(struct snd_soc_pcm_runtime *rtd)
78{
79 struct snd_soc_codec *codec = rtd->codec;
80
81 snd_soc_dapm_nc_pin(&codec->dapm, "LINEOUT");
82
83 /* At any time the WM9081 is active it will have this clock */
84 return snd_soc_codec_set_sysclk(codec, WM9081_SYSCLK_MCLK, 0,
85 CLKOUT_RATE, 0);
86}
87
88static const struct snd_soc_pcm_stream sub_params = {
89 .formats = SNDRV_PCM_FMTBIT_S32_LE,
90 .rate_min = 44100,
91 .rate_max = 44100,
92 .channels_min = 2,
93 .channels_max = 2,
94};
95
104static struct snd_soc_dai_link lowland_dai[] = { 96static struct snd_soc_dai_link lowland_dai[] = {
105 { 97 {
106 .name = "CPU", 98 .name = "CPU",
@@ -109,7 +101,8 @@ static struct snd_soc_dai_link lowland_dai[] = {
109 .codec_dai_name = "wm5100-aif1", 101 .codec_dai_name = "wm5100-aif1",
110 .platform_name = "samsung-audio", 102 .platform_name = "samsung-audio",
111 .codec_name = "wm5100.1-001a", 103 .codec_name = "wm5100.1-001a",
112 .ops = &lowland_ops, 104 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
105 SND_SOC_DAIFMT_CBM_CFM,
113 .init = lowland_wm5100_init, 106 .init = lowland_wm5100_init,
114 }, 107 },
115 { 108 {
@@ -118,24 +111,20 @@ static struct snd_soc_dai_link lowland_dai[] = {
118 .cpu_dai_name = "wm5100-aif2", 111 .cpu_dai_name = "wm5100-aif2",
119 .codec_dai_name = "wm1250-ev1", 112 .codec_dai_name = "wm1250-ev1",
120 .codec_name = "wm1250-ev1.1-0027", 113 .codec_name = "wm1250-ev1.1-0027",
121 .ops = &lowland_ops, 114 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
115 SND_SOC_DAIFMT_CBM_CFM,
122 .ignore_suspend = 1, 116 .ignore_suspend = 1,
123 }, 117 },
124};
125
126static int lowland_wm9081_init(struct snd_soc_dapm_context *dapm)
127{
128 snd_soc_dapm_nc_pin(dapm, "LINEOUT");
129
130 /* At any time the WM9081 is active it will have this clock */
131 return snd_soc_codec_set_sysclk(dapm->codec, WM9081_SYSCLK_MCLK, 0,
132 CLKOUT_RATE, 0);
133}
134
135static struct snd_soc_aux_dev lowland_aux_dev[] = {
136 { 118 {
137 .name = "wm9081", 119 .name = "Sub Speaker",
120 .stream_name = "Sub Speaker",
121 .cpu_dai_name = "wm5100-aif3",
122 .codec_dai_name = "wm9081-hifi",
138 .codec_name = "wm9081.1-006c", 123 .codec_name = "wm9081.1-006c",
124 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
125 SND_SOC_DAIFMT_CBM_CFM,
126 .ignore_suspend = 1,
127 .params = &sub_params,
139 .init = lowland_wm9081_init, 128 .init = lowland_wm9081_init,
140 }, 129 },
141}; 130};
@@ -180,8 +169,6 @@ static struct snd_soc_card lowland = {
180 .owner = THIS_MODULE, 169 .owner = THIS_MODULE,
181 .dai_link = lowland_dai, 170 .dai_link = lowland_dai,
182 .num_links = ARRAY_SIZE(lowland_dai), 171 .num_links = ARRAY_SIZE(lowland_dai),
183 .aux_dev = lowland_aux_dev,
184 .num_aux_devs = ARRAY_SIZE(lowland_aux_dev),
185 .codec_conf = lowland_codec_conf, 172 .codec_conf = lowland_codec_conf,
186 .num_configs = ARRAY_SIZE(lowland_codec_conf), 173 .num_configs = ARRAY_SIZE(lowland_codec_conf),
187 174
diff --git a/sound/soc/samsung/speyside.c b/sound/soc/samsung/speyside.c
index f9ab7707a3e4..a4a9fc7e8c76 100644
--- a/sound/soc/samsung/speyside.c
+++ b/sound/soc/samsung/speyside.c
@@ -92,33 +92,6 @@ static int speyside_set_bias_level_post(struct snd_soc_card *card,
92 return 0; 92 return 0;
93} 93}
94 94
95static int speyside_hw_params(struct snd_pcm_substream *substream,
96 struct snd_pcm_hw_params *params)
97{
98 struct snd_soc_pcm_runtime *rtd = substream->private_data;
99 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
100 struct snd_soc_dai *codec_dai = rtd->codec_dai;
101 int ret;
102
103 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
104 | SND_SOC_DAIFMT_NB_NF
105 | SND_SOC_DAIFMT_CBM_CFM);
106 if (ret < 0)
107 return ret;
108
109 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S
110 | SND_SOC_DAIFMT_NB_NF
111 | SND_SOC_DAIFMT_CBM_CFM);
112 if (ret < 0)
113 return ret;
114
115 return 0;
116}
117
118static struct snd_soc_ops speyside_ops = {
119 .hw_params = speyside_hw_params,
120};
121
122static struct snd_soc_jack speyside_headset; 95static struct snd_soc_jack speyside_headset;
123 96
124/* Headset jack detection DAPM pins */ 97/* Headset jack detection DAPM pins */
@@ -208,7 +181,8 @@ static struct snd_soc_dai_link speyside_dai[] = {
208 .platform_name = "samsung-audio", 181 .platform_name = "samsung-audio",
209 .codec_name = "wm8996.1-001a", 182 .codec_name = "wm8996.1-001a",
210 .init = speyside_wm8996_init, 183 .init = speyside_wm8996_init,
211 .ops = &speyside_ops, 184 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
185 | SND_SOC_DAIFMT_CBM_CFM,
212 }, 186 },
213 { 187 {
214 .name = "Baseband", 188 .name = "Baseband",
@@ -216,7 +190,8 @@ static struct snd_soc_dai_link speyside_dai[] = {
216 .cpu_dai_name = "wm8996-aif2", 190 .cpu_dai_name = "wm8996-aif2",
217 .codec_dai_name = "wm1250-ev1", 191 .codec_dai_name = "wm1250-ev1",
218 .codec_name = "wm1250-ev1.1-0027", 192 .codec_name = "wm1250-ev1.1-0027",
219 .ops = &speyside_ops, 193 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
194 | SND_SOC_DAIFMT_CBM_CFM,
220 .ignore_suspend = 1, 195 .ignore_suspend = 1,
221 }, 196 },
222}; 197};
diff --git a/sound/soc/sh/Kconfig b/sound/soc/sh/Kconfig
index d8e06a607a22..6bcb1164d599 100644
--- a/sound/soc/sh/Kconfig
+++ b/sound/soc/sh/Kconfig
@@ -22,6 +22,7 @@ config SND_SOC_SH4_SSI
22 22
23config SND_SOC_SH4_FSI 23config SND_SOC_SH4_FSI
24 tristate "SH4 FSI support" 24 tristate "SH4 FSI support"
25 select SND_SIMPLE_CARD
25 help 26 help
26 This option enables FSI sound support 27 This option enables FSI sound support
27 28
@@ -46,29 +47,6 @@ config SND_SH7760_AC97
46 This option enables generic sound support for the first 47 This option enables generic sound support for the first
47 AC97 unit of the SH7760. 48 AC97 unit of the SH7760.
48 49
49config SND_FSI_AK4642
50 tristate "FSI-AK4642 sound support"
51 depends on SND_SOC_SH4_FSI && I2C
52 select SND_SOC_AK4642
53 help
54 This option enables generic sound support for the
55 FSI - AK4642 unit
56
57config SND_FSI_DA7210
58 tristate "FSI-DA7210 sound support"
59 depends on SND_SOC_SH4_FSI && I2C
60 select SND_SOC_DA7210
61 help
62 This option enables generic sound support for the
63 FSI - DA7210 unit
64
65config SND_FSI_HDMI
66 tristate "FSI-HDMI sound support"
67 depends on SND_SOC_SH4_FSI && FB_SH_MOBILE_HDMI
68 help
69 This option enables generic sound support for the
70 FSI - HDMI unit
71
72config SND_SIU_MIGOR 50config SND_SIU_MIGOR
73 tristate "SIU sound support on Migo-R" 51 tristate "SIU sound support on Migo-R"
74 depends on SH_MIGOR 52 depends on SH_MIGOR
diff --git a/sound/soc/sh/Makefile b/sound/soc/sh/Makefile
index 94476d4c0fd5..849b387d17d9 100644
--- a/sound/soc/sh/Makefile
+++ b/sound/soc/sh/Makefile
@@ -14,13 +14,7 @@ obj-$(CONFIG_SND_SOC_SH4_SIU) += snd-soc-siu.o
14 14
15## boards 15## boards
16snd-soc-sh7760-ac97-objs := sh7760-ac97.o 16snd-soc-sh7760-ac97-objs := sh7760-ac97.o
17snd-soc-fsi-ak4642-objs := fsi-ak4642.o
18snd-soc-fsi-da7210-objs := fsi-da7210.o
19snd-soc-fsi-hdmi-objs := fsi-hdmi.o
20snd-soc-migor-objs := migor.o 17snd-soc-migor-objs := migor.o
21 18
22obj-$(CONFIG_SND_SH7760_AC97) += snd-soc-sh7760-ac97.o 19obj-$(CONFIG_SND_SH7760_AC97) += snd-soc-sh7760-ac97.o
23obj-$(CONFIG_SND_FSI_AK4642) += snd-soc-fsi-ak4642.o
24obj-$(CONFIG_SND_FSI_DA7210) += snd-soc-fsi-da7210.o
25obj-$(CONFIG_SND_FSI_HDMI) += snd-soc-fsi-hdmi.o
26obj-$(CONFIG_SND_SIU_MIGOR) += snd-soc-migor.o 20obj-$(CONFIG_SND_SIU_MIGOR) += snd-soc-migor.o
diff --git a/sound/soc/sh/fsi-ak4642.c b/sound/soc/sh/fsi-ak4642.c
deleted file mode 100644
index 97f540aabbdd..000000000000
--- a/sound/soc/sh/fsi-ak4642.c
+++ /dev/null
@@ -1,108 +0,0 @@
1/*
2 * FSI-AK464x sound support for ms7724se
3 *
4 * Copyright (C) 2009 Renesas Solutions Corp.
5 * Kuninori Morimoto <morimoto.kuninori@renesas.com>
6 *
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file "COPYING" in the main directory of this archive
9 * for more details.
10 */
11
12#include <linux/platform_device.h>
13#include <linux/module.h>
14#include <sound/sh_fsi.h>
15
16struct fsi_ak4642_data {
17 const char *name;
18 const char *card;
19 const char *cpu_dai;
20 const char *codec;
21 const char *platform;
22 int id;
23};
24
25static int fsi_ak4642_dai_init(struct snd_soc_pcm_runtime *rtd)
26{
27 struct snd_soc_dai *codec = rtd->codec_dai;
28 struct snd_soc_dai *cpu = rtd->cpu_dai;
29 int ret;
30
31 ret = snd_soc_dai_set_fmt(codec, SND_SOC_DAIFMT_LEFT_J |
32 SND_SOC_DAIFMT_CBM_CFM);
33 if (ret < 0)
34 return ret;
35
36 ret = snd_soc_dai_set_sysclk(codec, 0, 11289600, 0);
37 if (ret < 0)
38 return ret;
39
40 ret = snd_soc_dai_set_fmt(cpu, SND_SOC_DAIFMT_LEFT_J |
41 SND_SOC_DAIFMT_CBS_CFS);
42
43 return ret;
44}
45
46static struct snd_soc_dai_link fsi_dai_link = {
47 .codec_dai_name = "ak4642-hifi",
48 .init = fsi_ak4642_dai_init,
49};
50
51static struct snd_soc_card fsi_soc_card = {
52 .owner = THIS_MODULE,
53 .dai_link = &fsi_dai_link,
54 .num_links = 1,
55};
56
57static struct platform_device *fsi_snd_device;
58
59static int fsi_ak4642_probe(struct platform_device *pdev)
60{
61 int ret = -ENOMEM;
62 struct fsi_ak4642_info *pinfo = pdev->dev.platform_data;
63
64 if (!pinfo) {
65 dev_err(&pdev->dev, "no info for fsi ak4642\n");
66 goto out;
67 }
68
69 fsi_snd_device = platform_device_alloc("soc-audio", pinfo->id);
70 if (!fsi_snd_device)
71 goto out;
72
73 fsi_dai_link.name = pinfo->name;
74 fsi_dai_link.stream_name = pinfo->name;
75 fsi_dai_link.cpu_dai_name = pinfo->cpu_dai;
76 fsi_dai_link.platform_name = pinfo->platform;
77 fsi_dai_link.codec_name = pinfo->codec;
78 fsi_soc_card.name = pinfo->card;
79
80 platform_set_drvdata(fsi_snd_device, &fsi_soc_card);
81 ret = platform_device_add(fsi_snd_device);
82
83 if (ret)
84 platform_device_put(fsi_snd_device);
85
86out:
87 return ret;
88}
89
90static int fsi_ak4642_remove(struct platform_device *pdev)
91{
92 platform_device_unregister(fsi_snd_device);
93 return 0;
94}
95
96static struct platform_driver fsi_ak4642 = {
97 .driver = {
98 .name = "fsi-ak4642-audio",
99 },
100 .probe = fsi_ak4642_probe,
101 .remove = fsi_ak4642_remove,
102};
103
104module_platform_driver(fsi_ak4642);
105
106MODULE_LICENSE("GPL");
107MODULE_DESCRIPTION("Generic SH4 FSI-AK4642 sound card");
108MODULE_AUTHOR("Kuninori Morimoto <morimoto.kuninori@renesas.com>");
diff --git a/sound/soc/sh/fsi-da7210.c b/sound/soc/sh/fsi-da7210.c
deleted file mode 100644
index 1dd3354c7411..000000000000
--- a/sound/soc/sh/fsi-da7210.c
+++ /dev/null
@@ -1,81 +0,0 @@
1/*
2 * fsi-da7210.c
3 *
4 * Copyright (C) 2009 Renesas Solutions Corp.
5 * Kuninori Morimoto <morimoto.kuninori@renesas.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 */
12
13#include <linux/platform_device.h>
14#include <linux/module.h>
15#include <sound/sh_fsi.h>
16
17static int fsi_da7210_init(struct snd_soc_pcm_runtime *rtd)
18{
19 struct snd_soc_dai *codec = rtd->codec_dai;
20 struct snd_soc_dai *cpu = rtd->cpu_dai;
21 int ret;
22
23 ret = snd_soc_dai_set_fmt(codec,
24 SND_SOC_DAIFMT_I2S |
25 SND_SOC_DAIFMT_CBM_CFM);
26 if (ret < 0)
27 return ret;
28
29 ret = snd_soc_dai_set_fmt(cpu, SND_SOC_DAIFMT_I2S |
30 SND_SOC_DAIFMT_CBS_CFS);
31
32 return ret;
33}
34
35static struct snd_soc_dai_link fsi_da7210_dai = {
36 .name = "DA7210",
37 .stream_name = "DA7210",
38 .cpu_dai_name = "fsib-dai", /* FSI B */
39 .codec_dai_name = "da7210-hifi",
40 .platform_name = "sh_fsi.0",
41 .codec_name = "da7210-codec.0-001a",
42 .init = fsi_da7210_init,
43};
44
45static struct snd_soc_card fsi_soc_card = {
46 .name = "FSI-DA7210",
47 .owner = THIS_MODULE,
48 .dai_link = &fsi_da7210_dai,
49 .num_links = 1,
50};
51
52static struct platform_device *fsi_da7210_snd_device;
53
54static int __init fsi_da7210_sound_init(void)
55{
56 int ret;
57
58 fsi_da7210_snd_device = platform_device_alloc("soc-audio", FSI_PORT_B);
59 if (!fsi_da7210_snd_device)
60 return -ENOMEM;
61
62 platform_set_drvdata(fsi_da7210_snd_device, &fsi_soc_card);
63 ret = platform_device_add(fsi_da7210_snd_device);
64 if (ret)
65 platform_device_put(fsi_da7210_snd_device);
66
67 return ret;
68}
69
70static void __exit fsi_da7210_sound_exit(void)
71{
72 platform_device_unregister(fsi_da7210_snd_device);
73}
74
75module_init(fsi_da7210_sound_init);
76module_exit(fsi_da7210_sound_exit);
77
78/* Module information */
79MODULE_DESCRIPTION("ALSA SoC FSI DA2710");
80MODULE_AUTHOR("Kuninori Morimoto <morimoto.kuninori@renesas.com>");
81MODULE_LICENSE("GPL");
diff --git a/sound/soc/sh/fsi-hdmi.c b/sound/soc/sh/fsi-hdmi.c
deleted file mode 100644
index 6e41908323e8..000000000000
--- a/sound/soc/sh/fsi-hdmi.c
+++ /dev/null
@@ -1,118 +0,0 @@
1/*
2 * FSI - HDMI sound support
3 *
4 * Copyright (C) 2010 Renesas Solutions Corp.
5 * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
6 *
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file "COPYING" in the main directory of this archive
9 * for more details.
10 */
11
12#include <linux/platform_device.h>
13#include <linux/module.h>
14#include <sound/sh_fsi.h>
15
16struct fsi_hdmi_data {
17 const char *cpu_dai;
18 const char *card;
19 int id;
20};
21
22static int fsi_hdmi_dai_init(struct snd_soc_pcm_runtime *rtd)
23{
24 struct snd_soc_dai *cpu = rtd->cpu_dai;
25 int ret;
26
27 ret = snd_soc_dai_set_fmt(cpu, SND_SOC_DAIFMT_CBM_CFM);
28
29 return ret;
30}
31
32static struct snd_soc_dai_link fsi_dai_link = {
33 .name = "HDMI",
34 .stream_name = "HDMI",
35 .codec_dai_name = "sh_mobile_hdmi-hifi",
36 .platform_name = "sh_fsi2",
37 .codec_name = "sh-mobile-hdmi",
38 .init = fsi_hdmi_dai_init,
39};
40
41static struct snd_soc_card fsi_soc_card = {
42 .owner = THIS_MODULE,
43 .dai_link = &fsi_dai_link,
44 .num_links = 1,
45};
46
47static struct platform_device *fsi_snd_device;
48
49static int fsi_hdmi_probe(struct platform_device *pdev)
50{
51 int ret = -ENOMEM;
52 const struct platform_device_id *id_entry;
53 struct fsi_hdmi_data *pdata;
54
55 id_entry = pdev->id_entry;
56 if (!id_entry) {
57 dev_err(&pdev->dev, "unknown fsi hdmi\n");
58 return -ENODEV;
59 }
60
61 pdata = (struct fsi_hdmi_data *)id_entry->driver_data;
62
63 fsi_snd_device = platform_device_alloc("soc-audio", pdata->id);
64 if (!fsi_snd_device)
65 goto out;
66
67 fsi_dai_link.cpu_dai_name = pdata->cpu_dai;
68 fsi_soc_card.name = pdata->card;
69
70 platform_set_drvdata(fsi_snd_device, &fsi_soc_card);
71 ret = platform_device_add(fsi_snd_device);
72
73 if (ret)
74 platform_device_put(fsi_snd_device);
75
76out:
77 return ret;
78}
79
80static int fsi_hdmi_remove(struct platform_device *pdev)
81{
82 platform_device_unregister(fsi_snd_device);
83 return 0;
84}
85
86static struct fsi_hdmi_data fsi2_a_hdmi = {
87 .cpu_dai = "fsia-dai",
88 .card = "FSI2A-HDMI",
89 .id = FSI_PORT_A,
90};
91
92static struct fsi_hdmi_data fsi2_b_hdmi = {
93 .cpu_dai = "fsib-dai",
94 .card = "FSI2B-HDMI",
95 .id = FSI_PORT_B,
96};
97
98static struct platform_device_id fsi_id_table[] = {
99 /* FSI 2 */
100 { "sh_fsi2_a_hdmi", (kernel_ulong_t)&fsi2_a_hdmi },
101 { "sh_fsi2_b_hdmi", (kernel_ulong_t)&fsi2_b_hdmi },
102 {},
103};
104
105static struct platform_driver fsi_hdmi = {
106 .driver = {
107 .name = "fsi-hdmi-audio",
108 },
109 .probe = fsi_hdmi_probe,
110 .remove = fsi_hdmi_remove,
111 .id_table = fsi_id_table,
112};
113
114module_platform_driver(fsi_hdmi);
115
116MODULE_LICENSE("GPL");
117MODULE_DESCRIPTION("Generic SH4 FSI-HDMI sound card");
118MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>");
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index b390f00b4e99..b37ee8077ed1 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -39,6 +39,7 @@
39#include <sound/pcm.h> 39#include <sound/pcm.h>
40#include <sound/pcm_params.h> 40#include <sound/pcm_params.h>
41#include <sound/soc.h> 41#include <sound/soc.h>
42#include <sound/soc-dpcm.h>
42#include <sound/initval.h> 43#include <sound/initval.h>
43 44
44#define CREATE_TRACE_POINTS 45#define CREATE_TRACE_POINTS
@@ -54,7 +55,6 @@ EXPORT_SYMBOL_GPL(snd_soc_debugfs_root);
54#endif 55#endif
55 56
56static DEFINE_MUTEX(client_mutex); 57static DEFINE_MUTEX(client_mutex);
57static LIST_HEAD(card_list);
58static LIST_HEAD(dai_list); 58static LIST_HEAD(dai_list);
59static LIST_HEAD(platform_list); 59static LIST_HEAD(platform_list);
60static LIST_HEAD(codec_list); 60static LIST_HEAD(codec_list);
@@ -201,12 +201,6 @@ static ssize_t pmdown_time_set(struct device *dev,
201static DEVICE_ATTR(pmdown_time, 0644, pmdown_time_show, pmdown_time_set); 201static DEVICE_ATTR(pmdown_time, 0644, pmdown_time_show, pmdown_time_set);
202 202
203#ifdef CONFIG_DEBUG_FS 203#ifdef CONFIG_DEBUG_FS
204static int codec_reg_open_file(struct inode *inode, struct file *file)
205{
206 file->private_data = inode->i_private;
207 return 0;
208}
209
210static ssize_t codec_reg_read_file(struct file *file, char __user *user_buf, 204static ssize_t codec_reg_read_file(struct file *file, char __user *user_buf,
211 size_t count, loff_t *ppos) 205 size_t count, loff_t *ppos)
212{ 206{
@@ -264,7 +258,7 @@ static ssize_t codec_reg_write_file(struct file *file,
264} 258}
265 259
266static const struct file_operations codec_reg_fops = { 260static const struct file_operations codec_reg_fops = {
267 .open = codec_reg_open_file, 261 .open = simple_open,
268 .read = codec_reg_read_file, 262 .read = codec_reg_read_file,
269 .write = codec_reg_write_file, 263 .write = codec_reg_write_file,
270 .llseek = default_llseek, 264 .llseek = default_llseek,
@@ -471,6 +465,35 @@ static inline void soc_cleanup_card_debugfs(struct snd_soc_card *card)
471} 465}
472#endif 466#endif
473 467
468struct snd_pcm_substream *snd_soc_get_dai_substream(struct snd_soc_card *card,
469 const char *dai_link, int stream)
470{
471 int i;
472
473 for (i = 0; i < card->num_links; i++) {
474 if (card->rtd[i].dai_link->no_pcm &&
475 !strcmp(card->rtd[i].dai_link->name, dai_link))
476 return card->rtd[i].pcm->streams[stream].substream;
477 }
478 dev_dbg(card->dev, "failed to find dai link %s\n", dai_link);
479 return NULL;
480}
481EXPORT_SYMBOL_GPL(snd_soc_get_dai_substream);
482
483struct snd_soc_pcm_runtime *snd_soc_get_pcm_runtime(struct snd_soc_card *card,
484 const char *dai_link)
485{
486 int i;
487
488 for (i = 0; i < card->num_links; i++) {
489 if (!strcmp(card->rtd[i].dai_link->name, dai_link))
490 return &card->rtd[i];
491 }
492 dev_dbg(card->dev, "failed to find rtd %s\n", dai_link);
493 return NULL;
494}
495EXPORT_SYMBOL_GPL(snd_soc_get_pcm_runtime);
496
474#ifdef CONFIG_SND_SOC_AC97_BUS 497#ifdef CONFIG_SND_SOC_AC97_BUS
475/* unregister ac97 codec */ 498/* unregister ac97 codec */
476static int soc_ac97_dev_unregister(struct snd_soc_codec *codec) 499static int soc_ac97_dev_unregister(struct snd_soc_codec *codec)
@@ -573,19 +596,16 @@ int snd_soc_suspend(struct device *dev)
573 } 596 }
574 597
575 for (i = 0; i < card->num_rtd; i++) { 598 for (i = 0; i < card->num_rtd; i++) {
576 struct snd_soc_dai *codec_dai = card->rtd[i].codec_dai;
577 599
578 if (card->rtd[i].dai_link->ignore_suspend) 600 if (card->rtd[i].dai_link->ignore_suspend)
579 continue; 601 continue;
580 602
581 snd_soc_dapm_stream_event(&card->rtd[i], 603 snd_soc_dapm_stream_event(&card->rtd[i],
582 SNDRV_PCM_STREAM_PLAYBACK, 604 SNDRV_PCM_STREAM_PLAYBACK,
583 codec_dai,
584 SND_SOC_DAPM_STREAM_SUSPEND); 605 SND_SOC_DAPM_STREAM_SUSPEND);
585 606
586 snd_soc_dapm_stream_event(&card->rtd[i], 607 snd_soc_dapm_stream_event(&card->rtd[i],
587 SNDRV_PCM_STREAM_CAPTURE, 608 SNDRV_PCM_STREAM_CAPTURE,
588 codec_dai,
589 SND_SOC_DAPM_STREAM_SUSPEND); 609 SND_SOC_DAPM_STREAM_SUSPEND);
590 } 610 }
591 611
@@ -689,17 +709,16 @@ static void soc_resume_deferred(struct work_struct *work)
689 } 709 }
690 710
691 for (i = 0; i < card->num_rtd; i++) { 711 for (i = 0; i < card->num_rtd; i++) {
692 struct snd_soc_dai *codec_dai = card->rtd[i].codec_dai;
693 712
694 if (card->rtd[i].dai_link->ignore_suspend) 713 if (card->rtd[i].dai_link->ignore_suspend)
695 continue; 714 continue;
696 715
697 snd_soc_dapm_stream_event(&card->rtd[i], 716 snd_soc_dapm_stream_event(&card->rtd[i],
698 SNDRV_PCM_STREAM_PLAYBACK, codec_dai, 717 SNDRV_PCM_STREAM_PLAYBACK,
699 SND_SOC_DAPM_STREAM_RESUME); 718 SND_SOC_DAPM_STREAM_RESUME);
700 719
701 snd_soc_dapm_stream_event(&card->rtd[i], 720 snd_soc_dapm_stream_event(&card->rtd[i],
702 SNDRV_PCM_STREAM_CAPTURE, codec_dai, 721 SNDRV_PCM_STREAM_CAPTURE,
703 SND_SOC_DAPM_STREAM_RESUME); 722 SND_SOC_DAPM_STREAM_RESUME);
704 } 723 }
705 724
@@ -789,15 +808,9 @@ static int soc_bind_dai_link(struct snd_soc_card *card, int num)
789 struct snd_soc_dai *codec_dai, *cpu_dai; 808 struct snd_soc_dai *codec_dai, *cpu_dai;
790 const char *platform_name; 809 const char *platform_name;
791 810
792 if (rtd->complete)
793 return 1;
794 dev_dbg(card->dev, "binding %s at idx %d\n", dai_link->name, num); 811 dev_dbg(card->dev, "binding %s at idx %d\n", dai_link->name, num);
795 812
796 /* do we already have the CPU DAI for this link ? */ 813 /* Find CPU DAI from registered DAIs*/
797 if (rtd->cpu_dai) {
798 goto find_codec;
799 }
800 /* no, then find CPU DAI from registered DAIs*/
801 list_for_each_entry(cpu_dai, &dai_list, list) { 814 list_for_each_entry(cpu_dai, &dai_list, list) {
802 if (dai_link->cpu_dai_of_node) { 815 if (dai_link->cpu_dai_of_node) {
803 if (cpu_dai->dev->of_node != dai_link->cpu_dai_of_node) 816 if (cpu_dai->dev->of_node != dai_link->cpu_dai_of_node)
@@ -808,18 +821,15 @@ static int soc_bind_dai_link(struct snd_soc_card *card, int num)
808 } 821 }
809 822
810 rtd->cpu_dai = cpu_dai; 823 rtd->cpu_dai = cpu_dai;
811 goto find_codec;
812 } 824 }
813 dev_dbg(card->dev, "CPU DAI %s not registered\n",
814 dai_link->cpu_dai_name);
815 825
816find_codec: 826 if (!rtd->cpu_dai) {
817 /* do we already have the CODEC for this link ? */ 827 dev_dbg(card->dev, "CPU DAI %s not registered\n",
818 if (rtd->codec) { 828 dai_link->cpu_dai_name);
819 goto find_platform; 829 return -EPROBE_DEFER;
820 } 830 }
821 831
822 /* no, then find CODEC from registered CODECs*/ 832 /* Find CODEC from registered CODECs */
823 list_for_each_entry(codec, &codec_list, list) { 833 list_for_each_entry(codec, &codec_list, list) {
824 if (dai_link->codec_of_node) { 834 if (dai_link->codec_of_node) {
825 if (codec->dev->of_node != dai_link->codec_of_node) 835 if (codec->dev->of_node != dai_link->codec_of_node)
@@ -841,28 +851,28 @@ find_codec:
841 dai_link->codec_dai_name)) { 851 dai_link->codec_dai_name)) {
842 852
843 rtd->codec_dai = codec_dai; 853 rtd->codec_dai = codec_dai;
844 goto find_platform;
845 } 854 }
846 } 855 }
847 dev_dbg(card->dev, "CODEC DAI %s not registered\n",
848 dai_link->codec_dai_name);
849 856
850 goto find_platform; 857 if (!rtd->codec_dai) {
858 dev_dbg(card->dev, "CODEC DAI %s not registered\n",
859 dai_link->codec_dai_name);
860 return -EPROBE_DEFER;
861 }
851 } 862 }
852 dev_dbg(card->dev, "CODEC %s not registered\n",
853 dai_link->codec_name);
854 863
855find_platform: 864 if (!rtd->codec) {
856 /* do we need a platform? */ 865 dev_dbg(card->dev, "CODEC %s not registered\n",
857 if (rtd->platform) 866 dai_link->codec_name);
858 goto out; 867 return -EPROBE_DEFER;
868 }
859 869
860 /* if there's no platform we match on the empty platform */ 870 /* if there's no platform we match on the empty platform */
861 platform_name = dai_link->platform_name; 871 platform_name = dai_link->platform_name;
862 if (!platform_name && !dai_link->platform_of_node) 872 if (!platform_name && !dai_link->platform_of_node)
863 platform_name = "snd-soc-dummy"; 873 platform_name = "snd-soc-dummy";
864 874
865 /* no, then find one from the set of registered platforms */ 875 /* find one from the set of registered platforms */
866 list_for_each_entry(platform, &platform_list, list) { 876 list_for_each_entry(platform, &platform_list, list) {
867 if (dai_link->platform_of_node) { 877 if (dai_link->platform_of_node) {
868 if (platform->dev->of_node != 878 if (platform->dev->of_node !=
@@ -874,20 +884,16 @@ find_platform:
874 } 884 }
875 885
876 rtd->platform = platform; 886 rtd->platform = platform;
877 goto out;
878 } 887 }
879 888 if (!rtd->platform) {
880 dev_dbg(card->dev, "platform %s not registered\n", 889 dev_dbg(card->dev, "platform %s not registered\n",
881 dai_link->platform_name); 890 dai_link->platform_name);
882 return 0; 891 return -EPROBE_DEFER;
883
884out:
885 /* mark rtd as complete if we found all 4 of our client devices */
886 if (rtd->codec && rtd->codec_dai && rtd->platform && rtd->cpu_dai) {
887 rtd->complete = 1;
888 card->num_rtd++;
889 } 892 }
890 return 1; 893
894 card->num_rtd++;
895
896 return 0;
891} 897}
892 898
893static void soc_remove_codec(struct snd_soc_codec *codec) 899static void soc_remove_codec(struct snd_soc_codec *codec)
@@ -1074,6 +1080,7 @@ static int soc_probe_platform(struct snd_soc_card *card,
1074{ 1080{
1075 int ret = 0; 1081 int ret = 0;
1076 const struct snd_soc_platform_driver *driver = platform->driver; 1082 const struct snd_soc_platform_driver *driver = platform->driver;
1083 struct snd_soc_dai *dai;
1077 1084
1078 platform->card = card; 1085 platform->card = card;
1079 platform->dapm.card = card; 1086 platform->dapm.card = card;
@@ -1087,6 +1094,14 @@ static int soc_probe_platform(struct snd_soc_card *card,
1087 snd_soc_dapm_new_controls(&platform->dapm, 1094 snd_soc_dapm_new_controls(&platform->dapm,
1088 driver->dapm_widgets, driver->num_dapm_widgets); 1095 driver->dapm_widgets, driver->num_dapm_widgets);
1089 1096
1097 /* Create DAPM widgets for each DAI stream */
1098 list_for_each_entry(dai, &dai_list, list) {
1099 if (dai->dev != platform->dev)
1100 continue;
1101
1102 snd_soc_dapm_new_dai_widgets(&platform->dapm, dai);
1103 }
1104
1090 platform->dapm.idle_bias_off = 1; 1105 platform->dapm.idle_bias_off = 1;
1091 1106
1092 if (driver->probe) { 1107 if (driver->probe) {
@@ -1176,6 +1191,10 @@ static int soc_post_component_init(struct snd_soc_card *card,
1176 rtd->dev->init_name = name; 1191 rtd->dev->init_name = name;
1177 dev_set_drvdata(rtd->dev, rtd); 1192 dev_set_drvdata(rtd->dev, rtd);
1178 mutex_init(&rtd->pcm_mutex); 1193 mutex_init(&rtd->pcm_mutex);
1194 INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].be_clients);
1195 INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].be_clients);
1196 INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].fe_clients);
1197 INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].fe_clients);
1179 ret = device_add(rtd->dev); 1198 ret = device_add(rtd->dev);
1180 if (ret < 0) { 1199 if (ret < 0) {
1181 dev_err(card->dev, 1200 dev_err(card->dev,
@@ -1197,6 +1216,17 @@ static int soc_post_component_init(struct snd_soc_card *card,
1197 dev_err(codec->dev, 1216 dev_err(codec->dev,
1198 "asoc: failed to add codec sysfs files: %d\n", ret); 1217 "asoc: failed to add codec sysfs files: %d\n", ret);
1199 1218
1219#ifdef CONFIG_DEBUG_FS
1220 /* add DPCM sysfs entries */
1221 if (!dailess && !dai_link->dynamic)
1222 goto out;
1223
1224 ret = soc_dpcm_debugfs_add(rtd);
1225 if (ret < 0)
1226 dev_err(rtd->dev, "asoc: failed to add dpcm sysfs entries: %d\n", ret);
1227
1228out:
1229#endif
1200 return 0; 1230 return 0;
1201} 1231}
1202 1232
@@ -1206,14 +1236,15 @@ static int soc_probe_dai_link(struct snd_soc_card *card, int num, int order)
1206 struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; 1236 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
1207 struct snd_soc_codec *codec = rtd->codec; 1237 struct snd_soc_codec *codec = rtd->codec;
1208 struct snd_soc_platform *platform = rtd->platform; 1238 struct snd_soc_platform *platform = rtd->platform;
1209 struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai; 1239 struct snd_soc_dai *codec_dai = rtd->codec_dai;
1240 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1241 struct snd_soc_dapm_widget *play_w, *capture_w;
1210 int ret; 1242 int ret;
1211 1243
1212 dev_dbg(card->dev, "probe %s dai link %d late %d\n", 1244 dev_dbg(card->dev, "probe %s dai link %d late %d\n",
1213 card->name, num, order); 1245 card->name, num, order);
1214 1246
1215 /* config components */ 1247 /* config components */
1216 codec_dai->codec = codec;
1217 cpu_dai->platform = platform; 1248 cpu_dai->platform = platform;
1218 codec_dai->card = card; 1249 codec_dai->card = card;
1219 cpu_dai->card = card; 1250 cpu_dai->card = card;
@@ -1224,9 +1255,12 @@ static int soc_probe_dai_link(struct snd_soc_card *card, int num, int order)
1224 /* probe the cpu_dai */ 1255 /* probe the cpu_dai */
1225 if (!cpu_dai->probed && 1256 if (!cpu_dai->probed &&
1226 cpu_dai->driver->probe_order == order) { 1257 cpu_dai->driver->probe_order == order) {
1258 cpu_dai->dapm.card = card;
1227 if (!try_module_get(cpu_dai->dev->driver->owner)) 1259 if (!try_module_get(cpu_dai->dev->driver->owner))
1228 return -ENODEV; 1260 return -ENODEV;
1229 1261
1262 snd_soc_dapm_new_dai_widgets(&cpu_dai->dapm, cpu_dai);
1263
1230 if (cpu_dai->driver->probe) { 1264 if (cpu_dai->driver->probe) {
1231 ret = cpu_dai->driver->probe(cpu_dai); 1265 ret = cpu_dai->driver->probe(cpu_dai);
1232 if (ret < 0) { 1266 if (ret < 0) {
@@ -1285,12 +1319,39 @@ static int soc_probe_dai_link(struct snd_soc_card *card, int num, int order)
1285 if (ret < 0) 1319 if (ret < 0)
1286 pr_warn("asoc: failed to add pmdown_time sysfs:%d\n", ret); 1320 pr_warn("asoc: failed to add pmdown_time sysfs:%d\n", ret);
1287 1321
1288 /* create the pcm */ 1322 if (!dai_link->params) {
1289 ret = soc_new_pcm(rtd, num); 1323 /* create the pcm */
1290 if (ret < 0) { 1324 ret = soc_new_pcm(rtd, num);
1291 pr_err("asoc: can't create pcm %s :%d\n", 1325 if (ret < 0) {
1292 dai_link->stream_name, ret); 1326 pr_err("asoc: can't create pcm %s :%d\n",
1293 return ret; 1327 dai_link->stream_name, ret);
1328 return ret;
1329 }
1330 } else {
1331 /* link the DAI widgets */
1332 play_w = codec_dai->playback_widget;
1333 capture_w = cpu_dai->capture_widget;
1334 if (play_w && capture_w) {
1335 ret = snd_soc_dapm_new_pcm(card, dai_link->params,
1336 capture_w, play_w);
1337 if (ret != 0) {
1338 dev_err(card->dev, "Can't link %s to %s: %d\n",
1339 play_w->name, capture_w->name, ret);
1340 return ret;
1341 }
1342 }
1343
1344 play_w = cpu_dai->playback_widget;
1345 capture_w = codec_dai->capture_widget;
1346 if (play_w && capture_w) {
1347 ret = snd_soc_dapm_new_pcm(card, dai_link->params,
1348 capture_w, play_w);
1349 if (ret != 0) {
1350 dev_err(card->dev, "Can't link %s to %s: %d\n",
1351 play_w->name, capture_w->name, ret);
1352 return ret;
1353 }
1354 }
1294 } 1355 }
1295 1356
1296 /* add platform data for AC97 devices */ 1357 /* add platform data for AC97 devices */
@@ -1340,6 +1401,20 @@ static void soc_unregister_ac97_dai_link(struct snd_soc_codec *codec)
1340} 1401}
1341#endif 1402#endif
1342 1403
1404static int soc_check_aux_dev(struct snd_soc_card *card, int num)
1405{
1406 struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num];
1407 struct snd_soc_codec *codec;
1408
1409 /* find CODEC from registered CODECs*/
1410 list_for_each_entry(codec, &codec_list, list) {
1411 if (!strcmp(codec->name, aux_dev->codec_name))
1412 return 0;
1413 }
1414
1415 return -EPROBE_DEFER;
1416}
1417
1343static int soc_probe_aux_dev(struct snd_soc_card *card, int num) 1418static int soc_probe_aux_dev(struct snd_soc_card *card, int num)
1344{ 1419{
1345 struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num]; 1420 struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num];
@@ -1360,7 +1435,7 @@ static int soc_probe_aux_dev(struct snd_soc_card *card, int num)
1360 } 1435 }
1361 /* codec not found */ 1436 /* codec not found */
1362 dev_err(card->dev, "asoc: codec %s not found", aux_dev->codec_name); 1437 dev_err(card->dev, "asoc: codec %s not found", aux_dev->codec_name);
1363 goto out; 1438 return -EPROBE_DEFER;
1364 1439
1365found: 1440found:
1366 ret = soc_probe_codec(card, codec); 1441 ret = soc_probe_codec(card, codec);
@@ -1410,29 +1485,28 @@ static int snd_soc_init_codec_cache(struct snd_soc_codec *codec,
1410 return 0; 1485 return 0;
1411} 1486}
1412 1487
1413static void snd_soc_instantiate_card(struct snd_soc_card *card) 1488static int snd_soc_instantiate_card(struct snd_soc_card *card)
1414{ 1489{
1415 struct snd_soc_codec *codec; 1490 struct snd_soc_codec *codec;
1416 struct snd_soc_codec_conf *codec_conf; 1491 struct snd_soc_codec_conf *codec_conf;
1417 enum snd_soc_compress_type compress_type; 1492 enum snd_soc_compress_type compress_type;
1418 struct snd_soc_dai_link *dai_link; 1493 struct snd_soc_dai_link *dai_link;
1419 int ret, i, order; 1494 int ret, i, order, dai_fmt;
1420
1421 mutex_lock(&card->mutex);
1422 1495
1423 if (card->instantiated) { 1496 mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_INIT);
1424 mutex_unlock(&card->mutex);
1425 return;
1426 }
1427 1497
1428 /* bind DAIs */ 1498 /* bind DAIs */
1429 for (i = 0; i < card->num_links; i++) 1499 for (i = 0; i < card->num_links; i++) {
1430 soc_bind_dai_link(card, i); 1500 ret = soc_bind_dai_link(card, i);
1501 if (ret != 0)
1502 goto base_error;
1503 }
1431 1504
1432 /* bind completed ? */ 1505 /* check aux_devs too */
1433 if (card->num_rtd != card->num_links) { 1506 for (i = 0; i < card->num_aux_devs; i++) {
1434 mutex_unlock(&card->mutex); 1507 ret = soc_check_aux_dev(card, i);
1435 return; 1508 if (ret != 0)
1509 goto base_error;
1436 } 1510 }
1437 1511
1438 /* initialize the register cache for each available codec */ 1512 /* initialize the register cache for each available codec */
@@ -1452,10 +1526,8 @@ static void snd_soc_instantiate_card(struct snd_soc_card *card)
1452 } 1526 }
1453 } 1527 }
1454 ret = snd_soc_init_codec_cache(codec, compress_type); 1528 ret = snd_soc_init_codec_cache(codec, compress_type);
1455 if (ret < 0) { 1529 if (ret < 0)
1456 mutex_unlock(&card->mutex); 1530 goto base_error;
1457 return;
1458 }
1459 } 1531 }
1460 1532
1461 /* card bind complete so register a sound card */ 1533 /* card bind complete so register a sound card */
@@ -1464,8 +1536,7 @@ static void snd_soc_instantiate_card(struct snd_soc_card *card)
1464 if (ret < 0) { 1536 if (ret < 0) {
1465 pr_err("asoc: can't create sound card for card %s: %d\n", 1537 pr_err("asoc: can't create sound card for card %s: %d\n",
1466 card->name, ret); 1538 card->name, ret);
1467 mutex_unlock(&card->mutex); 1539 goto base_error;
1468 return;
1469 } 1540 }
1470 card->snd_card->dev = card->dev; 1541 card->snd_card->dev = card->dev;
1471 1542
@@ -1529,17 +1600,47 @@ static void snd_soc_instantiate_card(struct snd_soc_card *card)
1529 1600
1530 for (i = 0; i < card->num_links; i++) { 1601 for (i = 0; i < card->num_links; i++) {
1531 dai_link = &card->dai_link[i]; 1602 dai_link = &card->dai_link[i];
1603 dai_fmt = dai_link->dai_fmt;
1532 1604
1533 if (dai_link->dai_fmt) { 1605 if (dai_fmt) {
1534 ret = snd_soc_dai_set_fmt(card->rtd[i].codec_dai, 1606 ret = snd_soc_dai_set_fmt(card->rtd[i].codec_dai,
1535 dai_link->dai_fmt); 1607 dai_fmt);
1536 if (ret != 0 && ret != -ENOTSUPP) 1608 if (ret != 0 && ret != -ENOTSUPP)
1537 dev_warn(card->rtd[i].codec_dai->dev, 1609 dev_warn(card->rtd[i].codec_dai->dev,
1538 "Failed to set DAI format: %d\n", 1610 "Failed to set DAI format: %d\n",
1539 ret); 1611 ret);
1612 }
1540 1613
1614 /* If this is a regular CPU link there will be a platform */
1615 if (dai_fmt &&
1616 (dai_link->platform_name || dai_link->platform_of_node)) {
1541 ret = snd_soc_dai_set_fmt(card->rtd[i].cpu_dai, 1617 ret = snd_soc_dai_set_fmt(card->rtd[i].cpu_dai,
1542 dai_link->dai_fmt); 1618 dai_fmt);
1619 if (ret != 0 && ret != -ENOTSUPP)
1620 dev_warn(card->rtd[i].cpu_dai->dev,
1621 "Failed to set DAI format: %d\n",
1622 ret);
1623 } else if (dai_fmt) {
1624 /* Flip the polarity for the "CPU" end */
1625 dai_fmt &= ~SND_SOC_DAIFMT_MASTER_MASK;
1626 switch (dai_link->dai_fmt &
1627 SND_SOC_DAIFMT_MASTER_MASK) {
1628 case SND_SOC_DAIFMT_CBM_CFM:
1629 dai_fmt |= SND_SOC_DAIFMT_CBS_CFS;
1630 break;
1631 case SND_SOC_DAIFMT_CBM_CFS:
1632 dai_fmt |= SND_SOC_DAIFMT_CBS_CFM;
1633 break;
1634 case SND_SOC_DAIFMT_CBS_CFM:
1635 dai_fmt |= SND_SOC_DAIFMT_CBM_CFS;
1636 break;
1637 case SND_SOC_DAIFMT_CBS_CFS:
1638 dai_fmt |= SND_SOC_DAIFMT_CBM_CFM;
1639 break;
1640 }
1641
1642 ret = snd_soc_dai_set_fmt(card->rtd[i].cpu_dai,
1643 dai_fmt);
1543 if (ret != 0 && ret != -ENOTSUPP) 1644 if (ret != 0 && ret != -ENOTSUPP)
1544 dev_warn(card->rtd[i].cpu_dai->dev, 1645 dev_warn(card->rtd[i].cpu_dai->dev,
1545 "Failed to set DAI format: %d\n", 1646 "Failed to set DAI format: %d\n",
@@ -1605,7 +1706,8 @@ static void snd_soc_instantiate_card(struct snd_soc_card *card)
1605 card->instantiated = 1; 1706 card->instantiated = 1;
1606 snd_soc_dapm_sync(&card->dapm); 1707 snd_soc_dapm_sync(&card->dapm);
1607 mutex_unlock(&card->mutex); 1708 mutex_unlock(&card->mutex);
1608 return; 1709
1710 return 0;
1609 1711
1610probe_aux_dev_err: 1712probe_aux_dev_err:
1611 for (i = 0; i < card->num_aux_devs; i++) 1713 for (i = 0; i < card->num_aux_devs; i++)
@@ -1620,18 +1722,10 @@ card_probe_error:
1620 1722
1621 snd_card_free(card->snd_card); 1723 snd_card_free(card->snd_card);
1622 1724
1725base_error:
1623 mutex_unlock(&card->mutex); 1726 mutex_unlock(&card->mutex);
1624}
1625 1727
1626/* 1728 return ret;
1627 * Attempt to initialise any uninitialised cards. Must be called with
1628 * client_mutex.
1629 */
1630static void snd_soc_instantiate_cards(void)
1631{
1632 struct snd_soc_card *card;
1633 list_for_each_entry(card, &card_list, list)
1634 snd_soc_instantiate_card(card);
1635} 1729}
1636 1730
1637/* probes a new socdev */ 1731/* probes a new socdev */
@@ -2533,6 +2627,87 @@ int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
2533EXPORT_SYMBOL_GPL(snd_soc_put_volsw); 2627EXPORT_SYMBOL_GPL(snd_soc_put_volsw);
2534 2628
2535/** 2629/**
2630 * snd_soc_get_volsw_sx - single mixer get callback
2631 * @kcontrol: mixer control
2632 * @ucontrol: control element information
2633 *
2634 * Callback to get the value of a single mixer control, or a double mixer
2635 * control that spans 2 registers.
2636 *
2637 * Returns 0 for success.
2638 */
2639int snd_soc_get_volsw_sx(struct snd_kcontrol *kcontrol,
2640 struct snd_ctl_elem_value *ucontrol)
2641{
2642 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2643 struct soc_mixer_control *mc =
2644 (struct soc_mixer_control *)kcontrol->private_value;
2645
2646 unsigned int reg = mc->reg;
2647 unsigned int reg2 = mc->rreg;
2648 unsigned int shift = mc->shift;
2649 unsigned int rshift = mc->rshift;
2650 int max = mc->max;
2651 int min = mc->min;
2652 int mask = (1 << (fls(min + max) - 1)) - 1;
2653
2654 ucontrol->value.integer.value[0] =
2655 ((snd_soc_read(codec, reg) >> shift) - min) & mask;
2656
2657 if (snd_soc_volsw_is_stereo(mc))
2658 ucontrol->value.integer.value[1] =
2659 ((snd_soc_read(codec, reg2) >> rshift) - min) & mask;
2660
2661 return 0;
2662}
2663EXPORT_SYMBOL_GPL(snd_soc_get_volsw_sx);
2664
2665/**
2666 * snd_soc_put_volsw_sx - double mixer set callback
2667 * @kcontrol: mixer control
2668 * @uinfo: control element information
2669 *
2670 * Callback to set the value of a double mixer control that spans 2 registers.
2671 *
2672 * Returns 0 for success.
2673 */
2674int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol,
2675 struct snd_ctl_elem_value *ucontrol)
2676{
2677 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2678 struct soc_mixer_control *mc =
2679 (struct soc_mixer_control *)kcontrol->private_value;
2680
2681 unsigned int reg = mc->reg;
2682 unsigned int reg2 = mc->rreg;
2683 unsigned int shift = mc->shift;
2684 unsigned int rshift = mc->rshift;
2685 int max = mc->max;
2686 int min = mc->min;
2687 int mask = (1 << (fls(min + max) - 1)) - 1;
2688 int err = 0;
2689 unsigned short val, val_mask, val2 = 0;
2690
2691 val_mask = mask << shift;
2692 val = (ucontrol->value.integer.value[0] + min) & mask;
2693 val = val << shift;
2694
2695 if (snd_soc_update_bits_locked(codec, reg, val_mask, val))
2696 return err;
2697
2698 if (snd_soc_volsw_is_stereo(mc)) {
2699 val_mask = mask << rshift;
2700 val2 = (ucontrol->value.integer.value[1] + min) & mask;
2701 val2 = val2 << rshift;
2702
2703 if (snd_soc_update_bits_locked(codec, reg2, val_mask, val2))
2704 return err;
2705 }
2706 return 0;
2707}
2708EXPORT_SYMBOL_GPL(snd_soc_put_volsw_sx);
2709
2710/**
2536 * snd_soc_info_volsw_s8 - signed mixer info callback 2711 * snd_soc_info_volsw_s8 - signed mixer info callback
2537 * @kcontrol: mixer control 2712 * @kcontrol: mixer control
2538 * @uinfo: control element information 2713 * @uinfo: control element information
@@ -2653,99 +2828,6 @@ int snd_soc_limit_volume(struct snd_soc_codec *codec,
2653} 2828}
2654EXPORT_SYMBOL_GPL(snd_soc_limit_volume); 2829EXPORT_SYMBOL_GPL(snd_soc_limit_volume);
2655 2830
2656/**
2657 * snd_soc_info_volsw_2r_sx - double with tlv and variable data size
2658 * mixer info callback
2659 * @kcontrol: mixer control
2660 * @uinfo: control element information
2661 *
2662 * Returns 0 for success.
2663 */
2664int snd_soc_info_volsw_2r_sx(struct snd_kcontrol *kcontrol,
2665 struct snd_ctl_elem_info *uinfo)
2666{
2667 struct soc_mixer_control *mc =
2668 (struct soc_mixer_control *)kcontrol->private_value;
2669 int max = mc->max;
2670 int min = mc->min;
2671
2672 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2673 uinfo->count = 2;
2674 uinfo->value.integer.min = 0;
2675 uinfo->value.integer.max = max-min;
2676
2677 return 0;
2678}
2679EXPORT_SYMBOL_GPL(snd_soc_info_volsw_2r_sx);
2680
2681/**
2682 * snd_soc_get_volsw_2r_sx - double with tlv and variable data size
2683 * mixer get callback
2684 * @kcontrol: mixer control
2685 * @uinfo: control element information
2686 *
2687 * Returns 0 for success.
2688 */
2689int snd_soc_get_volsw_2r_sx(struct snd_kcontrol *kcontrol,
2690 struct snd_ctl_elem_value *ucontrol)
2691{
2692 struct soc_mixer_control *mc =
2693 (struct soc_mixer_control *)kcontrol->private_value;
2694 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2695 unsigned int mask = (1<<mc->shift)-1;
2696 int min = mc->min;
2697 int val = snd_soc_read(codec, mc->reg) & mask;
2698 int valr = snd_soc_read(codec, mc->rreg) & mask;
2699
2700 ucontrol->value.integer.value[0] = ((val & 0xff)-min) & mask;
2701 ucontrol->value.integer.value[1] = ((valr & 0xff)-min) & mask;
2702 return 0;
2703}
2704EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r_sx);
2705
2706/**
2707 * snd_soc_put_volsw_2r_sx - double with tlv and variable data size
2708 * mixer put callback
2709 * @kcontrol: mixer control
2710 * @uinfo: control element information
2711 *
2712 * Returns 0 for success.
2713 */
2714int snd_soc_put_volsw_2r_sx(struct snd_kcontrol *kcontrol,
2715 struct snd_ctl_elem_value *ucontrol)
2716{
2717 struct soc_mixer_control *mc =
2718 (struct soc_mixer_control *)kcontrol->private_value;
2719 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2720 unsigned int mask = (1<<mc->shift)-1;
2721 int min = mc->min;
2722 int ret;
2723 unsigned int val, valr, oval, ovalr;
2724
2725 val = ((ucontrol->value.integer.value[0]+min) & 0xff);
2726 val &= mask;
2727 valr = ((ucontrol->value.integer.value[1]+min) & 0xff);
2728 valr &= mask;
2729
2730 oval = snd_soc_read(codec, mc->reg) & mask;
2731 ovalr = snd_soc_read(codec, mc->rreg) & mask;
2732
2733 ret = 0;
2734 if (oval != val) {
2735 ret = snd_soc_write(codec, mc->reg, val);
2736 if (ret < 0)
2737 return ret;
2738 }
2739 if (ovalr != valr) {
2740 ret = snd_soc_write(codec, mc->rreg, valr);
2741 if (ret < 0)
2742 return ret;
2743 }
2744
2745 return 0;
2746}
2747EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r_sx);
2748
2749int snd_soc_bytes_info(struct snd_kcontrol *kcontrol, 2831int snd_soc_bytes_info(struct snd_kcontrol *kcontrol,
2750 struct snd_ctl_elem_info *uinfo) 2832 struct snd_ctl_elem_info *uinfo)
2751{ 2833{
@@ -2856,6 +2938,186 @@ int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
2856EXPORT_SYMBOL_GPL(snd_soc_bytes_put); 2938EXPORT_SYMBOL_GPL(snd_soc_bytes_put);
2857 2939
2858/** 2940/**
2941 * snd_soc_info_xr_sx - signed multi register info callback
2942 * @kcontrol: mreg control
2943 * @uinfo: control element information
2944 *
2945 * Callback to provide information of a control that can
2946 * span multiple codec registers which together
2947 * forms a single signed value in a MSB/LSB manner.
2948 *
2949 * Returns 0 for success.
2950 */
2951int snd_soc_info_xr_sx(struct snd_kcontrol *kcontrol,
2952 struct snd_ctl_elem_info *uinfo)
2953{
2954 struct soc_mreg_control *mc =
2955 (struct soc_mreg_control *)kcontrol->private_value;
2956 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2957 uinfo->count = 1;
2958 uinfo->value.integer.min = mc->min;
2959 uinfo->value.integer.max = mc->max;
2960
2961 return 0;
2962}
2963EXPORT_SYMBOL_GPL(snd_soc_info_xr_sx);
2964
2965/**
2966 * snd_soc_get_xr_sx - signed multi register get callback
2967 * @kcontrol: mreg control
2968 * @ucontrol: control element information
2969 *
2970 * Callback to get the value of a control that can span
2971 * multiple codec registers which together forms a single
2972 * signed value in a MSB/LSB manner. The control supports
2973 * specifying total no of bits used to allow for bitfields
2974 * across the multiple codec registers.
2975 *
2976 * Returns 0 for success.
2977 */
2978int snd_soc_get_xr_sx(struct snd_kcontrol *kcontrol,
2979 struct snd_ctl_elem_value *ucontrol)
2980{
2981 struct soc_mreg_control *mc =
2982 (struct soc_mreg_control *)kcontrol->private_value;
2983 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2984 unsigned int regbase = mc->regbase;
2985 unsigned int regcount = mc->regcount;
2986 unsigned int regwshift = codec->driver->reg_word_size * BITS_PER_BYTE;
2987 unsigned int regwmask = (1<<regwshift)-1;
2988 unsigned int invert = mc->invert;
2989 unsigned long mask = (1UL<<mc->nbits)-1;
2990 long min = mc->min;
2991 long max = mc->max;
2992 long val = 0;
2993 unsigned long regval;
2994 unsigned int i;
2995
2996 for (i = 0; i < regcount; i++) {
2997 regval = snd_soc_read(codec, regbase+i) & regwmask;
2998 val |= regval << (regwshift*(regcount-i-1));
2999 }
3000 val &= mask;
3001 if (min < 0 && val > max)
3002 val |= ~mask;
3003 if (invert)
3004 val = max - val;
3005 ucontrol->value.integer.value[0] = val;
3006
3007 return 0;
3008}
3009EXPORT_SYMBOL_GPL(snd_soc_get_xr_sx);
3010
3011/**
3012 * snd_soc_put_xr_sx - signed multi register get callback
3013 * @kcontrol: mreg control
3014 * @ucontrol: control element information
3015 *
3016 * Callback to set the value of a control that can span
3017 * multiple codec registers which together forms a single
3018 * signed value in a MSB/LSB manner. The control supports
3019 * specifying total no of bits used to allow for bitfields
3020 * across the multiple codec registers.
3021 *
3022 * Returns 0 for success.
3023 */
3024int snd_soc_put_xr_sx(struct snd_kcontrol *kcontrol,
3025 struct snd_ctl_elem_value *ucontrol)
3026{
3027 struct soc_mreg_control *mc =
3028 (struct soc_mreg_control *)kcontrol->private_value;
3029 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
3030 unsigned int regbase = mc->regbase;
3031 unsigned int regcount = mc->regcount;
3032 unsigned int regwshift = codec->driver->reg_word_size * BITS_PER_BYTE;
3033 unsigned int regwmask = (1<<regwshift)-1;
3034 unsigned int invert = mc->invert;
3035 unsigned long mask = (1UL<<mc->nbits)-1;
3036 long max = mc->max;
3037 long val = ucontrol->value.integer.value[0];
3038 unsigned int i, regval, regmask;
3039 int err;
3040
3041 if (invert)
3042 val = max - val;
3043 val &= mask;
3044 for (i = 0; i < regcount; i++) {
3045 regval = (val >> (regwshift*(regcount-i-1))) & regwmask;
3046 regmask = (mask >> (regwshift*(regcount-i-1))) & regwmask;
3047 err = snd_soc_update_bits_locked(codec, regbase+i,
3048 regmask, regval);
3049 if (err < 0)
3050 return err;
3051 }
3052
3053 return 0;
3054}
3055EXPORT_SYMBOL_GPL(snd_soc_put_xr_sx);
3056
3057/**
3058 * snd_soc_get_strobe - strobe get callback
3059 * @kcontrol: mixer control
3060 * @ucontrol: control element information
3061 *
3062 * Callback get the value of a strobe mixer control.
3063 *
3064 * Returns 0 for success.
3065 */
3066int snd_soc_get_strobe(struct snd_kcontrol *kcontrol,
3067 struct snd_ctl_elem_value *ucontrol)
3068{
3069 struct soc_mixer_control *mc =
3070 (struct soc_mixer_control *)kcontrol->private_value;
3071 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
3072 unsigned int reg = mc->reg;
3073 unsigned int shift = mc->shift;
3074 unsigned int mask = 1 << shift;
3075 unsigned int invert = mc->invert != 0;
3076 unsigned int val = snd_soc_read(codec, reg) & mask;
3077
3078 if (shift != 0 && val != 0)
3079 val = val >> shift;
3080 ucontrol->value.enumerated.item[0] = val ^ invert;
3081
3082 return 0;
3083}
3084EXPORT_SYMBOL_GPL(snd_soc_get_strobe);
3085
3086/**
3087 * snd_soc_put_strobe - strobe put callback
3088 * @kcontrol: mixer control
3089 * @ucontrol: control element information
3090 *
3091 * Callback strobe a register bit to high then low (or the inverse)
3092 * in one pass of a single mixer enum control.
3093 *
3094 * Returns 1 for success.
3095 */
3096int snd_soc_put_strobe(struct snd_kcontrol *kcontrol,
3097 struct snd_ctl_elem_value *ucontrol)
3098{
3099 struct soc_mixer_control *mc =
3100 (struct soc_mixer_control *)kcontrol->private_value;
3101 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
3102 unsigned int reg = mc->reg;
3103 unsigned int shift = mc->shift;
3104 unsigned int mask = 1 << shift;
3105 unsigned int invert = mc->invert != 0;
3106 unsigned int strobe = ucontrol->value.enumerated.item[0] != 0;
3107 unsigned int val1 = (strobe ^ invert) ? mask : 0;
3108 unsigned int val2 = (strobe ^ invert) ? 0 : mask;
3109 int err;
3110
3111 err = snd_soc_update_bits_locked(codec, reg, mask, val1);
3112 if (err < 0)
3113 return err;
3114
3115 err = snd_soc_update_bits_locked(codec, reg, mask, val2);
3116 return err;
3117}
3118EXPORT_SYMBOL_GPL(snd_soc_put_strobe);
3119
3120/**
2859 * snd_soc_dai_set_sysclk - configure DAI system or master clock. 3121 * snd_soc_dai_set_sysclk - configure DAI system or master clock.
2860 * @dai: DAI 3122 * @dai: DAI
2861 * @clk_id: DAI specific clock ID 3123 * @clk_id: DAI specific clock ID
@@ -3054,7 +3316,7 @@ int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute)
3054 if (dai->driver && dai->driver->ops->digital_mute) 3316 if (dai->driver && dai->driver->ops->digital_mute)
3055 return dai->driver->ops->digital_mute(dai, mute); 3317 return dai->driver->ops->digital_mute(dai, mute);
3056 else 3318 else
3057 return -EINVAL; 3319 return -ENOTSUPP;
3058} 3320}
3059EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute); 3321EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute);
3060 3322
@@ -3066,7 +3328,7 @@ EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute);
3066 */ 3328 */
3067int snd_soc_register_card(struct snd_soc_card *card) 3329int snd_soc_register_card(struct snd_soc_card *card)
3068{ 3330{
3069 int i; 3331 int i, ret;
3070 3332
3071 if (!card->name || !card->dev) 3333 if (!card->name || !card->dev)
3072 return -EINVAL; 3334 return -EINVAL;
@@ -3129,15 +3391,13 @@ int snd_soc_register_card(struct snd_soc_card *card)
3129 INIT_LIST_HEAD(&card->dapm_dirty); 3391 INIT_LIST_HEAD(&card->dapm_dirty);
3130 card->instantiated = 0; 3392 card->instantiated = 0;
3131 mutex_init(&card->mutex); 3393 mutex_init(&card->mutex);
3394 mutex_init(&card->dapm_mutex);
3132 3395
3133 mutex_lock(&client_mutex); 3396 ret = snd_soc_instantiate_card(card);
3134 list_add(&card->list, &card_list); 3397 if (ret != 0)
3135 snd_soc_instantiate_cards(); 3398 soc_cleanup_card_debugfs(card);
3136 mutex_unlock(&client_mutex);
3137
3138 dev_dbg(card->dev, "Registered card '%s'\n", card->name);
3139 3399
3140 return 0; 3400 return ret;
3141} 3401}
3142EXPORT_SYMBOL_GPL(snd_soc_register_card); 3402EXPORT_SYMBOL_GPL(snd_soc_register_card);
3143 3403
@@ -3151,9 +3411,6 @@ int snd_soc_unregister_card(struct snd_soc_card *card)
3151{ 3411{
3152 if (card->instantiated) 3412 if (card->instantiated)
3153 soc_cleanup_card_resources(card); 3413 soc_cleanup_card_resources(card);
3154 mutex_lock(&client_mutex);
3155 list_del(&card->list);
3156 mutex_unlock(&client_mutex);
3157 dev_dbg(card->dev, "Unregistered card '%s'\n", card->name); 3414 dev_dbg(card->dev, "Unregistered card '%s'\n", card->name);
3158 3415
3159 return 0; 3416 return 0;
@@ -3227,6 +3484,7 @@ static inline char *fmt_multiple_name(struct device *dev,
3227int snd_soc_register_dai(struct device *dev, 3484int snd_soc_register_dai(struct device *dev,
3228 struct snd_soc_dai_driver *dai_drv) 3485 struct snd_soc_dai_driver *dai_drv)
3229{ 3486{
3487 struct snd_soc_codec *codec;
3230 struct snd_soc_dai *dai; 3488 struct snd_soc_dai *dai;
3231 3489
3232 dev_dbg(dev, "dai register %s\n", dev_name(dev)); 3490 dev_dbg(dev, "dai register %s\n", dev_name(dev));
@@ -3244,12 +3502,23 @@ int snd_soc_register_dai(struct device *dev,
3244 3502
3245 dai->dev = dev; 3503 dai->dev = dev;
3246 dai->driver = dai_drv; 3504 dai->driver = dai_drv;
3505 dai->dapm.dev = dev;
3247 if (!dai->driver->ops) 3506 if (!dai->driver->ops)
3248 dai->driver->ops = &null_dai_ops; 3507 dai->driver->ops = &null_dai_ops;
3249 3508
3250 mutex_lock(&client_mutex); 3509 mutex_lock(&client_mutex);
3510
3511 list_for_each_entry(codec, &codec_list, list) {
3512 if (codec->dev == dev) {
3513 dev_dbg(dev, "Mapped DAI %s to CODEC %s\n",
3514 dai->name, codec->name);
3515 dai->codec = codec;
3516 break;
3517 }
3518 }
3519
3251 list_add(&dai->list, &dai_list); 3520 list_add(&dai->list, &dai_list);
3252 snd_soc_instantiate_cards(); 3521
3253 mutex_unlock(&client_mutex); 3522 mutex_unlock(&client_mutex);
3254 3523
3255 pr_debug("Registered DAI '%s'\n", dai->name); 3524 pr_debug("Registered DAI '%s'\n", dai->name);
@@ -3293,6 +3562,7 @@ EXPORT_SYMBOL_GPL(snd_soc_unregister_dai);
3293int snd_soc_register_dais(struct device *dev, 3562int snd_soc_register_dais(struct device *dev,
3294 struct snd_soc_dai_driver *dai_drv, size_t count) 3563 struct snd_soc_dai_driver *dai_drv, size_t count)
3295{ 3564{
3565 struct snd_soc_codec *codec;
3296 struct snd_soc_dai *dai; 3566 struct snd_soc_dai *dai;
3297 int i, ret = 0; 3567 int i, ret = 0;
3298 3568
@@ -3320,19 +3590,28 @@ int snd_soc_register_dais(struct device *dev,
3320 dai->id = dai->driver->id; 3590 dai->id = dai->driver->id;
3321 else 3591 else
3322 dai->id = i; 3592 dai->id = i;
3593 dai->dapm.dev = dev;
3323 if (!dai->driver->ops) 3594 if (!dai->driver->ops)
3324 dai->driver->ops = &null_dai_ops; 3595 dai->driver->ops = &null_dai_ops;
3325 3596
3326 mutex_lock(&client_mutex); 3597 mutex_lock(&client_mutex);
3598
3599 list_for_each_entry(codec, &codec_list, list) {
3600 if (codec->dev == dev) {
3601 dev_dbg(dev, "Mapped DAI %s to CODEC %s\n",
3602 dai->name, codec->name);
3603 dai->codec = codec;
3604 break;
3605 }
3606 }
3607
3327 list_add(&dai->list, &dai_list); 3608 list_add(&dai->list, &dai_list);
3609
3328 mutex_unlock(&client_mutex); 3610 mutex_unlock(&client_mutex);
3329 3611
3330 pr_debug("Registered DAI '%s'\n", dai->name); 3612 pr_debug("Registered DAI '%s'\n", dai->name);
3331 } 3613 }
3332 3614
3333 mutex_lock(&client_mutex);
3334 snd_soc_instantiate_cards();
3335 mutex_unlock(&client_mutex);
3336 return 0; 3615 return 0;
3337 3616
3338err: 3617err:
@@ -3390,7 +3669,6 @@ int snd_soc_register_platform(struct device *dev,
3390 3669
3391 mutex_lock(&client_mutex); 3670 mutex_lock(&client_mutex);
3392 list_add(&platform->list, &platform_list); 3671 list_add(&platform->list, &platform_list);
3393 snd_soc_instantiate_cards();
3394 mutex_unlock(&client_mutex); 3672 mutex_unlock(&client_mutex);
3395 3673
3396 pr_debug("Registered platform '%s'\n", platform->name); 3674 pr_debug("Registered platform '%s'\n", platform->name);
@@ -3540,18 +3818,18 @@ int snd_soc_register_codec(struct device *dev,
3540 fixup_codec_formats(&dai_drv[i].capture); 3818 fixup_codec_formats(&dai_drv[i].capture);
3541 } 3819 }
3542 3820
3821 mutex_lock(&client_mutex);
3822 list_add(&codec->list, &codec_list);
3823 mutex_unlock(&client_mutex);
3824
3543 /* register any DAIs */ 3825 /* register any DAIs */
3544 if (num_dai) { 3826 if (num_dai) {
3545 ret = snd_soc_register_dais(dev, dai_drv, num_dai); 3827 ret = snd_soc_register_dais(dev, dai_drv, num_dai);
3546 if (ret < 0) 3828 if (ret < 0)
3547 goto fail; 3829 dev_err(codec->dev, "Failed to regster DAIs: %d\n",
3830 ret);
3548 } 3831 }
3549 3832
3550 mutex_lock(&client_mutex);
3551 list_add(&codec->list, &codec_list);
3552 snd_soc_instantiate_cards();
3553 mutex_unlock(&client_mutex);
3554
3555 pr_debug("Registered codec '%s'\n", codec->name); 3833 pr_debug("Registered codec '%s'\n", codec->name);
3556 return 0; 3834 return 0;
3557 3835
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index dc7dbfe61cd0..90ee77d2409d 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -52,6 +52,7 @@ static int dapm_up_seq[] = {
52 [snd_soc_dapm_supply] = 1, 52 [snd_soc_dapm_supply] = 1,
53 [snd_soc_dapm_regulator_supply] = 1, 53 [snd_soc_dapm_regulator_supply] = 1,
54 [snd_soc_dapm_micbias] = 2, 54 [snd_soc_dapm_micbias] = 2,
55 [snd_soc_dapm_dai_link] = 2,
55 [snd_soc_dapm_dai] = 3, 56 [snd_soc_dapm_dai] = 3,
56 [snd_soc_dapm_aif_in] = 3, 57 [snd_soc_dapm_aif_in] = 3,
57 [snd_soc_dapm_aif_out] = 3, 58 [snd_soc_dapm_aif_out] = 3,
@@ -90,9 +91,10 @@ static int dapm_down_seq[] = {
90 [snd_soc_dapm_aif_in] = 10, 91 [snd_soc_dapm_aif_in] = 10,
91 [snd_soc_dapm_aif_out] = 10, 92 [snd_soc_dapm_aif_out] = 10,
92 [snd_soc_dapm_dai] = 10, 93 [snd_soc_dapm_dai] = 10,
93 [snd_soc_dapm_regulator_supply] = 11, 94 [snd_soc_dapm_dai_link] = 11,
94 [snd_soc_dapm_supply] = 11, 95 [snd_soc_dapm_regulator_supply] = 12,
95 [snd_soc_dapm_post] = 12, 96 [snd_soc_dapm_supply] = 12,
97 [snd_soc_dapm_post] = 13,
96}; 98};
97 99
98static void pop_wait(u32 pop_time) 100static void pop_wait(u32 pop_time)
@@ -208,7 +210,23 @@ static int soc_widget_write(struct snd_soc_dapm_widget *w, int reg, int val)
208 return -1; 210 return -1;
209} 211}
210 212
211static int soc_widget_update_bits(struct snd_soc_dapm_widget *w, 213static inline void soc_widget_lock(struct snd_soc_dapm_widget *w)
214{
215 if (w->codec && !w->codec->using_regmap)
216 mutex_lock(&w->codec->mutex);
217 else if (w->platform)
218 mutex_lock(&w->platform->mutex);
219}
220
221static inline void soc_widget_unlock(struct snd_soc_dapm_widget *w)
222{
223 if (w->codec && !w->codec->using_regmap)
224 mutex_unlock(&w->codec->mutex);
225 else if (w->platform)
226 mutex_unlock(&w->platform->mutex);
227}
228
229static int soc_widget_update_bits_locked(struct snd_soc_dapm_widget *w,
212 unsigned short reg, unsigned int mask, unsigned int value) 230 unsigned short reg, unsigned int mask, unsigned int value)
213{ 231{
214 bool change; 232 bool change;
@@ -221,18 +239,24 @@ static int soc_widget_update_bits(struct snd_soc_dapm_widget *w,
221 if (ret != 0) 239 if (ret != 0)
222 return ret; 240 return ret;
223 } else { 241 } else {
242 soc_widget_lock(w);
224 ret = soc_widget_read(w, reg); 243 ret = soc_widget_read(w, reg);
225 if (ret < 0) 244 if (ret < 0) {
245 soc_widget_unlock(w);
226 return ret; 246 return ret;
247 }
227 248
228 old = ret; 249 old = ret;
229 new = (old & ~mask) | (value & mask); 250 new = (old & ~mask) | (value & mask);
230 change = old != new; 251 change = old != new;
231 if (change) { 252 if (change) {
232 ret = soc_widget_write(w, reg, new); 253 ret = soc_widget_write(w, reg, new);
233 if (ret < 0) 254 if (ret < 0) {
255 soc_widget_unlock(w);
234 return ret; 256 return ret;
257 }
235 } 258 }
259 soc_widget_unlock(w);
236 } 260 }
237 261
238 return change; 262 return change;
@@ -374,6 +398,7 @@ static void dapm_set_path_status(struct snd_soc_dapm_widget *w,
374 case snd_soc_dapm_mic: 398 case snd_soc_dapm_mic:
375 case snd_soc_dapm_spk: 399 case snd_soc_dapm_spk:
376 case snd_soc_dapm_line: 400 case snd_soc_dapm_line:
401 case snd_soc_dapm_dai_link:
377 p->connect = 1; 402 p->connect = 1;
378 break; 403 break;
379 /* does affect routing - dynamically connected */ 404 /* does affect routing - dynamically connected */
@@ -682,11 +707,51 @@ static int snd_soc_dapm_suspend_check(struct snd_soc_dapm_widget *widget)
682 } 707 }
683} 708}
684 709
710/* add widget to list if it's not already in the list */
711static int dapm_list_add_widget(struct snd_soc_dapm_widget_list **list,
712 struct snd_soc_dapm_widget *w)
713{
714 struct snd_soc_dapm_widget_list *wlist;
715 int wlistsize, wlistentries, i;
716
717 if (*list == NULL)
718 return -EINVAL;
719
720 wlist = *list;
721
722 /* is this widget already in the list */
723 for (i = 0; i < wlist->num_widgets; i++) {
724 if (wlist->widgets[i] == w)
725 return 0;
726 }
727
728 /* allocate some new space */
729 wlistentries = wlist->num_widgets + 1;
730 wlistsize = sizeof(struct snd_soc_dapm_widget_list) +
731 wlistentries * sizeof(struct snd_soc_dapm_widget *);
732 *list = krealloc(wlist, wlistsize, GFP_KERNEL);
733 if (*list == NULL) {
734 dev_err(w->dapm->dev, "can't allocate widget list for %s\n",
735 w->name);
736 return -ENOMEM;
737 }
738 wlist = *list;
739
740 /* insert the widget */
741 dev_dbg(w->dapm->dev, "added %s in widget list pos %d\n",
742 w->name, wlist->num_widgets);
743
744 wlist->widgets[wlist->num_widgets] = w;
745 wlist->num_widgets++;
746 return 1;
747}
748
685/* 749/*
686 * Recursively check for a completed path to an active or physically connected 750 * Recursively check for a completed path to an active or physically connected
687 * output widget. Returns number of complete paths. 751 * output widget. Returns number of complete paths.
688 */ 752 */
689static int is_connected_output_ep(struct snd_soc_dapm_widget *widget) 753static int is_connected_output_ep(struct snd_soc_dapm_widget *widget,
754 struct snd_soc_dapm_widget_list **list)
690{ 755{
691 struct snd_soc_dapm_path *path; 756 struct snd_soc_dapm_path *path;
692 int con = 0; 757 int con = 0;
@@ -742,9 +807,23 @@ static int is_connected_output_ep(struct snd_soc_dapm_widget *widget)
742 if (path->walked) 807 if (path->walked)
743 continue; 808 continue;
744 809
810 trace_snd_soc_dapm_output_path(widget, path);
811
745 if (path->sink && path->connect) { 812 if (path->sink && path->connect) {
746 path->walked = 1; 813 path->walked = 1;
747 con += is_connected_output_ep(path->sink); 814
815 /* do we need to add this widget to the list ? */
816 if (list) {
817 int err;
818 err = dapm_list_add_widget(list, path->sink);
819 if (err < 0) {
820 dev_err(widget->dapm->dev, "could not add widget %s\n",
821 widget->name);
822 return con;
823 }
824 }
825
826 con += is_connected_output_ep(path->sink, list);
748 } 827 }
749 } 828 }
750 829
@@ -757,7 +836,8 @@ static int is_connected_output_ep(struct snd_soc_dapm_widget *widget)
757 * Recursively check for a completed path to an active or physically connected 836 * Recursively check for a completed path to an active or physically connected
758 * input widget. Returns number of complete paths. 837 * input widget. Returns number of complete paths.
759 */ 838 */
760static int is_connected_input_ep(struct snd_soc_dapm_widget *widget) 839static int is_connected_input_ep(struct snd_soc_dapm_widget *widget,
840 struct snd_soc_dapm_widget_list **list)
761{ 841{
762 struct snd_soc_dapm_path *path; 842 struct snd_soc_dapm_path *path;
763 int con = 0; 843 int con = 0;
@@ -825,9 +905,23 @@ static int is_connected_input_ep(struct snd_soc_dapm_widget *widget)
825 if (path->walked) 905 if (path->walked)
826 continue; 906 continue;
827 907
908 trace_snd_soc_dapm_input_path(widget, path);
909
828 if (path->source && path->connect) { 910 if (path->source && path->connect) {
829 path->walked = 1; 911 path->walked = 1;
830 con += is_connected_input_ep(path->source); 912
913 /* do we need to add this widget to the list ? */
914 if (list) {
915 int err;
916 err = dapm_list_add_widget(list, path->sink);
917 if (err < 0) {
918 dev_err(widget->dapm->dev, "could not add widget %s\n",
919 widget->name);
920 return con;
921 }
922 }
923
924 con += is_connected_input_ep(path->source, list);
831 } 925 }
832 } 926 }
833 927
@@ -836,6 +930,39 @@ static int is_connected_input_ep(struct snd_soc_dapm_widget *widget)
836 return con; 930 return con;
837} 931}
838 932
933/**
934 * snd_soc_dapm_get_connected_widgets - query audio path and it's widgets.
935 * @dai: the soc DAI.
936 * @stream: stream direction.
937 * @list: list of active widgets for this stream.
938 *
939 * Queries DAPM graph as to whether an valid audio stream path exists for
940 * the initial stream specified by name. This takes into account
941 * current mixer and mux kcontrol settings. Creates list of valid widgets.
942 *
943 * Returns the number of valid paths or negative error.
944 */
945int snd_soc_dapm_dai_get_connected_widgets(struct snd_soc_dai *dai, int stream,
946 struct snd_soc_dapm_widget_list **list)
947{
948 struct snd_soc_card *card = dai->card;
949 int paths;
950
951 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
952 dapm_reset(card);
953
954 if (stream == SNDRV_PCM_STREAM_PLAYBACK)
955 paths = is_connected_output_ep(dai->playback_widget, list);
956 else
957 paths = is_connected_input_ep(dai->playback_widget, list);
958
959 trace_snd_soc_dapm_connected(paths, stream);
960 dapm_clear_walk(&card->dapm);
961 mutex_unlock(&card->dapm_mutex);
962
963 return paths;
964}
965
839/* 966/*
840 * Handler for generic register modifier widget. 967 * Handler for generic register modifier widget.
841 */ 968 */
@@ -849,7 +976,7 @@ int dapm_reg_event(struct snd_soc_dapm_widget *w,
849 else 976 else
850 val = w->off_val; 977 val = w->off_val;
851 978
852 soc_widget_update_bits(w, -(w->reg + 1), 979 soc_widget_update_bits_locked(w, -(w->reg + 1),
853 w->mask << w->shift, val << w->shift); 980 w->mask << w->shift, val << w->shift);
854 981
855 return 0; 982 return 0;
@@ -863,9 +990,9 @@ int dapm_regulator_event(struct snd_soc_dapm_widget *w,
863 struct snd_kcontrol *kcontrol, int event) 990 struct snd_kcontrol *kcontrol, int event)
864{ 991{
865 if (SND_SOC_DAPM_EVENT_ON(event)) 992 if (SND_SOC_DAPM_EVENT_ON(event))
866 return regulator_enable(w->priv); 993 return regulator_enable(w->regulator);
867 else 994 else
868 return regulator_disable_deferred(w->priv, w->shift); 995 return regulator_disable_deferred(w->regulator, w->shift);
869} 996}
870EXPORT_SYMBOL_GPL(dapm_regulator_event); 997EXPORT_SYMBOL_GPL(dapm_regulator_event);
871 998
@@ -892,9 +1019,9 @@ static int dapm_generic_check_power(struct snd_soc_dapm_widget *w)
892 1019
893 DAPM_UPDATE_STAT(w, power_checks); 1020 DAPM_UPDATE_STAT(w, power_checks);
894 1021
895 in = is_connected_input_ep(w); 1022 in = is_connected_input_ep(w, NULL);
896 dapm_clear_walk(w->dapm); 1023 dapm_clear_walk(w->dapm);
897 out = is_connected_output_ep(w); 1024 out = is_connected_output_ep(w, NULL);
898 dapm_clear_walk(w->dapm); 1025 dapm_clear_walk(w->dapm);
899 return out != 0 && in != 0; 1026 return out != 0 && in != 0;
900} 1027}
@@ -903,7 +1030,10 @@ static int dapm_dai_check_power(struct snd_soc_dapm_widget *w)
903{ 1030{
904 DAPM_UPDATE_STAT(w, power_checks); 1031 DAPM_UPDATE_STAT(w, power_checks);
905 1032
906 return w->active; 1033 if (w->active)
1034 return w->active;
1035
1036 return dapm_generic_check_power(w);
907} 1037}
908 1038
909/* Check to see if an ADC has power */ 1039/* Check to see if an ADC has power */
@@ -914,7 +1044,7 @@ static int dapm_adc_check_power(struct snd_soc_dapm_widget *w)
914 DAPM_UPDATE_STAT(w, power_checks); 1044 DAPM_UPDATE_STAT(w, power_checks);
915 1045
916 if (w->active) { 1046 if (w->active) {
917 in = is_connected_input_ep(w); 1047 in = is_connected_input_ep(w, NULL);
918 dapm_clear_walk(w->dapm); 1048 dapm_clear_walk(w->dapm);
919 return in != 0; 1049 return in != 0;
920 } else { 1050 } else {
@@ -930,7 +1060,7 @@ static int dapm_dac_check_power(struct snd_soc_dapm_widget *w)
930 DAPM_UPDATE_STAT(w, power_checks); 1060 DAPM_UPDATE_STAT(w, power_checks);
931 1061
932 if (w->active) { 1062 if (w->active) {
933 out = is_connected_output_ep(w); 1063 out = is_connected_output_ep(w, NULL);
934 dapm_clear_walk(w->dapm); 1064 dapm_clear_walk(w->dapm);
935 return out != 0; 1065 return out != 0;
936 } else { 1066 } else {
@@ -1107,7 +1237,7 @@ static void dapm_seq_run_coalesced(struct snd_soc_dapm_context *dapm,
1107 "pop test : Applying 0x%x/0x%x to %x in %dms\n", 1237 "pop test : Applying 0x%x/0x%x to %x in %dms\n",
1108 value, mask, reg, card->pop_time); 1238 value, mask, reg, card->pop_time);
1109 pop_wait(card->pop_time); 1239 pop_wait(card->pop_time);
1110 soc_widget_update_bits(w, reg, mask, value); 1240 soc_widget_update_bits_locked(w, reg, mask, value);
1111 } 1241 }
1112 1242
1113 list_for_each_entry(w, pending, power_list) { 1243 list_for_each_entry(w, pending, power_list) {
@@ -1237,7 +1367,7 @@ static void dapm_widget_update(struct snd_soc_dapm_context *dapm)
1237 w->name, ret); 1367 w->name, ret);
1238 } 1368 }
1239 1369
1240 ret = snd_soc_update_bits(w->codec, update->reg, update->mask, 1370 ret = soc_widget_update_bits_locked(w, update->reg, update->mask,
1241 update->val); 1371 update->val);
1242 if (ret < 0) 1372 if (ret < 0)
1243 pr_err("%s DAPM update failed: %d\n", w->name, ret); 1373 pr_err("%s DAPM update failed: %d\n", w->name, ret);
@@ -1421,12 +1551,10 @@ static int dapm_power_widgets(struct snd_soc_dapm_context *dapm, int event)
1421 trace_snd_soc_dapm_start(card); 1551 trace_snd_soc_dapm_start(card);
1422 1552
1423 list_for_each_entry(d, &card->dapm_list, list) { 1553 list_for_each_entry(d, &card->dapm_list, list) {
1424 if (d->n_widgets || d->codec == NULL) { 1554 if (d->idle_bias_off)
1425 if (d->idle_bias_off) 1555 d->target_bias_level = SND_SOC_BIAS_OFF;
1426 d->target_bias_level = SND_SOC_BIAS_OFF; 1556 else
1427 else 1557 d->target_bias_level = SND_SOC_BIAS_STANDBY;
1428 d->target_bias_level = SND_SOC_BIAS_STANDBY;
1429 }
1430 } 1558 }
1431 1559
1432 dapm_reset(card); 1560 dapm_reset(card);
@@ -1471,32 +1599,6 @@ static int dapm_power_widgets(struct snd_soc_dapm_context *dapm, int event)
1471 1599
1472 } 1600 }
1473 1601
1474 /* If there are no DAPM widgets then try to figure out power from the
1475 * event type.
1476 */
1477 if (!dapm->n_widgets) {
1478 switch (event) {
1479 case SND_SOC_DAPM_STREAM_START:
1480 case SND_SOC_DAPM_STREAM_RESUME:
1481 dapm->target_bias_level = SND_SOC_BIAS_ON;
1482 break;
1483 case SND_SOC_DAPM_STREAM_STOP:
1484 if (dapm->codec && dapm->codec->active)
1485 dapm->target_bias_level = SND_SOC_BIAS_ON;
1486 else
1487 dapm->target_bias_level = SND_SOC_BIAS_STANDBY;
1488 break;
1489 case SND_SOC_DAPM_STREAM_SUSPEND:
1490 dapm->target_bias_level = SND_SOC_BIAS_STANDBY;
1491 break;
1492 case SND_SOC_DAPM_STREAM_NOP:
1493 dapm->target_bias_level = dapm->bias_level;
1494 break;
1495 default:
1496 break;
1497 }
1498 }
1499
1500 /* Force all contexts in the card to the same bias state if 1602 /* Force all contexts in the card to the same bias state if
1501 * they're not ground referenced. 1603 * they're not ground referenced.
1502 */ 1604 */
@@ -1546,12 +1648,6 @@ static int dapm_power_widgets(struct snd_soc_dapm_context *dapm, int event)
1546} 1648}
1547 1649
1548#ifdef CONFIG_DEBUG_FS 1650#ifdef CONFIG_DEBUG_FS
1549static int dapm_widget_power_open_file(struct inode *inode, struct file *file)
1550{
1551 file->private_data = inode->i_private;
1552 return 0;
1553}
1554
1555static ssize_t dapm_widget_power_read_file(struct file *file, 1651static ssize_t dapm_widget_power_read_file(struct file *file,
1556 char __user *user_buf, 1652 char __user *user_buf,
1557 size_t count, loff_t *ppos) 1653 size_t count, loff_t *ppos)
@@ -1566,9 +1662,9 @@ static ssize_t dapm_widget_power_read_file(struct file *file,
1566 if (!buf) 1662 if (!buf)
1567 return -ENOMEM; 1663 return -ENOMEM;
1568 1664
1569 in = is_connected_input_ep(w); 1665 in = is_connected_input_ep(w, NULL);
1570 dapm_clear_walk(w->dapm); 1666 dapm_clear_walk(w->dapm);
1571 out = is_connected_output_ep(w); 1667 out = is_connected_output_ep(w, NULL);
1572 dapm_clear_walk(w->dapm); 1668 dapm_clear_walk(w->dapm);
1573 1669
1574 ret = snprintf(buf, PAGE_SIZE, "%s: %s%s in %d out %d", 1670 ret = snprintf(buf, PAGE_SIZE, "%s: %s%s in %d out %d",
@@ -1615,17 +1711,11 @@ static ssize_t dapm_widget_power_read_file(struct file *file,
1615} 1711}
1616 1712
1617static const struct file_operations dapm_widget_power_fops = { 1713static const struct file_operations dapm_widget_power_fops = {
1618 .open = dapm_widget_power_open_file, 1714 .open = simple_open,
1619 .read = dapm_widget_power_read_file, 1715 .read = dapm_widget_power_read_file,
1620 .llseek = default_llseek, 1716 .llseek = default_llseek,
1621}; 1717};
1622 1718
1623static int dapm_bias_open_file(struct inode *inode, struct file *file)
1624{
1625 file->private_data = inode->i_private;
1626 return 0;
1627}
1628
1629static ssize_t dapm_bias_read_file(struct file *file, char __user *user_buf, 1719static ssize_t dapm_bias_read_file(struct file *file, char __user *user_buf,
1630 size_t count, loff_t *ppos) 1720 size_t count, loff_t *ppos)
1631{ 1721{
@@ -1656,7 +1746,7 @@ static ssize_t dapm_bias_read_file(struct file *file, char __user *user_buf,
1656} 1746}
1657 1747
1658static const struct file_operations dapm_bias_fops = { 1748static const struct file_operations dapm_bias_fops = {
1659 .open = dapm_bias_open_file, 1749 .open = simple_open,
1660 .read = dapm_bias_read_file, 1750 .read = dapm_bias_read_file,
1661 .llseek = default_llseek, 1751 .llseek = default_llseek,
1662}; 1752};
@@ -1721,7 +1811,7 @@ static inline void dapm_debugfs_cleanup(struct snd_soc_dapm_context *dapm)
1721#endif 1811#endif
1722 1812
1723/* test and update the power status of a mux widget */ 1813/* test and update the power status of a mux widget */
1724int snd_soc_dapm_mux_update_power(struct snd_soc_dapm_widget *widget, 1814static int soc_dapm_mux_update_power(struct snd_soc_dapm_widget *widget,
1725 struct snd_kcontrol *kcontrol, int mux, struct soc_enum *e) 1815 struct snd_kcontrol *kcontrol, int mux, struct soc_enum *e)
1726{ 1816{
1727 struct snd_soc_dapm_path *path; 1817 struct snd_soc_dapm_path *path;
@@ -1758,12 +1848,26 @@ int snd_soc_dapm_mux_update_power(struct snd_soc_dapm_widget *widget,
1758 dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP); 1848 dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP);
1759 } 1849 }
1760 1850
1761 return 0; 1851 return found;
1852}
1853
1854int snd_soc_dapm_mux_update_power(struct snd_soc_dapm_widget *widget,
1855 struct snd_kcontrol *kcontrol, int mux, struct soc_enum *e)
1856{
1857 struct snd_soc_card *card = widget->dapm->card;
1858 int ret;
1859
1860 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
1861 ret = soc_dapm_mux_update_power(widget, kcontrol, mux, e);
1862 mutex_unlock(&card->dapm_mutex);
1863 if (ret > 0)
1864 soc_dpcm_runtime_update(widget);
1865 return ret;
1762} 1866}
1763EXPORT_SYMBOL_GPL(snd_soc_dapm_mux_update_power); 1867EXPORT_SYMBOL_GPL(snd_soc_dapm_mux_update_power);
1764 1868
1765/* test and update the power status of a mixer or switch widget */ 1869/* test and update the power status of a mixer or switch widget */
1766int snd_soc_dapm_mixer_update_power(struct snd_soc_dapm_widget *widget, 1870static int soc_dapm_mixer_update_power(struct snd_soc_dapm_widget *widget,
1767 struct snd_kcontrol *kcontrol, int connect) 1871 struct snd_kcontrol *kcontrol, int connect)
1768{ 1872{
1769 struct snd_soc_dapm_path *path; 1873 struct snd_soc_dapm_path *path;
@@ -1790,7 +1894,21 @@ int snd_soc_dapm_mixer_update_power(struct snd_soc_dapm_widget *widget,
1790 dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP); 1894 dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP);
1791 } 1895 }
1792 1896
1793 return 0; 1897 return found;
1898}
1899
1900int snd_soc_dapm_mixer_update_power(struct snd_soc_dapm_widget *widget,
1901 struct snd_kcontrol *kcontrol, int connect)
1902{
1903 struct snd_soc_card *card = widget->dapm->card;
1904 int ret;
1905
1906 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
1907 ret = soc_dapm_mixer_update_power(widget, kcontrol, connect);
1908 mutex_unlock(&card->dapm_mutex);
1909 if (ret > 0)
1910 soc_dpcm_runtime_update(widget);
1911 return ret;
1794} 1912}
1795EXPORT_SYMBOL_GPL(snd_soc_dapm_mixer_update_power); 1913EXPORT_SYMBOL_GPL(snd_soc_dapm_mixer_update_power);
1796 1914
@@ -1951,6 +2069,8 @@ static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context *dapm,
1951 */ 2069 */
1952int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm) 2070int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm)
1953{ 2071{
2072 int ret;
2073
1954 /* 2074 /*
1955 * Suppress early reports (eg, jacks syncing their state) to avoid 2075 * Suppress early reports (eg, jacks syncing their state) to avoid
1956 * silly DAPM runs during card startup. 2076 * silly DAPM runs during card startup.
@@ -1958,7 +2078,10 @@ int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm)
1958 if (!dapm->card || !dapm->card->instantiated) 2078 if (!dapm->card || !dapm->card->instantiated)
1959 return 0; 2079 return 0;
1960 2080
1961 return dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP); 2081 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2082 ret = dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP);
2083 mutex_unlock(&dapm->card->dapm_mutex);
2084 return ret;
1962} 2085}
1963EXPORT_SYMBOL_GPL(snd_soc_dapm_sync); 2086EXPORT_SYMBOL_GPL(snd_soc_dapm_sync);
1964 2087
@@ -2067,6 +2190,7 @@ static int snd_soc_dapm_add_route(struct snd_soc_dapm_context *dapm,
2067 case snd_soc_dapm_aif_in: 2190 case snd_soc_dapm_aif_in:
2068 case snd_soc_dapm_aif_out: 2191 case snd_soc_dapm_aif_out:
2069 case snd_soc_dapm_dai: 2192 case snd_soc_dapm_dai:
2193 case snd_soc_dapm_dai_link:
2070 list_add(&path->list, &dapm->card->paths); 2194 list_add(&path->list, &dapm->card->paths);
2071 list_add(&path->list_sink, &wsink->sources); 2195 list_add(&path->list_sink, &wsink->sources);
2072 list_add(&path->list_source, &wsource->sinks); 2196 list_add(&path->list_source, &wsource->sinks);
@@ -2122,19 +2246,21 @@ err:
2122int snd_soc_dapm_add_routes(struct snd_soc_dapm_context *dapm, 2246int snd_soc_dapm_add_routes(struct snd_soc_dapm_context *dapm,
2123 const struct snd_soc_dapm_route *route, int num) 2247 const struct snd_soc_dapm_route *route, int num)
2124{ 2248{
2125 int i, ret; 2249 int i, ret = 0;
2126 2250
2251 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT);
2127 for (i = 0; i < num; i++) { 2252 for (i = 0; i < num; i++) {
2128 ret = snd_soc_dapm_add_route(dapm, route); 2253 ret = snd_soc_dapm_add_route(dapm, route);
2129 if (ret < 0) { 2254 if (ret < 0) {
2130 dev_err(dapm->dev, "Failed to add route %s->%s\n", 2255 dev_err(dapm->dev, "Failed to add route %s->%s\n",
2131 route->source, route->sink); 2256 route->source, route->sink);
2132 return ret; 2257 break;
2133 } 2258 }
2134 route++; 2259 route++;
2135 } 2260 }
2261 mutex_unlock(&dapm->card->dapm_mutex);
2136 2262
2137 return 0; 2263 return ret;
2138} 2264}
2139EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes); 2265EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes);
2140 2266
@@ -2205,12 +2331,14 @@ int snd_soc_dapm_weak_routes(struct snd_soc_dapm_context *dapm,
2205 int i, err; 2331 int i, err;
2206 int ret = 0; 2332 int ret = 0;
2207 2333
2334 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT);
2208 for (i = 0; i < num; i++) { 2335 for (i = 0; i < num; i++) {
2209 err = snd_soc_dapm_weak_route(dapm, route); 2336 err = snd_soc_dapm_weak_route(dapm, route);
2210 if (err) 2337 if (err)
2211 ret = err; 2338 ret = err;
2212 route++; 2339 route++;
2213 } 2340 }
2341 mutex_unlock(&dapm->card->dapm_mutex);
2214 2342
2215 return ret; 2343 return ret;
2216} 2344}
@@ -2229,6 +2357,8 @@ int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context *dapm)
2229 struct snd_soc_dapm_widget *w; 2357 struct snd_soc_dapm_widget *w;
2230 unsigned int val; 2358 unsigned int val;
2231 2359
2360 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT);
2361
2232 list_for_each_entry(w, &dapm->card->widgets, list) 2362 list_for_each_entry(w, &dapm->card->widgets, list)
2233 { 2363 {
2234 if (w->new) 2364 if (w->new)
@@ -2238,8 +2368,10 @@ int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context *dapm)
2238 w->kcontrols = kzalloc(w->num_kcontrols * 2368 w->kcontrols = kzalloc(w->num_kcontrols *
2239 sizeof(struct snd_kcontrol *), 2369 sizeof(struct snd_kcontrol *),
2240 GFP_KERNEL); 2370 GFP_KERNEL);
2241 if (!w->kcontrols) 2371 if (!w->kcontrols) {
2372 mutex_unlock(&dapm->card->dapm_mutex);
2242 return -ENOMEM; 2373 return -ENOMEM;
2374 }
2243 } 2375 }
2244 2376
2245 switch(w->id) { 2377 switch(w->id) {
@@ -2279,6 +2411,7 @@ int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context *dapm)
2279 } 2411 }
2280 2412
2281 dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP); 2413 dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP);
2414 mutex_unlock(&dapm->card->dapm_mutex);
2282 return 0; 2415 return 0;
2283} 2416}
2284EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets); 2417EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets);
@@ -2338,6 +2471,7 @@ int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,
2338 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); 2471 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2339 struct snd_soc_dapm_widget *widget = wlist->widgets[0]; 2472 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2340 struct snd_soc_codec *codec = widget->codec; 2473 struct snd_soc_codec *codec = widget->codec;
2474 struct snd_soc_card *card = codec->card;
2341 struct soc_mixer_control *mc = 2475 struct soc_mixer_control *mc =
2342 (struct soc_mixer_control *)kcontrol->private_value; 2476 (struct soc_mixer_control *)kcontrol->private_value;
2343 unsigned int reg = mc->reg; 2477 unsigned int reg = mc->reg;
@@ -2364,7 +2498,7 @@ int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,
2364 /* old connection must be powered down */ 2498 /* old connection must be powered down */
2365 connect = invert ? 1 : 0; 2499 connect = invert ? 1 : 0;
2366 2500
2367 mutex_lock(&codec->mutex); 2501 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2368 2502
2369 change = snd_soc_test_bits(widget->codec, reg, mask, val); 2503 change = snd_soc_test_bits(widget->codec, reg, mask, val);
2370 if (change) { 2504 if (change) {
@@ -2380,13 +2514,13 @@ int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,
2380 update.val = val; 2514 update.val = val;
2381 widget->dapm->update = &update; 2515 widget->dapm->update = &update;
2382 2516
2383 snd_soc_dapm_mixer_update_power(widget, kcontrol, connect); 2517 soc_dapm_mixer_update_power(widget, kcontrol, connect);
2384 2518
2385 widget->dapm->update = NULL; 2519 widget->dapm->update = NULL;
2386 } 2520 }
2387 } 2521 }
2388 2522
2389 mutex_unlock(&codec->mutex); 2523 mutex_unlock(&card->dapm_mutex);
2390 return 0; 2524 return 0;
2391} 2525}
2392EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw); 2526EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw);
@@ -2435,6 +2569,7 @@ int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
2435 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); 2569 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2436 struct snd_soc_dapm_widget *widget = wlist->widgets[0]; 2570 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2437 struct snd_soc_codec *codec = widget->codec; 2571 struct snd_soc_codec *codec = widget->codec;
2572 struct snd_soc_card *card = codec->card;
2438 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 2573 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2439 unsigned int val, mux, change; 2574 unsigned int val, mux, change;
2440 unsigned int mask, bitmask; 2575 unsigned int mask, bitmask;
@@ -2455,7 +2590,7 @@ int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
2455 mask |= (bitmask - 1) << e->shift_r; 2590 mask |= (bitmask - 1) << e->shift_r;
2456 } 2591 }
2457 2592
2458 mutex_lock(&codec->mutex); 2593 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2459 2594
2460 change = snd_soc_test_bits(widget->codec, e->reg, mask, val); 2595 change = snd_soc_test_bits(widget->codec, e->reg, mask, val);
2461 if (change) { 2596 if (change) {
@@ -2471,13 +2606,13 @@ int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
2471 update.val = val; 2606 update.val = val;
2472 widget->dapm->update = &update; 2607 widget->dapm->update = &update;
2473 2608
2474 snd_soc_dapm_mux_update_power(widget, kcontrol, mux, e); 2609 soc_dapm_mux_update_power(widget, kcontrol, mux, e);
2475 2610
2476 widget->dapm->update = NULL; 2611 widget->dapm->update = NULL;
2477 } 2612 }
2478 } 2613 }
2479 2614
2480 mutex_unlock(&codec->mutex); 2615 mutex_unlock(&card->dapm_mutex);
2481 return change; 2616 return change;
2482} 2617}
2483EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double); 2618EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double);
@@ -2514,6 +2649,7 @@ int snd_soc_dapm_put_enum_virt(struct snd_kcontrol *kcontrol,
2514 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); 2649 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2515 struct snd_soc_dapm_widget *widget = wlist->widgets[0]; 2650 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2516 struct snd_soc_codec *codec = widget->codec; 2651 struct snd_soc_codec *codec = widget->codec;
2652 struct snd_soc_card *card = codec->card;
2517 struct soc_enum *e = 2653 struct soc_enum *e =
2518 (struct soc_enum *)kcontrol->private_value; 2654 (struct soc_enum *)kcontrol->private_value;
2519 int change; 2655 int change;
@@ -2523,7 +2659,7 @@ int snd_soc_dapm_put_enum_virt(struct snd_kcontrol *kcontrol,
2523 if (ucontrol->value.enumerated.item[0] >= e->max) 2659 if (ucontrol->value.enumerated.item[0] >= e->max)
2524 return -EINVAL; 2660 return -EINVAL;
2525 2661
2526 mutex_lock(&codec->mutex); 2662 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2527 2663
2528 change = widget->value != ucontrol->value.enumerated.item[0]; 2664 change = widget->value != ucontrol->value.enumerated.item[0];
2529 if (change) { 2665 if (change) {
@@ -2532,11 +2668,11 @@ int snd_soc_dapm_put_enum_virt(struct snd_kcontrol *kcontrol,
2532 2668
2533 widget->value = ucontrol->value.enumerated.item[0]; 2669 widget->value = ucontrol->value.enumerated.item[0];
2534 2670
2535 snd_soc_dapm_mux_update_power(widget, kcontrol, widget->value, e); 2671 soc_dapm_mux_update_power(widget, kcontrol, widget->value, e);
2536 } 2672 }
2537 } 2673 }
2538 2674
2539 mutex_unlock(&codec->mutex); 2675 mutex_unlock(&card->dapm_mutex);
2540 return ret; 2676 return ret;
2541} 2677}
2542EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_virt); 2678EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_virt);
@@ -2601,6 +2737,7 @@ int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol,
2601 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); 2737 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2602 struct snd_soc_dapm_widget *widget = wlist->widgets[0]; 2738 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2603 struct snd_soc_codec *codec = widget->codec; 2739 struct snd_soc_codec *codec = widget->codec;
2740 struct snd_soc_card *card = codec->card;
2604 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 2741 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2605 unsigned int val, mux, change; 2742 unsigned int val, mux, change;
2606 unsigned int mask; 2743 unsigned int mask;
@@ -2619,7 +2756,7 @@ int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol,
2619 mask |= e->mask << e->shift_r; 2756 mask |= e->mask << e->shift_r;
2620 } 2757 }
2621 2758
2622 mutex_lock(&codec->mutex); 2759 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2623 2760
2624 change = snd_soc_test_bits(widget->codec, e->reg, mask, val); 2761 change = snd_soc_test_bits(widget->codec, e->reg, mask, val);
2625 if (change) { 2762 if (change) {
@@ -2635,13 +2772,13 @@ int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol,
2635 update.val = val; 2772 update.val = val;
2636 widget->dapm->update = &update; 2773 widget->dapm->update = &update;
2637 2774
2638 snd_soc_dapm_mux_update_power(widget, kcontrol, mux, e); 2775 soc_dapm_mux_update_power(widget, kcontrol, mux, e);
2639 2776
2640 widget->dapm->update = NULL; 2777 widget->dapm->update = NULL;
2641 } 2778 }
2642 } 2779 }
2643 2780
2644 mutex_unlock(&codec->mutex); 2781 mutex_unlock(&card->dapm_mutex);
2645 return change; 2782 return change;
2646} 2783}
2647EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double); 2784EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double);
@@ -2678,12 +2815,12 @@ int snd_soc_dapm_get_pin_switch(struct snd_kcontrol *kcontrol,
2678 struct snd_soc_card *card = snd_kcontrol_chip(kcontrol); 2815 struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
2679 const char *pin = (const char *)kcontrol->private_value; 2816 const char *pin = (const char *)kcontrol->private_value;
2680 2817
2681 mutex_lock(&card->mutex); 2818 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2682 2819
2683 ucontrol->value.integer.value[0] = 2820 ucontrol->value.integer.value[0] =
2684 snd_soc_dapm_get_pin_status(&card->dapm, pin); 2821 snd_soc_dapm_get_pin_status(&card->dapm, pin);
2685 2822
2686 mutex_unlock(&card->mutex); 2823 mutex_unlock(&card->dapm_mutex);
2687 2824
2688 return 0; 2825 return 0;
2689} 2826}
@@ -2701,17 +2838,16 @@ int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol,
2701 struct snd_soc_card *card = snd_kcontrol_chip(kcontrol); 2838 struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
2702 const char *pin = (const char *)kcontrol->private_value; 2839 const char *pin = (const char *)kcontrol->private_value;
2703 2840
2704 mutex_lock(&card->mutex); 2841 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2705 2842
2706 if (ucontrol->value.integer.value[0]) 2843 if (ucontrol->value.integer.value[0])
2707 snd_soc_dapm_enable_pin(&card->dapm, pin); 2844 snd_soc_dapm_enable_pin(&card->dapm, pin);
2708 else 2845 else
2709 snd_soc_dapm_disable_pin(&card->dapm, pin); 2846 snd_soc_dapm_disable_pin(&card->dapm, pin);
2710 2847
2711 snd_soc_dapm_sync(&card->dapm); 2848 mutex_unlock(&card->dapm_mutex);
2712
2713 mutex_unlock(&card->mutex);
2714 2849
2850 snd_soc_dapm_sync(&card->dapm);
2715 return 0; 2851 return 0;
2716} 2852}
2717EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch); 2853EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch);
@@ -2729,9 +2865,9 @@ snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
2729 2865
2730 switch (w->id) { 2866 switch (w->id) {
2731 case snd_soc_dapm_regulator_supply: 2867 case snd_soc_dapm_regulator_supply:
2732 w->priv = devm_regulator_get(dapm->dev, w->name); 2868 w->regulator = devm_regulator_get(dapm->dev, w->name);
2733 if (IS_ERR(w->priv)) { 2869 if (IS_ERR(w->regulator)) {
2734 ret = PTR_ERR(w->priv); 2870 ret = PTR_ERR(w->regulator);
2735 dev_err(dapm->dev, "Failed to request %s: %d\n", 2871 dev_err(dapm->dev, "Failed to request %s: %d\n",
2736 w->name, ret); 2872 w->name, ret);
2737 return NULL; 2873 return NULL;
@@ -2783,6 +2919,7 @@ snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
2783 case snd_soc_dapm_hp: 2919 case snd_soc_dapm_hp:
2784 case snd_soc_dapm_mic: 2920 case snd_soc_dapm_mic:
2785 case snd_soc_dapm_line: 2921 case snd_soc_dapm_line:
2922 case snd_soc_dapm_dai_link:
2786 w->power_check = dapm_generic_check_power; 2923 w->power_check = dapm_generic_check_power;
2787 break; 2924 break;
2788 case snd_soc_dapm_supply: 2925 case snd_soc_dapm_supply:
@@ -2828,21 +2965,177 @@ int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm,
2828{ 2965{
2829 struct snd_soc_dapm_widget *w; 2966 struct snd_soc_dapm_widget *w;
2830 int i; 2967 int i;
2968 int ret = 0;
2831 2969
2970 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT);
2832 for (i = 0; i < num; i++) { 2971 for (i = 0; i < num; i++) {
2833 w = snd_soc_dapm_new_control(dapm, widget); 2972 w = snd_soc_dapm_new_control(dapm, widget);
2834 if (!w) { 2973 if (!w) {
2835 dev_err(dapm->dev, 2974 dev_err(dapm->dev,
2836 "ASoC: Failed to create DAPM control %s\n", 2975 "ASoC: Failed to create DAPM control %s\n",
2837 widget->name); 2976 widget->name);
2838 return -ENOMEM; 2977 ret = -ENOMEM;
2978 break;
2839 } 2979 }
2840 widget++; 2980 widget++;
2841 } 2981 }
2842 return 0; 2982 mutex_unlock(&dapm->card->dapm_mutex);
2983 return ret;
2843} 2984}
2844EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls); 2985EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls);
2845 2986
2987static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w,
2988 struct snd_kcontrol *kcontrol, int event)
2989{
2990 struct snd_soc_dapm_path *source_p, *sink_p;
2991 struct snd_soc_dai *source, *sink;
2992 const struct snd_soc_pcm_stream *config = w->params;
2993 struct snd_pcm_substream substream;
2994 struct snd_pcm_hw_params *params = NULL;
2995 u64 fmt;
2996 int ret;
2997
2998 BUG_ON(!config);
2999 BUG_ON(list_empty(&w->sources) || list_empty(&w->sinks));
3000
3001 /* We only support a single source and sink, pick the first */
3002 source_p = list_first_entry(&w->sources, struct snd_soc_dapm_path,
3003 list_sink);
3004 sink_p = list_first_entry(&w->sinks, struct snd_soc_dapm_path,
3005 list_source);
3006
3007 BUG_ON(!source_p || !sink_p);
3008 BUG_ON(!sink_p->source || !source_p->sink);
3009 BUG_ON(!source_p->source || !sink_p->sink);
3010
3011 source = source_p->source->priv;
3012 sink = sink_p->sink->priv;
3013
3014 /* Be a little careful as we don't want to overflow the mask array */
3015 if (config->formats) {
3016 fmt = ffs(config->formats) - 1;
3017 } else {
3018 dev_warn(w->dapm->dev, "Invalid format %llx specified\n",
3019 config->formats);
3020 fmt = 0;
3021 }
3022
3023 /* Currently very limited parameter selection */
3024 params = kzalloc(sizeof(*params), GFP_KERNEL);
3025 if (!params) {
3026 ret = -ENOMEM;
3027 goto out;
3028 }
3029 snd_mask_set(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT), fmt);
3030
3031 hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE)->min =
3032 config->rate_min;
3033 hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE)->max =
3034 config->rate_max;
3035
3036 hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS)->min
3037 = config->channels_min;
3038 hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS)->max
3039 = config->channels_max;
3040
3041 memset(&substream, 0, sizeof(substream));
3042
3043 switch (event) {
3044 case SND_SOC_DAPM_PRE_PMU:
3045 if (source->driver->ops && source->driver->ops->hw_params) {
3046 substream.stream = SNDRV_PCM_STREAM_CAPTURE;
3047 ret = source->driver->ops->hw_params(&substream,
3048 params, source);
3049 if (ret != 0) {
3050 dev_err(source->dev,
3051 "hw_params() failed: %d\n", ret);
3052 goto out;
3053 }
3054 }
3055
3056 if (sink->driver->ops && sink->driver->ops->hw_params) {
3057 substream.stream = SNDRV_PCM_STREAM_PLAYBACK;
3058 ret = sink->driver->ops->hw_params(&substream, params,
3059 sink);
3060 if (ret != 0) {
3061 dev_err(sink->dev,
3062 "hw_params() failed: %d\n", ret);
3063 goto out;
3064 }
3065 }
3066 break;
3067
3068 case SND_SOC_DAPM_POST_PMU:
3069 ret = snd_soc_dai_digital_mute(sink, 0);
3070 if (ret != 0 && ret != -ENOTSUPP)
3071 dev_warn(sink->dev, "Failed to unmute: %d\n", ret);
3072 ret = 0;
3073 break;
3074
3075 case SND_SOC_DAPM_PRE_PMD:
3076 ret = snd_soc_dai_digital_mute(sink, 1);
3077 if (ret != 0 && ret != -ENOTSUPP)
3078 dev_warn(sink->dev, "Failed to mute: %d\n", ret);
3079 ret = 0;
3080 break;
3081
3082 default:
3083 BUG();
3084 return -EINVAL;
3085 }
3086
3087out:
3088 kfree(params);
3089 return ret;
3090}
3091
3092int snd_soc_dapm_new_pcm(struct snd_soc_card *card,
3093 const struct snd_soc_pcm_stream *params,
3094 struct snd_soc_dapm_widget *source,
3095 struct snd_soc_dapm_widget *sink)
3096{
3097 struct snd_soc_dapm_route routes[2];
3098 struct snd_soc_dapm_widget template;
3099 struct snd_soc_dapm_widget *w;
3100 size_t len;
3101 char *link_name;
3102
3103 len = strlen(source->name) + strlen(sink->name) + 2;
3104 link_name = devm_kzalloc(card->dev, len, GFP_KERNEL);
3105 if (!link_name)
3106 return -ENOMEM;
3107 snprintf(link_name, len, "%s-%s", source->name, sink->name);
3108
3109 memset(&template, 0, sizeof(template));
3110 template.reg = SND_SOC_NOPM;
3111 template.id = snd_soc_dapm_dai_link;
3112 template.name = link_name;
3113 template.event = snd_soc_dai_link_event;
3114 template.event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
3115 SND_SOC_DAPM_PRE_PMD;
3116
3117 dev_dbg(card->dev, "adding %s widget\n", link_name);
3118
3119 w = snd_soc_dapm_new_control(&card->dapm, &template);
3120 if (!w) {
3121 dev_err(card->dev, "Failed to create %s widget\n",
3122 link_name);
3123 return -ENOMEM;
3124 }
3125
3126 w->params = params;
3127
3128 memset(&routes, 0, sizeof(routes));
3129
3130 routes[0].source = source->name;
3131 routes[0].sink = link_name;
3132 routes[1].source = link_name;
3133 routes[1].sink = sink->name;
3134
3135 return snd_soc_dapm_add_routes(&card->dapm, routes,
3136 ARRAY_SIZE(routes));
3137}
3138
2846int snd_soc_dapm_new_dai_widgets(struct snd_soc_dapm_context *dapm, 3139int snd_soc_dapm_new_dai_widgets(struct snd_soc_dapm_context *dapm,
2847 struct snd_soc_dai *dai) 3140 struct snd_soc_dai *dai)
2848{ 3141{
@@ -2946,37 +3239,61 @@ int snd_soc_dapm_link_dai_widgets(struct snd_soc_card *card)
2946 return 0; 3239 return 0;
2947} 3240}
2948 3241
2949static void soc_dapm_stream_event(struct snd_soc_dapm_context *dapm, 3242static void soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream,
2950 int stream, struct snd_soc_dai *dai, 3243 int event)
2951 int event)
2952{ 3244{
2953 struct snd_soc_dapm_widget *w;
2954 3245
2955 if (stream == SNDRV_PCM_STREAM_PLAYBACK) 3246 struct snd_soc_dapm_widget *w_cpu, *w_codec;
2956 w = dai->playback_widget; 3247 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
2957 else 3248 struct snd_soc_dai *codec_dai = rtd->codec_dai;
2958 w = dai->capture_widget;
2959 3249
2960 if (!w) 3250 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
2961 return; 3251 w_cpu = cpu_dai->playback_widget;
3252 w_codec = codec_dai->playback_widget;
3253 } else {
3254 w_cpu = cpu_dai->capture_widget;
3255 w_codec = codec_dai->capture_widget;
3256 }
2962 3257
2963 dapm_mark_dirty(w, "stream event"); 3258 if (w_cpu) {
2964 3259
2965 switch (event) { 3260 dapm_mark_dirty(w_cpu, "stream event");
2966 case SND_SOC_DAPM_STREAM_START: 3261
2967 w->active = 1; 3262 switch (event) {
2968 break; 3263 case SND_SOC_DAPM_STREAM_START:
2969 case SND_SOC_DAPM_STREAM_STOP: 3264 w_cpu->active = 1;
2970 w->active = 0; 3265 break;
2971 break; 3266 case SND_SOC_DAPM_STREAM_STOP:
2972 case SND_SOC_DAPM_STREAM_SUSPEND: 3267 w_cpu->active = 0;
2973 case SND_SOC_DAPM_STREAM_RESUME: 3268 break;
2974 case SND_SOC_DAPM_STREAM_PAUSE_PUSH: 3269 case SND_SOC_DAPM_STREAM_SUSPEND:
2975 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE: 3270 case SND_SOC_DAPM_STREAM_RESUME:
2976 break; 3271 case SND_SOC_DAPM_STREAM_PAUSE_PUSH:
3272 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE:
3273 break;
3274 }
2977 } 3275 }
2978 3276
2979 dapm_power_widgets(dapm, event); 3277 if (w_codec) {
3278
3279 dapm_mark_dirty(w_codec, "stream event");
3280
3281 switch (event) {
3282 case SND_SOC_DAPM_STREAM_START:
3283 w_codec->active = 1;
3284 break;
3285 case SND_SOC_DAPM_STREAM_STOP:
3286 w_codec->active = 0;
3287 break;
3288 case SND_SOC_DAPM_STREAM_SUSPEND:
3289 case SND_SOC_DAPM_STREAM_RESUME:
3290 case SND_SOC_DAPM_STREAM_PAUSE_PUSH:
3291 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE:
3292 break;
3293 }
3294 }
3295
3296 dapm_power_widgets(&rtd->card->dapm, event);
2980} 3297}
2981 3298
2982/** 3299/**
@@ -2990,15 +3307,14 @@ static void soc_dapm_stream_event(struct snd_soc_dapm_context *dapm,
2990 * 3307 *
2991 * Returns 0 for success else error. 3308 * Returns 0 for success else error.
2992 */ 3309 */
2993int snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream, 3310void snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream,
2994 struct snd_soc_dai *dai, int event) 3311 int event)
2995{ 3312{
2996 struct snd_soc_codec *codec = rtd->codec; 3313 struct snd_soc_card *card = rtd->card;
2997 3314
2998 mutex_lock(&codec->mutex); 3315 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2999 soc_dapm_stream_event(&codec->dapm, stream, dai, event); 3316 soc_dapm_stream_event(rtd, stream, event);
3000 mutex_unlock(&codec->mutex); 3317 mutex_unlock(&card->dapm_mutex);
3001 return 0;
3002} 3318}
3003 3319
3004/** 3320/**
diff --git a/sound/soc/soc-jack.c b/sound/soc/soc-jack.c
index ee4353f843ea..7f8b3b7428bb 100644
--- a/sound/soc/soc-jack.c
+++ b/sound/soc/soc-jack.c
@@ -36,6 +36,7 @@
36int snd_soc_jack_new(struct snd_soc_codec *codec, const char *id, int type, 36int snd_soc_jack_new(struct snd_soc_codec *codec, const char *id, int type,
37 struct snd_soc_jack *jack) 37 struct snd_soc_jack *jack)
38{ 38{
39 mutex_init(&jack->mutex);
39 jack->codec = codec; 40 jack->codec = codec;
40 INIT_LIST_HEAD(&jack->pins); 41 INIT_LIST_HEAD(&jack->pins);
41 INIT_LIST_HEAD(&jack->jack_zones); 42 INIT_LIST_HEAD(&jack->jack_zones);
@@ -75,7 +76,7 @@ void snd_soc_jack_report(struct snd_soc_jack *jack, int status, int mask)
75 codec = jack->codec; 76 codec = jack->codec;
76 dapm = &codec->dapm; 77 dapm = &codec->dapm;
77 78
78 mutex_lock(&codec->mutex); 79 mutex_lock(&jack->mutex);
79 80
80 oldstatus = jack->status; 81 oldstatus = jack->status;
81 82
@@ -109,7 +110,7 @@ void snd_soc_jack_report(struct snd_soc_jack *jack, int status, int mask)
109 snd_jack_report(jack->jack, jack->status); 110 snd_jack_report(jack->jack, jack->status);
110 111
111out: 112out:
112 mutex_unlock(&codec->mutex); 113 mutex_unlock(&jack->mutex);
113} 114}
114EXPORT_SYMBOL_GPL(snd_soc_jack_report); 115EXPORT_SYMBOL_GPL(snd_soc_jack_report);
115 116
diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
index 0ad8dcacd2f3..bedd1717a373 100644
--- a/sound/soc/soc-pcm.c
+++ b/sound/soc/soc-pcm.c
@@ -22,12 +22,38 @@
22#include <linux/pm_runtime.h> 22#include <linux/pm_runtime.h>
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/workqueue.h> 24#include <linux/workqueue.h>
25#include <linux/export.h>
26#include <linux/debugfs.h>
25#include <sound/core.h> 27#include <sound/core.h>
26#include <sound/pcm.h> 28#include <sound/pcm.h>
27#include <sound/pcm_params.h> 29#include <sound/pcm_params.h>
28#include <sound/soc.h> 30#include <sound/soc.h>
31#include <sound/soc-dpcm.h>
29#include <sound/initval.h> 32#include <sound/initval.h>
30 33
34#define DPCM_MAX_BE_USERS 8
35
36/* DPCM stream event, send event to FE and all active BEs. */
37static int dpcm_dapm_stream_event(struct snd_soc_pcm_runtime *fe, int dir,
38 int event)
39{
40 struct snd_soc_dpcm *dpcm;
41
42 list_for_each_entry(dpcm, &fe->dpcm[dir].be_clients, list_be) {
43
44 struct snd_soc_pcm_runtime *be = dpcm->be;
45
46 dev_dbg(be->dev, "pm: BE %s event %d dir %d\n",
47 be->dai_link->name, event, dir);
48
49 snd_soc_dapm_stream_event(be, dir, event);
50 }
51
52 snd_soc_dapm_stream_event(fe, dir, event);
53
54 return 0;
55}
56
31static int soc_pcm_apply_symmetry(struct snd_pcm_substream *substream, 57static int soc_pcm_apply_symmetry(struct snd_pcm_substream *substream,
32 struct snd_soc_dai *soc_dai) 58 struct snd_soc_dai *soc_dai)
33{ 59{
@@ -156,6 +182,10 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
156 } 182 }
157 } 183 }
158 184
185 /* Dynamic PCM DAI links compat checks use dynamic capabilities */
186 if (rtd->dai_link->dynamic || rtd->dai_link->no_pcm)
187 goto dynamic;
188
159 /* Check that the codec and cpu DAIs are compatible */ 189 /* Check that the codec and cpu DAIs are compatible */
160 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 190 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
161 runtime->hw.rate_min = 191 runtime->hw.rate_min =
@@ -248,6 +278,7 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
248 pr_debug("asoc: min rate %d max rate %d\n", runtime->hw.rate_min, 278 pr_debug("asoc: min rate %d max rate %d\n", runtime->hw.rate_min,
249 runtime->hw.rate_max); 279 runtime->hw.rate_max);
250 280
281dynamic:
251 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 282 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
252 cpu_dai->playback_active++; 283 cpu_dai->playback_active++;
253 codec_dai->playback_active++; 284 codec_dai->playback_active++;
@@ -308,7 +339,7 @@ static void close_delayed_work(struct work_struct *work)
308 if (codec_dai->pop_wait == 1) { 339 if (codec_dai->pop_wait == 1) {
309 codec_dai->pop_wait = 0; 340 codec_dai->pop_wait = 0;
310 snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_PLAYBACK, 341 snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_PLAYBACK,
311 codec_dai, SND_SOC_DAPM_STREAM_STOP); 342 SND_SOC_DAPM_STREAM_STOP);
312 } 343 }
313 344
314 mutex_unlock(&rtd->pcm_mutex); 345 mutex_unlock(&rtd->pcm_mutex);
@@ -373,7 +404,6 @@ static int soc_pcm_close(struct snd_pcm_substream *substream)
373 /* powered down playback stream now */ 404 /* powered down playback stream now */
374 snd_soc_dapm_stream_event(rtd, 405 snd_soc_dapm_stream_event(rtd,
375 SNDRV_PCM_STREAM_PLAYBACK, 406 SNDRV_PCM_STREAM_PLAYBACK,
376 codec_dai,
377 SND_SOC_DAPM_STREAM_STOP); 407 SND_SOC_DAPM_STREAM_STOP);
378 } else { 408 } else {
379 /* start delayed pop wq here for playback streams */ 409 /* start delayed pop wq here for playback streams */
@@ -384,7 +414,7 @@ static int soc_pcm_close(struct snd_pcm_substream *substream)
384 } else { 414 } else {
385 /* capture streams can be powered down now */ 415 /* capture streams can be powered down now */
386 snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_CAPTURE, 416 snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_CAPTURE,
387 codec_dai, SND_SOC_DAPM_STREAM_STOP); 417 SND_SOC_DAPM_STREAM_STOP);
388 } 418 }
389 419
390 mutex_unlock(&rtd->pcm_mutex); 420 mutex_unlock(&rtd->pcm_mutex);
@@ -453,8 +483,8 @@ static int soc_pcm_prepare(struct snd_pcm_substream *substream)
453 cancel_delayed_work(&rtd->delayed_work); 483 cancel_delayed_work(&rtd->delayed_work);
454 } 484 }
455 485
456 snd_soc_dapm_stream_event(rtd, substream->stream, codec_dai, 486 snd_soc_dapm_stream_event(rtd, substream->stream,
457 SND_SOC_DAPM_STREAM_START); 487 SND_SOC_DAPM_STREAM_START);
458 488
459 snd_soc_dai_digital_mute(codec_dai, 0); 489 snd_soc_dai_digital_mute(codec_dai, 0);
460 490
@@ -602,6 +632,34 @@ static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
602 return 0; 632 return 0;
603} 633}
604 634
635static int soc_pcm_bespoke_trigger(struct snd_pcm_substream *substream,
636 int cmd)
637{
638 struct snd_soc_pcm_runtime *rtd = substream->private_data;
639 struct snd_soc_platform *platform = rtd->platform;
640 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
641 struct snd_soc_dai *codec_dai = rtd->codec_dai;
642 int ret;
643
644 if (codec_dai->driver->ops->bespoke_trigger) {
645 ret = codec_dai->driver->ops->bespoke_trigger(substream, cmd, codec_dai);
646 if (ret < 0)
647 return ret;
648 }
649
650 if (platform->driver->bespoke_trigger) {
651 ret = platform->driver->bespoke_trigger(substream, cmd);
652 if (ret < 0)
653 return ret;
654 }
655
656 if (cpu_dai->driver->ops->bespoke_trigger) {
657 ret = cpu_dai->driver->ops->bespoke_trigger(substream, cmd, cpu_dai);
658 if (ret < 0)
659 return ret;
660 }
661 return 0;
662}
605/* 663/*
606 * soc level wrapper for pointer callback 664 * soc level wrapper for pointer callback
607 * If cpu_dai, codec_dai, platform driver has the delay callback, than 665 * If cpu_dai, codec_dai, platform driver has the delay callback, than
@@ -634,6 +692,1308 @@ static snd_pcm_uframes_t soc_pcm_pointer(struct snd_pcm_substream *substream)
634 return offset; 692 return offset;
635} 693}
636 694
695/* connect a FE and BE */
696static int dpcm_be_connect(struct snd_soc_pcm_runtime *fe,
697 struct snd_soc_pcm_runtime *be, int stream)
698{
699 struct snd_soc_dpcm *dpcm;
700
701 /* only add new dpcms */
702 list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
703 if (dpcm->be == be && dpcm->fe == fe)
704 return 0;
705 }
706
707 dpcm = kzalloc(sizeof(struct snd_soc_dpcm), GFP_KERNEL);
708 if (!dpcm)
709 return -ENOMEM;
710
711 dpcm->be = be;
712 dpcm->fe = fe;
713 be->dpcm[stream].runtime = fe->dpcm[stream].runtime;
714 dpcm->state = SND_SOC_DPCM_LINK_STATE_NEW;
715 list_add(&dpcm->list_be, &fe->dpcm[stream].be_clients);
716 list_add(&dpcm->list_fe, &be->dpcm[stream].fe_clients);
717
718 dev_dbg(fe->dev, " connected new DPCM %s path %s %s %s\n",
719 stream ? "capture" : "playback", fe->dai_link->name,
720 stream ? "<-" : "->", be->dai_link->name);
721
722#ifdef CONFIG_DEBUG_FS
723 dpcm->debugfs_state = debugfs_create_u32(be->dai_link->name, 0644,
724 fe->debugfs_dpcm_root, &dpcm->state);
725#endif
726 return 1;
727}
728
729/* reparent a BE onto another FE */
730static void dpcm_be_reparent(struct snd_soc_pcm_runtime *fe,
731 struct snd_soc_pcm_runtime *be, int stream)
732{
733 struct snd_soc_dpcm *dpcm;
734 struct snd_pcm_substream *fe_substream, *be_substream;
735
736 /* reparent if BE is connected to other FEs */
737 if (!be->dpcm[stream].users)
738 return;
739
740 be_substream = snd_soc_dpcm_get_substream(be, stream);
741
742 list_for_each_entry(dpcm, &be->dpcm[stream].fe_clients, list_fe) {
743 if (dpcm->fe == fe)
744 continue;
745
746 dev_dbg(fe->dev, " reparent %s path %s %s %s\n",
747 stream ? "capture" : "playback",
748 dpcm->fe->dai_link->name,
749 stream ? "<-" : "->", dpcm->be->dai_link->name);
750
751 fe_substream = snd_soc_dpcm_get_substream(dpcm->fe, stream);
752 be_substream->runtime = fe_substream->runtime;
753 break;
754 }
755}
756
757/* disconnect a BE and FE */
758static void dpcm_be_disconnect(struct snd_soc_pcm_runtime *fe, int stream)
759{
760 struct snd_soc_dpcm *dpcm, *d;
761
762 list_for_each_entry_safe(dpcm, d, &fe->dpcm[stream].be_clients, list_be) {
763 dev_dbg(fe->dev, "BE %s disconnect check for %s\n",
764 stream ? "capture" : "playback",
765 dpcm->be->dai_link->name);
766
767 if (dpcm->state != SND_SOC_DPCM_LINK_STATE_FREE)
768 continue;
769
770 dev_dbg(fe->dev, " freed DSP %s path %s %s %s\n",
771 stream ? "capture" : "playback", fe->dai_link->name,
772 stream ? "<-" : "->", dpcm->be->dai_link->name);
773
774 /* BEs still alive need new FE */
775 dpcm_be_reparent(fe, dpcm->be, stream);
776
777#ifdef CONFIG_DEBUG_FS
778 debugfs_remove(dpcm->debugfs_state);
779#endif
780 list_del(&dpcm->list_be);
781 list_del(&dpcm->list_fe);
782 kfree(dpcm);
783 }
784}
785
786/* get BE for DAI widget and stream */
787static struct snd_soc_pcm_runtime *dpcm_get_be(struct snd_soc_card *card,
788 struct snd_soc_dapm_widget *widget, int stream)
789{
790 struct snd_soc_pcm_runtime *be;
791 int i;
792
793 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
794 for (i = 0; i < card->num_links; i++) {
795 be = &card->rtd[i];
796
797 if (be->cpu_dai->playback_widget == widget ||
798 be->codec_dai->playback_widget == widget)
799 return be;
800 }
801 } else {
802
803 for (i = 0; i < card->num_links; i++) {
804 be = &card->rtd[i];
805
806 if (be->cpu_dai->capture_widget == widget ||
807 be->codec_dai->capture_widget == widget)
808 return be;
809 }
810 }
811
812 dev_err(card->dev, "can't get %s BE for %s\n",
813 stream ? "capture" : "playback", widget->name);
814 return NULL;
815}
816
817static inline struct snd_soc_dapm_widget *
818 rtd_get_cpu_widget(struct snd_soc_pcm_runtime *rtd, int stream)
819{
820 if (stream == SNDRV_PCM_STREAM_PLAYBACK)
821 return rtd->cpu_dai->playback_widget;
822 else
823 return rtd->cpu_dai->capture_widget;
824}
825
826static inline struct snd_soc_dapm_widget *
827 rtd_get_codec_widget(struct snd_soc_pcm_runtime *rtd, int stream)
828{
829 if (stream == SNDRV_PCM_STREAM_PLAYBACK)
830 return rtd->codec_dai->playback_widget;
831 else
832 return rtd->codec_dai->capture_widget;
833}
834
835static int widget_in_list(struct snd_soc_dapm_widget_list *list,
836 struct snd_soc_dapm_widget *widget)
837{
838 int i;
839
840 for (i = 0; i < list->num_widgets; i++) {
841 if (widget == list->widgets[i])
842 return 1;
843 }
844
845 return 0;
846}
847
848static int dpcm_path_get(struct snd_soc_pcm_runtime *fe,
849 int stream, struct snd_soc_dapm_widget_list **list_)
850{
851 struct snd_soc_dai *cpu_dai = fe->cpu_dai;
852 struct snd_soc_dapm_widget_list *list;
853 int paths;
854
855 list = kzalloc(sizeof(struct snd_soc_dapm_widget_list) +
856 sizeof(struct snd_soc_dapm_widget *), GFP_KERNEL);
857 if (list == NULL)
858 return -ENOMEM;
859
860 /* get number of valid DAI paths and their widgets */
861 paths = snd_soc_dapm_dai_get_connected_widgets(cpu_dai, stream, &list);
862
863 dev_dbg(fe->dev, "found %d audio %s paths\n", paths,
864 stream ? "capture" : "playback");
865
866 *list_ = list;
867 return paths;
868}
869
870static inline void dpcm_path_put(struct snd_soc_dapm_widget_list **list)
871{
872 kfree(*list);
873}
874
875static int dpcm_prune_paths(struct snd_soc_pcm_runtime *fe, int stream,
876 struct snd_soc_dapm_widget_list **list_)
877{
878 struct snd_soc_dpcm *dpcm;
879 struct snd_soc_dapm_widget_list *list = *list_;
880 struct snd_soc_dapm_widget *widget;
881 int prune = 0;
882
883 /* Destroy any old FE <--> BE connections */
884 list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
885
886 /* is there a valid CPU DAI widget for this BE */
887 widget = rtd_get_cpu_widget(dpcm->be, stream);
888
889 /* prune the BE if it's no longer in our active list */
890 if (widget && widget_in_list(list, widget))
891 continue;
892
893 /* is there a valid CODEC DAI widget for this BE */
894 widget = rtd_get_codec_widget(dpcm->be, stream);
895
896 /* prune the BE if it's no longer in our active list */
897 if (widget && widget_in_list(list, widget))
898 continue;
899
900 dev_dbg(fe->dev, "pruning %s BE %s for %s\n",
901 stream ? "capture" : "playback",
902 dpcm->be->dai_link->name, fe->dai_link->name);
903 dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE;
904 dpcm->be->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_BE;
905 prune++;
906 }
907
908 dev_dbg(fe->dev, "found %d old BE paths for pruning\n", prune);
909 return prune;
910}
911
912static int dpcm_add_paths(struct snd_soc_pcm_runtime *fe, int stream,
913 struct snd_soc_dapm_widget_list **list_)
914{
915 struct snd_soc_card *card = fe->card;
916 struct snd_soc_dapm_widget_list *list = *list_;
917 struct snd_soc_pcm_runtime *be;
918 int i, new = 0, err;
919
920 /* Create any new FE <--> BE connections */
921 for (i = 0; i < list->num_widgets; i++) {
922
923 if (list->widgets[i]->id != snd_soc_dapm_dai)
924 continue;
925
926 /* is there a valid BE rtd for this widget */
927 be = dpcm_get_be(card, list->widgets[i], stream);
928 if (!be) {
929 dev_err(fe->dev, "no BE found for %s\n",
930 list->widgets[i]->name);
931 continue;
932 }
933
934 /* make sure BE is a real BE */
935 if (!be->dai_link->no_pcm)
936 continue;
937
938 /* don't connect if FE is not running */
939 if (!fe->dpcm[stream].runtime)
940 continue;
941
942 /* newly connected FE and BE */
943 err = dpcm_be_connect(fe, be, stream);
944 if (err < 0) {
945 dev_err(fe->dev, "can't connect %s\n",
946 list->widgets[i]->name);
947 break;
948 } else if (err == 0) /* already connected */
949 continue;
950
951 /* new */
952 be->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_BE;
953 new++;
954 }
955
956 dev_dbg(fe->dev, "found %d new BE paths\n", new);
957 return new;
958}
959
960/*
961 * Find the corresponding BE DAIs that source or sink audio to this
962 * FE substream.
963 */
964static int dpcm_process_paths(struct snd_soc_pcm_runtime *fe,
965 int stream, struct snd_soc_dapm_widget_list **list, int new)
966{
967 if (new)
968 return dpcm_add_paths(fe, stream, list);
969 else
970 return dpcm_prune_paths(fe, stream, list);
971}
972
973static void dpcm_clear_pending_state(struct snd_soc_pcm_runtime *fe, int stream)
974{
975 struct snd_soc_dpcm *dpcm;
976
977 list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be)
978 dpcm->be->dpcm[stream].runtime_update =
979 SND_SOC_DPCM_UPDATE_NO;
980}
981
982static void dpcm_be_dai_startup_unwind(struct snd_soc_pcm_runtime *fe,
983 int stream)
984{
985 struct snd_soc_dpcm *dpcm;
986
987 /* disable any enabled and non active backends */
988 list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
989
990 struct snd_soc_pcm_runtime *be = dpcm->be;
991 struct snd_pcm_substream *be_substream =
992 snd_soc_dpcm_get_substream(be, stream);
993
994 if (be->dpcm[stream].users == 0)
995 dev_err(be->dev, "no users %s at close - state %d\n",
996 stream ? "capture" : "playback",
997 be->dpcm[stream].state);
998
999 if (--be->dpcm[stream].users != 0)
1000 continue;
1001
1002 if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_OPEN)
1003 continue;
1004
1005 soc_pcm_close(be_substream);
1006 be_substream->runtime = NULL;
1007 be->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE;
1008 }
1009}
1010
1011static int dpcm_be_dai_startup(struct snd_soc_pcm_runtime *fe, int stream)
1012{
1013 struct snd_soc_dpcm *dpcm;
1014 int err, count = 0;
1015
1016 /* only startup BE DAIs that are either sinks or sources to this FE DAI */
1017 list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
1018
1019 struct snd_soc_pcm_runtime *be = dpcm->be;
1020 struct snd_pcm_substream *be_substream =
1021 snd_soc_dpcm_get_substream(be, stream);
1022
1023 /* is this op for this BE ? */
1024 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
1025 continue;
1026
1027 /* first time the dpcm is open ? */
1028 if (be->dpcm[stream].users == DPCM_MAX_BE_USERS)
1029 dev_err(be->dev, "too many users %s at open %d\n",
1030 stream ? "capture" : "playback",
1031 be->dpcm[stream].state);
1032
1033 if (be->dpcm[stream].users++ != 0)
1034 continue;
1035
1036 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_NEW) &&
1037 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_CLOSE))
1038 continue;
1039
1040 dev_dbg(be->dev, "dpcm: open BE %s\n", be->dai_link->name);
1041
1042 be_substream->runtime = be->dpcm[stream].runtime;
1043 err = soc_pcm_open(be_substream);
1044 if (err < 0) {
1045 dev_err(be->dev, "BE open failed %d\n", err);
1046 be->dpcm[stream].users--;
1047 if (be->dpcm[stream].users < 0)
1048 dev_err(be->dev, "no users %s at unwind %d\n",
1049 stream ? "capture" : "playback",
1050 be->dpcm[stream].state);
1051
1052 be->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE;
1053 goto unwind;
1054 }
1055
1056 be->dpcm[stream].state = SND_SOC_DPCM_STATE_OPEN;
1057 count++;
1058 }
1059
1060 return count;
1061
1062unwind:
1063 /* disable any enabled and non active backends */
1064 list_for_each_entry_continue_reverse(dpcm, &fe->dpcm[stream].be_clients, list_be) {
1065 struct snd_soc_pcm_runtime *be = dpcm->be;
1066 struct snd_pcm_substream *be_substream =
1067 snd_soc_dpcm_get_substream(be, stream);
1068
1069 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
1070 continue;
1071
1072 if (be->dpcm[stream].users == 0)
1073 dev_err(be->dev, "no users %s at close %d\n",
1074 stream ? "capture" : "playback",
1075 be->dpcm[stream].state);
1076
1077 if (--be->dpcm[stream].users != 0)
1078 continue;
1079
1080 if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_OPEN)
1081 continue;
1082
1083 soc_pcm_close(be_substream);
1084 be_substream->runtime = NULL;
1085 be->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE;
1086 }
1087
1088 return err;
1089}
1090
1091static void dpcm_set_fe_runtime(struct snd_pcm_substream *substream)
1092{
1093 struct snd_pcm_runtime *runtime = substream->runtime;
1094 struct snd_soc_pcm_runtime *rtd = substream->private_data;
1095 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1096 struct snd_soc_dai_driver *cpu_dai_drv = cpu_dai->driver;
1097
1098 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
1099 runtime->hw.rate_min = cpu_dai_drv->playback.rate_min;
1100 runtime->hw.rate_max = cpu_dai_drv->playback.rate_max;
1101 runtime->hw.channels_min = cpu_dai_drv->playback.channels_min;
1102 runtime->hw.channels_max = cpu_dai_drv->playback.channels_max;
1103 runtime->hw.formats &= cpu_dai_drv->playback.formats;
1104 runtime->hw.rates = cpu_dai_drv->playback.rates;
1105 } else {
1106 runtime->hw.rate_min = cpu_dai_drv->capture.rate_min;
1107 runtime->hw.rate_max = cpu_dai_drv->capture.rate_max;
1108 runtime->hw.channels_min = cpu_dai_drv->capture.channels_min;
1109 runtime->hw.channels_max = cpu_dai_drv->capture.channels_max;
1110 runtime->hw.formats &= cpu_dai_drv->capture.formats;
1111 runtime->hw.rates = cpu_dai_drv->capture.rates;
1112 }
1113}
1114
1115static int dpcm_fe_dai_startup(struct snd_pcm_substream *fe_substream)
1116{
1117 struct snd_soc_pcm_runtime *fe = fe_substream->private_data;
1118 struct snd_pcm_runtime *runtime = fe_substream->runtime;
1119 int stream = fe_substream->stream, ret = 0;
1120
1121 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE;
1122
1123 ret = dpcm_be_dai_startup(fe, fe_substream->stream);
1124 if (ret < 0) {
1125 dev_err(fe->dev,"dpcm: failed to start some BEs %d\n", ret);
1126 goto be_err;
1127 }
1128
1129 dev_dbg(fe->dev, "dpcm: open FE %s\n", fe->dai_link->name);
1130
1131 /* start the DAI frontend */
1132 ret = soc_pcm_open(fe_substream);
1133 if (ret < 0) {
1134 dev_err(fe->dev,"dpcm: failed to start FE %d\n", ret);
1135 goto unwind;
1136 }
1137
1138 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_OPEN;
1139
1140 dpcm_set_fe_runtime(fe_substream);
1141 snd_pcm_limit_hw_rates(runtime);
1142
1143 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
1144 return 0;
1145
1146unwind:
1147 dpcm_be_dai_startup_unwind(fe, fe_substream->stream);
1148be_err:
1149 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
1150 return ret;
1151}
1152
1153static int dpcm_be_dai_shutdown(struct snd_soc_pcm_runtime *fe, int stream)
1154{
1155 struct snd_soc_dpcm *dpcm;
1156
1157 /* only shutdown BEs that are either sinks or sources to this FE DAI */
1158 list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
1159
1160 struct snd_soc_pcm_runtime *be = dpcm->be;
1161 struct snd_pcm_substream *be_substream =
1162 snd_soc_dpcm_get_substream(be, stream);
1163
1164 /* is this op for this BE ? */
1165 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
1166 continue;
1167
1168 if (be->dpcm[stream].users == 0)
1169 dev_err(be->dev, "no users %s at close - state %d\n",
1170 stream ? "capture" : "playback",
1171 be->dpcm[stream].state);
1172
1173 if (--be->dpcm[stream].users != 0)
1174 continue;
1175
1176 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_FREE) &&
1177 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_OPEN))
1178 continue;
1179
1180 dev_dbg(be->dev, "dpcm: close BE %s\n",
1181 dpcm->fe->dai_link->name);
1182
1183 soc_pcm_close(be_substream);
1184 be_substream->runtime = NULL;
1185
1186 be->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE;
1187 }
1188 return 0;
1189}
1190
1191static int dpcm_fe_dai_shutdown(struct snd_pcm_substream *substream)
1192{
1193 struct snd_soc_pcm_runtime *fe = substream->private_data;
1194 int stream = substream->stream;
1195
1196 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE;
1197
1198 /* shutdown the BEs */
1199 dpcm_be_dai_shutdown(fe, substream->stream);
1200
1201 dev_dbg(fe->dev, "dpcm: close FE %s\n", fe->dai_link->name);
1202
1203 /* now shutdown the frontend */
1204 soc_pcm_close(substream);
1205
1206 /* run the stream event for each BE */
1207 dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_STOP);
1208
1209 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE;
1210 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
1211 return 0;
1212}
1213
1214static int dpcm_be_dai_hw_free(struct snd_soc_pcm_runtime *fe, int stream)
1215{
1216 struct snd_soc_dpcm *dpcm;
1217
1218 /* only hw_params backends that are either sinks or sources
1219 * to this frontend DAI */
1220 list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
1221
1222 struct snd_soc_pcm_runtime *be = dpcm->be;
1223 struct snd_pcm_substream *be_substream =
1224 snd_soc_dpcm_get_substream(be, stream);
1225
1226 /* is this op for this BE ? */
1227 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
1228 continue;
1229
1230 /* only free hw when no longer used - check all FEs */
1231 if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream))
1232 continue;
1233
1234 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_PARAMS) &&
1235 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_PREPARE) &&
1236 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_FREE) &&
1237 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_STOP))
1238 continue;
1239
1240 dev_dbg(be->dev, "dpcm: hw_free BE %s\n",
1241 dpcm->fe->dai_link->name);
1242
1243 soc_pcm_hw_free(be_substream);
1244
1245 be->dpcm[stream].state = SND_SOC_DPCM_STATE_HW_FREE;
1246 }
1247
1248 return 0;
1249}
1250
1251static int dpcm_fe_dai_hw_free(struct snd_pcm_substream *substream)
1252{
1253 struct snd_soc_pcm_runtime *fe = substream->private_data;
1254 int err, stream = substream->stream;
1255
1256 mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
1257 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE;
1258
1259 dev_dbg(fe->dev, "dpcm: hw_free FE %s\n", fe->dai_link->name);
1260
1261 /* call hw_free on the frontend */
1262 err = soc_pcm_hw_free(substream);
1263 if (err < 0)
1264 dev_err(fe->dev,"dpcm: hw_free FE %s failed\n",
1265 fe->dai_link->name);
1266
1267 /* only hw_params backends that are either sinks or sources
1268 * to this frontend DAI */
1269 err = dpcm_be_dai_hw_free(fe, stream);
1270
1271 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_HW_FREE;
1272 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
1273
1274 mutex_unlock(&fe->card->mutex);
1275 return 0;
1276}
1277
1278static int dpcm_be_dai_hw_params(struct snd_soc_pcm_runtime *fe, int stream)
1279{
1280 struct snd_soc_dpcm *dpcm;
1281 int ret;
1282
1283 list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
1284
1285 struct snd_soc_pcm_runtime *be = dpcm->be;
1286 struct snd_pcm_substream *be_substream =
1287 snd_soc_dpcm_get_substream(be, stream);
1288
1289 /* is this op for this BE ? */
1290 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
1291 continue;
1292
1293 /* only allow hw_params() if no connected FEs are running */
1294 if (!snd_soc_dpcm_can_be_params(fe, be, stream))
1295 continue;
1296
1297 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_OPEN) &&
1298 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_PARAMS) &&
1299 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_FREE))
1300 continue;
1301
1302 dev_dbg(be->dev, "dpcm: hw_params BE %s\n",
1303 dpcm->fe->dai_link->name);
1304
1305 /* copy params for each dpcm */
1306 memcpy(&dpcm->hw_params, &fe->dpcm[stream].hw_params,
1307 sizeof(struct snd_pcm_hw_params));
1308
1309 /* perform any hw_params fixups */
1310 if (be->dai_link->be_hw_params_fixup) {
1311 ret = be->dai_link->be_hw_params_fixup(be,
1312 &dpcm->hw_params);
1313 if (ret < 0) {
1314 dev_err(be->dev,
1315 "dpcm: hw_params BE fixup failed %d\n",
1316 ret);
1317 goto unwind;
1318 }
1319 }
1320
1321 ret = soc_pcm_hw_params(be_substream, &dpcm->hw_params);
1322 if (ret < 0) {
1323 dev_err(dpcm->be->dev,
1324 "dpcm: hw_params BE failed %d\n", ret);
1325 goto unwind;
1326 }
1327
1328 be->dpcm[stream].state = SND_SOC_DPCM_STATE_HW_PARAMS;
1329 }
1330 return 0;
1331
1332unwind:
1333 /* disable any enabled and non active backends */
1334 list_for_each_entry_continue_reverse(dpcm, &fe->dpcm[stream].be_clients, list_be) {
1335 struct snd_soc_pcm_runtime *be = dpcm->be;
1336 struct snd_pcm_substream *be_substream =
1337 snd_soc_dpcm_get_substream(be, stream);
1338
1339 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
1340 continue;
1341
1342 /* only allow hw_free() if no connected FEs are running */
1343 if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream))
1344 continue;
1345
1346 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_OPEN) &&
1347 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_PARAMS) &&
1348 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_FREE) &&
1349 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_STOP))
1350 continue;
1351
1352 soc_pcm_hw_free(be_substream);
1353 }
1354
1355 return ret;
1356}
1357
1358static int dpcm_fe_dai_hw_params(struct snd_pcm_substream *substream,
1359 struct snd_pcm_hw_params *params)
1360{
1361 struct snd_soc_pcm_runtime *fe = substream->private_data;
1362 int ret, stream = substream->stream;
1363
1364 mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
1365 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE;
1366
1367 memcpy(&fe->dpcm[substream->stream].hw_params, params,
1368 sizeof(struct snd_pcm_hw_params));
1369 ret = dpcm_be_dai_hw_params(fe, substream->stream);
1370 if (ret < 0) {
1371 dev_err(fe->dev,"dpcm: hw_params BE failed %d\n", ret);
1372 goto out;
1373 }
1374
1375 dev_dbg(fe->dev, "dpcm: hw_params FE %s rate %d chan %x fmt %d\n",
1376 fe->dai_link->name, params_rate(params),
1377 params_channels(params), params_format(params));
1378
1379 /* call hw_params on the frontend */
1380 ret = soc_pcm_hw_params(substream, params);
1381 if (ret < 0) {
1382 dev_err(fe->dev,"dpcm: hw_params FE failed %d\n", ret);
1383 dpcm_be_dai_hw_free(fe, stream);
1384 } else
1385 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_HW_PARAMS;
1386
1387out:
1388 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
1389 mutex_unlock(&fe->card->mutex);
1390 return ret;
1391}
1392
1393static int dpcm_do_trigger(struct snd_soc_dpcm *dpcm,
1394 struct snd_pcm_substream *substream, int cmd)
1395{
1396 int ret;
1397
1398 dev_dbg(dpcm->be->dev, "dpcm: trigger BE %s cmd %d\n",
1399 dpcm->fe->dai_link->name, cmd);
1400
1401 ret = soc_pcm_trigger(substream, cmd);
1402 if (ret < 0)
1403 dev_err(dpcm->be->dev,"dpcm: trigger BE failed %d\n", ret);
1404
1405 return ret;
1406}
1407
1408static int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream,
1409 int cmd)
1410{
1411 struct snd_soc_dpcm *dpcm;
1412 int ret = 0;
1413
1414 list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
1415
1416 struct snd_soc_pcm_runtime *be = dpcm->be;
1417 struct snd_pcm_substream *be_substream =
1418 snd_soc_dpcm_get_substream(be, stream);
1419
1420 /* is this op for this BE ? */
1421 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
1422 continue;
1423
1424 switch (cmd) {
1425 case SNDRV_PCM_TRIGGER_START:
1426 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_PREPARE) &&
1427 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_STOP))
1428 continue;
1429
1430 ret = dpcm_do_trigger(dpcm, be_substream, cmd);
1431 if (ret)
1432 return ret;
1433
1434 be->dpcm[stream].state = SND_SOC_DPCM_STATE_START;
1435 break;
1436 case SNDRV_PCM_TRIGGER_RESUME:
1437 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_SUSPEND))
1438 continue;
1439
1440 ret = dpcm_do_trigger(dpcm, be_substream, cmd);
1441 if (ret)
1442 return ret;
1443
1444 be->dpcm[stream].state = SND_SOC_DPCM_STATE_START;
1445 break;
1446 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
1447 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_PAUSED))
1448 continue;
1449
1450 ret = dpcm_do_trigger(dpcm, be_substream, cmd);
1451 if (ret)
1452 return ret;
1453
1454 be->dpcm[stream].state = SND_SOC_DPCM_STATE_START;
1455 break;
1456 case SNDRV_PCM_TRIGGER_STOP:
1457 if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_START)
1458 continue;
1459
1460 if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream))
1461 continue;
1462
1463 ret = dpcm_do_trigger(dpcm, be_substream, cmd);
1464 if (ret)
1465 return ret;
1466
1467 be->dpcm[stream].state = SND_SOC_DPCM_STATE_STOP;
1468 break;
1469 case SNDRV_PCM_TRIGGER_SUSPEND:
1470 if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_STOP)
1471 continue;
1472
1473 if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream))
1474 continue;
1475
1476 ret = dpcm_do_trigger(dpcm, be_substream, cmd);
1477 if (ret)
1478 return ret;
1479
1480 be->dpcm[stream].state = SND_SOC_DPCM_STATE_SUSPEND;
1481 break;
1482 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
1483 if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_START)
1484 continue;
1485
1486 if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream))
1487 continue;
1488
1489 ret = dpcm_do_trigger(dpcm, be_substream, cmd);
1490 if (ret)
1491 return ret;
1492
1493 be->dpcm[stream].state = SND_SOC_DPCM_STATE_PAUSED;
1494 break;
1495 }
1496 }
1497
1498 return ret;
1499}
1500EXPORT_SYMBOL_GPL(dpcm_be_dai_trigger);
1501
1502static int dpcm_fe_dai_trigger(struct snd_pcm_substream *substream, int cmd)
1503{
1504 struct snd_soc_pcm_runtime *fe = substream->private_data;
1505 int stream = substream->stream, ret;
1506 enum snd_soc_dpcm_trigger trigger = fe->dai_link->trigger[stream];
1507
1508 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE;
1509
1510 switch (trigger) {
1511 case SND_SOC_DPCM_TRIGGER_PRE:
1512 /* call trigger on the frontend before the backend. */
1513
1514 dev_dbg(fe->dev, "dpcm: pre trigger FE %s cmd %d\n",
1515 fe->dai_link->name, cmd);
1516
1517 ret = soc_pcm_trigger(substream, cmd);
1518 if (ret < 0) {
1519 dev_err(fe->dev,"dpcm: trigger FE failed %d\n", ret);
1520 goto out;
1521 }
1522
1523 ret = dpcm_be_dai_trigger(fe, substream->stream, cmd);
1524 break;
1525 case SND_SOC_DPCM_TRIGGER_POST:
1526 /* call trigger on the frontend after the backend. */
1527
1528 ret = dpcm_be_dai_trigger(fe, substream->stream, cmd);
1529 if (ret < 0) {
1530 dev_err(fe->dev,"dpcm: trigger FE failed %d\n", ret);
1531 goto out;
1532 }
1533
1534 dev_dbg(fe->dev, "dpcm: post trigger FE %s cmd %d\n",
1535 fe->dai_link->name, cmd);
1536
1537 ret = soc_pcm_trigger(substream, cmd);
1538 break;
1539 case SND_SOC_DPCM_TRIGGER_BESPOKE:
1540 /* bespoke trigger() - handles both FE and BEs */
1541
1542 dev_dbg(fe->dev, "dpcm: bespoke trigger FE %s cmd %d\n",
1543 fe->dai_link->name, cmd);
1544
1545 ret = soc_pcm_bespoke_trigger(substream, cmd);
1546 if (ret < 0) {
1547 dev_err(fe->dev,"dpcm: trigger FE failed %d\n", ret);
1548 goto out;
1549 }
1550 break;
1551 default:
1552 dev_err(fe->dev, "dpcm: invalid trigger cmd %d for %s\n", cmd,
1553 fe->dai_link->name);
1554 ret = -EINVAL;
1555 goto out;
1556 }
1557
1558 switch (cmd) {
1559 case SNDRV_PCM_TRIGGER_START:
1560 case SNDRV_PCM_TRIGGER_RESUME:
1561 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
1562 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_START;
1563 break;
1564 case SNDRV_PCM_TRIGGER_STOP:
1565 case SNDRV_PCM_TRIGGER_SUSPEND:
1566 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
1567 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_STOP;
1568 break;
1569 }
1570
1571out:
1572 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
1573 return ret;
1574}
1575
1576static int dpcm_be_dai_prepare(struct snd_soc_pcm_runtime *fe, int stream)
1577{
1578 struct snd_soc_dpcm *dpcm;
1579 int ret = 0;
1580
1581 list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
1582
1583 struct snd_soc_pcm_runtime *be = dpcm->be;
1584 struct snd_pcm_substream *be_substream =
1585 snd_soc_dpcm_get_substream(be, stream);
1586
1587 /* is this op for this BE ? */
1588 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
1589 continue;
1590
1591 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_PARAMS) &&
1592 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_STOP))
1593 continue;
1594
1595 dev_dbg(be->dev, "dpcm: prepare BE %s\n",
1596 dpcm->fe->dai_link->name);
1597
1598 ret = soc_pcm_prepare(be_substream);
1599 if (ret < 0) {
1600 dev_err(be->dev, "dpcm: backend prepare failed %d\n",
1601 ret);
1602 break;
1603 }
1604
1605 be->dpcm[stream].state = SND_SOC_DPCM_STATE_PREPARE;
1606 }
1607 return ret;
1608}
1609
1610static int dpcm_fe_dai_prepare(struct snd_pcm_substream *substream)
1611{
1612 struct snd_soc_pcm_runtime *fe = substream->private_data;
1613 int stream = substream->stream, ret = 0;
1614
1615 mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
1616
1617 dev_dbg(fe->dev, "dpcm: prepare FE %s\n", fe->dai_link->name);
1618
1619 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE;
1620
1621 /* there is no point preparing this FE if there are no BEs */
1622 if (list_empty(&fe->dpcm[stream].be_clients)) {
1623 dev_err(fe->dev, "dpcm: no backend DAIs enabled for %s\n",
1624 fe->dai_link->name);
1625 ret = -EINVAL;
1626 goto out;
1627 }
1628
1629 ret = dpcm_be_dai_prepare(fe, substream->stream);
1630 if (ret < 0)
1631 goto out;
1632
1633 /* call prepare on the frontend */
1634 ret = soc_pcm_prepare(substream);
1635 if (ret < 0) {
1636 dev_err(fe->dev,"dpcm: prepare FE %s failed\n",
1637 fe->dai_link->name);
1638 goto out;
1639 }
1640
1641 /* run the stream event for each BE */
1642 dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_START);
1643 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_PREPARE;
1644
1645out:
1646 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
1647 mutex_unlock(&fe->card->mutex);
1648
1649 return ret;
1650}
1651
1652static int soc_pcm_ioctl(struct snd_pcm_substream *substream,
1653 unsigned int cmd, void *arg)
1654{
1655 struct snd_soc_pcm_runtime *rtd = substream->private_data;
1656 struct snd_soc_platform *platform = rtd->platform;
1657
1658 if (platform->driver->ops->ioctl)
1659 return platform->driver->ops->ioctl(substream, cmd, arg);
1660 return snd_pcm_lib_ioctl(substream, cmd, arg);
1661}
1662
1663static int dpcm_run_update_shutdown(struct snd_soc_pcm_runtime *fe, int stream)
1664{
1665 struct snd_pcm_substream *substream =
1666 snd_soc_dpcm_get_substream(fe, stream);
1667 enum snd_soc_dpcm_trigger trigger = fe->dai_link->trigger[stream];
1668 int err;
1669
1670 dev_dbg(fe->dev, "runtime %s close on FE %s\n",
1671 stream ? "capture" : "playback", fe->dai_link->name);
1672
1673 if (trigger == SND_SOC_DPCM_TRIGGER_BESPOKE) {
1674 /* call bespoke trigger - FE takes care of all BE triggers */
1675 dev_dbg(fe->dev, "dpcm: bespoke trigger FE %s cmd stop\n",
1676 fe->dai_link->name);
1677
1678 err = soc_pcm_bespoke_trigger(substream, SNDRV_PCM_TRIGGER_STOP);
1679 if (err < 0)
1680 dev_err(fe->dev,"dpcm: trigger FE failed %d\n", err);
1681 } else {
1682 dev_dbg(fe->dev, "dpcm: trigger FE %s cmd stop\n",
1683 fe->dai_link->name);
1684
1685 err = dpcm_be_dai_trigger(fe, stream, SNDRV_PCM_TRIGGER_STOP);
1686 if (err < 0)
1687 dev_err(fe->dev,"dpcm: trigger FE failed %d\n", err);
1688 }
1689
1690 err = dpcm_be_dai_hw_free(fe, stream);
1691 if (err < 0)
1692 dev_err(fe->dev,"dpcm: hw_free FE failed %d\n", err);
1693
1694 err = dpcm_be_dai_shutdown(fe, stream);
1695 if (err < 0)
1696 dev_err(fe->dev,"dpcm: shutdown FE failed %d\n", err);
1697
1698 /* run the stream event for each BE */
1699 dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_NOP);
1700
1701 return 0;
1702}
1703
1704static int dpcm_run_update_startup(struct snd_soc_pcm_runtime *fe, int stream)
1705{
1706 struct snd_pcm_substream *substream =
1707 snd_soc_dpcm_get_substream(fe, stream);
1708 struct snd_soc_dpcm *dpcm;
1709 enum snd_soc_dpcm_trigger trigger = fe->dai_link->trigger[stream];
1710 int ret;
1711
1712 dev_dbg(fe->dev, "runtime %s open on FE %s\n",
1713 stream ? "capture" : "playback", fe->dai_link->name);
1714
1715 /* Only start the BE if the FE is ready */
1716 if (fe->dpcm[stream].state == SND_SOC_DPCM_STATE_HW_FREE ||
1717 fe->dpcm[stream].state == SND_SOC_DPCM_STATE_CLOSE)
1718 return -EINVAL;
1719
1720 /* startup must always be called for new BEs */
1721 ret = dpcm_be_dai_startup(fe, stream);
1722 if (ret < 0) {
1723 goto disconnect;
1724 return ret;
1725 }
1726
1727 /* keep going if FE state is > open */
1728 if (fe->dpcm[stream].state == SND_SOC_DPCM_STATE_OPEN)
1729 return 0;
1730
1731 ret = dpcm_be_dai_hw_params(fe, stream);
1732 if (ret < 0) {
1733 goto close;
1734 return ret;
1735 }
1736
1737 /* keep going if FE state is > hw_params */
1738 if (fe->dpcm[stream].state == SND_SOC_DPCM_STATE_HW_PARAMS)
1739 return 0;
1740
1741
1742 ret = dpcm_be_dai_prepare(fe, stream);
1743 if (ret < 0) {
1744 goto hw_free;
1745 return ret;
1746 }
1747
1748 /* run the stream event for each BE */
1749 dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_NOP);
1750
1751 /* keep going if FE state is > prepare */
1752 if (fe->dpcm[stream].state == SND_SOC_DPCM_STATE_PREPARE ||
1753 fe->dpcm[stream].state == SND_SOC_DPCM_STATE_STOP)
1754 return 0;
1755
1756 if (trigger == SND_SOC_DPCM_TRIGGER_BESPOKE) {
1757 /* call trigger on the frontend - FE takes care of all BE triggers */
1758 dev_dbg(fe->dev, "dpcm: bespoke trigger FE %s cmd start\n",
1759 fe->dai_link->name);
1760
1761 ret = soc_pcm_bespoke_trigger(substream, SNDRV_PCM_TRIGGER_START);
1762 if (ret < 0) {
1763 dev_err(fe->dev,"dpcm: bespoke trigger FE failed %d\n", ret);
1764 goto hw_free;
1765 }
1766 } else {
1767 dev_dbg(fe->dev, "dpcm: trigger FE %s cmd start\n",
1768 fe->dai_link->name);
1769
1770 ret = dpcm_be_dai_trigger(fe, stream,
1771 SNDRV_PCM_TRIGGER_START);
1772 if (ret < 0) {
1773 dev_err(fe->dev,"dpcm: trigger FE failed %d\n", ret);
1774 goto hw_free;
1775 }
1776 }
1777
1778 return 0;
1779
1780hw_free:
1781 dpcm_be_dai_hw_free(fe, stream);
1782close:
1783 dpcm_be_dai_shutdown(fe, stream);
1784disconnect:
1785 /* disconnect any non started BEs */
1786 list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
1787 struct snd_soc_pcm_runtime *be = dpcm->be;
1788 if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_START)
1789 dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE;
1790 }
1791
1792 return ret;
1793}
1794
1795static int dpcm_run_new_update(struct snd_soc_pcm_runtime *fe, int stream)
1796{
1797 int ret;
1798
1799 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_BE;
1800 ret = dpcm_run_update_startup(fe, stream);
1801 if (ret < 0)
1802 dev_err(fe->dev, "failed to startup some BEs\n");
1803 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
1804
1805 return ret;
1806}
1807
1808static int dpcm_run_old_update(struct snd_soc_pcm_runtime *fe, int stream)
1809{
1810 int ret;
1811
1812 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_BE;
1813 ret = dpcm_run_update_shutdown(fe, stream);
1814 if (ret < 0)
1815 dev_err(fe->dev, "failed to shutdown some BEs\n");
1816 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
1817
1818 return ret;
1819}
1820
1821/* Called by DAPM mixer/mux changes to update audio routing between PCMs and
1822 * any DAI links.
1823 */
1824int soc_dpcm_runtime_update(struct snd_soc_dapm_widget *widget)
1825{
1826 struct snd_soc_card *card;
1827 int i, old, new, paths;
1828
1829 if (widget->codec)
1830 card = widget->codec->card;
1831 else if (widget->platform)
1832 card = widget->platform->card;
1833 else
1834 return -EINVAL;
1835
1836 mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
1837 for (i = 0; i < card->num_rtd; i++) {
1838 struct snd_soc_dapm_widget_list *list;
1839 struct snd_soc_pcm_runtime *fe = &card->rtd[i];
1840
1841 /* make sure link is FE */
1842 if (!fe->dai_link->dynamic)
1843 continue;
1844
1845 /* only check active links */
1846 if (!fe->cpu_dai->active)
1847 continue;
1848
1849 /* DAPM sync will call this to update DSP paths */
1850 dev_dbg(fe->dev, "DPCM runtime update for FE %s\n",
1851 fe->dai_link->name);
1852
1853 /* skip if FE doesn't have playback capability */
1854 if (!fe->cpu_dai->driver->playback.channels_min)
1855 goto capture;
1856
1857 paths = dpcm_path_get(fe, SNDRV_PCM_STREAM_PLAYBACK, &list);
1858 if (paths < 0) {
1859 dev_warn(fe->dev, "%s no valid %s path\n",
1860 fe->dai_link->name, "playback");
1861 mutex_unlock(&card->mutex);
1862 return paths;
1863 }
1864
1865 /* update any new playback paths */
1866 new = dpcm_process_paths(fe, SNDRV_PCM_STREAM_PLAYBACK, &list, 1);
1867 if (new) {
1868 dpcm_run_new_update(fe, SNDRV_PCM_STREAM_PLAYBACK);
1869 dpcm_clear_pending_state(fe, SNDRV_PCM_STREAM_PLAYBACK);
1870 dpcm_be_disconnect(fe, SNDRV_PCM_STREAM_PLAYBACK);
1871 }
1872
1873 /* update any old playback paths */
1874 old = dpcm_process_paths(fe, SNDRV_PCM_STREAM_PLAYBACK, &list, 0);
1875 if (old) {
1876 dpcm_run_old_update(fe, SNDRV_PCM_STREAM_PLAYBACK);
1877 dpcm_clear_pending_state(fe, SNDRV_PCM_STREAM_PLAYBACK);
1878 dpcm_be_disconnect(fe, SNDRV_PCM_STREAM_PLAYBACK);
1879 }
1880
1881capture:
1882 /* skip if FE doesn't have capture capability */
1883 if (!fe->cpu_dai->driver->capture.channels_min)
1884 continue;
1885
1886 paths = dpcm_path_get(fe, SNDRV_PCM_STREAM_CAPTURE, &list);
1887 if (paths < 0) {
1888 dev_warn(fe->dev, "%s no valid %s path\n",
1889 fe->dai_link->name, "capture");
1890 mutex_unlock(&card->mutex);
1891 return paths;
1892 }
1893
1894 /* update any new capture paths */
1895 new = dpcm_process_paths(fe, SNDRV_PCM_STREAM_CAPTURE, &list, 1);
1896 if (new) {
1897 dpcm_run_new_update(fe, SNDRV_PCM_STREAM_CAPTURE);
1898 dpcm_clear_pending_state(fe, SNDRV_PCM_STREAM_CAPTURE);
1899 dpcm_be_disconnect(fe, SNDRV_PCM_STREAM_CAPTURE);
1900 }
1901
1902 /* update any old capture paths */
1903 old = dpcm_process_paths(fe, SNDRV_PCM_STREAM_CAPTURE, &list, 0);
1904 if (old) {
1905 dpcm_run_old_update(fe, SNDRV_PCM_STREAM_CAPTURE);
1906 dpcm_clear_pending_state(fe, SNDRV_PCM_STREAM_CAPTURE);
1907 dpcm_be_disconnect(fe, SNDRV_PCM_STREAM_CAPTURE);
1908 }
1909
1910 dpcm_path_put(&list);
1911 }
1912
1913 mutex_unlock(&card->mutex);
1914 return 0;
1915}
1916int soc_dpcm_be_digital_mute(struct snd_soc_pcm_runtime *fe, int mute)
1917{
1918 struct snd_soc_dpcm *dpcm;
1919 struct list_head *clients =
1920 &fe->dpcm[SNDRV_PCM_STREAM_PLAYBACK].be_clients;
1921
1922 list_for_each_entry(dpcm, clients, list_be) {
1923
1924 struct snd_soc_pcm_runtime *be = dpcm->be;
1925 struct snd_soc_dai *dai = be->codec_dai;
1926 struct snd_soc_dai_driver *drv = dai->driver;
1927
1928 if (be->dai_link->ignore_suspend)
1929 continue;
1930
1931 dev_dbg(be->dev, "BE digital mute %s\n", be->dai_link->name);
1932
1933 if (drv->ops->digital_mute && dai->playback_active)
1934 drv->ops->digital_mute(dai, mute);
1935 }
1936
1937 return 0;
1938}
1939
1940static int dpcm_fe_dai_open(struct snd_pcm_substream *fe_substream)
1941{
1942 struct snd_soc_pcm_runtime *fe = fe_substream->private_data;
1943 struct snd_soc_dpcm *dpcm;
1944 struct snd_soc_dapm_widget_list *list;
1945 int ret;
1946 int stream = fe_substream->stream;
1947
1948 mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
1949 fe->dpcm[stream].runtime = fe_substream->runtime;
1950
1951 if (dpcm_path_get(fe, stream, &list) <= 0) {
1952 dev_warn(fe->dev, "asoc: %s no valid %s route\n",
1953 fe->dai_link->name, stream ? "capture" : "playback");
1954 mutex_unlock(&fe->card->mutex);
1955 return -EINVAL;
1956 }
1957
1958 /* calculate valid and active FE <-> BE dpcms */
1959 dpcm_process_paths(fe, stream, &list, 1);
1960
1961 ret = dpcm_fe_dai_startup(fe_substream);
1962 if (ret < 0) {
1963 /* clean up all links */
1964 list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be)
1965 dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE;
1966
1967 dpcm_be_disconnect(fe, stream);
1968 fe->dpcm[stream].runtime = NULL;
1969 }
1970
1971 dpcm_clear_pending_state(fe, stream);
1972 dpcm_path_put(&list);
1973 mutex_unlock(&fe->card->mutex);
1974 return ret;
1975}
1976
1977static int dpcm_fe_dai_close(struct snd_pcm_substream *fe_substream)
1978{
1979 struct snd_soc_pcm_runtime *fe = fe_substream->private_data;
1980 struct snd_soc_dpcm *dpcm;
1981 int stream = fe_substream->stream, ret;
1982
1983 mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
1984 ret = dpcm_fe_dai_shutdown(fe_substream);
1985
1986 /* mark FE's links ready to prune */
1987 list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be)
1988 dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE;
1989
1990 dpcm_be_disconnect(fe, stream);
1991
1992 fe->dpcm[stream].runtime = NULL;
1993 mutex_unlock(&fe->card->mutex);
1994 return ret;
1995}
1996
637/* create a new pcm */ 1997/* create a new pcm */
638int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num) 1998int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
639{ 1999{
@@ -641,56 +2001,94 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
641 struct snd_soc_platform *platform = rtd->platform; 2001 struct snd_soc_platform *platform = rtd->platform;
642 struct snd_soc_dai *codec_dai = rtd->codec_dai; 2002 struct snd_soc_dai *codec_dai = rtd->codec_dai;
643 struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 2003 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
644 struct snd_pcm_ops *soc_pcm_ops = &rtd->ops;
645 struct snd_pcm *pcm; 2004 struct snd_pcm *pcm;
646 char new_name[64]; 2005 char new_name[64];
647 int ret = 0, playback = 0, capture = 0; 2006 int ret = 0, playback = 0, capture = 0;
648 2007
649 soc_pcm_ops->open = soc_pcm_open; 2008 if (rtd->dai_link->dynamic || rtd->dai_link->no_pcm) {
650 soc_pcm_ops->close = soc_pcm_close; 2009 if (cpu_dai->driver->playback.channels_min)
651 soc_pcm_ops->hw_params = soc_pcm_hw_params; 2010 playback = 1;
652 soc_pcm_ops->hw_free = soc_pcm_hw_free; 2011 if (cpu_dai->driver->capture.channels_min)
653 soc_pcm_ops->prepare = soc_pcm_prepare; 2012 capture = 1;
654 soc_pcm_ops->trigger = soc_pcm_trigger; 2013 } else {
655 soc_pcm_ops->pointer = soc_pcm_pointer; 2014 if (codec_dai->driver->playback.channels_min)
656 2015 playback = 1;
657 /* check client and interface hw capabilities */ 2016 if (codec_dai->driver->capture.channels_min)
658 snprintf(new_name, sizeof(new_name), "%s %s-%d", 2017 capture = 1;
659 rtd->dai_link->stream_name, codec_dai->name, num); 2018 }
660 2019
661 if (codec_dai->driver->playback.channels_min) 2020 /* create the PCM */
662 playback = 1; 2021 if (rtd->dai_link->no_pcm) {
663 if (codec_dai->driver->capture.channels_min) 2022 snprintf(new_name, sizeof(new_name), "(%s)",
664 capture = 1; 2023 rtd->dai_link->stream_name);
665 2024
666 dev_dbg(rtd->card->dev, "registered pcm #%d %s\n",num,new_name); 2025 ret = snd_pcm_new_internal(rtd->card->snd_card, new_name, num,
667 ret = snd_pcm_new(rtd->card->snd_card, new_name, 2026 playback, capture, &pcm);
668 num, playback, capture, &pcm); 2027 } else {
2028 if (rtd->dai_link->dynamic)
2029 snprintf(new_name, sizeof(new_name), "%s (*)",
2030 rtd->dai_link->stream_name);
2031 else
2032 snprintf(new_name, sizeof(new_name), "%s %s-%d",
2033 rtd->dai_link->stream_name, codec_dai->name, num);
2034
2035 ret = snd_pcm_new(rtd->card->snd_card, new_name, num, playback,
2036 capture, &pcm);
2037 }
669 if (ret < 0) { 2038 if (ret < 0) {
670 printk(KERN_ERR "asoc: can't create pcm for codec %s\n", codec->name); 2039 printk(KERN_ERR "asoc: can't create pcm for codec %s\n", codec->name);
671 return ret; 2040 return ret;
672 } 2041 }
2042 dev_dbg(rtd->card->dev, "registered pcm #%d %s\n",num, new_name);
673 2043
674 /* DAPM dai link stream work */ 2044 /* DAPM dai link stream work */
675 INIT_DELAYED_WORK(&rtd->delayed_work, close_delayed_work); 2045 INIT_DELAYED_WORK(&rtd->delayed_work, close_delayed_work);
676 2046
677 rtd->pcm = pcm; 2047 rtd->pcm = pcm;
678 pcm->private_data = rtd; 2048 pcm->private_data = rtd;
2049
2050 if (rtd->dai_link->no_pcm) {
2051 if (playback)
2052 pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream->private_data = rtd;
2053 if (capture)
2054 pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream->private_data = rtd;
2055 goto out;
2056 }
2057
2058 /* ASoC PCM operations */
2059 if (rtd->dai_link->dynamic) {
2060 rtd->ops.open = dpcm_fe_dai_open;
2061 rtd->ops.hw_params = dpcm_fe_dai_hw_params;
2062 rtd->ops.prepare = dpcm_fe_dai_prepare;
2063 rtd->ops.trigger = dpcm_fe_dai_trigger;
2064 rtd->ops.hw_free = dpcm_fe_dai_hw_free;
2065 rtd->ops.close = dpcm_fe_dai_close;
2066 rtd->ops.pointer = soc_pcm_pointer;
2067 rtd->ops.ioctl = soc_pcm_ioctl;
2068 } else {
2069 rtd->ops.open = soc_pcm_open;
2070 rtd->ops.hw_params = soc_pcm_hw_params;
2071 rtd->ops.prepare = soc_pcm_prepare;
2072 rtd->ops.trigger = soc_pcm_trigger;
2073 rtd->ops.hw_free = soc_pcm_hw_free;
2074 rtd->ops.close = soc_pcm_close;
2075 rtd->ops.pointer = soc_pcm_pointer;
2076 rtd->ops.ioctl = soc_pcm_ioctl;
2077 }
2078
679 if (platform->driver->ops) { 2079 if (platform->driver->ops) {
680 soc_pcm_ops->mmap = platform->driver->ops->mmap; 2080 rtd->ops.ack = platform->driver->ops->ack;
681 soc_pcm_ops->pointer = platform->driver->ops->pointer; 2081 rtd->ops.copy = platform->driver->ops->copy;
682 soc_pcm_ops->ioctl = platform->driver->ops->ioctl; 2082 rtd->ops.silence = platform->driver->ops->silence;
683 soc_pcm_ops->copy = platform->driver->ops->copy; 2083 rtd->ops.page = platform->driver->ops->page;
684 soc_pcm_ops->silence = platform->driver->ops->silence; 2084 rtd->ops.mmap = platform->driver->ops->mmap;
685 soc_pcm_ops->ack = platform->driver->ops->ack;
686 soc_pcm_ops->page = platform->driver->ops->page;
687 } 2085 }
688 2086
689 if (playback) 2087 if (playback)
690 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, soc_pcm_ops); 2088 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &rtd->ops);
691 2089
692 if (capture) 2090 if (capture)
693 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, soc_pcm_ops); 2091 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &rtd->ops);
694 2092
695 if (platform->driver->pcm_new) { 2093 if (platform->driver->pcm_new) {
696 ret = platform->driver->pcm_new(rtd); 2094 ret = platform->driver->pcm_new(rtd);
@@ -701,7 +2099,257 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
701 } 2099 }
702 2100
703 pcm->private_free = platform->driver->pcm_free; 2101 pcm->private_free = platform->driver->pcm_free;
2102out:
704 printk(KERN_INFO "asoc: %s <-> %s mapping ok\n", codec_dai->name, 2103 printk(KERN_INFO "asoc: %s <-> %s mapping ok\n", codec_dai->name,
705 cpu_dai->name); 2104 cpu_dai->name);
706 return ret; 2105 return ret;
707} 2106}
2107
2108/* is the current PCM operation for this FE ? */
2109int snd_soc_dpcm_fe_can_update(struct snd_soc_pcm_runtime *fe, int stream)
2110{
2111 if (fe->dpcm[stream].runtime_update == SND_SOC_DPCM_UPDATE_FE)
2112 return 1;
2113 return 0;
2114}
2115EXPORT_SYMBOL_GPL(snd_soc_dpcm_fe_can_update);
2116
2117/* is the current PCM operation for this BE ? */
2118int snd_soc_dpcm_be_can_update(struct snd_soc_pcm_runtime *fe,
2119 struct snd_soc_pcm_runtime *be, int stream)
2120{
2121 if ((fe->dpcm[stream].runtime_update == SND_SOC_DPCM_UPDATE_FE) ||
2122 ((fe->dpcm[stream].runtime_update == SND_SOC_DPCM_UPDATE_BE) &&
2123 be->dpcm[stream].runtime_update))
2124 return 1;
2125 return 0;
2126}
2127EXPORT_SYMBOL_GPL(snd_soc_dpcm_be_can_update);
2128
2129/* get the substream for this BE */
2130struct snd_pcm_substream *
2131 snd_soc_dpcm_get_substream(struct snd_soc_pcm_runtime *be, int stream)
2132{
2133 return be->pcm->streams[stream].substream;
2134}
2135EXPORT_SYMBOL_GPL(snd_soc_dpcm_get_substream);
2136
2137/* get the BE runtime state */
2138enum snd_soc_dpcm_state
2139 snd_soc_dpcm_be_get_state(struct snd_soc_pcm_runtime *be, int stream)
2140{
2141 return be->dpcm[stream].state;
2142}
2143EXPORT_SYMBOL_GPL(snd_soc_dpcm_be_get_state);
2144
2145/* set the BE runtime state */
2146void snd_soc_dpcm_be_set_state(struct snd_soc_pcm_runtime *be,
2147 int stream, enum snd_soc_dpcm_state state)
2148{
2149 be->dpcm[stream].state = state;
2150}
2151EXPORT_SYMBOL_GPL(snd_soc_dpcm_be_set_state);
2152
2153/*
2154 * We can only hw_free, stop, pause or suspend a BE DAI if any of it's FE
2155 * are not running, paused or suspended for the specified stream direction.
2156 */
2157int snd_soc_dpcm_can_be_free_stop(struct snd_soc_pcm_runtime *fe,
2158 struct snd_soc_pcm_runtime *be, int stream)
2159{
2160 struct snd_soc_dpcm *dpcm;
2161 int state;
2162
2163 list_for_each_entry(dpcm, &be->dpcm[stream].fe_clients, list_fe) {
2164
2165 if (dpcm->fe == fe)
2166 continue;
2167
2168 state = dpcm->fe->dpcm[stream].state;
2169 if (state == SND_SOC_DPCM_STATE_START ||
2170 state == SND_SOC_DPCM_STATE_PAUSED ||
2171 state == SND_SOC_DPCM_STATE_SUSPEND)
2172 return 0;
2173 }
2174
2175 /* it's safe to free/stop this BE DAI */
2176 return 1;
2177}
2178EXPORT_SYMBOL_GPL(snd_soc_dpcm_can_be_free_stop);
2179
2180/*
2181 * We can only change hw params a BE DAI if any of it's FE are not prepared,
2182 * running, paused or suspended for the specified stream direction.
2183 */
2184int snd_soc_dpcm_can_be_params(struct snd_soc_pcm_runtime *fe,
2185 struct snd_soc_pcm_runtime *be, int stream)
2186{
2187 struct snd_soc_dpcm *dpcm;
2188 int state;
2189
2190 list_for_each_entry(dpcm, &be->dpcm[stream].fe_clients, list_fe) {
2191
2192 if (dpcm->fe == fe)
2193 continue;
2194
2195 state = dpcm->fe->dpcm[stream].state;
2196 if (state == SND_SOC_DPCM_STATE_START ||
2197 state == SND_SOC_DPCM_STATE_PAUSED ||
2198 state == SND_SOC_DPCM_STATE_SUSPEND ||
2199 state == SND_SOC_DPCM_STATE_PREPARE)
2200 return 0;
2201 }
2202
2203 /* it's safe to change hw_params */
2204 return 1;
2205}
2206EXPORT_SYMBOL_GPL(snd_soc_dpcm_can_be_params);
2207
2208int snd_soc_platform_trigger(struct snd_pcm_substream *substream,
2209 int cmd, struct snd_soc_platform *platform)
2210{
2211 if (platform->driver->ops->trigger)
2212 return platform->driver->ops->trigger(substream, cmd);
2213 return 0;
2214}
2215EXPORT_SYMBOL_GPL(snd_soc_platform_trigger);
2216
2217#ifdef CONFIG_DEBUG_FS
2218static char *dpcm_state_string(enum snd_soc_dpcm_state state)
2219{
2220 switch (state) {
2221 case SND_SOC_DPCM_STATE_NEW:
2222 return "new";
2223 case SND_SOC_DPCM_STATE_OPEN:
2224 return "open";
2225 case SND_SOC_DPCM_STATE_HW_PARAMS:
2226 return "hw_params";
2227 case SND_SOC_DPCM_STATE_PREPARE:
2228 return "prepare";
2229 case SND_SOC_DPCM_STATE_START:
2230 return "start";
2231 case SND_SOC_DPCM_STATE_STOP:
2232 return "stop";
2233 case SND_SOC_DPCM_STATE_SUSPEND:
2234 return "suspend";
2235 case SND_SOC_DPCM_STATE_PAUSED:
2236 return "paused";
2237 case SND_SOC_DPCM_STATE_HW_FREE:
2238 return "hw_free";
2239 case SND_SOC_DPCM_STATE_CLOSE:
2240 return "close";
2241 }
2242
2243 return "unknown";
2244}
2245
2246static ssize_t dpcm_show_state(struct snd_soc_pcm_runtime *fe,
2247 int stream, char *buf, size_t size)
2248{
2249 struct snd_pcm_hw_params *params = &fe->dpcm[stream].hw_params;
2250 struct snd_soc_dpcm *dpcm;
2251 ssize_t offset = 0;
2252
2253 /* FE state */
2254 offset += snprintf(buf + offset, size - offset,
2255 "[%s - %s]\n", fe->dai_link->name,
2256 stream ? "Capture" : "Playback");
2257
2258 offset += snprintf(buf + offset, size - offset, "State: %s\n",
2259 dpcm_state_string(fe->dpcm[stream].state));
2260
2261 if ((fe->dpcm[stream].state >= SND_SOC_DPCM_STATE_HW_PARAMS) &&
2262 (fe->dpcm[stream].state <= SND_SOC_DPCM_STATE_STOP))
2263 offset += snprintf(buf + offset, size - offset,
2264 "Hardware Params: "
2265 "Format = %s, Channels = %d, Rate = %d\n",
2266 snd_pcm_format_name(params_format(params)),
2267 params_channels(params),
2268 params_rate(params));
2269
2270 /* BEs state */
2271 offset += snprintf(buf + offset, size - offset, "Backends:\n");
2272
2273 if (list_empty(&fe->dpcm[stream].be_clients)) {
2274 offset += snprintf(buf + offset, size - offset,
2275 " No active DSP links\n");
2276 goto out;
2277 }
2278
2279 list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
2280 struct snd_soc_pcm_runtime *be = dpcm->be;
2281 params = &dpcm->hw_params;
2282
2283 offset += snprintf(buf + offset, size - offset,
2284 "- %s\n", be->dai_link->name);
2285
2286 offset += snprintf(buf + offset, size - offset,
2287 " State: %s\n",
2288 dpcm_state_string(be->dpcm[stream].state));
2289
2290 if ((be->dpcm[stream].state >= SND_SOC_DPCM_STATE_HW_PARAMS) &&
2291 (be->dpcm[stream].state <= SND_SOC_DPCM_STATE_STOP))
2292 offset += snprintf(buf + offset, size - offset,
2293 " Hardware Params: "
2294 "Format = %s, Channels = %d, Rate = %d\n",
2295 snd_pcm_format_name(params_format(params)),
2296 params_channels(params),
2297 params_rate(params));
2298 }
2299
2300out:
2301 return offset;
2302}
2303
2304static ssize_t dpcm_state_read_file(struct file *file, char __user *user_buf,
2305 size_t count, loff_t *ppos)
2306{
2307 struct snd_soc_pcm_runtime *fe = file->private_data;
2308 ssize_t out_count = PAGE_SIZE, offset = 0, ret = 0;
2309 char *buf;
2310
2311 buf = kmalloc(out_count, GFP_KERNEL);
2312 if (!buf)
2313 return -ENOMEM;
2314
2315 if (fe->cpu_dai->driver->playback.channels_min)
2316 offset += dpcm_show_state(fe, SNDRV_PCM_STREAM_PLAYBACK,
2317 buf + offset, out_count - offset);
2318
2319 if (fe->cpu_dai->driver->capture.channels_min)
2320 offset += dpcm_show_state(fe, SNDRV_PCM_STREAM_CAPTURE,
2321 buf + offset, out_count - offset);
2322
2323 ret = simple_read_from_buffer(user_buf, count, ppos, buf, offset);
2324
2325 kfree(buf);
2326 return ret;
2327}
2328
2329static const struct file_operations dpcm_state_fops = {
2330 .open = simple_open,
2331 .read = dpcm_state_read_file,
2332 .llseek = default_llseek,
2333};
2334
2335int soc_dpcm_debugfs_add(struct snd_soc_pcm_runtime *rtd)
2336{
2337 if (!rtd->dai_link)
2338 return 0;
2339
2340 rtd->debugfs_dpcm_root = debugfs_create_dir(rtd->dai_link->name,
2341 rtd->card->debugfs_card_root);
2342 if (!rtd->debugfs_dpcm_root) {
2343 dev_dbg(rtd->dev,
2344 "ASoC: Failed to create dpcm debugfs directory %s\n",
2345 rtd->dai_link->name);
2346 return -EINVAL;
2347 }
2348
2349 rtd->debugfs_dpcm_state = debugfs_create_file("state", 0444,
2350 rtd->debugfs_dpcm_root,
2351 rtd, &dpcm_state_fops);
2352
2353 return 0;
2354}
2355#endif
diff --git a/sound/soc/tegra/Kconfig b/sound/soc/tegra/Kconfig
index ce1b773c351f..5331c61faf01 100644
--- a/sound/soc/tegra/Kconfig
+++ b/sound/soc/tegra/Kconfig
@@ -1,26 +1,53 @@
1config SND_SOC_TEGRA 1config SND_SOC_TEGRA
2 tristate "SoC Audio for the Tegra System-on-Chip" 2 tristate "SoC Audio for the Tegra System-on-Chip"
3 depends on ARCH_TEGRA && TEGRA_SYSTEM_DMA 3 depends on ARCH_TEGRA && TEGRA_SYSTEM_DMA
4 select REGMAP_MMIO
4 help 5 help
5 Say Y or M here if you want support for SoC audio on Tegra. 6 Say Y or M here if you want support for SoC audio on Tegra.
6 7
7config SND_SOC_TEGRA_I2S 8config SND_SOC_TEGRA20_DAS
8 tristate 9 tristate
9 depends on SND_SOC_TEGRA 10 depends on SND_SOC_TEGRA && ARCH_TEGRA_2x_SOC
11 help
12 Say Y or M if you want to add support for the Tegra20 DAS module.
13 You will also need to select the individual machine drivers to
14 support below.
15
16config SND_SOC_TEGRA20_I2S
17 tristate
18 depends on SND_SOC_TEGRA && ARCH_TEGRA_2x_SOC
19 select SND_SOC_TEGRA20_DAS
10 help 20 help
11 Say Y or M if you want to add support for codecs attached to the 21 Say Y or M if you want to add support for codecs attached to the
12 Tegra I2S interface. You will also need to select the individual 22 Tegra20 I2S interface. You will also need to select the individual
13 machine drivers to support below. 23 machine drivers to support below.
14 24
15config SND_SOC_TEGRA_SPDIF 25config SND_SOC_TEGRA20_SPDIF
16 tristate 26 tristate
17 depends on SND_SOC_TEGRA 27 depends on SND_SOC_TEGRA && ARCH_TEGRA_2x_SOC
18 default m 28 default m
19 help 29 help
20 Say Y or M if you want to add support for the SPDIF interface. 30 Say Y or M if you want to add support for the Tegra20 SPDIF interface.
21 You will also need to select the individual machine drivers to support 31 You will also need to select the individual machine drivers to support
22 below. 32 below.
23 33
34config SND_SOC_TEGRA30_AHUB
35 tristate
36 depends on SND_SOC_TEGRA && ARCH_TEGRA_3x_SOC
37 help
38 Say Y or M if you want to add support for the Tegra20 AHUB module.
39 You will also need to select the individual machine drivers to
40 support below.
41
42config SND_SOC_TEGRA30_I2S
43 tristate
44 depends on SND_SOC_TEGRA && ARCH_TEGRA_3x_SOC
45 select SND_SOC_TEGRA30_AHUB
46 help
47 Say Y or M if you want to add support for codecs attached to the
48 Tegra30 I2S interface. You will also need to select the individual
49 machine drivers to support below.
50
24config MACH_HAS_SND_SOC_TEGRA_WM8903 51config MACH_HAS_SND_SOC_TEGRA_WM8903
25 bool 52 bool
26 help 53 help
@@ -32,7 +59,8 @@ config SND_SOC_TEGRA_WM8903
32 tristate "SoC Audio support for Tegra boards using a WM8903 codec" 59 tristate "SoC Audio support for Tegra boards using a WM8903 codec"
33 depends on SND_SOC_TEGRA && I2C 60 depends on SND_SOC_TEGRA && I2C
34 depends on MACH_HAS_SND_SOC_TEGRA_WM8903 61 depends on MACH_HAS_SND_SOC_TEGRA_WM8903
35 select SND_SOC_TEGRA_I2S 62 select SND_SOC_TEGRA20_I2S if ARCH_TEGRA_2x_SOC
63 select SND_SOC_TEGRA30_I2S if ARCH_TEGRA_3x_SOC
36 select SND_SOC_WM8903 64 select SND_SOC_WM8903
37 help 65 help
38 Say Y or M here if you want to add support for SoC audio on Tegra 66 Say Y or M here if you want to add support for SoC audio on Tegra
@@ -42,17 +70,17 @@ config SND_SOC_TEGRA_WM8903
42config SND_SOC_TEGRA_TRIMSLICE 70config SND_SOC_TEGRA_TRIMSLICE
43 tristate "SoC Audio support for TrimSlice board" 71 tristate "SoC Audio support for TrimSlice board"
44 depends on SND_SOC_TEGRA && MACH_TRIMSLICE && I2C 72 depends on SND_SOC_TEGRA && MACH_TRIMSLICE && I2C
45 select SND_SOC_TEGRA_I2S 73 select SND_SOC_TEGRA20_I2S if ARCH_TEGRA_2x_SOC
46 select SND_SOC_TLV320AIC23 74 select SND_SOC_TLV320AIC23
47 help 75 help
48 Say Y or M here if you want to add support for SoC audio on the 76 Say Y or M here if you want to add support for SoC audio on the
49 TrimSlice platform. 77 TrimSlice platform.
50 78
51config SND_SOC_TEGRA_ALC5632 79config SND_SOC_TEGRA_ALC5632
52 tristate "SoC Audio support for Tegra boards using an ALC5632 codec" 80 tristate "SoC Audio support for Tegra boards using an ALC5632 codec"
53 depends on SND_SOC_TEGRA && I2C 81 depends on SND_SOC_TEGRA && I2C
54 select SND_SOC_TEGRA_I2S 82 select SND_SOC_TEGRA20_I2S if ARCH_TEGRA_2x_SOC
55 select SND_SOC_ALC5632 83 select SND_SOC_ALC5632
56 help 84 help
57 Say Y or M here if you want to add support for SoC audio on the 85 Say Y or M here if you want to add support for SoC audio on the
58 Toshiba AC100 netbook. 86 Toshiba AC100 netbook.
diff --git a/sound/soc/tegra/Makefile b/sound/soc/tegra/Makefile
index 8e584b8fcfba..98704b48b62a 100644
--- a/sound/soc/tegra/Makefile
+++ b/sound/soc/tegra/Makefile
@@ -1,15 +1,19 @@
1# Tegra platform Support 1# Tegra platform Support
2snd-soc-tegra-das-objs := tegra_das.o
3snd-soc-tegra-pcm-objs := tegra_pcm.o 2snd-soc-tegra-pcm-objs := tegra_pcm.o
4snd-soc-tegra-i2s-objs := tegra_i2s.o
5snd-soc-tegra-spdif-objs := tegra_spdif.o
6snd-soc-tegra-utils-objs += tegra_asoc_utils.o 3snd-soc-tegra-utils-objs += tegra_asoc_utils.o
4snd-soc-tegra20-das-objs := tegra20_das.o
5snd-soc-tegra20-i2s-objs := tegra20_i2s.o
6snd-soc-tegra20-spdif-objs := tegra20_spdif.o
7snd-soc-tegra30-ahub-objs := tegra30_ahub.o
8snd-soc-tegra30-i2s-objs := tegra30_i2s.o
7 9
8obj-$(CONFIG_SND_SOC_TEGRA) += snd-soc-tegra-utils.o
9obj-$(CONFIG_SND_SOC_TEGRA) += snd-soc-tegra-das.o
10obj-$(CONFIG_SND_SOC_TEGRA) += snd-soc-tegra-pcm.o 10obj-$(CONFIG_SND_SOC_TEGRA) += snd-soc-tegra-pcm.o
11obj-$(CONFIG_SND_SOC_TEGRA_I2S) += snd-soc-tegra-i2s.o 11obj-$(CONFIG_SND_SOC_TEGRA) += snd-soc-tegra-utils.o
12obj-$(CONFIG_SND_SOC_TEGRA_SPDIF) += snd-soc-tegra-spdif.o 12obj-$(CONFIG_SND_SOC_TEGRA20_DAS) += snd-soc-tegra20-das.o
13obj-$(CONFIG_SND_SOC_TEGRA20_I2S) += snd-soc-tegra20-i2s.o
14obj-$(CONFIG_SND_SOC_TEGRA20_SPDIF) += snd-soc-tegra20-spdif.o
15obj-$(CONFIG_SND_SOC_TEGRA30_AHUB) += snd-soc-tegra30-ahub.o
16obj-$(CONFIG_SND_SOC_TEGRA30_I2S) += snd-soc-tegra30-i2s.o
13 17
14# Tegra machine Support 18# Tegra machine Support
15snd-soc-tegra-wm8903-objs := tegra_wm8903.o 19snd-soc-tegra-wm8903-objs := tegra_wm8903.o
diff --git a/sound/soc/tegra/tegra20_das.c b/sound/soc/tegra/tegra20_das.c
new file mode 100644
index 000000000000..bf99296bce95
--- /dev/null
+++ b/sound/soc/tegra/tegra20_das.c
@@ -0,0 +1,233 @@
1/*
2 * tegra20_das.c - Tegra20 DAS driver
3 *
4 * Author: Stephen Warren <swarren@nvidia.com>
5 * Copyright (C) 2010 - NVIDIA, Inc.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * version 2 as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19 * 02110-1301 USA
20 *
21 */
22
23#include <linux/device.h>
24#include <linux/io.h>
25#include <linux/module.h>
26#include <linux/platform_device.h>
27#include <linux/regmap.h>
28#include <linux/slab.h>
29#include <sound/soc.h>
30#include "tegra20_das.h"
31
32#define DRV_NAME "tegra20-das"
33
34static struct tegra20_das *das;
35
36static inline void tegra20_das_write(u32 reg, u32 val)
37{
38 regmap_write(das->regmap, reg, val);
39}
40
41static inline u32 tegra20_das_read(u32 reg)
42{
43 u32 val;
44 regmap_read(das->regmap, reg, &val);
45 return val;
46}
47
48int tegra20_das_connect_dap_to_dac(int dap, int dac)
49{
50 u32 addr;
51 u32 reg;
52
53 if (!das)
54 return -ENODEV;
55
56 addr = TEGRA20_DAS_DAP_CTRL_SEL +
57 (dap * TEGRA20_DAS_DAP_CTRL_SEL_STRIDE);
58 reg = dac << TEGRA20_DAS_DAP_CTRL_SEL_DAP_CTRL_SEL_P;
59
60 tegra20_das_write(addr, reg);
61
62 return 0;
63}
64EXPORT_SYMBOL_GPL(tegra20_das_connect_dap_to_dac);
65
66int tegra20_das_connect_dap_to_dap(int dap, int otherdap, int master,
67 int sdata1rx, int sdata2rx)
68{
69 u32 addr;
70 u32 reg;
71
72 if (!das)
73 return -ENODEV;
74
75 addr = TEGRA20_DAS_DAP_CTRL_SEL +
76 (dap * TEGRA20_DAS_DAP_CTRL_SEL_STRIDE);
77 reg = otherdap << TEGRA20_DAS_DAP_CTRL_SEL_DAP_CTRL_SEL_P |
78 !!sdata2rx << TEGRA20_DAS_DAP_CTRL_SEL_DAP_SDATA2_TX_RX_P |
79 !!sdata1rx << TEGRA20_DAS_DAP_CTRL_SEL_DAP_SDATA1_TX_RX_P |
80 !!master << TEGRA20_DAS_DAP_CTRL_SEL_DAP_MS_SEL_P;
81
82 tegra20_das_write(addr, reg);
83
84 return 0;
85}
86EXPORT_SYMBOL_GPL(tegra20_das_connect_dap_to_dap);
87
88int tegra20_das_connect_dac_to_dap(int dac, int dap)
89{
90 u32 addr;
91 u32 reg;
92
93 if (!das)
94 return -ENODEV;
95
96 addr = TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL +
97 (dac * TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_STRIDE);
98 reg = dap << TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_CLK_SEL_P |
99 dap << TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_SDATA1_SEL_P |
100 dap << TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_SDATA2_SEL_P;
101
102 tegra20_das_write(addr, reg);
103
104 return 0;
105}
106EXPORT_SYMBOL_GPL(tegra20_das_connect_dac_to_dap);
107
108#define LAST_REG(name) \
109 (TEGRA20_DAS_##name + \
110 (TEGRA20_DAS_##name##_STRIDE * (TEGRA20_DAS_##name##_COUNT - 1)))
111
112static bool tegra20_das_wr_rd_reg(struct device *dev, unsigned int reg)
113{
114 if ((reg >= TEGRA20_DAS_DAP_CTRL_SEL) &&
115 (reg <= LAST_REG(DAP_CTRL_SEL)))
116 return true;
117 if ((reg >= TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL) &&
118 (reg <= LAST_REG(DAC_INPUT_DATA_CLK_SEL)))
119 return true;
120
121 return false;
122}
123
124static const struct regmap_config tegra20_das_regmap_config = {
125 .reg_bits = 32,
126 .reg_stride = 4,
127 .val_bits = 32,
128 .max_register = LAST_REG(DAC_INPUT_DATA_CLK_SEL),
129 .writeable_reg = tegra20_das_wr_rd_reg,
130 .readable_reg = tegra20_das_wr_rd_reg,
131 .cache_type = REGCACHE_RBTREE,
132};
133
134static int __devinit tegra20_das_probe(struct platform_device *pdev)
135{
136 struct resource *res, *region;
137 void __iomem *regs;
138 int ret = 0;
139
140 if (das)
141 return -ENODEV;
142
143 das = devm_kzalloc(&pdev->dev, sizeof(struct tegra20_das), GFP_KERNEL);
144 if (!das) {
145 dev_err(&pdev->dev, "Can't allocate tegra20_das\n");
146 ret = -ENOMEM;
147 goto err;
148 }
149 das->dev = &pdev->dev;
150
151 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
152 if (!res) {
153 dev_err(&pdev->dev, "No memory resource\n");
154 ret = -ENODEV;
155 goto err;
156 }
157
158 region = devm_request_mem_region(&pdev->dev, res->start,
159 resource_size(res), pdev->name);
160 if (!region) {
161 dev_err(&pdev->dev, "Memory region already claimed\n");
162 ret = -EBUSY;
163 goto err;
164 }
165
166 regs = devm_ioremap(&pdev->dev, res->start, resource_size(res));
167 if (!regs) {
168 dev_err(&pdev->dev, "ioremap failed\n");
169 ret = -ENOMEM;
170 goto err;
171 }
172
173 das->regmap = devm_regmap_init_mmio(&pdev->dev, regs,
174 &tegra20_das_regmap_config);
175 if (IS_ERR(das->regmap)) {
176 dev_err(&pdev->dev, "regmap init failed\n");
177 ret = PTR_ERR(das->regmap);
178 goto err;
179 }
180
181 ret = tegra20_das_connect_dap_to_dac(TEGRA20_DAS_DAP_ID_1,
182 TEGRA20_DAS_DAP_SEL_DAC1);
183 if (ret) {
184 dev_err(&pdev->dev, "Can't set up DAS DAP connection\n");
185 goto err;
186 }
187 ret = tegra20_das_connect_dac_to_dap(TEGRA20_DAS_DAC_ID_1,
188 TEGRA20_DAS_DAC_SEL_DAP1);
189 if (ret) {
190 dev_err(&pdev->dev, "Can't set up DAS DAC connection\n");
191 goto err;
192 }
193
194 platform_set_drvdata(pdev, das);
195
196 return 0;
197
198err:
199 das = NULL;
200 return ret;
201}
202
203static int __devexit tegra20_das_remove(struct platform_device *pdev)
204{
205 if (!das)
206 return -ENODEV;
207
208 das = NULL;
209
210 return 0;
211}
212
213static const struct of_device_id tegra20_das_of_match[] __devinitconst = {
214 { .compatible = "nvidia,tegra20-das", },
215 {},
216};
217
218static struct platform_driver tegra20_das_driver = {
219 .probe = tegra20_das_probe,
220 .remove = __devexit_p(tegra20_das_remove),
221 .driver = {
222 .name = DRV_NAME,
223 .owner = THIS_MODULE,
224 .of_match_table = tegra20_das_of_match,
225 },
226};
227module_platform_driver(tegra20_das_driver);
228
229MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>");
230MODULE_DESCRIPTION("Tegra20 DAS driver");
231MODULE_LICENSE("GPL");
232MODULE_ALIAS("platform:" DRV_NAME);
233MODULE_DEVICE_TABLE(of, tegra20_das_of_match);
diff --git a/sound/soc/tegra/tegra20_das.h b/sound/soc/tegra/tegra20_das.h
new file mode 100644
index 000000000000..be217f3d3a75
--- /dev/null
+++ b/sound/soc/tegra/tegra20_das.h
@@ -0,0 +1,134 @@
1/*
2 * tegra20_das.h - Definitions for Tegra20 DAS driver
3 *
4 * Author: Stephen Warren <swarren@nvidia.com>
5 * Copyright (C) 2010,2012 - NVIDIA, Inc.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * version 2 as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19 * 02110-1301 USA
20 *
21 */
22
23#ifndef __TEGRA20_DAS_H__
24#define __TEGRA20_DAS_H__
25
26/* Register TEGRA20_DAS_DAP_CTRL_SEL */
27#define TEGRA20_DAS_DAP_CTRL_SEL 0x00
28#define TEGRA20_DAS_DAP_CTRL_SEL_COUNT 5
29#define TEGRA20_DAS_DAP_CTRL_SEL_STRIDE 4
30#define TEGRA20_DAS_DAP_CTRL_SEL_DAP_MS_SEL_P 31
31#define TEGRA20_DAS_DAP_CTRL_SEL_DAP_MS_SEL_S 1
32#define TEGRA20_DAS_DAP_CTRL_SEL_DAP_SDATA1_TX_RX_P 30
33#define TEGRA20_DAS_DAP_CTRL_SEL_DAP_SDATA1_TX_RX_S 1
34#define TEGRA20_DAS_DAP_CTRL_SEL_DAP_SDATA2_TX_RX_P 29
35#define TEGRA20_DAS_DAP_CTRL_SEL_DAP_SDATA2_TX_RX_S 1
36#define TEGRA20_DAS_DAP_CTRL_SEL_DAP_CTRL_SEL_P 0
37#define TEGRA20_DAS_DAP_CTRL_SEL_DAP_CTRL_SEL_S 5
38
39/* Values for field TEGRA20_DAS_DAP_CTRL_SEL_DAP_CTRL_SEL */
40#define TEGRA20_DAS_DAP_SEL_DAC1 0
41#define TEGRA20_DAS_DAP_SEL_DAC2 1
42#define TEGRA20_DAS_DAP_SEL_DAC3 2
43#define TEGRA20_DAS_DAP_SEL_DAP1 16
44#define TEGRA20_DAS_DAP_SEL_DAP2 17
45#define TEGRA20_DAS_DAP_SEL_DAP3 18
46#define TEGRA20_DAS_DAP_SEL_DAP4 19
47#define TEGRA20_DAS_DAP_SEL_DAP5 20
48
49/* Register TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL */
50#define TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL 0x40
51#define TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_COUNT 3
52#define TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_STRIDE 4
53#define TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_SDATA2_SEL_P 28
54#define TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_SDATA2_SEL_S 4
55#define TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_SDATA1_SEL_P 24
56#define TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_SDATA1_SEL_S 4
57#define TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_CLK_SEL_P 0
58#define TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_CLK_SEL_S 4
59
60/*
61 * Values for:
62 * TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_SDATA2_SEL
63 * TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_SDATA1_SEL
64 * TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_CLK_SEL
65 */
66#define TEGRA20_DAS_DAC_SEL_DAP1 0
67#define TEGRA20_DAS_DAC_SEL_DAP2 1
68#define TEGRA20_DAS_DAC_SEL_DAP3 2
69#define TEGRA20_DAS_DAC_SEL_DAP4 3
70#define TEGRA20_DAS_DAC_SEL_DAP5 4
71
72/*
73 * Names/IDs of the DACs/DAPs.
74 */
75
76#define TEGRA20_DAS_DAP_ID_1 0
77#define TEGRA20_DAS_DAP_ID_2 1
78#define TEGRA20_DAS_DAP_ID_3 2
79#define TEGRA20_DAS_DAP_ID_4 3
80#define TEGRA20_DAS_DAP_ID_5 4
81
82#define TEGRA20_DAS_DAC_ID_1 0
83#define TEGRA20_DAS_DAC_ID_2 1
84#define TEGRA20_DAS_DAC_ID_3 2
85
86struct tegra20_das {
87 struct device *dev;
88 struct regmap *regmap;
89};
90
91/*
92 * Terminology:
93 * DAS: Digital audio switch (HW module controlled by this driver)
94 * DAP: Digital audio port (port/pins on Tegra device)
95 * DAC: Digital audio controller (e.g. I2S or AC97 controller elsewhere)
96 *
97 * The Tegra DAS is a mux/cross-bar which can connect each DAP to a specific
98 * DAC, or another DAP. When DAPs are connected, one must be the master and
99 * one the slave. Each DAC allows selection of a specific DAP for input, to
100 * cater for the case where N DAPs are connected to 1 DAC for broadcast
101 * output.
102 *
103 * This driver is dumb; no attempt is made to ensure that a valid routing
104 * configuration is programmed.
105 */
106
107/*
108 * Connect a DAP to to a DAC
109 * dap_id: DAP to connect: TEGRA20_DAS_DAP_ID_*
110 * dac_sel: DAC to connect to: TEGRA20_DAS_DAP_SEL_DAC*
111 */
112extern int tegra20_das_connect_dap_to_dac(int dap_id, int dac_sel);
113
114/*
115 * Connect a DAP to to another DAP
116 * dap_id: DAP to connect: TEGRA20_DAS_DAP_ID_*
117 * other_dap_sel: DAP to connect to: TEGRA20_DAS_DAP_SEL_DAP*
118 * master: Is this DAP the master (1) or slave (0)
119 * sdata1rx: Is this DAP's SDATA1 pin RX (1) or TX (0)
120 * sdata2rx: Is this DAP's SDATA2 pin RX (1) or TX (0)
121 */
122extern int tegra20_das_connect_dap_to_dap(int dap_id, int other_dap_sel,
123 int master, int sdata1rx,
124 int sdata2rx);
125
126/*
127 * Connect a DAC's input to a DAP
128 * (DAC outputs are selected by the DAP)
129 * dac_id: DAC ID to connect: TEGRA20_DAS_DAC_ID_*
130 * dap_sel: DAP to receive input from: TEGRA20_DAS_DAC_SEL_DAP*
131 */
132extern int tegra20_das_connect_dac_to_dap(int dac_id, int dap_sel);
133
134#endif
diff --git a/sound/soc/tegra/tegra20_i2s.c b/sound/soc/tegra/tegra20_i2s.c
new file mode 100644
index 000000000000..0c7af63d444b
--- /dev/null
+++ b/sound/soc/tegra/tegra20_i2s.c
@@ -0,0 +1,494 @@
1/*
2 * tegra20_i2s.c - Tegra20 I2S driver
3 *
4 * Author: Stephen Warren <swarren@nvidia.com>
5 * Copyright (C) 2010,2012 - NVIDIA, Inc.
6 *
7 * Based on code copyright/by:
8 *
9 * Copyright (c) 2009-2010, NVIDIA Corporation.
10 * Scott Peterson <speterson@nvidia.com>
11 *
12 * Copyright (C) 2010 Google, Inc.
13 * Iliyan Malchev <malchev@google.com>
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * version 2 as published by the Free Software Foundation.
18 *
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
27 * 02110-1301 USA
28 *
29 */
30
31#include <linux/clk.h>
32#include <linux/device.h>
33#include <linux/io.h>
34#include <linux/module.h>
35#include <linux/of.h>
36#include <linux/platform_device.h>
37#include <linux/pm_runtime.h>
38#include <linux/regmap.h>
39#include <linux/slab.h>
40#include <sound/core.h>
41#include <sound/pcm.h>
42#include <sound/pcm_params.h>
43#include <sound/soc.h>
44
45#include "tegra20_i2s.h"
46
47#define DRV_NAME "tegra20-i2s"
48
49static inline void tegra20_i2s_write(struct tegra20_i2s *i2s, u32 reg, u32 val)
50{
51 regmap_write(i2s->regmap, reg, val);
52}
53
54static inline u32 tegra20_i2s_read(struct tegra20_i2s *i2s, u32 reg)
55{
56 u32 val;
57 regmap_read(i2s->regmap, reg, &val);
58 return val;
59}
60
61static int tegra20_i2s_runtime_suspend(struct device *dev)
62{
63 struct tegra20_i2s *i2s = dev_get_drvdata(dev);
64
65 clk_disable(i2s->clk_i2s);
66
67 return 0;
68}
69
70static int tegra20_i2s_runtime_resume(struct device *dev)
71{
72 struct tegra20_i2s *i2s = dev_get_drvdata(dev);
73 int ret;
74
75 ret = clk_enable(i2s->clk_i2s);
76 if (ret) {
77 dev_err(dev, "clk_enable failed: %d\n", ret);
78 return ret;
79 }
80
81 return 0;
82}
83
84static int tegra20_i2s_set_fmt(struct snd_soc_dai *dai,
85 unsigned int fmt)
86{
87 struct tegra20_i2s *i2s = snd_soc_dai_get_drvdata(dai);
88
89 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
90 case SND_SOC_DAIFMT_NB_NF:
91 break;
92 default:
93 return -EINVAL;
94 }
95
96 i2s->reg_ctrl &= ~TEGRA20_I2S_CTRL_MASTER_ENABLE;
97 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
98 case SND_SOC_DAIFMT_CBS_CFS:
99 i2s->reg_ctrl |= TEGRA20_I2S_CTRL_MASTER_ENABLE;
100 break;
101 case SND_SOC_DAIFMT_CBM_CFM:
102 break;
103 default:
104 return -EINVAL;
105 }
106
107 i2s->reg_ctrl &= ~(TEGRA20_I2S_CTRL_BIT_FORMAT_MASK |
108 TEGRA20_I2S_CTRL_LRCK_MASK);
109 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
110 case SND_SOC_DAIFMT_DSP_A:
111 i2s->reg_ctrl |= TEGRA20_I2S_CTRL_BIT_FORMAT_DSP;
112 i2s->reg_ctrl |= TEGRA20_I2S_CTRL_LRCK_L_LOW;
113 break;
114 case SND_SOC_DAIFMT_DSP_B:
115 i2s->reg_ctrl |= TEGRA20_I2S_CTRL_BIT_FORMAT_DSP;
116 i2s->reg_ctrl |= TEGRA20_I2S_CTRL_LRCK_R_LOW;
117 break;
118 case SND_SOC_DAIFMT_I2S:
119 i2s->reg_ctrl |= TEGRA20_I2S_CTRL_BIT_FORMAT_I2S;
120 i2s->reg_ctrl |= TEGRA20_I2S_CTRL_LRCK_L_LOW;
121 break;
122 case SND_SOC_DAIFMT_RIGHT_J:
123 i2s->reg_ctrl |= TEGRA20_I2S_CTRL_BIT_FORMAT_RJM;
124 i2s->reg_ctrl |= TEGRA20_I2S_CTRL_LRCK_L_LOW;
125 break;
126 case SND_SOC_DAIFMT_LEFT_J:
127 i2s->reg_ctrl |= TEGRA20_I2S_CTRL_BIT_FORMAT_LJM;
128 i2s->reg_ctrl |= TEGRA20_I2S_CTRL_LRCK_L_LOW;
129 break;
130 default:
131 return -EINVAL;
132 }
133
134 return 0;
135}
136
137static int tegra20_i2s_hw_params(struct snd_pcm_substream *substream,
138 struct snd_pcm_hw_params *params,
139 struct snd_soc_dai *dai)
140{
141 struct device *dev = substream->pcm->card->dev;
142 struct tegra20_i2s *i2s = snd_soc_dai_get_drvdata(dai);
143 u32 reg;
144 int ret, sample_size, srate, i2sclock, bitcnt;
145
146 i2s->reg_ctrl &= ~TEGRA20_I2S_CTRL_BIT_SIZE_MASK;
147 switch (params_format(params)) {
148 case SNDRV_PCM_FORMAT_S16_LE:
149 i2s->reg_ctrl |= TEGRA20_I2S_CTRL_BIT_SIZE_16;
150 sample_size = 16;
151 break;
152 case SNDRV_PCM_FORMAT_S24_LE:
153 i2s->reg_ctrl |= TEGRA20_I2S_CTRL_BIT_SIZE_24;
154 sample_size = 24;
155 break;
156 case SNDRV_PCM_FORMAT_S32_LE:
157 i2s->reg_ctrl |= TEGRA20_I2S_CTRL_BIT_SIZE_32;
158 sample_size = 32;
159 break;
160 default:
161 return -EINVAL;
162 }
163
164 srate = params_rate(params);
165
166 /* Final "* 2" required by Tegra hardware */
167 i2sclock = srate * params_channels(params) * sample_size * 2;
168
169 ret = clk_set_rate(i2s->clk_i2s, i2sclock);
170 if (ret) {
171 dev_err(dev, "Can't set I2S clock rate: %d\n", ret);
172 return ret;
173 }
174
175 bitcnt = (i2sclock / (2 * srate)) - 1;
176 if (bitcnt < 0 || bitcnt > TEGRA20_I2S_TIMING_CHANNEL_BIT_COUNT_MASK_US)
177 return -EINVAL;
178 reg = bitcnt << TEGRA20_I2S_TIMING_CHANNEL_BIT_COUNT_SHIFT;
179
180 if (i2sclock % (2 * srate))
181 reg |= TEGRA20_I2S_TIMING_NON_SYM_ENABLE;
182
183 tegra20_i2s_write(i2s, TEGRA20_I2S_TIMING, reg);
184
185 tegra20_i2s_write(i2s, TEGRA20_I2S_FIFO_SCR,
186 TEGRA20_I2S_FIFO_SCR_FIFO2_ATN_LVL_FOUR_SLOTS |
187 TEGRA20_I2S_FIFO_SCR_FIFO1_ATN_LVL_FOUR_SLOTS);
188
189 return 0;
190}
191
192static void tegra20_i2s_start_playback(struct tegra20_i2s *i2s)
193{
194 i2s->reg_ctrl |= TEGRA20_I2S_CTRL_FIFO1_ENABLE;
195 tegra20_i2s_write(i2s, TEGRA20_I2S_CTRL, i2s->reg_ctrl);
196}
197
198static void tegra20_i2s_stop_playback(struct tegra20_i2s *i2s)
199{
200 i2s->reg_ctrl &= ~TEGRA20_I2S_CTRL_FIFO1_ENABLE;
201 tegra20_i2s_write(i2s, TEGRA20_I2S_CTRL, i2s->reg_ctrl);
202}
203
204static void tegra20_i2s_start_capture(struct tegra20_i2s *i2s)
205{
206 i2s->reg_ctrl |= TEGRA20_I2S_CTRL_FIFO2_ENABLE;
207 tegra20_i2s_write(i2s, TEGRA20_I2S_CTRL, i2s->reg_ctrl);
208}
209
210static void tegra20_i2s_stop_capture(struct tegra20_i2s *i2s)
211{
212 i2s->reg_ctrl &= ~TEGRA20_I2S_CTRL_FIFO2_ENABLE;
213 tegra20_i2s_write(i2s, TEGRA20_I2S_CTRL, i2s->reg_ctrl);
214}
215
216static int tegra20_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
217 struct snd_soc_dai *dai)
218{
219 struct tegra20_i2s *i2s = snd_soc_dai_get_drvdata(dai);
220
221 switch (cmd) {
222 case SNDRV_PCM_TRIGGER_START:
223 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
224 case SNDRV_PCM_TRIGGER_RESUME:
225 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
226 tegra20_i2s_start_playback(i2s);
227 else
228 tegra20_i2s_start_capture(i2s);
229 break;
230 case SNDRV_PCM_TRIGGER_STOP:
231 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
232 case SNDRV_PCM_TRIGGER_SUSPEND:
233 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
234 tegra20_i2s_stop_playback(i2s);
235 else
236 tegra20_i2s_stop_capture(i2s);
237 break;
238 default:
239 return -EINVAL;
240 }
241
242 return 0;
243}
244
245static int tegra20_i2s_probe(struct snd_soc_dai *dai)
246{
247 struct tegra20_i2s *i2s = snd_soc_dai_get_drvdata(dai);
248
249 dai->capture_dma_data = &i2s->capture_dma_data;
250 dai->playback_dma_data = &i2s->playback_dma_data;
251
252 return 0;
253}
254
255static const struct snd_soc_dai_ops tegra20_i2s_dai_ops = {
256 .set_fmt = tegra20_i2s_set_fmt,
257 .hw_params = tegra20_i2s_hw_params,
258 .trigger = tegra20_i2s_trigger,
259};
260
261static const struct snd_soc_dai_driver tegra20_i2s_dai_template = {
262 .probe = tegra20_i2s_probe,
263 .playback = {
264 .channels_min = 2,
265 .channels_max = 2,
266 .rates = SNDRV_PCM_RATE_8000_96000,
267 .formats = SNDRV_PCM_FMTBIT_S16_LE,
268 },
269 .capture = {
270 .channels_min = 2,
271 .channels_max = 2,
272 .rates = SNDRV_PCM_RATE_8000_96000,
273 .formats = SNDRV_PCM_FMTBIT_S16_LE,
274 },
275 .ops = &tegra20_i2s_dai_ops,
276 .symmetric_rates = 1,
277};
278
279static bool tegra20_i2s_wr_rd_reg(struct device *dev, unsigned int reg)
280{
281 switch (reg) {
282 case TEGRA20_I2S_CTRL:
283 case TEGRA20_I2S_STATUS:
284 case TEGRA20_I2S_TIMING:
285 case TEGRA20_I2S_FIFO_SCR:
286 case TEGRA20_I2S_PCM_CTRL:
287 case TEGRA20_I2S_NW_CTRL:
288 case TEGRA20_I2S_TDM_CTRL:
289 case TEGRA20_I2S_TDM_TX_RX_CTRL:
290 case TEGRA20_I2S_FIFO1:
291 case TEGRA20_I2S_FIFO2:
292 return true;
293 default:
294 return false;
295 };
296}
297
298static bool tegra20_i2s_volatile_reg(struct device *dev, unsigned int reg)
299{
300 switch (reg) {
301 case TEGRA20_I2S_STATUS:
302 case TEGRA20_I2S_FIFO_SCR:
303 case TEGRA20_I2S_FIFO1:
304 case TEGRA20_I2S_FIFO2:
305 return true;
306 default:
307 return false;
308 };
309}
310
311static bool tegra20_i2s_precious_reg(struct device *dev, unsigned int reg)
312{
313 switch (reg) {
314 case TEGRA20_I2S_FIFO1:
315 case TEGRA20_I2S_FIFO2:
316 return true;
317 default:
318 return false;
319 };
320}
321
322static const struct regmap_config tegra20_i2s_regmap_config = {
323 .reg_bits = 32,
324 .reg_stride = 4,
325 .val_bits = 32,
326 .max_register = TEGRA20_I2S_FIFO2,
327 .writeable_reg = tegra20_i2s_wr_rd_reg,
328 .readable_reg = tegra20_i2s_wr_rd_reg,
329 .volatile_reg = tegra20_i2s_volatile_reg,
330 .precious_reg = tegra20_i2s_precious_reg,
331 .cache_type = REGCACHE_RBTREE,
332};
333
334static __devinit int tegra20_i2s_platform_probe(struct platform_device *pdev)
335{
336 struct tegra20_i2s *i2s;
337 struct resource *mem, *memregion, *dmareq;
338 u32 of_dma[2];
339 u32 dma_ch;
340 void __iomem *regs;
341 int ret;
342
343 i2s = devm_kzalloc(&pdev->dev, sizeof(struct tegra20_i2s), GFP_KERNEL);
344 if (!i2s) {
345 dev_err(&pdev->dev, "Can't allocate tegra20_i2s\n");
346 ret = -ENOMEM;
347 goto err;
348 }
349 dev_set_drvdata(&pdev->dev, i2s);
350
351 i2s->dai = tegra20_i2s_dai_template;
352 i2s->dai.name = dev_name(&pdev->dev);
353
354 i2s->clk_i2s = clk_get(&pdev->dev, NULL);
355 if (IS_ERR(i2s->clk_i2s)) {
356 dev_err(&pdev->dev, "Can't retrieve i2s clock\n");
357 ret = PTR_ERR(i2s->clk_i2s);
358 goto err;
359 }
360
361 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
362 if (!mem) {
363 dev_err(&pdev->dev, "No memory resource\n");
364 ret = -ENODEV;
365 goto err_clk_put;
366 }
367
368 dmareq = platform_get_resource(pdev, IORESOURCE_DMA, 0);
369 if (!dmareq) {
370 if (of_property_read_u32_array(pdev->dev.of_node,
371 "nvidia,dma-request-selector",
372 of_dma, 2) < 0) {
373 dev_err(&pdev->dev, "No DMA resource\n");
374 ret = -ENODEV;
375 goto err_clk_put;
376 }
377 dma_ch = of_dma[1];
378 } else {
379 dma_ch = dmareq->start;
380 }
381
382 memregion = devm_request_mem_region(&pdev->dev, mem->start,
383 resource_size(mem), DRV_NAME);
384 if (!memregion) {
385 dev_err(&pdev->dev, "Memory region already claimed\n");
386 ret = -EBUSY;
387 goto err_clk_put;
388 }
389
390 regs = devm_ioremap(&pdev->dev, mem->start, resource_size(mem));
391 if (!regs) {
392 dev_err(&pdev->dev, "ioremap failed\n");
393 ret = -ENOMEM;
394 goto err_clk_put;
395 }
396
397 i2s->regmap = devm_regmap_init_mmio(&pdev->dev, regs,
398 &tegra20_i2s_regmap_config);
399 if (IS_ERR(i2s->regmap)) {
400 dev_err(&pdev->dev, "regmap init failed\n");
401 ret = PTR_ERR(i2s->regmap);
402 goto err_clk_put;
403 }
404
405 i2s->capture_dma_data.addr = mem->start + TEGRA20_I2S_FIFO2;
406 i2s->capture_dma_data.wrap = 4;
407 i2s->capture_dma_data.width = 32;
408 i2s->capture_dma_data.req_sel = dma_ch;
409
410 i2s->playback_dma_data.addr = mem->start + TEGRA20_I2S_FIFO1;
411 i2s->playback_dma_data.wrap = 4;
412 i2s->playback_dma_data.width = 32;
413 i2s->playback_dma_data.req_sel = dma_ch;
414
415 i2s->reg_ctrl = TEGRA20_I2S_CTRL_FIFO_FORMAT_PACKED;
416
417 pm_runtime_enable(&pdev->dev);
418 if (!pm_runtime_enabled(&pdev->dev)) {
419 ret = tegra20_i2s_runtime_resume(&pdev->dev);
420 if (ret)
421 goto err_pm_disable;
422 }
423
424 ret = snd_soc_register_dai(&pdev->dev, &i2s->dai);
425 if (ret) {
426 dev_err(&pdev->dev, "Could not register DAI: %d\n", ret);
427 ret = -ENOMEM;
428 goto err_suspend;
429 }
430
431 ret = tegra_pcm_platform_register(&pdev->dev);
432 if (ret) {
433 dev_err(&pdev->dev, "Could not register PCM: %d\n", ret);
434 goto err_unregister_dai;
435 }
436
437 return 0;
438
439err_unregister_dai:
440 snd_soc_unregister_dai(&pdev->dev);
441err_suspend:
442 if (!pm_runtime_status_suspended(&pdev->dev))
443 tegra20_i2s_runtime_suspend(&pdev->dev);
444err_pm_disable:
445 pm_runtime_disable(&pdev->dev);
446err_clk_put:
447 clk_put(i2s->clk_i2s);
448err:
449 return ret;
450}
451
452static int __devexit tegra20_i2s_platform_remove(struct platform_device *pdev)
453{
454 struct tegra20_i2s *i2s = dev_get_drvdata(&pdev->dev);
455
456 pm_runtime_disable(&pdev->dev);
457 if (!pm_runtime_status_suspended(&pdev->dev))
458 tegra20_i2s_runtime_suspend(&pdev->dev);
459
460 tegra_pcm_platform_unregister(&pdev->dev);
461 snd_soc_unregister_dai(&pdev->dev);
462
463 clk_put(i2s->clk_i2s);
464
465 return 0;
466}
467
468static const struct of_device_id tegra20_i2s_of_match[] __devinitconst = {
469 { .compatible = "nvidia,tegra20-i2s", },
470 {},
471};
472
473static const struct dev_pm_ops tegra20_i2s_pm_ops __devinitconst = {
474 SET_RUNTIME_PM_OPS(tegra20_i2s_runtime_suspend,
475 tegra20_i2s_runtime_resume, NULL)
476};
477
478static struct platform_driver tegra20_i2s_driver = {
479 .driver = {
480 .name = DRV_NAME,
481 .owner = THIS_MODULE,
482 .of_match_table = tegra20_i2s_of_match,
483 .pm = &tegra20_i2s_pm_ops,
484 },
485 .probe = tegra20_i2s_platform_probe,
486 .remove = __devexit_p(tegra20_i2s_platform_remove),
487};
488module_platform_driver(tegra20_i2s_driver);
489
490MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>");
491MODULE_DESCRIPTION("Tegra20 I2S ASoC driver");
492MODULE_LICENSE("GPL");
493MODULE_ALIAS("platform:" DRV_NAME);
494MODULE_DEVICE_TABLE(of, tegra20_i2s_of_match);
diff --git a/sound/soc/tegra/tegra20_i2s.h b/sound/soc/tegra/tegra20_i2s.h
new file mode 100644
index 000000000000..a57efc6a597e
--- /dev/null
+++ b/sound/soc/tegra/tegra20_i2s.h
@@ -0,0 +1,164 @@
1/*
2 * tegra20_i2s.h - Definitions for Tegra20 I2S driver
3 *
4 * Author: Stephen Warren <swarren@nvidia.com>
5 * Copyright (C) 2010,2012 - NVIDIA, Inc.
6 *
7 * Based on code copyright/by:
8 *
9 * Copyright (c) 2009-2010, NVIDIA Corporation.
10 * Scott Peterson <speterson@nvidia.com>
11 *
12 * Copyright (C) 2010 Google, Inc.
13 * Iliyan Malchev <malchev@google.com>
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * version 2 as published by the Free Software Foundation.
18 *
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
27 * 02110-1301 USA
28 *
29 */
30
31#ifndef __TEGRA20_I2S_H__
32#define __TEGRA20_I2S_H__
33
34#include "tegra_pcm.h"
35
36/* Register offsets from TEGRA20_I2S1_BASE and TEGRA20_I2S2_BASE */
37
38#define TEGRA20_I2S_CTRL 0x00
39#define TEGRA20_I2S_STATUS 0x04
40#define TEGRA20_I2S_TIMING 0x08
41#define TEGRA20_I2S_FIFO_SCR 0x0c
42#define TEGRA20_I2S_PCM_CTRL 0x10
43#define TEGRA20_I2S_NW_CTRL 0x14
44#define TEGRA20_I2S_TDM_CTRL 0x20
45#define TEGRA20_I2S_TDM_TX_RX_CTRL 0x24
46#define TEGRA20_I2S_FIFO1 0x40
47#define TEGRA20_I2S_FIFO2 0x80
48
49/* Fields in TEGRA20_I2S_CTRL */
50
51#define TEGRA20_I2S_CTRL_FIFO2_TX_ENABLE (1 << 30)
52#define TEGRA20_I2S_CTRL_FIFO1_ENABLE (1 << 29)
53#define TEGRA20_I2S_CTRL_FIFO2_ENABLE (1 << 28)
54#define TEGRA20_I2S_CTRL_FIFO1_RX_ENABLE (1 << 27)
55#define TEGRA20_I2S_CTRL_FIFO_LPBK_ENABLE (1 << 26)
56#define TEGRA20_I2S_CTRL_MASTER_ENABLE (1 << 25)
57
58#define TEGRA20_I2S_LRCK_LEFT_LOW 0
59#define TEGRA20_I2S_LRCK_RIGHT_LOW 1
60
61#define TEGRA20_I2S_CTRL_LRCK_SHIFT 24
62#define TEGRA20_I2S_CTRL_LRCK_MASK (1 << TEGRA20_I2S_CTRL_LRCK_SHIFT)
63#define TEGRA20_I2S_CTRL_LRCK_L_LOW (TEGRA20_I2S_LRCK_LEFT_LOW << TEGRA20_I2S_CTRL_LRCK_SHIFT)
64#define TEGRA20_I2S_CTRL_LRCK_R_LOW (TEGRA20_I2S_LRCK_RIGHT_LOW << TEGRA20_I2S_CTRL_LRCK_SHIFT)
65
66#define TEGRA20_I2S_BIT_FORMAT_I2S 0
67#define TEGRA20_I2S_BIT_FORMAT_RJM 1
68#define TEGRA20_I2S_BIT_FORMAT_LJM 2
69#define TEGRA20_I2S_BIT_FORMAT_DSP 3
70
71#define TEGRA20_I2S_CTRL_BIT_FORMAT_SHIFT 10
72#define TEGRA20_I2S_CTRL_BIT_FORMAT_MASK (3 << TEGRA20_I2S_CTRL_BIT_FORMAT_SHIFT)
73#define TEGRA20_I2S_CTRL_BIT_FORMAT_I2S (TEGRA20_I2S_BIT_FORMAT_I2S << TEGRA20_I2S_CTRL_BIT_FORMAT_SHIFT)
74#define TEGRA20_I2S_CTRL_BIT_FORMAT_RJM (TEGRA20_I2S_BIT_FORMAT_RJM << TEGRA20_I2S_CTRL_BIT_FORMAT_SHIFT)
75#define TEGRA20_I2S_CTRL_BIT_FORMAT_LJM (TEGRA20_I2S_BIT_FORMAT_LJM << TEGRA20_I2S_CTRL_BIT_FORMAT_SHIFT)
76#define TEGRA20_I2S_CTRL_BIT_FORMAT_DSP (TEGRA20_I2S_BIT_FORMAT_DSP << TEGRA20_I2S_CTRL_BIT_FORMAT_SHIFT)
77
78#define TEGRA20_I2S_BIT_SIZE_16 0
79#define TEGRA20_I2S_BIT_SIZE_20 1
80#define TEGRA20_I2S_BIT_SIZE_24 2
81#define TEGRA20_I2S_BIT_SIZE_32 3
82
83#define TEGRA20_I2S_CTRL_BIT_SIZE_SHIFT 8
84#define TEGRA20_I2S_CTRL_BIT_SIZE_MASK (3 << TEGRA20_I2S_CTRL_BIT_SIZE_SHIFT)
85#define TEGRA20_I2S_CTRL_BIT_SIZE_16 (TEGRA20_I2S_BIT_SIZE_16 << TEGRA20_I2S_CTRL_BIT_SIZE_SHIFT)
86#define TEGRA20_I2S_CTRL_BIT_SIZE_20 (TEGRA20_I2S_BIT_SIZE_20 << TEGRA20_I2S_CTRL_BIT_SIZE_SHIFT)
87#define TEGRA20_I2S_CTRL_BIT_SIZE_24 (TEGRA20_I2S_BIT_SIZE_24 << TEGRA20_I2S_CTRL_BIT_SIZE_SHIFT)
88#define TEGRA20_I2S_CTRL_BIT_SIZE_32 (TEGRA20_I2S_BIT_SIZE_32 << TEGRA20_I2S_CTRL_BIT_SIZE_SHIFT)
89
90#define TEGRA20_I2S_FIFO_16_LSB 0
91#define TEGRA20_I2S_FIFO_20_LSB 1
92#define TEGRA20_I2S_FIFO_24_LSB 2
93#define TEGRA20_I2S_FIFO_32 3
94#define TEGRA20_I2S_FIFO_PACKED 7
95
96#define TEGRA20_I2S_CTRL_FIFO_FORMAT_SHIFT 4
97#define TEGRA20_I2S_CTRL_FIFO_FORMAT_MASK (7 << TEGRA20_I2S_CTRL_FIFO_FORMAT_SHIFT)
98#define TEGRA20_I2S_CTRL_FIFO_FORMAT_16_LSB (TEGRA20_I2S_FIFO_16_LSB << TEGRA20_I2S_CTRL_FIFO_FORMAT_SHIFT)
99#define TEGRA20_I2S_CTRL_FIFO_FORMAT_20_LSB (TEGRA20_I2S_FIFO_20_LSB << TEGRA20_I2S_CTRL_FIFO_FORMAT_SHIFT)
100#define TEGRA20_I2S_CTRL_FIFO_FORMAT_24_LSB (TEGRA20_I2S_FIFO_24_LSB << TEGRA20_I2S_CTRL_FIFO_FORMAT_SHIFT)
101#define TEGRA20_I2S_CTRL_FIFO_FORMAT_32 (TEGRA20_I2S_FIFO_32 << TEGRA20_I2S_CTRL_FIFO_FORMAT_SHIFT)
102#define TEGRA20_I2S_CTRL_FIFO_FORMAT_PACKED (TEGRA20_I2S_FIFO_PACKED << TEGRA20_I2S_CTRL_FIFO_FORMAT_SHIFT)
103
104#define TEGRA20_I2S_CTRL_IE_FIFO1_ERR (1 << 3)
105#define TEGRA20_I2S_CTRL_IE_FIFO2_ERR (1 << 2)
106#define TEGRA20_I2S_CTRL_QE_FIFO1 (1 << 1)
107#define TEGRA20_I2S_CTRL_QE_FIFO2 (1 << 0)
108
109/* Fields in TEGRA20_I2S_STATUS */
110
111#define TEGRA20_I2S_STATUS_FIFO1_RDY (1 << 31)
112#define TEGRA20_I2S_STATUS_FIFO2_RDY (1 << 30)
113#define TEGRA20_I2S_STATUS_FIFO1_BSY (1 << 29)
114#define TEGRA20_I2S_STATUS_FIFO2_BSY (1 << 28)
115#define TEGRA20_I2S_STATUS_FIFO1_ERR (1 << 3)
116#define TEGRA20_I2S_STATUS_FIFO2_ERR (1 << 2)
117#define TEGRA20_I2S_STATUS_QS_FIFO1 (1 << 1)
118#define TEGRA20_I2S_STATUS_QS_FIFO2 (1 << 0)
119
120/* Fields in TEGRA20_I2S_TIMING */
121
122#define TEGRA20_I2S_TIMING_NON_SYM_ENABLE (1 << 12)
123#define TEGRA20_I2S_TIMING_CHANNEL_BIT_COUNT_SHIFT 0
124#define TEGRA20_I2S_TIMING_CHANNEL_BIT_COUNT_MASK_US 0x7fff
125#define TEGRA20_I2S_TIMING_CHANNEL_BIT_COUNT_MASK (TEGRA20_I2S_TIMING_CHANNEL_BIT_COUNT_MASK_US << TEGRA20_I2S_TIMING_CHANNEL_BIT_COUNT_SHIFT)
126
127/* Fields in TEGRA20_I2S_FIFO_SCR */
128
129#define TEGRA20_I2S_FIFO_SCR_FIFO2_FULL_EMPTY_COUNT_SHIFT 24
130#define TEGRA20_I2S_FIFO_SCR_FIFO1_FULL_EMPTY_COUNT_SHIFT 16
131#define TEGRA20_I2S_FIFO_SCR_FIFO_FULL_EMPTY_COUNT_MASK 0x3f
132
133#define TEGRA20_I2S_FIFO_SCR_FIFO2_CLR (1 << 12)
134#define TEGRA20_I2S_FIFO_SCR_FIFO1_CLR (1 << 8)
135
136#define TEGRA20_I2S_FIFO_ATN_LVL_ONE_SLOT 0
137#define TEGRA20_I2S_FIFO_ATN_LVL_FOUR_SLOTS 1
138#define TEGRA20_I2S_FIFO_ATN_LVL_EIGHT_SLOTS 2
139#define TEGRA20_I2S_FIFO_ATN_LVL_TWELVE_SLOTS 3
140
141#define TEGRA20_I2S_FIFO_SCR_FIFO2_ATN_LVL_SHIFT 4
142#define TEGRA20_I2S_FIFO_SCR_FIFO2_ATN_LVL_MASK (3 << TEGRA20_I2S_FIFO_SCR_FIFO2_ATN_LVL_SHIFT)
143#define TEGRA20_I2S_FIFO_SCR_FIFO2_ATN_LVL_ONE_SLOT (TEGRA20_I2S_FIFO_ATN_LVL_ONE_SLOT << TEGRA20_I2S_FIFO_SCR_FIFO2_ATN_LVL_SHIFT)
144#define TEGRA20_I2S_FIFO_SCR_FIFO2_ATN_LVL_FOUR_SLOTS (TEGRA20_I2S_FIFO_ATN_LVL_FOUR_SLOTS << TEGRA20_I2S_FIFO_SCR_FIFO2_ATN_LVL_SHIFT)
145#define TEGRA20_I2S_FIFO_SCR_FIFO2_ATN_LVL_EIGHT_SLOTS (TEGRA20_I2S_FIFO_ATN_LVL_EIGHT_SLOTS << TEGRA20_I2S_FIFO_SCR_FIFO2_ATN_LVL_SHIFT)
146#define TEGRA20_I2S_FIFO_SCR_FIFO2_ATN_LVL_TWELVE_SLOTS (TEGRA20_I2S_FIFO_ATN_LVL_TWELVE_SLOTS << TEGRA20_I2S_FIFO_SCR_FIFO2_ATN_LVL_SHIFT)
147
148#define TEGRA20_I2S_FIFO_SCR_FIFO1_ATN_LVL_SHIFT 0
149#define TEGRA20_I2S_FIFO_SCR_FIFO1_ATN_LVL_MASK (3 << TEGRA20_I2S_FIFO_SCR_FIFO1_ATN_LVL_SHIFT)
150#define TEGRA20_I2S_FIFO_SCR_FIFO1_ATN_LVL_ONE_SLOT (TEGRA20_I2S_FIFO_ATN_LVL_ONE_SLOT << TEGRA20_I2S_FIFO_SCR_FIFO1_ATN_LVL_SHIFT)
151#define TEGRA20_I2S_FIFO_SCR_FIFO1_ATN_LVL_FOUR_SLOTS (TEGRA20_I2S_FIFO_ATN_LVL_FOUR_SLOTS << TEGRA20_I2S_FIFO_SCR_FIFO1_ATN_LVL_SHIFT)
152#define TEGRA20_I2S_FIFO_SCR_FIFO1_ATN_LVL_EIGHT_SLOTS (TEGRA20_I2S_FIFO_ATN_LVL_EIGHT_SLOTS << TEGRA20_I2S_FIFO_SCR_FIFO1_ATN_LVL_SHIFT)
153#define TEGRA20_I2S_FIFO_SCR_FIFO1_ATN_LVL_TWELVE_SLOTS (TEGRA20_I2S_FIFO_ATN_LVL_TWELVE_SLOTS << TEGRA20_I2S_FIFO_SCR_FIFO1_ATN_LVL_SHIFT)
154
155struct tegra20_i2s {
156 struct snd_soc_dai_driver dai;
157 struct clk *clk_i2s;
158 struct tegra_pcm_dma_params capture_dma_data;
159 struct tegra_pcm_dma_params playback_dma_data;
160 struct regmap *regmap;
161 u32 reg_ctrl;
162};
163
164#endif
diff --git a/sound/soc/tegra/tegra20_spdif.c b/sound/soc/tegra/tegra20_spdif.c
new file mode 100644
index 000000000000..f9b57418bd08
--- /dev/null
+++ b/sound/soc/tegra/tegra20_spdif.c
@@ -0,0 +1,404 @@
1/*
2 * tegra20_spdif.c - Tegra20 SPDIF driver
3 *
4 * Author: Stephen Warren <swarren@nvidia.com>
5 * Copyright (C) 2011-2012 - NVIDIA, Inc.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * version 2 as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19 * 02110-1301 USA
20 *
21 */
22
23#include <linux/clk.h>
24#include <linux/device.h>
25#include <linux/io.h>
26#include <linux/module.h>
27#include <linux/platform_device.h>
28#include <linux/pm_runtime.h>
29#include <linux/regmap.h>
30#include <linux/slab.h>
31#include <sound/core.h>
32#include <sound/pcm.h>
33#include <sound/pcm_params.h>
34#include <sound/soc.h>
35
36#include "tegra20_spdif.h"
37
38#define DRV_NAME "tegra20-spdif"
39
40static inline void tegra20_spdif_write(struct tegra20_spdif *spdif, u32 reg,
41 u32 val)
42{
43 regmap_write(spdif->regmap, reg, val);
44}
45
46static inline u32 tegra20_spdif_read(struct tegra20_spdif *spdif, u32 reg)
47{
48 u32 val;
49 regmap_read(spdif->regmap, reg, &val);
50 return val;
51}
52
53static int tegra20_spdif_runtime_suspend(struct device *dev)
54{
55 struct tegra20_spdif *spdif = dev_get_drvdata(dev);
56
57 clk_disable(spdif->clk_spdif_out);
58
59 return 0;
60}
61
62static int tegra20_spdif_runtime_resume(struct device *dev)
63{
64 struct tegra20_spdif *spdif = dev_get_drvdata(dev);
65 int ret;
66
67 ret = clk_enable(spdif->clk_spdif_out);
68 if (ret) {
69 dev_err(dev, "clk_enable failed: %d\n", ret);
70 return ret;
71 }
72
73 return 0;
74}
75
76static int tegra20_spdif_hw_params(struct snd_pcm_substream *substream,
77 struct snd_pcm_hw_params *params,
78 struct snd_soc_dai *dai)
79{
80 struct device *dev = substream->pcm->card->dev;
81 struct tegra20_spdif *spdif = snd_soc_dai_get_drvdata(dai);
82 int ret, spdifclock;
83
84 spdif->reg_ctrl &= ~TEGRA20_SPDIF_CTRL_PACK;
85 spdif->reg_ctrl &= ~TEGRA20_SPDIF_CTRL_BIT_MODE_MASK;
86 switch (params_format(params)) {
87 case SNDRV_PCM_FORMAT_S16_LE:
88 spdif->reg_ctrl |= TEGRA20_SPDIF_CTRL_PACK;
89 spdif->reg_ctrl |= TEGRA20_SPDIF_CTRL_BIT_MODE_16BIT;
90 break;
91 default:
92 return -EINVAL;
93 }
94
95 switch (params_rate(params)) {
96 case 32000:
97 spdifclock = 4096000;
98 break;
99 case 44100:
100 spdifclock = 5644800;
101 break;
102 case 48000:
103 spdifclock = 6144000;
104 break;
105 case 88200:
106 spdifclock = 11289600;
107 break;
108 case 96000:
109 spdifclock = 12288000;
110 break;
111 case 176400:
112 spdifclock = 22579200;
113 break;
114 case 192000:
115 spdifclock = 24576000;
116 break;
117 default:
118 return -EINVAL;
119 }
120
121 ret = clk_set_rate(spdif->clk_spdif_out, spdifclock);
122 if (ret) {
123 dev_err(dev, "Can't set SPDIF clock rate: %d\n", ret);
124 return ret;
125 }
126
127 return 0;
128}
129
130static void tegra20_spdif_start_playback(struct tegra20_spdif *spdif)
131{
132 spdif->reg_ctrl |= TEGRA20_SPDIF_CTRL_TX_EN;
133 tegra20_spdif_write(spdif, TEGRA20_SPDIF_CTRL, spdif->reg_ctrl);
134}
135
136static void tegra20_spdif_stop_playback(struct tegra20_spdif *spdif)
137{
138 spdif->reg_ctrl &= ~TEGRA20_SPDIF_CTRL_TX_EN;
139 tegra20_spdif_write(spdif, TEGRA20_SPDIF_CTRL, spdif->reg_ctrl);
140}
141
142static int tegra20_spdif_trigger(struct snd_pcm_substream *substream, int cmd,
143 struct snd_soc_dai *dai)
144{
145 struct tegra20_spdif *spdif = snd_soc_dai_get_drvdata(dai);
146
147 switch (cmd) {
148 case SNDRV_PCM_TRIGGER_START:
149 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
150 case SNDRV_PCM_TRIGGER_RESUME:
151 tegra20_spdif_start_playback(spdif);
152 break;
153 case SNDRV_PCM_TRIGGER_STOP:
154 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
155 case SNDRV_PCM_TRIGGER_SUSPEND:
156 tegra20_spdif_stop_playback(spdif);
157 break;
158 default:
159 return -EINVAL;
160 }
161
162 return 0;
163}
164
165static int tegra20_spdif_probe(struct snd_soc_dai *dai)
166{
167 struct tegra20_spdif *spdif = snd_soc_dai_get_drvdata(dai);
168
169 dai->capture_dma_data = NULL;
170 dai->playback_dma_data = &spdif->playback_dma_data;
171
172 return 0;
173}
174
175static const struct snd_soc_dai_ops tegra20_spdif_dai_ops = {
176 .hw_params = tegra20_spdif_hw_params,
177 .trigger = tegra20_spdif_trigger,
178};
179
180static struct snd_soc_dai_driver tegra20_spdif_dai = {
181 .name = DRV_NAME,
182 .probe = tegra20_spdif_probe,
183 .playback = {
184 .channels_min = 2,
185 .channels_max = 2,
186 .rates = SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 |
187 SNDRV_PCM_RATE_48000,
188 .formats = SNDRV_PCM_FMTBIT_S16_LE,
189 },
190 .ops = &tegra20_spdif_dai_ops,
191};
192
193static bool tegra20_spdif_wr_rd_reg(struct device *dev, unsigned int reg)
194{
195 switch (reg) {
196 case TEGRA20_SPDIF_CTRL:
197 case TEGRA20_SPDIF_STATUS:
198 case TEGRA20_SPDIF_STROBE_CTRL:
199 case TEGRA20_SPDIF_DATA_FIFO_CSR:
200 case TEGRA20_SPDIF_DATA_OUT:
201 case TEGRA20_SPDIF_DATA_IN:
202 case TEGRA20_SPDIF_CH_STA_RX_A:
203 case TEGRA20_SPDIF_CH_STA_RX_B:
204 case TEGRA20_SPDIF_CH_STA_RX_C:
205 case TEGRA20_SPDIF_CH_STA_RX_D:
206 case TEGRA20_SPDIF_CH_STA_RX_E:
207 case TEGRA20_SPDIF_CH_STA_RX_F:
208 case TEGRA20_SPDIF_CH_STA_TX_A:
209 case TEGRA20_SPDIF_CH_STA_TX_B:
210 case TEGRA20_SPDIF_CH_STA_TX_C:
211 case TEGRA20_SPDIF_CH_STA_TX_D:
212 case TEGRA20_SPDIF_CH_STA_TX_E:
213 case TEGRA20_SPDIF_CH_STA_TX_F:
214 case TEGRA20_SPDIF_USR_STA_RX_A:
215 case TEGRA20_SPDIF_USR_DAT_TX_A:
216 return true;
217 default:
218 return false;
219 };
220}
221
222static bool tegra20_spdif_volatile_reg(struct device *dev, unsigned int reg)
223{
224 switch (reg) {
225 case TEGRA20_SPDIF_STATUS:
226 case TEGRA20_SPDIF_DATA_FIFO_CSR:
227 case TEGRA20_SPDIF_DATA_OUT:
228 case TEGRA20_SPDIF_DATA_IN:
229 case TEGRA20_SPDIF_CH_STA_RX_A:
230 case TEGRA20_SPDIF_CH_STA_RX_B:
231 case TEGRA20_SPDIF_CH_STA_RX_C:
232 case TEGRA20_SPDIF_CH_STA_RX_D:
233 case TEGRA20_SPDIF_CH_STA_RX_E:
234 case TEGRA20_SPDIF_CH_STA_RX_F:
235 case TEGRA20_SPDIF_USR_STA_RX_A:
236 case TEGRA20_SPDIF_USR_DAT_TX_A:
237 return true;
238 default:
239 return false;
240 };
241}
242
243static bool tegra20_spdif_precious_reg(struct device *dev, unsigned int reg)
244{
245 switch (reg) {
246 case TEGRA20_SPDIF_DATA_OUT:
247 case TEGRA20_SPDIF_DATA_IN:
248 case TEGRA20_SPDIF_USR_STA_RX_A:
249 case TEGRA20_SPDIF_USR_DAT_TX_A:
250 return true;
251 default:
252 return false;
253 };
254}
255
256static const struct regmap_config tegra20_spdif_regmap_config = {
257 .reg_bits = 32,
258 .reg_stride = 4,
259 .val_bits = 32,
260 .max_register = TEGRA20_SPDIF_USR_DAT_TX_A,
261 .writeable_reg = tegra20_spdif_wr_rd_reg,
262 .readable_reg = tegra20_spdif_wr_rd_reg,
263 .volatile_reg = tegra20_spdif_volatile_reg,
264 .precious_reg = tegra20_spdif_precious_reg,
265 .cache_type = REGCACHE_RBTREE,
266};
267
268static __devinit int tegra20_spdif_platform_probe(struct platform_device *pdev)
269{
270 struct tegra20_spdif *spdif;
271 struct resource *mem, *memregion, *dmareq;
272 void __iomem *regs;
273 int ret;
274
275 spdif = devm_kzalloc(&pdev->dev, sizeof(struct tegra20_spdif),
276 GFP_KERNEL);
277 if (!spdif) {
278 dev_err(&pdev->dev, "Can't allocate tegra20_spdif\n");
279 ret = -ENOMEM;
280 goto err;
281 }
282 dev_set_drvdata(&pdev->dev, spdif);
283
284 spdif->clk_spdif_out = clk_get(&pdev->dev, "spdif_out");
285 if (IS_ERR(spdif->clk_spdif_out)) {
286 pr_err("Can't retrieve spdif clock\n");
287 ret = PTR_ERR(spdif->clk_spdif_out);
288 goto err;
289 }
290
291 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
292 if (!mem) {
293 dev_err(&pdev->dev, "No memory resource\n");
294 ret = -ENODEV;
295 goto err_clk_put;
296 }
297
298 dmareq = platform_get_resource(pdev, IORESOURCE_DMA, 0);
299 if (!dmareq) {
300 dev_err(&pdev->dev, "No DMA resource\n");
301 ret = -ENODEV;
302 goto err_clk_put;
303 }
304
305 memregion = devm_request_mem_region(&pdev->dev, mem->start,
306 resource_size(mem), DRV_NAME);
307 if (!memregion) {
308 dev_err(&pdev->dev, "Memory region already claimed\n");
309 ret = -EBUSY;
310 goto err_clk_put;
311 }
312
313 regs = devm_ioremap(&pdev->dev, mem->start, resource_size(mem));
314 if (!regs) {
315 dev_err(&pdev->dev, "ioremap failed\n");
316 ret = -ENOMEM;
317 goto err_clk_put;
318 }
319
320 spdif->regmap = devm_regmap_init_mmio(&pdev->dev, regs,
321 &tegra20_spdif_regmap_config);
322 if (IS_ERR(spdif->regmap)) {
323 dev_err(&pdev->dev, "regmap init failed\n");
324 ret = PTR_ERR(spdif->regmap);
325 goto err_clk_put;
326 }
327
328 spdif->playback_dma_data.addr = mem->start + TEGRA20_SPDIF_DATA_OUT;
329 spdif->playback_dma_data.wrap = 4;
330 spdif->playback_dma_data.width = 32;
331 spdif->playback_dma_data.req_sel = dmareq->start;
332
333 pm_runtime_enable(&pdev->dev);
334 if (!pm_runtime_enabled(&pdev->dev)) {
335 ret = tegra20_spdif_runtime_resume(&pdev->dev);
336 if (ret)
337 goto err_pm_disable;
338 }
339
340 ret = snd_soc_register_dai(&pdev->dev, &tegra20_spdif_dai);
341 if (ret) {
342 dev_err(&pdev->dev, "Could not register DAI: %d\n", ret);
343 ret = -ENOMEM;
344 goto err_suspend;
345 }
346
347 ret = tegra_pcm_platform_register(&pdev->dev);
348 if (ret) {
349 dev_err(&pdev->dev, "Could not register PCM: %d\n", ret);
350 goto err_unregister_dai;
351 }
352
353 return 0;
354
355err_unregister_dai:
356 snd_soc_unregister_dai(&pdev->dev);
357err_suspend:
358 if (!pm_runtime_status_suspended(&pdev->dev))
359 tegra20_spdif_runtime_suspend(&pdev->dev);
360err_pm_disable:
361 pm_runtime_disable(&pdev->dev);
362err_clk_put:
363 clk_put(spdif->clk_spdif_out);
364err:
365 return ret;
366}
367
368static int __devexit tegra20_spdif_platform_remove(struct platform_device *pdev)
369{
370 struct tegra20_spdif *spdif = dev_get_drvdata(&pdev->dev);
371
372 pm_runtime_disable(&pdev->dev);
373 if (!pm_runtime_status_suspended(&pdev->dev))
374 tegra20_spdif_runtime_suspend(&pdev->dev);
375
376 tegra_pcm_platform_unregister(&pdev->dev);
377 snd_soc_unregister_dai(&pdev->dev);
378
379 clk_put(spdif->clk_spdif_out);
380
381 return 0;
382}
383
384static const struct dev_pm_ops tegra20_spdif_pm_ops __devinitconst = {
385 SET_RUNTIME_PM_OPS(tegra20_spdif_runtime_suspend,
386 tegra20_spdif_runtime_resume, NULL)
387};
388
389static struct platform_driver tegra20_spdif_driver = {
390 .driver = {
391 .name = DRV_NAME,
392 .owner = THIS_MODULE,
393 .pm = &tegra20_spdif_pm_ops,
394 },
395 .probe = tegra20_spdif_platform_probe,
396 .remove = __devexit_p(tegra20_spdif_platform_remove),
397};
398
399module_platform_driver(tegra20_spdif_driver);
400
401MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>");
402MODULE_DESCRIPTION("Tegra20 SPDIF ASoC driver");
403MODULE_LICENSE("GPL");
404MODULE_ALIAS("platform:" DRV_NAME);
diff --git a/sound/soc/tegra/tegra20_spdif.h b/sound/soc/tegra/tegra20_spdif.h
new file mode 100644
index 000000000000..ed756527efea
--- /dev/null
+++ b/sound/soc/tegra/tegra20_spdif.h
@@ -0,0 +1,471 @@
1/*
2 * tegra20_spdif.h - Definitions for Tegra20 SPDIF driver
3 *
4 * Author: Stephen Warren <swarren@nvidia.com>
5 * Copyright (C) 2011 - NVIDIA, Inc.
6 *
7 * Based on code copyright/by:
8 * Copyright (c) 2008-2009, NVIDIA Corporation
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * version 2 as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22 * 02110-1301 USA
23 *
24 */
25
26#ifndef __TEGRA20_SPDIF_H__
27#define __TEGRA20_SPDIF_H__
28
29#include "tegra_pcm.h"
30
31/* Offsets from TEGRA20_SPDIF_BASE */
32
33#define TEGRA20_SPDIF_CTRL 0x0
34#define TEGRA20_SPDIF_STATUS 0x4
35#define TEGRA20_SPDIF_STROBE_CTRL 0x8
36#define TEGRA20_SPDIF_DATA_FIFO_CSR 0x0C
37#define TEGRA20_SPDIF_DATA_OUT 0x40
38#define TEGRA20_SPDIF_DATA_IN 0x80
39#define TEGRA20_SPDIF_CH_STA_RX_A 0x100
40#define TEGRA20_SPDIF_CH_STA_RX_B 0x104
41#define TEGRA20_SPDIF_CH_STA_RX_C 0x108
42#define TEGRA20_SPDIF_CH_STA_RX_D 0x10C
43#define TEGRA20_SPDIF_CH_STA_RX_E 0x110
44#define TEGRA20_SPDIF_CH_STA_RX_F 0x114
45#define TEGRA20_SPDIF_CH_STA_TX_A 0x140
46#define TEGRA20_SPDIF_CH_STA_TX_B 0x144
47#define TEGRA20_SPDIF_CH_STA_TX_C 0x148
48#define TEGRA20_SPDIF_CH_STA_TX_D 0x14C
49#define TEGRA20_SPDIF_CH_STA_TX_E 0x150
50#define TEGRA20_SPDIF_CH_STA_TX_F 0x154
51#define TEGRA20_SPDIF_USR_STA_RX_A 0x180
52#define TEGRA20_SPDIF_USR_DAT_TX_A 0x1C0
53
54/* Fields in TEGRA20_SPDIF_CTRL */
55
56/* Start capturing from 0=right, 1=left channel */
57#define TEGRA20_SPDIF_CTRL_CAP_LC (1 << 30)
58
59/* SPDIF receiver(RX) enable */
60#define TEGRA20_SPDIF_CTRL_RX_EN (1 << 29)
61
62/* SPDIF Transmitter(TX) enable */
63#define TEGRA20_SPDIF_CTRL_TX_EN (1 << 28)
64
65/* Transmit Channel status */
66#define TEGRA20_SPDIF_CTRL_TC_EN (1 << 27)
67
68/* Transmit user Data */
69#define TEGRA20_SPDIF_CTRL_TU_EN (1 << 26)
70
71/* Interrupt on transmit error */
72#define TEGRA20_SPDIF_CTRL_IE_TXE (1 << 25)
73
74/* Interrupt on receive error */
75#define TEGRA20_SPDIF_CTRL_IE_RXE (1 << 24)
76
77/* Interrupt on invalid preamble */
78#define TEGRA20_SPDIF_CTRL_IE_P (1 << 23)
79
80/* Interrupt on "B" preamble */
81#define TEGRA20_SPDIF_CTRL_IE_B (1 << 22)
82
83/* Interrupt when block of channel status received */
84#define TEGRA20_SPDIF_CTRL_IE_C (1 << 21)
85
86/* Interrupt when a valid information unit (IU) is received */
87#define TEGRA20_SPDIF_CTRL_IE_U (1 << 20)
88
89/* Interrupt when RX user FIFO attention level is reached */
90#define TEGRA20_SPDIF_CTRL_QE_RU (1 << 19)
91
92/* Interrupt when TX user FIFO attention level is reached */
93#define TEGRA20_SPDIF_CTRL_QE_TU (1 << 18)
94
95/* Interrupt when RX data FIFO attention level is reached */
96#define TEGRA20_SPDIF_CTRL_QE_RX (1 << 17)
97
98/* Interrupt when TX data FIFO attention level is reached */
99#define TEGRA20_SPDIF_CTRL_QE_TX (1 << 16)
100
101/* Loopback test mode enable */
102#define TEGRA20_SPDIF_CTRL_LBK_EN (1 << 15)
103
104/*
105 * Pack data mode:
106 * 0 = Single data (16 bit needs to be padded to match the
107 * interface data bit size).
108 * 1 = Packeted left/right channel data into a single word.
109 */
110#define TEGRA20_SPDIF_CTRL_PACK (1 << 14)
111
112/*
113 * 00 = 16bit data
114 * 01 = 20bit data
115 * 10 = 24bit data
116 * 11 = raw data
117 */
118#define TEGRA20_SPDIF_BIT_MODE_16BIT 0
119#define TEGRA20_SPDIF_BIT_MODE_20BIT 1
120#define TEGRA20_SPDIF_BIT_MODE_24BIT 2
121#define TEGRA20_SPDIF_BIT_MODE_RAW 3
122
123#define TEGRA20_SPDIF_CTRL_BIT_MODE_SHIFT 12
124#define TEGRA20_SPDIF_CTRL_BIT_MODE_MASK (3 << TEGRA20_SPDIF_CTRL_BIT_MODE_SHIFT)
125#define TEGRA20_SPDIF_CTRL_BIT_MODE_16BIT (TEGRA20_SPDIF_BIT_MODE_16BIT << TEGRA20_SPDIF_CTRL_BIT_MODE_SHIFT)
126#define TEGRA20_SPDIF_CTRL_BIT_MODE_20BIT (TEGRA20_SPDIF_BIT_MODE_20BIT << TEGRA20_SPDIF_CTRL_BIT_MODE_SHIFT)
127#define TEGRA20_SPDIF_CTRL_BIT_MODE_24BIT (TEGRA20_SPDIF_BIT_MODE_24BIT << TEGRA20_SPDIF_CTRL_BIT_MODE_SHIFT)
128#define TEGRA20_SPDIF_CTRL_BIT_MODE_RAW (TEGRA20_SPDIF_BIT_MODE_RAW << TEGRA20_SPDIF_CTRL_BIT_MODE_SHIFT)
129
130/* Fields in TEGRA20_SPDIF_STATUS */
131
132/*
133 * Note: IS_P, IS_B, IS_C, and IS_U are sticky bits. Software must
134 * write a 1 to the corresponding bit location to clear the status.
135 */
136
137/*
138 * Receiver(RX) shifter is busy receiving data.
139 * This bit is asserted when the receiver first locked onto the
140 * preamble of the data stream after RX_EN is asserted. This bit is
141 * deasserted when either,
142 * (a) the end of a frame is reached after RX_EN is deeasserted, or
143 * (b) the SPDIF data stream becomes inactive.
144 */
145#define TEGRA20_SPDIF_STATUS_RX_BSY (1 << 29)
146
147/*
148 * Transmitter(TX) shifter is busy transmitting data.
149 * This bit is asserted when TX_EN is asserted.
150 * This bit is deasserted when the end of a frame is reached after
151 * TX_EN is deasserted.
152 */
153#define TEGRA20_SPDIF_STATUS_TX_BSY (1 << 28)
154
155/*
156 * TX is busy shifting out channel status.
157 * This bit is asserted when both TX_EN and TC_EN are asserted and
158 * data from CH_STA_TX_A register is loaded into the internal shifter.
159 * This bit is deasserted when either,
160 * (a) the end of a frame is reached after TX_EN is deasserted, or
161 * (b) CH_STA_TX_F register is loaded into the internal shifter.
162 */
163#define TEGRA20_SPDIF_STATUS_TC_BSY (1 << 27)
164
165/*
166 * TX User data FIFO busy.
167 * This bit is asserted when TX_EN and TXU_EN are asserted and
168 * there's data in the TX user FIFO. This bit is deassert when either,
169 * (a) the end of a frame is reached after TX_EN is deasserted, or
170 * (b) there's no data left in the TX user FIFO.
171 */
172#define TEGRA20_SPDIF_STATUS_TU_BSY (1 << 26)
173
174/* TX FIFO Underrun error status */
175#define TEGRA20_SPDIF_STATUS_TX_ERR (1 << 25)
176
177/* RX FIFO Overrun error status */
178#define TEGRA20_SPDIF_STATUS_RX_ERR (1 << 24)
179
180/* Preamble status: 0=Preamble OK, 1=bad/missing preamble */
181#define TEGRA20_SPDIF_STATUS_IS_P (1 << 23)
182
183/* B-preamble detection status: 0=not detected, 1=B-preamble detected */
184#define TEGRA20_SPDIF_STATUS_IS_B (1 << 22)
185
186/*
187 * RX channel block data receive status:
188 * 0=entire block not recieved yet.
189 * 1=received entire block of channel status,
190 */
191#define TEGRA20_SPDIF_STATUS_IS_C (1 << 21)
192
193/* RX User Data Valid flag: 1=valid IU detected, 0 = no IU detected. */
194#define TEGRA20_SPDIF_STATUS_IS_U (1 << 20)
195
196/*
197 * RX User FIFO Status:
198 * 1=attention level reached, 0=attention level not reached.
199 */
200#define TEGRA20_SPDIF_STATUS_QS_RU (1 << 19)
201
202/*
203 * TX User FIFO Status:
204 * 1=attention level reached, 0=attention level not reached.
205 */
206#define TEGRA20_SPDIF_STATUS_QS_TU (1 << 18)
207
208/*
209 * RX Data FIFO Status:
210 * 1=attention level reached, 0=attention level not reached.
211 */
212#define TEGRA20_SPDIF_STATUS_QS_RX (1 << 17)
213
214/*
215 * TX Data FIFO Status:
216 * 1=attention level reached, 0=attention level not reached.
217 */
218#define TEGRA20_SPDIF_STATUS_QS_TX (1 << 16)
219
220/* Fields in TEGRA20_SPDIF_STROBE_CTRL */
221
222/*
223 * Indicates the approximate number of detected SPDIFIN clocks within a
224 * bi-phase period.
225 */
226#define TEGRA20_SPDIF_STROBE_CTRL_PERIOD_SHIFT 16
227#define TEGRA20_SPDIF_STROBE_CTRL_PERIOD_MASK (0xff << TEGRA20_SPDIF_STROBE_CTRL_PERIOD_SHIFT)
228
229/* Data strobe mode: 0=Auto-locked 1=Manual locked */
230#define TEGRA20_SPDIF_STROBE_CTRL_STROBE (1 << 15)
231
232/*
233 * Manual data strobe time within the bi-phase clock period (in terms of
234 * the number of over-sampling clocks).
235 */
236#define TEGRA20_SPDIF_STROBE_CTRL_DATA_STROBES_SHIFT 8
237#define TEGRA20_SPDIF_STROBE_CTRL_DATA_STROBES_MASK (0x1f << TEGRA20_SPDIF_STROBE_CTRL_DATA_STROBES_SHIFT)
238
239/*
240 * Manual SPDIFIN bi-phase clock period (in terms of the number of
241 * over-sampling clocks).
242 */
243#define TEGRA20_SPDIF_STROBE_CTRL_CLOCK_PERIOD_SHIFT 0
244#define TEGRA20_SPDIF_STROBE_CTRL_CLOCK_PERIOD_MASK (0x3f << TEGRA20_SPDIF_STROBE_CTRL_CLOCK_PERIOD_SHIFT)
245
246/* Fields in SPDIF_DATA_FIFO_CSR */
247
248/* Clear Receiver User FIFO (RX USR.FIFO) */
249#define TEGRA20_SPDIF_DATA_FIFO_CSR_RU_CLR (1 << 31)
250
251#define TEGRA20_SPDIF_FIFO_ATN_LVL_U_ONE_SLOT 0
252#define TEGRA20_SPDIF_FIFO_ATN_LVL_U_TWO_SLOTS 1
253#define TEGRA20_SPDIF_FIFO_ATN_LVL_U_THREE_SLOTS 2
254#define TEGRA20_SPDIF_FIFO_ATN_LVL_U_FOUR_SLOTS 3
255
256/* RU FIFO attention level */
257#define TEGRA20_SPDIF_DATA_FIFO_CSR_RU_ATN_LVL_SHIFT 29
258#define TEGRA20_SPDIF_DATA_FIFO_CSR_RU_ATN_LVL_MASK \
259 (0x3 << TEGRA20_SPDIF_DATA_FIFO_CSR_RU_ATN_LVL_SHIFT)
260#define TEGRA20_SPDIF_DATA_FIFO_CSR_RU_ATN_LVL_RU1_WORD_FULL \
261 (TEGRA20_SPDIF_FIFO_ATN_LVL_U_ONE_SLOT << TEGRA20_SPDIF_DATA_FIFO_CSR_RU_ATN_LVL_SHIFT)
262#define TEGRA20_SPDIF_DATA_FIFO_CSR_RU_ATN_LVL_RU2_WORD_FULL \
263 (TEGRA20_SPDIF_FIFO_ATN_LVL_U_TWO_SLOTS << TEGRA20_SPDIF_DATA_FIFO_CSR_RU_ATN_LVL_SHIFT)
264#define TEGRA20_SPDIF_DATA_FIFO_CSR_RU_ATN_LVL_RU3_WORD_FULL \
265 (TEGRA20_SPDIF_FIFO_ATN_LVL_U_THREE_SLOTS << TEGRA20_SPDIF_DATA_FIFO_CSR_RU_ATN_LVL_SHIFT)
266#define TEGRA20_SPDIF_DATA_FIFO_CSR_RU_ATN_LVL_RU4_WORD_FULL \
267 (TEGRA20_SPDIF_FIFO_ATN_LVL_U_FOUR_SLOTS << TEGRA20_SPDIF_DATA_FIFO_CSR_RU_ATN_LVL_SHIFT)
268
269/* Number of RX USR.FIFO levels with valid data. */
270#define TEGRA20_SPDIF_DATA_FIFO_CSR_RU_FULL_COUNT_SHIFT 24
271#define TEGRA20_SPDIF_DATA_FIFO_CSR_RU_FULL_COUNT_MASK (0x1f << TEGRA20_SPDIF_DATA_FIFO_CSR_RU_FULL_COUNT_SHIFT)
272
273/* Clear Transmitter User FIFO (TX USR.FIFO) */
274#define TEGRA20_SPDIF_DATA_FIFO_CSR_TU_CLR (1 << 23)
275
276/* TU FIFO attention level */
277#define TEGRA20_SPDIF_DATA_FIFO_CSR_TU_ATN_LVL_SHIFT 21
278#define TEGRA20_SPDIF_DATA_FIFO_CSR_TU_ATN_LVL_MASK \
279 (0x3 << TEGRA20_SPDIF_DATA_FIFO_CSR_TU_ATN_LVL_SHIFT)
280#define TEGRA20_SPDIF_DATA_FIFO_CSR_TU_ATN_LVL_TU1_WORD_FULL \
281 (TEGRA20_SPDIF_FIFO_ATN_LVL_U_ONE_SLOT << TEGRA20_SPDIF_DATA_FIFO_CSR_TU_ATN_LVL_SHIFT)
282#define TEGRA20_SPDIF_DATA_FIFO_CSR_TU_ATN_LVL_TU2_WORD_FULL \
283 (TEGRA20_SPDIF_FIFO_ATN_LVL_U_TWO_SLOTS << TEGRA20_SPDIF_DATA_FIFO_CSR_TU_ATN_LVL_SHIFT)
284#define TEGRA20_SPDIF_DATA_FIFO_CSR_TU_ATN_LVL_TU3_WORD_FULL \
285 (TEGRA20_SPDIF_FIFO_ATN_LVL_U_THREE_SLOTS << TEGRA20_SPDIF_DATA_FIFO_CSR_TU_ATN_LVL_SHIFT)
286#define TEGRA20_SPDIF_DATA_FIFO_CSR_TU_ATN_LVL_TU4_WORD_FULL \
287 (TEGRA20_SPDIF_FIFO_ATN_LVL_U_FOUR_SLOTS << TEGRA20_SPDIF_DATA_FIFO_CSR_TU_ATN_LVL_SHIFT)
288
289/* Number of TX USR.FIFO levels that could be filled. */
290#define TEGRA20_SPDIF_DATA_FIFO_CSR_TU_EMPTY_COUNT_SHIFT 16
291#define TEGRA20_SPDIF_DATA_FIFO_CSR_TU_EMPTY_COUNT_MASK (0x1f << SPDIF_DATA_FIFO_CSR_TU_EMPTY_COUNT_SHIFT)
292
293/* Clear Receiver Data FIFO (RX DATA.FIFO) */
294#define TEGRA20_SPDIF_DATA_FIFO_CSR_RX_CLR (1 << 15)
295
296#define TEGRA20_SPDIF_FIFO_ATN_LVL_D_ONE_SLOT 0
297#define TEGRA20_SPDIF_FIFO_ATN_LVL_D_FOUR_SLOTS 1
298#define TEGRA20_SPDIF_FIFO_ATN_LVL_D_EIGHT_SLOTS 2
299#define TEGRA20_SPDIF_FIFO_ATN_LVL_D_TWELVE_SLOTS 3
300
301/* RU FIFO attention level */
302#define TEGRA20_SPDIF_DATA_FIFO_CSR_RX_ATN_LVL_SHIFT 13
303#define TEGRA20_SPDIF_DATA_FIFO_CSR_RX_ATN_LVL_MASK \
304 (0x3 << TEGRA20_SPDIF_DATA_FIFO_CSR_RX_ATN_LVL_SHIFT)
305#define TEGRA20_SPDIF_DATA_FIFO_CSR_RX_ATN_LVL_RU1_WORD_FULL \
306 (TEGRA20_SPDIF_FIFO_ATN_LVL_D_ONE_SLOT << TEGRA20_SPDIF_DATA_FIFO_CSR_RX_ATN_LVL_SHIFT)
307#define TEGRA20_SPDIF_DATA_FIFO_CSR_RX_ATN_LVL_RU4_WORD_FULL \
308 (TEGRA20_SPDIF_FIFO_ATN_LVL_D_FOUR_SLOTS << TEGRA20_SPDIF_DATA_FIFO_CSR_RX_ATN_LVL_SHIFT)
309#define TEGRA20_SPDIF_DATA_FIFO_CSR_RX_ATN_LVL_RU8_WORD_FULL \
310 (TEGRA20_SPDIF_FIFO_ATN_LVL_D_EIGHT_SLOTS << TEGRA20_SPDIF_DATA_FIFO_CSR_RX_ATN_LVL_SHIFT)
311#define TEGRA20_SPDIF_DATA_FIFO_CSR_RX_ATN_LVL_RU12_WORD_FULL \
312 (TEGRA20_SPDIF_FIFO_ATN_LVL_D_TWELVE_SLOTS << TEGRA20_SPDIF_DATA_FIFO_CSR_RX_ATN_LVL_SHIFT)
313
314/* Number of RX DATA.FIFO levels with valid data. */
315#define TEGRA20_SPDIF_DATA_FIFO_CSR_RX_FULL_COUNT_SHIFT 8
316#define TEGRA20_SPDIF_DATA_FIFO_CSR_RX_FULL_COUNT_MASK (0x1f << TEGRA20_SPDIF_DATA_FIFO_CSR_RX_FULL_COUNT_SHIFT)
317
318/* Clear Transmitter Data FIFO (TX DATA.FIFO) */
319#define TEGRA20_SPDIF_DATA_FIFO_CSR_TX_CLR (1 << 7)
320
321/* TU FIFO attention level */
322#define TEGRA20_SPDIF_DATA_FIFO_CSR_TX_ATN_LVL_SHIFT 5
323#define TEGRA20_SPDIF_DATA_FIFO_CSR_TX_ATN_LVL_MASK \
324 (0x3 << TEGRA20_SPDIF_DATA_FIFO_CSR_TX_ATN_LVL_SHIFT)
325#define TEGRA20_SPDIF_DATA_FIFO_CSR_TX_ATN_LVL_TU1_WORD_FULL \
326 (TEGRA20_SPDIF_FIFO_ATN_LVL_D_ONE_SLOT << TEGRA20_SPDIF_DATA_FIFO_CSR_TX_ATN_LVL_SHIFT)
327#define TEGRA20_SPDIF_DATA_FIFO_CSR_TX_ATN_LVL_TU4_WORD_FULL \
328 (TEGRA20_SPDIF_FIFO_ATN_LVL_D_FOUR_SLOTS << TEGRA20_SPDIF_DATA_FIFO_CSR_TX_ATN_LVL_SHIFT)
329#define TEGRA20_SPDIF_DATA_FIFO_CSR_TX_ATN_LVL_TU8_WORD_FULL \
330 (TEGRA20_SPDIF_FIFO_ATN_LVL_D_EIGHT_SLOTS << TEGRA20_SPDIF_DATA_FIFO_CSR_TX_ATN_LVL_SHIFT)
331#define TEGRA20_SPDIF_DATA_FIFO_CSR_TX_ATN_LVL_TU12_WORD_FULL \
332 (TEGRA20_SPDIF_FIFO_ATN_LVL_D_TWELVE_SLOTS << TEGRA20_SPDIF_DATA_FIFO_CSR_TX_ATN_LVL_SHIFT)
333
334/* Number of TX DATA.FIFO levels that could be filled. */
335#define TEGRA20_SPDIF_DATA_FIFO_CSR_TX_EMPTY_COUNT_SHIFT 0
336#define TEGRA20_SPDIF_DATA_FIFO_CSR_TX_EMPTY_COUNT_MASK (0x1f << SPDIF_DATA_FIFO_CSR_TX_EMPTY_COUNT_SHIFT)
337
338/* Fields in TEGRA20_SPDIF_DATA_OUT */
339
340/*
341 * This register has 5 different formats:
342 * 16-bit (BIT_MODE=00, PACK=0)
343 * 20-bit (BIT_MODE=01, PACK=0)
344 * 24-bit (BIT_MODE=10, PACK=0)
345 * raw (BIT_MODE=11, PACK=0)
346 * 16-bit packed (BIT_MODE=00, PACK=1)
347 */
348
349#define TEGRA20_SPDIF_DATA_OUT_DATA_16_SHIFT 0
350#define TEGRA20_SPDIF_DATA_OUT_DATA_16_MASK (0xffff << TEGRA20_SPDIF_DATA_OUT_DATA_16_SHIFT)
351
352#define TEGRA20_SPDIF_DATA_OUT_DATA_20_SHIFT 0
353#define TEGRA20_SPDIF_DATA_OUT_DATA_20_MASK (0xfffff << TEGRA20_SPDIF_DATA_OUT_DATA_20_SHIFT)
354
355#define TEGRA20_SPDIF_DATA_OUT_DATA_24_SHIFT 0
356#define TEGRA20_SPDIF_DATA_OUT_DATA_24_MASK (0xffffff << TEGRA20_SPDIF_DATA_OUT_DATA_24_SHIFT)
357
358#define TEGRA20_SPDIF_DATA_OUT_DATA_RAW_P (1 << 31)
359#define TEGRA20_SPDIF_DATA_OUT_DATA_RAW_C (1 << 30)
360#define TEGRA20_SPDIF_DATA_OUT_DATA_RAW_U (1 << 29)
361#define TEGRA20_SPDIF_DATA_OUT_DATA_RAW_V (1 << 28)
362
363#define TEGRA20_SPDIF_DATA_OUT_DATA_RAW_DATA_SHIFT 8
364#define TEGRA20_SPDIF_DATA_OUT_DATA_RAW_DATA_MASK (0xfffff << TEGRA20_SPDIF_DATA_OUT_DATA_RAW_DATA_SHIFT)
365
366#define TEGRA20_SPDIF_DATA_OUT_DATA_RAW_AUX_SHIFT 4
367#define TEGRA20_SPDIF_DATA_OUT_DATA_RAW_AUX_MASK (0xf << TEGRA20_SPDIF_DATA_OUT_DATA_RAW_AUX_SHIFT)
368
369#define TEGRA20_SPDIF_DATA_OUT_DATA_RAW_PREAMBLE_SHIFT 0
370#define TEGRA20_SPDIF_DATA_OUT_DATA_RAW_PREAMBLE_MASK (0xf << TEGRA20_SPDIF_DATA_OUT_DATA_RAW_PREAMBLE_SHIFT)
371
372#define TEGRA20_SPDIF_DATA_OUT_DATA_16_PACKED_RIGHT_SHIFT 16
373#define TEGRA20_SPDIF_DATA_OUT_DATA_16_PACKED_RIGHT_MASK (0xffff << TEGRA20_SPDIF_DATA_OUT_DATA_16_PACKED_RIGHT_SHIFT)
374
375#define TEGRA20_SPDIF_DATA_OUT_DATA_16_PACKED_LEFT_SHIFT 0
376#define TEGRA20_SPDIF_DATA_OUT_DATA_16_PACKED_LEFT_MASK (0xffff << TEGRA20_SPDIF_DATA_OUT_DATA_16_PACKED_LEFT_SHIFT)
377
378/* Fields in TEGRA20_SPDIF_DATA_IN */
379
380/*
381 * This register has 5 different formats:
382 * 16-bit (BIT_MODE=00, PACK=0)
383 * 20-bit (BIT_MODE=01, PACK=0)
384 * 24-bit (BIT_MODE=10, PACK=0)
385 * raw (BIT_MODE=11, PACK=0)
386 * 16-bit packed (BIT_MODE=00, PACK=1)
387 *
388 * Bits 31:24 are common to all modes except 16-bit packed
389 */
390
391#define TEGRA20_SPDIF_DATA_IN_DATA_P (1 << 31)
392#define TEGRA20_SPDIF_DATA_IN_DATA_C (1 << 30)
393#define TEGRA20_SPDIF_DATA_IN_DATA_U (1 << 29)
394#define TEGRA20_SPDIF_DATA_IN_DATA_V (1 << 28)
395
396#define TEGRA20_SPDIF_DATA_IN_DATA_PREAMBLE_SHIFT 24
397#define TEGRA20_SPDIF_DATA_IN_DATA_PREAMBLE_MASK (0xf << TEGRA20_SPDIF_DATA_IN_DATA_PREAMBLE_SHIFT)
398
399#define TEGRA20_SPDIF_DATA_IN_DATA_16_SHIFT 0
400#define TEGRA20_SPDIF_DATA_IN_DATA_16_MASK (0xffff << TEGRA20_SPDIF_DATA_IN_DATA_16_SHIFT)
401
402#define TEGRA20_SPDIF_DATA_IN_DATA_20_SHIFT 0
403#define TEGRA20_SPDIF_DATA_IN_DATA_20_MASK (0xfffff << TEGRA20_SPDIF_DATA_IN_DATA_20_SHIFT)
404
405#define TEGRA20_SPDIF_DATA_IN_DATA_24_SHIFT 0
406#define TEGRA20_SPDIF_DATA_IN_DATA_24_MASK (0xffffff << TEGRA20_SPDIF_DATA_IN_DATA_24_SHIFT)
407
408#define TEGRA20_SPDIF_DATA_IN_DATA_RAW_DATA_SHIFT 8
409#define TEGRA20_SPDIF_DATA_IN_DATA_RAW_DATA_MASK (0xfffff << TEGRA20_SPDIF_DATA_IN_DATA_RAW_DATA_SHIFT)
410
411#define TEGRA20_SPDIF_DATA_IN_DATA_RAW_AUX_SHIFT 4
412#define TEGRA20_SPDIF_DATA_IN_DATA_RAW_AUX_MASK (0xf << TEGRA20_SPDIF_DATA_IN_DATA_RAW_AUX_SHIFT)
413
414#define TEGRA20_SPDIF_DATA_IN_DATA_RAW_PREAMBLE_SHIFT 0
415#define TEGRA20_SPDIF_DATA_IN_DATA_RAW_PREAMBLE_MASK (0xf << TEGRA20_SPDIF_DATA_IN_DATA_RAW_PREAMBLE_SHIFT)
416
417#define TEGRA20_SPDIF_DATA_IN_DATA_16_PACKED_RIGHT_SHIFT 16
418#define TEGRA20_SPDIF_DATA_IN_DATA_16_PACKED_RIGHT_MASK (0xffff << TEGRA20_SPDIF_DATA_IN_DATA_16_PACKED_RIGHT_SHIFT)
419
420#define TEGRA20_SPDIF_DATA_IN_DATA_16_PACKED_LEFT_SHIFT 0
421#define TEGRA20_SPDIF_DATA_IN_DATA_16_PACKED_LEFT_MASK (0xffff << TEGRA20_SPDIF_DATA_IN_DATA_16_PACKED_LEFT_SHIFT)
422
423/* Fields in TEGRA20_SPDIF_CH_STA_RX_A */
424/* Fields in TEGRA20_SPDIF_CH_STA_RX_B */
425/* Fields in TEGRA20_SPDIF_CH_STA_RX_C */
426/* Fields in TEGRA20_SPDIF_CH_STA_RX_D */
427/* Fields in TEGRA20_SPDIF_CH_STA_RX_E */
428/* Fields in TEGRA20_SPDIF_CH_STA_RX_F */
429
430/*
431 * The 6-word receive channel data page buffer holds a block (192 frames) of
432 * channel status information. The order of receive is from LSB to MSB
433 * bit, and from CH_STA_RX_A to CH_STA_RX_F then back to CH_STA_RX_A.
434 */
435
436/* Fields in TEGRA20_SPDIF_CH_STA_TX_A */
437/* Fields in TEGRA20_SPDIF_CH_STA_TX_B */
438/* Fields in TEGRA20_SPDIF_CH_STA_TX_C */
439/* Fields in TEGRA20_SPDIF_CH_STA_TX_D */
440/* Fields in TEGRA20_SPDIF_CH_STA_TX_E */
441/* Fields in TEGRA20_SPDIF_CH_STA_TX_F */
442
443/*
444 * The 6-word transmit channel data page buffer holds a block (192 frames) of
445 * channel status information. The order of transmission is from LSB to MSB
446 * bit, and from CH_STA_TX_A to CH_STA_TX_F then back to CH_STA_TX_A.
447 */
448
449/* Fields in TEGRA20_SPDIF_USR_STA_RX_A */
450
451/*
452 * This 4-word deep FIFO receives user FIFO field information. The order of
453 * receive is from LSB to MSB bit.
454 */
455
456/* Fields in TEGRA20_SPDIF_USR_DAT_TX_A */
457
458/*
459 * This 4-word deep FIFO transmits user FIFO field information. The order of
460 * transmission is from LSB to MSB bit.
461 */
462
463struct tegra20_spdif {
464 struct clk *clk_spdif_out;
465 struct tegra_pcm_dma_params capture_dma_data;
466 struct tegra_pcm_dma_params playback_dma_data;
467 struct regmap *regmap;
468 u32 reg_ctrl;
469};
470
471#endif
diff --git a/sound/soc/tegra/tegra30_ahub.c b/sound/soc/tegra/tegra30_ahub.c
new file mode 100644
index 000000000000..57cd419f743e
--- /dev/null
+++ b/sound/soc/tegra/tegra30_ahub.c
@@ -0,0 +1,631 @@
1/*
2 * tegra30_ahub.c - Tegra30 AHUB driver
3 *
4 * Copyright (c) 2011,2012, NVIDIA CORPORATION. All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <linux/clk.h>
20#include <linux/device.h>
21#include <linux/io.h>
22#include <linux/module.h>
23#include <linux/of_platform.h>
24#include <linux/platform_device.h>
25#include <linux/pm_runtime.h>
26#include <linux/regmap.h>
27#include <linux/slab.h>
28#include <mach/clk.h>
29#include <mach/dma.h>
30#include <sound/soc.h>
31#include "tegra30_ahub.h"
32
33#define DRV_NAME "tegra30-ahub"
34
35static struct tegra30_ahub *ahub;
36
37static inline void tegra30_apbif_write(u32 reg, u32 val)
38{
39 regmap_write(ahub->regmap_apbif, reg, val);
40}
41
42static inline u32 tegra30_apbif_read(u32 reg)
43{
44 u32 val;
45 regmap_read(ahub->regmap_apbif, reg, &val);
46 return val;
47}
48
49static inline void tegra30_audio_write(u32 reg, u32 val)
50{
51 regmap_write(ahub->regmap_ahub, reg, val);
52}
53
54static int tegra30_ahub_runtime_suspend(struct device *dev)
55{
56 regcache_cache_only(ahub->regmap_apbif, true);
57 regcache_cache_only(ahub->regmap_ahub, true);
58
59 clk_disable(ahub->clk_apbif);
60 clk_disable(ahub->clk_d_audio);
61
62 return 0;
63}
64
65/*
66 * clk_apbif isn't required for an I2S<->I2S configuration where no PCM data
67 * is read from or sent to memory. However, that's not something the rest of
68 * the driver supports right now, so we'll just treat the two clocks as one
69 * for now.
70 *
71 * These functions should not be a plain ref-count. Instead, each active stream
72 * contributes some requirement to the minimum clock rate, so starting or
73 * stopping streams should dynamically adjust the clock as required. However,
74 * this is not yet implemented.
75 */
76static int tegra30_ahub_runtime_resume(struct device *dev)
77{
78 int ret;
79
80 ret = clk_enable(ahub->clk_d_audio);
81 if (ret) {
82 dev_err(dev, "clk_enable d_audio failed: %d\n", ret);
83 return ret;
84 }
85 ret = clk_enable(ahub->clk_apbif);
86 if (ret) {
87 dev_err(dev, "clk_enable apbif failed: %d\n", ret);
88 clk_disable(ahub->clk_d_audio);
89 return ret;
90 }
91
92 regcache_cache_only(ahub->regmap_apbif, false);
93 regcache_cache_only(ahub->regmap_ahub, false);
94
95 return 0;
96}
97
98int tegra30_ahub_allocate_rx_fifo(enum tegra30_ahub_rxcif *rxcif,
99 unsigned long *fiforeg,
100 unsigned long *reqsel)
101{
102 int channel;
103 u32 reg, val;
104
105 channel = find_first_zero_bit(ahub->rx_usage,
106 TEGRA30_AHUB_CHANNEL_CTRL_COUNT);
107 if (channel >= TEGRA30_AHUB_CHANNEL_CTRL_COUNT)
108 return -EBUSY;
109
110 __set_bit(channel, ahub->rx_usage);
111
112 *rxcif = TEGRA30_AHUB_RXCIF_APBIF_RX0 + channel;
113 *fiforeg = ahub->apbif_addr + TEGRA30_AHUB_CHANNEL_RXFIFO +
114 (channel * TEGRA30_AHUB_CHANNEL_RXFIFO_STRIDE);
115 *reqsel = ahub->dma_sel + channel;
116
117 reg = TEGRA30_AHUB_CHANNEL_CTRL +
118 (channel * TEGRA30_AHUB_CHANNEL_CTRL_STRIDE);
119 val = tegra30_apbif_read(reg);
120 val &= ~(TEGRA30_AHUB_CHANNEL_CTRL_RX_THRESHOLD_MASK |
121 TEGRA30_AHUB_CHANNEL_CTRL_RX_PACK_MASK);
122 val |= (7 << TEGRA30_AHUB_CHANNEL_CTRL_RX_THRESHOLD_SHIFT) |
123 TEGRA30_AHUB_CHANNEL_CTRL_RX_PACK_EN |
124 TEGRA30_AHUB_CHANNEL_CTRL_RX_PACK_16;
125 tegra30_apbif_write(reg, val);
126
127 reg = TEGRA30_AHUB_CIF_RX_CTRL +
128 (channel * TEGRA30_AHUB_CIF_RX_CTRL_STRIDE);
129 val = (0 << TEGRA30_AUDIOCIF_CTRL_FIFO_THRESHOLD_SHIFT) |
130 (1 << TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_SHIFT) |
131 (1 << TEGRA30_AUDIOCIF_CTRL_CLIENT_CHANNELS_SHIFT) |
132 TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_16 |
133 TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_16 |
134 TEGRA30_AUDIOCIF_CTRL_DIRECTION_RX;
135 tegra30_apbif_write(reg, val);
136
137 return 0;
138}
139EXPORT_SYMBOL_GPL(tegra30_ahub_allocate_rx_fifo);
140
141int tegra30_ahub_enable_rx_fifo(enum tegra30_ahub_rxcif rxcif)
142{
143 int channel = rxcif - TEGRA30_AHUB_RXCIF_APBIF_RX0;
144 int reg, val;
145
146 reg = TEGRA30_AHUB_CHANNEL_CTRL +
147 (channel * TEGRA30_AHUB_CHANNEL_CTRL_STRIDE);
148 val = tegra30_apbif_read(reg);
149 val |= TEGRA30_AHUB_CHANNEL_CTRL_RX_EN;
150 tegra30_apbif_write(reg, val);
151
152 return 0;
153}
154EXPORT_SYMBOL_GPL(tegra30_ahub_enable_rx_fifo);
155
156int tegra30_ahub_disable_rx_fifo(enum tegra30_ahub_rxcif rxcif)
157{
158 int channel = rxcif - TEGRA30_AHUB_RXCIF_APBIF_RX0;
159 int reg, val;
160
161 reg = TEGRA30_AHUB_CHANNEL_CTRL +
162 (channel * TEGRA30_AHUB_CHANNEL_CTRL_STRIDE);
163 val = tegra30_apbif_read(reg);
164 val &= ~TEGRA30_AHUB_CHANNEL_CTRL_RX_EN;
165 tegra30_apbif_write(reg, val);
166
167 return 0;
168}
169EXPORT_SYMBOL_GPL(tegra30_ahub_disable_rx_fifo);
170
171int tegra30_ahub_free_rx_fifo(enum tegra30_ahub_rxcif rxcif)
172{
173 int channel = rxcif - TEGRA30_AHUB_RXCIF_APBIF_RX0;
174
175 __clear_bit(channel, ahub->rx_usage);
176
177 return 0;
178}
179EXPORT_SYMBOL_GPL(tegra30_ahub_free_rx_fifo);
180
181int tegra30_ahub_allocate_tx_fifo(enum tegra30_ahub_txcif *txcif,
182 unsigned long *fiforeg,
183 unsigned long *reqsel)
184{
185 int channel;
186 u32 reg, val;
187
188 channel = find_first_zero_bit(ahub->tx_usage,
189 TEGRA30_AHUB_CHANNEL_CTRL_COUNT);
190 if (channel >= TEGRA30_AHUB_CHANNEL_CTRL_COUNT)
191 return -EBUSY;
192
193 __set_bit(channel, ahub->tx_usage);
194
195 *txcif = TEGRA30_AHUB_TXCIF_APBIF_TX0 + channel;
196 *fiforeg = ahub->apbif_addr + TEGRA30_AHUB_CHANNEL_TXFIFO +
197 (channel * TEGRA30_AHUB_CHANNEL_TXFIFO_STRIDE);
198 *reqsel = ahub->dma_sel + channel;
199
200 reg = TEGRA30_AHUB_CHANNEL_CTRL +
201 (channel * TEGRA30_AHUB_CHANNEL_CTRL_STRIDE);
202 val = tegra30_apbif_read(reg);
203 val &= ~(TEGRA30_AHUB_CHANNEL_CTRL_TX_THRESHOLD_MASK |
204 TEGRA30_AHUB_CHANNEL_CTRL_TX_PACK_MASK);
205 val |= (7 << TEGRA30_AHUB_CHANNEL_CTRL_TX_THRESHOLD_SHIFT) |
206 TEGRA30_AHUB_CHANNEL_CTRL_TX_PACK_EN |
207 TEGRA30_AHUB_CHANNEL_CTRL_TX_PACK_16;
208 tegra30_apbif_write(reg, val);
209
210 reg = TEGRA30_AHUB_CIF_TX_CTRL +
211 (channel * TEGRA30_AHUB_CIF_TX_CTRL_STRIDE);
212 val = (0 << TEGRA30_AUDIOCIF_CTRL_FIFO_THRESHOLD_SHIFT) |
213 (1 << TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_SHIFT) |
214 (1 << TEGRA30_AUDIOCIF_CTRL_CLIENT_CHANNELS_SHIFT) |
215 TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_16 |
216 TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_16 |
217 TEGRA30_AUDIOCIF_CTRL_DIRECTION_TX;
218 tegra30_apbif_write(reg, val);
219
220 return 0;
221}
222EXPORT_SYMBOL_GPL(tegra30_ahub_allocate_tx_fifo);
223
224int tegra30_ahub_enable_tx_fifo(enum tegra30_ahub_txcif txcif)
225{
226 int channel = txcif - TEGRA30_AHUB_TXCIF_APBIF_TX0;
227 int reg, val;
228
229 reg = TEGRA30_AHUB_CHANNEL_CTRL +
230 (channel * TEGRA30_AHUB_CHANNEL_CTRL_STRIDE);
231 val = tegra30_apbif_read(reg);
232 val |= TEGRA30_AHUB_CHANNEL_CTRL_TX_EN;
233 tegra30_apbif_write(reg, val);
234
235 return 0;
236}
237EXPORT_SYMBOL_GPL(tegra30_ahub_enable_tx_fifo);
238
239int tegra30_ahub_disable_tx_fifo(enum tegra30_ahub_txcif txcif)
240{
241 int channel = txcif - TEGRA30_AHUB_TXCIF_APBIF_TX0;
242 int reg, val;
243
244 reg = TEGRA30_AHUB_CHANNEL_CTRL +
245 (channel * TEGRA30_AHUB_CHANNEL_CTRL_STRIDE);
246 val = tegra30_apbif_read(reg);
247 val &= ~TEGRA30_AHUB_CHANNEL_CTRL_TX_EN;
248 tegra30_apbif_write(reg, val);
249
250 return 0;
251}
252EXPORT_SYMBOL_GPL(tegra30_ahub_disable_tx_fifo);
253
254int tegra30_ahub_free_tx_fifo(enum tegra30_ahub_txcif txcif)
255{
256 int channel = txcif - TEGRA30_AHUB_TXCIF_APBIF_TX0;
257
258 __clear_bit(channel, ahub->tx_usage);
259
260 return 0;
261}
262EXPORT_SYMBOL_GPL(tegra30_ahub_free_tx_fifo);
263
264int tegra30_ahub_set_rx_cif_source(enum tegra30_ahub_rxcif rxcif,
265 enum tegra30_ahub_txcif txcif)
266{
267 int channel = rxcif - TEGRA30_AHUB_RXCIF_APBIF_RX0;
268 int reg;
269
270 reg = TEGRA30_AHUB_AUDIO_RX +
271 (channel * TEGRA30_AHUB_AUDIO_RX_STRIDE);
272 tegra30_audio_write(reg, 1 << txcif);
273
274 return 0;
275}
276EXPORT_SYMBOL_GPL(tegra30_ahub_set_rx_cif_source);
277
278int tegra30_ahub_unset_rx_cif_source(enum tegra30_ahub_rxcif rxcif)
279{
280 int channel = rxcif - TEGRA30_AHUB_RXCIF_APBIF_RX0;
281 int reg;
282
283 reg = TEGRA30_AHUB_AUDIO_RX +
284 (channel * TEGRA30_AHUB_AUDIO_RX_STRIDE);
285 tegra30_audio_write(reg, 0);
286
287 return 0;
288}
289EXPORT_SYMBOL_GPL(tegra30_ahub_unset_rx_cif_source);
290
291static const char * const configlink_clocks[] __devinitconst = {
292 "i2s0",
293 "i2s1",
294 "i2s2",
295 "i2s3",
296 "i2s4",
297 "dam0",
298 "dam1",
299 "dam2",
300 "spdif_in",
301};
302
303struct of_dev_auxdata ahub_auxdata[] __devinitdata = {
304 OF_DEV_AUXDATA("nvidia,tegra30-i2s", 0x70080300, "tegra30-i2s.0", NULL),
305 OF_DEV_AUXDATA("nvidia,tegra30-i2s", 0x70080400, "tegra30-i2s.1", NULL),
306 OF_DEV_AUXDATA("nvidia,tegra30-i2s", 0x70080500, "tegra30-i2s.2", NULL),
307 OF_DEV_AUXDATA("nvidia,tegra30-i2s", 0x70080600, "tegra30-i2s.3", NULL),
308 OF_DEV_AUXDATA("nvidia,tegra30-i2s", 0x70080700, "tegra30-i2s.4", NULL),
309 {}
310};
311
312#define LAST_REG(name) \
313 (TEGRA30_AHUB_##name + \
314 (TEGRA30_AHUB_##name##_STRIDE * TEGRA30_AHUB_##name##_COUNT) - 4)
315
316#define REG_IN_ARRAY(reg, name) \
317 ((reg >= TEGRA30_AHUB_##name) && \
318 (reg <= LAST_REG(name) && \
319 (!((reg - TEGRA30_AHUB_##name) % TEGRA30_AHUB_##name##_STRIDE))))
320
321static bool tegra30_ahub_apbif_wr_rd_reg(struct device *dev, unsigned int reg)
322{
323 switch (reg) {
324 case TEGRA30_AHUB_CONFIG_LINK_CTRL:
325 case TEGRA30_AHUB_MISC_CTRL:
326 case TEGRA30_AHUB_APBDMA_LIVE_STATUS:
327 case TEGRA30_AHUB_I2S_LIVE_STATUS:
328 case TEGRA30_AHUB_SPDIF_LIVE_STATUS:
329 case TEGRA30_AHUB_I2S_INT_MASK:
330 case TEGRA30_AHUB_DAM_INT_MASK:
331 case TEGRA30_AHUB_SPDIF_INT_MASK:
332 case TEGRA30_AHUB_APBIF_INT_MASK:
333 case TEGRA30_AHUB_I2S_INT_STATUS:
334 case TEGRA30_AHUB_DAM_INT_STATUS:
335 case TEGRA30_AHUB_SPDIF_INT_STATUS:
336 case TEGRA30_AHUB_APBIF_INT_STATUS:
337 case TEGRA30_AHUB_I2S_INT_SOURCE:
338 case TEGRA30_AHUB_DAM_INT_SOURCE:
339 case TEGRA30_AHUB_SPDIF_INT_SOURCE:
340 case TEGRA30_AHUB_APBIF_INT_SOURCE:
341 case TEGRA30_AHUB_I2S_INT_SET:
342 case TEGRA30_AHUB_DAM_INT_SET:
343 case TEGRA30_AHUB_SPDIF_INT_SET:
344 case TEGRA30_AHUB_APBIF_INT_SET:
345 return true;
346 default:
347 break;
348 };
349
350 if (REG_IN_ARRAY(reg, CHANNEL_CTRL) ||
351 REG_IN_ARRAY(reg, CHANNEL_CLEAR) ||
352 REG_IN_ARRAY(reg, CHANNEL_STATUS) ||
353 REG_IN_ARRAY(reg, CHANNEL_TXFIFO) ||
354 REG_IN_ARRAY(reg, CHANNEL_RXFIFO) ||
355 REG_IN_ARRAY(reg, CIF_TX_CTRL) ||
356 REG_IN_ARRAY(reg, CIF_RX_CTRL) ||
357 REG_IN_ARRAY(reg, DAM_LIVE_STATUS))
358 return true;
359
360 return false;
361}
362
363static bool tegra30_ahub_apbif_volatile_reg(struct device *dev,
364 unsigned int reg)
365{
366 switch (reg) {
367 case TEGRA30_AHUB_CONFIG_LINK_CTRL:
368 case TEGRA30_AHUB_MISC_CTRL:
369 case TEGRA30_AHUB_APBDMA_LIVE_STATUS:
370 case TEGRA30_AHUB_I2S_LIVE_STATUS:
371 case TEGRA30_AHUB_SPDIF_LIVE_STATUS:
372 case TEGRA30_AHUB_I2S_INT_STATUS:
373 case TEGRA30_AHUB_DAM_INT_STATUS:
374 case TEGRA30_AHUB_SPDIF_INT_STATUS:
375 case TEGRA30_AHUB_APBIF_INT_STATUS:
376 case TEGRA30_AHUB_I2S_INT_SET:
377 case TEGRA30_AHUB_DAM_INT_SET:
378 case TEGRA30_AHUB_SPDIF_INT_SET:
379 case TEGRA30_AHUB_APBIF_INT_SET:
380 return true;
381 default:
382 break;
383 };
384
385 if (REG_IN_ARRAY(reg, CHANNEL_CLEAR) ||
386 REG_IN_ARRAY(reg, CHANNEL_STATUS) ||
387 REG_IN_ARRAY(reg, CHANNEL_TXFIFO) ||
388 REG_IN_ARRAY(reg, CHANNEL_RXFIFO) ||
389 REG_IN_ARRAY(reg, DAM_LIVE_STATUS))
390 return true;
391
392 return false;
393}
394
395static bool tegra30_ahub_apbif_precious_reg(struct device *dev,
396 unsigned int reg)
397{
398 if (REG_IN_ARRAY(reg, CHANNEL_TXFIFO) ||
399 REG_IN_ARRAY(reg, CHANNEL_RXFIFO))
400 return true;
401
402 return false;
403}
404
405static const struct regmap_config tegra30_ahub_apbif_regmap_config = {
406 .name = "apbif",
407 .reg_bits = 32,
408 .val_bits = 32,
409 .reg_stride = 4,
410 .max_register = TEGRA30_AHUB_APBIF_INT_SET,
411 .writeable_reg = tegra30_ahub_apbif_wr_rd_reg,
412 .readable_reg = tegra30_ahub_apbif_wr_rd_reg,
413 .volatile_reg = tegra30_ahub_apbif_volatile_reg,
414 .precious_reg = tegra30_ahub_apbif_precious_reg,
415 .cache_type = REGCACHE_RBTREE,
416};
417
418static bool tegra30_ahub_ahub_wr_rd_reg(struct device *dev, unsigned int reg)
419{
420 if (REG_IN_ARRAY(reg, AUDIO_RX))
421 return true;
422
423 return false;
424}
425
426static const struct regmap_config tegra30_ahub_ahub_regmap_config = {
427 .name = "ahub",
428 .reg_bits = 32,
429 .val_bits = 32,
430 .reg_stride = 4,
431 .max_register = LAST_REG(AUDIO_RX),
432 .writeable_reg = tegra30_ahub_ahub_wr_rd_reg,
433 .readable_reg = tegra30_ahub_ahub_wr_rd_reg,
434 .cache_type = REGCACHE_RBTREE,
435};
436
437static int __devinit tegra30_ahub_probe(struct platform_device *pdev)
438{
439 struct clk *clk;
440 int i;
441 struct resource *res0, *res1, *region;
442 u32 of_dma[2];
443 void __iomem *regs_apbif, *regs_ahub;
444 int ret = 0;
445
446 if (ahub)
447 return -ENODEV;
448
449 /*
450 * The AHUB hosts a register bus: the "configlink". For this to
451 * operate correctly, all devices on this bus must be out of reset.
452 * Ensure that here.
453 */
454 for (i = 0; i < ARRAY_SIZE(configlink_clocks); i++) {
455 clk = clk_get_sys(NULL, configlink_clocks[i]);
456 if (IS_ERR(clk)) {
457 dev_err(&pdev->dev, "Can't get clock %s\n",
458 configlink_clocks[i]);
459 ret = PTR_ERR(clk);
460 goto err;
461 }
462 tegra_periph_reset_deassert(clk);
463 clk_put(clk);
464 }
465
466 ahub = devm_kzalloc(&pdev->dev, sizeof(struct tegra30_ahub),
467 GFP_KERNEL);
468 if (!ahub) {
469 dev_err(&pdev->dev, "Can't allocate tegra30_ahub\n");
470 ret = -ENOMEM;
471 goto err;
472 }
473 dev_set_drvdata(&pdev->dev, ahub);
474
475 ahub->dev = &pdev->dev;
476
477 ahub->clk_d_audio = clk_get(&pdev->dev, "d_audio");
478 if (IS_ERR(ahub->clk_d_audio)) {
479 dev_err(&pdev->dev, "Can't retrieve ahub d_audio clock\n");
480 ret = PTR_ERR(ahub->clk_d_audio);
481 goto err;
482 }
483
484 ahub->clk_apbif = clk_get(&pdev->dev, "apbif");
485 if (IS_ERR(ahub->clk_apbif)) {
486 dev_err(&pdev->dev, "Can't retrieve ahub apbif clock\n");
487 ret = PTR_ERR(ahub->clk_apbif);
488 goto err_clk_put_d_audio;
489 }
490
491 if (of_property_read_u32_array(pdev->dev.of_node,
492 "nvidia,dma-request-selector",
493 of_dma, 2) < 0) {
494 dev_err(&pdev->dev,
495 "Missing property nvidia,dma-request-selector\n");
496 ret = -ENODEV;
497 goto err_clk_put_d_audio;
498 }
499 ahub->dma_sel = of_dma[1];
500
501 res0 = platform_get_resource(pdev, IORESOURCE_MEM, 0);
502 if (!res0) {
503 dev_err(&pdev->dev, "No apbif memory resource\n");
504 ret = -ENODEV;
505 goto err_clk_put_apbif;
506 }
507
508 region = devm_request_mem_region(&pdev->dev, res0->start,
509 resource_size(res0), DRV_NAME);
510 if (!region) {
511 dev_err(&pdev->dev, "request region apbif failed\n");
512 ret = -EBUSY;
513 goto err_clk_put_apbif;
514 }
515 ahub->apbif_addr = res0->start;
516
517 regs_apbif = devm_ioremap(&pdev->dev, res0->start,
518 resource_size(res0));
519 if (!regs_apbif) {
520 dev_err(&pdev->dev, "ioremap apbif failed\n");
521 ret = -ENOMEM;
522 goto err_clk_put_apbif;
523 }
524
525 ahub->regmap_apbif = devm_regmap_init_mmio(&pdev->dev, regs_apbif,
526 &tegra30_ahub_apbif_regmap_config);
527 if (IS_ERR(ahub->regmap_apbif)) {
528 dev_err(&pdev->dev, "apbif regmap init failed\n");
529 ret = PTR_ERR(ahub->regmap_apbif);
530 goto err_clk_put_apbif;
531 }
532 regcache_cache_only(ahub->regmap_apbif, true);
533
534 res1 = platform_get_resource(pdev, IORESOURCE_MEM, 1);
535 if (!res1) {
536 dev_err(&pdev->dev, "No ahub memory resource\n");
537 ret = -ENODEV;
538 goto err_clk_put_apbif;
539 }
540
541 region = devm_request_mem_region(&pdev->dev, res1->start,
542 resource_size(res1), DRV_NAME);
543 if (!region) {
544 dev_err(&pdev->dev, "request region ahub failed\n");
545 ret = -EBUSY;
546 goto err_clk_put_apbif;
547 }
548
549 regs_ahub = devm_ioremap(&pdev->dev, res1->start,
550 resource_size(res1));
551 if (!regs_ahub) {
552 dev_err(&pdev->dev, "ioremap ahub failed\n");
553 ret = -ENOMEM;
554 goto err_clk_put_apbif;
555 }
556
557 ahub->regmap_ahub = devm_regmap_init_mmio(&pdev->dev, regs_ahub,
558 &tegra30_ahub_ahub_regmap_config);
559 if (IS_ERR(ahub->regmap_ahub)) {
560 dev_err(&pdev->dev, "ahub regmap init failed\n");
561 ret = PTR_ERR(ahub->regmap_ahub);
562 goto err_clk_put_apbif;
563 }
564 regcache_cache_only(ahub->regmap_ahub, true);
565
566 pm_runtime_enable(&pdev->dev);
567 if (!pm_runtime_enabled(&pdev->dev)) {
568 ret = tegra30_ahub_runtime_resume(&pdev->dev);
569 if (ret)
570 goto err_pm_disable;
571 }
572
573 of_platform_populate(pdev->dev.of_node, NULL, ahub_auxdata,
574 &pdev->dev);
575
576 return 0;
577
578err_pm_disable:
579 pm_runtime_disable(&pdev->dev);
580err_clk_put_apbif:
581 clk_put(ahub->clk_apbif);
582err_clk_put_d_audio:
583 clk_put(ahub->clk_d_audio);
584 ahub = 0;
585err:
586 return ret;
587}
588
589static int __devexit tegra30_ahub_remove(struct platform_device *pdev)
590{
591 if (!ahub)
592 return -ENODEV;
593
594 pm_runtime_disable(&pdev->dev);
595 if (!pm_runtime_status_suspended(&pdev->dev))
596 tegra30_ahub_runtime_suspend(&pdev->dev);
597
598 clk_put(ahub->clk_apbif);
599 clk_put(ahub->clk_d_audio);
600
601 ahub = 0;
602
603 return 0;
604}
605
606static const struct of_device_id tegra30_ahub_of_match[] __devinitconst = {
607 { .compatible = "nvidia,tegra30-ahub", },
608 {},
609};
610
611static const struct dev_pm_ops tegra30_ahub_pm_ops __devinitconst = {
612 SET_RUNTIME_PM_OPS(tegra30_ahub_runtime_suspend,
613 tegra30_ahub_runtime_resume, NULL)
614};
615
616static struct platform_driver tegra30_ahub_driver = {
617 .probe = tegra30_ahub_probe,
618 .remove = __devexit_p(tegra30_ahub_remove),
619 .driver = {
620 .name = DRV_NAME,
621 .owner = THIS_MODULE,
622 .of_match_table = tegra30_ahub_of_match,
623 .pm = &tegra30_ahub_pm_ops,
624 },
625};
626module_platform_driver(tegra30_ahub_driver);
627
628MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>");
629MODULE_DESCRIPTION("Tegra30 AHUB driver");
630MODULE_LICENSE("GPL v2");
631MODULE_ALIAS("platform:" DRV_NAME);
diff --git a/sound/soc/tegra/tegra30_ahub.h b/sound/soc/tegra/tegra30_ahub.h
new file mode 100644
index 000000000000..e690e2eecc92
--- /dev/null
+++ b/sound/soc/tegra/tegra30_ahub.h
@@ -0,0 +1,483 @@
1/*
2 * tegra30_ahub.h - Definitions for Tegra30 AHUB driver
3 *
4 * Copyright (c) 2011,2012, NVIDIA CORPORATION. All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef __TEGRA30_AHUB_H__
20#define __TEGRA30_AHUB_H__
21
22/* Fields in *_CIF_RX/TX_CTRL; used by AHUB FIFOs, and all other audio modules */
23
24#define TEGRA30_AUDIOCIF_CTRL_FIFO_THRESHOLD_SHIFT 28
25#define TEGRA30_AUDIOCIF_CTRL_FIFO_THRESHOLD_MASK_US 0xf
26#define TEGRA30_AUDIOCIF_CTRL_FIFO_THRESHOLD_MASK (TEGRA30_AUDIOCIF_CTRL_FIFO_THRESHOLD_MASK_US << TEGRA30_AUDIOCIF_CTRL_FIFO_THRESHOLD_SHIFT)
27
28/* Channel count minus 1 */
29#define TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_SHIFT 24
30#define TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_MASK_US 7
31#define TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_MASK (TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_MASK_US << TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_SHIFT)
32
33/* Channel count minus 1 */
34#define TEGRA30_AUDIOCIF_CTRL_CLIENT_CHANNELS_SHIFT 16
35#define TEGRA30_AUDIOCIF_CTRL_CLIENT_CHANNELS_MASK_US 7
36#define TEGRA30_AUDIOCIF_CTRL_CLIENT_CHANNELS_MASK (TEGRA30_AUDIOCIF_CTRL_CLIENT_CHANNELS_MASK_US << TEGRA30_AUDIOCIF_CTRL_CLIENT_CHANNELS_SHIFT)
37
38#define TEGRA30_AUDIOCIF_BITS_4 0
39#define TEGRA30_AUDIOCIF_BITS_8 1
40#define TEGRA30_AUDIOCIF_BITS_12 2
41#define TEGRA30_AUDIOCIF_BITS_16 3
42#define TEGRA30_AUDIOCIF_BITS_20 4
43#define TEGRA30_AUDIOCIF_BITS_24 5
44#define TEGRA30_AUDIOCIF_BITS_28 6
45#define TEGRA30_AUDIOCIF_BITS_32 7
46
47#define TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_SHIFT 12
48#define TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_MASK (7 << TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_SHIFT)
49#define TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_4 (TEGRA30_AUDIOCIF_BITS_4 << TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_SHIFT)
50#define TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_8 (TEGRA30_AUDIOCIF_BITS_8 << TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_SHIFT)
51#define TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_12 (TEGRA30_AUDIOCIF_BITS_12 << TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_SHIFT)
52#define TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_16 (TEGRA30_AUDIOCIF_BITS_16 << TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_SHIFT)
53#define TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_20 (TEGRA30_AUDIOCIF_BITS_20 << TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_SHIFT)
54#define TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_24 (TEGRA30_AUDIOCIF_BITS_24 << TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_SHIFT)
55#define TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_28 (TEGRA30_AUDIOCIF_BITS_28 << TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_SHIFT)
56#define TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_32 (TEGRA30_AUDIOCIF_BITS_32 << TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_SHIFT)
57
58#define TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_SHIFT 8
59#define TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_MASK (7 << TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_SHIFT)
60#define TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_4 (TEGRA30_AUDIOCIF_BITS_4 << TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_SHIFT)
61#define TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_8 (TEGRA30_AUDIOCIF_BITS_8 << TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_SHIFT)
62#define TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_12 (TEGRA30_AUDIOCIF_BITS_12 << TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_SHIFT)
63#define TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_16 (TEGRA30_AUDIOCIF_BITS_16 << TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_SHIFT)
64#define TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_20 (TEGRA30_AUDIOCIF_BITS_20 << TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_SHIFT)
65#define TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_24 (TEGRA30_AUDIOCIF_BITS_24 << TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_SHIFT)
66#define TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_28 (TEGRA30_AUDIOCIF_BITS_28 << TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_SHIFT)
67#define TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_32 (TEGRA30_AUDIOCIF_BITS_32 << TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_SHIFT)
68
69#define TEGRA30_AUDIOCIF_EXPAND_ZERO 0
70#define TEGRA30_AUDIOCIF_EXPAND_ONE 1
71#define TEGRA30_AUDIOCIF_EXPAND_LFSR 2
72
73#define TEGRA30_AUDIOCIF_CTRL_EXPAND_SHIFT 6
74#define TEGRA30_AUDIOCIF_CTRL_EXPAND_MASK (3 << TEGRA30_AUDIOCIF_CTRL_EXPAND_SHIFT)
75#define TEGRA30_AUDIOCIF_CTRL_EXPAND_ZERO (TEGRA30_AUDIOCIF_EXPAND_ZERO << TEGRA30_AUDIOCIF_CTRL_EXPAND_SHIFT)
76#define TEGRA30_AUDIOCIF_CTRL_EXPAND_ONE (TEGRA30_AUDIOCIF_EXPAND_ONE << TEGRA30_AUDIOCIF_CTRL_EXPAND_SHIFT)
77#define TEGRA30_AUDIOCIF_CTRL_EXPAND_LFSR (TEGRA30_AUDIOCIF_EXPAND_LFSR << TEGRA30_AUDIOCIF_CTRL_EXPAND_SHIFT)
78
79#define TEGRA30_AUDIOCIF_STEREO_CONV_CH0 0
80#define TEGRA30_AUDIOCIF_STEREO_CONV_CH1 1
81#define TEGRA30_AUDIOCIF_STEREO_CONV_AVG 2
82
83#define TEGRA30_AUDIOCIF_CTRL_STEREO_CONV_SHIFT 4
84#define TEGRA30_AUDIOCIF_CTRL_STEREO_CONV_MASK (3 << TEGRA30_AUDIOCIF_CTRL_STEREO_CONV_SHIFT)
85#define TEGRA30_AUDIOCIF_CTRL_STEREO_CONV_CH0 (TEGRA30_AUDIOCIF_STEREO_CONV_CH0 << TEGRA30_AUDIOCIF_CTRL_STEREO_CONV_SHIFT)
86#define TEGRA30_AUDIOCIF_CTRL_STEREO_CONV_CH1 (TEGRA30_AUDIOCIF_STEREO_CONV_CH1 << TEGRA30_AUDIOCIF_CTRL_STEREO_CONV_SHIFT)
87#define TEGRA30_AUDIOCIF_CTRL_STEREO_CONV_AVG (TEGRA30_AUDIOCIF_STEREO_CONV_AVG << TEGRA30_AUDIOCIF_CTRL_STEREO_CONV_SHIFT)
88
89#define TEGRA30_AUDIOCIF_CTRL_REPLICATE 3
90
91#define TEGRA30_AUDIOCIF_DIRECTION_TX 0
92#define TEGRA30_AUDIOCIF_DIRECTION_RX 1
93
94#define TEGRA30_AUDIOCIF_CTRL_DIRECTION_SHIFT 2
95#define TEGRA30_AUDIOCIF_CTRL_DIRECTION_MASK (1 << TEGRA30_AUDIOCIF_CTRL_DIRECTION_SHIFT)
96#define TEGRA30_AUDIOCIF_CTRL_DIRECTION_TX (TEGRA30_AUDIOCIF_DIRECTION_TX << TEGRA30_AUDIOCIF_CTRL_DIRECTION_SHIFT)
97#define TEGRA30_AUDIOCIF_CTRL_DIRECTION_RX (TEGRA30_AUDIOCIF_DIRECTION_RX << TEGRA30_AUDIOCIF_CTRL_DIRECTION_SHIFT)
98
99#define TEGRA30_AUDIOCIF_TRUNCATE_ROUND 0
100#define TEGRA30_AUDIOCIF_TRUNCATE_CHOP 1
101
102#define TEGRA30_AUDIOCIF_CTRL_TRUNCATE_SHIFT 1
103#define TEGRA30_AUDIOCIF_CTRL_TRUNCATE_MASK (1 << TEGRA30_AUDIOCIF_CTRL_TRUNCATE_SHIFT)
104#define TEGRA30_AUDIOCIF_CTRL_TRUNCATE_ROUND (TEGRA30_AUDIOCIF_TRUNCATE_ROUND << TEGRA30_AUDIOCIF_CTRL_TRUNCATE_SHIFT)
105#define TEGRA30_AUDIOCIF_CTRL_TRUNCATE_CHOP (TEGRA30_AUDIOCIF_TRUNCATE_CHOP << TEGRA30_AUDIOCIF_CTRL_TRUNCATE_SHIFT)
106
107#define TEGRA30_AUDIOCIF_MONO_CONV_ZERO 0
108#define TEGRA30_AUDIOCIF_MONO_CONV_COPY 1
109
110#define TEGRA30_AUDIOCIF_CTRL_MONO_CONV_SHIFT 0
111#define TEGRA30_AUDIOCIF_CTRL_MONO_CONV_MASK (1 << TEGRA30_AUDIOCIF_CTRL_MONO_CONV_SHIFT)
112#define TEGRA30_AUDIOCIF_CTRL_MONO_CONV_ZERO (TEGRA30_AUDIOCIF_MONO_CONV_ZERO << TEGRA30_AUDIOCIF_CTRL_MONO_CONV_SHIFT)
113#define TEGRA30_AUDIOCIF_CTRL_MONO_CONV_COPY (TEGRA30_AUDIOCIF_MONO_CONV_COPY << TEGRA30_AUDIOCIF_CTRL_MONO_CONV_SHIFT)
114
115/* Registers within TEGRA30_AUDIO_CLUSTER_BASE */
116
117/* TEGRA30_AHUB_CHANNEL_CTRL */
118
119#define TEGRA30_AHUB_CHANNEL_CTRL 0x0
120#define TEGRA30_AHUB_CHANNEL_CTRL_STRIDE 0x20
121#define TEGRA30_AHUB_CHANNEL_CTRL_COUNT 4
122#define TEGRA30_AHUB_CHANNEL_CTRL_TX_EN (1 << 31)
123#define TEGRA30_AHUB_CHANNEL_CTRL_RX_EN (1 << 30)
124#define TEGRA30_AHUB_CHANNEL_CTRL_LOOPBACK (1 << 29)
125
126#define TEGRA30_AHUB_CHANNEL_CTRL_TX_THRESHOLD_SHIFT 16
127#define TEGRA30_AHUB_CHANNEL_CTRL_TX_THRESHOLD_MASK_US 0xff
128#define TEGRA30_AHUB_CHANNEL_CTRL_TX_THRESHOLD_MASK (TEGRA30_AHUB_CHANNEL_CTRL_TX_THRESHOLD_MASK_US << TEGRA30_AHUB_CHANNEL_CTRL_TX_THRESHOLD_SHIFT)
129
130#define TEGRA30_AHUB_CHANNEL_CTRL_RX_THRESHOLD_SHIFT 8
131#define TEGRA30_AHUB_CHANNEL_CTRL_RX_THRESHOLD_MASK_US 0xff
132#define TEGRA30_AHUB_CHANNEL_CTRL_RX_THRESHOLD_MASK (TEGRA30_AHUB_CHANNEL_CTRL_RX_THRESHOLD_MASK_US << TEGRA30_AHUB_CHANNEL_CTRL_RX_THRESHOLD_SHIFT)
133
134#define TEGRA30_AHUB_CHANNEL_CTRL_TX_PACK_EN (1 << 6)
135
136#define TEGRA30_PACK_8_4 2
137#define TEGRA30_PACK_16 3
138
139#define TEGRA30_AHUB_CHANNEL_CTRL_TX_PACK_SHIFT 4
140#define TEGRA30_AHUB_CHANNEL_CTRL_TX_PACK_MASK_US 3
141#define TEGRA30_AHUB_CHANNEL_CTRL_TX_PACK_MASK (TEGRA30_AHUB_CHANNEL_CTRL_TX_PACK_MASK_US << TEGRA30_AHUB_CHANNEL_CTRL_TX_PACK_SHIFT)
142#define TEGRA30_AHUB_CHANNEL_CTRL_TX_PACK_8_4 (TEGRA30_PACK_8_4 << TEGRA30_AHUB_CHANNEL_CTRL_TX_PACK_SHIFT)
143#define TEGRA30_AHUB_CHANNEL_CTRL_TX_PACK_16 (TEGRA30_PACK_16 << TEGRA30_AHUB_CHANNEL_CTRL_TX_PACK_SHIFT)
144
145#define TEGRA30_AHUB_CHANNEL_CTRL_RX_PACK_EN (1 << 2)
146
147#define TEGRA30_AHUB_CHANNEL_CTRL_RX_PACK_SHIFT 0
148#define TEGRA30_AHUB_CHANNEL_CTRL_RX_PACK_MASK_US 3
149#define TEGRA30_AHUB_CHANNEL_CTRL_RX_PACK_MASK (TEGRA30_AHUB_CHANNEL_CTRL_RX_PACK_MASK_US << TEGRA30_AHUB_CHANNEL_CTRL_RX_PACK_SHIFT)
150#define TEGRA30_AHUB_CHANNEL_CTRL_RX_PACK_8_4 (TEGRA30_PACK_8_4 << TEGRA30_AHUB_CHANNEL_CTRL_RX_PACK_SHIFT)
151#define TEGRA30_AHUB_CHANNEL_CTRL_RX_PACK_16 (TEGRA30_PACK_16 << TEGRA30_AHUB_CHANNEL_CTRL_RX_PACK_SHIFT)
152
153/* TEGRA30_AHUB_CHANNEL_CLEAR */
154
155#define TEGRA30_AHUB_CHANNEL_CLEAR 0x4
156#define TEGRA30_AHUB_CHANNEL_CLEAR_STRIDE 0x20
157#define TEGRA30_AHUB_CHANNEL_CLEAR_COUNT 4
158#define TEGRA30_AHUB_CHANNEL_CLEAR_TX_SOFT_RESET (1 << 31)
159#define TEGRA30_AHUB_CHANNEL_CLEAR_RX_SOFT_RESET (1 << 30)
160
161/* TEGRA30_AHUB_CHANNEL_STATUS */
162
163#define TEGRA30_AHUB_CHANNEL_STATUS 0x8
164#define TEGRA30_AHUB_CHANNEL_STATUS_STRIDE 0x20
165#define TEGRA30_AHUB_CHANNEL_STATUS_COUNT 4
166#define TEGRA30_AHUB_CHANNEL_STATUS_TX_FREE_SHIFT 24
167#define TEGRA30_AHUB_CHANNEL_STATUS_TX_FREE_MASK_US 0xff
168#define TEGRA30_AHUB_CHANNEL_STATUS_TX_FREE_MASK (TEGRA30_AHUB_CHANNEL_STATUS_TX_FREE_MASK_US << TEGRA30_AHUB_CHANNEL_STATUS_TX_FREE_SHIFT)
169#define TEGRA30_AHUB_CHANNEL_STATUS_RX_FREE_SHIFT 16
170#define TEGRA30_AHUB_CHANNEL_STATUS_RX_FREE_MASK_US 0xff
171#define TEGRA30_AHUB_CHANNEL_STATUS_RX_FREE_MASK (TEGRA30_AHUB_CHANNEL_STATUS_RX_FREE_MASK_US << TEGRA30_AHUB_CHANNEL_STATUS_RX_FREE_SHIFT)
172#define TEGRA30_AHUB_CHANNEL_STATUS_TX_TRIG (1 << 1)
173#define TEGRA30_AHUB_CHANNEL_STATUS_RX_TRIG (1 << 0)
174
175/* TEGRA30_AHUB_CHANNEL_TXFIFO */
176
177#define TEGRA30_AHUB_CHANNEL_TXFIFO 0xc
178#define TEGRA30_AHUB_CHANNEL_TXFIFO_STRIDE 0x20
179#define TEGRA30_AHUB_CHANNEL_TXFIFO_COUNT 4
180
181/* TEGRA30_AHUB_CHANNEL_RXFIFO */
182
183#define TEGRA30_AHUB_CHANNEL_RXFIFO 0x10
184#define TEGRA30_AHUB_CHANNEL_RXFIFO_STRIDE 0x20
185#define TEGRA30_AHUB_CHANNEL_RXFIFO_COUNT 4
186
187/* TEGRA30_AHUB_CIF_TX_CTRL */
188
189#define TEGRA30_AHUB_CIF_TX_CTRL 0x14
190#define TEGRA30_AHUB_CIF_TX_CTRL_STRIDE 0x20
191#define TEGRA30_AHUB_CIF_TX_CTRL_COUNT 4
192/* Uses field from TEGRA30_AUDIOCIF_CTRL_* */
193
194/* TEGRA30_AHUB_CIF_RX_CTRL */
195
196#define TEGRA30_AHUB_CIF_RX_CTRL 0x18
197#define TEGRA30_AHUB_CIF_RX_CTRL_STRIDE 0x20
198#define TEGRA30_AHUB_CIF_RX_CTRL_COUNT 4
199/* Uses field from TEGRA30_AUDIOCIF_CTRL_* */
200
201/* TEGRA30_AHUB_CONFIG_LINK_CTRL */
202
203#define TEGRA30_AHUB_CONFIG_LINK_CTRL 0x80
204#define TEGRA30_AHUB_CONFIG_LINK_CTRL_MASTER_FIFO_FULL_CNT_SHIFT 28
205#define TEGRA30_AHUB_CONFIG_LINK_CTRL_MASTER_FIFO_FULL_CNT_MASK_US 0xf
206#define TEGRA30_AHUB_CONFIG_LINK_CTRL_MASTER_FIFO_FULL_CNT_MASK (TEGRA30_AHUB_CONFIG_LINK_CTRL_MASTER_FIFO_FULL_CNT_MASK_US << TEGRA30_AHUB_CONFIG_LINK_CTRL_MASTER_FIFO_FULL_CNT_SHIFT)
207#define TEGRA30_AHUB_CONFIG_LINK_CTRL_TIMEOUT_CNT_SHIFT 16
208#define TEGRA30_AHUB_CONFIG_LINK_CTRL_TIMEOUT_CNT_MASK_US 0xfff
209#define TEGRA30_AHUB_CONFIG_LINK_CTRL_TIMEOUT_CNT_MASK (TEGRA30_AHUB_CONFIG_LINK_CTRL_TIMEOUT_CNT_MASK_US << TEGRA30_AHUB_CONFIG_LINK_CTRL_TIMEOUT_CNT_SHIFT)
210#define TEGRA30_AHUB_CONFIG_LINK_CTRL_IDLE_CNT_SHIFT 4
211#define TEGRA30_AHUB_CONFIG_LINK_CTRL_IDLE_CNT_MASK_US 0xfff
212#define TEGRA30_AHUB_CONFIG_LINK_CTRL_IDLE_CNT_MASK (TEGRA30_AHUB_CONFIG_LINK_CTRL_IDLE_CNT_MASK_US << TEGRA30_AHUB_CONFIG_LINK_CTRL_IDLE_CNT_SHIFT)
213#define TEGRA30_AHUB_CONFIG_LINK_CTRL_CG_EN (1 << 2)
214#define TEGRA30_AHUB_CONFIG_LINK_CTRL_CLEAR_TIMEOUT_CNTR (1 << 1)
215#define TEGRA30_AHUB_CONFIG_LINK_CTRL_SOFT_RESET (1 << 0)
216
217/* TEGRA30_AHUB_MISC_CTRL */
218
219#define TEGRA30_AHUB_MISC_CTRL 0x84
220#define TEGRA30_AHUB_MISC_CTRL_AUDIO_ACTIVE (1 << 31)
221#define TEGRA30_AHUB_MISC_CTRL_AUDIO_CG_EN (1 << 8)
222#define TEGRA30_AHUB_MISC_CTRL_AUDIO_OBS_SEL_SHIFT 0
223#define TEGRA30_AHUB_MISC_CTRL_AUDIO_OBS_SEL_MASK (0x1f << TEGRA30_AHUB_MISC_CTRL_AUDIO_OBS_SEL_SHIFT)
224
225/* TEGRA30_AHUB_APBDMA_LIVE_STATUS */
226
227#define TEGRA30_AHUB_APBDMA_LIVE_STATUS 0x88
228#define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH3_RX_CIF_FIFO_FULL (1 << 31)
229#define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH3_TX_CIF_FIFO_FULL (1 << 30)
230#define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH2_RX_CIF_FIFO_FULL (1 << 29)
231#define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH2_TX_CIF_FIFO_FULL (1 << 28)
232#define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH1_RX_CIF_FIFO_FULL (1 << 27)
233#define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH1_TX_CIF_FIFO_FULL (1 << 26)
234#define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH0_RX_CIF_FIFO_FULL (1 << 25)
235#define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH0_TX_CIF_FIFO_FULL (1 << 24)
236#define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH3_RX_CIF_FIFO_EMPTY (1 << 23)
237#define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH3_TX_CIF_FIFO_EMPTY (1 << 22)
238#define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH2_RX_CIF_FIFO_EMPTY (1 << 21)
239#define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH2_TX_CIF_FIFO_EMPTY (1 << 20)
240#define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH1_RX_CIF_FIFO_EMPTY (1 << 19)
241#define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH1_TX_CIF_FIFO_EMPTY (1 << 18)
242#define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH0_RX_CIF_FIFO_EMPTY (1 << 17)
243#define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH0_TX_CIF_FIFO_EMPTY (1 << 16)
244#define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH3_RX_DMA_FIFO_FULL (1 << 15)
245#define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH3_TX_DMA_FIFO_FULL (1 << 14)
246#define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH2_RX_DMA_FIFO_FULL (1 << 13)
247#define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH2_TX_DMA_FIFO_FULL (1 << 12)
248#define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH1_RX_DMA_FIFO_FULL (1 << 11)
249#define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH1_TX_DMA_FIFO_FULL (1 << 10)
250#define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH0_RX_DMA_FIFO_FULL (1 << 9)
251#define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH0_TX_DMA_FIFO_FULL (1 << 8)
252#define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH3_RX_DMA_FIFO_EMPTY (1 << 7)
253#define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH3_TX_DMA_FIFO_EMPTY (1 << 6)
254#define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH2_RX_DMA_FIFO_EMPTY (1 << 5)
255#define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH2_TX_DMA_FIFO_EMPTY (1 << 4)
256#define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH1_RX_DMA_FIFO_EMPTY (1 << 3)
257#define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH1_TX_DMA_FIFO_EMPTY (1 << 2)
258#define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH0_RX_DMA_FIFO_EMPTY (1 << 1)
259#define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH0_TX_DMA_FIFO_EMPTY (1 << 0)
260
261/* TEGRA30_AHUB_I2S_LIVE_STATUS */
262
263#define TEGRA30_AHUB_I2S_LIVE_STATUS 0x8c
264#define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S4_RX_FIFO_FULL (1 << 29)
265#define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S4_TX_FIFO_FULL (1 << 28)
266#define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S3_RX_FIFO_FULL (1 << 27)
267#define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S3_TX_FIFO_FULL (1 << 26)
268#define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S2_RX_FIFO_FULL (1 << 25)
269#define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S2_TX_FIFO_FULL (1 << 24)
270#define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S1_RX_FIFO_FULL (1 << 23)
271#define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S1_TX_FIFO_FULL (1 << 22)
272#define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S0_RX_FIFO_FULL (1 << 21)
273#define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S0_TX_FIFO_FULL (1 << 20)
274#define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S4_RX_FIFO_ENABLED (1 << 19)
275#define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S4_TX_FIFO_ENABLED (1 << 18)
276#define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S3_RX_FIFO_ENABLED (1 << 17)
277#define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S3_TX_FIFO_ENABLED (1 << 16)
278#define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S2_RX_FIFO_ENABLED (1 << 15)
279#define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S2_TX_FIFO_ENABLED (1 << 14)
280#define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S1_RX_FIFO_ENABLED (1 << 13)
281#define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S1_TX_FIFO_ENABLED (1 << 12)
282#define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S0_RX_FIFO_ENABLED (1 << 11)
283#define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S0_TX_FIFO_ENABLED (1 << 10)
284#define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S4_RX_FIFO_EMPTY (1 << 9)
285#define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S4_TX_FIFO_EMPTY (1 << 8)
286#define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S3_RX_FIFO_EMPTY (1 << 7)
287#define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S3_TX_FIFO_EMPTY (1 << 6)
288#define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S2_RX_FIFO_EMPTY (1 << 5)
289#define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S2_TX_FIFO_EMPTY (1 << 4)
290#define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S1_RX_FIFO_EMPTY (1 << 3)
291#define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S1_TX_FIFO_EMPTY (1 << 2)
292#define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S0_RX_FIFO_EMPTY (1 << 1)
293#define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S0_TX_FIFO_EMPTY (1 << 0)
294
295/* TEGRA30_AHUB_DAM0_LIVE_STATUS */
296
297#define TEGRA30_AHUB_DAM_LIVE_STATUS 0x90
298#define TEGRA30_AHUB_DAM_LIVE_STATUS_STRIDE 0x8
299#define TEGRA30_AHUB_DAM_LIVE_STATUS_COUNT 3
300#define TEGRA30_AHUB_DAM_LIVE_STATUS_TX_ENABLED (1 << 26)
301#define TEGRA30_AHUB_DAM_LIVE_STATUS_RX1_ENABLED (1 << 25)
302#define TEGRA30_AHUB_DAM_LIVE_STATUS_RX0_ENABLED (1 << 24)
303#define TEGRA30_AHUB_DAM_LIVE_STATUS_TXFIFO_FULL (1 << 15)
304#define TEGRA30_AHUB_DAM_LIVE_STATUS_RX1FIFO_FULL (1 << 9)
305#define TEGRA30_AHUB_DAM_LIVE_STATUS_RX0FIFO_FULL (1 << 8)
306#define TEGRA30_AHUB_DAM_LIVE_STATUS_TXFIFO_EMPTY (1 << 7)
307#define TEGRA30_AHUB_DAM_LIVE_STATUS_RX1FIFO_EMPTY (1 << 1)
308#define TEGRA30_AHUB_DAM_LIVE_STATUS_RX0FIFO_EMPTY (1 << 0)
309
310/* TEGRA30_AHUB_SPDIF_LIVE_STATUS */
311
312#define TEGRA30_AHUB_SPDIF_LIVE_STATUS 0xa8
313#define TEGRA30_AHUB_SPDIF_LIVE_STATUS_USER_TX_ENABLED (1 << 11)
314#define TEGRA30_AHUB_SPDIF_LIVE_STATUS_USER_RX_ENABLED (1 << 10)
315#define TEGRA30_AHUB_SPDIF_LIVE_STATUS_DATA_TX_ENABLED (1 << 9)
316#define TEGRA30_AHUB_SPDIF_LIVE_STATUS_DATA_RX_ENABLED (1 << 8)
317#define TEGRA30_AHUB_SPDIF_LIVE_STATUS_USER_TXFIFO_FULL (1 << 7)
318#define TEGRA30_AHUB_SPDIF_LIVE_STATUS_USER_RXFIFO_FULL (1 << 6)
319#define TEGRA30_AHUB_SPDIF_LIVE_STATUS_DATA_TXFIFO_FULL (1 << 5)
320#define TEGRA30_AHUB_SPDIF_LIVE_STATUS_DATA_RXFIFO_FULL (1 << 4)
321#define TEGRA30_AHUB_SPDIF_LIVE_STATUS_USER_TXFIFO_EMPTY (1 << 3)
322#define TEGRA30_AHUB_SPDIF_LIVE_STATUS_USER_RXFIFO_EMPTY (1 << 2)
323#define TEGRA30_AHUB_SPDIF_LIVE_STATUS_DATA_TXFIFO_EMPTY (1 << 1)
324#define TEGRA30_AHUB_SPDIF_LIVE_STATUS_DATA_RXFIFO_EMPTY (1 << 0)
325
326/* TEGRA30_AHUB_I2S_INT_MASK */
327
328#define TEGRA30_AHUB_I2S_INT_MASK 0xb0
329
330/* TEGRA30_AHUB_DAM_INT_MASK */
331
332#define TEGRA30_AHUB_DAM_INT_MASK 0xb4
333
334/* TEGRA30_AHUB_SPDIF_INT_MASK */
335
336#define TEGRA30_AHUB_SPDIF_INT_MASK 0xbc
337
338/* TEGRA30_AHUB_APBIF_INT_MASK */
339
340#define TEGRA30_AHUB_APBIF_INT_MASK 0xc0
341
342/* TEGRA30_AHUB_I2S_INT_STATUS */
343
344#define TEGRA30_AHUB_I2S_INT_STATUS 0xc8
345
346/* TEGRA30_AHUB_DAM_INT_STATUS */
347
348#define TEGRA30_AHUB_DAM_INT_STATUS 0xcc
349
350/* TEGRA30_AHUB_SPDIF_INT_STATUS */
351
352#define TEGRA30_AHUB_SPDIF_INT_STATUS 0xd4
353
354/* TEGRA30_AHUB_APBIF_INT_STATUS */
355
356#define TEGRA30_AHUB_APBIF_INT_STATUS 0xd8
357
358/* TEGRA30_AHUB_I2S_INT_SOURCE */
359
360#define TEGRA30_AHUB_I2S_INT_SOURCE 0xe0
361
362/* TEGRA30_AHUB_DAM_INT_SOURCE */
363
364#define TEGRA30_AHUB_DAM_INT_SOURCE 0xe4
365
366/* TEGRA30_AHUB_SPDIF_INT_SOURCE */
367
368#define TEGRA30_AHUB_SPDIF_INT_SOURCE 0xec
369
370/* TEGRA30_AHUB_APBIF_INT_SOURCE */
371
372#define TEGRA30_AHUB_APBIF_INT_SOURCE 0xf0
373
374/* TEGRA30_AHUB_I2S_INT_SET */
375
376#define TEGRA30_AHUB_I2S_INT_SET 0xf8
377
378/* TEGRA30_AHUB_DAM_INT_SET */
379
380#define TEGRA30_AHUB_DAM_INT_SET 0xfc
381
382/* TEGRA30_AHUB_SPDIF_INT_SET */
383
384#define TEGRA30_AHUB_SPDIF_INT_SET 0x100
385
386/* TEGRA30_AHUB_APBIF_INT_SET */
387
388#define TEGRA30_AHUB_APBIF_INT_SET 0x104
389
390/* Registers within TEGRA30_AHUB_BASE */
391
392#define TEGRA30_AHUB_AUDIO_RX 0x0
393#define TEGRA30_AHUB_AUDIO_RX_STRIDE 0x4
394#define TEGRA30_AHUB_AUDIO_RX_COUNT 17
395/* This register repeats once for each entry in enum tegra30_ahub_rxcif */
396/* The fields in this register are 1 bit per entry in tegra30_ahub_txcif */
397
398/*
399 * Terminology:
400 * AHUB: Audio Hub; a cross-bar switch between the audio devices: DMA FIFOs,
401 * I2S controllers, SPDIF controllers, and DAMs.
402 * XBAR: The core cross-bar component of the AHUB.
403 * CIF: Client Interface; the HW module connecting an audio device to the
404 * XBAR.
405 * DAM: Digital Audio Mixer: A HW module that mixes multiple audio streams,
406 * possibly including sample-rate conversion.
407 *
408 * Each TX CIF transmits data into the XBAR. Each RX CIF can receive audio
409 * transmitted by a particular TX CIF.
410 *
411 * This driver is currently very simplistic; many HW features are not
412 * exposed; DAMs are not supported, only 16-bit stereo audio is supported,
413 * etc.
414 */
415
416enum tegra30_ahub_txcif {
417 TEGRA30_AHUB_TXCIF_APBIF_TX0,
418 TEGRA30_AHUB_TXCIF_APBIF_TX1,
419 TEGRA30_AHUB_TXCIF_APBIF_TX2,
420 TEGRA30_AHUB_TXCIF_APBIF_TX3,
421 TEGRA30_AHUB_TXCIF_I2S0_TX0,
422 TEGRA30_AHUB_TXCIF_I2S1_TX0,
423 TEGRA30_AHUB_TXCIF_I2S2_TX0,
424 TEGRA30_AHUB_TXCIF_I2S3_TX0,
425 TEGRA30_AHUB_TXCIF_I2S4_TX0,
426 TEGRA30_AHUB_TXCIF_DAM0_TX0,
427 TEGRA30_AHUB_TXCIF_DAM1_TX0,
428 TEGRA30_AHUB_TXCIF_DAM2_TX0,
429 TEGRA30_AHUB_TXCIF_SPDIF_TX0,
430 TEGRA30_AHUB_TXCIF_SPDIF_TX1,
431};
432
433enum tegra30_ahub_rxcif {
434 TEGRA30_AHUB_RXCIF_APBIF_RX0,
435 TEGRA30_AHUB_RXCIF_APBIF_RX1,
436 TEGRA30_AHUB_RXcIF_APBIF_RX2,
437 TEGRA30_AHUB_RXCIF_APBIF_RX3,
438 TEGRA30_AHUB_RXCIF_I2S0_RX0,
439 TEGRA30_AHUB_RXCIF_I2S1_RX0,
440 TEGRA30_AHUB_RXCIF_I2S2_RX0,
441 TEGRA30_AHUB_RXCIF_I2S3_RX0,
442 TEGRA30_AHUB_RXCIF_I2S4_RX0,
443 TEGRA30_AHUB_RXCIF_DAM0_RX0,
444 TEGRA30_AHUB_RXCIF_DAM0_RX1,
445 TEGRA30_AHUB_RXCIF_DAM1_RX0,
446 TEGRA30_AHUB_RXCIF_DAM2_RX1,
447 TEGRA30_AHUB_RXCIF_DAM3_RX0,
448 TEGRA30_AHUB_RXCIF_DAM3_RX1,
449 TEGRA30_AHUB_RXCIF_SPDIF_RX0,
450 TEGRA30_AHUB_RXCIF_SPDIF_RX1,
451};
452
453extern int tegra30_ahub_allocate_rx_fifo(enum tegra30_ahub_rxcif *rxcif,
454 unsigned long *fiforeg,
455 unsigned long *reqsel);
456extern int tegra30_ahub_enable_rx_fifo(enum tegra30_ahub_rxcif rxcif);
457extern int tegra30_ahub_disable_rx_fifo(enum tegra30_ahub_rxcif rxcif);
458extern int tegra30_ahub_free_rx_fifo(enum tegra30_ahub_rxcif rxcif);
459
460extern int tegra30_ahub_allocate_tx_fifo(enum tegra30_ahub_txcif *txcif,
461 unsigned long *fiforeg,
462 unsigned long *reqsel);
463extern int tegra30_ahub_enable_tx_fifo(enum tegra30_ahub_txcif txcif);
464extern int tegra30_ahub_disable_tx_fifo(enum tegra30_ahub_txcif txcif);
465extern int tegra30_ahub_free_tx_fifo(enum tegra30_ahub_txcif txcif);
466
467extern int tegra30_ahub_set_rx_cif_source(enum tegra30_ahub_rxcif rxcif,
468 enum tegra30_ahub_txcif txcif);
469extern int tegra30_ahub_unset_rx_cif_source(enum tegra30_ahub_rxcif rxcif);
470
471struct tegra30_ahub {
472 struct device *dev;
473 struct clk *clk_d_audio;
474 struct clk *clk_apbif;
475 int dma_sel;
476 resource_size_t apbif_addr;
477 struct regmap *regmap_apbif;
478 struct regmap *regmap_ahub;
479 DECLARE_BITMAP(rx_usage, TEGRA30_AHUB_CHANNEL_CTRL_COUNT);
480 DECLARE_BITMAP(tx_usage, TEGRA30_AHUB_CHANNEL_CTRL_COUNT);
481};
482
483#endif
diff --git a/sound/soc/tegra/tegra30_i2s.c b/sound/soc/tegra/tegra30_i2s.c
new file mode 100644
index 000000000000..8596032985dc
--- /dev/null
+++ b/sound/soc/tegra/tegra30_i2s.c
@@ -0,0 +1,536 @@
1/*
2 * tegra30_i2s.c - Tegra30 I2S driver
3 *
4 * Author: Stephen Warren <swarren@nvidia.com>
5 * Copyright (c) 2010-2012, NVIDIA CORPORATION. All rights reserved.
6 *
7 * Based on code copyright/by:
8 *
9 * Copyright (c) 2009-2010, NVIDIA Corporation.
10 * Scott Peterson <speterson@nvidia.com>
11 *
12 * Copyright (C) 2010 Google, Inc.
13 * Iliyan Malchev <malchev@google.com>
14 *
15 * This program is free software; you can redistribute it and/or modify it
16 * under the terms and conditions of the GNU General Public License,
17 * version 2, as published by the Free Software Foundation.
18 *
19 * This program is distributed in the hope it will be useful, but WITHOUT
20 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
22 * more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 */
27
28#include <linux/clk.h>
29#include <linux/device.h>
30#include <linux/io.h>
31#include <linux/module.h>
32#include <linux/of.h>
33#include <linux/platform_device.h>
34#include <linux/pm_runtime.h>
35#include <linux/regmap.h>
36#include <linux/slab.h>
37#include <sound/core.h>
38#include <sound/pcm.h>
39#include <sound/pcm_params.h>
40#include <sound/soc.h>
41
42#include "tegra30_ahub.h"
43#include "tegra30_i2s.h"
44
45#define DRV_NAME "tegra30-i2s"
46
47static inline void tegra30_i2s_write(struct tegra30_i2s *i2s, u32 reg, u32 val)
48{
49 regmap_write(i2s->regmap, reg, val);
50}
51
52static inline u32 tegra30_i2s_read(struct tegra30_i2s *i2s, u32 reg)
53{
54 u32 val;
55 regmap_read(i2s->regmap, reg, &val);
56 return val;
57}
58
59static int tegra30_i2s_runtime_suspend(struct device *dev)
60{
61 struct tegra30_i2s *i2s = dev_get_drvdata(dev);
62
63 regcache_cache_only(i2s->regmap, true);
64
65 clk_disable(i2s->clk_i2s);
66
67 return 0;
68}
69
70static int tegra30_i2s_runtime_resume(struct device *dev)
71{
72 struct tegra30_i2s *i2s = dev_get_drvdata(dev);
73 int ret;
74
75 ret = clk_enable(i2s->clk_i2s);
76 if (ret) {
77 dev_err(dev, "clk_enable failed: %d\n", ret);
78 return ret;
79 }
80
81 regcache_cache_only(i2s->regmap, false);
82
83 return 0;
84}
85
86int tegra30_i2s_startup(struct snd_pcm_substream *substream,
87 struct snd_soc_dai *dai)
88{
89 struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(dai);
90 int ret;
91
92 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
93 ret = tegra30_ahub_allocate_tx_fifo(&i2s->playback_fifo_cif,
94 &i2s->playback_dma_data.addr,
95 &i2s->playback_dma_data.req_sel);
96 i2s->playback_dma_data.wrap = 4;
97 i2s->playback_dma_data.width = 32;
98 tegra30_ahub_set_rx_cif_source(i2s->playback_i2s_cif,
99 i2s->playback_fifo_cif);
100 } else {
101 ret = tegra30_ahub_allocate_rx_fifo(&i2s->capture_fifo_cif,
102 &i2s->capture_dma_data.addr,
103 &i2s->capture_dma_data.req_sel);
104 i2s->capture_dma_data.wrap = 4;
105 i2s->capture_dma_data.width = 32;
106 tegra30_ahub_set_rx_cif_source(i2s->capture_fifo_cif,
107 i2s->capture_i2s_cif);
108 }
109
110 return ret;
111}
112
113void tegra30_i2s_shutdown(struct snd_pcm_substream *substream,
114 struct snd_soc_dai *dai)
115{
116 struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(dai);
117
118 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
119 tegra30_ahub_unset_rx_cif_source(i2s->playback_i2s_cif);
120 tegra30_ahub_free_tx_fifo(i2s->playback_fifo_cif);
121 } else {
122 tegra30_ahub_unset_rx_cif_source(i2s->capture_fifo_cif);
123 tegra30_ahub_free_rx_fifo(i2s->capture_fifo_cif);
124 }
125}
126
127static int tegra30_i2s_set_fmt(struct snd_soc_dai *dai,
128 unsigned int fmt)
129{
130 struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(dai);
131
132 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
133 case SND_SOC_DAIFMT_NB_NF:
134 break;
135 default:
136 return -EINVAL;
137 }
138
139 i2s->reg_ctrl &= ~TEGRA30_I2S_CTRL_MASTER_ENABLE;
140 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
141 case SND_SOC_DAIFMT_CBS_CFS:
142 i2s->reg_ctrl |= TEGRA30_I2S_CTRL_MASTER_ENABLE;
143 break;
144 case SND_SOC_DAIFMT_CBM_CFM:
145 break;
146 default:
147 return -EINVAL;
148 }
149
150 i2s->reg_ctrl &= ~(TEGRA30_I2S_CTRL_FRAME_FORMAT_MASK |
151 TEGRA30_I2S_CTRL_LRCK_MASK);
152 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
153 case SND_SOC_DAIFMT_DSP_A:
154 i2s->reg_ctrl |= TEGRA30_I2S_CTRL_FRAME_FORMAT_FSYNC;
155 i2s->reg_ctrl |= TEGRA30_I2S_CTRL_LRCK_L_LOW;
156 break;
157 case SND_SOC_DAIFMT_DSP_B:
158 i2s->reg_ctrl |= TEGRA30_I2S_CTRL_FRAME_FORMAT_FSYNC;
159 i2s->reg_ctrl |= TEGRA30_I2S_CTRL_LRCK_R_LOW;
160 break;
161 case SND_SOC_DAIFMT_I2S:
162 i2s->reg_ctrl |= TEGRA30_I2S_CTRL_FRAME_FORMAT_LRCK;
163 i2s->reg_ctrl |= TEGRA30_I2S_CTRL_LRCK_L_LOW;
164 break;
165 case SND_SOC_DAIFMT_RIGHT_J:
166 i2s->reg_ctrl |= TEGRA30_I2S_CTRL_FRAME_FORMAT_LRCK;
167 i2s->reg_ctrl |= TEGRA30_I2S_CTRL_LRCK_L_LOW;
168 break;
169 case SND_SOC_DAIFMT_LEFT_J:
170 i2s->reg_ctrl |= TEGRA30_I2S_CTRL_FRAME_FORMAT_LRCK;
171 i2s->reg_ctrl |= TEGRA30_I2S_CTRL_LRCK_L_LOW;
172 break;
173 default:
174 return -EINVAL;
175 }
176
177 return 0;
178}
179
180static int tegra30_i2s_hw_params(struct snd_pcm_substream *substream,
181 struct snd_pcm_hw_params *params,
182 struct snd_soc_dai *dai)
183{
184 struct device *dev = substream->pcm->card->dev;
185 struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(dai);
186 u32 val;
187 int ret, sample_size, srate, i2sclock, bitcnt;
188
189 if (params_channels(params) != 2)
190 return -EINVAL;
191
192 i2s->reg_ctrl &= ~TEGRA30_I2S_CTRL_BIT_SIZE_MASK;
193 switch (params_format(params)) {
194 case SNDRV_PCM_FORMAT_S16_LE:
195 i2s->reg_ctrl |= TEGRA30_I2S_CTRL_BIT_SIZE_16;
196 sample_size = 16;
197 break;
198 default:
199 return -EINVAL;
200 }
201
202 srate = params_rate(params);
203
204 /* Final "* 2" required by Tegra hardware */
205 i2sclock = srate * params_channels(params) * sample_size * 2;
206
207 bitcnt = (i2sclock / (2 * srate)) - 1;
208 if (bitcnt < 0 || bitcnt > TEGRA30_I2S_TIMING_CHANNEL_BIT_COUNT_MASK_US)
209 return -EINVAL;
210
211 ret = clk_set_rate(i2s->clk_i2s, i2sclock);
212 if (ret) {
213 dev_err(dev, "Can't set I2S clock rate: %d\n", ret);
214 return ret;
215 }
216
217 val = bitcnt << TEGRA30_I2S_TIMING_CHANNEL_BIT_COUNT_SHIFT;
218
219 if (i2sclock % (2 * srate))
220 val |= TEGRA30_I2S_TIMING_NON_SYM_ENABLE;
221
222 tegra30_i2s_write(i2s, TEGRA30_I2S_TIMING, val);
223
224 val = (0 << TEGRA30_AUDIOCIF_CTRL_FIFO_THRESHOLD_SHIFT) |
225 (1 << TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_SHIFT) |
226 (1 << TEGRA30_AUDIOCIF_CTRL_CLIENT_CHANNELS_SHIFT) |
227 TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_16 |
228 TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_16;
229
230 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
231 val |= TEGRA30_AUDIOCIF_CTRL_DIRECTION_RX;
232 tegra30_i2s_write(i2s, TEGRA30_I2S_CIF_RX_CTRL, val);
233 } else {
234 val |= TEGRA30_AUDIOCIF_CTRL_DIRECTION_TX;
235 tegra30_i2s_write(i2s, TEGRA30_I2S_CIF_TX_CTRL, val);
236 }
237
238 val = (1 << TEGRA30_I2S_OFFSET_RX_DATA_OFFSET_SHIFT) |
239 (1 << TEGRA30_I2S_OFFSET_TX_DATA_OFFSET_SHIFT);
240 tegra30_i2s_write(i2s, TEGRA30_I2S_OFFSET, val);
241
242 return 0;
243}
244
245static void tegra30_i2s_start_playback(struct tegra30_i2s *i2s)
246{
247 tegra30_ahub_enable_tx_fifo(i2s->playback_fifo_cif);
248 i2s->reg_ctrl |= TEGRA30_I2S_CTRL_XFER_EN_TX;
249 tegra30_i2s_write(i2s, TEGRA30_I2S_CTRL, i2s->reg_ctrl);
250}
251
252static void tegra30_i2s_stop_playback(struct tegra30_i2s *i2s)
253{
254 tegra30_ahub_disable_tx_fifo(i2s->playback_fifo_cif);
255 i2s->reg_ctrl &= ~TEGRA30_I2S_CTRL_XFER_EN_TX;
256 tegra30_i2s_write(i2s, TEGRA30_I2S_CTRL, i2s->reg_ctrl);
257}
258
259static void tegra30_i2s_start_capture(struct tegra30_i2s *i2s)
260{
261 tegra30_ahub_enable_rx_fifo(i2s->capture_fifo_cif);
262 i2s->reg_ctrl |= TEGRA30_I2S_CTRL_XFER_EN_RX;
263 tegra30_i2s_write(i2s, TEGRA30_I2S_CTRL, i2s->reg_ctrl);
264}
265
266static void tegra30_i2s_stop_capture(struct tegra30_i2s *i2s)
267{
268 tegra30_ahub_disable_rx_fifo(i2s->capture_fifo_cif);
269 i2s->reg_ctrl &= ~TEGRA30_I2S_CTRL_XFER_EN_RX;
270 tegra30_i2s_write(i2s, TEGRA30_I2S_CTRL, i2s->reg_ctrl);
271}
272
273static int tegra30_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
274 struct snd_soc_dai *dai)
275{
276 struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(dai);
277
278 switch (cmd) {
279 case SNDRV_PCM_TRIGGER_START:
280 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
281 case SNDRV_PCM_TRIGGER_RESUME:
282 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
283 tegra30_i2s_start_playback(i2s);
284 else
285 tegra30_i2s_start_capture(i2s);
286 break;
287 case SNDRV_PCM_TRIGGER_STOP:
288 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
289 case SNDRV_PCM_TRIGGER_SUSPEND:
290 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
291 tegra30_i2s_stop_playback(i2s);
292 else
293 tegra30_i2s_stop_capture(i2s);
294 break;
295 default:
296 return -EINVAL;
297 }
298
299 return 0;
300}
301
302static int tegra30_i2s_probe(struct snd_soc_dai *dai)
303{
304 struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(dai);
305
306 dai->capture_dma_data = &i2s->capture_dma_data;
307 dai->playback_dma_data = &i2s->playback_dma_data;
308
309 return 0;
310}
311
312static struct snd_soc_dai_ops tegra30_i2s_dai_ops = {
313 .startup = tegra30_i2s_startup,
314 .shutdown = tegra30_i2s_shutdown,
315 .set_fmt = tegra30_i2s_set_fmt,
316 .hw_params = tegra30_i2s_hw_params,
317 .trigger = tegra30_i2s_trigger,
318};
319
320static const struct snd_soc_dai_driver tegra30_i2s_dai_template = {
321 .probe = tegra30_i2s_probe,
322 .playback = {
323 .channels_min = 2,
324 .channels_max = 2,
325 .rates = SNDRV_PCM_RATE_8000_96000,
326 .formats = SNDRV_PCM_FMTBIT_S16_LE,
327 },
328 .capture = {
329 .channels_min = 2,
330 .channels_max = 2,
331 .rates = SNDRV_PCM_RATE_8000_96000,
332 .formats = SNDRV_PCM_FMTBIT_S16_LE,
333 },
334 .ops = &tegra30_i2s_dai_ops,
335 .symmetric_rates = 1,
336};
337
338static bool tegra30_i2s_wr_rd_reg(struct device *dev, unsigned int reg)
339{
340 switch (reg) {
341 case TEGRA30_I2S_CTRL:
342 case TEGRA30_I2S_TIMING:
343 case TEGRA30_I2S_OFFSET:
344 case TEGRA30_I2S_CH_CTRL:
345 case TEGRA30_I2S_SLOT_CTRL:
346 case TEGRA30_I2S_CIF_RX_CTRL:
347 case TEGRA30_I2S_CIF_TX_CTRL:
348 case TEGRA30_I2S_FLOWCTL:
349 case TEGRA30_I2S_TX_STEP:
350 case TEGRA30_I2S_FLOW_STATUS:
351 case TEGRA30_I2S_FLOW_TOTAL:
352 case TEGRA30_I2S_FLOW_OVER:
353 case TEGRA30_I2S_FLOW_UNDER:
354 case TEGRA30_I2S_LCOEF_1_4_0:
355 case TEGRA30_I2S_LCOEF_1_4_1:
356 case TEGRA30_I2S_LCOEF_1_4_2:
357 case TEGRA30_I2S_LCOEF_1_4_3:
358 case TEGRA30_I2S_LCOEF_1_4_4:
359 case TEGRA30_I2S_LCOEF_1_4_5:
360 case TEGRA30_I2S_LCOEF_2_4_0:
361 case TEGRA30_I2S_LCOEF_2_4_1:
362 case TEGRA30_I2S_LCOEF_2_4_2:
363 return true;
364 default:
365 return false;
366 };
367}
368
369static bool tegra30_i2s_volatile_reg(struct device *dev, unsigned int reg)
370{
371 switch (reg) {
372 case TEGRA30_I2S_FLOW_STATUS:
373 case TEGRA30_I2S_FLOW_TOTAL:
374 case TEGRA30_I2S_FLOW_OVER:
375 case TEGRA30_I2S_FLOW_UNDER:
376 return true;
377 default:
378 return false;
379 };
380}
381
382static const struct regmap_config tegra30_i2s_regmap_config = {
383 .reg_bits = 32,
384 .reg_stride = 4,
385 .val_bits = 32,
386 .max_register = TEGRA30_I2S_LCOEF_2_4_2,
387 .writeable_reg = tegra30_i2s_wr_rd_reg,
388 .readable_reg = tegra30_i2s_wr_rd_reg,
389 .volatile_reg = tegra30_i2s_volatile_reg,
390 .cache_type = REGCACHE_RBTREE,
391};
392
393static __devinit int tegra30_i2s_platform_probe(struct platform_device *pdev)
394{
395 struct tegra30_i2s *i2s;
396 u32 cif_ids[2];
397 struct resource *mem, *memregion;
398 void __iomem *regs;
399 int ret;
400
401 i2s = devm_kzalloc(&pdev->dev, sizeof(struct tegra30_i2s), GFP_KERNEL);
402 if (!i2s) {
403 dev_err(&pdev->dev, "Can't allocate tegra30_i2s\n");
404 ret = -ENOMEM;
405 goto err;
406 }
407 dev_set_drvdata(&pdev->dev, i2s);
408
409 i2s->dai = tegra30_i2s_dai_template;
410 i2s->dai.name = dev_name(&pdev->dev);
411
412 ret = of_property_read_u32_array(pdev->dev.of_node,
413 "nvidia,ahub-cif-ids", cif_ids,
414 ARRAY_SIZE(cif_ids));
415 if (ret < 0)
416 goto err;
417
418 i2s->playback_i2s_cif = cif_ids[0];
419 i2s->capture_i2s_cif = cif_ids[1];
420
421 i2s->clk_i2s = clk_get(&pdev->dev, NULL);
422 if (IS_ERR(i2s->clk_i2s)) {
423 dev_err(&pdev->dev, "Can't retrieve i2s clock\n");
424 ret = PTR_ERR(i2s->clk_i2s);
425 goto err;
426 }
427
428 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
429 if (!mem) {
430 dev_err(&pdev->dev, "No memory resource\n");
431 ret = -ENODEV;
432 goto err_clk_put;
433 }
434
435 memregion = devm_request_mem_region(&pdev->dev, mem->start,
436 resource_size(mem), DRV_NAME);
437 if (!memregion) {
438 dev_err(&pdev->dev, "Memory region already claimed\n");
439 ret = -EBUSY;
440 goto err_clk_put;
441 }
442
443 regs = devm_ioremap(&pdev->dev, mem->start, resource_size(mem));
444 if (!regs) {
445 dev_err(&pdev->dev, "ioremap failed\n");
446 ret = -ENOMEM;
447 goto err_clk_put;
448 }
449
450 i2s->regmap = devm_regmap_init_mmio(&pdev->dev, regs,
451 &tegra30_i2s_regmap_config);
452 if (IS_ERR(i2s->regmap)) {
453 dev_err(&pdev->dev, "regmap init failed\n");
454 ret = PTR_ERR(i2s->regmap);
455 goto err_clk_put;
456 }
457 regcache_cache_only(i2s->regmap, true);
458
459 pm_runtime_enable(&pdev->dev);
460 if (!pm_runtime_enabled(&pdev->dev)) {
461 ret = tegra30_i2s_runtime_resume(&pdev->dev);
462 if (ret)
463 goto err_pm_disable;
464 }
465
466 ret = snd_soc_register_dai(&pdev->dev, &i2s->dai);
467 if (ret) {
468 dev_err(&pdev->dev, "Could not register DAI: %d\n", ret);
469 ret = -ENOMEM;
470 goto err_suspend;
471 }
472
473 ret = tegra_pcm_platform_register(&pdev->dev);
474 if (ret) {
475 dev_err(&pdev->dev, "Could not register PCM: %d\n", ret);
476 goto err_unregister_dai;
477 }
478
479 return 0;
480
481err_unregister_dai:
482 snd_soc_unregister_dai(&pdev->dev);
483err_suspend:
484 if (!pm_runtime_status_suspended(&pdev->dev))
485 tegra30_i2s_runtime_suspend(&pdev->dev);
486err_pm_disable:
487 pm_runtime_disable(&pdev->dev);
488err_clk_put:
489 clk_put(i2s->clk_i2s);
490err:
491 return ret;
492}
493
494static int __devexit tegra30_i2s_platform_remove(struct platform_device *pdev)
495{
496 struct tegra30_i2s *i2s = dev_get_drvdata(&pdev->dev);
497
498 pm_runtime_disable(&pdev->dev);
499 if (!pm_runtime_status_suspended(&pdev->dev))
500 tegra30_i2s_runtime_suspend(&pdev->dev);
501
502 tegra_pcm_platform_unregister(&pdev->dev);
503 snd_soc_unregister_dai(&pdev->dev);
504
505 clk_put(i2s->clk_i2s);
506
507 return 0;
508}
509
510static const struct of_device_id tegra30_i2s_of_match[] __devinitconst = {
511 { .compatible = "nvidia,tegra30-i2s", },
512 {},
513};
514
515static const struct dev_pm_ops tegra30_i2s_pm_ops __devinitconst = {
516 SET_RUNTIME_PM_OPS(tegra30_i2s_runtime_suspend,
517 tegra30_i2s_runtime_resume, NULL)
518};
519
520static struct platform_driver tegra30_i2s_driver = {
521 .driver = {
522 .name = DRV_NAME,
523 .owner = THIS_MODULE,
524 .of_match_table = tegra30_i2s_of_match,
525 .pm = &tegra30_i2s_pm_ops,
526 },
527 .probe = tegra30_i2s_platform_probe,
528 .remove = __devexit_p(tegra30_i2s_platform_remove),
529};
530module_platform_driver(tegra30_i2s_driver);
531
532MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>");
533MODULE_DESCRIPTION("Tegra30 I2S ASoC driver");
534MODULE_LICENSE("GPL");
535MODULE_ALIAS("platform:" DRV_NAME);
536MODULE_DEVICE_TABLE(of, tegra30_i2s_of_match);
diff --git a/sound/soc/tegra/tegra30_i2s.h b/sound/soc/tegra/tegra30_i2s.h
new file mode 100644
index 000000000000..91adf29c7a87
--- /dev/null
+++ b/sound/soc/tegra/tegra30_i2s.h
@@ -0,0 +1,242 @@
1/*
2 * tegra30_i2s.h - Definitions for Tegra30 I2S driver
3 *
4 * Copyright (c) 2011,2012, NVIDIA CORPORATION. All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef __TEGRA30_I2S_H__
20#define __TEGRA30_I2S_H__
21
22#include "tegra_pcm.h"
23
24/* Register offsets from TEGRA30_I2S*_BASE */
25
26#define TEGRA30_I2S_CTRL 0x0
27#define TEGRA30_I2S_TIMING 0x4
28#define TEGRA30_I2S_OFFSET 0x08
29#define TEGRA30_I2S_CH_CTRL 0x0c
30#define TEGRA30_I2S_SLOT_CTRL 0x10
31#define TEGRA30_I2S_CIF_RX_CTRL 0x14
32#define TEGRA30_I2S_CIF_TX_CTRL 0x18
33#define TEGRA30_I2S_FLOWCTL 0x1c
34#define TEGRA30_I2S_TX_STEP 0x20
35#define TEGRA30_I2S_FLOW_STATUS 0x24
36#define TEGRA30_I2S_FLOW_TOTAL 0x28
37#define TEGRA30_I2S_FLOW_OVER 0x2c
38#define TEGRA30_I2S_FLOW_UNDER 0x30
39#define TEGRA30_I2S_LCOEF_1_4_0 0x34
40#define TEGRA30_I2S_LCOEF_1_4_1 0x38
41#define TEGRA30_I2S_LCOEF_1_4_2 0x3c
42#define TEGRA30_I2S_LCOEF_1_4_3 0x40
43#define TEGRA30_I2S_LCOEF_1_4_4 0x44
44#define TEGRA30_I2S_LCOEF_1_4_5 0x48
45#define TEGRA30_I2S_LCOEF_2_4_0 0x4c
46#define TEGRA30_I2S_LCOEF_2_4_1 0x50
47#define TEGRA30_I2S_LCOEF_2_4_2 0x54
48
49/* Fields in TEGRA30_I2S_CTRL */
50
51#define TEGRA30_I2S_CTRL_XFER_EN_TX (1 << 31)
52#define TEGRA30_I2S_CTRL_XFER_EN_RX (1 << 30)
53#define TEGRA30_I2S_CTRL_CG_EN (1 << 29)
54#define TEGRA30_I2S_CTRL_SOFT_RESET (1 << 28)
55#define TEGRA30_I2S_CTRL_TX_FLOWCTL_EN (1 << 27)
56
57#define TEGRA30_I2S_CTRL_OBS_SEL_SHIFT 24
58#define TEGRA30_I2S_CTRL_OBS_SEL_MASK (7 << TEGRA30_I2S_CTRL_OBS_SEL_SHIFT)
59
60#define TEGRA30_I2S_FRAME_FORMAT_LRCK 0
61#define TEGRA30_I2S_FRAME_FORMAT_FSYNC 1
62
63#define TEGRA30_I2S_CTRL_FRAME_FORMAT_SHIFT 12
64#define TEGRA30_I2S_CTRL_FRAME_FORMAT_MASK (7 << TEGRA30_I2S_CTRL_FRAME_FORMAT_SHIFT)
65#define TEGRA30_I2S_CTRL_FRAME_FORMAT_LRCK (TEGRA30_I2S_FRAME_FORMAT_LRCK << TEGRA30_I2S_CTRL_FRAME_FORMAT_SHIFT)
66#define TEGRA30_I2S_CTRL_FRAME_FORMAT_FSYNC (TEGRA30_I2S_FRAME_FORMAT_FSYNC << TEGRA30_I2S_CTRL_FRAME_FORMAT_SHIFT)
67
68#define TEGRA30_I2S_CTRL_MASTER_ENABLE (1 << 10)
69
70#define TEGRA30_I2S_LRCK_LEFT_LOW 0
71#define TEGRA30_I2S_LRCK_RIGHT_LOW 1
72
73#define TEGRA30_I2S_CTRL_LRCK_SHIFT 9
74#define TEGRA30_I2S_CTRL_LRCK_MASK (1 << TEGRA30_I2S_CTRL_LRCK_SHIFT)
75#define TEGRA30_I2S_CTRL_LRCK_L_LOW (TEGRA30_I2S_LRCK_LEFT_LOW << TEGRA30_I2S_CTRL_LRCK_SHIFT)
76#define TEGRA30_I2S_CTRL_LRCK_R_LOW (TEGRA30_I2S_LRCK_RIGHT_LOW << TEGRA30_I2S_CTRL_LRCK_SHIFT)
77
78#define TEGRA30_I2S_CTRL_LPBK_ENABLE (1 << 8)
79
80#define TEGRA30_I2S_BIT_CODE_LINEAR 0
81#define TEGRA30_I2S_BIT_CODE_ULAW 1
82#define TEGRA30_I2S_BIT_CODE_ALAW 2
83
84#define TEGRA30_I2S_CTRL_BIT_CODE_SHIFT 4
85#define TEGRA30_I2S_CTRL_BIT_CODE_MASK (3 << TEGRA30_I2S_CTRL_BIT_CODE_SHIFT)
86#define TEGRA30_I2S_CTRL_BIT_CODE_LINEAR (TEGRA30_I2S_BIT_CODE_LINEAR << TEGRA30_I2S_CTRL_BIT_CODE_SHIFT)
87#define TEGRA30_I2S_CTRL_BIT_CODE_ULAW (TEGRA30_I2S_BIT_CODE_ULAW << TEGRA30_I2S_CTRL_BIT_CODE_SHIFT)
88#define TEGRA30_I2S_CTRL_BIT_CODE_ALAW (TEGRA30_I2S_BIT_CODE_ALAW << TEGRA30_I2S_CTRL_BIT_CODE_SHIFT)
89
90#define TEGRA30_I2S_BITS_8 1
91#define TEGRA30_I2S_BITS_12 2
92#define TEGRA30_I2S_BITS_16 3
93#define TEGRA30_I2S_BITS_20 4
94#define TEGRA30_I2S_BITS_24 5
95#define TEGRA30_I2S_BITS_28 6
96#define TEGRA30_I2S_BITS_32 7
97
98/* Sample container size; see {RX,TX}_MASK field in CH_CTRL below */
99#define TEGRA30_I2S_CTRL_BIT_SIZE_SHIFT 0
100#define TEGRA30_I2S_CTRL_BIT_SIZE_MASK (7 << TEGRA30_I2S_CTRL_BIT_SIZE_SHIFT)
101#define TEGRA30_I2S_CTRL_BIT_SIZE_8 (TEGRA30_I2S_BITS_8 << TEGRA30_I2S_CTRL_BIT_SIZE_SHIFT)
102#define TEGRA30_I2S_CTRL_BIT_SIZE_12 (TEGRA30_I2S_BITS_12 << TEGRA30_I2S_CTRL_BIT_SIZE_SHIFT)
103#define TEGRA30_I2S_CTRL_BIT_SIZE_16 (TEGRA30_I2S_BITS_16 << TEGRA30_I2S_CTRL_BIT_SIZE_SHIFT)
104#define TEGRA30_I2S_CTRL_BIT_SIZE_20 (TEGRA30_I2S_BITS_20 << TEGRA30_I2S_CTRL_BIT_SIZE_SHIFT)
105#define TEGRA30_I2S_CTRL_BIT_SIZE_24 (TEGRA30_I2S_BITS_24 << TEGRA30_I2S_CTRL_BIT_SIZE_SHIFT)
106#define TEGRA30_I2S_CTRL_BIT_SIZE_28 (TEGRA30_I2S_BITS_28 << TEGRA30_I2S_CTRL_BIT_SIZE_SHIFT)
107#define TEGRA30_I2S_CTRL_BIT_SIZE_32 (TEGRA30_I2S_BITS_32 << TEGRA30_I2S_CTRL_BIT_SIZE_SHIFT)
108
109/* Fields in TEGRA30_I2S_TIMING */
110
111#define TEGRA30_I2S_TIMING_NON_SYM_ENABLE (1 << 12)
112#define TEGRA30_I2S_TIMING_CHANNEL_BIT_COUNT_SHIFT 0
113#define TEGRA30_I2S_TIMING_CHANNEL_BIT_COUNT_MASK_US 0x7fff
114#define TEGRA30_I2S_TIMING_CHANNEL_BIT_COUNT_MASK (TEGRA30_I2S_TIMING_CHANNEL_BIT_COUNT_MASK_US << TEGRA30_I2S_TIMING_CHANNEL_BIT_COUNT_SHIFT)
115
116/* Fields in TEGRA30_I2S_OFFSET */
117
118#define TEGRA30_I2S_OFFSET_RX_DATA_OFFSET_SHIFT 16
119#define TEGRA30_I2S_OFFSET_RX_DATA_OFFSET_MASK_US 0x7ff
120#define TEGRA30_I2S_OFFSET_RX_DATA_OFFSET_MASK (TEGRA30_I2S_OFFSET_RX_DATA_OFFSET_MASK_US << TEGRA30_I2S_OFFSET_RX_DATA_OFFSET_SHIFT)
121#define TEGRA30_I2S_OFFSET_TX_DATA_OFFSET_SHIFT 0
122#define TEGRA30_I2S_OFFSET_TX_DATA_OFFSET_MASK_US 0x7ff
123#define TEGRA30_I2S_OFFSET_TX_DATA_OFFSET_MASK (TEGRA30_I2S_OFFSET_TX_DATA_OFFSET_MASK_US << TEGRA30_I2S_OFFSET_TX_DATA_OFFSET_SHIFT)
124
125/* Fields in TEGRA30_I2S_CH_CTRL */
126
127/* (FSYNC width - 1) in bit clocks */
128#define TEGRA30_I2S_CH_CTRL_FSYNC_WIDTH_SHIFT 24
129#define TEGRA30_I2S_CH_CTRL_FSYNC_WIDTH_MASK_US 0xff
130#define TEGRA30_I2S_CH_CTRL_FSYNC_WIDTH_MASK (TEGRA30_I2S_CH_CTRL_FSYNC_WIDTH_MASK_US << TEGRA30_I2S_CH_CTRL_FSYNC_WIDTH_SHIFT)
131
132#define TEGRA30_I2S_HIGHZ_NO 0
133#define TEGRA30_I2S_HIGHZ_YES 1
134#define TEGRA30_I2S_HIGHZ_ON_HALF_BIT_CLK 2
135
136#define TEGRA30_I2S_CH_CTRL_HIGHZ_CTRL_SHIFT 12
137#define TEGRA30_I2S_CH_CTRL_HIGHZ_CTRL_MASK (3 << TEGRA30_I2S_CH_CTRL_HIGHZ_CTRL_SHIFT)
138#define TEGRA30_I2S_CH_CTRL_HIGHZ_CTRL_NO (TEGRA30_I2S_HIGHZ_NO << TEGRA30_I2S_CH_CTRL_HIGHZ_CTRL_SHIFT)
139#define TEGRA30_I2S_CH_CTRL_HIGHZ_CTRL_YES (TEGRA30_I2S_HIGHZ_YES << TEGRA30_I2S_CH_CTRL_HIGHZ_CTRL_SHIFT)
140#define TEGRA30_I2S_CH_CTRL_HIGHZ_CTRL_ON_HALF_BIT_CLK (TEGRA30_I2S_HIGHZ_ON_HALF_BIT_CLK << TEGRA30_I2S_CH_CTRL_HIGHZ_CTRL_SHIFT)
141
142#define TEGRA30_I2S_MSB_FIRST 0
143#define TEGRA30_I2S_LSB_FIRST 1
144
145#define TEGRA30_I2S_CH_CTRL_RX_BIT_ORDER_SHIFT 10
146#define TEGRA30_I2S_CH_CTRL_RX_BIT_ORDER_MASK (1 << TEGRA30_I2S_CH_CTRL_RX_BIT_ORDER_SHIFT)
147#define TEGRA30_I2S_CH_CTRL_RX_BIT_ORDER_MSB_FIRST (TEGRA30_I2S_MSB_FIRST << TEGRA30_I2S_CH_CTRL_RX_BIT_ORDER_SHIFT)
148#define TEGRA30_I2S_CH_CTRL_RX_BIT_ORDER_LSB_FIRST (TEGRA30_I2S_LSB_FIRST << TEGRA30_I2S_CH_CTRL_RX_BIT_ORDER_SHIFT)
149#define TEGRA30_I2S_CH_CTRL_TX_BIT_ORDER_SHIFT 9
150#define TEGRA30_I2S_CH_CTRL_TX_BIT_ORDER_MASK (1 << TEGRA30_I2S_CH_CTRL_TX_BIT_ORDER_SHIFT)
151#define TEGRA30_I2S_CH_CTRL_TX_BIT_ORDER_MSB_FIRST (TEGRA30_I2S_MSB_FIRST << TEGRA30_I2S_CH_CTRL_TX_BIT_ORDER_SHIFT)
152#define TEGRA30_I2S_CH_CTRL_TX_BIT_ORDER_LSB_FIRST (TEGRA30_I2S_LSB_FIRST << TEGRA30_I2S_CH_CTRL_TX_BIT_ORDER_SHIFT)
153
154#define TEGRA30_I2S_POS_EDGE 0
155#define TEGRA30_I2S_NEG_EDGE 1
156
157#define TEGRA30_I2S_CH_CTRL_EGDE_CTRL_SHIFT 8
158#define TEGRA30_I2S_CH_CTRL_EGDE_CTRL_MASK (1 << TEGRA30_I2S_CH_CTRL_EGDE_CTRL_SHIFT)
159#define TEGRA30_I2S_CH_CTRL_EGDE_CTRL_POS_EDGE (TEGRA30_I2S_POS_EDGE << TEGRA30_I2S_CH_CTRL_EGDE_CTRL_SHIFT)
160#define TEGRA30_I2S_CH_CTRL_EGDE_CTRL_NEG_EDGE (TEGRA30_I2S_NEG_EDGE << TEGRA30_I2S_CH_CTRL_EGDE_CTRL_SHIFT)
161
162/* Sample size is # bits from BIT_SIZE minus this field */
163#define TEGRA30_I2S_CH_CTRL_RX_MASK_BITS_SHIFT 4
164#define TEGRA30_I2S_CH_CTRL_RX_MASK_BITS_MASK_US 7
165#define TEGRA30_I2S_CH_CTRL_RX_MASK_BITS_MASK (TEGRA30_I2S_CH_CTRL_RX_MASK_BITS_MASK_US << TEGRA30_I2S_CH_CTRL_RX_MASK_BITS_SHIFT)
166
167#define TEGRA30_I2S_CH_CTRL_TX_MASK_BITS_SHIFT 0
168#define TEGRA30_I2S_CH_CTRL_TX_MASK_BITS_MASK_US 7
169#define TEGRA30_I2S_CH_CTRL_TX_MASK_BITS_MASK (TEGRA30_I2S_CH_CTRL_TX_MASK_BITS_MASK_US << TEGRA30_I2S_CH_CTRL_TX_MASK_BITS_SHIFT)
170
171/* Fields in TEGRA30_I2S_SLOT_CTRL */
172
173/* Number of slots in frame, minus 1 */
174#define TEGRA30_I2S_SLOT_CTRL_TOTAL_SLOTS_SHIFT 16
175#define TEGRA30_I2S_SLOT_CTRL_TOTAL_SLOTS_MASK_US 7
176#define TEGRA30_I2S_SLOT_CTRL_TOTAL_SLOTS_MASK (TEGRA30_I2S_SLOT_CTRL_TOTAL_SLOT_MASK_US << TEGRA30_I2S_SLOT_CTRL_TOTAL_SLOT_SHIFT)
177
178/* TDM mode slot enable bitmask */
179#define TEGRA30_I2S_SLOT_CTRL_RX_SLOT_ENABLES_SHIFT 8
180#define TEGRA30_I2S_SLOT_CTRL_RX_SLOT_ENABLES_MASK (0xff << TEGRA30_I2S_SLOT_CTRL_RX_SLOT_ENABLES_SHIFT)
181
182#define TEGRA30_I2S_SLOT_CTRL_TX_SLOT_ENABLES_SHIFT 0
183#define TEGRA30_I2S_SLOT_CTRL_TX_SLOT_ENABLES_MASK (0xff << TEGRA30_I2S_SLOT_CTRL_TX_SLOT_ENABLES_SHIFT)
184
185/* Fields in TEGRA30_I2S_CIF_RX_CTRL */
186/* Uses field from TEGRA30_AUDIOCIF_CTRL_* in tegra30_ahub.h */
187
188/* Fields in TEGRA30_I2S_CIF_TX_CTRL */
189/* Uses field from TEGRA30_AUDIOCIF_CTRL_* in tegra30_ahub.h */
190
191/* Fields in TEGRA30_I2S_FLOWCTL */
192
193#define TEGRA30_I2S_FILTER_LINEAR 0
194#define TEGRA30_I2S_FILTER_QUAD 1
195
196#define TEGRA30_I2S_FLOWCTL_FILTER_SHIFT 31
197#define TEGRA30_I2S_FLOWCTL_FILTER_MASK (1 << TEGRA30_I2S_FLOWCTL_FILTER_SHIFT)
198#define TEGRA30_I2S_FLOWCTL_FILTER_LINEAR (TEGRA30_I2S_FILTER_LINEAR << TEGRA30_I2S_FLOWCTL_FILTER_SHIFT)
199#define TEGRA30_I2S_FLOWCTL_FILTER_QUAD (TEGRA30_I2S_FILTER_QUAD << TEGRA30_I2S_FLOWCTL_FILTER_SHIFT)
200
201/* Fields in TEGRA30_I2S_TX_STEP */
202
203#define TEGRA30_I2S_TX_STEP_SHIFT 0
204#define TEGRA30_I2S_TX_STEP_MASK_US 0xffff
205#define TEGRA30_I2S_TX_STEP_MASK (TEGRA30_I2S_TX_STEP_MASK_US << TEGRA30_I2S_TX_STEP_SHIFT)
206
207/* Fields in TEGRA30_I2S_FLOW_STATUS */
208
209#define TEGRA30_I2S_FLOW_STATUS_UNDERFLOW (1 << 31)
210#define TEGRA30_I2S_FLOW_STATUS_OVERFLOW (1 << 30)
211#define TEGRA30_I2S_FLOW_STATUS_MONITOR_INT_EN (1 << 4)
212#define TEGRA30_I2S_FLOW_STATUS_COUNTER_CLR (1 << 3)
213#define TEGRA30_I2S_FLOW_STATUS_MONITOR_CLR (1 << 2)
214#define TEGRA30_I2S_FLOW_STATUS_COUNTER_EN (1 << 1)
215#define TEGRA30_I2S_FLOW_STATUS_MONITOR_EN (1 << 0)
216
217/*
218 * There are no fields in TEGRA30_I2S_FLOW_TOTAL, TEGRA30_I2S_FLOW_OVER,
219 * TEGRA30_I2S_FLOW_UNDER; they are counters taking the whole register.
220 */
221
222/* Fields in TEGRA30_I2S_LCOEF_* */
223
224#define TEGRA30_I2S_LCOEF_COEF_SHIFT 0
225#define TEGRA30_I2S_LCOEF_COEF_MASK_US 0xffff
226#define TEGRA30_I2S_LCOEF_COEF_MASK (TEGRA30_I2S_LCOEF_COEF_MASK_US << TEGRA30_I2S_LCOEF_COEF_SHIFT)
227
228struct tegra30_i2s {
229 struct snd_soc_dai_driver dai;
230 int cif_id;
231 struct clk *clk_i2s;
232 enum tegra30_ahub_txcif capture_i2s_cif;
233 enum tegra30_ahub_rxcif capture_fifo_cif;
234 struct tegra_pcm_dma_params capture_dma_data;
235 enum tegra30_ahub_rxcif playback_i2s_cif;
236 enum tegra30_ahub_txcif playback_fifo_cif;
237 struct tegra_pcm_dma_params playback_dma_data;
238 struct regmap *regmap;
239 u32 reg_ctrl;
240};
241
242#endif
diff --git a/sound/soc/tegra/tegra_alc5632.c b/sound/soc/tegra/tegra_alc5632.c
index e45ccd851f6a..32de7006daf0 100644
--- a/sound/soc/tegra/tegra_alc5632.c
+++ b/sound/soc/tegra/tegra_alc5632.c
@@ -1,16 +1,17 @@
1/* 1/*
2* tegra_alc5632.c -- Toshiba AC100(PAZ00) machine ASoC driver 2 * tegra_alc5632.c -- Toshiba AC100(PAZ00) machine ASoC driver
3* 3 *
4* Copyright (C) 2011 The AC100 Kernel Team <ac100@lists.lauchpad.net> 4 * Copyright (C) 2011 The AC100 Kernel Team <ac100@lists.lauchpad.net>
5* 5 * Copyright (C) 2012 - NVIDIA, Inc.
6* Authors: Leon Romanovsky <leon@leon.nu> 6 *
7* Andrey Danin <danindrey@mail.ru> 7 * Authors: Leon Romanovsky <leon@leon.nu>
8* Marc Dietrich <marvin24@gmx.de> 8 * Andrey Danin <danindrey@mail.ru>
9* 9 * Marc Dietrich <marvin24@gmx.de>
10* This program is free software; you can redistribute it and/or modify 10 *
11* it under the terms of the GNU General Public License version 2 as 11 * This program is free software; you can redistribute it and/or modify
12* published by the Free Software Foundation. 12 * it under the terms of the GNU General Public License version 2 as
13*/ 13 * published by the Free Software Foundation.
14 */
14 15
15#include <asm/mach-types.h> 16#include <asm/mach-types.h>
16 17
@@ -28,9 +29,6 @@
28 29
29#include "../codecs/alc5632.h" 30#include "../codecs/alc5632.h"
30 31
31#include "tegra_das.h"
32#include "tegra_i2s.h"
33#include "tegra_pcm.h"
34#include "tegra_asoc_utils.h" 32#include "tegra_asoc_utils.h"
35 33
36#define DRV_NAME "tegra-alc5632" 34#define DRV_NAME "tegra-alc5632"
@@ -39,7 +37,6 @@
39 37
40struct tegra_alc5632 { 38struct tegra_alc5632 {
41 struct tegra_asoc_utils_data util_data; 39 struct tegra_asoc_utils_data util_data;
42 struct platform_device *pcm_dev;
43 int gpio_requested; 40 int gpio_requested;
44 int gpio_hp_det; 41 int gpio_hp_det;
45}; 42};
@@ -140,7 +137,6 @@ static int tegra_alc5632_asoc_init(struct snd_soc_pcm_runtime *rtd)
140static struct snd_soc_dai_link tegra_alc5632_dai = { 137static struct snd_soc_dai_link tegra_alc5632_dai = {
141 .name = "ALC5632", 138 .name = "ALC5632",
142 .stream_name = "ALC5632 PCM", 139 .stream_name = "ALC5632 PCM",
143 .platform_name = "tegra-pcm-audio",
144 .codec_dai_name = "alc5632-hifi", 140 .codec_dai_name = "alc5632-hifi",
145 .init = tegra_alc5632_asoc_init, 141 .init = tegra_alc5632_asoc_init,
146 .ops = &tegra_alc5632_asoc_ops, 142 .ops = &tegra_alc5632_asoc_ops,
@@ -179,8 +175,6 @@ static __devinit int tegra_alc5632_probe(struct platform_device *pdev)
179 platform_set_drvdata(pdev, card); 175 platform_set_drvdata(pdev, card);
180 snd_soc_card_set_drvdata(card, alc5632); 176 snd_soc_card_set_drvdata(card, alc5632);
181 177
182 alc5632->pcm_dev = ERR_PTR(-EINVAL);
183
184 if (!(pdev->dev.of_node)) { 178 if (!(pdev->dev.of_node)) {
185 dev_err(&pdev->dev, "Must be instantiated using device tree\n"); 179 dev_err(&pdev->dev, "Must be instantiated using device tree\n");
186 ret = -EINVAL; 180 ret = -EINVAL;
@@ -214,18 +208,11 @@ static __devinit int tegra_alc5632_probe(struct platform_device *pdev)
214 goto err; 208 goto err;
215 } 209 }
216 210
217 alc5632->pcm_dev = platform_device_register_simple( 211 tegra_alc5632_dai.platform_of_node = tegra_alc5632_dai.cpu_dai_of_node;
218 "tegra-pcm-audio", -1, NULL, 0);
219 if (IS_ERR(alc5632->pcm_dev)) {
220 dev_err(&pdev->dev,
221 "Can't instantiate tegra-pcm-audio\n");
222 ret = PTR_ERR(alc5632->pcm_dev);
223 goto err;
224 }
225 212
226 ret = tegra_asoc_utils_init(&alc5632->util_data, &pdev->dev); 213 ret = tegra_asoc_utils_init(&alc5632->util_data, &pdev->dev);
227 if (ret) 214 if (ret)
228 goto err_unregister; 215 goto err;
229 216
230 ret = snd_soc_register_card(card); 217 ret = snd_soc_register_card(card);
231 if (ret) { 218 if (ret) {
@@ -238,9 +225,6 @@ static __devinit int tegra_alc5632_probe(struct platform_device *pdev)
238 225
239err_fini_utils: 226err_fini_utils:
240 tegra_asoc_utils_fini(&alc5632->util_data); 227 tegra_asoc_utils_fini(&alc5632->util_data);
241err_unregister:
242 if (!IS_ERR(alc5632->pcm_dev))
243 platform_device_unregister(alc5632->pcm_dev);
244err: 228err:
245 return ret; 229 return ret;
246} 230}
@@ -259,8 +243,6 @@ static int __devexit tegra_alc5632_remove(struct platform_device *pdev)
259 snd_soc_unregister_card(card); 243 snd_soc_unregister_card(card);
260 244
261 tegra_asoc_utils_fini(&machine->util_data); 245 tegra_asoc_utils_fini(&machine->util_data);
262 if (!IS_ERR(machine->pcm_dev))
263 platform_device_unregister(machine->pcm_dev);
264 246
265 return 0; 247 return 0;
266} 248}
diff --git a/sound/soc/tegra/tegra_asoc_utils.c b/sound/soc/tegra/tegra_asoc_utils.c
index f8428e410e05..9515ce58ea02 100644
--- a/sound/soc/tegra/tegra_asoc_utils.c
+++ b/sound/soc/tegra/tegra_asoc_utils.c
@@ -2,7 +2,7 @@
2 * tegra_asoc_utils.c - Harmony machine ASoC driver 2 * tegra_asoc_utils.c - Harmony machine ASoC driver
3 * 3 *
4 * Author: Stephen Warren <swarren@nvidia.com> 4 * Author: Stephen Warren <swarren@nvidia.com>
5 * Copyright (C) 2010 - NVIDIA, Inc. 5 * Copyright (C) 2010,2012 - NVIDIA, Inc.
6 * 6 *
7 * This program is free software; you can redistribute it and/or 7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License 8 * modify it under the terms of the GNU General Public License
@@ -25,6 +25,7 @@
25#include <linux/err.h> 25#include <linux/err.h>
26#include <linux/kernel.h> 26#include <linux/kernel.h>
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/of.h>
28 29
29#include "tegra_asoc_utils.h" 30#include "tegra_asoc_utils.h"
30 31
@@ -40,7 +41,10 @@ int tegra_asoc_utils_set_rate(struct tegra_asoc_utils_data *data, int srate,
40 case 22050: 41 case 22050:
41 case 44100: 42 case 44100:
42 case 88200: 43 case 88200:
43 new_baseclock = 56448000; 44 if (data->soc == TEGRA_ASOC_UTILS_SOC_TEGRA20)
45 new_baseclock = 56448000;
46 else
47 new_baseclock = 564480000;
44 break; 48 break;
45 case 8000: 49 case 8000:
46 case 16000: 50 case 16000:
@@ -48,7 +52,10 @@ int tegra_asoc_utils_set_rate(struct tegra_asoc_utils_data *data, int srate,
48 case 48000: 52 case 48000:
49 case 64000: 53 case 64000:
50 case 96000: 54 case 96000:
51 new_baseclock = 73728000; 55 if (data->soc == TEGRA_ASOC_UTILS_SOC_TEGRA20)
56 new_baseclock = 73728000;
57 else
58 new_baseclock = 552960000;
52 break; 59 break;
53 default: 60 default:
54 return -EINVAL; 61 return -EINVAL;
@@ -78,7 +85,7 @@ int tegra_asoc_utils_set_rate(struct tegra_asoc_utils_data *data, int srate,
78 return err; 85 return err;
79 } 86 }
80 87
81 /* Don't set cdev1 rate; its locked to pll_a_out0 */ 88 /* Don't set cdev1/extern1 rate; it's locked to pll_a_out0 */
82 89
83 err = clk_enable(data->clk_pll_a); 90 err = clk_enable(data->clk_pll_a);
84 if (err) { 91 if (err) {
@@ -112,6 +119,17 @@ int tegra_asoc_utils_init(struct tegra_asoc_utils_data *data,
112 119
113 data->dev = dev; 120 data->dev = dev;
114 121
122 if (of_machine_is_compatible("nvidia,tegra20"))
123 data->soc = TEGRA_ASOC_UTILS_SOC_TEGRA20;
124 else if (of_machine_is_compatible("nvidia,tegra30"))
125 data->soc = TEGRA_ASOC_UTILS_SOC_TEGRA30;
126 else if (!dev->of_node)
127 /* non-DT is always Tegra20 */
128 data->soc = TEGRA_ASOC_UTILS_SOC_TEGRA20;
129 else
130 /* DT boot, but unknown SoC */
131 return -EINVAL;
132
115 data->clk_pll_a = clk_get_sys(NULL, "pll_a"); 133 data->clk_pll_a = clk_get_sys(NULL, "pll_a");
116 if (IS_ERR(data->clk_pll_a)) { 134 if (IS_ERR(data->clk_pll_a)) {
117 dev_err(data->dev, "Can't retrieve clk pll_a\n"); 135 dev_err(data->dev, "Can't retrieve clk pll_a\n");
@@ -126,15 +144,24 @@ int tegra_asoc_utils_init(struct tegra_asoc_utils_data *data,
126 goto err_put_pll_a; 144 goto err_put_pll_a;
127 } 145 }
128 146
129 data->clk_cdev1 = clk_get_sys(NULL, "cdev1"); 147 if (data->soc == TEGRA_ASOC_UTILS_SOC_TEGRA20)
148 data->clk_cdev1 = clk_get_sys(NULL, "cdev1");
149 else
150 data->clk_cdev1 = clk_get_sys("extern1", NULL);
130 if (IS_ERR(data->clk_cdev1)) { 151 if (IS_ERR(data->clk_cdev1)) {
131 dev_err(data->dev, "Can't retrieve clk cdev1\n"); 152 dev_err(data->dev, "Can't retrieve clk cdev1\n");
132 ret = PTR_ERR(data->clk_cdev1); 153 ret = PTR_ERR(data->clk_cdev1);
133 goto err_put_pll_a_out0; 154 goto err_put_pll_a_out0;
134 } 155 }
135 156
157 ret = tegra_asoc_utils_set_rate(data, 44100, 256 * 44100);
158 if (ret)
159 goto err_put_cdev1;
160
136 return 0; 161 return 0;
137 162
163err_put_cdev1:
164 clk_put(data->clk_cdev1);
138err_put_pll_a_out0: 165err_put_pll_a_out0:
139 clk_put(data->clk_pll_a_out0); 166 clk_put(data->clk_pll_a_out0);
140err_put_pll_a: 167err_put_pll_a:
diff --git a/sound/soc/tegra/tegra_asoc_utils.h b/sound/soc/tegra/tegra_asoc_utils.h
index 4818195da25c..44db1dbb8f21 100644
--- a/sound/soc/tegra/tegra_asoc_utils.h
+++ b/sound/soc/tegra/tegra_asoc_utils.h
@@ -2,7 +2,7 @@
2 * tegra_asoc_utils.h - Definitions for Tegra DAS driver 2 * tegra_asoc_utils.h - Definitions for Tegra DAS driver
3 * 3 *
4 * Author: Stephen Warren <swarren@nvidia.com> 4 * Author: Stephen Warren <swarren@nvidia.com>
5 * Copyright (C) 2010 - NVIDIA, Inc. 5 * Copyright (C) 2010,2012 - NVIDIA, Inc.
6 * 6 *
7 * This program is free software; you can redistribute it and/or 7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License 8 * modify it under the terms of the GNU General Public License
@@ -26,8 +26,14 @@
26struct clk; 26struct clk;
27struct device; 27struct device;
28 28
29enum tegra_asoc_utils_soc {
30 TEGRA_ASOC_UTILS_SOC_TEGRA20,
31 TEGRA_ASOC_UTILS_SOC_TEGRA30,
32};
33
29struct tegra_asoc_utils_data { 34struct tegra_asoc_utils_data {
30 struct device *dev; 35 struct device *dev;
36 enum tegra_asoc_utils_soc soc;
31 struct clk *clk_pll_a; 37 struct clk *clk_pll_a;
32 struct clk *clk_pll_a_out0; 38 struct clk *clk_pll_a_out0;
33 struct clk *clk_cdev1; 39 struct clk *clk_cdev1;
@@ -42,4 +48,3 @@ int tegra_asoc_utils_init(struct tegra_asoc_utils_data *data,
42void tegra_asoc_utils_fini(struct tegra_asoc_utils_data *data); 48void tegra_asoc_utils_fini(struct tegra_asoc_utils_data *data);
43 49
44#endif 50#endif
45
diff --git a/sound/soc/tegra/tegra_das.c b/sound/soc/tegra/tegra_das.c
deleted file mode 100644
index 3b3c1ba4d235..000000000000
--- a/sound/soc/tegra/tegra_das.c
+++ /dev/null
@@ -1,261 +0,0 @@
1/*
2 * tegra_das.c - Tegra DAS driver
3 *
4 * Author: Stephen Warren <swarren@nvidia.com>
5 * Copyright (C) 2010 - NVIDIA, Inc.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * version 2 as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19 * 02110-1301 USA
20 *
21 */
22
23#include <linux/module.h>
24#include <linux/debugfs.h>
25#include <linux/device.h>
26#include <linux/platform_device.h>
27#include <linux/seq_file.h>
28#include <linux/slab.h>
29#include <linux/io.h>
30#include <mach/iomap.h>
31#include <sound/soc.h>
32#include "tegra_das.h"
33
34#define DRV_NAME "tegra-das"
35
36static struct tegra_das *das;
37
38static inline void tegra_das_write(u32 reg, u32 val)
39{
40 __raw_writel(val, das->regs + reg);
41}
42
43static inline u32 tegra_das_read(u32 reg)
44{
45 return __raw_readl(das->regs + reg);
46}
47
48int tegra_das_connect_dap_to_dac(int dap, int dac)
49{
50 u32 addr;
51 u32 reg;
52
53 if (!das)
54 return -ENODEV;
55
56 addr = TEGRA_DAS_DAP_CTRL_SEL +
57 (dap * TEGRA_DAS_DAP_CTRL_SEL_STRIDE);
58 reg = dac << TEGRA_DAS_DAP_CTRL_SEL_DAP_CTRL_SEL_P;
59
60 tegra_das_write(addr, reg);
61
62 return 0;
63}
64EXPORT_SYMBOL_GPL(tegra_das_connect_dap_to_dac);
65
66int tegra_das_connect_dap_to_dap(int dap, int otherdap, int master,
67 int sdata1rx, int sdata2rx)
68{
69 u32 addr;
70 u32 reg;
71
72 if (!das)
73 return -ENODEV;
74
75 addr = TEGRA_DAS_DAP_CTRL_SEL +
76 (dap * TEGRA_DAS_DAP_CTRL_SEL_STRIDE);
77 reg = otherdap << TEGRA_DAS_DAP_CTRL_SEL_DAP_CTRL_SEL_P |
78 !!sdata2rx << TEGRA_DAS_DAP_CTRL_SEL_DAP_SDATA2_TX_RX_P |
79 !!sdata1rx << TEGRA_DAS_DAP_CTRL_SEL_DAP_SDATA1_TX_RX_P |
80 !!master << TEGRA_DAS_DAP_CTRL_SEL_DAP_MS_SEL_P;
81
82 tegra_das_write(addr, reg);
83
84 return 0;
85}
86EXPORT_SYMBOL_GPL(tegra_das_connect_dap_to_dap);
87
88int tegra_das_connect_dac_to_dap(int dac, int dap)
89{
90 u32 addr;
91 u32 reg;
92
93 if (!das)
94 return -ENODEV;
95
96 addr = TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL +
97 (dac * TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_STRIDE);
98 reg = dap << TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_CLK_SEL_P |
99 dap << TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_SDATA1_SEL_P |
100 dap << TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_SDATA2_SEL_P;
101
102 tegra_das_write(addr, reg);
103
104 return 0;
105}
106EXPORT_SYMBOL_GPL(tegra_das_connect_dac_to_dap);
107
108#ifdef CONFIG_DEBUG_FS
109static int tegra_das_show(struct seq_file *s, void *unused)
110{
111 int i;
112 u32 addr;
113 u32 reg;
114
115 for (i = 0; i < TEGRA_DAS_DAP_CTRL_SEL_COUNT; i++) {
116 addr = TEGRA_DAS_DAP_CTRL_SEL +
117 (i * TEGRA_DAS_DAP_CTRL_SEL_STRIDE);
118 reg = tegra_das_read(addr);
119 seq_printf(s, "TEGRA_DAS_DAP_CTRL_SEL[%d] = %08x\n", i, reg);
120 }
121
122 for (i = 0; i < TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_COUNT; i++) {
123 addr = TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL +
124 (i * TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_STRIDE);
125 reg = tegra_das_read(addr);
126 seq_printf(s, "TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL[%d] = %08x\n",
127 i, reg);
128 }
129
130 return 0;
131}
132
133static int tegra_das_debug_open(struct inode *inode, struct file *file)
134{
135 return single_open(file, tegra_das_show, inode->i_private);
136}
137
138static const struct file_operations tegra_das_debug_fops = {
139 .open = tegra_das_debug_open,
140 .read = seq_read,
141 .llseek = seq_lseek,
142 .release = single_release,
143};
144
145static void tegra_das_debug_add(struct tegra_das *das)
146{
147 das->debug = debugfs_create_file(DRV_NAME, S_IRUGO,
148 snd_soc_debugfs_root, das,
149 &tegra_das_debug_fops);
150}
151
152static void tegra_das_debug_remove(struct tegra_das *das)
153{
154 if (das->debug)
155 debugfs_remove(das->debug);
156}
157#else
158static inline void tegra_das_debug_add(struct tegra_das *das)
159{
160}
161
162static inline void tegra_das_debug_remove(struct tegra_das *das)
163{
164}
165#endif
166
167static int __devinit tegra_das_probe(struct platform_device *pdev)
168{
169 struct resource *res, *region;
170 int ret = 0;
171
172 if (das)
173 return -ENODEV;
174
175 das = devm_kzalloc(&pdev->dev, sizeof(struct tegra_das), GFP_KERNEL);
176 if (!das) {
177 dev_err(&pdev->dev, "Can't allocate tegra_das\n");
178 ret = -ENOMEM;
179 goto err;
180 }
181 das->dev = &pdev->dev;
182
183 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
184 if (!res) {
185 dev_err(&pdev->dev, "No memory resource\n");
186 ret = -ENODEV;
187 goto err;
188 }
189
190 region = devm_request_mem_region(&pdev->dev, res->start,
191 resource_size(res), pdev->name);
192 if (!region) {
193 dev_err(&pdev->dev, "Memory region already claimed\n");
194 ret = -EBUSY;
195 goto err;
196 }
197
198 das->regs = devm_ioremap(&pdev->dev, res->start, resource_size(res));
199 if (!das->regs) {
200 dev_err(&pdev->dev, "ioremap failed\n");
201 ret = -ENOMEM;
202 goto err;
203 }
204
205 ret = tegra_das_connect_dap_to_dac(TEGRA_DAS_DAP_ID_1,
206 TEGRA_DAS_DAP_SEL_DAC1);
207 if (ret) {
208 dev_err(&pdev->dev, "Can't set up DAS DAP connection\n");
209 goto err;
210 }
211 ret = tegra_das_connect_dac_to_dap(TEGRA_DAS_DAC_ID_1,
212 TEGRA_DAS_DAC_SEL_DAP1);
213 if (ret) {
214 dev_err(&pdev->dev, "Can't set up DAS DAC connection\n");
215 goto err;
216 }
217
218 tegra_das_debug_add(das);
219
220 platform_set_drvdata(pdev, das);
221
222 return 0;
223
224err:
225 das = NULL;
226 return ret;
227}
228
229static int __devexit tegra_das_remove(struct platform_device *pdev)
230{
231 if (!das)
232 return -ENODEV;
233
234 tegra_das_debug_remove(das);
235
236 das = NULL;
237
238 return 0;
239}
240
241static const struct of_device_id tegra_das_of_match[] __devinitconst = {
242 { .compatible = "nvidia,tegra20-das", },
243 {},
244};
245
246static struct platform_driver tegra_das_driver = {
247 .probe = tegra_das_probe,
248 .remove = __devexit_p(tegra_das_remove),
249 .driver = {
250 .name = DRV_NAME,
251 .owner = THIS_MODULE,
252 .of_match_table = tegra_das_of_match,
253 },
254};
255module_platform_driver(tegra_das_driver);
256
257MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>");
258MODULE_DESCRIPTION("Tegra DAS driver");
259MODULE_LICENSE("GPL");
260MODULE_ALIAS("platform:" DRV_NAME);
261MODULE_DEVICE_TABLE(of, tegra_das_of_match);
diff --git a/sound/soc/tegra/tegra_das.h b/sound/soc/tegra/tegra_das.h
deleted file mode 100644
index 2c96c7b3c459..000000000000
--- a/sound/soc/tegra/tegra_das.h
+++ /dev/null
@@ -1,135 +0,0 @@
1/*
2 * tegra_das.h - Definitions for Tegra DAS driver
3 *
4 * Author: Stephen Warren <swarren@nvidia.com>
5 * Copyright (C) 2010 - NVIDIA, Inc.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * version 2 as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19 * 02110-1301 USA
20 *
21 */
22
23#ifndef __TEGRA_DAS_H__
24#define __TEGRA_DAS_H__
25
26/* Register TEGRA_DAS_DAP_CTRL_SEL */
27#define TEGRA_DAS_DAP_CTRL_SEL 0x00
28#define TEGRA_DAS_DAP_CTRL_SEL_COUNT 5
29#define TEGRA_DAS_DAP_CTRL_SEL_STRIDE 4
30#define TEGRA_DAS_DAP_CTRL_SEL_DAP_MS_SEL_P 31
31#define TEGRA_DAS_DAP_CTRL_SEL_DAP_MS_SEL_S 1
32#define TEGRA_DAS_DAP_CTRL_SEL_DAP_SDATA1_TX_RX_P 30
33#define TEGRA_DAS_DAP_CTRL_SEL_DAP_SDATA1_TX_RX_S 1
34#define TEGRA_DAS_DAP_CTRL_SEL_DAP_SDATA2_TX_RX_P 29
35#define TEGRA_DAS_DAP_CTRL_SEL_DAP_SDATA2_TX_RX_S 1
36#define TEGRA_DAS_DAP_CTRL_SEL_DAP_CTRL_SEL_P 0
37#define TEGRA_DAS_DAP_CTRL_SEL_DAP_CTRL_SEL_S 5
38
39/* Values for field TEGRA_DAS_DAP_CTRL_SEL_DAP_CTRL_SEL */
40#define TEGRA_DAS_DAP_SEL_DAC1 0
41#define TEGRA_DAS_DAP_SEL_DAC2 1
42#define TEGRA_DAS_DAP_SEL_DAC3 2
43#define TEGRA_DAS_DAP_SEL_DAP1 16
44#define TEGRA_DAS_DAP_SEL_DAP2 17
45#define TEGRA_DAS_DAP_SEL_DAP3 18
46#define TEGRA_DAS_DAP_SEL_DAP4 19
47#define TEGRA_DAS_DAP_SEL_DAP5 20
48
49/* Register TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL */
50#define TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL 0x40
51#define TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_COUNT 3
52#define TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_STRIDE 4
53#define TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_SDATA2_SEL_P 28
54#define TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_SDATA2_SEL_S 4
55#define TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_SDATA1_SEL_P 24
56#define TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_SDATA1_SEL_S 4
57#define TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_CLK_SEL_P 0
58#define TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_CLK_SEL_S 4
59
60/*
61 * Values for:
62 * TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_SDATA2_SEL
63 * TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_SDATA1_SEL
64 * TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_CLK_SEL
65 */
66#define TEGRA_DAS_DAC_SEL_DAP1 0
67#define TEGRA_DAS_DAC_SEL_DAP2 1
68#define TEGRA_DAS_DAC_SEL_DAP3 2
69#define TEGRA_DAS_DAC_SEL_DAP4 3
70#define TEGRA_DAS_DAC_SEL_DAP5 4
71
72/*
73 * Names/IDs of the DACs/DAPs.
74 */
75
76#define TEGRA_DAS_DAP_ID_1 0
77#define TEGRA_DAS_DAP_ID_2 1
78#define TEGRA_DAS_DAP_ID_3 2
79#define TEGRA_DAS_DAP_ID_4 3
80#define TEGRA_DAS_DAP_ID_5 4
81
82#define TEGRA_DAS_DAC_ID_1 0
83#define TEGRA_DAS_DAC_ID_2 1
84#define TEGRA_DAS_DAC_ID_3 2
85
86struct tegra_das {
87 struct device *dev;
88 void __iomem *regs;
89 struct dentry *debug;
90};
91
92/*
93 * Terminology:
94 * DAS: Digital audio switch (HW module controlled by this driver)
95 * DAP: Digital audio port (port/pins on Tegra device)
96 * DAC: Digital audio controller (e.g. I2S or AC97 controller elsewhere)
97 *
98 * The Tegra DAS is a mux/cross-bar which can connect each DAP to a specific
99 * DAC, or another DAP. When DAPs are connected, one must be the master and
100 * one the slave. Each DAC allows selection of a specific DAP for input, to
101 * cater for the case where N DAPs are connected to 1 DAC for broadcast
102 * output.
103 *
104 * This driver is dumb; no attempt is made to ensure that a valid routing
105 * configuration is programmed.
106 */
107
108/*
109 * Connect a DAP to to a DAC
110 * dap_id: DAP to connect: TEGRA_DAS_DAP_ID_*
111 * dac_sel: DAC to connect to: TEGRA_DAS_DAP_SEL_DAC*
112 */
113extern int tegra_das_connect_dap_to_dac(int dap_id, int dac_sel);
114
115/*
116 * Connect a DAP to to another DAP
117 * dap_id: DAP to connect: TEGRA_DAS_DAP_ID_*
118 * other_dap_sel: DAP to connect to: TEGRA_DAS_DAP_SEL_DAP*
119 * master: Is this DAP the master (1) or slave (0)
120 * sdata1rx: Is this DAP's SDATA1 pin RX (1) or TX (0)
121 * sdata2rx: Is this DAP's SDATA2 pin RX (1) or TX (0)
122 */
123extern int tegra_das_connect_dap_to_dap(int dap_id, int other_dap_sel,
124 int master, int sdata1rx,
125 int sdata2rx);
126
127/*
128 * Connect a DAC's input to a DAP
129 * (DAC outputs are selected by the DAP)
130 * dac_id: DAC ID to connect: TEGRA_DAS_DAC_ID_*
131 * dap_sel: DAP to receive input from: TEGRA_DAS_DAC_SEL_DAP*
132 */
133extern int tegra_das_connect_dac_to_dap(int dac_id, int dap_sel);
134
135#endif
diff --git a/sound/soc/tegra/tegra_i2s.c b/sound/soc/tegra/tegra_i2s.c
deleted file mode 100644
index e53349912b2e..000000000000
--- a/sound/soc/tegra/tegra_i2s.c
+++ /dev/null
@@ -1,459 +0,0 @@
1/*
2 * tegra_i2s.c - Tegra I2S driver
3 *
4 * Author: Stephen Warren <swarren@nvidia.com>
5 * Copyright (C) 2010 - NVIDIA, Inc.
6 *
7 * Based on code copyright/by:
8 *
9 * Copyright (c) 2009-2010, NVIDIA Corporation.
10 * Scott Peterson <speterson@nvidia.com>
11 *
12 * Copyright (C) 2010 Google, Inc.
13 * Iliyan Malchev <malchev@google.com>
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * version 2 as published by the Free Software Foundation.
18 *
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
27 * 02110-1301 USA
28 *
29 */
30
31#include <linux/clk.h>
32#include <linux/module.h>
33#include <linux/debugfs.h>
34#include <linux/device.h>
35#include <linux/platform_device.h>
36#include <linux/seq_file.h>
37#include <linux/slab.h>
38#include <linux/io.h>
39#include <linux/of.h>
40#include <mach/iomap.h>
41#include <sound/core.h>
42#include <sound/pcm.h>
43#include <sound/pcm_params.h>
44#include <sound/soc.h>
45
46#include "tegra_i2s.h"
47
48#define DRV_NAME "tegra-i2s"
49
50static inline void tegra_i2s_write(struct tegra_i2s *i2s, u32 reg, u32 val)
51{
52 __raw_writel(val, i2s->regs + reg);
53}
54
55static inline u32 tegra_i2s_read(struct tegra_i2s *i2s, u32 reg)
56{
57 return __raw_readl(i2s->regs + reg);
58}
59
60#ifdef CONFIG_DEBUG_FS
61static int tegra_i2s_show(struct seq_file *s, void *unused)
62{
63#define REG(r) { r, #r }
64 static const struct {
65 int offset;
66 const char *name;
67 } regs[] = {
68 REG(TEGRA_I2S_CTRL),
69 REG(TEGRA_I2S_STATUS),
70 REG(TEGRA_I2S_TIMING),
71 REG(TEGRA_I2S_FIFO_SCR),
72 REG(TEGRA_I2S_PCM_CTRL),
73 REG(TEGRA_I2S_NW_CTRL),
74 REG(TEGRA_I2S_TDM_CTRL),
75 REG(TEGRA_I2S_TDM_TX_RX_CTRL),
76 };
77#undef REG
78
79 struct tegra_i2s *i2s = s->private;
80 int i;
81
82 clk_enable(i2s->clk_i2s);
83
84 for (i = 0; i < ARRAY_SIZE(regs); i++) {
85 u32 val = tegra_i2s_read(i2s, regs[i].offset);
86 seq_printf(s, "%s = %08x\n", regs[i].name, val);
87 }
88
89 clk_disable(i2s->clk_i2s);
90
91 return 0;
92}
93
94static int tegra_i2s_debug_open(struct inode *inode, struct file *file)
95{
96 return single_open(file, tegra_i2s_show, inode->i_private);
97}
98
99static const struct file_operations tegra_i2s_debug_fops = {
100 .open = tegra_i2s_debug_open,
101 .read = seq_read,
102 .llseek = seq_lseek,
103 .release = single_release,
104};
105
106static void tegra_i2s_debug_add(struct tegra_i2s *i2s)
107{
108 i2s->debug = debugfs_create_file(i2s->dai.name, S_IRUGO,
109 snd_soc_debugfs_root, i2s,
110 &tegra_i2s_debug_fops);
111}
112
113static void tegra_i2s_debug_remove(struct tegra_i2s *i2s)
114{
115 if (i2s->debug)
116 debugfs_remove(i2s->debug);
117}
118#else
119static inline void tegra_i2s_debug_add(struct tegra_i2s *i2s)
120{
121}
122
123static inline void tegra_i2s_debug_remove(struct tegra_i2s *i2s)
124{
125}
126#endif
127
128static int tegra_i2s_set_fmt(struct snd_soc_dai *dai,
129 unsigned int fmt)
130{
131 struct tegra_i2s *i2s = snd_soc_dai_get_drvdata(dai);
132
133 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
134 case SND_SOC_DAIFMT_NB_NF:
135 break;
136 default:
137 return -EINVAL;
138 }
139
140 i2s->reg_ctrl &= ~TEGRA_I2S_CTRL_MASTER_ENABLE;
141 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
142 case SND_SOC_DAIFMT_CBS_CFS:
143 i2s->reg_ctrl |= TEGRA_I2S_CTRL_MASTER_ENABLE;
144 break;
145 case SND_SOC_DAIFMT_CBM_CFM:
146 break;
147 default:
148 return -EINVAL;
149 }
150
151 i2s->reg_ctrl &= ~(TEGRA_I2S_CTRL_BIT_FORMAT_MASK |
152 TEGRA_I2S_CTRL_LRCK_MASK);
153 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
154 case SND_SOC_DAIFMT_DSP_A:
155 i2s->reg_ctrl |= TEGRA_I2S_CTRL_BIT_FORMAT_DSP;
156 i2s->reg_ctrl |= TEGRA_I2S_CTRL_LRCK_L_LOW;
157 break;
158 case SND_SOC_DAIFMT_DSP_B:
159 i2s->reg_ctrl |= TEGRA_I2S_CTRL_BIT_FORMAT_DSP;
160 i2s->reg_ctrl |= TEGRA_I2S_CTRL_LRCK_R_LOW;
161 break;
162 case SND_SOC_DAIFMT_I2S:
163 i2s->reg_ctrl |= TEGRA_I2S_CTRL_BIT_FORMAT_I2S;
164 i2s->reg_ctrl |= TEGRA_I2S_CTRL_LRCK_L_LOW;
165 break;
166 case SND_SOC_DAIFMT_RIGHT_J:
167 i2s->reg_ctrl |= TEGRA_I2S_CTRL_BIT_FORMAT_RJM;
168 i2s->reg_ctrl |= TEGRA_I2S_CTRL_LRCK_L_LOW;
169 break;
170 case SND_SOC_DAIFMT_LEFT_J:
171 i2s->reg_ctrl |= TEGRA_I2S_CTRL_BIT_FORMAT_LJM;
172 i2s->reg_ctrl |= TEGRA_I2S_CTRL_LRCK_L_LOW;
173 break;
174 default:
175 return -EINVAL;
176 }
177
178 return 0;
179}
180
181static int tegra_i2s_hw_params(struct snd_pcm_substream *substream,
182 struct snd_pcm_hw_params *params,
183 struct snd_soc_dai *dai)
184{
185 struct device *dev = substream->pcm->card->dev;
186 struct tegra_i2s *i2s = snd_soc_dai_get_drvdata(dai);
187 u32 reg;
188 int ret, sample_size, srate, i2sclock, bitcnt;
189
190 i2s->reg_ctrl &= ~TEGRA_I2S_CTRL_BIT_SIZE_MASK;
191 switch (params_format(params)) {
192 case SNDRV_PCM_FORMAT_S16_LE:
193 i2s->reg_ctrl |= TEGRA_I2S_CTRL_BIT_SIZE_16;
194 sample_size = 16;
195 break;
196 case SNDRV_PCM_FORMAT_S24_LE:
197 i2s->reg_ctrl |= TEGRA_I2S_CTRL_BIT_SIZE_24;
198 sample_size = 24;
199 break;
200 case SNDRV_PCM_FORMAT_S32_LE:
201 i2s->reg_ctrl |= TEGRA_I2S_CTRL_BIT_SIZE_32;
202 sample_size = 32;
203 break;
204 default:
205 return -EINVAL;
206 }
207
208 srate = params_rate(params);
209
210 /* Final "* 2" required by Tegra hardware */
211 i2sclock = srate * params_channels(params) * sample_size * 2;
212
213 ret = clk_set_rate(i2s->clk_i2s, i2sclock);
214 if (ret) {
215 dev_err(dev, "Can't set I2S clock rate: %d\n", ret);
216 return ret;
217 }
218
219 bitcnt = (i2sclock / (2 * srate)) - 1;
220 if (bitcnt < 0 || bitcnt > TEGRA_I2S_TIMING_CHANNEL_BIT_COUNT_MASK_US)
221 return -EINVAL;
222 reg = bitcnt << TEGRA_I2S_TIMING_CHANNEL_BIT_COUNT_SHIFT;
223
224 if (i2sclock % (2 * srate))
225 reg |= TEGRA_I2S_TIMING_NON_SYM_ENABLE;
226
227 if (!i2s->clk_refs)
228 clk_enable(i2s->clk_i2s);
229
230 tegra_i2s_write(i2s, TEGRA_I2S_TIMING, reg);
231
232 tegra_i2s_write(i2s, TEGRA_I2S_FIFO_SCR,
233 TEGRA_I2S_FIFO_SCR_FIFO2_ATN_LVL_FOUR_SLOTS |
234 TEGRA_I2S_FIFO_SCR_FIFO1_ATN_LVL_FOUR_SLOTS);
235
236 if (!i2s->clk_refs)
237 clk_disable(i2s->clk_i2s);
238
239 return 0;
240}
241
242static void tegra_i2s_start_playback(struct tegra_i2s *i2s)
243{
244 i2s->reg_ctrl |= TEGRA_I2S_CTRL_FIFO1_ENABLE;
245 tegra_i2s_write(i2s, TEGRA_I2S_CTRL, i2s->reg_ctrl);
246}
247
248static void tegra_i2s_stop_playback(struct tegra_i2s *i2s)
249{
250 i2s->reg_ctrl &= ~TEGRA_I2S_CTRL_FIFO1_ENABLE;
251 tegra_i2s_write(i2s, TEGRA_I2S_CTRL, i2s->reg_ctrl);
252}
253
254static void tegra_i2s_start_capture(struct tegra_i2s *i2s)
255{
256 i2s->reg_ctrl |= TEGRA_I2S_CTRL_FIFO2_ENABLE;
257 tegra_i2s_write(i2s, TEGRA_I2S_CTRL, i2s->reg_ctrl);
258}
259
260static void tegra_i2s_stop_capture(struct tegra_i2s *i2s)
261{
262 i2s->reg_ctrl &= ~TEGRA_I2S_CTRL_FIFO2_ENABLE;
263 tegra_i2s_write(i2s, TEGRA_I2S_CTRL, i2s->reg_ctrl);
264}
265
266static int tegra_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
267 struct snd_soc_dai *dai)
268{
269 struct tegra_i2s *i2s = snd_soc_dai_get_drvdata(dai);
270
271 switch (cmd) {
272 case SNDRV_PCM_TRIGGER_START:
273 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
274 case SNDRV_PCM_TRIGGER_RESUME:
275 if (!i2s->clk_refs)
276 clk_enable(i2s->clk_i2s);
277 i2s->clk_refs++;
278 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
279 tegra_i2s_start_playback(i2s);
280 else
281 tegra_i2s_start_capture(i2s);
282 break;
283 case SNDRV_PCM_TRIGGER_STOP:
284 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
285 case SNDRV_PCM_TRIGGER_SUSPEND:
286 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
287 tegra_i2s_stop_playback(i2s);
288 else
289 tegra_i2s_stop_capture(i2s);
290 i2s->clk_refs--;
291 if (!i2s->clk_refs)
292 clk_disable(i2s->clk_i2s);
293 break;
294 default:
295 return -EINVAL;
296 }
297
298 return 0;
299}
300
301static int tegra_i2s_probe(struct snd_soc_dai *dai)
302{
303 struct tegra_i2s * i2s = snd_soc_dai_get_drvdata(dai);
304
305 dai->capture_dma_data = &i2s->capture_dma_data;
306 dai->playback_dma_data = &i2s->playback_dma_data;
307
308 return 0;
309}
310
311static const struct snd_soc_dai_ops tegra_i2s_dai_ops = {
312 .set_fmt = tegra_i2s_set_fmt,
313 .hw_params = tegra_i2s_hw_params,
314 .trigger = tegra_i2s_trigger,
315};
316
317static const struct snd_soc_dai_driver tegra_i2s_dai_template = {
318 .probe = tegra_i2s_probe,
319 .playback = {
320 .channels_min = 2,
321 .channels_max = 2,
322 .rates = SNDRV_PCM_RATE_8000_96000,
323 .formats = SNDRV_PCM_FMTBIT_S16_LE,
324 },
325 .capture = {
326 .channels_min = 2,
327 .channels_max = 2,
328 .rates = SNDRV_PCM_RATE_8000_96000,
329 .formats = SNDRV_PCM_FMTBIT_S16_LE,
330 },
331 .ops = &tegra_i2s_dai_ops,
332 .symmetric_rates = 1,
333};
334
335static __devinit int tegra_i2s_platform_probe(struct platform_device *pdev)
336{
337 struct tegra_i2s * i2s;
338 struct resource *mem, *memregion, *dmareq;
339 u32 of_dma[2];
340 u32 dma_ch;
341 int ret;
342
343 i2s = devm_kzalloc(&pdev->dev, sizeof(struct tegra_i2s), GFP_KERNEL);
344 if (!i2s) {
345 dev_err(&pdev->dev, "Can't allocate tegra_i2s\n");
346 ret = -ENOMEM;
347 goto err;
348 }
349 dev_set_drvdata(&pdev->dev, i2s);
350
351 i2s->dai = tegra_i2s_dai_template;
352 i2s->dai.name = dev_name(&pdev->dev);
353
354 i2s->clk_i2s = clk_get(&pdev->dev, NULL);
355 if (IS_ERR(i2s->clk_i2s)) {
356 dev_err(&pdev->dev, "Can't retrieve i2s clock\n");
357 ret = PTR_ERR(i2s->clk_i2s);
358 goto err;
359 }
360
361 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
362 if (!mem) {
363 dev_err(&pdev->dev, "No memory resource\n");
364 ret = -ENODEV;
365 goto err_clk_put;
366 }
367
368 dmareq = platform_get_resource(pdev, IORESOURCE_DMA, 0);
369 if (!dmareq) {
370 if (of_property_read_u32_array(pdev->dev.of_node,
371 "nvidia,dma-request-selector",
372 of_dma, 2) < 0) {
373 dev_err(&pdev->dev, "No DMA resource\n");
374 ret = -ENODEV;
375 goto err_clk_put;
376 }
377 dma_ch = of_dma[1];
378 } else {
379 dma_ch = dmareq->start;
380 }
381
382 memregion = devm_request_mem_region(&pdev->dev, mem->start,
383 resource_size(mem), DRV_NAME);
384 if (!memregion) {
385 dev_err(&pdev->dev, "Memory region already claimed\n");
386 ret = -EBUSY;
387 goto err_clk_put;
388 }
389
390 i2s->regs = devm_ioremap(&pdev->dev, mem->start, resource_size(mem));
391 if (!i2s->regs) {
392 dev_err(&pdev->dev, "ioremap failed\n");
393 ret = -ENOMEM;
394 goto err_clk_put;
395 }
396
397 i2s->capture_dma_data.addr = mem->start + TEGRA_I2S_FIFO2;
398 i2s->capture_dma_data.wrap = 4;
399 i2s->capture_dma_data.width = 32;
400 i2s->capture_dma_data.req_sel = dma_ch;
401
402 i2s->playback_dma_data.addr = mem->start + TEGRA_I2S_FIFO1;
403 i2s->playback_dma_data.wrap = 4;
404 i2s->playback_dma_data.width = 32;
405 i2s->playback_dma_data.req_sel = dma_ch;
406
407 i2s->reg_ctrl = TEGRA_I2S_CTRL_FIFO_FORMAT_PACKED;
408
409 ret = snd_soc_register_dai(&pdev->dev, &i2s->dai);
410 if (ret) {
411 dev_err(&pdev->dev, "Could not register DAI: %d\n", ret);
412 ret = -ENOMEM;
413 goto err_clk_put;
414 }
415
416 tegra_i2s_debug_add(i2s);
417
418 return 0;
419
420err_clk_put:
421 clk_put(i2s->clk_i2s);
422err:
423 return ret;
424}
425
426static int __devexit tegra_i2s_platform_remove(struct platform_device *pdev)
427{
428 struct tegra_i2s *i2s = dev_get_drvdata(&pdev->dev);
429
430 snd_soc_unregister_dai(&pdev->dev);
431
432 tegra_i2s_debug_remove(i2s);
433
434 clk_put(i2s->clk_i2s);
435
436 return 0;
437}
438
439static const struct of_device_id tegra_i2s_of_match[] __devinitconst = {
440 { .compatible = "nvidia,tegra20-i2s", },
441 {},
442};
443
444static struct platform_driver tegra_i2s_driver = {
445 .driver = {
446 .name = DRV_NAME,
447 .owner = THIS_MODULE,
448 .of_match_table = tegra_i2s_of_match,
449 },
450 .probe = tegra_i2s_platform_probe,
451 .remove = __devexit_p(tegra_i2s_platform_remove),
452};
453module_platform_driver(tegra_i2s_driver);
454
455MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>");
456MODULE_DESCRIPTION("Tegra I2S ASoC driver");
457MODULE_LICENSE("GPL");
458MODULE_ALIAS("platform:" DRV_NAME);
459MODULE_DEVICE_TABLE(of, tegra_i2s_of_match);
diff --git a/sound/soc/tegra/tegra_i2s.h b/sound/soc/tegra/tegra_i2s.h
deleted file mode 100644
index 15ce1e2e8bde..000000000000
--- a/sound/soc/tegra/tegra_i2s.h
+++ /dev/null
@@ -1,166 +0,0 @@
1/*
2 * tegra_i2s.h - Definitions for Tegra I2S driver
3 *
4 * Author: Stephen Warren <swarren@nvidia.com>
5 * Copyright (C) 2010 - NVIDIA, Inc.
6 *
7 * Based on code copyright/by:
8 *
9 * Copyright (c) 2009-2010, NVIDIA Corporation.
10 * Scott Peterson <speterson@nvidia.com>
11 *
12 * Copyright (C) 2010 Google, Inc.
13 * Iliyan Malchev <malchev@google.com>
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * version 2 as published by the Free Software Foundation.
18 *
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
27 * 02110-1301 USA
28 *
29 */
30
31#ifndef __TEGRA_I2S_H__
32#define __TEGRA_I2S_H__
33
34#include "tegra_pcm.h"
35
36/* Register offsets from TEGRA_I2S1_BASE and TEGRA_I2S2_BASE */
37
38#define TEGRA_I2S_CTRL 0x00
39#define TEGRA_I2S_STATUS 0x04
40#define TEGRA_I2S_TIMING 0x08
41#define TEGRA_I2S_FIFO_SCR 0x0c
42#define TEGRA_I2S_PCM_CTRL 0x10
43#define TEGRA_I2S_NW_CTRL 0x14
44#define TEGRA_I2S_TDM_CTRL 0x20
45#define TEGRA_I2S_TDM_TX_RX_CTRL 0x24
46#define TEGRA_I2S_FIFO1 0x40
47#define TEGRA_I2S_FIFO2 0x80
48
49/* Fields in TEGRA_I2S_CTRL */
50
51#define TEGRA_I2S_CTRL_FIFO2_TX_ENABLE (1 << 30)
52#define TEGRA_I2S_CTRL_FIFO1_ENABLE (1 << 29)
53#define TEGRA_I2S_CTRL_FIFO2_ENABLE (1 << 28)
54#define TEGRA_I2S_CTRL_FIFO1_RX_ENABLE (1 << 27)
55#define TEGRA_I2S_CTRL_FIFO_LPBK_ENABLE (1 << 26)
56#define TEGRA_I2S_CTRL_MASTER_ENABLE (1 << 25)
57
58#define TEGRA_I2S_LRCK_LEFT_LOW 0
59#define TEGRA_I2S_LRCK_RIGHT_LOW 1
60
61#define TEGRA_I2S_CTRL_LRCK_SHIFT 24
62#define TEGRA_I2S_CTRL_LRCK_MASK (1 << TEGRA_I2S_CTRL_LRCK_SHIFT)
63#define TEGRA_I2S_CTRL_LRCK_L_LOW (TEGRA_I2S_LRCK_LEFT_LOW << TEGRA_I2S_CTRL_LRCK_SHIFT)
64#define TEGRA_I2S_CTRL_LRCK_R_LOW (TEGRA_I2S_LRCK_RIGHT_LOW << TEGRA_I2S_CTRL_LRCK_SHIFT)
65
66#define TEGRA_I2S_BIT_FORMAT_I2S 0
67#define TEGRA_I2S_BIT_FORMAT_RJM 1
68#define TEGRA_I2S_BIT_FORMAT_LJM 2
69#define TEGRA_I2S_BIT_FORMAT_DSP 3
70
71#define TEGRA_I2S_CTRL_BIT_FORMAT_SHIFT 10
72#define TEGRA_I2S_CTRL_BIT_FORMAT_MASK (3 << TEGRA_I2S_CTRL_BIT_FORMAT_SHIFT)
73#define TEGRA_I2S_CTRL_BIT_FORMAT_I2S (TEGRA_I2S_BIT_FORMAT_I2S << TEGRA_I2S_CTRL_BIT_FORMAT_SHIFT)
74#define TEGRA_I2S_CTRL_BIT_FORMAT_RJM (TEGRA_I2S_BIT_FORMAT_RJM << TEGRA_I2S_CTRL_BIT_FORMAT_SHIFT)
75#define TEGRA_I2S_CTRL_BIT_FORMAT_LJM (TEGRA_I2S_BIT_FORMAT_LJM << TEGRA_I2S_CTRL_BIT_FORMAT_SHIFT)
76#define TEGRA_I2S_CTRL_BIT_FORMAT_DSP (TEGRA_I2S_BIT_FORMAT_DSP << TEGRA_I2S_CTRL_BIT_FORMAT_SHIFT)
77
78#define TEGRA_I2S_BIT_SIZE_16 0
79#define TEGRA_I2S_BIT_SIZE_20 1
80#define TEGRA_I2S_BIT_SIZE_24 2
81#define TEGRA_I2S_BIT_SIZE_32 3
82
83#define TEGRA_I2S_CTRL_BIT_SIZE_SHIFT 8
84#define TEGRA_I2S_CTRL_BIT_SIZE_MASK (3 << TEGRA_I2S_CTRL_BIT_SIZE_SHIFT)
85#define TEGRA_I2S_CTRL_BIT_SIZE_16 (TEGRA_I2S_BIT_SIZE_16 << TEGRA_I2S_CTRL_BIT_SIZE_SHIFT)
86#define TEGRA_I2S_CTRL_BIT_SIZE_20 (TEGRA_I2S_BIT_SIZE_20 << TEGRA_I2S_CTRL_BIT_SIZE_SHIFT)
87#define TEGRA_I2S_CTRL_BIT_SIZE_24 (TEGRA_I2S_BIT_SIZE_24 << TEGRA_I2S_CTRL_BIT_SIZE_SHIFT)
88#define TEGRA_I2S_CTRL_BIT_SIZE_32 (TEGRA_I2S_BIT_SIZE_32 << TEGRA_I2S_CTRL_BIT_SIZE_SHIFT)
89
90#define TEGRA_I2S_FIFO_16_LSB 0
91#define TEGRA_I2S_FIFO_20_LSB 1
92#define TEGRA_I2S_FIFO_24_LSB 2
93#define TEGRA_I2S_FIFO_32 3
94#define TEGRA_I2S_FIFO_PACKED 7
95
96#define TEGRA_I2S_CTRL_FIFO_FORMAT_SHIFT 4
97#define TEGRA_I2S_CTRL_FIFO_FORMAT_MASK (7 << TEGRA_I2S_CTRL_FIFO_FORMAT_SHIFT)
98#define TEGRA_I2S_CTRL_FIFO_FORMAT_16_LSB (TEGRA_I2S_FIFO_16_LSB << TEGRA_I2S_CTRL_FIFO_FORMAT_SHIFT)
99#define TEGRA_I2S_CTRL_FIFO_FORMAT_20_LSB (TEGRA_I2S_FIFO_20_LSB << TEGRA_I2S_CTRL_FIFO_FORMAT_SHIFT)
100#define TEGRA_I2S_CTRL_FIFO_FORMAT_24_LSB (TEGRA_I2S_FIFO_24_LSB << TEGRA_I2S_CTRL_FIFO_FORMAT_SHIFT)
101#define TEGRA_I2S_CTRL_FIFO_FORMAT_32 (TEGRA_I2S_FIFO_32 << TEGRA_I2S_CTRL_FIFO_FORMAT_SHIFT)
102#define TEGRA_I2S_CTRL_FIFO_FORMAT_PACKED (TEGRA_I2S_FIFO_PACKED << TEGRA_I2S_CTRL_FIFO_FORMAT_SHIFT)
103
104#define TEGRA_I2S_CTRL_IE_FIFO1_ERR (1 << 3)
105#define TEGRA_I2S_CTRL_IE_FIFO2_ERR (1 << 2)
106#define TEGRA_I2S_CTRL_QE_FIFO1 (1 << 1)
107#define TEGRA_I2S_CTRL_QE_FIFO2 (1 << 0)
108
109/* Fields in TEGRA_I2S_STATUS */
110
111#define TEGRA_I2S_STATUS_FIFO1_RDY (1 << 31)
112#define TEGRA_I2S_STATUS_FIFO2_RDY (1 << 30)
113#define TEGRA_I2S_STATUS_FIFO1_BSY (1 << 29)
114#define TEGRA_I2S_STATUS_FIFO2_BSY (1 << 28)
115#define TEGRA_I2S_STATUS_FIFO1_ERR (1 << 3)
116#define TEGRA_I2S_STATUS_FIFO2_ERR (1 << 2)
117#define TEGRA_I2S_STATUS_QS_FIFO1 (1 << 1)
118#define TEGRA_I2S_STATUS_QS_FIFO2 (1 << 0)
119
120/* Fields in TEGRA_I2S_TIMING */
121
122#define TEGRA_I2S_TIMING_NON_SYM_ENABLE (1 << 12)
123#define TEGRA_I2S_TIMING_CHANNEL_BIT_COUNT_SHIFT 0
124#define TEGRA_I2S_TIMING_CHANNEL_BIT_COUNT_MASK_US 0x7fff
125#define TEGRA_I2S_TIMING_CHANNEL_BIT_COUNT_MASK (TEGRA_I2S_TIMING_CHANNEL_BIT_COUNT_MASK_US << TEGRA_I2S_TIMING_CHANNEL_BIT_COUNT_SHIFT)
126
127/* Fields in TEGRA_I2S_FIFO_SCR */
128
129#define TEGRA_I2S_FIFO_SCR_FIFO2_FULL_EMPTY_COUNT_SHIFT 24
130#define TEGRA_I2S_FIFO_SCR_FIFO1_FULL_EMPTY_COUNT_SHIFT 16
131#define TEGRA_I2S_FIFO_SCR_FIFO_FULL_EMPTY_COUNT_MASK 0x3f
132
133#define TEGRA_I2S_FIFO_SCR_FIFO2_CLR (1 << 12)
134#define TEGRA_I2S_FIFO_SCR_FIFO1_CLR (1 << 8)
135
136#define TEGRA_I2S_FIFO_ATN_LVL_ONE_SLOT 0
137#define TEGRA_I2S_FIFO_ATN_LVL_FOUR_SLOTS 1
138#define TEGRA_I2S_FIFO_ATN_LVL_EIGHT_SLOTS 2
139#define TEGRA_I2S_FIFO_ATN_LVL_TWELVE_SLOTS 3
140
141#define TEGRA_I2S_FIFO_SCR_FIFO2_ATN_LVL_SHIFT 4
142#define TEGRA_I2S_FIFO_SCR_FIFO2_ATN_LVL_MASK (3 << TEGRA_I2S_FIFO_SCR_FIFO2_ATN_LVL_SHIFT)
143#define TEGRA_I2S_FIFO_SCR_FIFO2_ATN_LVL_ONE_SLOT (TEGRA_I2S_FIFO_ATN_LVL_ONE_SLOT << TEGRA_I2S_FIFO_SCR_FIFO2_ATN_LVL_SHIFT)
144#define TEGRA_I2S_FIFO_SCR_FIFO2_ATN_LVL_FOUR_SLOTS (TEGRA_I2S_FIFO_ATN_LVL_FOUR_SLOTS << TEGRA_I2S_FIFO_SCR_FIFO2_ATN_LVL_SHIFT)
145#define TEGRA_I2S_FIFO_SCR_FIFO2_ATN_LVL_EIGHT_SLOTS (TEGRA_I2S_FIFO_ATN_LVL_EIGHT_SLOTS << TEGRA_I2S_FIFO_SCR_FIFO2_ATN_LVL_SHIFT)
146#define TEGRA_I2S_FIFO_SCR_FIFO2_ATN_LVL_TWELVE_SLOTS (TEGRA_I2S_FIFO_ATN_LVL_TWELVE_SLOTS << TEGRA_I2S_FIFO_SCR_FIFO2_ATN_LVL_SHIFT)
147
148#define TEGRA_I2S_FIFO_SCR_FIFO1_ATN_LVL_SHIFT 0
149#define TEGRA_I2S_FIFO_SCR_FIFO1_ATN_LVL_MASK (3 << TEGRA_I2S_FIFO_SCR_FIFO1_ATN_LVL_SHIFT)
150#define TEGRA_I2S_FIFO_SCR_FIFO1_ATN_LVL_ONE_SLOT (TEGRA_I2S_FIFO_ATN_LVL_ONE_SLOT << TEGRA_I2S_FIFO_SCR_FIFO1_ATN_LVL_SHIFT)
151#define TEGRA_I2S_FIFO_SCR_FIFO1_ATN_LVL_FOUR_SLOTS (TEGRA_I2S_FIFO_ATN_LVL_FOUR_SLOTS << TEGRA_I2S_FIFO_SCR_FIFO1_ATN_LVL_SHIFT)
152#define TEGRA_I2S_FIFO_SCR_FIFO1_ATN_LVL_EIGHT_SLOTS (TEGRA_I2S_FIFO_ATN_LVL_EIGHT_SLOTS << TEGRA_I2S_FIFO_SCR_FIFO1_ATN_LVL_SHIFT)
153#define TEGRA_I2S_FIFO_SCR_FIFO1_ATN_LVL_TWELVE_SLOTS (TEGRA_I2S_FIFO_ATN_LVL_TWELVE_SLOTS << TEGRA_I2S_FIFO_SCR_FIFO1_ATN_LVL_SHIFT)
154
155struct tegra_i2s {
156 struct snd_soc_dai_driver dai;
157 struct clk *clk_i2s;
158 int clk_refs;
159 struct tegra_pcm_dma_params capture_dma_data;
160 struct tegra_pcm_dma_params playback_dma_data;
161 void __iomem *regs;
162 struct dentry *debug;
163 u32 reg_ctrl;
164};
165
166#endif
diff --git a/sound/soc/tegra/tegra_pcm.c b/sound/soc/tegra/tegra_pcm.c
index 8b4457137c7c..127348dc09b1 100644
--- a/sound/soc/tegra/tegra_pcm.c
+++ b/sound/soc/tegra/tegra_pcm.c
@@ -2,7 +2,7 @@
2 * tegra_pcm.c - Tegra PCM driver 2 * tegra_pcm.c - Tegra PCM driver
3 * 3 *
4 * Author: Stephen Warren <swarren@nvidia.com> 4 * Author: Stephen Warren <swarren@nvidia.com>
5 * Copyright (C) 2010 - NVIDIA, Inc. 5 * Copyright (C) 2010,2012 - NVIDIA, Inc.
6 * 6 *
7 * Based on code copyright/by: 7 * Based on code copyright/by:
8 * 8 *
@@ -29,8 +29,8 @@
29 * 29 *
30 */ 30 */
31 31
32#include <linux/module.h>
33#include <linux/dma-mapping.h> 32#include <linux/dma-mapping.h>
33#include <linux/module.h>
34#include <linux/slab.h> 34#include <linux/slab.h>
35#include <sound/core.h> 35#include <sound/core.h>
36#include <sound/pcm.h> 36#include <sound/pcm.h>
@@ -39,8 +39,6 @@
39 39
40#include "tegra_pcm.h" 40#include "tegra_pcm.h"
41 41
42#define DRV_NAME "tegra-pcm-audio"
43
44static const struct snd_pcm_hardware tegra_pcm_hardware = { 42static const struct snd_pcm_hardware tegra_pcm_hardware = {
45 .info = SNDRV_PCM_INFO_MMAP | 43 .info = SNDRV_PCM_INFO_MMAP |
46 SNDRV_PCM_INFO_MMAP_VALID | 44 SNDRV_PCM_INFO_MMAP_VALID |
@@ -372,28 +370,18 @@ static struct snd_soc_platform_driver tegra_pcm_platform = {
372 .pcm_free = tegra_pcm_free, 370 .pcm_free = tegra_pcm_free,
373}; 371};
374 372
375static int __devinit tegra_pcm_platform_probe(struct platform_device *pdev) 373int __devinit tegra_pcm_platform_register(struct device *dev)
376{ 374{
377 return snd_soc_register_platform(&pdev->dev, &tegra_pcm_platform); 375 return snd_soc_register_platform(dev, &tegra_pcm_platform);
378} 376}
377EXPORT_SYMBOL_GPL(tegra_pcm_platform_register);
379 378
380static int __devexit tegra_pcm_platform_remove(struct platform_device *pdev) 379void __devexit tegra_pcm_platform_unregister(struct device *dev)
381{ 380{
382 snd_soc_unregister_platform(&pdev->dev); 381 snd_soc_unregister_platform(dev);
383 return 0;
384} 382}
385 383EXPORT_SYMBOL_GPL(tegra_pcm_platform_unregister);
386static struct platform_driver tegra_pcm_driver = {
387 .driver = {
388 .name = DRV_NAME,
389 .owner = THIS_MODULE,
390 },
391 .probe = tegra_pcm_platform_probe,
392 .remove = __devexit_p(tegra_pcm_platform_remove),
393};
394module_platform_driver(tegra_pcm_driver);
395 384
396MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>"); 385MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>");
397MODULE_DESCRIPTION("Tegra PCM ASoC driver"); 386MODULE_DESCRIPTION("Tegra PCM ASoC driver");
398MODULE_LICENSE("GPL"); 387MODULE_LICENSE("GPL");
399MODULE_ALIAS("platform:" DRV_NAME);
diff --git a/sound/soc/tegra/tegra_pcm.h b/sound/soc/tegra/tegra_pcm.h
index dbb90339fe0d..985d418a35e7 100644
--- a/sound/soc/tegra/tegra_pcm.h
+++ b/sound/soc/tegra/tegra_pcm.h
@@ -2,7 +2,7 @@
2 * tegra_pcm.h - Definitions for Tegra PCM driver 2 * tegra_pcm.h - Definitions for Tegra PCM driver
3 * 3 *
4 * Author: Stephen Warren <swarren@nvidia.com> 4 * Author: Stephen Warren <swarren@nvidia.com>
5 * Copyright (C) 2010 - NVIDIA, Inc. 5 * Copyright (C) 2010,2012 - NVIDIA, Inc.
6 * 6 *
7 * Based on code copyright/by: 7 * Based on code copyright/by:
8 * 8 *
@@ -52,4 +52,7 @@ struct tegra_runtime_data {
52 struct tegra_dma_channel *dma_chan; 52 struct tegra_dma_channel *dma_chan;
53}; 53};
54 54
55int tegra_pcm_platform_register(struct device *dev);
56void tegra_pcm_platform_unregister(struct device *dev);
57
55#endif 58#endif
diff --git a/sound/soc/tegra/tegra_spdif.c b/sound/soc/tegra/tegra_spdif.c
deleted file mode 100644
index 9ff2c601445f..000000000000
--- a/sound/soc/tegra/tegra_spdif.c
+++ /dev/null
@@ -1,364 +0,0 @@
1/*
2 * tegra_spdif.c - Tegra SPDIF driver
3 *
4 * Author: Stephen Warren <swarren@nvidia.com>
5 * Copyright (C) 2011 - NVIDIA, Inc.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * version 2 as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19 * 02110-1301 USA
20 *
21 */
22
23#include <linux/clk.h>
24#include <linux/module.h>
25#include <linux/debugfs.h>
26#include <linux/device.h>
27#include <linux/platform_device.h>
28#include <linux/seq_file.h>
29#include <linux/slab.h>
30#include <linux/io.h>
31#include <mach/iomap.h>
32#include <sound/core.h>
33#include <sound/pcm.h>
34#include <sound/pcm_params.h>
35#include <sound/soc.h>
36
37#include "tegra_spdif.h"
38
39#define DRV_NAME "tegra-spdif"
40
41static inline void tegra_spdif_write(struct tegra_spdif *spdif, u32 reg,
42 u32 val)
43{
44 __raw_writel(val, spdif->regs + reg);
45}
46
47static inline u32 tegra_spdif_read(struct tegra_spdif *spdif, u32 reg)
48{
49 return __raw_readl(spdif->regs + reg);
50}
51
52#ifdef CONFIG_DEBUG_FS
53static int tegra_spdif_show(struct seq_file *s, void *unused)
54{
55#define REG(r) { r, #r }
56 static const struct {
57 int offset;
58 const char *name;
59 } regs[] = {
60 REG(TEGRA_SPDIF_CTRL),
61 REG(TEGRA_SPDIF_STATUS),
62 REG(TEGRA_SPDIF_STROBE_CTRL),
63 REG(TEGRA_SPDIF_DATA_FIFO_CSR),
64 REG(TEGRA_SPDIF_CH_STA_RX_A),
65 REG(TEGRA_SPDIF_CH_STA_RX_B),
66 REG(TEGRA_SPDIF_CH_STA_RX_C),
67 REG(TEGRA_SPDIF_CH_STA_RX_D),
68 REG(TEGRA_SPDIF_CH_STA_RX_E),
69 REG(TEGRA_SPDIF_CH_STA_RX_F),
70 REG(TEGRA_SPDIF_CH_STA_TX_A),
71 REG(TEGRA_SPDIF_CH_STA_TX_B),
72 REG(TEGRA_SPDIF_CH_STA_TX_C),
73 REG(TEGRA_SPDIF_CH_STA_TX_D),
74 REG(TEGRA_SPDIF_CH_STA_TX_E),
75 REG(TEGRA_SPDIF_CH_STA_TX_F),
76 };
77#undef REG
78
79 struct tegra_spdif *spdif = s->private;
80 int i;
81
82 clk_enable(spdif->clk_spdif_out);
83
84 for (i = 0; i < ARRAY_SIZE(regs); i++) {
85 u32 val = tegra_spdif_read(spdif, regs[i].offset);
86 seq_printf(s, "%s = %08x\n", regs[i].name, val);
87 }
88
89 clk_disable(spdif->clk_spdif_out);
90
91 return 0;
92}
93
94static int tegra_spdif_debug_open(struct inode *inode, struct file *file)
95{
96 return single_open(file, tegra_spdif_show, inode->i_private);
97}
98
99static const struct file_operations tegra_spdif_debug_fops = {
100 .open = tegra_spdif_debug_open,
101 .read = seq_read,
102 .llseek = seq_lseek,
103 .release = single_release,
104};
105
106static void tegra_spdif_debug_add(struct tegra_spdif *spdif)
107{
108 spdif->debug = debugfs_create_file(DRV_NAME, S_IRUGO,
109 snd_soc_debugfs_root, spdif,
110 &tegra_spdif_debug_fops);
111}
112
113static void tegra_spdif_debug_remove(struct tegra_spdif *spdif)
114{
115 if (spdif->debug)
116 debugfs_remove(spdif->debug);
117}
118#else
119static inline void tegra_spdif_debug_add(struct tegra_spdif *spdif)
120{
121}
122
123static inline void tegra_spdif_debug_remove(struct tegra_spdif *spdif)
124{
125}
126#endif
127
128static int tegra_spdif_hw_params(struct snd_pcm_substream *substream,
129 struct snd_pcm_hw_params *params,
130 struct snd_soc_dai *dai)
131{
132 struct device *dev = substream->pcm->card->dev;
133 struct tegra_spdif *spdif = snd_soc_dai_get_drvdata(dai);
134 int ret, spdifclock;
135
136 spdif->reg_ctrl &= ~TEGRA_SPDIF_CTRL_PACK;
137 spdif->reg_ctrl &= ~TEGRA_SPDIF_CTRL_BIT_MODE_MASK;
138 switch (params_format(params)) {
139 case SNDRV_PCM_FORMAT_S16_LE:
140 spdif->reg_ctrl |= TEGRA_SPDIF_CTRL_PACK;
141 spdif->reg_ctrl |= TEGRA_SPDIF_CTRL_BIT_MODE_16BIT;
142 break;
143 default:
144 return -EINVAL;
145 }
146
147 switch (params_rate(params)) {
148 case 32000:
149 spdifclock = 4096000;
150 break;
151 case 44100:
152 spdifclock = 5644800;
153 break;
154 case 48000:
155 spdifclock = 6144000;
156 break;
157 case 88200:
158 spdifclock = 11289600;
159 break;
160 case 96000:
161 spdifclock = 12288000;
162 break;
163 case 176400:
164 spdifclock = 22579200;
165 break;
166 case 192000:
167 spdifclock = 24576000;
168 break;
169 default:
170 return -EINVAL;
171 }
172
173 ret = clk_set_rate(spdif->clk_spdif_out, spdifclock);
174 if (ret) {
175 dev_err(dev, "Can't set SPDIF clock rate: %d\n", ret);
176 return ret;
177 }
178
179 return 0;
180}
181
182static void tegra_spdif_start_playback(struct tegra_spdif *spdif)
183{
184 spdif->reg_ctrl |= TEGRA_SPDIF_CTRL_TX_EN;
185 tegra_spdif_write(spdif, TEGRA_SPDIF_CTRL, spdif->reg_ctrl);
186}
187
188static void tegra_spdif_stop_playback(struct tegra_spdif *spdif)
189{
190 spdif->reg_ctrl &= ~TEGRA_SPDIF_CTRL_TX_EN;
191 tegra_spdif_write(spdif, TEGRA_SPDIF_CTRL, spdif->reg_ctrl);
192}
193
194static int tegra_spdif_trigger(struct snd_pcm_substream *substream, int cmd,
195 struct snd_soc_dai *dai)
196{
197 struct tegra_spdif *spdif = snd_soc_dai_get_drvdata(dai);
198
199 switch (cmd) {
200 case SNDRV_PCM_TRIGGER_START:
201 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
202 case SNDRV_PCM_TRIGGER_RESUME:
203 if (!spdif->clk_refs)
204 clk_enable(spdif->clk_spdif_out);
205 spdif->clk_refs++;
206 tegra_spdif_start_playback(spdif);
207 break;
208 case SNDRV_PCM_TRIGGER_STOP:
209 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
210 case SNDRV_PCM_TRIGGER_SUSPEND:
211 tegra_spdif_stop_playback(spdif);
212 spdif->clk_refs--;
213 if (!spdif->clk_refs)
214 clk_disable(spdif->clk_spdif_out);
215 break;
216 default:
217 return -EINVAL;
218 }
219
220 return 0;
221}
222
223static int tegra_spdif_probe(struct snd_soc_dai *dai)
224{
225 struct tegra_spdif *spdif = snd_soc_dai_get_drvdata(dai);
226
227 dai->capture_dma_data = NULL;
228 dai->playback_dma_data = &spdif->playback_dma_data;
229
230 return 0;
231}
232
233static const struct snd_soc_dai_ops tegra_spdif_dai_ops = {
234 .hw_params = tegra_spdif_hw_params,
235 .trigger = tegra_spdif_trigger,
236};
237
238static struct snd_soc_dai_driver tegra_spdif_dai = {
239 .name = DRV_NAME,
240 .probe = tegra_spdif_probe,
241 .playback = {
242 .channels_min = 2,
243 .channels_max = 2,
244 .rates = SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 |
245 SNDRV_PCM_RATE_48000,
246 .formats = SNDRV_PCM_FMTBIT_S16_LE,
247 },
248 .ops = &tegra_spdif_dai_ops,
249};
250
251static __devinit int tegra_spdif_platform_probe(struct platform_device *pdev)
252{
253 struct tegra_spdif *spdif;
254 struct resource *mem, *memregion, *dmareq;
255 int ret;
256
257 spdif = kzalloc(sizeof(struct tegra_spdif), GFP_KERNEL);
258 if (!spdif) {
259 dev_err(&pdev->dev, "Can't allocate tegra_spdif\n");
260 ret = -ENOMEM;
261 goto exit;
262 }
263 dev_set_drvdata(&pdev->dev, spdif);
264
265 spdif->clk_spdif_out = clk_get(&pdev->dev, "spdif_out");
266 if (IS_ERR(spdif->clk_spdif_out)) {
267 pr_err("Can't retrieve spdif clock\n");
268 ret = PTR_ERR(spdif->clk_spdif_out);
269 goto err_free;
270 }
271
272 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
273 if (!mem) {
274 dev_err(&pdev->dev, "No memory resource\n");
275 ret = -ENODEV;
276 goto err_clk_put;
277 }
278
279 dmareq = platform_get_resource(pdev, IORESOURCE_DMA, 0);
280 if (!dmareq) {
281 dev_err(&pdev->dev, "No DMA resource\n");
282 ret = -ENODEV;
283 goto err_clk_put;
284 }
285
286 memregion = request_mem_region(mem->start, resource_size(mem),
287 DRV_NAME);
288 if (!memregion) {
289 dev_err(&pdev->dev, "Memory region already claimed\n");
290 ret = -EBUSY;
291 goto err_clk_put;
292 }
293
294 spdif->regs = ioremap(mem->start, resource_size(mem));
295 if (!spdif->regs) {
296 dev_err(&pdev->dev, "ioremap failed\n");
297 ret = -ENOMEM;
298 goto err_release;
299 }
300
301 spdif->playback_dma_data.addr = mem->start + TEGRA_SPDIF_DATA_OUT;
302 spdif->playback_dma_data.wrap = 4;
303 spdif->playback_dma_data.width = 32;
304 spdif->playback_dma_data.req_sel = dmareq->start;
305
306 ret = snd_soc_register_dai(&pdev->dev, &tegra_spdif_dai);
307 if (ret) {
308 dev_err(&pdev->dev, "Could not register DAI: %d\n", ret);
309 ret = -ENOMEM;
310 goto err_unmap;
311 }
312
313 tegra_spdif_debug_add(spdif);
314
315 return 0;
316
317err_unmap:
318 iounmap(spdif->regs);
319err_release:
320 release_mem_region(mem->start, resource_size(mem));
321err_clk_put:
322 clk_put(spdif->clk_spdif_out);
323err_free:
324 kfree(spdif);
325exit:
326 return ret;
327}
328
329static int __devexit tegra_spdif_platform_remove(struct platform_device *pdev)
330{
331 struct tegra_spdif *spdif = dev_get_drvdata(&pdev->dev);
332 struct resource *res;
333
334 snd_soc_unregister_dai(&pdev->dev);
335
336 tegra_spdif_debug_remove(spdif);
337
338 iounmap(spdif->regs);
339
340 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
341 release_mem_region(res->start, resource_size(res));
342
343 clk_put(spdif->clk_spdif_out);
344
345 kfree(spdif);
346
347 return 0;
348}
349
350static struct platform_driver tegra_spdif_driver = {
351 .driver = {
352 .name = DRV_NAME,
353 .owner = THIS_MODULE,
354 },
355 .probe = tegra_spdif_platform_probe,
356 .remove = __devexit_p(tegra_spdif_platform_remove),
357};
358
359module_platform_driver(tegra_spdif_driver);
360
361MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>");
362MODULE_DESCRIPTION("Tegra SPDIF ASoC driver");
363MODULE_LICENSE("GPL");
364MODULE_ALIAS("platform:" DRV_NAME);
diff --git a/sound/soc/tegra/tegra_spdif.h b/sound/soc/tegra/tegra_spdif.h
deleted file mode 100644
index 2e03db430279..000000000000
--- a/sound/soc/tegra/tegra_spdif.h
+++ /dev/null
@@ -1,473 +0,0 @@
1/*
2 * tegra_spdif.h - Definitions for Tegra SPDIF driver
3 *
4 * Author: Stephen Warren <swarren@nvidia.com>
5 * Copyright (C) 2011 - NVIDIA, Inc.
6 *
7 * Based on code copyright/by:
8 * Copyright (c) 2008-2009, NVIDIA Corporation
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * version 2 as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22 * 02110-1301 USA
23 *
24 */
25
26#ifndef __TEGRA_SPDIF_H__
27#define __TEGRA_SPDIF_H__
28
29#include "tegra_pcm.h"
30
31/* Offsets from TEGRA_SPDIF_BASE */
32
33#define TEGRA_SPDIF_CTRL 0x0
34#define TEGRA_SPDIF_STATUS 0x4
35#define TEGRA_SPDIF_STROBE_CTRL 0x8
36#define TEGRA_SPDIF_DATA_FIFO_CSR 0x0C
37#define TEGRA_SPDIF_DATA_OUT 0x40
38#define TEGRA_SPDIF_DATA_IN 0x80
39#define TEGRA_SPDIF_CH_STA_RX_A 0x100
40#define TEGRA_SPDIF_CH_STA_RX_B 0x104
41#define TEGRA_SPDIF_CH_STA_RX_C 0x108
42#define TEGRA_SPDIF_CH_STA_RX_D 0x10C
43#define TEGRA_SPDIF_CH_STA_RX_E 0x110
44#define TEGRA_SPDIF_CH_STA_RX_F 0x114
45#define TEGRA_SPDIF_CH_STA_TX_A 0x140
46#define TEGRA_SPDIF_CH_STA_TX_B 0x144
47#define TEGRA_SPDIF_CH_STA_TX_C 0x148
48#define TEGRA_SPDIF_CH_STA_TX_D 0x14C
49#define TEGRA_SPDIF_CH_STA_TX_E 0x150
50#define TEGRA_SPDIF_CH_STA_TX_F 0x154
51#define TEGRA_SPDIF_USR_STA_RX_A 0x180
52#define TEGRA_SPDIF_USR_DAT_TX_A 0x1C0
53
54/* Fields in TEGRA_SPDIF_CTRL */
55
56/* Start capturing from 0=right, 1=left channel */
57#define TEGRA_SPDIF_CTRL_CAP_LC (1 << 30)
58
59/* SPDIF receiver(RX) enable */
60#define TEGRA_SPDIF_CTRL_RX_EN (1 << 29)
61
62/* SPDIF Transmitter(TX) enable */
63#define TEGRA_SPDIF_CTRL_TX_EN (1 << 28)
64
65/* Transmit Channel status */
66#define TEGRA_SPDIF_CTRL_TC_EN (1 << 27)
67
68/* Transmit user Data */
69#define TEGRA_SPDIF_CTRL_TU_EN (1 << 26)
70
71/* Interrupt on transmit error */
72#define TEGRA_SPDIF_CTRL_IE_TXE (1 << 25)
73
74/* Interrupt on receive error */
75#define TEGRA_SPDIF_CTRL_IE_RXE (1 << 24)
76
77/* Interrupt on invalid preamble */
78#define TEGRA_SPDIF_CTRL_IE_P (1 << 23)
79
80/* Interrupt on "B" preamble */
81#define TEGRA_SPDIF_CTRL_IE_B (1 << 22)
82
83/* Interrupt when block of channel status received */
84#define TEGRA_SPDIF_CTRL_IE_C (1 << 21)
85
86/* Interrupt when a valid information unit (IU) is received */
87#define TEGRA_SPDIF_CTRL_IE_U (1 << 20)
88
89/* Interrupt when RX user FIFO attention level is reached */
90#define TEGRA_SPDIF_CTRL_QE_RU (1 << 19)
91
92/* Interrupt when TX user FIFO attention level is reached */
93#define TEGRA_SPDIF_CTRL_QE_TU (1 << 18)
94
95/* Interrupt when RX data FIFO attention level is reached */
96#define TEGRA_SPDIF_CTRL_QE_RX (1 << 17)
97
98/* Interrupt when TX data FIFO attention level is reached */
99#define TEGRA_SPDIF_CTRL_QE_TX (1 << 16)
100
101/* Loopback test mode enable */
102#define TEGRA_SPDIF_CTRL_LBK_EN (1 << 15)
103
104/*
105 * Pack data mode:
106 * 0 = Single data (16 bit needs to be padded to match the
107 * interface data bit size).
108 * 1 = Packeted left/right channel data into a single word.
109 */
110#define TEGRA_SPDIF_CTRL_PACK (1 << 14)
111
112/*
113 * 00 = 16bit data
114 * 01 = 20bit data
115 * 10 = 24bit data
116 * 11 = raw data
117 */
118#define TEGRA_SPDIF_BIT_MODE_16BIT 0
119#define TEGRA_SPDIF_BIT_MODE_20BIT 1
120#define TEGRA_SPDIF_BIT_MODE_24BIT 2
121#define TEGRA_SPDIF_BIT_MODE_RAW 3
122
123#define TEGRA_SPDIF_CTRL_BIT_MODE_SHIFT 12
124#define TEGRA_SPDIF_CTRL_BIT_MODE_MASK (3 << TEGRA_SPDIF_CTRL_BIT_MODE_SHIFT)
125#define TEGRA_SPDIF_CTRL_BIT_MODE_16BIT (TEGRA_SPDIF_BIT_MODE_16BIT << TEGRA_SPDIF_CTRL_BIT_MODE_SHIFT)
126#define TEGRA_SPDIF_CTRL_BIT_MODE_20BIT (TEGRA_SPDIF_BIT_MODE_20BIT << TEGRA_SPDIF_CTRL_BIT_MODE_SHIFT)
127#define TEGRA_SPDIF_CTRL_BIT_MODE_24BIT (TEGRA_SPDIF_BIT_MODE_24BIT << TEGRA_SPDIF_CTRL_BIT_MODE_SHIFT)
128#define TEGRA_SPDIF_CTRL_BIT_MODE_RAW (TEGRA_SPDIF_BIT_MODE_RAW << TEGRA_SPDIF_CTRL_BIT_MODE_SHIFT)
129
130/* Fields in TEGRA_SPDIF_STATUS */
131
132/*
133 * Note: IS_P, IS_B, IS_C, and IS_U are sticky bits. Software must
134 * write a 1 to the corresponding bit location to clear the status.
135 */
136
137/*
138 * Receiver(RX) shifter is busy receiving data.
139 * This bit is asserted when the receiver first locked onto the
140 * preamble of the data stream after RX_EN is asserted. This bit is
141 * deasserted when either,
142 * (a) the end of a frame is reached after RX_EN is deeasserted, or
143 * (b) the SPDIF data stream becomes inactive.
144 */
145#define TEGRA_SPDIF_STATUS_RX_BSY (1 << 29)
146
147/*
148 * Transmitter(TX) shifter is busy transmitting data.
149 * This bit is asserted when TX_EN is asserted.
150 * This bit is deasserted when the end of a frame is reached after
151 * TX_EN is deasserted.
152 */
153#define TEGRA_SPDIF_STATUS_TX_BSY (1 << 28)
154
155/*
156 * TX is busy shifting out channel status.
157 * This bit is asserted when both TX_EN and TC_EN are asserted and
158 * data from CH_STA_TX_A register is loaded into the internal shifter.
159 * This bit is deasserted when either,
160 * (a) the end of a frame is reached after TX_EN is deasserted, or
161 * (b) CH_STA_TX_F register is loaded into the internal shifter.
162 */
163#define TEGRA_SPDIF_STATUS_TC_BSY (1 << 27)
164
165/*
166 * TX User data FIFO busy.
167 * This bit is asserted when TX_EN and TXU_EN are asserted and
168 * there's data in the TX user FIFO. This bit is deassert when either,
169 * (a) the end of a frame is reached after TX_EN is deasserted, or
170 * (b) there's no data left in the TX user FIFO.
171 */
172#define TEGRA_SPDIF_STATUS_TU_BSY (1 << 26)
173
174/* TX FIFO Underrun error status */
175#define TEGRA_SPDIF_STATUS_TX_ERR (1 << 25)
176
177/* RX FIFO Overrun error status */
178#define TEGRA_SPDIF_STATUS_RX_ERR (1 << 24)
179
180/* Preamble status: 0=Preamble OK, 1=bad/missing preamble */
181#define TEGRA_SPDIF_STATUS_IS_P (1 << 23)
182
183/* B-preamble detection status: 0=not detected, 1=B-preamble detected */
184#define TEGRA_SPDIF_STATUS_IS_B (1 << 22)
185
186/*
187 * RX channel block data receive status:
188 * 0=entire block not recieved yet.
189 * 1=received entire block of channel status,
190 */
191#define TEGRA_SPDIF_STATUS_IS_C (1 << 21)
192
193/* RX User Data Valid flag: 1=valid IU detected, 0 = no IU detected. */
194#define TEGRA_SPDIF_STATUS_IS_U (1 << 20)
195
196/*
197 * RX User FIFO Status:
198 * 1=attention level reached, 0=attention level not reached.
199 */
200#define TEGRA_SPDIF_STATUS_QS_RU (1 << 19)
201
202/*
203 * TX User FIFO Status:
204 * 1=attention level reached, 0=attention level not reached.
205 */
206#define TEGRA_SPDIF_STATUS_QS_TU (1 << 18)
207
208/*
209 * RX Data FIFO Status:
210 * 1=attention level reached, 0=attention level not reached.
211 */
212#define TEGRA_SPDIF_STATUS_QS_RX (1 << 17)
213
214/*
215 * TX Data FIFO Status:
216 * 1=attention level reached, 0=attention level not reached.
217 */
218#define TEGRA_SPDIF_STATUS_QS_TX (1 << 16)
219
220/* Fields in TEGRA_SPDIF_STROBE_CTRL */
221
222/*
223 * Indicates the approximate number of detected SPDIFIN clocks within a
224 * bi-phase period.
225 */
226#define TEGRA_SPDIF_STROBE_CTRL_PERIOD_SHIFT 16
227#define TEGRA_SPDIF_STROBE_CTRL_PERIOD_MASK (0xff << TEGRA_SPDIF_STROBE_CTRL_PERIOD_SHIFT)
228
229/* Data strobe mode: 0=Auto-locked 1=Manual locked */
230#define TEGRA_SPDIF_STROBE_CTRL_STROBE (1 << 15)
231
232/*
233 * Manual data strobe time within the bi-phase clock period (in terms of
234 * the number of over-sampling clocks).
235 */
236#define TEGRA_SPDIF_STROBE_CTRL_DATA_STROBES_SHIFT 8
237#define TEGRA_SPDIF_STROBE_CTRL_DATA_STROBES_MASK (0x1f << TEGRA_SPDIF_STROBE_CTRL_DATA_STROBES_SHIFT)
238
239/*
240 * Manual SPDIFIN bi-phase clock period (in terms of the number of
241 * over-sampling clocks).
242 */
243#define TEGRA_SPDIF_STROBE_CTRL_CLOCK_PERIOD_SHIFT 0
244#define TEGRA_SPDIF_STROBE_CTRL_CLOCK_PERIOD_MASK (0x3f << TEGRA_SPDIF_STROBE_CTRL_CLOCK_PERIOD_SHIFT)
245
246/* Fields in SPDIF_DATA_FIFO_CSR */
247
248/* Clear Receiver User FIFO (RX USR.FIFO) */
249#define TEGRA_SPDIF_DATA_FIFO_CSR_RU_CLR (1 << 31)
250
251#define TEGRA_SPDIF_FIFO_ATN_LVL_U_ONE_SLOT 0
252#define TEGRA_SPDIF_FIFO_ATN_LVL_U_TWO_SLOTS 1
253#define TEGRA_SPDIF_FIFO_ATN_LVL_U_THREE_SLOTS 2
254#define TEGRA_SPDIF_FIFO_ATN_LVL_U_FOUR_SLOTS 3
255
256/* RU FIFO attention level */
257#define TEGRA_SPDIF_DATA_FIFO_CSR_RU_ATN_LVL_SHIFT 29
258#define TEGRA_SPDIF_DATA_FIFO_CSR_RU_ATN_LVL_MASK \
259 (0x3 << TEGRA_SPDIF_DATA_FIFO_CSR_RU_ATN_LVL_SHIFT)
260#define TEGRA_SPDIF_DATA_FIFO_CSR_RU_ATN_LVL_RU1_WORD_FULL \
261 (TEGRA_SPDIF_FIFO_ATN_LVL_U_ONE_SLOT << TEGRA_SPDIF_DATA_FIFO_CSR_RU_ATN_LVL_SHIFT)
262#define TEGRA_SPDIF_DATA_FIFO_CSR_RU_ATN_LVL_RU2_WORD_FULL \
263 (TEGRA_SPDIF_FIFO_ATN_LVL_U_TWO_SLOTS << TEGRA_SPDIF_DATA_FIFO_CSR_RU_ATN_LVL_SHIFT)
264#define TEGRA_SPDIF_DATA_FIFO_CSR_RU_ATN_LVL_RU3_WORD_FULL \
265 (TEGRA_SPDIF_FIFO_ATN_LVL_U_THREE_SLOTS << TEGRA_SPDIF_DATA_FIFO_CSR_RU_ATN_LVL_SHIFT)
266#define TEGRA_SPDIF_DATA_FIFO_CSR_RU_ATN_LVL_RU4_WORD_FULL \
267 (TEGRA_SPDIF_FIFO_ATN_LVL_U_FOUR_SLOTS << TEGRA_SPDIF_DATA_FIFO_CSR_RU_ATN_LVL_SHIFT)
268
269/* Number of RX USR.FIFO levels with valid data. */
270#define TEGRA_SPDIF_DATA_FIFO_CSR_RU_FULL_COUNT_SHIFT 24
271#define TEGRA_SPDIF_DATA_FIFO_CSR_RU_FULL_COUNT_MASK (0x1f << TEGRA_SPDIF_DATA_FIFO_CSR_RU_FULL_COUNT_SHIFT)
272
273/* Clear Transmitter User FIFO (TX USR.FIFO) */
274#define TEGRA_SPDIF_DATA_FIFO_CSR_TU_CLR (1 << 23)
275
276/* TU FIFO attention level */
277#define TEGRA_SPDIF_DATA_FIFO_CSR_TU_ATN_LVL_SHIFT 21
278#define TEGRA_SPDIF_DATA_FIFO_CSR_TU_ATN_LVL_MASK \
279 (0x3 << TEGRA_SPDIF_DATA_FIFO_CSR_TU_ATN_LVL_SHIFT)
280#define TEGRA_SPDIF_DATA_FIFO_CSR_TU_ATN_LVL_TU1_WORD_FULL \
281 (TEGRA_SPDIF_FIFO_ATN_LVL_U_ONE_SLOT << TEGRA_SPDIF_DATA_FIFO_CSR_TU_ATN_LVL_SHIFT)
282#define TEGRA_SPDIF_DATA_FIFO_CSR_TU_ATN_LVL_TU2_WORD_FULL \
283 (TEGRA_SPDIF_FIFO_ATN_LVL_U_TWO_SLOTS << TEGRA_SPDIF_DATA_FIFO_CSR_TU_ATN_LVL_SHIFT)
284#define TEGRA_SPDIF_DATA_FIFO_CSR_TU_ATN_LVL_TU3_WORD_FULL \
285 (TEGRA_SPDIF_FIFO_ATN_LVL_U_THREE_SLOTS << TEGRA_SPDIF_DATA_FIFO_CSR_TU_ATN_LVL_SHIFT)
286#define TEGRA_SPDIF_DATA_FIFO_CSR_TU_ATN_LVL_TU4_WORD_FULL \
287 (TEGRA_SPDIF_FIFO_ATN_LVL_U_FOUR_SLOTS << TEGRA_SPDIF_DATA_FIFO_CSR_TU_ATN_LVL_SHIFT)
288
289/* Number of TX USR.FIFO levels that could be filled. */
290#define TEGRA_SPDIF_DATA_FIFO_CSR_TU_EMPTY_COUNT_SHIFT 16
291#define TEGRA_SPDIF_DATA_FIFO_CSR_TU_EMPTY_COUNT_MASK (0x1f << SPDIF_DATA_FIFO_CSR_TU_EMPTY_COUNT_SHIFT)
292
293/* Clear Receiver Data FIFO (RX DATA.FIFO) */
294#define TEGRA_SPDIF_DATA_FIFO_CSR_RX_CLR (1 << 15)
295
296#define TEGRA_SPDIF_FIFO_ATN_LVL_D_ONE_SLOT 0
297#define TEGRA_SPDIF_FIFO_ATN_LVL_D_FOUR_SLOTS 1
298#define TEGRA_SPDIF_FIFO_ATN_LVL_D_EIGHT_SLOTS 2
299#define TEGRA_SPDIF_FIFO_ATN_LVL_D_TWELVE_SLOTS 3
300
301/* RU FIFO attention level */
302#define TEGRA_SPDIF_DATA_FIFO_CSR_RX_ATN_LVL_SHIFT 13
303#define TEGRA_SPDIF_DATA_FIFO_CSR_RX_ATN_LVL_MASK \
304 (0x3 << TEGRA_SPDIF_DATA_FIFO_CSR_RX_ATN_LVL_SHIFT)
305#define TEGRA_SPDIF_DATA_FIFO_CSR_RX_ATN_LVL_RU1_WORD_FULL \
306 (TEGRA_SPDIF_FIFO_ATN_LVL_D_ONE_SLOT << TEGRA_SPDIF_DATA_FIFO_CSR_RX_ATN_LVL_SHIFT)
307#define TEGRA_SPDIF_DATA_FIFO_CSR_RX_ATN_LVL_RU4_WORD_FULL \
308 (TEGRA_SPDIF_FIFO_ATN_LVL_D_FOUR_SLOTS << TEGRA_SPDIF_DATA_FIFO_CSR_RX_ATN_LVL_SHIFT)
309#define TEGRA_SPDIF_DATA_FIFO_CSR_RX_ATN_LVL_RU8_WORD_FULL \
310 (TEGRA_SPDIF_FIFO_ATN_LVL_D_EIGHT_SLOTS << TEGRA_SPDIF_DATA_FIFO_CSR_RX_ATN_LVL_SHIFT)
311#define TEGRA_SPDIF_DATA_FIFO_CSR_RX_ATN_LVL_RU12_WORD_FULL \
312 (TEGRA_SPDIF_FIFO_ATN_LVL_D_TWELVE_SLOTS << TEGRA_SPDIF_DATA_FIFO_CSR_RX_ATN_LVL_SHIFT)
313
314/* Number of RX DATA.FIFO levels with valid data. */
315#define TEGRA_SPDIF_DATA_FIFO_CSR_RX_FULL_COUNT_SHIFT 8
316#define TEGRA_SPDIF_DATA_FIFO_CSR_RX_FULL_COUNT_MASK (0x1f << TEGRA_SPDIF_DATA_FIFO_CSR_RX_FULL_COUNT_SHIFT)
317
318/* Clear Transmitter Data FIFO (TX DATA.FIFO) */
319#define TEGRA_SPDIF_DATA_FIFO_CSR_TX_CLR (1 << 7)
320
321/* TU FIFO attention level */
322#define TEGRA_SPDIF_DATA_FIFO_CSR_TX_ATN_LVL_SHIFT 5
323#define TEGRA_SPDIF_DATA_FIFO_CSR_TX_ATN_LVL_MASK \
324 (0x3 << TEGRA_SPDIF_DATA_FIFO_CSR_TX_ATN_LVL_SHIFT)
325#define TEGRA_SPDIF_DATA_FIFO_CSR_TX_ATN_LVL_TU1_WORD_FULL \
326 (TEGRA_SPDIF_FIFO_ATN_LVL_D_ONE_SLOT << TEGRA_SPDIF_DATA_FIFO_CSR_TX_ATN_LVL_SHIFT)
327#define TEGRA_SPDIF_DATA_FIFO_CSR_TX_ATN_LVL_TU4_WORD_FULL \
328 (TEGRA_SPDIF_FIFO_ATN_LVL_D_FOUR_SLOTS << TEGRA_SPDIF_DATA_FIFO_CSR_TX_ATN_LVL_SHIFT)
329#define TEGRA_SPDIF_DATA_FIFO_CSR_TX_ATN_LVL_TU8_WORD_FULL \
330 (TEGRA_SPDIF_FIFO_ATN_LVL_D_EIGHT_SLOTS << TEGRA_SPDIF_DATA_FIFO_CSR_TX_ATN_LVL_SHIFT)
331#define TEGRA_SPDIF_DATA_FIFO_CSR_TX_ATN_LVL_TU12_WORD_FULL \
332 (TEGRA_SPDIF_FIFO_ATN_LVL_D_TWELVE_SLOTS << TEGRA_SPDIF_DATA_FIFO_CSR_TX_ATN_LVL_SHIFT)
333
334/* Number of TX DATA.FIFO levels that could be filled. */
335#define TEGRA_SPDIF_DATA_FIFO_CSR_TX_EMPTY_COUNT_SHIFT 0
336#define TEGRA_SPDIF_DATA_FIFO_CSR_TX_EMPTY_COUNT_MASK (0x1f << SPDIF_DATA_FIFO_CSR_TX_EMPTY_COUNT_SHIFT)
337
338/* Fields in TEGRA_SPDIF_DATA_OUT */
339
340/*
341 * This register has 5 different formats:
342 * 16-bit (BIT_MODE=00, PACK=0)
343 * 20-bit (BIT_MODE=01, PACK=0)
344 * 24-bit (BIT_MODE=10, PACK=0)
345 * raw (BIT_MODE=11, PACK=0)
346 * 16-bit packed (BIT_MODE=00, PACK=1)
347 */
348
349#define TEGRA_SPDIF_DATA_OUT_DATA_16_SHIFT 0
350#define TEGRA_SPDIF_DATA_OUT_DATA_16_MASK (0xffff << TEGRA_SPDIF_DATA_OUT_DATA_16_SHIFT)
351
352#define TEGRA_SPDIF_DATA_OUT_DATA_20_SHIFT 0
353#define TEGRA_SPDIF_DATA_OUT_DATA_20_MASK (0xfffff << TEGRA_SPDIF_DATA_OUT_DATA_20_SHIFT)
354
355#define TEGRA_SPDIF_DATA_OUT_DATA_24_SHIFT 0
356#define TEGRA_SPDIF_DATA_OUT_DATA_24_MASK (0xffffff << TEGRA_SPDIF_DATA_OUT_DATA_24_SHIFT)
357
358#define TEGRA_SPDIF_DATA_OUT_DATA_RAW_P (1 << 31)
359#define TEGRA_SPDIF_DATA_OUT_DATA_RAW_C (1 << 30)
360#define TEGRA_SPDIF_DATA_OUT_DATA_RAW_U (1 << 29)
361#define TEGRA_SPDIF_DATA_OUT_DATA_RAW_V (1 << 28)
362
363#define TEGRA_SPDIF_DATA_OUT_DATA_RAW_DATA_SHIFT 8
364#define TEGRA_SPDIF_DATA_OUT_DATA_RAW_DATA_MASK (0xfffff << TEGRA_SPDIF_DATA_OUT_DATA_RAW_DATA_SHIFT)
365
366#define TEGRA_SPDIF_DATA_OUT_DATA_RAW_AUX_SHIFT 4
367#define TEGRA_SPDIF_DATA_OUT_DATA_RAW_AUX_MASK (0xf << TEGRA_SPDIF_DATA_OUT_DATA_RAW_AUX_SHIFT)
368
369#define TEGRA_SPDIF_DATA_OUT_DATA_RAW_PREAMBLE_SHIFT 0
370#define TEGRA_SPDIF_DATA_OUT_DATA_RAW_PREAMBLE_MASK (0xf << TEGRA_SPDIF_DATA_OUT_DATA_RAW_PREAMBLE_SHIFT)
371
372#define TEGRA_SPDIF_DATA_OUT_DATA_16_PACKED_RIGHT_SHIFT 16
373#define TEGRA_SPDIF_DATA_OUT_DATA_16_PACKED_RIGHT_MASK (0xffff << TEGRA_SPDIF_DATA_OUT_DATA_16_PACKED_RIGHT_SHIFT)
374
375#define TEGRA_SPDIF_DATA_OUT_DATA_16_PACKED_LEFT_SHIFT 0
376#define TEGRA_SPDIF_DATA_OUT_DATA_16_PACKED_LEFT_MASK (0xffff << TEGRA_SPDIF_DATA_OUT_DATA_16_PACKED_LEFT_SHIFT)
377
378/* Fields in TEGRA_SPDIF_DATA_IN */
379
380/*
381 * This register has 5 different formats:
382 * 16-bit (BIT_MODE=00, PACK=0)
383 * 20-bit (BIT_MODE=01, PACK=0)
384 * 24-bit (BIT_MODE=10, PACK=0)
385 * raw (BIT_MODE=11, PACK=0)
386 * 16-bit packed (BIT_MODE=00, PACK=1)
387 *
388 * Bits 31:24 are common to all modes except 16-bit packed
389 */
390
391#define TEGRA_SPDIF_DATA_IN_DATA_P (1 << 31)
392#define TEGRA_SPDIF_DATA_IN_DATA_C (1 << 30)
393#define TEGRA_SPDIF_DATA_IN_DATA_U (1 << 29)
394#define TEGRA_SPDIF_DATA_IN_DATA_V (1 << 28)
395
396#define TEGRA_SPDIF_DATA_IN_DATA_PREAMBLE_SHIFT 24
397#define TEGRA_SPDIF_DATA_IN_DATA_PREAMBLE_MASK (0xf << TEGRA_SPDIF_DATA_IN_DATA_PREAMBLE_SHIFT)
398
399#define TEGRA_SPDIF_DATA_IN_DATA_16_SHIFT 0
400#define TEGRA_SPDIF_DATA_IN_DATA_16_MASK (0xffff << TEGRA_SPDIF_DATA_IN_DATA_16_SHIFT)
401
402#define TEGRA_SPDIF_DATA_IN_DATA_20_SHIFT 0
403#define TEGRA_SPDIF_DATA_IN_DATA_20_MASK (0xfffff << TEGRA_SPDIF_DATA_IN_DATA_20_SHIFT)
404
405#define TEGRA_SPDIF_DATA_IN_DATA_24_SHIFT 0
406#define TEGRA_SPDIF_DATA_IN_DATA_24_MASK (0xffffff << TEGRA_SPDIF_DATA_IN_DATA_24_SHIFT)
407
408#define TEGRA_SPDIF_DATA_IN_DATA_RAW_DATA_SHIFT 8
409#define TEGRA_SPDIF_DATA_IN_DATA_RAW_DATA_MASK (0xfffff << TEGRA_SPDIF_DATA_IN_DATA_RAW_DATA_SHIFT)
410
411#define TEGRA_SPDIF_DATA_IN_DATA_RAW_AUX_SHIFT 4
412#define TEGRA_SPDIF_DATA_IN_DATA_RAW_AUX_MASK (0xf << TEGRA_SPDIF_DATA_IN_DATA_RAW_AUX_SHIFT)
413
414#define TEGRA_SPDIF_DATA_IN_DATA_RAW_PREAMBLE_SHIFT 0
415#define TEGRA_SPDIF_DATA_IN_DATA_RAW_PREAMBLE_MASK (0xf << TEGRA_SPDIF_DATA_IN_DATA_RAW_PREAMBLE_SHIFT)
416
417#define TEGRA_SPDIF_DATA_IN_DATA_16_PACKED_RIGHT_SHIFT 16
418#define TEGRA_SPDIF_DATA_IN_DATA_16_PACKED_RIGHT_MASK (0xffff << TEGRA_SPDIF_DATA_IN_DATA_16_PACKED_RIGHT_SHIFT)
419
420#define TEGRA_SPDIF_DATA_IN_DATA_16_PACKED_LEFT_SHIFT 0
421#define TEGRA_SPDIF_DATA_IN_DATA_16_PACKED_LEFT_MASK (0xffff << TEGRA_SPDIF_DATA_IN_DATA_16_PACKED_LEFT_SHIFT)
422
423/* Fields in TEGRA_SPDIF_CH_STA_RX_A */
424/* Fields in TEGRA_SPDIF_CH_STA_RX_B */
425/* Fields in TEGRA_SPDIF_CH_STA_RX_C */
426/* Fields in TEGRA_SPDIF_CH_STA_RX_D */
427/* Fields in TEGRA_SPDIF_CH_STA_RX_E */
428/* Fields in TEGRA_SPDIF_CH_STA_RX_F */
429
430/*
431 * The 6-word receive channel data page buffer holds a block (192 frames) of
432 * channel status information. The order of receive is from LSB to MSB
433 * bit, and from CH_STA_RX_A to CH_STA_RX_F then back to CH_STA_RX_A.
434 */
435
436/* Fields in TEGRA_SPDIF_CH_STA_TX_A */
437/* Fields in TEGRA_SPDIF_CH_STA_TX_B */
438/* Fields in TEGRA_SPDIF_CH_STA_TX_C */
439/* Fields in TEGRA_SPDIF_CH_STA_TX_D */
440/* Fields in TEGRA_SPDIF_CH_STA_TX_E */
441/* Fields in TEGRA_SPDIF_CH_STA_TX_F */
442
443/*
444 * The 6-word transmit channel data page buffer holds a block (192 frames) of
445 * channel status information. The order of transmission is from LSB to MSB
446 * bit, and from CH_STA_TX_A to CH_STA_TX_F then back to CH_STA_TX_A.
447 */
448
449/* Fields in TEGRA_SPDIF_USR_STA_RX_A */
450
451/*
452 * This 4-word deep FIFO receives user FIFO field information. The order of
453 * receive is from LSB to MSB bit.
454 */
455
456/* Fields in TEGRA_SPDIF_USR_DAT_TX_A */
457
458/*
459 * This 4-word deep FIFO transmits user FIFO field information. The order of
460 * transmission is from LSB to MSB bit.
461 */
462
463struct tegra_spdif {
464 struct clk *clk_spdif_out;
465 int clk_refs;
466 struct tegra_pcm_dma_params capture_dma_data;
467 struct tegra_pcm_dma_params playback_dma_data;
468 void __iomem *regs;
469 struct dentry *debug;
470 u32 reg_ctrl;
471};
472
473#endif
diff --git a/sound/soc/tegra/tegra_wm8903.c b/sound/soc/tegra/tegra_wm8903.c
index 566655e23b7d..0b0df49d9d33 100644
--- a/sound/soc/tegra/tegra_wm8903.c
+++ b/sound/soc/tegra/tegra_wm8903.c
@@ -2,7 +2,7 @@
2 * tegra_wm8903.c - Tegra machine ASoC driver for boards using WM8903 codec. 2 * tegra_wm8903.c - Tegra machine ASoC driver for boards using WM8903 codec.
3 * 3 *
4 * Author: Stephen Warren <swarren@nvidia.com> 4 * Author: Stephen Warren <swarren@nvidia.com>
5 * Copyright (C) 2010-2011 - NVIDIA, Inc. 5 * Copyright (C) 2010-2012 - NVIDIA, Inc.
6 * 6 *
7 * Based on code copyright/by: 7 * Based on code copyright/by:
8 * 8 *
@@ -46,9 +46,6 @@
46 46
47#include "../codecs/wm8903.h" 47#include "../codecs/wm8903.h"
48 48
49#include "tegra_das.h"
50#include "tegra_i2s.h"
51#include "tegra_pcm.h"
52#include "tegra_asoc_utils.h" 49#include "tegra_asoc_utils.h"
53 50
54#define DRV_NAME "tegra-snd-wm8903" 51#define DRV_NAME "tegra-snd-wm8903"
@@ -61,7 +58,6 @@
61 58
62struct tegra_wm8903 { 59struct tegra_wm8903 {
63 struct tegra_wm8903_platform_data pdata; 60 struct tegra_wm8903_platform_data pdata;
64 struct platform_device *pcm_dev;
65 struct tegra_asoc_utils_data util_data; 61 struct tegra_asoc_utils_data util_data;
66 int gpio_requested; 62 int gpio_requested;
67}; 63};
@@ -354,8 +350,8 @@ static struct snd_soc_dai_link tegra_wm8903_dai = {
354 .name = "WM8903", 350 .name = "WM8903",
355 .stream_name = "WM8903 PCM", 351 .stream_name = "WM8903 PCM",
356 .codec_name = "wm8903.0-001a", 352 .codec_name = "wm8903.0-001a",
357 .platform_name = "tegra-pcm-audio", 353 .platform_name = "tegra20-i2s.0",
358 .cpu_dai_name = "tegra-i2s.0", 354 .cpu_dai_name = "tegra20-i2s.0",
359 .codec_dai_name = "wm8903-hifi", 355 .codec_dai_name = "wm8903-hifi",
360 .init = tegra_wm8903_init, 356 .init = tegra_wm8903_init,
361 .ops = &tegra_wm8903_ops, 357 .ops = &tegra_wm8903_ops,
@@ -392,7 +388,6 @@ static __devinit int tegra_wm8903_driver_probe(struct platform_device *pdev)
392 ret = -ENOMEM; 388 ret = -ENOMEM;
393 goto err; 389 goto err;
394 } 390 }
395 machine->pcm_dev = ERR_PTR(-EINVAL);
396 391
397 card->dev = &pdev->dev; 392 card->dev = &pdev->dev;
398 platform_set_drvdata(pdev, card); 393 platform_set_drvdata(pdev, card);
@@ -428,14 +423,9 @@ static __devinit int tegra_wm8903_driver_probe(struct platform_device *pdev)
428 goto err; 423 goto err;
429 } 424 }
430 425
431 machine->pcm_dev = platform_device_register_simple( 426 tegra_wm8903_dai.platform_name = NULL;
432 "tegra-pcm-audio", -1, NULL, 0); 427 tegra_wm8903_dai.platform_of_node =
433 if (IS_ERR(machine->pcm_dev)) { 428 tegra_wm8903_dai.cpu_dai_of_node;
434 dev_err(&pdev->dev,
435 "Can't instantiate tegra-pcm-audio\n");
436 ret = PTR_ERR(machine->pcm_dev);
437 goto err;
438 }
439 } else { 429 } else {
440 if (machine_is_harmony()) { 430 if (machine_is_harmony()) {
441 card->dapm_routes = harmony_audio_map; 431 card->dapm_routes = harmony_audio_map;
@@ -454,7 +444,7 @@ static __devinit int tegra_wm8903_driver_probe(struct platform_device *pdev)
454 444
455 ret = tegra_asoc_utils_init(&machine->util_data, &pdev->dev); 445 ret = tegra_asoc_utils_init(&machine->util_data, &pdev->dev);
456 if (ret) 446 if (ret)
457 goto err_unregister; 447 goto err;
458 448
459 ret = snd_soc_register_card(card); 449 ret = snd_soc_register_card(card);
460 if (ret) { 450 if (ret) {
@@ -467,9 +457,6 @@ static __devinit int tegra_wm8903_driver_probe(struct platform_device *pdev)
467 457
468err_fini_utils: 458err_fini_utils:
469 tegra_asoc_utils_fini(&machine->util_data); 459 tegra_asoc_utils_fini(&machine->util_data);
470err_unregister:
471 if (!IS_ERR(machine->pcm_dev))
472 platform_device_unregister(machine->pcm_dev);
473err: 460err:
474 return ret; 461 return ret;
475} 462}
@@ -497,8 +484,6 @@ static int __devexit tegra_wm8903_driver_remove(struct platform_device *pdev)
497 snd_soc_unregister_card(card); 484 snd_soc_unregister_card(card);
498 485
499 tegra_asoc_utils_fini(&machine->util_data); 486 tegra_asoc_utils_fini(&machine->util_data);
500 if (!IS_ERR(machine->pcm_dev))
501 platform_device_unregister(machine->pcm_dev);
502 487
503 return 0; 488 return 0;
504} 489}
diff --git a/sound/soc/tegra/trimslice.c b/sound/soc/tegra/trimslice.c
index 2bdfc550cff8..4a8d5b672c9f 100644
--- a/sound/soc/tegra/trimslice.c
+++ b/sound/soc/tegra/trimslice.c
@@ -27,6 +27,7 @@
27#include <asm/mach-types.h> 27#include <asm/mach-types.h>
28 28
29#include <linux/module.h> 29#include <linux/module.h>
30#include <linux/of.h>
30#include <linux/platform_device.h> 31#include <linux/platform_device.h>
31#include <linux/slab.h> 32#include <linux/slab.h>
32 33
@@ -38,9 +39,6 @@
38 39
39#include "../codecs/tlv320aic23.h" 40#include "../codecs/tlv320aic23.h"
40 41
41#include "tegra_das.h"
42#include "tegra_i2s.h"
43#include "tegra_pcm.h"
44#include "tegra_asoc_utils.h" 42#include "tegra_asoc_utils.h"
45 43
46#define DRV_NAME "tegra-snd-trimslice" 44#define DRV_NAME "tegra-snd-trimslice"
@@ -119,8 +117,8 @@ static struct snd_soc_dai_link trimslice_tlv320aic23_dai = {
119 .name = "TLV320AIC23", 117 .name = "TLV320AIC23",
120 .stream_name = "AIC23", 118 .stream_name = "AIC23",
121 .codec_name = "tlv320aic23-codec.2-001a", 119 .codec_name = "tlv320aic23-codec.2-001a",
122 .platform_name = "tegra-pcm-audio", 120 .platform_name = "tegra20-i2s.0",
123 .cpu_dai_name = "tegra-i2s.0", 121 .cpu_dai_name = "tegra20-i2s.0",
124 .codec_dai_name = "tlv320aic23-hifi", 122 .codec_dai_name = "tlv320aic23-hifi",
125 .ops = &trimslice_asoc_ops, 123 .ops = &trimslice_asoc_ops,
126}; 124};
@@ -152,6 +150,32 @@ static __devinit int tegra_snd_trimslice_probe(struct platform_device *pdev)
152 goto err; 150 goto err;
153 } 151 }
154 152
153 if (pdev->dev.of_node) {
154 trimslice_tlv320aic23_dai.codec_name = NULL;
155 trimslice_tlv320aic23_dai.codec_of_node = of_parse_phandle(
156 pdev->dev.of_node, "nvidia,audio-codec", 0);
157 if (!trimslice_tlv320aic23_dai.codec_of_node) {
158 dev_err(&pdev->dev,
159 "Property 'nvidia,audio-codec' missing or invalid\n");
160 ret = -EINVAL;
161 goto err;
162 }
163
164 trimslice_tlv320aic23_dai.cpu_dai_name = NULL;
165 trimslice_tlv320aic23_dai.cpu_dai_of_node = of_parse_phandle(
166 pdev->dev.of_node, "nvidia,i2s-controller", 0);
167 if (!trimslice_tlv320aic23_dai.cpu_dai_of_node) {
168 dev_err(&pdev->dev,
169 "Property 'nvidia,i2s-controller' missing or invalid\n");
170 ret = -EINVAL;
171 goto err;
172 }
173
174 trimslice_tlv320aic23_dai.platform_name = NULL;
175 trimslice_tlv320aic23_dai.platform_of_node =
176 trimslice_tlv320aic23_dai.cpu_dai_of_node;
177 }
178
155 ret = tegra_asoc_utils_init(&trimslice->util_data, &pdev->dev); 179 ret = tegra_asoc_utils_init(&trimslice->util_data, &pdev->dev);
156 if (ret) 180 if (ret)
157 goto err; 181 goto err;
@@ -187,10 +211,17 @@ static int __devexit tegra_snd_trimslice_remove(struct platform_device *pdev)
187 return 0; 211 return 0;
188} 212}
189 213
214static const struct of_device_id trimslice_of_match[] __devinitconst = {
215 { .compatible = "nvidia,tegra-audio-trimslice", },
216 {},
217};
218MODULE_DEVICE_TABLE(of, trimslice_of_match);
219
190static struct platform_driver tegra_snd_trimslice_driver = { 220static struct platform_driver tegra_snd_trimslice_driver = {
191 .driver = { 221 .driver = {
192 .name = DRV_NAME, 222 .name = DRV_NAME,
193 .owner = THIS_MODULE, 223 .owner = THIS_MODULE,
224 .of_match_table = trimslice_of_match,
194 }, 225 },
195 .probe = tegra_snd_trimslice_probe, 226 .probe = tegra_snd_trimslice_probe,
196 .remove = __devexit_p(tegra_snd_trimslice_remove), 227 .remove = __devexit_p(tegra_snd_trimslice_remove),
diff --git a/sound/soc/ux500/Kconfig b/sound/soc/ux500/Kconfig
new file mode 100644
index 000000000000..44cf43404cd9
--- /dev/null
+++ b/sound/soc/ux500/Kconfig
@@ -0,0 +1,14 @@
1#
2# Ux500 SoC audio configuration
3#
4menuconfig SND_SOC_UX500
5 tristate "SoC Audio support for Ux500 platform"
6 depends on SND_SOC
7 depends on MFD_DB8500_PRCMU
8 help
9 Say Y if you want to enable ASoC-support for
10 any of the Ux500 platforms (e.g. U8500).
11
12config SND_SOC_UX500_PLAT_MSP_I2S
13 tristate
14 depends on SND_SOC_UX500
diff --git a/sound/soc/ux500/Makefile b/sound/soc/ux500/Makefile
new file mode 100644
index 000000000000..19974c5a2ea1
--- /dev/null
+++ b/sound/soc/ux500/Makefile
@@ -0,0 +1,4 @@
1# Ux500 Platform Support
2
3snd-soc-ux500-plat-msp-i2s-objs := ux500_msp_dai.o ux500_msp_i2s.o
4obj-$(CONFIG_SND_SOC_UX500_PLAT_MSP_I2S) += snd-soc-ux500-plat-msp-i2s.o
diff --git a/sound/soc/ux500/ux500_msp_dai.c b/sound/soc/ux500/ux500_msp_dai.c
new file mode 100644
index 000000000000..93c6c40e724c
--- /dev/null
+++ b/sound/soc/ux500/ux500_msp_dai.c
@@ -0,0 +1,843 @@
1/*
2 * Copyright (C) ST-Ericsson SA 2012
3 *
4 * Author: Ola Lilja <ola.o.lilja@stericsson.com>,
5 * Roger Nilsson <roger.xr.nilsson@stericsson.com>
6 * for ST-Ericsson.
7 *
8 * License terms:
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as published
12 * by the Free Software Foundation.
13 */
14
15#include <linux/module.h>
16#include <linux/slab.h>
17#include <linux/bitops.h>
18#include <linux/platform_device.h>
19#include <linux/clk.h>
20#include <linux/regulator/consumer.h>
21#include <linux/mfd/dbx500-prcmu.h>
22
23#include <mach/hardware.h>
24#include <mach/board-mop500-msp.h>
25
26#include <sound/soc.h>
27#include <sound/soc-dai.h>
28
29#include "ux500_msp_i2s.h"
30#include "ux500_msp_dai.h"
31
32static int setup_pcm_multichan(struct snd_soc_dai *dai,
33 struct ux500_msp_config *msp_config)
34{
35 struct ux500_msp_i2s_drvdata *drvdata = dev_get_drvdata(dai->dev);
36 struct msp_multichannel_config *multi =
37 &msp_config->multichannel_config;
38
39 if (drvdata->slots > 1) {
40 msp_config->multichannel_configured = 1;
41
42 multi->tx_multichannel_enable = true;
43 multi->rx_multichannel_enable = true;
44 multi->rx_comparison_enable_mode = MSP_COMPARISON_DISABLED;
45
46 multi->tx_channel_0_enable = drvdata->tx_mask;
47 multi->tx_channel_1_enable = 0;
48 multi->tx_channel_2_enable = 0;
49 multi->tx_channel_3_enable = 0;
50
51 multi->rx_channel_0_enable = drvdata->rx_mask;
52 multi->rx_channel_1_enable = 0;
53 multi->rx_channel_2_enable = 0;
54 multi->rx_channel_3_enable = 0;
55
56 dev_dbg(dai->dev,
57 "%s: Multichannel enabled. Slots: %d, TX: %u, RX: %u\n",
58 __func__, drvdata->slots, multi->tx_channel_0_enable,
59 multi->rx_channel_0_enable);
60 }
61
62 return 0;
63}
64
65static int setup_frameper(struct snd_soc_dai *dai, unsigned int rate,
66 struct msp_protdesc *prot_desc)
67{
68 struct ux500_msp_i2s_drvdata *drvdata = dev_get_drvdata(dai->dev);
69
70 switch (drvdata->slots) {
71 case 1:
72 switch (rate) {
73 case 8000:
74 prot_desc->frame_period =
75 FRAME_PER_SINGLE_SLOT_8_KHZ;
76 break;
77
78 case 16000:
79 prot_desc->frame_period =
80 FRAME_PER_SINGLE_SLOT_16_KHZ;
81 break;
82
83 case 44100:
84 prot_desc->frame_period =
85 FRAME_PER_SINGLE_SLOT_44_1_KHZ;
86 break;
87
88 case 48000:
89 prot_desc->frame_period =
90 FRAME_PER_SINGLE_SLOT_48_KHZ;
91 break;
92
93 default:
94 dev_err(dai->dev,
95 "%s: Error: Unsupported sample-rate (freq = %d)!\n",
96 __func__, rate);
97 return -EINVAL;
98 }
99 break;
100
101 case 2:
102 prot_desc->frame_period = FRAME_PER_2_SLOTS;
103 break;
104
105 case 8:
106 prot_desc->frame_period = FRAME_PER_8_SLOTS;
107 break;
108
109 case 16:
110 prot_desc->frame_period = FRAME_PER_16_SLOTS;
111 break;
112 default:
113 dev_err(dai->dev,
114 "%s: Error: Unsupported slot-count (slots = %d)!\n",
115 __func__, drvdata->slots);
116 return -EINVAL;
117 }
118
119 prot_desc->clocks_per_frame =
120 prot_desc->frame_period+1;
121
122 dev_dbg(dai->dev, "%s: Clocks per frame: %u\n",
123 __func__,
124 prot_desc->clocks_per_frame);
125
126 return 0;
127}
128
129static int setup_pcm_framing(struct snd_soc_dai *dai, unsigned int rate,
130 struct msp_protdesc *prot_desc)
131{
132 struct ux500_msp_i2s_drvdata *drvdata = dev_get_drvdata(dai->dev);
133
134 u32 frame_length = MSP_FRAME_LEN_1;
135 prot_desc->frame_width = 0;
136
137 switch (drvdata->slots) {
138 case 1:
139 frame_length = MSP_FRAME_LEN_1;
140 break;
141
142 case 2:
143 frame_length = MSP_FRAME_LEN_2;
144 break;
145
146 case 8:
147 frame_length = MSP_FRAME_LEN_8;
148 break;
149
150 case 16:
151 frame_length = MSP_FRAME_LEN_16;
152 break;
153 default:
154 dev_err(dai->dev,
155 "%s: Error: Unsupported slot-count (slots = %d)!\n",
156 __func__, drvdata->slots);
157 return -EINVAL;
158 }
159
160 prot_desc->tx_frame_len_1 = frame_length;
161 prot_desc->rx_frame_len_1 = frame_length;
162 prot_desc->tx_frame_len_2 = frame_length;
163 prot_desc->rx_frame_len_2 = frame_length;
164
165 prot_desc->tx_elem_len_1 = MSP_ELEM_LEN_16;
166 prot_desc->rx_elem_len_1 = MSP_ELEM_LEN_16;
167 prot_desc->tx_elem_len_2 = MSP_ELEM_LEN_16;
168 prot_desc->rx_elem_len_2 = MSP_ELEM_LEN_16;
169
170 return setup_frameper(dai, rate, prot_desc);
171}
172
173static int setup_clocking(struct snd_soc_dai *dai,
174 unsigned int fmt,
175 struct ux500_msp_config *msp_config)
176{
177 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
178 case SND_SOC_DAIFMT_NB_NF:
179 break;
180
181 case SND_SOC_DAIFMT_NB_IF:
182 msp_config->tx_fsync_pol ^= 1 << TFSPOL_SHIFT;
183 msp_config->rx_fsync_pol ^= 1 << RFSPOL_SHIFT;
184
185 break;
186
187 default:
188 dev_err(dai->dev,
189 "%s: Error: Unsopported inversion (fmt = 0x%x)!\n",
190 __func__, fmt);
191
192 return -EINVAL;
193 }
194
195 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
196 case SND_SOC_DAIFMT_CBM_CFM:
197 dev_dbg(dai->dev, "%s: Codec is master.\n", __func__);
198
199 msp_config->iodelay = 0x20;
200 msp_config->rx_fsync_sel = 0;
201 msp_config->tx_fsync_sel = 1 << TFSSEL_SHIFT;
202 msp_config->tx_clk_sel = 0;
203 msp_config->rx_clk_sel = 0;
204 msp_config->srg_clk_sel = 0x2 << SCKSEL_SHIFT;
205
206 break;
207
208 case SND_SOC_DAIFMT_CBS_CFS:
209 dev_dbg(dai->dev, "%s: Codec is slave.\n", __func__);
210
211 msp_config->tx_clk_sel = TX_CLK_SEL_SRG;
212 msp_config->tx_fsync_sel = TX_SYNC_SRG_PROG;
213 msp_config->rx_clk_sel = RX_CLK_SEL_SRG;
214 msp_config->rx_fsync_sel = RX_SYNC_SRG;
215 msp_config->srg_clk_sel = 1 << SCKSEL_SHIFT;
216
217 break;
218
219 default:
220 dev_err(dai->dev, "%s: Error: Unsopported master (fmt = 0x%x)!\n",
221 __func__, fmt);
222
223 return -EINVAL;
224 }
225
226 return 0;
227}
228
229static int setup_pcm_protdesc(struct snd_soc_dai *dai,
230 unsigned int fmt,
231 struct msp_protdesc *prot_desc)
232{
233 prot_desc->rx_phase_mode = MSP_SINGLE_PHASE;
234 prot_desc->tx_phase_mode = MSP_SINGLE_PHASE;
235 prot_desc->rx_phase2_start_mode = MSP_PHASE2_START_MODE_IMEDIATE;
236 prot_desc->tx_phase2_start_mode = MSP_PHASE2_START_MODE_IMEDIATE;
237 prot_desc->rx_byte_order = MSP_BTF_MS_BIT_FIRST;
238 prot_desc->tx_byte_order = MSP_BTF_MS_BIT_FIRST;
239 prot_desc->tx_fsync_pol = MSP_FSYNC_POL(MSP_FSYNC_POL_ACT_HI);
240 prot_desc->rx_fsync_pol = MSP_FSYNC_POL_ACT_HI << RFSPOL_SHIFT;
241
242 if ((fmt & SND_SOC_DAIFMT_FORMAT_MASK) == SND_SOC_DAIFMT_DSP_A) {
243 dev_dbg(dai->dev, "%s: DSP_A.\n", __func__);
244 prot_desc->rx_clk_pol = MSP_RISING_EDGE;
245 prot_desc->tx_clk_pol = MSP_FALLING_EDGE;
246
247 prot_desc->rx_data_delay = MSP_DELAY_1;
248 prot_desc->tx_data_delay = MSP_DELAY_1;
249 } else {
250 dev_dbg(dai->dev, "%s: DSP_B.\n", __func__);
251 prot_desc->rx_clk_pol = MSP_FALLING_EDGE;
252 prot_desc->tx_clk_pol = MSP_RISING_EDGE;
253
254 prot_desc->rx_data_delay = MSP_DELAY_0;
255 prot_desc->tx_data_delay = MSP_DELAY_0;
256 }
257
258 prot_desc->rx_half_word_swap = MSP_SWAP_NONE;
259 prot_desc->tx_half_word_swap = MSP_SWAP_NONE;
260 prot_desc->compression_mode = MSP_COMPRESS_MODE_LINEAR;
261 prot_desc->expansion_mode = MSP_EXPAND_MODE_LINEAR;
262 prot_desc->frame_sync_ignore = MSP_FSYNC_IGNORE;
263
264 return 0;
265}
266
267static int setup_i2s_protdesc(struct msp_protdesc *prot_desc)
268{
269 prot_desc->rx_phase_mode = MSP_DUAL_PHASE;
270 prot_desc->tx_phase_mode = MSP_DUAL_PHASE;
271 prot_desc->rx_phase2_start_mode = MSP_PHASE2_START_MODE_FSYNC;
272 prot_desc->tx_phase2_start_mode = MSP_PHASE2_START_MODE_FSYNC;
273 prot_desc->rx_byte_order = MSP_BTF_MS_BIT_FIRST;
274 prot_desc->tx_byte_order = MSP_BTF_MS_BIT_FIRST;
275 prot_desc->tx_fsync_pol = MSP_FSYNC_POL(MSP_FSYNC_POL_ACT_LO);
276 prot_desc->rx_fsync_pol = MSP_FSYNC_POL_ACT_LO << RFSPOL_SHIFT;
277
278 prot_desc->rx_frame_len_1 = MSP_FRAME_LEN_1;
279 prot_desc->rx_frame_len_2 = MSP_FRAME_LEN_1;
280 prot_desc->tx_frame_len_1 = MSP_FRAME_LEN_1;
281 prot_desc->tx_frame_len_2 = MSP_FRAME_LEN_1;
282 prot_desc->rx_elem_len_1 = MSP_ELEM_LEN_16;
283 prot_desc->rx_elem_len_2 = MSP_ELEM_LEN_16;
284 prot_desc->tx_elem_len_1 = MSP_ELEM_LEN_16;
285 prot_desc->tx_elem_len_2 = MSP_ELEM_LEN_16;
286
287 prot_desc->rx_clk_pol = MSP_RISING_EDGE;
288 prot_desc->tx_clk_pol = MSP_FALLING_EDGE;
289
290 prot_desc->rx_data_delay = MSP_DELAY_0;
291 prot_desc->tx_data_delay = MSP_DELAY_0;
292
293 prot_desc->tx_half_word_swap = MSP_SWAP_NONE;
294 prot_desc->rx_half_word_swap = MSP_SWAP_NONE;
295 prot_desc->compression_mode = MSP_COMPRESS_MODE_LINEAR;
296 prot_desc->expansion_mode = MSP_EXPAND_MODE_LINEAR;
297 prot_desc->frame_sync_ignore = MSP_FSYNC_IGNORE;
298
299 return 0;
300}
301
302static int setup_msp_config(struct snd_pcm_substream *substream,
303 struct snd_soc_dai *dai,
304 struct ux500_msp_config *msp_config)
305{
306 struct ux500_msp_i2s_drvdata *drvdata = dev_get_drvdata(dai->dev);
307 struct msp_protdesc *prot_desc = &msp_config->protdesc;
308 struct snd_pcm_runtime *runtime = substream->runtime;
309 unsigned int fmt = drvdata->fmt;
310 int ret;
311
312 memset(msp_config, 0, sizeof(*msp_config));
313
314 msp_config->f_inputclk = drvdata->master_clk;
315
316 msp_config->tx_fifo_config = TX_FIFO_ENABLE;
317 msp_config->rx_fifo_config = RX_FIFO_ENABLE;
318 msp_config->def_elem_len = 1;
319 msp_config->direction = substream->stream == SNDRV_PCM_STREAM_PLAYBACK ?
320 MSP_DIR_TX : MSP_DIR_RX;
321 msp_config->data_size = MSP_DATA_BITS_32;
322 msp_config->frame_freq = runtime->rate;
323
324 dev_dbg(dai->dev, "%s: f_inputclk = %u, frame_freq = %u.\n",
325 __func__, msp_config->f_inputclk, msp_config->frame_freq);
326 /* To avoid division by zero */
327 prot_desc->clocks_per_frame = 1;
328
329 dev_dbg(dai->dev, "%s: rate: %u, channels: %d.\n", __func__,
330 runtime->rate, runtime->channels);
331 switch (fmt &
332 (SND_SOC_DAIFMT_FORMAT_MASK | SND_SOC_DAIFMT_MASTER_MASK)) {
333 case SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS:
334 dev_dbg(dai->dev, "%s: SND_SOC_DAIFMT_I2S.\n", __func__);
335
336 msp_config->default_protdesc = 1;
337 msp_config->protocol = MSP_I2S_PROTOCOL;
338 break;
339
340 case SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBM_CFM:
341 dev_dbg(dai->dev, "%s: SND_SOC_DAIFMT_I2S.\n", __func__);
342
343 msp_config->data_size = MSP_DATA_BITS_16;
344 msp_config->protocol = MSP_I2S_PROTOCOL;
345
346 ret = setup_i2s_protdesc(prot_desc);
347 if (ret < 0)
348 return ret;
349
350 break;
351
352 case SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_CBS_CFS:
353 case SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_CBM_CFM:
354 case SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBS_CFS:
355 case SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM:
356 dev_dbg(dai->dev, "%s: PCM format.\n", __func__);
357
358 msp_config->data_size = MSP_DATA_BITS_16;
359 msp_config->protocol = MSP_PCM_PROTOCOL;
360
361 ret = setup_pcm_protdesc(dai, fmt, prot_desc);
362 if (ret < 0)
363 return ret;
364
365 ret = setup_pcm_multichan(dai, msp_config);
366 if (ret < 0)
367 return ret;
368
369 ret = setup_pcm_framing(dai, runtime->rate, prot_desc);
370 if (ret < 0)
371 return ret;
372
373 break;
374
375 default:
376 dev_err(dai->dev, "%s: Error: Unsopported format (%d)!\n",
377 __func__, fmt);
378 return -EINVAL;
379 }
380
381 return setup_clocking(dai, fmt, msp_config);
382}
383
384static int ux500_msp_dai_startup(struct snd_pcm_substream *substream,
385 struct snd_soc_dai *dai)
386{
387 int ret = 0;
388 struct ux500_msp_i2s_drvdata *drvdata = dev_get_drvdata(dai->dev);
389
390 dev_dbg(dai->dev, "%s: MSP %d (%s): Enter.\n", __func__, dai->id,
391 snd_pcm_stream_str(substream));
392
393 /* Enable regulator */
394 ret = regulator_enable(drvdata->reg_vape);
395 if (ret != 0) {
396 dev_err(drvdata->msp->dev,
397 "%s: Failed to enable regulator!\n", __func__);
398 return ret;
399 }
400
401 /* Enable clock */
402 dev_dbg(dai->dev, "%s: Enabling MSP-clock.\n", __func__);
403 clk_enable(drvdata->clk);
404
405 return 0;
406}
407
408static void ux500_msp_dai_shutdown(struct snd_pcm_substream *substream,
409 struct snd_soc_dai *dai)
410{
411 int ret;
412 struct ux500_msp_i2s_drvdata *drvdata = dev_get_drvdata(dai->dev);
413 bool is_playback = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK);
414
415 dev_dbg(dai->dev, "%s: MSP %d (%s): Enter.\n", __func__, dai->id,
416 snd_pcm_stream_str(substream));
417
418 if (drvdata->vape_opp_constraint == 1) {
419 prcmu_qos_update_requirement(PRCMU_QOS_APE_OPP,
420 "ux500_msp_i2s", 50);
421 drvdata->vape_opp_constraint = 0;
422 }
423
424 if (ux500_msp_i2s_close(drvdata->msp,
425 is_playback ? MSP_DIR_TX : MSP_DIR_RX)) {
426 dev_err(dai->dev,
427 "%s: Error: MSP %d (%s): Unable to close i2s.\n",
428 __func__, dai->id, snd_pcm_stream_str(substream));
429 }
430
431 /* Disable clock */
432 clk_disable(drvdata->clk);
433
434 /* Disable regulator */
435 ret = regulator_disable(drvdata->reg_vape);
436 if (ret < 0)
437 dev_err(dai->dev,
438 "%s: ERROR: Failed to disable regulator (%d)!\n",
439 __func__, ret);
440}
441
442static int ux500_msp_dai_prepare(struct snd_pcm_substream *substream,
443 struct snd_soc_dai *dai)
444{
445 int ret = 0;
446 struct ux500_msp_i2s_drvdata *drvdata = dev_get_drvdata(dai->dev);
447 struct snd_pcm_runtime *runtime = substream->runtime;
448 struct ux500_msp_config msp_config;
449
450 dev_dbg(dai->dev, "%s: MSP %d (%s): Enter (rate = %d).\n", __func__,
451 dai->id, snd_pcm_stream_str(substream), runtime->rate);
452
453 setup_msp_config(substream, dai, &msp_config);
454
455 ret = ux500_msp_i2s_open(drvdata->msp, &msp_config);
456 if (ret < 0) {
457 dev_err(dai->dev, "%s: Error: msp_setup failed (ret = %d)!\n",
458 __func__, ret);
459 return ret;
460 }
461
462 /* Set OPP-level */
463 if ((drvdata->fmt & SND_SOC_DAIFMT_MASTER_MASK) &&
464 (drvdata->msp->f_bitclk > 19200000)) {
465 /* If the bit-clock is higher than 19.2MHz, Vape should be
466 * run in 100% OPP. Only when bit-clock is used (MSP master) */
467 prcmu_qos_update_requirement(PRCMU_QOS_APE_OPP,
468 "ux500-msp-i2s", 100);
469 drvdata->vape_opp_constraint = 1;
470 } else {
471 prcmu_qos_update_requirement(PRCMU_QOS_APE_OPP,
472 "ux500-msp-i2s", 50);
473 drvdata->vape_opp_constraint = 0;
474 }
475
476 return ret;
477}
478
479static int ux500_msp_dai_hw_params(struct snd_pcm_substream *substream,
480 struct snd_pcm_hw_params *params,
481 struct snd_soc_dai *dai)
482{
483 unsigned int mask, slots_active;
484 struct snd_pcm_runtime *runtime = substream->runtime;
485 struct ux500_msp_i2s_drvdata *drvdata = dev_get_drvdata(dai->dev);
486
487 dev_dbg(dai->dev, "%s: MSP %d (%s): Enter.\n",
488 __func__, dai->id, snd_pcm_stream_str(substream));
489
490 switch (drvdata->fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
491 case SND_SOC_DAIFMT_I2S:
492 snd_pcm_hw_constraint_minmax(runtime,
493 SNDRV_PCM_HW_PARAM_CHANNELS,
494 1, 2);
495 break;
496
497 case SND_SOC_DAIFMT_DSP_B:
498 case SND_SOC_DAIFMT_DSP_A:
499 mask = substream->stream == SNDRV_PCM_STREAM_PLAYBACK ?
500 drvdata->tx_mask :
501 drvdata->rx_mask;
502
503 slots_active = hweight32(mask);
504 dev_dbg(dai->dev, "TDM-slots active: %d", slots_active);
505
506 snd_pcm_hw_constraint_minmax(runtime,
507 SNDRV_PCM_HW_PARAM_CHANNELS,
508 slots_active, slots_active);
509 break;
510
511 default:
512 dev_err(dai->dev,
513 "%s: Error: Unsupported protocol (fmt = 0x%x)!\n",
514 __func__, drvdata->fmt);
515 return -EINVAL;
516 }
517
518 return 0;
519}
520
521static int ux500_msp_dai_set_dai_fmt(struct snd_soc_dai *dai,
522 unsigned int fmt)
523{
524 struct ux500_msp_i2s_drvdata *drvdata = dev_get_drvdata(dai->dev);
525
526 dev_dbg(dai->dev, "%s: MSP %d: Enter.\n", __func__, dai->id);
527
528 switch (fmt & (SND_SOC_DAIFMT_FORMAT_MASK |
529 SND_SOC_DAIFMT_MASTER_MASK)) {
530 case SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS:
531 case SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBM_CFM:
532 case SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBS_CFS:
533 case SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM:
534 case SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_CBS_CFS:
535 case SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_CBM_CFM:
536 break;
537
538 default:
539 dev_err(dai->dev,
540 "%s: Error: Unsupported protocol/master (fmt = 0x%x)!\n",
541 __func__, drvdata->fmt);
542 return -EINVAL;
543 }
544
545 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
546 case SND_SOC_DAIFMT_NB_NF:
547 case SND_SOC_DAIFMT_NB_IF:
548 case SND_SOC_DAIFMT_IB_IF:
549 break;
550
551 default:
552 dev_err(dai->dev,
553 "%s: Error: Unsupported inversion (fmt = 0x%x)!\n",
554 __func__, drvdata->fmt);
555 return -EINVAL;
556 }
557
558 drvdata->fmt = fmt;
559 return 0;
560}
561
562static int ux500_msp_dai_set_tdm_slot(struct snd_soc_dai *dai,
563 unsigned int tx_mask,
564 unsigned int rx_mask,
565 int slots, int slot_width)
566{
567 struct ux500_msp_i2s_drvdata *drvdata = dev_get_drvdata(dai->dev);
568 unsigned int cap;
569
570 switch (slots) {
571 case 1:
572 cap = 0x01;
573 break;
574 case 2:
575 cap = 0x03;
576 break;
577 case 8:
578 cap = 0xFF;
579 break;
580 case 16:
581 cap = 0xFFFF;
582 break;
583 default:
584 dev_err(dai->dev, "%s: Error: Unsupported slot-count (%d)!\n",
585 __func__, slots);
586 return -EINVAL;
587 }
588 drvdata->slots = slots;
589
590 if (!(slot_width == 16)) {
591 dev_err(dai->dev, "%s: Error: Unsupported slot-width (%d)!\n",
592 __func__, slot_width);
593 return -EINVAL;
594 }
595 drvdata->slot_width = slot_width;
596
597 drvdata->tx_mask = tx_mask & cap;
598 drvdata->rx_mask = rx_mask & cap;
599
600 return 0;
601}
602
603static int ux500_msp_dai_set_dai_sysclk(struct snd_soc_dai *dai,
604 int clk_id, unsigned int freq, int dir)
605{
606 struct ux500_msp_i2s_drvdata *drvdata = dev_get_drvdata(dai->dev);
607
608 dev_dbg(dai->dev, "%s: MSP %d: Enter. clk-id: %d, freq: %u.\n",
609 __func__, dai->id, clk_id, freq);
610
611 switch (clk_id) {
612 case UX500_MSP_MASTER_CLOCK:
613 drvdata->master_clk = freq;
614 break;
615
616 default:
617 dev_err(dai->dev, "%s: MSP %d: Invalid clk-id (%d)!\n",
618 __func__, dai->id, clk_id);
619 return -EINVAL;
620 }
621
622 return 0;
623}
624
625static int ux500_msp_dai_trigger(struct snd_pcm_substream *substream,
626 int cmd, struct snd_soc_dai *dai)
627{
628 int ret = 0;
629 struct ux500_msp_i2s_drvdata *drvdata = dev_get_drvdata(dai->dev);
630
631 dev_dbg(dai->dev, "%s: MSP %d (%s): Enter (msp->id = %d, cmd = %d).\n",
632 __func__, dai->id, snd_pcm_stream_str(substream),
633 (int)drvdata->msp->id, cmd);
634
635 ret = ux500_msp_i2s_trigger(drvdata->msp, cmd, substream->stream);
636
637 return ret;
638}
639
640static int ux500_msp_dai_probe(struct snd_soc_dai *dai)
641{
642 struct ux500_msp_i2s_drvdata *drvdata = dev_get_drvdata(dai->dev);
643
644 drvdata->playback_dma_data.dma_cfg = drvdata->msp->dma_cfg_tx;
645 drvdata->capture_dma_data.dma_cfg = drvdata->msp->dma_cfg_rx;
646
647 dai->playback_dma_data = &drvdata->playback_dma_data;
648 dai->capture_dma_data = &drvdata->capture_dma_data;
649
650 drvdata->playback_dma_data.data_size = drvdata->slot_width;
651 drvdata->capture_dma_data.data_size = drvdata->slot_width;
652
653 return 0;
654}
655
656static struct snd_soc_dai_ops ux500_msp_dai_ops[] = {
657 {
658 .set_sysclk = ux500_msp_dai_set_dai_sysclk,
659 .set_fmt = ux500_msp_dai_set_dai_fmt,
660 .set_tdm_slot = ux500_msp_dai_set_tdm_slot,
661 .startup = ux500_msp_dai_startup,
662 .shutdown = ux500_msp_dai_shutdown,
663 .prepare = ux500_msp_dai_prepare,
664 .trigger = ux500_msp_dai_trigger,
665 .hw_params = ux500_msp_dai_hw_params,
666 }
667};
668
669static struct snd_soc_dai_driver ux500_msp_dai_drv[UX500_NBR_OF_DAI] = {
670 {
671 .name = "ux500-msp-i2s.0",
672 .probe = ux500_msp_dai_probe,
673 .id = 0,
674 .suspend = NULL,
675 .resume = NULL,
676 .playback = {
677 .channels_min = UX500_MSP_MIN_CHANNELS,
678 .channels_max = UX500_MSP_MAX_CHANNELS,
679 .rates = UX500_I2S_RATES,
680 .formats = UX500_I2S_FORMATS,
681 },
682 .capture = {
683 .channels_min = UX500_MSP_MIN_CHANNELS,
684 .channels_max = UX500_MSP_MAX_CHANNELS,
685 .rates = UX500_I2S_RATES,
686 .formats = UX500_I2S_FORMATS,
687 },
688 .ops = ux500_msp_dai_ops,
689 },
690 {
691 .name = "ux500-msp-i2s.1",
692 .probe = ux500_msp_dai_probe,
693 .id = 1,
694 .suspend = NULL,
695 .resume = NULL,
696 .playback = {
697 .channels_min = UX500_MSP_MIN_CHANNELS,
698 .channels_max = UX500_MSP_MAX_CHANNELS,
699 .rates = UX500_I2S_RATES,
700 .formats = UX500_I2S_FORMATS,
701 },
702 .capture = {
703 .channels_min = UX500_MSP_MIN_CHANNELS,
704 .channels_max = UX500_MSP_MAX_CHANNELS,
705 .rates = UX500_I2S_RATES,
706 .formats = UX500_I2S_FORMATS,
707 },
708 .ops = ux500_msp_dai_ops,
709 },
710 {
711 .name = "ux500-msp-i2s.2",
712 .id = 2,
713 .probe = ux500_msp_dai_probe,
714 .suspend = NULL,
715 .resume = NULL,
716 .playback = {
717 .channels_min = UX500_MSP_MIN_CHANNELS,
718 .channels_max = UX500_MSP_MAX_CHANNELS,
719 .rates = UX500_I2S_RATES,
720 .formats = UX500_I2S_FORMATS,
721 },
722 .capture = {
723 .channels_min = UX500_MSP_MIN_CHANNELS,
724 .channels_max = UX500_MSP_MAX_CHANNELS,
725 .rates = UX500_I2S_RATES,
726 .formats = UX500_I2S_FORMATS,
727 },
728 .ops = ux500_msp_dai_ops,
729 },
730 {
731 .name = "ux500-msp-i2s.3",
732 .probe = ux500_msp_dai_probe,
733 .id = 3,
734 .suspend = NULL,
735 .resume = NULL,
736 .playback = {
737 .channels_min = UX500_MSP_MIN_CHANNELS,
738 .channels_max = UX500_MSP_MAX_CHANNELS,
739 .rates = UX500_I2S_RATES,
740 .formats = UX500_I2S_FORMATS,
741 },
742 .capture = {
743 .channels_min = UX500_MSP_MIN_CHANNELS,
744 .channels_max = UX500_MSP_MAX_CHANNELS,
745 .rates = UX500_I2S_RATES,
746 .formats = UX500_I2S_FORMATS,
747 },
748 .ops = ux500_msp_dai_ops,
749 },
750};
751
752static int __devinit ux500_msp_drv_probe(struct platform_device *pdev)
753{
754 struct ux500_msp_i2s_drvdata *drvdata;
755 int ret = 0;
756
757 dev_dbg(&pdev->dev, "%s: Enter (pdev->name = %s).\n", __func__,
758 pdev->name);
759
760 drvdata = devm_kzalloc(&pdev->dev,
761 sizeof(struct ux500_msp_i2s_drvdata),
762 GFP_KERNEL);
763 drvdata->fmt = 0;
764 drvdata->slots = 1;
765 drvdata->tx_mask = 0x01;
766 drvdata->rx_mask = 0x01;
767 drvdata->slot_width = 16;
768 drvdata->master_clk = MSP_INPUT_FREQ_APB;
769
770 drvdata->reg_vape = devm_regulator_get(&pdev->dev, "v-ape");
771 if (IS_ERR(drvdata->reg_vape)) {
772 ret = (int)PTR_ERR(drvdata->reg_vape);
773 dev_err(&pdev->dev,
774 "%s: ERROR: Failed to get Vape supply (%d)!\n",
775 __func__, ret);
776 return ret;
777 }
778 prcmu_qos_add_requirement(PRCMU_QOS_APE_OPP, (char *)pdev->name, 50);
779
780 drvdata->clk = clk_get(&pdev->dev, NULL);
781 if (IS_ERR(drvdata->clk)) {
782 ret = (int)PTR_ERR(drvdata->clk);
783 dev_err(&pdev->dev, "%s: ERROR: clk_get failed (%d)!\n",
784 __func__, ret);
785 goto err_clk;
786 }
787
788 ret = ux500_msp_i2s_init_msp(pdev, &drvdata->msp,
789 pdev->dev.platform_data);
790 if (!drvdata->msp) {
791 dev_err(&pdev->dev,
792 "%s: ERROR: Failed to init MSP-struct (%d)!",
793 __func__, ret);
794 goto err_init_msp;
795 }
796 dev_set_drvdata(&pdev->dev, drvdata);
797
798 ret = snd_soc_register_dai(&pdev->dev,
799 &ux500_msp_dai_drv[drvdata->msp->id]);
800 if (ret < 0) {
801 dev_err(&pdev->dev, "Error: %s: Failed to register MSP%d!\n",
802 __func__, drvdata->msp->id);
803 goto err_init_msp;
804 }
805
806 return 0;
807
808err_init_msp:
809 clk_put(drvdata->clk);
810
811err_clk:
812 devm_regulator_put(drvdata->reg_vape);
813
814 return ret;
815}
816
817static int __devexit ux500_msp_drv_remove(struct platform_device *pdev)
818{
819 struct ux500_msp_i2s_drvdata *drvdata = dev_get_drvdata(&pdev->dev);
820
821 snd_soc_unregister_dais(&pdev->dev, ARRAY_SIZE(ux500_msp_dai_drv));
822
823 devm_regulator_put(drvdata->reg_vape);
824 prcmu_qos_remove_requirement(PRCMU_QOS_APE_OPP, "ux500_msp_i2s");
825
826 clk_put(drvdata->clk);
827
828 ux500_msp_i2s_cleanup_msp(pdev, drvdata->msp);
829
830 return 0;
831}
832
833static struct platform_driver msp_i2s_driver = {
834 .driver = {
835 .name = "ux500-msp-i2s",
836 .owner = THIS_MODULE,
837 },
838 .probe = ux500_msp_drv_probe,
839 .remove = ux500_msp_drv_remove,
840};
841module_platform_driver(msp_i2s_driver);
842
843MODULE_LICENSE("GPLv2");
diff --git a/sound/soc/ux500/ux500_msp_dai.h b/sound/soc/ux500/ux500_msp_dai.h
new file mode 100644
index 000000000000..98202a34a5dd
--- /dev/null
+++ b/sound/soc/ux500/ux500_msp_dai.h
@@ -0,0 +1,79 @@
1/*
2 * Copyright (C) ST-Ericsson SA 2012
3 *
4 * Author: Ola Lilja <ola.o.lilja@stericsson.com>,
5 * Roger Nilsson <roger.xr.nilsson@stericsson.com>
6 * for ST-Ericsson.
7 *
8 * License terms:
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as published
12 * by the Free Software Foundation.
13 */
14
15#ifndef UX500_msp_dai_H
16#define UX500_msp_dai_H
17
18#include <linux/types.h>
19#include <linux/spinlock.h>
20
21#include "ux500_msp_i2s.h"
22
23#define UX500_NBR_OF_DAI 4
24
25#define UX500_I2S_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 | \
26 SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000)
27
28#define UX500_I2S_FORMATS (SNDRV_PCM_FMTBIT_S16_LE)
29
30#define FRAME_PER_SINGLE_SLOT_8_KHZ 31
31#define FRAME_PER_SINGLE_SLOT_16_KHZ 124
32#define FRAME_PER_SINGLE_SLOT_44_1_KHZ 63
33#define FRAME_PER_SINGLE_SLOT_48_KHZ 49
34#define FRAME_PER_2_SLOTS 31
35#define FRAME_PER_8_SLOTS 138
36#define FRAME_PER_16_SLOTS 277
37
38#ifndef CONFIG_SND_SOC_UX500_AB5500
39#define UX500_MSP_INTERNAL_CLOCK_FREQ 40000000
40#define UX500_MSP1_INTERNAL_CLOCK_FREQ UX500_MSP_INTERNAL_CLOCK_FREQ
41#else
42#define UX500_MSP_INTERNAL_CLOCK_FREQ 13000000
43#define UX500_MSP1_INTERNAL_CLOCK_FREQ (UX500_MSP_INTERNAL_CLOCK_FREQ * 2)
44#endif
45
46#define UX500_MSP_MIN_CHANNELS 1
47#define UX500_MSP_MAX_CHANNELS 8
48
49#define PLAYBACK_CONFIGURED 1
50#define CAPTURE_CONFIGURED 2
51
52enum ux500_msp_clock_id {
53 UX500_MSP_MASTER_CLOCK,
54};
55
56struct ux500_msp_i2s_drvdata {
57 struct ux500_msp *msp;
58 struct regulator *reg_vape;
59 struct ux500_msp_dma_params playback_dma_data;
60 struct ux500_msp_dma_params capture_dma_data;
61 unsigned int fmt;
62 unsigned int tx_mask;
63 unsigned int rx_mask;
64 int slots;
65 int slot_width;
66 u8 configured;
67 int data_delay;
68
69 /* Clocks */
70 unsigned int master_clk;
71 struct clk *clk;
72
73 /* Regulators */
74 int vape_opp_constraint;
75};
76
77int ux500_msp_dai_set_data_delay(struct snd_soc_dai *dai, int delay);
78
79#endif
diff --git a/sound/soc/ux500/ux500_msp_i2s.c b/sound/soc/ux500/ux500_msp_i2s.c
new file mode 100644
index 000000000000..496dec10c96e
--- /dev/null
+++ b/sound/soc/ux500/ux500_msp_i2s.c
@@ -0,0 +1,742 @@
1/*
2 * Copyright (C) ST-Ericsson SA 2012
3 *
4 * Author: Ola Lilja <ola.o.lilja@stericsson.com>,
5 * Roger Nilsson <roger.xr.nilsson@stericsson.com>,
6 * Sandeep Kaushik <sandeep.kaushik@st.com>
7 * for ST-Ericsson.
8 *
9 * License terms:
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as published
13 * by the Free Software Foundation.
14 */
15
16#include <linux/module.h>
17#include <linux/platform_device.h>
18#include <linux/delay.h>
19#include <linux/slab.h>
20
21#include <mach/hardware.h>
22#include <mach/board-mop500-msp.h>
23
24#include <sound/soc.h>
25
26#include "ux500_msp_i2s.h"
27
28 /* Protocol desciptors */
29static const struct msp_protdesc prot_descs[] = {
30 { /* I2S */
31 MSP_SINGLE_PHASE,
32 MSP_SINGLE_PHASE,
33 MSP_PHASE2_START_MODE_IMEDIATE,
34 MSP_PHASE2_START_MODE_IMEDIATE,
35 MSP_BTF_MS_BIT_FIRST,
36 MSP_BTF_MS_BIT_FIRST,
37 MSP_FRAME_LEN_1,
38 MSP_FRAME_LEN_1,
39 MSP_FRAME_LEN_1,
40 MSP_FRAME_LEN_1,
41 MSP_ELEM_LEN_32,
42 MSP_ELEM_LEN_32,
43 MSP_ELEM_LEN_32,
44 MSP_ELEM_LEN_32,
45 MSP_DELAY_1,
46 MSP_DELAY_1,
47 MSP_RISING_EDGE,
48 MSP_FALLING_EDGE,
49 MSP_FSYNC_POL_ACT_LO,
50 MSP_FSYNC_POL_ACT_LO,
51 MSP_SWAP_NONE,
52 MSP_SWAP_NONE,
53 MSP_COMPRESS_MODE_LINEAR,
54 MSP_EXPAND_MODE_LINEAR,
55 MSP_FSYNC_IGNORE,
56 31,
57 15,
58 32,
59 }, { /* PCM */
60 MSP_DUAL_PHASE,
61 MSP_DUAL_PHASE,
62 MSP_PHASE2_START_MODE_FSYNC,
63 MSP_PHASE2_START_MODE_FSYNC,
64 MSP_BTF_MS_BIT_FIRST,
65 MSP_BTF_MS_BIT_FIRST,
66 MSP_FRAME_LEN_1,
67 MSP_FRAME_LEN_1,
68 MSP_FRAME_LEN_1,
69 MSP_FRAME_LEN_1,
70 MSP_ELEM_LEN_16,
71 MSP_ELEM_LEN_16,
72 MSP_ELEM_LEN_16,
73 MSP_ELEM_LEN_16,
74 MSP_DELAY_0,
75 MSP_DELAY_0,
76 MSP_RISING_EDGE,
77 MSP_FALLING_EDGE,
78 MSP_FSYNC_POL_ACT_HI,
79 MSP_FSYNC_POL_ACT_HI,
80 MSP_SWAP_NONE,
81 MSP_SWAP_NONE,
82 MSP_COMPRESS_MODE_LINEAR,
83 MSP_EXPAND_MODE_LINEAR,
84 MSP_FSYNC_IGNORE,
85 255,
86 0,
87 256,
88 }, { /* Companded PCM */
89 MSP_SINGLE_PHASE,
90 MSP_SINGLE_PHASE,
91 MSP_PHASE2_START_MODE_FSYNC,
92 MSP_PHASE2_START_MODE_FSYNC,
93 MSP_BTF_MS_BIT_FIRST,
94 MSP_BTF_MS_BIT_FIRST,
95 MSP_FRAME_LEN_1,
96 MSP_FRAME_LEN_1,
97 MSP_FRAME_LEN_1,
98 MSP_FRAME_LEN_1,
99 MSP_ELEM_LEN_8,
100 MSP_ELEM_LEN_8,
101 MSP_ELEM_LEN_8,
102 MSP_ELEM_LEN_8,
103 MSP_DELAY_0,
104 MSP_DELAY_0,
105 MSP_RISING_EDGE,
106 MSP_RISING_EDGE,
107 MSP_FSYNC_POL_ACT_HI,
108 MSP_FSYNC_POL_ACT_HI,
109 MSP_SWAP_NONE,
110 MSP_SWAP_NONE,
111 MSP_COMPRESS_MODE_LINEAR,
112 MSP_EXPAND_MODE_LINEAR,
113 MSP_FSYNC_IGNORE,
114 255,
115 0,
116 256,
117 },
118};
119
120static void set_prot_desc_tx(struct ux500_msp *msp,
121 struct msp_protdesc *protdesc,
122 enum msp_data_size data_size)
123{
124 u32 temp_reg = 0;
125
126 temp_reg |= MSP_P2_ENABLE_BIT(protdesc->tx_phase_mode);
127 temp_reg |= MSP_P2_START_MODE_BIT(protdesc->tx_phase2_start_mode);
128 temp_reg |= MSP_P1_FRAME_LEN_BITS(protdesc->tx_frame_len_1);
129 temp_reg |= MSP_P2_FRAME_LEN_BITS(protdesc->tx_frame_len_2);
130 if (msp->def_elem_len) {
131 temp_reg |= MSP_P1_ELEM_LEN_BITS(protdesc->tx_elem_len_1);
132 temp_reg |= MSP_P2_ELEM_LEN_BITS(protdesc->tx_elem_len_2);
133 } else {
134 temp_reg |= MSP_P1_ELEM_LEN_BITS(data_size);
135 temp_reg |= MSP_P2_ELEM_LEN_BITS(data_size);
136 }
137 temp_reg |= MSP_DATA_DELAY_BITS(protdesc->tx_data_delay);
138 temp_reg |= MSP_SET_ENDIANNES_BIT(protdesc->tx_byte_order);
139 temp_reg |= MSP_FSYNC_POL(protdesc->tx_fsync_pol);
140 temp_reg |= MSP_DATA_WORD_SWAP(protdesc->tx_half_word_swap);
141 temp_reg |= MSP_SET_COMPANDING_MODE(protdesc->compression_mode);
142 temp_reg |= MSP_SET_FSYNC_IGNORE(protdesc->frame_sync_ignore);
143
144 writel(temp_reg, msp->registers + MSP_TCF);
145}
146
147static void set_prot_desc_rx(struct ux500_msp *msp,
148 struct msp_protdesc *protdesc,
149 enum msp_data_size data_size)
150{
151 u32 temp_reg = 0;
152
153 temp_reg |= MSP_P2_ENABLE_BIT(protdesc->rx_phase_mode);
154 temp_reg |= MSP_P2_START_MODE_BIT(protdesc->rx_phase2_start_mode);
155 temp_reg |= MSP_P1_FRAME_LEN_BITS(protdesc->rx_frame_len_1);
156 temp_reg |= MSP_P2_FRAME_LEN_BITS(protdesc->rx_frame_len_2);
157 if (msp->def_elem_len) {
158 temp_reg |= MSP_P1_ELEM_LEN_BITS(protdesc->rx_elem_len_1);
159 temp_reg |= MSP_P2_ELEM_LEN_BITS(protdesc->rx_elem_len_2);
160 } else {
161 temp_reg |= MSP_P1_ELEM_LEN_BITS(data_size);
162 temp_reg |= MSP_P2_ELEM_LEN_BITS(data_size);
163 }
164
165 temp_reg |= MSP_DATA_DELAY_BITS(protdesc->rx_data_delay);
166 temp_reg |= MSP_SET_ENDIANNES_BIT(protdesc->rx_byte_order);
167 temp_reg |= MSP_FSYNC_POL(protdesc->rx_fsync_pol);
168 temp_reg |= MSP_DATA_WORD_SWAP(protdesc->rx_half_word_swap);
169 temp_reg |= MSP_SET_COMPANDING_MODE(protdesc->expansion_mode);
170 temp_reg |= MSP_SET_FSYNC_IGNORE(protdesc->frame_sync_ignore);
171
172 writel(temp_reg, msp->registers + MSP_RCF);
173}
174
175static int configure_protocol(struct ux500_msp *msp,
176 struct ux500_msp_config *config)
177{
178 struct msp_protdesc *protdesc;
179 enum msp_data_size data_size;
180 u32 temp_reg = 0;
181
182 data_size = config->data_size;
183 msp->def_elem_len = config->def_elem_len;
184 if (config->default_protdesc == 1) {
185 if (config->protocol >= MSP_INVALID_PROTOCOL) {
186 dev_err(msp->dev, "%s: ERROR: Invalid protocol!\n",
187 __func__);
188 return -EINVAL;
189 }
190 protdesc =
191 (struct msp_protdesc *)&prot_descs[config->protocol];
192 } else {
193 protdesc = (struct msp_protdesc *)&config->protdesc;
194 }
195
196 if (data_size < MSP_DATA_BITS_DEFAULT || data_size > MSP_DATA_BITS_32) {
197 dev_err(msp->dev,
198 "%s: ERROR: Invalid data-size requested (data_size = %d)!\n",
199 __func__, data_size);
200 return -EINVAL;
201 }
202
203 if (config->direction & MSP_DIR_TX)
204 set_prot_desc_tx(msp, protdesc, data_size);
205 if (config->direction & MSP_DIR_RX)
206 set_prot_desc_rx(msp, protdesc, data_size);
207
208 /* The code below should not be separated. */
209 temp_reg = readl(msp->registers + MSP_GCR) & ~TX_CLK_POL_RISING;
210 temp_reg |= MSP_TX_CLKPOL_BIT(~protdesc->tx_clk_pol);
211 writel(temp_reg, msp->registers + MSP_GCR);
212 temp_reg = readl(msp->registers + MSP_GCR) & ~RX_CLK_POL_RISING;
213 temp_reg |= MSP_RX_CLKPOL_BIT(protdesc->rx_clk_pol);
214 writel(temp_reg, msp->registers + MSP_GCR);
215
216 return 0;
217}
218
219static int setup_bitclk(struct ux500_msp *msp, struct ux500_msp_config *config)
220{
221 u32 reg_val_GCR;
222 u32 frame_per = 0;
223 u32 sck_div = 0;
224 u32 frame_width = 0;
225 u32 temp_reg = 0;
226 struct msp_protdesc *protdesc = NULL;
227
228 reg_val_GCR = readl(msp->registers + MSP_GCR);
229 writel(reg_val_GCR & ~SRG_ENABLE, msp->registers + MSP_GCR);
230
231 if (config->default_protdesc)
232 protdesc =
233 (struct msp_protdesc *)&prot_descs[config->protocol];
234 else
235 protdesc = (struct msp_protdesc *)&config->protdesc;
236
237 switch (config->protocol) {
238 case MSP_PCM_PROTOCOL:
239 case MSP_PCM_COMPAND_PROTOCOL:
240 frame_width = protdesc->frame_width;
241 sck_div = config->f_inputclk / (config->frame_freq *
242 (protdesc->clocks_per_frame));
243 frame_per = protdesc->frame_period;
244 break;
245 case MSP_I2S_PROTOCOL:
246 frame_width = protdesc->frame_width;
247 sck_div = config->f_inputclk / (config->frame_freq *
248 (protdesc->clocks_per_frame));
249 frame_per = protdesc->frame_period;
250 break;
251 default:
252 dev_err(msp->dev, "%s: ERROR: Unknown protocol (%d)!\n",
253 __func__,
254 config->protocol);
255 return -EINVAL;
256 }
257
258 temp_reg = (sck_div - 1) & SCK_DIV_MASK;
259 temp_reg |= FRAME_WIDTH_BITS(frame_width);
260 temp_reg |= FRAME_PERIOD_BITS(frame_per);
261 writel(temp_reg, msp->registers + MSP_SRG);
262
263 msp->f_bitclk = (config->f_inputclk)/(sck_div + 1);
264
265 /* Enable bit-clock */
266 udelay(100);
267 reg_val_GCR = readl(msp->registers + MSP_GCR);
268 writel(reg_val_GCR | SRG_ENABLE, msp->registers + MSP_GCR);
269 udelay(100);
270
271 return 0;
272}
273
274static int configure_multichannel(struct ux500_msp *msp,
275 struct ux500_msp_config *config)
276{
277 struct msp_protdesc *protdesc;
278 struct msp_multichannel_config *mcfg;
279 u32 reg_val_MCR;
280
281 if (config->default_protdesc == 1) {
282 if (config->protocol >= MSP_INVALID_PROTOCOL) {
283 dev_err(msp->dev,
284 "%s: ERROR: Invalid protocol (%d)!\n",
285 __func__, config->protocol);
286 return -EINVAL;
287 }
288 protdesc = (struct msp_protdesc *)
289 &prot_descs[config->protocol];
290 } else {
291 protdesc = (struct msp_protdesc *)&config->protdesc;
292 }
293
294 mcfg = &config->multichannel_config;
295 if (mcfg->tx_multichannel_enable) {
296 if (protdesc->tx_phase_mode == MSP_SINGLE_PHASE) {
297 reg_val_MCR = readl(msp->registers + MSP_MCR);
298 writel(reg_val_MCR | (mcfg->tx_multichannel_enable ?
299 1 << TMCEN_BIT : 0),
300 msp->registers + MSP_MCR);
301 writel(mcfg->tx_channel_0_enable,
302 msp->registers + MSP_TCE0);
303 writel(mcfg->tx_channel_1_enable,
304 msp->registers + MSP_TCE1);
305 writel(mcfg->tx_channel_2_enable,
306 msp->registers + MSP_TCE2);
307 writel(mcfg->tx_channel_3_enable,
308 msp->registers + MSP_TCE3);
309 } else {
310 dev_err(msp->dev,
311 "%s: ERROR: Only single-phase supported (TX-mode: %d)!\n",
312 __func__, protdesc->tx_phase_mode);
313 return -EINVAL;
314 }
315 }
316 if (mcfg->rx_multichannel_enable) {
317 if (protdesc->rx_phase_mode == MSP_SINGLE_PHASE) {
318 reg_val_MCR = readl(msp->registers + MSP_MCR);
319 writel(reg_val_MCR | (mcfg->rx_multichannel_enable ?
320 1 << RMCEN_BIT : 0),
321 msp->registers + MSP_MCR);
322 writel(mcfg->rx_channel_0_enable,
323 msp->registers + MSP_RCE0);
324 writel(mcfg->rx_channel_1_enable,
325 msp->registers + MSP_RCE1);
326 writel(mcfg->rx_channel_2_enable,
327 msp->registers + MSP_RCE2);
328 writel(mcfg->rx_channel_3_enable,
329 msp->registers + MSP_RCE3);
330 } else {
331 dev_err(msp->dev,
332 "%s: ERROR: Only single-phase supported (RX-mode: %d)!\n",
333 __func__, protdesc->rx_phase_mode);
334 return -EINVAL;
335 }
336 if (mcfg->rx_comparison_enable_mode) {
337 reg_val_MCR = readl(msp->registers + MSP_MCR);
338 writel(reg_val_MCR |
339 (mcfg->rx_comparison_enable_mode << RCMPM_BIT),
340 msp->registers + MSP_MCR);
341
342 writel(mcfg->comparison_mask,
343 msp->registers + MSP_RCM);
344 writel(mcfg->comparison_value,
345 msp->registers + MSP_RCV);
346
347 }
348 }
349
350 return 0;
351}
352
353static int enable_msp(struct ux500_msp *msp, struct ux500_msp_config *config)
354{
355 int status = 0;
356 u32 reg_val_DMACR, reg_val_GCR;
357
358 /* Check msp state whether in RUN or CONFIGURED Mode */
359 if ((msp->msp_state == MSP_STATE_IDLE) && (msp->plat_init)) {
360 status = msp->plat_init();
361 if (status) {
362 dev_err(msp->dev, "%s: ERROR: Failed to init MSP (%d)!\n",
363 __func__, status);
364 return status;
365 }
366 }
367
368 /* Configure msp with protocol dependent settings */
369 configure_protocol(msp, config);
370 setup_bitclk(msp, config);
371 if (config->multichannel_configured == 1) {
372 status = configure_multichannel(msp, config);
373 if (status)
374 dev_warn(msp->dev,
375 "%s: WARN: configure_multichannel failed (%d)!\n",
376 __func__, status);
377 }
378
379 /* Make sure the correct DMA-directions are configured */
380 if ((config->direction & MSP_DIR_RX) && (!msp->dma_cfg_rx)) {
381 dev_err(msp->dev, "%s: ERROR: MSP RX-mode is not configured!",
382 __func__);
383 return -EINVAL;
384 }
385 if ((config->direction == MSP_DIR_TX) && (!msp->dma_cfg_tx)) {
386 dev_err(msp->dev, "%s: ERROR: MSP TX-mode is not configured!",
387 __func__);
388 return -EINVAL;
389 }
390
391 reg_val_DMACR = readl(msp->registers + MSP_DMACR);
392 if (config->direction & MSP_DIR_RX)
393 reg_val_DMACR |= RX_DMA_ENABLE;
394 if (config->direction & MSP_DIR_TX)
395 reg_val_DMACR |= TX_DMA_ENABLE;
396 writel(reg_val_DMACR, msp->registers + MSP_DMACR);
397
398 writel(config->iodelay, msp->registers + MSP_IODLY);
399
400 /* Enable frame generation logic */
401 reg_val_GCR = readl(msp->registers + MSP_GCR);
402 writel(reg_val_GCR | FRAME_GEN_ENABLE, msp->registers + MSP_GCR);
403
404 return status;
405}
406
407static void flush_fifo_rx(struct ux500_msp *msp)
408{
409 u32 reg_val_DR, reg_val_GCR, reg_val_FLR;
410 u32 limit = 32;
411
412 reg_val_GCR = readl(msp->registers + MSP_GCR);
413 writel(reg_val_GCR | RX_ENABLE, msp->registers + MSP_GCR);
414
415 reg_val_FLR = readl(msp->registers + MSP_FLR);
416 while (!(reg_val_FLR & RX_FIFO_EMPTY) && limit--) {
417 reg_val_DR = readl(msp->registers + MSP_DR);
418 reg_val_FLR = readl(msp->registers + MSP_FLR);
419 }
420
421 writel(reg_val_GCR, msp->registers + MSP_GCR);
422}
423
424static void flush_fifo_tx(struct ux500_msp *msp)
425{
426 u32 reg_val_TSTDR, reg_val_GCR, reg_val_FLR;
427 u32 limit = 32;
428
429 reg_val_GCR = readl(msp->registers + MSP_GCR);
430 writel(reg_val_GCR | TX_ENABLE, msp->registers + MSP_GCR);
431 writel(MSP_ITCR_ITEN | MSP_ITCR_TESTFIFO, msp->registers + MSP_ITCR);
432
433 reg_val_FLR = readl(msp->registers + MSP_FLR);
434 while (!(reg_val_FLR & TX_FIFO_EMPTY) && limit--) {
435 reg_val_TSTDR = readl(msp->registers + MSP_TSTDR);
436 reg_val_FLR = readl(msp->registers + MSP_FLR);
437 }
438 writel(0x0, msp->registers + MSP_ITCR);
439 writel(reg_val_GCR, msp->registers + MSP_GCR);
440}
441
442int ux500_msp_i2s_open(struct ux500_msp *msp,
443 struct ux500_msp_config *config)
444{
445 u32 old_reg, new_reg, mask;
446 int res;
447 unsigned int tx_sel, rx_sel, tx_busy, rx_busy;
448
449 if (in_interrupt()) {
450 dev_err(msp->dev,
451 "%s: ERROR: Open called in interrupt context!\n",
452 __func__);
453 return -1;
454 }
455
456 tx_sel = (config->direction & MSP_DIR_TX) > 0;
457 rx_sel = (config->direction & MSP_DIR_RX) > 0;
458 if (!tx_sel && !rx_sel) {
459 dev_err(msp->dev, "%s: Error: No direction selected!\n",
460 __func__);
461 return -EINVAL;
462 }
463
464 tx_busy = (msp->dir_busy & MSP_DIR_TX) > 0;
465 rx_busy = (msp->dir_busy & MSP_DIR_RX) > 0;
466 if (tx_busy && tx_sel) {
467 dev_err(msp->dev, "%s: Error: TX is in use!\n", __func__);
468 return -EBUSY;
469 }
470 if (rx_busy && rx_sel) {
471 dev_err(msp->dev, "%s: Error: RX is in use!\n", __func__);
472 return -EBUSY;
473 }
474
475 msp->dir_busy |= (tx_sel ? MSP_DIR_TX : 0) | (rx_sel ? MSP_DIR_RX : 0);
476
477 /* First do the global config register */
478 mask = RX_CLK_SEL_MASK | TX_CLK_SEL_MASK | RX_FSYNC_MASK |
479 TX_FSYNC_MASK | RX_SYNC_SEL_MASK | TX_SYNC_SEL_MASK |
480 RX_FIFO_ENABLE_MASK | TX_FIFO_ENABLE_MASK | SRG_CLK_SEL_MASK |
481 LOOPBACK_MASK | TX_EXTRA_DELAY_MASK;
482
483 new_reg = (config->tx_clk_sel | config->rx_clk_sel |
484 config->rx_fsync_pol | config->tx_fsync_pol |
485 config->rx_fsync_sel | config->tx_fsync_sel |
486 config->rx_fifo_config | config->tx_fifo_config |
487 config->srg_clk_sel | config->loopback_enable |
488 config->tx_data_enable);
489
490 old_reg = readl(msp->registers + MSP_GCR);
491 old_reg &= ~mask;
492 new_reg |= old_reg;
493 writel(new_reg, msp->registers + MSP_GCR);
494
495 res = enable_msp(msp, config);
496 if (res < 0) {
497 dev_err(msp->dev, "%s: ERROR: enable_msp failed (%d)!\n",
498 __func__, res);
499 return -EBUSY;
500 }
501 if (config->loopback_enable & 0x80)
502 msp->loopback_enable = 1;
503
504 /* Flush FIFOs */
505 flush_fifo_tx(msp);
506 flush_fifo_rx(msp);
507
508 msp->msp_state = MSP_STATE_CONFIGURED;
509 return 0;
510}
511
512static void disable_msp_rx(struct ux500_msp *msp)
513{
514 u32 reg_val_GCR, reg_val_DMACR, reg_val_IMSC;
515
516 reg_val_GCR = readl(msp->registers + MSP_GCR);
517 writel(reg_val_GCR & ~RX_ENABLE, msp->registers + MSP_GCR);
518 reg_val_DMACR = readl(msp->registers + MSP_DMACR);
519 writel(reg_val_DMACR & ~RX_DMA_ENABLE, msp->registers + MSP_DMACR);
520 reg_val_IMSC = readl(msp->registers + MSP_IMSC);
521 writel(reg_val_IMSC &
522 ~(RX_SERVICE_INT | RX_OVERRUN_ERROR_INT),
523 msp->registers + MSP_IMSC);
524
525 msp->dir_busy &= ~MSP_DIR_RX;
526}
527
528static void disable_msp_tx(struct ux500_msp *msp)
529{
530 u32 reg_val_GCR, reg_val_DMACR, reg_val_IMSC;
531
532 reg_val_GCR = readl(msp->registers + MSP_GCR);
533 writel(reg_val_GCR & ~TX_ENABLE, msp->registers + MSP_GCR);
534 reg_val_DMACR = readl(msp->registers + MSP_DMACR);
535 writel(reg_val_DMACR & ~TX_DMA_ENABLE, msp->registers + MSP_DMACR);
536 reg_val_IMSC = readl(msp->registers + MSP_IMSC);
537 writel(reg_val_IMSC &
538 ~(TX_SERVICE_INT | TX_UNDERRUN_ERR_INT),
539 msp->registers + MSP_IMSC);
540
541 msp->dir_busy &= ~MSP_DIR_TX;
542}
543
544static int disable_msp(struct ux500_msp *msp, unsigned int dir)
545{
546 u32 reg_val_GCR;
547 int status = 0;
548 unsigned int disable_tx, disable_rx;
549
550 reg_val_GCR = readl(msp->registers + MSP_GCR);
551 disable_tx = dir & MSP_DIR_TX;
552 disable_rx = dir & MSP_DIR_TX;
553 if (disable_tx && disable_rx) {
554 reg_val_GCR = readl(msp->registers + MSP_GCR);
555 writel(reg_val_GCR | LOOPBACK_MASK,
556 msp->registers + MSP_GCR);
557
558 /* Flush TX-FIFO */
559 flush_fifo_tx(msp);
560
561 /* Disable TX-channel */
562 writel((readl(msp->registers + MSP_GCR) &
563 (~TX_ENABLE)), msp->registers + MSP_GCR);
564
565 /* Flush RX-FIFO */
566 flush_fifo_rx(msp);
567
568 /* Disable Loopback and Receive channel */
569 writel((readl(msp->registers + MSP_GCR) &
570 (~(RX_ENABLE | LOOPBACK_MASK))),
571 msp->registers + MSP_GCR);
572
573 disable_msp_tx(msp);
574 disable_msp_rx(msp);
575 } else if (disable_tx)
576 disable_msp_tx(msp);
577 else if (disable_rx)
578 disable_msp_rx(msp);
579
580 return status;
581}
582
583int ux500_msp_i2s_trigger(struct ux500_msp *msp, int cmd, int direction)
584{
585 u32 reg_val_GCR, enable_bit;
586
587 if (msp->msp_state == MSP_STATE_IDLE) {
588 dev_err(msp->dev, "%s: ERROR: MSP is not configured!\n",
589 __func__);
590 return -EINVAL;
591 }
592
593 switch (cmd) {
594 case SNDRV_PCM_TRIGGER_START:
595 case SNDRV_PCM_TRIGGER_RESUME:
596 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
597 if (direction == SNDRV_PCM_STREAM_PLAYBACK)
598 enable_bit = TX_ENABLE;
599 else
600 enable_bit = RX_ENABLE;
601 reg_val_GCR = readl(msp->registers + MSP_GCR);
602 writel(reg_val_GCR | enable_bit, msp->registers + MSP_GCR);
603 break;
604
605 case SNDRV_PCM_TRIGGER_STOP:
606 case SNDRV_PCM_TRIGGER_SUSPEND:
607 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
608 if (direction == SNDRV_PCM_STREAM_PLAYBACK)
609 disable_msp_tx(msp);
610 else
611 disable_msp_rx(msp);
612 break;
613 default:
614 return -EINVAL;
615 break;
616 }
617
618 return 0;
619}
620
621int ux500_msp_i2s_close(struct ux500_msp *msp, unsigned int dir)
622{
623 int status = 0;
624
625 dev_dbg(msp->dev, "%s: Enter (dir = 0x%01x).\n", __func__, dir);
626
627 status = disable_msp(msp, dir);
628 if (msp->dir_busy == 0) {
629 /* disable sample rate and frame generators */
630 msp->msp_state = MSP_STATE_IDLE;
631 writel((readl(msp->registers + MSP_GCR) &
632 (~(FRAME_GEN_ENABLE | SRG_ENABLE))),
633 msp->registers + MSP_GCR);
634 if (msp->plat_exit)
635 status = msp->plat_exit();
636 if (status)
637 dev_warn(msp->dev,
638 "%s: WARN: ux500_msp_i2s_exit failed (%d)!\n",
639 __func__, status);
640 writel(0, msp->registers + MSP_GCR);
641 writel(0, msp->registers + MSP_TCF);
642 writel(0, msp->registers + MSP_RCF);
643 writel(0, msp->registers + MSP_DMACR);
644 writel(0, msp->registers + MSP_SRG);
645 writel(0, msp->registers + MSP_MCR);
646 writel(0, msp->registers + MSP_RCM);
647 writel(0, msp->registers + MSP_RCV);
648 writel(0, msp->registers + MSP_TCE0);
649 writel(0, msp->registers + MSP_TCE1);
650 writel(0, msp->registers + MSP_TCE2);
651 writel(0, msp->registers + MSP_TCE3);
652 writel(0, msp->registers + MSP_RCE0);
653 writel(0, msp->registers + MSP_RCE1);
654 writel(0, msp->registers + MSP_RCE2);
655 writel(0, msp->registers + MSP_RCE3);
656 }
657
658 return status;
659
660}
661
662int ux500_msp_i2s_init_msp(struct platform_device *pdev,
663 struct ux500_msp **msp_p,
664 struct msp_i2s_platform_data *platform_data)
665{
666 int ret = 0;
667 struct resource *res = NULL;
668 struct i2s_controller *i2s_cont;
669 struct ux500_msp *msp;
670
671 dev_dbg(&pdev->dev, "%s: Enter (name: %s, id: %d).\n", __func__,
672 pdev->name, platform_data->id);
673
674 *msp_p = devm_kzalloc(&pdev->dev, sizeof(struct ux500_msp), GFP_KERNEL);
675 msp = *msp_p;
676
677 msp->id = platform_data->id;
678 msp->dev = &pdev->dev;
679 msp->plat_init = platform_data->msp_i2s_init;
680 msp->plat_exit = platform_data->msp_i2s_exit;
681 msp->dma_cfg_rx = platform_data->msp_i2s_dma_rx;
682 msp->dma_cfg_tx = platform_data->msp_i2s_dma_tx;
683
684 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
685 if (res == NULL) {
686 dev_err(&pdev->dev, "%s: ERROR: Unable to get resource!\n",
687 __func__);
688 ret = -ENOMEM;
689 goto err_res;
690 }
691
692 msp->registers = ioremap(res->start, (res->end - res->start + 1));
693 if (msp->registers == NULL) {
694 dev_err(&pdev->dev, "%s: ERROR: ioremap failed!\n", __func__);
695 ret = -ENOMEM;
696 goto err_res;
697 }
698
699 msp->msp_state = MSP_STATE_IDLE;
700 msp->loopback_enable = 0;
701
702 /* I2S-controller is allocated and added in I2S controller class. */
703 i2s_cont = devm_kzalloc(&pdev->dev, sizeof(*i2s_cont), GFP_KERNEL);
704 if (!i2s_cont) {
705 dev_err(&pdev->dev,
706 "%s: ERROR: Failed to allocate I2S-controller!\n",
707 __func__);
708 goto err_i2s_cont;
709 }
710 i2s_cont->dev.parent = &pdev->dev;
711 i2s_cont->data = (void *)msp;
712 i2s_cont->id = (s16)msp->id;
713 snprintf(i2s_cont->name, sizeof(i2s_cont->name), "ux500-msp-i2s.%04x",
714 msp->id);
715 dev_dbg(&pdev->dev, "I2S device-name: '%s'\n", i2s_cont->name);
716 msp->i2s_cont = i2s_cont;
717
718 return 0;
719
720err_i2s_cont:
721 iounmap(msp->registers);
722
723err_res:
724 devm_kfree(&pdev->dev, msp);
725
726 return ret;
727}
728
729void ux500_msp_i2s_cleanup_msp(struct platform_device *pdev,
730 struct ux500_msp *msp)
731{
732 dev_dbg(msp->dev, "%s: Enter (id = %d).\n", __func__, msp->id);
733
734 device_unregister(&msp->i2s_cont->dev);
735 devm_kfree(&pdev->dev, msp->i2s_cont);
736
737 iounmap(msp->registers);
738
739 devm_kfree(&pdev->dev, msp);
740}
741
742MODULE_LICENSE("GPLv2");
diff --git a/sound/soc/ux500/ux500_msp_i2s.h b/sound/soc/ux500/ux500_msp_i2s.h
new file mode 100644
index 000000000000..7f71b4a0d4bc
--- /dev/null
+++ b/sound/soc/ux500/ux500_msp_i2s.h
@@ -0,0 +1,553 @@
1/*
2 * Copyright (C) ST-Ericsson SA 2012
3 *
4 * Author: Ola Lilja <ola.o.lilja@stericsson.com>,
5 * for ST-Ericsson.
6 *
7 * License terms:
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as published
11 * by the Free Software Foundation.
12 */
13
14
15#ifndef UX500_MSP_I2S_H
16#define UX500_MSP_I2S_H
17
18#include <linux/platform_device.h>
19
20#include <mach/board-mop500-msp.h>
21
22#define MSP_INPUT_FREQ_APB 48000000
23
24/*** Stereo mode. Used for APB data accesses as 16 bits accesses (mono),
25 * 32 bits accesses (stereo).
26 ***/
27enum msp_stereo_mode {
28 MSP_MONO,
29 MSP_STEREO
30};
31
32/* Direction (Transmit/Receive mode) */
33enum msp_direction {
34 MSP_TX = 1,
35 MSP_RX = 2
36};
37
38/* Transmit and receive configuration register */
39#define MSP_BIG_ENDIAN 0x00000000
40#define MSP_LITTLE_ENDIAN 0x00001000
41#define MSP_UNEXPECTED_FS_ABORT 0x00000000
42#define MSP_UNEXPECTED_FS_IGNORE 0x00008000
43#define MSP_NON_MODE_BIT_MASK 0x00009000
44
45/* Global configuration register */
46#define RX_ENABLE 0x00000001
47#define RX_FIFO_ENABLE 0x00000002
48#define RX_SYNC_SRG 0x00000010
49#define RX_CLK_POL_RISING 0x00000020
50#define RX_CLK_SEL_SRG 0x00000040
51#define TX_ENABLE 0x00000100
52#define TX_FIFO_ENABLE 0x00000200
53#define TX_SYNC_SRG_PROG 0x00001800
54#define TX_SYNC_SRG_AUTO 0x00001000
55#define TX_CLK_POL_RISING 0x00002000
56#define TX_CLK_SEL_SRG 0x00004000
57#define TX_EXTRA_DELAY_ENABLE 0x00008000
58#define SRG_ENABLE 0x00010000
59#define FRAME_GEN_ENABLE 0x00100000
60#define SRG_CLK_SEL_APB 0x00000000
61#define RX_FIFO_SYNC_HI 0x00000000
62#define TX_FIFO_SYNC_HI 0x00000000
63#define SPI_CLK_MODE_NORMAL 0x00000000
64
65#define MSP_FRAME_SIZE_AUTO -1
66
67#define MSP_DR 0x00
68#define MSP_GCR 0x04
69#define MSP_TCF 0x08
70#define MSP_RCF 0x0c
71#define MSP_SRG 0x10
72#define MSP_FLR 0x14
73#define MSP_DMACR 0x18
74
75#define MSP_IMSC 0x20
76#define MSP_RIS 0x24
77#define MSP_MIS 0x28
78#define MSP_ICR 0x2c
79#define MSP_MCR 0x30
80#define MSP_RCV 0x34
81#define MSP_RCM 0x38
82
83#define MSP_TCE0 0x40
84#define MSP_TCE1 0x44
85#define MSP_TCE2 0x48
86#define MSP_TCE3 0x4c
87
88#define MSP_RCE0 0x60
89#define MSP_RCE1 0x64
90#define MSP_RCE2 0x68
91#define MSP_RCE3 0x6c
92#define MSP_IODLY 0x70
93
94#define MSP_ITCR 0x80
95#define MSP_ITIP 0x84
96#define MSP_ITOP 0x88
97#define MSP_TSTDR 0x8c
98
99#define MSP_PID0 0xfe0
100#define MSP_PID1 0xfe4
101#define MSP_PID2 0xfe8
102#define MSP_PID3 0xfec
103
104#define MSP_CID0 0xff0
105#define MSP_CID1 0xff4
106#define MSP_CID2 0xff8
107#define MSP_CID3 0xffc
108
109/* Protocol dependant parameters list */
110#define RX_ENABLE_MASK BIT(0)
111#define RX_FIFO_ENABLE_MASK BIT(1)
112#define RX_FSYNC_MASK BIT(2)
113#define DIRECT_COMPANDING_MASK BIT(3)
114#define RX_SYNC_SEL_MASK BIT(4)
115#define RX_CLK_POL_MASK BIT(5)
116#define RX_CLK_SEL_MASK BIT(6)
117#define LOOPBACK_MASK BIT(7)
118#define TX_ENABLE_MASK BIT(8)
119#define TX_FIFO_ENABLE_MASK BIT(9)
120#define TX_FSYNC_MASK BIT(10)
121#define TX_MSP_TDR_TSR BIT(11)
122#define TX_SYNC_SEL_MASK (BIT(12) | BIT(11))
123#define TX_CLK_POL_MASK BIT(13)
124#define TX_CLK_SEL_MASK BIT(14)
125#define TX_EXTRA_DELAY_MASK BIT(15)
126#define SRG_ENABLE_MASK BIT(16)
127#define SRG_CLK_POL_MASK BIT(17)
128#define SRG_CLK_SEL_MASK (BIT(19) | BIT(18))
129#define FRAME_GEN_EN_MASK BIT(20)
130#define SPI_CLK_MODE_MASK (BIT(22) | BIT(21))
131#define SPI_BURST_MODE_MASK BIT(23)
132
133#define RXEN_SHIFT 0
134#define RFFEN_SHIFT 1
135#define RFSPOL_SHIFT 2
136#define DCM_SHIFT 3
137#define RFSSEL_SHIFT 4
138#define RCKPOL_SHIFT 5
139#define RCKSEL_SHIFT 6
140#define LBM_SHIFT 7
141#define TXEN_SHIFT 8
142#define TFFEN_SHIFT 9
143#define TFSPOL_SHIFT 10
144#define TFSSEL_SHIFT 11
145#define TCKPOL_SHIFT 13
146#define TCKSEL_SHIFT 14
147#define TXDDL_SHIFT 15
148#define SGEN_SHIFT 16
149#define SCKPOL_SHIFT 17
150#define SCKSEL_SHIFT 18
151#define FGEN_SHIFT 20
152#define SPICKM_SHIFT 21
153#define TBSWAP_SHIFT 28
154
155#define RCKPOL_MASK BIT(0)
156#define TCKPOL_MASK BIT(0)
157#define SPICKM_MASK (BIT(1) | BIT(0))
158#define MSP_RX_CLKPOL_BIT(n) ((n & RCKPOL_MASK) << RCKPOL_SHIFT)
159#define MSP_TX_CLKPOL_BIT(n) ((n & TCKPOL_MASK) << TCKPOL_SHIFT)
160
161#define P1ELEN_SHIFT 0
162#define P1FLEN_SHIFT 3
163#define DTYP_SHIFT 10
164#define ENDN_SHIFT 12
165#define DDLY_SHIFT 13
166#define FSIG_SHIFT 15
167#define P2ELEN_SHIFT 16
168#define P2FLEN_SHIFT 19
169#define P2SM_SHIFT 26
170#define P2EN_SHIFT 27
171#define FSYNC_SHIFT 15
172
173#define P1ELEN_MASK 0x00000007
174#define P2ELEN_MASK 0x00070000
175#define P1FLEN_MASK 0x00000378
176#define P2FLEN_MASK 0x03780000
177#define DDLY_MASK 0x00003000
178#define DTYP_MASK 0x00000600
179#define P2SM_MASK 0x04000000
180#define P2EN_MASK 0x08000000
181#define ENDN_MASK 0x00001000
182#define TFSPOL_MASK 0x00000400
183#define TBSWAP_MASK 0x30000000
184#define COMPANDING_MODE_MASK 0x00000c00
185#define FSYNC_MASK 0x00008000
186
187#define MSP_P1_ELEM_LEN_BITS(n) (n & P1ELEN_MASK)
188#define MSP_P2_ELEM_LEN_BITS(n) (((n) << P2ELEN_SHIFT) & P2ELEN_MASK)
189#define MSP_P1_FRAME_LEN_BITS(n) (((n) << P1FLEN_SHIFT) & P1FLEN_MASK)
190#define MSP_P2_FRAME_LEN_BITS(n) (((n) << P2FLEN_SHIFT) & P2FLEN_MASK)
191#define MSP_DATA_DELAY_BITS(n) (((n) << DDLY_SHIFT) & DDLY_MASK)
192#define MSP_DATA_TYPE_BITS(n) (((n) << DTYP_SHIFT) & DTYP_MASK)
193#define MSP_P2_START_MODE_BIT(n) ((n << P2SM_SHIFT) & P2SM_MASK)
194#define MSP_P2_ENABLE_BIT(n) ((n << P2EN_SHIFT) & P2EN_MASK)
195#define MSP_SET_ENDIANNES_BIT(n) ((n << ENDN_SHIFT) & ENDN_MASK)
196#define MSP_FSYNC_POL(n) ((n << TFSPOL_SHIFT) & TFSPOL_MASK)
197#define MSP_DATA_WORD_SWAP(n) ((n << TBSWAP_SHIFT) & TBSWAP_MASK)
198#define MSP_SET_COMPANDING_MODE(n) ((n << DTYP_SHIFT) & \
199 COMPANDING_MODE_MASK)
200#define MSP_SET_FSYNC_IGNORE(n) ((n << FSYNC_SHIFT) & FSYNC_MASK)
201
202/* Flag register */
203#define RX_BUSY BIT(0)
204#define RX_FIFO_EMPTY BIT(1)
205#define RX_FIFO_FULL BIT(2)
206#define TX_BUSY BIT(3)
207#define TX_FIFO_EMPTY BIT(4)
208#define TX_FIFO_FULL BIT(5)
209
210#define RBUSY_SHIFT 0
211#define RFE_SHIFT 1
212#define RFU_SHIFT 2
213#define TBUSY_SHIFT 3
214#define TFE_SHIFT 4
215#define TFU_SHIFT 5
216
217/* Multichannel control register */
218#define RMCEN_SHIFT 0
219#define RMCSF_SHIFT 1
220#define RCMPM_SHIFT 3
221#define TMCEN_SHIFT 5
222#define TNCSF_SHIFT 6
223
224/* Sample rate generator register */
225#define SCKDIV_SHIFT 0
226#define FRWID_SHIFT 10
227#define FRPER_SHIFT 16
228
229#define SCK_DIV_MASK 0x0000003FF
230#define FRAME_WIDTH_BITS(n) (((n) << FRWID_SHIFT) & 0x0000FC00)
231#define FRAME_PERIOD_BITS(n) (((n) << FRPER_SHIFT) & 0x1FFF0000)
232
233/* DMA controller register */
234#define RX_DMA_ENABLE BIT(0)
235#define TX_DMA_ENABLE BIT(1)
236
237#define RDMAE_SHIFT 0
238#define TDMAE_SHIFT 1
239
240/* Interrupt Register */
241#define RX_SERVICE_INT BIT(0)
242#define RX_OVERRUN_ERROR_INT BIT(1)
243#define RX_FSYNC_ERR_INT BIT(2)
244#define RX_FSYNC_INT BIT(3)
245#define TX_SERVICE_INT BIT(4)
246#define TX_UNDERRUN_ERR_INT BIT(5)
247#define TX_FSYNC_ERR_INT BIT(6)
248#define TX_FSYNC_INT BIT(7)
249#define ALL_INT 0x000000ff
250
251/* MSP test control register */
252#define MSP_ITCR_ITEN BIT(0)
253#define MSP_ITCR_TESTFIFO BIT(1)
254
255#define RMCEN_BIT 0
256#define RMCSF_BIT 1
257#define RCMPM_BIT 3
258#define TMCEN_BIT 5
259#define TNCSF_BIT 6
260
261/* Single or dual phase mode */
262enum msp_phase_mode {
263 MSP_SINGLE_PHASE,
264 MSP_DUAL_PHASE
265};
266
267/* Frame length */
268enum msp_frame_length {
269 MSP_FRAME_LEN_1 = 0,
270 MSP_FRAME_LEN_2 = 1,
271 MSP_FRAME_LEN_4 = 3,
272 MSP_FRAME_LEN_8 = 7,
273 MSP_FRAME_LEN_12 = 11,
274 MSP_FRAME_LEN_16 = 15,
275 MSP_FRAME_LEN_20 = 19,
276 MSP_FRAME_LEN_32 = 31,
277 MSP_FRAME_LEN_48 = 47,
278 MSP_FRAME_LEN_64 = 63
279};
280
281/* Element length */
282enum msp_elem_length {
283 MSP_ELEM_LEN_8 = 0,
284 MSP_ELEM_LEN_10 = 1,
285 MSP_ELEM_LEN_12 = 2,
286 MSP_ELEM_LEN_14 = 3,
287 MSP_ELEM_LEN_16 = 4,
288 MSP_ELEM_LEN_20 = 5,
289 MSP_ELEM_LEN_24 = 6,
290 MSP_ELEM_LEN_32 = 7
291};
292
293enum msp_data_xfer_width {
294 MSP_DATA_TRANSFER_WIDTH_BYTE,
295 MSP_DATA_TRANSFER_WIDTH_HALFWORD,
296 MSP_DATA_TRANSFER_WIDTH_WORD
297};
298
299enum msp_frame_sync {
300 MSP_FSYNC_UNIGNORE = 0,
301 MSP_FSYNC_IGNORE = 1,
302};
303
304enum msp_phase2_start_mode {
305 MSP_PHASE2_START_MODE_IMEDIATE,
306 MSP_PHASE2_START_MODE_FSYNC
307};
308
309enum msp_btf {
310 MSP_BTF_MS_BIT_FIRST = 0,
311 MSP_BTF_LS_BIT_FIRST = 1
312};
313
314enum msp_fsync_pol {
315 MSP_FSYNC_POL_ACT_HI = 0,
316 MSP_FSYNC_POL_ACT_LO = 1
317};
318
319/* Data delay (in bit clock cycles) */
320enum msp_delay {
321 MSP_DELAY_0 = 0,
322 MSP_DELAY_1 = 1,
323 MSP_DELAY_2 = 2,
324 MSP_DELAY_3 = 3
325};
326
327/* Configurations of clocks (transmit, receive or sample rate generator) */
328enum msp_edge {
329 MSP_FALLING_EDGE = 0,
330 MSP_RISING_EDGE = 1,
331};
332
333enum msp_hws {
334 MSP_SWAP_NONE = 0,
335 MSP_SWAP_BYTE_PER_WORD = 1,
336 MSP_SWAP_BYTE_PER_HALF_WORD = 2,
337 MSP_SWAP_HALF_WORD_PER_WORD = 3
338};
339
340enum msp_compress_mode {
341 MSP_COMPRESS_MODE_LINEAR = 0,
342 MSP_COMPRESS_MODE_MU_LAW = 2,
343 MSP_COMPRESS_MODE_A_LAW = 3
344};
345
346enum msp_spi_burst_mode {
347 MSP_SPI_BURST_MODE_DISABLE = 0,
348 MSP_SPI_BURST_MODE_ENABLE = 1
349};
350
351enum msp_expand_mode {
352 MSP_EXPAND_MODE_LINEAR = 0,
353 MSP_EXPAND_MODE_LINEAR_SIGNED = 1,
354 MSP_EXPAND_MODE_MU_LAW = 2,
355 MSP_EXPAND_MODE_A_LAW = 3
356};
357
358#define MSP_FRAME_PERIOD_IN_MONO_MODE 256
359#define MSP_FRAME_PERIOD_IN_STEREO_MODE 32
360#define MSP_FRAME_WIDTH_IN_STEREO_MODE 16
361
362enum msp_protocol {
363 MSP_I2S_PROTOCOL,
364 MSP_PCM_PROTOCOL,
365 MSP_PCM_COMPAND_PROTOCOL,
366 MSP_INVALID_PROTOCOL
367};
368
369/*
370 * No of registers to backup during
371 * suspend resume
372 */
373#define MAX_MSP_BACKUP_REGS 36
374
375enum enum_i2s_controller {
376 MSP_0_I2S_CONTROLLER = 0,
377 MSP_1_I2S_CONTROLLER,
378 MSP_2_I2S_CONTROLLER,
379 MSP_3_I2S_CONTROLLER,
380};
381
382enum i2s_direction_t {
383 MSP_DIR_TX = 0x01,
384 MSP_DIR_RX = 0x02,
385};
386
387enum msp_data_size {
388 MSP_DATA_BITS_DEFAULT = -1,
389 MSP_DATA_BITS_8 = 0x00,
390 MSP_DATA_BITS_10,
391 MSP_DATA_BITS_12,
392 MSP_DATA_BITS_14,
393 MSP_DATA_BITS_16,
394 MSP_DATA_BITS_20,
395 MSP_DATA_BITS_24,
396 MSP_DATA_BITS_32,
397};
398
399enum msp_state {
400 MSP_STATE_IDLE = 0,
401 MSP_STATE_CONFIGURED = 1,
402 MSP_STATE_RUNNING = 2,
403};
404
405enum msp_rx_comparison_enable_mode {
406 MSP_COMPARISON_DISABLED = 0,
407 MSP_COMPARISON_NONEQUAL_ENABLED = 2,
408 MSP_COMPARISON_EQUAL_ENABLED = 3
409};
410
411struct msp_multichannel_config {
412 bool rx_multichannel_enable;
413 bool tx_multichannel_enable;
414 enum msp_rx_comparison_enable_mode rx_comparison_enable_mode;
415 u8 padding;
416 u32 comparison_value;
417 u32 comparison_mask;
418 u32 rx_channel_0_enable;
419 u32 rx_channel_1_enable;
420 u32 rx_channel_2_enable;
421 u32 rx_channel_3_enable;
422 u32 tx_channel_0_enable;
423 u32 tx_channel_1_enable;
424 u32 tx_channel_2_enable;
425 u32 tx_channel_3_enable;
426};
427
428struct msp_protdesc {
429 u32 rx_phase_mode;
430 u32 tx_phase_mode;
431 u32 rx_phase2_start_mode;
432 u32 tx_phase2_start_mode;
433 u32 rx_byte_order;
434 u32 tx_byte_order;
435 u32 rx_frame_len_1;
436 u32 rx_frame_len_2;
437 u32 tx_frame_len_1;
438 u32 tx_frame_len_2;
439 u32 rx_elem_len_1;
440 u32 rx_elem_len_2;
441 u32 tx_elem_len_1;
442 u32 tx_elem_len_2;
443 u32 rx_data_delay;
444 u32 tx_data_delay;
445 u32 rx_clk_pol;
446 u32 tx_clk_pol;
447 u32 rx_fsync_pol;
448 u32 tx_fsync_pol;
449 u32 rx_half_word_swap;
450 u32 tx_half_word_swap;
451 u32 compression_mode;
452 u32 expansion_mode;
453 u32 frame_sync_ignore;
454 u32 frame_period;
455 u32 frame_width;
456 u32 clocks_per_frame;
457};
458
459struct i2s_message {
460 enum i2s_direction_t i2s_direction;
461 void *txdata;
462 void *rxdata;
463 size_t txbytes;
464 size_t rxbytes;
465 int dma_flag;
466 int tx_offset;
467 int rx_offset;
468 bool cyclic_dma;
469 dma_addr_t buf_addr;
470 size_t buf_len;
471 size_t period_len;
472};
473
474struct i2s_controller {
475 struct module *owner;
476 unsigned int id;
477 unsigned int class;
478 const struct i2s_algorithm *algo; /* the algorithm to access the bus */
479 void *data;
480 struct mutex bus_lock;
481 struct device dev; /* the controller device */
482 char name[48];
483};
484
485struct ux500_msp_config {
486 unsigned int f_inputclk;
487 unsigned int rx_clk_sel;
488 unsigned int tx_clk_sel;
489 unsigned int srg_clk_sel;
490 unsigned int rx_fsync_pol;
491 unsigned int tx_fsync_pol;
492 unsigned int rx_fsync_sel;
493 unsigned int tx_fsync_sel;
494 unsigned int rx_fifo_config;
495 unsigned int tx_fifo_config;
496 unsigned int spi_clk_mode;
497 unsigned int spi_burst_mode;
498 unsigned int loopback_enable;
499 unsigned int tx_data_enable;
500 unsigned int default_protdesc;
501 struct msp_protdesc protdesc;
502 int multichannel_configured;
503 struct msp_multichannel_config multichannel_config;
504 unsigned int direction;
505 unsigned int protocol;
506 unsigned int frame_freq;
507 unsigned int frame_size;
508 enum msp_data_size data_size;
509 unsigned int def_elem_len;
510 unsigned int iodelay;
511 void (*handler) (void *data);
512 void *tx_callback_data;
513 void *rx_callback_data;
514};
515
516struct ux500_msp {
517 enum enum_i2s_controller id;
518 void __iomem *registers;
519 struct device *dev;
520 struct i2s_controller *i2s_cont;
521 struct stedma40_chan_cfg *dma_cfg_rx;
522 struct stedma40_chan_cfg *dma_cfg_tx;
523 struct dma_chan *tx_pipeid;
524 struct dma_chan *rx_pipeid;
525 enum msp_state msp_state;
526 int (*transfer) (struct ux500_msp *msp, struct i2s_message *message);
527 int (*plat_init) (void);
528 int (*plat_exit) (void);
529 struct timer_list notify_timer;
530 int def_elem_len;
531 unsigned int dir_busy;
532 int loopback_enable;
533 u32 backup_regs[MAX_MSP_BACKUP_REGS];
534 unsigned int f_bitclk;
535};
536
537struct ux500_msp_dma_params {
538 unsigned int data_size;
539 struct stedma40_chan_cfg *dma_cfg;
540};
541
542int ux500_msp_i2s_init_msp(struct platform_device *pdev,
543 struct ux500_msp **msp_p,
544 struct msp_i2s_platform_data *platform_data);
545void ux500_msp_i2s_cleanup_msp(struct platform_device *pdev,
546 struct ux500_msp *msp);
547int ux500_msp_i2s_open(struct ux500_msp *msp, struct ux500_msp_config *config);
548int ux500_msp_i2s_close(struct ux500_msp *msp,
549 unsigned int dir);
550int ux500_msp_i2s_trigger(struct ux500_msp *msp, int cmd,
551 int direction);
552
553#endif
diff --git a/tools/perf/.gitignore b/tools/perf/.gitignore
index 416684be0ad3..26b823b61aa1 100644
--- a/tools/perf/.gitignore
+++ b/tools/perf/.gitignore
@@ -19,3 +19,5 @@ TAGS
19cscope* 19cscope*
20config.mak 20config.mak
21config.mak.autogen 21config.mak.autogen
22*-bison.*
23*-flex.*
diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 820371f10d1b..9bf3fc759344 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -234,24 +234,23 @@ endif
234 234
235export PERL_PATH 235export PERL_PATH
236 236
237FLEX = $(CROSS_COMPILE)flex 237FLEX = flex
238BISON= $(CROSS_COMPILE)bison 238BISON= bison
239 239
240event-parser: 240$(OUTPUT)util/parse-events-flex.c: util/parse-events.l
241 $(QUIET_BISON)$(BISON) -v util/parse-events.y -d -o $(OUTPUT)util/parse-events-bison.c
242 $(QUIET_FLEX)$(FLEX) --header-file=$(OUTPUT)util/parse-events-flex.h -t util/parse-events.l > $(OUTPUT)util/parse-events-flex.c 241 $(QUIET_FLEX)$(FLEX) --header-file=$(OUTPUT)util/parse-events-flex.h -t util/parse-events.l > $(OUTPUT)util/parse-events-flex.c
243 242
244$(OUTPUT)util/parse-events-flex.c: event-parser 243$(OUTPUT)util/parse-events-bison.c: util/parse-events.y
245$(OUTPUT)util/parse-events-bison.c: event-parser 244 $(QUIET_BISON)$(BISON) -v util/parse-events.y -d -o $(OUTPUT)util/parse-events-bison.c
246 245
247pmu-parser: 246$(OUTPUT)util/pmu-flex.c: util/pmu.l
248 $(QUIET_BISON)$(BISON) -v util/pmu.y -d -o $(OUTPUT)util/pmu-bison.c
249 $(QUIET_FLEX)$(FLEX) --header-file=$(OUTPUT)util/pmu-flex.h -t util/pmu.l > $(OUTPUT)util/pmu-flex.c 247 $(QUIET_FLEX)$(FLEX) --header-file=$(OUTPUT)util/pmu-flex.h -t util/pmu.l > $(OUTPUT)util/pmu-flex.c
250 248
251$(OUTPUT)util/pmu-flex.c: pmu-parser 249$(OUTPUT)util/pmu-bison.c: util/pmu.y
252$(OUTPUT)util/pmu-bison.c: pmu-parser 250 $(QUIET_BISON)$(BISON) -v util/pmu.y -d -o $(OUTPUT)util/pmu-bison.c
253 251
254$(OUTPUT)util/parse-events.o: event-parser pmu-parser 252$(OUTPUT)util/parse-events.o: $(OUTPUT)util/parse-events-flex.c $(OUTPUT)util/parse-events-bison.c
253$(OUTPUT)util/pmu.o: $(OUTPUT)util/pmu-flex.c $(OUTPUT)util/pmu-bison.c
255 254
256LIB_FILE=$(OUTPUT)libperf.a 255LIB_FILE=$(OUTPUT)libperf.a
257 256
@@ -527,7 +526,7 @@ else
527endif 526endif
528 527
529ifdef NO_GTK2 528ifdef NO_GTK2
530 BASIC_CFLAGS += -DNO_GTK2 529 BASIC_CFLAGS += -DNO_GTK2_SUPPORT
531else 530else
532 FLAGS_GTK2=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS) $(shell pkg-config --libs --cflags gtk+-2.0) 531 FLAGS_GTK2=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS) $(shell pkg-config --libs --cflags gtk+-2.0)
533 ifneq ($(call try-cc,$(SOURCE_GTK2),$(FLAGS_GTK2)),y) 532 ifneq ($(call try-cc,$(SOURCE_GTK2),$(FLAGS_GTK2)),y)
@@ -852,8 +851,6 @@ help:
852 @echo ' html - make html documentation' 851 @echo ' html - make html documentation'
853 @echo ' info - make GNU info documentation (access with info <foo>)' 852 @echo ' info - make GNU info documentation (access with info <foo>)'
854 @echo ' pdf - make pdf documentation' 853 @echo ' pdf - make pdf documentation'
855 @echo ' event-parser - make event parser code'
856 @echo ' pmu-parser - make pmu format parser code'
857 @echo ' TAGS - use etags to make tag information for source browsing' 854 @echo ' TAGS - use etags to make tag information for source browsing'
858 @echo ' tags - use ctags to make tag information for source browsing' 855 @echo ' tags - use ctags to make tag information for source browsing'
859 @echo ' cscope - use cscope to make interactive browsing database' 856 @echo ' cscope - use cscope to make interactive browsing database'
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 2e317438980b..cdae9b2db1cc 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -374,16 +374,23 @@ static int __cmd_report(struct perf_report *rep)
374 (kernel_map->dso->hit && 374 (kernel_map->dso->hit &&
375 (kernel_kmap->ref_reloc_sym == NULL || 375 (kernel_kmap->ref_reloc_sym == NULL ||
376 kernel_kmap->ref_reloc_sym->addr == 0))) { 376 kernel_kmap->ref_reloc_sym->addr == 0))) {
377 const struct dso *kdso = kernel_map->dso; 377 const char *desc =
378 "As no suitable kallsyms nor vmlinux was found, kernel samples\n"
379 "can't be resolved.";
380
381 if (kernel_map) {
382 const struct dso *kdso = kernel_map->dso;
383 if (!RB_EMPTY_ROOT(&kdso->symbols[MAP__FUNCTION])) {
384 desc = "If some relocation was applied (e.g. "
385 "kexec) symbols may be misresolved.";
386 }
387 }
378 388
379 ui__warning( 389 ui__warning(
380"Kernel address maps (/proc/{kallsyms,modules}) were restricted.\n\n" 390"Kernel address maps (/proc/{kallsyms,modules}) were restricted.\n\n"
381"Check /proc/sys/kernel/kptr_restrict before running 'perf record'.\n\n%s\n\n" 391"Check /proc/sys/kernel/kptr_restrict before running 'perf record'.\n\n%s\n\n"
382"Samples in kernel modules can't be resolved as well.\n\n", 392"Samples in kernel modules can't be resolved as well.\n\n",
383 RB_EMPTY_ROOT(&kdso->symbols[MAP__FUNCTION]) ? 393 desc);
384"As no suitable kallsyms nor vmlinux was found, kernel samples\n"
385"can't be resolved." :
386"If some relocation was applied (e.g. kexec) symbols may be misresolved.");
387 } 394 }
388 395
389 if (dump_trace) { 396 if (dump_trace) {
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index fb8b5f83b4a0..1cad3af4bf4c 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -17,6 +17,7 @@
17#include "util/debug.h" 17#include "util/debug.h"
18 18
19#include <sys/prctl.h> 19#include <sys/prctl.h>
20#include <sys/resource.h>
20 21
21#include <semaphore.h> 22#include <semaphore.h>
22#include <pthread.h> 23#include <pthread.h>
diff --git a/tools/perf/builtin-test.c b/tools/perf/builtin-test.c
index 1c5b9801ac61..223ffdcc0fd8 100644
--- a/tools/perf/builtin-test.c
+++ b/tools/perf/builtin-test.c
@@ -851,6 +851,28 @@ static int test__checkevent_symbolic_name_modifier(struct perf_evlist *evlist)
851 return test__checkevent_symbolic_name(evlist); 851 return test__checkevent_symbolic_name(evlist);
852} 852}
853 853
854static int test__checkevent_exclude_host_modifier(struct perf_evlist *evlist)
855{
856 struct perf_evsel *evsel = list_entry(evlist->entries.next,
857 struct perf_evsel, node);
858
859 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
860 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
861
862 return test__checkevent_symbolic_name(evlist);
863}
864
865static int test__checkevent_exclude_guest_modifier(struct perf_evlist *evlist)
866{
867 struct perf_evsel *evsel = list_entry(evlist->entries.next,
868 struct perf_evsel, node);
869
870 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
871 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
872
873 return test__checkevent_symbolic_name(evlist);
874}
875
854static int test__checkevent_symbolic_alias_modifier(struct perf_evlist *evlist) 876static int test__checkevent_symbolic_alias_modifier(struct perf_evlist *evlist)
855{ 877{
856 struct perf_evsel *evsel = list_entry(evlist->entries.next, 878 struct perf_evsel *evsel = list_entry(evlist->entries.next,
@@ -1091,6 +1113,14 @@ static struct test__event_st {
1091 .name = "r1,syscalls:sys_enter_open:k,1:1:hp", 1113 .name = "r1,syscalls:sys_enter_open:k,1:1:hp",
1092 .check = test__checkevent_list, 1114 .check = test__checkevent_list,
1093 }, 1115 },
1116 {
1117 .name = "instructions:G",
1118 .check = test__checkevent_exclude_host_modifier,
1119 },
1120 {
1121 .name = "instructions:H",
1122 .check = test__checkevent_exclude_guest_modifier,
1123 },
1094}; 1124};
1095 1125
1096#define TEST__EVENTS_CNT (sizeof(test__events) / sizeof(struct test__event_st)) 1126#define TEST__EVENTS_CNT (sizeof(test__events) / sizeof(struct test__event_st))
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index e3c63aef8efc..8ef59f8262bb 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -42,6 +42,7 @@
42#include "util/debug.h" 42#include "util/debug.h"
43 43
44#include <assert.h> 44#include <assert.h>
45#include <elf.h>
45#include <fcntl.h> 46#include <fcntl.h>
46 47
47#include <stdio.h> 48#include <stdio.h>
@@ -59,6 +60,7 @@
59#include <sys/prctl.h> 60#include <sys/prctl.h>
60#include <sys/wait.h> 61#include <sys/wait.h>
61#include <sys/uio.h> 62#include <sys/uio.h>
63#include <sys/utsname.h>
62#include <sys/mman.h> 64#include <sys/mman.h>
63 65
64#include <linux/unistd.h> 66#include <linux/unistd.h>
@@ -162,12 +164,40 @@ static void __zero_source_counters(struct hist_entry *he)
162 symbol__annotate_zero_histograms(sym); 164 symbol__annotate_zero_histograms(sym);
163} 165}
164 166
167static void ui__warn_map_erange(struct map *map, struct symbol *sym, u64 ip)
168{
169 struct utsname uts;
170 int err = uname(&uts);
171
172 ui__warning("Out of bounds address found:\n\n"
173 "Addr: %" PRIx64 "\n"
174 "DSO: %s %c\n"
175 "Map: %" PRIx64 "-%" PRIx64 "\n"
176 "Symbol: %" PRIx64 "-%" PRIx64 " %c %s\n"
177 "Arch: %s\n"
178 "Kernel: %s\n"
179 "Tools: %s\n\n"
180 "Not all samples will be on the annotation output.\n\n"
181 "Please report to linux-kernel@vger.kernel.org\n",
182 ip, map->dso->long_name, dso__symtab_origin(map->dso),
183 map->start, map->end, sym->start, sym->end,
184 sym->binding == STB_GLOBAL ? 'g' :
185 sym->binding == STB_LOCAL ? 'l' : 'w', sym->name,
186 err ? "[unknown]" : uts.machine,
187 err ? "[unknown]" : uts.release, perf_version_string);
188 if (use_browser <= 0)
189 sleep(5);
190
191 map->erange_warned = true;
192}
193
165static void perf_top__record_precise_ip(struct perf_top *top, 194static void perf_top__record_precise_ip(struct perf_top *top,
166 struct hist_entry *he, 195 struct hist_entry *he,
167 int counter, u64 ip) 196 int counter, u64 ip)
168{ 197{
169 struct annotation *notes; 198 struct annotation *notes;
170 struct symbol *sym; 199 struct symbol *sym;
200 int err;
171 201
172 if (he == NULL || he->ms.sym == NULL || 202 if (he == NULL || he->ms.sym == NULL ||
173 ((top->sym_filter_entry == NULL || 203 ((top->sym_filter_entry == NULL ||
@@ -189,9 +219,12 @@ static void perf_top__record_precise_ip(struct perf_top *top,
189 } 219 }
190 220
191 ip = he->ms.map->map_ip(he->ms.map, ip); 221 ip = he->ms.map->map_ip(he->ms.map, ip);
192 symbol__inc_addr_samples(sym, he->ms.map, counter, ip); 222 err = symbol__inc_addr_samples(sym, he->ms.map, counter, ip);
193 223
194 pthread_mutex_unlock(&notes->lock); 224 pthread_mutex_unlock(&notes->lock);
225
226 if (err == -ERANGE && !he->ms.map->erange_warned)
227 ui__warn_map_erange(he->ms.map, sym, ip);
195} 228}
196 229
197static void perf_top__show_details(struct perf_top *top) 230static void perf_top__show_details(struct perf_top *top)
@@ -615,6 +648,7 @@ process_hotkey:
615 648
616/* Tag samples to be skipped. */ 649/* Tag samples to be skipped. */
617static const char *skip_symbols[] = { 650static const char *skip_symbols[] = {
651 "intel_idle",
618 "default_idle", 652 "default_idle",
619 "native_safe_halt", 653 "native_safe_halt",
620 "cpu_idle", 654 "cpu_idle",
diff --git a/tools/perf/perf-archive.sh b/tools/perf/perf-archive.sh
index 677e59d62a8d..95b6f8b6177a 100644
--- a/tools/perf/perf-archive.sh
+++ b/tools/perf/perf-archive.sh
@@ -29,13 +29,14 @@ if [ ! -s $BUILDIDS ] ; then
29fi 29fi
30 30
31MANIFEST=$(mktemp /tmp/perf-archive-manifest.XXXXXX) 31MANIFEST=$(mktemp /tmp/perf-archive-manifest.XXXXXX)
32PERF_BUILDID_LINKDIR=$(readlink -f $PERF_BUILDID_DIR)/
32 33
33cut -d ' ' -f 1 $BUILDIDS | \ 34cut -d ' ' -f 1 $BUILDIDS | \
34while read build_id ; do 35while read build_id ; do
35 linkname=$PERF_BUILDID_DIR.build-id/${build_id:0:2}/${build_id:2} 36 linkname=$PERF_BUILDID_DIR.build-id/${build_id:0:2}/${build_id:2}
36 filename=$(readlink -f $linkname) 37 filename=$(readlink -f $linkname)
37 echo ${linkname#$PERF_BUILDID_DIR} >> $MANIFEST 38 echo ${linkname#$PERF_BUILDID_DIR} >> $MANIFEST
38 echo ${filename#$PERF_BUILDID_DIR} >> $MANIFEST 39 echo ${filename#$PERF_BUILDID_LINKDIR} >> $MANIFEST
39done 40done
40 41
41tar cfj $PERF_DATA.tar.bz2 -C $PERF_BUILDID_DIR -T $MANIFEST 42tar cfj $PERF_DATA.tar.bz2 -C $PERF_BUILDID_DIR -T $MANIFEST
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 199f69ec656f..08c6d138a655 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -64,8 +64,8 @@ int symbol__inc_addr_samples(struct symbol *sym, struct map *map,
64 64
65 pr_debug3("%s: addr=%#" PRIx64 "\n", __func__, map->unmap_ip(map, addr)); 65 pr_debug3("%s: addr=%#" PRIx64 "\n", __func__, map->unmap_ip(map, addr));
66 66
67 if (addr > sym->end) 67 if (addr < sym->start || addr > sym->end)
68 return 0; 68 return -ERANGE;
69 69
70 offset = addr - sym->start; 70 offset = addr - sym->start;
71 h = annotation__histogram(notes, evidx); 71 h = annotation__histogram(notes, evidx);
@@ -561,16 +561,12 @@ void symbol__annotate_decay_histogram(struct symbol *sym, int evidx)
561{ 561{
562 struct annotation *notes = symbol__annotation(sym); 562 struct annotation *notes = symbol__annotation(sym);
563 struct sym_hist *h = annotation__histogram(notes, evidx); 563 struct sym_hist *h = annotation__histogram(notes, evidx);
564 struct objdump_line *pos; 564 int len = sym->end - sym->start, offset;
565 int len = sym->end - sym->start;
566 565
567 h->sum = 0; 566 h->sum = 0;
568 567 for (offset = 0; offset < len; ++offset) {
569 list_for_each_entry(pos, &notes->src->source, node) { 568 h->addr[offset] = h->addr[offset] * 7 / 8;
570 if (pos->offset != -1 && pos->offset < len) { 569 h->sum += h->addr[offset];
571 h->addr[pos->offset] = h->addr[pos->offset] * 7 / 8;
572 h->sum += h->addr[pos->offset];
573 }
574 } 570 }
575} 571}
576 572
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index 2ec4b60aff6c..9f6d630d5316 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -256,6 +256,18 @@ static struct hist_entry *add_hist_entry(struct hists *hists,
256 if (!cmp) { 256 if (!cmp) {
257 he->period += period; 257 he->period += period;
258 ++he->nr_events; 258 ++he->nr_events;
259
260 /* If the map of an existing hist_entry has
261 * become out-of-date due to an exec() or
262 * similar, update it. Otherwise we will
263 * mis-adjust symbol addresses when computing
264 * the history counter to increment.
265 */
266 if (he->ms.map != entry->ms.map) {
267 he->ms.map = entry->ms.map;
268 if (he->ms.map)
269 he->ms.map->referenced = true;
270 }
259 goto out; 271 goto out;
260 } 272 }
261 273
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index dea6d1c1a954..35ae56864e4f 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -38,6 +38,7 @@ void map__init(struct map *self, enum map_type type,
38 RB_CLEAR_NODE(&self->rb_node); 38 RB_CLEAR_NODE(&self->rb_node);
39 self->groups = NULL; 39 self->groups = NULL;
40 self->referenced = false; 40 self->referenced = false;
41 self->erange_warned = false;
41} 42}
42 43
43struct map *map__new(struct list_head *dsos__list, u64 start, u64 len, 44struct map *map__new(struct list_head *dsos__list, u64 start, u64 len,
diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h
index b100c20b7f94..81371bad4ef0 100644
--- a/tools/perf/util/map.h
+++ b/tools/perf/util/map.h
@@ -33,6 +33,7 @@ struct map {
33 u64 end; 33 u64 end;
34 u8 /* enum map_type */ type; 34 u8 /* enum map_type */ type;
35 bool referenced; 35 bool referenced;
36 bool erange_warned;
36 u32 priv; 37 u32 priv;
37 u64 pgoff; 38 u64 pgoff;
38 39
diff --git a/tools/perf/util/parse-events.l b/tools/perf/util/parse-events.l
index 05d766e3ecb5..1fcf1bbc5458 100644
--- a/tools/perf/util/parse-events.l
+++ b/tools/perf/util/parse-events.l
@@ -54,7 +54,7 @@ num_dec [0-9]+
54num_hex 0x[a-fA-F0-9]+ 54num_hex 0x[a-fA-F0-9]+
55num_raw_hex [a-fA-F0-9]+ 55num_raw_hex [a-fA-F0-9]+
56name [a-zA-Z_*?][a-zA-Z0-9_*?]* 56name [a-zA-Z_*?][a-zA-Z0-9_*?]*
57modifier_event [ukhp]{1,5} 57modifier_event [ukhpGH]{1,8}
58modifier_bp [rwx] 58modifier_bp [rwx]
59 59
60%% 60%%
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 9412e3b05f68..1efd3bee6336 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -826,8 +826,16 @@ static struct machine *
826{ 826{
827 const u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; 827 const u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
828 828
829 if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL && perf_guest) 829 if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL && perf_guest) {
830 return perf_session__find_machine(session, event->ip.pid); 830 u32 pid;
831
832 if (event->header.type == PERF_RECORD_MMAP)
833 pid = event->mmap.pid;
834 else
835 pid = event->ip.pid;
836
837 return perf_session__find_machine(session, pid);
838 }
831 839
832 return perf_session__find_host_machine(session); 840 return perf_session__find_host_machine(session);
833} 841}
@@ -868,11 +876,11 @@ static int perf_session_deliver_event(struct perf_session *session,
868 dump_sample(session, event, sample); 876 dump_sample(session, event, sample);
869 if (evsel == NULL) { 877 if (evsel == NULL) {
870 ++session->hists.stats.nr_unknown_id; 878 ++session->hists.stats.nr_unknown_id;
871 return -1; 879 return 0;
872 } 880 }
873 if (machine == NULL) { 881 if (machine == NULL) {
874 ++session->hists.stats.nr_unprocessable_samples; 882 ++session->hists.stats.nr_unprocessable_samples;
875 return -1; 883 return 0;
876 } 884 }
877 return tool->sample(tool, event, sample, evsel, machine); 885 return tool->sample(tool, event, sample, evsel, machine);
878 case PERF_RECORD_MMAP: 886 case PERF_RECORD_MMAP:
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index c0a028c3ebaf..ab9867b2b433 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -977,8 +977,9 @@ static Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep,
977 * And always look at the original dso, not at debuginfo packages, that 977 * And always look at the original dso, not at debuginfo packages, that
978 * have the PLT data stripped out (shdr_rel_plt.sh_type == SHT_NOBITS). 978 * have the PLT data stripped out (shdr_rel_plt.sh_type == SHT_NOBITS).
979 */ 979 */
980static int dso__synthesize_plt_symbols(struct dso *dso, struct map *map, 980static int
981 symbol_filter_t filter) 981dso__synthesize_plt_symbols(struct dso *dso, char *name, struct map *map,
982 symbol_filter_t filter)
982{ 983{
983 uint32_t nr_rel_entries, idx; 984 uint32_t nr_rel_entries, idx;
984 GElf_Sym sym; 985 GElf_Sym sym;
@@ -993,10 +994,7 @@ static int dso__synthesize_plt_symbols(struct dso *dso, struct map *map,
993 char sympltname[1024]; 994 char sympltname[1024];
994 Elf *elf; 995 Elf *elf;
995 int nr = 0, symidx, fd, err = 0; 996 int nr = 0, symidx, fd, err = 0;
996 char name[PATH_MAX];
997 997
998 snprintf(name, sizeof(name), "%s%s",
999 symbol_conf.symfs, dso->long_name);
1000 fd = open(name, O_RDONLY); 998 fd = open(name, O_RDONLY);
1001 if (fd < 0) 999 if (fd < 0)
1002 goto out; 1000 goto out;
@@ -1703,8 +1701,9 @@ restart:
1703 continue; 1701 continue;
1704 1702
1705 if (ret > 0) { 1703 if (ret > 0) {
1706 int nr_plt = dso__synthesize_plt_symbols(dso, map, 1704 int nr_plt;
1707 filter); 1705
1706 nr_plt = dso__synthesize_plt_symbols(dso, name, map, filter);
1708 if (nr_plt > 0) 1707 if (nr_plt > 0)
1709 ret += nr_plt; 1708 ret += nr_plt;
1710 break; 1709 break;
diff --git a/tools/perf/util/ui/browsers/hists.c b/tools/perf/util/ui/browsers/hists.c
index d7a1c4afe28b..2f83e5dc9967 100644
--- a/tools/perf/util/ui/browsers/hists.c
+++ b/tools/perf/util/ui/browsers/hists.c
@@ -125,6 +125,9 @@ static int callchain__count_rows(struct rb_root *chain)
125 125
126static bool map_symbol__toggle_fold(struct map_symbol *self) 126static bool map_symbol__toggle_fold(struct map_symbol *self)
127{ 127{
128 if (!self)
129 return false;
130
128 if (!self->has_children) 131 if (!self->has_children)
129 return false; 132 return false;
130 133
diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl
index 95d6a6f7c33a..4915408f6a98 100755
--- a/tools/testing/ktest/ktest.pl
+++ b/tools/testing/ktest/ktest.pl
@@ -183,6 +183,9 @@ my %force_config;
183# do not force reboots on config problems 183# do not force reboots on config problems
184my $no_reboot = 1; 184my $no_reboot = 1;
185 185
186# reboot on success
187my $reboot_success = 0;
188
186my %option_map = ( 189my %option_map = (
187 "MACHINE" => \$machine, 190 "MACHINE" => \$machine,
188 "SSH_USER" => \$ssh_user, 191 "SSH_USER" => \$ssh_user,
@@ -2192,7 +2195,7 @@ sub run_bisect {
2192 } 2195 }
2193 2196
2194 # Are we looking for where it worked, not failed? 2197 # Are we looking for where it worked, not failed?
2195 if ($reverse_bisect) { 2198 if ($reverse_bisect && $ret >= 0) {
2196 $ret = !$ret; 2199 $ret = !$ret;
2197 } 2200 }
2198 2201
@@ -3469,6 +3472,7 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
3469 3472
3470 # Do not reboot on failing test options 3473 # Do not reboot on failing test options
3471 $no_reboot = 1; 3474 $no_reboot = 1;
3475 $reboot_success = 0;
3472 3476
3473 $iteration = $i; 3477 $iteration = $i;
3474 3478
@@ -3554,9 +3558,11 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
3554 die "failed to checkout $checkout"; 3558 die "failed to checkout $checkout";
3555 } 3559 }
3556 3560
3561 $no_reboot = 0;
3562
3557 # A test may opt to not reboot the box 3563 # A test may opt to not reboot the box
3558 if ($reboot_on_success) { 3564 if ($reboot_on_success) {
3559 $no_reboot = 0; 3565 $reboot_success = 1;
3560 } 3566 }
3561 3567
3562 if ($test_type eq "bisect") { 3568 if ($test_type eq "bisect") {
@@ -3600,7 +3606,7 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
3600 3606
3601if ($opt{"POWEROFF_ON_SUCCESS"}) { 3607if ($opt{"POWEROFF_ON_SUCCESS"}) {
3602 halt; 3608 halt;
3603} elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot) { 3609} elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot && $reboot_success) {
3604 reboot_to_good; 3610 reboot_to_good;
3605} elsif (defined($switch_to_good)) { 3611} elsif (defined($switch_to_good)) {
3606 # still need to get to the good kernel 3612 # still need to get to the good kernel
diff --git a/virt/kvm/iommu.c b/virt/kvm/iommu.c
index a457d2138f49..e9fff9830bf0 100644
--- a/virt/kvm/iommu.c
+++ b/virt/kvm/iommu.c
@@ -240,9 +240,13 @@ int kvm_iommu_map_guest(struct kvm *kvm)
240 return -ENODEV; 240 return -ENODEV;
241 } 241 }
242 242
243 mutex_lock(&kvm->slots_lock);
244
243 kvm->arch.iommu_domain = iommu_domain_alloc(&pci_bus_type); 245 kvm->arch.iommu_domain = iommu_domain_alloc(&pci_bus_type);
244 if (!kvm->arch.iommu_domain) 246 if (!kvm->arch.iommu_domain) {
245 return -ENOMEM; 247 r = -ENOMEM;
248 goto out_unlock;
249 }
246 250
247 if (!allow_unsafe_assigned_interrupts && 251 if (!allow_unsafe_assigned_interrupts &&
248 !iommu_domain_has_cap(kvm->arch.iommu_domain, 252 !iommu_domain_has_cap(kvm->arch.iommu_domain,
@@ -253,17 +257,16 @@ int kvm_iommu_map_guest(struct kvm *kvm)
253 " module option.\n", __func__); 257 " module option.\n", __func__);
254 iommu_domain_free(kvm->arch.iommu_domain); 258 iommu_domain_free(kvm->arch.iommu_domain);
255 kvm->arch.iommu_domain = NULL; 259 kvm->arch.iommu_domain = NULL;
256 return -EPERM; 260 r = -EPERM;
261 goto out_unlock;
257 } 262 }
258 263
259 r = kvm_iommu_map_memslots(kvm); 264 r = kvm_iommu_map_memslots(kvm);
260 if (r) 265 if (r)
261 goto out_unmap; 266 kvm_iommu_unmap_memslots(kvm);
262
263 return 0;
264 267
265out_unmap: 268out_unlock:
266 kvm_iommu_unmap_memslots(kvm); 269 mutex_unlock(&kvm->slots_lock);
267 return r; 270 return r;
268} 271}
269 272
@@ -310,6 +313,11 @@ static void kvm_iommu_put_pages(struct kvm *kvm,
310 } 313 }
311} 314}
312 315
316void kvm_iommu_unmap_pages(struct kvm *kvm, struct kvm_memory_slot *slot)
317{
318 kvm_iommu_put_pages(kvm, slot->base_gfn, slot->npages);
319}
320
313static int kvm_iommu_unmap_memslots(struct kvm *kvm) 321static int kvm_iommu_unmap_memslots(struct kvm *kvm)
314{ 322{
315 int idx; 323 int idx;
@@ -320,7 +328,7 @@ static int kvm_iommu_unmap_memslots(struct kvm *kvm)
320 slots = kvm_memslots(kvm); 328 slots = kvm_memslots(kvm);
321 329
322 kvm_for_each_memslot(memslot, slots) 330 kvm_for_each_memslot(memslot, slots)
323 kvm_iommu_put_pages(kvm, memslot->base_gfn, memslot->npages); 331 kvm_iommu_unmap_pages(kvm, memslot);
324 332
325 srcu_read_unlock(&kvm->srcu, idx); 333 srcu_read_unlock(&kvm->srcu, idx);
326 334
@@ -335,7 +343,11 @@ int kvm_iommu_unmap_guest(struct kvm *kvm)
335 if (!domain) 343 if (!domain)
336 return 0; 344 return 0;
337 345
346 mutex_lock(&kvm->slots_lock);
338 kvm_iommu_unmap_memslots(kvm); 347 kvm_iommu_unmap_memslots(kvm);
348 kvm->arch.iommu_domain = NULL;
349 mutex_unlock(&kvm->slots_lock);
350
339 iommu_domain_free(domain); 351 iommu_domain_free(domain);
340 return 0; 352 return 0;
341} 353}
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 42b73930a6de..9739b533ca2e 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -808,12 +808,13 @@ int __kvm_set_memory_region(struct kvm *kvm,
808 if (r) 808 if (r)
809 goto out_free; 809 goto out_free;
810 810
811 /* map the pages in iommu page table */ 811 /* map/unmap the pages in iommu page table */
812 if (npages) { 812 if (npages) {
813 r = kvm_iommu_map_pages(kvm, &new); 813 r = kvm_iommu_map_pages(kvm, &new);
814 if (r) 814 if (r)
815 goto out_free; 815 goto out_free;
816 } 816 } else
817 kvm_iommu_unmap_pages(kvm, &old);
817 818
818 r = -ENOMEM; 819 r = -ENOMEM;
819 slots = kmemdup(kvm->memslots, sizeof(struct kvm_memslots), 820 slots = kmemdup(kvm->memslots, sizeof(struct kvm_memslots),