aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Brown <broonie@opensource.wolfsonmicro.com>2012-07-22 14:32:00 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2012-07-22 14:32:00 -0400
commit3384fb98845dc014770caa224d61a2effd258ca5 (patch)
tree8189134a4938632e2d06e93af04c9fc1f3c2d4c9
parent8cfc545e0e3e6cc82acfdc79321b41eeeab0ca45 (diff)
parentade7515fefad9af13f6dd469f35bb413b6a5b473 (diff)
Merge branch 'regulator-drivers' into regulator-next
-rw-r--r--Documentation/ABI/testing/sysfs-block-rssd21
-rw-r--r--Documentation/ABI/testing/sysfs-class-mtd17
-rw-r--r--Documentation/DocBook/media/v4l/controls.xml2
-rw-r--r--Documentation/DocBook/media/v4l/vidioc-g-ext-ctrls.xml7
-rw-r--r--Documentation/device-mapper/verity.txt131
-rw-r--r--Documentation/devicetree/bindings/input/fsl-mma8450.txt1
-rw-r--r--Documentation/devicetree/bindings/mfd/mc13xxx.txt4
-rw-r--r--Documentation/devicetree/bindings/mfd/tps65910.txt90
-rw-r--r--Documentation/devicetree/bindings/mmc/fsl-imx-esdhc.txt4
-rw-r--r--Documentation/devicetree/bindings/net/fsl-fec.txt2
-rw-r--r--Documentation/devicetree/bindings/regulator/fixed-regulator.txt2
-rw-r--r--Documentation/devicetree/bindings/regulator/regulator.txt5
-rw-r--r--Documentation/devicetree/bindings/regulator/tps65217.txt91
-rw-r--r--Documentation/devicetree/bindings/regulator/tps6586x.txt77
-rw-r--r--Documentation/devicetree/bindings/regulator/twl-regulator.txt1
-rw-r--r--Documentation/devicetree/bindings/spi/fsl-imx-cspi.txt4
-rw-r--r--Documentation/devicetree/bindings/vendor-prefixes.txt1
-rw-r--r--Documentation/prctl/no_new_privs.txt57
-rw-r--r--Documentation/virtual/kvm/api.txt17
-rw-r--r--MAINTAINERS7
-rw-r--r--Makefile2
-rw-r--r--arch/arm/boot/dts/db8500.dtsi30
-rw-r--r--arch/arm/configs/omap2plus_defconfig1
-rw-r--r--arch/arm/include/asm/atomic.h2
-rw-r--r--arch/arm/include/asm/domain.h18
-rw-r--r--arch/arm/include/asm/thread_info.h5
-rw-r--r--arch/arm/kernel/kprobes-test-arm.c4
-rw-r--r--arch/arm/kernel/perf_event.c2
-rw-r--r--arch/arm/kernel/ptrace.c3
-rw-r--r--arch/arm/kernel/signal.c46
-rw-r--r--arch/arm/kernel/signal.h2
-rw-r--r--arch/arm/kernel/traps.c2
-rw-r--r--arch/arm/kernel/vmlinux.lds.S2
-rw-r--r--arch/arm/mach-dove/include/mach/bridge-regs.h1
-rw-r--r--arch/arm/mach-dove/include/mach/dove.h1
-rw-r--r--arch/arm/mach-exynos/pm_domains.c13
-rw-r--r--arch/arm/mach-imx/clk-imx35.c9
-rw-r--r--arch/arm/mach-imx/mach-imx27_visstrim_m10.c2
-rw-r--r--arch/arm/mach-mmp/include/mach/gpio-pxa.h29
-rw-r--r--arch/arm/mach-mv78xx0/include/mach/bridge-regs.h1
-rw-r--r--arch/arm/mach-mv78xx0/include/mach/mv78xx0.h2
-rw-r--r--arch/arm/mach-mxs/mach-apx4devkit.c11
-rw-r--r--arch/arm/mach-omap2/board-overo.c2
-rw-r--r--arch/arm/mach-omap2/clockdomain.h4
-rw-r--r--arch/arm/mach-omap2/clockdomains2xxx_3xxx_data.c1
-rw-r--r--arch/arm/mach-omap2/clockdomains44xx_data.c2
-rw-r--r--arch/arm/mach-omap2/omap_hwmod.c32
-rw-r--r--arch/arm/mach-omap2/omap_hwmod_44xx_data.c28
-rw-r--r--arch/arm/mach-omap2/twl-common.c2
-rw-r--r--arch/arm/mach-pxa/hx4700.c15
-rw-r--r--arch/arm/mach-s3c24xx/clock-s3c2440.c2
-rw-r--r--arch/arm/mach-shmobile/platsmp.c5
-rw-r--r--arch/arm/mach-ux500/board-mop500.c12
-rw-r--r--arch/arm/mach-ux500/timer.c2
-rw-r--r--arch/arm/mach-versatile/pci.c1
-rw-r--r--arch/arm/mm/mm.h2
-rw-r--r--arch/arm/mm/mmu.c74
-rw-r--r--arch/arm/plat-samsung/adc.c8
-rw-r--r--arch/arm/plat-samsung/devs.c3
-rw-r--r--arch/arm/plat-samsung/s5p-clock.c1
-rw-r--r--arch/h8300/include/asm/pgtable.h3
-rw-r--r--arch/h8300/include/asm/uaccess.h3
-rw-r--r--arch/h8300/kernel/signal.c2
-rw-r--r--arch/h8300/kernel/time.c1
-rw-r--r--arch/mips/pci/pci-lantiq.c4
-rw-r--r--arch/mn10300/include/asm/ptrace.h3
-rw-r--r--arch/mn10300/include/asm/thread_info.h2
-rw-r--r--arch/mn10300/include/asm/timex.h11
-rw-r--r--arch/mn10300/kernel/cevt-mn10300.c10
-rw-r--r--arch/mn10300/kernel/internal.h2
-rw-r--r--arch/mn10300/kernel/irq.c4
-rw-r--r--arch/mn10300/kernel/traps.c1
-rw-r--r--arch/mn10300/mm/dma-alloc.c1
-rw-r--r--arch/mn10300/unit-asb2303/include/unit/timex.h4
-rw-r--r--arch/mn10300/unit-asb2303/smc91111.c1
-rw-r--r--arch/mn10300/unit-asb2305/include/unit/timex.h4
-rw-r--r--arch/mn10300/unit-asb2305/unit-init.c1
-rw-r--r--arch/mn10300/unit-asb2364/include/unit/timex.h4
-rw-r--r--arch/powerpc/include/asm/hw_irq.h6
-rw-r--r--arch/powerpc/kernel/irq.c48
-rw-r--r--arch/powerpc/kvm/book3s_hv_rmhandlers.S2
-rw-r--r--arch/powerpc/kvm/book3s_pr_papr.c1
-rw-r--r--arch/powerpc/mm/numa.c2
-rw-r--r--arch/powerpc/platforms/cell/pervasive.c11
-rw-r--r--arch/powerpc/platforms/pseries/processor_idle.c17
-rw-r--r--arch/powerpc/xmon/xmon.c2
-rw-r--r--arch/sh/include/asm/io_noioport.h17
-rw-r--r--arch/sh/kernel/cpu/sh3/serial-sh7720.c2
-rw-r--r--arch/tile/kernel/backtrace.c9
-rw-r--r--arch/um/drivers/mconsole_kern.c1
-rw-r--r--arch/x86/kernel/vsyscall_64.c39
-rw-r--r--arch/x86/kvm/mmu.c3
-rw-r--r--arch/xtensa/kernel/process.c2
-rw-r--r--block/blk-cgroup.c9
-rw-r--r--block/blk-core.c25
-rw-r--r--block/blk-timeout.c41
-rw-r--r--block/cfq-iosched.c30
-rw-r--r--block/scsi_ioctl.c5
-rw-r--r--drivers/acpi/acpica/hwsleep.c22
-rw-r--r--drivers/acpi/acpica/nspredef.c2
-rw-r--r--drivers/acpi/processor_core.c6
-rw-r--r--drivers/block/drbd/drbd_bitmap.c11
-rw-r--r--drivers/block/drbd/drbd_req.c66
-rw-r--r--drivers/block/floppy.c1
-rw-r--r--drivers/block/loop.c8
-rw-r--r--drivers/block/mtip32xx/mtip32xx.c166
-rw-r--r--drivers/block/mtip32xx/mtip32xx.h5
-rw-r--r--drivers/block/umem.c40
-rw-r--r--drivers/block/xen-blkback/common.h2
-rw-r--r--drivers/block/xen-blkfront.c58
-rw-r--r--drivers/clk/clk.c28
-rw-r--r--drivers/gpio/Kconfig2
-rw-r--r--drivers/gpio/devres.c1
-rw-r--r--drivers/gpio/gpio-mxc.c10
-rw-r--r--drivers/gpio/gpio-omap.c14
-rw-r--r--drivers/gpio/gpio-sta2x11.c5
-rw-r--r--drivers/gpio/gpio-tps65910.c3
-rw-r--r--drivers/gpio/gpio-wm8994.c5
-rw-r--r--drivers/gpu/drm/drm_edid.c27
-rw-r--r--drivers/gpu/drm/i915/i915_dma.c37
-rw-r--r--drivers/gpu/drm/radeon/radeon_gart.c13
-rw-r--r--drivers/gpu/drm/radeon/radeon_gem.c10
-rw-r--r--drivers/gpu/drm/radeon/si.c4
-rw-r--r--drivers/hid/hid-apple.c6
-rw-r--r--drivers/hid/hid-core.c7
-rw-r--r--drivers/hid/hid-ids.h6
-rw-r--r--drivers/hwmon/it87.c2
-rw-r--r--drivers/hwspinlock/hwspinlock_core.c4
-rw-r--r--drivers/input/joystick/as5011.c5
-rw-r--r--drivers/input/joystick/xpad.c6
-rw-r--r--drivers/input/keyboard/mcs_touchkey.c3
-rw-r--r--drivers/input/keyboard/mpr121_touchkey.c2
-rw-r--r--drivers/input/keyboard/qt1070.c3
-rw-r--r--drivers/input/keyboard/tca6416-keypad.c3
-rw-r--r--drivers/input/keyboard/tca8418_keypad.c2
-rw-r--r--drivers/input/keyboard/tnetv107x-keypad.c8
-rw-r--r--drivers/input/misc/ad714x.c8
-rw-r--r--drivers/input/misc/dm355evm_keys.c3
-rw-r--r--drivers/input/mouse/bcm5974.c20
-rw-r--r--drivers/input/tablet/wacom_sys.c6
-rw-r--r--drivers/input/touchscreen/ad7879.c2
-rw-r--r--drivers/input/touchscreen/atmel_mxt_ts.c3
-rw-r--r--drivers/input/touchscreen/bu21013_ts.c3
-rw-r--r--drivers/input/touchscreen/cy8ctmg110_ts.c3
-rw-r--r--drivers/input/touchscreen/intel-mid-touch.c2
-rw-r--r--drivers/input/touchscreen/pixcir_i2c_ts.c2
-rw-r--r--drivers/input/touchscreen/tnetv107x-ts.c2
-rw-r--r--drivers/input/touchscreen/tsc2005.c3
-rw-r--r--drivers/iommu/amd_iommu.c11
-rw-r--r--drivers/iommu/amd_iommu_init.c6
-rw-r--r--drivers/iommu/amd_iommu_types.h2
-rw-r--r--drivers/iommu/tegra-smmu.c4
-rw-r--r--drivers/leds/ledtrig-heartbeat.c16
-rw-r--r--drivers/md/dm-thin.c7
-rw-r--r--drivers/md/md.c8
-rw-r--r--drivers/md/multipath.c3
-rw-r--r--drivers/md/persistent-data/dm-space-map-checker.c54
-rw-r--r--drivers/md/persistent-data/dm-space-map-disk.c11
-rw-r--r--drivers/md/persistent-data/dm-transaction-manager.c11
-rw-r--r--drivers/md/raid1.c16
-rw-r--r--drivers/md/raid10.c26
-rw-r--r--drivers/md/raid5.c67
-rw-r--r--drivers/media/dvb/dvb-core/dvbdev.c1
-rw-r--r--drivers/media/rc/winbond-cir.c4
-rw-r--r--drivers/media/video/cx231xx/cx231xx-audio.c4
-rw-r--r--drivers/media/video/cx231xx/cx231xx-vbi.c2
-rw-r--r--drivers/media/video/cx23885/cx23885-cards.c89
-rw-r--r--drivers/media/video/cx23885/cx23885-dvb.c6
-rw-r--r--drivers/media/video/cx23885/cx23885-video.c9
-rw-r--r--drivers/media/video/cx23885/cx23885.h1
-rw-r--r--drivers/media/video/cx25840/cx25840-core.c76
-rw-r--r--drivers/media/video/em28xx/em28xx-cards.c2
-rw-r--r--drivers/media/video/gspca/sn9c20x.c13
-rw-r--r--drivers/media/video/mx2_camera.c27
-rw-r--r--drivers/media/video/omap3isp/isppreview.c6
-rw-r--r--drivers/media/video/pms.c1
-rw-r--r--drivers/media/video/s5p-fimc/fimc-capture.c69
-rw-r--r--drivers/media/video/s5p-fimc/fimc-core.c19
-rw-r--r--drivers/media/video/s5p-fimc/fimc-lite.c73
-rw-r--r--drivers/media/video/s5p-fimc/fimc-mdevice.c48
-rw-r--r--drivers/media/video/s5p-fimc/fimc-mdevice.h2
-rw-r--r--drivers/media/video/s5p-mfc/s5p_mfc_dec.c1
-rw-r--r--drivers/media/video/s5p-mfc/s5p_mfc_enc.c1
-rw-r--r--drivers/media/video/smiapp/smiapp-core.c1
-rw-r--r--drivers/mfd/Kconfig1
-rw-r--r--drivers/mfd/ab5500-core.h87
-rw-r--r--drivers/mfd/mc13xxx-spi.c67
-rw-r--r--drivers/mfd/omap-usb-host.c48
-rw-r--r--drivers/mfd/palmas.c13
-rw-r--r--drivers/mfd/tps65217.c67
-rw-r--r--drivers/misc/mei/main.c2
-rw-r--r--drivers/misc/sgi-xp/xpc_uv.c4
-rw-r--r--drivers/mmc/core/cd-gpio.c4
-rw-r--r--drivers/mmc/core/mmc.c18
-rw-r--r--drivers/mtd/nand/cafe_nand.c2
-rw-r--r--drivers/mtd/nand/gpmi-nand/gpmi-nand.c10
-rw-r--r--drivers/mtd/nand/mxc_nand.c37
-rw-r--r--drivers/mtd/nand/nand_base.c7
-rw-r--r--drivers/mtd/nand/nandsim.c12
-rw-r--r--drivers/net/ethernet/freescale/gianfar.c10
-rw-r--r--drivers/net/ethernet/intel/e1000e/defines.h1
-rw-r--r--drivers/net/ethernet/intel/e1000e/netdev.c75
-rw-r--r--drivers/net/ethernet/intel/igbvf/ethtool.c29
-rw-r--r--drivers/net/ethernet/ti/davinci_cpdma.c1
-rw-r--r--drivers/net/usb/qmi_wwan.c4
-rw-r--r--drivers/net/wireless/ath/ath.h1
-rw-r--r--drivers/net/wireless/ath/ath9k/hw.c2
-rw-r--r--drivers/net/wireless/ath/ath9k/recv.c7
-rw-r--r--drivers/net/wireless/ath/key.c4
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-mac80211.c12
-rw-r--r--drivers/net/wireless/mwifiex/11n_rxreorder.c5
-rw-r--r--drivers/net/wireless/mwifiex/11n_rxreorder.h7
-rw-r--r--drivers/net/wireless/mwifiex/ie.c1
-rw-r--r--drivers/net/wireless/mwifiex/sdio.c6
-rw-r--r--drivers/net/wireless/mwifiex/sta_event.c9
-rw-r--r--drivers/net/wireless/mwifiex/usb.c28
-rw-r--r--drivers/net/wireless/mwifiex/wmm.c3
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192cu/sw.c3
-rw-r--r--drivers/net/wireless/ti/wlcore/Kconfig1
-rw-r--r--drivers/of/platform.c8
-rw-r--r--drivers/pci/pci-driver.c12
-rw-r--r--drivers/pci/pci.c5
-rw-r--r--drivers/pci/quirks.c26
-rw-r--r--drivers/regulator/Kconfig37
-rw-r--r--drivers/regulator/Makefile6
-rw-r--r--drivers/regulator/aat2870-regulator.c21
-rw-r--r--drivers/regulator/ab3100.c119
-rw-r--r--drivers/regulator/ab8500.c96
-rw-r--r--drivers/regulator/ad5398.c9
-rw-r--r--drivers/regulator/anatop-regulator.c42
-rw-r--r--drivers/regulator/arizona-ldo1.c138
-rw-r--r--drivers/regulator/arizona-micsupp.c188
-rw-r--r--drivers/regulator/core.c211
-rw-r--r--drivers/regulator/da903x.c6
-rw-r--r--drivers/regulator/da9052-regulator.c4
-rw-r--r--drivers/regulator/fixed.c163
-rw-r--r--drivers/regulator/gpio-regulator.c115
-rw-r--r--drivers/regulator/isl6271a-regulator.c13
-rw-r--r--drivers/regulator/lp3971.c66
-rw-r--r--drivers/regulator/lp3972.c102
-rw-r--r--drivers/regulator/lp872x.c943
-rw-r--r--drivers/regulator/lp8788-buck.c629
-rw-r--r--drivers/regulator/lp8788-ldo.c842
-rw-r--r--drivers/regulator/max1586.c108
-rw-r--r--drivers/regulator/max77686.c389
-rw-r--r--drivers/regulator/max8952.c60
-rw-r--r--drivers/regulator/max8997.c40
-rw-r--r--drivers/regulator/max8998.c133
-rw-r--r--drivers/regulator/mc13783-regulator.c38
-rw-r--r--drivers/regulator/mc13892-regulator.c43
-rw-r--r--drivers/regulator/mc13xxx-regulator-core.c36
-rw-r--r--drivers/regulator/mc13xxx.h11
-rw-r--r--drivers/regulator/of_regulator.c57
-rw-r--r--drivers/regulator/palmas-regulator.c59
-rw-r--r--drivers/regulator/pcap-regulator.c95
-rw-r--r--drivers/regulator/pcf50633-regulator.c20
-rw-r--r--drivers/regulator/rc5t583-regulator.c24
-rw-r--r--drivers/regulator/s2mps11.c363
-rw-r--r--drivers/regulator/s5m8767.c229
-rw-r--r--drivers/regulator/tps6105x-regulator.c14
-rw-r--r--drivers/regulator/tps62360-regulator.c57
-rw-r--r--drivers/regulator/tps65023-regulator.c201
-rw-r--r--drivers/regulator/tps6507x-regulator.c98
-rw-r--r--drivers/regulator/tps65217-regulator.c140
-rw-r--r--drivers/regulator/tps6524x-regulator.c94
-rw-r--r--drivers/regulator/tps6586x-regulator.c106
-rw-r--r--drivers/regulator/tps65910-regulator.c425
-rw-r--r--drivers/regulator/twl-regulator.c92
-rw-r--r--drivers/regulator/wm831x-dcdc.c78
-rw-r--r--drivers/regulator/wm831x-ldo.c131
-rw-r--r--drivers/regulator/wm8350-regulator.c426
-rw-r--r--drivers/regulator/wm8400-regulator.c25
-rw-r--r--drivers/regulator/wm8994-regulator.c93
-rw-r--r--drivers/remoteproc/Kconfig2
-rw-r--r--drivers/rpmsg/virtio_rpmsg_bus.c55
-rw-r--r--drivers/rtc/rtc-ab8500.c10
-rw-r--r--drivers/rtc/rtc-mxc.c5
-rw-r--r--drivers/rtc/rtc-spear.c2
-rw-r--r--drivers/rtc/rtc-twl.c2
-rw-r--r--drivers/scsi/aic94xx/aic94xx_task.c2
-rw-r--r--drivers/scsi/bnx2i/bnx2i.h1
-rw-r--r--drivers/scsi/bnx2i/bnx2i_hwi.c3
-rw-r--r--drivers/scsi/bnx2i/bnx2i_iscsi.c10
-rw-r--r--drivers/scsi/libsas/sas_ata.c12
-rw-r--r--drivers/scsi/qla2xxx/qla_target.c35
-rw-r--r--drivers/target/tcm_fc/tfc_sess.c3
-rw-r--r--drivers/tty/hvc/hvc_opal.c2
-rw-r--r--drivers/usb/class/cdc-wdm.c2
-rw-r--r--drivers/usb/core/hub.c18
-rw-r--r--drivers/usb/host/ehci-omap.c18
-rw-r--r--drivers/usb/host/xhci-hub.c44
-rw-r--r--drivers/usb/host/xhci-ring.c11
-rw-r--r--drivers/usb/host/xhci.h6
-rw-r--r--drivers/usb/serial/metro-usb.c8
-rw-r--r--drivers/usb/serial/option.c26
-rw-r--r--drivers/video/omap2/dss/core.c43
-rw-r--r--drivers/video/omap2/dss/dispc.c2
-rw-r--r--drivers/video/omap2/dss/dsi.c2
-rw-r--r--drivers/video/omap2/dss/dss.c2
-rw-r--r--drivers/video/omap2/dss/hdmi.c2
-rw-r--r--drivers/video/omap2/dss/rfbi.c2
-rw-r--r--drivers/video/omap2/dss/venc.c2
-rw-r--r--drivers/virtio/virtio_balloon.c24
-rw-r--r--fs/btrfs/backref.c15
-rw-r--r--fs/btrfs/ctree.c60
-rw-r--r--fs/btrfs/disk-io.c34
-rw-r--r--fs/btrfs/extent-tree.c11
-rw-r--r--fs/btrfs/extent_io.c14
-rw-r--r--fs/btrfs/file.c13
-rw-r--r--fs/btrfs/free-space-cache.c145
-rw-r--r--fs/btrfs/inode.c57
-rw-r--r--fs/btrfs/ioctl.h2
-rw-r--r--fs/btrfs/super.c4
-rw-r--r--fs/btrfs/tree-log.c6
-rw-r--r--fs/btrfs/volumes.c95
-rw-r--r--fs/btrfs/volumes.h3
-rw-r--r--fs/buffer.c22
-rw-r--r--fs/cifs/connect.c41
-rw-r--r--fs/ecryptfs/kthread.c2
-rw-r--r--fs/ecryptfs/miscdev.c48
-rw-r--r--fs/fat/inode.c13
-rw-r--r--fs/locks.c2
-rw-r--r--fs/nfs/direct.c6
-rw-r--r--fs/nfs/super.c2
-rw-r--r--fs/ocfs2/dlmglue.c33
-rw-r--r--fs/ocfs2/extent_map.c2
-rw-r--r--fs/ocfs2/file.c6
-rw-r--r--fs/ocfs2/quota_global.c2
-rw-r--r--fs/open.c6
-rw-r--r--fs/ramfs/file-nommu.c1
-rw-r--r--fs/splice.c35
-rw-r--r--include/linux/aio.h1
-rw-r--r--include/linux/blkdev.h1
-rw-r--r--include/linux/bootmem.h5
-rw-r--r--include/linux/gpio.h4
-rw-r--r--include/linux/hrtimer.h10
-rw-r--r--include/linux/input.h1
-rw-r--r--include/linux/kvm_host.h4
-rw-r--r--include/linux/memblock.h4
-rw-r--r--include/linux/mfd/s5m87xx/s5m-core.h5
-rw-r--r--include/linux/mfd/tps65217.h13
-rw-r--r--include/linux/mfd/tps65910.h6
-rw-r--r--include/linux/mmzone.h2
-rw-r--r--include/linux/pci.h2
-rw-r--r--include/linux/prctl.h2
-rw-r--r--include/linux/rcupdate.h1
-rw-r--r--include/linux/rcutiny.h6
-rw-r--r--include/linux/regulator/driver.h23
-rw-r--r--include/linux/regulator/fixed.h2
-rw-r--r--include/linux/regulator/lp872x.h90
-rw-r--r--include/linux/regulator/machine.h3
-rw-r--r--include/linux/rpmsg.h6
-rw-r--r--include/linux/sched.h18
-rw-r--r--include/linux/splice.h8
-rw-r--r--include/net/sctp/structs.h4
-rw-r--r--include/net/sctp/tsnmap.h3
-rw-r--r--include/scsi/libsas.h6
-rw-r--r--include/scsi/scsi_cmnd.h8
-rw-r--r--kernel/cgroup.c23
-rw-r--r--kernel/fork.c11
-rw-r--r--kernel/hrtimer.c53
-rw-r--r--kernel/printk.c202
-rw-r--r--kernel/rcutree.c1
-rw-r--r--kernel/rcutree.h1
-rw-r--r--kernel/rcutree_plugin.h14
-rw-r--r--kernel/relay.c5
-rw-r--r--kernel/sched/core.c276
-rw-r--r--kernel/sched/idle_task.c1
-rw-r--r--kernel/sched/sched.h2
-rw-r--r--kernel/sys.c16
-rw-r--r--kernel/time/tick-sched.c2
-rw-r--r--kernel/time/timekeeping.c63
-rw-r--r--kernel/trace/ring_buffer.c6
-rw-r--r--kernel/trace/trace.c6
-rw-r--r--lib/dma-debug.c4
-rw-r--r--mm/bootmem.c2
-rw-r--r--mm/compaction.c5
-rw-r--r--mm/madvise.c18
-rw-r--r--mm/memblock.c51
-rw-r--r--mm/memory_hotplug.c2
-rw-r--r--mm/nobootmem.c40
-rw-r--r--mm/shmem.c196
-rw-r--r--mm/sparse.c20
-rw-r--r--mm/vmscan.c7
-rw-r--r--net/core/dev.c4
-rw-r--r--net/core/skbuff.c1
-rw-r--r--net/mac80211/mlme.c13
-rw-r--r--net/mac80211/rx.c5
-rw-r--r--net/netfilter/ipset/ip_set_core.c12
-rw-r--r--net/netfilter/ipset/ip_set_hash_netiface.c32
-rw-r--r--net/netfilter/ipvs/ip_vs_ctl.c14
-rw-r--r--net/netfilter/nfnetlink.c4
-rw-r--r--net/nfc/nci/ntf.c10
-rw-r--r--net/nfc/rawsock.c5
-rw-r--r--net/sctp/associola.c1
-rw-r--r--net/sctp/output.c5
-rw-r--r--net/sctp/sm_make_chunk.c16
-rw-r--r--net/sctp/sm_sideeffect.c2
-rw-r--r--net/sctp/transport.c2
-rw-r--r--net/sctp/tsnmap.c6
-rw-r--r--net/sctp/ulpevent.c3
-rw-r--r--net/sctp/ulpqueue.c2
-rw-r--r--security/security.c1
-rw-r--r--sound/pci/hda/patch_realtek.c28
-rw-r--r--sound/soc/codecs/tlv320aic3x.c4
-rw-r--r--sound/soc/codecs/tlv320aic3x.h1
-rw-r--r--sound/soc/codecs/wm2200.c1
-rw-r--r--sound/usb/endpoint.c73
-rw-r--r--sound/usb/pcm.c61
-rw-r--r--tools/perf/util/map.c29
-rw-r--r--tools/perf/util/session.c2
-rw-r--r--tools/perf/util/trace-event-parse.c3
-rw-r--r--virt/kvm/assigned-dev.c15
-rw-r--r--virt/kvm/eventfd.c23
-rw-r--r--virt/kvm/kvm_main.c3
415 files changed, 8773 insertions, 4598 deletions
diff --git a/Documentation/ABI/testing/sysfs-block-rssd b/Documentation/ABI/testing/sysfs-block-rssd
index 679ce3543122..beef30c046b0 100644
--- a/Documentation/ABI/testing/sysfs-block-rssd
+++ b/Documentation/ABI/testing/sysfs-block-rssd
@@ -1,26 +1,5 @@
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 - Completed
10 - PORT IRQ STAT
11 - HOST IRQ STAT
12 - Allocated
13 - Commands in Q
14
15What: /sys/block/rssd*/status 1What: /sys/block/rssd*/status
16Date: April 2012 2Date: April 2012
17KernelVersion: 3.4 3KernelVersion: 3.4
18Contact: Asai Thambi S P <asamymuthupa@micron.com> 4Contact: Asai Thambi S P <asamymuthupa@micron.com>
19Description: This is a read-only file. Indicates the status of the device. 5Description: This is a read-only file. Indicates the status of the device.
20
21What: /sys/block/rssd*/flags
22Date: May 2012
23KernelVersion: 3.5
24Contact: Asai Thambi S P <asamymuthupa@micron.com>
25Description: This is a read-only file. Dumps the flags in port and driver
26 data structure
diff --git a/Documentation/ABI/testing/sysfs-class-mtd b/Documentation/ABI/testing/sysfs-class-mtd
index db1ad7e34fc3..938ef71e2035 100644
--- a/Documentation/ABI/testing/sysfs-class-mtd
+++ b/Documentation/ABI/testing/sysfs-class-mtd
@@ -142,13 +142,14 @@ KernelVersion: 3.4
142Contact: linux-mtd@lists.infradead.org 142Contact: linux-mtd@lists.infradead.org
143Description: 143Description:
144 This allows the user to examine and adjust the criteria by which 144 This allows the user to examine and adjust the criteria by which
145 mtd returns -EUCLEAN from mtd_read(). If the maximum number of 145 mtd returns -EUCLEAN from mtd_read() and mtd_read_oob(). If the
146 bit errors that were corrected on any single region comprising 146 maximum number of bit errors that were corrected on any single
147 an ecc step (as reported by the driver) equals or exceeds this 147 region comprising an ecc step (as reported by the driver) equals
148 value, -EUCLEAN is returned. Otherwise, absent an error, 0 is 148 or exceeds this value, -EUCLEAN is returned. Otherwise, absent
149 returned. Higher layers (e.g., UBI) use this return code as an 149 an error, 0 is returned. Higher layers (e.g., UBI) use this
150 indication that an erase block may be degrading and should be 150 return code as an indication that an erase block may be
151 scrutinized as a candidate for being marked as bad. 151 degrading and should be scrutinized as a candidate for being
152 marked as bad.
152 153
153 The initial value may be specified by the flash device driver. 154 The initial value may be specified by the flash device driver.
154 If not, then the default value is ecc_strength. 155 If not, then the default value is ecc_strength.
@@ -167,7 +168,7 @@ Description:
167 block degradation, but high enough to avoid the consequences of 168 block degradation, but high enough to avoid the consequences of
168 a persistent return value of -EUCLEAN on devices where sticky 169 a persistent return value of -EUCLEAN on devices where sticky
169 bitflips occur. Note that if bitflip_threshold exceeds 170 bitflips occur. Note that if bitflip_threshold exceeds
170 ecc_strength, -EUCLEAN is never returned by mtd_read(). 171 ecc_strength, -EUCLEAN is never returned by the read operations.
171 Conversely, if bitflip_threshold is zero, -EUCLEAN is always 172 Conversely, if bitflip_threshold is zero, -EUCLEAN is always
172 returned, absent a hard error. 173 returned, absent a hard error.
173 174
diff --git a/Documentation/DocBook/media/v4l/controls.xml b/Documentation/DocBook/media/v4l/controls.xml
index 676bc46f9c52..cda0dfb6769a 100644
--- a/Documentation/DocBook/media/v4l/controls.xml
+++ b/Documentation/DocBook/media/v4l/controls.xml
@@ -3988,7 +3988,7 @@ interface and may change in the future.</para>
3988 from RGB to Y'CbCr color space. 3988 from RGB to Y'CbCr color space.
3989 </entry> 3989 </entry>
3990 </row> 3990 </row>
3991 <row id = "v4l2-jpeg-chroma-subsampling"> 3991 <row>
3992 <entrytbl spanname="descr" cols="2"> 3992 <entrytbl spanname="descr" cols="2">
3993 <tbody valign="top"> 3993 <tbody valign="top">
3994 <row> 3994 <row>
diff --git a/Documentation/DocBook/media/v4l/vidioc-g-ext-ctrls.xml b/Documentation/DocBook/media/v4l/vidioc-g-ext-ctrls.xml
index e3d5afcdafbb..0a4b90fcf2da 100644
--- a/Documentation/DocBook/media/v4l/vidioc-g-ext-ctrls.xml
+++ b/Documentation/DocBook/media/v4l/vidioc-g-ext-ctrls.xml
@@ -284,13 +284,6 @@ These controls are described in <xref
284 processing controls. These controls are described in <xref 284 processing controls. These controls are described in <xref
285 linkend="image-process-controls" />.</entry> 285 linkend="image-process-controls" />.</entry>
286 </row> 286 </row>
287 <row>
288 <entry><constant>V4L2_CTRL_CLASS_JPEG</constant></entry>
289 <entry>0x9d0000</entry>
290 <entry>The class containing JPEG compression controls.
291These controls are described in <xref
292 linkend="jpeg-controls" />.</entry>
293 </row>
294 </tbody> 287 </tbody>
295 </tgroup> 288 </tgroup>
296 </table> 289 </table>
diff --git a/Documentation/device-mapper/verity.txt b/Documentation/device-mapper/verity.txt
index 32e48797a14f..9884681535ee 100644
--- a/Documentation/device-mapper/verity.txt
+++ b/Documentation/device-mapper/verity.txt
@@ -7,39 +7,39 @@ This target is read-only.
7 7
8Construction Parameters 8Construction Parameters
9======================= 9=======================
10 <version> <dev> <hash_dev> <hash_start> 10 <version> <dev> <hash_dev>
11 <data_block_size> <hash_block_size> 11 <data_block_size> <hash_block_size>
12 <num_data_blocks> <hash_start_block> 12 <num_data_blocks> <hash_start_block>
13 <algorithm> <digest> <salt> 13 <algorithm> <digest> <salt>
14 14
15<version> 15<version>
16 This is the version number of the on-disk format. 16 This is the type of the on-disk hash format.
17 17
18 0 is the original format used in the Chromium OS. 18 0 is the original format used in the Chromium OS.
19 The salt is appended when hashing, digests are stored continuously and 19 The salt is appended when hashing, digests are stored continuously and
20 the rest of the block is padded with zeros. 20 the rest of the block is padded with zeros.
21 21
22 1 is the current format that should be used for new devices. 22 1 is the current format that should be used for new devices.
23 The salt is prepended when hashing and each digest is 23 The salt is prepended when hashing and each digest is
24 padded with zeros to the power of two. 24 padded with zeros to the power of two.
25 25
26<dev> 26<dev>
27 This is the device containing the data the integrity of which needs to be 27 This is the device containing data, the integrity of which needs to be
28 checked. It may be specified as a path, like /dev/sdaX, or a device number, 28 checked. It may be specified as a path, like /dev/sdaX, or a device number,
29 <major>:<minor>. 29 <major>:<minor>.
30 30
31<hash_dev> 31<hash_dev>
32 This is the device that that supplies the hash tree data. It may be 32 This is the device that supplies the hash tree data. It may be
33 specified similarly to the device path and may be the same device. If the 33 specified similarly to the device path and may be the same device. If the
34 same device is used, the hash_start should be outside of the dm-verity 34 same device is used, the hash_start should be outside the configured
35 configured device size. 35 dm-verity device.
36 36
37<data_block_size> 37<data_block_size>
38 The block size on a data device. Each block corresponds to one digest on 38 The block size on a data device in bytes.
39 the hash device. 39 Each block corresponds to one digest on the hash device.
40 40
41<hash_block_size> 41<hash_block_size>
42 The size of a hash block. 42 The size of a hash block in bytes.
43 43
44<num_data_blocks> 44<num_data_blocks>
45 The number of data blocks on the data device. Additional blocks are 45 The number of data blocks on the data device. Additional blocks are
@@ -65,7 +65,7 @@ Construction Parameters
65Theory of operation 65Theory of operation
66=================== 66===================
67 67
68dm-verity is meant to be setup as part of a verified boot path. This 68dm-verity is meant to be set up as part of a verified boot path. This
69may be anything ranging from a boot using tboot or trustedgrub to just 69may be anything ranging from a boot using tboot or trustedgrub to just
70booting from a known-good device (like a USB drive or CD). 70booting from a known-good device (like a USB drive or CD).
71 71
@@ -73,20 +73,20 @@ When a dm-verity device is configured, it is expected that the caller
73has been authenticated in some way (cryptographic signatures, etc). 73has been authenticated in some way (cryptographic signatures, etc).
74After instantiation, all hashes will be verified on-demand during 74After instantiation, all hashes will be verified on-demand during
75disk access. If they cannot be verified up to the root node of the 75disk access. If they cannot be verified up to the root node of the
76tree, the root hash, then the I/O will fail. This should identify 76tree, the root hash, then the I/O will fail. This should detect
77tampering with any data on the device and the hash data. 77tampering with any data on the device and the hash data.
78 78
79Cryptographic hashes are used to assert the integrity of the device on a 79Cryptographic hashes are used to assert the integrity of the device on a
80per-block basis. This allows for a lightweight hash computation on first read 80per-block basis. This allows for a lightweight hash computation on first read
81into the page cache. Block hashes are stored linearly-aligned to the nearest 81into the page cache. Block hashes are stored linearly, aligned to the nearest
82block the size of a page. 82block size.
83 83
84Hash Tree 84Hash Tree
85--------- 85---------
86 86
87Each node in the tree is a cryptographic hash. If it is a leaf node, the hash 87Each node in the tree is a cryptographic hash. If it is a leaf node, the hash
88is of some block data on disk. If it is an intermediary node, then the hash is 88of some data block on disk is calculated. If it is an intermediary node,
89of a number of child nodes. 89the hash of a number of child nodes is calculated.
90 90
91Each entry in the tree is a collection of neighboring nodes that fit in one 91Each entry in the tree is a collection of neighboring nodes that fit in one
92block. The number is determined based on block_size and the size of the 92block. The number is determined based on block_size and the size of the
@@ -110,63 +110,23 @@ alg = sha256, num_blocks = 32768, block_size = 4096
110On-disk format 110On-disk format
111============== 111==============
112 112
113Below is the recommended on-disk format. The verity kernel code does not 113The verity kernel code does not read the verity metadata on-disk header.
114read the on-disk header. It only reads the hash blocks which directly 114It only reads the hash blocks which directly follow the header.
115follow the header. It is expected that a user-space tool will verify the 115It is expected that a user-space tool will verify the integrity of the
116integrity of the verity_header and then call dmsetup with the correct 116verity header.
117parameters. Alternatively, the header can be omitted and the dmsetup
118parameters can be passed via the kernel command-line in a rooted chain
119of trust where the command-line is verified.
120 117
121The on-disk format is especially useful in cases where the hash blocks 118Alternatively, the header can be omitted and the dmsetup parameters can
122are on a separate partition. The magic number allows easy identification 119be passed via the kernel command-line in a rooted chain of trust where
123of the partition contents. Alternatively, the hash blocks can be stored 120the command-line is verified.
124in the same partition as the data to be verified. In such a configuration
125the filesystem on the partition would be sized a little smaller than
126the full-partition, leaving room for the hash blocks.
127
128struct superblock {
129 uint8_t signature[8]
130 "verity\0\0";
131
132 uint8_t version;
133 1 - current format
134
135 uint8_t data_block_bits;
136 log2(data block size)
137
138 uint8_t hash_block_bits;
139 log2(hash block size)
140
141 uint8_t pad1[1];
142 zero padding
143
144 uint16_t salt_size;
145 big-endian salt size
146
147 uint8_t pad2[2];
148 zero padding
149
150 uint32_t data_blocks_hi;
151 big-endian high 32 bits of the 64-bit number of data blocks
152
153 uint32_t data_blocks_lo;
154 big-endian low 32 bits of the 64-bit number of data blocks
155
156 uint8_t algorithm[16];
157 cryptographic algorithm
158
159 uint8_t salt[384];
160 salt (the salt size is specified above)
161
162 uint8_t pad3[88];
163 zero padding to 512-byte boundary
164}
165 121
166Directly following the header (and with sector number padded to the next hash 122Directly following the header (and with sector number padded to the next hash
167block boundary) are the hash blocks which are stored a depth at a time 123block boundary) are the hash blocks which are stored a depth at a time
168(starting from the root), sorted in order of increasing index. 124(starting from the root), sorted in order of increasing index.
169 125
126The full specification of kernel parameters and on-disk metadata format
127is available at the cryptsetup project's wiki page
128 http://code.google.com/p/cryptsetup/wiki/DMVerity
129
170Status 130Status
171====== 131======
172V (for Valid) is returned if every check performed so far was valid. 132V (for Valid) is returned if every check performed so far was valid.
@@ -174,21 +134,22 @@ If any check failed, C (for Corruption) is returned.
174 134
175Example 135Example
176======= 136=======
177 137Set up a device:
178Setup a device: 138 # dmsetup create vroot --readonly --table \
179 dmsetup create vroot --table \ 139 "0 2097152 verity 1 /dev/sda1 /dev/sda2 4096 4096 262144 1 sha256 "\
180 "0 2097152 "\
181 "verity 1 /dev/sda1 /dev/sda2 4096 4096 2097152 1 "\
182 "4392712ba01368efdf14b05c76f9e4df0d53664630b5d48632ed17a137f39076 "\ 140 "4392712ba01368efdf14b05c76f9e4df0d53664630b5d48632ed17a137f39076 "\
183 "1234000000000000000000000000000000000000000000000000000000000000" 141 "1234000000000000000000000000000000000000000000000000000000000000"
184 142
185A command line tool veritysetup is available to compute or verify 143A command line tool veritysetup is available to compute or verify
186the hash tree or activate the kernel driver. This is available from 144the hash tree or activate the kernel device. This is available from
187the LVM2 upstream repository and may be supplied as a package called 145the cryptsetup upstream repository http://code.google.com/p/cryptsetup/
188device-mapper-verity-tools: 146(as a libcryptsetup extension).
189 git://sources.redhat.com/git/lvm2 147
190 http://sourceware.org/git/?p=lvm2.git 148Create hash on the device:
191 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/verity?cvsroot=lvm2 149 # veritysetup format /dev/sda1 /dev/sda2
192 150 ...
193veritysetup -a vroot /dev/sda1 /dev/sda2 \ 151 Root hash: 4392712ba01368efdf14b05c76f9e4df0d53664630b5d48632ed17a137f39076
194 4392712ba01368efdf14b05c76f9e4df0d53664630b5d48632ed17a137f39076 152
153Activate the device:
154 # veritysetup create vroot /dev/sda1 /dev/sda2 \
155 4392712ba01368efdf14b05c76f9e4df0d53664630b5d48632ed17a137f39076
diff --git a/Documentation/devicetree/bindings/input/fsl-mma8450.txt b/Documentation/devicetree/bindings/input/fsl-mma8450.txt
index a00c94ccbdee..0b96e5737d3a 100644
--- a/Documentation/devicetree/bindings/input/fsl-mma8450.txt
+++ b/Documentation/devicetree/bindings/input/fsl-mma8450.txt
@@ -2,6 +2,7 @@
2 2
3Required properties: 3Required properties:
4- compatible : "fsl,mma8450". 4- compatible : "fsl,mma8450".
5- reg: the I2C address of MMA8450
5 6
6Example: 7Example:
7 8
diff --git a/Documentation/devicetree/bindings/mfd/mc13xxx.txt b/Documentation/devicetree/bindings/mfd/mc13xxx.txt
index 19f6af47a792..baf07987ae68 100644
--- a/Documentation/devicetree/bindings/mfd/mc13xxx.txt
+++ b/Documentation/devicetree/bindings/mfd/mc13xxx.txt
@@ -46,8 +46,8 @@ Examples:
46 46
47ecspi@70010000 { /* ECSPI1 */ 47ecspi@70010000 { /* ECSPI1 */
48 fsl,spi-num-chipselects = <2>; 48 fsl,spi-num-chipselects = <2>;
49 cs-gpios = <&gpio3 24 0>, /* GPIO4_24 */ 49 cs-gpios = <&gpio4 24 0>, /* GPIO4_24 */
50 <&gpio3 25 0>; /* GPIO4_25 */ 50 <&gpio4 25 0>; /* GPIO4_25 */
51 status = "okay"; 51 status = "okay";
52 52
53 pmic: mc13892@0 { 53 pmic: mc13892@0 {
diff --git a/Documentation/devicetree/bindings/mfd/tps65910.txt b/Documentation/devicetree/bindings/mfd/tps65910.txt
index 645f5eaadb3f..d2802d4717bc 100644
--- a/Documentation/devicetree/bindings/mfd/tps65910.txt
+++ b/Documentation/devicetree/bindings/mfd/tps65910.txt
@@ -17,18 +17,46 @@ Required properties:
17 device need to be present. The definition for each of these nodes is defined 17 device need to be present. The definition for each of these nodes is defined
18 using the standard binding for regulators found at 18 using the standard binding for regulators found at
19 Documentation/devicetree/bindings/regulator/regulator.txt. 19 Documentation/devicetree/bindings/regulator/regulator.txt.
20 The regulator is matched with the regulator-compatible.
20 21
21 The valid names for regulators are: 22 The valid regulator-compatible values are:
22 tps65910: vrtc, vio, vdd1, vdd2, vdd3, vdig1, vdig2, vpll, vdac, vaux1, 23 tps65910: vrtc, vio, vdd1, vdd2, vdd3, vdig1, vdig2, vpll, vdac, vaux1,
23 vaux2, vaux33, vmmc 24 vaux2, vaux33, vmmc
24 tps65911: vrtc, vio, vdd1, vdd3, vddctrl, ldo1, ldo2, ldo3, ldo4, ldo5, 25 tps65911: vrtc, vio, vdd1, vdd3, vddctrl, ldo1, ldo2, ldo3, ldo4, ldo5,
25 ldo6, ldo7, ldo8 26 ldo6, ldo7, ldo8
26 27
28- xxx-supply: Input voltage supply regulator.
29 These entries are require if regulators are enabled for a device. Missing of these
30 properties can cause the regulator registration fails.
31 If some of input supply is powered through battery or always-on supply then
32 also it is require to have these parameters with proper node handle of always
33 on power supply.
34 tps65910:
35 vcc1-supply: VDD1 input.
36 vcc2-supply: VDD2 input.
37 vcc3-supply: VAUX33 and VMMC input.
38 vcc4-supply: VAUX1 and VAUX2 input.
39 vcc5-supply: VPLL and VDAC input.
40 vcc6-supply: VDIG1 and VDIG2 input.
41 vcc7-supply: VRTC input.
42 vccio-supply: VIO input.
43 tps65911:
44 vcc1-supply: VDD1 input.
45 vcc2-supply: VDD2 input.
46 vcc3-supply: LDO6, LDO7 and LDO8 input.
47 vcc4-supply: LDO5 input.
48 vcc5-supply: LDO3 and LDO4 input.
49 vcc6-supply: LDO1 and LDO2 input.
50 vcc7-supply: VRTC input.
51 vccio-supply: VIO input.
52
27Optional properties: 53Optional properties:
28- ti,vmbch-threshold: (tps65911) main battery charged threshold 54- ti,vmbch-threshold: (tps65911) main battery charged threshold
29 comparator. (see VMBCH_VSEL in TPS65910 datasheet) 55 comparator. (see VMBCH_VSEL in TPS65910 datasheet)
30- ti,vmbch2-threshold: (tps65911) main battery discharged threshold 56- ti,vmbch2-threshold: (tps65911) main battery discharged threshold
31 comparator. (see VMBCH_VSEL in TPS65910 datasheet) 57 comparator. (see VMBCH_VSEL in TPS65910 datasheet)
58- ti,en-ck32k-xtal: enable external 32-kHz crystal oscillator (see CK32K_CTRL
59 in TPS6591X datasheet)
32- ti,en-gpio-sleep: enable sleep control for gpios 60- ti,en-gpio-sleep: enable sleep control for gpios
33 There should be 9 entries here, one for each gpio. 61 There should be 9 entries here, one for each gpio.
34 62
@@ -56,74 +84,110 @@ Example:
56 84
57 ti,en-gpio-sleep = <0 0 1 0 0 0 0 0 0>; 85 ti,en-gpio-sleep = <0 0 1 0 0 0 0 0 0>;
58 86
87 vcc1-supply = <&reg_parent>;
88 vcc2-supply = <&some_reg>;
89 vcc3-supply = <...>;
90 vcc4-supply = <...>;
91 vcc5-supply = <...>;
92 vcc6-supply = <...>;
93 vcc7-supply = <...>;
94 vccio-supply = <...>;
95
59 regulators { 96 regulators {
60 vdd1_reg: vdd1 { 97 #address-cells = <1>;
98 #size-cells = <0>;
99
100 vdd1_reg: regulator@0 {
101 regulator-compatible = "vdd1";
102 reg = <0>;
61 regulator-min-microvolt = < 600000>; 103 regulator-min-microvolt = < 600000>;
62 regulator-max-microvolt = <1500000>; 104 regulator-max-microvolt = <1500000>;
63 regulator-always-on; 105 regulator-always-on;
64 regulator-boot-on; 106 regulator-boot-on;
65 ti,regulator-ext-sleep-control = <0>; 107 ti,regulator-ext-sleep-control = <0>;
66 }; 108 };
67 vdd2_reg: vdd2 { 109 vdd2_reg: regulator@1 {
110 regulator-compatible = "vdd2";
111 reg = <1>;
68 regulator-min-microvolt = < 600000>; 112 regulator-min-microvolt = < 600000>;
69 regulator-max-microvolt = <1500000>; 113 regulator-max-microvolt = <1500000>;
70 regulator-always-on; 114 regulator-always-on;
71 regulator-boot-on; 115 regulator-boot-on;
72 ti,regulator-ext-sleep-control = <4>; 116 ti,regulator-ext-sleep-control = <4>;
73 }; 117 };
74 vddctrl_reg: vddctrl { 118 vddctrl_reg: regulator@2 {
119 regulator-compatible = "vddctrl";
120 reg = <2>;
75 regulator-min-microvolt = < 600000>; 121 regulator-min-microvolt = < 600000>;
76 regulator-max-microvolt = <1400000>; 122 regulator-max-microvolt = <1400000>;
77 regulator-always-on; 123 regulator-always-on;
78 regulator-boot-on; 124 regulator-boot-on;
79 ti,regulator-ext-sleep-control = <0>; 125 ti,regulator-ext-sleep-control = <0>;
80 }; 126 };
81 vio_reg: vio { 127 vio_reg: regulator@3 {
128 regulator-compatible = "vio";
129 reg = <3>;
82 regulator-min-microvolt = <1500000>; 130 regulator-min-microvolt = <1500000>;
83 regulator-max-microvolt = <1800000>; 131 regulator-max-microvolt = <1800000>;
84 regulator-always-on; 132 regulator-always-on;
85 regulator-boot-on; 133 regulator-boot-on;
86 ti,regulator-ext-sleep-control = <1>; 134 ti,regulator-ext-sleep-control = <1>;
87 }; 135 };
88 ldo1_reg: ldo1 { 136 ldo1_reg: regulator@4 {
137 regulator-compatible = "ldo1";
138 reg = <4>;
89 regulator-min-microvolt = <1000000>; 139 regulator-min-microvolt = <1000000>;
90 regulator-max-microvolt = <3300000>; 140 regulator-max-microvolt = <3300000>;
91 ti,regulator-ext-sleep-control = <0>; 141 ti,regulator-ext-sleep-control = <0>;
92 }; 142 };
93 ldo2_reg: ldo2 { 143 ldo2_reg: regulator@5 {
144 regulator-compatible = "ldo2";
145 reg = <5>;
94 regulator-min-microvolt = <1050000>; 146 regulator-min-microvolt = <1050000>;
95 regulator-max-microvolt = <1050000>; 147 regulator-max-microvolt = <1050000>;
96 ti,regulator-ext-sleep-control = <0>; 148 ti,regulator-ext-sleep-control = <0>;
97 }; 149 };
98 ldo3_reg: ldo3 { 150 ldo3_reg: regulator@6 {
151 regulator-compatible = "ldo3";
152 reg = <6>;
99 regulator-min-microvolt = <1000000>; 153 regulator-min-microvolt = <1000000>;
100 regulator-max-microvolt = <3300000>; 154 regulator-max-microvolt = <3300000>;
101 ti,regulator-ext-sleep-control = <0>; 155 ti,regulator-ext-sleep-control = <0>;
102 }; 156 };
103 ldo4_reg: ldo4 { 157 ldo4_reg: regulator@7 {
158 regulator-compatible = "ldo4";
159 reg = <7>;
104 regulator-min-microvolt = <1000000>; 160 regulator-min-microvolt = <1000000>;
105 regulator-max-microvolt = <3300000>; 161 regulator-max-microvolt = <3300000>;
106 regulator-always-on; 162 regulator-always-on;
107 ti,regulator-ext-sleep-control = <0>; 163 ti,regulator-ext-sleep-control = <0>;
108 }; 164 };
109 ldo5_reg: ldo5 { 165 ldo5_reg: regulator@8 {
166 regulator-compatible = "ldo5";
167 reg = <8>;
110 regulator-min-microvolt = <1000000>; 168 regulator-min-microvolt = <1000000>;
111 regulator-max-microvolt = <3300000>; 169 regulator-max-microvolt = <3300000>;
112 ti,regulator-ext-sleep-control = <0>; 170 ti,regulator-ext-sleep-control = <0>;
113 }; 171 };
114 ldo6_reg: ldo6 { 172 ldo6_reg: regulator@9 {
173 regulator-compatible = "ldo6";
174 reg = <9>;
115 regulator-min-microvolt = <1200000>; 175 regulator-min-microvolt = <1200000>;
116 regulator-max-microvolt = <1200000>; 176 regulator-max-microvolt = <1200000>;
117 ti,regulator-ext-sleep-control = <0>; 177 ti,regulator-ext-sleep-control = <0>;
118 }; 178 };
119 ldo7_reg: ldo7 { 179 ldo7_reg: regulator@10 {
180 regulator-compatible = "ldo7";
181 reg = <10>;
120 regulator-min-microvolt = <1200000>; 182 regulator-min-microvolt = <1200000>;
121 regulator-max-microvolt = <1200000>; 183 regulator-max-microvolt = <1200000>;
122 regulator-always-on; 184 regulator-always-on;
123 regulator-boot-on; 185 regulator-boot-on;
124 ti,regulator-ext-sleep-control = <1>; 186 ti,regulator-ext-sleep-control = <1>;
125 }; 187 };
126 ldo8_reg: ldo8 { 188 ldo8_reg: regulator@11 {
189 regulator-compatible = "ldo8";
190 reg = <11>;
127 regulator-min-microvolt = <1000000>; 191 regulator-min-microvolt = <1000000>;
128 regulator-max-microvolt = <3300000>; 192 regulator-max-microvolt = <3300000>;
129 regulator-always-on; 193 regulator-always-on;
diff --git a/Documentation/devicetree/bindings/mmc/fsl-imx-esdhc.txt b/Documentation/devicetree/bindings/mmc/fsl-imx-esdhc.txt
index c7e404b3ef05..fea541ee8b34 100644
--- a/Documentation/devicetree/bindings/mmc/fsl-imx-esdhc.txt
+++ b/Documentation/devicetree/bindings/mmc/fsl-imx-esdhc.txt
@@ -29,6 +29,6 @@ esdhc@70008000 {
29 compatible = "fsl,imx51-esdhc"; 29 compatible = "fsl,imx51-esdhc";
30 reg = <0x70008000 0x4000>; 30 reg = <0x70008000 0x4000>;
31 interrupts = <2>; 31 interrupts = <2>;
32 cd-gpios = <&gpio0 6 0>; /* GPIO1_6 */ 32 cd-gpios = <&gpio1 6 0>; /* GPIO1_6 */
33 wp-gpios = <&gpio0 5 0>; /* GPIO1_5 */ 33 wp-gpios = <&gpio1 5 0>; /* GPIO1_5 */
34}; 34};
diff --git a/Documentation/devicetree/bindings/net/fsl-fec.txt b/Documentation/devicetree/bindings/net/fsl-fec.txt
index 7ab9e1a2d8be..4616fc28ee86 100644
--- a/Documentation/devicetree/bindings/net/fsl-fec.txt
+++ b/Documentation/devicetree/bindings/net/fsl-fec.txt
@@ -19,6 +19,6 @@ ethernet@83fec000 {
19 reg = <0x83fec000 0x4000>; 19 reg = <0x83fec000 0x4000>;
20 interrupts = <87>; 20 interrupts = <87>;
21 phy-mode = "mii"; 21 phy-mode = "mii";
22 phy-reset-gpios = <&gpio1 14 0>; /* GPIO2_14 */ 22 phy-reset-gpios = <&gpio2 14 0>; /* GPIO2_14 */
23 local-mac-address = [00 04 9F 01 1B B9]; 23 local-mac-address = [00 04 9F 01 1B B9];
24}; 24};
diff --git a/Documentation/devicetree/bindings/regulator/fixed-regulator.txt b/Documentation/devicetree/bindings/regulator/fixed-regulator.txt
index 2f5b6b1ba15f..4fae41d54798 100644
--- a/Documentation/devicetree/bindings/regulator/fixed-regulator.txt
+++ b/Documentation/devicetree/bindings/regulator/fixed-regulator.txt
@@ -10,6 +10,7 @@ Optional properties:
10If this property is missing, the default assumed is Active low. 10If this property is missing, the default assumed is Active low.
11- gpio-open-drain: GPIO is open drain type. 11- gpio-open-drain: GPIO is open drain type.
12 If this property is missing then default assumption is false. 12 If this property is missing then default assumption is false.
13-vin-supply: Input supply name.
13 14
14Any property defined as part of the core regulator 15Any property defined as part of the core regulator
15binding, defined in regulator.txt, can also be used. 16binding, defined in regulator.txt, can also be used.
@@ -29,4 +30,5 @@ Example:
29 enable-active-high; 30 enable-active-high;
30 regulator-boot-on; 31 regulator-boot-on;
31 gpio-open-drain; 32 gpio-open-drain;
33 vin-supply = <&parent_reg>;
32 }; 34 };
diff --git a/Documentation/devicetree/bindings/regulator/regulator.txt b/Documentation/devicetree/bindings/regulator/regulator.txt
index 5b7a408acdaa..66ece3f87bbc 100644
--- a/Documentation/devicetree/bindings/regulator/regulator.txt
+++ b/Documentation/devicetree/bindings/regulator/regulator.txt
@@ -10,6 +10,11 @@ Optional properties:
10- regulator-always-on: boolean, regulator should never be disabled 10- regulator-always-on: boolean, regulator should never be disabled
11- regulator-boot-on: bootloader/firmware enabled regulator 11- regulator-boot-on: bootloader/firmware enabled regulator
12- <name>-supply: phandle to the parent supply/regulator node 12- <name>-supply: phandle to the parent supply/regulator node
13- regulator-ramp-delay: ramp delay for regulator(in uV/uS)
14- regulator-compatible: If a regulator chip contains multiple
15 regulators, and if the chip's binding contains a child node that
16 describes each regulator, then this property indicates which regulator
17 this child node is intended to configure.
13 18
14Example: 19Example:
15 20
diff --git a/Documentation/devicetree/bindings/regulator/tps65217.txt b/Documentation/devicetree/bindings/regulator/tps65217.txt
new file mode 100644
index 000000000000..0487e9675ba0
--- /dev/null
+++ b/Documentation/devicetree/bindings/regulator/tps65217.txt
@@ -0,0 +1,91 @@
1TPS65217 family of regulators
2
3Required properties:
4- compatible: "ti,tps65217"
5- reg: I2C slave address
6- regulators: list of regulators provided by this controller, must be named
7 after their hardware counterparts: dcdc[1-3] and ldo[1-4]
8- regulators: This is the list of child nodes that specify the regulator
9 initialization data for defined regulators. Not all regulators for the given
10 device need to be present. The definition for each of these nodes is defined
11 using the standard binding for regulators found at
12 Documentation/devicetree/bindings/regulator/regulator.txt.
13
14 The valid names for regulators are:
15 tps65217: dcdc1, dcdc2, dcdc3, ldo1, ldo2, ldo3 and ldo4
16
17Each regulator is defined using the standard binding for regulators.
18
19Example:
20
21 tps: tps@24 {
22 compatible = "ti,tps65217";
23
24 regulators {
25 #address-cells = <1>;
26 #size-cells = <0>;
27
28 dcdc1_reg: regulator@0 {
29 reg = <0>;
30 regulator-compatible = "dcdc1";
31 regulator-min-microvolt = <900000>;
32 regulator-max-microvolt = <1800000>;
33 regulator-boot-on;
34 regulator-always-on;
35 };
36
37 dcdc2_reg: regulator@1 {
38 reg = <1>;
39 regulator-compatible = "dcdc2";
40 regulator-min-microvolt = <900000>;
41 regulator-max-microvolt = <3300000>;
42 regulator-boot-on;
43 regulator-always-on;
44 };
45
46 dcdc3_reg: regulator@2 {
47 reg = <2>;
48 regulator-compatible = "dcdc3";
49 regulator-min-microvolt = <900000>;
50 regulator-max-microvolt = <1500000>;
51 regulator-boot-on;
52 regulator-always-on;
53 };
54
55 ldo1_reg: regulator@3 {
56 reg = <3>;
57 regulator-compatible = "ldo1";
58 regulator-min-microvolt = <1000000>;
59 regulator-max-microvolt = <3300000>;
60 regulator-boot-on;
61 regulator-always-on;
62 };
63
64 ldo2_reg: regulator@4 {
65 reg = <4>;
66 regulator-compatible = "ldo2";
67 regulator-min-microvolt = <900000>;
68 regulator-max-microvolt = <3300000>;
69 regulator-boot-on;
70 regulator-always-on;
71 };
72
73 ldo3_reg: regulator@5 {
74 reg = <5>;
75 regulator-compatible = "ldo3";
76 regulator-min-microvolt = <1800000>;
77 regulator-max-microvolt = <3300000>;
78 regulator-boot-on;
79 regulator-always-on;
80 };
81
82 ldo4_reg: regulator@6 {
83 reg = <6>;
84 regulator-compatible = "ldo4";
85 regulator-min-microvolt = <1800000>;
86 regulator-max-microvolt = <3300000>;
87 regulator-boot-on;
88 regulator-always-on;
89 };
90 };
91 };
diff --git a/Documentation/devicetree/bindings/regulator/tps6586x.txt b/Documentation/devicetree/bindings/regulator/tps6586x.txt
index 0fcabaa3baa3..d156e1b5db12 100644
--- a/Documentation/devicetree/bindings/regulator/tps6586x.txt
+++ b/Documentation/devicetree/bindings/regulator/tps6586x.txt
@@ -6,8 +6,17 @@ Required properties:
6- interrupts: the interrupt outputs of the controller 6- interrupts: the interrupt outputs of the controller
7- #gpio-cells: number of cells to describe a GPIO 7- #gpio-cells: number of cells to describe a GPIO
8- gpio-controller: mark the device as a GPIO controller 8- gpio-controller: mark the device as a GPIO controller
9- regulators: list of regulators provided by this controller, must be named 9- regulators: list of regulators provided by this controller, must have
10 after their hardware counterparts: sm[0-2], ldo[0-9] and ldo_rtc 10 property "regulator-compatible" to match their hardware counterparts:
11 sm[0-2], ldo[0-9] and ldo_rtc
12- sm0-supply: The input supply for the SM0.
13- sm1-supply: The input supply for the SM1.
14- sm2-supply: The input supply for the SM2.
15- vinldo01-supply: The input supply for the LDO1 and LDO2
16- vinldo23-supply: The input supply for the LDO2 and LDO3
17- vinldo4-supply: The input supply for the LDO4
18- vinldo678-supply: The input supply for the LDO6, LDO7 and LDO8
19- vinldo9-supply: The input supply for the LDO9
11 20
12Each regulator is defined using the standard binding for regulators. 21Each regulator is defined using the standard binding for regulators.
13 22
@@ -21,75 +30,113 @@ Example:
21 #gpio-cells = <2>; 30 #gpio-cells = <2>;
22 gpio-controller; 31 gpio-controller;
23 32
33 sm0-supply = <&some_reg>;
34 sm1-supply = <&some_reg>;
35 sm2-supply = <&some_reg>;
36 vinldo01-supply = <...>;
37 vinldo23-supply = <...>;
38 vinldo4-supply = <...>;
39 vinldo678-supply = <...>;
40 vinldo9-supply = <...>;
41
24 regulators { 42 regulators {
25 sm0_reg: sm0 { 43 #address-cells = <1>;
44 #size-cells = <0>;
45
46 sm0_reg: regulator@0 {
47 reg = <0>;
48 regulator-compatible = "sm0";
26 regulator-min-microvolt = < 725000>; 49 regulator-min-microvolt = < 725000>;
27 regulator-max-microvolt = <1500000>; 50 regulator-max-microvolt = <1500000>;
28 regulator-boot-on; 51 regulator-boot-on;
29 regulator-always-on; 52 regulator-always-on;
30 }; 53 };
31 54
32 sm1_reg: sm1 { 55 sm1_reg: regulator@1 {
56 reg = <1>;
57 regulator-compatible = "sm1";
33 regulator-min-microvolt = < 725000>; 58 regulator-min-microvolt = < 725000>;
34 regulator-max-microvolt = <1500000>; 59 regulator-max-microvolt = <1500000>;
35 regulator-boot-on; 60 regulator-boot-on;
36 regulator-always-on; 61 regulator-always-on;
37 }; 62 };
38 63
39 sm2_reg: sm2 { 64 sm2_reg: regulator@2 {
65 reg = <2>;
66 regulator-compatible = "sm2";
40 regulator-min-microvolt = <3000000>; 67 regulator-min-microvolt = <3000000>;
41 regulator-max-microvolt = <4550000>; 68 regulator-max-microvolt = <4550000>;
42 regulator-boot-on; 69 regulator-boot-on;
43 regulator-always-on; 70 regulator-always-on;
44 }; 71 };
45 72
46 ldo0_reg: ldo0 { 73 ldo0_reg: regulator@3 {
74 reg = <3>;
75 regulator-compatible = "ldo0";
47 regulator-name = "PCIE CLK"; 76 regulator-name = "PCIE CLK";
48 regulator-min-microvolt = <3300000>; 77 regulator-min-microvolt = <3300000>;
49 regulator-max-microvolt = <3300000>; 78 regulator-max-microvolt = <3300000>;
50 }; 79 };
51 80
52 ldo1_reg: ldo1 { 81 ldo1_reg: regulator@4 {
82 reg = <4>;
83 regulator-compatible = "ldo1";
53 regulator-min-microvolt = < 725000>; 84 regulator-min-microvolt = < 725000>;
54 regulator-max-microvolt = <1500000>; 85 regulator-max-microvolt = <1500000>;
55 }; 86 };
56 87
57 ldo2_reg: ldo2 { 88 ldo2_reg: regulator@5 {
89 reg = <5>;
90 regulator-compatible = "ldo2";
58 regulator-min-microvolt = < 725000>; 91 regulator-min-microvolt = < 725000>;
59 regulator-max-microvolt = <1500000>; 92 regulator-max-microvolt = <1500000>;
60 }; 93 };
61 94
62 ldo3_reg: ldo3 { 95 ldo3_reg: regulator@6 {
96 reg = <6>;
97 regulator-compatible = "ldo3";
63 regulator-min-microvolt = <1250000>; 98 regulator-min-microvolt = <1250000>;
64 regulator-max-microvolt = <3300000>; 99 regulator-max-microvolt = <3300000>;
65 }; 100 };
66 101
67 ldo4_reg: ldo4 { 102 ldo4_reg: regulator@7 {
103 reg = <7>;
104 regulator-compatible = "ldo4";
68 regulator-min-microvolt = <1700000>; 105 regulator-min-microvolt = <1700000>;
69 regulator-max-microvolt = <2475000>; 106 regulator-max-microvolt = <2475000>;
70 }; 107 };
71 108
72 ldo5_reg: ldo5 { 109 ldo5_reg: regulator@8 {
110 reg = <8>;
111 regulator-compatible = "ldo5";
73 regulator-min-microvolt = <1250000>; 112 regulator-min-microvolt = <1250000>;
74 regulator-max-microvolt = <3300000>; 113 regulator-max-microvolt = <3300000>;
75 }; 114 };
76 115
77 ldo6_reg: ldo6 { 116 ldo6_reg: regulator@9 {
117 reg = <9>;
118 regulator-compatible = "ldo6";
78 regulator-min-microvolt = <1250000>; 119 regulator-min-microvolt = <1250000>;
79 regulator-max-microvolt = <3300000>; 120 regulator-max-microvolt = <3300000>;
80 }; 121 };
81 122
82 ldo7_reg: ldo7 { 123 ldo7_reg: regulator@10 {
124 reg = <10>;
125 regulator-compatible = "ldo7";
83 regulator-min-microvolt = <1250000>; 126 regulator-min-microvolt = <1250000>;
84 regulator-max-microvolt = <3300000>; 127 regulator-max-microvolt = <3300000>;
85 }; 128 };
86 129
87 ldo8_reg: ldo8 { 130 ldo8_reg: regulator@11 {
131 reg = <11>;
132 regulator-compatible = "ldo8";
88 regulator-min-microvolt = <1250000>; 133 regulator-min-microvolt = <1250000>;
89 regulator-max-microvolt = <3300000>; 134 regulator-max-microvolt = <3300000>;
90 }; 135 };
91 136
92 ldo9_reg: ldo9 { 137 ldo9_reg: regulator@12 {
138 reg = <12>;
139 regulator-compatible = "ldo9";
93 regulator-min-microvolt = <1250000>; 140 regulator-min-microvolt = <1250000>;
94 regulator-max-microvolt = <3300000>; 141 regulator-max-microvolt = <3300000>;
95 }; 142 };
diff --git a/Documentation/devicetree/bindings/regulator/twl-regulator.txt b/Documentation/devicetree/bindings/regulator/twl-regulator.txt
index 0c3395d55ac1..658749b90b97 100644
--- a/Documentation/devicetree/bindings/regulator/twl-regulator.txt
+++ b/Documentation/devicetree/bindings/regulator/twl-regulator.txt
@@ -15,7 +15,6 @@ For twl6030 regulators/LDOs
15 - "ti,twl6030-vusb" for VUSB LDO 15 - "ti,twl6030-vusb" for VUSB LDO
16 - "ti,twl6030-v1v8" for V1V8 LDO 16 - "ti,twl6030-v1v8" for V1V8 LDO
17 - "ti,twl6030-v2v1" for V2V1 LDO 17 - "ti,twl6030-v2v1" for V2V1 LDO
18 - "ti,twl6030-clk32kg" for CLK32KG RESOURCE
19 - "ti,twl6030-vdd1" for VDD1 SMPS 18 - "ti,twl6030-vdd1" for VDD1 SMPS
20 - "ti,twl6030-vdd2" for VDD2 SMPS 19 - "ti,twl6030-vdd2" for VDD2 SMPS
21 - "ti,twl6030-vdd3" for VDD3 SMPS 20 - "ti,twl6030-vdd3" for VDD3 SMPS
diff --git a/Documentation/devicetree/bindings/spi/fsl-imx-cspi.txt b/Documentation/devicetree/bindings/spi/fsl-imx-cspi.txt
index 9841057d112b..4256a6df9b79 100644
--- a/Documentation/devicetree/bindings/spi/fsl-imx-cspi.txt
+++ b/Documentation/devicetree/bindings/spi/fsl-imx-cspi.txt
@@ -17,6 +17,6 @@ ecspi@70010000 {
17 reg = <0x70010000 0x4000>; 17 reg = <0x70010000 0x4000>;
18 interrupts = <36>; 18 interrupts = <36>;
19 fsl,spi-num-chipselects = <2>; 19 fsl,spi-num-chipselects = <2>;
20 cs-gpios = <&gpio3 24 0>, /* GPIO4_24 */ 20 cs-gpios = <&gpio3 24 0>, /* GPIO3_24 */
21 <&gpio3 25 0>; /* GPIO4_25 */ 21 <&gpio3 25 0>; /* GPIO3_25 */
22}; 22};
diff --git a/Documentation/devicetree/bindings/vendor-prefixes.txt b/Documentation/devicetree/bindings/vendor-prefixes.txt
index 6eab91747a86..db4d3af3643c 100644
--- a/Documentation/devicetree/bindings/vendor-prefixes.txt
+++ b/Documentation/devicetree/bindings/vendor-prefixes.txt
@@ -3,6 +3,7 @@ Device tree binding vendor prefix registry. Keep list in alphabetical order.
3This isn't an exhaustive list, but you should add new prefixes to it before 3This isn't an exhaustive list, but you should add new prefixes to it before
4using them to avoid name-space collisions. 4using them to avoid name-space collisions.
5 5
6ad Avionic Design GmbH
6adi Analog Devices, Inc. 7adi Analog Devices, Inc.
7amcc Applied Micro Circuits Corporation (APM, formally AMCC) 8amcc Applied Micro Circuits Corporation (APM, formally AMCC)
8apm Applied Micro Circuits Corporation (APM) 9apm Applied Micro Circuits Corporation (APM)
diff --git a/Documentation/prctl/no_new_privs.txt b/Documentation/prctl/no_new_privs.txt
new file mode 100644
index 000000000000..f7be84fba910
--- /dev/null
+++ b/Documentation/prctl/no_new_privs.txt
@@ -0,0 +1,57 @@
1The execve system call can grant a newly-started program privileges that
2its parent did not have. The most obvious examples are setuid/setgid
3programs and file capabilities. To prevent the parent program from
4gaining these privileges as well, the kernel and user code must be
5careful to prevent the parent from doing anything that could subvert the
6child. For example:
7
8 - The dynamic loader handles LD_* environment variables differently if
9 a program is setuid.
10
11 - chroot is disallowed to unprivileged processes, since it would allow
12 /etc/passwd to be replaced from the point of view of a process that
13 inherited chroot.
14
15 - The exec code has special handling for ptrace.
16
17These are all ad-hoc fixes. The no_new_privs bit (since Linux 3.5) is a
18new, generic mechanism to make it safe for a process to modify its
19execution environment in a manner that persists across execve. Any task
20can set no_new_privs. Once the bit is set, it is inherited across fork,
21clone, and execve and cannot be unset. With no_new_privs set, execve
22promises not to grant the privilege to do anything that could not have
23been done without the execve call. For example, the setuid and setgid
24bits will no longer change the uid or gid; file capabilities will not
25add to the permitted set, and LSMs will not relax constraints after
26execve.
27
28To set no_new_privs, use prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0).
29
30Be careful, though: LSMs might also not tighten constraints on exec
31in no_new_privs mode. (This means that setting up a general-purpose
32service launcher to set no_new_privs before execing daemons may
33interfere with LSM-based sandboxing.)
34
35Note that no_new_privs does not prevent privilege changes that do not
36involve execve. An appropriately privileged task can still call
37setuid(2) and receive SCM_RIGHTS datagrams.
38
39There are two main use cases for no_new_privs so far:
40
41 - Filters installed for the seccomp mode 2 sandbox persist across
42 execve and can change the behavior of newly-executed programs.
43 Unprivileged users are therefore only allowed to install such filters
44 if no_new_privs is set.
45
46 - By itself, no_new_privs can be used to reduce the attack surface
47 available to an unprivileged user. If everything running with a
48 given uid has no_new_privs set, then that uid will be unable to
49 escalate its privileges by directly attacking setuid, setgid, and
50 fcap-using binaries; it will need to compromise something without the
51 no_new_privs bit set first.
52
53In the future, other potentially dangerous kernel features could become
54available to unprivileged tasks if no_new_privs is set. In principle,
55several options to unshare(2) and clone(2) would be safe when
56no_new_privs is set, and no_new_privs + chroot is considerable less
57dangerous than chroot by itself.
diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/kvm/api.txt
index 930126698a0f..2c9948379469 100644
--- a/Documentation/virtual/kvm/api.txt
+++ b/Documentation/virtual/kvm/api.txt
@@ -1930,6 +1930,23 @@ The "pte_enc" field provides a value that can OR'ed into the hash
1930PTE's RPN field (ie, it needs to be shifted left by 12 to OR it 1930PTE's RPN field (ie, it needs to be shifted left by 12 to OR it
1931into the hash PTE second double word). 1931into the hash PTE second double word).
1932 1932
19334.75 KVM_IRQFD
1934
1935Capability: KVM_CAP_IRQFD
1936Architectures: x86
1937Type: vm ioctl
1938Parameters: struct kvm_irqfd (in)
1939Returns: 0 on success, -1 on error
1940
1941Allows setting an eventfd to directly trigger a guest interrupt.
1942kvm_irqfd.fd specifies the file descriptor to use as the eventfd and
1943kvm_irqfd.gsi specifies the irqchip pin toggled by this event. When
1944an event is tiggered on the eventfd, an interrupt is injected into
1945the guest using the specified gsi pin. The irqfd is removed using
1946the KVM_IRQFD_FLAG_DEASSIGN flag, specifying both kvm_irqfd.fd
1947and kvm_irqfd.gsi.
1948
1949
19335. The kvm_run structure 19505. The kvm_run structure
1934------------------------ 1951------------------------
1935 1952
diff --git a/MAINTAINERS b/MAINTAINERS
index eb22272b2116..1b71f6ceae0a 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4654,8 +4654,8 @@ L: netfilter@vger.kernel.org
4654L: coreteam@netfilter.org 4654L: coreteam@netfilter.org
4655W: http://www.netfilter.org/ 4655W: http://www.netfilter.org/
4656W: http://www.iptables.org/ 4656W: http://www.iptables.org/
4657T: git git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf-2.6.git 4657T: git git://1984.lsi.us.es/nf
4658T: git git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf-next-2.6.git 4658T: git git://1984.lsi.us.es/nf-next
4659S: Supported 4659S: Supported
4660F: include/linux/netfilter* 4660F: include/linux/netfilter*
4661F: include/linux/netfilter/ 4661F: include/linux/netfilter/
@@ -4857,6 +4857,7 @@ M: Kevin Hilman <khilman@ti.com>
4857L: linux-omap@vger.kernel.org 4857L: linux-omap@vger.kernel.org
4858S: Maintained 4858S: Maintained
4859F: arch/arm/*omap*/*pm* 4859F: arch/arm/*omap*/*pm*
4860F: drivers/cpufreq/omap-cpufreq.c
4860 4861
4861OMAP POWERDOMAIN/CLOCKDOMAIN SOC ADAPTATION LAYER SUPPORT 4862OMAP POWERDOMAIN/CLOCKDOMAIN SOC ADAPTATION LAYER SUPPORT
4862M: Rajendra Nayak <rnayak@ti.com> 4863M: Rajendra Nayak <rnayak@ti.com>
@@ -5909,7 +5910,7 @@ M: Ingo Molnar <mingo@redhat.com>
5909M: Peter Zijlstra <peterz@infradead.org> 5910M: Peter Zijlstra <peterz@infradead.org>
5910T: git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git sched/core 5911T: git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git sched/core
5911S: Maintained 5912S: Maintained
5912F: kernel/sched* 5913F: kernel/sched/
5913F: include/linux/sched.h 5914F: include/linux/sched.h
5914 5915
5915SCORE ARCHITECTURE 5916SCORE ARCHITECTURE
diff --git a/Makefile b/Makefile
index 81ea15450049..aa8e315f26ef 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
1VERSION = 3 1VERSION = 3
2PATCHLEVEL = 5 2PATCHLEVEL = 5
3SUBLEVEL = 0 3SUBLEVEL = 0
4EXTRAVERSION = -rc5 4EXTRAVERSION = -rc7
5NAME = Saber-toothed Squirrel 5NAME = Saber-toothed Squirrel
6 6
7# *DOCUMENTATION* 7# *DOCUMENTATION*
diff --git a/arch/arm/boot/dts/db8500.dtsi b/arch/arm/boot/dts/db8500.dtsi
index 4ad5160018cb..ec2be92b270d 100644
--- a/arch/arm/boot/dts/db8500.dtsi
+++ b/arch/arm/boot/dts/db8500.dtsi
@@ -206,62 +206,74 @@
206 206
207 // DB8500_REGULATOR_VAPE 207 // DB8500_REGULATOR_VAPE
208 db8500_vape_reg: db8500_vape { 208 db8500_vape_reg: db8500_vape {
209 regulator-compatible = "db8500_vape";
209 regulator-name = "db8500-vape"; 210 regulator-name = "db8500-vape";
210 regulator-always-on; 211 regulator-always-on;
211 }; 212 };
212 213
213 // DB8500_REGULATOR_VARM 214 // DB8500_REGULATOR_VARM
214 db8500_varm_reg: db8500_varm { 215 db8500_varm_reg: db8500_varm {
216 regulator-compatible = "db8500_varm";
215 regulator-name = "db8500-varm"; 217 regulator-name = "db8500-varm";
216 }; 218 };
217 219
218 // DB8500_REGULATOR_VMODEM 220 // DB8500_REGULATOR_VMODEM
219 db8500_vmodem_reg: db8500_vmodem { 221 db8500_vmodem_reg: db8500_vmodem {
222 regulator-compatible = "db8500_vmodem";
220 regulator-name = "db8500-vmodem"; 223 regulator-name = "db8500-vmodem";
221 }; 224 };
222 225
223 // DB8500_REGULATOR_VPLL 226 // DB8500_REGULATOR_VPLL
224 db8500_vpll_reg: db8500_vpll { 227 db8500_vpll_reg: db8500_vpll {
228 regulator-compatible = "db8500_vpll";
225 regulator-name = "db8500-vpll"; 229 regulator-name = "db8500-vpll";
226 }; 230 };
227 231
228 // DB8500_REGULATOR_VSMPS1 232 // DB8500_REGULATOR_VSMPS1
229 db8500_vsmps1_reg: db8500_vsmps1 { 233 db8500_vsmps1_reg: db8500_vsmps1 {
234 regulator-compatible = "db8500_vsmps1";
230 regulator-name = "db8500-vsmps1"; 235 regulator-name = "db8500-vsmps1";
231 }; 236 };
232 237
233 // DB8500_REGULATOR_VSMPS2 238 // DB8500_REGULATOR_VSMPS2
234 db8500_vsmps2_reg: db8500_vsmps2 { 239 db8500_vsmps2_reg: db8500_vsmps2 {
240 regulator-compatible = "db8500_vsmps2";
235 regulator-name = "db8500-vsmps2"; 241 regulator-name = "db8500-vsmps2";
236 }; 242 };
237 243
238 // DB8500_REGULATOR_VSMPS3 244 // DB8500_REGULATOR_VSMPS3
239 db8500_vsmps3_reg: db8500_vsmps3 { 245 db8500_vsmps3_reg: db8500_vsmps3 {
246 regulator-compatible = "db8500_vsmps3";
240 regulator-name = "db8500-vsmps3"; 247 regulator-name = "db8500-vsmps3";
241 }; 248 };
242 249
243 // DB8500_REGULATOR_VRF1 250 // DB8500_REGULATOR_VRF1
244 db8500_vrf1_reg: db8500_vrf1 { 251 db8500_vrf1_reg: db8500_vrf1 {
252 regulator-compatible = "db8500_vrf1";
245 regulator-name = "db8500-vrf1"; 253 regulator-name = "db8500-vrf1";
246 }; 254 };
247 255
248 // DB8500_REGULATOR_SWITCH_SVAMMDSP 256 // DB8500_REGULATOR_SWITCH_SVAMMDSP
249 db8500_sva_mmdsp_reg: db8500_sva_mmdsp { 257 db8500_sva_mmdsp_reg: db8500_sva_mmdsp {
258 regulator-compatible = "db8500_sva_mmdsp";
250 regulator-name = "db8500-sva-mmdsp"; 259 regulator-name = "db8500-sva-mmdsp";
251 }; 260 };
252 261
253 // DB8500_REGULATOR_SWITCH_SVAMMDSPRET 262 // DB8500_REGULATOR_SWITCH_SVAMMDSPRET
254 db8500_sva_mmdsp_ret_reg: db8500_sva_mmdsp_ret { 263 db8500_sva_mmdsp_ret_reg: db8500_sva_mmdsp_ret {
264 regulator-compatible = "db8500_sva_mmdsp_ret";
255 regulator-name = "db8500-sva-mmdsp-ret"; 265 regulator-name = "db8500-sva-mmdsp-ret";
256 }; 266 };
257 267
258 // DB8500_REGULATOR_SWITCH_SVAPIPE 268 // DB8500_REGULATOR_SWITCH_SVAPIPE
259 db8500_sva_pipe_reg: db8500_sva_pipe { 269 db8500_sva_pipe_reg: db8500_sva_pipe {
270 regulator-compatible = "db8500_sva_pipe";
260 regulator-name = "db8500_sva_pipe"; 271 regulator-name = "db8500_sva_pipe";
261 }; 272 };
262 273
263 // DB8500_REGULATOR_SWITCH_SIAMMDSP 274 // DB8500_REGULATOR_SWITCH_SIAMMDSP
264 db8500_sia_mmdsp_reg: db8500_sia_mmdsp { 275 db8500_sia_mmdsp_reg: db8500_sia_mmdsp {
276 regulator-compatible = "db8500_sia_mmdsp";
265 regulator-name = "db8500_sia_mmdsp"; 277 regulator-name = "db8500_sia_mmdsp";
266 }; 278 };
267 279
@@ -272,38 +284,45 @@
272 284
273 // DB8500_REGULATOR_SWITCH_SIAPIPE 285 // DB8500_REGULATOR_SWITCH_SIAPIPE
274 db8500_sia_pipe_reg: db8500_sia_pipe { 286 db8500_sia_pipe_reg: db8500_sia_pipe {
287 regulator-compatible = "db8500_sia_pipe";
275 regulator-name = "db8500-sia-pipe"; 288 regulator-name = "db8500-sia-pipe";
276 }; 289 };
277 290
278 // DB8500_REGULATOR_SWITCH_SGA 291 // DB8500_REGULATOR_SWITCH_SGA
279 db8500_sga_reg: db8500_sga { 292 db8500_sga_reg: db8500_sga {
293 regulator-compatible = "db8500_sga";
280 regulator-name = "db8500-sga"; 294 regulator-name = "db8500-sga";
281 vin-supply = <&db8500_vape_reg>; 295 vin-supply = <&db8500_vape_reg>;
282 }; 296 };
283 297
284 // DB8500_REGULATOR_SWITCH_B2R2_MCDE 298 // DB8500_REGULATOR_SWITCH_B2R2_MCDE
285 db8500_b2r2_mcde_reg: db8500_b2r2_mcde { 299 db8500_b2r2_mcde_reg: db8500_b2r2_mcde {
300 regulator-compatible = "db8500_b2r2_mcde";
286 regulator-name = "db8500-b2r2-mcde"; 301 regulator-name = "db8500-b2r2-mcde";
287 vin-supply = <&db8500_vape_reg>; 302 vin-supply = <&db8500_vape_reg>;
288 }; 303 };
289 304
290 // DB8500_REGULATOR_SWITCH_ESRAM12 305 // DB8500_REGULATOR_SWITCH_ESRAM12
291 db8500_esram12_reg: db8500_esram12 { 306 db8500_esram12_reg: db8500_esram12 {
307 regulator-compatible = "db8500_esram12";
292 regulator-name = "db8500-esram12"; 308 regulator-name = "db8500-esram12";
293 }; 309 };
294 310
295 // DB8500_REGULATOR_SWITCH_ESRAM12RET 311 // DB8500_REGULATOR_SWITCH_ESRAM12RET
296 db8500_esram12_ret_reg: db8500_esram12_ret { 312 db8500_esram12_ret_reg: db8500_esram12_ret {
313 regulator-compatible = "db8500_esram12_ret";
297 regulator-name = "db8500-esram12-ret"; 314 regulator-name = "db8500-esram12-ret";
298 }; 315 };
299 316
300 // DB8500_REGULATOR_SWITCH_ESRAM34 317 // DB8500_REGULATOR_SWITCH_ESRAM34
301 db8500_esram34_reg: db8500_esram34 { 318 db8500_esram34_reg: db8500_esram34 {
319 regulator-compatible = "db8500_esram34";
302 regulator-name = "db8500-esram34"; 320 regulator-name = "db8500-esram34";
303 }; 321 };
304 322
305 // DB8500_REGULATOR_SWITCH_ESRAM34RET 323 // DB8500_REGULATOR_SWITCH_ESRAM34RET
306 db8500_esram34_ret_reg: db8500_esram34_ret { 324 db8500_esram34_ret_reg: db8500_esram34_ret {
325 regulator-compatible = "db8500_esram34_ret";
307 regulator-name = "db8500-esram34-ret"; 326 regulator-name = "db8500-esram34-ret";
308 }; 327 };
309 }; 328 };
@@ -318,6 +337,7 @@
318 337
319 // supplies to the display/camera 338 // supplies to the display/camera
320 ab8500_ldo_aux1_reg: ab8500_ldo_aux1 { 339 ab8500_ldo_aux1_reg: ab8500_ldo_aux1 {
340 regulator-compatible = "ab8500_ldo_aux1";
321 regulator-name = "V-DISPLAY"; 341 regulator-name = "V-DISPLAY";
322 regulator-min-microvolt = <2500000>; 342 regulator-min-microvolt = <2500000>;
323 regulator-max-microvolt = <2900000>; 343 regulator-max-microvolt = <2900000>;
@@ -328,6 +348,7 @@
328 348
329 // supplies to the on-board eMMC 349 // supplies to the on-board eMMC
330 ab8500_ldo_aux2_reg: ab8500_ldo_aux2 { 350 ab8500_ldo_aux2_reg: ab8500_ldo_aux2 {
351 regulator-compatible = "ab8500_ldo_aux2";
331 regulator-name = "V-eMMC1"; 352 regulator-name = "V-eMMC1";
332 regulator-min-microvolt = <1100000>; 353 regulator-min-microvolt = <1100000>;
333 regulator-max-microvolt = <3300000>; 354 regulator-max-microvolt = <3300000>;
@@ -335,6 +356,7 @@
335 356
336 // supply for VAUX3; SDcard slots 357 // supply for VAUX3; SDcard slots
337 ab8500_ldo_aux3_reg: ab8500_ldo_aux3 { 358 ab8500_ldo_aux3_reg: ab8500_ldo_aux3 {
359 regulator-compatible = "ab8500_ldo_aux3";
338 regulator-name = "V-MMC-SD"; 360 regulator-name = "V-MMC-SD";
339 regulator-min-microvolt = <1100000>; 361 regulator-min-microvolt = <1100000>;
340 regulator-max-microvolt = <3300000>; 362 regulator-max-microvolt = <3300000>;
@@ -342,41 +364,49 @@
342 364
343 // supply for v-intcore12; VINTCORE12 LDO 365 // supply for v-intcore12; VINTCORE12 LDO
344 ab8500_ldo_initcore_reg: ab8500_ldo_initcore { 366 ab8500_ldo_initcore_reg: ab8500_ldo_initcore {
367 regulator-compatible = "ab8500_ldo_initcore";
345 regulator-name = "V-INTCORE"; 368 regulator-name = "V-INTCORE";
346 }; 369 };
347 370
348 // supply for tvout; gpadc; TVOUT LDO 371 // supply for tvout; gpadc; TVOUT LDO
349 ab8500_ldo_tvout_reg: ab8500_ldo_tvout { 372 ab8500_ldo_tvout_reg: ab8500_ldo_tvout {
373 regulator-compatible = "ab8500_ldo_tvout";
350 regulator-name = "V-TVOUT"; 374 regulator-name = "V-TVOUT";
351 }; 375 };
352 376
353 // supply for ab8500-usb; USB LDO 377 // supply for ab8500-usb; USB LDO
354 ab8500_ldo_usb_reg: ab8500_ldo_usb { 378 ab8500_ldo_usb_reg: ab8500_ldo_usb {
379 regulator-compatible = "ab8500_ldo_usb";
355 regulator-name = "dummy"; 380 regulator-name = "dummy";
356 }; 381 };
357 382
358 // supply for ab8500-vaudio; VAUDIO LDO 383 // supply for ab8500-vaudio; VAUDIO LDO
359 ab8500_ldo_audio_reg: ab8500_ldo_audio { 384 ab8500_ldo_audio_reg: ab8500_ldo_audio {
385 regulator-compatible = "ab8500_ldo_audio";
360 regulator-name = "V-AUD"; 386 regulator-name = "V-AUD";
361 }; 387 };
362 388
363 // supply for v-anamic1 VAMic1-LDO 389 // supply for v-anamic1 VAMic1-LDO
364 ab8500_ldo_anamic1_reg: ab8500_ldo_anamic1 { 390 ab8500_ldo_anamic1_reg: ab8500_ldo_anamic1 {
391 regulator-compatible = "ab8500_ldo_anamic1";
365 regulator-name = "V-AMIC1"; 392 regulator-name = "V-AMIC1";
366 }; 393 };
367 394
368 // supply for v-amic2; VAMIC2 LDO; reuse constants for AMIC1 395 // supply for v-amic2; VAMIC2 LDO; reuse constants for AMIC1
369 ab8500_ldo_amamic2_reg: ab8500_ldo_amamic2 { 396 ab8500_ldo_amamic2_reg: ab8500_ldo_amamic2 {
397 regulator-compatible = "ab8500_ldo_amamic2";
370 regulator-name = "V-AMIC2"; 398 regulator-name = "V-AMIC2";
371 }; 399 };
372 400
373 // supply for v-dmic; VDMIC LDO 401 // supply for v-dmic; VDMIC LDO
374 ab8500_ldo_dmic_reg: ab8500_ldo_dmic { 402 ab8500_ldo_dmic_reg: ab8500_ldo_dmic {
403 regulator-compatible = "ab8500_ldo_dmic";
375 regulator-name = "V-DMIC"; 404 regulator-name = "V-DMIC";
376 }; 405 };
377 406
378 // supply for U8500 CSI/DSI; VANA LDO 407 // supply for U8500 CSI/DSI; VANA LDO
379 ab8500_ldo_ana_reg: ab8500_ldo_ana { 408 ab8500_ldo_ana_reg: ab8500_ldo_ana {
409 regulator-compatible = "ab8500_ldo_ana";
380 regulator-name = "V-CSI/DSI"; 410 regulator-name = "V-CSI/DSI";
381 }; 411 };
382 }; 412 };
diff --git a/arch/arm/configs/omap2plus_defconfig b/arch/arm/configs/omap2plus_defconfig
index 9854ff4279e0..11828e632532 100644
--- a/arch/arm/configs/omap2plus_defconfig
+++ b/arch/arm/configs/omap2plus_defconfig
@@ -176,7 +176,6 @@ CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
176CONFIG_USB_DEVICEFS=y 176CONFIG_USB_DEVICEFS=y
177CONFIG_USB_SUSPEND=y 177CONFIG_USB_SUSPEND=y
178CONFIG_USB_MON=y 178CONFIG_USB_MON=y
179CONFIG_USB_EHCI_HCD=y
180CONFIG_USB_WDM=y 179CONFIG_USB_WDM=y
181CONFIG_USB_STORAGE=y 180CONFIG_USB_STORAGE=y
182CONFIG_USB_LIBUSUAL=y 181CONFIG_USB_LIBUSUAL=y
diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
index 68374ba6a943..c79f61faa3a5 100644
--- a/arch/arm/include/asm/atomic.h
+++ b/arch/arm/include/asm/atomic.h
@@ -243,7 +243,7 @@ typedef struct {
243 243
244#define ATOMIC64_INIT(i) { (i) } 244#define ATOMIC64_INIT(i) { (i) }
245 245
246static inline u64 atomic64_read(atomic64_t *v) 246static inline u64 atomic64_read(const atomic64_t *v)
247{ 247{
248 u64 result; 248 u64 result;
249 249
diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
index 3d2220498abc..6ddbe446425e 100644
--- a/arch/arm/include/asm/domain.h
+++ b/arch/arm/include/asm/domain.h
@@ -60,13 +60,13 @@
60#ifndef __ASSEMBLY__ 60#ifndef __ASSEMBLY__
61 61
62#ifdef CONFIG_CPU_USE_DOMAINS 62#ifdef CONFIG_CPU_USE_DOMAINS
63#define set_domain(x) \ 63static inline void set_domain(unsigned val)
64 do { \ 64{
65 __asm__ __volatile__( \ 65 asm volatile(
66 "mcr p15, 0, %0, c3, c0 @ set domain" \ 66 "mcr p15, 0, %0, c3, c0 @ set domain"
67 : : "r" (x)); \ 67 : : "r" (val));
68 isb(); \ 68 isb();
69 } while (0) 69}
70 70
71#define modify_domain(dom,type) \ 71#define modify_domain(dom,type) \
72 do { \ 72 do { \
@@ -78,8 +78,8 @@
78 } while (0) 78 } while (0)
79 79
80#else 80#else
81#define set_domain(x) do { } while (0) 81static inline void set_domain(unsigned val) { }
82#define modify_domain(dom,type) do { } while (0) 82static inline void modify_domain(unsigned dom, unsigned type) { }
83#endif 83#endif
84 84
85/* 85/*
diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
index b79f8e97f775..af7b0bda3355 100644
--- a/arch/arm/include/asm/thread_info.h
+++ b/arch/arm/include/asm/thread_info.h
@@ -148,7 +148,6 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
148#define TIF_NOTIFY_RESUME 2 /* callback before returning to user */ 148#define TIF_NOTIFY_RESUME 2 /* callback before returning to user */
149#define TIF_SYSCALL_TRACE 8 149#define TIF_SYSCALL_TRACE 8
150#define TIF_SYSCALL_AUDIT 9 150#define TIF_SYSCALL_AUDIT 9
151#define TIF_SYSCALL_RESTARTSYS 10
152#define TIF_POLLING_NRFLAG 16 151#define TIF_POLLING_NRFLAG 16
153#define TIF_USING_IWMMXT 17 152#define TIF_USING_IWMMXT 17
154#define TIF_MEMDIE 18 /* is terminating due to OOM killer */ 153#define TIF_MEMDIE 18 /* is terminating due to OOM killer */
@@ -164,11 +163,9 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
164#define _TIF_POLLING_NRFLAG (1 << TIF_POLLING_NRFLAG) 163#define _TIF_POLLING_NRFLAG (1 << TIF_POLLING_NRFLAG)
165#define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT) 164#define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
166#define _TIF_SECCOMP (1 << TIF_SECCOMP) 165#define _TIF_SECCOMP (1 << TIF_SECCOMP)
167#define _TIF_SYSCALL_RESTARTSYS (1 << TIF_SYSCALL_RESTARTSYS)
168 166
169/* Checks for any syscall work in entry-common.S */ 167/* Checks for any syscall work in entry-common.S */
170#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \ 168#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
171 _TIF_SYSCALL_RESTARTSYS)
172 169
173/* 170/*
174 * Change these and you break ASM code in entry-common.S 171 * Change these and you break ASM code in entry-common.S
diff --git a/arch/arm/kernel/kprobes-test-arm.c b/arch/arm/kernel/kprobes-test-arm.c
index ba32b393b3f0..38c1a3b103a0 100644
--- a/arch/arm/kernel/kprobes-test-arm.c
+++ b/arch/arm/kernel/kprobes-test-arm.c
@@ -187,8 +187,8 @@ void kprobe_arm_test_cases(void)
187 TEST_BF_R ("mov pc, r",0,2f,"") 187 TEST_BF_R ("mov pc, r",0,2f,"")
188 TEST_BF_RR("mov pc, r",0,2f,", asl r",1,0,"") 188 TEST_BF_RR("mov pc, r",0,2f,", asl r",1,0,"")
189 TEST_BB( "sub pc, pc, #1b-2b+8") 189 TEST_BB( "sub pc, pc, #1b-2b+8")
190#if __LINUX_ARM_ARCH__ >= 6 190#if __LINUX_ARM_ARCH__ == 6 && !defined(CONFIG_CPU_V7)
191 TEST_BB( "sub pc, pc, #1b-2b+8-2") /* UNPREDICTABLE before ARMv6 */ 191 TEST_BB( "sub pc, pc, #1b-2b+8-2") /* UNPREDICTABLE before and after ARMv6 */
192#endif 192#endif
193 TEST_BB_R( "sub pc, pc, r",14, 1f-2f+8,"") 193 TEST_BB_R( "sub pc, pc, r",14, 1f-2f+8,"")
194 TEST_BB_R( "rsb pc, r",14,1f-2f+8,", pc") 194 TEST_BB_R( "rsb pc, r",14,1f-2f+8,", pc")
diff --git a/arch/arm/kernel/perf_event.c b/arch/arm/kernel/perf_event.c
index 186c8cb982c5..a02eada3aa5d 100644
--- a/arch/arm/kernel/perf_event.c
+++ b/arch/arm/kernel/perf_event.c
@@ -503,7 +503,7 @@ __hw_perf_event_init(struct perf_event *event)
503 event_requires_mode_exclusion(&event->attr)) { 503 event_requires_mode_exclusion(&event->attr)) {
504 pr_debug("ARM performance counters do not support " 504 pr_debug("ARM performance counters do not support "
505 "mode exclusion\n"); 505 "mode exclusion\n");
506 return -EPERM; 506 return -EOPNOTSUPP;
507 } 507 }
508 508
509 /* 509 /*
diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
index 5700a7ae7f0b..14e38261cd31 100644
--- a/arch/arm/kernel/ptrace.c
+++ b/arch/arm/kernel/ptrace.c
@@ -25,7 +25,6 @@
25#include <linux/regset.h> 25#include <linux/regset.h>
26#include <linux/audit.h> 26#include <linux/audit.h>
27#include <linux/tracehook.h> 27#include <linux/tracehook.h>
28#include <linux/unistd.h>
29 28
30#include <asm/pgtable.h> 29#include <asm/pgtable.h>
31#include <asm/traps.h> 30#include <asm/traps.h>
@@ -918,8 +917,6 @@ asmlinkage int syscall_trace(int why, struct pt_regs *regs, int scno)
918 audit_syscall_entry(AUDIT_ARCH_ARM, scno, regs->ARM_r0, 917 audit_syscall_entry(AUDIT_ARCH_ARM, scno, regs->ARM_r0,
919 regs->ARM_r1, regs->ARM_r2, regs->ARM_r3); 918 regs->ARM_r1, regs->ARM_r2, regs->ARM_r3);
920 919
921 if (why == 0 && test_and_clear_thread_flag(TIF_SYSCALL_RESTARTSYS))
922 scno = __NR_restart_syscall - __NR_SYSCALL_BASE;
923 if (!test_thread_flag(TIF_SYSCALL_TRACE)) 920 if (!test_thread_flag(TIF_SYSCALL_TRACE))
924 return scno; 921 return scno;
925 922
diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
index fd2392a17ac1..536c5d6b340b 100644
--- a/arch/arm/kernel/signal.c
+++ b/arch/arm/kernel/signal.c
@@ -27,6 +27,7 @@
27 */ 27 */
28#define SWI_SYS_SIGRETURN (0xef000000|(__NR_sigreturn)|(__NR_OABI_SYSCALL_BASE)) 28#define SWI_SYS_SIGRETURN (0xef000000|(__NR_sigreturn)|(__NR_OABI_SYSCALL_BASE))
29#define SWI_SYS_RT_SIGRETURN (0xef000000|(__NR_rt_sigreturn)|(__NR_OABI_SYSCALL_BASE)) 29#define SWI_SYS_RT_SIGRETURN (0xef000000|(__NR_rt_sigreturn)|(__NR_OABI_SYSCALL_BASE))
30#define SWI_SYS_RESTART (0xef000000|__NR_restart_syscall|__NR_OABI_SYSCALL_BASE)
30 31
31/* 32/*
32 * With EABI, the syscall number has to be loaded into r7. 33 * With EABI, the syscall number has to be loaded into r7.
@@ -47,6 +48,18 @@ const unsigned long sigreturn_codes[7] = {
47}; 48};
48 49
49/* 50/*
51 * Either we support OABI only, or we have EABI with the OABI
52 * compat layer enabled. In the later case we don't know if
53 * user space is EABI or not, and if not we must not clobber r7.
54 * Always using the OABI syscall solves that issue and works for
55 * all those cases.
56 */
57const unsigned long syscall_restart_code[2] = {
58 SWI_SYS_RESTART, /* swi __NR_restart_syscall */
59 0xe49df004, /* ldr pc, [sp], #4 */
60};
61
62/*
50 * atomically swap in the new signal mask, and wait for a signal. 63 * atomically swap in the new signal mask, and wait for a signal.
51 */ 64 */
52asmlinkage int sys_sigsuspend(int restart, unsigned long oldmask, old_sigset_t mask) 65asmlinkage int sys_sigsuspend(int restart, unsigned long oldmask, old_sigset_t mask)
@@ -592,10 +605,12 @@ static void do_signal(struct pt_regs *regs, int syscall)
592 case -ERESTARTNOHAND: 605 case -ERESTARTNOHAND:
593 case -ERESTARTSYS: 606 case -ERESTARTSYS:
594 case -ERESTARTNOINTR: 607 case -ERESTARTNOINTR:
595 case -ERESTART_RESTARTBLOCK:
596 regs->ARM_r0 = regs->ARM_ORIG_r0; 608 regs->ARM_r0 = regs->ARM_ORIG_r0;
597 regs->ARM_pc = restart_addr; 609 regs->ARM_pc = restart_addr;
598 break; 610 break;
611 case -ERESTART_RESTARTBLOCK:
612 regs->ARM_r0 = -EINTR;
613 break;
599 } 614 }
600 } 615 }
601 616
@@ -611,14 +626,12 @@ static void do_signal(struct pt_regs *regs, int syscall)
611 * debugger has chosen to restart at a different PC. 626 * debugger has chosen to restart at a different PC.
612 */ 627 */
613 if (regs->ARM_pc == restart_addr) { 628 if (regs->ARM_pc == restart_addr) {
614 if (retval == -ERESTARTNOHAND || 629 if (retval == -ERESTARTNOHAND
615 retval == -ERESTART_RESTARTBLOCK
616 || (retval == -ERESTARTSYS 630 || (retval == -ERESTARTSYS
617 && !(ka.sa.sa_flags & SA_RESTART))) { 631 && !(ka.sa.sa_flags & SA_RESTART))) {
618 regs->ARM_r0 = -EINTR; 632 regs->ARM_r0 = -EINTR;
619 regs->ARM_pc = continue_addr; 633 regs->ARM_pc = continue_addr;
620 } 634 }
621 clear_thread_flag(TIF_SYSCALL_RESTARTSYS);
622 } 635 }
623 636
624 handle_signal(signr, &ka, &info, regs); 637 handle_signal(signr, &ka, &info, regs);
@@ -632,8 +645,29 @@ static void do_signal(struct pt_regs *regs, int syscall)
632 * ignore the restart. 645 * ignore the restart.
633 */ 646 */
634 if (retval == -ERESTART_RESTARTBLOCK 647 if (retval == -ERESTART_RESTARTBLOCK
635 && regs->ARM_pc == restart_addr) 648 && regs->ARM_pc == continue_addr) {
636 set_thread_flag(TIF_SYSCALL_RESTARTSYS); 649 if (thumb_mode(regs)) {
650 regs->ARM_r7 = __NR_restart_syscall - __NR_SYSCALL_BASE;
651 regs->ARM_pc -= 2;
652 } else {
653#if defined(CONFIG_AEABI) && !defined(CONFIG_OABI_COMPAT)
654 regs->ARM_r7 = __NR_restart_syscall;
655 regs->ARM_pc -= 4;
656#else
657 u32 __user *usp;
658
659 regs->ARM_sp -= 4;
660 usp = (u32 __user *)regs->ARM_sp;
661
662 if (put_user(regs->ARM_pc, usp) == 0) {
663 regs->ARM_pc = KERN_RESTART_CODE;
664 } else {
665 regs->ARM_sp += 4;
666 force_sigsegv(0, current);
667 }
668#endif
669 }
670 }
637 } 671 }
638 672
639 restore_saved_sigmask(); 673 restore_saved_sigmask();
diff --git a/arch/arm/kernel/signal.h b/arch/arm/kernel/signal.h
index 5ff067b7c752..6fcfe8398aa4 100644
--- a/arch/arm/kernel/signal.h
+++ b/arch/arm/kernel/signal.h
@@ -8,5 +8,7 @@
8 * published by the Free Software Foundation. 8 * published by the Free Software Foundation.
9 */ 9 */
10#define KERN_SIGRETURN_CODE (CONFIG_VECTORS_BASE + 0x00000500) 10#define KERN_SIGRETURN_CODE (CONFIG_VECTORS_BASE + 0x00000500)
11#define KERN_RESTART_CODE (KERN_SIGRETURN_CODE + sizeof(sigreturn_codes))
11 12
12extern const unsigned long sigreturn_codes[7]; 13extern const unsigned long sigreturn_codes[7];
14extern const unsigned long syscall_restart_code[2];
diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
index 4928d89758f4..3647170e9a16 100644
--- a/arch/arm/kernel/traps.c
+++ b/arch/arm/kernel/traps.c
@@ -820,6 +820,8 @@ void __init early_trap_init(void *vectors_base)
820 */ 820 */
821 memcpy((void *)(vectors + KERN_SIGRETURN_CODE - CONFIG_VECTORS_BASE), 821 memcpy((void *)(vectors + KERN_SIGRETURN_CODE - CONFIG_VECTORS_BASE),
822 sigreturn_codes, sizeof(sigreturn_codes)); 822 sigreturn_codes, sizeof(sigreturn_codes));
823 memcpy((void *)(vectors + KERN_RESTART_CODE - CONFIG_VECTORS_BASE),
824 syscall_restart_code, sizeof(syscall_restart_code));
823 825
824 flush_icache_range(vectors, vectors + PAGE_SIZE); 826 flush_icache_range(vectors, vectors + PAGE_SIZE);
825 modify_domain(DOMAIN_USER, DOMAIN_CLIENT); 827 modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
index 43a31fb06318..36ff15bbfdd4 100644
--- a/arch/arm/kernel/vmlinux.lds.S
+++ b/arch/arm/kernel/vmlinux.lds.S
@@ -183,7 +183,9 @@ SECTIONS
183 } 183 }
184#endif 184#endif
185 185
186#ifdef CONFIG_SMP
186 PERCPU_SECTION(L1_CACHE_BYTES) 187 PERCPU_SECTION(L1_CACHE_BYTES)
188#endif
187 189
188#ifdef CONFIG_XIP_KERNEL 190#ifdef CONFIG_XIP_KERNEL
189 __data_loc = ALIGN(4); /* location in binary */ 191 __data_loc = ALIGN(4); /* location in binary */
diff --git a/arch/arm/mach-dove/include/mach/bridge-regs.h b/arch/arm/mach-dove/include/mach/bridge-regs.h
index 226949dc4ac0..f953bb54aa9d 100644
--- a/arch/arm/mach-dove/include/mach/bridge-regs.h
+++ b/arch/arm/mach-dove/include/mach/bridge-regs.h
@@ -50,5 +50,6 @@
50#define POWER_MANAGEMENT (BRIDGE_VIRT_BASE | 0x011c) 50#define POWER_MANAGEMENT (BRIDGE_VIRT_BASE | 0x011c)
51 51
52#define TIMER_VIRT_BASE (BRIDGE_VIRT_BASE | 0x0300) 52#define TIMER_VIRT_BASE (BRIDGE_VIRT_BASE | 0x0300)
53#define TIMER_PHYS_BASE (BRIDGE_PHYS_BASE | 0x0300)
53 54
54#endif 55#endif
diff --git a/arch/arm/mach-dove/include/mach/dove.h b/arch/arm/mach-dove/include/mach/dove.h
index ad1165d488c1..d52b0ef313b7 100644
--- a/arch/arm/mach-dove/include/mach/dove.h
+++ b/arch/arm/mach-dove/include/mach/dove.h
@@ -78,6 +78,7 @@
78 78
79/* North-South Bridge */ 79/* North-South Bridge */
80#define BRIDGE_VIRT_BASE (DOVE_SB_REGS_VIRT_BASE | 0x20000) 80#define BRIDGE_VIRT_BASE (DOVE_SB_REGS_VIRT_BASE | 0x20000)
81#define BRIDGE_PHYS_BASE (DOVE_SB_REGS_PHYS_BASE | 0x20000)
81 82
82/* Cryptographic Engine */ 83/* Cryptographic Engine */
83#define DOVE_CRYPT_PHYS_BASE (DOVE_SB_REGS_PHYS_BASE | 0x30000) 84#define DOVE_CRYPT_PHYS_BASE (DOVE_SB_REGS_PHYS_BASE | 0x30000)
diff --git a/arch/arm/mach-exynos/pm_domains.c b/arch/arm/mach-exynos/pm_domains.c
index e9fafcf163de..373c3c00d24c 100644
--- a/arch/arm/mach-exynos/pm_domains.c
+++ b/arch/arm/mach-exynos/pm_domains.c
@@ -119,7 +119,9 @@ static __init void exynos_pm_add_dev_to_genpd(struct platform_device *pdev,
119 struct exynos_pm_domain *pd) 119 struct exynos_pm_domain *pd)
120{ 120{
121 if (pdev->dev.bus) { 121 if (pdev->dev.bus) {
122 if (pm_genpd_add_device(&pd->pd, &pdev->dev)) 122 if (!pm_genpd_add_device(&pd->pd, &pdev->dev))
123 pm_genpd_dev_need_restore(&pdev->dev, true);
124 else
123 pr_info("%s: error in adding %s device to %s power" 125 pr_info("%s: error in adding %s device to %s power"
124 "domain\n", __func__, dev_name(&pdev->dev), 126 "domain\n", __func__, dev_name(&pdev->dev),
125 pd->name); 127 pd->name);
@@ -151,9 +153,12 @@ static __init int exynos4_pm_init_power_domain(void)
151 if (of_have_populated_dt()) 153 if (of_have_populated_dt())
152 return exynos_pm_dt_parse_domains(); 154 return exynos_pm_dt_parse_domains();
153 155
154 for (idx = 0; idx < ARRAY_SIZE(exynos4_pm_domains); idx++) 156 for (idx = 0; idx < ARRAY_SIZE(exynos4_pm_domains); idx++) {
155 pm_genpd_init(&exynos4_pm_domains[idx]->pd, NULL, 157 struct exynos_pm_domain *pd = exynos4_pm_domains[idx];
156 exynos4_pm_domains[idx]->is_off); 158 int on = __raw_readl(pd->base + 0x4) & S5P_INT_LOCAL_PWR_EN;
159
160 pm_genpd_init(&pd->pd, NULL, !on);
161 }
157 162
158#ifdef CONFIG_S5P_DEV_FIMD0 163#ifdef CONFIG_S5P_DEV_FIMD0
159 exynos_pm_add_dev_to_genpd(&s5p_device_fimd0, &exynos4_pd_lcd0); 164 exynos_pm_add_dev_to_genpd(&s5p_device_fimd0, &exynos4_pd_lcd0);
diff --git a/arch/arm/mach-imx/clk-imx35.c b/arch/arm/mach-imx/clk-imx35.c
index 920a8cc42726..c6422fb10bae 100644
--- a/arch/arm/mach-imx/clk-imx35.c
+++ b/arch/arm/mach-imx/clk-imx35.c
@@ -201,7 +201,6 @@ int __init mx35_clocks_init()
201 pr_err("i.MX35 clk %d: register failed with %ld\n", 201 pr_err("i.MX35 clk %d: register failed with %ld\n",
202 i, PTR_ERR(clk[i])); 202 i, PTR_ERR(clk[i]));
203 203
204
205 clk_register_clkdev(clk[pata_gate], NULL, "pata_imx"); 204 clk_register_clkdev(clk[pata_gate], NULL, "pata_imx");
206 clk_register_clkdev(clk[can1_gate], NULL, "flexcan.0"); 205 clk_register_clkdev(clk[can1_gate], NULL, "flexcan.0");
207 clk_register_clkdev(clk[can2_gate], NULL, "flexcan.1"); 206 clk_register_clkdev(clk[can2_gate], NULL, "flexcan.1");
@@ -264,6 +263,14 @@ int __init mx35_clocks_init()
264 clk_prepare_enable(clk[iim_gate]); 263 clk_prepare_enable(clk[iim_gate]);
265 clk_prepare_enable(clk[emi_gate]); 264 clk_prepare_enable(clk[emi_gate]);
266 265
266 /*
267 * SCC is needed to boot via mmc after a watchdog reset. The clock code
268 * before conversion to common clk also enabled UART1 (which isn't
269 * handled here and not needed for mmc) and IIM (which is enabled
270 * unconditionally above).
271 */
272 clk_prepare_enable(clk[scc_gate]);
273
267 imx_print_silicon_rev("i.MX35", mx35_revision()); 274 imx_print_silicon_rev("i.MX35", mx35_revision());
268 275
269#ifdef CONFIG_MXC_USE_EPIT 276#ifdef CONFIG_MXC_USE_EPIT
diff --git a/arch/arm/mach-imx/mach-imx27_visstrim_m10.c b/arch/arm/mach-imx/mach-imx27_visstrim_m10.c
index f76edb96a48a..ba09552fe5fe 100644
--- a/arch/arm/mach-imx/mach-imx27_visstrim_m10.c
+++ b/arch/arm/mach-imx/mach-imx27_visstrim_m10.c
@@ -38,7 +38,7 @@
38#include <asm/mach-types.h> 38#include <asm/mach-types.h>
39#include <asm/mach/arch.h> 39#include <asm/mach/arch.h>
40#include <asm/mach/time.h> 40#include <asm/mach/time.h>
41#include <asm/system.h> 41#include <asm/system_info.h>
42#include <mach/common.h> 42#include <mach/common.h>
43#include <mach/iomux-mx27.h> 43#include <mach/iomux-mx27.h>
44 44
diff --git a/arch/arm/mach-mmp/include/mach/gpio-pxa.h b/arch/arm/mach-mmp/include/mach/gpio-pxa.h
deleted file mode 100644
index 0e135a599f3e..000000000000
--- a/arch/arm/mach-mmp/include/mach/gpio-pxa.h
+++ /dev/null
@@ -1,29 +0,0 @@
1#ifndef __ASM_MACH_GPIO_PXA_H
2#define __ASM_MACH_GPIO_PXA_H
3
4#include <mach/addr-map.h>
5#include <mach/cputype.h>
6#include <mach/irqs.h>
7
8#define GPIO_REGS_VIRT (APB_VIRT_BASE + 0x19000)
9
10#define BANK_OFF(n) (((n) < 3) ? (n) << 2 : 0x100 + (((n) - 3) << 2))
11#define GPIO_REG(x) (*(volatile u32 *)(GPIO_REGS_VIRT + (x)))
12
13#define gpio_to_bank(gpio) ((gpio) >> 5)
14
15/* NOTE: these macros are defined here to make optimization of
16 * gpio_{get,set}_value() to work when 'gpio' is a constant.
17 * Usage of these macros otherwise is no longer recommended,
18 * use generic GPIO API whenever possible.
19 */
20#define GPIO_bit(gpio) (1 << ((gpio) & 0x1f))
21
22#define GPLR(x) GPIO_REG(BANK_OFF(gpio_to_bank(x)) + 0x00)
23#define GPDR(x) GPIO_REG(BANK_OFF(gpio_to_bank(x)) + 0x0c)
24#define GPSR(x) GPIO_REG(BANK_OFF(gpio_to_bank(x)) + 0x18)
25#define GPCR(x) GPIO_REG(BANK_OFF(gpio_to_bank(x)) + 0x24)
26
27#include <plat/gpio-pxa.h>
28
29#endif /* __ASM_MACH_GPIO_PXA_H */
diff --git a/arch/arm/mach-mv78xx0/include/mach/bridge-regs.h b/arch/arm/mach-mv78xx0/include/mach/bridge-regs.h
index c64dbb96dbad..eb187e0e059b 100644
--- a/arch/arm/mach-mv78xx0/include/mach/bridge-regs.h
+++ b/arch/arm/mach-mv78xx0/include/mach/bridge-regs.h
@@ -31,5 +31,6 @@
31#define IRQ_MASK_HIGH_OFF 0x0014 31#define IRQ_MASK_HIGH_OFF 0x0014
32 32
33#define TIMER_VIRT_BASE (BRIDGE_VIRT_BASE | 0x0300) 33#define TIMER_VIRT_BASE (BRIDGE_VIRT_BASE | 0x0300)
34#define TIMER_PHYS_BASE (BRIDGE_PHYS_BASE | 0x0300)
34 35
35#endif 36#endif
diff --git a/arch/arm/mach-mv78xx0/include/mach/mv78xx0.h b/arch/arm/mach-mv78xx0/include/mach/mv78xx0.h
index 3674497162e3..e807c4c52a0b 100644
--- a/arch/arm/mach-mv78xx0/include/mach/mv78xx0.h
+++ b/arch/arm/mach-mv78xx0/include/mach/mv78xx0.h
@@ -42,6 +42,7 @@
42#define MV78XX0_CORE0_REGS_PHYS_BASE 0xf1020000 42#define MV78XX0_CORE0_REGS_PHYS_BASE 0xf1020000
43#define MV78XX0_CORE1_REGS_PHYS_BASE 0xf1024000 43#define MV78XX0_CORE1_REGS_PHYS_BASE 0xf1024000
44#define MV78XX0_CORE_REGS_VIRT_BASE 0xfe400000 44#define MV78XX0_CORE_REGS_VIRT_BASE 0xfe400000
45#define MV78XX0_CORE_REGS_PHYS_BASE 0xfe400000
45#define MV78XX0_CORE_REGS_SIZE SZ_16K 46#define MV78XX0_CORE_REGS_SIZE SZ_16K
46 47
47#define MV78XX0_PCIE_IO_PHYS_BASE(i) (0xf0800000 + ((i) << 20)) 48#define MV78XX0_PCIE_IO_PHYS_BASE(i) (0xf0800000 + ((i) << 20))
@@ -59,6 +60,7 @@
59 * Core-specific peripheral registers. 60 * Core-specific peripheral registers.
60 */ 61 */
61#define BRIDGE_VIRT_BASE (MV78XX0_CORE_REGS_VIRT_BASE) 62#define BRIDGE_VIRT_BASE (MV78XX0_CORE_REGS_VIRT_BASE)
63#define BRIDGE_PHYS_BASE (MV78XX0_CORE_REGS_PHYS_BASE)
62 64
63/* 65/*
64 * Register Map 66 * Register Map
diff --git a/arch/arm/mach-mxs/mach-apx4devkit.c b/arch/arm/mach-mxs/mach-apx4devkit.c
index 5e90b9dcdef8..f5f061757deb 100644
--- a/arch/arm/mach-mxs/mach-apx4devkit.c
+++ b/arch/arm/mach-mxs/mach-apx4devkit.c
@@ -205,6 +205,16 @@ static int apx4devkit_phy_fixup(struct phy_device *phy)
205 return 0; 205 return 0;
206} 206}
207 207
208static void __init apx4devkit_fec_phy_clk_enable(void)
209{
210 struct clk *clk;
211
212 /* Enable fec phy clock */
213 clk = clk_get_sys("enet_out", NULL);
214 if (!IS_ERR(clk))
215 clk_prepare_enable(clk);
216}
217
208static void __init apx4devkit_init(void) 218static void __init apx4devkit_init(void)
209{ 219{
210 mx28_soc_init(); 220 mx28_soc_init();
@@ -225,6 +235,7 @@ static void __init apx4devkit_init(void)
225 phy_register_fixup_for_uid(PHY_ID_KS8051, MICREL_PHY_ID_MASK, 235 phy_register_fixup_for_uid(PHY_ID_KS8051, MICREL_PHY_ID_MASK,
226 apx4devkit_phy_fixup); 236 apx4devkit_phy_fixup);
227 237
238 apx4devkit_fec_phy_clk_enable();
228 mx28_add_fec(0, &mx28_fec_pdata); 239 mx28_add_fec(0, &mx28_fec_pdata);
229 240
230 mx28_add_mxs_mmc(0, &apx4devkit_mmc_pdata); 241 mx28_add_mxs_mmc(0, &apx4devkit_mmc_pdata);
diff --git a/arch/arm/mach-omap2/board-overo.c b/arch/arm/mach-omap2/board-overo.c
index 8fa2fc3a4c3c..779734d8ba37 100644
--- a/arch/arm/mach-omap2/board-overo.c
+++ b/arch/arm/mach-omap2/board-overo.c
@@ -494,8 +494,8 @@ static void __init overo_init(void)
494 494
495 regulator_register_fixed(0, dummy_supplies, ARRAY_SIZE(dummy_supplies)); 495 regulator_register_fixed(0, dummy_supplies, ARRAY_SIZE(dummy_supplies));
496 omap3_mux_init(board_mux, OMAP_PACKAGE_CBB); 496 omap3_mux_init(board_mux, OMAP_PACKAGE_CBB);
497 omap_hsmmc_init(mmc);
498 overo_i2c_init(); 497 overo_i2c_init();
498 omap_hsmmc_init(mmc);
499 omap_display_init(&overo_dss_data); 499 omap_display_init(&overo_dss_data);
500 omap_serial_init(); 500 omap_serial_init();
501 omap_sdrc_init(mt46h32m32lf6_sdrc_params, 501 omap_sdrc_init(mt46h32m32lf6_sdrc_params,
diff --git a/arch/arm/mach-omap2/clockdomain.h b/arch/arm/mach-omap2/clockdomain.h
index f7b58609bad8..6227e9505c2d 100644
--- a/arch/arm/mach-omap2/clockdomain.h
+++ b/arch/arm/mach-omap2/clockdomain.h
@@ -31,12 +31,16 @@
31 * 31 *
32 * CLKDM_NO_AUTODEPS: Prevent "autodeps" from being added/removed from this 32 * CLKDM_NO_AUTODEPS: Prevent "autodeps" from being added/removed from this
33 * clockdomain. (Currently, this applies to OMAP3 clockdomains only.) 33 * clockdomain. (Currently, this applies to OMAP3 clockdomains only.)
34 * CLKDM_ACTIVE_WITH_MPU: The PRCM guarantees that this clockdomain is
35 * active whenever the MPU is active. True for interconnects and
36 * the WKUP clockdomains.
34 */ 37 */
35#define CLKDM_CAN_FORCE_SLEEP (1 << 0) 38#define CLKDM_CAN_FORCE_SLEEP (1 << 0)
36#define CLKDM_CAN_FORCE_WAKEUP (1 << 1) 39#define CLKDM_CAN_FORCE_WAKEUP (1 << 1)
37#define CLKDM_CAN_ENABLE_AUTO (1 << 2) 40#define CLKDM_CAN_ENABLE_AUTO (1 << 2)
38#define CLKDM_CAN_DISABLE_AUTO (1 << 3) 41#define CLKDM_CAN_DISABLE_AUTO (1 << 3)
39#define CLKDM_NO_AUTODEPS (1 << 4) 42#define CLKDM_NO_AUTODEPS (1 << 4)
43#define CLKDM_ACTIVE_WITH_MPU (1 << 5)
40 44
41#define CLKDM_CAN_HWSUP (CLKDM_CAN_ENABLE_AUTO | CLKDM_CAN_DISABLE_AUTO) 45#define CLKDM_CAN_HWSUP (CLKDM_CAN_ENABLE_AUTO | CLKDM_CAN_DISABLE_AUTO)
42#define CLKDM_CAN_SWSUP (CLKDM_CAN_FORCE_SLEEP | CLKDM_CAN_FORCE_WAKEUP) 46#define CLKDM_CAN_SWSUP (CLKDM_CAN_FORCE_SLEEP | CLKDM_CAN_FORCE_WAKEUP)
diff --git a/arch/arm/mach-omap2/clockdomains2xxx_3xxx_data.c b/arch/arm/mach-omap2/clockdomains2xxx_3xxx_data.c
index 839145e1cfbe..4972219653ce 100644
--- a/arch/arm/mach-omap2/clockdomains2xxx_3xxx_data.c
+++ b/arch/arm/mach-omap2/clockdomains2xxx_3xxx_data.c
@@ -88,4 +88,5 @@ struct clockdomain wkup_common_clkdm = {
88 .name = "wkup_clkdm", 88 .name = "wkup_clkdm",
89 .pwrdm = { .name = "wkup_pwrdm" }, 89 .pwrdm = { .name = "wkup_pwrdm" },
90 .dep_bit = OMAP_EN_WKUP_SHIFT, 90 .dep_bit = OMAP_EN_WKUP_SHIFT,
91 .flags = CLKDM_ACTIVE_WITH_MPU,
91}; 92};
diff --git a/arch/arm/mach-omap2/clockdomains44xx_data.c b/arch/arm/mach-omap2/clockdomains44xx_data.c
index c53425847493..7f2133abe7d3 100644
--- a/arch/arm/mach-omap2/clockdomains44xx_data.c
+++ b/arch/arm/mach-omap2/clockdomains44xx_data.c
@@ -381,7 +381,7 @@ static struct clockdomain l4_wkup_44xx_clkdm = {
381 .cm_inst = OMAP4430_PRM_WKUP_CM_INST, 381 .cm_inst = OMAP4430_PRM_WKUP_CM_INST,
382 .clkdm_offs = OMAP4430_PRM_WKUP_CM_WKUP_CDOFFS, 382 .clkdm_offs = OMAP4430_PRM_WKUP_CM_WKUP_CDOFFS,
383 .dep_bit = OMAP4430_L4WKUP_STATDEP_SHIFT, 383 .dep_bit = OMAP4430_L4WKUP_STATDEP_SHIFT,
384 .flags = CLKDM_CAN_HWSUP, 384 .flags = CLKDM_CAN_HWSUP | CLKDM_ACTIVE_WITH_MPU,
385}; 385};
386 386
387static struct clockdomain emu_sys_44xx_clkdm = { 387static struct clockdomain emu_sys_44xx_clkdm = {
diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
index 773193670ea2..2d710f50fca2 100644
--- a/arch/arm/mach-omap2/omap_hwmod.c
+++ b/arch/arm/mach-omap2/omap_hwmod.c
@@ -1124,15 +1124,18 @@ static struct omap_hwmod_addr_space * __init _find_mpu_rt_addr_space(struct omap
1124 * _enable_sysc - try to bring a module out of idle via OCP_SYSCONFIG 1124 * _enable_sysc - try to bring a module out of idle via OCP_SYSCONFIG
1125 * @oh: struct omap_hwmod * 1125 * @oh: struct omap_hwmod *
1126 * 1126 *
1127 * If module is marked as SWSUP_SIDLE, force the module out of slave 1127 * Ensure that the OCP_SYSCONFIG register for the IP block represented
1128 * idle; otherwise, configure it for smart-idle. If module is marked 1128 * by @oh is set to indicate to the PRCM that the IP block is active.
1129 * as SWSUP_MSUSPEND, force the module out of master standby; 1129 * Usually this means placing the module into smart-idle mode and
1130 * otherwise, configure it for smart-standby. No return value. 1130 * smart-standby, but if there is a bug in the automatic idle handling
1131 * for the IP block, it may need to be placed into the force-idle or
1132 * no-idle variants of these modes. No return value.
1131 */ 1133 */
1132static void _enable_sysc(struct omap_hwmod *oh) 1134static void _enable_sysc(struct omap_hwmod *oh)
1133{ 1135{
1134 u8 idlemode, sf; 1136 u8 idlemode, sf;
1135 u32 v; 1137 u32 v;
1138 bool clkdm_act;
1136 1139
1137 if (!oh->class->sysc) 1140 if (!oh->class->sysc)
1138 return; 1141 return;
@@ -1141,8 +1144,16 @@ static void _enable_sysc(struct omap_hwmod *oh)
1141 sf = oh->class->sysc->sysc_flags; 1144 sf = oh->class->sysc->sysc_flags;
1142 1145
1143 if (sf & SYSC_HAS_SIDLEMODE) { 1146 if (sf & SYSC_HAS_SIDLEMODE) {
1144 idlemode = (oh->flags & HWMOD_SWSUP_SIDLE) ? 1147 clkdm_act = ((oh->clkdm &&
1145 HWMOD_IDLEMODE_NO : HWMOD_IDLEMODE_SMART; 1148 oh->clkdm->flags & CLKDM_ACTIVE_WITH_MPU) ||
1149 (oh->_clk && oh->_clk->clkdm &&
1150 oh->_clk->clkdm->flags & CLKDM_ACTIVE_WITH_MPU));
1151 if (clkdm_act && !(oh->class->sysc->idlemodes &
1152 (SIDLE_SMART | SIDLE_SMART_WKUP)))
1153 idlemode = HWMOD_IDLEMODE_FORCE;
1154 else
1155 idlemode = (oh->flags & HWMOD_SWSUP_SIDLE) ?
1156 HWMOD_IDLEMODE_NO : HWMOD_IDLEMODE_SMART;
1146 _set_slave_idlemode(oh, idlemode, &v); 1157 _set_slave_idlemode(oh, idlemode, &v);
1147 } 1158 }
1148 1159
@@ -1208,8 +1219,13 @@ static void _idle_sysc(struct omap_hwmod *oh)
1208 sf = oh->class->sysc->sysc_flags; 1219 sf = oh->class->sysc->sysc_flags;
1209 1220
1210 if (sf & SYSC_HAS_SIDLEMODE) { 1221 if (sf & SYSC_HAS_SIDLEMODE) {
1211 idlemode = (oh->flags & HWMOD_SWSUP_SIDLE) ? 1222 /* XXX What about HWMOD_IDLEMODE_SMART_WKUP? */
1212 HWMOD_IDLEMODE_FORCE : HWMOD_IDLEMODE_SMART; 1223 if (oh->flags & HWMOD_SWSUP_SIDLE ||
1224 !(oh->class->sysc->idlemodes &
1225 (SIDLE_SMART | SIDLE_SMART_WKUP)))
1226 idlemode = HWMOD_IDLEMODE_FORCE;
1227 else
1228 idlemode = HWMOD_IDLEMODE_SMART;
1213 _set_slave_idlemode(oh, idlemode, &v); 1229 _set_slave_idlemode(oh, idlemode, &v);
1214 } 1230 }
1215 1231
diff --git a/arch/arm/mach-omap2/omap_hwmod_44xx_data.c b/arch/arm/mach-omap2/omap_hwmod_44xx_data.c
index f30e861ce6d9..b7bcba5221ba 100644
--- a/arch/arm/mach-omap2/omap_hwmod_44xx_data.c
+++ b/arch/arm/mach-omap2/omap_hwmod_44xx_data.c
@@ -1928,7 +1928,7 @@ static struct omap_hwmod_dma_info omap44xx_mcbsp1_sdma_reqs[] = {
1928 1928
1929static struct omap_hwmod_opt_clk mcbsp1_opt_clks[] = { 1929static struct omap_hwmod_opt_clk mcbsp1_opt_clks[] = {
1930 { .role = "pad_fck", .clk = "pad_clks_ck" }, 1930 { .role = "pad_fck", .clk = "pad_clks_ck" },
1931 { .role = "prcm_clk", .clk = "mcbsp1_sync_mux_ck" }, 1931 { .role = "prcm_fck", .clk = "mcbsp1_sync_mux_ck" },
1932}; 1932};
1933 1933
1934static struct omap_hwmod omap44xx_mcbsp1_hwmod = { 1934static struct omap_hwmod omap44xx_mcbsp1_hwmod = {
@@ -1963,7 +1963,7 @@ static struct omap_hwmod_dma_info omap44xx_mcbsp2_sdma_reqs[] = {
1963 1963
1964static struct omap_hwmod_opt_clk mcbsp2_opt_clks[] = { 1964static struct omap_hwmod_opt_clk mcbsp2_opt_clks[] = {
1965 { .role = "pad_fck", .clk = "pad_clks_ck" }, 1965 { .role = "pad_fck", .clk = "pad_clks_ck" },
1966 { .role = "prcm_clk", .clk = "mcbsp2_sync_mux_ck" }, 1966 { .role = "prcm_fck", .clk = "mcbsp2_sync_mux_ck" },
1967}; 1967};
1968 1968
1969static struct omap_hwmod omap44xx_mcbsp2_hwmod = { 1969static struct omap_hwmod omap44xx_mcbsp2_hwmod = {
@@ -1998,7 +1998,7 @@ static struct omap_hwmod_dma_info omap44xx_mcbsp3_sdma_reqs[] = {
1998 1998
1999static struct omap_hwmod_opt_clk mcbsp3_opt_clks[] = { 1999static struct omap_hwmod_opt_clk mcbsp3_opt_clks[] = {
2000 { .role = "pad_fck", .clk = "pad_clks_ck" }, 2000 { .role = "pad_fck", .clk = "pad_clks_ck" },
2001 { .role = "prcm_clk", .clk = "mcbsp3_sync_mux_ck" }, 2001 { .role = "prcm_fck", .clk = "mcbsp3_sync_mux_ck" },
2002}; 2002};
2003 2003
2004static struct omap_hwmod omap44xx_mcbsp3_hwmod = { 2004static struct omap_hwmod omap44xx_mcbsp3_hwmod = {
@@ -2033,7 +2033,7 @@ static struct omap_hwmod_dma_info omap44xx_mcbsp4_sdma_reqs[] = {
2033 2033
2034static struct omap_hwmod_opt_clk mcbsp4_opt_clks[] = { 2034static struct omap_hwmod_opt_clk mcbsp4_opt_clks[] = {
2035 { .role = "pad_fck", .clk = "pad_clks_ck" }, 2035 { .role = "pad_fck", .clk = "pad_clks_ck" },
2036 { .role = "prcm_clk", .clk = "mcbsp4_sync_mux_ck" }, 2036 { .role = "prcm_fck", .clk = "mcbsp4_sync_mux_ck" },
2037}; 2037};
2038 2038
2039static struct omap_hwmod omap44xx_mcbsp4_hwmod = { 2039static struct omap_hwmod omap44xx_mcbsp4_hwmod = {
@@ -3864,7 +3864,7 @@ static struct omap_hwmod_ocp_if omap44xx_l4_cfg__l3_main_2 = {
3864}; 3864};
3865 3865
3866/* usb_host_fs -> l3_main_2 */ 3866/* usb_host_fs -> l3_main_2 */
3867static struct omap_hwmod_ocp_if omap44xx_usb_host_fs__l3_main_2 = { 3867static struct omap_hwmod_ocp_if __maybe_unused omap44xx_usb_host_fs__l3_main_2 = {
3868 .master = &omap44xx_usb_host_fs_hwmod, 3868 .master = &omap44xx_usb_host_fs_hwmod,
3869 .slave = &omap44xx_l3_main_2_hwmod, 3869 .slave = &omap44xx_l3_main_2_hwmod,
3870 .clk = "l3_div_ck", 3870 .clk = "l3_div_ck",
@@ -3922,7 +3922,7 @@ static struct omap_hwmod_ocp_if omap44xx_l4_cfg__l3_main_3 = {
3922}; 3922};
3923 3923
3924/* aess -> l4_abe */ 3924/* aess -> l4_abe */
3925static struct omap_hwmod_ocp_if omap44xx_aess__l4_abe = { 3925static struct omap_hwmod_ocp_if __maybe_unused omap44xx_aess__l4_abe = {
3926 .master = &omap44xx_aess_hwmod, 3926 .master = &omap44xx_aess_hwmod,
3927 .slave = &omap44xx_l4_abe_hwmod, 3927 .slave = &omap44xx_l4_abe_hwmod,
3928 .clk = "ocp_abe_iclk", 3928 .clk = "ocp_abe_iclk",
@@ -4013,7 +4013,7 @@ static struct omap_hwmod_addr_space omap44xx_aess_addrs[] = {
4013}; 4013};
4014 4014
4015/* l4_abe -> aess */ 4015/* l4_abe -> aess */
4016static struct omap_hwmod_ocp_if omap44xx_l4_abe__aess = { 4016static struct omap_hwmod_ocp_if __maybe_unused omap44xx_l4_abe__aess = {
4017 .master = &omap44xx_l4_abe_hwmod, 4017 .master = &omap44xx_l4_abe_hwmod,
4018 .slave = &omap44xx_aess_hwmod, 4018 .slave = &omap44xx_aess_hwmod,
4019 .clk = "ocp_abe_iclk", 4019 .clk = "ocp_abe_iclk",
@@ -4031,7 +4031,7 @@ static struct omap_hwmod_addr_space omap44xx_aess_dma_addrs[] = {
4031}; 4031};
4032 4032
4033/* l4_abe -> aess (dma) */ 4033/* l4_abe -> aess (dma) */
4034static struct omap_hwmod_ocp_if omap44xx_l4_abe__aess_dma = { 4034static struct omap_hwmod_ocp_if __maybe_unused omap44xx_l4_abe__aess_dma = {
4035 .master = &omap44xx_l4_abe_hwmod, 4035 .master = &omap44xx_l4_abe_hwmod,
4036 .slave = &omap44xx_aess_hwmod, 4036 .slave = &omap44xx_aess_hwmod,
4037 .clk = "ocp_abe_iclk", 4037 .clk = "ocp_abe_iclk",
@@ -5857,7 +5857,7 @@ static struct omap_hwmod_addr_space omap44xx_usb_host_fs_addrs[] = {
5857}; 5857};
5858 5858
5859/* l4_cfg -> usb_host_fs */ 5859/* l4_cfg -> usb_host_fs */
5860static struct omap_hwmod_ocp_if omap44xx_l4_cfg__usb_host_fs = { 5860static struct omap_hwmod_ocp_if __maybe_unused omap44xx_l4_cfg__usb_host_fs = {
5861 .master = &omap44xx_l4_cfg_hwmod, 5861 .master = &omap44xx_l4_cfg_hwmod,
5862 .slave = &omap44xx_usb_host_fs_hwmod, 5862 .slave = &omap44xx_usb_host_fs_hwmod,
5863 .clk = "l4_div_ck", 5863 .clk = "l4_div_ck",
@@ -6014,13 +6014,13 @@ static struct omap_hwmod_ocp_if *omap44xx_hwmod_ocp_ifs[] __initdata = {
6014 &omap44xx_iva__l3_main_2, 6014 &omap44xx_iva__l3_main_2,
6015 &omap44xx_l3_main_1__l3_main_2, 6015 &omap44xx_l3_main_1__l3_main_2,
6016 &omap44xx_l4_cfg__l3_main_2, 6016 &omap44xx_l4_cfg__l3_main_2,
6017 &omap44xx_usb_host_fs__l3_main_2, 6017 /* &omap44xx_usb_host_fs__l3_main_2, */
6018 &omap44xx_usb_host_hs__l3_main_2, 6018 &omap44xx_usb_host_hs__l3_main_2,
6019 &omap44xx_usb_otg_hs__l3_main_2, 6019 &omap44xx_usb_otg_hs__l3_main_2,
6020 &omap44xx_l3_main_1__l3_main_3, 6020 &omap44xx_l3_main_1__l3_main_3,
6021 &omap44xx_l3_main_2__l3_main_3, 6021 &omap44xx_l3_main_2__l3_main_3,
6022 &omap44xx_l4_cfg__l3_main_3, 6022 &omap44xx_l4_cfg__l3_main_3,
6023 &omap44xx_aess__l4_abe, 6023 /* &omap44xx_aess__l4_abe, */
6024 &omap44xx_dsp__l4_abe, 6024 &omap44xx_dsp__l4_abe,
6025 &omap44xx_l3_main_1__l4_abe, 6025 &omap44xx_l3_main_1__l4_abe,
6026 &omap44xx_mpu__l4_abe, 6026 &omap44xx_mpu__l4_abe,
@@ -6029,8 +6029,8 @@ static struct omap_hwmod_ocp_if *omap44xx_hwmod_ocp_ifs[] __initdata = {
6029 &omap44xx_l4_cfg__l4_wkup, 6029 &omap44xx_l4_cfg__l4_wkup,
6030 &omap44xx_mpu__mpu_private, 6030 &omap44xx_mpu__mpu_private,
6031 &omap44xx_l4_cfg__ocp_wp_noc, 6031 &omap44xx_l4_cfg__ocp_wp_noc,
6032 &omap44xx_l4_abe__aess, 6032 /* &omap44xx_l4_abe__aess, */
6033 &omap44xx_l4_abe__aess_dma, 6033 /* &omap44xx_l4_abe__aess_dma, */
6034 &omap44xx_l3_main_2__c2c, 6034 &omap44xx_l3_main_2__c2c,
6035 &omap44xx_l4_wkup__counter_32k, 6035 &omap44xx_l4_wkup__counter_32k,
6036 &omap44xx_l4_cfg__ctrl_module_core, 6036 &omap44xx_l4_cfg__ctrl_module_core,
@@ -6136,7 +6136,7 @@ static struct omap_hwmod_ocp_if *omap44xx_hwmod_ocp_ifs[] __initdata = {
6136 &omap44xx_l4_per__uart2, 6136 &omap44xx_l4_per__uart2,
6137 &omap44xx_l4_per__uart3, 6137 &omap44xx_l4_per__uart3,
6138 &omap44xx_l4_per__uart4, 6138 &omap44xx_l4_per__uart4,
6139 &omap44xx_l4_cfg__usb_host_fs, 6139 /* &omap44xx_l4_cfg__usb_host_fs, */
6140 &omap44xx_l4_cfg__usb_host_hs, 6140 &omap44xx_l4_cfg__usb_host_hs,
6141 &omap44xx_l4_cfg__usb_otg_hs, 6141 &omap44xx_l4_cfg__usb_otg_hs,
6142 &omap44xx_l4_cfg__usb_tll_hs, 6142 &omap44xx_l4_cfg__usb_tll_hs,
diff --git a/arch/arm/mach-omap2/twl-common.c b/arch/arm/mach-omap2/twl-common.c
index 119d5a910f3a..43a979075338 100644
--- a/arch/arm/mach-omap2/twl-common.c
+++ b/arch/arm/mach-omap2/twl-common.c
@@ -32,6 +32,7 @@
32#include "twl-common.h" 32#include "twl-common.h"
33#include "pm.h" 33#include "pm.h"
34#include "voltage.h" 34#include "voltage.h"
35#include "mux.h"
35 36
36static struct i2c_board_info __initdata pmic_i2c_board_info = { 37static struct i2c_board_info __initdata pmic_i2c_board_info = {
37 .addr = 0x48, 38 .addr = 0x48,
@@ -77,6 +78,7 @@ void __init omap4_pmic_init(const char *pmic_type,
77 struct twl6040_platform_data *twl6040_data, int twl6040_irq) 78 struct twl6040_platform_data *twl6040_data, int twl6040_irq)
78{ 79{
79 /* PMIC part*/ 80 /* PMIC part*/
81 omap_mux_init_signal("sys_nirq1", OMAP_PIN_INPUT_PULLUP | OMAP_PIN_OFF_WAKEUPENABLE);
80 strncpy(omap4_i2c1_board_info[0].type, pmic_type, 82 strncpy(omap4_i2c1_board_info[0].type, pmic_type,
81 sizeof(omap4_i2c1_board_info[0].type)); 83 sizeof(omap4_i2c1_board_info[0].type));
82 omap4_i2c1_board_info[0].irq = OMAP44XX_IRQ_SYS_1N; 84 omap4_i2c1_board_info[0].irq = OMAP44XX_IRQ_SYS_1N;
diff --git a/arch/arm/mach-pxa/hx4700.c b/arch/arm/mach-pxa/hx4700.c
index d09da6a746b8..d3de84b0dcbe 100644
--- a/arch/arm/mach-pxa/hx4700.c
+++ b/arch/arm/mach-pxa/hx4700.c
@@ -127,7 +127,11 @@ static unsigned long hx4700_pin_config[] __initdata = {
127 GPIO19_SSP2_SCLK, 127 GPIO19_SSP2_SCLK,
128 GPIO86_SSP2_RXD, 128 GPIO86_SSP2_RXD,
129 GPIO87_SSP2_TXD, 129 GPIO87_SSP2_TXD,
130 GPIO88_GPIO, 130 GPIO88_GPIO | MFP_LPM_DRIVE_HIGH, /* TSC2046_CS */
131
132 /* BQ24022 Regulator */
133 GPIO72_GPIO | MFP_LPM_KEEP_OUTPUT, /* BQ24022_nCHARGE_EN */
134 GPIO96_GPIO | MFP_LPM_KEEP_OUTPUT, /* BQ24022_ISET2 */
131 135
132 /* HX4700 specific input GPIOs */ 136 /* HX4700 specific input GPIOs */
133 GPIO12_GPIO | WAKEUP_ON_EDGE_RISE, /* ASIC3_IRQ */ 137 GPIO12_GPIO | WAKEUP_ON_EDGE_RISE, /* ASIC3_IRQ */
@@ -135,6 +139,10 @@ static unsigned long hx4700_pin_config[] __initdata = {
135 GPIO14_GPIO, /* nWLAN_IRQ */ 139 GPIO14_GPIO, /* nWLAN_IRQ */
136 140
137 /* HX4700 specific output GPIOs */ 141 /* HX4700 specific output GPIOs */
142 GPIO61_GPIO | MFP_LPM_DRIVE_HIGH, /* W3220_nRESET */
143 GPIO71_GPIO | MFP_LPM_DRIVE_HIGH, /* ASIC3_nRESET */
144 GPIO81_GPIO | MFP_LPM_DRIVE_HIGH, /* CPU_GP_nRESET */
145 GPIO116_GPIO | MFP_LPM_DRIVE_HIGH, /* CPU_HW_nRESET */
138 GPIO102_GPIO | MFP_LPM_DRIVE_LOW, /* SYNAPTICS_POWER_ON */ 146 GPIO102_GPIO | MFP_LPM_DRIVE_LOW, /* SYNAPTICS_POWER_ON */
139 147
140 GPIO10_GPIO, /* GSM_IRQ */ 148 GPIO10_GPIO, /* GSM_IRQ */
@@ -872,14 +880,19 @@ static struct gpio global_gpios[] = {
872 { GPIO110_HX4700_LCD_LVDD_3V3_ON, GPIOF_OUT_INIT_HIGH, "LCD_LVDD" }, 880 { GPIO110_HX4700_LCD_LVDD_3V3_ON, GPIOF_OUT_INIT_HIGH, "LCD_LVDD" },
873 { GPIO111_HX4700_LCD_AVDD_3V3_ON, GPIOF_OUT_INIT_HIGH, "LCD_AVDD" }, 881 { GPIO111_HX4700_LCD_AVDD_3V3_ON, GPIOF_OUT_INIT_HIGH, "LCD_AVDD" },
874 { GPIO32_HX4700_RS232_ON, GPIOF_OUT_INIT_HIGH, "RS232_ON" }, 882 { GPIO32_HX4700_RS232_ON, GPIOF_OUT_INIT_HIGH, "RS232_ON" },
883 { GPIO61_HX4700_W3220_nRESET, GPIOF_OUT_INIT_HIGH, "W3220_nRESET" },
875 { GPIO71_HX4700_ASIC3_nRESET, GPIOF_OUT_INIT_HIGH, "ASIC3_nRESET" }, 884 { GPIO71_HX4700_ASIC3_nRESET, GPIOF_OUT_INIT_HIGH, "ASIC3_nRESET" },
885 { GPIO81_HX4700_CPU_GP_nRESET, GPIOF_OUT_INIT_HIGH, "CPU_GP_nRESET" },
876 { GPIO82_HX4700_EUART_RESET, GPIOF_OUT_INIT_HIGH, "EUART_RESET" }, 886 { GPIO82_HX4700_EUART_RESET, GPIOF_OUT_INIT_HIGH, "EUART_RESET" },
887 { GPIO116_HX4700_CPU_HW_nRESET, GPIOF_OUT_INIT_HIGH, "CPU_HW_nRESET" },
877}; 888};
878 889
879static void __init hx4700_init(void) 890static void __init hx4700_init(void)
880{ 891{
881 int ret; 892 int ret;
882 893
894 PCFR = PCFR_GPR_EN | PCFR_OPDE;
895
883 pxa2xx_mfp_config(ARRAY_AND_SIZE(hx4700_pin_config)); 896 pxa2xx_mfp_config(ARRAY_AND_SIZE(hx4700_pin_config));
884 gpio_set_wake(GPIO12_HX4700_ASIC3_IRQ, 1); 897 gpio_set_wake(GPIO12_HX4700_ASIC3_IRQ, 1);
885 ret = gpio_request_array(ARRAY_AND_SIZE(global_gpios)); 898 ret = gpio_request_array(ARRAY_AND_SIZE(global_gpios));
diff --git a/arch/arm/mach-s3c24xx/clock-s3c2440.c b/arch/arm/mach-s3c24xx/clock-s3c2440.c
index 414364eb426c..cb2883d553b5 100644
--- a/arch/arm/mach-s3c24xx/clock-s3c2440.c
+++ b/arch/arm/mach-s3c24xx/clock-s3c2440.c
@@ -106,7 +106,7 @@ static struct clk s3c2440_clk_cam_upll = {
106static struct clk s3c2440_clk_ac97 = { 106static struct clk s3c2440_clk_ac97 = {
107 .name = "ac97", 107 .name = "ac97",
108 .enable = s3c2410_clkcon_enable, 108 .enable = s3c2410_clkcon_enable,
109 .ctrlbit = S3C2440_CLKCON_CAMERA, 109 .ctrlbit = S3C2440_CLKCON_AC97,
110}; 110};
111 111
112static unsigned long s3c2440_fclk_n_getrate(struct clk *clk) 112static unsigned long s3c2440_fclk_n_getrate(struct clk *clk)
diff --git a/arch/arm/mach-shmobile/platsmp.c b/arch/arm/mach-shmobile/platsmp.c
index e859fcdb3d58..fde0d23121dc 100644
--- a/arch/arm/mach-shmobile/platsmp.c
+++ b/arch/arm/mach-shmobile/platsmp.c
@@ -22,8 +22,13 @@
22#include <mach/common.h> 22#include <mach/common.h>
23#include <mach/emev2.h> 23#include <mach/emev2.h>
24 24
25#ifdef CONFIG_ARCH_SH73A0
25#define is_sh73a0() (machine_is_ag5evm() || machine_is_kota2() || \ 26#define is_sh73a0() (machine_is_ag5evm() || machine_is_kota2() || \
26 of_machine_is_compatible("renesas,sh73a0")) 27 of_machine_is_compatible("renesas,sh73a0"))
28#else
29#define is_sh73a0() (0)
30#endif
31
27#define is_r8a7779() machine_is_marzen() 32#define is_r8a7779() machine_is_marzen()
28 33
29#ifdef CONFIG_ARCH_EMEV2 34#ifdef CONFIG_ARCH_EMEV2
diff --git a/arch/arm/mach-ux500/board-mop500.c b/arch/arm/mach-ux500/board-mop500.c
index 1509a3cb5833..4fd93f5c49ec 100644
--- a/arch/arm/mach-ux500/board-mop500.c
+++ b/arch/arm/mach-ux500/board-mop500.c
@@ -625,11 +625,6 @@ static struct platform_device *snowball_platform_devs[] __initdata = {
625 &ab8500_device, 625 &ab8500_device,
626}; 626};
627 627
628static struct platform_device *snowball_of_platform_devs[] __initdata = {
629 &snowball_led_dev,
630 &snowball_key_dev,
631};
632
633static void __init mop500_init_machine(void) 628static void __init mop500_init_machine(void)
634{ 629{
635 struct device *parent = NULL; 630 struct device *parent = NULL;
@@ -769,6 +764,11 @@ MACHINE_END
769 764
770#ifdef CONFIG_MACH_UX500_DT 765#ifdef CONFIG_MACH_UX500_DT
771 766
767static struct platform_device *snowball_of_platform_devs[] __initdata = {
768 &snowball_led_dev,
769 &snowball_key_dev,
770};
771
772struct of_dev_auxdata u8500_auxdata_lookup[] __initdata = { 772struct of_dev_auxdata u8500_auxdata_lookup[] __initdata = {
773 /* Requires DMA and call-back bindings. */ 773 /* Requires DMA and call-back bindings. */
774 OF_DEV_AUXDATA("arm,pl011", 0x80120000, "uart0", &uart0_plat), 774 OF_DEV_AUXDATA("arm,pl011", 0x80120000, "uart0", &uart0_plat),
@@ -786,6 +786,8 @@ struct of_dev_auxdata u8500_auxdata_lookup[] __initdata = {
786 OF_DEV_AUXDATA("st,nomadik-gpio", 0x8011e000, "gpio.6", NULL), 786 OF_DEV_AUXDATA("st,nomadik-gpio", 0x8011e000, "gpio.6", NULL),
787 OF_DEV_AUXDATA("st,nomadik-gpio", 0x8011e080, "gpio.7", NULL), 787 OF_DEV_AUXDATA("st,nomadik-gpio", 0x8011e080, "gpio.7", NULL),
788 OF_DEV_AUXDATA("st,nomadik-gpio", 0xa03fe000, "gpio.8", NULL), 788 OF_DEV_AUXDATA("st,nomadik-gpio", 0xa03fe000, "gpio.8", NULL),
789 /* Requires device name bindings. */
790 OF_DEV_AUXDATA("stericsson,nmk_pinctrl", 0, "pinctrl-db8500", NULL),
789 {}, 791 {},
790}; 792};
791 793
diff --git a/arch/arm/mach-ux500/timer.c b/arch/arm/mach-ux500/timer.c
index 741e71feca78..66e7f00884ab 100644
--- a/arch/arm/mach-ux500/timer.c
+++ b/arch/arm/mach-ux500/timer.c
@@ -63,8 +63,10 @@ static void __init ux500_timer_init(void)
63 63
64 /* TODO: Once MTU has been DT:ed place code above into else. */ 64 /* TODO: Once MTU has been DT:ed place code above into else. */
65 if (of_have_populated_dt()) { 65 if (of_have_populated_dt()) {
66#ifdef CONFIG_OF
66 np = of_find_matching_node(NULL, prcmu_timer_of_match); 67 np = of_find_matching_node(NULL, prcmu_timer_of_match);
67 if (!np) 68 if (!np)
69#endif
68 goto dt_fail; 70 goto dt_fail;
69 71
70 tmp_base = of_iomap(np, 0); 72 tmp_base = of_iomap(np, 0);
diff --git a/arch/arm/mach-versatile/pci.c b/arch/arm/mach-versatile/pci.c
index bec933b04ef0..e95bf84cc837 100644
--- a/arch/arm/mach-versatile/pci.c
+++ b/arch/arm/mach-versatile/pci.c
@@ -339,7 +339,6 @@ void __init pci_versatile_preinit(void)
339static int __init versatile_map_irq(const struct pci_dev *dev, u8 slot, u8 pin) 339static int __init versatile_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
340{ 340{
341 int irq; 341 int irq;
342 int devslot = PCI_SLOT(dev->devfn);
343 342
344 /* slot, pin, irq 343 /* slot, pin, irq
345 * 24 1 27 344 * 24 1 27
diff --git a/arch/arm/mm/mm.h b/arch/arm/mm/mm.h
index c471436c7952..2e8a1efdf7b8 100644
--- a/arch/arm/mm/mm.h
+++ b/arch/arm/mm/mm.h
@@ -64,7 +64,7 @@ extern void __flush_dcache_page(struct address_space *mapping, struct page *page
64#ifdef CONFIG_ZONE_DMA 64#ifdef CONFIG_ZONE_DMA
65extern phys_addr_t arm_dma_limit; 65extern phys_addr_t arm_dma_limit;
66#else 66#else
67#define arm_dma_limit ((u32)~0) 67#define arm_dma_limit ((phys_addr_t)~0)
68#endif 68#endif
69 69
70extern phys_addr_t arm_lowmem_limit; 70extern phys_addr_t arm_lowmem_limit;
diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
index e5dad60b558b..cf4528d51774 100644
--- a/arch/arm/mm/mmu.c
+++ b/arch/arm/mm/mmu.c
@@ -791,6 +791,79 @@ void __init iotable_init(struct map_desc *io_desc, int nr)
791 } 791 }
792} 792}
793 793
794#ifndef CONFIG_ARM_LPAE
795
796/*
797 * The Linux PMD is made of two consecutive section entries covering 2MB
798 * (see definition in include/asm/pgtable-2level.h). However a call to
799 * create_mapping() may optimize static mappings by using individual
800 * 1MB section mappings. This leaves the actual PMD potentially half
801 * initialized if the top or bottom section entry isn't used, leaving it
802 * open to problems if a subsequent ioremap() or vmalloc() tries to use
803 * the virtual space left free by that unused section entry.
804 *
805 * Let's avoid the issue by inserting dummy vm entries covering the unused
806 * PMD halves once the static mappings are in place.
807 */
808
809static void __init pmd_empty_section_gap(unsigned long addr)
810{
811 struct vm_struct *vm;
812
813 vm = early_alloc_aligned(sizeof(*vm), __alignof__(*vm));
814 vm->addr = (void *)addr;
815 vm->size = SECTION_SIZE;
816 vm->flags = VM_IOREMAP | VM_ARM_STATIC_MAPPING;
817 vm->caller = pmd_empty_section_gap;
818 vm_area_add_early(vm);
819}
820
821static void __init fill_pmd_gaps(void)
822{
823 struct vm_struct *vm;
824 unsigned long addr, next = 0;
825 pmd_t *pmd;
826
827 /* we're still single threaded hence no lock needed here */
828 for (vm = vmlist; vm; vm = vm->next) {
829 if (!(vm->flags & VM_ARM_STATIC_MAPPING))
830 continue;
831 addr = (unsigned long)vm->addr;
832 if (addr < next)
833 continue;
834
835 /*
836 * Check if this vm starts on an odd section boundary.
837 * If so and the first section entry for this PMD is free
838 * then we block the corresponding virtual address.
839 */
840 if ((addr & ~PMD_MASK) == SECTION_SIZE) {
841 pmd = pmd_off_k(addr);
842 if (pmd_none(*pmd))
843 pmd_empty_section_gap(addr & PMD_MASK);
844 }
845
846 /*
847 * Then check if this vm ends on an odd section boundary.
848 * If so and the second section entry for this PMD is empty
849 * then we block the corresponding virtual address.
850 */
851 addr += vm->size;
852 if ((addr & ~PMD_MASK) == SECTION_SIZE) {
853 pmd = pmd_off_k(addr) + 1;
854 if (pmd_none(*pmd))
855 pmd_empty_section_gap(addr);
856 }
857
858 /* no need to look at any vm entry until we hit the next PMD */
859 next = (addr + PMD_SIZE - 1) & PMD_MASK;
860 }
861}
862
863#else
864#define fill_pmd_gaps() do { } while (0)
865#endif
866
794static void * __initdata vmalloc_min = 867static void * __initdata vmalloc_min =
795 (void *)(VMALLOC_END - (240 << 20) - VMALLOC_OFFSET); 868 (void *)(VMALLOC_END - (240 << 20) - VMALLOC_OFFSET);
796 869
@@ -1072,6 +1145,7 @@ static void __init devicemaps_init(struct machine_desc *mdesc)
1072 */ 1145 */
1073 if (mdesc->map_io) 1146 if (mdesc->map_io)
1074 mdesc->map_io(); 1147 mdesc->map_io();
1148 fill_pmd_gaps();
1075 1149
1076 /* 1150 /*
1077 * Finally flush the caches and tlb to ensure that we're in a 1151 * Finally flush the caches and tlb to ensure that we're in a
diff --git a/arch/arm/plat-samsung/adc.c b/arch/arm/plat-samsung/adc.c
index 33ecd0c9f0c3..b1e05ccff3ac 100644
--- a/arch/arm/plat-samsung/adc.c
+++ b/arch/arm/plat-samsung/adc.c
@@ -157,11 +157,13 @@ int s3c_adc_start(struct s3c_adc_client *client,
157 return -EINVAL; 157 return -EINVAL;
158 } 158 }
159 159
160 if (client->is_ts && adc->ts_pend)
161 return -EAGAIN;
162
163 spin_lock_irqsave(&adc->lock, flags); 160 spin_lock_irqsave(&adc->lock, flags);
164 161
162 if (client->is_ts && adc->ts_pend) {
163 spin_unlock_irqrestore(&adc->lock, flags);
164 return -EAGAIN;
165 }
166
165 client->channel = channel; 167 client->channel = channel;
166 client->nr_samples = nr_samples; 168 client->nr_samples = nr_samples;
167 169
diff --git a/arch/arm/plat-samsung/devs.c b/arch/arm/plat-samsung/devs.c
index 1d214cb9d770..6303974c2ee0 100644
--- a/arch/arm/plat-samsung/devs.c
+++ b/arch/arm/plat-samsung/devs.c
@@ -126,7 +126,8 @@ struct platform_device s3c_device_adc = {
126#ifdef CONFIG_CPU_S3C2440 126#ifdef CONFIG_CPU_S3C2440
127static struct resource s3c_camif_resource[] = { 127static struct resource s3c_camif_resource[] = {
128 [0] = DEFINE_RES_MEM(S3C2440_PA_CAMIF, S3C2440_SZ_CAMIF), 128 [0] = DEFINE_RES_MEM(S3C2440_PA_CAMIF, S3C2440_SZ_CAMIF),
129 [1] = DEFINE_RES_IRQ(IRQ_CAM), 129 [1] = DEFINE_RES_IRQ(IRQ_S3C2440_CAM_C),
130 [2] = DEFINE_RES_IRQ(IRQ_S3C2440_CAM_P),
130}; 131};
131 132
132struct platform_device s3c_device_camif = { 133struct platform_device s3c_device_camif = {
diff --git a/arch/arm/plat-samsung/s5p-clock.c b/arch/arm/plat-samsung/s5p-clock.c
index 031a61899bef..48a159911037 100644
--- a/arch/arm/plat-samsung/s5p-clock.c
+++ b/arch/arm/plat-samsung/s5p-clock.c
@@ -37,6 +37,7 @@ struct clk clk_ext_xtal_mux = {
37struct clk clk_xusbxti = { 37struct clk clk_xusbxti = {
38 .name = "xusbxti", 38 .name = "xusbxti",
39 .id = -1, 39 .id = -1,
40 .rate = 24000000,
40}; 41};
41 42
42struct clk s5p_clk_27m = { 43struct clk s5p_clk_27m = {
diff --git a/arch/h8300/include/asm/pgtable.h b/arch/h8300/include/asm/pgtable.h
index a09230a08e02..62ef17676b40 100644
--- a/arch/h8300/include/asm/pgtable.h
+++ b/arch/h8300/include/asm/pgtable.h
@@ -70,4 +70,7 @@ extern int is_in_rom(unsigned long);
70#define VMALLOC_END 0xffffffff 70#define VMALLOC_END 0xffffffff
71 71
72#define arch_enter_lazy_cpu_mode() do {} while (0) 72#define arch_enter_lazy_cpu_mode() do {} while (0)
73
74#include <asm-generic/pgtable.h>
75
73#endif /* _H8300_PGTABLE_H */ 76#endif /* _H8300_PGTABLE_H */
diff --git a/arch/h8300/include/asm/uaccess.h b/arch/h8300/include/asm/uaccess.h
index 356068cd0879..8725d1ad4272 100644
--- a/arch/h8300/include/asm/uaccess.h
+++ b/arch/h8300/include/asm/uaccess.h
@@ -100,7 +100,6 @@ extern int __put_user_bad(void);
100 break; \ 100 break; \
101 default: \ 101 default: \
102 __gu_err = __get_user_bad(); \ 102 __gu_err = __get_user_bad(); \
103 __gu_val = 0; \
104 break; \ 103 break; \
105 } \ 104 } \
106 (x) = __gu_val; \ 105 (x) = __gu_val; \
@@ -159,4 +158,6 @@ clear_user(void *to, unsigned long n)
159 return 0; 158 return 0;
160} 159}
161 160
161#define __clear_user clear_user
162
162#endif /* _H8300_UACCESS_H */ 163#endif /* _H8300_UACCESS_H */
diff --git a/arch/h8300/kernel/signal.c b/arch/h8300/kernel/signal.c
index fca10378701b..5adaadaf9218 100644
--- a/arch/h8300/kernel/signal.c
+++ b/arch/h8300/kernel/signal.c
@@ -447,7 +447,7 @@ handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
447 * want to handle. Thus you cannot kill init even with a SIGKILL even by 447 * want to handle. Thus you cannot kill init even with a SIGKILL even by
448 * mistake. 448 * mistake.
449 */ 449 */
450statis void do_signal(struct pt_regs *regs) 450static void do_signal(struct pt_regs *regs)
451{ 451{
452 siginfo_t info; 452 siginfo_t info;
453 int signr; 453 int signr;
diff --git a/arch/h8300/kernel/time.c b/arch/h8300/kernel/time.c
index 32263a138aa6..e0f74191d553 100644
--- a/arch/h8300/kernel/time.c
+++ b/arch/h8300/kernel/time.c
@@ -27,6 +27,7 @@
27#include <linux/profile.h> 27#include <linux/profile.h>
28 28
29#include <asm/io.h> 29#include <asm/io.h>
30#include <asm/irq_regs.h>
30#include <asm/timer.h> 31#include <asm/timer.h>
31 32
32#define TICK_SIZE (tick_nsec / 1000) 33#define TICK_SIZE (tick_nsec / 1000)
diff --git a/arch/mips/pci/pci-lantiq.c b/arch/mips/pci/pci-lantiq.c
index ea453532a33c..075d87acd12a 100644
--- a/arch/mips/pci/pci-lantiq.c
+++ b/arch/mips/pci/pci-lantiq.c
@@ -129,7 +129,7 @@ static int __devinit ltq_pci_startup(struct platform_device *pdev)
129 129
130 /* setup reset gpio used by pci */ 130 /* setup reset gpio used by pci */
131 reset_gpio = of_get_named_gpio(node, "gpio-reset", 0); 131 reset_gpio = of_get_named_gpio(node, "gpio-reset", 0);
132 if (reset_gpio > 0) 132 if (gpio_is_valid(reset_gpio))
133 devm_gpio_request(&pdev->dev, reset_gpio, "pci-reset"); 133 devm_gpio_request(&pdev->dev, reset_gpio, "pci-reset");
134 134
135 /* enable auto-switching between PCI and EBU */ 135 /* enable auto-switching between PCI and EBU */
@@ -192,7 +192,7 @@ static int __devinit ltq_pci_startup(struct platform_device *pdev)
192 ltq_ebu_w32(ltq_ebu_r32(LTQ_EBU_PCC_IEN) | 0x10, LTQ_EBU_PCC_IEN); 192 ltq_ebu_w32(ltq_ebu_r32(LTQ_EBU_PCC_IEN) | 0x10, LTQ_EBU_PCC_IEN);
193 193
194 /* toggle reset pin */ 194 /* toggle reset pin */
195 if (reset_gpio > 0) { 195 if (gpio_is_valid(reset_gpio)) {
196 __gpio_set_value(reset_gpio, 0); 196 __gpio_set_value(reset_gpio, 0);
197 wmb(); 197 wmb();
198 mdelay(1); 198 mdelay(1);
diff --git a/arch/mn10300/include/asm/ptrace.h b/arch/mn10300/include/asm/ptrace.h
index 55b79ef10028..44251b974f1d 100644
--- a/arch/mn10300/include/asm/ptrace.h
+++ b/arch/mn10300/include/asm/ptrace.h
@@ -81,9 +81,6 @@ struct pt_regs {
81#define PTRACE_GETFPREGS 14 81#define PTRACE_GETFPREGS 14
82#define PTRACE_SETFPREGS 15 82#define PTRACE_SETFPREGS 15
83 83
84/* options set using PTRACE_SETOPTIONS */
85#define PTRACE_O_TRACESYSGOOD 0x00000001
86
87#ifdef __KERNEL__ 84#ifdef __KERNEL__
88 85
89#define user_mode(regs) (((regs)->epsw & EPSW_nSL) == EPSW_nSL) 86#define user_mode(regs) (((regs)->epsw & EPSW_nSL) == EPSW_nSL)
diff --git a/arch/mn10300/include/asm/thread_info.h b/arch/mn10300/include/asm/thread_info.h
index 08251d6f6b11..ac519bbd42ff 100644
--- a/arch/mn10300/include/asm/thread_info.h
+++ b/arch/mn10300/include/asm/thread_info.h
@@ -123,7 +123,7 @@ static inline unsigned long current_stack_pointer(void)
123} 123}
124 124
125#ifndef CONFIG_KGDB 125#ifndef CONFIG_KGDB
126void arch_release_thread_info(struct thread_info *ti) 126void arch_release_thread_info(struct thread_info *ti);
127#endif 127#endif
128#define get_thread_info(ti) get_task_struct((ti)->task) 128#define get_thread_info(ti) get_task_struct((ti)->task)
129#define put_thread_info(ti) put_task_struct((ti)->task) 129#define put_thread_info(ti) put_task_struct((ti)->task)
diff --git a/arch/mn10300/include/asm/timex.h b/arch/mn10300/include/asm/timex.h
index bd4e90dfe6c2..f8e66425cbf8 100644
--- a/arch/mn10300/include/asm/timex.h
+++ b/arch/mn10300/include/asm/timex.h
@@ -11,7 +11,6 @@
11#ifndef _ASM_TIMEX_H 11#ifndef _ASM_TIMEX_H
12#define _ASM_TIMEX_H 12#define _ASM_TIMEX_H
13 13
14#include <asm/hardirq.h>
15#include <unit/timex.h> 14#include <unit/timex.h>
16 15
17#define TICK_SIZE (tick_nsec / 1000) 16#define TICK_SIZE (tick_nsec / 1000)
@@ -30,16 +29,6 @@ static inline cycles_t get_cycles(void)
30extern int init_clockevents(void); 29extern int init_clockevents(void);
31extern int init_clocksource(void); 30extern int init_clocksource(void);
32 31
33static inline void setup_jiffies_interrupt(int irq,
34 struct irqaction *action)
35{
36 u16 tmp;
37 setup_irq(irq, action);
38 set_intr_level(irq, NUM2GxICR_LEVEL(CONFIG_TIMER_IRQ_LEVEL));
39 GxICR(irq) |= GxICR_ENABLE | GxICR_DETECT | GxICR_REQUEST;
40 tmp = GxICR(irq);
41}
42
43#endif /* __KERNEL__ */ 32#endif /* __KERNEL__ */
44 33
45#endif /* _ASM_TIMEX_H */ 34#endif /* _ASM_TIMEX_H */
diff --git a/arch/mn10300/kernel/cevt-mn10300.c b/arch/mn10300/kernel/cevt-mn10300.c
index 69cae0260786..ccce35e3e179 100644
--- a/arch/mn10300/kernel/cevt-mn10300.c
+++ b/arch/mn10300/kernel/cevt-mn10300.c
@@ -70,6 +70,16 @@ static void event_handler(struct clock_event_device *dev)
70{ 70{
71} 71}
72 72
73static inline void setup_jiffies_interrupt(int irq,
74 struct irqaction *action)
75{
76 u16 tmp;
77 setup_irq(irq, action);
78 set_intr_level(irq, NUM2GxICR_LEVEL(CONFIG_TIMER_IRQ_LEVEL));
79 GxICR(irq) |= GxICR_ENABLE | GxICR_DETECT | GxICR_REQUEST;
80 tmp = GxICR(irq);
81}
82
73int __init init_clockevents(void) 83int __init init_clockevents(void)
74{ 84{
75 struct clock_event_device *cd; 85 struct clock_event_device *cd;
diff --git a/arch/mn10300/kernel/internal.h b/arch/mn10300/kernel/internal.h
index a5ac755dd69f..2df440105a80 100644
--- a/arch/mn10300/kernel/internal.h
+++ b/arch/mn10300/kernel/internal.h
@@ -9,6 +9,8 @@
9 * 2 of the Licence, or (at your option) any later version. 9 * 2 of the Licence, or (at your option) any later version.
10 */ 10 */
11 11
12#include <linux/irqreturn.h>
13
12struct clocksource; 14struct clocksource;
13struct clock_event_device; 15struct clock_event_device;
14 16
diff --git a/arch/mn10300/kernel/irq.c b/arch/mn10300/kernel/irq.c
index 2381df83bd00..35932a8de8b8 100644
--- a/arch/mn10300/kernel/irq.c
+++ b/arch/mn10300/kernel/irq.c
@@ -170,9 +170,9 @@ mn10300_cpupic_setaffinity(struct irq_data *d, const struct cpumask *mask,
170 case SC1TXIRQ: 170 case SC1TXIRQ:
171#ifdef CONFIG_MN10300_TTYSM1_TIMER12 171#ifdef CONFIG_MN10300_TTYSM1_TIMER12
172 case TM12IRQ: 172 case TM12IRQ:
173#elif CONFIG_MN10300_TTYSM1_TIMER9 173#elif defined(CONFIG_MN10300_TTYSM1_TIMER9)
174 case TM9IRQ: 174 case TM9IRQ:
175#elif CONFIG_MN10300_TTYSM1_TIMER3 175#elif defined(CONFIG_MN10300_TTYSM1_TIMER3)
176 case TM3IRQ: 176 case TM3IRQ:
177#endif /* CONFIG_MN10300_TTYSM1_TIMER12 */ 177#endif /* CONFIG_MN10300_TTYSM1_TIMER12 */
178#endif /* CONFIG_MN10300_TTYSM1 */ 178#endif /* CONFIG_MN10300_TTYSM1 */
diff --git a/arch/mn10300/kernel/traps.c b/arch/mn10300/kernel/traps.c
index 94a9c6d53e1b..b900e5afa0ae 100644
--- a/arch/mn10300/kernel/traps.c
+++ b/arch/mn10300/kernel/traps.c
@@ -26,6 +26,7 @@
26#include <linux/kdebug.h> 26#include <linux/kdebug.h>
27#include <linux/bug.h> 27#include <linux/bug.h>
28#include <linux/irq.h> 28#include <linux/irq.h>
29#include <linux/export.h>
29#include <asm/processor.h> 30#include <asm/processor.h>
30#include <linux/uaccess.h> 31#include <linux/uaccess.h>
31#include <asm/io.h> 32#include <asm/io.h>
diff --git a/arch/mn10300/mm/dma-alloc.c b/arch/mn10300/mm/dma-alloc.c
index 159acb02cfd4..e244ebe637e1 100644
--- a/arch/mn10300/mm/dma-alloc.c
+++ b/arch/mn10300/mm/dma-alloc.c
@@ -15,6 +15,7 @@
15#include <linux/string.h> 15#include <linux/string.h>
16#include <linux/pci.h> 16#include <linux/pci.h>
17#include <linux/gfp.h> 17#include <linux/gfp.h>
18#include <linux/export.h>
18#include <asm/io.h> 19#include <asm/io.h>
19 20
20static unsigned long pci_sram_allocated = 0xbc000000; 21static unsigned long pci_sram_allocated = 0xbc000000;
diff --git a/arch/mn10300/unit-asb2303/include/unit/timex.h b/arch/mn10300/unit-asb2303/include/unit/timex.h
index cc18fe7d8b90..c37f9832cf17 100644
--- a/arch/mn10300/unit-asb2303/include/unit/timex.h
+++ b/arch/mn10300/unit-asb2303/include/unit/timex.h
@@ -11,10 +11,6 @@
11#ifndef _ASM_UNIT_TIMEX_H 11#ifndef _ASM_UNIT_TIMEX_H
12#define _ASM_UNIT_TIMEX_H 12#define _ASM_UNIT_TIMEX_H
13 13
14#ifndef __ASSEMBLY__
15#include <linux/irq.h>
16#endif /* __ASSEMBLY__ */
17
18#include <asm/timer-regs.h> 14#include <asm/timer-regs.h>
19#include <unit/clock.h> 15#include <unit/clock.h>
20#include <asm/param.h> 16#include <asm/param.h>
diff --git a/arch/mn10300/unit-asb2303/smc91111.c b/arch/mn10300/unit-asb2303/smc91111.c
index 43c246439413..53677694b165 100644
--- a/arch/mn10300/unit-asb2303/smc91111.c
+++ b/arch/mn10300/unit-asb2303/smc91111.c
@@ -15,6 +15,7 @@
15#include <linux/platform_device.h> 15#include <linux/platform_device.h>
16 16
17#include <asm/io.h> 17#include <asm/io.h>
18#include <asm/irq.h>
18#include <asm/timex.h> 19#include <asm/timex.h>
19#include <asm/processor.h> 20#include <asm/processor.h>
20#include <asm/intctl-regs.h> 21#include <asm/intctl-regs.h>
diff --git a/arch/mn10300/unit-asb2305/include/unit/timex.h b/arch/mn10300/unit-asb2305/include/unit/timex.h
index 758af30d1a16..4cefc224f448 100644
--- a/arch/mn10300/unit-asb2305/include/unit/timex.h
+++ b/arch/mn10300/unit-asb2305/include/unit/timex.h
@@ -11,10 +11,6 @@
11#ifndef _ASM_UNIT_TIMEX_H 11#ifndef _ASM_UNIT_TIMEX_H
12#define _ASM_UNIT_TIMEX_H 12#define _ASM_UNIT_TIMEX_H
13 13
14#ifndef __ASSEMBLY__
15#include <linux/irq.h>
16#endif /* __ASSEMBLY__ */
17
18#include <asm/timer-regs.h> 14#include <asm/timer-regs.h>
19#include <unit/clock.h> 15#include <unit/clock.h>
20#include <asm/param.h> 16#include <asm/param.h>
diff --git a/arch/mn10300/unit-asb2305/unit-init.c b/arch/mn10300/unit-asb2305/unit-init.c
index e1becd6b7571..bc4adfaf815c 100644
--- a/arch/mn10300/unit-asb2305/unit-init.c
+++ b/arch/mn10300/unit-asb2305/unit-init.c
@@ -13,6 +13,7 @@
13#include <linux/init.h> 13#include <linux/init.h>
14#include <linux/pci.h> 14#include <linux/pci.h>
15#include <asm/io.h> 15#include <asm/io.h>
16#include <asm/irq.h>
16#include <asm/setup.h> 17#include <asm/setup.h>
17#include <asm/processor.h> 18#include <asm/processor.h>
18#include <asm/intctl-regs.h> 19#include <asm/intctl-regs.h>
diff --git a/arch/mn10300/unit-asb2364/include/unit/timex.h b/arch/mn10300/unit-asb2364/include/unit/timex.h
index ddb7ed010706..42f32db75087 100644
--- a/arch/mn10300/unit-asb2364/include/unit/timex.h
+++ b/arch/mn10300/unit-asb2364/include/unit/timex.h
@@ -11,10 +11,6 @@
11#ifndef _ASM_UNIT_TIMEX_H 11#ifndef _ASM_UNIT_TIMEX_H
12#define _ASM_UNIT_TIMEX_H 12#define _ASM_UNIT_TIMEX_H
13 13
14#ifndef __ASSEMBLY__
15#include <linux/irq.h>
16#endif /* __ASSEMBLY__ */
17
18#include <asm/timer-regs.h> 14#include <asm/timer-regs.h>
19#include <unit/clock.h> 15#include <unit/clock.h>
20#include <asm/param.h> 16#include <asm/param.h>
diff --git a/arch/powerpc/include/asm/hw_irq.h b/arch/powerpc/include/asm/hw_irq.h
index 6eb75b80488c..0554ab062bdc 100644
--- a/arch/powerpc/include/asm/hw_irq.h
+++ b/arch/powerpc/include/asm/hw_irq.h
@@ -86,8 +86,8 @@ static inline bool arch_irqs_disabled(void)
86} 86}
87 87
88#ifdef CONFIG_PPC_BOOK3E 88#ifdef CONFIG_PPC_BOOK3E
89#define __hard_irq_enable() asm volatile("wrteei 1" : : : "memory"); 89#define __hard_irq_enable() asm volatile("wrteei 1" : : : "memory")
90#define __hard_irq_disable() asm volatile("wrteei 0" : : : "memory"); 90#define __hard_irq_disable() asm volatile("wrteei 0" : : : "memory")
91#else 91#else
92#define __hard_irq_enable() __mtmsrd(local_paca->kernel_msr | MSR_EE, 1) 92#define __hard_irq_enable() __mtmsrd(local_paca->kernel_msr | MSR_EE, 1)
93#define __hard_irq_disable() __mtmsrd(local_paca->kernel_msr, 1) 93#define __hard_irq_disable() __mtmsrd(local_paca->kernel_msr, 1)
@@ -125,6 +125,8 @@ static inline bool arch_irq_disabled_regs(struct pt_regs *regs)
125 return !regs->softe; 125 return !regs->softe;
126} 126}
127 127
128extern bool prep_irq_for_idle(void);
129
128#else /* CONFIG_PPC64 */ 130#else /* CONFIG_PPC64 */
129 131
130#define SET_MSR_EE(x) mtmsr(x) 132#define SET_MSR_EE(x) mtmsr(x)
diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
index 1b415027ec0e..1f017bb7a7ce 100644
--- a/arch/powerpc/kernel/irq.c
+++ b/arch/powerpc/kernel/irq.c
@@ -229,7 +229,7 @@ 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 232#ifdef CONFIG_TRACE_IRQFLAGS
233 else { 233 else {
234 /* 234 /*
235 * We should already be hard disabled here. We had bugs 235 * We should already be hard disabled here. We had bugs
@@ -286,6 +286,52 @@ void notrace restore_interrupts(void)
286 __hard_irq_enable(); 286 __hard_irq_enable();
287} 287}
288 288
289/*
290 * This is a helper to use when about to go into idle low-power
291 * when the latter has the side effect of re-enabling interrupts
292 * (such as calling H_CEDE under pHyp).
293 *
294 * You call this function with interrupts soft-disabled (this is
295 * already the case when ppc_md.power_save is called). The function
296 * will return whether to enter power save or just return.
297 *
298 * In the former case, it will have notified lockdep of interrupts
299 * being re-enabled and generally sanitized the lazy irq state,
300 * and in the latter case it will leave with interrupts hard
301 * disabled and marked as such, so the local_irq_enable() call
302 * in cpu_idle() will properly re-enable everything.
303 */
304bool prep_irq_for_idle(void)
305{
306 /*
307 * First we need to hard disable to ensure no interrupt
308 * occurs before we effectively enter the low power state
309 */
310 hard_irq_disable();
311
312 /*
313 * If anything happened while we were soft-disabled,
314 * we return now and do not enter the low power state.
315 */
316 if (lazy_irq_pending())
317 return false;
318
319 /* Tell lockdep we are about to re-enable */
320 trace_hardirqs_on();
321
322 /*
323 * Mark interrupts as soft-enabled and clear the
324 * PACA_IRQ_HARD_DIS from the pending mask since we
325 * are about to hard enable as well as a side effect
326 * of entering the low power state.
327 */
328 local_paca->irq_happened &= ~PACA_IRQ_HARD_DIS;
329 local_paca->soft_enabled = 1;
330
331 /* Tell the caller to enter the low power state */
332 return true;
333}
334
289#endif /* CONFIG_PPC64 */ 335#endif /* CONFIG_PPC64 */
290 336
291int arch_show_interrupts(struct seq_file *p, int prec) 337int arch_show_interrupts(struct seq_file *p, int prec)
diff --git a/arch/powerpc/kvm/book3s_hv_rmhandlers.S b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
index a84aafce2a12..a1044f43becd 100644
--- a/arch/powerpc/kvm/book3s_hv_rmhandlers.S
+++ b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
@@ -810,7 +810,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
810 lwz r3,VCORE_NAPPING_THREADS(r5) 810 lwz r3,VCORE_NAPPING_THREADS(r5)
811 lwz r4,VCPU_PTID(r9) 811 lwz r4,VCPU_PTID(r9)
812 li r0,1 812 li r0,1
813 sldi r0,r0,r4 813 sld r0,r0,r4
814 andc. r3,r3,r0 /* no sense IPI'ing ourselves */ 814 andc. r3,r3,r0 /* no sense IPI'ing ourselves */
815 beq 43f 815 beq 43f
816 mulli r4,r4,PACA_SIZE /* get paca for thread 0 */ 816 mulli r4,r4,PACA_SIZE /* get paca for thread 0 */
diff --git a/arch/powerpc/kvm/book3s_pr_papr.c b/arch/powerpc/kvm/book3s_pr_papr.c
index 3ff9013d6e79..ee02b30878ed 100644
--- a/arch/powerpc/kvm/book3s_pr_papr.c
+++ b/arch/powerpc/kvm/book3s_pr_papr.c
@@ -241,6 +241,7 @@ int kvmppc_h_pr(struct kvm_vcpu *vcpu, unsigned long cmd)
241 case H_PUT_TCE: 241 case H_PUT_TCE:
242 return kvmppc_h_pr_put_tce(vcpu); 242 return kvmppc_h_pr_put_tce(vcpu);
243 case H_CEDE: 243 case H_CEDE:
244 vcpu->arch.shared->msr |= MSR_EE;
244 kvm_vcpu_block(vcpu); 245 kvm_vcpu_block(vcpu);
245 clear_bit(KVM_REQ_UNHALT, &vcpu->requests); 246 clear_bit(KVM_REQ_UNHALT, &vcpu->requests);
246 vcpu->stat.halt_wakeup++; 247 vcpu->stat.halt_wakeup++;
diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
index 6e8f677f5646..1e95556dc692 100644
--- a/arch/powerpc/mm/numa.c
+++ b/arch/powerpc/mm/numa.c
@@ -639,7 +639,7 @@ static void __init parse_drconf_memory(struct device_node *memory)
639 unsigned int n, rc, ranges, is_kexec_kdump = 0; 639 unsigned int n, rc, ranges, is_kexec_kdump = 0;
640 unsigned long lmb_size, base, size, sz; 640 unsigned long lmb_size, base, size, sz;
641 int nid; 641 int nid;
642 struct assoc_arrays aa; 642 struct assoc_arrays aa = { .arrays = NULL };
643 643
644 n = of_get_drconf_memory(memory, &dm); 644 n = of_get_drconf_memory(memory, &dm);
645 if (!n) 645 if (!n)
diff --git a/arch/powerpc/platforms/cell/pervasive.c b/arch/powerpc/platforms/cell/pervasive.c
index efdacc829576..d17e98bc0c10 100644
--- a/arch/powerpc/platforms/cell/pervasive.c
+++ b/arch/powerpc/platforms/cell/pervasive.c
@@ -42,11 +42,9 @@ static void cbe_power_save(void)
42{ 42{
43 unsigned long ctrl, thread_switch_control; 43 unsigned long ctrl, thread_switch_control;
44 44
45 /* 45 /* Ensure our interrupt state is properly tracked */
46 * We need to hard disable interrupts, the local_irq_enable() done by 46 if (!prep_irq_for_idle())
47 * our caller upon return will hard re-enable. 47 return;
48 */
49 hard_irq_disable();
50 48
51 ctrl = mfspr(SPRN_CTRLF); 49 ctrl = mfspr(SPRN_CTRLF);
52 50
@@ -81,6 +79,9 @@ static void cbe_power_save(void)
81 */ 79 */
82 ctrl &= ~(CTRL_RUNLATCH | CTRL_TE); 80 ctrl &= ~(CTRL_RUNLATCH | CTRL_TE);
83 mtspr(SPRN_CTRLT, ctrl); 81 mtspr(SPRN_CTRLT, ctrl);
82
83 /* Re-enable interrupts in MSR */
84 __hard_irq_enable();
84} 85}
85 86
86static int cbe_system_reset_exception(struct pt_regs *regs) 87static int cbe_system_reset_exception(struct pt_regs *regs)
diff --git a/arch/powerpc/platforms/pseries/processor_idle.c b/arch/powerpc/platforms/pseries/processor_idle.c
index e61483e8e960..c71be66bd5dc 100644
--- a/arch/powerpc/platforms/pseries/processor_idle.c
+++ b/arch/powerpc/platforms/pseries/processor_idle.c
@@ -99,15 +99,18 @@ out:
99static void check_and_cede_processor(void) 99static void check_and_cede_processor(void)
100{ 100{
101 /* 101 /*
102 * Interrupts are soft-disabled at this point, 102 * Ensure our interrupt state is properly tracked,
103 * but not hard disabled. So an interrupt might have 103 * also checks if no interrupt has occurred while we
104 * occurred before entering NAP, and would be potentially 104 * were soft-disabled
105 * lost (edge events, decrementer events, etc...) unless
106 * we first hard disable then check.
107 */ 105 */
108 hard_irq_disable(); 106 if (prep_irq_for_idle()) {
109 if (!lazy_irq_pending())
110 cede_processor(); 107 cede_processor();
108#ifdef CONFIG_TRACE_IRQFLAGS
109 /* Ensure that H_CEDE returns with IRQs on */
110 if (WARN_ON(!(mfmsr() & MSR_EE)))
111 __hard_irq_enable();
112#endif
113 }
111} 114}
112 115
113static int dedicated_cede_loop(struct cpuidle_device *dev, 116static int dedicated_cede_loop(struct cpuidle_device *dev,
diff --git a/arch/powerpc/xmon/xmon.c b/arch/powerpc/xmon/xmon.c
index 0f3ab06d2222..eab3492a45c5 100644
--- a/arch/powerpc/xmon/xmon.c
+++ b/arch/powerpc/xmon/xmon.c
@@ -971,7 +971,7 @@ static int cpu_cmd(void)
971 /* print cpus waiting or in xmon */ 971 /* print cpus waiting or in xmon */
972 printf("cpus stopped:"); 972 printf("cpus stopped:");
973 count = 0; 973 count = 0;
974 for (cpu = 0; cpu < NR_CPUS; ++cpu) { 974 for_each_possible_cpu(cpu) {
975 if (cpumask_test_cpu(cpu, &cpus_in_xmon)) { 975 if (cpumask_test_cpu(cpu, &cpus_in_xmon)) {
976 if (count == 0) 976 if (count == 0)
977 printf(" %x", cpu); 977 printf(" %x", cpu);
diff --git a/arch/sh/include/asm/io_noioport.h b/arch/sh/include/asm/io_noioport.h
index e136d28d1d2e..4d48f1436a63 100644
--- a/arch/sh/include/asm/io_noioport.h
+++ b/arch/sh/include/asm/io_noioport.h
@@ -19,9 +19,20 @@ static inline u32 inl(unsigned long addr)
19 return -1; 19 return -1;
20} 20}
21 21
22#define outb(x, y) BUG() 22static inline void outb(unsigned char x, unsigned long port)
23#define outw(x, y) BUG() 23{
24#define outl(x, y) BUG() 24 BUG();
25}
26
27static inline void outw(unsigned short x, unsigned long port)
28{
29 BUG();
30}
31
32static inline void outl(unsigned int x, unsigned long port)
33{
34 BUG();
35}
25 36
26#define inb_p(addr) inb(addr) 37#define inb_p(addr) inb(addr)
27#define inw_p(addr) inw(addr) 38#define inw_p(addr) inw(addr)
diff --git a/arch/sh/kernel/cpu/sh3/serial-sh7720.c b/arch/sh/kernel/cpu/sh3/serial-sh7720.c
index 8832c526cdf9..c4a0336660dd 100644
--- a/arch/sh/kernel/cpu/sh3/serial-sh7720.c
+++ b/arch/sh/kernel/cpu/sh3/serial-sh7720.c
@@ -2,7 +2,7 @@
2#include <linux/serial_core.h> 2#include <linux/serial_core.h>
3#include <linux/io.h> 3#include <linux/io.h>
4#include <cpu/serial.h> 4#include <cpu/serial.h>
5#include <asm/gpio.h> 5#include <cpu/gpio.h>
6 6
7static void sh7720_sci_init_pins(struct uart_port *port, unsigned int cflag) 7static void sh7720_sci_init_pins(struct uart_port *port, unsigned int cflag)
8{ 8{
diff --git a/arch/tile/kernel/backtrace.c b/arch/tile/kernel/backtrace.c
index 9092ce8aa6b4..f8b74ca83b92 100644
--- a/arch/tile/kernel/backtrace.c
+++ b/arch/tile/kernel/backtrace.c
@@ -14,6 +14,7 @@
14 14
15#include <linux/kernel.h> 15#include <linux/kernel.h>
16#include <linux/string.h> 16#include <linux/string.h>
17#include <asm/byteorder.h>
17#include <asm/backtrace.h> 18#include <asm/backtrace.h>
18#include <asm/tile-desc.h> 19#include <asm/tile-desc.h>
19#include <arch/abi.h> 20#include <arch/abi.h>
@@ -336,8 +337,12 @@ static void find_caller_pc_and_caller_sp(CallerLocation *location,
336 bytes_to_prefetch / sizeof(tile_bundle_bits); 337 bytes_to_prefetch / sizeof(tile_bundle_bits);
337 } 338 }
338 339
339 /* Decode the next bundle. */ 340 /*
340 bundle.bits = prefetched_bundles[next_bundle++]; 341 * Decode the next bundle.
342 * TILE always stores instruction bundles in little-endian
343 * mode, even when the chip is running in big-endian mode.
344 */
345 bundle.bits = le64_to_cpu(prefetched_bundles[next_bundle++]);
341 bundle.num_insns = 346 bundle.num_insns =
342 parse_insn_tile(bundle.bits, pc, bundle.insns); 347 parse_insn_tile(bundle.bits, pc, bundle.insns);
343 num_info_ops = bt_get_info_ops(&bundle, info_operands); 348 num_info_ops = bt_get_info_ops(&bundle, info_operands);
diff --git a/arch/um/drivers/mconsole_kern.c b/arch/um/drivers/mconsole_kern.c
index 88e466b159dc..43b39d61b538 100644
--- a/arch/um/drivers/mconsole_kern.c
+++ b/arch/um/drivers/mconsole_kern.c
@@ -705,7 +705,6 @@ static void stack_proc(void *arg)
705 struct task_struct *from = current, *to = arg; 705 struct task_struct *from = current, *to = arg;
706 706
707 to->thread.saved_task = from; 707 to->thread.saved_task = from;
708 rcu_switch_from(from);
709 switch_to(from, to, from); 708 switch_to(from, to, from);
710} 709}
711 710
diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
index 7515cf0e1805..5db36caf4289 100644
--- a/arch/x86/kernel/vsyscall_64.c
+++ b/arch/x86/kernel/vsyscall_64.c
@@ -139,6 +139,19 @@ static int addr_to_vsyscall_nr(unsigned long addr)
139 return nr; 139 return nr;
140} 140}
141 141
142#ifdef CONFIG_SECCOMP
143static int vsyscall_seccomp(struct task_struct *tsk, int syscall_nr)
144{
145 if (!seccomp_mode(&tsk->seccomp))
146 return 0;
147 task_pt_regs(tsk)->orig_ax = syscall_nr;
148 task_pt_regs(tsk)->ax = syscall_nr;
149 return __secure_computing(syscall_nr);
150}
151#else
152#define vsyscall_seccomp(_tsk, _nr) 0
153#endif
154
142static bool write_ok_or_segv(unsigned long ptr, size_t size) 155static bool write_ok_or_segv(unsigned long ptr, size_t size)
143{ 156{
144 /* 157 /*
@@ -174,6 +187,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
174 int vsyscall_nr; 187 int vsyscall_nr;
175 int prev_sig_on_uaccess_error; 188 int prev_sig_on_uaccess_error;
176 long ret; 189 long ret;
190 int skip;
177 191
178 /* 192 /*
179 * No point in checking CS -- the only way to get here is a user mode 193 * No point in checking CS -- the only way to get here is a user mode
@@ -205,9 +219,6 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
205 } 219 }
206 220
207 tsk = current; 221 tsk = current;
208 if (seccomp_mode(&tsk->seccomp))
209 do_exit(SIGKILL);
210
211 /* 222 /*
212 * With a real vsyscall, page faults cause SIGSEGV. We want to 223 * With a real vsyscall, page faults cause SIGSEGV. We want to
213 * preserve that behavior to make writing exploits harder. 224 * preserve that behavior to make writing exploits harder.
@@ -222,8 +233,13 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
222 * address 0". 233 * address 0".
223 */ 234 */
224 ret = -EFAULT; 235 ret = -EFAULT;
236 skip = 0;
225 switch (vsyscall_nr) { 237 switch (vsyscall_nr) {
226 case 0: 238 case 0:
239 skip = vsyscall_seccomp(tsk, __NR_gettimeofday);
240 if (skip)
241 break;
242
227 if (!write_ok_or_segv(regs->di, sizeof(struct timeval)) || 243 if (!write_ok_or_segv(regs->di, sizeof(struct timeval)) ||
228 !write_ok_or_segv(regs->si, sizeof(struct timezone))) 244 !write_ok_or_segv(regs->si, sizeof(struct timezone)))
229 break; 245 break;
@@ -234,6 +250,10 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
234 break; 250 break;
235 251
236 case 1: 252 case 1:
253 skip = vsyscall_seccomp(tsk, __NR_time);
254 if (skip)
255 break;
256
237 if (!write_ok_or_segv(regs->di, sizeof(time_t))) 257 if (!write_ok_or_segv(regs->di, sizeof(time_t)))
238 break; 258 break;
239 259
@@ -241,6 +261,10 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
241 break; 261 break;
242 262
243 case 2: 263 case 2:
264 skip = vsyscall_seccomp(tsk, __NR_getcpu);
265 if (skip)
266 break;
267
244 if (!write_ok_or_segv(regs->di, sizeof(unsigned)) || 268 if (!write_ok_or_segv(regs->di, sizeof(unsigned)) ||
245 !write_ok_or_segv(regs->si, sizeof(unsigned))) 269 !write_ok_or_segv(regs->si, sizeof(unsigned)))
246 break; 270 break;
@@ -253,6 +277,12 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
253 277
254 current_thread_info()->sig_on_uaccess_error = prev_sig_on_uaccess_error; 278 current_thread_info()->sig_on_uaccess_error = prev_sig_on_uaccess_error;
255 279
280 if (skip) {
281 if ((long)regs->ax <= 0L) /* seccomp errno emulation */
282 goto do_ret;
283 goto done; /* seccomp trace/trap */
284 }
285
256 if (ret == -EFAULT) { 286 if (ret == -EFAULT) {
257 /* Bad news -- userspace fed a bad pointer to a vsyscall. */ 287 /* Bad news -- userspace fed a bad pointer to a vsyscall. */
258 warn_bad_vsyscall(KERN_INFO, regs, 288 warn_bad_vsyscall(KERN_INFO, regs,
@@ -271,10 +301,11 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
271 301
272 regs->ax = ret; 302 regs->ax = ret;
273 303
304do_ret:
274 /* Emulate a ret instruction. */ 305 /* Emulate a ret instruction. */
275 regs->ip = caller; 306 regs->ip = caller;
276 regs->sp += 8; 307 regs->sp += 8;
277 308done:
278 return true; 309 return true;
279 310
280sigsegv: 311sigsegv:
diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index be3cea4407ff..57e168e27b5b 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -3934,6 +3934,9 @@ static void kvm_mmu_remove_some_alloc_mmu_pages(struct kvm *kvm,
3934{ 3934{
3935 struct kvm_mmu_page *page; 3935 struct kvm_mmu_page *page;
3936 3936
3937 if (list_empty(&kvm->arch.active_mmu_pages))
3938 return;
3939
3937 page = container_of(kvm->arch.active_mmu_pages.prev, 3940 page = container_of(kvm->arch.active_mmu_pages.prev,
3938 struct kvm_mmu_page, link); 3941 struct kvm_mmu_page, link);
3939 kvm_mmu_prepare_zap_page(kvm, page, invalid_list); 3942 kvm_mmu_prepare_zap_page(kvm, page, invalid_list);
diff --git a/arch/xtensa/kernel/process.c b/arch/xtensa/kernel/process.c
index 9b306e550e3f..2c8d6a3d250a 100644
--- a/arch/xtensa/kernel/process.c
+++ b/arch/xtensa/kernel/process.c
@@ -277,7 +277,7 @@ void xtensa_elf_core_copy_regs (xtensa_gregset_t *elfregs, struct pt_regs *regs)
277 277
278 /* Don't leak any random bits. */ 278 /* Don't leak any random bits. */
279 279
280 memset(elfregs, 0, sizeof (elfregs)); 280 memset(elfregs, 0, sizeof(*elfregs));
281 281
282 /* Note: PS.EXCM is not set while user task is running; its 282 /* Note: PS.EXCM is not set while user task is running; its
283 * being set in regs->ps is for exception handling convenience. 283 * being set in regs->ps is for exception handling convenience.
diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index 02cf6335e9bd..e7dee617358e 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -125,12 +125,8 @@ static struct blkcg_gq *blkg_alloc(struct blkcg *blkcg, struct request_queue *q)
125 125
126 blkg->pd[i] = pd; 126 blkg->pd[i] = pd;
127 pd->blkg = blkg; 127 pd->blkg = blkg;
128 }
129
130 /* invoke per-policy init */
131 for (i = 0; i < BLKCG_MAX_POLS; i++) {
132 struct blkcg_policy *pol = blkcg_policy[i];
133 128
129 /* invoke per-policy init */
134 if (blkcg_policy_enabled(blkg->q, pol)) 130 if (blkcg_policy_enabled(blkg->q, pol))
135 pol->pd_init_fn(blkg); 131 pol->pd_init_fn(blkg);
136 } 132 }
@@ -245,10 +241,9 @@ EXPORT_SYMBOL_GPL(blkg_lookup_create);
245 241
246static void blkg_destroy(struct blkcg_gq *blkg) 242static void blkg_destroy(struct blkcg_gq *blkg)
247{ 243{
248 struct request_queue *q = blkg->q;
249 struct blkcg *blkcg = blkg->blkcg; 244 struct blkcg *blkcg = blkg->blkcg;
250 245
251 lockdep_assert_held(q->queue_lock); 246 lockdep_assert_held(blkg->q->queue_lock);
252 lockdep_assert_held(&blkcg->lock); 247 lockdep_assert_held(&blkcg->lock);
253 248
254 /* Something wrong if we are trying to remove same group twice */ 249 /* Something wrong if we are trying to remove same group twice */
diff --git a/block/blk-core.c b/block/blk-core.c
index 3c923a7aeb56..93eb3e4f88ce 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -361,9 +361,10 @@ EXPORT_SYMBOL(blk_put_queue);
361 */ 361 */
362void blk_drain_queue(struct request_queue *q, bool drain_all) 362void blk_drain_queue(struct request_queue *q, bool drain_all)
363{ 363{
364 int i;
365
364 while (true) { 366 while (true) {
365 bool drain = false; 367 bool drain = false;
366 int i;
367 368
368 spin_lock_irq(q->queue_lock); 369 spin_lock_irq(q->queue_lock);
369 370
@@ -408,6 +409,18 @@ void blk_drain_queue(struct request_queue *q, bool drain_all)
408 break; 409 break;
409 msleep(10); 410 msleep(10);
410 } 411 }
412
413 /*
414 * With queue marked dead, any woken up waiter will fail the
415 * allocation path, so the wakeup chaining is lost and we're
416 * left with hung waiters. We need to wake up those waiters.
417 */
418 if (q->request_fn) {
419 spin_lock_irq(q->queue_lock);
420 for (i = 0; i < ARRAY_SIZE(q->rq.wait); i++)
421 wake_up_all(&q->rq.wait[i]);
422 spin_unlock_irq(q->queue_lock);
423 }
411} 424}
412 425
413/** 426/**
@@ -467,7 +480,6 @@ void blk_cleanup_queue(struct request_queue *q)
467 /* mark @q DEAD, no new request or merges will be allowed afterwards */ 480 /* mark @q DEAD, no new request or merges will be allowed afterwards */
468 mutex_lock(&q->sysfs_lock); 481 mutex_lock(&q->sysfs_lock);
469 queue_flag_set_unlocked(QUEUE_FLAG_DEAD, q); 482 queue_flag_set_unlocked(QUEUE_FLAG_DEAD, q);
470
471 spin_lock_irq(lock); 483 spin_lock_irq(lock);
472 484
473 /* 485 /*
@@ -485,10 +497,6 @@ void blk_cleanup_queue(struct request_queue *q)
485 queue_flag_set(QUEUE_FLAG_NOMERGES, q); 497 queue_flag_set(QUEUE_FLAG_NOMERGES, q);
486 queue_flag_set(QUEUE_FLAG_NOXMERGES, q); 498 queue_flag_set(QUEUE_FLAG_NOXMERGES, q);
487 queue_flag_set(QUEUE_FLAG_DEAD, q); 499 queue_flag_set(QUEUE_FLAG_DEAD, q);
488
489 if (q->queue_lock != &q->__queue_lock)
490 q->queue_lock = &q->__queue_lock;
491
492 spin_unlock_irq(lock); 500 spin_unlock_irq(lock);
493 mutex_unlock(&q->sysfs_lock); 501 mutex_unlock(&q->sysfs_lock);
494 502
@@ -499,6 +507,11 @@ void blk_cleanup_queue(struct request_queue *q)
499 del_timer_sync(&q->backing_dev_info.laptop_mode_wb_timer); 507 del_timer_sync(&q->backing_dev_info.laptop_mode_wb_timer);
500 blk_sync_queue(q); 508 blk_sync_queue(q);
501 509
510 spin_lock_irq(lock);
511 if (q->queue_lock != &q->__queue_lock)
512 q->queue_lock = &q->__queue_lock;
513 spin_unlock_irq(lock);
514
502 /* @q is and will stay empty, shutdown and put */ 515 /* @q is and will stay empty, shutdown and put */
503 blk_put_queue(q); 516 blk_put_queue(q);
504} 517}
diff --git a/block/blk-timeout.c b/block/blk-timeout.c
index 780354888958..6e4744cbfb56 100644
--- a/block/blk-timeout.c
+++ b/block/blk-timeout.c
@@ -197,44 +197,3 @@ void blk_add_timer(struct request *req)
197 mod_timer(&q->timeout, expiry); 197 mod_timer(&q->timeout, expiry);
198} 198}
199 199
200/**
201 * blk_abort_queue -- Abort all request on given queue
202 * @queue: pointer to queue
203 *
204 */
205void blk_abort_queue(struct request_queue *q)
206{
207 unsigned long flags;
208 struct request *rq, *tmp;
209 LIST_HEAD(list);
210
211 /*
212 * Not a request based block device, nothing to abort
213 */
214 if (!q->request_fn)
215 return;
216
217 spin_lock_irqsave(q->queue_lock, flags);
218
219 elv_abort_queue(q);
220
221 /*
222 * Splice entries to local list, to avoid deadlocking if entries
223 * get readded to the timeout list by error handling
224 */
225 list_splice_init(&q->timeout_list, &list);
226
227 list_for_each_entry_safe(rq, tmp, &list, timeout_list)
228 blk_abort_request(rq);
229
230 /*
231 * Occasionally, blk_abort_request() will return without
232 * deleting the element from the list. Make sure we add those back
233 * instead of leaving them on the local stack list.
234 */
235 list_splice(&list, &q->timeout_list);
236
237 spin_unlock_irqrestore(q->queue_lock, flags);
238
239}
240EXPORT_SYMBOL_GPL(blk_abort_queue);
diff --git a/block/cfq-iosched.c b/block/cfq-iosched.c
index 673c977cc2bf..fb52df9744f5 100644
--- a/block/cfq-iosched.c
+++ b/block/cfq-iosched.c
@@ -17,8 +17,6 @@
17#include "blk.h" 17#include "blk.h"
18#include "blk-cgroup.h" 18#include "blk-cgroup.h"
19 19
20static struct blkcg_policy blkcg_policy_cfq __maybe_unused;
21
22/* 20/*
23 * tunables 21 * tunables
24 */ 22 */
@@ -418,11 +416,6 @@ static inline struct cfq_group *pd_to_cfqg(struct blkg_policy_data *pd)
418 return pd ? container_of(pd, struct cfq_group, pd) : NULL; 416 return pd ? container_of(pd, struct cfq_group, pd) : NULL;
419} 417}
420 418
421static inline struct cfq_group *blkg_to_cfqg(struct blkcg_gq *blkg)
422{
423 return pd_to_cfqg(blkg_to_pd(blkg, &blkcg_policy_cfq));
424}
425
426static inline struct blkcg_gq *cfqg_to_blkg(struct cfq_group *cfqg) 419static inline struct blkcg_gq *cfqg_to_blkg(struct cfq_group *cfqg)
427{ 420{
428 return pd_to_blkg(&cfqg->pd); 421 return pd_to_blkg(&cfqg->pd);
@@ -572,6 +565,13 @@ static inline void cfqg_stats_update_avg_queue_size(struct cfq_group *cfqg) { }
572 565
573#ifdef CONFIG_CFQ_GROUP_IOSCHED 566#ifdef CONFIG_CFQ_GROUP_IOSCHED
574 567
568static struct blkcg_policy blkcg_policy_cfq;
569
570static inline struct cfq_group *blkg_to_cfqg(struct blkcg_gq *blkg)
571{
572 return pd_to_cfqg(blkg_to_pd(blkg, &blkcg_policy_cfq));
573}
574
575static inline void cfqg_get(struct cfq_group *cfqg) 575static inline void cfqg_get(struct cfq_group *cfqg)
576{ 576{
577 return blkg_get(cfqg_to_blkg(cfqg)); 577 return blkg_get(cfqg_to_blkg(cfqg));
@@ -3951,10 +3951,11 @@ static void cfq_exit_queue(struct elevator_queue *e)
3951 3951
3952 cfq_shutdown_timer_wq(cfqd); 3952 cfq_shutdown_timer_wq(cfqd);
3953 3953
3954#ifndef CONFIG_CFQ_GROUP_IOSCHED 3954#ifdef CONFIG_CFQ_GROUP_IOSCHED
3955 blkcg_deactivate_policy(q, &blkcg_policy_cfq);
3956#else
3955 kfree(cfqd->root_group); 3957 kfree(cfqd->root_group);
3956#endif 3958#endif
3957 blkcg_deactivate_policy(q, &blkcg_policy_cfq);
3958 kfree(cfqd); 3959 kfree(cfqd);
3959} 3960}
3960 3961
@@ -4194,14 +4195,15 @@ static int __init cfq_init(void)
4194#ifdef CONFIG_CFQ_GROUP_IOSCHED 4195#ifdef CONFIG_CFQ_GROUP_IOSCHED
4195 if (!cfq_group_idle) 4196 if (!cfq_group_idle)
4196 cfq_group_idle = 1; 4197 cfq_group_idle = 1;
4197#else
4198 cfq_group_idle = 0;
4199#endif
4200 4198
4201 ret = blkcg_policy_register(&blkcg_policy_cfq); 4199 ret = blkcg_policy_register(&blkcg_policy_cfq);
4202 if (ret) 4200 if (ret)
4203 return ret; 4201 return ret;
4202#else
4203 cfq_group_idle = 0;
4204#endif
4204 4205
4206 ret = -ENOMEM;
4205 cfq_pool = KMEM_CACHE(cfq_queue, 0); 4207 cfq_pool = KMEM_CACHE(cfq_queue, 0);
4206 if (!cfq_pool) 4208 if (!cfq_pool)
4207 goto err_pol_unreg; 4209 goto err_pol_unreg;
@@ -4215,13 +4217,17 @@ static int __init cfq_init(void)
4215err_free_pool: 4217err_free_pool:
4216 kmem_cache_destroy(cfq_pool); 4218 kmem_cache_destroy(cfq_pool);
4217err_pol_unreg: 4219err_pol_unreg:
4220#ifdef CONFIG_CFQ_GROUP_IOSCHED
4218 blkcg_policy_unregister(&blkcg_policy_cfq); 4221 blkcg_policy_unregister(&blkcg_policy_cfq);
4222#endif
4219 return ret; 4223 return ret;
4220} 4224}
4221 4225
4222static void __exit cfq_exit(void) 4226static void __exit cfq_exit(void)
4223{ 4227{
4228#ifdef CONFIG_CFQ_GROUP_IOSCHED
4224 blkcg_policy_unregister(&blkcg_policy_cfq); 4229 blkcg_policy_unregister(&blkcg_policy_cfq);
4230#endif
4225 elv_unregister(&iosched_cfq); 4231 elv_unregister(&iosched_cfq);
4226 kmem_cache_destroy(cfq_pool); 4232 kmem_cache_destroy(cfq_pool);
4227} 4233}
diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
index 260fa80ef575..9a87daa6f4fb 100644
--- a/block/scsi_ioctl.c
+++ b/block/scsi_ioctl.c
@@ -721,11 +721,14 @@ int scsi_verify_blk_ioctl(struct block_device *bd, unsigned int cmd)
721 break; 721 break;
722 } 722 }
723 723
724 if (capable(CAP_SYS_RAWIO))
725 return 0;
726
724 /* In particular, rule out all resets and host-specific ioctls. */ 727 /* In particular, rule out all resets and host-specific ioctls. */
725 printk_ratelimited(KERN_WARNING 728 printk_ratelimited(KERN_WARNING
726 "%s: sending ioctl %x to a partition!\n", current->comm, cmd); 729 "%s: sending ioctl %x to a partition!\n", current->comm, cmd);
727 730
728 return capable(CAP_SYS_RAWIO) ? 0 : -ENOIOCTLCMD; 731 return -ENOIOCTLCMD;
729} 732}
730EXPORT_SYMBOL(scsi_verify_blk_ioctl); 733EXPORT_SYMBOL(scsi_verify_blk_ioctl);
731 734
diff --git a/drivers/acpi/acpica/hwsleep.c b/drivers/acpi/acpica/hwsleep.c
index 0ed85cac3231..615996a36bed 100644
--- a/drivers/acpi/acpica/hwsleep.c
+++ b/drivers/acpi/acpica/hwsleep.c
@@ -95,18 +95,6 @@ acpi_status acpi_hw_legacy_sleep(u8 sleep_state, u8 flags)
95 return_ACPI_STATUS(status); 95 return_ACPI_STATUS(status);
96 } 96 }
97 97
98 if (sleep_state != ACPI_STATE_S5) {
99 /*
100 * Disable BM arbitration. This feature is contained within an
101 * optional register (PM2 Control), so ignore a BAD_ADDRESS
102 * exception.
103 */
104 status = acpi_write_bit_register(ACPI_BITREG_ARB_DISABLE, 1);
105 if (ACPI_FAILURE(status) && (status != AE_BAD_ADDRESS)) {
106 return_ACPI_STATUS(status);
107 }
108 }
109
110 /* 98 /*
111 * 1) Disable/Clear all GPEs 99 * 1) Disable/Clear all GPEs
112 * 2) Enable all wakeup GPEs 100 * 2) Enable all wakeup GPEs
@@ -364,16 +352,6 @@ acpi_status acpi_hw_legacy_wake(u8 sleep_state, u8 flags)
364 [ACPI_EVENT_POWER_BUTTON]. 352 [ACPI_EVENT_POWER_BUTTON].
365 status_register_id, ACPI_CLEAR_STATUS); 353 status_register_id, ACPI_CLEAR_STATUS);
366 354
367 /*
368 * Enable BM arbitration. This feature is contained within an
369 * optional register (PM2 Control), so ignore a BAD_ADDRESS
370 * exception.
371 */
372 status = acpi_write_bit_register(ACPI_BITREG_ARB_DISABLE, 0);
373 if (ACPI_FAILURE(status) && (status != AE_BAD_ADDRESS)) {
374 return_ACPI_STATUS(status);
375 }
376
377 acpi_hw_execute_sleep_method(METHOD_PATHNAME__SST, ACPI_SST_WORKING); 355 acpi_hw_execute_sleep_method(METHOD_PATHNAME__SST, ACPI_SST_WORKING);
378 return_ACPI_STATUS(status); 356 return_ACPI_STATUS(status);
379} 357}
diff --git a/drivers/acpi/acpica/nspredef.c b/drivers/acpi/acpica/nspredef.c
index 23ce09686418..fe6626035495 100644
--- a/drivers/acpi/acpica/nspredef.c
+++ b/drivers/acpi/acpica/nspredef.c
@@ -638,7 +638,7 @@ acpi_ns_check_package(struct acpi_predefined_data *data,
638 /* Create the new outer package and populate it */ 638 /* Create the new outer package and populate it */
639 639
640 status = 640 status =
641 acpi_ns_wrap_with_package(data, *elements, 641 acpi_ns_wrap_with_package(data, return_object,
642 return_object_ptr); 642 return_object_ptr);
643 if (ACPI_FAILURE(status)) { 643 if (ACPI_FAILURE(status)) {
644 return (status); 644 return (status);
diff --git a/drivers/acpi/processor_core.c b/drivers/acpi/processor_core.c
index c850de4c9a14..eff722278ff5 100644
--- a/drivers/acpi/processor_core.c
+++ b/drivers/acpi/processor_core.c
@@ -189,10 +189,12 @@ int acpi_get_cpuid(acpi_handle handle, int type, u32 acpi_id)
189 * Processor (CPU3, 0x03, 0x00000410, 0x06) {} 189 * Processor (CPU3, 0x03, 0x00000410, 0x06) {}
190 * } 190 * }
191 * 191 *
192 * Ignores apic_id and always return 0 for CPU0's handle. 192 * Ignores apic_id and always returns 0 for the processor
193 * handle with acpi id 0 if nr_cpu_ids is 1.
194 * This should be the case if SMP tables are not found.
193 * Return -1 for other CPU's handle. 195 * Return -1 for other CPU's handle.
194 */ 196 */
195 if (acpi_id == 0) 197 if (nr_cpu_ids <= 1 && acpi_id == 0)
196 return acpi_id; 198 return acpi_id;
197 else 199 else
198 return apic_id; 200 return apic_id;
diff --git a/drivers/block/drbd/drbd_bitmap.c b/drivers/block/drbd/drbd_bitmap.c
index b5c5ff53cb57..fcb956bb4b4c 100644
--- a/drivers/block/drbd/drbd_bitmap.c
+++ b/drivers/block/drbd/drbd_bitmap.c
@@ -1475,10 +1475,17 @@ void _drbd_bm_set_bits(struct drbd_conf *mdev, const unsigned long s, const unsi
1475 first_word = 0; 1475 first_word = 0;
1476 spin_lock_irq(&b->bm_lock); 1476 spin_lock_irq(&b->bm_lock);
1477 } 1477 }
1478
1479 /* last page (respectively only page, for first page == last page) */ 1478 /* last page (respectively only page, for first page == last page) */
1480 last_word = MLPP(el >> LN2_BPL); 1479 last_word = MLPP(el >> LN2_BPL);
1481 bm_set_full_words_within_one_page(mdev->bitmap, last_page, first_word, last_word); 1480
1481 /* consider bitmap->bm_bits = 32768, bitmap->bm_number_of_pages = 1. (or multiples).
1482 * ==> e = 32767, el = 32768, last_page = 2,
1483 * and now last_word = 0.
1484 * We do not want to touch last_page in this case,
1485 * as we did not allocate it, it is not present in bitmap->bm_pages.
1486 */
1487 if (last_word)
1488 bm_set_full_words_within_one_page(mdev->bitmap, last_page, first_word, last_word);
1482 1489
1483 /* possibly trailing bits. 1490 /* possibly trailing bits.
1484 * example: (e & 63) == 63, el will be e+1. 1491 * example: (e & 63) == 63, el will be e+1.
diff --git a/drivers/block/drbd/drbd_req.c b/drivers/block/drbd/drbd_req.c
index 9c5c84946b05..8e93a6ac9bb6 100644
--- a/drivers/block/drbd/drbd_req.c
+++ b/drivers/block/drbd/drbd_req.c
@@ -472,12 +472,17 @@ int __req_mod(struct drbd_request *req, enum drbd_req_event what,
472 req->rq_state |= RQ_LOCAL_COMPLETED; 472 req->rq_state |= RQ_LOCAL_COMPLETED;
473 req->rq_state &= ~RQ_LOCAL_PENDING; 473 req->rq_state &= ~RQ_LOCAL_PENDING;
474 474
475 D_ASSERT(!(req->rq_state & RQ_NET_MASK)); 475 if (req->rq_state & RQ_LOCAL_ABORTED) {
476 _req_may_be_done(req, m);
477 break;
478 }
476 479
477 __drbd_chk_io_error(mdev, false); 480 __drbd_chk_io_error(mdev, false);
478 481
479 goto_queue_for_net_read: 482 goto_queue_for_net_read:
480 483
484 D_ASSERT(!(req->rq_state & RQ_NET_MASK));
485
481 /* no point in retrying if there is no good remote data, 486 /* no point in retrying if there is no good remote data,
482 * or we have no connection. */ 487 * or we have no connection. */
483 if (mdev->state.pdsk != D_UP_TO_DATE) { 488 if (mdev->state.pdsk != D_UP_TO_DATE) {
@@ -765,6 +770,40 @@ static int drbd_may_do_local_read(struct drbd_conf *mdev, sector_t sector, int s
765 return 0 == drbd_bm_count_bits(mdev, sbnr, ebnr); 770 return 0 == drbd_bm_count_bits(mdev, sbnr, ebnr);
766} 771}
767 772
773static void maybe_pull_ahead(struct drbd_conf *mdev)
774{
775 int congested = 0;
776
777 /* If I don't even have good local storage, we can not reasonably try
778 * to pull ahead of the peer. We also need the local reference to make
779 * sure mdev->act_log is there.
780 * Note: caller has to make sure that net_conf is there.
781 */
782 if (!get_ldev_if_state(mdev, D_UP_TO_DATE))
783 return;
784
785 if (mdev->net_conf->cong_fill &&
786 atomic_read(&mdev->ap_in_flight) >= mdev->net_conf->cong_fill) {
787 dev_info(DEV, "Congestion-fill threshold reached\n");
788 congested = 1;
789 }
790
791 if (mdev->act_log->used >= mdev->net_conf->cong_extents) {
792 dev_info(DEV, "Congestion-extents threshold reached\n");
793 congested = 1;
794 }
795
796 if (congested) {
797 queue_barrier(mdev); /* last barrier, after mirrored writes */
798
799 if (mdev->net_conf->on_congestion == OC_PULL_AHEAD)
800 _drbd_set_state(_NS(mdev, conn, C_AHEAD), 0, NULL);
801 else /*mdev->net_conf->on_congestion == OC_DISCONNECT */
802 _drbd_set_state(_NS(mdev, conn, C_DISCONNECTING), 0, NULL);
803 }
804 put_ldev(mdev);
805}
806
768static int drbd_make_request_common(struct drbd_conf *mdev, struct bio *bio, unsigned long start_time) 807static int drbd_make_request_common(struct drbd_conf *mdev, struct bio *bio, unsigned long start_time)
769{ 808{
770 const int rw = bio_rw(bio); 809 const int rw = bio_rw(bio);
@@ -972,29 +1011,8 @@ allocate_barrier:
972 _req_mod(req, queue_for_send_oos); 1011 _req_mod(req, queue_for_send_oos);
973 1012
974 if (remote && 1013 if (remote &&
975 mdev->net_conf->on_congestion != OC_BLOCK && mdev->agreed_pro_version >= 96) { 1014 mdev->net_conf->on_congestion != OC_BLOCK && mdev->agreed_pro_version >= 96)
976 int congested = 0; 1015 maybe_pull_ahead(mdev);
977
978 if (mdev->net_conf->cong_fill &&
979 atomic_read(&mdev->ap_in_flight) >= mdev->net_conf->cong_fill) {
980 dev_info(DEV, "Congestion-fill threshold reached\n");
981 congested = 1;
982 }
983
984 if (mdev->act_log->used >= mdev->net_conf->cong_extents) {
985 dev_info(DEV, "Congestion-extents threshold reached\n");
986 congested = 1;
987 }
988
989 if (congested) {
990 queue_barrier(mdev); /* last barrier, after mirrored writes */
991
992 if (mdev->net_conf->on_congestion == OC_PULL_AHEAD)
993 _drbd_set_state(_NS(mdev, conn, C_AHEAD), 0, NULL);
994 else /*mdev->net_conf->on_congestion == OC_DISCONNECT */
995 _drbd_set_state(_NS(mdev, conn, C_DISCONNECTING), 0, NULL);
996 }
997 }
998 1016
999 spin_unlock_irq(&mdev->req_lock); 1017 spin_unlock_irq(&mdev->req_lock);
1000 kfree(b); /* if someone else has beaten us to it... */ 1018 kfree(b); /* if someone else has beaten us to it... */
diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index cce7df367b79..553f43a90953 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -671,6 +671,7 @@ static void __reschedule_timeout(int drive, const char *message)
671 671
672 if (drive == current_reqD) 672 if (drive == current_reqD)
673 drive = current_drive; 673 drive = current_drive;
674 __cancel_delayed_work(&fd_timeout);
674 675
675 if (drive < 0 || drive >= N_DRIVE) { 676 if (drive < 0 || drive >= N_DRIVE) {
676 delay = 20UL * HZ; 677 delay = 20UL * HZ;
diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index bbca966f8f66..3bba65510d23 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -1597,14 +1597,12 @@ static int loop_add(struct loop_device **l, int i)
1597 struct gendisk *disk; 1597 struct gendisk *disk;
1598 int err; 1598 int err;
1599 1599
1600 err = -ENOMEM;
1600 lo = kzalloc(sizeof(*lo), GFP_KERNEL); 1601 lo = kzalloc(sizeof(*lo), GFP_KERNEL);
1601 if (!lo) { 1602 if (!lo)
1602 err = -ENOMEM;
1603 goto out; 1603 goto out;
1604 }
1605 1604
1606 err = idr_pre_get(&loop_index_idr, GFP_KERNEL); 1605 if (!idr_pre_get(&loop_index_idr, GFP_KERNEL))
1607 if (err < 0)
1608 goto out_free_dev; 1606 goto out_free_dev;
1609 1607
1610 if (i >= 0) { 1608 if (i >= 0) {
diff --git a/drivers/block/mtip32xx/mtip32xx.c b/drivers/block/mtip32xx/mtip32xx.c
index 264bc77dcb91..a8fddeb3d638 100644
--- a/drivers/block/mtip32xx/mtip32xx.c
+++ b/drivers/block/mtip32xx/mtip32xx.c
@@ -37,6 +37,7 @@
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 <linux/export.h>
40#include <linux/debugfs.h>
40#include "mtip32xx.h" 41#include "mtip32xx.h"
41 42
42#define HW_CMD_SLOT_SZ (MTIP_MAX_COMMAND_SLOTS * 32) 43#define HW_CMD_SLOT_SZ (MTIP_MAX_COMMAND_SLOTS * 32)
@@ -85,6 +86,7 @@ static int instance;
85 * allocated in mtip_init(). 86 * allocated in mtip_init().
86 */ 87 */
87static int mtip_major; 88static int mtip_major;
89static struct dentry *dfs_parent;
88 90
89static DEFINE_SPINLOCK(rssd_index_lock); 91static DEFINE_SPINLOCK(rssd_index_lock);
90static DEFINE_IDA(rssd_index_ida); 92static DEFINE_IDA(rssd_index_ida);
@@ -2546,7 +2548,7 @@ static struct scatterlist *mtip_hw_get_scatterlist(struct driver_data *dd,
2546} 2548}
2547 2549
2548/* 2550/*
2549 * Sysfs register/status dump. 2551 * Sysfs status dump.
2550 * 2552 *
2551 * @dev Pointer to the device structure, passed by the kernrel. 2553 * @dev Pointer to the device structure, passed by the kernrel.
2552 * @attr Pointer to the device_attribute structure passed by the kernel. 2554 * @attr Pointer to the device_attribute structure passed by the kernel.
@@ -2555,45 +2557,68 @@ static struct scatterlist *mtip_hw_get_scatterlist(struct driver_data *dd,
2555 * return value 2557 * return value
2556 * The size, in bytes, of the data copied into buf. 2558 * The size, in bytes, of the data copied into buf.
2557 */ 2559 */
2558static ssize_t mtip_hw_show_registers(struct device *dev, 2560static ssize_t mtip_hw_show_status(struct device *dev,
2559 struct device_attribute *attr, 2561 struct device_attribute *attr,
2560 char *buf) 2562 char *buf)
2561{ 2563{
2562 u32 group_allocated;
2563 struct driver_data *dd = dev_to_disk(dev)->private_data; 2564 struct driver_data *dd = dev_to_disk(dev)->private_data;
2564 int size = 0; 2565 int size = 0;
2566
2567 if (test_bit(MTIP_DDF_OVER_TEMP_BIT, &dd->dd_flag))
2568 size += sprintf(buf, "%s", "thermal_shutdown\n");
2569 else if (test_bit(MTIP_DDF_WRITE_PROTECT_BIT, &dd->dd_flag))
2570 size += sprintf(buf, "%s", "write_protect\n");
2571 else
2572 size += sprintf(buf, "%s", "online\n");
2573
2574 return size;
2575}
2576
2577static DEVICE_ATTR(status, S_IRUGO, mtip_hw_show_status, NULL);
2578
2579static ssize_t mtip_hw_read_registers(struct file *f, char __user *ubuf,
2580 size_t len, loff_t *offset)
2581{
2582 struct driver_data *dd = (struct driver_data *)f->private_data;
2583 char buf[MTIP_DFS_MAX_BUF_SIZE];
2584 u32 group_allocated;
2585 int size = *offset;
2565 int n; 2586 int n;
2566 2587
2567 size += sprintf(&buf[size], "Hardware\n--------\n"); 2588 if (!len || size)
2568 size += sprintf(&buf[size], "S ACTive : [ 0x"); 2589 return 0;
2590
2591 if (size < 0)
2592 return -EINVAL;
2593
2594 size += sprintf(&buf[size], "H/ S ACTive : [ 0x");
2569 2595
2570 for (n = dd->slot_groups-1; n >= 0; n--) 2596 for (n = dd->slot_groups-1; n >= 0; n--)
2571 size += sprintf(&buf[size], "%08X ", 2597 size += sprintf(&buf[size], "%08X ",
2572 readl(dd->port->s_active[n])); 2598 readl(dd->port->s_active[n]));
2573 2599
2574 size += sprintf(&buf[size], "]\n"); 2600 size += sprintf(&buf[size], "]\n");
2575 size += sprintf(&buf[size], "Command Issue : [ 0x"); 2601 size += sprintf(&buf[size], "H/ Command Issue : [ 0x");
2576 2602
2577 for (n = dd->slot_groups-1; n >= 0; n--) 2603 for (n = dd->slot_groups-1; n >= 0; n--)
2578 size += sprintf(&buf[size], "%08X ", 2604 size += sprintf(&buf[size], "%08X ",
2579 readl(dd->port->cmd_issue[n])); 2605 readl(dd->port->cmd_issue[n]));
2580 2606
2581 size += sprintf(&buf[size], "]\n"); 2607 size += sprintf(&buf[size], "]\n");
2582 size += sprintf(&buf[size], "Completed : [ 0x"); 2608 size += sprintf(&buf[size], "H/ Completed : [ 0x");
2583 2609
2584 for (n = dd->slot_groups-1; n >= 0; n--) 2610 for (n = dd->slot_groups-1; n >= 0; n--)
2585 size += sprintf(&buf[size], "%08X ", 2611 size += sprintf(&buf[size], "%08X ",
2586 readl(dd->port->completed[n])); 2612 readl(dd->port->completed[n]));
2587 2613
2588 size += sprintf(&buf[size], "]\n"); 2614 size += sprintf(&buf[size], "]\n");
2589 size += sprintf(&buf[size], "PORT IRQ STAT : [ 0x%08X ]\n", 2615 size += sprintf(&buf[size], "H/ PORT IRQ STAT : [ 0x%08X ]\n",
2590 readl(dd->port->mmio + PORT_IRQ_STAT)); 2616 readl(dd->port->mmio + PORT_IRQ_STAT));
2591 size += sprintf(&buf[size], "HOST IRQ STAT : [ 0x%08X ]\n", 2617 size += sprintf(&buf[size], "H/ HOST IRQ STAT : [ 0x%08X ]\n",
2592 readl(dd->mmio + HOST_IRQ_STAT)); 2618 readl(dd->mmio + HOST_IRQ_STAT));
2593 size += sprintf(&buf[size], "\n"); 2619 size += sprintf(&buf[size], "\n");
2594 2620
2595 size += sprintf(&buf[size], "Local\n-----\n"); 2621 size += sprintf(&buf[size], "L/ Allocated : [ 0x");
2596 size += sprintf(&buf[size], "Allocated : [ 0x");
2597 2622
2598 for (n = dd->slot_groups-1; n >= 0; n--) { 2623 for (n = dd->slot_groups-1; n >= 0; n--) {
2599 if (sizeof(long) > sizeof(u32)) 2624 if (sizeof(long) > sizeof(u32))
@@ -2605,7 +2630,7 @@ static ssize_t mtip_hw_show_registers(struct device *dev,
2605 } 2630 }
2606 size += sprintf(&buf[size], "]\n"); 2631 size += sprintf(&buf[size], "]\n");
2607 2632
2608 size += sprintf(&buf[size], "Commands in Q: [ 0x"); 2633 size += sprintf(&buf[size], "L/ Commands in Q : [ 0x");
2609 2634
2610 for (n = dd->slot_groups-1; n >= 0; n--) { 2635 for (n = dd->slot_groups-1; n >= 0; n--) {
2611 if (sizeof(long) > sizeof(u32)) 2636 if (sizeof(long) > sizeof(u32))
@@ -2617,44 +2642,53 @@ static ssize_t mtip_hw_show_registers(struct device *dev,
2617 } 2642 }
2618 size += sprintf(&buf[size], "]\n"); 2643 size += sprintf(&buf[size], "]\n");
2619 2644
2620 return size; 2645 *offset = size <= len ? size : len;
2646 size = copy_to_user(ubuf, buf, *offset);
2647 if (size)
2648 return -EFAULT;
2649
2650 return *offset;
2621} 2651}
2622 2652
2623static ssize_t mtip_hw_show_status(struct device *dev, 2653static ssize_t mtip_hw_read_flags(struct file *f, char __user *ubuf,
2624 struct device_attribute *attr, 2654 size_t len, loff_t *offset)
2625 char *buf)
2626{ 2655{
2627 struct driver_data *dd = dev_to_disk(dev)->private_data; 2656 struct driver_data *dd = (struct driver_data *)f->private_data;
2628 int size = 0; 2657 char buf[MTIP_DFS_MAX_BUF_SIZE];
2658 int size = *offset;
2629 2659
2630 if (test_bit(MTIP_DDF_OVER_TEMP_BIT, &dd->dd_flag)) 2660 if (!len || size)
2631 size += sprintf(buf, "%s", "thermal_shutdown\n"); 2661 return 0;
2632 else if (test_bit(MTIP_DDF_WRITE_PROTECT_BIT, &dd->dd_flag))
2633 size += sprintf(buf, "%s", "write_protect\n");
2634 else
2635 size += sprintf(buf, "%s", "online\n");
2636
2637 return size;
2638}
2639 2662
2640static ssize_t mtip_hw_show_flags(struct device *dev, 2663 if (size < 0)
2641 struct device_attribute *attr, 2664 return -EINVAL;
2642 char *buf)
2643{
2644 struct driver_data *dd = dev_to_disk(dev)->private_data;
2645 int size = 0;
2646 2665
2647 size += sprintf(&buf[size], "Flag in port struct : [ %08lX ]\n", 2666 size += sprintf(&buf[size], "Flag-port : [ %08lX ]\n",
2648 dd->port->flags); 2667 dd->port->flags);
2649 size += sprintf(&buf[size], "Flag in dd struct : [ %08lX ]\n", 2668 size += sprintf(&buf[size], "Flag-dd : [ %08lX ]\n",
2650 dd->dd_flag); 2669 dd->dd_flag);
2651 2670
2652 return size; 2671 *offset = size <= len ? size : len;
2672 size = copy_to_user(ubuf, buf, *offset);
2673 if (size)
2674 return -EFAULT;
2675
2676 return *offset;
2653} 2677}
2654 2678
2655static DEVICE_ATTR(registers, S_IRUGO, mtip_hw_show_registers, NULL); 2679static const struct file_operations mtip_regs_fops = {
2656static DEVICE_ATTR(status, S_IRUGO, mtip_hw_show_status, NULL); 2680 .owner = THIS_MODULE,
2657static DEVICE_ATTR(flags, S_IRUGO, mtip_hw_show_flags, NULL); 2681 .open = simple_open,
2682 .read = mtip_hw_read_registers,
2683 .llseek = no_llseek,
2684};
2685
2686static const struct file_operations mtip_flags_fops = {
2687 .owner = THIS_MODULE,
2688 .open = simple_open,
2689 .read = mtip_hw_read_flags,
2690 .llseek = no_llseek,
2691};
2658 2692
2659/* 2693/*
2660 * Create the sysfs related attributes. 2694 * Create the sysfs related attributes.
@@ -2671,15 +2705,9 @@ static int mtip_hw_sysfs_init(struct driver_data *dd, struct kobject *kobj)
2671 if (!kobj || !dd) 2705 if (!kobj || !dd)
2672 return -EINVAL; 2706 return -EINVAL;
2673 2707
2674 if (sysfs_create_file(kobj, &dev_attr_registers.attr))
2675 dev_warn(&dd->pdev->dev,
2676 "Error creating 'registers' sysfs entry\n");
2677 if (sysfs_create_file(kobj, &dev_attr_status.attr)) 2708 if (sysfs_create_file(kobj, &dev_attr_status.attr))
2678 dev_warn(&dd->pdev->dev, 2709 dev_warn(&dd->pdev->dev,
2679 "Error creating 'status' sysfs entry\n"); 2710 "Error creating 'status' sysfs entry\n");
2680 if (sysfs_create_file(kobj, &dev_attr_flags.attr))
2681 dev_warn(&dd->pdev->dev,
2682 "Error creating 'flags' sysfs entry\n");
2683 return 0; 2711 return 0;
2684} 2712}
2685 2713
@@ -2698,13 +2726,39 @@ static int mtip_hw_sysfs_exit(struct driver_data *dd, struct kobject *kobj)
2698 if (!kobj || !dd) 2726 if (!kobj || !dd)
2699 return -EINVAL; 2727 return -EINVAL;
2700 2728
2701 sysfs_remove_file(kobj, &dev_attr_registers.attr);
2702 sysfs_remove_file(kobj, &dev_attr_status.attr); 2729 sysfs_remove_file(kobj, &dev_attr_status.attr);
2703 sysfs_remove_file(kobj, &dev_attr_flags.attr);
2704 2730
2705 return 0; 2731 return 0;
2706} 2732}
2707 2733
2734static int mtip_hw_debugfs_init(struct driver_data *dd)
2735{
2736 if (!dfs_parent)
2737 return -1;
2738
2739 dd->dfs_node = debugfs_create_dir(dd->disk->disk_name, dfs_parent);
2740 if (IS_ERR_OR_NULL(dd->dfs_node)) {
2741 dev_warn(&dd->pdev->dev,
2742 "Error creating node %s under debugfs\n",
2743 dd->disk->disk_name);
2744 dd->dfs_node = NULL;
2745 return -1;
2746 }
2747
2748 debugfs_create_file("flags", S_IRUGO, dd->dfs_node, dd,
2749 &mtip_flags_fops);
2750 debugfs_create_file("registers", S_IRUGO, dd->dfs_node, dd,
2751 &mtip_regs_fops);
2752
2753 return 0;
2754}
2755
2756static void mtip_hw_debugfs_exit(struct driver_data *dd)
2757{
2758 debugfs_remove_recursive(dd->dfs_node);
2759}
2760
2761
2708/* 2762/*
2709 * Perform any init/resume time hardware setup 2763 * Perform any init/resume time hardware setup
2710 * 2764 *
@@ -3730,6 +3784,7 @@ skip_create_disk:
3730 mtip_hw_sysfs_init(dd, kobj); 3784 mtip_hw_sysfs_init(dd, kobj);
3731 kobject_put(kobj); 3785 kobject_put(kobj);
3732 } 3786 }
3787 mtip_hw_debugfs_init(dd);
3733 3788
3734 if (dd->mtip_svc_handler) { 3789 if (dd->mtip_svc_handler) {
3735 set_bit(MTIP_DDF_INIT_DONE_BIT, &dd->dd_flag); 3790 set_bit(MTIP_DDF_INIT_DONE_BIT, &dd->dd_flag);
@@ -3755,6 +3810,8 @@ start_service_thread:
3755 return rv; 3810 return rv;
3756 3811
3757kthread_run_error: 3812kthread_run_error:
3813 mtip_hw_debugfs_exit(dd);
3814
3758 /* Delete our gendisk. This also removes the device from /dev */ 3815 /* Delete our gendisk. This also removes the device from /dev */
3759 del_gendisk(dd->disk); 3816 del_gendisk(dd->disk);
3760 3817
@@ -3805,6 +3862,7 @@ static int mtip_block_remove(struct driver_data *dd)
3805 kobject_put(kobj); 3862 kobject_put(kobj);
3806 } 3863 }
3807 } 3864 }
3865 mtip_hw_debugfs_exit(dd);
3808 3866
3809 /* 3867 /*
3810 * Delete our gendisk structure. This also removes the device 3868 * Delete our gendisk structure. This also removes the device
@@ -4152,10 +4210,20 @@ static int __init mtip_init(void)
4152 } 4210 }
4153 mtip_major = error; 4211 mtip_major = error;
4154 4212
4213 if (!dfs_parent) {
4214 dfs_parent = debugfs_create_dir("rssd", NULL);
4215 if (IS_ERR_OR_NULL(dfs_parent)) {
4216 printk(KERN_WARNING "Error creating debugfs parent\n");
4217 dfs_parent = NULL;
4218 }
4219 }
4220
4155 /* Register our PCI operations. */ 4221 /* Register our PCI operations. */
4156 error = pci_register_driver(&mtip_pci_driver); 4222 error = pci_register_driver(&mtip_pci_driver);
4157 if (error) 4223 if (error) {
4224 debugfs_remove(dfs_parent);
4158 unregister_blkdev(mtip_major, MTIP_DRV_NAME); 4225 unregister_blkdev(mtip_major, MTIP_DRV_NAME);
4226 }
4159 4227
4160 return error; 4228 return error;
4161} 4229}
@@ -4172,6 +4240,8 @@ static int __init mtip_init(void)
4172 */ 4240 */
4173static void __exit mtip_exit(void) 4241static void __exit mtip_exit(void)
4174{ 4242{
4243 debugfs_remove_recursive(dfs_parent);
4244
4175 /* Release the allocated major block device number. */ 4245 /* Release the allocated major block device number. */
4176 unregister_blkdev(mtip_major, MTIP_DRV_NAME); 4246 unregister_blkdev(mtip_major, MTIP_DRV_NAME);
4177 4247
diff --git a/drivers/block/mtip32xx/mtip32xx.h b/drivers/block/mtip32xx/mtip32xx.h
index b2c88da26b2a..f51fc23d17bb 100644
--- a/drivers/block/mtip32xx/mtip32xx.h
+++ b/drivers/block/mtip32xx/mtip32xx.h
@@ -26,7 +26,6 @@
26#include <linux/ata.h> 26#include <linux/ata.h>
27#include <linux/interrupt.h> 27#include <linux/interrupt.h>
28#include <linux/genhd.h> 28#include <linux/genhd.h>
29#include <linux/version.h>
30 29
31/* Offset of Subsystem Device ID in pci confoguration space */ 30/* Offset of Subsystem Device ID in pci confoguration space */
32#define PCI_SUBSYSTEM_DEVICEID 0x2E 31#define PCI_SUBSYSTEM_DEVICEID 0x2E
@@ -111,6 +110,8 @@
111 #define dbg_printk(format, arg...) 110 #define dbg_printk(format, arg...)
112#endif 111#endif
113 112
113#define MTIP_DFS_MAX_BUF_SIZE 1024
114
114#define __force_bit2int (unsigned int __force) 115#define __force_bit2int (unsigned int __force)
115 116
116enum { 117enum {
@@ -447,6 +448,8 @@ struct driver_data {
447 unsigned long dd_flag; /* NOTE: use atomic bit operations on this */ 448 unsigned long dd_flag; /* NOTE: use atomic bit operations on this */
448 449
449 struct task_struct *mtip_svc_handler; /* task_struct of svc thd */ 450 struct task_struct *mtip_svc_handler; /* task_struct of svc thd */
451
452 struct dentry *dfs_node;
450}; 453};
451 454
452#endif 455#endif
diff --git a/drivers/block/umem.c b/drivers/block/umem.c
index aa2712060bfb..9a72277a31df 100644
--- a/drivers/block/umem.c
+++ b/drivers/block/umem.c
@@ -513,6 +513,44 @@ static void process_page(unsigned long data)
513 } 513 }
514} 514}
515 515
516struct mm_plug_cb {
517 struct blk_plug_cb cb;
518 struct cardinfo *card;
519};
520
521static void mm_unplug(struct blk_plug_cb *cb)
522{
523 struct mm_plug_cb *mmcb = container_of(cb, struct mm_plug_cb, cb);
524
525 spin_lock_irq(&mmcb->card->lock);
526 activate(mmcb->card);
527 spin_unlock_irq(&mmcb->card->lock);
528 kfree(mmcb);
529}
530
531static int mm_check_plugged(struct cardinfo *card)
532{
533 struct blk_plug *plug = current->plug;
534 struct mm_plug_cb *mmcb;
535
536 if (!plug)
537 return 0;
538
539 list_for_each_entry(mmcb, &plug->cb_list, cb.list) {
540 if (mmcb->cb.callback == mm_unplug && mmcb->card == card)
541 return 1;
542 }
543 /* Not currently on the callback list */
544 mmcb = kmalloc(sizeof(*mmcb), GFP_ATOMIC);
545 if (!mmcb)
546 return 0;
547
548 mmcb->card = card;
549 mmcb->cb.callback = mm_unplug;
550 list_add(&mmcb->cb.list, &plug->cb_list);
551 return 1;
552}
553
516static void mm_make_request(struct request_queue *q, struct bio *bio) 554static void mm_make_request(struct request_queue *q, struct bio *bio)
517{ 555{
518 struct cardinfo *card = q->queuedata; 556 struct cardinfo *card = q->queuedata;
@@ -523,6 +561,8 @@ static void mm_make_request(struct request_queue *q, struct bio *bio)
523 *card->biotail = bio; 561 *card->biotail = bio;
524 bio->bi_next = NULL; 562 bio->bi_next = NULL;
525 card->biotail = &bio->bi_next; 563 card->biotail = &bio->bi_next;
564 if (bio->bi_rw & REQ_SYNC || !mm_check_plugged(card))
565 activate(card);
526 spin_unlock_irq(&card->lock); 566 spin_unlock_irq(&card->lock);
527 567
528 return; 568 return;
diff --git a/drivers/block/xen-blkback/common.h b/drivers/block/xen-blkback/common.h
index 773cf27dc23f..9ad3b5ec1dc1 100644
--- a/drivers/block/xen-blkback/common.h
+++ b/drivers/block/xen-blkback/common.h
@@ -257,6 +257,7 @@ static inline void blkif_get_x86_32_req(struct blkif_request *dst,
257 break; 257 break;
258 case BLKIF_OP_DISCARD: 258 case BLKIF_OP_DISCARD:
259 dst->u.discard.flag = src->u.discard.flag; 259 dst->u.discard.flag = src->u.discard.flag;
260 dst->u.discard.id = src->u.discard.id;
260 dst->u.discard.sector_number = src->u.discard.sector_number; 261 dst->u.discard.sector_number = src->u.discard.sector_number;
261 dst->u.discard.nr_sectors = src->u.discard.nr_sectors; 262 dst->u.discard.nr_sectors = src->u.discard.nr_sectors;
262 break; 263 break;
@@ -287,6 +288,7 @@ static inline void blkif_get_x86_64_req(struct blkif_request *dst,
287 break; 288 break;
288 case BLKIF_OP_DISCARD: 289 case BLKIF_OP_DISCARD:
289 dst->u.discard.flag = src->u.discard.flag; 290 dst->u.discard.flag = src->u.discard.flag;
291 dst->u.discard.id = src->u.discard.id;
290 dst->u.discard.sector_number = src->u.discard.sector_number; 292 dst->u.discard.sector_number = src->u.discard.sector_number;
291 dst->u.discard.nr_sectors = src->u.discard.nr_sectors; 293 dst->u.discard.nr_sectors = src->u.discard.nr_sectors;
292 break; 294 break;
diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c
index 60eed4bdd2e4..e4fb3374dcd2 100644
--- a/drivers/block/xen-blkfront.c
+++ b/drivers/block/xen-blkfront.c
@@ -141,14 +141,36 @@ static int get_id_from_freelist(struct blkfront_info *info)
141 return free; 141 return free;
142} 142}
143 143
144static void add_id_to_freelist(struct blkfront_info *info, 144static int add_id_to_freelist(struct blkfront_info *info,
145 unsigned long id) 145 unsigned long id)
146{ 146{
147 if (info->shadow[id].req.u.rw.id != id)
148 return -EINVAL;
149 if (info->shadow[id].request == NULL)
150 return -EINVAL;
147 info->shadow[id].req.u.rw.id = info->shadow_free; 151 info->shadow[id].req.u.rw.id = info->shadow_free;
148 info->shadow[id].request = NULL; 152 info->shadow[id].request = NULL;
149 info->shadow_free = id; 153 info->shadow_free = id;
154 return 0;
150} 155}
151 156
157static const char *op_name(int op)
158{
159 static const char *const names[] = {
160 [BLKIF_OP_READ] = "read",
161 [BLKIF_OP_WRITE] = "write",
162 [BLKIF_OP_WRITE_BARRIER] = "barrier",
163 [BLKIF_OP_FLUSH_DISKCACHE] = "flush",
164 [BLKIF_OP_DISCARD] = "discard" };
165
166 if (op < 0 || op >= ARRAY_SIZE(names))
167 return "unknown";
168
169 if (!names[op])
170 return "reserved";
171
172 return names[op];
173}
152static int xlbd_reserve_minors(unsigned int minor, unsigned int nr) 174static int xlbd_reserve_minors(unsigned int minor, unsigned int nr)
153{ 175{
154 unsigned int end = minor + nr; 176 unsigned int end = minor + nr;
@@ -746,20 +768,36 @@ static irqreturn_t blkif_interrupt(int irq, void *dev_id)
746 768
747 bret = RING_GET_RESPONSE(&info->ring, i); 769 bret = RING_GET_RESPONSE(&info->ring, i);
748 id = bret->id; 770 id = bret->id;
771 /*
772 * The backend has messed up and given us an id that we would
773 * never have given to it (we stamp it up to BLK_RING_SIZE -
774 * look in get_id_from_freelist.
775 */
776 if (id >= BLK_RING_SIZE) {
777 WARN(1, "%s: response to %s has incorrect id (%ld)\n",
778 info->gd->disk_name, op_name(bret->operation), id);
779 /* We can't safely get the 'struct request' as
780 * the id is busted. */
781 continue;
782 }
749 req = info->shadow[id].request; 783 req = info->shadow[id].request;
750 784
751 if (bret->operation != BLKIF_OP_DISCARD) 785 if (bret->operation != BLKIF_OP_DISCARD)
752 blkif_completion(&info->shadow[id]); 786 blkif_completion(&info->shadow[id]);
753 787
754 add_id_to_freelist(info, id); 788 if (add_id_to_freelist(info, id)) {
789 WARN(1, "%s: response to %s (id %ld) couldn't be recycled!\n",
790 info->gd->disk_name, op_name(bret->operation), id);
791 continue;
792 }
755 793
756 error = (bret->status == BLKIF_RSP_OKAY) ? 0 : -EIO; 794 error = (bret->status == BLKIF_RSP_OKAY) ? 0 : -EIO;
757 switch (bret->operation) { 795 switch (bret->operation) {
758 case BLKIF_OP_DISCARD: 796 case BLKIF_OP_DISCARD:
759 if (unlikely(bret->status == BLKIF_RSP_EOPNOTSUPP)) { 797 if (unlikely(bret->status == BLKIF_RSP_EOPNOTSUPP)) {
760 struct request_queue *rq = info->rq; 798 struct request_queue *rq = info->rq;
761 printk(KERN_WARNING "blkfront: %s: discard op failed\n", 799 printk(KERN_WARNING "blkfront: %s: %s op failed\n",
762 info->gd->disk_name); 800 info->gd->disk_name, op_name(bret->operation));
763 error = -EOPNOTSUPP; 801 error = -EOPNOTSUPP;
764 info->feature_discard = 0; 802 info->feature_discard = 0;
765 info->feature_secdiscard = 0; 803 info->feature_secdiscard = 0;
@@ -771,18 +809,14 @@ static irqreturn_t blkif_interrupt(int irq, void *dev_id)
771 case BLKIF_OP_FLUSH_DISKCACHE: 809 case BLKIF_OP_FLUSH_DISKCACHE:
772 case BLKIF_OP_WRITE_BARRIER: 810 case BLKIF_OP_WRITE_BARRIER:
773 if (unlikely(bret->status == BLKIF_RSP_EOPNOTSUPP)) { 811 if (unlikely(bret->status == BLKIF_RSP_EOPNOTSUPP)) {
774 printk(KERN_WARNING "blkfront: %s: write %s op failed\n", 812 printk(KERN_WARNING "blkfront: %s: %s op failed\n",
775 info->flush_op == BLKIF_OP_WRITE_BARRIER ? 813 info->gd->disk_name, op_name(bret->operation));
776 "barrier" : "flush disk cache",
777 info->gd->disk_name);
778 error = -EOPNOTSUPP; 814 error = -EOPNOTSUPP;
779 } 815 }
780 if (unlikely(bret->status == BLKIF_RSP_ERROR && 816 if (unlikely(bret->status == BLKIF_RSP_ERROR &&
781 info->shadow[id].req.u.rw.nr_segments == 0)) { 817 info->shadow[id].req.u.rw.nr_segments == 0)) {
782 printk(KERN_WARNING "blkfront: %s: empty write %s op failed\n", 818 printk(KERN_WARNING "blkfront: %s: empty %s op failed\n",
783 info->flush_op == BLKIF_OP_WRITE_BARRIER ? 819 info->gd->disk_name, op_name(bret->operation));
784 "barrier" : "flush disk cache",
785 info->gd->disk_name);
786 error = -EOPNOTSUPP; 820 error = -EOPNOTSUPP;
787 } 821 }
788 if (unlikely(error)) { 822 if (unlikely(error)) {
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index dcbe05616090..9a1eb0cfa95f 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -1067,26 +1067,24 @@ static int __clk_set_parent(struct clk *clk, struct clk *parent)
1067 1067
1068 old_parent = clk->parent; 1068 old_parent = clk->parent;
1069 1069
1070 /* find index of new parent clock using cached parent ptrs */ 1070 if (!clk->parents)
1071 if (clk->parents)
1072 for (i = 0; i < clk->num_parents; i++)
1073 if (clk->parents[i] == parent)
1074 break;
1075 else
1076 clk->parents = kzalloc((sizeof(struct clk*) * clk->num_parents), 1071 clk->parents = kzalloc((sizeof(struct clk*) * clk->num_parents),
1077 GFP_KERNEL); 1072 GFP_KERNEL);
1078 1073
1079 /* 1074 /*
1080 * find index of new parent clock using string name comparison 1075 * find index of new parent clock using cached parent ptrs,
1081 * also try to cache the parent to avoid future calls to __clk_lookup 1076 * or if not yet cached, use string name comparison and cache
1077 * them now to avoid future calls to __clk_lookup.
1082 */ 1078 */
1083 if (i == clk->num_parents) 1079 for (i = 0; i < clk->num_parents; i++) {
1084 for (i = 0; i < clk->num_parents; i++) 1080 if (clk->parents && clk->parents[i] == parent)
1085 if (!strcmp(clk->parent_names[i], parent->name)) { 1081 break;
1086 if (clk->parents) 1082 else if (!strcmp(clk->parent_names[i], parent->name)) {
1087 clk->parents[i] = __clk_lookup(parent->name); 1083 if (clk->parents)
1088 break; 1084 clk->parents[i] = __clk_lookup(parent->name);
1089 } 1085 break;
1086 }
1087 }
1090 1088
1091 if (i == clk->num_parents) { 1089 if (i == clk->num_parents) {
1092 pr_debug("%s: clock %s is not a possible parent of clock %s\n", 1090 pr_debug("%s: clock %s is not a possible parent of clock %s\n",
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index c4067d0141f7..542f0c04b695 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -136,7 +136,7 @@ config GPIO_MPC8XXX
136 136
137config GPIO_MSM_V1 137config GPIO_MSM_V1
138 tristate "Qualcomm MSM GPIO v1" 138 tristate "Qualcomm MSM GPIO v1"
139 depends on GPIOLIB && ARCH_MSM 139 depends on GPIOLIB && ARCH_MSM && (ARCH_MSM7X00A || ARCH_MSM7X30 || ARCH_QSD8X50)
140 help 140 help
141 Say yes here to support the GPIO interface on ARM v6 based 141 Say yes here to support the GPIO interface on ARM v6 based
142 Qualcomm MSM chips. Most of the pins on the MSM can be 142 Qualcomm MSM chips. Most of the pins on the MSM can be
diff --git a/drivers/gpio/devres.c b/drivers/gpio/devres.c
index 9e9947cb86a3..1077754f8289 100644
--- a/drivers/gpio/devres.c
+++ b/drivers/gpio/devres.c
@@ -98,6 +98,7 @@ int devm_gpio_request_one(struct device *dev, unsigned gpio,
98 98
99 return 0; 99 return 0;
100} 100}
101EXPORT_SYMBOL(devm_gpio_request_one);
101 102
102/** 103/**
103 * devm_gpio_free - free an interrupt 104 * devm_gpio_free - free an interrupt
diff --git a/drivers/gpio/gpio-mxc.c b/drivers/gpio/gpio-mxc.c
index c337143b18f8..c89c4c1e668d 100644
--- a/drivers/gpio/gpio-mxc.c
+++ b/drivers/gpio/gpio-mxc.c
@@ -398,10 +398,12 @@ static int __devinit mxc_gpio_probe(struct platform_device *pdev)
398 writel(~0, port->base + GPIO_ISR); 398 writel(~0, port->base + GPIO_ISR);
399 399
400 if (mxc_gpio_hwtype == IMX21_GPIO) { 400 if (mxc_gpio_hwtype == IMX21_GPIO) {
401 /* setup one handler for all GPIO interrupts */ 401 /*
402 if (pdev->id == 0) 402 * Setup one handler for all GPIO interrupts. Actually setting
403 irq_set_chained_handler(port->irq, 403 * the handler is needed only once, but doing it for every port
404 mx2_gpio_irq_handler); 404 * is more robust and easier.
405 */
406 irq_set_chained_handler(port->irq, mx2_gpio_irq_handler);
405 } else { 407 } else {
406 /* setup one handler for each entry */ 408 /* setup one handler for each entry */
407 irq_set_chained_handler(port->irq, mx3_gpio_irq_handler); 409 irq_set_chained_handler(port->irq, mx3_gpio_irq_handler);
diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
index c4ed1722734c..4fbc208c32cf 100644
--- a/drivers/gpio/gpio-omap.c
+++ b/drivers/gpio/gpio-omap.c
@@ -174,12 +174,22 @@ static inline void _gpio_dbck_enable(struct gpio_bank *bank)
174 if (bank->dbck_enable_mask && !bank->dbck_enabled) { 174 if (bank->dbck_enable_mask && !bank->dbck_enabled) {
175 clk_enable(bank->dbck); 175 clk_enable(bank->dbck);
176 bank->dbck_enabled = true; 176 bank->dbck_enabled = true;
177
178 __raw_writel(bank->dbck_enable_mask,
179 bank->base + bank->regs->debounce_en);
177 } 180 }
178} 181}
179 182
180static inline void _gpio_dbck_disable(struct gpio_bank *bank) 183static inline void _gpio_dbck_disable(struct gpio_bank *bank)
181{ 184{
182 if (bank->dbck_enable_mask && bank->dbck_enabled) { 185 if (bank->dbck_enable_mask && bank->dbck_enabled) {
186 /*
187 * Disable debounce before cutting it's clock. If debounce is
188 * enabled but the clock is not, GPIO module seems to be unable
189 * to detect events and generate interrupts at least on OMAP3.
190 */
191 __raw_writel(0, bank->base + bank->regs->debounce_en);
192
183 clk_disable(bank->dbck); 193 clk_disable(bank->dbck);
184 bank->dbck_enabled = false; 194 bank->dbck_enabled = false;
185 } 195 }
@@ -1081,7 +1091,6 @@ static int __devinit omap_gpio_probe(struct platform_device *pdev)
1081 bank->is_mpuio = pdata->is_mpuio; 1091 bank->is_mpuio = pdata->is_mpuio;
1082 bank->non_wakeup_gpios = pdata->non_wakeup_gpios; 1092 bank->non_wakeup_gpios = pdata->non_wakeup_gpios;
1083 bank->loses_context = pdata->loses_context; 1093 bank->loses_context = pdata->loses_context;
1084 bank->get_context_loss_count = pdata->get_context_loss_count;
1085 bank->regs = pdata->regs; 1094 bank->regs = pdata->regs;
1086#ifdef CONFIG_OF_GPIO 1095#ifdef CONFIG_OF_GPIO
1087 bank->chip.of_node = of_node_get(node); 1096 bank->chip.of_node = of_node_get(node);
@@ -1135,6 +1144,9 @@ static int __devinit omap_gpio_probe(struct platform_device *pdev)
1135 omap_gpio_chip_init(bank); 1144 omap_gpio_chip_init(bank);
1136 omap_gpio_show_rev(bank); 1145 omap_gpio_show_rev(bank);
1137 1146
1147 if (bank->loses_context)
1148 bank->get_context_loss_count = pdata->get_context_loss_count;
1149
1138 pm_runtime_put(bank->dev); 1150 pm_runtime_put(bank->dev);
1139 1151
1140 list_add_tail(&bank->node, &omap_gpio_list); 1152 list_add_tail(&bank->node, &omap_gpio_list);
diff --git a/drivers/gpio/gpio-sta2x11.c b/drivers/gpio/gpio-sta2x11.c
index 38416be8ba11..6064fb376e11 100644
--- a/drivers/gpio/gpio-sta2x11.c
+++ b/drivers/gpio/gpio-sta2x11.c
@@ -383,8 +383,9 @@ static int __devinit gsta_probe(struct platform_device *dev)
383 } 383 }
384 spin_lock_init(&chip->lock); 384 spin_lock_init(&chip->lock);
385 gsta_gpio_setup(chip); 385 gsta_gpio_setup(chip);
386 for (i = 0; i < GSTA_NR_GPIO; i++) 386 if (gpio_pdata)
387 gsta_set_config(chip, i, gpio_pdata->pinconfig[i]); 387 for (i = 0; i < GSTA_NR_GPIO; i++)
388 gsta_set_config(chip, i, gpio_pdata->pinconfig[i]);
388 389
389 /* 384 was used in previous code: be compatible for other drivers */ 390 /* 384 was used in previous code: be compatible for other drivers */
390 err = irq_alloc_descs(-1, 384, GSTA_NR_GPIO, NUMA_NO_NODE); 391 err = irq_alloc_descs(-1, 384, GSTA_NR_GPIO, NUMA_NO_NODE);
diff --git a/drivers/gpio/gpio-tps65910.c b/drivers/gpio/gpio-tps65910.c
index c1ad2884f2ed..11f29c82253c 100644
--- a/drivers/gpio/gpio-tps65910.c
+++ b/drivers/gpio/gpio-tps65910.c
@@ -149,6 +149,9 @@ static int __devinit tps65910_gpio_probe(struct platform_device *pdev)
149 tps65910_gpio->gpio_chip.set = tps65910_gpio_set; 149 tps65910_gpio->gpio_chip.set = tps65910_gpio_set;
150 tps65910_gpio->gpio_chip.get = tps65910_gpio_get; 150 tps65910_gpio->gpio_chip.get = tps65910_gpio_get;
151 tps65910_gpio->gpio_chip.dev = &pdev->dev; 151 tps65910_gpio->gpio_chip.dev = &pdev->dev;
152#ifdef CONFIG_OF_GPIO
153 tps65910_gpio->gpio_chip.of_node = tps65910->dev->of_node;
154#endif
152 if (pdata && pdata->gpio_base) 155 if (pdata && pdata->gpio_base)
153 tps65910_gpio->gpio_chip.base = pdata->gpio_base; 156 tps65910_gpio->gpio_chip.base = pdata->gpio_base;
154 else 157 else
diff --git a/drivers/gpio/gpio-wm8994.c b/drivers/gpio/gpio-wm8994.c
index 92ea5350dfe9..aa61ad2fcaaa 100644
--- a/drivers/gpio/gpio-wm8994.c
+++ b/drivers/gpio/gpio-wm8994.c
@@ -89,8 +89,11 @@ static int wm8994_gpio_direction_out(struct gpio_chip *chip,
89 struct wm8994_gpio *wm8994_gpio = to_wm8994_gpio(chip); 89 struct wm8994_gpio *wm8994_gpio = to_wm8994_gpio(chip);
90 struct wm8994 *wm8994 = wm8994_gpio->wm8994; 90 struct wm8994 *wm8994 = wm8994_gpio->wm8994;
91 91
92 if (value)
93 value = WM8994_GPN_LVL;
94
92 return wm8994_set_bits(wm8994, WM8994_GPIO_1 + offset, 95 return wm8994_set_bits(wm8994, WM8994_GPIO_1 + offset,
93 WM8994_GPN_DIR, 0); 96 WM8994_GPN_DIR | WM8994_GPN_LVL, value);
94} 97}
95 98
96static void wm8994_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 99static void wm8994_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
index 5873e481e5d2..a8743c399e83 100644
--- a/drivers/gpu/drm/drm_edid.c
+++ b/drivers/gpu/drm/drm_edid.c
@@ -1039,6 +1039,24 @@ mode_in_range(const struct drm_display_mode *mode, struct edid *edid,
1039 return true; 1039 return true;
1040} 1040}
1041 1041
1042static bool valid_inferred_mode(const struct drm_connector *connector,
1043 const struct drm_display_mode *mode)
1044{
1045 struct drm_display_mode *m;
1046 bool ok = false;
1047
1048 list_for_each_entry(m, &connector->probed_modes, head) {
1049 if (mode->hdisplay == m->hdisplay &&
1050 mode->vdisplay == m->vdisplay &&
1051 drm_mode_vrefresh(mode) == drm_mode_vrefresh(m))
1052 return false; /* duplicated */
1053 if (mode->hdisplay <= m->hdisplay &&
1054 mode->vdisplay <= m->vdisplay)
1055 ok = true;
1056 }
1057 return ok;
1058}
1059
1042static int 1060static int
1043drm_dmt_modes_for_range(struct drm_connector *connector, struct edid *edid, 1061drm_dmt_modes_for_range(struct drm_connector *connector, struct edid *edid,
1044 struct detailed_timing *timing) 1062 struct detailed_timing *timing)
@@ -1048,7 +1066,8 @@ drm_dmt_modes_for_range(struct drm_connector *connector, struct edid *edid,
1048 struct drm_device *dev = connector->dev; 1066 struct drm_device *dev = connector->dev;
1049 1067
1050 for (i = 0; i < drm_num_dmt_modes; i++) { 1068 for (i = 0; i < drm_num_dmt_modes; i++) {
1051 if (mode_in_range(drm_dmt_modes + i, edid, timing)) { 1069 if (mode_in_range(drm_dmt_modes + i, edid, timing) &&
1070 valid_inferred_mode(connector, drm_dmt_modes + i)) {
1052 newmode = drm_mode_duplicate(dev, &drm_dmt_modes[i]); 1071 newmode = drm_mode_duplicate(dev, &drm_dmt_modes[i]);
1053 if (newmode) { 1072 if (newmode) {
1054 drm_mode_probed_add(connector, newmode); 1073 drm_mode_probed_add(connector, newmode);
@@ -1088,7 +1107,8 @@ drm_gtf_modes_for_range(struct drm_connector *connector, struct edid *edid,
1088 return modes; 1107 return modes;
1089 1108
1090 fixup_mode_1366x768(newmode); 1109 fixup_mode_1366x768(newmode);
1091 if (!mode_in_range(newmode, edid, timing)) { 1110 if (!mode_in_range(newmode, edid, timing) ||
1111 !valid_inferred_mode(connector, newmode)) {
1092 drm_mode_destroy(dev, newmode); 1112 drm_mode_destroy(dev, newmode);
1093 continue; 1113 continue;
1094 } 1114 }
@@ -1116,7 +1136,8 @@ drm_cvt_modes_for_range(struct drm_connector *connector, struct edid *edid,
1116 return modes; 1136 return modes;
1117 1137
1118 fixup_mode_1366x768(newmode); 1138 fixup_mode_1366x768(newmode);
1119 if (!mode_in_range(newmode, edid, timing)) { 1139 if (!mode_in_range(newmode, edid, timing) ||
1140 !valid_inferred_mode(connector, newmode)) {
1120 drm_mode_destroy(dev, newmode); 1141 drm_mode_destroy(dev, newmode);
1121 continue; 1142 continue;
1122 } 1143 }
diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
index f94792626b94..36822b924eb1 100644
--- a/drivers/gpu/drm/i915/i915_dma.c
+++ b/drivers/gpu/drm/i915/i915_dma.c
@@ -1401,6 +1401,27 @@ i915_mtrr_setup(struct drm_i915_private *dev_priv, unsigned long base,
1401 } 1401 }
1402} 1402}
1403 1403
1404static void i915_kick_out_firmware_fb(struct drm_i915_private *dev_priv)
1405{
1406 struct apertures_struct *ap;
1407 struct pci_dev *pdev = dev_priv->dev->pdev;
1408 bool primary;
1409
1410 ap = alloc_apertures(1);
1411 if (!ap)
1412 return;
1413
1414 ap->ranges[0].base = dev_priv->dev->agp->base;
1415 ap->ranges[0].size =
1416 dev_priv->mm.gtt->gtt_mappable_entries << PAGE_SHIFT;
1417 primary =
1418 pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW;
1419
1420 remove_conflicting_framebuffers(ap, "inteldrmfb", primary);
1421
1422 kfree(ap);
1423}
1424
1404/** 1425/**
1405 * i915_driver_load - setup chip and create an initial config 1426 * i915_driver_load - setup chip and create an initial config
1406 * @dev: DRM device 1427 * @dev: DRM device
@@ -1446,6 +1467,15 @@ int i915_driver_load(struct drm_device *dev, unsigned long flags)
1446 goto free_priv; 1467 goto free_priv;
1447 } 1468 }
1448 1469
1470 dev_priv->mm.gtt = intel_gtt_get();
1471 if (!dev_priv->mm.gtt) {
1472 DRM_ERROR("Failed to initialize GTT\n");
1473 ret = -ENODEV;
1474 goto put_bridge;
1475 }
1476
1477 i915_kick_out_firmware_fb(dev_priv);
1478
1449 pci_set_master(dev->pdev); 1479 pci_set_master(dev->pdev);
1450 1480
1451 /* overlay on gen2 is broken and can't address above 1G */ 1481 /* overlay on gen2 is broken and can't address above 1G */
@@ -1471,13 +1501,6 @@ int i915_driver_load(struct drm_device *dev, unsigned long flags)
1471 goto put_bridge; 1501 goto put_bridge;
1472 } 1502 }
1473 1503
1474 dev_priv->mm.gtt = intel_gtt_get();
1475 if (!dev_priv->mm.gtt) {
1476 DRM_ERROR("Failed to initialize GTT\n");
1477 ret = -ENODEV;
1478 goto out_rmmap;
1479 }
1480
1481 aperture_size = dev_priv->mm.gtt->gtt_mappable_entries << PAGE_SHIFT; 1504 aperture_size = dev_priv->mm.gtt->gtt_mappable_entries << PAGE_SHIFT;
1482 1505
1483 dev_priv->mm.gtt_mapping = 1506 dev_priv->mm.gtt_mapping =
diff --git a/drivers/gpu/drm/radeon/radeon_gart.c b/drivers/gpu/drm/radeon/radeon_gart.c
index 59d44937dd9f..84b648a7ddd8 100644
--- a/drivers/gpu/drm/radeon/radeon_gart.c
+++ b/drivers/gpu/drm/radeon/radeon_gart.c
@@ -289,8 +289,9 @@ int radeon_vm_manager_init(struct radeon_device *rdev)
289 rdev->vm_manager.enabled = false; 289 rdev->vm_manager.enabled = false;
290 290
291 /* mark first vm as always in use, it's the system one */ 291 /* mark first vm as always in use, it's the system one */
292 /* allocate enough for 2 full VM pts */
292 r = radeon_sa_bo_manager_init(rdev, &rdev->vm_manager.sa_manager, 293 r = radeon_sa_bo_manager_init(rdev, &rdev->vm_manager.sa_manager,
293 rdev->vm_manager.max_pfn * 8, 294 rdev->vm_manager.max_pfn * 8 * 2,
294 RADEON_GEM_DOMAIN_VRAM); 295 RADEON_GEM_DOMAIN_VRAM);
295 if (r) { 296 if (r) {
296 dev_err(rdev->dev, "failed to allocate vm bo (%dKB)\n", 297 dev_err(rdev->dev, "failed to allocate vm bo (%dKB)\n",
@@ -633,7 +634,15 @@ int radeon_vm_init(struct radeon_device *rdev, struct radeon_vm *vm)
633 mutex_init(&vm->mutex); 634 mutex_init(&vm->mutex);
634 INIT_LIST_HEAD(&vm->list); 635 INIT_LIST_HEAD(&vm->list);
635 INIT_LIST_HEAD(&vm->va); 636 INIT_LIST_HEAD(&vm->va);
636 vm->last_pfn = 0; 637 /* SI requires equal sized PTs for all VMs, so always set
638 * last_pfn to max_pfn. cayman allows variable sized
639 * pts so we can grow then as needed. Once we switch
640 * to two level pts we can unify this again.
641 */
642 if (rdev->family >= CHIP_TAHITI)
643 vm->last_pfn = rdev->vm_manager.max_pfn;
644 else
645 vm->last_pfn = 0;
637 /* map the ib pool buffer at 0 in virtual address space, set 646 /* map the ib pool buffer at 0 in virtual address space, set
638 * read only 647 * read only
639 */ 648 */
diff --git a/drivers/gpu/drm/radeon/radeon_gem.c b/drivers/gpu/drm/radeon/radeon_gem.c
index f28bd4b7ef98..21ec9f5653ce 100644
--- a/drivers/gpu/drm/radeon/radeon_gem.c
+++ b/drivers/gpu/drm/radeon/radeon_gem.c
@@ -292,6 +292,7 @@ int radeon_gem_mmap_ioctl(struct drm_device *dev, void *data,
292int radeon_gem_busy_ioctl(struct drm_device *dev, void *data, 292int radeon_gem_busy_ioctl(struct drm_device *dev, void *data,
293 struct drm_file *filp) 293 struct drm_file *filp)
294{ 294{
295 struct radeon_device *rdev = dev->dev_private;
295 struct drm_radeon_gem_busy *args = data; 296 struct drm_radeon_gem_busy *args = data;
296 struct drm_gem_object *gobj; 297 struct drm_gem_object *gobj;
297 struct radeon_bo *robj; 298 struct radeon_bo *robj;
@@ -317,13 +318,14 @@ int radeon_gem_busy_ioctl(struct drm_device *dev, void *data,
317 break; 318 break;
318 } 319 }
319 drm_gem_object_unreference_unlocked(gobj); 320 drm_gem_object_unreference_unlocked(gobj);
320 r = radeon_gem_handle_lockup(robj->rdev, r); 321 r = radeon_gem_handle_lockup(rdev, r);
321 return r; 322 return r;
322} 323}
323 324
324int radeon_gem_wait_idle_ioctl(struct drm_device *dev, void *data, 325int radeon_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
325 struct drm_file *filp) 326 struct drm_file *filp)
326{ 327{
328 struct radeon_device *rdev = dev->dev_private;
327 struct drm_radeon_gem_wait_idle *args = data; 329 struct drm_radeon_gem_wait_idle *args = data;
328 struct drm_gem_object *gobj; 330 struct drm_gem_object *gobj;
329 struct radeon_bo *robj; 331 struct radeon_bo *robj;
@@ -336,10 +338,10 @@ int radeon_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
336 robj = gem_to_radeon_bo(gobj); 338 robj = gem_to_radeon_bo(gobj);
337 r = radeon_bo_wait(robj, NULL, false); 339 r = radeon_bo_wait(robj, NULL, false);
338 /* callback hw specific functions if any */ 340 /* callback hw specific functions if any */
339 if (robj->rdev->asic->ioctl_wait_idle) 341 if (rdev->asic->ioctl_wait_idle)
340 robj->rdev->asic->ioctl_wait_idle(robj->rdev, robj); 342 robj->rdev->asic->ioctl_wait_idle(rdev, robj);
341 drm_gem_object_unreference_unlocked(gobj); 343 drm_gem_object_unreference_unlocked(gobj);
342 r = radeon_gem_handle_lockup(robj->rdev, r); 344 r = radeon_gem_handle_lockup(rdev, r);
343 return r; 345 return r;
344} 346}
345 347
diff --git a/drivers/gpu/drm/radeon/si.c b/drivers/gpu/drm/radeon/si.c
index c7b61f16ecfd..0b0279291a73 100644
--- a/drivers/gpu/drm/radeon/si.c
+++ b/drivers/gpu/drm/radeon/si.c
@@ -2365,12 +2365,12 @@ int si_pcie_gart_enable(struct radeon_device *rdev)
2365 WREG32(0x15DC, 0); 2365 WREG32(0x15DC, 0);
2366 2366
2367 /* empty context1-15 */ 2367 /* empty context1-15 */
2368 /* FIXME start with 1G, once using 2 level pt switch to full 2368 /* FIXME start with 4G, once using 2 level pt switch to full
2369 * vm size space 2369 * vm size space
2370 */ 2370 */
2371 /* set vm size, must be a multiple of 4 */ 2371 /* set vm size, must be a multiple of 4 */
2372 WREG32(VM_CONTEXT1_PAGE_TABLE_START_ADDR, 0); 2372 WREG32(VM_CONTEXT1_PAGE_TABLE_START_ADDR, 0);
2373 WREG32(VM_CONTEXT1_PAGE_TABLE_END_ADDR, (1 << 30) / RADEON_GPU_PAGE_SIZE); 2373 WREG32(VM_CONTEXT1_PAGE_TABLE_END_ADDR, rdev->vm_manager.max_pfn);
2374 for (i = 1; i < 16; i++) { 2374 for (i = 1; i < 16; i++) {
2375 if (i < 8) 2375 if (i < 8)
2376 WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (i << 2), 2376 WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (i << 2),
diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c
index fa10f847f7db..585344b6d338 100644
--- a/drivers/hid/hid-apple.c
+++ b/drivers/hid/hid-apple.c
@@ -517,6 +517,12 @@ static const struct hid_device_id apple_devices[] = {
517 .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD }, 517 .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD },
518 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_JIS), 518 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_JIS),
519 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS }, 519 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
520 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ANSI),
521 .driver_data = APPLE_HAS_FN },
522 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ISO),
523 .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD },
524 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_JIS),
525 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
520 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI), 526 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI),
521 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, 527 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
522 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO), 528 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO),
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 6ac0286b5375..4c87276c8ddb 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -1503,6 +1503,9 @@ static const struct hid_device_id hid_have_special_driver[] = {
1503 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ANSI) }, 1503 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ANSI) },
1504 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ISO) }, 1504 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ISO) },
1505 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_JIS) }, 1505 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_JIS) },
1506 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ANSI) },
1507 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ISO) },
1508 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_JIS) },
1506 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI) }, 1509 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI) },
1507 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO) }, 1510 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO) },
1508 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS) }, 1511 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS) },
@@ -1995,6 +1998,7 @@ static const struct hid_device_id hid_ignore_list[] = {
1995 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MCT) }, 1998 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MCT) },
1996 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_HYBRID) }, 1999 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_HYBRID) },
1997 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_HEATCONTROL) }, 2000 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_HEATCONTROL) },
2001 { HID_USB_DEVICE(USB_VENDOR_ID_MADCATZ, USB_DEVICE_ID_MADCATZ_BEATPAD) },
1998 { HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1024LS) }, 2002 { HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1024LS) },
1999 { HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1208LS) }, 2003 { HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1208LS) },
2000 { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT1) }, 2004 { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT1) },
@@ -2089,6 +2093,9 @@ static const struct hid_device_id hid_mouse_ignore_list[] = {
2089 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ANSI) }, 2093 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ANSI) },
2090 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ISO) }, 2094 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ISO) },
2091 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_JIS) }, 2095 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_JIS) },
2096 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ANSI) },
2097 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ISO) },
2098 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_JIS) },
2092 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) }, 2099 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) },
2093 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) }, 2100 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) },
2094 { } 2101 { }
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index d1cdd2d28409..875ff451842b 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -125,6 +125,9 @@
125#define USB_DEVICE_ID_APPLE_WELLSPRING6_ANSI 0x024c 125#define USB_DEVICE_ID_APPLE_WELLSPRING6_ANSI 0x024c
126#define USB_DEVICE_ID_APPLE_WELLSPRING6_ISO 0x024d 126#define USB_DEVICE_ID_APPLE_WELLSPRING6_ISO 0x024d
127#define USB_DEVICE_ID_APPLE_WELLSPRING6_JIS 0x024e 127#define USB_DEVICE_ID_APPLE_WELLSPRING6_JIS 0x024e
128#define USB_DEVICE_ID_APPLE_WELLSPRING7_ANSI 0x0262
129#define USB_DEVICE_ID_APPLE_WELLSPRING7_ISO 0x0263
130#define USB_DEVICE_ID_APPLE_WELLSPRING7_JIS 0x0264
128#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI 0x0239 131#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI 0x0239
129#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO 0x023a 132#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO 0x023a
130#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS 0x023b 133#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS 0x023b
@@ -518,6 +521,9 @@
518#define USB_DEVICE_ID_CRYSTALTOUCH 0x0006 521#define USB_DEVICE_ID_CRYSTALTOUCH 0x0006
519#define USB_DEVICE_ID_CRYSTALTOUCH_DUAL 0x0007 522#define USB_DEVICE_ID_CRYSTALTOUCH_DUAL 0x0007
520 523
524#define USB_VENDOR_ID_MADCATZ 0x0738
525#define USB_DEVICE_ID_MADCATZ_BEATPAD 0x4540
526
521#define USB_VENDOR_ID_MCC 0x09db 527#define USB_VENDOR_ID_MCC 0x09db
522#define USB_DEVICE_ID_MCC_PMD1024LS 0x0076 528#define USB_DEVICE_ID_MCC_PMD1024LS 0x0076
523#define USB_DEVICE_ID_MCC_PMD1208LS 0x007a 529#define USB_DEVICE_ID_MCC_PMD1208LS 0x007a
diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c
index e7701d99f8e8..f1de3979181f 100644
--- a/drivers/hwmon/it87.c
+++ b/drivers/hwmon/it87.c
@@ -2341,7 +2341,7 @@ static void __devinit it87_init_device(struct platform_device *pdev)
2341 2341
2342 /* Start monitoring */ 2342 /* Start monitoring */
2343 it87_write_value(data, IT87_REG_CONFIG, 2343 it87_write_value(data, IT87_REG_CONFIG,
2344 (it87_read_value(data, IT87_REG_CONFIG) & 0x36) 2344 (it87_read_value(data, IT87_REG_CONFIG) & 0x3e)
2345 | (update_vbat ? 0x41 : 0x01)); 2345 | (update_vbat ? 0x41 : 0x01));
2346} 2346}
2347 2347
diff --git a/drivers/hwspinlock/hwspinlock_core.c b/drivers/hwspinlock/hwspinlock_core.c
index 61c9cf15fa52..1201a15784c3 100644
--- a/drivers/hwspinlock/hwspinlock_core.c
+++ b/drivers/hwspinlock/hwspinlock_core.c
@@ -345,7 +345,7 @@ int hwspin_lock_register(struct hwspinlock_device *bank, struct device *dev,
345 spin_lock_init(&hwlock->lock); 345 spin_lock_init(&hwlock->lock);
346 hwlock->bank = bank; 346 hwlock->bank = bank;
347 347
348 ret = hwspin_lock_register_single(hwlock, i); 348 ret = hwspin_lock_register_single(hwlock, base_id + i);
349 if (ret) 349 if (ret)
350 goto reg_failed; 350 goto reg_failed;
351 } 351 }
@@ -354,7 +354,7 @@ int hwspin_lock_register(struct hwspinlock_device *bank, struct device *dev,
354 354
355reg_failed: 355reg_failed:
356 while (--i >= 0) 356 while (--i >= 0)
357 hwspin_lock_unregister_single(i); 357 hwspin_lock_unregister_single(base_id + i);
358 return ret; 358 return ret;
359} 359}
360EXPORT_SYMBOL_GPL(hwspin_lock_register); 360EXPORT_SYMBOL_GPL(hwspin_lock_register);
diff --git a/drivers/input/joystick/as5011.c b/drivers/input/joystick/as5011.c
index 57d19d4e0a2d..c96653b58867 100644
--- a/drivers/input/joystick/as5011.c
+++ b/drivers/input/joystick/as5011.c
@@ -282,7 +282,8 @@ static int __devinit as5011_probe(struct i2c_client *client,
282 282
283 error = request_threaded_irq(as5011->button_irq, 283 error = request_threaded_irq(as5011->button_irq,
284 NULL, as5011_button_interrupt, 284 NULL, as5011_button_interrupt,
285 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, 285 IRQF_TRIGGER_RISING |
286 IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
286 "as5011_button", as5011); 287 "as5011_button", as5011);
287 if (error < 0) { 288 if (error < 0) {
288 dev_err(&client->dev, 289 dev_err(&client->dev,
@@ -296,7 +297,7 @@ static int __devinit as5011_probe(struct i2c_client *client,
296 297
297 error = request_threaded_irq(as5011->axis_irq, NULL, 298 error = request_threaded_irq(as5011->axis_irq, NULL,
298 as5011_axis_interrupt, 299 as5011_axis_interrupt,
299 plat_data->axis_irqflags, 300 plat_data->axis_irqflags | IRQF_ONESHOT,
300 "as5011_joystick", as5011); 301 "as5011_joystick", as5011);
301 if (error) { 302 if (error) {
302 dev_err(&client->dev, 303 dev_err(&client->dev,
diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
index ee16fb67b7ae..83811e45d633 100644
--- a/drivers/input/joystick/xpad.c
+++ b/drivers/input/joystick/xpad.c
@@ -142,6 +142,7 @@ static const struct xpad_device {
142 { 0x0c12, 0x880a, "Pelican Eclipse PL-2023", 0, XTYPE_XBOX }, 142 { 0x0c12, 0x880a, "Pelican Eclipse PL-2023", 0, XTYPE_XBOX },
143 { 0x0c12, 0x8810, "Zeroplus Xbox Controller", 0, XTYPE_XBOX }, 143 { 0x0c12, 0x8810, "Zeroplus Xbox Controller", 0, XTYPE_XBOX },
144 { 0x0c12, 0x9902, "HAMA VibraX - *FAULTY HARDWARE*", 0, XTYPE_XBOX }, 144 { 0x0c12, 0x9902, "HAMA VibraX - *FAULTY HARDWARE*", 0, XTYPE_XBOX },
145 { 0x0d2f, 0x0002, "Andamiro Pump It Up pad", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX },
145 { 0x0e4c, 0x1097, "Radica Gamester Controller", 0, XTYPE_XBOX }, 146 { 0x0e4c, 0x1097, "Radica Gamester Controller", 0, XTYPE_XBOX },
146 { 0x0e4c, 0x2390, "Radica Games Jtech Controller", 0, XTYPE_XBOX }, 147 { 0x0e4c, 0x2390, "Radica Games Jtech Controller", 0, XTYPE_XBOX },
147 { 0x0e6f, 0x0003, "Logic3 Freebird wireless Controller", 0, XTYPE_XBOX }, 148 { 0x0e6f, 0x0003, "Logic3 Freebird wireless Controller", 0, XTYPE_XBOX },
@@ -164,6 +165,7 @@ static const struct xpad_device {
164 { 0x1bad, 0x0003, "Harmonix Rock Band Drumkit", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360 }, 165 { 0x1bad, 0x0003, "Harmonix Rock Band Drumkit", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360 },
165 { 0x0f0d, 0x0016, "Hori Real Arcade Pro.EX", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 }, 166 { 0x0f0d, 0x0016, "Hori Real Arcade Pro.EX", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
166 { 0x0f0d, 0x000d, "Hori Fighting Stick EX2", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 }, 167 { 0x0f0d, 0x000d, "Hori Fighting Stick EX2", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
168 { 0x1689, 0xfd00, "Razer Onza Tournament Edition", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360 },
167 { 0xffff, 0xffff, "Chinese-made Xbox Controller", 0, XTYPE_XBOX }, 169 { 0xffff, 0xffff, "Chinese-made Xbox Controller", 0, XTYPE_XBOX },
168 { 0x0000, 0x0000, "Generic X-Box pad", 0, XTYPE_UNKNOWN } 170 { 0x0000, 0x0000, "Generic X-Box pad", 0, XTYPE_UNKNOWN }
169}; 171};
@@ -238,12 +240,14 @@ static struct usb_device_id xpad_table [] = {
238 XPAD_XBOX360_VENDOR(0x045e), /* Microsoft X-Box 360 controllers */ 240 XPAD_XBOX360_VENDOR(0x045e), /* Microsoft X-Box 360 controllers */
239 XPAD_XBOX360_VENDOR(0x046d), /* Logitech X-Box 360 style controllers */ 241 XPAD_XBOX360_VENDOR(0x046d), /* Logitech X-Box 360 style controllers */
240 XPAD_XBOX360_VENDOR(0x0738), /* Mad Catz X-Box 360 controllers */ 242 XPAD_XBOX360_VENDOR(0x0738), /* Mad Catz X-Box 360 controllers */
243 { USB_DEVICE(0x0738, 0x4540) }, /* Mad Catz Beat Pad */
241 XPAD_XBOX360_VENDOR(0x0e6f), /* 0x0e6f X-Box 360 controllers */ 244 XPAD_XBOX360_VENDOR(0x0e6f), /* 0x0e6f X-Box 360 controllers */
242 XPAD_XBOX360_VENDOR(0x12ab), /* X-Box 360 dance pads */ 245 XPAD_XBOX360_VENDOR(0x12ab), /* X-Box 360 dance pads */
243 XPAD_XBOX360_VENDOR(0x1430), /* RedOctane X-Box 360 controllers */ 246 XPAD_XBOX360_VENDOR(0x1430), /* RedOctane X-Box 360 controllers */
244 XPAD_XBOX360_VENDOR(0x146b), /* BigBen Interactive Controllers */ 247 XPAD_XBOX360_VENDOR(0x146b), /* BigBen Interactive Controllers */
245 XPAD_XBOX360_VENDOR(0x1bad), /* Harminix Rock Band Guitar and Drums */ 248 XPAD_XBOX360_VENDOR(0x1bad), /* Harminix Rock Band Guitar and Drums */
246 XPAD_XBOX360_VENDOR(0x0f0d), /* Hori Controllers */ 249 XPAD_XBOX360_VENDOR(0x0f0d), /* Hori Controllers */
250 XPAD_XBOX360_VENDOR(0x1689), /* Razer Onza */
247 { } 251 { }
248}; 252};
249 253
diff --git a/drivers/input/keyboard/mcs_touchkey.c b/drivers/input/keyboard/mcs_touchkey.c
index 64a0ca4c92f3..0d77f6c84950 100644
--- a/drivers/input/keyboard/mcs_touchkey.c
+++ b/drivers/input/keyboard/mcs_touchkey.c
@@ -178,7 +178,8 @@ static int __devinit mcs_touchkey_probe(struct i2c_client *client,
178 } 178 }
179 179
180 error = request_threaded_irq(client->irq, NULL, mcs_touchkey_interrupt, 180 error = request_threaded_irq(client->irq, NULL, mcs_touchkey_interrupt,
181 IRQF_TRIGGER_FALLING, client->dev.driver->name, data); 181 IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
182 client->dev.driver->name, data);
182 if (error) { 183 if (error) {
183 dev_err(&client->dev, "Failed to register interrupt\n"); 184 dev_err(&client->dev, "Failed to register interrupt\n");
184 goto err_free_mem; 185 goto err_free_mem;
diff --git a/drivers/input/keyboard/mpr121_touchkey.c b/drivers/input/keyboard/mpr121_touchkey.c
index caa218a51b5a..7613f1cac951 100644
--- a/drivers/input/keyboard/mpr121_touchkey.c
+++ b/drivers/input/keyboard/mpr121_touchkey.c
@@ -248,7 +248,7 @@ static int __devinit mpr_touchkey_probe(struct i2c_client *client,
248 248
249 error = request_threaded_irq(client->irq, NULL, 249 error = request_threaded_irq(client->irq, NULL,
250 mpr_touchkey_interrupt, 250 mpr_touchkey_interrupt,
251 IRQF_TRIGGER_FALLING, 251 IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
252 client->dev.driver->name, mpr121); 252 client->dev.driver->name, mpr121);
253 if (error) { 253 if (error) {
254 dev_err(&client->dev, "Failed to register interrupt\n"); 254 dev_err(&client->dev, "Failed to register interrupt\n");
diff --git a/drivers/input/keyboard/qt1070.c b/drivers/input/keyboard/qt1070.c
index 0b7b2f891752..ca68f2992d72 100644
--- a/drivers/input/keyboard/qt1070.c
+++ b/drivers/input/keyboard/qt1070.c
@@ -201,7 +201,8 @@ static int __devinit qt1070_probe(struct i2c_client *client,
201 msleep(QT1070_RESET_TIME); 201 msleep(QT1070_RESET_TIME);
202 202
203 err = request_threaded_irq(client->irq, NULL, qt1070_interrupt, 203 err = request_threaded_irq(client->irq, NULL, qt1070_interrupt,
204 IRQF_TRIGGER_NONE, client->dev.driver->name, data); 204 IRQF_TRIGGER_NONE | IRQF_ONESHOT,
205 client->dev.driver->name, data);
205 if (err) { 206 if (err) {
206 dev_err(&client->dev, "fail to request irq\n"); 207 dev_err(&client->dev, "fail to request irq\n");
207 goto err_free_mem; 208 goto err_free_mem;
diff --git a/drivers/input/keyboard/tca6416-keypad.c b/drivers/input/keyboard/tca6416-keypad.c
index 3afea3f89718..c355cdde8d22 100644
--- a/drivers/input/keyboard/tca6416-keypad.c
+++ b/drivers/input/keyboard/tca6416-keypad.c
@@ -278,7 +278,8 @@ static int __devinit tca6416_keypad_probe(struct i2c_client *client,
278 278
279 error = request_threaded_irq(chip->irqnum, NULL, 279 error = request_threaded_irq(chip->irqnum, NULL,
280 tca6416_keys_isr, 280 tca6416_keys_isr,
281 IRQF_TRIGGER_FALLING, 281 IRQF_TRIGGER_FALLING |
282 IRQF_ONESHOT,
282 "tca6416-keypad", chip); 283 "tca6416-keypad", chip);
283 if (error) { 284 if (error) {
284 dev_dbg(&client->dev, 285 dev_dbg(&client->dev,
diff --git a/drivers/input/keyboard/tca8418_keypad.c b/drivers/input/keyboard/tca8418_keypad.c
index 5f87b28b3192..893869b29ed9 100644
--- a/drivers/input/keyboard/tca8418_keypad.c
+++ b/drivers/input/keyboard/tca8418_keypad.c
@@ -360,7 +360,7 @@ static int __devinit tca8418_keypad_probe(struct i2c_client *client,
360 client->irq = gpio_to_irq(client->irq); 360 client->irq = gpio_to_irq(client->irq);
361 361
362 error = request_threaded_irq(client->irq, NULL, tca8418_irq_handler, 362 error = request_threaded_irq(client->irq, NULL, tca8418_irq_handler,
363 IRQF_TRIGGER_FALLING, 363 IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
364 client->name, keypad_data); 364 client->name, keypad_data);
365 if (error) { 365 if (error) {
366 dev_dbg(&client->dev, 366 dev_dbg(&client->dev,
diff --git a/drivers/input/keyboard/tnetv107x-keypad.c b/drivers/input/keyboard/tnetv107x-keypad.c
index a4a445fb7020..4c34f21fbe2d 100644
--- a/drivers/input/keyboard/tnetv107x-keypad.c
+++ b/drivers/input/keyboard/tnetv107x-keypad.c
@@ -227,15 +227,15 @@ static int __devinit keypad_probe(struct platform_device *pdev)
227 goto error_clk; 227 goto error_clk;
228 } 228 }
229 229
230 error = request_threaded_irq(kp->irq_press, NULL, keypad_irq, 0, 230 error = request_threaded_irq(kp->irq_press, NULL, keypad_irq,
231 dev_name(dev), kp); 231 IRQF_ONESHOT, dev_name(dev), kp);
232 if (error < 0) { 232 if (error < 0) {
233 dev_err(kp->dev, "Could not allocate keypad press key irq\n"); 233 dev_err(kp->dev, "Could not allocate keypad press key irq\n");
234 goto error_irq_press; 234 goto error_irq_press;
235 } 235 }
236 236
237 error = request_threaded_irq(kp->irq_release, NULL, keypad_irq, 0, 237 error = request_threaded_irq(kp->irq_release, NULL, keypad_irq,
238 dev_name(dev), kp); 238 IRQF_ONESHOT, dev_name(dev), kp);
239 if (error < 0) { 239 if (error < 0) {
240 dev_err(kp->dev, "Could not allocate keypad release key irq\n"); 240 dev_err(kp->dev, "Could not allocate keypad release key irq\n");
241 goto error_irq_release; 241 goto error_irq_release;
diff --git a/drivers/input/misc/ad714x.c b/drivers/input/misc/ad714x.c
index 0ac75bbad4d6..2e5d5e1de647 100644
--- a/drivers/input/misc/ad714x.c
+++ b/drivers/input/misc/ad714x.c
@@ -972,6 +972,7 @@ struct ad714x_chip *ad714x_probe(struct device *dev, u16 bus_type, int irq,
972 struct ad714x_platform_data *plat_data = dev->platform_data; 972 struct ad714x_platform_data *plat_data = dev->platform_data;
973 struct ad714x_chip *ad714x; 973 struct ad714x_chip *ad714x;
974 void *drv_mem; 974 void *drv_mem;
975 unsigned long irqflags;
975 976
976 struct ad714x_button_drv *bt_drv; 977 struct ad714x_button_drv *bt_drv;
977 struct ad714x_slider_drv *sd_drv; 978 struct ad714x_slider_drv *sd_drv;
@@ -1162,10 +1163,11 @@ struct ad714x_chip *ad714x_probe(struct device *dev, u16 bus_type, int irq,
1162 alloc_idx++; 1163 alloc_idx++;
1163 } 1164 }
1164 1165
1166 irqflags = plat_data->irqflags ?: IRQF_TRIGGER_FALLING;
1167 irqflags |= IRQF_ONESHOT;
1168
1165 error = request_threaded_irq(ad714x->irq, NULL, ad714x_interrupt_thread, 1169 error = request_threaded_irq(ad714x->irq, NULL, ad714x_interrupt_thread,
1166 plat_data->irqflags ? 1170 irqflags, "ad714x_captouch", ad714x);
1167 plat_data->irqflags : IRQF_TRIGGER_FALLING,
1168 "ad714x_captouch", ad714x);
1169 if (error) { 1171 if (error) {
1170 dev_err(dev, "can't allocate irq %d\n", ad714x->irq); 1172 dev_err(dev, "can't allocate irq %d\n", ad714x->irq);
1171 goto err_unreg_dev; 1173 goto err_unreg_dev;
diff --git a/drivers/input/misc/dm355evm_keys.c b/drivers/input/misc/dm355evm_keys.c
index 35083c6836c3..c1313d8535c3 100644
--- a/drivers/input/misc/dm355evm_keys.c
+++ b/drivers/input/misc/dm355evm_keys.c
@@ -213,7 +213,8 @@ static int __devinit dm355evm_keys_probe(struct platform_device *pdev)
213 /* REVISIT: flush the event queue? */ 213 /* REVISIT: flush the event queue? */
214 214
215 status = request_threaded_irq(keys->irq, NULL, dm355evm_keys_irq, 215 status = request_threaded_irq(keys->irq, NULL, dm355evm_keys_irq,
216 IRQF_TRIGGER_FALLING, dev_name(&pdev->dev), keys); 216 IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
217 dev_name(&pdev->dev), keys);
217 if (status < 0) 218 if (status < 0)
218 goto fail2; 219 goto fail2;
219 220
diff --git a/drivers/input/mouse/bcm5974.c b/drivers/input/mouse/bcm5974.c
index 2cf681d98c0d..d528c23e194f 100644
--- a/drivers/input/mouse/bcm5974.c
+++ b/drivers/input/mouse/bcm5974.c
@@ -79,6 +79,10 @@
79#define USB_DEVICE_ID_APPLE_WELLSPRING5A_ANSI 0x0252 79#define USB_DEVICE_ID_APPLE_WELLSPRING5A_ANSI 0x0252
80#define USB_DEVICE_ID_APPLE_WELLSPRING5A_ISO 0x0253 80#define USB_DEVICE_ID_APPLE_WELLSPRING5A_ISO 0x0253
81#define USB_DEVICE_ID_APPLE_WELLSPRING5A_JIS 0x0254 81#define USB_DEVICE_ID_APPLE_WELLSPRING5A_JIS 0x0254
82/* MacbookPro10,1 (unibody, June 2012) */
83#define USB_DEVICE_ID_APPLE_WELLSPRING7_ANSI 0x0262
84#define USB_DEVICE_ID_APPLE_WELLSPRING7_ISO 0x0263
85#define USB_DEVICE_ID_APPLE_WELLSPRING7_JIS 0x0264
82 86
83#define BCM5974_DEVICE(prod) { \ 87#define BCM5974_DEVICE(prod) { \
84 .match_flags = (USB_DEVICE_ID_MATCH_DEVICE | \ 88 .match_flags = (USB_DEVICE_ID_MATCH_DEVICE | \
@@ -128,6 +132,10 @@ static const struct usb_device_id bcm5974_table[] = {
128 BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING5A_ANSI), 132 BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING5A_ANSI),
129 BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING5A_ISO), 133 BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING5A_ISO),
130 BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING5A_JIS), 134 BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING5A_JIS),
135 /* MacbookPro10,1 */
136 BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING7_ANSI),
137 BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING7_ISO),
138 BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING7_JIS),
131 /* Terminating entry */ 139 /* Terminating entry */
132 {} 140 {}
133}; 141};
@@ -354,6 +362,18 @@ static const struct bcm5974_config bcm5974_config_table[] = {
354 { DIM_X, DIM_X / SN_COORD, -4620, 5140 }, 362 { DIM_X, DIM_X / SN_COORD, -4620, 5140 },
355 { DIM_Y, DIM_Y / SN_COORD, -150, 6600 } 363 { DIM_Y, DIM_Y / SN_COORD, -150, 6600 }
356 }, 364 },
365 {
366 USB_DEVICE_ID_APPLE_WELLSPRING7_ANSI,
367 USB_DEVICE_ID_APPLE_WELLSPRING7_ISO,
368 USB_DEVICE_ID_APPLE_WELLSPRING7_JIS,
369 HAS_INTEGRATED_BUTTON,
370 0x84, sizeof(struct bt_data),
371 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS,
372 { DIM_PRESSURE, DIM_PRESSURE / SN_PRESSURE, 0, 300 },
373 { DIM_WIDTH, DIM_WIDTH / SN_WIDTH, 0, 2048 },
374 { DIM_X, DIM_X / SN_COORD, -4750, 5280 },
375 { DIM_Y, DIM_Y / SN_COORD, -150, 6730 }
376 },
357 {} 377 {}
358}; 378};
359 379
diff --git a/drivers/input/tablet/wacom_sys.c b/drivers/input/tablet/wacom_sys.c
index cad5602d3ce4..8b31473a81fe 100644
--- a/drivers/input/tablet/wacom_sys.c
+++ b/drivers/input/tablet/wacom_sys.c
@@ -216,7 +216,7 @@ static void wacom_retrieve_report_data(struct usb_interface *intf,
216 216
217 rep_data[0] = 12; 217 rep_data[0] = 12;
218 result = wacom_get_report(intf, WAC_HID_FEATURE_REPORT, 218 result = wacom_get_report(intf, WAC_HID_FEATURE_REPORT,
219 rep_data[0], &rep_data, 2, 219 rep_data[0], rep_data, 2,
220 WAC_MSG_RETRIES); 220 WAC_MSG_RETRIES);
221 221
222 if (result >= 0 && rep_data[1] > 2) 222 if (result >= 0 && rep_data[1] > 2)
@@ -401,7 +401,9 @@ static int wacom_parse_hid(struct usb_interface *intf,
401 break; 401 break;
402 402
403 case HID_USAGE_CONTACTMAX: 403 case HID_USAGE_CONTACTMAX:
404 wacom_retrieve_report_data(intf, features); 404 /* leave touch_max as is if predefined */
405 if (!features->touch_max)
406 wacom_retrieve_report_data(intf, features);
405 i++; 407 i++;
406 break; 408 break;
407 } 409 }
diff --git a/drivers/input/touchscreen/ad7879.c b/drivers/input/touchscreen/ad7879.c
index e2482b40da51..bd4eb4277697 100644
--- a/drivers/input/touchscreen/ad7879.c
+++ b/drivers/input/touchscreen/ad7879.c
@@ -597,7 +597,7 @@ struct ad7879 *ad7879_probe(struct device *dev, u8 devid, unsigned int irq,
597 AD7879_TMR(ts->pen_down_acc_interval); 597 AD7879_TMR(ts->pen_down_acc_interval);
598 598
599 err = request_threaded_irq(ts->irq, NULL, ad7879_irq, 599 err = request_threaded_irq(ts->irq, NULL, ad7879_irq,
600 IRQF_TRIGGER_FALLING, 600 IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
601 dev_name(dev), ts); 601 dev_name(dev), ts);
602 if (err) { 602 if (err) {
603 dev_err(dev, "irq %d busy?\n", ts->irq); 603 dev_err(dev, "irq %d busy?\n", ts->irq);
diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index 42e645062c20..25fd0561a17d 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -1149,7 +1149,8 @@ static int __devinit mxt_probe(struct i2c_client *client,
1149 goto err_free_object; 1149 goto err_free_object;
1150 1150
1151 error = request_threaded_irq(client->irq, NULL, mxt_interrupt, 1151 error = request_threaded_irq(client->irq, NULL, mxt_interrupt,
1152 pdata->irqflags, client->dev.driver->name, data); 1152 pdata->irqflags | IRQF_ONESHOT,
1153 client->dev.driver->name, data);
1153 if (error) { 1154 if (error) {
1154 dev_err(&client->dev, "Failed to register interrupt\n"); 1155 dev_err(&client->dev, "Failed to register interrupt\n");
1155 goto err_free_object; 1156 goto err_free_object;
diff --git a/drivers/input/touchscreen/bu21013_ts.c b/drivers/input/touchscreen/bu21013_ts.c
index f2d03c06c2da..5c487d23f11c 100644
--- a/drivers/input/touchscreen/bu21013_ts.c
+++ b/drivers/input/touchscreen/bu21013_ts.c
@@ -509,7 +509,8 @@ static int __devinit bu21013_probe(struct i2c_client *client,
509 input_set_drvdata(in_dev, bu21013_data); 509 input_set_drvdata(in_dev, bu21013_data);
510 510
511 error = request_threaded_irq(pdata->irq, NULL, bu21013_gpio_irq, 511 error = request_threaded_irq(pdata->irq, NULL, bu21013_gpio_irq,
512 IRQF_TRIGGER_FALLING | IRQF_SHARED, 512 IRQF_TRIGGER_FALLING | IRQF_SHARED |
513 IRQF_ONESHOT,
513 DRIVER_TP, bu21013_data); 514 DRIVER_TP, bu21013_data);
514 if (error) { 515 if (error) {
515 dev_err(&client->dev, "request irq %d failed\n", pdata->irq); 516 dev_err(&client->dev, "request irq %d failed\n", pdata->irq);
diff --git a/drivers/input/touchscreen/cy8ctmg110_ts.c b/drivers/input/touchscreen/cy8ctmg110_ts.c
index 237753ad1031..464f1bf4b61d 100644
--- a/drivers/input/touchscreen/cy8ctmg110_ts.c
+++ b/drivers/input/touchscreen/cy8ctmg110_ts.c
@@ -251,7 +251,8 @@ static int __devinit cy8ctmg110_probe(struct i2c_client *client,
251 } 251 }
252 252
253 err = request_threaded_irq(client->irq, NULL, cy8ctmg110_irq_thread, 253 err = request_threaded_irq(client->irq, NULL, cy8ctmg110_irq_thread,
254 IRQF_TRIGGER_RISING, "touch_reset_key", ts); 254 IRQF_TRIGGER_RISING | IRQF_ONESHOT,
255 "touch_reset_key", ts);
255 if (err < 0) { 256 if (err < 0) {
256 dev_err(&client->dev, 257 dev_err(&client->dev,
257 "irq %d busy? error %d\n", client->irq, err); 258 "irq %d busy? error %d\n", client->irq, err);
diff --git a/drivers/input/touchscreen/intel-mid-touch.c b/drivers/input/touchscreen/intel-mid-touch.c
index 3cd7a837f82b..cf299377fc49 100644
--- a/drivers/input/touchscreen/intel-mid-touch.c
+++ b/drivers/input/touchscreen/intel-mid-touch.c
@@ -620,7 +620,7 @@ static int __devinit mrstouch_probe(struct platform_device *pdev)
620 MRST_PRESSURE_MIN, MRST_PRESSURE_MAX, 0, 0); 620 MRST_PRESSURE_MIN, MRST_PRESSURE_MAX, 0, 0);
621 621
622 err = request_threaded_irq(tsdev->irq, NULL, mrstouch_pendet_irq, 622 err = request_threaded_irq(tsdev->irq, NULL, mrstouch_pendet_irq,
623 0, "mrstouch", tsdev); 623 IRQF_ONESHOT, "mrstouch", tsdev);
624 if (err) { 624 if (err) {
625 dev_err(tsdev->dev, "unable to allocate irq\n"); 625 dev_err(tsdev->dev, "unable to allocate irq\n");
626 goto err_free_mem; 626 goto err_free_mem;
diff --git a/drivers/input/touchscreen/pixcir_i2c_ts.c b/drivers/input/touchscreen/pixcir_i2c_ts.c
index 72f6ba3a4709..953b4c105cad 100644
--- a/drivers/input/touchscreen/pixcir_i2c_ts.c
+++ b/drivers/input/touchscreen/pixcir_i2c_ts.c
@@ -165,7 +165,7 @@ static int __devinit pixcir_i2c_ts_probe(struct i2c_client *client,
165 input_set_drvdata(input, tsdata); 165 input_set_drvdata(input, tsdata);
166 166
167 error = request_threaded_irq(client->irq, NULL, pixcir_ts_isr, 167 error = request_threaded_irq(client->irq, NULL, pixcir_ts_isr,
168 IRQF_TRIGGER_FALLING, 168 IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
169 client->name, tsdata); 169 client->name, tsdata);
170 if (error) { 170 if (error) {
171 dev_err(&client->dev, "Unable to request touchscreen IRQ.\n"); 171 dev_err(&client->dev, "Unable to request touchscreen IRQ.\n");
diff --git a/drivers/input/touchscreen/tnetv107x-ts.c b/drivers/input/touchscreen/tnetv107x-ts.c
index 7e7488097359..368d2c6cf780 100644
--- a/drivers/input/touchscreen/tnetv107x-ts.c
+++ b/drivers/input/touchscreen/tnetv107x-ts.c
@@ -297,7 +297,7 @@ static int __devinit tsc_probe(struct platform_device *pdev)
297 goto error_clk; 297 goto error_clk;
298 } 298 }
299 299
300 error = request_threaded_irq(ts->tsc_irq, NULL, tsc_irq, 0, 300 error = request_threaded_irq(ts->tsc_irq, NULL, tsc_irq, IRQF_ONESHOT,
301 dev_name(dev), ts); 301 dev_name(dev), ts);
302 if (error < 0) { 302 if (error < 0) {
303 dev_err(ts->dev, "Could not allocate ts irq\n"); 303 dev_err(ts->dev, "Could not allocate ts irq\n");
diff --git a/drivers/input/touchscreen/tsc2005.c b/drivers/input/touchscreen/tsc2005.c
index b6adeaee9cc5..5ce3fa8ce646 100644
--- a/drivers/input/touchscreen/tsc2005.c
+++ b/drivers/input/touchscreen/tsc2005.c
@@ -650,7 +650,8 @@ static int __devinit tsc2005_probe(struct spi_device *spi)
650 tsc2005_stop_scan(ts); 650 tsc2005_stop_scan(ts);
651 651
652 error = request_threaded_irq(spi->irq, NULL, tsc2005_irq_thread, 652 error = request_threaded_irq(spi->irq, NULL, tsc2005_irq_thread,
653 IRQF_TRIGGER_RISING, "tsc2005", ts); 653 IRQF_TRIGGER_RISING | IRQF_ONESHOT,
654 "tsc2005", ts);
654 if (error) { 655 if (error) {
655 dev_err(&spi->dev, "Failed to request irq, err: %d\n", error); 656 dev_err(&spi->dev, "Failed to request irq, err: %d\n", error);
656 goto err_free_mem; 657 goto err_free_mem;
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index a2e418cba0ff..625626391f2d 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -83,6 +83,8 @@ static struct iommu_ops amd_iommu_ops;
83static ATOMIC_NOTIFIER_HEAD(ppr_notifier); 83static ATOMIC_NOTIFIER_HEAD(ppr_notifier);
84int amd_iommu_max_glx_val = -1; 84int amd_iommu_max_glx_val = -1;
85 85
86static struct dma_map_ops amd_iommu_dma_ops;
87
86/* 88/*
87 * general struct to manage commands send to an IOMMU 89 * general struct to manage commands send to an IOMMU
88 */ 90 */
@@ -402,7 +404,7 @@ static void amd_iommu_stats_init(void)
402 return; 404 return;
403 405
404 de_fflush = debugfs_create_bool("fullflush", 0444, stats_dir, 406 de_fflush = debugfs_create_bool("fullflush", 0444, stats_dir,
405 (u32 *)&amd_iommu_unmap_flush); 407 &amd_iommu_unmap_flush);
406 408
407 amd_iommu_stats_add(&compl_wait); 409 amd_iommu_stats_add(&compl_wait);
408 amd_iommu_stats_add(&cnt_map_single); 410 amd_iommu_stats_add(&cnt_map_single);
@@ -2267,6 +2269,13 @@ static int device_change_notifier(struct notifier_block *nb,
2267 list_add_tail(&dma_domain->list, &iommu_pd_list); 2269 list_add_tail(&dma_domain->list, &iommu_pd_list);
2268 spin_unlock_irqrestore(&iommu_pd_list_lock, flags); 2270 spin_unlock_irqrestore(&iommu_pd_list_lock, flags);
2269 2271
2272 dev_data = get_dev_data(dev);
2273
2274 if (!dev_data->passthrough)
2275 dev->archdata.dma_ops = &amd_iommu_dma_ops;
2276 else
2277 dev->archdata.dma_ops = &nommu_dma_ops;
2278
2270 break; 2279 break;
2271 case BUS_NOTIFY_DEL_DEVICE: 2280 case BUS_NOTIFY_DEL_DEVICE:
2272 2281
diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c
index 542024ba6dba..a33612f3206f 100644
--- a/drivers/iommu/amd_iommu_init.c
+++ b/drivers/iommu/amd_iommu_init.c
@@ -129,7 +129,7 @@ u16 amd_iommu_last_bdf; /* largest PCI device id we have
129 to handle */ 129 to handle */
130LIST_HEAD(amd_iommu_unity_map); /* a list of required unity mappings 130LIST_HEAD(amd_iommu_unity_map); /* a list of required unity mappings
131 we find in ACPI */ 131 we find in ACPI */
132bool amd_iommu_unmap_flush; /* if true, flush on every unmap */ 132u32 amd_iommu_unmap_flush; /* if true, flush on every unmap */
133 133
134LIST_HEAD(amd_iommu_list); /* list of all AMD IOMMUs in the 134LIST_HEAD(amd_iommu_list); /* list of all AMD IOMMUs in the
135 system */ 135 system */
@@ -1641,6 +1641,8 @@ static int __init amd_iommu_init(void)
1641 1641
1642 amd_iommu_init_api(); 1642 amd_iommu_init_api();
1643 1643
1644 x86_platform.iommu_shutdown = disable_iommus;
1645
1644 if (iommu_pass_through) 1646 if (iommu_pass_through)
1645 goto out; 1647 goto out;
1646 1648
@@ -1649,8 +1651,6 @@ static int __init amd_iommu_init(void)
1649 else 1651 else
1650 printk(KERN_INFO "AMD-Vi: Lazy IO/TLB flushing enabled\n"); 1652 printk(KERN_INFO "AMD-Vi: Lazy IO/TLB flushing enabled\n");
1651 1653
1652 x86_platform.iommu_shutdown = disable_iommus;
1653
1654out: 1654out:
1655 return ret; 1655 return ret;
1656 1656
diff --git a/drivers/iommu/amd_iommu_types.h b/drivers/iommu/amd_iommu_types.h
index 24355559a2ad..c1b1d489817e 100644
--- a/drivers/iommu/amd_iommu_types.h
+++ b/drivers/iommu/amd_iommu_types.h
@@ -652,7 +652,7 @@ extern unsigned long *amd_iommu_pd_alloc_bitmap;
652 * If true, the addresses will be flushed on unmap time, not when 652 * If true, the addresses will be flushed on unmap time, not when
653 * they are reused 653 * they are reused
654 */ 654 */
655extern bool amd_iommu_unmap_flush; 655extern u32 amd_iommu_unmap_flush;
656 656
657/* Smallest number of PASIDs supported by any IOMMU in the system */ 657/* Smallest number of PASIDs supported by any IOMMU in the system */
658extern u32 amd_iommu_max_pasids; 658extern u32 amd_iommu_max_pasids;
diff --git a/drivers/iommu/tegra-smmu.c b/drivers/iommu/tegra-smmu.c
index ecd679043d77..3f3d09d560ea 100644
--- a/drivers/iommu/tegra-smmu.c
+++ b/drivers/iommu/tegra-smmu.c
@@ -550,13 +550,13 @@ static int alloc_pdir(struct smmu_as *as)
550 return 0; 550 return 0;
551 551
552 as->pte_count = devm_kzalloc(smmu->dev, 552 as->pte_count = devm_kzalloc(smmu->dev,
553 sizeof(as->pte_count[0]) * SMMU_PDIR_COUNT, GFP_KERNEL); 553 sizeof(as->pte_count[0]) * SMMU_PDIR_COUNT, GFP_ATOMIC);
554 if (!as->pte_count) { 554 if (!as->pte_count) {
555 dev_err(smmu->dev, 555 dev_err(smmu->dev,
556 "failed to allocate smmu_device PTE cunters\n"); 556 "failed to allocate smmu_device PTE cunters\n");
557 return -ENOMEM; 557 return -ENOMEM;
558 } 558 }
559 as->pdir_page = alloc_page(GFP_KERNEL | __GFP_DMA); 559 as->pdir_page = alloc_page(GFP_ATOMIC | __GFP_DMA);
560 if (!as->pdir_page) { 560 if (!as->pdir_page) {
561 dev_err(smmu->dev, 561 dev_err(smmu->dev,
562 "failed to allocate smmu_device page directory\n"); 562 "failed to allocate smmu_device page directory\n");
diff --git a/drivers/leds/ledtrig-heartbeat.c b/drivers/leds/ledtrig-heartbeat.c
index 41dc76db4311..a019fbb70880 100644
--- a/drivers/leds/ledtrig-heartbeat.c
+++ b/drivers/leds/ledtrig-heartbeat.c
@@ -21,6 +21,8 @@
21#include <linux/reboot.h> 21#include <linux/reboot.h>
22#include "leds.h" 22#include "leds.h"
23 23
24static int panic_heartbeats;
25
24struct heartbeat_trig_data { 26struct heartbeat_trig_data {
25 unsigned int phase; 27 unsigned int phase;
26 unsigned int period; 28 unsigned int period;
@@ -34,6 +36,11 @@ static void led_heartbeat_function(unsigned long data)
34 unsigned long brightness = LED_OFF; 36 unsigned long brightness = LED_OFF;
35 unsigned long delay = 0; 37 unsigned long delay = 0;
36 38
39 if (unlikely(panic_heartbeats)) {
40 led_set_brightness(led_cdev, LED_OFF);
41 return;
42 }
43
37 /* acts like an actual heart beat -- ie thump-thump-pause... */ 44 /* acts like an actual heart beat -- ie thump-thump-pause... */
38 switch (heartbeat_data->phase) { 45 switch (heartbeat_data->phase) {
39 case 0: 46 case 0:
@@ -111,12 +118,19 @@ static int heartbeat_reboot_notifier(struct notifier_block *nb,
111 return NOTIFY_DONE; 118 return NOTIFY_DONE;
112} 119}
113 120
121static int heartbeat_panic_notifier(struct notifier_block *nb,
122 unsigned long code, void *unused)
123{
124 panic_heartbeats = 1;
125 return NOTIFY_DONE;
126}
127
114static struct notifier_block heartbeat_reboot_nb = { 128static struct notifier_block heartbeat_reboot_nb = {
115 .notifier_call = heartbeat_reboot_notifier, 129 .notifier_call = heartbeat_reboot_notifier,
116}; 130};
117 131
118static struct notifier_block heartbeat_panic_nb = { 132static struct notifier_block heartbeat_panic_nb = {
119 .notifier_call = heartbeat_reboot_notifier, 133 .notifier_call = heartbeat_panic_notifier,
120}; 134};
121 135
122static int __init heartbeat_trig_init(void) 136static int __init heartbeat_trig_init(void)
diff --git a/drivers/md/dm-thin.c b/drivers/md/dm-thin.c
index 37fdaf81bd1f..ce59824fb414 100644
--- a/drivers/md/dm-thin.c
+++ b/drivers/md/dm-thin.c
@@ -2292,6 +2292,13 @@ static int process_reserve_metadata_snap_mesg(unsigned argc, char **argv, struct
2292 if (r) 2292 if (r)
2293 return r; 2293 return r;
2294 2294
2295 r = dm_pool_commit_metadata(pool->pmd);
2296 if (r) {
2297 DMERR("%s: dm_pool_commit_metadata() failed, error = %d",
2298 __func__, r);
2299 return r;
2300 }
2301
2295 r = dm_pool_reserve_metadata_snap(pool->pmd); 2302 r = dm_pool_reserve_metadata_snap(pool->pmd);
2296 if (r) 2303 if (r)
2297 DMWARN("reserve_metadata_snap message failed."); 2304 DMWARN("reserve_metadata_snap message failed.");
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 1c2f9048e1ae..a4c219e3c859 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -5784,8 +5784,7 @@ static int add_new_disk(struct mddev * mddev, mdu_disk_info_t *info)
5784 super_types[mddev->major_version]. 5784 super_types[mddev->major_version].
5785 validate_super(mddev, rdev); 5785 validate_super(mddev, rdev);
5786 if ((info->state & (1<<MD_DISK_SYNC)) && 5786 if ((info->state & (1<<MD_DISK_SYNC)) &&
5787 (!test_bit(In_sync, &rdev->flags) || 5787 rdev->raid_disk != info->raid_disk) {
5788 rdev->raid_disk != info->raid_disk)) {
5789 /* This was a hot-add request, but events doesn't 5788 /* This was a hot-add request, but events doesn't
5790 * match, so reject it. 5789 * match, so reject it.
5791 */ 5790 */
@@ -6751,7 +6750,7 @@ struct md_thread *md_register_thread(void (*run) (struct mddev *), struct mddev
6751 thread->tsk = kthread_run(md_thread, thread, 6750 thread->tsk = kthread_run(md_thread, thread,
6752 "%s_%s", 6751 "%s_%s",
6753 mdname(thread->mddev), 6752 mdname(thread->mddev),
6754 name ?: mddev->pers->name); 6753 name);
6755 if (IS_ERR(thread->tsk)) { 6754 if (IS_ERR(thread->tsk)) {
6756 kfree(thread); 6755 kfree(thread);
6757 return NULL; 6756 return NULL;
@@ -7298,6 +7297,7 @@ void md_do_sync(struct mddev *mddev)
7298 int skipped = 0; 7297 int skipped = 0;
7299 struct md_rdev *rdev; 7298 struct md_rdev *rdev;
7300 char *desc; 7299 char *desc;
7300 struct blk_plug plug;
7301 7301
7302 /* just incase thread restarts... */ 7302 /* just incase thread restarts... */
7303 if (test_bit(MD_RECOVERY_DONE, &mddev->recovery)) 7303 if (test_bit(MD_RECOVERY_DONE, &mddev->recovery))
@@ -7447,6 +7447,7 @@ void md_do_sync(struct mddev *mddev)
7447 } 7447 }
7448 mddev->curr_resync_completed = j; 7448 mddev->curr_resync_completed = j;
7449 7449
7450 blk_start_plug(&plug);
7450 while (j < max_sectors) { 7451 while (j < max_sectors) {
7451 sector_t sectors; 7452 sector_t sectors;
7452 7453
@@ -7552,6 +7553,7 @@ void md_do_sync(struct mddev *mddev)
7552 * this also signals 'finished resyncing' to md_stop 7553 * this also signals 'finished resyncing' to md_stop
7553 */ 7554 */
7554 out: 7555 out:
7556 blk_finish_plug(&plug);
7555 wait_event(mddev->recovery_wait, !atomic_read(&mddev->recovery_active)); 7557 wait_event(mddev->recovery_wait, !atomic_read(&mddev->recovery_active));
7556 7558
7557 /* tell personality that we are finished */ 7559 /* tell personality that we are finished */
diff --git a/drivers/md/multipath.c b/drivers/md/multipath.c
index 9339e67fcc79..61a1833ebaf3 100644
--- a/drivers/md/multipath.c
+++ b/drivers/md/multipath.c
@@ -474,7 +474,8 @@ static int multipath_run (struct mddev *mddev)
474 } 474 }
475 475
476 { 476 {
477 mddev->thread = md_register_thread(multipathd, mddev, NULL); 477 mddev->thread = md_register_thread(multipathd, mddev,
478 "multipath");
478 if (!mddev->thread) { 479 if (!mddev->thread) {
479 printk(KERN_ERR "multipath: couldn't allocate thread" 480 printk(KERN_ERR "multipath: couldn't allocate thread"
480 " for %s\n", mdname(mddev)); 481 " for %s\n", mdname(mddev));
diff --git a/drivers/md/persistent-data/dm-space-map-checker.c b/drivers/md/persistent-data/dm-space-map-checker.c
index 50ed53bf4aa2..fc90c11620ad 100644
--- a/drivers/md/persistent-data/dm-space-map-checker.c
+++ b/drivers/md/persistent-data/dm-space-map-checker.c
@@ -8,6 +8,7 @@
8 8
9#include <linux/device-mapper.h> 9#include <linux/device-mapper.h>
10#include <linux/export.h> 10#include <linux/export.h>
11#include <linux/vmalloc.h>
11 12
12#ifdef CONFIG_DM_DEBUG_SPACE_MAPS 13#ifdef CONFIG_DM_DEBUG_SPACE_MAPS
13 14
@@ -89,13 +90,23 @@ static int ca_create(struct count_array *ca, struct dm_space_map *sm)
89 90
90 ca->nr = nr_blocks; 91 ca->nr = nr_blocks;
91 ca->nr_free = nr_blocks; 92 ca->nr_free = nr_blocks;
92 ca->counts = kzalloc(sizeof(*ca->counts) * nr_blocks, GFP_KERNEL); 93
93 if (!ca->counts) 94 if (!nr_blocks)
94 return -ENOMEM; 95 ca->counts = NULL;
96 else {
97 ca->counts = vzalloc(sizeof(*ca->counts) * nr_blocks);
98 if (!ca->counts)
99 return -ENOMEM;
100 }
95 101
96 return 0; 102 return 0;
97} 103}
98 104
105static void ca_destroy(struct count_array *ca)
106{
107 vfree(ca->counts);
108}
109
99static int ca_load(struct count_array *ca, struct dm_space_map *sm) 110static int ca_load(struct count_array *ca, struct dm_space_map *sm)
100{ 111{
101 int r; 112 int r;
@@ -126,12 +137,14 @@ static int ca_load(struct count_array *ca, struct dm_space_map *sm)
126static int ca_extend(struct count_array *ca, dm_block_t extra_blocks) 137static int ca_extend(struct count_array *ca, dm_block_t extra_blocks)
127{ 138{
128 dm_block_t nr_blocks = ca->nr + extra_blocks; 139 dm_block_t nr_blocks = ca->nr + extra_blocks;
129 uint32_t *counts = kzalloc(sizeof(*counts) * nr_blocks, GFP_KERNEL); 140 uint32_t *counts = vzalloc(sizeof(*counts) * nr_blocks);
130 if (!counts) 141 if (!counts)
131 return -ENOMEM; 142 return -ENOMEM;
132 143
133 memcpy(counts, ca->counts, sizeof(*counts) * ca->nr); 144 if (ca->counts) {
134 kfree(ca->counts); 145 memcpy(counts, ca->counts, sizeof(*counts) * ca->nr);
146 ca_destroy(ca);
147 }
135 ca->nr = nr_blocks; 148 ca->nr = nr_blocks;
136 ca->nr_free += extra_blocks; 149 ca->nr_free += extra_blocks;
137 ca->counts = counts; 150 ca->counts = counts;
@@ -151,11 +164,6 @@ static int ca_commit(struct count_array *old, struct count_array *new)
151 return 0; 164 return 0;
152} 165}
153 166
154static void ca_destroy(struct count_array *ca)
155{
156 kfree(ca->counts);
157}
158
159/*----------------------------------------------------------------*/ 167/*----------------------------------------------------------------*/
160 168
161struct sm_checker { 169struct sm_checker {
@@ -343,25 +351,25 @@ struct dm_space_map *dm_sm_checker_create(struct dm_space_map *sm)
343 int r; 351 int r;
344 struct sm_checker *smc; 352 struct sm_checker *smc;
345 353
346 if (!sm) 354 if (IS_ERR_OR_NULL(sm))
347 return NULL; 355 return ERR_PTR(-EINVAL);
348 356
349 smc = kmalloc(sizeof(*smc), GFP_KERNEL); 357 smc = kmalloc(sizeof(*smc), GFP_KERNEL);
350 if (!smc) 358 if (!smc)
351 return NULL; 359 return ERR_PTR(-ENOMEM);
352 360
353 memcpy(&smc->sm, &ops_, sizeof(smc->sm)); 361 memcpy(&smc->sm, &ops_, sizeof(smc->sm));
354 r = ca_create(&smc->old_counts, sm); 362 r = ca_create(&smc->old_counts, sm);
355 if (r) { 363 if (r) {
356 kfree(smc); 364 kfree(smc);
357 return NULL; 365 return ERR_PTR(r);
358 } 366 }
359 367
360 r = ca_create(&smc->counts, sm); 368 r = ca_create(&smc->counts, sm);
361 if (r) { 369 if (r) {
362 ca_destroy(&smc->old_counts); 370 ca_destroy(&smc->old_counts);
363 kfree(smc); 371 kfree(smc);
364 return NULL; 372 return ERR_PTR(r);
365 } 373 }
366 374
367 smc->real_sm = sm; 375 smc->real_sm = sm;
@@ -371,7 +379,7 @@ struct dm_space_map *dm_sm_checker_create(struct dm_space_map *sm)
371 ca_destroy(&smc->counts); 379 ca_destroy(&smc->counts);
372 ca_destroy(&smc->old_counts); 380 ca_destroy(&smc->old_counts);
373 kfree(smc); 381 kfree(smc);
374 return NULL; 382 return ERR_PTR(r);
375 } 383 }
376 384
377 r = ca_commit(&smc->old_counts, &smc->counts); 385 r = ca_commit(&smc->old_counts, &smc->counts);
@@ -379,7 +387,7 @@ struct dm_space_map *dm_sm_checker_create(struct dm_space_map *sm)
379 ca_destroy(&smc->counts); 387 ca_destroy(&smc->counts);
380 ca_destroy(&smc->old_counts); 388 ca_destroy(&smc->old_counts);
381 kfree(smc); 389 kfree(smc);
382 return NULL; 390 return ERR_PTR(r);
383 } 391 }
384 392
385 return &smc->sm; 393 return &smc->sm;
@@ -391,25 +399,25 @@ struct dm_space_map *dm_sm_checker_create_fresh(struct dm_space_map *sm)
391 int r; 399 int r;
392 struct sm_checker *smc; 400 struct sm_checker *smc;
393 401
394 if (!sm) 402 if (IS_ERR_OR_NULL(sm))
395 return NULL; 403 return ERR_PTR(-EINVAL);
396 404
397 smc = kmalloc(sizeof(*smc), GFP_KERNEL); 405 smc = kmalloc(sizeof(*smc), GFP_KERNEL);
398 if (!smc) 406 if (!smc)
399 return NULL; 407 return ERR_PTR(-ENOMEM);
400 408
401 memcpy(&smc->sm, &ops_, sizeof(smc->sm)); 409 memcpy(&smc->sm, &ops_, sizeof(smc->sm));
402 r = ca_create(&smc->old_counts, sm); 410 r = ca_create(&smc->old_counts, sm);
403 if (r) { 411 if (r) {
404 kfree(smc); 412 kfree(smc);
405 return NULL; 413 return ERR_PTR(r);
406 } 414 }
407 415
408 r = ca_create(&smc->counts, sm); 416 r = ca_create(&smc->counts, sm);
409 if (r) { 417 if (r) {
410 ca_destroy(&smc->old_counts); 418 ca_destroy(&smc->old_counts);
411 kfree(smc); 419 kfree(smc);
412 return NULL; 420 return ERR_PTR(r);
413 } 421 }
414 422
415 smc->real_sm = sm; 423 smc->real_sm = sm;
diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
index fc469ba9f627..3d0ed5332883 100644
--- a/drivers/md/persistent-data/dm-space-map-disk.c
+++ b/drivers/md/persistent-data/dm-space-map-disk.c
@@ -290,7 +290,16 @@ struct dm_space_map *dm_sm_disk_create(struct dm_transaction_manager *tm,
290 dm_block_t nr_blocks) 290 dm_block_t nr_blocks)
291{ 291{
292 struct dm_space_map *sm = dm_sm_disk_create_real(tm, nr_blocks); 292 struct dm_space_map *sm = dm_sm_disk_create_real(tm, nr_blocks);
293 return dm_sm_checker_create_fresh(sm); 293 struct dm_space_map *smc;
294
295 if (IS_ERR_OR_NULL(sm))
296 return sm;
297
298 smc = dm_sm_checker_create_fresh(sm);
299 if (IS_ERR(smc))
300 dm_sm_destroy(sm);
301
302 return smc;
294} 303}
295EXPORT_SYMBOL_GPL(dm_sm_disk_create); 304EXPORT_SYMBOL_GPL(dm_sm_disk_create);
296 305
diff --git a/drivers/md/persistent-data/dm-transaction-manager.c b/drivers/md/persistent-data/dm-transaction-manager.c
index 400fe144c0cd..e5604b32d91f 100644
--- a/drivers/md/persistent-data/dm-transaction-manager.c
+++ b/drivers/md/persistent-data/dm-transaction-manager.c
@@ -138,6 +138,9 @@ EXPORT_SYMBOL_GPL(dm_tm_create_non_blocking_clone);
138 138
139void dm_tm_destroy(struct dm_transaction_manager *tm) 139void dm_tm_destroy(struct dm_transaction_manager *tm)
140{ 140{
141 if (!tm->is_clone)
142 wipe_shadow_table(tm);
143
141 kfree(tm); 144 kfree(tm);
142} 145}
143EXPORT_SYMBOL_GPL(dm_tm_destroy); 146EXPORT_SYMBOL_GPL(dm_tm_destroy);
@@ -344,8 +347,10 @@ static int dm_tm_create_internal(struct dm_block_manager *bm,
344 } 347 }
345 348
346 *sm = dm_sm_checker_create(inner); 349 *sm = dm_sm_checker_create(inner);
347 if (!*sm) 350 if (IS_ERR(*sm)) {
351 r = PTR_ERR(*sm);
348 goto bad2; 352 goto bad2;
353 }
349 354
350 } else { 355 } else {
351 r = dm_bm_write_lock(dm_tm_get_bm(*tm), sb_location, 356 r = dm_bm_write_lock(dm_tm_get_bm(*tm), sb_location,
@@ -364,8 +369,10 @@ static int dm_tm_create_internal(struct dm_block_manager *bm,
364 } 369 }
365 370
366 *sm = dm_sm_checker_create(inner); 371 *sm = dm_sm_checker_create(inner);
367 if (!*sm) 372 if (IS_ERR(*sm)) {
373 r = PTR_ERR(*sm);
368 goto bad2; 374 goto bad2;
375 }
369 } 376 }
370 377
371 return 0; 378 return 0;
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index a9c7981ddd24..240ff3125040 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -517,8 +517,8 @@ static int read_balance(struct r1conf *conf, struct r1bio *r1_bio, int *max_sect
517 int bad_sectors; 517 int bad_sectors;
518 518
519 int disk = start_disk + i; 519 int disk = start_disk + i;
520 if (disk >= conf->raid_disks) 520 if (disk >= conf->raid_disks * 2)
521 disk -= conf->raid_disks; 521 disk -= conf->raid_disks * 2;
522 522
523 rdev = rcu_dereference(conf->mirrors[disk].rdev); 523 rdev = rcu_dereference(conf->mirrors[disk].rdev);
524 if (r1_bio->bios[disk] == IO_BLOCKED 524 if (r1_bio->bios[disk] == IO_BLOCKED
@@ -883,7 +883,6 @@ static void make_request(struct mddev *mddev, struct bio * bio)
883 const unsigned long do_sync = (bio->bi_rw & REQ_SYNC); 883 const unsigned long do_sync = (bio->bi_rw & REQ_SYNC);
884 const unsigned long do_flush_fua = (bio->bi_rw & (REQ_FLUSH | REQ_FUA)); 884 const unsigned long do_flush_fua = (bio->bi_rw & (REQ_FLUSH | REQ_FUA));
885 struct md_rdev *blocked_rdev; 885 struct md_rdev *blocked_rdev;
886 int plugged;
887 int first_clone; 886 int first_clone;
888 int sectors_handled; 887 int sectors_handled;
889 int max_sectors; 888 int max_sectors;
@@ -1034,7 +1033,6 @@ read_again:
1034 * the bad blocks. Each set of writes gets it's own r1bio 1033 * the bad blocks. Each set of writes gets it's own r1bio
1035 * with a set of bios attached. 1034 * with a set of bios attached.
1036 */ 1035 */
1037 plugged = mddev_check_plugged(mddev);
1038 1036
1039 disks = conf->raid_disks * 2; 1037 disks = conf->raid_disks * 2;
1040 retry_write: 1038 retry_write:
@@ -1191,6 +1189,8 @@ read_again:
1191 bio_list_add(&conf->pending_bio_list, mbio); 1189 bio_list_add(&conf->pending_bio_list, mbio);
1192 conf->pending_count++; 1190 conf->pending_count++;
1193 spin_unlock_irqrestore(&conf->device_lock, flags); 1191 spin_unlock_irqrestore(&conf->device_lock, flags);
1192 if (!mddev_check_plugged(mddev))
1193 md_wakeup_thread(mddev->thread);
1194 } 1194 }
1195 /* Mustn't call r1_bio_write_done before this next test, 1195 /* Mustn't call r1_bio_write_done before this next test,
1196 * as it could result in the bio being freed. 1196 * as it could result in the bio being freed.
@@ -1213,9 +1213,6 @@ read_again:
1213 1213
1214 /* In case raid1d snuck in to freeze_array */ 1214 /* In case raid1d snuck in to freeze_array */
1215 wake_up(&conf->wait_barrier); 1215 wake_up(&conf->wait_barrier);
1216
1217 if (do_sync || !bitmap || !plugged)
1218 md_wakeup_thread(mddev->thread);
1219} 1216}
1220 1217
1221static void status(struct seq_file *seq, struct mddev *mddev) 1218static void status(struct seq_file *seq, struct mddev *mddev)
@@ -2488,9 +2485,10 @@ static sector_t sync_request(struct mddev *mddev, sector_t sector_nr, int *skipp
2488 */ 2485 */
2489 if (test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) { 2486 if (test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) {
2490 atomic_set(&r1_bio->remaining, read_targets); 2487 atomic_set(&r1_bio->remaining, read_targets);
2491 for (i = 0; i < conf->raid_disks * 2; i++) { 2488 for (i = 0; i < conf->raid_disks * 2 && read_targets; i++) {
2492 bio = r1_bio->bios[i]; 2489 bio = r1_bio->bios[i];
2493 if (bio->bi_end_io == end_sync_read) { 2490 if (bio->bi_end_io == end_sync_read) {
2491 read_targets--;
2494 md_sync_acct(bio->bi_bdev, nr_sectors); 2492 md_sync_acct(bio->bi_bdev, nr_sectors);
2495 generic_make_request(bio); 2493 generic_make_request(bio);
2496 } 2494 }
@@ -2621,7 +2619,7 @@ static struct r1conf *setup_conf(struct mddev *mddev)
2621 goto abort; 2619 goto abort;
2622 } 2620 }
2623 err = -ENOMEM; 2621 err = -ENOMEM;
2624 conf->thread = md_register_thread(raid1d, mddev, NULL); 2622 conf->thread = md_register_thread(raid1d, mddev, "raid1");
2625 if (!conf->thread) { 2623 if (!conf->thread) {
2626 printk(KERN_ERR 2624 printk(KERN_ERR
2627 "md/raid1:%s: couldn't allocate thread\n", 2625 "md/raid1:%s: couldn't allocate thread\n",
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 99ae6068e456..8da6282254c3 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -1039,7 +1039,6 @@ static void make_request(struct mddev *mddev, struct bio * bio)
1039 const unsigned long do_fua = (bio->bi_rw & REQ_FUA); 1039 const unsigned long do_fua = (bio->bi_rw & REQ_FUA);
1040 unsigned long flags; 1040 unsigned long flags;
1041 struct md_rdev *blocked_rdev; 1041 struct md_rdev *blocked_rdev;
1042 int plugged;
1043 int sectors_handled; 1042 int sectors_handled;
1044 int max_sectors; 1043 int max_sectors;
1045 int sectors; 1044 int sectors;
@@ -1239,7 +1238,6 @@ read_again:
1239 * of r10_bios is recored in bio->bi_phys_segments just as with 1238 * of r10_bios is recored in bio->bi_phys_segments just as with
1240 * the read case. 1239 * the read case.
1241 */ 1240 */
1242 plugged = mddev_check_plugged(mddev);
1243 1241
1244 r10_bio->read_slot = -1; /* make sure repl_bio gets freed */ 1242 r10_bio->read_slot = -1; /* make sure repl_bio gets freed */
1245 raid10_find_phys(conf, r10_bio); 1243 raid10_find_phys(conf, r10_bio);
@@ -1396,6 +1394,8 @@ retry_write:
1396 bio_list_add(&conf->pending_bio_list, mbio); 1394 bio_list_add(&conf->pending_bio_list, mbio);
1397 conf->pending_count++; 1395 conf->pending_count++;
1398 spin_unlock_irqrestore(&conf->device_lock, flags); 1396 spin_unlock_irqrestore(&conf->device_lock, flags);
1397 if (!mddev_check_plugged(mddev))
1398 md_wakeup_thread(mddev->thread);
1399 1399
1400 if (!r10_bio->devs[i].repl_bio) 1400 if (!r10_bio->devs[i].repl_bio)
1401 continue; 1401 continue;
@@ -1423,6 +1423,8 @@ retry_write:
1423 bio_list_add(&conf->pending_bio_list, mbio); 1423 bio_list_add(&conf->pending_bio_list, mbio);
1424 conf->pending_count++; 1424 conf->pending_count++;
1425 spin_unlock_irqrestore(&conf->device_lock, flags); 1425 spin_unlock_irqrestore(&conf->device_lock, flags);
1426 if (!mddev_check_plugged(mddev))
1427 md_wakeup_thread(mddev->thread);
1426 } 1428 }
1427 1429
1428 /* Don't remove the bias on 'remaining' (one_write_done) until 1430 /* Don't remove the bias on 'remaining' (one_write_done) until
@@ -1448,9 +1450,6 @@ retry_write:
1448 1450
1449 /* In case raid10d snuck in to freeze_array */ 1451 /* In case raid10d snuck in to freeze_array */
1450 wake_up(&conf->wait_barrier); 1452 wake_up(&conf->wait_barrier);
1451
1452 if (do_sync || !mddev->bitmap || !plugged)
1453 md_wakeup_thread(mddev->thread);
1454} 1453}
1455 1454
1456static void status(struct seq_file *seq, struct mddev *mddev) 1455static void status(struct seq_file *seq, struct mddev *mddev)
@@ -2310,7 +2309,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
2310 if (r10_sync_page_io(rdev, 2309 if (r10_sync_page_io(rdev,
2311 r10_bio->devs[sl].addr + 2310 r10_bio->devs[sl].addr +
2312 sect, 2311 sect,
2313 s<<9, conf->tmppage, WRITE) 2312 s, conf->tmppage, WRITE)
2314 == 0) { 2313 == 0) {
2315 /* Well, this device is dead */ 2314 /* Well, this device is dead */
2316 printk(KERN_NOTICE 2315 printk(KERN_NOTICE
@@ -2349,7 +2348,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
2349 switch (r10_sync_page_io(rdev, 2348 switch (r10_sync_page_io(rdev,
2350 r10_bio->devs[sl].addr + 2349 r10_bio->devs[sl].addr +
2351 sect, 2350 sect,
2352 s<<9, conf->tmppage, 2351 s, conf->tmppage,
2353 READ)) { 2352 READ)) {
2354 case 0: 2353 case 0:
2355 /* Well, this device is dead */ 2354 /* Well, this device is dead */
@@ -2512,7 +2511,7 @@ read_more:
2512 slot = r10_bio->read_slot; 2511 slot = r10_bio->read_slot;
2513 printk_ratelimited( 2512 printk_ratelimited(
2514 KERN_ERR 2513 KERN_ERR
2515 "md/raid10:%s: %s: redirecting" 2514 "md/raid10:%s: %s: redirecting "
2516 "sector %llu to another mirror\n", 2515 "sector %llu to another mirror\n",
2517 mdname(mddev), 2516 mdname(mddev),
2518 bdevname(rdev->bdev, b), 2517 bdevname(rdev->bdev, b),
@@ -2661,7 +2660,8 @@ static void raid10d(struct mddev *mddev)
2661 blk_start_plug(&plug); 2660 blk_start_plug(&plug);
2662 for (;;) { 2661 for (;;) {
2663 2662
2664 flush_pending_writes(conf); 2663 if (atomic_read(&mddev->plug_cnt) == 0)
2664 flush_pending_writes(conf);
2665 2665
2666 spin_lock_irqsave(&conf->device_lock, flags); 2666 spin_lock_irqsave(&conf->device_lock, flags);
2667 if (list_empty(head)) { 2667 if (list_empty(head)) {
@@ -2890,6 +2890,12 @@ static sector_t sync_request(struct mddev *mddev, sector_t sector_nr,
2890 /* want to reconstruct this device */ 2890 /* want to reconstruct this device */
2891 rb2 = r10_bio; 2891 rb2 = r10_bio;
2892 sect = raid10_find_virt(conf, sector_nr, i); 2892 sect = raid10_find_virt(conf, sector_nr, i);
2893 if (sect >= mddev->resync_max_sectors) {
2894 /* last stripe is not complete - don't
2895 * try to recover this sector.
2896 */
2897 continue;
2898 }
2893 /* Unless we are doing a full sync, or a replacement 2899 /* Unless we are doing a full sync, or a replacement
2894 * we only need to recover the block if it is set in 2900 * we only need to recover the block if it is set in
2895 * the bitmap 2901 * the bitmap
@@ -3421,7 +3427,7 @@ static struct r10conf *setup_conf(struct mddev *mddev)
3421 spin_lock_init(&conf->resync_lock); 3427 spin_lock_init(&conf->resync_lock);
3422 init_waitqueue_head(&conf->wait_barrier); 3428 init_waitqueue_head(&conf->wait_barrier);
3423 3429
3424 conf->thread = md_register_thread(raid10d, mddev, NULL); 3430 conf->thread = md_register_thread(raid10d, mddev, "raid10");
3425 if (!conf->thread) 3431 if (!conf->thread)
3426 goto out; 3432 goto out;
3427 3433
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index d26767246d26..04348d76bb30 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -196,12 +196,14 @@ static void __release_stripe(struct r5conf *conf, struct stripe_head *sh)
196 BUG_ON(!list_empty(&sh->lru)); 196 BUG_ON(!list_empty(&sh->lru));
197 BUG_ON(atomic_read(&conf->active_stripes)==0); 197 BUG_ON(atomic_read(&conf->active_stripes)==0);
198 if (test_bit(STRIPE_HANDLE, &sh->state)) { 198 if (test_bit(STRIPE_HANDLE, &sh->state)) {
199 if (test_bit(STRIPE_DELAYED, &sh->state)) 199 if (test_bit(STRIPE_DELAYED, &sh->state) &&
200 !test_bit(STRIPE_PREREAD_ACTIVE, &sh->state))
200 list_add_tail(&sh->lru, &conf->delayed_list); 201 list_add_tail(&sh->lru, &conf->delayed_list);
201 else if (test_bit(STRIPE_BIT_DELAY, &sh->state) && 202 else if (test_bit(STRIPE_BIT_DELAY, &sh->state) &&
202 sh->bm_seq - conf->seq_write > 0) 203 sh->bm_seq - conf->seq_write > 0)
203 list_add_tail(&sh->lru, &conf->bitmap_list); 204 list_add_tail(&sh->lru, &conf->bitmap_list);
204 else { 205 else {
206 clear_bit(STRIPE_DELAYED, &sh->state);
205 clear_bit(STRIPE_BIT_DELAY, &sh->state); 207 clear_bit(STRIPE_BIT_DELAY, &sh->state);
206 list_add_tail(&sh->lru, &conf->handle_list); 208 list_add_tail(&sh->lru, &conf->handle_list);
207 } 209 }
@@ -606,6 +608,12 @@ static void ops_run_io(struct stripe_head *sh, struct stripe_head_state *s)
606 * a chance*/ 608 * a chance*/
607 md_check_recovery(conf->mddev); 609 md_check_recovery(conf->mddev);
608 } 610 }
611 /*
612 * Because md_wait_for_blocked_rdev
613 * will dec nr_pending, we must
614 * increment it first.
615 */
616 atomic_inc(&rdev->nr_pending);
609 md_wait_for_blocked_rdev(rdev, conf->mddev); 617 md_wait_for_blocked_rdev(rdev, conf->mddev);
610 } else { 618 } else {
611 /* Acknowledged bad block - skip the write */ 619 /* Acknowledged bad block - skip the write */
@@ -1737,6 +1745,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
1737 } else { 1745 } else {
1738 const char *bdn = bdevname(rdev->bdev, b); 1746 const char *bdn = bdevname(rdev->bdev, b);
1739 int retry = 0; 1747 int retry = 0;
1748 int set_bad = 0;
1740 1749
1741 clear_bit(R5_UPTODATE, &sh->dev[i].flags); 1750 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
1742 atomic_inc(&rdev->read_errors); 1751 atomic_inc(&rdev->read_errors);
@@ -1748,7 +1757,8 @@ static void raid5_end_read_request(struct bio * bi, int error)
1748 mdname(conf->mddev), 1757 mdname(conf->mddev),
1749 (unsigned long long)s, 1758 (unsigned long long)s,
1750 bdn); 1759 bdn);
1751 else if (conf->mddev->degraded >= conf->max_degraded) 1760 else if (conf->mddev->degraded >= conf->max_degraded) {
1761 set_bad = 1;
1752 printk_ratelimited( 1762 printk_ratelimited(
1753 KERN_WARNING 1763 KERN_WARNING
1754 "md/raid:%s: read error not correctable " 1764 "md/raid:%s: read error not correctable "
@@ -1756,8 +1766,9 @@ static void raid5_end_read_request(struct bio * bi, int error)
1756 mdname(conf->mddev), 1766 mdname(conf->mddev),
1757 (unsigned long long)s, 1767 (unsigned long long)s,
1758 bdn); 1768 bdn);
1759 else if (test_bit(R5_ReWrite, &sh->dev[i].flags)) 1769 } else if (test_bit(R5_ReWrite, &sh->dev[i].flags)) {
1760 /* Oh, no!!! */ 1770 /* Oh, no!!! */
1771 set_bad = 1;
1761 printk_ratelimited( 1772 printk_ratelimited(
1762 KERN_WARNING 1773 KERN_WARNING
1763 "md/raid:%s: read error NOT corrected!! " 1774 "md/raid:%s: read error NOT corrected!! "
@@ -1765,7 +1776,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
1765 mdname(conf->mddev), 1776 mdname(conf->mddev),
1766 (unsigned long long)s, 1777 (unsigned long long)s,
1767 bdn); 1778 bdn);
1768 else if (atomic_read(&rdev->read_errors) 1779 } else if (atomic_read(&rdev->read_errors)
1769 > conf->max_nr_stripes) 1780 > conf->max_nr_stripes)
1770 printk(KERN_WARNING 1781 printk(KERN_WARNING
1771 "md/raid:%s: Too many read errors, failing device %s.\n", 1782 "md/raid:%s: Too many read errors, failing device %s.\n",
@@ -1777,7 +1788,11 @@ static void raid5_end_read_request(struct bio * bi, int error)
1777 else { 1788 else {
1778 clear_bit(R5_ReadError, &sh->dev[i].flags); 1789 clear_bit(R5_ReadError, &sh->dev[i].flags);
1779 clear_bit(R5_ReWrite, &sh->dev[i].flags); 1790 clear_bit(R5_ReWrite, &sh->dev[i].flags);
1780 md_error(conf->mddev, rdev); 1791 if (!(set_bad
1792 && test_bit(In_sync, &rdev->flags)
1793 && rdev_set_badblocks(
1794 rdev, sh->sector, STRIPE_SECTORS, 0)))
1795 md_error(conf->mddev, rdev);
1781 } 1796 }
1782 } 1797 }
1783 rdev_dec_pending(rdev, conf->mddev); 1798 rdev_dec_pending(rdev, conf->mddev);
@@ -3582,8 +3597,18 @@ static void handle_stripe(struct stripe_head *sh)
3582 3597
3583finish: 3598finish:
3584 /* wait for this device to become unblocked */ 3599 /* wait for this device to become unblocked */
3585 if (conf->mddev->external && unlikely(s.blocked_rdev)) 3600 if (unlikely(s.blocked_rdev)) {
3586 md_wait_for_blocked_rdev(s.blocked_rdev, conf->mddev); 3601 if (conf->mddev->external)
3602 md_wait_for_blocked_rdev(s.blocked_rdev,
3603 conf->mddev);
3604 else
3605 /* Internal metadata will immediately
3606 * be written by raid5d, so we don't
3607 * need to wait here.
3608 */
3609 rdev_dec_pending(s.blocked_rdev,
3610 conf->mddev);
3611 }
3587 3612
3588 if (s.handle_bad_blocks) 3613 if (s.handle_bad_blocks)
3589 for (i = disks; i--; ) { 3614 for (i = disks; i--; ) {
@@ -3881,8 +3906,6 @@ static int chunk_aligned_read(struct mddev *mddev, struct bio * raid_bio)
3881 raid_bio->bi_next = (void*)rdev; 3906 raid_bio->bi_next = (void*)rdev;
3882 align_bi->bi_bdev = rdev->bdev; 3907 align_bi->bi_bdev = rdev->bdev;
3883 align_bi->bi_flags &= ~(1 << BIO_SEG_VALID); 3908 align_bi->bi_flags &= ~(1 << BIO_SEG_VALID);
3884 /* No reshape active, so we can trust rdev->data_offset */
3885 align_bi->bi_sector += rdev->data_offset;
3886 3909
3887 if (!bio_fits_rdev(align_bi) || 3910 if (!bio_fits_rdev(align_bi) ||
3888 is_badblock(rdev, align_bi->bi_sector, align_bi->bi_size>>9, 3911 is_badblock(rdev, align_bi->bi_sector, align_bi->bi_size>>9,
@@ -3893,6 +3916,9 @@ static int chunk_aligned_read(struct mddev *mddev, struct bio * raid_bio)
3893 return 0; 3916 return 0;
3894 } 3917 }
3895 3918
3919 /* No reshape active, so we can trust rdev->data_offset */
3920 align_bi->bi_sector += rdev->data_offset;
3921
3896 spin_lock_irq(&conf->device_lock); 3922 spin_lock_irq(&conf->device_lock);
3897 wait_event_lock_irq(conf->wait_for_stripe, 3923 wait_event_lock_irq(conf->wait_for_stripe,
3898 conf->quiesce == 0, 3924 conf->quiesce == 0,
@@ -3971,7 +3997,6 @@ static void make_request(struct mddev *mddev, struct bio * bi)
3971 struct stripe_head *sh; 3997 struct stripe_head *sh;
3972 const int rw = bio_data_dir(bi); 3998 const int rw = bio_data_dir(bi);
3973 int remaining; 3999 int remaining;
3974 int plugged;
3975 4000
3976 if (unlikely(bi->bi_rw & REQ_FLUSH)) { 4001 if (unlikely(bi->bi_rw & REQ_FLUSH)) {
3977 md_flush_request(mddev, bi); 4002 md_flush_request(mddev, bi);
@@ -3990,7 +4015,6 @@ static void make_request(struct mddev *mddev, struct bio * bi)
3990 bi->bi_next = NULL; 4015 bi->bi_next = NULL;
3991 bi->bi_phys_segments = 1; /* over-loaded to count active stripes */ 4016 bi->bi_phys_segments = 1; /* over-loaded to count active stripes */
3992 4017
3993 plugged = mddev_check_plugged(mddev);
3994 for (;logical_sector < last_sector; logical_sector += STRIPE_SECTORS) { 4018 for (;logical_sector < last_sector; logical_sector += STRIPE_SECTORS) {
3995 DEFINE_WAIT(w); 4019 DEFINE_WAIT(w);
3996 int previous; 4020 int previous;
@@ -4092,6 +4116,7 @@ static void make_request(struct mddev *mddev, struct bio * bi)
4092 if ((bi->bi_rw & REQ_SYNC) && 4116 if ((bi->bi_rw & REQ_SYNC) &&
4093 !test_and_set_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) 4117 !test_and_set_bit(STRIPE_PREREAD_ACTIVE, &sh->state))
4094 atomic_inc(&conf->preread_active_stripes); 4118 atomic_inc(&conf->preread_active_stripes);
4119 mddev_check_plugged(mddev);
4095 release_stripe(sh); 4120 release_stripe(sh);
4096 } else { 4121 } else {
4097 /* cannot get stripe for read-ahead, just give-up */ 4122 /* cannot get stripe for read-ahead, just give-up */
@@ -4099,10 +4124,7 @@ static void make_request(struct mddev *mddev, struct bio * bi)
4099 finish_wait(&conf->wait_for_overlap, &w); 4124 finish_wait(&conf->wait_for_overlap, &w);
4100 break; 4125 break;
4101 } 4126 }
4102
4103 } 4127 }
4104 if (!plugged)
4105 md_wakeup_thread(mddev->thread);
4106 4128
4107 spin_lock_irq(&conf->device_lock); 4129 spin_lock_irq(&conf->device_lock);
4108 remaining = raid5_dec_bi_phys_segments(bi); 4130 remaining = raid5_dec_bi_phys_segments(bi);
@@ -4823,6 +4845,7 @@ static struct r5conf *setup_conf(struct mddev *mddev)
4823 int raid_disk, memory, max_disks; 4845 int raid_disk, memory, max_disks;
4824 struct md_rdev *rdev; 4846 struct md_rdev *rdev;
4825 struct disk_info *disk; 4847 struct disk_info *disk;
4848 char pers_name[6];
4826 4849
4827 if (mddev->new_level != 5 4850 if (mddev->new_level != 5
4828 && mddev->new_level != 4 4851 && mddev->new_level != 4
@@ -4946,7 +4969,8 @@ static struct r5conf *setup_conf(struct mddev *mddev)
4946 printk(KERN_INFO "md/raid:%s: allocated %dkB\n", 4969 printk(KERN_INFO "md/raid:%s: allocated %dkB\n",
4947 mdname(mddev), memory); 4970 mdname(mddev), memory);
4948 4971
4949 conf->thread = md_register_thread(raid5d, mddev, NULL); 4972 sprintf(pers_name, "raid%d", mddev->new_level);
4973 conf->thread = md_register_thread(raid5d, mddev, pers_name);
4950 if (!conf->thread) { 4974 if (!conf->thread) {
4951 printk(KERN_ERR 4975 printk(KERN_ERR
4952 "md/raid:%s: couldn't allocate thread.\n", 4976 "md/raid:%s: couldn't allocate thread.\n",
@@ -5465,10 +5489,9 @@ static int raid5_add_disk(struct mddev *mddev, struct md_rdev *rdev)
5465 if (rdev->saved_raid_disk >= 0 && 5489 if (rdev->saved_raid_disk >= 0 &&
5466 rdev->saved_raid_disk >= first && 5490 rdev->saved_raid_disk >= first &&
5467 conf->disks[rdev->saved_raid_disk].rdev == NULL) 5491 conf->disks[rdev->saved_raid_disk].rdev == NULL)
5468 disk = rdev->saved_raid_disk; 5492 first = rdev->saved_raid_disk;
5469 else 5493
5470 disk = first; 5494 for (disk = first; disk <= last; disk++) {
5471 for ( ; disk <= last ; disk++) {
5472 p = conf->disks + disk; 5495 p = conf->disks + disk;
5473 if (p->rdev == NULL) { 5496 if (p->rdev == NULL) {
5474 clear_bit(In_sync, &rdev->flags); 5497 clear_bit(In_sync, &rdev->flags);
@@ -5477,8 +5500,11 @@ static int raid5_add_disk(struct mddev *mddev, struct md_rdev *rdev)
5477 if (rdev->saved_raid_disk != disk) 5500 if (rdev->saved_raid_disk != disk)
5478 conf->fullsync = 1; 5501 conf->fullsync = 1;
5479 rcu_assign_pointer(p->rdev, rdev); 5502 rcu_assign_pointer(p->rdev, rdev);
5480 break; 5503 goto out;
5481 } 5504 }
5505 }
5506 for (disk = first; disk <= last; disk++) {
5507 p = conf->disks + disk;
5482 if (test_bit(WantReplacement, &p->rdev->flags) && 5508 if (test_bit(WantReplacement, &p->rdev->flags) &&
5483 p->replacement == NULL) { 5509 p->replacement == NULL) {
5484 clear_bit(In_sync, &rdev->flags); 5510 clear_bit(In_sync, &rdev->flags);
@@ -5490,6 +5516,7 @@ static int raid5_add_disk(struct mddev *mddev, struct md_rdev *rdev)
5490 break; 5516 break;
5491 } 5517 }
5492 } 5518 }
5519out:
5493 print_raid5_conf(conf); 5520 print_raid5_conf(conf);
5494 return err; 5521 return err;
5495} 5522}
diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
index 00a67326c193..39eab73b01ae 100644
--- a/drivers/media/dvb/dvb-core/dvbdev.c
+++ b/drivers/media/dvb/dvb-core/dvbdev.c
@@ -243,6 +243,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
243 if (minor == MAX_DVB_MINORS) { 243 if (minor == MAX_DVB_MINORS) {
244 kfree(dvbdevfops); 244 kfree(dvbdevfops);
245 kfree(dvbdev); 245 kfree(dvbdev);
246 up_write(&minor_rwsem);
246 mutex_unlock(&dvbdev_register_lock); 247 mutex_unlock(&dvbdev_register_lock);
247 return -EINVAL; 248 return -EINVAL;
248 } 249 }
diff --git a/drivers/media/rc/winbond-cir.c b/drivers/media/rc/winbond-cir.c
index 342c2c8c1ddf..54ee34872d14 100644
--- a/drivers/media/rc/winbond-cir.c
+++ b/drivers/media/rc/winbond-cir.c
@@ -232,7 +232,7 @@ MODULE_PARM_DESC(invert, "Invert the signal from the IR receiver");
232 232
233static bool txandrx; /* default = 0 */ 233static bool txandrx; /* default = 0 */
234module_param(txandrx, bool, 0444); 234module_param(txandrx, bool, 0444);
235MODULE_PARM_DESC(invert, "Allow simultaneous TX and RX"); 235MODULE_PARM_DESC(txandrx, "Allow simultaneous TX and RX");
236 236
237static unsigned int wake_sc = 0x800F040C; 237static unsigned int wake_sc = 0x800F040C;
238module_param(wake_sc, uint, 0644); 238module_param(wake_sc, uint, 0644);
@@ -1032,6 +1032,8 @@ wbcir_probe(struct pnp_dev *device, const struct pnp_device_id *dev_id)
1032 data->dev->tx_ir = wbcir_tx; 1032 data->dev->tx_ir = wbcir_tx;
1033 data->dev->priv = data; 1033 data->dev->priv = data;
1034 data->dev->dev.parent = &device->dev; 1034 data->dev->dev.parent = &device->dev;
1035 data->dev->timeout = MS_TO_NS(100);
1036 data->dev->allowed_protos = RC_TYPE_ALL;
1035 1037
1036 if (!request_region(data->wbase, WAKEUP_IOMEM_LEN, DRVNAME)) { 1038 if (!request_region(data->wbase, WAKEUP_IOMEM_LEN, DRVNAME)) {
1037 dev_err(dev, "Region 0x%lx-0x%lx already in use!\n", 1039 dev_err(dev, "Region 0x%lx-0x%lx already in use!\n",
diff --git a/drivers/media/video/cx231xx/cx231xx-audio.c b/drivers/media/video/cx231xx/cx231xx-audio.c
index 068f78dc5d13..b4c99c7270cf 100644
--- a/drivers/media/video/cx231xx/cx231xx-audio.c
+++ b/drivers/media/video/cx231xx/cx231xx-audio.c
@@ -307,7 +307,7 @@ static int cx231xx_init_audio_isoc(struct cx231xx *dev)
307 urb->context = dev; 307 urb->context = dev;
308 urb->pipe = usb_rcvisocpipe(dev->udev, 308 urb->pipe = usb_rcvisocpipe(dev->udev,
309 dev->adev.end_point_addr); 309 dev->adev.end_point_addr);
310 urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP; 310 urb->transfer_flags = URB_ISO_ASAP;
311 urb->transfer_buffer = dev->adev.transfer_buffer[i]; 311 urb->transfer_buffer = dev->adev.transfer_buffer[i];
312 urb->interval = 1; 312 urb->interval = 1;
313 urb->complete = cx231xx_audio_isocirq; 313 urb->complete = cx231xx_audio_isocirq;
@@ -368,7 +368,7 @@ static int cx231xx_init_audio_bulk(struct cx231xx *dev)
368 urb->context = dev; 368 urb->context = dev;
369 urb->pipe = usb_rcvbulkpipe(dev->udev, 369 urb->pipe = usb_rcvbulkpipe(dev->udev,
370 dev->adev.end_point_addr); 370 dev->adev.end_point_addr);
371 urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP; 371 urb->transfer_flags = 0;
372 urb->transfer_buffer = dev->adev.transfer_buffer[i]; 372 urb->transfer_buffer = dev->adev.transfer_buffer[i];
373 urb->complete = cx231xx_audio_bulkirq; 373 urb->complete = cx231xx_audio_bulkirq;
374 urb->transfer_buffer_length = sb_size; 374 urb->transfer_buffer_length = sb_size;
diff --git a/drivers/media/video/cx231xx/cx231xx-vbi.c b/drivers/media/video/cx231xx/cx231xx-vbi.c
index 3d15314e1f88..ac7db52f404f 100644
--- a/drivers/media/video/cx231xx/cx231xx-vbi.c
+++ b/drivers/media/video/cx231xx/cx231xx-vbi.c
@@ -448,7 +448,7 @@ int cx231xx_init_vbi_isoc(struct cx231xx *dev, int max_packets,
448 return -ENOMEM; 448 return -ENOMEM;
449 } 449 }
450 dev->vbi_mode.bulk_ctl.urb[i] = urb; 450 dev->vbi_mode.bulk_ctl.urb[i] = urb;
451 urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP; 451 urb->transfer_flags = 0;
452 452
453 dev->vbi_mode.bulk_ctl.transfer_buffer[i] = 453 dev->vbi_mode.bulk_ctl.transfer_buffer[i] =
454 kzalloc(sb_size, GFP_KERNEL); 454 kzalloc(sb_size, GFP_KERNEL);
diff --git a/drivers/media/video/cx23885/cx23885-cards.c b/drivers/media/video/cx23885/cx23885-cards.c
index 13739e002a63..080e11157e5f 100644
--- a/drivers/media/video/cx23885/cx23885-cards.c
+++ b/drivers/media/video/cx23885/cx23885-cards.c
@@ -127,22 +127,37 @@ struct cx23885_board cx23885_boards[] = {
127 }, 127 },
128 [CX23885_BOARD_HAUPPAUGE_HVR1250] = { 128 [CX23885_BOARD_HAUPPAUGE_HVR1250] = {
129 .name = "Hauppauge WinTV-HVR1250", 129 .name = "Hauppauge WinTV-HVR1250",
130 .porta = CX23885_ANALOG_VIDEO,
130 .portc = CX23885_MPEG_DVB, 131 .portc = CX23885_MPEG_DVB,
132#ifdef MT2131_NO_ANALOG_SUPPORT_YET
133 .tuner_type = TUNER_PHILIPS_TDA8290,
134 .tuner_addr = 0x42, /* 0x84 >> 1 */
135 .tuner_bus = 1,
136#endif
137 .force_bff = 1,
131 .input = {{ 138 .input = {{
139#ifdef MT2131_NO_ANALOG_SUPPORT_YET
132 .type = CX23885_VMUX_TELEVISION, 140 .type = CX23885_VMUX_TELEVISION,
133 .vmux = 0, 141 .vmux = CX25840_VIN7_CH3 |
142 CX25840_VIN5_CH2 |
143 CX25840_VIN2_CH1,
144 .amux = CX25840_AUDIO8,
134 .gpio0 = 0xff00, 145 .gpio0 = 0xff00,
135 }, { 146 }, {
136 .type = CX23885_VMUX_DEBUG, 147#endif
137 .vmux = 0,
138 .gpio0 = 0xff01,
139 }, {
140 .type = CX23885_VMUX_COMPOSITE1, 148 .type = CX23885_VMUX_COMPOSITE1,
141 .vmux = 1, 149 .vmux = CX25840_VIN7_CH3 |
150 CX25840_VIN4_CH2 |
151 CX25840_VIN6_CH1,
152 .amux = CX25840_AUDIO7,
142 .gpio0 = 0xff02, 153 .gpio0 = 0xff02,
143 }, { 154 }, {
144 .type = CX23885_VMUX_SVIDEO, 155 .type = CX23885_VMUX_SVIDEO,
145 .vmux = 2, 156 .vmux = CX25840_VIN7_CH3 |
157 CX25840_VIN4_CH2 |
158 CX25840_VIN8_CH1 |
159 CX25840_SVIDEO_ON,
160 .amux = CX25840_AUDIO7,
146 .gpio0 = 0xff02, 161 .gpio0 = 0xff02,
147 } }, 162 } },
148 }, 163 },
@@ -267,7 +282,55 @@ struct cx23885_board cx23885_boards[] = {
267 }, 282 },
268 [CX23885_BOARD_HAUPPAUGE_HVR1255] = { 283 [CX23885_BOARD_HAUPPAUGE_HVR1255] = {
269 .name = "Hauppauge WinTV-HVR1255", 284 .name = "Hauppauge WinTV-HVR1255",
285 .porta = CX23885_ANALOG_VIDEO,
286 .portc = CX23885_MPEG_DVB,
287 .tuner_type = TUNER_ABSENT,
288 .tuner_addr = 0x42, /* 0x84 >> 1 */
289 .force_bff = 1,
290 .input = {{
291 .type = CX23885_VMUX_TELEVISION,
292 .vmux = CX25840_VIN7_CH3 |
293 CX25840_VIN5_CH2 |
294 CX25840_VIN2_CH1 |
295 CX25840_DIF_ON,
296 .amux = CX25840_AUDIO8,
297 }, {
298 .type = CX23885_VMUX_COMPOSITE1,
299 .vmux = CX25840_VIN7_CH3 |
300 CX25840_VIN4_CH2 |
301 CX25840_VIN6_CH1,
302 .amux = CX25840_AUDIO7,
303 }, {
304 .type = CX23885_VMUX_SVIDEO,
305 .vmux = CX25840_VIN7_CH3 |
306 CX25840_VIN4_CH2 |
307 CX25840_VIN8_CH1 |
308 CX25840_SVIDEO_ON,
309 .amux = CX25840_AUDIO7,
310 } },
311 },
312 [CX23885_BOARD_HAUPPAUGE_HVR1255_22111] = {
313 .name = "Hauppauge WinTV-HVR1255",
314 .porta = CX23885_ANALOG_VIDEO,
270 .portc = CX23885_MPEG_DVB, 315 .portc = CX23885_MPEG_DVB,
316 .tuner_type = TUNER_ABSENT,
317 .tuner_addr = 0x42, /* 0x84 >> 1 */
318 .force_bff = 1,
319 .input = {{
320 .type = CX23885_VMUX_TELEVISION,
321 .vmux = CX25840_VIN7_CH3 |
322 CX25840_VIN5_CH2 |
323 CX25840_VIN2_CH1 |
324 CX25840_DIF_ON,
325 .amux = CX25840_AUDIO8,
326 }, {
327 .type = CX23885_VMUX_SVIDEO,
328 .vmux = CX25840_VIN7_CH3 |
329 CX25840_VIN4_CH2 |
330 CX25840_VIN8_CH1 |
331 CX25840_SVIDEO_ON,
332 .amux = CX25840_AUDIO7,
333 } },
271 }, 334 },
272 [CX23885_BOARD_HAUPPAUGE_HVR1210] = { 335 [CX23885_BOARD_HAUPPAUGE_HVR1210] = {
273 .name = "Hauppauge WinTV-HVR1210", 336 .name = "Hauppauge WinTV-HVR1210",
@@ -624,7 +687,7 @@ struct cx23885_subid cx23885_subids[] = {
624 }, { 687 }, {
625 .subvendor = 0x0070, 688 .subvendor = 0x0070,
626 .subdevice = 0x2259, 689 .subdevice = 0x2259,
627 .card = CX23885_BOARD_HAUPPAUGE_HVR1255, 690 .card = CX23885_BOARD_HAUPPAUGE_HVR1255_22111,
628 }, { 691 }, {
629 .subvendor = 0x0070, 692 .subvendor = 0x0070,
630 .subdevice = 0x2291, 693 .subdevice = 0x2291,
@@ -900,7 +963,7 @@ int cx23885_tuner_callback(void *priv, int component, int command, int arg)
900 struct cx23885_dev *dev = port->dev; 963 struct cx23885_dev *dev = port->dev;
901 u32 bitmask = 0; 964 u32 bitmask = 0;
902 965
903 if (command == XC2028_RESET_CLK) 966 if ((command == XC2028_RESET_CLK) || (command == XC2028_I2C_FLUSH))
904 return 0; 967 return 0;
905 968
906 if (command != 0) { 969 if (command != 0) {
@@ -1130,6 +1193,7 @@ void cx23885_gpio_setup(struct cx23885_dev *dev)
1130 case CX23885_BOARD_HAUPPAUGE_HVR1270: 1193 case CX23885_BOARD_HAUPPAUGE_HVR1270:
1131 case CX23885_BOARD_HAUPPAUGE_HVR1275: 1194 case CX23885_BOARD_HAUPPAUGE_HVR1275:
1132 case CX23885_BOARD_HAUPPAUGE_HVR1255: 1195 case CX23885_BOARD_HAUPPAUGE_HVR1255:
1196 case CX23885_BOARD_HAUPPAUGE_HVR1255_22111:
1133 case CX23885_BOARD_HAUPPAUGE_HVR1210: 1197 case CX23885_BOARD_HAUPPAUGE_HVR1210:
1134 /* GPIO-5 RF Control: 0 = RF1 Terrestrial, 1 = RF2 Cable */ 1198 /* GPIO-5 RF Control: 0 = RF1 Terrestrial, 1 = RF2 Cable */
1135 /* GPIO-6 I2C Gate which can isolate the demod from the bus */ 1199 /* GPIO-6 I2C Gate which can isolate the demod from the bus */
@@ -1267,6 +1331,7 @@ int cx23885_ir_init(struct cx23885_dev *dev)
1267 case CX23885_BOARD_HAUPPAUGE_HVR1400: 1331 case CX23885_BOARD_HAUPPAUGE_HVR1400:
1268 case CX23885_BOARD_HAUPPAUGE_HVR1275: 1332 case CX23885_BOARD_HAUPPAUGE_HVR1275:
1269 case CX23885_BOARD_HAUPPAUGE_HVR1255: 1333 case CX23885_BOARD_HAUPPAUGE_HVR1255:
1334 case CX23885_BOARD_HAUPPAUGE_HVR1255_22111:
1270 case CX23885_BOARD_HAUPPAUGE_HVR1210: 1335 case CX23885_BOARD_HAUPPAUGE_HVR1210:
1271 /* FIXME: Implement me */ 1336 /* FIXME: Implement me */
1272 break; 1337 break;
@@ -1424,6 +1489,7 @@ void cx23885_card_setup(struct cx23885_dev *dev)
1424 case CX23885_BOARD_HAUPPAUGE_HVR1270: 1489 case CX23885_BOARD_HAUPPAUGE_HVR1270:
1425 case CX23885_BOARD_HAUPPAUGE_HVR1275: 1490 case CX23885_BOARD_HAUPPAUGE_HVR1275:
1426 case CX23885_BOARD_HAUPPAUGE_HVR1255: 1491 case CX23885_BOARD_HAUPPAUGE_HVR1255:
1492 case CX23885_BOARD_HAUPPAUGE_HVR1255_22111:
1427 case CX23885_BOARD_HAUPPAUGE_HVR1210: 1493 case CX23885_BOARD_HAUPPAUGE_HVR1210:
1428 case CX23885_BOARD_HAUPPAUGE_HVR1850: 1494 case CX23885_BOARD_HAUPPAUGE_HVR1850:
1429 case CX23885_BOARD_HAUPPAUGE_HVR1290: 1495 case CX23885_BOARD_HAUPPAUGE_HVR1290:
@@ -1511,6 +1577,7 @@ void cx23885_card_setup(struct cx23885_dev *dev)
1511 case CX23885_BOARD_HAUPPAUGE_HVR1270: 1577 case CX23885_BOARD_HAUPPAUGE_HVR1270:
1512 case CX23885_BOARD_HAUPPAUGE_HVR1275: 1578 case CX23885_BOARD_HAUPPAUGE_HVR1275:
1513 case CX23885_BOARD_HAUPPAUGE_HVR1255: 1579 case CX23885_BOARD_HAUPPAUGE_HVR1255:
1580 case CX23885_BOARD_HAUPPAUGE_HVR1255_22111:
1514 case CX23885_BOARD_HAUPPAUGE_HVR1210: 1581 case CX23885_BOARD_HAUPPAUGE_HVR1210:
1515 case CX23885_BOARD_COMPRO_VIDEOMATE_E800: 1582 case CX23885_BOARD_COMPRO_VIDEOMATE_E800:
1516 case CX23885_BOARD_HAUPPAUGE_HVR1290: 1583 case CX23885_BOARD_HAUPPAUGE_HVR1290:
@@ -1526,10 +1593,10 @@ void cx23885_card_setup(struct cx23885_dev *dev)
1526 */ 1593 */
1527 switch (dev->board) { 1594 switch (dev->board) {
1528 case CX23885_BOARD_TEVII_S470: 1595 case CX23885_BOARD_TEVII_S470:
1529 case CX23885_BOARD_HAUPPAUGE_HVR1250:
1530 /* Currently only enabled for the integrated IR controller */ 1596 /* Currently only enabled for the integrated IR controller */
1531 if (!enable_885_ir) 1597 if (!enable_885_ir)
1532 break; 1598 break;
1599 case CX23885_BOARD_HAUPPAUGE_HVR1250:
1533 case CX23885_BOARD_HAUPPAUGE_HVR1800: 1600 case CX23885_BOARD_HAUPPAUGE_HVR1800:
1534 case CX23885_BOARD_HAUPPAUGE_HVR1800lp: 1601 case CX23885_BOARD_HAUPPAUGE_HVR1800lp:
1535 case CX23885_BOARD_HAUPPAUGE_HVR1700: 1602 case CX23885_BOARD_HAUPPAUGE_HVR1700:
@@ -1539,6 +1606,8 @@ void cx23885_card_setup(struct cx23885_dev *dev)
1539 case CX23885_BOARD_NETUP_DUAL_DVBS2_CI: 1606 case CX23885_BOARD_NETUP_DUAL_DVBS2_CI:
1540 case CX23885_BOARD_NETUP_DUAL_DVB_T_C_CI_RF: 1607 case CX23885_BOARD_NETUP_DUAL_DVB_T_C_CI_RF:
1541 case CX23885_BOARD_COMPRO_VIDEOMATE_E800: 1608 case CX23885_BOARD_COMPRO_VIDEOMATE_E800:
1609 case CX23885_BOARD_HAUPPAUGE_HVR1255:
1610 case CX23885_BOARD_HAUPPAUGE_HVR1255_22111:
1542 case CX23885_BOARD_HAUPPAUGE_HVR1270: 1611 case CX23885_BOARD_HAUPPAUGE_HVR1270:
1543 case CX23885_BOARD_HAUPPAUGE_HVR1850: 1612 case CX23885_BOARD_HAUPPAUGE_HVR1850:
1544 case CX23885_BOARD_MYGICA_X8506: 1613 case CX23885_BOARD_MYGICA_X8506:
diff --git a/drivers/media/video/cx23885/cx23885-dvb.c b/drivers/media/video/cx23885/cx23885-dvb.c
index a80a92c47455..cd542684ba02 100644
--- a/drivers/media/video/cx23885/cx23885-dvb.c
+++ b/drivers/media/video/cx23885/cx23885-dvb.c
@@ -712,6 +712,7 @@ static int dvb_register(struct cx23885_tsport *port)
712 } 712 }
713 break; 713 break;
714 case CX23885_BOARD_HAUPPAUGE_HVR1255: 714 case CX23885_BOARD_HAUPPAUGE_HVR1255:
715 case CX23885_BOARD_HAUPPAUGE_HVR1255_22111:
715 i2c_bus = &dev->i2c_bus[0]; 716 i2c_bus = &dev->i2c_bus[0];
716 fe0->dvb.frontend = dvb_attach(s5h1411_attach, 717 fe0->dvb.frontend = dvb_attach(s5h1411_attach,
717 &hcw_s5h1411_config, 718 &hcw_s5h1411_config,
@@ -721,6 +722,11 @@ static int dvb_register(struct cx23885_tsport *port)
721 0x60, &dev->i2c_bus[1].i2c_adap, 722 0x60, &dev->i2c_bus[1].i2c_adap,
722 &hauppauge_tda18271_config); 723 &hauppauge_tda18271_config);
723 } 724 }
725
726 tda18271_attach(&dev->ts1.analog_fe,
727 0x60, &dev->i2c_bus[1].i2c_adap,
728 &hauppauge_tda18271_config);
729
724 break; 730 break;
725 case CX23885_BOARD_HAUPPAUGE_HVR1800: 731 case CX23885_BOARD_HAUPPAUGE_HVR1800:
726 i2c_bus = &dev->i2c_bus[0]; 732 i2c_bus = &dev->i2c_bus[0];
diff --git a/drivers/media/video/cx23885/cx23885-video.c b/drivers/media/video/cx23885/cx23885-video.c
index c654bdc7ccb2..22f8e7fbd665 100644
--- a/drivers/media/video/cx23885/cx23885-video.c
+++ b/drivers/media/video/cx23885/cx23885-video.c
@@ -505,6 +505,9 @@ static int cx23885_video_mux(struct cx23885_dev *dev, unsigned int input)
505 505
506 if ((dev->board == CX23885_BOARD_HAUPPAUGE_HVR1800) || 506 if ((dev->board == CX23885_BOARD_HAUPPAUGE_HVR1800) ||
507 (dev->board == CX23885_BOARD_MPX885) || 507 (dev->board == CX23885_BOARD_MPX885) ||
508 (dev->board == CX23885_BOARD_HAUPPAUGE_HVR1250) ||
509 (dev->board == CX23885_BOARD_HAUPPAUGE_HVR1255) ||
510 (dev->board == CX23885_BOARD_HAUPPAUGE_HVR1255_22111) ||
508 (dev->board == CX23885_BOARD_HAUPPAUGE_HVR1850)) { 511 (dev->board == CX23885_BOARD_HAUPPAUGE_HVR1850)) {
509 /* Configure audio routing */ 512 /* Configure audio routing */
510 v4l2_subdev_call(dev->sd_cx25840, audio, s_routing, 513 v4l2_subdev_call(dev->sd_cx25840, audio, s_routing,
@@ -1578,7 +1581,9 @@ static int cx23885_set_freq_via_ops(struct cx23885_dev *dev,
1578 1581
1579 fe = vfe->dvb.frontend; 1582 fe = vfe->dvb.frontend;
1580 1583
1581 if (dev->board == CX23885_BOARD_HAUPPAUGE_HVR1850) 1584 if ((dev->board == CX23885_BOARD_HAUPPAUGE_HVR1850) ||
1585 (dev->board == CX23885_BOARD_HAUPPAUGE_HVR1255) ||
1586 (dev->board == CX23885_BOARD_HAUPPAUGE_HVR1255_22111))
1582 fe = &dev->ts1.analog_fe; 1587 fe = &dev->ts1.analog_fe;
1583 1588
1584 if (fe && fe->ops.tuner_ops.set_analog_params) { 1589 if (fe && fe->ops.tuner_ops.set_analog_params) {
@@ -1608,6 +1613,8 @@ int cx23885_set_frequency(struct file *file, void *priv,
1608 int ret; 1613 int ret;
1609 1614
1610 switch (dev->board) { 1615 switch (dev->board) {
1616 case CX23885_BOARD_HAUPPAUGE_HVR1255:
1617 case CX23885_BOARD_HAUPPAUGE_HVR1255_22111:
1611 case CX23885_BOARD_HAUPPAUGE_HVR1850: 1618 case CX23885_BOARD_HAUPPAUGE_HVR1850:
1612 ret = cx23885_set_freq_via_ops(dev, f); 1619 ret = cx23885_set_freq_via_ops(dev, f);
1613 break; 1620 break;
diff --git a/drivers/media/video/cx23885/cx23885.h b/drivers/media/video/cx23885/cx23885.h
index d884784a1c85..13c37ec07ae7 100644
--- a/drivers/media/video/cx23885/cx23885.h
+++ b/drivers/media/video/cx23885/cx23885.h
@@ -90,6 +90,7 @@
90#define CX23885_BOARD_MYGICA_X8507 33 90#define CX23885_BOARD_MYGICA_X8507 33
91#define CX23885_BOARD_TERRATEC_CINERGY_T_PCIE_DUAL 34 91#define CX23885_BOARD_TERRATEC_CINERGY_T_PCIE_DUAL 34
92#define CX23885_BOARD_TEVII_S471 35 92#define CX23885_BOARD_TEVII_S471 35
93#define CX23885_BOARD_HAUPPAUGE_HVR1255_22111 36
93 94
94#define GPIO_0 0x00000001 95#define GPIO_0 0x00000001
95#define GPIO_1 0x00000002 96#define GPIO_1 0x00000002
diff --git a/drivers/media/video/cx25840/cx25840-core.c b/drivers/media/video/cx25840/cx25840-core.c
index fc1ff69cffd0..d8eac3e30a7e 100644
--- a/drivers/media/video/cx25840/cx25840-core.c
+++ b/drivers/media/video/cx25840/cx25840-core.c
@@ -84,7 +84,7 @@ MODULE_PARM_DESC(debug, "Debugging messages [0=Off (default) 1=On]");
84 84
85 85
86/* ----------------------------------------------------------------------- */ 86/* ----------------------------------------------------------------------- */
87static void cx23885_std_setup(struct i2c_client *client); 87static void cx23888_std_setup(struct i2c_client *client);
88 88
89int cx25840_write(struct i2c_client *client, u16 addr, u8 value) 89int cx25840_write(struct i2c_client *client, u16 addr, u8 value)
90{ 90{
@@ -638,10 +638,13 @@ static void cx23885_initialize(struct i2c_client *client)
638 finish_wait(&state->fw_wait, &wait); 638 finish_wait(&state->fw_wait, &wait);
639 destroy_workqueue(q); 639 destroy_workqueue(q);
640 640
641 /* Call the cx23885 specific std setup func, we no longer rely on 641 /* Call the cx23888 specific std setup func, we no longer rely on
642 * the generic cx24840 func. 642 * the generic cx24840 func.
643 */ 643 */
644 cx23885_std_setup(client); 644 if (is_cx23888(state))
645 cx23888_std_setup(client);
646 else
647 cx25840_std_setup(client);
645 648
646 /* (re)set input */ 649 /* (re)set input */
647 set_input(client, state->vid_input, state->aud_input); 650 set_input(client, state->vid_input, state->aud_input);
@@ -1103,9 +1106,23 @@ static int set_input(struct i2c_client *client, enum cx25840_video_input vid_inp
1103 1106
1104 cx25840_write4(client, 0x410, 0xffff0dbf); 1107 cx25840_write4(client, 0x410, 0xffff0dbf);
1105 cx25840_write4(client, 0x414, 0x00137d03); 1108 cx25840_write4(client, 0x414, 0x00137d03);
1106 cx25840_write4(client, 0x418, 0x01008080); 1109
1110 /* on the 887, 0x418 is HSCALE_CTRL, on the 888 it is
1111 CHROMA_CTRL */
1112 if (is_cx23888(state))
1113 cx25840_write4(client, 0x418, 0x01008080);
1114 else
1115 cx25840_write4(client, 0x418, 0x01000000);
1116
1107 cx25840_write4(client, 0x41c, 0x00000000); 1117 cx25840_write4(client, 0x41c, 0x00000000);
1108 cx25840_write4(client, 0x420, 0x001c3e0f); 1118
1119 /* on the 887, 0x420 is CHROMA_CTRL, on the 888 it is
1120 CRUSH_CTRL */
1121 if (is_cx23888(state))
1122 cx25840_write4(client, 0x420, 0x001c3e0f);
1123 else
1124 cx25840_write4(client, 0x420, 0x001c8282);
1125
1109 cx25840_write4(client, 0x42c, 0x42600000); 1126 cx25840_write4(client, 0x42c, 0x42600000);
1110 cx25840_write4(client, 0x430, 0x0000039b); 1127 cx25840_write4(client, 0x430, 0x0000039b);
1111 cx25840_write4(client, 0x438, 0x00000000); 1128 cx25840_write4(client, 0x438, 0x00000000);
@@ -1233,7 +1250,7 @@ static int set_input(struct i2c_client *client, enum cx25840_video_input vid_inp
1233 cx25840_write4(client, 0x8d0, 0x1f063870); 1250 cx25840_write4(client, 0x8d0, 0x1f063870);
1234 } 1251 }
1235 1252
1236 if (is_cx2388x(state)) { 1253 if (is_cx23888(state)) {
1237 /* HVR1850 */ 1254 /* HVR1850 */
1238 /* AUD_IO_CTRL - I2S Input, Parallel1*/ 1255 /* AUD_IO_CTRL - I2S Input, Parallel1*/
1239 /* - Channel 1 src - Parallel1 (Merlin out) */ 1256 /* - Channel 1 src - Parallel1 (Merlin out) */
@@ -1298,8 +1315,8 @@ static int set_v4lstd(struct i2c_client *client)
1298 } 1315 }
1299 cx25840_and_or(client, 0x400, ~0xf, fmt); 1316 cx25840_and_or(client, 0x400, ~0xf, fmt);
1300 cx25840_and_or(client, 0x403, ~0x3, pal_m); 1317 cx25840_and_or(client, 0x403, ~0x3, pal_m);
1301 if (is_cx2388x(state)) 1318 if (is_cx23888(state))
1302 cx23885_std_setup(client); 1319 cx23888_std_setup(client);
1303 else 1320 else
1304 cx25840_std_setup(client); 1321 cx25840_std_setup(client);
1305 if (!is_cx2583x(state)) 1322 if (!is_cx2583x(state))
@@ -1312,6 +1329,7 @@ static int set_v4lstd(struct i2c_client *client)
1312static int cx25840_s_ctrl(struct v4l2_ctrl *ctrl) 1329static int cx25840_s_ctrl(struct v4l2_ctrl *ctrl)
1313{ 1330{
1314 struct v4l2_subdev *sd = to_sd(ctrl); 1331 struct v4l2_subdev *sd = to_sd(ctrl);
1332 struct cx25840_state *state = to_state(sd);
1315 struct i2c_client *client = v4l2_get_subdevdata(sd); 1333 struct i2c_client *client = v4l2_get_subdevdata(sd);
1316 1334
1317 switch (ctrl->id) { 1335 switch (ctrl->id) {
@@ -1324,12 +1342,20 @@ static int cx25840_s_ctrl(struct v4l2_ctrl *ctrl)
1324 break; 1342 break;
1325 1343
1326 case V4L2_CID_SATURATION: 1344 case V4L2_CID_SATURATION:
1327 cx25840_write(client, 0x420, ctrl->val << 1); 1345 if (is_cx23888(state)) {
1328 cx25840_write(client, 0x421, ctrl->val << 1); 1346 cx25840_write(client, 0x418, ctrl->val << 1);
1347 cx25840_write(client, 0x419, ctrl->val << 1);
1348 } else {
1349 cx25840_write(client, 0x420, ctrl->val << 1);
1350 cx25840_write(client, 0x421, ctrl->val << 1);
1351 }
1329 break; 1352 break;
1330 1353
1331 case V4L2_CID_HUE: 1354 case V4L2_CID_HUE:
1332 cx25840_write(client, 0x422, ctrl->val); 1355 if (is_cx23888(state))
1356 cx25840_write(client, 0x41a, ctrl->val);
1357 else
1358 cx25840_write(client, 0x422, ctrl->val);
1333 break; 1359 break;
1334 1360
1335 default: 1361 default:
@@ -1354,11 +1380,21 @@ static int cx25840_s_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt
1354 fmt->field = V4L2_FIELD_INTERLACED; 1380 fmt->field = V4L2_FIELD_INTERLACED;
1355 fmt->colorspace = V4L2_COLORSPACE_SMPTE170M; 1381 fmt->colorspace = V4L2_COLORSPACE_SMPTE170M;
1356 1382
1357 Vsrc = (cx25840_read(client, 0x476) & 0x3f) << 4; 1383 if (is_cx23888(state)) {
1358 Vsrc |= (cx25840_read(client, 0x475) & 0xf0) >> 4; 1384 Vsrc = (cx25840_read(client, 0x42a) & 0x3f) << 4;
1385 Vsrc |= (cx25840_read(client, 0x429) & 0xf0) >> 4;
1386 } else {
1387 Vsrc = (cx25840_read(client, 0x476) & 0x3f) << 4;
1388 Vsrc |= (cx25840_read(client, 0x475) & 0xf0) >> 4;
1389 }
1359 1390
1360 Hsrc = (cx25840_read(client, 0x472) & 0x3f) << 4; 1391 if (is_cx23888(state)) {
1361 Hsrc |= (cx25840_read(client, 0x471) & 0xf0) >> 4; 1392 Hsrc = (cx25840_read(client, 0x426) & 0x3f) << 4;
1393 Hsrc |= (cx25840_read(client, 0x425) & 0xf0) >> 4;
1394 } else {
1395 Hsrc = (cx25840_read(client, 0x472) & 0x3f) << 4;
1396 Hsrc |= (cx25840_read(client, 0x471) & 0xf0) >> 4;
1397 }
1362 1398
1363 Vlines = fmt->height + (is_50Hz ? 4 : 7); 1399 Vlines = fmt->height + (is_50Hz ? 4 : 7);
1364 1400
@@ -1782,8 +1818,8 @@ static int cx25840_s_video_routing(struct v4l2_subdev *sd,
1782 struct cx25840_state *state = to_state(sd); 1818 struct cx25840_state *state = to_state(sd);
1783 struct i2c_client *client = v4l2_get_subdevdata(sd); 1819 struct i2c_client *client = v4l2_get_subdevdata(sd);
1784 1820
1785 if (is_cx2388x(state)) 1821 if (is_cx23888(state))
1786 cx23885_std_setup(client); 1822 cx23888_std_setup(client);
1787 1823
1788 return set_input(client, input, state->aud_input); 1824 return set_input(client, input, state->aud_input);
1789} 1825}
@@ -1794,8 +1830,8 @@ static int cx25840_s_audio_routing(struct v4l2_subdev *sd,
1794 struct cx25840_state *state = to_state(sd); 1830 struct cx25840_state *state = to_state(sd);
1795 struct i2c_client *client = v4l2_get_subdevdata(sd); 1831 struct i2c_client *client = v4l2_get_subdevdata(sd);
1796 1832
1797 if (is_cx2388x(state)) 1833 if (is_cx23888(state))
1798 cx23885_std_setup(client); 1834 cx23888_std_setup(client);
1799 return set_input(client, state->vid_input, input); 1835 return set_input(client, state->vid_input, input);
1800} 1836}
1801 1837
@@ -4939,7 +4975,7 @@ void cx23885_dif_setup(struct i2c_client *client, u32 ifHz)
4939 } 4975 }
4940} 4976}
4941 4977
4942static void cx23885_std_setup(struct i2c_client *client) 4978static void cx23888_std_setup(struct i2c_client *client)
4943{ 4979{
4944 struct cx25840_state *state = to_state(i2c_get_clientdata(client)); 4980 struct cx25840_state *state = to_state(i2c_get_clientdata(client));
4945 v4l2_std_id std = state->std; 4981 v4l2_std_id std = state->std;
diff --git a/drivers/media/video/em28xx/em28xx-cards.c b/drivers/media/video/em28xx/em28xx-cards.c
index 92da7c28b6f0..862c6575c557 100644
--- a/drivers/media/video/em28xx/em28xx-cards.c
+++ b/drivers/media/video/em28xx/em28xx-cards.c
@@ -2893,7 +2893,7 @@ static void request_module_async(struct work_struct *work)
2893 2893
2894 if (dev->board.has_dvb) 2894 if (dev->board.has_dvb)
2895 request_module("em28xx-dvb"); 2895 request_module("em28xx-dvb");
2896 if (dev->board.has_ir_i2c && !disable_ir) 2896 if (dev->board.ir_codes && !disable_ir)
2897 request_module("em28xx-rc"); 2897 request_module("em28xx-rc");
2898} 2898}
2899 2899
diff --git a/drivers/media/video/gspca/sn9c20x.c b/drivers/media/video/gspca/sn9c20x.c
index 6c31e46a1fd2..b9c6f17eabb2 100644
--- a/drivers/media/video/gspca/sn9c20x.c
+++ b/drivers/media/video/gspca/sn9c20x.c
@@ -2070,10 +2070,13 @@ static int sd_start(struct gspca_dev *gspca_dev)
2070 set_gamma(gspca_dev, v4l2_ctrl_g_ctrl(sd->gamma)); 2070 set_gamma(gspca_dev, v4l2_ctrl_g_ctrl(sd->gamma));
2071 set_redblue(gspca_dev, v4l2_ctrl_g_ctrl(sd->blue), 2071 set_redblue(gspca_dev, v4l2_ctrl_g_ctrl(sd->blue),
2072 v4l2_ctrl_g_ctrl(sd->red)); 2072 v4l2_ctrl_g_ctrl(sd->red));
2073 set_gain(gspca_dev, v4l2_ctrl_g_ctrl(sd->gain)); 2073 if (sd->gain)
2074 set_exposure(gspca_dev, v4l2_ctrl_g_ctrl(sd->exposure)); 2074 set_gain(gspca_dev, v4l2_ctrl_g_ctrl(sd->gain));
2075 set_hvflip(gspca_dev, v4l2_ctrl_g_ctrl(sd->hflip), 2075 if (sd->exposure)
2076 v4l2_ctrl_g_ctrl(sd->vflip)); 2076 set_exposure(gspca_dev, v4l2_ctrl_g_ctrl(sd->exposure));
2077 if (sd->hflip)
2078 set_hvflip(gspca_dev, v4l2_ctrl_g_ctrl(sd->hflip),
2079 v4l2_ctrl_g_ctrl(sd->vflip));
2077 2080
2078 reg_w1(gspca_dev, 0x1007, 0x20); 2081 reg_w1(gspca_dev, 0x1007, 0x20);
2079 reg_w1(gspca_dev, 0x1061, 0x03); 2082 reg_w1(gspca_dev, 0x1061, 0x03);
@@ -2176,7 +2179,7 @@ static void sd_dqcallback(struct gspca_dev *gspca_dev)
2176 struct sd *sd = (struct sd *) gspca_dev; 2179 struct sd *sd = (struct sd *) gspca_dev;
2177 int avg_lum; 2180 int avg_lum;
2178 2181
2179 if (!v4l2_ctrl_g_ctrl(sd->autogain)) 2182 if (sd->autogain == NULL || !v4l2_ctrl_g_ctrl(sd->autogain))
2180 return; 2183 return;
2181 2184
2182 avg_lum = atomic_read(&sd->avg_lum); 2185 avg_lum = atomic_read(&sd->avg_lum);
diff --git a/drivers/media/video/mx2_camera.c b/drivers/media/video/mx2_camera.c
index 41f9a254b245..637bde8aca28 100644
--- a/drivers/media/video/mx2_camera.c
+++ b/drivers/media/video/mx2_camera.c
@@ -83,6 +83,7 @@
83#define CSICR1_INV_DATA (1 << 3) 83#define CSICR1_INV_DATA (1 << 3)
84#define CSICR1_INV_PCLK (1 << 2) 84#define CSICR1_INV_PCLK (1 << 2)
85#define CSICR1_REDGE (1 << 1) 85#define CSICR1_REDGE (1 << 1)
86#define CSICR1_FMT_MASK (CSICR1_PACK_DIR | CSICR1_SWAP16_EN)
86 87
87#define SHIFT_STATFF_LEVEL 22 88#define SHIFT_STATFF_LEVEL 22
88#define SHIFT_RXFF_LEVEL 19 89#define SHIFT_RXFF_LEVEL 19
@@ -230,6 +231,7 @@ struct mx2_prp_cfg {
230 u32 src_pixel; 231 u32 src_pixel;
231 u32 ch1_pixel; 232 u32 ch1_pixel;
232 u32 irq_flags; 233 u32 irq_flags;
234 u32 csicr1;
233}; 235};
234 236
235/* prp resizing parameters */ 237/* prp resizing parameters */
@@ -330,6 +332,7 @@ static struct mx2_fmt_cfg mx27_emma_prp_table[] = {
330 .ch1_pixel = 0x2ca00565, /* RGB565 */ 332 .ch1_pixel = 0x2ca00565, /* RGB565 */
331 .irq_flags = PRP_INTR_RDERR | PRP_INTR_CH1WERR | 333 .irq_flags = PRP_INTR_RDERR | PRP_INTR_CH1WERR |
332 PRP_INTR_CH1FC | PRP_INTR_LBOVF, 334 PRP_INTR_CH1FC | PRP_INTR_LBOVF,
335 .csicr1 = 0,
333 } 336 }
334 }, 337 },
335 { 338 {
@@ -343,6 +346,21 @@ static struct mx2_fmt_cfg mx27_emma_prp_table[] = {
343 .irq_flags = PRP_INTR_RDERR | PRP_INTR_CH2WERR | 346 .irq_flags = PRP_INTR_RDERR | PRP_INTR_CH2WERR |
344 PRP_INTR_CH2FC | PRP_INTR_LBOVF | 347 PRP_INTR_CH2FC | PRP_INTR_LBOVF |
345 PRP_INTR_CH2OVF, 348 PRP_INTR_CH2OVF,
349 .csicr1 = CSICR1_PACK_DIR,
350 }
351 },
352 {
353 .in_fmt = V4L2_MBUS_FMT_UYVY8_2X8,
354 .out_fmt = V4L2_PIX_FMT_YUV420,
355 .cfg = {
356 .channel = 2,
357 .in_fmt = PRP_CNTL_DATA_IN_YUV422,
358 .out_fmt = PRP_CNTL_CH2_OUT_YUV420,
359 .src_pixel = 0x22000888, /* YUV422 (YUYV) */
360 .irq_flags = PRP_INTR_RDERR | PRP_INTR_CH2WERR |
361 PRP_INTR_CH2FC | PRP_INTR_LBOVF |
362 PRP_INTR_CH2OVF,
363 .csicr1 = CSICR1_SWAP16_EN,
346 } 364 }
347 }, 365 },
348}; 366};
@@ -1015,14 +1033,14 @@ static int mx2_camera_set_bus_param(struct soc_camera_device *icd)
1015 return ret; 1033 return ret;
1016 } 1034 }
1017 1035
1036 csicr1 = (csicr1 & ~CSICR1_FMT_MASK) | pcdev->emma_prp->cfg.csicr1;
1037
1018 if (common_flags & V4L2_MBUS_PCLK_SAMPLE_RISING) 1038 if (common_flags & V4L2_MBUS_PCLK_SAMPLE_RISING)
1019 csicr1 |= CSICR1_REDGE; 1039 csicr1 |= CSICR1_REDGE;
1020 if (common_flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH) 1040 if (common_flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH)
1021 csicr1 |= CSICR1_SOF_POL; 1041 csicr1 |= CSICR1_SOF_POL;
1022 if (common_flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH) 1042 if (common_flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH)
1023 csicr1 |= CSICR1_HSYNC_POL; 1043 csicr1 |= CSICR1_HSYNC_POL;
1024 if (pcdev->platform_flags & MX2_CAMERA_SWAP16)
1025 csicr1 |= CSICR1_SWAP16_EN;
1026 if (pcdev->platform_flags & MX2_CAMERA_EXT_VSYNC) 1044 if (pcdev->platform_flags & MX2_CAMERA_EXT_VSYNC)
1027 csicr1 |= CSICR1_EXT_VSYNC; 1045 csicr1 |= CSICR1_EXT_VSYNC;
1028 if (pcdev->platform_flags & MX2_CAMERA_CCIR) 1046 if (pcdev->platform_flags & MX2_CAMERA_CCIR)
@@ -1033,8 +1051,6 @@ static int mx2_camera_set_bus_param(struct soc_camera_device *icd)
1033 csicr1 |= CSICR1_GCLK_MODE; 1051 csicr1 |= CSICR1_GCLK_MODE;
1034 if (pcdev->platform_flags & MX2_CAMERA_INV_DATA) 1052 if (pcdev->platform_flags & MX2_CAMERA_INV_DATA)
1035 csicr1 |= CSICR1_INV_DATA; 1053 csicr1 |= CSICR1_INV_DATA;
1036 if (pcdev->platform_flags & MX2_CAMERA_PACK_DIR_MSB)
1037 csicr1 |= CSICR1_PACK_DIR;
1038 1054
1039 pcdev->csicr1 = csicr1; 1055 pcdev->csicr1 = csicr1;
1040 1056
@@ -1109,7 +1125,8 @@ static int mx2_camera_get_formats(struct soc_camera_device *icd,
1109 return 0; 1125 return 0;
1110 } 1126 }
1111 1127
1112 if (code == V4L2_MBUS_FMT_YUYV8_2X8) { 1128 if (code == V4L2_MBUS_FMT_YUYV8_2X8 ||
1129 code == V4L2_MBUS_FMT_UYVY8_2X8) {
1113 formats++; 1130 formats++;
1114 if (xlate) { 1131 if (xlate) {
1115 /* 1132 /*
diff --git a/drivers/media/video/omap3isp/isppreview.c b/drivers/media/video/omap3isp/isppreview.c
index 8a4935ecc655..dd91da26f1b0 100644
--- a/drivers/media/video/omap3isp/isppreview.c
+++ b/drivers/media/video/omap3isp/isppreview.c
@@ -888,12 +888,12 @@ static const struct preview_update update_attrs[] = {
888 preview_config_contrast, 888 preview_config_contrast,
889 NULL, 889 NULL,
890 offsetof(struct prev_params, contrast), 890 offsetof(struct prev_params, contrast),
891 0, true, 891 0, 0, true,
892 }, /* OMAP3ISP_PREV_BRIGHTNESS */ { 892 }, /* OMAP3ISP_PREV_BRIGHTNESS */ {
893 preview_config_brightness, 893 preview_config_brightness,
894 NULL, 894 NULL,
895 offsetof(struct prev_params, brightness), 895 offsetof(struct prev_params, brightness),
896 0, true, 896 0, 0, true,
897 }, 897 },
898}; 898};
899 899
@@ -1102,7 +1102,7 @@ static void preview_config_input_size(struct isp_prev_device *prev, u32 active)
1102 unsigned int elv = prev->crop.top + prev->crop.height - 1; 1102 unsigned int elv = prev->crop.top + prev->crop.height - 1;
1103 u32 features; 1103 u32 features;
1104 1104
1105 if (format->code == V4L2_MBUS_FMT_Y10_1X10) { 1105 if (format->code != V4L2_MBUS_FMT_Y10_1X10) {
1106 sph -= 2; 1106 sph -= 2;
1107 eph += 2; 1107 eph += 2;
1108 slv -= 2; 1108 slv -= 2;
diff --git a/drivers/media/video/pms.c b/drivers/media/video/pms.c
index c370c2d87c17..b4c679b3fb0f 100644
--- a/drivers/media/video/pms.c
+++ b/drivers/media/video/pms.c
@@ -26,6 +26,7 @@
26#include <linux/fs.h> 26#include <linux/fs.h>
27#include <linux/kernel.h> 27#include <linux/kernel.h>
28#include <linux/mm.h> 28#include <linux/mm.h>
29#include <linux/slab.h>
29#include <linux/ioport.h> 30#include <linux/ioport.h>
30#include <linux/init.h> 31#include <linux/init.h>
31#include <linux/mutex.h> 32#include <linux/mutex.h>
diff --git a/drivers/media/video/s5p-fimc/fimc-capture.c b/drivers/media/video/s5p-fimc/fimc-capture.c
index 354574591908..725812aa0c30 100644
--- a/drivers/media/video/s5p-fimc/fimc-capture.c
+++ b/drivers/media/video/s5p-fimc/fimc-capture.c
@@ -350,7 +350,8 @@ static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *pfmt,
350 if (pixm) 350 if (pixm)
351 sizes[i] = max(size, pixm->plane_fmt[i].sizeimage); 351 sizes[i] = max(size, pixm->plane_fmt[i].sizeimage);
352 else 352 else
353 sizes[i] = size; 353 sizes[i] = max_t(u32, size, frame->payload[i]);
354
354 allocators[i] = ctx->fimc_dev->alloc_ctx; 355 allocators[i] = ctx->fimc_dev->alloc_ctx;
355 } 356 }
356 357
@@ -479,37 +480,39 @@ static int fimc_capture_set_default_format(struct fimc_dev *fimc);
479static int fimc_capture_open(struct file *file) 480static int fimc_capture_open(struct file *file)
480{ 481{
481 struct fimc_dev *fimc = video_drvdata(file); 482 struct fimc_dev *fimc = video_drvdata(file);
482 int ret = v4l2_fh_open(file); 483 int ret;
483
484 if (ret)
485 return ret;
486 484
487 dbg("pid: %d, state: 0x%lx", task_pid_nr(current), fimc->state); 485 dbg("pid: %d, state: 0x%lx", task_pid_nr(current), fimc->state);
488 486
489 /* Return if the corresponding video mem2mem node is already opened. */
490 if (fimc_m2m_active(fimc)) 487 if (fimc_m2m_active(fimc))
491 return -EBUSY; 488 return -EBUSY;
492 489
493 set_bit(ST_CAPT_BUSY, &fimc->state); 490 set_bit(ST_CAPT_BUSY, &fimc->state);
494 pm_runtime_get_sync(&fimc->pdev->dev); 491 ret = pm_runtime_get_sync(&fimc->pdev->dev);
492 if (ret < 0)
493 return ret;
495 494
496 if (++fimc->vid_cap.refcnt == 1) { 495 ret = v4l2_fh_open(file);
497 ret = fimc_pipeline_initialize(&fimc->pipeline, 496 if (ret)
498 &fimc->vid_cap.vfd->entity, true); 497 return ret;
499 if (ret < 0) {
500 dev_err(&fimc->pdev->dev,
501 "Video pipeline initialization failed\n");
502 pm_runtime_put_sync(&fimc->pdev->dev);
503 fimc->vid_cap.refcnt--;
504 v4l2_fh_release(file);
505 clear_bit(ST_CAPT_BUSY, &fimc->state);
506 return ret;
507 }
508 ret = fimc_capture_ctrls_create(fimc);
509 498
510 if (!ret && !fimc->vid_cap.user_subdev_api) 499 if (++fimc->vid_cap.refcnt != 1)
511 ret = fimc_capture_set_default_format(fimc); 500 return 0;
501
502 ret = fimc_pipeline_initialize(&fimc->pipeline,
503 &fimc->vid_cap.vfd->entity, true);
504 if (ret < 0) {
505 clear_bit(ST_CAPT_BUSY, &fimc->state);
506 pm_runtime_put_sync(&fimc->pdev->dev);
507 fimc->vid_cap.refcnt--;
508 v4l2_fh_release(file);
509 return ret;
512 } 510 }
511 ret = fimc_capture_ctrls_create(fimc);
512
513 if (!ret && !fimc->vid_cap.user_subdev_api)
514 ret = fimc_capture_set_default_format(fimc);
515
513 return ret; 516 return ret;
514} 517}
515 518
@@ -818,9 +821,6 @@ static int fimc_cap_g_fmt_mplane(struct file *file, void *fh,
818 struct fimc_dev *fimc = video_drvdata(file); 821 struct fimc_dev *fimc = video_drvdata(file);
819 struct fimc_ctx *ctx = fimc->vid_cap.ctx; 822 struct fimc_ctx *ctx = fimc->vid_cap.ctx;
820 823
821 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
822 return -EINVAL;
823
824 return fimc_fill_format(&ctx->d_frame, f); 824 return fimc_fill_format(&ctx->d_frame, f);
825} 825}
826 826
@@ -833,9 +833,6 @@ static int fimc_cap_try_fmt_mplane(struct file *file, void *fh,
833 struct v4l2_mbus_framefmt mf; 833 struct v4l2_mbus_framefmt mf;
834 struct fimc_fmt *ffmt = NULL; 834 struct fimc_fmt *ffmt = NULL;
835 835
836 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
837 return -EINVAL;
838
839 if (pix->pixelformat == V4L2_PIX_FMT_JPEG) { 836 if (pix->pixelformat == V4L2_PIX_FMT_JPEG) {
840 fimc_capture_try_format(ctx, &pix->width, &pix->height, 837 fimc_capture_try_format(ctx, &pix->width, &pix->height,
841 NULL, &pix->pixelformat, 838 NULL, &pix->pixelformat,
@@ -887,8 +884,6 @@ static int fimc_capture_set_format(struct fimc_dev *fimc, struct v4l2_format *f)
887 struct fimc_fmt *s_fmt = NULL; 884 struct fimc_fmt *s_fmt = NULL;
888 int ret, i; 885 int ret, i;
889 886
890 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
891 return -EINVAL;
892 if (vb2_is_busy(&fimc->vid_cap.vbq)) 887 if (vb2_is_busy(&fimc->vid_cap.vbq))
893 return -EBUSY; 888 return -EBUSY;
894 889
@@ -924,10 +919,10 @@ static int fimc_capture_set_format(struct fimc_dev *fimc, struct v4l2_format *f)
924 pix->width = mf->width; 919 pix->width = mf->width;
925 pix->height = mf->height; 920 pix->height = mf->height;
926 } 921 }
922
927 fimc_adjust_mplane_format(ff->fmt, pix->width, pix->height, pix); 923 fimc_adjust_mplane_format(ff->fmt, pix->width, pix->height, pix);
928 for (i = 0; i < ff->fmt->colplanes; i++) 924 for (i = 0; i < ff->fmt->colplanes; i++)
929 ff->payload[i] = 925 ff->payload[i] = pix->plane_fmt[i].sizeimage;
930 (pix->width * pix->height * ff->fmt->depth[i]) / 8;
931 926
932 set_frame_bounds(ff, pix->width, pix->height); 927 set_frame_bounds(ff, pix->width, pix->height);
933 /* Reset the composition rectangle if not yet configured */ 928 /* Reset the composition rectangle if not yet configured */
@@ -1045,18 +1040,22 @@ static int fimc_cap_streamon(struct file *file, void *priv,
1045{ 1040{
1046 struct fimc_dev *fimc = video_drvdata(file); 1041 struct fimc_dev *fimc = video_drvdata(file);
1047 struct fimc_pipeline *p = &fimc->pipeline; 1042 struct fimc_pipeline *p = &fimc->pipeline;
1043 struct v4l2_subdev *sd = p->subdevs[IDX_SENSOR];
1048 int ret; 1044 int ret;
1049 1045
1050 if (fimc_capture_active(fimc)) 1046 if (fimc_capture_active(fimc))
1051 return -EBUSY; 1047 return -EBUSY;
1052 1048
1053 media_entity_pipeline_start(&p->subdevs[IDX_SENSOR]->entity, 1049 ret = media_entity_pipeline_start(&sd->entity, p->m_pipeline);
1054 p->m_pipeline); 1050 if (ret < 0)
1051 return ret;
1055 1052
1056 if (fimc->vid_cap.user_subdev_api) { 1053 if (fimc->vid_cap.user_subdev_api) {
1057 ret = fimc_pipeline_validate(fimc); 1054 ret = fimc_pipeline_validate(fimc);
1058 if (ret) 1055 if (ret < 0) {
1056 media_entity_pipeline_stop(&sd->entity);
1059 return ret; 1057 return ret;
1058 }
1060 } 1059 }
1061 return vb2_streamon(&fimc->vid_cap.vbq, type); 1060 return vb2_streamon(&fimc->vid_cap.vbq, type);
1062} 1061}
diff --git a/drivers/media/video/s5p-fimc/fimc-core.c b/drivers/media/video/s5p-fimc/fimc-core.c
index 92fc5a20fb76..a4646ca1d56f 100644
--- a/drivers/media/video/s5p-fimc/fimc-core.c
+++ b/drivers/media/video/s5p-fimc/fimc-core.c
@@ -153,7 +153,7 @@ static struct fimc_fmt fimc_formats[] = {
153 .colplanes = 2, 153 .colplanes = 2,
154 .flags = FMT_FLAGS_M2M, 154 .flags = FMT_FLAGS_M2M,
155 }, { 155 }, {
156 .name = "YUV 4:2:0 non-contiguous 2-planar, Y/CbCr", 156 .name = "YUV 4:2:0 non-contig. 2p, Y/CbCr",
157 .fourcc = V4L2_PIX_FMT_NV12M, 157 .fourcc = V4L2_PIX_FMT_NV12M,
158 .color = FIMC_FMT_YCBCR420, 158 .color = FIMC_FMT_YCBCR420,
159 .depth = { 8, 4 }, 159 .depth = { 8, 4 },
@@ -161,7 +161,7 @@ static struct fimc_fmt fimc_formats[] = {
161 .colplanes = 2, 161 .colplanes = 2,
162 .flags = FMT_FLAGS_M2M, 162 .flags = FMT_FLAGS_M2M,
163 }, { 163 }, {
164 .name = "YUV 4:2:0 non-contiguous 3-planar, Y/Cb/Cr", 164 .name = "YUV 4:2:0 non-contig. 3p, Y/Cb/Cr",
165 .fourcc = V4L2_PIX_FMT_YUV420M, 165 .fourcc = V4L2_PIX_FMT_YUV420M,
166 .color = FIMC_FMT_YCBCR420, 166 .color = FIMC_FMT_YCBCR420,
167 .depth = { 8, 2, 2 }, 167 .depth = { 8, 2, 2 },
@@ -169,7 +169,7 @@ static struct fimc_fmt fimc_formats[] = {
169 .colplanes = 3, 169 .colplanes = 3,
170 .flags = FMT_FLAGS_M2M, 170 .flags = FMT_FLAGS_M2M,
171 }, { 171 }, {
172 .name = "YUV 4:2:0 non-contiguous 2-planar, Y/CbCr, tiled", 172 .name = "YUV 4:2:0 non-contig. 2p, tiled",
173 .fourcc = V4L2_PIX_FMT_NV12MT, 173 .fourcc = V4L2_PIX_FMT_NV12MT,
174 .color = FIMC_FMT_YCBCR420, 174 .color = FIMC_FMT_YCBCR420,
175 .depth = { 8, 4 }, 175 .depth = { 8, 4 },
@@ -641,7 +641,7 @@ void fimc_ctrls_activate(struct fimc_ctx *ctx, bool active)
641 if (!ctrls->ready) 641 if (!ctrls->ready)
642 return; 642 return;
643 643
644 mutex_lock(&ctrls->handler.lock); 644 mutex_lock(ctrls->handler.lock);
645 v4l2_ctrl_activate(ctrls->rotate, active); 645 v4l2_ctrl_activate(ctrls->rotate, active);
646 v4l2_ctrl_activate(ctrls->hflip, active); 646 v4l2_ctrl_activate(ctrls->hflip, active);
647 v4l2_ctrl_activate(ctrls->vflip, active); 647 v4l2_ctrl_activate(ctrls->vflip, active);
@@ -660,7 +660,7 @@ void fimc_ctrls_activate(struct fimc_ctx *ctx, bool active)
660 ctx->hflip = 0; 660 ctx->hflip = 0;
661 ctx->vflip = 0; 661 ctx->vflip = 0;
662 } 662 }
663 mutex_unlock(&ctrls->handler.lock); 663 mutex_unlock(ctrls->handler.lock);
664} 664}
665 665
666/* Update maximum value of the alpha color control */ 666/* Update maximum value of the alpha color control */
@@ -741,8 +741,8 @@ void fimc_adjust_mplane_format(struct fimc_fmt *fmt, u32 width, u32 height,
741 pix->width = width; 741 pix->width = width;
742 742
743 for (i = 0; i < pix->num_planes; ++i) { 743 for (i = 0; i < pix->num_planes; ++i) {
744 u32 bpl = pix->plane_fmt[i].bytesperline; 744 struct v4l2_plane_pix_format *plane_fmt = &pix->plane_fmt[i];
745 u32 *sizeimage = &pix->plane_fmt[i].sizeimage; 745 u32 bpl = plane_fmt->bytesperline;
746 746
747 if (fmt->colplanes > 1 && (bpl == 0 || bpl < pix->width)) 747 if (fmt->colplanes > 1 && (bpl == 0 || bpl < pix->width))
748 bpl = pix->width; /* Planar */ 748 bpl = pix->width; /* Planar */
@@ -754,8 +754,9 @@ void fimc_adjust_mplane_format(struct fimc_fmt *fmt, u32 width, u32 height,
754 if (i == 0) /* Same bytesperline for each plane. */ 754 if (i == 0) /* Same bytesperline for each plane. */
755 bytesperline = bpl; 755 bytesperline = bpl;
756 756
757 pix->plane_fmt[i].bytesperline = bytesperline; 757 plane_fmt->bytesperline = bytesperline;
758 *sizeimage = (pix->width * pix->height * fmt->depth[i]) / 8; 758 plane_fmt->sizeimage = max((pix->width * pix->height *
759 fmt->depth[i]) / 8, plane_fmt->sizeimage);
759 } 760 }
760} 761}
761 762
diff --git a/drivers/media/video/s5p-fimc/fimc-lite.c b/drivers/media/video/s5p-fimc/fimc-lite.c
index 400d701aef04..74ff310db30c 100644
--- a/drivers/media/video/s5p-fimc/fimc-lite.c
+++ b/drivers/media/video/s5p-fimc/fimc-lite.c
@@ -451,34 +451,44 @@ static void fimc_lite_clear_event_counters(struct fimc_lite *fimc)
451static int fimc_lite_open(struct file *file) 451static int fimc_lite_open(struct file *file)
452{ 452{
453 struct fimc_lite *fimc = video_drvdata(file); 453 struct fimc_lite *fimc = video_drvdata(file);
454 int ret = v4l2_fh_open(file); 454 int ret;
455 455
456 if (ret) 456 if (mutex_lock_interruptible(&fimc->lock))
457 return ret; 457 return -ERESTARTSYS;
458 458
459 set_bit(ST_FLITE_IN_USE, &fimc->state); 459 set_bit(ST_FLITE_IN_USE, &fimc->state);
460 pm_runtime_get_sync(&fimc->pdev->dev); 460 ret = pm_runtime_get_sync(&fimc->pdev->dev);
461 if (ret < 0)
462 goto done;
461 463
462 if (++fimc->ref_count != 1 || fimc->out_path != FIMC_IO_DMA) 464 ret = v4l2_fh_open(file);
463 return ret; 465 if (ret < 0)
466 goto done;
464 467
465 ret = fimc_pipeline_initialize(&fimc->pipeline, &fimc->vfd->entity, 468 if (++fimc->ref_count == 1 && fimc->out_path == FIMC_IO_DMA) {
466 true); 469 ret = fimc_pipeline_initialize(&fimc->pipeline,
467 if (ret < 0) { 470 &fimc->vfd->entity, true);
468 v4l2_err(fimc->vfd, "Video pipeline initialization failed\n"); 471 if (ret < 0) {
469 pm_runtime_put_sync(&fimc->pdev->dev); 472 pm_runtime_put_sync(&fimc->pdev->dev);
470 fimc->ref_count--; 473 fimc->ref_count--;
471 v4l2_fh_release(file); 474 v4l2_fh_release(file);
472 clear_bit(ST_FLITE_IN_USE, &fimc->state); 475 clear_bit(ST_FLITE_IN_USE, &fimc->state);
473 } 476 }
474 477
475 fimc_lite_clear_event_counters(fimc); 478 fimc_lite_clear_event_counters(fimc);
479 }
480done:
481 mutex_unlock(&fimc->lock);
476 return ret; 482 return ret;
477} 483}
478 484
479static int fimc_lite_close(struct file *file) 485static int fimc_lite_close(struct file *file)
480{ 486{
481 struct fimc_lite *fimc = video_drvdata(file); 487 struct fimc_lite *fimc = video_drvdata(file);
488 int ret;
489
490 if (mutex_lock_interruptible(&fimc->lock))
491 return -ERESTARTSYS;
482 492
483 if (--fimc->ref_count == 0 && fimc->out_path == FIMC_IO_DMA) { 493 if (--fimc->ref_count == 0 && fimc->out_path == FIMC_IO_DMA) {
484 clear_bit(ST_FLITE_IN_USE, &fimc->state); 494 clear_bit(ST_FLITE_IN_USE, &fimc->state);
@@ -492,20 +502,39 @@ static int fimc_lite_close(struct file *file)
492 if (fimc->ref_count == 0) 502 if (fimc->ref_count == 0)
493 vb2_queue_release(&fimc->vb_queue); 503 vb2_queue_release(&fimc->vb_queue);
494 504
495 return v4l2_fh_release(file); 505 ret = v4l2_fh_release(file);
506
507 mutex_unlock(&fimc->lock);
508 return ret;
496} 509}
497 510
498static unsigned int fimc_lite_poll(struct file *file, 511static unsigned int fimc_lite_poll(struct file *file,
499 struct poll_table_struct *wait) 512 struct poll_table_struct *wait)
500{ 513{
501 struct fimc_lite *fimc = video_drvdata(file); 514 struct fimc_lite *fimc = video_drvdata(file);
502 return vb2_poll(&fimc->vb_queue, file, wait); 515 int ret;
516
517 if (mutex_lock_interruptible(&fimc->lock))
518 return POLL_ERR;
519
520 ret = vb2_poll(&fimc->vb_queue, file, wait);
521 mutex_unlock(&fimc->lock);
522
523 return ret;
503} 524}
504 525
505static int fimc_lite_mmap(struct file *file, struct vm_area_struct *vma) 526static int fimc_lite_mmap(struct file *file, struct vm_area_struct *vma)
506{ 527{
507 struct fimc_lite *fimc = video_drvdata(file); 528 struct fimc_lite *fimc = video_drvdata(file);
508 return vb2_mmap(&fimc->vb_queue, vma); 529 int ret;
530
531 if (mutex_lock_interruptible(&fimc->lock))
532 return -ERESTARTSYS;
533
534 ret = vb2_mmap(&fimc->vb_queue, vma);
535 mutex_unlock(&fimc->lock);
536
537 return ret;
509} 538}
510 539
511static const struct v4l2_file_operations fimc_lite_fops = { 540static const struct v4l2_file_operations fimc_lite_fops = {
@@ -762,7 +791,9 @@ static int fimc_lite_streamon(struct file *file, void *priv,
762 if (fimc_lite_active(fimc)) 791 if (fimc_lite_active(fimc))
763 return -EBUSY; 792 return -EBUSY;
764 793
765 media_entity_pipeline_start(&sensor->entity, p->m_pipeline); 794 ret = media_entity_pipeline_start(&sensor->entity, p->m_pipeline);
795 if (ret < 0)
796 return ret;
766 797
767 ret = fimc_pipeline_validate(fimc); 798 ret = fimc_pipeline_validate(fimc);
768 if (ret) { 799 if (ret) {
@@ -1508,7 +1539,7 @@ static int fimc_lite_suspend(struct device *dev)
1508 return 0; 1539 return 0;
1509 1540
1510 ret = fimc_lite_stop_capture(fimc, suspend); 1541 ret = fimc_lite_stop_capture(fimc, suspend);
1511 if (ret) 1542 if (ret < 0 || !fimc_lite_active(fimc))
1512 return ret; 1543 return ret;
1513 1544
1514 return fimc_pipeline_shutdown(&fimc->pipeline); 1545 return fimc_pipeline_shutdown(&fimc->pipeline);
diff --git a/drivers/media/video/s5p-fimc/fimc-mdevice.c b/drivers/media/video/s5p-fimc/fimc-mdevice.c
index 6753c45631b8..52cef4865423 100644
--- a/drivers/media/video/s5p-fimc/fimc-mdevice.c
+++ b/drivers/media/video/s5p-fimc/fimc-mdevice.c
@@ -193,9 +193,13 @@ int __fimc_pipeline_shutdown(struct fimc_pipeline *p)
193 193
194int fimc_pipeline_shutdown(struct fimc_pipeline *p) 194int fimc_pipeline_shutdown(struct fimc_pipeline *p)
195{ 195{
196 struct media_entity *me = &p->subdevs[IDX_SENSOR]->entity; 196 struct media_entity *me;
197 int ret; 197 int ret;
198 198
199 if (!p || !p->subdevs[IDX_SENSOR])
200 return -EINVAL;
201
202 me = &p->subdevs[IDX_SENSOR]->entity;
199 mutex_lock(&me->parent->graph_mutex); 203 mutex_lock(&me->parent->graph_mutex);
200 ret = __fimc_pipeline_shutdown(p); 204 ret = __fimc_pipeline_shutdown(p);
201 mutex_unlock(&me->parent->graph_mutex); 205 mutex_unlock(&me->parent->graph_mutex);
@@ -498,12 +502,12 @@ static void fimc_md_unregister_entities(struct fimc_md *fmd)
498 * @source: the source entity to create links to all fimc entities from 502 * @source: the source entity to create links to all fimc entities from
499 * @sensor: sensor subdev linked to FIMC[fimc_id] entity, may be null 503 * @sensor: sensor subdev linked to FIMC[fimc_id] entity, may be null
500 * @pad: the source entity pad index 504 * @pad: the source entity pad index
501 * @fimc_id: index of the fimc device for which link should be enabled 505 * @link_mask: bitmask of the fimc devices for which link should be enabled
502 */ 506 */
503static int __fimc_md_create_fimc_sink_links(struct fimc_md *fmd, 507static int __fimc_md_create_fimc_sink_links(struct fimc_md *fmd,
504 struct media_entity *source, 508 struct media_entity *source,
505 struct v4l2_subdev *sensor, 509 struct v4l2_subdev *sensor,
506 int pad, int fimc_id) 510 int pad, int link_mask)
507{ 511{
508 struct fimc_sensor_info *s_info; 512 struct fimc_sensor_info *s_info;
509 struct media_entity *sink; 513 struct media_entity *sink;
@@ -520,7 +524,7 @@ static int __fimc_md_create_fimc_sink_links(struct fimc_md *fmd,
520 if (!fmd->fimc[i]->variant->has_cam_if) 524 if (!fmd->fimc[i]->variant->has_cam_if)
521 continue; 525 continue;
522 526
523 flags = (i == fimc_id) ? MEDIA_LNK_FL_ENABLED : 0; 527 flags = ((1 << i) & link_mask) ? MEDIA_LNK_FL_ENABLED : 0;
524 528
525 sink = &fmd->fimc[i]->vid_cap.subdev.entity; 529 sink = &fmd->fimc[i]->vid_cap.subdev.entity;
526 ret = media_entity_create_link(source, pad, sink, 530 ret = media_entity_create_link(source, pad, sink,
@@ -552,7 +556,10 @@ static int __fimc_md_create_fimc_sink_links(struct fimc_md *fmd,
552 if (!fmd->fimc_lite[i]) 556 if (!fmd->fimc_lite[i])
553 continue; 557 continue;
554 558
555 flags = (i == fimc_id) ? MEDIA_LNK_FL_ENABLED : 0; 559 if (link_mask & (1 << (i + FIMC_MAX_DEVS)))
560 flags = MEDIA_LNK_FL_ENABLED;
561 else
562 flags = 0;
556 563
557 sink = &fmd->fimc_lite[i]->subdev.entity; 564 sink = &fmd->fimc_lite[i]->subdev.entity;
558 ret = media_entity_create_link(source, pad, sink, 565 ret = media_entity_create_link(source, pad, sink,
@@ -614,9 +621,8 @@ static int fimc_md_create_links(struct fimc_md *fmd)
614 struct s5p_fimc_isp_info *pdata; 621 struct s5p_fimc_isp_info *pdata;
615 struct fimc_sensor_info *s_info; 622 struct fimc_sensor_info *s_info;
616 struct media_entity *source, *sink; 623 struct media_entity *source, *sink;
617 int i, pad, fimc_id = 0; 624 int i, pad, fimc_id = 0, ret = 0;
618 int ret = 0; 625 u32 flags, link_mask = 0;
619 u32 flags;
620 626
621 for (i = 0; i < fmd->num_sensors; i++) { 627 for (i = 0; i < fmd->num_sensors; i++) {
622 if (fmd->sensor[i].subdev == NULL) 628 if (fmd->sensor[i].subdev == NULL)
@@ -668,19 +674,20 @@ static int fimc_md_create_links(struct fimc_md *fmd)
668 if (source == NULL) 674 if (source == NULL)
669 continue; 675 continue;
670 676
677 link_mask = 1 << fimc_id++;
671 ret = __fimc_md_create_fimc_sink_links(fmd, source, sensor, 678 ret = __fimc_md_create_fimc_sink_links(fmd, source, sensor,
672 pad, fimc_id++); 679 pad, link_mask);
673 } 680 }
674 681
675 fimc_id = 0;
676 for (i = 0; i < ARRAY_SIZE(fmd->csis); i++) { 682 for (i = 0; i < ARRAY_SIZE(fmd->csis); i++) {
677 if (fmd->csis[i].sd == NULL) 683 if (fmd->csis[i].sd == NULL)
678 continue; 684 continue;
679 source = &fmd->csis[i].sd->entity; 685 source = &fmd->csis[i].sd->entity;
680 pad = CSIS_PAD_SOURCE; 686 pad = CSIS_PAD_SOURCE;
681 687
688 link_mask = 1 << fimc_id++;
682 ret = __fimc_md_create_fimc_sink_links(fmd, source, NULL, 689 ret = __fimc_md_create_fimc_sink_links(fmd, source, NULL,
683 pad, fimc_id++); 690 pad, link_mask);
684 } 691 }
685 692
686 /* Create immutable links between each FIMC's subdev and video node */ 693 /* Create immutable links between each FIMC's subdev and video node */
@@ -734,8 +741,8 @@ static void fimc_md_put_clocks(struct fimc_md *fmd)
734} 741}
735 742
736static int __fimc_md_set_camclk(struct fimc_md *fmd, 743static int __fimc_md_set_camclk(struct fimc_md *fmd,
737 struct fimc_sensor_info *s_info, 744 struct fimc_sensor_info *s_info,
738 bool on) 745 bool on)
739{ 746{
740 struct s5p_fimc_isp_info *pdata = s_info->pdata; 747 struct s5p_fimc_isp_info *pdata = s_info->pdata;
741 struct fimc_camclk_info *camclk; 748 struct fimc_camclk_info *camclk;
@@ -744,12 +751,10 @@ static int __fimc_md_set_camclk(struct fimc_md *fmd,
744 if (WARN_ON(pdata->clk_id >= FIMC_MAX_CAMCLKS) || fmd == NULL) 751 if (WARN_ON(pdata->clk_id >= FIMC_MAX_CAMCLKS) || fmd == NULL)
745 return -EINVAL; 752 return -EINVAL;
746 753
747 if (s_info->clk_on == on)
748 return 0;
749 camclk = &fmd->camclk[pdata->clk_id]; 754 camclk = &fmd->camclk[pdata->clk_id];
750 755
751 dbg("camclk %d, f: %lu, clk: %p, on: %d", 756 dbg("camclk %d, f: %lu, use_count: %d, on: %d",
752 pdata->clk_id, pdata->clk_frequency, camclk, on); 757 pdata->clk_id, pdata->clk_frequency, camclk->use_count, on);
753 758
754 if (on) { 759 if (on) {
755 if (camclk->use_count > 0 && 760 if (camclk->use_count > 0 &&
@@ -760,11 +765,9 @@ static int __fimc_md_set_camclk(struct fimc_md *fmd,
760 clk_set_rate(camclk->clock, pdata->clk_frequency); 765 clk_set_rate(camclk->clock, pdata->clk_frequency);
761 camclk->frequency = pdata->clk_frequency; 766 camclk->frequency = pdata->clk_frequency;
762 ret = clk_enable(camclk->clock); 767 ret = clk_enable(camclk->clock);
768 dbg("Enabled camclk %d: f: %lu", pdata->clk_id,
769 clk_get_rate(camclk->clock));
763 } 770 }
764 s_info->clk_on = 1;
765 dbg("Enabled camclk %d: f: %lu", pdata->clk_id,
766 clk_get_rate(camclk->clock));
767
768 return ret; 771 return ret;
769 } 772 }
770 773
@@ -773,7 +776,6 @@ static int __fimc_md_set_camclk(struct fimc_md *fmd,
773 776
774 if (--camclk->use_count == 0) { 777 if (--camclk->use_count == 0) {
775 clk_disable(camclk->clock); 778 clk_disable(camclk->clock);
776 s_info->clk_on = 0;
777 dbg("Disabled camclk %d", pdata->clk_id); 779 dbg("Disabled camclk %d", pdata->clk_id);
778 } 780 }
779 return ret; 781 return ret;
@@ -789,8 +791,6 @@ static int __fimc_md_set_camclk(struct fimc_md *fmd,
789 * devices to which sensors can be attached, either directly or through 791 * devices to which sensors can be attached, either directly or through
790 * the MIPI CSI receiver. The clock is allowed here to be used by 792 * the MIPI CSI receiver. The clock is allowed here to be used by
791 * multiple sensors concurrently if they use same frequency. 793 * multiple sensors concurrently if they use same frequency.
792 * The per sensor subdev clk_on attribute helps to synchronize accesses
793 * to the sclk_cam clocks from the video and media device nodes.
794 * This function should only be called when the graph mutex is held. 794 * This function should only be called when the graph mutex is held.
795 */ 795 */
796int fimc_md_set_camclk(struct v4l2_subdev *sd, bool on) 796int fimc_md_set_camclk(struct v4l2_subdev *sd, bool on)
diff --git a/drivers/media/video/s5p-fimc/fimc-mdevice.h b/drivers/media/video/s5p-fimc/fimc-mdevice.h
index 3b8a3492a176..1f5dbaff5442 100644
--- a/drivers/media/video/s5p-fimc/fimc-mdevice.h
+++ b/drivers/media/video/s5p-fimc/fimc-mdevice.h
@@ -47,7 +47,6 @@ struct fimc_camclk_info {
47 * @pdata: sensor's atrributes passed as media device's platform data 47 * @pdata: sensor's atrributes passed as media device's platform data
48 * @subdev: image sensor v4l2 subdev 48 * @subdev: image sensor v4l2 subdev
49 * @host: fimc device the sensor is currently linked to 49 * @host: fimc device the sensor is currently linked to
50 * @clk_on: sclk_cam clock's state associated with this subdev
51 * 50 *
52 * This data structure applies to image sensor and the writeback subdevs. 51 * This data structure applies to image sensor and the writeback subdevs.
53 */ 52 */
@@ -55,7 +54,6 @@ struct fimc_sensor_info {
55 struct s5p_fimc_isp_info *pdata; 54 struct s5p_fimc_isp_info *pdata;
56 struct v4l2_subdev *subdev; 55 struct v4l2_subdev *subdev;
57 struct fimc_dev *host; 56 struct fimc_dev *host;
58 bool clk_on;
59}; 57};
60 58
61/** 59/**
diff --git a/drivers/media/video/s5p-mfc/s5p_mfc_dec.c b/drivers/media/video/s5p-mfc/s5p_mfc_dec.c
index 4dd32fc8fd82..feea867f318c 100644
--- a/drivers/media/video/s5p-mfc/s5p_mfc_dec.c
+++ b/drivers/media/video/s5p-mfc/s5p_mfc_dec.c
@@ -996,6 +996,7 @@ int s5p_mfc_dec_ctrls_setup(struct s5p_mfc_ctx *ctx)
996 996
997 for (i = 0; i < NUM_CTRLS; i++) { 997 for (i = 0; i < NUM_CTRLS; i++) {
998 if (IS_MFC51_PRIV(controls[i].id)) { 998 if (IS_MFC51_PRIV(controls[i].id)) {
999 memset(&cfg, 0, sizeof(struct v4l2_ctrl_config));
999 cfg.ops = &s5p_mfc_dec_ctrl_ops; 1000 cfg.ops = &s5p_mfc_dec_ctrl_ops;
1000 cfg.id = controls[i].id; 1001 cfg.id = controls[i].id;
1001 cfg.min = controls[i].minimum; 1002 cfg.min = controls[i].minimum;
diff --git a/drivers/media/video/s5p-mfc/s5p_mfc_enc.c b/drivers/media/video/s5p-mfc/s5p_mfc_enc.c
index 03d83340e7fb..158b78989b89 100644
--- a/drivers/media/video/s5p-mfc/s5p_mfc_enc.c
+++ b/drivers/media/video/s5p-mfc/s5p_mfc_enc.c
@@ -1773,6 +1773,7 @@ int s5p_mfc_enc_ctrls_setup(struct s5p_mfc_ctx *ctx)
1773 } 1773 }
1774 for (i = 0; i < NUM_CTRLS; i++) { 1774 for (i = 0; i < NUM_CTRLS; i++) {
1775 if (IS_MFC51_PRIV(controls[i].id)) { 1775 if (IS_MFC51_PRIV(controls[i].id)) {
1776 memset(&cfg, 0, sizeof(struct v4l2_ctrl_config));
1776 cfg.ops = &s5p_mfc_enc_ctrl_ops; 1777 cfg.ops = &s5p_mfc_enc_ctrl_ops;
1777 cfg.id = controls[i].id; 1778 cfg.id = controls[i].id;
1778 cfg.min = controls[i].minimum; 1779 cfg.min = controls[i].minimum;
diff --git a/drivers/media/video/smiapp/smiapp-core.c b/drivers/media/video/smiapp/smiapp-core.c
index e8c93c89265a..9cf5bda35fbe 100644
--- a/drivers/media/video/smiapp/smiapp-core.c
+++ b/drivers/media/video/smiapp/smiapp-core.c
@@ -31,6 +31,7 @@
31#include <linux/device.h> 31#include <linux/device.h>
32#include <linux/gpio.h> 32#include <linux/gpio.h>
33#include <linux/module.h> 33#include <linux/module.h>
34#include <linux/slab.h>
34#include <linux/regulator/consumer.h> 35#include <linux/regulator/consumer.h>
35#include <linux/slab.h> 36#include <linux/slab.h>
36#include <linux/v4l2-mediabus.h> 37#include <linux/v4l2-mediabus.h>
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index e129c820df7d..92144ed1ad46 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -286,6 +286,7 @@ config TWL6040_CORE
286 depends on I2C=y && GENERIC_HARDIRQS 286 depends on I2C=y && GENERIC_HARDIRQS
287 select MFD_CORE 287 select MFD_CORE
288 select REGMAP_I2C 288 select REGMAP_I2C
289 select IRQ_DOMAIN
289 default n 290 default n
290 help 291 help
291 Say yes here if you want support for Texas Instruments TWL6040 audio 292 Say yes here if you want support for Texas Instruments TWL6040 audio
diff --git a/drivers/mfd/ab5500-core.h b/drivers/mfd/ab5500-core.h
deleted file mode 100644
index 63b30b17e4f3..000000000000
--- a/drivers/mfd/ab5500-core.h
+++ /dev/null
@@ -1,87 +0,0 @@
1/*
2 * Copyright (C) 2011 ST-Ericsson
3 * License terms: GNU General Public License (GPL) version 2
4 * Shared definitions and data structures for the AB5500 MFD driver
5 */
6
7/* Read/write operation values. */
8#define AB5500_PERM_RD (0x01)
9#define AB5500_PERM_WR (0x02)
10
11/* Read/write permissions. */
12#define AB5500_PERM_RO (AB5500_PERM_RD)
13#define AB5500_PERM_RW (AB5500_PERM_RD | AB5500_PERM_WR)
14
15#define AB5500_MASK_BASE (0x60)
16#define AB5500_MASK_END (0x79)
17#define AB5500_CHIP_ID (0x20)
18
19/**
20 * struct ab5500_reg_range
21 * @first: the first address of the range
22 * @last: the last address of the range
23 * @perm: access permissions for the range
24 */
25struct ab5500_reg_range {
26 u8 first;
27 u8 last;
28 u8 perm;
29};
30
31/**
32 * struct ab5500_i2c_ranges
33 * @count: the number of ranges in the list
34 * @range: the list of register ranges
35 */
36struct ab5500_i2c_ranges {
37 u8 nranges;
38 u8 bankid;
39 const struct ab5500_reg_range *range;
40};
41
42/**
43 * struct ab5500_i2c_banks
44 * @count: the number of ranges in the list
45 * @range: the list of register ranges
46 */
47struct ab5500_i2c_banks {
48 u8 nbanks;
49 const struct ab5500_i2c_ranges *bank;
50};
51
52/**
53 * struct ab5500_bank
54 * @slave_addr: I2C slave_addr found in AB5500 specification
55 * @name: Documentation name of the bank. For reference
56 */
57struct ab5500_bank {
58 u8 slave_addr;
59 const char *name;
60};
61
62static const struct ab5500_bank bankinfo[AB5500_NUM_BANKS] = {
63 [AB5500_BANK_VIT_IO_I2C_CLK_TST_OTP] = {
64 AB5500_ADDR_VIT_IO_I2C_CLK_TST_OTP, "VIT_IO_I2C_CLK_TST_OTP"},
65 [AB5500_BANK_VDDDIG_IO_I2C_CLK_TST] = {
66 AB5500_ADDR_VDDDIG_IO_I2C_CLK_TST, "VDDDIG_IO_I2C_CLK_TST"},
67 [AB5500_BANK_VDENC] = {AB5500_ADDR_VDENC, "VDENC"},
68 [AB5500_BANK_SIM_USBSIM] = {AB5500_ADDR_SIM_USBSIM, "SIM_USBSIM"},
69 [AB5500_BANK_LED] = {AB5500_ADDR_LED, "LED"},
70 [AB5500_BANK_ADC] = {AB5500_ADDR_ADC, "ADC"},
71 [AB5500_BANK_RTC] = {AB5500_ADDR_RTC, "RTC"},
72 [AB5500_BANK_STARTUP] = {AB5500_ADDR_STARTUP, "STARTUP"},
73 [AB5500_BANK_DBI_ECI] = {AB5500_ADDR_DBI_ECI, "DBI-ECI"},
74 [AB5500_BANK_CHG] = {AB5500_ADDR_CHG, "CHG"},
75 [AB5500_BANK_FG_BATTCOM_ACC] = {
76 AB5500_ADDR_FG_BATTCOM_ACC, "FG_BATCOM_ACC"},
77 [AB5500_BANK_USB] = {AB5500_ADDR_USB, "USB"},
78 [AB5500_BANK_IT] = {AB5500_ADDR_IT, "IT"},
79 [AB5500_BANK_VIBRA] = {AB5500_ADDR_VIBRA, "VIBRA"},
80 [AB5500_BANK_AUDIO_HEADSETUSB] = {
81 AB5500_ADDR_AUDIO_HEADSETUSB, "AUDIO_HEADSETUSB"},
82};
83
84int ab5500_get_register_interruptible_raw(struct ab5500 *ab, u8 bank, u8 reg,
85 u8 *value);
86int ab5500_mask_and_set_register_interruptible_raw(struct ab5500 *ab, u8 bank,
87 u8 reg, u8 bitmask, u8 bitvalues);
diff --git a/drivers/mfd/mc13xxx-spi.c b/drivers/mfd/mc13xxx-spi.c
index 3fcdab3eb8eb..03df422feb76 100644
--- a/drivers/mfd/mc13xxx-spi.c
+++ b/drivers/mfd/mc13xxx-spi.c
@@ -49,10 +49,72 @@ static struct regmap_config mc13xxx_regmap_spi_config = {
49 .reg_bits = 7, 49 .reg_bits = 7,
50 .pad_bits = 1, 50 .pad_bits = 1,
51 .val_bits = 24, 51 .val_bits = 24,
52 .write_flag_mask = 0x80,
52 53
53 .max_register = MC13XXX_NUMREGS, 54 .max_register = MC13XXX_NUMREGS,
54 55
55 .cache_type = REGCACHE_NONE, 56 .cache_type = REGCACHE_NONE,
57 .use_single_rw = 1,
58};
59
60static int mc13xxx_spi_read(void *context, const void *reg, size_t reg_size,
61 void *val, size_t val_size)
62{
63 unsigned char w[4] = { *((unsigned char *) reg), 0, 0, 0};
64 unsigned char r[4];
65 unsigned char *p = val;
66 struct device *dev = context;
67 struct spi_device *spi = to_spi_device(dev);
68 struct spi_transfer t = {
69 .tx_buf = w,
70 .rx_buf = r,
71 .len = 4,
72 };
73
74 struct spi_message m;
75 int ret;
76
77 if (val_size != 3 || reg_size != 1)
78 return -ENOTSUPP;
79
80 spi_message_init(&m);
81 spi_message_add_tail(&t, &m);
82 ret = spi_sync(spi, &m);
83
84 memcpy(p, &r[1], 3);
85
86 return ret;
87}
88
89static int mc13xxx_spi_write(void *context, const void *data, size_t count)
90{
91 struct device *dev = context;
92 struct spi_device *spi = to_spi_device(dev);
93
94 if (count != 4)
95 return -ENOTSUPP;
96
97 return spi_write(spi, data, count);
98}
99
100/*
101 * We cannot use regmap-spi generic bus implementation here.
102 * The MC13783 chip will get corrupted if CS signal is deasserted
103 * and on i.Mx31 SoC (the target SoC for MC13783 PMIC) the SPI controller
104 * has the following errata (DSPhl22960):
105 * "The CSPI negates SS when the FIFO becomes empty with
106 * SSCTL= 0. Software cannot guarantee that the FIFO will not
107 * drain because of higher priority interrupts and the
108 * non-realtime characteristics of the operating system. As a
109 * result, the SS will negate before all of the data has been
110 * transferred to/from the peripheral."
111 * We workaround this by accessing the SPI controller with a
112 * single transfert.
113 */
114
115static struct regmap_bus regmap_mc13xxx_bus = {
116 .write = mc13xxx_spi_write,
117 .read = mc13xxx_spi_read,
56}; 118};
57 119
58static int mc13xxx_spi_probe(struct spi_device *spi) 120static int mc13xxx_spi_probe(struct spi_device *spi)
@@ -73,12 +135,13 @@ static int mc13xxx_spi_probe(struct spi_device *spi)
73 135
74 dev_set_drvdata(&spi->dev, mc13xxx); 136 dev_set_drvdata(&spi->dev, mc13xxx);
75 spi->mode = SPI_MODE_0 | SPI_CS_HIGH; 137 spi->mode = SPI_MODE_0 | SPI_CS_HIGH;
76 spi->bits_per_word = 32;
77 138
78 mc13xxx->dev = &spi->dev; 139 mc13xxx->dev = &spi->dev;
79 mutex_init(&mc13xxx->lock); 140 mutex_init(&mc13xxx->lock);
80 141
81 mc13xxx->regmap = regmap_init_spi(spi, &mc13xxx_regmap_spi_config); 142 mc13xxx->regmap = regmap_init(&spi->dev, &regmap_mc13xxx_bus, &spi->dev,
143 &mc13xxx_regmap_spi_config);
144
82 if (IS_ERR(mc13xxx->regmap)) { 145 if (IS_ERR(mc13xxx->regmap)) {
83 ret = PTR_ERR(mc13xxx->regmap); 146 ret = PTR_ERR(mc13xxx->regmap);
84 dev_err(mc13xxx->dev, "Failed to initialize register map: %d\n", 147 dev_err(mc13xxx->dev, "Failed to initialize register map: %d\n",
diff --git a/drivers/mfd/omap-usb-host.c b/drivers/mfd/omap-usb-host.c
index 7e96bb229724..41088ecbb2a9 100644
--- a/drivers/mfd/omap-usb-host.c
+++ b/drivers/mfd/omap-usb-host.c
@@ -25,6 +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/cpu.h>
29#include <plat/usb.h> 30#include <plat/usb.h>
30#include <linux/pm_runtime.h> 31#include <linux/pm_runtime.h>
@@ -500,8 +501,21 @@ static void omap_usbhs_init(struct device *dev)
500 dev_dbg(dev, "starting TI HSUSB Controller\n"); 501 dev_dbg(dev, "starting TI HSUSB Controller\n");
501 502
502 pm_runtime_get_sync(dev); 503 pm_runtime_get_sync(dev);
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 spin_lock_irqsave(&omap->lock, flags);
505 omap->usbhs_rev = usbhs_read(omap->uhh_base, OMAP_UHH_REVISION); 519 omap->usbhs_rev = usbhs_read(omap->uhh_base, OMAP_UHH_REVISION);
506 dev_dbg(dev, "OMAP UHH_REVISION 0x%x\n", omap->usbhs_rev); 520 dev_dbg(dev, "OMAP UHH_REVISION 0x%x\n", omap->usbhs_rev);
507 521
@@ -581,9 +595,39 @@ static void omap_usbhs_init(struct device *dev)
581 } 595 }
582 596
583 spin_unlock_irqrestore(&omap->lock, flags); 597 spin_unlock_irqrestore(&omap->lock, flags);
598
599 if (pdata->ehci_data->phy_reset) {
600 /* Hold the PHY in RESET for enough time till
601 * PHY is settled and ready
602 */
603 udelay(10);
604
605 if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[0]))
606 gpio_set_value_cansleep
607 (pdata->ehci_data->reset_gpio_port[0], 1);
608
609 if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[1]))
610 gpio_set_value_cansleep
611 (pdata->ehci_data->reset_gpio_port[1], 1);
612 }
613
584 pm_runtime_put_sync(dev); 614 pm_runtime_put_sync(dev);
585} 615}
586 616
617static void omap_usbhs_deinit(struct device *dev)
618{
619 struct usbhs_hcd_omap *omap = dev_get_drvdata(dev);
620 struct usbhs_omap_platform_data *pdata = &omap->platdata;
621
622 if (pdata->ehci_data->phy_reset) {
623 if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[0]))
624 gpio_free(pdata->ehci_data->reset_gpio_port[0]);
625
626 if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[1]))
627 gpio_free(pdata->ehci_data->reset_gpio_port[1]);
628 }
629}
630
587 631
588/** 632/**
589 * usbhs_omap_probe - initialize TI-based HCDs 633 * usbhs_omap_probe - initialize TI-based HCDs
@@ -767,6 +811,7 @@ static int __devinit usbhs_omap_probe(struct platform_device *pdev)
767 goto end_probe; 811 goto end_probe;
768 812
769err_alloc: 813err_alloc:
814 omap_usbhs_deinit(&pdev->dev);
770 iounmap(omap->tll_base); 815 iounmap(omap->tll_base);
771 816
772err_tll: 817err_tll:
@@ -818,6 +863,7 @@ static int __devexit usbhs_omap_remove(struct platform_device *pdev)
818{ 863{
819 struct usbhs_hcd_omap *omap = platform_get_drvdata(pdev); 864 struct usbhs_hcd_omap *omap = platform_get_drvdata(pdev);
820 865
866 omap_usbhs_deinit(&pdev->dev);
821 iounmap(omap->tll_base); 867 iounmap(omap->tll_base);
822 iounmap(omap->uhh_base); 868 iounmap(omap->uhh_base);
823 clk_put(omap->init_60m_fclk); 869 clk_put(omap->init_60m_fclk);
diff --git a/drivers/mfd/palmas.c b/drivers/mfd/palmas.c
index 00c0aba7eba0..c4a69f193a1d 100644
--- a/drivers/mfd/palmas.c
+++ b/drivers/mfd/palmas.c
@@ -356,7 +356,14 @@ static int __devinit palmas_i2c_probe(struct i2c_client *i2c,
356 } 356 }
357 } 357 }
358 358
359 ret = regmap_add_irq_chip(palmas->regmap[1], palmas->irq, 359 /* Change IRQ into clear on read mode for efficiency */
360 slave = PALMAS_BASE_TO_SLAVE(PALMAS_INTERRUPT_BASE);
361 addr = PALMAS_BASE_TO_REG(PALMAS_INTERRUPT_BASE, PALMAS_INT_CTRL);
362 reg = PALMAS_INT_CTRL_INT_CLEAR;
363
364 regmap_write(palmas->regmap[slave], addr, reg);
365
366 ret = regmap_add_irq_chip(palmas->regmap[slave], palmas->irq,
360 IRQF_ONESHOT | IRQF_TRIGGER_LOW, -1, &palmas_irq_chip, 367 IRQF_ONESHOT | IRQF_TRIGGER_LOW, -1, &palmas_irq_chip,
361 &palmas->irq_data); 368 &palmas->irq_data);
362 if (ret < 0) 369 if (ret < 0)
@@ -441,6 +448,9 @@ static int __devinit palmas_i2c_probe(struct i2c_client *i2c,
441 goto err; 448 goto err;
442 } 449 }
443 450
451 children[PALMAS_PMIC_ID].platform_data = pdata->pmic_pdata;
452 children[PALMAS_PMIC_ID].pdata_size = sizeof(*pdata->pmic_pdata);
453
444 ret = mfd_add_devices(palmas->dev, -1, 454 ret = mfd_add_devices(palmas->dev, -1,
445 children, ARRAY_SIZE(palmas_children), 455 children, ARRAY_SIZE(palmas_children),
446 NULL, regmap_irq_chip_get_base(palmas->irq_data)); 456 NULL, regmap_irq_chip_get_base(palmas->irq_data));
@@ -472,6 +482,7 @@ static const struct i2c_device_id palmas_i2c_id[] = {
472 { "twl6035", }, 482 { "twl6035", },
473 { "twl6037", }, 483 { "twl6037", },
474 { "tps65913", }, 484 { "tps65913", },
485 { /* end */ }
475}; 486};
476MODULE_DEVICE_TABLE(i2c, palmas_i2c_id); 487MODULE_DEVICE_TABLE(i2c, palmas_i2c_id);
477 488
diff --git a/drivers/mfd/tps65217.c b/drivers/mfd/tps65217.c
index db194e433c08..61c097a98f5d 100644
--- a/drivers/mfd/tps65217.c
+++ b/drivers/mfd/tps65217.c
@@ -24,6 +24,7 @@
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/regmap.h> 25#include <linux/regmap.h>
26#include <linux/err.h> 26#include <linux/err.h>
27#include <linux/regulator/of_regulator.h>
27 28
28#include <linux/mfd/core.h> 29#include <linux/mfd/core.h>
29#include <linux/mfd/tps65217.h> 30#include <linux/mfd/tps65217.h>
@@ -132,6 +133,61 @@ int tps65217_clear_bits(struct tps65217 *tps, unsigned int reg,
132} 133}
133EXPORT_SYMBOL_GPL(tps65217_clear_bits); 134EXPORT_SYMBOL_GPL(tps65217_clear_bits);
134 135
136#ifdef CONFIG_OF
137static struct of_regulator_match reg_matches[] = {
138 { .name = "dcdc1", .driver_data = (void *)TPS65217_DCDC_1 },
139 { .name = "dcdc2", .driver_data = (void *)TPS65217_DCDC_2 },
140 { .name = "dcdc3", .driver_data = (void *)TPS65217_DCDC_3 },
141 { .name = "ldo1", .driver_data = (void *)TPS65217_LDO_1 },
142 { .name = "ldo2", .driver_data = (void *)TPS65217_LDO_2 },
143 { .name = "ldo3", .driver_data = (void *)TPS65217_LDO_3 },
144 { .name = "ldo4", .driver_data = (void *)TPS65217_LDO_4 },
145};
146
147static struct tps65217_board *tps65217_parse_dt(struct i2c_client *client)
148{
149 struct device_node *node = client->dev.of_node;
150 struct tps65217_board *pdata;
151 struct device_node *regs;
152 int count = ARRAY_SIZE(reg_matches);
153 int ret, i;
154
155 regs = of_find_node_by_name(node, "regulators");
156 if (!regs)
157 return NULL;
158
159 ret = of_regulator_match(&client->dev, regs, reg_matches, count);
160 of_node_put(regs);
161 if ((ret < 0) || (ret > count))
162 return NULL;
163
164 count = ret;
165 pdata = devm_kzalloc(&client->dev, count * sizeof(*pdata), GFP_KERNEL);
166 if (!pdata)
167 return NULL;
168
169 for (i = 0; i < count; i++) {
170 if (!reg_matches[i].init_data || !reg_matches[i].of_node)
171 continue;
172
173 pdata->tps65217_init_data[i] = reg_matches[i].init_data;
174 pdata->of_node[i] = reg_matches[i].of_node;
175 }
176
177 return pdata;
178}
179
180static struct of_device_id tps65217_of_match[] = {
181 { .compatible = "ti,tps65217", },
182 { },
183};
184#else
185static struct tps65217_board *tps65217_parse_dt(struct i2c_client *client)
186{
187 return NULL;
188}
189#endif
190
135static struct regmap_config tps65217_regmap_config = { 191static struct regmap_config tps65217_regmap_config = {
136 .reg_bits = 8, 192 .reg_bits = 8,
137 .val_bits = 8, 193 .val_bits = 8,
@@ -141,10 +197,14 @@ static int __devinit tps65217_probe(struct i2c_client *client,
141 const struct i2c_device_id *ids) 197 const struct i2c_device_id *ids)
142{ 198{
143 struct tps65217 *tps; 199 struct tps65217 *tps;
200 struct regulator_init_data *reg_data;
144 struct tps65217_board *pdata = client->dev.platform_data; 201 struct tps65217_board *pdata = client->dev.platform_data;
145 int i, ret; 202 int i, ret;
146 unsigned int version; 203 unsigned int version;
147 204
205 if (!pdata && client->dev.of_node)
206 pdata = tps65217_parse_dt(client);
207
148 tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL); 208 tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL);
149 if (!tps) 209 if (!tps)
150 return -ENOMEM; 210 return -ENOMEM;
@@ -182,8 +242,9 @@ static int __devinit tps65217_probe(struct i2c_client *client,
182 } 242 }
183 243
184 pdev->dev.parent = tps->dev; 244 pdev->dev.parent = tps->dev;
185 platform_device_add_data(pdev, &pdata->tps65217_init_data[i], 245 pdev->dev.of_node = pdata->of_node[i];
186 sizeof(pdata->tps65217_init_data[i])); 246 reg_data = pdata->tps65217_init_data[i];
247 platform_device_add_data(pdev, reg_data, sizeof(*reg_data));
187 tps->regulator_pdev[i] = pdev; 248 tps->regulator_pdev[i] = pdev;
188 249
189 platform_device_add(pdev); 250 platform_device_add(pdev);
@@ -212,6 +273,8 @@ MODULE_DEVICE_TABLE(i2c, tps65217_id_table);
212static struct i2c_driver tps65217_driver = { 273static struct i2c_driver tps65217_driver = {
213 .driver = { 274 .driver = {
214 .name = "tps65217", 275 .name = "tps65217",
276 .owner = THIS_MODULE,
277 .of_match_table = of_match_ptr(tps65217_of_match),
215 }, 278 },
216 .id_table = tps65217_id_table, 279 .id_table = tps65217_id_table,
217 .probe = tps65217_probe, 280 .probe = tps65217_probe,
diff --git a/drivers/misc/mei/main.c b/drivers/misc/mei/main.c
index 7de13891e49e..783fcd7365bc 100644
--- a/drivers/misc/mei/main.c
+++ b/drivers/misc/mei/main.c
@@ -1147,7 +1147,7 @@ static int mei_pci_resume(struct device *device)
1147 err = request_threaded_irq(pdev->irq, 1147 err = request_threaded_irq(pdev->irq,
1148 NULL, 1148 NULL,
1149 mei_interrupt_thread_handler, 1149 mei_interrupt_thread_handler,
1150 0, mei_driver_name, dev); 1150 IRQF_ONESHOT, mei_driver_name, dev);
1151 else 1151 else
1152 err = request_threaded_irq(pdev->irq, 1152 err = request_threaded_irq(pdev->irq,
1153 mei_interrupt_quick_handler, 1153 mei_interrupt_quick_handler,
diff --git a/drivers/misc/sgi-xp/xpc_uv.c b/drivers/misc/sgi-xp/xpc_uv.c
index 17bbacb1b4b1..87b251ab6ec5 100644
--- a/drivers/misc/sgi-xp/xpc_uv.c
+++ b/drivers/misc/sgi-xp/xpc_uv.c
@@ -452,9 +452,9 @@ xpc_handle_activate_mq_msg_uv(struct xpc_partition *part,
452 452
453 if (msg->activate_gru_mq_desc_gpa != 453 if (msg->activate_gru_mq_desc_gpa !=
454 part_uv->activate_gru_mq_desc_gpa) { 454 part_uv->activate_gru_mq_desc_gpa) {
455 spin_lock_irqsave(&part_uv->flags_lock, irq_flags); 455 spin_lock(&part_uv->flags_lock);
456 part_uv->flags &= ~XPC_P_CACHED_ACTIVATE_GRU_MQ_DESC_UV; 456 part_uv->flags &= ~XPC_P_CACHED_ACTIVATE_GRU_MQ_DESC_UV;
457 spin_unlock_irqrestore(&part_uv->flags_lock, irq_flags); 457 spin_unlock(&part_uv->flags_lock);
458 part_uv->activate_gru_mq_desc_gpa = 458 part_uv->activate_gru_mq_desc_gpa =
459 msg->activate_gru_mq_desc_gpa; 459 msg->activate_gru_mq_desc_gpa;
460 } 460 }
diff --git a/drivers/mmc/core/cd-gpio.c b/drivers/mmc/core/cd-gpio.c
index f13e38deceac..8f5dc08d6598 100644
--- a/drivers/mmc/core/cd-gpio.c
+++ b/drivers/mmc/core/cd-gpio.c
@@ -50,8 +50,8 @@ int mmc_cd_gpio_request(struct mmc_host *host, unsigned int gpio)
50 goto egpioreq; 50 goto egpioreq;
51 51
52 ret = request_threaded_irq(irq, NULL, mmc_cd_gpio_irqt, 52 ret = request_threaded_irq(irq, NULL, mmc_cd_gpio_irqt,
53 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, 53 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING |
54 cd->label, host); 54 IRQF_ONESHOT, cd->label, host);
55 if (ret < 0) 55 if (ret < 0)
56 goto eirqreq; 56 goto eirqreq;
57 57
diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
index 258b203397aa..4f4489aa6bae 100644
--- a/drivers/mmc/core/mmc.c
+++ b/drivers/mmc/core/mmc.c
@@ -717,10 +717,6 @@ static int mmc_select_powerclass(struct mmc_card *card,
717 card->ext_csd.generic_cmd6_time); 717 card->ext_csd.generic_cmd6_time);
718 } 718 }
719 719
720 if (err)
721 pr_err("%s: power class selection for ext_csd_bus_width %d"
722 " failed\n", mmc_hostname(card->host), bus_width);
723
724 return err; 720 return err;
725} 721}
726 722
@@ -1104,7 +1100,9 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
1104 EXT_CSD_BUS_WIDTH_8 : EXT_CSD_BUS_WIDTH_4; 1100 EXT_CSD_BUS_WIDTH_8 : EXT_CSD_BUS_WIDTH_4;
1105 err = mmc_select_powerclass(card, ext_csd_bits, ext_csd); 1101 err = mmc_select_powerclass(card, ext_csd_bits, ext_csd);
1106 if (err) 1102 if (err)
1107 goto err; 1103 pr_warning("%s: power class selection to bus width %d"
1104 " failed\n", mmc_hostname(card->host),
1105 1 << bus_width);
1108 } 1106 }
1109 1107
1110 /* 1108 /*
@@ -1136,7 +1134,10 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
1136 err = mmc_select_powerclass(card, ext_csd_bits[idx][0], 1134 err = mmc_select_powerclass(card, ext_csd_bits[idx][0],
1137 ext_csd); 1135 ext_csd);
1138 if (err) 1136 if (err)
1139 goto err; 1137 pr_warning("%s: power class selection to "
1138 "bus width %d failed\n",
1139 mmc_hostname(card->host),
1140 1 << bus_width);
1140 1141
1141 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 1142 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
1142 EXT_CSD_BUS_WIDTH, 1143 EXT_CSD_BUS_WIDTH,
@@ -1164,7 +1165,10 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
1164 err = mmc_select_powerclass(card, ext_csd_bits[idx][1], 1165 err = mmc_select_powerclass(card, ext_csd_bits[idx][1],
1165 ext_csd); 1166 ext_csd);
1166 if (err) 1167 if (err)
1167 goto err; 1168 pr_warning("%s: power class selection to "
1169 "bus width %d ddr %d failed\n",
1170 mmc_hostname(card->host),
1171 1 << bus_width, ddr);
1168 1172
1169 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 1173 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
1170 EXT_CSD_BUS_WIDTH, 1174 EXT_CSD_BUS_WIDTH,
diff --git a/drivers/mtd/nand/cafe_nand.c b/drivers/mtd/nand/cafe_nand.c
index 41371ba1a811..f3f6cfedd69e 100644
--- a/drivers/mtd/nand/cafe_nand.c
+++ b/drivers/mtd/nand/cafe_nand.c
@@ -102,7 +102,7 @@ static const char *part_probes[] = { "cmdlinepart", "RedBoot", NULL };
102static int cafe_device_ready(struct mtd_info *mtd) 102static int cafe_device_ready(struct mtd_info *mtd)
103{ 103{
104 struct cafe_priv *cafe = mtd->priv; 104 struct cafe_priv *cafe = mtd->priv;
105 int result = !!(cafe_readl(cafe, NAND_STATUS) | 0x40000000); 105 int result = !!(cafe_readl(cafe, NAND_STATUS) & 0x40000000);
106 uint32_t irqs = cafe_readl(cafe, NAND_IRQ); 106 uint32_t irqs = cafe_readl(cafe, NAND_IRQ);
107 107
108 cafe_writel(cafe, irqs, NAND_IRQ); 108 cafe_writel(cafe, irqs, NAND_IRQ);
diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
index a05b7b444d4f..a6cad5caba78 100644
--- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
+++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
@@ -920,12 +920,12 @@ static int gpmi_ecc_read_page(struct mtd_info *mtd, struct nand_chip *chip,
920 */ 920 */
921 memset(chip->oob_poi, ~0, mtd->oobsize); 921 memset(chip->oob_poi, ~0, mtd->oobsize);
922 chip->oob_poi[0] = ((uint8_t *) auxiliary_virt)[0]; 922 chip->oob_poi[0] = ((uint8_t *) auxiliary_virt)[0];
923
924 read_page_swap_end(this, buf, mtd->writesize,
925 this->payload_virt, this->payload_phys,
926 nfc_geo->payload_size,
927 payload_virt, payload_phys);
928 } 923 }
924
925 read_page_swap_end(this, buf, mtd->writesize,
926 this->payload_virt, this->payload_phys,
927 nfc_geo->payload_size,
928 payload_virt, payload_phys);
929exit_nfc: 929exit_nfc:
930 return ret; 930 return ret;
931} 931}
diff --git a/drivers/mtd/nand/mxc_nand.c b/drivers/mtd/nand/mxc_nand.c
index c58e6a93f445..6acc790c2fbb 100644
--- a/drivers/mtd/nand/mxc_nand.c
+++ b/drivers/mtd/nand/mxc_nand.c
@@ -273,6 +273,26 @@ static struct nand_ecclayout nandv2_hw_eccoob_4k = {
273 273
274static const char *part_probes[] = { "RedBoot", "cmdlinepart", "ofpart", NULL }; 274static const char *part_probes[] = { "RedBoot", "cmdlinepart", "ofpart", NULL };
275 275
276static void memcpy32_fromio(void *trg, const void __iomem *src, size_t size)
277{
278 int i;
279 u32 *t = trg;
280 const __iomem u32 *s = src;
281
282 for (i = 0; i < (size >> 2); i++)
283 *t++ = __raw_readl(s++);
284}
285
286static void memcpy32_toio(void __iomem *trg, const void *src, int size)
287{
288 int i;
289 u32 __iomem *t = trg;
290 const u32 *s = src;
291
292 for (i = 0; i < (size >> 2); i++)
293 __raw_writel(*s++, t++);
294}
295
276static int check_int_v3(struct mxc_nand_host *host) 296static int check_int_v3(struct mxc_nand_host *host)
277{ 297{
278 uint32_t tmp; 298 uint32_t tmp;
@@ -519,7 +539,7 @@ static void send_read_id_v3(struct mxc_nand_host *host)
519 539
520 wait_op_done(host, true); 540 wait_op_done(host, true);
521 541
522 memcpy_fromio(host->data_buf, host->main_area0, 16); 542 memcpy32_fromio(host->data_buf, host->main_area0, 16);
523} 543}
524 544
525/* Request the NANDFC to perform a read of the NAND device ID. */ 545/* Request the NANDFC to perform a read of the NAND device ID. */
@@ -535,7 +555,7 @@ static void send_read_id_v1_v2(struct mxc_nand_host *host)
535 /* Wait for operation to complete */ 555 /* Wait for operation to complete */
536 wait_op_done(host, true); 556 wait_op_done(host, true);
537 557
538 memcpy_fromio(host->data_buf, host->main_area0, 16); 558 memcpy32_fromio(host->data_buf, host->main_area0, 16);
539 559
540 if (this->options & NAND_BUSWIDTH_16) { 560 if (this->options & NAND_BUSWIDTH_16) {
541 /* compress the ID info */ 561 /* compress the ID info */
@@ -797,16 +817,16 @@ static void copy_spare(struct mtd_info *mtd, bool bfrom)
797 817
798 if (bfrom) { 818 if (bfrom) {
799 for (i = 0; i < n - 1; i++) 819 for (i = 0; i < n - 1; i++)
800 memcpy_fromio(d + i * j, s + i * t, j); 820 memcpy32_fromio(d + i * j, s + i * t, j);
801 821
802 /* the last section */ 822 /* the last section */
803 memcpy_fromio(d + i * j, s + i * t, mtd->oobsize - i * j); 823 memcpy32_fromio(d + i * j, s + i * t, mtd->oobsize - i * j);
804 } else { 824 } else {
805 for (i = 0; i < n - 1; i++) 825 for (i = 0; i < n - 1; i++)
806 memcpy_toio(&s[i * t], &d[i * j], j); 826 memcpy32_toio(&s[i * t], &d[i * j], j);
807 827
808 /* the last section */ 828 /* the last section */
809 memcpy_toio(&s[i * t], &d[i * j], mtd->oobsize - i * j); 829 memcpy32_toio(&s[i * t], &d[i * j], mtd->oobsize - i * j);
810 } 830 }
811} 831}
812 832
@@ -1070,7 +1090,8 @@ static void mxc_nand_command(struct mtd_info *mtd, unsigned command,
1070 1090
1071 host->devtype_data->send_page(mtd, NFC_OUTPUT); 1091 host->devtype_data->send_page(mtd, NFC_OUTPUT);
1072 1092
1073 memcpy_fromio(host->data_buf, host->main_area0, mtd->writesize); 1093 memcpy32_fromio(host->data_buf, host->main_area0,
1094 mtd->writesize);
1074 copy_spare(mtd, true); 1095 copy_spare(mtd, true);
1075 break; 1096 break;
1076 1097
@@ -1086,7 +1107,7 @@ static void mxc_nand_command(struct mtd_info *mtd, unsigned command,
1086 break; 1107 break;
1087 1108
1088 case NAND_CMD_PAGEPROG: 1109 case NAND_CMD_PAGEPROG:
1089 memcpy_toio(host->main_area0, host->data_buf, mtd->writesize); 1110 memcpy32_toio(host->main_area0, host->data_buf, mtd->writesize);
1090 copy_spare(mtd, false); 1111 copy_spare(mtd, false);
1091 host->devtype_data->send_page(mtd, NFC_INPUT); 1112 host->devtype_data->send_page(mtd, NFC_INPUT);
1092 host->devtype_data->send_cmd(host, command, true); 1113 host->devtype_data->send_cmd(host, command, true);
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index d47586cf64ce..a11253a0fcab 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -3501,6 +3501,13 @@ int nand_scan_tail(struct mtd_info *mtd)
3501 /* propagate ecc info to mtd_info */ 3501 /* propagate ecc info to mtd_info */
3502 mtd->ecclayout = chip->ecc.layout; 3502 mtd->ecclayout = chip->ecc.layout;
3503 mtd->ecc_strength = chip->ecc.strength; 3503 mtd->ecc_strength = chip->ecc.strength;
3504 /*
3505 * Initialize bitflip_threshold to its default prior scan_bbt() call.
3506 * scan_bbt() might invoke mtd_read(), thus bitflip_threshold must be
3507 * properly set.
3508 */
3509 if (!mtd->bitflip_threshold)
3510 mtd->bitflip_threshold = mtd->ecc_strength;
3504 3511
3505 /* Check, if we should skip the bad block table scan */ 3512 /* Check, if we should skip the bad block table scan */
3506 if (chip->options & NAND_SKIP_BBTSCAN) 3513 if (chip->options & NAND_SKIP_BBTSCAN)
diff --git a/drivers/mtd/nand/nandsim.c b/drivers/mtd/nand/nandsim.c
index 6cc8fbfabb8e..cf0cd3146817 100644
--- a/drivers/mtd/nand/nandsim.c
+++ b/drivers/mtd/nand/nandsim.c
@@ -28,7 +28,7 @@
28#include <linux/module.h> 28#include <linux/module.h>
29#include <linux/moduleparam.h> 29#include <linux/moduleparam.h>
30#include <linux/vmalloc.h> 30#include <linux/vmalloc.h>
31#include <asm/div64.h> 31#include <linux/math64.h>
32#include <linux/slab.h> 32#include <linux/slab.h>
33#include <linux/errno.h> 33#include <linux/errno.h>
34#include <linux/string.h> 34#include <linux/string.h>
@@ -546,12 +546,6 @@ static char *get_partition_name(int i)
546 return kstrdup(buf, GFP_KERNEL); 546 return kstrdup(buf, GFP_KERNEL);
547} 547}
548 548
549static uint64_t divide(uint64_t n, uint32_t d)
550{
551 do_div(n, d);
552 return n;
553}
554
555/* 549/*
556 * Initialize the nandsim structure. 550 * Initialize the nandsim structure.
557 * 551 *
@@ -580,7 +574,7 @@ static int init_nandsim(struct mtd_info *mtd)
580 ns->geom.oobsz = mtd->oobsize; 574 ns->geom.oobsz = mtd->oobsize;
581 ns->geom.secsz = mtd->erasesize; 575 ns->geom.secsz = mtd->erasesize;
582 ns->geom.pgszoob = ns->geom.pgsz + ns->geom.oobsz; 576 ns->geom.pgszoob = ns->geom.pgsz + ns->geom.oobsz;
583 ns->geom.pgnum = divide(ns->geom.totsz, ns->geom.pgsz); 577 ns->geom.pgnum = div_u64(ns->geom.totsz, ns->geom.pgsz);
584 ns->geom.totszoob = ns->geom.totsz + (uint64_t)ns->geom.pgnum * ns->geom.oobsz; 578 ns->geom.totszoob = ns->geom.totsz + (uint64_t)ns->geom.pgnum * ns->geom.oobsz;
585 ns->geom.secshift = ffs(ns->geom.secsz) - 1; 579 ns->geom.secshift = ffs(ns->geom.secsz) - 1;
586 ns->geom.pgshift = chip->page_shift; 580 ns->geom.pgshift = chip->page_shift;
@@ -921,7 +915,7 @@ static int setup_wear_reporting(struct mtd_info *mtd)
921 915
922 if (!rptwear) 916 if (!rptwear)
923 return 0; 917 return 0;
924 wear_eb_count = divide(mtd->size, mtd->erasesize); 918 wear_eb_count = div_u64(mtd->size, mtd->erasesize);
925 mem = wear_eb_count * sizeof(unsigned long); 919 mem = wear_eb_count * sizeof(unsigned long);
926 if (mem / sizeof(unsigned long) != wear_eb_count) { 920 if (mem / sizeof(unsigned long) != wear_eb_count) {
927 NS_ERR("Too many erase blocks for wear reporting\n"); 921 NS_ERR("Too many erase blocks for wear reporting\n");
diff --git a/drivers/net/ethernet/freescale/gianfar.c b/drivers/net/ethernet/freescale/gianfar.c
index 0741aded9eb0..f2db8fca46a1 100644
--- a/drivers/net/ethernet/freescale/gianfar.c
+++ b/drivers/net/ethernet/freescale/gianfar.c
@@ -1804,18 +1804,16 @@ void gfar_configure_coalescing(struct gfar_private *priv,
1804 if (priv->mode == MQ_MG_MODE) { 1804 if (priv->mode == MQ_MG_MODE) {
1805 baddr = &regs->txic0; 1805 baddr = &regs->txic0;
1806 for_each_set_bit(i, &tx_mask, priv->num_tx_queues) { 1806 for_each_set_bit(i, &tx_mask, priv->num_tx_queues) {
1807 if (likely(priv->tx_queue[i]->txcoalescing)) { 1807 gfar_write(baddr + i, 0);
1808 gfar_write(baddr + i, 0); 1808 if (likely(priv->tx_queue[i]->txcoalescing))
1809 gfar_write(baddr + i, priv->tx_queue[i]->txic); 1809 gfar_write(baddr + i, priv->tx_queue[i]->txic);
1810 }
1811 } 1810 }
1812 1811
1813 baddr = &regs->rxic0; 1812 baddr = &regs->rxic0;
1814 for_each_set_bit(i, &rx_mask, priv->num_rx_queues) { 1813 for_each_set_bit(i, &rx_mask, priv->num_rx_queues) {
1815 if (likely(priv->rx_queue[i]->rxcoalescing)) { 1814 gfar_write(baddr + i, 0);
1816 gfar_write(baddr + i, 0); 1815 if (likely(priv->rx_queue[i]->rxcoalescing))
1817 gfar_write(baddr + i, priv->rx_queue[i]->rxic); 1816 gfar_write(baddr + i, priv->rx_queue[i]->rxic);
1818 }
1819 } 1817 }
1820 } 1818 }
1821} 1819}
diff --git a/drivers/net/ethernet/intel/e1000e/defines.h b/drivers/net/ethernet/intel/e1000e/defines.h
index 351a4097b2ba..76edbc1be33b 100644
--- a/drivers/net/ethernet/intel/e1000e/defines.h
+++ b/drivers/net/ethernet/intel/e1000e/defines.h
@@ -103,6 +103,7 @@
103#define E1000_RXD_ERR_SEQ 0x04 /* Sequence Error */ 103#define E1000_RXD_ERR_SEQ 0x04 /* Sequence Error */
104#define E1000_RXD_ERR_CXE 0x10 /* Carrier Extension Error */ 104#define E1000_RXD_ERR_CXE 0x10 /* Carrier Extension Error */
105#define E1000_RXD_ERR_TCPE 0x20 /* TCP/UDP Checksum Error */ 105#define E1000_RXD_ERR_TCPE 0x20 /* TCP/UDP Checksum Error */
106#define E1000_RXD_ERR_IPE 0x40 /* IP Checksum Error */
106#define E1000_RXD_ERR_RXE 0x80 /* Rx Data Error */ 107#define E1000_RXD_ERR_RXE 0x80 /* Rx Data Error */
107#define E1000_RXD_SPC_VLAN_MASK 0x0FFF /* VLAN ID is in lower 12 bits */ 108#define E1000_RXD_SPC_VLAN_MASK 0x0FFF /* VLAN ID is in lower 12 bits */
108 109
diff --git a/drivers/net/ethernet/intel/e1000e/netdev.c b/drivers/net/ethernet/intel/e1000e/netdev.c
index 31d37a2b5ba8..623e30b9964d 100644
--- a/drivers/net/ethernet/intel/e1000e/netdev.c
+++ b/drivers/net/ethernet/intel/e1000e/netdev.c
@@ -496,7 +496,7 @@ static void e1000_receive_skb(struct e1000_adapter *adapter,
496 * @sk_buff: socket buffer with received data 496 * @sk_buff: socket buffer with received data
497 **/ 497 **/
498static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err, 498static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
499 __le16 csum, struct sk_buff *skb) 499 struct sk_buff *skb)
500{ 500{
501 u16 status = (u16)status_err; 501 u16 status = (u16)status_err;
502 u8 errors = (u8)(status_err >> 24); 502 u8 errors = (u8)(status_err >> 24);
@@ -511,8 +511,8 @@ static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
511 if (status & E1000_RXD_STAT_IXSM) 511 if (status & E1000_RXD_STAT_IXSM)
512 return; 512 return;
513 513
514 /* TCP/UDP checksum error bit is set */ 514 /* TCP/UDP checksum error bit or IP checksum error bit is set */
515 if (errors & E1000_RXD_ERR_TCPE) { 515 if (errors & (E1000_RXD_ERR_TCPE | E1000_RXD_ERR_IPE)) {
516 /* let the stack verify checksum errors */ 516 /* let the stack verify checksum errors */
517 adapter->hw_csum_err++; 517 adapter->hw_csum_err++;
518 return; 518 return;
@@ -523,19 +523,7 @@ static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
523 return; 523 return;
524 524
525 /* It must be a TCP or UDP packet with a valid checksum */ 525 /* It must be a TCP or UDP packet with a valid checksum */
526 if (status & E1000_RXD_STAT_TCPCS) { 526 skb->ip_summed = CHECKSUM_UNNECESSARY;
527 /* TCP checksum is good */
528 skb->ip_summed = CHECKSUM_UNNECESSARY;
529 } else {
530 /*
531 * IP fragment with UDP payload
532 * Hardware complements the payload checksum, so we undo it
533 * and then put the value in host order for further stack use.
534 */
535 __sum16 sum = (__force __sum16)swab16((__force u16)csum);
536 skb->csum = csum_unfold(~sum);
537 skb->ip_summed = CHECKSUM_COMPLETE;
538 }
539 adapter->hw_csum_good++; 527 adapter->hw_csum_good++;
540} 528}
541 529
@@ -954,8 +942,7 @@ static bool e1000_clean_rx_irq(struct e1000_ring *rx_ring, int *work_done,
954 skb_put(skb, length); 942 skb_put(skb, length);
955 943
956 /* Receive Checksum Offload */ 944 /* Receive Checksum Offload */
957 e1000_rx_checksum(adapter, staterr, 945 e1000_rx_checksum(adapter, staterr, skb);
958 rx_desc->wb.lower.hi_dword.csum_ip.csum, skb);
959 946
960 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb); 947 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
961 948
@@ -1341,8 +1328,7 @@ copydone:
1341 total_rx_bytes += skb->len; 1328 total_rx_bytes += skb->len;
1342 total_rx_packets++; 1329 total_rx_packets++;
1343 1330
1344 e1000_rx_checksum(adapter, staterr, 1331 e1000_rx_checksum(adapter, staterr, skb);
1345 rx_desc->wb.lower.hi_dword.csum_ip.csum, skb);
1346 1332
1347 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb); 1333 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1348 1334
@@ -1512,9 +1498,8 @@ static bool e1000_clean_jumbo_rx_irq(struct e1000_ring *rx_ring, int *work_done,
1512 } 1498 }
1513 } 1499 }
1514 1500
1515 /* Receive Checksum Offload XXX recompute due to CRC strip? */ 1501 /* Receive Checksum Offload */
1516 e1000_rx_checksum(adapter, staterr, 1502 e1000_rx_checksum(adapter, staterr, skb);
1517 rx_desc->wb.lower.hi_dword.csum_ip.csum, skb);
1518 1503
1519 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb); 1504 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1520 1505
@@ -3098,19 +3083,10 @@ static void e1000_configure_rx(struct e1000_adapter *adapter)
3098 3083
3099 /* Enable Receive Checksum Offload for TCP and UDP */ 3084 /* Enable Receive Checksum Offload for TCP and UDP */
3100 rxcsum = er32(RXCSUM); 3085 rxcsum = er32(RXCSUM);
3101 if (adapter->netdev->features & NETIF_F_RXCSUM) { 3086 if (adapter->netdev->features & NETIF_F_RXCSUM)
3102 rxcsum |= E1000_RXCSUM_TUOFL; 3087 rxcsum |= E1000_RXCSUM_TUOFL;
3103 3088 else
3104 /*
3105 * IPv4 payload checksum for UDP fragments must be
3106 * used in conjunction with packet-split.
3107 */
3108 if (adapter->rx_ps_pages)
3109 rxcsum |= E1000_RXCSUM_IPPCSE;
3110 } else {
3111 rxcsum &= ~E1000_RXCSUM_TUOFL; 3089 rxcsum &= ~E1000_RXCSUM_TUOFL;
3112 /* no need to clear IPPCSE as it defaults to 0 */
3113 }
3114 ew32(RXCSUM, rxcsum); 3090 ew32(RXCSUM, rxcsum);
3115 3091
3116 if (adapter->hw.mac.type == e1000_pch2lan) { 3092 if (adapter->hw.mac.type == e1000_pch2lan) {
@@ -5241,22 +5217,10 @@ static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
5241 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; 5217 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5242 5218
5243 /* Jumbo frame support */ 5219 /* Jumbo frame support */
5244 if (max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) { 5220 if ((max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) &&
5245 if (!(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) { 5221 !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
5246 e_err("Jumbo Frames not supported.\n"); 5222 e_err("Jumbo Frames not supported.\n");
5247 return -EINVAL; 5223 return -EINVAL;
5248 }
5249
5250 /*
5251 * IP payload checksum (enabled with jumbos/packet-split when
5252 * Rx checksum is enabled) and generation of RSS hash is
5253 * mutually exclusive in the hardware.
5254 */
5255 if ((netdev->features & NETIF_F_RXCSUM) &&
5256 (netdev->features & NETIF_F_RXHASH)) {
5257 e_err("Jumbo frames cannot be enabled when both receive checksum offload and receive hashing are enabled. Disable one of the receive offload features before enabling jumbos.\n");
5258 return -EINVAL;
5259 }
5260 } 5224 }
5261 5225
5262 /* Supported frame sizes */ 5226 /* Supported frame sizes */
@@ -6030,17 +5994,6 @@ static int e1000_set_features(struct net_device *netdev,
6030 NETIF_F_RXALL))) 5994 NETIF_F_RXALL)))
6031 return 0; 5995 return 0;
6032 5996
6033 /*
6034 * IP payload checksum (enabled with jumbos/packet-split when Rx
6035 * checksum is enabled) and generation of RSS hash is mutually
6036 * exclusive in the hardware.
6037 */
6038 if (adapter->rx_ps_pages &&
6039 (features & NETIF_F_RXCSUM) && (features & NETIF_F_RXHASH)) {
6040 e_err("Enabling both receive checksum offload and receive hashing is not possible with jumbo frames. Disable jumbos or enable only one of the receive offload features.\n");
6041 return -EINVAL;
6042 }
6043
6044 if (changed & NETIF_F_RXFCS) { 5997 if (changed & NETIF_F_RXFCS) {
6045 if (features & NETIF_F_RXFCS) { 5998 if (features & NETIF_F_RXFCS) {
6046 adapter->flags2 &= ~FLAG2_CRC_STRIPPING; 5999 adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
diff --git a/drivers/net/ethernet/intel/igbvf/ethtool.c b/drivers/net/ethernet/intel/igbvf/ethtool.c
index 8ce67064b9c5..90eef07943f4 100644
--- a/drivers/net/ethernet/intel/igbvf/ethtool.c
+++ b/drivers/net/ethernet/intel/igbvf/ethtool.c
@@ -357,21 +357,28 @@ static int igbvf_set_coalesce(struct net_device *netdev,
357 struct igbvf_adapter *adapter = netdev_priv(netdev); 357 struct igbvf_adapter *adapter = netdev_priv(netdev);
358 struct e1000_hw *hw = &adapter->hw; 358 struct e1000_hw *hw = &adapter->hw;
359 359
360 if ((ec->rx_coalesce_usecs > IGBVF_MAX_ITR_USECS) || 360 if ((ec->rx_coalesce_usecs >= IGBVF_MIN_ITR_USECS) &&
361 ((ec->rx_coalesce_usecs > 3) && 361 (ec->rx_coalesce_usecs <= IGBVF_MAX_ITR_USECS)) {
362 (ec->rx_coalesce_usecs < IGBVF_MIN_ITR_USECS)) || 362 adapter->current_itr = ec->rx_coalesce_usecs << 2;
363 (ec->rx_coalesce_usecs == 2)) 363 adapter->requested_itr = 1000000000 /
364 return -EINVAL; 364 (adapter->current_itr * 256);
365 365 } else if ((ec->rx_coalesce_usecs == 3) ||
366 /* convert to rate of irq's per second */ 366 (ec->rx_coalesce_usecs == 2)) {
367 if (ec->rx_coalesce_usecs && ec->rx_coalesce_usecs <= 3) {
368 adapter->current_itr = IGBVF_START_ITR; 367 adapter->current_itr = IGBVF_START_ITR;
369 adapter->requested_itr = ec->rx_coalesce_usecs; 368 adapter->requested_itr = ec->rx_coalesce_usecs;
370 } else { 369 } else if (ec->rx_coalesce_usecs == 0) {
371 adapter->current_itr = ec->rx_coalesce_usecs << 2; 370 /*
371 * The user's desire is to turn off interrupt throttling
372 * altogether, but due to HW limitations, we can't do that.
373 * Instead we set a very small value in EITR, which would
374 * allow ~967k interrupts per second, but allow the adapter's
375 * internal clocking to still function properly.
376 */
377 adapter->current_itr = 4;
372 adapter->requested_itr = 1000000000 / 378 adapter->requested_itr = 1000000000 /
373 (adapter->current_itr * 256); 379 (adapter->current_itr * 256);
374 } 380 } else
381 return -EINVAL;
375 382
376 writel(adapter->current_itr, 383 writel(adapter->current_itr,
377 hw->hw_addr + adapter->rx_ring->itr_register); 384 hw->hw_addr + adapter->rx_ring->itr_register);
diff --git a/drivers/net/ethernet/ti/davinci_cpdma.c b/drivers/net/ethernet/ti/davinci_cpdma.c
index d614c374ed9d..3b5c4571b55e 100644
--- a/drivers/net/ethernet/ti/davinci_cpdma.c
+++ b/drivers/net/ethernet/ti/davinci_cpdma.c
@@ -15,6 +15,7 @@
15#include <linux/kernel.h> 15#include <linux/kernel.h>
16#include <linux/spinlock.h> 16#include <linux/spinlock.h>
17#include <linux/device.h> 17#include <linux/device.h>
18#include <linux/module.h>
18#include <linux/slab.h> 19#include <linux/slab.h>
19#include <linux/err.h> 20#include <linux/err.h>
20#include <linux/dma-mapping.h> 21#include <linux/dma-mapping.h>
diff --git a/drivers/net/usb/qmi_wwan.c b/drivers/net/usb/qmi_wwan.c
index 3767a1225860..b01960fcfbc9 100644
--- a/drivers/net/usb/qmi_wwan.c
+++ b/drivers/net/usb/qmi_wwan.c
@@ -197,6 +197,10 @@ err:
197static int qmi_wwan_cdc_wdm_manage_power(struct usb_interface *intf, int on) 197static int qmi_wwan_cdc_wdm_manage_power(struct usb_interface *intf, int on)
198{ 198{
199 struct usbnet *dev = usb_get_intfdata(intf); 199 struct usbnet *dev = usb_get_intfdata(intf);
200
201 /* can be called while disconnecting */
202 if (!dev)
203 return 0;
200 return qmi_wwan_manage_power(dev, on); 204 return qmi_wwan_manage_power(dev, on);
201} 205}
202 206
diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
index c54b7d37bff1..420d69b2674c 100644
--- a/drivers/net/wireless/ath/ath.h
+++ b/drivers/net/wireless/ath/ath.h
@@ -143,6 +143,7 @@ struct ath_common {
143 u32 keymax; 143 u32 keymax;
144 DECLARE_BITMAP(keymap, ATH_KEYMAX); 144 DECLARE_BITMAP(keymap, ATH_KEYMAX);
145 DECLARE_BITMAP(tkip_keymap, ATH_KEYMAX); 145 DECLARE_BITMAP(tkip_keymap, ATH_KEYMAX);
146 DECLARE_BITMAP(ccmp_keymap, ATH_KEYMAX);
146 enum ath_crypt_caps crypt_caps; 147 enum ath_crypt_caps crypt_caps;
147 148
148 unsigned int clockrate; 149 unsigned int clockrate;
diff --git a/drivers/net/wireless/ath/ath9k/hw.c b/drivers/net/wireless/ath/ath9k/hw.c
index 1c68e564f503..995ca8e1302e 100644
--- a/drivers/net/wireless/ath/ath9k/hw.c
+++ b/drivers/net/wireless/ath/ath9k/hw.c
@@ -622,7 +622,7 @@ static int __ath9k_hw_init(struct ath_hw *ah)
622 622
623 if (NR_CPUS > 1 && ah->config.serialize_regmode == SER_REG_MODE_AUTO) { 623 if (NR_CPUS > 1 && ah->config.serialize_regmode == SER_REG_MODE_AUTO) {
624 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI || 624 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI ||
625 ((AR_SREV_9160(ah) || AR_SREV_9280(ah)) && 625 ((AR_SREV_9160(ah) || AR_SREV_9280(ah) || AR_SREV_9287(ah)) &&
626 !ah->is_pciexpress)) { 626 !ah->is_pciexpress)) {
627 ah->config.serialize_regmode = 627 ah->config.serialize_regmode =
628 SER_REG_MODE_ON; 628 SER_REG_MODE_ON;
diff --git a/drivers/net/wireless/ath/ath9k/recv.c b/drivers/net/wireless/ath/ath9k/recv.c
index e1fcc68124dc..0735aeb3b26c 100644
--- a/drivers/net/wireless/ath/ath9k/recv.c
+++ b/drivers/net/wireless/ath/ath9k/recv.c
@@ -695,9 +695,9 @@ static bool ath_edma_get_buffers(struct ath_softc *sc,
695 __skb_unlink(skb, &rx_edma->rx_fifo); 695 __skb_unlink(skb, &rx_edma->rx_fifo);
696 list_add_tail(&bf->list, &sc->rx.rxbuf); 696 list_add_tail(&bf->list, &sc->rx.rxbuf);
697 ath_rx_edma_buf_link(sc, qtype); 697 ath_rx_edma_buf_link(sc, qtype);
698 } else {
699 bf = NULL;
700 } 698 }
699
700 bf = NULL;
701 } 701 }
702 702
703 *dest = bf; 703 *dest = bf;
@@ -822,7 +822,8 @@ static bool ath9k_rx_accept(struct ath_common *common,
822 * descriptor does contain a valid key index. This has been observed 822 * descriptor does contain a valid key index. This has been observed
823 * mostly with CCMP encryption. 823 * mostly with CCMP encryption.
824 */ 824 */
825 if (rx_stats->rs_keyix == ATH9K_RXKEYIX_INVALID) 825 if (rx_stats->rs_keyix == ATH9K_RXKEYIX_INVALID ||
826 !test_bit(rx_stats->rs_keyix, common->ccmp_keymap))
826 rx_stats->rs_status &= ~ATH9K_RXERR_KEYMISS; 827 rx_stats->rs_status &= ~ATH9K_RXERR_KEYMISS;
827 828
828 if (!rx_stats->rs_datalen) { 829 if (!rx_stats->rs_datalen) {
diff --git a/drivers/net/wireless/ath/key.c b/drivers/net/wireless/ath/key.c
index 0e81904956cf..5c54aa43ca2d 100644
--- a/drivers/net/wireless/ath/key.c
+++ b/drivers/net/wireless/ath/key.c
@@ -556,6 +556,9 @@ int ath_key_config(struct ath_common *common,
556 return -EIO; 556 return -EIO;
557 557
558 set_bit(idx, common->keymap); 558 set_bit(idx, common->keymap);
559 if (key->cipher == WLAN_CIPHER_SUITE_CCMP)
560 set_bit(idx, common->ccmp_keymap);
561
559 if (key->cipher == WLAN_CIPHER_SUITE_TKIP) { 562 if (key->cipher == WLAN_CIPHER_SUITE_TKIP) {
560 set_bit(idx + 64, common->keymap); 563 set_bit(idx + 64, common->keymap);
561 set_bit(idx, common->tkip_keymap); 564 set_bit(idx, common->tkip_keymap);
@@ -582,6 +585,7 @@ void ath_key_delete(struct ath_common *common, struct ieee80211_key_conf *key)
582 return; 585 return;
583 586
584 clear_bit(key->hw_key_idx, common->keymap); 587 clear_bit(key->hw_key_idx, common->keymap);
588 clear_bit(key->hw_key_idx, common->ccmp_keymap);
585 if (key->cipher != WLAN_CIPHER_SUITE_TKIP) 589 if (key->cipher != WLAN_CIPHER_SUITE_TKIP)
586 return; 590 return;
587 591
diff --git a/drivers/net/wireless/iwlwifi/iwl-mac80211.c b/drivers/net/wireless/iwlwifi/iwl-mac80211.c
index 3ee23134c02b..013680332f07 100644
--- a/drivers/net/wireless/iwlwifi/iwl-mac80211.c
+++ b/drivers/net/wireless/iwlwifi/iwl-mac80211.c
@@ -796,6 +796,18 @@ int iwlagn_mac_sta_state(struct ieee80211_hw *hw,
796 switch (op) { 796 switch (op) {
797 case ADD: 797 case ADD:
798 ret = iwlagn_mac_sta_add(hw, vif, sta); 798 ret = iwlagn_mac_sta_add(hw, vif, sta);
799 if (ret)
800 break;
801 /*
802 * Clear the in-progress flag, the AP station entry was added
803 * but we'll initialize LQ only when we've associated (which
804 * would also clear the in-progress flag). This is necessary
805 * in case we never initialize LQ because association fails.
806 */
807 spin_lock_bh(&priv->sta_lock);
808 priv->stations[iwl_sta_id(sta)].used &=
809 ~IWL_STA_UCODE_INPROGRESS;
810 spin_unlock_bh(&priv->sta_lock);
799 break; 811 break;
800 case REMOVE: 812 case REMOVE:
801 ret = iwlagn_mac_sta_remove(hw, vif, sta); 813 ret = iwlagn_mac_sta_remove(hw, vif, sta);
diff --git a/drivers/net/wireless/mwifiex/11n_rxreorder.c b/drivers/net/wireless/mwifiex/11n_rxreorder.c
index 9c44088054dd..900ee129e825 100644
--- a/drivers/net/wireless/mwifiex/11n_rxreorder.c
+++ b/drivers/net/wireless/mwifiex/11n_rxreorder.c
@@ -256,7 +256,8 @@ mwifiex_11n_create_rx_reorder_tbl(struct mwifiex_private *priv, u8 *ta,
256 else 256 else
257 last_seq = priv->rx_seq[tid]; 257 last_seq = priv->rx_seq[tid];
258 258
259 if (last_seq >= new_node->start_win) 259 if (last_seq != MWIFIEX_DEF_11N_RX_SEQ_NUM &&
260 last_seq >= new_node->start_win)
260 new_node->start_win = last_seq + 1; 261 new_node->start_win = last_seq + 1;
261 262
262 new_node->win_size = win_size; 263 new_node->win_size = win_size;
@@ -596,5 +597,5 @@ void mwifiex_11n_cleanup_reorder_tbl(struct mwifiex_private *priv)
596 spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags); 597 spin_unlock_irqrestore(&priv->rx_reorder_tbl_lock, flags);
597 598
598 INIT_LIST_HEAD(&priv->rx_reorder_tbl_ptr); 599 INIT_LIST_HEAD(&priv->rx_reorder_tbl_ptr);
599 memset(priv->rx_seq, 0, sizeof(priv->rx_seq)); 600 mwifiex_reset_11n_rx_seq_num(priv);
600} 601}
diff --git a/drivers/net/wireless/mwifiex/11n_rxreorder.h b/drivers/net/wireless/mwifiex/11n_rxreorder.h
index f1bffebabc60..6c9815a0f5d8 100644
--- a/drivers/net/wireless/mwifiex/11n_rxreorder.h
+++ b/drivers/net/wireless/mwifiex/11n_rxreorder.h
@@ -37,6 +37,13 @@
37 37
38#define ADDBA_RSP_STATUS_ACCEPT 0 38#define ADDBA_RSP_STATUS_ACCEPT 0
39 39
40#define MWIFIEX_DEF_11N_RX_SEQ_NUM 0xffff
41
42static inline void mwifiex_reset_11n_rx_seq_num(struct mwifiex_private *priv)
43{
44 memset(priv->rx_seq, 0xff, sizeof(priv->rx_seq));
45}
46
40int mwifiex_11n_rx_reorder_pkt(struct mwifiex_private *, 47int mwifiex_11n_rx_reorder_pkt(struct mwifiex_private *,
41 u16 seqNum, 48 u16 seqNum,
42 u16 tid, u8 *ta, 49 u16 tid, u8 *ta,
diff --git a/drivers/net/wireless/mwifiex/ie.c b/drivers/net/wireless/mwifiex/ie.c
index ceb82cd749cc..383820a52beb 100644
--- a/drivers/net/wireless/mwifiex/ie.c
+++ b/drivers/net/wireless/mwifiex/ie.c
@@ -213,6 +213,7 @@ mwifiex_update_uap_custom_ie(struct mwifiex_private *priv,
213 /* save assoc resp ie index after auto-indexing */ 213 /* save assoc resp ie index after auto-indexing */
214 *assoc_idx = *((u16 *)pos); 214 *assoc_idx = *((u16 *)pos);
215 215
216 kfree(ap_custom_ie);
216 return ret; 217 return ret;
217} 218}
218 219
diff --git a/drivers/net/wireless/mwifiex/sdio.c b/drivers/net/wireless/mwifiex/sdio.c
index e0377473282f..fc8a9bfa1248 100644
--- a/drivers/net/wireless/mwifiex/sdio.c
+++ b/drivers/net/wireless/mwifiex/sdio.c
@@ -978,10 +978,10 @@ static int mwifiex_decode_rx_packet(struct mwifiex_adapter *adapter,
978 dev_dbg(adapter->dev, "info: --- Rx: Event ---\n"); 978 dev_dbg(adapter->dev, "info: --- Rx: Event ---\n");
979 adapter->event_cause = *(u32 *) skb->data; 979 adapter->event_cause = *(u32 *) skb->data;
980 980
981 skb_pull(skb, MWIFIEX_EVENT_HEADER_LEN);
982
983 if ((skb->len > 0) && (skb->len < MAX_EVENT_SIZE)) 981 if ((skb->len > 0) && (skb->len < MAX_EVENT_SIZE))
984 memcpy(adapter->event_body, skb->data, skb->len); 982 memcpy(adapter->event_body,
983 skb->data + MWIFIEX_EVENT_HEADER_LEN,
984 skb->len);
985 985
986 /* event cause has been saved to adapter->event_cause */ 986 /* event cause has been saved to adapter->event_cause */
987 adapter->event_received = true; 987 adapter->event_received = true;
diff --git a/drivers/net/wireless/mwifiex/sta_event.c b/drivers/net/wireless/mwifiex/sta_event.c
index 4ace5a3dcd23..11e731f3581c 100644
--- a/drivers/net/wireless/mwifiex/sta_event.c
+++ b/drivers/net/wireless/mwifiex/sta_event.c
@@ -406,9 +406,9 @@ int mwifiex_process_sta_event(struct mwifiex_private *priv)
406 break; 406 break;
407 407
408 case EVENT_UAP_STA_ASSOC: 408 case EVENT_UAP_STA_ASSOC:
409 skb_pull(adapter->event_skb, MWIFIEX_UAP_EVENT_EXTRA_HEADER);
410 memset(&sinfo, 0, sizeof(sinfo)); 409 memset(&sinfo, 0, sizeof(sinfo));
411 event = (struct mwifiex_assoc_event *)adapter->event_skb->data; 410 event = (struct mwifiex_assoc_event *)
411 (adapter->event_body + MWIFIEX_UAP_EVENT_EXTRA_HEADER);
412 if (le16_to_cpu(event->type) == TLV_TYPE_UAP_MGMT_FRAME) { 412 if (le16_to_cpu(event->type) == TLV_TYPE_UAP_MGMT_FRAME) {
413 len = -1; 413 len = -1;
414 414
@@ -433,9 +433,8 @@ int mwifiex_process_sta_event(struct mwifiex_private *priv)
433 GFP_KERNEL); 433 GFP_KERNEL);
434 break; 434 break;
435 case EVENT_UAP_STA_DEAUTH: 435 case EVENT_UAP_STA_DEAUTH:
436 skb_pull(adapter->event_skb, MWIFIEX_UAP_EVENT_EXTRA_HEADER); 436 cfg80211_del_sta(priv->netdev, adapter->event_body +
437 cfg80211_del_sta(priv->netdev, adapter->event_skb->data, 437 MWIFIEX_UAP_EVENT_EXTRA_HEADER, GFP_KERNEL);
438 GFP_KERNEL);
439 break; 438 break;
440 case EVENT_UAP_BSS_IDLE: 439 case EVENT_UAP_BSS_IDLE:
441 priv->media_connected = false; 440 priv->media_connected = false;
diff --git a/drivers/net/wireless/mwifiex/usb.c b/drivers/net/wireless/mwifiex/usb.c
index 49ebf20c56eb..22a5916564b8 100644
--- a/drivers/net/wireless/mwifiex/usb.c
+++ b/drivers/net/wireless/mwifiex/usb.c
@@ -49,6 +49,7 @@ static int mwifiex_usb_recv(struct mwifiex_adapter *adapter,
49 struct device *dev = adapter->dev; 49 struct device *dev = adapter->dev;
50 u32 recv_type; 50 u32 recv_type;
51 __le32 tmp; 51 __le32 tmp;
52 int ret;
52 53
53 if (adapter->hs_activated) 54 if (adapter->hs_activated)
54 mwifiex_process_hs_config(adapter); 55 mwifiex_process_hs_config(adapter);
@@ -69,16 +70,19 @@ static int mwifiex_usb_recv(struct mwifiex_adapter *adapter,
69 case MWIFIEX_USB_TYPE_CMD: 70 case MWIFIEX_USB_TYPE_CMD:
70 if (skb->len > MWIFIEX_SIZE_OF_CMD_BUFFER) { 71 if (skb->len > MWIFIEX_SIZE_OF_CMD_BUFFER) {
71 dev_err(dev, "CMD: skb->len too large\n"); 72 dev_err(dev, "CMD: skb->len too large\n");
72 return -1; 73 ret = -1;
74 goto exit_restore_skb;
73 } else if (!adapter->curr_cmd) { 75 } else if (!adapter->curr_cmd) {
74 dev_dbg(dev, "CMD: no curr_cmd\n"); 76 dev_dbg(dev, "CMD: no curr_cmd\n");
75 if (adapter->ps_state == PS_STATE_SLEEP_CFM) { 77 if (adapter->ps_state == PS_STATE_SLEEP_CFM) {
76 mwifiex_process_sleep_confirm_resp( 78 mwifiex_process_sleep_confirm_resp(
77 adapter, skb->data, 79 adapter, skb->data,
78 skb->len); 80 skb->len);
79 return 0; 81 ret = 0;
82 goto exit_restore_skb;
80 } 83 }
81 return -1; 84 ret = -1;
85 goto exit_restore_skb;
82 } 86 }
83 87
84 adapter->curr_cmd->resp_skb = skb; 88 adapter->curr_cmd->resp_skb = skb;
@@ -87,20 +91,22 @@ static int mwifiex_usb_recv(struct mwifiex_adapter *adapter,
87 case MWIFIEX_USB_TYPE_EVENT: 91 case MWIFIEX_USB_TYPE_EVENT:
88 if (skb->len < sizeof(u32)) { 92 if (skb->len < sizeof(u32)) {
89 dev_err(dev, "EVENT: skb->len too small\n"); 93 dev_err(dev, "EVENT: skb->len too small\n");
90 return -1; 94 ret = -1;
95 goto exit_restore_skb;
91 } 96 }
92 skb_copy_from_linear_data(skb, &tmp, sizeof(u32)); 97 skb_copy_from_linear_data(skb, &tmp, sizeof(u32));
93 adapter->event_cause = le32_to_cpu(tmp); 98 adapter->event_cause = le32_to_cpu(tmp);
94 skb_pull(skb, sizeof(u32));
95 dev_dbg(dev, "event_cause %#x\n", adapter->event_cause); 99 dev_dbg(dev, "event_cause %#x\n", adapter->event_cause);
96 100
97 if (skb->len > MAX_EVENT_SIZE) { 101 if (skb->len > MAX_EVENT_SIZE) {
98 dev_err(dev, "EVENT: event body too large\n"); 102 dev_err(dev, "EVENT: event body too large\n");
99 return -1; 103 ret = -1;
104 goto exit_restore_skb;
100 } 105 }
101 106
102 skb_copy_from_linear_data(skb, adapter->event_body, 107 memcpy(adapter->event_body, skb->data +
103 skb->len); 108 MWIFIEX_EVENT_HEADER_LEN, skb->len);
109
104 adapter->event_received = true; 110 adapter->event_received = true;
105 adapter->event_skb = skb; 111 adapter->event_skb = skb;
106 break; 112 break;
@@ -124,6 +130,12 @@ static int mwifiex_usb_recv(struct mwifiex_adapter *adapter,
124 } 130 }
125 131
126 return -EINPROGRESS; 132 return -EINPROGRESS;
133
134exit_restore_skb:
135 /* The buffer will be reused for further cmds/events */
136 skb_push(skb, INTF_HEADER_LEN);
137
138 return ret;
127} 139}
128 140
129static void mwifiex_usb_rx_complete(struct urb *urb) 141static void mwifiex_usb_rx_complete(struct urb *urb)
diff --git a/drivers/net/wireless/mwifiex/wmm.c b/drivers/net/wireless/mwifiex/wmm.c
index f3fc65515857..3fa4d4176993 100644
--- a/drivers/net/wireless/mwifiex/wmm.c
+++ b/drivers/net/wireless/mwifiex/wmm.c
@@ -404,6 +404,8 @@ mwifiex_wmm_init(struct mwifiex_adapter *adapter)
404 priv->add_ba_param.tx_win_size = MWIFIEX_AMPDU_DEF_TXWINSIZE; 404 priv->add_ba_param.tx_win_size = MWIFIEX_AMPDU_DEF_TXWINSIZE;
405 priv->add_ba_param.rx_win_size = MWIFIEX_AMPDU_DEF_RXWINSIZE; 405 priv->add_ba_param.rx_win_size = MWIFIEX_AMPDU_DEF_RXWINSIZE;
406 406
407 mwifiex_reset_11n_rx_seq_num(priv);
408
407 atomic_set(&priv->wmm.tx_pkts_queued, 0); 409 atomic_set(&priv->wmm.tx_pkts_queued, 0);
408 atomic_set(&priv->wmm.highest_queued_prio, HIGH_PRIO_TID); 410 atomic_set(&priv->wmm.highest_queued_prio, HIGH_PRIO_TID);
409 } 411 }
@@ -1221,6 +1223,7 @@ mwifiex_dequeue_tx_packet(struct mwifiex_adapter *adapter)
1221 1223
1222 if (!ptr->is_11n_enabled || 1224 if (!ptr->is_11n_enabled ||
1223 mwifiex_is_ba_stream_setup(priv, ptr, tid) || 1225 mwifiex_is_ba_stream_setup(priv, ptr, tid) ||
1226 priv->wps.session_enable ||
1224 ((priv->sec_info.wpa_enabled || 1227 ((priv->sec_info.wpa_enabled ||
1225 priv->sec_info.wpa2_enabled) && 1228 priv->sec_info.wpa2_enabled) &&
1226 !priv->wpa_is_gtk_set)) { 1229 !priv->wpa_is_gtk_set)) {
diff --git a/drivers/net/wireless/rtlwifi/rtl8192cu/sw.c b/drivers/net/wireless/rtlwifi/rtl8192cu/sw.c
index d228358e6a40..9970c2b1b199 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192cu/sw.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192cu/sw.c
@@ -301,9 +301,11 @@ static struct usb_device_id rtl8192c_usb_ids[] = {
301 {RTL_USB_DEVICE(0x07b8, 0x8188, rtl92cu_hal_cfg)}, /*Abocom - Abocom*/ 301 {RTL_USB_DEVICE(0x07b8, 0x8188, rtl92cu_hal_cfg)}, /*Abocom - Abocom*/
302 {RTL_USB_DEVICE(0x07b8, 0x8189, rtl92cu_hal_cfg)}, /*Funai - Abocom*/ 302 {RTL_USB_DEVICE(0x07b8, 0x8189, rtl92cu_hal_cfg)}, /*Funai - Abocom*/
303 {RTL_USB_DEVICE(0x0846, 0x9041, rtl92cu_hal_cfg)}, /*NetGear WNA1000M*/ 303 {RTL_USB_DEVICE(0x0846, 0x9041, rtl92cu_hal_cfg)}, /*NetGear WNA1000M*/
304 {RTL_USB_DEVICE(0x0bda, 0x5088, rtl92cu_hal_cfg)}, /*Thinkware-CC&C*/
304 {RTL_USB_DEVICE(0x0df6, 0x0052, rtl92cu_hal_cfg)}, /*Sitecom - Edimax*/ 305 {RTL_USB_DEVICE(0x0df6, 0x0052, rtl92cu_hal_cfg)}, /*Sitecom - Edimax*/
305 {RTL_USB_DEVICE(0x0df6, 0x005c, rtl92cu_hal_cfg)}, /*Sitecom - Edimax*/ 306 {RTL_USB_DEVICE(0x0df6, 0x005c, rtl92cu_hal_cfg)}, /*Sitecom - Edimax*/
306 {RTL_USB_DEVICE(0x0eb0, 0x9071, rtl92cu_hal_cfg)}, /*NO Brand - Etop*/ 307 {RTL_USB_DEVICE(0x0eb0, 0x9071, rtl92cu_hal_cfg)}, /*NO Brand - Etop*/
308 {RTL_USB_DEVICE(0x4856, 0x0091, rtl92cu_hal_cfg)}, /*NetweeN - Feixun*/
307 /* HP - Lite-On ,8188CUS Slim Combo */ 309 /* HP - Lite-On ,8188CUS Slim Combo */
308 {RTL_USB_DEVICE(0x103c, 0x1629, rtl92cu_hal_cfg)}, 310 {RTL_USB_DEVICE(0x103c, 0x1629, rtl92cu_hal_cfg)},
309 {RTL_USB_DEVICE(0x13d3, 0x3357, rtl92cu_hal_cfg)}, /* AzureWave */ 311 {RTL_USB_DEVICE(0x13d3, 0x3357, rtl92cu_hal_cfg)}, /* AzureWave */
@@ -346,6 +348,7 @@ static struct usb_device_id rtl8192c_usb_ids[] = {
346 {RTL_USB_DEVICE(0x07b8, 0x8178, rtl92cu_hal_cfg)}, /*Funai -Abocom*/ 348 {RTL_USB_DEVICE(0x07b8, 0x8178, rtl92cu_hal_cfg)}, /*Funai -Abocom*/
347 {RTL_USB_DEVICE(0x0846, 0x9021, rtl92cu_hal_cfg)}, /*Netgear-Sercomm*/ 349 {RTL_USB_DEVICE(0x0846, 0x9021, rtl92cu_hal_cfg)}, /*Netgear-Sercomm*/
348 {RTL_USB_DEVICE(0x0b05, 0x17ab, rtl92cu_hal_cfg)}, /*ASUS-Edimax*/ 350 {RTL_USB_DEVICE(0x0b05, 0x17ab, rtl92cu_hal_cfg)}, /*ASUS-Edimax*/
351 {RTL_USB_DEVICE(0x0bda, 0x8186, rtl92cu_hal_cfg)}, /*Realtek 92CE-VAU*/
349 {RTL_USB_DEVICE(0x0df6, 0x0061, rtl92cu_hal_cfg)}, /*Sitecom-Edimax*/ 352 {RTL_USB_DEVICE(0x0df6, 0x0061, rtl92cu_hal_cfg)}, /*Sitecom-Edimax*/
350 {RTL_USB_DEVICE(0x0e66, 0x0019, rtl92cu_hal_cfg)}, /*Hawking-Edimax*/ 353 {RTL_USB_DEVICE(0x0e66, 0x0019, rtl92cu_hal_cfg)}, /*Hawking-Edimax*/
351 {RTL_USB_DEVICE(0x2001, 0x3307, rtl92cu_hal_cfg)}, /*D-Link-Cameo*/ 354 {RTL_USB_DEVICE(0x2001, 0x3307, rtl92cu_hal_cfg)}, /*D-Link-Cameo*/
diff --git a/drivers/net/wireless/ti/wlcore/Kconfig b/drivers/net/wireless/ti/wlcore/Kconfig
index 54156b0b5c2d..d7b907e67170 100644
--- a/drivers/net/wireless/ti/wlcore/Kconfig
+++ b/drivers/net/wireless/ti/wlcore/Kconfig
@@ -1,7 +1,6 @@
1config WLCORE 1config WLCORE
2 tristate "TI wlcore support" 2 tristate "TI wlcore support"
3 depends on WL_TI && GENERIC_HARDIRQS && MAC80211 3 depends on WL_TI && GENERIC_HARDIRQS && MAC80211
4 depends on INET
5 select FW_LOADER 4 select FW_LOADER
6 ---help--- 5 ---help---
7 This module contains the main code for TI WLAN chips. It abstracts 6 This module contains the main code for TI WLAN chips. It abstracts
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index 343ad29e211c..e44f8c2d239d 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -317,10 +317,9 @@ static const struct of_dev_auxdata *of_dev_lookup(const struct of_dev_auxdata *l
317 for(; lookup->compatible != NULL; lookup++) { 317 for(; lookup->compatible != NULL; lookup++) {
318 if (!of_device_is_compatible(np, lookup->compatible)) 318 if (!of_device_is_compatible(np, lookup->compatible))
319 continue; 319 continue;
320 if (of_address_to_resource(np, 0, &res)) 320 if (!of_address_to_resource(np, 0, &res))
321 continue; 321 if (res.start != lookup->phys_addr)
322 if (res.start != lookup->phys_addr) 322 continue;
323 continue;
324 pr_debug("%s: devname=%s\n", np->full_name, lookup->name); 323 pr_debug("%s: devname=%s\n", np->full_name, lookup->name);
325 return lookup; 324 return lookup;
326 } 325 }
@@ -462,4 +461,5 @@ int of_platform_populate(struct device_node *root,
462 of_node_put(root); 461 of_node_put(root);
463 return rc; 462 return rc;
464} 463}
464EXPORT_SYMBOL_GPL(of_platform_populate);
465#endif /* CONFIG_OF_ADDRESS */ 465#endif /* CONFIG_OF_ADDRESS */
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index bf0cee629b60..099f46cd8e87 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -748,6 +748,18 @@ static int pci_pm_suspend_noirq(struct device *dev)
748 748
749 pci_pm_set_unknown_state(pci_dev); 749 pci_pm_set_unknown_state(pci_dev);
750 750
751 /*
752 * Some BIOSes from ASUS have a bug: If a USB EHCI host controller's
753 * PCI COMMAND register isn't 0, the BIOS assumes that the controller
754 * hasn't been quiesced and tries to turn it off. If the controller
755 * is already in D3, this can hang or cause memory corruption.
756 *
757 * Since the value of the COMMAND register doesn't matter once the
758 * device has been suspended, we can safely set it to 0 here.
759 */
760 if (pci_dev->class == PCI_CLASS_SERIAL_USB_EHCI)
761 pci_write_config_word(pci_dev, PCI_COMMAND, 0);
762
751 return 0; 763 return 0;
752} 764}
753 765
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 77cb54a65cde..447e83472c01 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -1744,11 +1744,6 @@ int pci_prepare_to_sleep(struct pci_dev *dev)
1744 if (target_state == PCI_POWER_ERROR) 1744 if (target_state == PCI_POWER_ERROR)
1745 return -EIO; 1745 return -EIO;
1746 1746
1747 /* Some devices mustn't be in D3 during system sleep */
1748 if (target_state == PCI_D3hot &&
1749 (dev->dev_flags & PCI_DEV_FLAGS_NO_D3_DURING_SLEEP))
1750 return 0;
1751
1752 pci_enable_wake(dev, target_state, device_may_wakeup(&dev->dev)); 1747 pci_enable_wake(dev, target_state, device_may_wakeup(&dev->dev));
1753 1748
1754 error = pci_set_power_state(dev, target_state); 1749 error = pci_set_power_state(dev, target_state);
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index 194b243a2817..2a7521677541 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -2929,32 +2929,6 @@ static void __devinit disable_igfx_irq(struct pci_dev *dev)
2929DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x0102, disable_igfx_irq); 2929DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x0102, disable_igfx_irq);
2930DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x010a, disable_igfx_irq); 2930DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x010a, disable_igfx_irq);
2931 2931
2932/*
2933 * The Intel 6 Series/C200 Series chipset's EHCI controllers on many
2934 * ASUS motherboards will cause memory corruption or a system crash
2935 * if they are in D3 while the system is put into S3 sleep.
2936 */
2937static void __devinit asus_ehci_no_d3(struct pci_dev *dev)
2938{
2939 const char *sys_info;
2940 static const char good_Asus_board[] = "P8Z68-V";
2941
2942 if (dev->dev_flags & PCI_DEV_FLAGS_NO_D3_DURING_SLEEP)
2943 return;
2944 if (dev->subsystem_vendor != PCI_VENDOR_ID_ASUSTEK)
2945 return;
2946 sys_info = dmi_get_system_info(DMI_BOARD_NAME);
2947 if (sys_info && memcmp(sys_info, good_Asus_board,
2948 sizeof(good_Asus_board) - 1) == 0)
2949 return;
2950
2951 dev_info(&dev->dev, "broken D3 during system sleep on ASUS\n");
2952 dev->dev_flags |= PCI_DEV_FLAGS_NO_D3_DURING_SLEEP;
2953 device_set_wakeup_capable(&dev->dev, false);
2954}
2955DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x1c26, asus_ehci_no_d3);
2956DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x1c2d, asus_ehci_no_d3);
2957
2958static void pci_do_fixups(struct pci_dev *dev, struct pci_fixup *f, 2932static void pci_do_fixups(struct pci_dev *dev, struct pci_fixup *f,
2959 struct pci_fixup *end) 2933 struct pci_fixup *end)
2960{ 2934{
diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index c86b8864e411..f34c3be6c9fe 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -20,6 +20,7 @@ menuconfig REGULATOR
20 20
21 If unsure, say no. 21 If unsure, say no.
22 22
23
23if REGULATOR 24if REGULATOR
24 25
25config REGULATOR_DEBUG 26config REGULATOR_DEBUG
@@ -88,6 +89,13 @@ config REGULATOR_AAT2870
88 If you have a AnalogicTech AAT2870 say Y to enable the 89 If you have a AnalogicTech AAT2870 say Y to enable the
89 regulator driver. 90 regulator driver.
90 91
92config REGULATOR_ARIZONA
93 tristate "Wolfson Arizona class devices"
94 depends on MFD_ARIZONA
95 help
96 Support for the regulators found on Wolfson Arizona class
97 devices.
98
91config REGULATOR_DA903X 99config REGULATOR_DA903X
92 tristate "Dialog Semiconductor DA9030/DA9034 regulators" 100 tristate "Dialog Semiconductor DA9030/DA9034 regulators"
93 depends on PMIC_DA903X 101 depends on PMIC_DA903X
@@ -195,6 +203,14 @@ config REGULATOR_MAX8998
195 via I2C bus. The provided regulator is suitable for S3C6410 203 via I2C bus. The provided regulator is suitable for S3C6410
196 and S5PC1XX chips to control VCC_CORE and VCC_USIM voltages. 204 and S5PC1XX chips to control VCC_CORE and VCC_USIM voltages.
197 205
206config REGULATOR_MAX77686
207 tristate "Maxim 77686 regulator"
208 depends on MFD_MAX77686
209 help
210 This driver controls a Maxim 77686 regulator
211 via I2C bus. The provided regulator is suitable for
212 Exynos-4 chips to control VARM and VINT voltages.
213
198config REGULATOR_PCAP 214config REGULATOR_PCAP
199 tristate "Motorola PCAP2 regulator driver" 215 tristate "Motorola PCAP2 regulator driver"
200 depends on EZX_PCAP 216 depends on EZX_PCAP
@@ -216,6 +232,19 @@ config REGULATOR_LP3972
216 Say Y here to support the voltage regulators and convertors 232 Say Y here to support the voltage regulators and convertors
217 on National Semiconductors LP3972 PMIC 233 on National Semiconductors LP3972 PMIC
218 234
235config REGULATOR_LP872X
236 bool "TI/National Semiconductor LP8720/LP8725 voltage regulators"
237 depends on I2C=y
238 select REGMAP_I2C
239 help
240 This driver supports LP8720/LP8725 PMIC
241
242config REGULATOR_LP8788
243 bool "TI LP8788 Power Regulators"
244 depends on MFD_LP8788
245 help
246 This driver supports LP8788 voltage regulator chip.
247
219config REGULATOR_PCF50633 248config REGULATOR_PCF50633
220 tristate "NXP PCF50633 regulator driver" 249 tristate "NXP PCF50633 regulator driver"
221 depends on MFD_PCF50633 250 depends on MFD_PCF50633
@@ -233,6 +262,14 @@ config REGULATOR_RC5T583
233 through regulator interface. The device supports multiple DCDC/LDO 262 through regulator interface. The device supports multiple DCDC/LDO
234 outputs which can be controlled by i2c communication. 263 outputs which can be controlled by i2c communication.
235 264
265config REGULATOR_S2MPS11
266 tristate "Samsung S2MPS11 voltage regulator"
267 depends on MFD_SEC_CORE
268 help
269 This driver supports a Samsung S2MPS11 voltage output regulator
270 via I2C bus. S2MPS11 is comprised of high efficient Buck converters
271 including Dual-Phase Buck converter, Buck-Boost converter, various LDOs.
272
236config REGULATOR_S5M8767 273config REGULATOR_S5M8767
237 tristate "Samsung S5M8767A voltage regulator" 274 tristate "Samsung S5M8767A voltage regulator"
238 depends on MFD_S5M_CORE 275 depends on MFD_S5M_CORE
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index 977fd46909ab..3342615cf25e 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -15,6 +15,7 @@ obj-$(CONFIG_REGULATOR_AB3100) += ab3100.o
15obj-$(CONFIG_REGULATOR_AB8500) += ab8500.o 15obj-$(CONFIG_REGULATOR_AB8500) += ab8500.o
16obj-$(CONFIG_REGULATOR_AD5398) += ad5398.o 16obj-$(CONFIG_REGULATOR_AD5398) += ad5398.o
17obj-$(CONFIG_REGULATOR_ANATOP) += anatop-regulator.o 17obj-$(CONFIG_REGULATOR_ANATOP) += anatop-regulator.o
18obj-$(CONFIG_REGULATOR_ARIZONA) += arizona-micsupp.o arizona-ldo1.o
18obj-$(CONFIG_REGULATOR_DA903X) += da903x.o 19obj-$(CONFIG_REGULATOR_DA903X) += da903x.o
19obj-$(CONFIG_REGULATOR_DA9052) += da9052-regulator.o 20obj-$(CONFIG_REGULATOR_DA9052) += da9052-regulator.o
20obj-$(CONFIG_REGULATOR_DBX500_PRCMU) += dbx500-prcmu.o 21obj-$(CONFIG_REGULATOR_DBX500_PRCMU) += dbx500-prcmu.o
@@ -23,6 +24,9 @@ obj-$(CONFIG_REGULATOR_GPIO) += gpio-regulator.o
23obj-$(CONFIG_REGULATOR_ISL6271A) += isl6271a-regulator.o 24obj-$(CONFIG_REGULATOR_ISL6271A) += isl6271a-regulator.o
24obj-$(CONFIG_REGULATOR_LP3971) += lp3971.o 25obj-$(CONFIG_REGULATOR_LP3971) += lp3971.o
25obj-$(CONFIG_REGULATOR_LP3972) += lp3972.o 26obj-$(CONFIG_REGULATOR_LP3972) += lp3972.o
27obj-$(CONFIG_REGULATOR_LP872X) += lp872x.o
28obj-$(CONFIG_REGULATOR_LP8788) += lp8788-buck.o
29obj-$(CONFIG_REGULATOR_LP8788) += lp8788-ldo.o
26obj-$(CONFIG_REGULATOR_MAX1586) += max1586.o 30obj-$(CONFIG_REGULATOR_MAX1586) += max1586.o
27obj-$(CONFIG_REGULATOR_MAX8649) += max8649.o 31obj-$(CONFIG_REGULATOR_MAX8649) += max8649.o
28obj-$(CONFIG_REGULATOR_MAX8660) += max8660.o 32obj-$(CONFIG_REGULATOR_MAX8660) += max8660.o
@@ -30,6 +34,7 @@ obj-$(CONFIG_REGULATOR_MAX8925) += max8925-regulator.o
30obj-$(CONFIG_REGULATOR_MAX8952) += max8952.o 34obj-$(CONFIG_REGULATOR_MAX8952) += max8952.o
31obj-$(CONFIG_REGULATOR_MAX8997) += max8997.o 35obj-$(CONFIG_REGULATOR_MAX8997) += max8997.o
32obj-$(CONFIG_REGULATOR_MAX8998) += max8998.o 36obj-$(CONFIG_REGULATOR_MAX8998) += max8998.o
37obj-$(CONFIG_REGULATOR_MAX77686) += max77686.o
33obj-$(CONFIG_REGULATOR_MC13783) += mc13783-regulator.o 38obj-$(CONFIG_REGULATOR_MC13783) += mc13783-regulator.o
34obj-$(CONFIG_REGULATOR_MC13892) += mc13892-regulator.o 39obj-$(CONFIG_REGULATOR_MC13892) += mc13892-regulator.o
35obj-$(CONFIG_REGULATOR_MC13XXX_CORE) += mc13xxx-regulator-core.o 40obj-$(CONFIG_REGULATOR_MC13XXX_CORE) += mc13xxx-regulator-core.o
@@ -37,6 +42,7 @@ obj-$(CONFIG_REGULATOR_PALMAS) += palmas-regulator.o
37obj-$(CONFIG_REGULATOR_PCAP) += pcap-regulator.o 42obj-$(CONFIG_REGULATOR_PCAP) += pcap-regulator.o
38obj-$(CONFIG_REGULATOR_PCF50633) += pcf50633-regulator.o 43obj-$(CONFIG_REGULATOR_PCF50633) += pcf50633-regulator.o
39obj-$(CONFIG_REGULATOR_RC5T583) += rc5t583-regulator.o 44obj-$(CONFIG_REGULATOR_RC5T583) += rc5t583-regulator.o
45obj-$(CONFIG_REGULATOR_S2MPS11) += s2mps11.o
40obj-$(CONFIG_REGULATOR_S5M8767) += s5m8767.o 46obj-$(CONFIG_REGULATOR_S5M8767) += s5m8767.o
41obj-$(CONFIG_REGULATOR_TPS6105X) += tps6105x-regulator.o 47obj-$(CONFIG_REGULATOR_TPS6105X) += tps6105x-regulator.o
42obj-$(CONFIG_REGULATOR_TPS62360) += tps62360-regulator.o 48obj-$(CONFIG_REGULATOR_TPS62360) += tps62360-regulator.o
diff --git a/drivers/regulator/aat2870-regulator.c b/drivers/regulator/aat2870-regulator.c
index 06776ca945f2..6f45bfd22e83 100644
--- a/drivers/regulator/aat2870-regulator.c
+++ b/drivers/regulator/aat2870-regulator.c
@@ -33,11 +33,6 @@ struct aat2870_regulator {
33 struct aat2870_data *aat2870; 33 struct aat2870_data *aat2870;
34 struct regulator_desc desc; 34 struct regulator_desc desc;
35 35
36 const int *voltages; /* uV */
37
38 int min_uV;
39 int max_uV;
40
41 u8 enable_addr; 36 u8 enable_addr;
42 u8 enable_shift; 37 u8 enable_shift;
43 u8 enable_mask; 38 u8 enable_mask;
@@ -47,14 +42,6 @@ struct aat2870_regulator {
47 u8 voltage_mask; 42 u8 voltage_mask;
48}; 43};
49 44
50static int aat2870_ldo_list_voltage(struct regulator_dev *rdev,
51 unsigned selector)
52{
53 struct aat2870_regulator *ri = rdev_get_drvdata(rdev);
54
55 return ri->voltages[selector];
56}
57
58static int aat2870_ldo_set_voltage_sel(struct regulator_dev *rdev, 45static int aat2870_ldo_set_voltage_sel(struct regulator_dev *rdev,
59 unsigned selector) 46 unsigned selector)
60{ 47{
@@ -111,7 +98,7 @@ static int aat2870_ldo_is_enabled(struct regulator_dev *rdev)
111} 98}
112 99
113static struct regulator_ops aat2870_ldo_ops = { 100static struct regulator_ops aat2870_ldo_ops = {
114 .list_voltage = aat2870_ldo_list_voltage, 101 .list_voltage = regulator_list_voltage_table,
115 .set_voltage_sel = aat2870_ldo_set_voltage_sel, 102 .set_voltage_sel = aat2870_ldo_set_voltage_sel,
116 .get_voltage_sel = aat2870_ldo_get_voltage_sel, 103 .get_voltage_sel = aat2870_ldo_get_voltage_sel,
117 .enable = aat2870_ldo_enable, 104 .enable = aat2870_ldo_enable,
@@ -119,7 +106,7 @@ static struct regulator_ops aat2870_ldo_ops = {
119 .is_enabled = aat2870_ldo_is_enabled, 106 .is_enabled = aat2870_ldo_is_enabled,
120}; 107};
121 108
122static const int aat2870_ldo_voltages[] = { 109static const unsigned int aat2870_ldo_voltages[] = {
123 1200000, 1300000, 1500000, 1600000, 110 1200000, 1300000, 1500000, 1600000,
124 1800000, 2000000, 2200000, 2500000, 111 1800000, 2000000, 2200000, 2500000,
125 2600000, 2700000, 2800000, 2900000, 112 2600000, 2700000, 2800000, 2900000,
@@ -132,13 +119,11 @@ static const int aat2870_ldo_voltages[] = {
132 .name = #ids, \ 119 .name = #ids, \
133 .id = AAT2870_ID_##ids, \ 120 .id = AAT2870_ID_##ids, \
134 .n_voltages = ARRAY_SIZE(aat2870_ldo_voltages), \ 121 .n_voltages = ARRAY_SIZE(aat2870_ldo_voltages), \
122 .volt_table = aat2870_ldo_voltages, \
135 .ops = &aat2870_ldo_ops, \ 123 .ops = &aat2870_ldo_ops, \
136 .type = REGULATOR_VOLTAGE, \ 124 .type = REGULATOR_VOLTAGE, \
137 .owner = THIS_MODULE, \ 125 .owner = THIS_MODULE, \
138 }, \ 126 }, \
139 .voltages = aat2870_ldo_voltages, \
140 .min_uV = 1200000, \
141 .max_uV = 3300000, \
142 } 127 }
143 128
144static struct aat2870_regulator aat2870_regulators[] = { 129static struct aat2870_regulator aat2870_regulators[] = {
diff --git a/drivers/regulator/ab3100.c b/drivers/regulator/ab3100.c
index 03f4d9c604ec..182b553059c9 100644
--- a/drivers/regulator/ab3100.c
+++ b/drivers/regulator/ab3100.c
@@ -43,20 +43,12 @@
43 * @dev: handle to the device 43 * @dev: handle to the device
44 * @plfdata: AB3100 platform data passed in at probe time 44 * @plfdata: AB3100 platform data passed in at probe time
45 * @regreg: regulator register number in the AB3100 45 * @regreg: regulator register number in the AB3100
46 * @fixed_voltage: a fixed voltage for this regulator, if this
47 * 0 the voltages array is used instead.
48 * @typ_voltages: an array of available typical voltages for
49 * this regulator
50 * @voltages_len: length of the array of available voltages
51 */ 46 */
52struct ab3100_regulator { 47struct ab3100_regulator {
53 struct regulator_dev *rdev; 48 struct regulator_dev *rdev;
54 struct device *dev; 49 struct device *dev;
55 struct ab3100_platform_data *plfdata; 50 struct ab3100_platform_data *plfdata;
56 u8 regreg; 51 u8 regreg;
57 int fixed_voltage;
58 int const *typ_voltages;
59 u8 voltages_len;
60}; 52};
61 53
62/* The order in which registers are initialized */ 54/* The order in which registers are initialized */
@@ -80,7 +72,7 @@ static const u8 ab3100_reg_init_order[AB3100_NUM_REGULATORS+2] = {
80#define LDO_C_VOLTAGE 2650000 72#define LDO_C_VOLTAGE 2650000
81#define LDO_D_VOLTAGE 2650000 73#define LDO_D_VOLTAGE 2650000
82 74
83static const int ldo_e_buck_typ_voltages[] = { 75static const unsigned int ldo_e_buck_typ_voltages[] = {
84 1800000, 76 1800000,
85 1400000, 77 1400000,
86 1300000, 78 1300000,
@@ -90,7 +82,7 @@ static const int ldo_e_buck_typ_voltages[] = {
90 900000, 82 900000,
91}; 83};
92 84
93static const int ldo_f_typ_voltages[] = { 85static const unsigned int ldo_f_typ_voltages[] = {
94 1800000, 86 1800000,
95 1400000, 87 1400000,
96 1300000, 88 1300000,
@@ -101,21 +93,21 @@ static const int ldo_f_typ_voltages[] = {
101 2650000, 93 2650000,
102}; 94};
103 95
104static const int ldo_g_typ_voltages[] = { 96static const unsigned int ldo_g_typ_voltages[] = {
105 2850000, 97 2850000,
106 2750000, 98 2750000,
107 1800000, 99 1800000,
108 1500000, 100 1500000,
109}; 101};
110 102
111static const int ldo_h_typ_voltages[] = { 103static const unsigned int ldo_h_typ_voltages[] = {
112 2750000, 104 2750000,
113 1800000, 105 1800000,
114 1500000, 106 1500000,
115 1200000, 107 1200000,
116}; 108};
117 109
118static const int ldo_k_typ_voltages[] = { 110static const unsigned int ldo_k_typ_voltages[] = {
119 2750000, 111 2750000,
120 1800000, 112 1800000,
121}; 113};
@@ -126,40 +118,27 @@ static struct ab3100_regulator
126ab3100_regulators[AB3100_NUM_REGULATORS] = { 118ab3100_regulators[AB3100_NUM_REGULATORS] = {
127 { 119 {
128 .regreg = AB3100_LDO_A, 120 .regreg = AB3100_LDO_A,
129 .fixed_voltage = LDO_A_VOLTAGE,
130 }, 121 },
131 { 122 {
132 .regreg = AB3100_LDO_C, 123 .regreg = AB3100_LDO_C,
133 .fixed_voltage = LDO_C_VOLTAGE,
134 }, 124 },
135 { 125 {
136 .regreg = AB3100_LDO_D, 126 .regreg = AB3100_LDO_D,
137 .fixed_voltage = LDO_D_VOLTAGE,
138 }, 127 },
139 { 128 {
140 .regreg = AB3100_LDO_E, 129 .regreg = AB3100_LDO_E,
141 .typ_voltages = ldo_e_buck_typ_voltages,
142 .voltages_len = ARRAY_SIZE(ldo_e_buck_typ_voltages),
143 }, 130 },
144 { 131 {
145 .regreg = AB3100_LDO_F, 132 .regreg = AB3100_LDO_F,
146 .typ_voltages = ldo_f_typ_voltages,
147 .voltages_len = ARRAY_SIZE(ldo_f_typ_voltages),
148 }, 133 },
149 { 134 {
150 .regreg = AB3100_LDO_G, 135 .regreg = AB3100_LDO_G,
151 .typ_voltages = ldo_g_typ_voltages,
152 .voltages_len = ARRAY_SIZE(ldo_g_typ_voltages),
153 }, 136 },
154 { 137 {
155 .regreg = AB3100_LDO_H, 138 .regreg = AB3100_LDO_H,
156 .typ_voltages = ldo_h_typ_voltages,
157 .voltages_len = ARRAY_SIZE(ldo_h_typ_voltages),
158 }, 139 },
159 { 140 {
160 .regreg = AB3100_LDO_K, 141 .regreg = AB3100_LDO_K,
161 .typ_voltages = ldo_k_typ_voltages,
162 .voltages_len = ARRAY_SIZE(ldo_k_typ_voltages),
163 }, 142 },
164 { 143 {
165 .regreg = AB3100_LDO_EXT, 144 .regreg = AB3100_LDO_EXT,
@@ -167,8 +146,6 @@ ab3100_regulators[AB3100_NUM_REGULATORS] = {
167 }, 146 },
168 { 147 {
169 .regreg = AB3100_BUCK, 148 .regreg = AB3100_BUCK,
170 .typ_voltages = ldo_e_buck_typ_voltages,
171 .voltages_len = ARRAY_SIZE(ldo_e_buck_typ_voltages),
172 }, 149 },
173}; 150};
174 151
@@ -178,7 +155,7 @@ ab3100_regulators[AB3100_NUM_REGULATORS] = {
178 */ 155 */
179static int ab3100_enable_regulator(struct regulator_dev *reg) 156static int ab3100_enable_regulator(struct regulator_dev *reg)
180{ 157{
181 struct ab3100_regulator *abreg = reg->reg_data; 158 struct ab3100_regulator *abreg = rdev_get_drvdata(reg);
182 int err; 159 int err;
183 u8 regval; 160 u8 regval;
184 161
@@ -209,7 +186,7 @@ static int ab3100_enable_regulator(struct regulator_dev *reg)
209 186
210static int ab3100_disable_regulator(struct regulator_dev *reg) 187static int ab3100_disable_regulator(struct regulator_dev *reg)
211{ 188{
212 struct ab3100_regulator *abreg = reg->reg_data; 189 struct ab3100_regulator *abreg = rdev_get_drvdata(reg);
213 int err; 190 int err;
214 u8 regval; 191 u8 regval;
215 192
@@ -242,7 +219,7 @@ static int ab3100_disable_regulator(struct regulator_dev *reg)
242 219
243static int ab3100_is_enabled_regulator(struct regulator_dev *reg) 220static int ab3100_is_enabled_regulator(struct regulator_dev *reg)
244{ 221{
245 struct ab3100_regulator *abreg = reg->reg_data; 222 struct ab3100_regulator *abreg = rdev_get_drvdata(reg);
246 u8 regval; 223 u8 regval;
247 int err; 224 int err;
248 225
@@ -257,26 +234,12 @@ static int ab3100_is_enabled_regulator(struct regulator_dev *reg)
257 return regval & AB3100_REG_ON_MASK; 234 return regval & AB3100_REG_ON_MASK;
258} 235}
259 236
260static int ab3100_list_voltage_regulator(struct regulator_dev *reg,
261 unsigned selector)
262{
263 struct ab3100_regulator *abreg = reg->reg_data;
264
265 if (selector >= abreg->voltages_len)
266 return -EINVAL;
267 return abreg->typ_voltages[selector];
268}
269
270static int ab3100_get_voltage_regulator(struct regulator_dev *reg) 237static int ab3100_get_voltage_regulator(struct regulator_dev *reg)
271{ 238{
272 struct ab3100_regulator *abreg = reg->reg_data; 239 struct ab3100_regulator *abreg = rdev_get_drvdata(reg);
273 u8 regval; 240 u8 regval;
274 int err; 241 int err;
275 242
276 /* Return the voltage for fixed regulators immediately */
277 if (abreg->fixed_voltage)
278 return abreg->fixed_voltage;
279
280 /* 243 /*
281 * For variable types, read out setting and index into 244 * For variable types, read out setting and index into
282 * supplied voltage list. 245 * supplied voltage list.
@@ -294,20 +257,20 @@ static int ab3100_get_voltage_regulator(struct regulator_dev *reg)
294 regval &= 0xE0; 257 regval &= 0xE0;
295 regval >>= 5; 258 regval >>= 5;
296 259
297 if (regval >= abreg->voltages_len) { 260 if (regval >= reg->desc->n_voltages) {
298 dev_err(&reg->dev, 261 dev_err(&reg->dev,
299 "regulator register %02x contains an illegal voltage setting\n", 262 "regulator register %02x contains an illegal voltage setting\n",
300 abreg->regreg); 263 abreg->regreg);
301 return -EINVAL; 264 return -EINVAL;
302 } 265 }
303 266
304 return abreg->typ_voltages[regval]; 267 return reg->desc->volt_table[regval];
305} 268}
306 269
307static int ab3100_set_voltage_regulator_sel(struct regulator_dev *reg, 270static int ab3100_set_voltage_regulator_sel(struct regulator_dev *reg,
308 unsigned selector) 271 unsigned selector)
309{ 272{
310 struct ab3100_regulator *abreg = reg->reg_data; 273 struct ab3100_regulator *abreg = rdev_get_drvdata(reg);
311 u8 regval; 274 u8 regval;
312 int err; 275 int err;
313 276
@@ -336,7 +299,7 @@ static int ab3100_set_voltage_regulator_sel(struct regulator_dev *reg,
336static int ab3100_set_suspend_voltage_regulator(struct regulator_dev *reg, 299static int ab3100_set_suspend_voltage_regulator(struct regulator_dev *reg,
337 int uV) 300 int uV)
338{ 301{
339 struct ab3100_regulator *abreg = reg->reg_data; 302 struct ab3100_regulator *abreg = rdev_get_drvdata(reg);
340 u8 regval; 303 u8 regval;
341 int err; 304 int err;
342 int bestindex; 305 int bestindex;
@@ -379,42 +342,22 @@ static int ab3100_set_suspend_voltage_regulator(struct regulator_dev *reg,
379 */ 342 */
380static int ab3100_get_voltage_regulator_external(struct regulator_dev *reg) 343static int ab3100_get_voltage_regulator_external(struct regulator_dev *reg)
381{ 344{
382 struct ab3100_regulator *abreg = reg->reg_data; 345 struct ab3100_regulator *abreg = rdev_get_drvdata(reg);
383 346
384 return abreg->plfdata->external_voltage; 347 return abreg->plfdata->external_voltage;
385} 348}
386 349
387static int ab3100_enable_time_regulator(struct regulator_dev *reg) 350static int ab3100_get_fixed_voltage_regulator(struct regulator_dev *reg)
388{ 351{
389 struct ab3100_regulator *abreg = reg->reg_data; 352 return reg->desc->min_uV;
390
391 /* Per-regulator power on delay from spec */
392 switch (abreg->regreg) {
393 case AB3100_LDO_A: /* Fallthrough */
394 case AB3100_LDO_C: /* Fallthrough */
395 case AB3100_LDO_D: /* Fallthrough */
396 case AB3100_LDO_E: /* Fallthrough */
397 case AB3100_LDO_H: /* Fallthrough */
398 case AB3100_LDO_K:
399 return 200;
400 case AB3100_LDO_F:
401 return 600;
402 case AB3100_LDO_G:
403 return 400;
404 case AB3100_BUCK:
405 return 1000;
406 default:
407 break;
408 }
409 return 0;
410} 353}
411 354
412static struct regulator_ops regulator_ops_fixed = { 355static struct regulator_ops regulator_ops_fixed = {
356 .list_voltage = regulator_list_voltage_linear,
413 .enable = ab3100_enable_regulator, 357 .enable = ab3100_enable_regulator,
414 .disable = ab3100_disable_regulator, 358 .disable = ab3100_disable_regulator,
415 .is_enabled = ab3100_is_enabled_regulator, 359 .is_enabled = ab3100_is_enabled_regulator,
416 .get_voltage = ab3100_get_voltage_regulator, 360 .get_voltage = ab3100_get_fixed_voltage_regulator,
417 .enable_time = ab3100_enable_time_regulator,
418}; 361};
419 362
420static struct regulator_ops regulator_ops_variable = { 363static struct regulator_ops regulator_ops_variable = {
@@ -423,8 +366,7 @@ static struct regulator_ops regulator_ops_variable = {
423 .is_enabled = ab3100_is_enabled_regulator, 366 .is_enabled = ab3100_is_enabled_regulator,
424 .get_voltage = ab3100_get_voltage_regulator, 367 .get_voltage = ab3100_get_voltage_regulator,
425 .set_voltage_sel = ab3100_set_voltage_regulator_sel, 368 .set_voltage_sel = ab3100_set_voltage_regulator_sel,
426 .list_voltage = ab3100_list_voltage_regulator, 369 .list_voltage = regulator_list_voltage_table,
427 .enable_time = ab3100_enable_time_regulator,
428}; 370};
429 371
430static struct regulator_ops regulator_ops_variable_sleepable = { 372static struct regulator_ops regulator_ops_variable_sleepable = {
@@ -434,8 +376,7 @@ static struct regulator_ops regulator_ops_variable_sleepable = {
434 .get_voltage = ab3100_get_voltage_regulator, 376 .get_voltage = ab3100_get_voltage_regulator,
435 .set_voltage_sel = ab3100_set_voltage_regulator_sel, 377 .set_voltage_sel = ab3100_set_voltage_regulator_sel,
436 .set_suspend_voltage = ab3100_set_suspend_voltage_regulator, 378 .set_suspend_voltage = ab3100_set_suspend_voltage_regulator,
437 .list_voltage = ab3100_list_voltage_regulator, 379 .list_voltage = regulator_list_voltage_table,
438 .enable_time = ab3100_enable_time_regulator,
439}; 380};
440 381
441/* 382/*
@@ -457,62 +398,81 @@ ab3100_regulator_desc[AB3100_NUM_REGULATORS] = {
457 .name = "LDO_A", 398 .name = "LDO_A",
458 .id = AB3100_LDO_A, 399 .id = AB3100_LDO_A,
459 .ops = &regulator_ops_fixed, 400 .ops = &regulator_ops_fixed,
401 .n_voltages = 1,
460 .type = REGULATOR_VOLTAGE, 402 .type = REGULATOR_VOLTAGE,
461 .owner = THIS_MODULE, 403 .owner = THIS_MODULE,
404 .min_uV = LDO_A_VOLTAGE,
405 .enable_time = 200,
462 }, 406 },
463 { 407 {
464 .name = "LDO_C", 408 .name = "LDO_C",
465 .id = AB3100_LDO_C, 409 .id = AB3100_LDO_C,
466 .ops = &regulator_ops_fixed, 410 .ops = &regulator_ops_fixed,
411 .n_voltages = 1,
467 .type = REGULATOR_VOLTAGE, 412 .type = REGULATOR_VOLTAGE,
468 .owner = THIS_MODULE, 413 .owner = THIS_MODULE,
414 .min_uV = LDO_C_VOLTAGE,
415 .enable_time = 200,
469 }, 416 },
470 { 417 {
471 .name = "LDO_D", 418 .name = "LDO_D",
472 .id = AB3100_LDO_D, 419 .id = AB3100_LDO_D,
473 .ops = &regulator_ops_fixed, 420 .ops = &regulator_ops_fixed,
421 .n_voltages = 1,
474 .type = REGULATOR_VOLTAGE, 422 .type = REGULATOR_VOLTAGE,
475 .owner = THIS_MODULE, 423 .owner = THIS_MODULE,
424 .min_uV = LDO_D_VOLTAGE,
425 .enable_time = 200,
476 }, 426 },
477 { 427 {
478 .name = "LDO_E", 428 .name = "LDO_E",
479 .id = AB3100_LDO_E, 429 .id = AB3100_LDO_E,
480 .ops = &regulator_ops_variable_sleepable, 430 .ops = &regulator_ops_variable_sleepable,
481 .n_voltages = ARRAY_SIZE(ldo_e_buck_typ_voltages), 431 .n_voltages = ARRAY_SIZE(ldo_e_buck_typ_voltages),
432 .volt_table = ldo_e_buck_typ_voltages,
482 .type = REGULATOR_VOLTAGE, 433 .type = REGULATOR_VOLTAGE,
483 .owner = THIS_MODULE, 434 .owner = THIS_MODULE,
435 .enable_time = 200,
484 }, 436 },
485 { 437 {
486 .name = "LDO_F", 438 .name = "LDO_F",
487 .id = AB3100_LDO_F, 439 .id = AB3100_LDO_F,
488 .ops = &regulator_ops_variable, 440 .ops = &regulator_ops_variable,
489 .n_voltages = ARRAY_SIZE(ldo_f_typ_voltages), 441 .n_voltages = ARRAY_SIZE(ldo_f_typ_voltages),
442 .volt_table = ldo_f_typ_voltages,
490 .type = REGULATOR_VOLTAGE, 443 .type = REGULATOR_VOLTAGE,
491 .owner = THIS_MODULE, 444 .owner = THIS_MODULE,
445 .enable_time = 600,
492 }, 446 },
493 { 447 {
494 .name = "LDO_G", 448 .name = "LDO_G",
495 .id = AB3100_LDO_G, 449 .id = AB3100_LDO_G,
496 .ops = &regulator_ops_variable, 450 .ops = &regulator_ops_variable,
497 .n_voltages = ARRAY_SIZE(ldo_g_typ_voltages), 451 .n_voltages = ARRAY_SIZE(ldo_g_typ_voltages),
452 .volt_table = ldo_g_typ_voltages,
498 .type = REGULATOR_VOLTAGE, 453 .type = REGULATOR_VOLTAGE,
499 .owner = THIS_MODULE, 454 .owner = THIS_MODULE,
455 .enable_time = 400,
500 }, 456 },
501 { 457 {
502 .name = "LDO_H", 458 .name = "LDO_H",
503 .id = AB3100_LDO_H, 459 .id = AB3100_LDO_H,
504 .ops = &regulator_ops_variable, 460 .ops = &regulator_ops_variable,
505 .n_voltages = ARRAY_SIZE(ldo_h_typ_voltages), 461 .n_voltages = ARRAY_SIZE(ldo_h_typ_voltages),
462 .volt_table = ldo_h_typ_voltages,
506 .type = REGULATOR_VOLTAGE, 463 .type = REGULATOR_VOLTAGE,
507 .owner = THIS_MODULE, 464 .owner = THIS_MODULE,
465 .enable_time = 200,
508 }, 466 },
509 { 467 {
510 .name = "LDO_K", 468 .name = "LDO_K",
511 .id = AB3100_LDO_K, 469 .id = AB3100_LDO_K,
512 .ops = &regulator_ops_variable, 470 .ops = &regulator_ops_variable,
513 .n_voltages = ARRAY_SIZE(ldo_k_typ_voltages), 471 .n_voltages = ARRAY_SIZE(ldo_k_typ_voltages),
472 .volt_table = ldo_k_typ_voltages,
514 .type = REGULATOR_VOLTAGE, 473 .type = REGULATOR_VOLTAGE,
515 .owner = THIS_MODULE, 474 .owner = THIS_MODULE,
475 .enable_time = 200,
516 }, 476 },
517 { 477 {
518 .name = "LDO_EXT", 478 .name = "LDO_EXT",
@@ -528,6 +488,7 @@ ab3100_regulator_desc[AB3100_NUM_REGULATORS] = {
528 .n_voltages = ARRAY_SIZE(ldo_e_buck_typ_voltages), 488 .n_voltages = ARRAY_SIZE(ldo_e_buck_typ_voltages),
529 .type = REGULATOR_VOLTAGE, 489 .type = REGULATOR_VOLTAGE,
530 .owner = THIS_MODULE, 490 .owner = THIS_MODULE,
491 .enable_time = 1000,
531 }, 492 },
532}; 493};
533 494
diff --git a/drivers/regulator/ab8500.c b/drivers/regulator/ab8500.c
index a739f5ca936a..13d424fc1c14 100644
--- a/drivers/regulator/ab8500.c
+++ b/drivers/regulator/ab8500.c
@@ -30,9 +30,6 @@
30 * @dev: device pointer 30 * @dev: device pointer
31 * @desc: regulator description 31 * @desc: regulator description
32 * @regulator_dev: regulator device 32 * @regulator_dev: regulator device
33 * @max_uV: maximum voltage (for variable voltage supplies)
34 * @min_uV: minimum voltage (for variable voltage supplies)
35 * @fixed_uV: typical voltage (for fixed voltage supplies)
36 * @update_bank: bank to control on/off 33 * @update_bank: bank to control on/off
37 * @update_reg: register to control on/off 34 * @update_reg: register to control on/off
38 * @update_mask: mask to enable/disable regulator 35 * @update_mask: mask to enable/disable regulator
@@ -40,17 +37,12 @@
40 * @voltage_bank: bank to control regulator voltage 37 * @voltage_bank: bank to control regulator voltage
41 * @voltage_reg: register to control regulator voltage 38 * @voltage_reg: register to control regulator voltage
42 * @voltage_mask: mask to control regulator voltage 39 * @voltage_mask: mask to control regulator voltage
43 * @voltages: supported voltage table
44 * @voltages_len: number of supported voltages for the regulator
45 * @delay: startup/set voltage delay in us 40 * @delay: startup/set voltage delay in us
46 */ 41 */
47struct ab8500_regulator_info { 42struct ab8500_regulator_info {
48 struct device *dev; 43 struct device *dev;
49 struct regulator_desc desc; 44 struct regulator_desc desc;
50 struct regulator_dev *regulator; 45 struct regulator_dev *regulator;
51 int max_uV;
52 int min_uV;
53 int fixed_uV;
54 u8 update_bank; 46 u8 update_bank;
55 u8 update_reg; 47 u8 update_reg;
56 u8 update_mask; 48 u8 update_mask;
@@ -58,13 +50,11 @@ struct ab8500_regulator_info {
58 u8 voltage_bank; 50 u8 voltage_bank;
59 u8 voltage_reg; 51 u8 voltage_reg;
60 u8 voltage_mask; 52 u8 voltage_mask;
61 int const *voltages;
62 int voltages_len;
63 unsigned int delay; 53 unsigned int delay;
64}; 54};
65 55
66/* voltage tables for the vauxn/vintcore supplies */ 56/* voltage tables for the vauxn/vintcore supplies */
67static const int ldo_vauxn_voltages[] = { 57static const unsigned int ldo_vauxn_voltages[] = {
68 1100000, 58 1100000,
69 1200000, 59 1200000,
70 1300000, 60 1300000,
@@ -83,7 +73,7 @@ static const int ldo_vauxn_voltages[] = {
83 3300000, 73 3300000,
84}; 74};
85 75
86static const int ldo_vaux3_voltages[] = { 76static const unsigned int ldo_vaux3_voltages[] = {
87 1200000, 77 1200000,
88 1500000, 78 1500000,
89 1800000, 79 1800000,
@@ -94,7 +84,7 @@ static const int ldo_vaux3_voltages[] = {
94 2910000, 84 2910000,
95}; 85};
96 86
97static const int ldo_vintcore_voltages[] = { 87static const unsigned int ldo_vintcore_voltages[] = {
98 1200000, 88 1200000,
99 1225000, 89 1225000,
100 1250000, 90 1250000,
@@ -185,25 +175,6 @@ static int ab8500_regulator_is_enabled(struct regulator_dev *rdev)
185 return false; 175 return false;
186} 176}
187 177
188static int ab8500_list_voltage(struct regulator_dev *rdev, unsigned selector)
189{
190 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
191
192 if (info == NULL) {
193 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
194 return -EINVAL;
195 }
196
197 /* return the uV for the fixed regulators */
198 if (info->fixed_uV)
199 return info->fixed_uV;
200
201 if (selector >= info->voltages_len)
202 return -EINVAL;
203
204 return info->voltages[selector];
205}
206
207static int ab8500_regulator_get_voltage_sel(struct regulator_dev *rdev) 178static int ab8500_regulator_get_voltage_sel(struct regulator_dev *rdev)
208{ 179{
209 int ret, val; 180 int ret, val;
@@ -279,14 +250,7 @@ static int ab8500_regulator_set_voltage_time_sel(struct regulator_dev *rdev,
279 unsigned int new_sel) 250 unsigned int new_sel)
280{ 251{
281 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); 252 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
282 int ret;
283 253
284 /* If the regulator isn't on, it won't take time here */
285 ret = ab8500_regulator_is_enabled(rdev);
286 if (ret < 0)
287 return ret;
288 if (!ret)
289 return 0;
290 return info->delay; 254 return info->delay;
291} 255}
292 256
@@ -296,21 +260,14 @@ static struct regulator_ops ab8500_regulator_ops = {
296 .is_enabled = ab8500_regulator_is_enabled, 260 .is_enabled = ab8500_regulator_is_enabled,
297 .get_voltage_sel = ab8500_regulator_get_voltage_sel, 261 .get_voltage_sel = ab8500_regulator_get_voltage_sel,
298 .set_voltage_sel = ab8500_regulator_set_voltage_sel, 262 .set_voltage_sel = ab8500_regulator_set_voltage_sel,
299 .list_voltage = ab8500_list_voltage, 263 .list_voltage = regulator_list_voltage_table,
300 .enable_time = ab8500_regulator_enable_time, 264 .enable_time = ab8500_regulator_enable_time,
301 .set_voltage_time_sel = ab8500_regulator_set_voltage_time_sel, 265 .set_voltage_time_sel = ab8500_regulator_set_voltage_time_sel,
302}; 266};
303 267
304static int ab8500_fixed_get_voltage(struct regulator_dev *rdev) 268static int ab8500_fixed_get_voltage(struct regulator_dev *rdev)
305{ 269{
306 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); 270 return rdev->desc->min_uV;
307
308 if (info == NULL) {
309 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
310 return -EINVAL;
311 }
312
313 return info->fixed_uV;
314} 271}
315 272
316static struct regulator_ops ab8500_regulator_fixed_ops = { 273static struct regulator_ops ab8500_regulator_fixed_ops = {
@@ -318,9 +275,8 @@ static struct regulator_ops ab8500_regulator_fixed_ops = {
318 .disable = ab8500_regulator_disable, 275 .disable = ab8500_regulator_disable,
319 .is_enabled = ab8500_regulator_is_enabled, 276 .is_enabled = ab8500_regulator_is_enabled,
320 .get_voltage = ab8500_fixed_get_voltage, 277 .get_voltage = ab8500_fixed_get_voltage,
321 .list_voltage = ab8500_list_voltage, 278 .list_voltage = regulator_list_voltage_linear,
322 .enable_time = ab8500_regulator_enable_time, 279 .enable_time = ab8500_regulator_enable_time,
323 .set_voltage_time_sel = ab8500_regulator_set_voltage_time_sel,
324}; 280};
325 281
326static struct ab8500_regulator_info 282static struct ab8500_regulator_info
@@ -329,7 +285,7 @@ static struct ab8500_regulator_info
329 * Variable Voltage Regulators 285 * Variable Voltage Regulators
330 * name, min mV, max mV, 286 * name, min mV, max mV,
331 * update bank, reg, mask, enable val 287 * update bank, reg, mask, enable val
332 * volt bank, reg, mask, table, table length 288 * volt bank, reg, mask
333 */ 289 */
334 [AB8500_LDO_AUX1] = { 290 [AB8500_LDO_AUX1] = {
335 .desc = { 291 .desc = {
@@ -339,9 +295,8 @@ static struct ab8500_regulator_info
339 .id = AB8500_LDO_AUX1, 295 .id = AB8500_LDO_AUX1,
340 .owner = THIS_MODULE, 296 .owner = THIS_MODULE,
341 .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages), 297 .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages),
298 .volt_table = ldo_vauxn_voltages,
342 }, 299 },
343 .min_uV = 1100000,
344 .max_uV = 3300000,
345 .update_bank = 0x04, 300 .update_bank = 0x04,
346 .update_reg = 0x09, 301 .update_reg = 0x09,
347 .update_mask = 0x03, 302 .update_mask = 0x03,
@@ -349,8 +304,6 @@ static struct ab8500_regulator_info
349 .voltage_bank = 0x04, 304 .voltage_bank = 0x04,
350 .voltage_reg = 0x1f, 305 .voltage_reg = 0x1f,
351 .voltage_mask = 0x0f, 306 .voltage_mask = 0x0f,
352 .voltages = ldo_vauxn_voltages,
353 .voltages_len = ARRAY_SIZE(ldo_vauxn_voltages),
354 }, 307 },
355 [AB8500_LDO_AUX2] = { 308 [AB8500_LDO_AUX2] = {
356 .desc = { 309 .desc = {
@@ -360,9 +313,8 @@ static struct ab8500_regulator_info
360 .id = AB8500_LDO_AUX2, 313 .id = AB8500_LDO_AUX2,
361 .owner = THIS_MODULE, 314 .owner = THIS_MODULE,
362 .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages), 315 .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages),
316 .volt_table = ldo_vauxn_voltages,
363 }, 317 },
364 .min_uV = 1100000,
365 .max_uV = 3300000,
366 .update_bank = 0x04, 318 .update_bank = 0x04,
367 .update_reg = 0x09, 319 .update_reg = 0x09,
368 .update_mask = 0x0c, 320 .update_mask = 0x0c,
@@ -370,8 +322,6 @@ static struct ab8500_regulator_info
370 .voltage_bank = 0x04, 322 .voltage_bank = 0x04,
371 .voltage_reg = 0x20, 323 .voltage_reg = 0x20,
372 .voltage_mask = 0x0f, 324 .voltage_mask = 0x0f,
373 .voltages = ldo_vauxn_voltages,
374 .voltages_len = ARRAY_SIZE(ldo_vauxn_voltages),
375 }, 325 },
376 [AB8500_LDO_AUX3] = { 326 [AB8500_LDO_AUX3] = {
377 .desc = { 327 .desc = {
@@ -381,9 +331,8 @@ static struct ab8500_regulator_info
381 .id = AB8500_LDO_AUX3, 331 .id = AB8500_LDO_AUX3,
382 .owner = THIS_MODULE, 332 .owner = THIS_MODULE,
383 .n_voltages = ARRAY_SIZE(ldo_vaux3_voltages), 333 .n_voltages = ARRAY_SIZE(ldo_vaux3_voltages),
334 .volt_table = ldo_vaux3_voltages,
384 }, 335 },
385 .min_uV = 1100000,
386 .max_uV = 3300000,
387 .update_bank = 0x04, 336 .update_bank = 0x04,
388 .update_reg = 0x0a, 337 .update_reg = 0x0a,
389 .update_mask = 0x03, 338 .update_mask = 0x03,
@@ -391,8 +340,6 @@ static struct ab8500_regulator_info
391 .voltage_bank = 0x04, 340 .voltage_bank = 0x04,
392 .voltage_reg = 0x21, 341 .voltage_reg = 0x21,
393 .voltage_mask = 0x07, 342 .voltage_mask = 0x07,
394 .voltages = ldo_vaux3_voltages,
395 .voltages_len = ARRAY_SIZE(ldo_vaux3_voltages),
396 }, 343 },
397 [AB8500_LDO_INTCORE] = { 344 [AB8500_LDO_INTCORE] = {
398 .desc = { 345 .desc = {
@@ -402,9 +349,8 @@ static struct ab8500_regulator_info
402 .id = AB8500_LDO_INTCORE, 349 .id = AB8500_LDO_INTCORE,
403 .owner = THIS_MODULE, 350 .owner = THIS_MODULE,
404 .n_voltages = ARRAY_SIZE(ldo_vintcore_voltages), 351 .n_voltages = ARRAY_SIZE(ldo_vintcore_voltages),
352 .volt_table = ldo_vintcore_voltages,
405 }, 353 },
406 .min_uV = 1100000,
407 .max_uV = 3300000,
408 .update_bank = 0x03, 354 .update_bank = 0x03,
409 .update_reg = 0x80, 355 .update_reg = 0x80,
410 .update_mask = 0x44, 356 .update_mask = 0x44,
@@ -412,8 +358,6 @@ static struct ab8500_regulator_info
412 .voltage_bank = 0x03, 358 .voltage_bank = 0x03,
413 .voltage_reg = 0x80, 359 .voltage_reg = 0x80,
414 .voltage_mask = 0x38, 360 .voltage_mask = 0x38,
415 .voltages = ldo_vintcore_voltages,
416 .voltages_len = ARRAY_SIZE(ldo_vintcore_voltages),
417 }, 361 },
418 362
419 /* 363 /*
@@ -429,9 +373,9 @@ static struct ab8500_regulator_info
429 .id = AB8500_LDO_TVOUT, 373 .id = AB8500_LDO_TVOUT,
430 .owner = THIS_MODULE, 374 .owner = THIS_MODULE,
431 .n_voltages = 1, 375 .n_voltages = 1,
376 .min_uV = 2000000,
432 }, 377 },
433 .delay = 10000, 378 .delay = 10000,
434 .fixed_uV = 2000000,
435 .update_bank = 0x03, 379 .update_bank = 0x03,
436 .update_reg = 0x80, 380 .update_reg = 0x80,
437 .update_mask = 0x82, 381 .update_mask = 0x82,
@@ -445,8 +389,8 @@ static struct ab8500_regulator_info
445 .id = AB8500_LDO_USB, 389 .id = AB8500_LDO_USB,
446 .owner = THIS_MODULE, 390 .owner = THIS_MODULE,
447 .n_voltages = 1, 391 .n_voltages = 1,
392 .min_uV = 3300000,
448 }, 393 },
449 .fixed_uV = 3300000,
450 .update_bank = 0x03, 394 .update_bank = 0x03,
451 .update_reg = 0x82, 395 .update_reg = 0x82,
452 .update_mask = 0x03, 396 .update_mask = 0x03,
@@ -460,8 +404,8 @@ static struct ab8500_regulator_info
460 .id = AB8500_LDO_AUDIO, 404 .id = AB8500_LDO_AUDIO,
461 .owner = THIS_MODULE, 405 .owner = THIS_MODULE,
462 .n_voltages = 1, 406 .n_voltages = 1,
407 .min_uV = 2000000,
463 }, 408 },
464 .fixed_uV = 2000000,
465 .update_bank = 0x03, 409 .update_bank = 0x03,
466 .update_reg = 0x83, 410 .update_reg = 0x83,
467 .update_mask = 0x02, 411 .update_mask = 0x02,
@@ -475,8 +419,8 @@ static struct ab8500_regulator_info
475 .id = AB8500_LDO_ANAMIC1, 419 .id = AB8500_LDO_ANAMIC1,
476 .owner = THIS_MODULE, 420 .owner = THIS_MODULE,
477 .n_voltages = 1, 421 .n_voltages = 1,
422 .min_uV = 2050000,
478 }, 423 },
479 .fixed_uV = 2050000,
480 .update_bank = 0x03, 424 .update_bank = 0x03,
481 .update_reg = 0x83, 425 .update_reg = 0x83,
482 .update_mask = 0x08, 426 .update_mask = 0x08,
@@ -490,8 +434,8 @@ static struct ab8500_regulator_info
490 .id = AB8500_LDO_ANAMIC2, 434 .id = AB8500_LDO_ANAMIC2,
491 .owner = THIS_MODULE, 435 .owner = THIS_MODULE,
492 .n_voltages = 1, 436 .n_voltages = 1,
437 .min_uV = 2050000,
493 }, 438 },
494 .fixed_uV = 2050000,
495 .update_bank = 0x03, 439 .update_bank = 0x03,
496 .update_reg = 0x83, 440 .update_reg = 0x83,
497 .update_mask = 0x10, 441 .update_mask = 0x10,
@@ -505,8 +449,8 @@ static struct ab8500_regulator_info
505 .id = AB8500_LDO_DMIC, 449 .id = AB8500_LDO_DMIC,
506 .owner = THIS_MODULE, 450 .owner = THIS_MODULE,
507 .n_voltages = 1, 451 .n_voltages = 1,
452 .min_uV = 1800000,
508 }, 453 },
509 .fixed_uV = 1800000,
510 .update_bank = 0x03, 454 .update_bank = 0x03,
511 .update_reg = 0x83, 455 .update_reg = 0x83,
512 .update_mask = 0x04, 456 .update_mask = 0x04,
@@ -520,8 +464,8 @@ static struct ab8500_regulator_info
520 .id = AB8500_LDO_ANA, 464 .id = AB8500_LDO_ANA,
521 .owner = THIS_MODULE, 465 .owner = THIS_MODULE,
522 .n_voltages = 1, 466 .n_voltages = 1,
467 .min_uV = 1200000,
523 }, 468 },
524 .fixed_uV = 1200000,
525 .update_bank = 0x04, 469 .update_bank = 0x04,
526 .update_reg = 0x06, 470 .update_reg = 0x06,
527 .update_mask = 0x0c, 471 .update_mask = 0x0c,
@@ -769,9 +713,7 @@ static __devinit int ab8500_regulator_register(struct platform_device *pdev,
769 if (info->desc.id == AB8500_LDO_AUX3) { 713 if (info->desc.id == AB8500_LDO_AUX3) {
770 info->desc.n_voltages = 714 info->desc.n_voltages =
771 ARRAY_SIZE(ldo_vauxn_voltages); 715 ARRAY_SIZE(ldo_vauxn_voltages);
772 info->voltages = ldo_vauxn_voltages; 716 info->desc.volt_table = ldo_vauxn_voltages;
773 info->voltages_len =
774 ARRAY_SIZE(ldo_vauxn_voltages);
775 info->voltage_mask = 0xf; 717 info->voltage_mask = 0xf;
776 } 718 }
777 } 719 }
diff --git a/drivers/regulator/ad5398.c b/drivers/regulator/ad5398.c
index 46d05f38baf8..f123f7e3b752 100644
--- a/drivers/regulator/ad5398.c
+++ b/drivers/regulator/ad5398.c
@@ -89,9 +89,12 @@ static int ad5398_set_current_limit(struct regulator_dev *rdev, int min_uA, int
89 unsigned short data; 89 unsigned short data;
90 int ret; 90 int ret;
91 91
92 if (min_uA > chip->max_uA || min_uA < chip->min_uA) 92 if (min_uA < chip->min_uA)
93 return -EINVAL; 93 min_uA = chip->min_uA;
94 if (max_uA > chip->max_uA || max_uA < chip->min_uA) 94 if (max_uA > chip->max_uA)
95 max_uA = chip->max_uA;
96
97 if (min_uA > chip->max_uA || max_uA < chip->min_uA)
95 return -EINVAL; 98 return -EINVAL;
96 99
97 selector = DIV_ROUND_UP((min_uA - chip->min_uA) * chip->current_level, 100 selector = DIV_ROUND_UP((min_uA - chip->min_uA) * chip->current_level,
diff --git a/drivers/regulator/anatop-regulator.c b/drivers/regulator/anatop-regulator.c
index e82e7eaac0f1..e9c2085f9dfb 100644
--- a/drivers/regulator/anatop-regulator.c
+++ b/drivers/regulator/anatop-regulator.c
@@ -43,33 +43,15 @@ struct anatop_regulator {
43 struct regulator_init_data *initdata; 43 struct regulator_init_data *initdata;
44}; 44};
45 45
46static int anatop_set_voltage(struct regulator_dev *reg, int min_uV, 46static int anatop_set_voltage_sel(struct regulator_dev *reg, unsigned selector)
47 int max_uV, unsigned *selector)
48{ 47{
49 struct anatop_regulator *anatop_reg = rdev_get_drvdata(reg); 48 struct anatop_regulator *anatop_reg = rdev_get_drvdata(reg);
50 u32 val, sel, mask; 49 u32 val, mask;
51 int uv;
52
53 uv = min_uV;
54 dev_dbg(&reg->dev, "%s: uv %d, min %d, max %d\n", __func__,
55 uv, anatop_reg->min_voltage,
56 anatop_reg->max_voltage);
57
58 if (uv < anatop_reg->min_voltage) {
59 if (max_uV > anatop_reg->min_voltage)
60 uv = anatop_reg->min_voltage;
61 else
62 return -EINVAL;
63 }
64 50
65 if (!anatop_reg->control_reg) 51 if (!anatop_reg->control_reg)
66 return -ENOTSUPP; 52 return -ENOTSUPP;
67 53
68 sel = DIV_ROUND_UP(uv - anatop_reg->min_voltage, 25000); 54 val = anatop_reg->min_bit_val + selector;
69 if (sel * 25000 + anatop_reg->min_voltage > anatop_reg->max_voltage)
70 return -EINVAL;
71 val = anatop_reg->min_bit_val + sel;
72 *selector = sel;
73 dev_dbg(&reg->dev, "%s: calculated val %d\n", __func__, val); 55 dev_dbg(&reg->dev, "%s: calculated val %d\n", __func__, val);
74 mask = ((1 << anatop_reg->vol_bit_width) - 1) << 56 mask = ((1 << anatop_reg->vol_bit_width) - 1) <<
75 anatop_reg->vol_bit_shift; 57 anatop_reg->vol_bit_shift;
@@ -94,21 +76,11 @@ static int anatop_get_voltage_sel(struct regulator_dev *reg)
94 return val - anatop_reg->min_bit_val; 76 return val - anatop_reg->min_bit_val;
95} 77}
96 78
97static int anatop_list_voltage(struct regulator_dev *reg, unsigned selector)
98{
99 struct anatop_regulator *anatop_reg = rdev_get_drvdata(reg);
100 int uv;
101
102 uv = anatop_reg->min_voltage + selector * 25000;
103 dev_dbg(&reg->dev, "vddio = %d, selector = %u\n", uv, selector);
104
105 return uv;
106}
107
108static struct regulator_ops anatop_rops = { 79static struct regulator_ops anatop_rops = {
109 .set_voltage = anatop_set_voltage, 80 .set_voltage_sel = anatop_set_voltage_sel,
110 .get_voltage_sel = anatop_get_voltage_sel, 81 .get_voltage_sel = anatop_get_voltage_sel,
111 .list_voltage = anatop_list_voltage, 82 .list_voltage = regulator_list_voltage_linear,
83 .map_voltage = regulator_map_voltage_linear,
112}; 84};
113 85
114static int __devinit anatop_regulator_probe(struct platform_device *pdev) 86static int __devinit anatop_regulator_probe(struct platform_device *pdev)
@@ -176,6 +148,8 @@ static int __devinit anatop_regulator_probe(struct platform_device *pdev)
176 148
177 rdesc->n_voltages = (sreg->max_voltage - sreg->min_voltage) 149 rdesc->n_voltages = (sreg->max_voltage - sreg->min_voltage)
178 / 25000 + 1; 150 / 25000 + 1;
151 rdesc->min_uV = sreg->min_voltage;
152 rdesc->uV_step = 25000;
179 153
180 config.dev = &pdev->dev; 154 config.dev = &pdev->dev;
181 config.init_data = initdata; 155 config.init_data = initdata;
diff --git a/drivers/regulator/arizona-ldo1.c b/drivers/regulator/arizona-ldo1.c
new file mode 100644
index 000000000000..c8f95c07adb6
--- /dev/null
+++ b/drivers/regulator/arizona-ldo1.c
@@ -0,0 +1,138 @@
1/*
2 * arizona-ldo1.c -- LDO1 supply for Arizona devices
3 *
4 * Copyright 2012 Wolfson Microelectronics PLC.
5 *
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 */
13
14#include <linux/module.h>
15#include <linux/moduleparam.h>
16#include <linux/init.h>
17#include <linux/bitops.h>
18#include <linux/err.h>
19#include <linux/platform_device.h>
20#include <linux/regulator/driver.h>
21#include <linux/regulator/machine.h>
22#include <linux/gpio.h>
23#include <linux/slab.h>
24
25#include <linux/mfd/arizona/core.h>
26#include <linux/mfd/arizona/pdata.h>
27#include <linux/mfd/arizona/registers.h>
28
29struct arizona_ldo1 {
30 struct regulator_dev *regulator;
31 struct arizona *arizona;
32
33 struct regulator_consumer_supply supply;
34 struct regulator_init_data init_data;
35};
36
37static struct regulator_ops arizona_ldo1_ops = {
38 .list_voltage = regulator_list_voltage_linear,
39 .map_voltage = regulator_map_voltage_linear,
40 .get_voltage_sel = regulator_get_voltage_sel_regmap,
41 .set_voltage_sel = regulator_set_voltage_sel_regmap,
42};
43
44static const struct regulator_desc arizona_ldo1 = {
45 .name = "LDO1",
46 .supply_name = "LDOVDD",
47 .type = REGULATOR_VOLTAGE,
48 .ops = &arizona_ldo1_ops,
49
50 .vsel_reg = ARIZONA_LDO1_CONTROL_1,
51 .vsel_mask = ARIZONA_LDO1_VSEL_MASK,
52 .min_uV = 900000,
53 .uV_step = 50000,
54 .n_voltages = 7,
55
56 .owner = THIS_MODULE,
57};
58
59static const struct regulator_init_data arizona_ldo1_default = {
60 .constraints = {
61 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
62 },
63 .num_consumer_supplies = 1,
64};
65
66static __devinit int arizona_ldo1_probe(struct platform_device *pdev)
67{
68 struct arizona *arizona = dev_get_drvdata(pdev->dev.parent);
69 struct regulator_config config = { };
70 struct arizona_ldo1 *ldo1;
71 int ret;
72
73 ldo1 = devm_kzalloc(&pdev->dev, sizeof(*ldo1), GFP_KERNEL);
74 if (ldo1 == NULL) {
75 dev_err(&pdev->dev, "Unable to allocate private data\n");
76 return -ENOMEM;
77 }
78
79 ldo1->arizona = arizona;
80
81 /*
82 * Since the chip usually supplies itself we provide some
83 * default init_data for it. This will be overridden with
84 * platform data if provided.
85 */
86 ldo1->init_data = arizona_ldo1_default;
87 ldo1->init_data.consumer_supplies = &ldo1->supply;
88 ldo1->supply.supply = "DCVDD";
89 ldo1->supply.dev_name = dev_name(arizona->dev);
90
91 config.dev = arizona->dev;
92 config.driver_data = ldo1;
93 config.regmap = arizona->regmap;
94 config.ena_gpio = arizona->pdata.ldoena;
95
96 if (arizona->pdata.ldo1)
97 config.init_data = arizona->pdata.ldo1;
98 else
99 config.init_data = &ldo1->init_data;
100
101 ldo1->regulator = regulator_register(&arizona_ldo1, &config);
102 if (IS_ERR(ldo1->regulator)) {
103 ret = PTR_ERR(ldo1->regulator);
104 dev_err(arizona->dev, "Failed to register LDO1 supply: %d\n",
105 ret);
106 return ret;
107 }
108
109 platform_set_drvdata(pdev, ldo1);
110
111 return 0;
112}
113
114static __devexit int arizona_ldo1_remove(struct platform_device *pdev)
115{
116 struct arizona_ldo1 *ldo1 = platform_get_drvdata(pdev);
117
118 regulator_unregister(ldo1->regulator);
119
120 return 0;
121}
122
123static struct platform_driver arizona_ldo1_driver = {
124 .probe = arizona_ldo1_probe,
125 .remove = __devexit_p(arizona_ldo1_remove),
126 .driver = {
127 .name = "arizona-ldo1",
128 .owner = THIS_MODULE,
129 },
130};
131
132module_platform_driver(arizona_ldo1_driver);
133
134/* Module information */
135MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
136MODULE_DESCRIPTION("Arizona LDO1 driver");
137MODULE_LICENSE("GPL");
138MODULE_ALIAS("platform:arizona-ldo1");
diff --git a/drivers/regulator/arizona-micsupp.c b/drivers/regulator/arizona-micsupp.c
new file mode 100644
index 000000000000..450a069aa9b6
--- /dev/null
+++ b/drivers/regulator/arizona-micsupp.c
@@ -0,0 +1,188 @@
1/*
2 * arizona-micsupp.c -- Microphone supply for Arizona devices
3 *
4 * Copyright 2012 Wolfson Microelectronics PLC.
5 *
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 */
13
14#include <linux/module.h>
15#include <linux/moduleparam.h>
16#include <linux/init.h>
17#include <linux/bitops.h>
18#include <linux/err.h>
19#include <linux/platform_device.h>
20#include <linux/regulator/driver.h>
21#include <linux/regulator/machine.h>
22#include <linux/gpio.h>
23#include <linux/slab.h>
24
25#include <linux/mfd/arizona/core.h>
26#include <linux/mfd/arizona/pdata.h>
27#include <linux/mfd/arizona/registers.h>
28
29#define ARIZONA_MICSUPP_MAX_SELECTOR 0x1f
30
31struct arizona_micsupp {
32 struct regulator_dev *regulator;
33 struct arizona *arizona;
34
35 struct regulator_consumer_supply supply;
36 struct regulator_init_data init_data;
37};
38
39static int arizona_micsupp_list_voltage(struct regulator_dev *rdev,
40 unsigned int selector)
41{
42 if (selector > ARIZONA_MICSUPP_MAX_SELECTOR)
43 return -EINVAL;
44
45 if (selector == ARIZONA_MICSUPP_MAX_SELECTOR)
46 return 3300000;
47 else
48 return (selector * 50000) + 1700000;
49}
50
51static int arizona_micsupp_map_voltage(struct regulator_dev *rdev,
52 int min_uV, int max_uV)
53{
54 unsigned int voltage;
55 int selector;
56
57 if (min_uV < 1700000)
58 min_uV = 1700000;
59
60 if (min_uV > 3200000)
61 selector = ARIZONA_MICSUPP_MAX_SELECTOR;
62 else
63 selector = DIV_ROUND_UP(min_uV - 1700000, 50000);
64
65 if (selector < 0)
66 return -EINVAL;
67
68 voltage = arizona_micsupp_list_voltage(rdev, selector);
69 if (voltage < min_uV || voltage > max_uV)
70 return -EINVAL;
71
72 return selector;
73}
74
75static struct regulator_ops arizona_micsupp_ops = {
76 .enable = regulator_enable_regmap,
77 .disable = regulator_disable_regmap,
78 .is_enabled = regulator_is_enabled_regmap,
79
80 .list_voltage = arizona_micsupp_list_voltage,
81 .map_voltage = arizona_micsupp_map_voltage,
82
83 .get_voltage_sel = regulator_get_voltage_sel_regmap,
84 .set_voltage_sel = regulator_set_voltage_sel_regmap,
85};
86
87static const struct regulator_desc arizona_micsupp = {
88 .name = "MICVDD",
89 .supply_name = "CPVDD",
90 .type = REGULATOR_VOLTAGE,
91 .n_voltages = ARIZONA_MICSUPP_MAX_SELECTOR + 1,
92 .ops = &arizona_micsupp_ops,
93
94 .vsel_reg = ARIZONA_LDO2_CONTROL_1,
95 .vsel_mask = ARIZONA_LDO2_VSEL_MASK,
96 .enable_reg = ARIZONA_MIC_CHARGE_PUMP_1,
97 .enable_mask = ARIZONA_CPMIC_ENA,
98
99 .owner = THIS_MODULE,
100};
101
102static const struct regulator_init_data arizona_micsupp_default = {
103 .constraints = {
104 .valid_ops_mask = REGULATOR_CHANGE_STATUS |
105 REGULATOR_CHANGE_VOLTAGE,
106 .min_uV = 1700000,
107 .max_uV = 3300000,
108 },
109
110 .num_consumer_supplies = 1,
111};
112
113static __devinit int arizona_micsupp_probe(struct platform_device *pdev)
114{
115 struct arizona *arizona = dev_get_drvdata(pdev->dev.parent);
116 struct regulator_config config = { };
117 struct arizona_micsupp *micsupp;
118 int ret;
119
120 micsupp = devm_kzalloc(&pdev->dev, sizeof(*micsupp), GFP_KERNEL);
121 if (micsupp == NULL) {
122 dev_err(&pdev->dev, "Unable to allocate private data\n");
123 return -ENOMEM;
124 }
125
126 micsupp->arizona = arizona;
127
128 /*
129 * Since the chip usually supplies itself we provide some
130 * default init_data for it. This will be overridden with
131 * platform data if provided.
132 */
133 micsupp->init_data = arizona_micsupp_default;
134 micsupp->init_data.consumer_supplies = &micsupp->supply;
135 micsupp->supply.supply = "MICVDD";
136 micsupp->supply.dev_name = dev_name(arizona->dev);
137
138 config.dev = arizona->dev;
139 config.driver_data = micsupp;
140 config.regmap = arizona->regmap;
141
142 if (arizona->pdata.micvdd)
143 config.init_data = arizona->pdata.micvdd;
144 else
145 config.init_data = &micsupp->init_data;
146
147 /* Default to regulated mode until the API supports bypass */
148 regmap_update_bits(arizona->regmap, ARIZONA_MIC_CHARGE_PUMP_1,
149 ARIZONA_CPMIC_BYPASS, 0);
150
151 micsupp->regulator = regulator_register(&arizona_micsupp, &config);
152 if (IS_ERR(micsupp->regulator)) {
153 ret = PTR_ERR(micsupp->regulator);
154 dev_err(arizona->dev, "Failed to register mic supply: %d\n",
155 ret);
156 return ret;
157 }
158
159 platform_set_drvdata(pdev, micsupp);
160
161 return 0;
162}
163
164static __devexit int arizona_micsupp_remove(struct platform_device *pdev)
165{
166 struct arizona_micsupp *micsupp = platform_get_drvdata(pdev);
167
168 regulator_unregister(micsupp->regulator);
169
170 return 0;
171}
172
173static struct platform_driver arizona_micsupp_driver = {
174 .probe = arizona_micsupp_probe,
175 .remove = __devexit_p(arizona_micsupp_remove),
176 .driver = {
177 .name = "arizona-micsupp",
178 .owner = THIS_MODULE,
179 },
180};
181
182module_platform_driver(arizona_micsupp_driver);
183
184/* Module information */
185MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
186MODULE_DESCRIPTION("Arizona microphone supply driver");
187MODULE_LICENSE("GPL");
188MODULE_ALIAS("platform:arizona-micsupp");
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index e8ee20095a19..2e31dffbefe7 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -23,6 +23,7 @@
23#include <linux/mutex.h> 23#include <linux/mutex.h>
24#include <linux/suspend.h> 24#include <linux/suspend.h>
25#include <linux/delay.h> 25#include <linux/delay.h>
26#include <linux/gpio.h>
26#include <linux/of.h> 27#include <linux/of.h>
27#include <linux/regmap.h> 28#include <linux/regmap.h>
28#include <linux/regulator/of_regulator.h> 29#include <linux/regulator/of_regulator.h>
@@ -936,6 +937,14 @@ static int set_machine_constraints(struct regulator_dev *rdev,
936 } 937 }
937 } 938 }
938 939
940 if (rdev->constraints->ramp_delay && ops->set_ramp_delay) {
941 ret = ops->set_ramp_delay(rdev, rdev->constraints->ramp_delay);
942 if (ret < 0) {
943 rdev_err(rdev, "failed to set ramp_delay\n");
944 goto out;
945 }
946 }
947
939 print_constraints(rdev); 948 print_constraints(rdev);
940 return 0; 949 return 0;
941out: 950out:
@@ -1125,7 +1134,7 @@ overflow_err:
1125static int _regulator_get_enable_time(struct regulator_dev *rdev) 1134static int _regulator_get_enable_time(struct regulator_dev *rdev)
1126{ 1135{
1127 if (!rdev->desc->ops->enable_time) 1136 if (!rdev->desc->ops->enable_time)
1128 return 0; 1137 return rdev->desc->enable_time;
1129 return rdev->desc->ops->enable_time(rdev); 1138 return rdev->desc->ops->enable_time(rdev);
1130} 1139}
1131 1140
@@ -1407,10 +1416,54 @@ void devm_regulator_put(struct regulator *regulator)
1407} 1416}
1408EXPORT_SYMBOL_GPL(devm_regulator_put); 1417EXPORT_SYMBOL_GPL(devm_regulator_put);
1409 1418
1419static int _regulator_do_enable(struct regulator_dev *rdev)
1420{
1421 int ret, delay;
1422
1423 /* Query before enabling in case configuration dependent. */
1424 ret = _regulator_get_enable_time(rdev);
1425 if (ret >= 0) {
1426 delay = ret;
1427 } else {
1428 rdev_warn(rdev, "enable_time() failed: %d\n", ret);
1429 delay = 0;
1430 }
1431
1432 trace_regulator_enable(rdev_get_name(rdev));
1433
1434 if (rdev->ena_gpio) {
1435 gpio_set_value_cansleep(rdev->ena_gpio,
1436 !rdev->ena_gpio_invert);
1437 rdev->ena_gpio_state = 1;
1438 } else if (rdev->desc->ops->enable) {
1439 ret = rdev->desc->ops->enable(rdev);
1440 if (ret < 0)
1441 return ret;
1442 } else {
1443 return -EINVAL;
1444 }
1445
1446 /* Allow the regulator to ramp; it would be useful to extend
1447 * this for bulk operations so that the regulators can ramp
1448 * together. */
1449 trace_regulator_enable_delay(rdev_get_name(rdev));
1450
1451 if (delay >= 1000) {
1452 mdelay(delay / 1000);
1453 udelay(delay % 1000);
1454 } else if (delay) {
1455 udelay(delay);
1456 }
1457
1458 trace_regulator_enable_complete(rdev_get_name(rdev));
1459
1460 return 0;
1461}
1462
1410/* locks held by regulator_enable() */ 1463/* locks held by regulator_enable() */
1411static int _regulator_enable(struct regulator_dev *rdev) 1464static int _regulator_enable(struct regulator_dev *rdev)
1412{ 1465{
1413 int ret, delay; 1466 int ret;
1414 1467
1415 /* check voltage and requested load before enabling */ 1468 /* check voltage and requested load before enabling */
1416 if (rdev->constraints && 1469 if (rdev->constraints &&
@@ -1424,40 +1477,10 @@ static int _regulator_enable(struct regulator_dev *rdev)
1424 if (!_regulator_can_change_status(rdev)) 1477 if (!_regulator_can_change_status(rdev))
1425 return -EPERM; 1478 return -EPERM;
1426 1479
1427 if (!rdev->desc->ops->enable) 1480 ret = _regulator_do_enable(rdev);
1428 return -EINVAL;
1429
1430 /* Query before enabling in case configuration
1431 * dependent. */
1432 ret = _regulator_get_enable_time(rdev);
1433 if (ret >= 0) {
1434 delay = ret;
1435 } else {
1436 rdev_warn(rdev, "enable_time() failed: %d\n",
1437 ret);
1438 delay = 0;
1439 }
1440
1441 trace_regulator_enable(rdev_get_name(rdev));
1442
1443 /* Allow the regulator to ramp; it would be useful
1444 * to extend this for bulk operations so that the
1445 * regulators can ramp together. */
1446 ret = rdev->desc->ops->enable(rdev);
1447 if (ret < 0) 1481 if (ret < 0)
1448 return ret; 1482 return ret;
1449 1483
1450 trace_regulator_enable_delay(rdev_get_name(rdev));
1451
1452 if (delay >= 1000) {
1453 mdelay(delay / 1000);
1454 udelay(delay % 1000);
1455 } else if (delay) {
1456 udelay(delay);
1457 }
1458
1459 trace_regulator_enable_complete(rdev_get_name(rdev));
1460
1461 } else if (ret < 0) { 1484 } else if (ret < 0) {
1462 rdev_err(rdev, "is_enabled() failed: %d\n", ret); 1485 rdev_err(rdev, "is_enabled() failed: %d\n", ret);
1463 return ret; 1486 return ret;
@@ -1506,6 +1529,30 @@ int regulator_enable(struct regulator *regulator)
1506} 1529}
1507EXPORT_SYMBOL_GPL(regulator_enable); 1530EXPORT_SYMBOL_GPL(regulator_enable);
1508 1531
1532static int _regulator_do_disable(struct regulator_dev *rdev)
1533{
1534 int ret;
1535
1536 trace_regulator_disable(rdev_get_name(rdev));
1537
1538 if (rdev->ena_gpio) {
1539 gpio_set_value_cansleep(rdev->ena_gpio,
1540 rdev->ena_gpio_invert);
1541 rdev->ena_gpio_state = 0;
1542
1543 } else if (rdev->desc->ops->disable) {
1544 ret = rdev->desc->ops->disable(rdev);
1545 if (ret != 0)
1546 return ret;
1547 }
1548
1549 trace_regulator_disable_complete(rdev_get_name(rdev));
1550
1551 _notifier_call_chain(rdev, REGULATOR_EVENT_DISABLE,
1552 NULL);
1553 return 0;
1554}
1555
1509/* locks held by regulator_disable() */ 1556/* locks held by regulator_disable() */
1510static int _regulator_disable(struct regulator_dev *rdev) 1557static int _regulator_disable(struct regulator_dev *rdev)
1511{ 1558{
@@ -1520,20 +1567,12 @@ static int _regulator_disable(struct regulator_dev *rdev)
1520 (rdev->constraints && !rdev->constraints->always_on)) { 1567 (rdev->constraints && !rdev->constraints->always_on)) {
1521 1568
1522 /* we are last user */ 1569 /* we are last user */
1523 if (_regulator_can_change_status(rdev) && 1570 if (_regulator_can_change_status(rdev)) {
1524 rdev->desc->ops->disable) { 1571 ret = _regulator_do_disable(rdev);
1525 trace_regulator_disable(rdev_get_name(rdev));
1526
1527 ret = rdev->desc->ops->disable(rdev);
1528 if (ret < 0) { 1572 if (ret < 0) {
1529 rdev_err(rdev, "failed to disable\n"); 1573 rdev_err(rdev, "failed to disable\n");
1530 return ret; 1574 return ret;
1531 } 1575 }
1532
1533 trace_regulator_disable_complete(rdev_get_name(rdev));
1534
1535 _notifier_call_chain(rdev, REGULATOR_EVENT_DISABLE,
1536 NULL);
1537 } 1576 }
1538 1577
1539 rdev->use_count = 0; 1578 rdev->use_count = 0;
@@ -1751,6 +1790,10 @@ EXPORT_SYMBOL_GPL(regulator_disable_regmap);
1751 1790
1752static int _regulator_is_enabled(struct regulator_dev *rdev) 1791static int _regulator_is_enabled(struct regulator_dev *rdev)
1753{ 1792{
1793 /* A GPIO control always takes precedence */
1794 if (rdev->ena_gpio)
1795 return rdev->ena_gpio_state;
1796
1754 /* If we don't know then assume that the regulator is always on */ 1797 /* If we don't know then assume that the regulator is always on */
1755 if (!rdev->desc->ops->is_enabled) 1798 if (!rdev->desc->ops->is_enabled)
1756 return 1; 1799 return 1;
@@ -2019,6 +2062,14 @@ int regulator_map_voltage_linear(struct regulator_dev *rdev,
2019{ 2062{
2020 int ret, voltage; 2063 int ret, voltage;
2021 2064
2065 /* Allow uV_step to be 0 for fixed voltage */
2066 if (rdev->desc->n_voltages == 1 && rdev->desc->uV_step == 0) {
2067 if (min_uV <= rdev->desc->min_uV && rdev->desc->min_uV <= max_uV)
2068 return 0;
2069 else
2070 return -EINVAL;
2071 }
2072
2022 if (!rdev->desc->uV_step) { 2073 if (!rdev->desc->uV_step) {
2023 BUG_ON(!rdev->desc->uV_step); 2074 BUG_ON(!rdev->desc->uV_step);
2024 return -EINVAL; 2075 return -EINVAL;
@@ -2240,6 +2291,46 @@ int regulator_set_voltage_time(struct regulator *regulator,
2240EXPORT_SYMBOL_GPL(regulator_set_voltage_time); 2291EXPORT_SYMBOL_GPL(regulator_set_voltage_time);
2241 2292
2242/** 2293/**
2294 *regulator_set_voltage_time_sel - get raise/fall time
2295 * @regulator: regulator source
2296 * @old_selector: selector for starting voltage
2297 * @new_selector: selector for target voltage
2298 *
2299 * Provided with the starting and target voltage selectors, this function
2300 * returns time in microseconds required to rise or fall to this new voltage
2301 *
2302 * Drivers providing ramp_delay in regulation_constraints can use this as their
2303 * set_voltage_time_sel() operation.
2304 */
2305int regulator_set_voltage_time_sel(struct regulator_dev *rdev,
2306 unsigned int old_selector,
2307 unsigned int new_selector)
2308{
2309 unsigned int ramp_delay = 0;
2310 int old_volt, new_volt;
2311
2312 if (rdev->constraints->ramp_delay)
2313 ramp_delay = rdev->constraints->ramp_delay;
2314 else if (rdev->desc->ramp_delay)
2315 ramp_delay = rdev->desc->ramp_delay;
2316
2317 if (ramp_delay == 0) {
2318 rdev_warn(rdev, "ramp_delay not set\n");
2319 return 0;
2320 }
2321
2322 /* sanity check */
2323 if (!rdev->desc->ops->list_voltage)
2324 return -EINVAL;
2325
2326 old_volt = rdev->desc->ops->list_voltage(rdev, old_selector);
2327 new_volt = rdev->desc->ops->list_voltage(rdev, new_selector);
2328
2329 return DIV_ROUND_UP(abs(new_volt - old_volt), ramp_delay);
2330}
2331EXPORT_SYMBOL_GPL(regulator_set_voltage_time_sel);
2332
2333/**
2243 * regulator_sync_voltage - re-apply last regulator output voltage 2334 * regulator_sync_voltage - re-apply last regulator output voltage
2244 * @regulator: regulator source 2335 * @regulator: regulator source
2245 * 2336 *
@@ -2510,9 +2601,12 @@ int regulator_set_optimum_mode(struct regulator *regulator, int uA_load)
2510{ 2601{
2511 struct regulator_dev *rdev = regulator->rdev; 2602 struct regulator_dev *rdev = regulator->rdev;
2512 struct regulator *consumer; 2603 struct regulator *consumer;
2513 int ret, output_uV, input_uV, total_uA_load = 0; 2604 int ret, output_uV, input_uV = 0, total_uA_load = 0;
2514 unsigned int mode; 2605 unsigned int mode;
2515 2606
2607 if (rdev->supply)
2608 input_uV = regulator_get_voltage(rdev->supply);
2609
2516 mutex_lock(&rdev->mutex); 2610 mutex_lock(&rdev->mutex);
2517 2611
2518 /* 2612 /*
@@ -2545,10 +2639,7 @@ int regulator_set_optimum_mode(struct regulator *regulator, int uA_load)
2545 goto out; 2639 goto out;
2546 } 2640 }
2547 2641
2548 /* get input voltage */ 2642 /* No supply? Use constraint voltage */
2549 input_uV = 0;
2550 if (rdev->supply)
2551 input_uV = regulator_get_voltage(rdev->supply);
2552 if (input_uV <= 0) 2643 if (input_uV <= 0)
2553 input_uV = rdev->constraints->input_uV; 2644 input_uV = rdev->constraints->input_uV;
2554 if (input_uV <= 0) { 2645 if (input_uV <= 0) {
@@ -3126,6 +3217,26 @@ regulator_register(const struct regulator_desc *regulator_desc,
3126 3217
3127 dev_set_drvdata(&rdev->dev, rdev); 3218 dev_set_drvdata(&rdev->dev, rdev);
3128 3219
3220 if (config->ena_gpio) {
3221 ret = gpio_request_one(config->ena_gpio,
3222 GPIOF_DIR_OUT | config->ena_gpio_flags,
3223 rdev_get_name(rdev));
3224 if (ret != 0) {
3225 rdev_err(rdev, "Failed to request enable GPIO%d: %d\n",
3226 config->ena_gpio, ret);
3227 goto clean;
3228 }
3229
3230 rdev->ena_gpio = config->ena_gpio;
3231 rdev->ena_gpio_invert = config->ena_gpio_invert;
3232
3233 if (config->ena_gpio_flags & GPIOF_OUT_INIT_HIGH)
3234 rdev->ena_gpio_state = 1;
3235
3236 if (rdev->ena_gpio_invert)
3237 rdev->ena_gpio_state = !rdev->ena_gpio_state;
3238 }
3239
3129 /* set regulator constraints */ 3240 /* set regulator constraints */
3130 if (init_data) 3241 if (init_data)
3131 constraints = &init_data->constraints; 3242 constraints = &init_data->constraints;
@@ -3194,6 +3305,8 @@ unset_supplies:
3194scrub: 3305scrub:
3195 if (rdev->supply) 3306 if (rdev->supply)
3196 regulator_put(rdev->supply); 3307 regulator_put(rdev->supply);
3308 if (rdev->ena_gpio)
3309 gpio_free(rdev->ena_gpio);
3197 kfree(rdev->constraints); 3310 kfree(rdev->constraints);
3198 device_unregister(&rdev->dev); 3311 device_unregister(&rdev->dev);
3199 /* device core frees rdev */ 3312 /* device core frees rdev */
@@ -3227,6 +3340,8 @@ void regulator_unregister(struct regulator_dev *rdev)
3227 unset_regulator_supplies(rdev); 3340 unset_regulator_supplies(rdev);
3228 list_del(&rdev->list); 3341 list_del(&rdev->list);
3229 kfree(rdev->constraints); 3342 kfree(rdev->constraints);
3343 if (rdev->ena_gpio)
3344 gpio_free(rdev->ena_gpio);
3230 device_unregister(&rdev->dev); 3345 device_unregister(&rdev->dev);
3231 mutex_unlock(&regulator_list_mutex); 3346 mutex_unlock(&regulator_list_mutex);
3232} 3347}
diff --git a/drivers/regulator/da903x.c b/drivers/regulator/da903x.c
index 1005f5f7e603..36c5b92fe0af 100644
--- a/drivers/regulator/da903x.c
+++ b/drivers/regulator/da903x.c
@@ -107,6 +107,9 @@ static int da903x_set_voltage_sel(struct regulator_dev *rdev, unsigned selector)
107 struct device *da9034_dev = to_da903x_dev(rdev); 107 struct device *da9034_dev = to_da903x_dev(rdev);
108 uint8_t val, mask; 108 uint8_t val, mask;
109 109
110 if (rdev->desc->n_voltages == 1)
111 return -EINVAL;
112
110 val = selector << info->vol_shift; 113 val = selector << info->vol_shift;
111 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; 114 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
112 115
@@ -120,6 +123,9 @@ static int da903x_get_voltage_sel(struct regulator_dev *rdev)
120 uint8_t val, mask; 123 uint8_t val, mask;
121 int ret; 124 int ret;
122 125
126 if (rdev->desc->n_voltages == 1)
127 return 0;
128
123 ret = da903x_read(da9034_dev, info->vol_reg, &val); 129 ret = da903x_read(da9034_dev, info->vol_reg, &val);
124 if (ret) 130 if (ret)
125 return ret; 131 return ret;
diff --git a/drivers/regulator/da9052-regulator.c b/drivers/regulator/da9052-regulator.c
index 88976d8d44ed..903299cf15cf 100644
--- a/drivers/regulator/da9052-regulator.c
+++ b/drivers/regulator/da9052-regulator.c
@@ -405,12 +405,12 @@ static int __devinit da9052_regulator_probe(struct platform_device *pdev)
405 if (!nproot) 405 if (!nproot)
406 return -ENODEV; 406 return -ENODEV;
407 407
408 for (np = of_get_next_child(nproot, NULL); np; 408 for_each_child_of_node(nproot, np) {
409 np = of_get_next_child(nproot, np)) {
410 if (!of_node_cmp(np->name, 409 if (!of_node_cmp(np->name,
411 regulator->info->reg_desc.name)) { 410 regulator->info->reg_desc.name)) {
412 config.init_data = of_get_regulator_init_data( 411 config.init_data = of_get_regulator_init_data(
413 &pdev->dev, np); 412 &pdev->dev, np);
413 config.of_node = np;
414 break; 414 break;
415 } 415 }
416 } 416 }
diff --git a/drivers/regulator/fixed.c b/drivers/regulator/fixed.c
index f09fe7b20e82..185468c4d38f 100644
--- a/drivers/regulator/fixed.c
+++ b/drivers/regulator/fixed.c
@@ -35,10 +35,6 @@ struct fixed_voltage_data {
35 struct regulator_desc desc; 35 struct regulator_desc desc;
36 struct regulator_dev *dev; 36 struct regulator_dev *dev;
37 int microvolts; 37 int microvolts;
38 int gpio;
39 unsigned startup_delay;
40 bool enable_high;
41 bool is_enabled;
42}; 38};
43 39
44 40
@@ -61,11 +57,11 @@ of_get_fixed_voltage_config(struct device *dev)
61 config = devm_kzalloc(dev, sizeof(struct fixed_voltage_config), 57 config = devm_kzalloc(dev, sizeof(struct fixed_voltage_config),
62 GFP_KERNEL); 58 GFP_KERNEL);
63 if (!config) 59 if (!config)
64 return NULL; 60 return ERR_PTR(-ENOMEM);
65 61
66 config->init_data = of_get_regulator_init_data(dev, dev->of_node); 62 config->init_data = of_get_regulator_init_data(dev, dev->of_node);
67 if (!config->init_data) 63 if (!config->init_data)
68 return NULL; 64 return ERR_PTR(-EINVAL);
69 65
70 init_data = config->init_data; 66 init_data = config->init_data;
71 init_data->constraints.apply_uV = 0; 67 init_data->constraints.apply_uV = 0;
@@ -76,13 +72,26 @@ of_get_fixed_voltage_config(struct device *dev)
76 } else { 72 } else {
77 dev_err(dev, 73 dev_err(dev,
78 "Fixed regulator specified with variable voltages\n"); 74 "Fixed regulator specified with variable voltages\n");
79 return NULL; 75 return ERR_PTR(-EINVAL);
80 } 76 }
81 77
82 if (init_data->constraints.boot_on) 78 if (init_data->constraints.boot_on)
83 config->enabled_at_boot = true; 79 config->enabled_at_boot = true;
84 80
85 config->gpio = of_get_named_gpio(np, "gpio", 0); 81 config->gpio = of_get_named_gpio(np, "gpio", 0);
82 /*
83 * of_get_named_gpio() currently returns ENODEV rather than
84 * EPROBE_DEFER. This code attempts to be compatible with both
85 * for now; the ENODEV check can be removed once the API is fixed.
86 * of_get_named_gpio() doesn't differentiate between a missing
87 * property (which would be fine here, since the GPIO is optional)
88 * and some other error. Patches have been posted for both issues.
89 * Once they are check in, we should replace this with:
90 * if (config->gpio < 0 && config->gpio != -ENOENT)
91 */
92 if ((config->gpio == -ENODEV) || (config->gpio == -EPROBE_DEFER))
93 return ERR_PTR(-EPROBE_DEFER);
94
86 delay = of_get_property(np, "startup-delay-us", NULL); 95 delay = of_get_property(np, "startup-delay-us", NULL);
87 if (delay) 96 if (delay)
88 config->startup_delay = be32_to_cpu(*delay); 97 config->startup_delay = be32_to_cpu(*delay);
@@ -93,41 +102,10 @@ of_get_fixed_voltage_config(struct device *dev)
93 if (of_find_property(np, "gpio-open-drain", NULL)) 102 if (of_find_property(np, "gpio-open-drain", NULL))
94 config->gpio_is_open_drain = true; 103 config->gpio_is_open_drain = true;
95 104
96 return config; 105 if (of_find_property(np, "vin-supply", NULL))
97} 106 config->input_supply = "vin";
98
99static int fixed_voltage_is_enabled(struct regulator_dev *dev)
100{
101 struct fixed_voltage_data *data = rdev_get_drvdata(dev);
102
103 return data->is_enabled;
104}
105
106static int fixed_voltage_enable(struct regulator_dev *dev)
107{
108 struct fixed_voltage_data *data = rdev_get_drvdata(dev);
109
110 gpio_set_value_cansleep(data->gpio, data->enable_high);
111 data->is_enabled = true;
112
113 return 0;
114}
115
116static int fixed_voltage_disable(struct regulator_dev *dev)
117{
118 struct fixed_voltage_data *data = rdev_get_drvdata(dev);
119
120 gpio_set_value_cansleep(data->gpio, !data->enable_high);
121 data->is_enabled = false;
122
123 return 0;
124}
125 107
126static int fixed_voltage_enable_time(struct regulator_dev *dev) 108 return config;
127{
128 struct fixed_voltage_data *data = rdev_get_drvdata(dev);
129
130 return data->startup_delay;
131} 109}
132 110
133static int fixed_voltage_get_voltage(struct regulator_dev *dev) 111static int fixed_voltage_get_voltage(struct regulator_dev *dev)
@@ -151,15 +129,6 @@ static int fixed_voltage_list_voltage(struct regulator_dev *dev,
151 return data->microvolts; 129 return data->microvolts;
152} 130}
153 131
154static struct regulator_ops fixed_voltage_gpio_ops = {
155 .is_enabled = fixed_voltage_is_enabled,
156 .enable = fixed_voltage_enable,
157 .disable = fixed_voltage_disable,
158 .enable_time = fixed_voltage_enable_time,
159 .get_voltage = fixed_voltage_get_voltage,
160 .list_voltage = fixed_voltage_list_voltage,
161};
162
163static struct regulator_ops fixed_voltage_ops = { 132static struct regulator_ops fixed_voltage_ops = {
164 .get_voltage = fixed_voltage_get_voltage, 133 .get_voltage = fixed_voltage_get_voltage,
165 .list_voltage = fixed_voltage_list_voltage, 134 .list_voltage = fixed_voltage_list_voltage,
@@ -172,10 +141,13 @@ static int __devinit reg_fixed_voltage_probe(struct platform_device *pdev)
172 struct regulator_config cfg = { }; 141 struct regulator_config cfg = { };
173 int ret; 142 int ret;
174 143
175 if (pdev->dev.of_node) 144 if (pdev->dev.of_node) {
176 config = of_get_fixed_voltage_config(&pdev->dev); 145 config = of_get_fixed_voltage_config(&pdev->dev);
177 else 146 if (IS_ERR(config))
147 return PTR_ERR(config);
148 } else {
178 config = pdev->dev.platform_data; 149 config = pdev->dev.platform_data;
150 }
179 151
180 if (!config) 152 if (!config)
181 return -ENOMEM; 153 return -ENOMEM;
@@ -196,59 +168,44 @@ static int __devinit reg_fixed_voltage_probe(struct platform_device *pdev)
196 } 168 }
197 drvdata->desc.type = REGULATOR_VOLTAGE; 169 drvdata->desc.type = REGULATOR_VOLTAGE;
198 drvdata->desc.owner = THIS_MODULE; 170 drvdata->desc.owner = THIS_MODULE;
171 drvdata->desc.ops = &fixed_voltage_ops;
199 172
200 if (config->microvolts) 173 drvdata->desc.enable_time = config->startup_delay;
201 drvdata->desc.n_voltages = 1;
202 174
203 drvdata->microvolts = config->microvolts; 175 if (config->input_supply) {
204 drvdata->gpio = config->gpio; 176 drvdata->desc.supply_name = kstrdup(config->input_supply,
205 drvdata->startup_delay = config->startup_delay; 177 GFP_KERNEL);
206 178 if (!drvdata->desc.supply_name) {
207 if (gpio_is_valid(config->gpio)) {
208 int gpio_flag;
209 drvdata->enable_high = config->enable_high;
210
211 /* FIXME: Remove below print warning
212 *
213 * config->gpio must be set to -EINVAL by platform code if
214 * GPIO control is not required. However, early adopters
215 * not requiring GPIO control may forget to initialize
216 * config->gpio to -EINVAL. This will cause GPIO 0 to be used
217 * for GPIO control.
218 *
219 * This warning will be removed once there are a couple of users
220 * for this driver.
221 */
222 if (!config->gpio)
223 dev_warn(&pdev->dev,
224 "using GPIO 0 for regulator enable control\n");
225
226 /*
227 * set output direction without changing state
228 * to prevent glitch
229 */
230 drvdata->is_enabled = config->enabled_at_boot;
231 ret = drvdata->is_enabled ?
232 config->enable_high : !config->enable_high;
233 gpio_flag = ret ? GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW;
234
235 if (config->gpio_is_open_drain)
236 gpio_flag |= GPIOF_OPEN_DRAIN;
237
238 ret = gpio_request_one(config->gpio, gpio_flag,
239 config->supply_name);
240 if (ret) {
241 dev_err(&pdev->dev, 179 dev_err(&pdev->dev,
242 "Could not obtain regulator enable GPIO %d: %d\n", 180 "Failed to allocate input supply\n");
243 config->gpio, ret); 181 ret = -ENOMEM;
244 goto err_name; 182 goto err_name;
245 } 183 }
184 }
185
186 if (config->microvolts)
187 drvdata->desc.n_voltages = 1;
246 188
247 drvdata->desc.ops = &fixed_voltage_gpio_ops; 189 drvdata->microvolts = config->microvolts;
248 190
191 if (config->gpio >= 0)
192 cfg.ena_gpio = config->gpio;
193 cfg.ena_gpio_invert = !config->enable_high;
194 if (config->enabled_at_boot) {
195 if (config->enable_high) {
196 cfg.ena_gpio_flags |= GPIOF_OUT_INIT_HIGH;
197 } else {
198 cfg.ena_gpio_flags |= GPIOF_OUT_INIT_LOW;
199 }
249 } else { 200 } else {
250 drvdata->desc.ops = &fixed_voltage_ops; 201 if (config->enable_high) {
202 cfg.ena_gpio_flags |= GPIOF_OUT_INIT_LOW;
203 } else {
204 cfg.ena_gpio_flags |= GPIOF_OUT_INIT_HIGH;
205 }
251 } 206 }
207 if (config->gpio_is_open_drain)
208 cfg.ena_gpio_flags |= GPIOF_OPEN_DRAIN;
252 209
253 cfg.dev = &pdev->dev; 210 cfg.dev = &pdev->dev;
254 cfg.init_data = config->init_data; 211 cfg.init_data = config->init_data;
@@ -259,7 +216,7 @@ static int __devinit reg_fixed_voltage_probe(struct platform_device *pdev)
259 if (IS_ERR(drvdata->dev)) { 216 if (IS_ERR(drvdata->dev)) {
260 ret = PTR_ERR(drvdata->dev); 217 ret = PTR_ERR(drvdata->dev);
261 dev_err(&pdev->dev, "Failed to register regulator: %d\n", ret); 218 dev_err(&pdev->dev, "Failed to register regulator: %d\n", ret);
262 goto err_gpio; 219 goto err_input;
263 } 220 }
264 221
265 platform_set_drvdata(pdev, drvdata); 222 platform_set_drvdata(pdev, drvdata);
@@ -269,9 +226,8 @@ static int __devinit reg_fixed_voltage_probe(struct platform_device *pdev)
269 226
270 return 0; 227 return 0;
271 228
272err_gpio: 229err_input:
273 if (gpio_is_valid(config->gpio)) 230 kfree(drvdata->desc.supply_name);
274 gpio_free(config->gpio);
275err_name: 231err_name:
276 kfree(drvdata->desc.name); 232 kfree(drvdata->desc.name);
277err: 233err:
@@ -283,8 +239,7 @@ static int __devexit reg_fixed_voltage_remove(struct platform_device *pdev)
283 struct fixed_voltage_data *drvdata = platform_get_drvdata(pdev); 239 struct fixed_voltage_data *drvdata = platform_get_drvdata(pdev);
284 240
285 regulator_unregister(drvdata->dev); 241 regulator_unregister(drvdata->dev);
286 if (gpio_is_valid(drvdata->gpio)) 242 kfree(drvdata->desc.supply_name);
287 gpio_free(drvdata->gpio);
288 kfree(drvdata->desc.name); 243 kfree(drvdata->desc.name);
289 244
290 return 0; 245 return 0;
@@ -296,8 +251,6 @@ static const struct of_device_id fixed_of_match[] __devinitconst = {
296 {}, 251 {},
297}; 252};
298MODULE_DEVICE_TABLE(of, fixed_of_match); 253MODULE_DEVICE_TABLE(of, fixed_of_match);
299#else
300#define fixed_of_match NULL
301#endif 254#endif
302 255
303static struct platform_driver regulator_fixed_voltage_driver = { 256static struct platform_driver regulator_fixed_voltage_driver = {
@@ -306,7 +259,7 @@ static struct platform_driver regulator_fixed_voltage_driver = {
306 .driver = { 259 .driver = {
307 .name = "reg-fixed-voltage", 260 .name = "reg-fixed-voltage",
308 .owner = THIS_MODULE, 261 .owner = THIS_MODULE,
309 .of_match_table = fixed_of_match, 262 .of_match_table = of_match_ptr(fixed_of_match),
310 }, 263 },
311}; 264};
312 265
diff --git a/drivers/regulator/gpio-regulator.c b/drivers/regulator/gpio-regulator.c
index 242851a4c1a6..34b67bee9323 100644
--- a/drivers/regulator/gpio-regulator.c
+++ b/drivers/regulator/gpio-regulator.c
@@ -36,11 +36,6 @@ struct gpio_regulator_data {
36 struct regulator_desc desc; 36 struct regulator_desc desc;
37 struct regulator_dev *dev; 37 struct regulator_dev *dev;
38 38
39 int enable_gpio;
40 bool enable_high;
41 bool is_enabled;
42 unsigned startup_delay;
43
44 struct gpio *gpios; 39 struct gpio *gpios;
45 int nr_gpios; 40 int nr_gpios;
46 41
@@ -50,44 +45,6 @@ struct gpio_regulator_data {
50 int state; 45 int state;
51}; 46};
52 47
53static int gpio_regulator_is_enabled(struct regulator_dev *dev)
54{
55 struct gpio_regulator_data *data = rdev_get_drvdata(dev);
56
57 return data->is_enabled;
58}
59
60static int gpio_regulator_enable(struct regulator_dev *dev)
61{
62 struct gpio_regulator_data *data = rdev_get_drvdata(dev);
63
64 if (gpio_is_valid(data->enable_gpio)) {
65 gpio_set_value_cansleep(data->enable_gpio, data->enable_high);
66 data->is_enabled = true;
67 }
68
69 return 0;
70}
71
72static int gpio_regulator_disable(struct regulator_dev *dev)
73{
74 struct gpio_regulator_data *data = rdev_get_drvdata(dev);
75
76 if (gpio_is_valid(data->enable_gpio)) {
77 gpio_set_value_cansleep(data->enable_gpio, !data->enable_high);
78 data->is_enabled = false;
79 }
80
81 return 0;
82}
83
84static int gpio_regulator_enable_time(struct regulator_dev *dev)
85{
86 struct gpio_regulator_data *data = rdev_get_drvdata(dev);
87
88 return data->startup_delay;
89}
90
91static int gpio_regulator_get_value(struct regulator_dev *dev) 48static int gpio_regulator_get_value(struct regulator_dev *dev)
92{ 49{
93 struct gpio_regulator_data *data = rdev_get_drvdata(dev); 50 struct gpio_regulator_data *data = rdev_get_drvdata(dev);
@@ -153,20 +110,12 @@ static int gpio_regulator_set_current_limit(struct regulator_dev *dev,
153} 110}
154 111
155static struct regulator_ops gpio_regulator_voltage_ops = { 112static struct regulator_ops gpio_regulator_voltage_ops = {
156 .is_enabled = gpio_regulator_is_enabled,
157 .enable = gpio_regulator_enable,
158 .disable = gpio_regulator_disable,
159 .enable_time = gpio_regulator_enable_time,
160 .get_voltage = gpio_regulator_get_value, 113 .get_voltage = gpio_regulator_get_value,
161 .set_voltage = gpio_regulator_set_voltage, 114 .set_voltage = gpio_regulator_set_voltage,
162 .list_voltage = gpio_regulator_list_voltage, 115 .list_voltage = gpio_regulator_list_voltage,
163}; 116};
164 117
165static struct regulator_ops gpio_regulator_current_ops = { 118static struct regulator_ops gpio_regulator_current_ops = {
166 .is_enabled = gpio_regulator_is_enabled,
167 .enable = gpio_regulator_enable,
168 .disable = gpio_regulator_disable,
169 .enable_time = gpio_regulator_enable_time,
170 .get_current_limit = gpio_regulator_get_value, 119 .get_current_limit = gpio_regulator_get_value,
171 .set_current_limit = gpio_regulator_set_current_limit, 120 .set_current_limit = gpio_regulator_set_current_limit,
172}; 121};
@@ -213,6 +162,7 @@ static int __devinit gpio_regulator_probe(struct platform_device *pdev)
213 drvdata->nr_states = config->nr_states; 162 drvdata->nr_states = config->nr_states;
214 163
215 drvdata->desc.owner = THIS_MODULE; 164 drvdata->desc.owner = THIS_MODULE;
165 drvdata->desc.enable_time = config->startup_delay;
216 166
217 /* handle regulator type*/ 167 /* handle regulator type*/
218 switch (config->type) { 168 switch (config->type) {
@@ -232,52 +182,12 @@ static int __devinit gpio_regulator_probe(struct platform_device *pdev)
232 break; 182 break;
233 } 183 }
234 184
235 drvdata->enable_gpio = config->enable_gpio;
236 drvdata->startup_delay = config->startup_delay;
237
238 if (gpio_is_valid(config->enable_gpio)) {
239 drvdata->enable_high = config->enable_high;
240
241 ret = gpio_request(config->enable_gpio, config->supply_name);
242 if (ret) {
243 dev_err(&pdev->dev,
244 "Could not obtain regulator enable GPIO %d: %d\n",
245 config->enable_gpio, ret);
246 goto err_memstate;
247 }
248
249 /* set output direction without changing state
250 * to prevent glitch
251 */
252 if (config->enabled_at_boot) {
253 drvdata->is_enabled = true;
254 ret = gpio_direction_output(config->enable_gpio,
255 config->enable_high);
256 } else {
257 drvdata->is_enabled = false;
258 ret = gpio_direction_output(config->enable_gpio,
259 !config->enable_high);
260 }
261
262 if (ret) {
263 dev_err(&pdev->dev,
264 "Could not configure regulator enable GPIO %d direction: %d\n",
265 config->enable_gpio, ret);
266 goto err_enablegpio;
267 }
268 } else {
269 /* Regulator without GPIO control is considered
270 * always enabled
271 */
272 drvdata->is_enabled = true;
273 }
274
275 drvdata->nr_gpios = config->nr_gpios; 185 drvdata->nr_gpios = config->nr_gpios;
276 ret = gpio_request_array(drvdata->gpios, drvdata->nr_gpios); 186 ret = gpio_request_array(drvdata->gpios, drvdata->nr_gpios);
277 if (ret) { 187 if (ret) {
278 dev_err(&pdev->dev, 188 dev_err(&pdev->dev,
279 "Could not obtain regulator setting GPIOs: %d\n", ret); 189 "Could not obtain regulator setting GPIOs: %d\n", ret);
280 goto err_enablegpio; 190 goto err_memstate;
281 } 191 }
282 192
283 /* build initial state from gpio init data. */ 193 /* build initial state from gpio init data. */
@@ -292,6 +202,21 @@ static int __devinit gpio_regulator_probe(struct platform_device *pdev)
292 cfg.init_data = config->init_data; 202 cfg.init_data = config->init_data;
293 cfg.driver_data = drvdata; 203 cfg.driver_data = drvdata;
294 204
205 if (config->enable_gpio >= 0)
206 cfg.ena_gpio = config->enable_gpio;
207 cfg.ena_gpio_invert = !config->enable_high;
208 if (config->enabled_at_boot) {
209 if (config->enable_high)
210 cfg.ena_gpio_flags |= GPIOF_OUT_INIT_HIGH;
211 else
212 cfg.ena_gpio_flags |= GPIOF_OUT_INIT_LOW;
213 } else {
214 if (config->enable_high)
215 cfg.ena_gpio_flags |= GPIOF_OUT_INIT_LOW;
216 else
217 cfg.ena_gpio_flags |= GPIOF_OUT_INIT_HIGH;
218 }
219
295 drvdata->dev = regulator_register(&drvdata->desc, &cfg); 220 drvdata->dev = regulator_register(&drvdata->desc, &cfg);
296 if (IS_ERR(drvdata->dev)) { 221 if (IS_ERR(drvdata->dev)) {
297 ret = PTR_ERR(drvdata->dev); 222 ret = PTR_ERR(drvdata->dev);
@@ -305,9 +230,6 @@ static int __devinit gpio_regulator_probe(struct platform_device *pdev)
305 230
306err_stategpio: 231err_stategpio:
307 gpio_free_array(drvdata->gpios, drvdata->nr_gpios); 232 gpio_free_array(drvdata->gpios, drvdata->nr_gpios);
308err_enablegpio:
309 if (gpio_is_valid(config->enable_gpio))
310 gpio_free(config->enable_gpio);
311err_memstate: 233err_memstate:
312 kfree(drvdata->states); 234 kfree(drvdata->states);
313err_memgpio: 235err_memgpio:
@@ -329,9 +251,6 @@ static int __devexit gpio_regulator_remove(struct platform_device *pdev)
329 kfree(drvdata->states); 251 kfree(drvdata->states);
330 kfree(drvdata->gpios); 252 kfree(drvdata->gpios);
331 253
332 if (gpio_is_valid(drvdata->enable_gpio))
333 gpio_free(drvdata->enable_gpio);
334
335 kfree(drvdata->desc.name); 254 kfree(drvdata->desc.name);
336 255
337 return 0; 256 return 0;
diff --git a/drivers/regulator/isl6271a-regulator.c b/drivers/regulator/isl6271a-regulator.c
index 56d273f25603..1d145a07ada9 100644
--- a/drivers/regulator/isl6271a-regulator.c
+++ b/drivers/regulator/isl6271a-regulator.c
@@ -75,19 +75,12 @@ static struct regulator_ops isl_core_ops = {
75 75
76static int isl6271a_get_fixed_voltage(struct regulator_dev *dev) 76static int isl6271a_get_fixed_voltage(struct regulator_dev *dev)
77{ 77{
78 int id = rdev_get_id(dev); 78 return dev->desc->min_uV;
79 return (id == 1) ? 1100000 : 1300000;
80}
81
82static int isl6271a_list_fixed_voltage(struct regulator_dev *dev, unsigned selector)
83{
84 int id = rdev_get_id(dev);
85 return (id == 1) ? 1100000 : 1300000;
86} 79}
87 80
88static struct regulator_ops isl_fixed_ops = { 81static struct regulator_ops isl_fixed_ops = {
89 .get_voltage = isl6271a_get_fixed_voltage, 82 .get_voltage = isl6271a_get_fixed_voltage,
90 .list_voltage = isl6271a_list_fixed_voltage, 83 .list_voltage = regulator_list_voltage_linear,
91}; 84};
92 85
93static const struct regulator_desc isl_rd[] = { 86static const struct regulator_desc isl_rd[] = {
@@ -107,6 +100,7 @@ static const struct regulator_desc isl_rd[] = {
107 .ops = &isl_fixed_ops, 100 .ops = &isl_fixed_ops,
108 .type = REGULATOR_VOLTAGE, 101 .type = REGULATOR_VOLTAGE,
109 .owner = THIS_MODULE, 102 .owner = THIS_MODULE,
103 .min_uV = 1100000,
110 }, { 104 }, {
111 .name = "LDO2", 105 .name = "LDO2",
112 .id = 2, 106 .id = 2,
@@ -114,6 +108,7 @@ static const struct regulator_desc isl_rd[] = {
114 .ops = &isl_fixed_ops, 108 .ops = &isl_fixed_ops,
115 .type = REGULATOR_VOLTAGE, 109 .type = REGULATOR_VOLTAGE,
116 .owner = THIS_MODULE, 110 .owner = THIS_MODULE,
111 .min_uV = 1300000,
117 }, 112 },
118}; 113};
119 114
diff --git a/drivers/regulator/lp3971.c b/drivers/regulator/lp3971.c
index 981bea9cb9d7..7c6e3b8ff484 100644
--- a/drivers/regulator/lp3971.c
+++ b/drivers/regulator/lp3971.c
@@ -65,11 +65,11 @@ static const int buck_base_addr[] = {
65#define LP3971_BUCK_TARGET_VOL1_REG(x) (buck_base_addr[x]) 65#define LP3971_BUCK_TARGET_VOL1_REG(x) (buck_base_addr[x])
66#define LP3971_BUCK_TARGET_VOL2_REG(x) (buck_base_addr[x]+1) 66#define LP3971_BUCK_TARGET_VOL2_REG(x) (buck_base_addr[x]+1)
67 67
68static const int buck_voltage_map[] = { 68static const unsigned int buck_voltage_map[] = {
69 0, 800, 850, 900, 950, 1000, 1050, 1100, 69 0, 800000, 850000, 900000, 950000, 1000000, 1050000, 1100000,
70 1150, 1200, 1250, 1300, 1350, 1400, 1450, 1500, 70 1150000, 1200000, 1250000, 1300000, 1350000, 1400000, 1450000, 1500000,
71 1550, 1600, 1650, 1700, 1800, 1900, 2500, 2800, 71 1550000, 1600000, 1650000, 1700000, 1800000, 1900000, 2500000, 2800000,
72 3000, 3300, 72 3000000, 3300000,
73}; 73};
74 74
75#define BUCK_TARGET_VOL_MASK 0x3f 75#define BUCK_TARGET_VOL_MASK 0x3f
@@ -98,39 +98,19 @@ static const int buck_voltage_map[] = {
98#define LDO_VOL_CONTR_SHIFT(x) ((x & 1) << 2) 98#define LDO_VOL_CONTR_SHIFT(x) ((x & 1) << 2)
99#define LDO_VOL_CONTR_MASK 0x0f 99#define LDO_VOL_CONTR_MASK 0x0f
100 100
101static const int ldo45_voltage_map[] = { 101static const unsigned int ldo45_voltage_map[] = {
102 1000, 1050, 1100, 1150, 1200, 1250, 1300, 1350, 102 1000000, 1050000, 1100000, 1150000, 1200000, 1250000, 1300000, 1350000,
103 1400, 1500, 1800, 1900, 2500, 2800, 3000, 3300, 103 1400000, 1500000, 1800000, 1900000, 2500000, 2800000, 3000000, 3300000,
104}; 104};
105 105
106static const int ldo123_voltage_map[] = { 106static const unsigned int ldo123_voltage_map[] = {
107 1800, 1900, 2000, 2100, 2200, 2300, 2400, 2500, 107 1800000, 1900000, 2000000, 2100000, 2200000, 2300000, 2400000, 2500000,
108 2600, 2700, 2800, 2900, 3000, 3100, 3200, 3300, 108 2600000, 2700000, 2800000, 2900000, 3000000, 3100000, 3200000, 3300000,
109}; 109};
110 110
111static const int *ldo_voltage_map[] = {
112 ldo123_voltage_map, /* LDO1 */
113 ldo123_voltage_map, /* LDO2 */
114 ldo123_voltage_map, /* LDO3 */
115 ldo45_voltage_map, /* LDO4 */
116 ldo45_voltage_map, /* LDO5 */
117};
118
119#define LDO_VOL_VALUE_MAP(x) (ldo_voltage_map[(x - LP3971_LDO1)])
120
121#define LDO_VOL_MIN_IDX 0x00 111#define LDO_VOL_MIN_IDX 0x00
122#define LDO_VOL_MAX_IDX 0x0f 112#define LDO_VOL_MAX_IDX 0x0f
123 113
124static int lp3971_ldo_list_voltage(struct regulator_dev *dev, unsigned index)
125{
126 int ldo = rdev_get_id(dev) - LP3971_LDO1;
127
128 if (index > LDO_VOL_MAX_IDX)
129 return -EINVAL;
130
131 return 1000 * LDO_VOL_VALUE_MAP(ldo)[index];
132}
133
134static int lp3971_ldo_is_enabled(struct regulator_dev *dev) 114static int lp3971_ldo_is_enabled(struct regulator_dev *dev)
135{ 115{
136 struct lp3971 *lp3971 = rdev_get_drvdata(dev); 116 struct lp3971 *lp3971 = rdev_get_drvdata(dev);
@@ -169,7 +149,7 @@ static int lp3971_ldo_get_voltage(struct regulator_dev *dev)
169 reg = lp3971_reg_read(lp3971, LP3971_LDO_VOL_CONTR_REG(ldo)); 149 reg = lp3971_reg_read(lp3971, LP3971_LDO_VOL_CONTR_REG(ldo));
170 val = (reg >> LDO_VOL_CONTR_SHIFT(ldo)) & LDO_VOL_CONTR_MASK; 150 val = (reg >> LDO_VOL_CONTR_SHIFT(ldo)) & LDO_VOL_CONTR_MASK;
171 151
172 return 1000 * LDO_VOL_VALUE_MAP(ldo)[val]; 152 return dev->desc->volt_table[val];
173} 153}
174 154
175static int lp3971_ldo_set_voltage_sel(struct regulator_dev *dev, 155static int lp3971_ldo_set_voltage_sel(struct regulator_dev *dev,
@@ -184,7 +164,7 @@ static int lp3971_ldo_set_voltage_sel(struct regulator_dev *dev,
184} 164}
185 165
186static struct regulator_ops lp3971_ldo_ops = { 166static struct regulator_ops lp3971_ldo_ops = {
187 .list_voltage = lp3971_ldo_list_voltage, 167 .list_voltage = regulator_list_voltage_table,
188 .is_enabled = lp3971_ldo_is_enabled, 168 .is_enabled = lp3971_ldo_is_enabled,
189 .enable = lp3971_ldo_enable, 169 .enable = lp3971_ldo_enable,
190 .disable = lp3971_ldo_disable, 170 .disable = lp3971_ldo_disable,
@@ -192,14 +172,6 @@ static struct regulator_ops lp3971_ldo_ops = {
192 .set_voltage_sel = lp3971_ldo_set_voltage_sel, 172 .set_voltage_sel = lp3971_ldo_set_voltage_sel,
193}; 173};
194 174
195static int lp3971_dcdc_list_voltage(struct regulator_dev *dev, unsigned index)
196{
197 if (index < BUCK_TARGET_VOL_MIN_IDX || index > BUCK_TARGET_VOL_MAX_IDX)
198 return -EINVAL;
199
200 return 1000 * buck_voltage_map[index];
201}
202
203static int lp3971_dcdc_is_enabled(struct regulator_dev *dev) 175static int lp3971_dcdc_is_enabled(struct regulator_dev *dev)
204{ 176{
205 struct lp3971 *lp3971 = rdev_get_drvdata(dev); 177 struct lp3971 *lp3971 = rdev_get_drvdata(dev);
@@ -240,7 +212,7 @@ static int lp3971_dcdc_get_voltage(struct regulator_dev *dev)
240 reg &= BUCK_TARGET_VOL_MASK; 212 reg &= BUCK_TARGET_VOL_MASK;
241 213
242 if (reg <= BUCK_TARGET_VOL_MAX_IDX) 214 if (reg <= BUCK_TARGET_VOL_MAX_IDX)
243 val = 1000 * buck_voltage_map[reg]; 215 val = buck_voltage_map[reg];
244 else { 216 else {
245 val = 0; 217 val = 0;
246 dev_warn(&dev->dev, "chip reported incorrect voltage value.\n"); 218 dev_warn(&dev->dev, "chip reported incorrect voltage value.\n");
@@ -273,7 +245,7 @@ static int lp3971_dcdc_set_voltage_sel(struct regulator_dev *dev,
273} 245}
274 246
275static struct regulator_ops lp3971_dcdc_ops = { 247static struct regulator_ops lp3971_dcdc_ops = {
276 .list_voltage = lp3971_dcdc_list_voltage, 248 .list_voltage = regulator_list_voltage_table,
277 .is_enabled = lp3971_dcdc_is_enabled, 249 .is_enabled = lp3971_dcdc_is_enabled,
278 .enable = lp3971_dcdc_enable, 250 .enable = lp3971_dcdc_enable,
279 .disable = lp3971_dcdc_disable, 251 .disable = lp3971_dcdc_disable,
@@ -287,6 +259,7 @@ static const struct regulator_desc regulators[] = {
287 .id = LP3971_LDO1, 259 .id = LP3971_LDO1,
288 .ops = &lp3971_ldo_ops, 260 .ops = &lp3971_ldo_ops,
289 .n_voltages = ARRAY_SIZE(ldo123_voltage_map), 261 .n_voltages = ARRAY_SIZE(ldo123_voltage_map),
262 .volt_table = ldo123_voltage_map,
290 .type = REGULATOR_VOLTAGE, 263 .type = REGULATOR_VOLTAGE,
291 .owner = THIS_MODULE, 264 .owner = THIS_MODULE,
292 }, 265 },
@@ -295,6 +268,7 @@ static const struct regulator_desc regulators[] = {
295 .id = LP3971_LDO2, 268 .id = LP3971_LDO2,
296 .ops = &lp3971_ldo_ops, 269 .ops = &lp3971_ldo_ops,
297 .n_voltages = ARRAY_SIZE(ldo123_voltage_map), 270 .n_voltages = ARRAY_SIZE(ldo123_voltage_map),
271 .volt_table = ldo123_voltage_map,
298 .type = REGULATOR_VOLTAGE, 272 .type = REGULATOR_VOLTAGE,
299 .owner = THIS_MODULE, 273 .owner = THIS_MODULE,
300 }, 274 },
@@ -303,6 +277,7 @@ static const struct regulator_desc regulators[] = {
303 .id = LP3971_LDO3, 277 .id = LP3971_LDO3,
304 .ops = &lp3971_ldo_ops, 278 .ops = &lp3971_ldo_ops,
305 .n_voltages = ARRAY_SIZE(ldo123_voltage_map), 279 .n_voltages = ARRAY_SIZE(ldo123_voltage_map),
280 .volt_table = ldo123_voltage_map,
306 .type = REGULATOR_VOLTAGE, 281 .type = REGULATOR_VOLTAGE,
307 .owner = THIS_MODULE, 282 .owner = THIS_MODULE,
308 }, 283 },
@@ -311,6 +286,7 @@ static const struct regulator_desc regulators[] = {
311 .id = LP3971_LDO4, 286 .id = LP3971_LDO4,
312 .ops = &lp3971_ldo_ops, 287 .ops = &lp3971_ldo_ops,
313 .n_voltages = ARRAY_SIZE(ldo45_voltage_map), 288 .n_voltages = ARRAY_SIZE(ldo45_voltage_map),
289 .volt_table = ldo45_voltage_map,
314 .type = REGULATOR_VOLTAGE, 290 .type = REGULATOR_VOLTAGE,
315 .owner = THIS_MODULE, 291 .owner = THIS_MODULE,
316 }, 292 },
@@ -319,6 +295,7 @@ static const struct regulator_desc regulators[] = {
319 .id = LP3971_LDO5, 295 .id = LP3971_LDO5,
320 .ops = &lp3971_ldo_ops, 296 .ops = &lp3971_ldo_ops,
321 .n_voltages = ARRAY_SIZE(ldo45_voltage_map), 297 .n_voltages = ARRAY_SIZE(ldo45_voltage_map),
298 .volt_table = ldo45_voltage_map,
322 .type = REGULATOR_VOLTAGE, 299 .type = REGULATOR_VOLTAGE,
323 .owner = THIS_MODULE, 300 .owner = THIS_MODULE,
324 }, 301 },
@@ -327,6 +304,7 @@ static const struct regulator_desc regulators[] = {
327 .id = LP3971_DCDC1, 304 .id = LP3971_DCDC1,
328 .ops = &lp3971_dcdc_ops, 305 .ops = &lp3971_dcdc_ops,
329 .n_voltages = ARRAY_SIZE(buck_voltage_map), 306 .n_voltages = ARRAY_SIZE(buck_voltage_map),
307 .volt_table = buck_voltage_map,
330 .type = REGULATOR_VOLTAGE, 308 .type = REGULATOR_VOLTAGE,
331 .owner = THIS_MODULE, 309 .owner = THIS_MODULE,
332 }, 310 },
@@ -335,6 +313,7 @@ static const struct regulator_desc regulators[] = {
335 .id = LP3971_DCDC2, 313 .id = LP3971_DCDC2,
336 .ops = &lp3971_dcdc_ops, 314 .ops = &lp3971_dcdc_ops,
337 .n_voltages = ARRAY_SIZE(buck_voltage_map), 315 .n_voltages = ARRAY_SIZE(buck_voltage_map),
316 .volt_table = buck_voltage_map,
338 .type = REGULATOR_VOLTAGE, 317 .type = REGULATOR_VOLTAGE,
339 .owner = THIS_MODULE, 318 .owner = THIS_MODULE,
340 }, 319 },
@@ -343,6 +322,7 @@ static const struct regulator_desc regulators[] = {
343 .id = LP3971_DCDC3, 322 .id = LP3971_DCDC3,
344 .ops = &lp3971_dcdc_ops, 323 .ops = &lp3971_dcdc_ops,
345 .n_voltages = ARRAY_SIZE(buck_voltage_map), 324 .n_voltages = ARRAY_SIZE(buck_voltage_map),
325 .volt_table = buck_voltage_map,
346 .type = REGULATOR_VOLTAGE, 326 .type = REGULATOR_VOLTAGE,
347 .owner = THIS_MODULE, 327 .owner = THIS_MODULE,
348 }, 328 },
diff --git a/drivers/regulator/lp3972.c b/drivers/regulator/lp3972.c
index de073df7d344..3cdc755d9b22 100644
--- a/drivers/regulator/lp3972.c
+++ b/drivers/regulator/lp3972.c
@@ -74,54 +74,40 @@ struct lp3972 {
74#define LP3972_OVER2_LDO4_EN BIT(4) 74#define LP3972_OVER2_LDO4_EN BIT(4)
75#define LP3972_OVER1_S_EN BIT(2) 75#define LP3972_OVER1_S_EN BIT(2)
76 76
77static const int ldo1_voltage_map[] = { 77static const unsigned int ldo1_voltage_map[] = {
78 1700, 1725, 1750, 1775, 1800, 1825, 1850, 1875, 78 1700000, 1725000, 1750000, 1775000, 1800000, 1825000, 1850000, 1875000,
79 1900, 1925, 1950, 1975, 2000, 79 1900000, 1925000, 1950000, 1975000, 2000000,
80}; 80};
81 81
82static const int ldo23_voltage_map[] = { 82static const unsigned int ldo23_voltage_map[] = {
83 1800, 1900, 2000, 2100, 2200, 2300, 2400, 2500, 83 1800000, 1900000, 2000000, 2100000, 2200000, 2300000, 2400000, 2500000,
84 2600, 2700, 2800, 2900, 3000, 3100, 3200, 3300, 84 2600000, 2700000, 2800000, 2900000, 3000000, 3100000, 3200000, 3300000,
85}; 85};
86 86
87static const int ldo4_voltage_map[] = { 87static const unsigned int ldo4_voltage_map[] = {
88 1000, 1050, 1100, 1150, 1200, 1250, 1300, 1350, 88 1000000, 1050000, 1100000, 1150000, 1200000, 1250000, 1300000, 1350000,
89 1400, 1500, 1800, 1900, 2500, 2800, 3000, 3300, 89 1400000, 1500000, 1800000, 1900000, 2500000, 2800000, 3000000, 3300000,
90}; 90};
91 91
92static const int ldo5_voltage_map[] = { 92static const unsigned int ldo5_voltage_map[] = {
93 0, 0, 0, 0, 0, 850, 875, 900, 93 0, 0, 0, 0, 0, 850000, 875000, 900000,
94 925, 950, 975, 1000, 1025, 1050, 1075, 1100, 94 925000, 950000, 975000, 1000000, 1025000, 1050000, 1075000, 1100000,
95 1125, 1150, 1175, 1200, 1225, 1250, 1275, 1300, 95 1125000, 1150000, 1175000, 1200000, 1225000, 1250000, 1275000, 1300000,
96 1325, 1350, 1375, 1400, 1425, 1450, 1475, 1500, 96 1325000, 1350000, 1375000, 1400000, 1425000, 1450000, 1475000, 1500000,
97}; 97};
98 98
99static const int buck1_voltage_map[] = { 99static const unsigned int buck1_voltage_map[] = {
100 725, 750, 775, 800, 825, 850, 875, 900, 100 725000, 750000, 775000, 800000, 825000, 850000, 875000, 900000,
101 925, 950, 975, 1000, 1025, 1050, 1075, 1100, 101 925000, 950000, 975000, 1000000, 1025000, 1050000, 1075000, 1100000,
102 1125, 1150, 1175, 1200, 1225, 1250, 1275, 1300, 102 1125000, 1150000, 1175000, 1200000, 1225000, 1250000, 1275000, 1300000,
103 1325, 1350, 1375, 1400, 1425, 1450, 1475, 1500, 103 1325000, 1350000, 1375000, 1400000, 1425000, 1450000, 1475000, 1500000,
104}; 104};
105 105
106static const int buck23_voltage_map[] = { 106static const unsigned int buck23_voltage_map[] = {
107 0, 800, 850, 900, 950, 1000, 1050, 1100, 107 0, 800000, 850000, 900000, 950000, 1000000, 1050000, 1100000,
108 1150, 1200, 1250, 1300, 1350, 1400, 1450, 1500, 108 1150000, 1200000, 1250000, 1300000, 1350000, 1400000, 1450000, 1500000,
109 1550, 1600, 1650, 1700, 1800, 1900, 2500, 2800, 109 1550000, 1600000, 1650000, 1700000, 1800000, 1900000, 2500000, 2800000,
110 3000, 3300, 110 3000000, 3300000,
111};
112
113static const int *ldo_voltage_map[] = {
114 ldo1_voltage_map,
115 ldo23_voltage_map,
116 ldo23_voltage_map,
117 ldo4_voltage_map,
118 ldo5_voltage_map,
119};
120
121static const int *buck_voltage_map[] = {
122 buck1_voltage_map,
123 buck23_voltage_map,
124 buck23_voltage_map,
125}; 111};
126 112
127static const int ldo_output_enable_mask[] = { 113static const int ldo_output_enable_mask[] = {
@@ -160,7 +146,6 @@ static const int buck_base_addr[] = {
160 LP3972_B3TV_REG, 146 LP3972_B3TV_REG,
161}; 147};
162 148
163#define LP3972_LDO_VOL_VALUE_MAP(x) (ldo_voltage_map[x])
164#define LP3972_LDO_OUTPUT_ENABLE_MASK(x) (ldo_output_enable_mask[x]) 149#define LP3972_LDO_OUTPUT_ENABLE_MASK(x) (ldo_output_enable_mask[x])
165#define LP3972_LDO_OUTPUT_ENABLE_REG(x) (ldo_output_enable_addr[x]) 150#define LP3972_LDO_OUTPUT_ENABLE_REG(x) (ldo_output_enable_addr[x])
166 151
@@ -177,7 +162,6 @@ static const int buck_base_addr[] = {
177#define LP3972_LDO_VOL_MIN_IDX(x) (((x) == 4) ? 0x05 : 0x00) 162#define LP3972_LDO_VOL_MIN_IDX(x) (((x) == 4) ? 0x05 : 0x00)
178#define LP3972_LDO_VOL_MAX_IDX(x) ((x) ? (((x) == 4) ? 0x1f : 0x0f) : 0x0c) 163#define LP3972_LDO_VOL_MAX_IDX(x) ((x) ? (((x) == 4) ? 0x1f : 0x0f) : 0x0c)
179 164
180#define LP3972_BUCK_VOL_VALUE_MAP(x) (buck_voltage_map[x])
181#define LP3972_BUCK_VOL_ENABLE_REG(x) (buck_vol_enable_addr[x]) 165#define LP3972_BUCK_VOL_ENABLE_REG(x) (buck_vol_enable_addr[x])
182#define LP3972_BUCK_VOL1_REG(x) (buck_base_addr[x]) 166#define LP3972_BUCK_VOL1_REG(x) (buck_base_addr[x])
183#define LP3972_BUCK_VOL_MASK 0x1f 167#define LP3972_BUCK_VOL_MASK 0x1f
@@ -242,17 +226,6 @@ static int lp3972_set_bits(struct lp3972 *lp3972, u8 reg, u16 mask, u16 val)
242 return ret; 226 return ret;
243} 227}
244 228
245static int lp3972_ldo_list_voltage(struct regulator_dev *dev, unsigned index)
246{
247 int ldo = rdev_get_id(dev) - LP3972_LDO1;
248
249 if (index < LP3972_LDO_VOL_MIN_IDX(ldo) ||
250 index > LP3972_LDO_VOL_MAX_IDX(ldo))
251 return -EINVAL;
252
253 return 1000 * LP3972_LDO_VOL_VALUE_MAP(ldo)[index];
254}
255
256static int lp3972_ldo_is_enabled(struct regulator_dev *dev) 229static int lp3972_ldo_is_enabled(struct regulator_dev *dev)
257{ 230{
258 struct lp3972 *lp3972 = rdev_get_drvdata(dev); 231 struct lp3972 *lp3972 = rdev_get_drvdata(dev);
@@ -294,7 +267,7 @@ static int lp3972_ldo_get_voltage(struct regulator_dev *dev)
294 reg = lp3972_reg_read(lp3972, LP3972_LDO_VOL_CONTR_REG(ldo)); 267 reg = lp3972_reg_read(lp3972, LP3972_LDO_VOL_CONTR_REG(ldo));
295 val = (reg >> LP3972_LDO_VOL_CONTR_SHIFT(ldo)) & mask; 268 val = (reg >> LP3972_LDO_VOL_CONTR_SHIFT(ldo)) & mask;
296 269
297 return 1000 * LP3972_LDO_VOL_VALUE_MAP(ldo)[val]; 270 return dev->desc->volt_table[val];
298} 271}
299 272
300static int lp3972_ldo_set_voltage_sel(struct regulator_dev *dev, 273static int lp3972_ldo_set_voltage_sel(struct regulator_dev *dev,
@@ -337,7 +310,7 @@ static int lp3972_ldo_set_voltage_sel(struct regulator_dev *dev,
337} 310}
338 311
339static struct regulator_ops lp3972_ldo_ops = { 312static struct regulator_ops lp3972_ldo_ops = {
340 .list_voltage = lp3972_ldo_list_voltage, 313 .list_voltage = regulator_list_voltage_table,
341 .is_enabled = lp3972_ldo_is_enabled, 314 .is_enabled = lp3972_ldo_is_enabled,
342 .enable = lp3972_ldo_enable, 315 .enable = lp3972_ldo_enable,
343 .disable = lp3972_ldo_disable, 316 .disable = lp3972_ldo_disable,
@@ -345,17 +318,6 @@ static struct regulator_ops lp3972_ldo_ops = {
345 .set_voltage_sel = lp3972_ldo_set_voltage_sel, 318 .set_voltage_sel = lp3972_ldo_set_voltage_sel,
346}; 319};
347 320
348static int lp3972_dcdc_list_voltage(struct regulator_dev *dev, unsigned index)
349{
350 int buck = rdev_get_id(dev) - LP3972_DCDC1;
351
352 if (index < LP3972_BUCK_VOL_MIN_IDX(buck) ||
353 index > LP3972_BUCK_VOL_MAX_IDX(buck))
354 return -EINVAL;
355
356 return 1000 * buck_voltage_map[buck][index];
357}
358
359static int lp3972_dcdc_is_enabled(struct regulator_dev *dev) 321static int lp3972_dcdc_is_enabled(struct regulator_dev *dev)
360{ 322{
361 struct lp3972 *lp3972 = rdev_get_drvdata(dev); 323 struct lp3972 *lp3972 = rdev_get_drvdata(dev);
@@ -401,7 +363,7 @@ static int lp3972_dcdc_get_voltage(struct regulator_dev *dev)
401 reg = lp3972_reg_read(lp3972, LP3972_BUCK_VOL1_REG(buck)); 363 reg = lp3972_reg_read(lp3972, LP3972_BUCK_VOL1_REG(buck));
402 reg &= LP3972_BUCK_VOL_MASK; 364 reg &= LP3972_BUCK_VOL_MASK;
403 if (reg <= LP3972_BUCK_VOL_MAX_IDX(buck)) 365 if (reg <= LP3972_BUCK_VOL_MAX_IDX(buck))
404 val = 1000 * buck_voltage_map[buck][reg]; 366 val = dev->desc->volt_table[reg];
405 else { 367 else {
406 val = 0; 368 val = 0;
407 dev_warn(&dev->dev, "chip reported incorrect voltage value." 369 dev_warn(&dev->dev, "chip reported incorrect voltage value."
@@ -436,7 +398,7 @@ static int lp3972_dcdc_set_voltage_sel(struct regulator_dev *dev,
436} 398}
437 399
438static struct regulator_ops lp3972_dcdc_ops = { 400static struct regulator_ops lp3972_dcdc_ops = {
439 .list_voltage = lp3972_dcdc_list_voltage, 401 .list_voltage = regulator_list_voltage_table,
440 .is_enabled = lp3972_dcdc_is_enabled, 402 .is_enabled = lp3972_dcdc_is_enabled,
441 .enable = lp3972_dcdc_enable, 403 .enable = lp3972_dcdc_enable,
442 .disable = lp3972_dcdc_disable, 404 .disable = lp3972_dcdc_disable,
@@ -450,6 +412,7 @@ static const struct regulator_desc regulators[] = {
450 .id = LP3972_LDO1, 412 .id = LP3972_LDO1,
451 .ops = &lp3972_ldo_ops, 413 .ops = &lp3972_ldo_ops,
452 .n_voltages = ARRAY_SIZE(ldo1_voltage_map), 414 .n_voltages = ARRAY_SIZE(ldo1_voltage_map),
415 .volt_table = ldo1_voltage_map,
453 .type = REGULATOR_VOLTAGE, 416 .type = REGULATOR_VOLTAGE,
454 .owner = THIS_MODULE, 417 .owner = THIS_MODULE,
455 }, 418 },
@@ -458,6 +421,7 @@ static const struct regulator_desc regulators[] = {
458 .id = LP3972_LDO2, 421 .id = LP3972_LDO2,
459 .ops = &lp3972_ldo_ops, 422 .ops = &lp3972_ldo_ops,
460 .n_voltages = ARRAY_SIZE(ldo23_voltage_map), 423 .n_voltages = ARRAY_SIZE(ldo23_voltage_map),
424 .volt_table = ldo23_voltage_map,
461 .type = REGULATOR_VOLTAGE, 425 .type = REGULATOR_VOLTAGE,
462 .owner = THIS_MODULE, 426 .owner = THIS_MODULE,
463 }, 427 },
@@ -466,6 +430,7 @@ static const struct regulator_desc regulators[] = {
466 .id = LP3972_LDO3, 430 .id = LP3972_LDO3,
467 .ops = &lp3972_ldo_ops, 431 .ops = &lp3972_ldo_ops,
468 .n_voltages = ARRAY_SIZE(ldo23_voltage_map), 432 .n_voltages = ARRAY_SIZE(ldo23_voltage_map),
433 .volt_table = ldo23_voltage_map,
469 .type = REGULATOR_VOLTAGE, 434 .type = REGULATOR_VOLTAGE,
470 .owner = THIS_MODULE, 435 .owner = THIS_MODULE,
471 }, 436 },
@@ -474,6 +439,7 @@ static const struct regulator_desc regulators[] = {
474 .id = LP3972_LDO4, 439 .id = LP3972_LDO4,
475 .ops = &lp3972_ldo_ops, 440 .ops = &lp3972_ldo_ops,
476 .n_voltages = ARRAY_SIZE(ldo4_voltage_map), 441 .n_voltages = ARRAY_SIZE(ldo4_voltage_map),
442 .volt_table = ldo4_voltage_map,
477 .type = REGULATOR_VOLTAGE, 443 .type = REGULATOR_VOLTAGE,
478 .owner = THIS_MODULE, 444 .owner = THIS_MODULE,
479 }, 445 },
@@ -482,6 +448,7 @@ static const struct regulator_desc regulators[] = {
482 .id = LP3972_LDO5, 448 .id = LP3972_LDO5,
483 .ops = &lp3972_ldo_ops, 449 .ops = &lp3972_ldo_ops,
484 .n_voltages = ARRAY_SIZE(ldo5_voltage_map), 450 .n_voltages = ARRAY_SIZE(ldo5_voltage_map),
451 .volt_table = ldo5_voltage_map,
485 .type = REGULATOR_VOLTAGE, 452 .type = REGULATOR_VOLTAGE,
486 .owner = THIS_MODULE, 453 .owner = THIS_MODULE,
487 }, 454 },
@@ -490,6 +457,7 @@ static const struct regulator_desc regulators[] = {
490 .id = LP3972_DCDC1, 457 .id = LP3972_DCDC1,
491 .ops = &lp3972_dcdc_ops, 458 .ops = &lp3972_dcdc_ops,
492 .n_voltages = ARRAY_SIZE(buck1_voltage_map), 459 .n_voltages = ARRAY_SIZE(buck1_voltage_map),
460 .volt_table = buck1_voltage_map,
493 .type = REGULATOR_VOLTAGE, 461 .type = REGULATOR_VOLTAGE,
494 .owner = THIS_MODULE, 462 .owner = THIS_MODULE,
495 }, 463 },
@@ -498,6 +466,7 @@ static const struct regulator_desc regulators[] = {
498 .id = LP3972_DCDC2, 466 .id = LP3972_DCDC2,
499 .ops = &lp3972_dcdc_ops, 467 .ops = &lp3972_dcdc_ops,
500 .n_voltages = ARRAY_SIZE(buck23_voltage_map), 468 .n_voltages = ARRAY_SIZE(buck23_voltage_map),
469 .volt_table = buck23_voltage_map,
501 .type = REGULATOR_VOLTAGE, 470 .type = REGULATOR_VOLTAGE,
502 .owner = THIS_MODULE, 471 .owner = THIS_MODULE,
503 }, 472 },
@@ -506,6 +475,7 @@ static const struct regulator_desc regulators[] = {
506 .id = LP3972_DCDC3, 475 .id = LP3972_DCDC3,
507 .ops = &lp3972_dcdc_ops, 476 .ops = &lp3972_dcdc_ops,
508 .n_voltages = ARRAY_SIZE(buck23_voltage_map), 477 .n_voltages = ARRAY_SIZE(buck23_voltage_map),
478 .volt_table = buck23_voltage_map,
509 .type = REGULATOR_VOLTAGE, 479 .type = REGULATOR_VOLTAGE,
510 .owner = THIS_MODULE, 480 .owner = THIS_MODULE,
511 }, 481 },
diff --git a/drivers/regulator/lp872x.c b/drivers/regulator/lp872x.c
new file mode 100644
index 000000000000..212c38eaba70
--- /dev/null
+++ b/drivers/regulator/lp872x.c
@@ -0,0 +1,943 @@
1/*
2 * Copyright 2012 Texas Instruments
3 *
4 * Author: Milo(Woogyom) Kim <milo.kim@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
12#include <linux/module.h>
13#include <linux/slab.h>
14#include <linux/i2c.h>
15#include <linux/regmap.h>
16#include <linux/err.h>
17#include <linux/gpio.h>
18#include <linux/regulator/lp872x.h>
19#include <linux/regulator/driver.h>
20#include <linux/platform_device.h>
21
22/* Registers : LP8720/8725 shared */
23#define LP872X_GENERAL_CFG 0x00
24#define LP872X_LDO1_VOUT 0x01
25#define LP872X_LDO2_VOUT 0x02
26#define LP872X_LDO3_VOUT 0x03
27#define LP872X_LDO4_VOUT 0x04
28#define LP872X_LDO5_VOUT 0x05
29
30/* Registers : LP8720 */
31#define LP8720_BUCK_VOUT1 0x06
32#define LP8720_BUCK_VOUT2 0x07
33#define LP8720_ENABLE 0x08
34
35/* Registers : LP8725 */
36#define LP8725_LILO1_VOUT 0x06
37#define LP8725_LILO2_VOUT 0x07
38#define LP8725_BUCK1_VOUT1 0x08
39#define LP8725_BUCK1_VOUT2 0x09
40#define LP8725_BUCK2_VOUT1 0x0A
41#define LP8725_BUCK2_VOUT2 0x0B
42#define LP8725_BUCK_CTRL 0x0C
43#define LP8725_LDO_CTRL 0x0D
44
45/* Mask/shift : LP8720/LP8725 shared */
46#define LP872X_VOUT_M 0x1F
47#define LP872X_START_DELAY_M 0xE0
48#define LP872X_START_DELAY_S 5
49#define LP872X_EN_LDO1_M BIT(0)
50#define LP872X_EN_LDO2_M BIT(1)
51#define LP872X_EN_LDO3_M BIT(2)
52#define LP872X_EN_LDO4_M BIT(3)
53#define LP872X_EN_LDO5_M BIT(4)
54
55/* Mask/shift : LP8720 */
56#define LP8720_TIMESTEP_S 0 /* Addr 00h */
57#define LP8720_TIMESTEP_M BIT(0)
58#define LP8720_EXT_DVS_M BIT(2)
59#define LP8720_BUCK_FPWM_S 5 /* Addr 07h */
60#define LP8720_BUCK_FPWM_M BIT(5)
61#define LP8720_EN_BUCK_M BIT(5) /* Addr 08h */
62#define LP8720_DVS_SEL_M BIT(7)
63
64/* Mask/shift : LP8725 */
65#define LP8725_TIMESTEP_M 0xC0 /* Addr 00h */
66#define LP8725_TIMESTEP_S 6
67#define LP8725_BUCK1_EN_M BIT(0)
68#define LP8725_DVS1_M BIT(2)
69#define LP8725_DVS2_M BIT(3)
70#define LP8725_BUCK2_EN_M BIT(4)
71#define LP8725_BUCK_CL_M 0xC0 /* Addr 09h, 0Bh */
72#define LP8725_BUCK_CL_S 6
73#define LP8725_BUCK1_FPWM_S 1 /* Addr 0Ch */
74#define LP8725_BUCK1_FPWM_M BIT(1)
75#define LP8725_BUCK2_FPWM_S 5
76#define LP8725_BUCK2_FPWM_M BIT(5)
77#define LP8725_EN_LILO1_M BIT(5) /* Addr 0Dh */
78#define LP8725_EN_LILO2_M BIT(6)
79
80/* PWM mode */
81#define LP872X_FORCE_PWM 1
82#define LP872X_AUTO_PWM 0
83
84#define LP8720_NUM_REGULATORS 6
85#define LP8725_NUM_REGULATORS 9
86#define EXTERN_DVS_USED 0
87#define MAX_DELAY 6
88
89/* dump registers in regmap-debugfs */
90#define MAX_REGISTERS 0x0F
91
92enum lp872x_id {
93 LP8720,
94 LP8725,
95};
96
97struct lp872x {
98 struct regmap *regmap;
99 struct device *dev;
100 enum lp872x_id chipid;
101 struct lp872x_platform_data *pdata;
102 struct regulator_dev **regulators;
103 int num_regulators;
104 enum lp872x_dvs_state dvs_pin;
105 int dvs_gpio;
106};
107
108/* LP8720/LP8725 shared voltage table for LDOs */
109static const unsigned int lp872x_ldo_vtbl[] = {
110 1200000, 1250000, 1300000, 1350000, 1400000, 1450000, 1500000, 1550000,
111 1600000, 1650000, 1700000, 1750000, 1800000, 1850000, 1900000, 2000000,
112 2100000, 2200000, 2300000, 2400000, 2500000, 2600000, 2650000, 2700000,
113 2750000, 2800000, 2850000, 2900000, 2950000, 3000000, 3100000, 3300000,
114};
115
116/* LP8720 LDO4 voltage table */
117static const unsigned int lp8720_ldo4_vtbl[] = {
118 800000, 850000, 900000, 1000000, 1100000, 1200000, 1250000, 1300000,
119 1350000, 1400000, 1450000, 1500000, 1550000, 1600000, 1650000, 1700000,
120 1750000, 1800000, 1850000, 1900000, 2000000, 2100000, 2200000, 2300000,
121 2400000, 2500000, 2600000, 2650000, 2700000, 2750000, 2800000, 2850000,
122};
123
124/* LP8725 LILO(Low Input Low Output) voltage table */
125static const unsigned int lp8725_lilo_vtbl[] = {
126 800000, 850000, 900000, 950000, 1000000, 1050000, 1100000, 1150000,
127 1200000, 1250000, 1300000, 1350000, 1400000, 1500000, 1600000, 1700000,
128 1800000, 1900000, 2000000, 2100000, 2200000, 2300000, 2400000, 2500000,
129 2600000, 2700000, 2800000, 2850000, 2900000, 3000000, 3100000, 3300000,
130};
131
132/* LP8720 BUCK voltage table */
133#define EXT_R 0 /* external resistor divider */
134static const unsigned int lp8720_buck_vtbl[] = {
135 EXT_R, 800000, 850000, 900000, 950000, 1000000, 1050000, 1100000,
136 1150000, 1200000, 1250000, 1300000, 1350000, 1400000, 1450000, 1500000,
137 1550000, 1600000, 1650000, 1700000, 1750000, 1800000, 1850000, 1900000,
138 1950000, 2000000, 2050000, 2100000, 2150000, 2200000, 2250000, 2300000,
139};
140
141/* LP8725 BUCK voltage table */
142static const unsigned int lp8725_buck_vtbl[] = {
143 800000, 850000, 900000, 950000, 1000000, 1050000, 1100000, 1150000,
144 1200000, 1250000, 1300000, 1350000, 1400000, 1500000, 1600000, 1700000,
145 1750000, 1800000, 1850000, 1900000, 2000000, 2100000, 2200000, 2300000,
146 2400000, 2500000, 2600000, 2700000, 2800000, 2850000, 2900000, 3000000,
147};
148
149/* LP8725 BUCK current limit */
150static const unsigned int lp8725_buck_uA[] = {
151 460000, 780000, 1050000, 1370000,
152};
153
154static int lp872x_read_byte(struct lp872x *lp, u8 addr, u8 *data)
155{
156 int ret;
157 unsigned int val;
158
159 ret = regmap_read(lp->regmap, addr, &val);
160 if (ret < 0) {
161 dev_err(lp->dev, "failed to read 0x%.2x\n", addr);
162 return ret;
163 }
164
165 *data = (u8)val;
166 return 0;
167}
168
169static inline int lp872x_write_byte(struct lp872x *lp, u8 addr, u8 data)
170{
171 return regmap_write(lp->regmap, addr, data);
172}
173
174static inline int lp872x_update_bits(struct lp872x *lp, u8 addr,
175 unsigned int mask, u8 data)
176{
177 return regmap_update_bits(lp->regmap, addr, mask, data);
178}
179
180static int _rdev_to_offset(struct regulator_dev *rdev)
181{
182 enum lp872x_regulator_id id = rdev_get_id(rdev);
183
184 switch (id) {
185 case LP8720_ID_LDO1 ... LP8720_ID_BUCK:
186 return id;
187 case LP8725_ID_LDO1 ... LP8725_ID_BUCK2:
188 return id - LP8725_ID_BASE;
189 default:
190 return -EINVAL;
191 }
192}
193
194static int lp872x_get_timestep_usec(struct lp872x *lp)
195{
196 enum lp872x_id chip = lp->chipid;
197 u8 val, mask, shift;
198 int *time_usec, size, ret;
199 int lp8720_time_usec[] = { 25, 50 };
200 int lp8725_time_usec[] = { 32, 64, 128, 256 };
201
202 switch (chip) {
203 case LP8720:
204 mask = LP8720_TIMESTEP_M;
205 shift = LP8720_TIMESTEP_S;
206 time_usec = &lp8720_time_usec[0];
207 size = ARRAY_SIZE(lp8720_time_usec);
208 break;
209 case LP8725:
210 mask = LP8725_TIMESTEP_M;
211 shift = LP8725_TIMESTEP_S;
212 time_usec = &lp8725_time_usec[0];
213 size = ARRAY_SIZE(lp8725_time_usec);
214 break;
215 default:
216 return -EINVAL;
217 }
218
219 ret = lp872x_read_byte(lp, LP872X_GENERAL_CFG, &val);
220 if (ret)
221 return -EINVAL;
222
223 val = (val & mask) >> shift;
224 if (val >= size)
225 return -EINVAL;
226
227 return *(time_usec + val);
228}
229
230static int lp872x_regulator_enable_time(struct regulator_dev *rdev)
231{
232 struct lp872x *lp = rdev_get_drvdata(rdev);
233 enum lp872x_regulator_id regulator = rdev_get_id(rdev);
234 int time_step_us = lp872x_get_timestep_usec(lp);
235 int ret, offset;
236 u8 addr, val;
237
238 if (time_step_us < 0)
239 return -EINVAL;
240
241 switch (regulator) {
242 case LP8720_ID_LDO1 ... LP8720_ID_LDO5:
243 case LP8725_ID_LDO1 ... LP8725_ID_LILO2:
244 offset = _rdev_to_offset(rdev);
245 if (offset < 0)
246 return -EINVAL;
247
248 addr = LP872X_LDO1_VOUT + offset;
249 break;
250 case LP8720_ID_BUCK:
251 addr = LP8720_BUCK_VOUT1;
252 break;
253 case LP8725_ID_BUCK1:
254 addr = LP8725_BUCK1_VOUT1;
255 break;
256 case LP8725_ID_BUCK2:
257 addr = LP8725_BUCK2_VOUT1;
258 break;
259 default:
260 return -EINVAL;
261 }
262
263 ret = lp872x_read_byte(lp, addr, &val);
264 if (ret)
265 return ret;
266
267 val = (val & LP872X_START_DELAY_M) >> LP872X_START_DELAY_S;
268
269 return val > MAX_DELAY ? 0 : val * time_step_us;
270}
271
272static void lp872x_set_dvs(struct lp872x *lp, int gpio)
273{
274 enum lp872x_dvs_sel dvs_sel = lp->pdata->dvs->vsel;
275 enum lp872x_dvs_state state;
276
277 state = dvs_sel == SEL_V1 ? DVS_HIGH : DVS_LOW;
278 gpio_set_value(gpio, state);
279 lp->dvs_pin = state;
280}
281
282static u8 lp872x_select_buck_vout_addr(struct lp872x *lp,
283 enum lp872x_regulator_id buck)
284{
285 u8 val, addr;
286
287 if (lp872x_read_byte(lp, LP872X_GENERAL_CFG, &val))
288 return 0;
289
290 switch (buck) {
291 case LP8720_ID_BUCK:
292 if (val & LP8720_EXT_DVS_M) {
293 addr = (lp->dvs_pin == DVS_HIGH) ?
294 LP8720_BUCK_VOUT1 : LP8720_BUCK_VOUT2;
295 } else {
296 if (lp872x_read_byte(lp, LP8720_ENABLE, &val))
297 return 0;
298
299 addr = val & LP8720_DVS_SEL_M ?
300 LP8720_BUCK_VOUT1 : LP8720_BUCK_VOUT2;
301 }
302 break;
303 case LP8725_ID_BUCK1:
304 if (val & LP8725_DVS1_M)
305 addr = LP8725_BUCK1_VOUT1;
306 else
307 addr = (lp->dvs_pin == DVS_HIGH) ?
308 LP8725_BUCK1_VOUT1 : LP8725_BUCK1_VOUT2;
309 break;
310 case LP8725_ID_BUCK2:
311 addr = val & LP8725_DVS2_M ?
312 LP8725_BUCK2_VOUT1 : LP8725_BUCK2_VOUT2;
313 break;
314 default:
315 return 0;
316 }
317
318 return addr;
319}
320
321static bool lp872x_is_valid_buck_addr(u8 addr)
322{
323 switch (addr) {
324 case LP8720_BUCK_VOUT1:
325 case LP8720_BUCK_VOUT2:
326 case LP8725_BUCK1_VOUT1:
327 case LP8725_BUCK1_VOUT2:
328 case LP8725_BUCK2_VOUT1:
329 case LP8725_BUCK2_VOUT2:
330 return true;
331 default:
332 return false;
333 }
334}
335
336static int lp872x_buck_set_voltage_sel(struct regulator_dev *rdev,
337 unsigned selector)
338{
339 struct lp872x *lp = rdev_get_drvdata(rdev);
340 enum lp872x_regulator_id buck = rdev_get_id(rdev);
341 u8 addr, mask = LP872X_VOUT_M;
342 struct lp872x_dvs *dvs = lp->pdata->dvs;
343
344 if (dvs && gpio_is_valid(dvs->gpio))
345 lp872x_set_dvs(lp, dvs->gpio);
346
347 addr = lp872x_select_buck_vout_addr(lp, buck);
348 if (!lp872x_is_valid_buck_addr(addr))
349 return -EINVAL;
350
351 return lp872x_update_bits(lp, addr, mask, selector);
352}
353
354static int lp872x_buck_get_voltage_sel(struct regulator_dev *rdev)
355{
356 struct lp872x *lp = rdev_get_drvdata(rdev);
357 enum lp872x_regulator_id buck = rdev_get_id(rdev);
358 u8 addr, val;
359 int ret;
360
361 addr = lp872x_select_buck_vout_addr(lp, buck);
362 if (!lp872x_is_valid_buck_addr(addr))
363 return -EINVAL;
364
365 ret = lp872x_read_byte(lp, addr, &val);
366 if (ret)
367 return ret;
368
369 return val & LP872X_VOUT_M;
370}
371
372static int lp8725_buck_set_current_limit(struct regulator_dev *rdev,
373 int min_uA, int max_uA)
374{
375 struct lp872x *lp = rdev_get_drvdata(rdev);
376 enum lp872x_regulator_id buck = rdev_get_id(rdev);
377 int i, max = ARRAY_SIZE(lp8725_buck_uA);
378 u8 addr, val;
379
380 switch (buck) {
381 case LP8725_ID_BUCK1:
382 addr = LP8725_BUCK1_VOUT2;
383 break;
384 case LP8725_ID_BUCK2:
385 addr = LP8725_BUCK2_VOUT2;
386 break;
387 default:
388 return -EINVAL;
389 }
390
391 for (i = 0 ; i < max ; i++)
392 if (lp8725_buck_uA[i] >= min_uA &&
393 lp8725_buck_uA[i] <= max_uA)
394 break;
395
396 if (i == max)
397 return -EINVAL;
398
399 val = i << LP8725_BUCK_CL_S;
400
401 return lp872x_update_bits(lp, addr, LP8725_BUCK_CL_M, val);
402}
403
404static int lp8725_buck_get_current_limit(struct regulator_dev *rdev)
405{
406 struct lp872x *lp = rdev_get_drvdata(rdev);
407 enum lp872x_regulator_id buck = rdev_get_id(rdev);
408 u8 addr, val;
409 int ret;
410
411 switch (buck) {
412 case LP8725_ID_BUCK1:
413 addr = LP8725_BUCK1_VOUT2;
414 break;
415 case LP8725_ID_BUCK2:
416 addr = LP8725_BUCK2_VOUT2;
417 break;
418 default:
419 return -EINVAL;
420 }
421
422 ret = lp872x_read_byte(lp, addr, &val);
423 if (ret)
424 return ret;
425
426 val = (val & LP8725_BUCK_CL_M) >> LP8725_BUCK_CL_S;
427
428 return (val < ARRAY_SIZE(lp8725_buck_uA)) ?
429 lp8725_buck_uA[val] : -EINVAL;
430}
431
432static int lp872x_buck_set_mode(struct regulator_dev *rdev, unsigned int mode)
433{
434 struct lp872x *lp = rdev_get_drvdata(rdev);
435 enum lp872x_regulator_id buck = rdev_get_id(rdev);
436 u8 addr, mask, shift, val;
437
438 switch (buck) {
439 case LP8720_ID_BUCK:
440 addr = LP8720_BUCK_VOUT2;
441 mask = LP8720_BUCK_FPWM_M;
442 shift = LP8720_BUCK_FPWM_S;
443 break;
444 case LP8725_ID_BUCK1:
445 addr = LP8725_BUCK_CTRL;
446 mask = LP8725_BUCK1_FPWM_M;
447 shift = LP8725_BUCK1_FPWM_S;
448 break;
449 case LP8725_ID_BUCK2:
450 addr = LP8725_BUCK_CTRL;
451 mask = LP8725_BUCK2_FPWM_M;
452 shift = LP8725_BUCK2_FPWM_S;
453 break;
454 default:
455 return -EINVAL;
456 }
457
458 if (mode == REGULATOR_MODE_FAST)
459 val = LP872X_FORCE_PWM << shift;
460 else if (mode == REGULATOR_MODE_NORMAL)
461 val = LP872X_AUTO_PWM << shift;
462 else
463 return -EINVAL;
464
465 return lp872x_update_bits(lp, addr, mask, val);
466}
467
468static unsigned int lp872x_buck_get_mode(struct regulator_dev *rdev)
469{
470 struct lp872x *lp = rdev_get_drvdata(rdev);
471 enum lp872x_regulator_id buck = rdev_get_id(rdev);
472 u8 addr, mask, val;
473 int ret;
474
475 switch (buck) {
476 case LP8720_ID_BUCK:
477 addr = LP8720_BUCK_VOUT2;
478 mask = LP8720_BUCK_FPWM_M;
479 break;
480 case LP8725_ID_BUCK1:
481 addr = LP8725_BUCK_CTRL;
482 mask = LP8725_BUCK1_FPWM_M;
483 break;
484 case LP8725_ID_BUCK2:
485 addr = LP8725_BUCK_CTRL;
486 mask = LP8725_BUCK2_FPWM_M;
487 break;
488 default:
489 return -EINVAL;
490 }
491
492 ret = lp872x_read_byte(lp, addr, &val);
493 if (ret)
494 return ret;
495
496 return val & mask ? REGULATOR_MODE_FAST : REGULATOR_MODE_NORMAL;
497}
498
499static struct regulator_ops lp872x_ldo_ops = {
500 .list_voltage = regulator_list_voltage_table,
501 .set_voltage_sel = regulator_set_voltage_sel_regmap,
502 .get_voltage_sel = regulator_get_voltage_sel_regmap,
503 .enable = regulator_enable_regmap,
504 .disable = regulator_disable_regmap,
505 .is_enabled = regulator_is_enabled_regmap,
506 .enable_time = lp872x_regulator_enable_time,
507};
508
509static struct regulator_ops lp8720_buck_ops = {
510 .list_voltage = regulator_list_voltage_table,
511 .set_voltage_sel = lp872x_buck_set_voltage_sel,
512 .get_voltage_sel = lp872x_buck_get_voltage_sel,
513 .enable = regulator_enable_regmap,
514 .disable = regulator_disable_regmap,
515 .is_enabled = regulator_is_enabled_regmap,
516 .enable_time = lp872x_regulator_enable_time,
517 .set_mode = lp872x_buck_set_mode,
518 .get_mode = lp872x_buck_get_mode,
519};
520
521static struct regulator_ops lp8725_buck_ops = {
522 .list_voltage = regulator_list_voltage_table,
523 .set_voltage_sel = lp872x_buck_set_voltage_sel,
524 .get_voltage_sel = lp872x_buck_get_voltage_sel,
525 .enable = regulator_enable_regmap,
526 .disable = regulator_disable_regmap,
527 .is_enabled = regulator_is_enabled_regmap,
528 .enable_time = lp872x_regulator_enable_time,
529 .set_mode = lp872x_buck_set_mode,
530 .get_mode = lp872x_buck_get_mode,
531 .set_current_limit = lp8725_buck_set_current_limit,
532 .get_current_limit = lp8725_buck_get_current_limit,
533};
534
535static struct regulator_desc lp8720_regulator_desc[] = {
536 {
537 .name = "ldo1",
538 .id = LP8720_ID_LDO1,
539 .ops = &lp872x_ldo_ops,
540 .n_voltages = ARRAY_SIZE(lp872x_ldo_vtbl),
541 .volt_table = lp872x_ldo_vtbl,
542 .type = REGULATOR_VOLTAGE,
543 .owner = THIS_MODULE,
544 .vsel_reg = LP872X_LDO1_VOUT,
545 .vsel_mask = LP872X_VOUT_M,
546 .enable_reg = LP8720_ENABLE,
547 .enable_mask = LP872X_EN_LDO1_M,
548 },
549 {
550 .name = "ldo2",
551 .id = LP8720_ID_LDO2,
552 .ops = &lp872x_ldo_ops,
553 .n_voltages = ARRAY_SIZE(lp872x_ldo_vtbl),
554 .volt_table = lp872x_ldo_vtbl,
555 .type = REGULATOR_VOLTAGE,
556 .owner = THIS_MODULE,
557 .vsel_reg = LP872X_LDO2_VOUT,
558 .vsel_mask = LP872X_VOUT_M,
559 .enable_reg = LP8720_ENABLE,
560 .enable_mask = LP872X_EN_LDO2_M,
561 },
562 {
563 .name = "ldo3",
564 .id = LP8720_ID_LDO3,
565 .ops = &lp872x_ldo_ops,
566 .n_voltages = ARRAY_SIZE(lp872x_ldo_vtbl),
567 .volt_table = lp872x_ldo_vtbl,
568 .type = REGULATOR_VOLTAGE,
569 .owner = THIS_MODULE,
570 .vsel_reg = LP872X_LDO3_VOUT,
571 .vsel_mask = LP872X_VOUT_M,
572 .enable_reg = LP8720_ENABLE,
573 .enable_mask = LP872X_EN_LDO3_M,
574 },
575 {
576 .name = "ldo4",
577 .id = LP8720_ID_LDO4,
578 .ops = &lp872x_ldo_ops,
579 .n_voltages = ARRAY_SIZE(lp8720_ldo4_vtbl),
580 .volt_table = lp8720_ldo4_vtbl,
581 .type = REGULATOR_VOLTAGE,
582 .owner = THIS_MODULE,
583 .vsel_reg = LP872X_LDO4_VOUT,
584 .vsel_mask = LP872X_VOUT_M,
585 .enable_reg = LP8720_ENABLE,
586 .enable_mask = LP872X_EN_LDO4_M,
587 },
588 {
589 .name = "ldo5",
590 .id = LP8720_ID_LDO5,
591 .ops = &lp872x_ldo_ops,
592 .n_voltages = ARRAY_SIZE(lp872x_ldo_vtbl),
593 .volt_table = lp872x_ldo_vtbl,
594 .type = REGULATOR_VOLTAGE,
595 .owner = THIS_MODULE,
596 .vsel_reg = LP872X_LDO5_VOUT,
597 .vsel_mask = LP872X_VOUT_M,
598 .enable_reg = LP8720_ENABLE,
599 .enable_mask = LP872X_EN_LDO5_M,
600 },
601 {
602 .name = "buck",
603 .id = LP8720_ID_BUCK,
604 .ops = &lp8720_buck_ops,
605 .n_voltages = ARRAY_SIZE(lp8720_buck_vtbl),
606 .volt_table = lp8720_buck_vtbl,
607 .type = REGULATOR_VOLTAGE,
608 .owner = THIS_MODULE,
609 .enable_reg = LP8720_ENABLE,
610 .enable_mask = LP8720_EN_BUCK_M,
611 },
612};
613
614static struct regulator_desc lp8725_regulator_desc[] = {
615 {
616 .name = "ldo1",
617 .id = LP8725_ID_LDO1,
618 .ops = &lp872x_ldo_ops,
619 .n_voltages = ARRAY_SIZE(lp872x_ldo_vtbl),
620 .volt_table = lp872x_ldo_vtbl,
621 .type = REGULATOR_VOLTAGE,
622 .owner = THIS_MODULE,
623 .vsel_reg = LP872X_LDO1_VOUT,
624 .vsel_mask = LP872X_VOUT_M,
625 .enable_reg = LP8725_LDO_CTRL,
626 .enable_mask = LP872X_EN_LDO1_M,
627 },
628 {
629 .name = "ldo2",
630 .id = LP8725_ID_LDO2,
631 .ops = &lp872x_ldo_ops,
632 .n_voltages = ARRAY_SIZE(lp872x_ldo_vtbl),
633 .volt_table = lp872x_ldo_vtbl,
634 .type = REGULATOR_VOLTAGE,
635 .owner = THIS_MODULE,
636 .vsel_reg = LP872X_LDO2_VOUT,
637 .vsel_mask = LP872X_VOUT_M,
638 .enable_reg = LP8725_LDO_CTRL,
639 .enable_mask = LP872X_EN_LDO2_M,
640 },
641 {
642 .name = "ldo3",
643 .id = LP8725_ID_LDO3,
644 .ops = &lp872x_ldo_ops,
645 .n_voltages = ARRAY_SIZE(lp872x_ldo_vtbl),
646 .volt_table = lp872x_ldo_vtbl,
647 .type = REGULATOR_VOLTAGE,
648 .owner = THIS_MODULE,
649 .vsel_reg = LP872X_LDO3_VOUT,
650 .vsel_mask = LP872X_VOUT_M,
651 .enable_reg = LP8725_LDO_CTRL,
652 .enable_mask = LP872X_EN_LDO3_M,
653 },
654 {
655 .name = "ldo4",
656 .id = LP8725_ID_LDO4,
657 .ops = &lp872x_ldo_ops,
658 .n_voltages = ARRAY_SIZE(lp872x_ldo_vtbl),
659 .volt_table = lp872x_ldo_vtbl,
660 .type = REGULATOR_VOLTAGE,
661 .owner = THIS_MODULE,
662 .vsel_reg = LP872X_LDO4_VOUT,
663 .vsel_mask = LP872X_VOUT_M,
664 .enable_reg = LP8725_LDO_CTRL,
665 .enable_mask = LP872X_EN_LDO4_M,
666 },
667 {
668 .name = "ldo5",
669 .id = LP8725_ID_LDO5,
670 .ops = &lp872x_ldo_ops,
671 .n_voltages = ARRAY_SIZE(lp872x_ldo_vtbl),
672 .volt_table = lp872x_ldo_vtbl,
673 .type = REGULATOR_VOLTAGE,
674 .owner = THIS_MODULE,
675 .vsel_reg = LP872X_LDO5_VOUT,
676 .vsel_mask = LP872X_VOUT_M,
677 .enable_reg = LP8725_LDO_CTRL,
678 .enable_mask = LP872X_EN_LDO5_M,
679 },
680 {
681 .name = "lilo1",
682 .id = LP8725_ID_LILO1,
683 .ops = &lp872x_ldo_ops,
684 .n_voltages = ARRAY_SIZE(lp8725_lilo_vtbl),
685 .volt_table = lp8725_lilo_vtbl,
686 .type = REGULATOR_VOLTAGE,
687 .owner = THIS_MODULE,
688 .vsel_reg = LP8725_LILO1_VOUT,
689 .vsel_mask = LP872X_VOUT_M,
690 .enable_reg = LP8725_LDO_CTRL,
691 .enable_mask = LP8725_EN_LILO1_M,
692 },
693 {
694 .name = "lilo2",
695 .id = LP8725_ID_LILO2,
696 .ops = &lp872x_ldo_ops,
697 .n_voltages = ARRAY_SIZE(lp8725_lilo_vtbl),
698 .volt_table = lp8725_lilo_vtbl,
699 .type = REGULATOR_VOLTAGE,
700 .owner = THIS_MODULE,
701 .vsel_reg = LP8725_LILO2_VOUT,
702 .vsel_mask = LP872X_VOUT_M,
703 .enable_reg = LP8725_LDO_CTRL,
704 .enable_mask = LP8725_EN_LILO2_M,
705 },
706 {
707 .name = "buck1",
708 .id = LP8725_ID_BUCK1,
709 .ops = &lp8725_buck_ops,
710 .n_voltages = ARRAY_SIZE(lp8725_buck_vtbl),
711 .volt_table = lp8725_buck_vtbl,
712 .type = REGULATOR_VOLTAGE,
713 .owner = THIS_MODULE,
714 .enable_reg = LP872X_GENERAL_CFG,
715 .enable_mask = LP8725_BUCK1_EN_M,
716 },
717 {
718 .name = "buck2",
719 .id = LP8725_ID_BUCK2,
720 .ops = &lp8725_buck_ops,
721 .n_voltages = ARRAY_SIZE(lp8725_buck_vtbl),
722 .volt_table = lp8725_buck_vtbl,
723 .type = REGULATOR_VOLTAGE,
724 .owner = THIS_MODULE,
725 .enable_reg = LP872X_GENERAL_CFG,
726 .enable_mask = LP8725_BUCK2_EN_M,
727 },
728};
729
730static int lp872x_check_dvs_validity(struct lp872x *lp)
731{
732 struct lp872x_dvs *dvs = lp->pdata->dvs;
733 u8 val = 0;
734 int ret;
735
736 ret = lp872x_read_byte(lp, LP872X_GENERAL_CFG, &val);
737 if (ret)
738 return ret;
739
740 ret = 0;
741 if (lp->chipid == LP8720) {
742 if (val & LP8720_EXT_DVS_M)
743 ret = dvs ? 0 : -EINVAL;
744 } else {
745 if ((val & LP8725_DVS1_M) == EXTERN_DVS_USED)
746 ret = dvs ? 0 : -EINVAL;
747 }
748
749 return ret;
750}
751
752static int lp872x_init_dvs(struct lp872x *lp)
753{
754 int ret, gpio;
755 struct lp872x_dvs *dvs = lp->pdata->dvs;
756 enum lp872x_dvs_state pinstate;
757
758 ret = lp872x_check_dvs_validity(lp);
759 if (ret) {
760 dev_warn(lp->dev, "invalid dvs data: %d\n", ret);
761 return ret;
762 }
763
764 gpio = dvs->gpio;
765 if (!gpio_is_valid(gpio)) {
766 dev_err(lp->dev, "invalid gpio: %d\n", gpio);
767 return -EINVAL;
768 }
769
770 pinstate = dvs->init_state;
771 ret = devm_gpio_request_one(lp->dev, gpio, pinstate, "LP872X DVS");
772 if (ret) {
773 dev_err(lp->dev, "gpio request err: %d\n", ret);
774 return ret;
775 }
776
777 lp->dvs_pin = pinstate;
778 lp->dvs_gpio = gpio;
779
780 return 0;
781}
782
783static int lp872x_config(struct lp872x *lp)
784{
785 struct lp872x_platform_data *pdata = lp->pdata;
786 int ret;
787
788 if (!pdata->update_config)
789 return 0;
790
791 ret = lp872x_write_byte(lp, LP872X_GENERAL_CFG, pdata->general_config);
792 if (ret)
793 return ret;
794
795 return lp872x_init_dvs(lp);
796}
797
798static struct regulator_init_data
799*lp872x_find_regulator_init_data(int id, struct lp872x *lp)
800{
801 int i;
802
803 for (i = 0; i < lp->num_regulators; i++) {
804 if (lp->pdata->regulator_data[i].id == id)
805 return lp->pdata->regulator_data[i].init_data;
806 }
807
808 return NULL;
809}
810
811static int lp872x_regulator_register(struct lp872x *lp)
812{
813 struct regulator_desc *desc;
814 struct regulator_config cfg = { };
815 struct regulator_dev *rdev;
816 int i, ret;
817
818 for (i = 0 ; i < lp->num_regulators ; i++) {
819 desc = (lp->chipid == LP8720) ? &lp8720_regulator_desc[i] :
820 &lp8725_regulator_desc[i];
821
822 cfg.dev = lp->dev;
823 cfg.init_data = lp872x_find_regulator_init_data(desc->id, lp);
824 cfg.driver_data = lp;
825 cfg.regmap = lp->regmap;
826
827 rdev = regulator_register(desc, &cfg);
828 if (IS_ERR(rdev)) {
829 dev_err(lp->dev, "regulator register err");
830 ret = PTR_ERR(rdev);
831 goto err;
832 }
833
834 *(lp->regulators + i) = rdev;
835 }
836
837 return 0;
838err:
839 while (--i >= 0) {
840 rdev = *(lp->regulators + i);
841 regulator_unregister(rdev);
842 }
843 return ret;
844}
845
846static void lp872x_regulator_unregister(struct lp872x *lp)
847{
848 struct regulator_dev *rdev;
849 int i;
850
851 for (i = 0 ; i < lp->num_regulators ; i++) {
852 rdev = *(lp->regulators + i);
853 regulator_unregister(rdev);
854 }
855}
856
857static const struct regmap_config lp872x_regmap_config = {
858 .reg_bits = 8,
859 .val_bits = 8,
860 .max_register = MAX_REGISTERS,
861};
862
863static int lp872x_probe(struct i2c_client *cl, const struct i2c_device_id *id)
864{
865 struct lp872x *lp;
866 struct lp872x_platform_data *pdata = cl->dev.platform_data;
867 int ret, size, num_regulators;
868 const int lp872x_num_regulators[] = {
869 [LP8720] = LP8720_NUM_REGULATORS,
870 [LP8725] = LP8725_NUM_REGULATORS,
871 };
872
873 if (!pdata) {
874 dev_err(&cl->dev, "no platform data\n");
875 return -EINVAL;
876 }
877
878 lp = devm_kzalloc(&cl->dev, sizeof(struct lp872x), GFP_KERNEL);
879 if (!lp)
880 goto err_mem;
881
882 num_regulators = lp872x_num_regulators[id->driver_data];
883 size = sizeof(struct regulator_dev *) * num_regulators;
884
885 lp->regulators = devm_kzalloc(&cl->dev, size, GFP_KERNEL);
886 if (!lp->regulators)
887 goto err_mem;
888
889 lp->regmap = devm_regmap_init_i2c(cl, &lp872x_regmap_config);
890 if (IS_ERR(lp->regmap)) {
891 ret = PTR_ERR(lp->regmap);
892 dev_err(&cl->dev, "regmap init i2c err: %d\n", ret);
893 goto err_dev;
894 }
895
896 lp->dev = &cl->dev;
897 lp->pdata = pdata;
898 lp->chipid = id->driver_data;
899 lp->num_regulators = num_regulators;
900 i2c_set_clientdata(cl, lp);
901
902 ret = lp872x_config(lp);
903 if (ret)
904 goto err_dev;
905
906 return lp872x_regulator_register(lp);
907
908err_mem:
909 return -ENOMEM;
910err_dev:
911 return ret;
912}
913
914static int __devexit lp872x_remove(struct i2c_client *cl)
915{
916 struct lp872x *lp = i2c_get_clientdata(cl);
917
918 lp872x_regulator_unregister(lp);
919 return 0;
920}
921
922static const struct i2c_device_id lp872x_ids[] = {
923 {"lp8720", LP8720},
924 {"lp8725", LP8725},
925 { }
926};
927MODULE_DEVICE_TABLE(i2c, lp872x_ids);
928
929static struct i2c_driver lp872x_driver = {
930 .driver = {
931 .name = "lp872x",
932 .owner = THIS_MODULE,
933 },
934 .probe = lp872x_probe,
935 .remove = __devexit_p(lp872x_remove),
936 .id_table = lp872x_ids,
937};
938
939module_i2c_driver(lp872x_driver);
940
941MODULE_DESCRIPTION("TI/National Semiconductor LP872x PMU Regulator Driver");
942MODULE_AUTHOR("Milo Kim");
943MODULE_LICENSE("GPL");
diff --git a/drivers/regulator/lp8788-buck.c b/drivers/regulator/lp8788-buck.c
new file mode 100644
index 000000000000..6356e821400f
--- /dev/null
+++ b/drivers/regulator/lp8788-buck.c
@@ -0,0 +1,629 @@
1/*
2 * TI LP8788 MFD - buck regulator driver
3 *
4 * Copyright 2012 Texas Instruments
5 *
6 * Author: Milo(Woogyom) Kim <milo.kim@ti.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 */
13
14#include <linux/module.h>
15#include <linux/slab.h>
16#include <linux/err.h>
17#include <linux/platform_device.h>
18#include <linux/regulator/driver.h>
19#include <linux/mfd/lp8788.h>
20#include <linux/gpio.h>
21
22/* register address */
23#define LP8788_EN_BUCK 0x0C
24#define LP8788_BUCK_DVS_SEL 0x1D
25#define LP8788_BUCK1_VOUT0 0x1E
26#define LP8788_BUCK1_VOUT1 0x1F
27#define LP8788_BUCK1_VOUT2 0x20
28#define LP8788_BUCK1_VOUT3 0x21
29#define LP8788_BUCK2_VOUT0 0x22
30#define LP8788_BUCK2_VOUT1 0x23
31#define LP8788_BUCK2_VOUT2 0x24
32#define LP8788_BUCK2_VOUT3 0x25
33#define LP8788_BUCK3_VOUT 0x26
34#define LP8788_BUCK4_VOUT 0x27
35#define LP8788_BUCK1_TIMESTEP 0x28
36#define LP8788_BUCK_PWM 0x2D
37
38/* mask/shift bits */
39#define LP8788_EN_BUCK1_M BIT(0) /* Addr 0Ch */
40#define LP8788_EN_BUCK2_M BIT(1)
41#define LP8788_EN_BUCK3_M BIT(2)
42#define LP8788_EN_BUCK4_M BIT(3)
43#define LP8788_BUCK1_DVS_SEL_M 0x04 /* Addr 1Dh */
44#define LP8788_BUCK1_DVS_M 0x03
45#define LP8788_BUCK1_DVS_S 0
46#define LP8788_BUCK2_DVS_SEL_M 0x40
47#define LP8788_BUCK2_DVS_M 0x30
48#define LP8788_BUCK2_DVS_S 4
49#define LP8788_BUCK1_DVS_I2C BIT(2)
50#define LP8788_BUCK2_DVS_I2C BIT(6)
51#define LP8788_BUCK1_DVS_PIN (0 << 2)
52#define LP8788_BUCK2_DVS_PIN (0 << 6)
53#define LP8788_VOUT_M 0x1F /* Addr 1Eh ~ 27h */
54#define LP8788_STARTUP_TIME_M 0xF8 /* Addr 28h ~ 2Bh */
55#define LP8788_STARTUP_TIME_S 3
56#define LP8788_FPWM_BUCK1_M BIT(0) /* Addr 2Dh */
57#define LP8788_FPWM_BUCK1_S 0
58#define LP8788_FPWM_BUCK2_M BIT(1)
59#define LP8788_FPWM_BUCK2_S 1
60#define LP8788_FPWM_BUCK3_M BIT(2)
61#define LP8788_FPWM_BUCK3_S 2
62#define LP8788_FPWM_BUCK4_M BIT(3)
63#define LP8788_FPWM_BUCK4_S 3
64
65#define INVALID_ADDR 0xFF
66#define LP8788_FORCE_PWM 1
67#define LP8788_AUTO_PWM 0
68#define PIN_LOW 0
69#define PIN_HIGH 1
70#define ENABLE_TIME_USEC 32
71
72enum lp8788_dvs_state {
73 DVS_LOW = GPIOF_OUT_INIT_LOW,
74 DVS_HIGH = GPIOF_OUT_INIT_HIGH,
75};
76
77enum lp8788_dvs_mode {
78 REGISTER,
79 EXTPIN,
80};
81
82enum lp8788_buck_id {
83 BUCK1,
84 BUCK2,
85 BUCK3,
86 BUCK4,
87};
88
89struct lp8788_pwm_map {
90 u8 mask;
91 u8 shift;
92};
93
94struct lp8788_buck {
95 struct lp8788 *lp;
96 struct regulator_dev *regulator;
97 struct lp8788_pwm_map *pmap;
98 void *dvs;
99};
100
101/* BUCK 1 ~ 4 voltage table */
102static const int lp8788_buck_vtbl[] = {
103 500000, 800000, 850000, 900000, 950000, 1000000, 1050000, 1100000,
104 1150000, 1200000, 1250000, 1300000, 1350000, 1400000, 1450000, 1500000,
105 1550000, 1600000, 1650000, 1700000, 1750000, 1800000, 1850000, 1900000,
106 1950000, 2000000,
107};
108
109/* buck pwm mode selection : used for set/get_mode in regulator ops
110 * @forced pwm : fast mode
111 * @auto pwm : normal mode
112 */
113static struct lp8788_pwm_map buck_pmap[] = {
114 [BUCK1] = {
115 .mask = LP8788_FPWM_BUCK1_M,
116 .shift = LP8788_FPWM_BUCK1_S,
117 },
118 [BUCK2] = {
119 .mask = LP8788_FPWM_BUCK2_M,
120 .shift = LP8788_FPWM_BUCK2_S,
121 },
122 [BUCK3] = {
123 .mask = LP8788_FPWM_BUCK3_M,
124 .shift = LP8788_FPWM_BUCK3_S,
125 },
126 [BUCK4] = {
127 .mask = LP8788_FPWM_BUCK4_M,
128 .shift = LP8788_FPWM_BUCK4_S,
129 },
130};
131
132static const u8 buck1_vout_addr[] = {
133 LP8788_BUCK1_VOUT0, LP8788_BUCK1_VOUT1,
134 LP8788_BUCK1_VOUT2, LP8788_BUCK1_VOUT3,
135};
136
137static const u8 buck2_vout_addr[] = {
138 LP8788_BUCK2_VOUT0, LP8788_BUCK2_VOUT1,
139 LP8788_BUCK2_VOUT2, LP8788_BUCK2_VOUT3,
140};
141
142static void lp8788_buck1_set_dvs(struct lp8788_buck *buck)
143{
144 struct lp8788_buck1_dvs *dvs = (struct lp8788_buck1_dvs *)buck->dvs;
145 enum lp8788_dvs_state pinstate;
146
147 if (!dvs)
148 return;
149
150 pinstate = dvs->vsel == DVS_SEL_V0 ? DVS_LOW : DVS_HIGH;
151 if (gpio_is_valid(dvs->gpio))
152 gpio_set_value(dvs->gpio, pinstate);
153}
154
155static void lp8788_buck2_set_dvs(struct lp8788_buck *buck)
156{
157 struct lp8788_buck2_dvs *dvs = (struct lp8788_buck2_dvs *)buck->dvs;
158 enum lp8788_dvs_state pin1, pin2;
159
160 if (!dvs)
161 return;
162
163 switch (dvs->vsel) {
164 case DVS_SEL_V0:
165 pin1 = DVS_LOW;
166 pin2 = DVS_LOW;
167 break;
168 case DVS_SEL_V1:
169 pin1 = DVS_HIGH;
170 pin2 = DVS_LOW;
171 break;
172 case DVS_SEL_V2:
173 pin1 = DVS_LOW;
174 pin2 = DVS_HIGH;
175 break;
176 case DVS_SEL_V3:
177 pin1 = DVS_HIGH;
178 pin2 = DVS_HIGH;
179 break;
180 default:
181 return;
182 }
183
184 if (gpio_is_valid(dvs->gpio[0]))
185 gpio_set_value(dvs->gpio[0], pin1);
186
187 if (gpio_is_valid(dvs->gpio[1]))
188 gpio_set_value(dvs->gpio[1], pin2);
189}
190
191static void lp8788_set_dvs(struct lp8788_buck *buck, enum lp8788_buck_id id)
192{
193 switch (id) {
194 case BUCK1:
195 lp8788_buck1_set_dvs(buck);
196 break;
197 case BUCK2:
198 lp8788_buck2_set_dvs(buck);
199 break;
200 default:
201 break;
202 }
203}
204
205static enum lp8788_dvs_mode
206lp8788_get_buck_dvs_ctrl_mode(struct lp8788_buck *buck, enum lp8788_buck_id id)
207{
208 u8 val, mask;
209
210 switch (id) {
211 case BUCK1:
212 mask = LP8788_BUCK1_DVS_SEL_M;
213 break;
214 case BUCK2:
215 mask = LP8788_BUCK2_DVS_SEL_M;
216 break;
217 default:
218 return REGISTER;
219 }
220
221 lp8788_read_byte(buck->lp, LP8788_BUCK_DVS_SEL, &val);
222
223 return val & mask ? REGISTER : EXTPIN;
224}
225
226static bool lp8788_is_valid_buck_addr(u8 addr)
227{
228 switch (addr) {
229 case LP8788_BUCK1_VOUT0:
230 case LP8788_BUCK1_VOUT1:
231 case LP8788_BUCK1_VOUT2:
232 case LP8788_BUCK1_VOUT3:
233 case LP8788_BUCK2_VOUT0:
234 case LP8788_BUCK2_VOUT1:
235 case LP8788_BUCK2_VOUT2:
236 case LP8788_BUCK2_VOUT3:
237 return true;
238 default:
239 return false;
240 }
241}
242
243static u8 lp8788_select_buck_vout_addr(struct lp8788_buck *buck,
244 enum lp8788_buck_id id)
245{
246 enum lp8788_dvs_mode mode = lp8788_get_buck_dvs_ctrl_mode(buck, id);
247 struct lp8788_buck1_dvs *b1_dvs;
248 struct lp8788_buck2_dvs *b2_dvs;
249 u8 val, idx, addr;
250 int pin1, pin2;
251
252 switch (id) {
253 case BUCK1:
254 if (mode == EXTPIN) {
255 b1_dvs = (struct lp8788_buck1_dvs *)buck->dvs;
256 if (!b1_dvs)
257 goto err;
258
259 idx = gpio_get_value(b1_dvs->gpio) ? 1 : 0;
260 } else {
261 lp8788_read_byte(buck->lp, LP8788_BUCK_DVS_SEL, &val);
262 idx = (val & LP8788_BUCK1_DVS_M) >> LP8788_BUCK1_DVS_S;
263 }
264 addr = buck1_vout_addr[idx];
265 break;
266 case BUCK2:
267 if (mode == EXTPIN) {
268 b2_dvs = (struct lp8788_buck2_dvs *)buck->dvs;
269 if (!b2_dvs)
270 goto err;
271
272 pin1 = gpio_get_value(b2_dvs->gpio[0]);
273 pin2 = gpio_get_value(b2_dvs->gpio[1]);
274
275 if (pin1 == PIN_LOW && pin2 == PIN_LOW)
276 idx = 0;
277 else if (pin1 == PIN_LOW && pin2 == PIN_HIGH)
278 idx = 2;
279 else if (pin1 == PIN_HIGH && pin2 == PIN_LOW)
280 idx = 1;
281 else
282 idx = 3;
283 } else {
284 lp8788_read_byte(buck->lp, LP8788_BUCK_DVS_SEL, &val);
285 idx = (val & LP8788_BUCK2_DVS_M) >> LP8788_BUCK2_DVS_S;
286 }
287 addr = buck2_vout_addr[idx];
288 break;
289 default:
290 goto err;
291 }
292
293 return addr;
294err:
295 return INVALID_ADDR;
296}
297
298static int lp8788_buck12_set_voltage_sel(struct regulator_dev *rdev,
299 unsigned selector)
300{
301 struct lp8788_buck *buck = rdev_get_drvdata(rdev);
302 enum lp8788_buck_id id = rdev_get_id(rdev);
303 u8 addr;
304
305 if (buck->dvs)
306 lp8788_set_dvs(buck, id);
307
308 addr = lp8788_select_buck_vout_addr(buck, id);
309 if (!lp8788_is_valid_buck_addr(addr))
310 return -EINVAL;
311
312 return lp8788_update_bits(buck->lp, addr, LP8788_VOUT_M, selector);
313}
314
315static int lp8788_buck12_get_voltage_sel(struct regulator_dev *rdev)
316{
317 struct lp8788_buck *buck = rdev_get_drvdata(rdev);
318 enum lp8788_buck_id id = rdev_get_id(rdev);
319 int ret;
320 u8 val, addr;
321
322 addr = lp8788_select_buck_vout_addr(buck, id);
323 if (!lp8788_is_valid_buck_addr(addr))
324 return -EINVAL;
325
326 ret = lp8788_read_byte(buck->lp, addr, &val);
327 if (ret)
328 return ret;
329
330 return val & LP8788_VOUT_M;
331}
332
333static int lp8788_buck_enable_time(struct regulator_dev *rdev)
334{
335 struct lp8788_buck *buck = rdev_get_drvdata(rdev);
336 enum lp8788_buck_id id = rdev_get_id(rdev);
337 u8 val, addr = LP8788_BUCK1_TIMESTEP + id;
338
339 if (lp8788_read_byte(buck->lp, addr, &val))
340 return -EINVAL;
341
342 val = (val & LP8788_STARTUP_TIME_M) >> LP8788_STARTUP_TIME_S;
343
344 return ENABLE_TIME_USEC * val;
345}
346
347static int lp8788_buck_set_mode(struct regulator_dev *rdev, unsigned int mode)
348{
349 struct lp8788_buck *buck = rdev_get_drvdata(rdev);
350 struct lp8788_pwm_map *pmap = buck->pmap;
351 u8 val;
352
353 if (!pmap)
354 return -EINVAL;
355
356 switch (mode) {
357 case REGULATOR_MODE_FAST:
358 val = LP8788_FORCE_PWM << pmap->shift;
359 break;
360 case REGULATOR_MODE_NORMAL:
361 val = LP8788_AUTO_PWM << pmap->shift;
362 break;
363 default:
364 return -EINVAL;
365 }
366
367 return lp8788_update_bits(buck->lp, LP8788_BUCK_PWM, pmap->mask, val);
368}
369
370static unsigned int lp8788_buck_get_mode(struct regulator_dev *rdev)
371{
372 struct lp8788_buck *buck = rdev_get_drvdata(rdev);
373 struct lp8788_pwm_map *pmap = buck->pmap;
374 u8 val;
375 int ret;
376
377 if (!pmap)
378 return -EINVAL;
379
380 ret = lp8788_read_byte(buck->lp, LP8788_BUCK_PWM, &val);
381 if (ret)
382 return ret;
383
384 return val & pmap->mask ? REGULATOR_MODE_FAST : REGULATOR_MODE_NORMAL;
385}
386
387static struct regulator_ops lp8788_buck12_ops = {
388 .list_voltage = regulator_list_voltage_table,
389 .set_voltage_sel = lp8788_buck12_set_voltage_sel,
390 .get_voltage_sel = lp8788_buck12_get_voltage_sel,
391 .enable = regulator_enable_regmap,
392 .disable = regulator_disable_regmap,
393 .is_enabled = regulator_is_enabled_regmap,
394 .enable_time = lp8788_buck_enable_time,
395 .set_mode = lp8788_buck_set_mode,
396 .get_mode = lp8788_buck_get_mode,
397};
398
399static struct regulator_ops lp8788_buck34_ops = {
400 .list_voltage = regulator_list_voltage_table,
401 .set_voltage_sel = regulator_set_voltage_sel_regmap,
402 .get_voltage_sel = regulator_get_voltage_sel_regmap,
403 .enable = regulator_enable_regmap,
404 .disable = regulator_disable_regmap,
405 .is_enabled = regulator_is_enabled_regmap,
406 .enable_time = lp8788_buck_enable_time,
407 .set_mode = lp8788_buck_set_mode,
408 .get_mode = lp8788_buck_get_mode,
409};
410
411static struct regulator_desc lp8788_buck_desc[] = {
412 {
413 .name = "buck1",
414 .id = BUCK1,
415 .ops = &lp8788_buck12_ops,
416 .n_voltages = ARRAY_SIZE(lp8788_buck_vtbl),
417 .volt_table = lp8788_buck_vtbl,
418 .type = REGULATOR_VOLTAGE,
419 .owner = THIS_MODULE,
420 .enable_reg = LP8788_EN_BUCK,
421 .enable_mask = LP8788_EN_BUCK1_M,
422 },
423 {
424 .name = "buck2",
425 .id = BUCK2,
426 .ops = &lp8788_buck12_ops,
427 .n_voltages = ARRAY_SIZE(lp8788_buck_vtbl),
428 .volt_table = lp8788_buck_vtbl,
429 .type = REGULATOR_VOLTAGE,
430 .owner = THIS_MODULE,
431 .enable_reg = LP8788_EN_BUCK,
432 .enable_mask = LP8788_EN_BUCK2_M,
433 },
434 {
435 .name = "buck3",
436 .id = BUCK3,
437 .ops = &lp8788_buck34_ops,
438 .n_voltages = ARRAY_SIZE(lp8788_buck_vtbl),
439 .volt_table = lp8788_buck_vtbl,
440 .type = REGULATOR_VOLTAGE,
441 .owner = THIS_MODULE,
442 .vsel_reg = LP8788_BUCK3_VOUT,
443 .vsel_mask = LP8788_VOUT_M,
444 .enable_reg = LP8788_EN_BUCK,
445 .enable_mask = LP8788_EN_BUCK3_M,
446 },
447 {
448 .name = "buck4",
449 .id = BUCK4,
450 .ops = &lp8788_buck34_ops,
451 .n_voltages = ARRAY_SIZE(lp8788_buck_vtbl),
452 .volt_table = lp8788_buck_vtbl,
453 .type = REGULATOR_VOLTAGE,
454 .owner = THIS_MODULE,
455 .vsel_reg = LP8788_BUCK4_VOUT,
456 .vsel_mask = LP8788_VOUT_M,
457 .enable_reg = LP8788_EN_BUCK,
458 .enable_mask = LP8788_EN_BUCK4_M,
459 },
460};
461
462static int lp8788_set_default_dvs_ctrl_mode(struct lp8788 *lp,
463 enum lp8788_buck_id id)
464{
465 u8 mask, val;
466
467 switch (id) {
468 case BUCK1:
469 mask = LP8788_BUCK1_DVS_SEL_M;
470 val = LP8788_BUCK1_DVS_I2C;
471 break;
472 case BUCK2:
473 mask = LP8788_BUCK2_DVS_SEL_M;
474 val = LP8788_BUCK2_DVS_I2C;
475 break;
476 default:
477 return 0;
478 }
479
480 return lp8788_update_bits(lp, LP8788_BUCK_DVS_SEL, mask, val);
481}
482
483static int _gpio_request(struct lp8788_buck *buck, int gpio, char *name)
484{
485 struct device *dev = buck->lp->dev;
486
487 if (!gpio_is_valid(gpio)) {
488 dev_err(dev, "invalid gpio: %d\n", gpio);
489 return -EINVAL;
490 }
491
492 return devm_gpio_request_one(dev, gpio, DVS_LOW, name);
493}
494
495static int lp8788_dvs_gpio_request(struct lp8788_buck *buck,
496 enum lp8788_buck_id id)
497{
498 struct lp8788_platform_data *pdata = buck->lp->pdata;
499 char *b1_name = "LP8788_B1_DVS";
500 char *b2_name[] = { "LP8788_B2_DVS1", "LP8788_B2_DVS2" };
501 int i, gpio, ret;
502
503 switch (id) {
504 case BUCK1:
505 gpio = pdata->buck1_dvs->gpio;
506 ret = _gpio_request(buck, gpio, b1_name);
507 if (ret)
508 return ret;
509
510 buck->dvs = pdata->buck1_dvs;
511 break;
512 case BUCK2:
513 for (i = 0 ; i < LP8788_NUM_BUCK2_DVS ; i++) {
514 gpio = pdata->buck2_dvs->gpio[i];
515 ret = _gpio_request(buck, gpio, b2_name[i]);
516 if (ret)
517 return ret;
518 }
519 buck->dvs = pdata->buck2_dvs;
520 break;
521 default:
522 break;
523 }
524
525 return 0;
526}
527
528static int lp8788_init_dvs(struct lp8788_buck *buck, enum lp8788_buck_id id)
529{
530 struct lp8788_platform_data *pdata = buck->lp->pdata;
531 u8 mask[] = { LP8788_BUCK1_DVS_SEL_M, LP8788_BUCK2_DVS_SEL_M };
532 u8 val[] = { LP8788_BUCK1_DVS_PIN, LP8788_BUCK2_DVS_PIN };
533
534 /* no dvs for buck3, 4 */
535 if (id == BUCK3 || id == BUCK4)
536 return 0;
537
538 /* no dvs platform data, then dvs will be selected by I2C registers */
539 if (!pdata)
540 goto set_default_dvs_mode;
541
542 if ((id == BUCK1 && !pdata->buck1_dvs) ||
543 (id == BUCK2 && !pdata->buck2_dvs))
544 goto set_default_dvs_mode;
545
546 if (lp8788_dvs_gpio_request(buck, id))
547 goto set_default_dvs_mode;
548
549 return lp8788_update_bits(buck->lp, LP8788_BUCK_DVS_SEL, mask[id],
550 val[id]);
551
552set_default_dvs_mode:
553 return lp8788_set_default_dvs_ctrl_mode(buck->lp, id);
554}
555
556static __devinit int lp8788_buck_probe(struct platform_device *pdev)
557{
558 struct lp8788 *lp = dev_get_drvdata(pdev->dev.parent);
559 int id = pdev->id;
560 struct lp8788_buck *buck;
561 struct regulator_config cfg = { };
562 struct regulator_dev *rdev;
563 int ret;
564
565 buck = devm_kzalloc(lp->dev, sizeof(struct lp8788_buck), GFP_KERNEL);
566 if (!buck)
567 return -ENOMEM;
568
569 buck->lp = lp;
570 buck->pmap = &buck_pmap[id];
571
572 ret = lp8788_init_dvs(buck, id);
573 if (ret)
574 return ret;
575
576 cfg.dev = lp->dev;
577 cfg.init_data = lp->pdata ? lp->pdata->buck_data[id] : NULL;
578 cfg.driver_data = buck;
579 cfg.regmap = lp->regmap;
580
581 rdev = regulator_register(&lp8788_buck_desc[id], &cfg);
582 if (IS_ERR(rdev)) {
583 ret = PTR_ERR(rdev);
584 dev_err(lp->dev, "BUCK%d regulator register err = %d\n",
585 id + 1, ret);
586 return ret;
587 }
588
589 buck->regulator = rdev;
590 platform_set_drvdata(pdev, buck);
591
592 return 0;
593}
594
595static int __devexit lp8788_buck_remove(struct platform_device *pdev)
596{
597 struct lp8788_buck *buck = platform_get_drvdata(pdev);
598
599 platform_set_drvdata(pdev, NULL);
600 regulator_unregister(buck->regulator);
601
602 return 0;
603}
604
605static struct platform_driver lp8788_buck_driver = {
606 .probe = lp8788_buck_probe,
607 .remove = __devexit_p(lp8788_buck_remove),
608 .driver = {
609 .name = LP8788_DEV_BUCK,
610 .owner = THIS_MODULE,
611 },
612};
613
614static int __init lp8788_buck_init(void)
615{
616 return platform_driver_register(&lp8788_buck_driver);
617}
618subsys_initcall(lp8788_buck_init);
619
620static void __exit lp8788_buck_exit(void)
621{
622 platform_driver_unregister(&lp8788_buck_driver);
623}
624module_exit(lp8788_buck_exit);
625
626MODULE_DESCRIPTION("TI LP8788 BUCK Driver");
627MODULE_AUTHOR("Milo Kim");
628MODULE_LICENSE("GPL");
629MODULE_ALIAS("platform:lp8788-buck");
diff --git a/drivers/regulator/lp8788-ldo.c b/drivers/regulator/lp8788-ldo.c
new file mode 100644
index 000000000000..d2122e41a96d
--- /dev/null
+++ b/drivers/regulator/lp8788-ldo.c
@@ -0,0 +1,842 @@
1/*
2 * TI LP8788 MFD - ldo regulator driver
3 *
4 * Copyright 2012 Texas Instruments
5 *
6 * Author: Milo(Woogyom) Kim <milo.kim@ti.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 */
13
14#include <linux/module.h>
15#include <linux/slab.h>
16#include <linux/err.h>
17#include <linux/platform_device.h>
18#include <linux/regulator/driver.h>
19#include <linux/gpio.h>
20#include <linux/mfd/lp8788.h>
21
22/* register address */
23#define LP8788_EN_LDO_A 0x0D /* DLDO 1 ~ 8 */
24#define LP8788_EN_LDO_B 0x0E /* DLDO 9 ~ 12, ALDO 1 ~ 4 */
25#define LP8788_EN_LDO_C 0x0F /* ALDO 5 ~ 10 */
26#define LP8788_EN_SEL 0x10
27#define LP8788_DLDO1_VOUT 0x2E
28#define LP8788_DLDO2_VOUT 0x2F
29#define LP8788_DLDO3_VOUT 0x30
30#define LP8788_DLDO4_VOUT 0x31
31#define LP8788_DLDO5_VOUT 0x32
32#define LP8788_DLDO6_VOUT 0x33
33#define LP8788_DLDO7_VOUT 0x34
34#define LP8788_DLDO8_VOUT 0x35
35#define LP8788_DLDO9_VOUT 0x36
36#define LP8788_DLDO10_VOUT 0x37
37#define LP8788_DLDO11_VOUT 0x38
38#define LP8788_DLDO12_VOUT 0x39
39#define LP8788_ALDO1_VOUT 0x3A
40#define LP8788_ALDO2_VOUT 0x3B
41#define LP8788_ALDO3_VOUT 0x3C
42#define LP8788_ALDO4_VOUT 0x3D
43#define LP8788_ALDO5_VOUT 0x3E
44#define LP8788_ALDO6_VOUT 0x3F
45#define LP8788_ALDO7_VOUT 0x40
46#define LP8788_ALDO8_VOUT 0x41
47#define LP8788_ALDO9_VOUT 0x42
48#define LP8788_ALDO10_VOUT 0x43
49#define LP8788_DLDO1_TIMESTEP 0x44
50
51/* mask/shift bits */
52#define LP8788_EN_DLDO1_M BIT(0) /* Addr 0Dh ~ 0Fh */
53#define LP8788_EN_DLDO2_M BIT(1)
54#define LP8788_EN_DLDO3_M BIT(2)
55#define LP8788_EN_DLDO4_M BIT(3)
56#define LP8788_EN_DLDO5_M BIT(4)
57#define LP8788_EN_DLDO6_M BIT(5)
58#define LP8788_EN_DLDO7_M BIT(6)
59#define LP8788_EN_DLDO8_M BIT(7)
60#define LP8788_EN_DLDO9_M BIT(0)
61#define LP8788_EN_DLDO10_M BIT(1)
62#define LP8788_EN_DLDO11_M BIT(2)
63#define LP8788_EN_DLDO12_M BIT(3)
64#define LP8788_EN_ALDO1_M BIT(4)
65#define LP8788_EN_ALDO2_M BIT(5)
66#define LP8788_EN_ALDO3_M BIT(6)
67#define LP8788_EN_ALDO4_M BIT(7)
68#define LP8788_EN_ALDO5_M BIT(0)
69#define LP8788_EN_ALDO6_M BIT(1)
70#define LP8788_EN_ALDO7_M BIT(2)
71#define LP8788_EN_ALDO8_M BIT(3)
72#define LP8788_EN_ALDO9_M BIT(4)
73#define LP8788_EN_ALDO10_M BIT(5)
74#define LP8788_EN_SEL_DLDO911_M BIT(0) /* Addr 10h */
75#define LP8788_EN_SEL_DLDO7_M BIT(1)
76#define LP8788_EN_SEL_ALDO7_M BIT(2)
77#define LP8788_EN_SEL_ALDO5_M BIT(3)
78#define LP8788_EN_SEL_ALDO234_M BIT(4)
79#define LP8788_EN_SEL_ALDO1_M BIT(5)
80#define LP8788_VOUT_5BIT_M 0x1F /* Addr 2Eh ~ 43h */
81#define LP8788_VOUT_4BIT_M 0x0F
82#define LP8788_VOUT_3BIT_M 0x07
83#define LP8788_VOUT_1BIT_M 0x01
84#define LP8788_STARTUP_TIME_M 0xF8 /* Addr 44h ~ 59h */
85#define LP8788_STARTUP_TIME_S 3
86
87#define ENABLE_TIME_USEC 32
88#define ENABLE GPIOF_OUT_INIT_HIGH
89#define DISABLE GPIOF_OUT_INIT_LOW
90
91enum lp8788_enable_mode {
92 REGISTER,
93 EXTPIN,
94};
95
96enum lp8788_ldo_id {
97 DLDO1,
98 DLDO2,
99 DLDO3,
100 DLDO4,
101 DLDO5,
102 DLDO6,
103 DLDO7,
104 DLDO8,
105 DLDO9,
106 DLDO10,
107 DLDO11,
108 DLDO12,
109 ALDO1,
110 ALDO2,
111 ALDO3,
112 ALDO4,
113 ALDO5,
114 ALDO6,
115 ALDO7,
116 ALDO8,
117 ALDO9,
118 ALDO10,
119};
120
121struct lp8788_ldo {
122 struct lp8788 *lp;
123 struct regulator_desc *desc;
124 struct regulator_dev *regulator;
125 struct lp8788_ldo_enable_pin *en_pin;
126};
127
128/* DLDO 1, 2, 3, 9 voltage table */
129const int lp8788_dldo1239_vtbl[] = {
130 1800000, 1900000, 2000000, 2100000, 2200000, 2300000, 2400000, 2500000,
131 2600000, 2700000, 2800000, 2900000, 3000000, 2850000, 2850000, 2850000,
132 2850000, 2850000, 2850000, 2850000, 2850000, 2850000, 2850000, 2850000,
133 2850000, 2850000, 2850000, 2850000, 2850000, 2850000, 2850000, 2850000,
134};
135
136/* DLDO 4 voltage table */
137static const int lp8788_dldo4_vtbl[] = { 1800000, 3000000 };
138
139/* DLDO 5, 7, 8 and ALDO 6 voltage table */
140static const int lp8788_dldo578_aldo6_vtbl[] = {
141 1800000, 1900000, 2000000, 2100000, 2200000, 2300000, 2400000, 2500000,
142 2600000, 2700000, 2800000, 2900000, 3000000, 3000000, 3000000, 3000000,
143};
144
145/* DLDO 6 voltage table */
146static const int lp8788_dldo6_vtbl[] = {
147 3000000, 3100000, 3200000, 3300000, 3400000, 3500000, 3600000, 3600000,
148};
149
150/* DLDO 10, 11 voltage table */
151static const int lp8788_dldo1011_vtbl[] = {
152 1100000, 1150000, 1200000, 1250000, 1300000, 1350000, 1400000, 1450000,
153 1500000, 1500000, 1500000, 1500000, 1500000, 1500000, 1500000, 1500000,
154};
155
156/* ALDO 1 voltage table */
157static const int lp8788_aldo1_vtbl[] = { 1800000, 2850000 };
158
159/* ALDO 7 voltage table */
160static const int lp8788_aldo7_vtbl[] = {
161 1200000, 1300000, 1400000, 1500000, 1600000, 1700000, 1800000, 1800000,
162};
163
164static enum lp8788_ldo_id lp8788_dldo_id[] = {
165 DLDO1,
166 DLDO2,
167 DLDO3,
168 DLDO4,
169 DLDO5,
170 DLDO6,
171 DLDO7,
172 DLDO8,
173 DLDO9,
174 DLDO10,
175 DLDO11,
176 DLDO12,
177};
178
179static enum lp8788_ldo_id lp8788_aldo_id[] = {
180 ALDO1,
181 ALDO2,
182 ALDO3,
183 ALDO4,
184 ALDO5,
185 ALDO6,
186 ALDO7,
187 ALDO8,
188 ALDO9,
189 ALDO10,
190};
191
192/* DLDO 7, 9 and 11, ALDO 1 ~ 5 and 7
193 : can be enabled either by external pin or by i2c register */
194static enum lp8788_enable_mode
195lp8788_get_ldo_enable_mode(struct lp8788_ldo *ldo, enum lp8788_ldo_id id)
196{
197 int ret;
198 u8 val, mask;
199
200 ret = lp8788_read_byte(ldo->lp, LP8788_EN_SEL, &val);
201 if (ret)
202 return ret;
203
204 switch (id) {
205 case DLDO7:
206 mask = LP8788_EN_SEL_DLDO7_M;
207 break;
208 case DLDO9:
209 case DLDO11:
210 mask = LP8788_EN_SEL_DLDO911_M;
211 break;
212 case ALDO1:
213 mask = LP8788_EN_SEL_ALDO1_M;
214 break;
215 case ALDO2 ... ALDO4:
216 mask = LP8788_EN_SEL_ALDO234_M;
217 break;
218 case ALDO5:
219 mask = LP8788_EN_SEL_ALDO5_M;
220 break;
221 case ALDO7:
222 mask = LP8788_EN_SEL_ALDO7_M;
223 break;
224 default:
225 return REGISTER;
226 }
227
228 return val & mask ? EXTPIN : REGISTER;
229}
230
231static int lp8788_ldo_ctrl_by_extern_pin(struct lp8788_ldo *ldo, int pinstate)
232{
233 struct lp8788_ldo_enable_pin *pin = ldo->en_pin;
234
235 if (!pin)
236 return -EINVAL;
237
238 if (gpio_is_valid(pin->gpio))
239 gpio_set_value(pin->gpio, pinstate);
240
241 return 0;
242}
243
244static int lp8788_ldo_is_enabled_by_extern_pin(struct lp8788_ldo *ldo)
245{
246 struct lp8788_ldo_enable_pin *pin = ldo->en_pin;
247
248 if (!pin)
249 return -EINVAL;
250
251 return gpio_get_value(pin->gpio) ? 1 : 0;
252}
253
254static int lp8788_ldo_enable(struct regulator_dev *rdev)
255{
256 struct lp8788_ldo *ldo = rdev_get_drvdata(rdev);
257 enum lp8788_ldo_id id = rdev_get_id(rdev);
258 enum lp8788_enable_mode mode = lp8788_get_ldo_enable_mode(ldo, id);
259
260 switch (mode) {
261 case EXTPIN:
262 return lp8788_ldo_ctrl_by_extern_pin(ldo, ENABLE);
263 case REGISTER:
264 return regulator_enable_regmap(rdev);
265 default:
266 return -EINVAL;
267 }
268}
269
270static int lp8788_ldo_disable(struct regulator_dev *rdev)
271{
272 struct lp8788_ldo *ldo = rdev_get_drvdata(rdev);
273 enum lp8788_ldo_id id = rdev_get_id(rdev);
274 enum lp8788_enable_mode mode = lp8788_get_ldo_enable_mode(ldo, id);
275
276 switch (mode) {
277 case EXTPIN:
278 return lp8788_ldo_ctrl_by_extern_pin(ldo, DISABLE);
279 case REGISTER:
280 return regulator_disable_regmap(rdev);
281 default:
282 return -EINVAL;
283 }
284}
285
286static int lp8788_ldo_is_enabled(struct regulator_dev *rdev)
287{
288 struct lp8788_ldo *ldo = rdev_get_drvdata(rdev);
289 enum lp8788_ldo_id id = rdev_get_id(rdev);
290 enum lp8788_enable_mode mode = lp8788_get_ldo_enable_mode(ldo, id);
291
292 switch (mode) {
293 case EXTPIN:
294 return lp8788_ldo_is_enabled_by_extern_pin(ldo);
295 case REGISTER:
296 return regulator_is_enabled_regmap(rdev);
297 default:
298 return -EINVAL;
299 }
300}
301
302static int lp8788_ldo_enable_time(struct regulator_dev *rdev)
303{
304 struct lp8788_ldo *ldo = rdev_get_drvdata(rdev);
305 enum lp8788_ldo_id id = rdev_get_id(rdev);
306 u8 val, addr = LP8788_DLDO1_TIMESTEP + id;
307
308 if (lp8788_read_byte(ldo->lp, addr, &val))
309 return -EINVAL;
310
311 val = (val & LP8788_STARTUP_TIME_M) >> LP8788_STARTUP_TIME_S;
312
313 return ENABLE_TIME_USEC * val;
314}
315
316static int lp8788_ldo_fixed_get_voltage(struct regulator_dev *rdev)
317{
318 enum lp8788_ldo_id id = rdev_get_id(rdev);
319
320 switch (id) {
321 case ALDO2 ... ALDO5:
322 return 2850000;
323 case DLDO12:
324 case ALDO8 ... ALDO9:
325 return 2500000;
326 case ALDO10:
327 return 1100000;
328 default:
329 return -EINVAL;
330 }
331}
332
333static struct regulator_ops lp8788_ldo_voltage_table_ops = {
334 .list_voltage = regulator_list_voltage_table,
335 .set_voltage_sel = regulator_set_voltage_sel_regmap,
336 .get_voltage_sel = regulator_get_voltage_sel_regmap,
337 .enable = lp8788_ldo_enable,
338 .disable = lp8788_ldo_disable,
339 .is_enabled = lp8788_ldo_is_enabled,
340 .enable_time = lp8788_ldo_enable_time,
341};
342
343static struct regulator_ops lp8788_ldo_voltage_fixed_ops = {
344 .get_voltage = lp8788_ldo_fixed_get_voltage,
345 .enable = lp8788_ldo_enable,
346 .disable = lp8788_ldo_disable,
347 .is_enabled = lp8788_ldo_is_enabled,
348 .enable_time = lp8788_ldo_enable_time,
349};
350
351static struct regulator_desc lp8788_dldo_desc[] = {
352 {
353 .name = "dldo1",
354 .id = DLDO1,
355 .ops = &lp8788_ldo_voltage_table_ops,
356 .n_voltages = ARRAY_SIZE(lp8788_dldo1239_vtbl),
357 .volt_table = lp8788_dldo1239_vtbl,
358 .type = REGULATOR_VOLTAGE,
359 .owner = THIS_MODULE,
360 .vsel_reg = LP8788_DLDO1_VOUT,
361 .vsel_mask = LP8788_VOUT_5BIT_M,
362 .enable_reg = LP8788_EN_LDO_A,
363 .enable_mask = LP8788_EN_DLDO1_M,
364 },
365 {
366 .name = "dldo2",
367 .id = DLDO2,
368 .ops = &lp8788_ldo_voltage_table_ops,
369 .n_voltages = ARRAY_SIZE(lp8788_dldo1239_vtbl),
370 .volt_table = lp8788_dldo1239_vtbl,
371 .type = REGULATOR_VOLTAGE,
372 .owner = THIS_MODULE,
373 .vsel_reg = LP8788_DLDO2_VOUT,
374 .vsel_mask = LP8788_VOUT_5BIT_M,
375 .enable_reg = LP8788_EN_LDO_A,
376 .enable_mask = LP8788_EN_DLDO2_M,
377 },
378 {
379 .name = "dldo3",
380 .id = DLDO3,
381 .ops = &lp8788_ldo_voltage_table_ops,
382 .n_voltages = ARRAY_SIZE(lp8788_dldo1239_vtbl),
383 .volt_table = lp8788_dldo1239_vtbl,
384 .type = REGULATOR_VOLTAGE,
385 .owner = THIS_MODULE,
386 .vsel_reg = LP8788_DLDO3_VOUT,
387 .vsel_mask = LP8788_VOUT_5BIT_M,
388 .enable_reg = LP8788_EN_LDO_A,
389 .enable_mask = LP8788_EN_DLDO3_M,
390 },
391 {
392 .name = "dldo4",
393 .id = DLDO4,
394 .ops = &lp8788_ldo_voltage_table_ops,
395 .n_voltages = ARRAY_SIZE(lp8788_dldo4_vtbl),
396 .volt_table = lp8788_dldo4_vtbl,
397 .type = REGULATOR_VOLTAGE,
398 .owner = THIS_MODULE,
399 .vsel_reg = LP8788_DLDO4_VOUT,
400 .vsel_mask = LP8788_VOUT_1BIT_M,
401 .enable_reg = LP8788_EN_LDO_A,
402 .enable_mask = LP8788_EN_DLDO4_M,
403 },
404 {
405 .name = "dldo5",
406 .id = DLDO5,
407 .ops = &lp8788_ldo_voltage_table_ops,
408 .n_voltages = ARRAY_SIZE(lp8788_dldo578_aldo6_vtbl),
409 .volt_table = lp8788_dldo578_aldo6_vtbl,
410 .type = REGULATOR_VOLTAGE,
411 .owner = THIS_MODULE,
412 .vsel_reg = LP8788_DLDO5_VOUT,
413 .vsel_mask = LP8788_VOUT_4BIT_M,
414 .enable_reg = LP8788_EN_LDO_A,
415 .enable_mask = LP8788_EN_DLDO5_M,
416 },
417 {
418 .name = "dldo6",
419 .id = DLDO6,
420 .ops = &lp8788_ldo_voltage_table_ops,
421 .n_voltages = ARRAY_SIZE(lp8788_dldo6_vtbl),
422 .volt_table = lp8788_dldo6_vtbl,
423 .type = REGULATOR_VOLTAGE,
424 .owner = THIS_MODULE,
425 .vsel_reg = LP8788_DLDO6_VOUT,
426 .vsel_mask = LP8788_VOUT_3BIT_M,
427 .enable_reg = LP8788_EN_LDO_A,
428 .enable_mask = LP8788_EN_DLDO6_M,
429 },
430 {
431 .name = "dldo7",
432 .id = DLDO7,
433 .ops = &lp8788_ldo_voltage_table_ops,
434 .n_voltages = ARRAY_SIZE(lp8788_dldo578_aldo6_vtbl),
435 .volt_table = lp8788_dldo578_aldo6_vtbl,
436 .type = REGULATOR_VOLTAGE,
437 .owner = THIS_MODULE,
438 .vsel_reg = LP8788_DLDO7_VOUT,
439 .vsel_mask = LP8788_VOUT_4BIT_M,
440 .enable_reg = LP8788_EN_LDO_A,
441 .enable_mask = LP8788_EN_DLDO7_M,
442 },
443 {
444 .name = "dldo8",
445 .id = DLDO8,
446 .ops = &lp8788_ldo_voltage_table_ops,
447 .n_voltages = ARRAY_SIZE(lp8788_dldo578_aldo6_vtbl),
448 .volt_table = lp8788_dldo578_aldo6_vtbl,
449 .type = REGULATOR_VOLTAGE,
450 .owner = THIS_MODULE,
451 .vsel_reg = LP8788_DLDO8_VOUT,
452 .vsel_mask = LP8788_VOUT_4BIT_M,
453 .enable_reg = LP8788_EN_LDO_A,
454 .enable_mask = LP8788_EN_DLDO8_M,
455 },
456 {
457 .name = "dldo9",
458 .id = DLDO9,
459 .ops = &lp8788_ldo_voltage_table_ops,
460 .n_voltages = ARRAY_SIZE(lp8788_dldo1239_vtbl),
461 .volt_table = lp8788_dldo1239_vtbl,
462 .type = REGULATOR_VOLTAGE,
463 .owner = THIS_MODULE,
464 .vsel_reg = LP8788_DLDO9_VOUT,
465 .vsel_mask = LP8788_VOUT_5BIT_M,
466 .enable_reg = LP8788_EN_LDO_B,
467 .enable_mask = LP8788_EN_DLDO9_M,
468 },
469 {
470 .name = "dldo10",
471 .id = DLDO10,
472 .ops = &lp8788_ldo_voltage_table_ops,
473 .n_voltages = ARRAY_SIZE(lp8788_dldo1011_vtbl),
474 .volt_table = lp8788_dldo1011_vtbl,
475 .type = REGULATOR_VOLTAGE,
476 .owner = THIS_MODULE,
477 .vsel_reg = LP8788_DLDO10_VOUT,
478 .vsel_mask = LP8788_VOUT_4BIT_M,
479 .enable_reg = LP8788_EN_LDO_B,
480 .enable_mask = LP8788_EN_DLDO10_M,
481 },
482 {
483 .name = "dldo11",
484 .id = DLDO11,
485 .ops = &lp8788_ldo_voltage_table_ops,
486 .n_voltages = ARRAY_SIZE(lp8788_dldo1011_vtbl),
487 .volt_table = lp8788_dldo1011_vtbl,
488 .type = REGULATOR_VOLTAGE,
489 .owner = THIS_MODULE,
490 .vsel_reg = LP8788_DLDO11_VOUT,
491 .vsel_mask = LP8788_VOUT_4BIT_M,
492 .enable_reg = LP8788_EN_LDO_B,
493 .enable_mask = LP8788_EN_DLDO11_M,
494 },
495 {
496 .name = "dldo12",
497 .id = DLDO12,
498 .ops = &lp8788_ldo_voltage_fixed_ops,
499 .type = REGULATOR_VOLTAGE,
500 .owner = THIS_MODULE,
501 .enable_reg = LP8788_EN_LDO_B,
502 .enable_mask = LP8788_EN_DLDO12_M,
503 },
504};
505
506static struct regulator_desc lp8788_aldo_desc[] = {
507 {
508 .name = "aldo1",
509 .id = ALDO1,
510 .ops = &lp8788_ldo_voltage_table_ops,
511 .n_voltages = ARRAY_SIZE(lp8788_aldo1_vtbl),
512 .volt_table = lp8788_aldo1_vtbl,
513 .type = REGULATOR_VOLTAGE,
514 .owner = THIS_MODULE,
515 .vsel_reg = LP8788_ALDO1_VOUT,
516 .vsel_mask = LP8788_VOUT_1BIT_M,
517 .enable_reg = LP8788_EN_LDO_B,
518 .enable_mask = LP8788_EN_ALDO1_M,
519 },
520 {
521 .name = "aldo2",
522 .id = ALDO2,
523 .ops = &lp8788_ldo_voltage_fixed_ops,
524 .type = REGULATOR_VOLTAGE,
525 .owner = THIS_MODULE,
526 .enable_reg = LP8788_EN_LDO_B,
527 .enable_mask = LP8788_EN_ALDO2_M,
528 },
529 {
530 .name = "aldo3",
531 .id = ALDO3,
532 .ops = &lp8788_ldo_voltage_fixed_ops,
533 .type = REGULATOR_VOLTAGE,
534 .owner = THIS_MODULE,
535 .enable_reg = LP8788_EN_LDO_B,
536 .enable_mask = LP8788_EN_ALDO3_M,
537 },
538 {
539 .name = "aldo4",
540 .id = ALDO4,
541 .ops = &lp8788_ldo_voltage_fixed_ops,
542 .type = REGULATOR_VOLTAGE,
543 .owner = THIS_MODULE,
544 .enable_reg = LP8788_EN_LDO_B,
545 .enable_mask = LP8788_EN_ALDO4_M,
546 },
547 {
548 .name = "aldo5",
549 .id = ALDO5,
550 .ops = &lp8788_ldo_voltage_fixed_ops,
551 .type = REGULATOR_VOLTAGE,
552 .owner = THIS_MODULE,
553 .enable_reg = LP8788_EN_LDO_C,
554 .enable_mask = LP8788_EN_ALDO5_M,
555 },
556 {
557 .name = "aldo6",
558 .id = ALDO6,
559 .ops = &lp8788_ldo_voltage_table_ops,
560 .n_voltages = ARRAY_SIZE(lp8788_dldo578_aldo6_vtbl),
561 .volt_table = lp8788_dldo578_aldo6_vtbl,
562 .type = REGULATOR_VOLTAGE,
563 .owner = THIS_MODULE,
564 .vsel_reg = LP8788_ALDO6_VOUT,
565 .vsel_mask = LP8788_VOUT_4BIT_M,
566 .enable_reg = LP8788_EN_LDO_C,
567 .enable_mask = LP8788_EN_ALDO6_M,
568 },
569 {
570 .name = "aldo7",
571 .id = ALDO7,
572 .ops = &lp8788_ldo_voltage_table_ops,
573 .n_voltages = ARRAY_SIZE(lp8788_aldo7_vtbl),
574 .volt_table = lp8788_aldo7_vtbl,
575 .type = REGULATOR_VOLTAGE,
576 .owner = THIS_MODULE,
577 .vsel_reg = LP8788_ALDO7_VOUT,
578 .vsel_mask = LP8788_VOUT_3BIT_M,
579 .enable_reg = LP8788_EN_LDO_C,
580 .enable_mask = LP8788_EN_ALDO7_M,
581 },
582 {
583 .name = "aldo8",
584 .id = ALDO8,
585 .ops = &lp8788_ldo_voltage_fixed_ops,
586 .type = REGULATOR_VOLTAGE,
587 .owner = THIS_MODULE,
588 .enable_reg = LP8788_EN_LDO_C,
589 .enable_mask = LP8788_EN_ALDO8_M,
590 },
591 {
592 .name = "aldo9",
593 .id = ALDO9,
594 .ops = &lp8788_ldo_voltage_fixed_ops,
595 .type = REGULATOR_VOLTAGE,
596 .owner = THIS_MODULE,
597 .enable_reg = LP8788_EN_LDO_C,
598 .enable_mask = LP8788_EN_ALDO9_M,
599 },
600 {
601 .name = "aldo10",
602 .id = ALDO10,
603 .ops = &lp8788_ldo_voltage_fixed_ops,
604 .type = REGULATOR_VOLTAGE,
605 .owner = THIS_MODULE,
606 .enable_reg = LP8788_EN_LDO_C,
607 .enable_mask = LP8788_EN_ALDO10_M,
608 },
609};
610
611static int lp8788_gpio_request_ldo_en(struct lp8788_ldo *ldo,
612 enum lp8788_ext_ldo_en_id id)
613{
614 struct device *dev = ldo->lp->dev;
615 struct lp8788_ldo_enable_pin *pin = ldo->en_pin;
616 int ret, gpio, pinstate;
617 char *name[] = {
618 [EN_ALDO1] = "LP8788_EN_ALDO1",
619 [EN_ALDO234] = "LP8788_EN_ALDO234",
620 [EN_ALDO5] = "LP8788_EN_ALDO5",
621 [EN_ALDO7] = "LP8788_EN_ALDO7",
622 [EN_DLDO7] = "LP8788_EN_DLDO7",
623 [EN_DLDO911] = "LP8788_EN_DLDO911",
624 };
625
626 gpio = pin->gpio;
627 if (!gpio_is_valid(gpio)) {
628 dev_err(dev, "invalid gpio: %d\n", gpio);
629 return -EINVAL;
630 }
631
632 pinstate = pin->init_state;
633 ret = devm_gpio_request_one(dev, gpio, pinstate, name[id]);
634 if (ret == -EBUSY) {
635 dev_warn(dev, "gpio%d already used\n", gpio);
636 return 0;
637 }
638
639 return ret;
640}
641
642static int lp8788_config_ldo_enable_mode(struct lp8788_ldo *ldo,
643 enum lp8788_ldo_id id)
644{
645 int ret;
646 struct lp8788 *lp = ldo->lp;
647 struct lp8788_platform_data *pdata = lp->pdata;
648 enum lp8788_ext_ldo_en_id enable_id;
649 u8 en_mask[] = {
650 [EN_ALDO1] = LP8788_EN_SEL_ALDO1_M,
651 [EN_ALDO234] = LP8788_EN_SEL_ALDO234_M,
652 [EN_ALDO5] = LP8788_EN_SEL_ALDO5_M,
653 [EN_ALDO7] = LP8788_EN_SEL_ALDO7_M,
654 [EN_DLDO7] = LP8788_EN_SEL_DLDO7_M,
655 [EN_DLDO911] = LP8788_EN_SEL_DLDO911_M,
656 };
657 u8 val[] = {
658 [EN_ALDO1] = 0 << 5,
659 [EN_ALDO234] = 0 << 4,
660 [EN_ALDO5] = 0 << 3,
661 [EN_ALDO7] = 0 << 2,
662 [EN_DLDO7] = 0 << 1,
663 [EN_DLDO911] = 0 << 0,
664 };
665
666 switch (id) {
667 case DLDO7:
668 enable_id = EN_DLDO7;
669 break;
670 case DLDO9:
671 case DLDO11:
672 enable_id = EN_DLDO911;
673 break;
674 case ALDO1:
675 enable_id = EN_ALDO1;
676 break;
677 case ALDO2 ... ALDO4:
678 enable_id = EN_ALDO234;
679 break;
680 case ALDO5:
681 enable_id = EN_ALDO5;
682 break;
683 case ALDO7:
684 enable_id = EN_ALDO7;
685 break;
686 default:
687 return 0;
688 }
689
690 /* if no platform data for ldo pin, then set default enable mode */
691 if (!pdata || !pdata->ldo_pin || !pdata->ldo_pin[enable_id])
692 goto set_default_ldo_enable_mode;
693
694 ldo->en_pin = pdata->ldo_pin[enable_id];
695
696 ret = lp8788_gpio_request_ldo_en(ldo, enable_id);
697 if (ret)
698 goto set_default_ldo_enable_mode;
699
700 return ret;
701
702set_default_ldo_enable_mode:
703 return lp8788_update_bits(lp, LP8788_EN_SEL, en_mask[enable_id],
704 val[enable_id]);
705}
706
707static __devinit int lp8788_dldo_probe(struct platform_device *pdev)
708{
709 struct lp8788 *lp = dev_get_drvdata(pdev->dev.parent);
710 int id = pdev->id;
711 struct lp8788_ldo *ldo;
712 struct regulator_config cfg = { };
713 struct regulator_dev *rdev;
714 int ret;
715
716 ldo = devm_kzalloc(lp->dev, sizeof(struct lp8788_ldo), GFP_KERNEL);
717 if (!ldo)
718 return -ENOMEM;
719
720 ldo->lp = lp;
721 ret = lp8788_config_ldo_enable_mode(ldo, lp8788_dldo_id[id]);
722 if (ret)
723 return ret;
724
725 cfg.dev = lp->dev;
726 cfg.init_data = lp->pdata ? lp->pdata->dldo_data[id] : NULL;
727 cfg.driver_data = ldo;
728 cfg.regmap = lp->regmap;
729
730 rdev = regulator_register(&lp8788_dldo_desc[id], &cfg);
731 if (IS_ERR(rdev)) {
732 ret = PTR_ERR(rdev);
733 dev_err(lp->dev, "DLDO%d regulator register err = %d\n",
734 id + 1, ret);
735 return ret;
736 }
737
738 ldo->regulator = rdev;
739 platform_set_drvdata(pdev, ldo);
740
741 return 0;
742}
743
744static int __devexit lp8788_dldo_remove(struct platform_device *pdev)
745{
746 struct lp8788_ldo *ldo = platform_get_drvdata(pdev);
747
748 platform_set_drvdata(pdev, NULL);
749 regulator_unregister(ldo->regulator);
750
751 return 0;
752}
753
754static struct platform_driver lp8788_dldo_driver = {
755 .probe = lp8788_dldo_probe,
756 .remove = __devexit_p(lp8788_dldo_remove),
757 .driver = {
758 .name = LP8788_DEV_DLDO,
759 .owner = THIS_MODULE,
760 },
761};
762
763static __devinit int lp8788_aldo_probe(struct platform_device *pdev)
764{
765 struct lp8788 *lp = dev_get_drvdata(pdev->dev.parent);
766 int id = pdev->id;
767 struct lp8788_ldo *ldo;
768 struct regulator_config cfg = { };
769 struct regulator_dev *rdev;
770 int ret;
771
772 ldo = devm_kzalloc(lp->dev, sizeof(struct lp8788_ldo), GFP_KERNEL);
773 if (!ldo)
774 return -ENOMEM;
775
776 ldo->lp = lp;
777 ret = lp8788_config_ldo_enable_mode(ldo, lp8788_aldo_id[id]);
778 if (ret)
779 return ret;
780
781 cfg.dev = lp->dev;
782 cfg.init_data = lp->pdata ? lp->pdata->aldo_data[id] : NULL;
783 cfg.driver_data = ldo;
784 cfg.regmap = lp->regmap;
785
786 rdev = regulator_register(&lp8788_aldo_desc[id], &cfg);
787 if (IS_ERR(rdev)) {
788 ret = PTR_ERR(rdev);
789 dev_err(lp->dev, "ALDO%d regulator register err = %d\n",
790 id + 1, ret);
791 return ret;
792 }
793
794 ldo->regulator = rdev;
795 platform_set_drvdata(pdev, ldo);
796
797 return 0;
798}
799
800static int __devexit lp8788_aldo_remove(struct platform_device *pdev)
801{
802 struct lp8788_ldo *ldo = platform_get_drvdata(pdev);
803
804 platform_set_drvdata(pdev, NULL);
805 regulator_unregister(ldo->regulator);
806
807 return 0;
808}
809
810static struct platform_driver lp8788_aldo_driver = {
811 .probe = lp8788_aldo_probe,
812 .remove = __devexit_p(lp8788_aldo_remove),
813 .driver = {
814 .name = LP8788_DEV_ALDO,
815 .owner = THIS_MODULE,
816 },
817};
818
819static int __init lp8788_ldo_init(void)
820{
821 int ret;
822
823 ret = platform_driver_register(&lp8788_dldo_driver);
824 if (ret)
825 return ret;
826
827 return platform_driver_register(&lp8788_aldo_driver);
828}
829subsys_initcall(lp8788_ldo_init);
830
831static void __exit lp8788_ldo_exit(void)
832{
833 platform_driver_unregister(&lp8788_aldo_driver);
834 platform_driver_unregister(&lp8788_dldo_driver);
835}
836module_exit(lp8788_ldo_exit);
837
838MODULE_DESCRIPTION("TI LP8788 LDO Driver");
839MODULE_AUTHOR("Milo Kim");
840MODULE_LICENSE("GPL");
841MODULE_ALIAS("platform:lp8788-dldo");
842MODULE_ALIAS("platform:lp8788-aldo");
diff --git a/drivers/regulator/max1586.c b/drivers/regulator/max1586.c
index b9444ee08da9..f67af3c1b963 100644
--- a/drivers/regulator/max1586.c
+++ b/drivers/regulator/max1586.c
@@ -48,6 +48,14 @@ struct max1586_data {
48}; 48};
49 49
50/* 50/*
51 * V6 voltage
52 * On I2C bus, sending a "x" byte to the max1586 means :
53 * set V6 to either 0V, 1.8V, 2.5V, 3V depending on (x & 0x3)
54 * As regulator framework doesn't accept voltages to be 0V, we use 1uV.
55 */
56static int v6_voltages_uv[] = { 1, 1800000, 2500000, 3000000 };
57
58/*
51 * V3 voltage 59 * V3 voltage
52 * On I2C bus, sending a "x" byte to the max1586 means : 60 * On I2C bus, sending a "x" byte to the max1586 means :
53 * set V3 to 0.700V + (x & 0x1f) * 0.025V 61 * set V3 to 0.700V + (x & 0x1f) * 0.025V
@@ -55,113 +63,49 @@ struct max1586_data {
55 * R24 and R25=100kOhm as described in the data sheet. 63 * R24 and R25=100kOhm as described in the data sheet.
56 * The gain is approximately: 1 + R24/R25 + R24/185.5kOhm 64 * The gain is approximately: 1 + R24/R25 + R24/185.5kOhm
57 */ 65 */
58static int max1586_v3_calc_voltage(struct max1586_data *max1586, 66static int max1586_v3_set_voltage_sel(struct regulator_dev *rdev,
59 unsigned selector) 67 unsigned selector)
60{
61 unsigned range_uV = max1586->max_uV - max1586->min_uV;
62
63 return max1586->min_uV + (selector * range_uV / MAX1586_V3_MAX_VSEL);
64}
65
66static int max1586_v3_set(struct regulator_dev *rdev, int min_uV, int max_uV,
67 unsigned *selector)
68{ 68{
69 struct max1586_data *max1586 = rdev_get_drvdata(rdev); 69 struct max1586_data *max1586 = rdev_get_drvdata(rdev);
70 struct i2c_client *client = max1586->client; 70 struct i2c_client *client = max1586->client;
71 unsigned range_uV = max1586->max_uV - max1586->min_uV;
72 u8 v3_prog; 71 u8 v3_prog;
73 72
74 if (min_uV > max1586->max_uV || max_uV < max1586->min_uV)
75 return -EINVAL;
76 if (min_uV < max1586->min_uV)
77 min_uV = max1586->min_uV;
78
79 *selector = DIV_ROUND_UP((min_uV - max1586->min_uV) *
80 MAX1586_V3_MAX_VSEL, range_uV);
81 if (max1586_v3_calc_voltage(max1586, *selector) > max_uV)
82 return -EINVAL;
83
84 dev_dbg(&client->dev, "changing voltage v3 to %dmv\n", 73 dev_dbg(&client->dev, "changing voltage v3 to %dmv\n",
85 max1586_v3_calc_voltage(max1586, *selector) / 1000); 74 regulator_list_voltage_linear(rdev, selector) / 1000);
86 75
87 v3_prog = I2C_V3_SELECT | (u8) *selector; 76 v3_prog = I2C_V3_SELECT | (u8) selector;
88 return i2c_smbus_write_byte(client, v3_prog); 77 return i2c_smbus_write_byte(client, v3_prog);
89} 78}
90 79
91static int max1586_v3_list(struct regulator_dev *rdev, unsigned selector) 80static int max1586_v6_set_voltage_sel(struct regulator_dev *rdev,
92{ 81 unsigned int selector)
93 struct max1586_data *max1586 = rdev_get_drvdata(rdev);
94
95 if (selector > MAX1586_V3_MAX_VSEL)
96 return -EINVAL;
97 return max1586_v3_calc_voltage(max1586, selector);
98}
99
100/*
101 * V6 voltage
102 * On I2C bus, sending a "x" byte to the max1586 means :
103 * set V6 to either 0V, 1.8V, 2.5V, 3V depending on (x & 0x3)
104 * As regulator framework doesn't accept voltages to be 0V, we use 1uV.
105 */
106static int max1586_v6_calc_voltage(unsigned selector)
107{
108 static int voltages_uv[] = { 1, 1800000, 2500000, 3000000 };
109
110 return voltages_uv[selector];
111}
112
113static int max1586_v6_set(struct regulator_dev *rdev, int min_uV, int max_uV,
114 unsigned int *selector)
115{ 82{
116 struct i2c_client *client = rdev_get_drvdata(rdev); 83 struct i2c_client *client = rdev_get_drvdata(rdev);
117 u8 v6_prog; 84 u8 v6_prog;
118 85
119 if (min_uV < MAX1586_V6_MIN_UV || min_uV > MAX1586_V6_MAX_UV)
120 return -EINVAL;
121 if (max_uV < MAX1586_V6_MIN_UV || max_uV > MAX1586_V6_MAX_UV)
122 return -EINVAL;
123
124 if (min_uV < 1800000)
125 *selector = 0;
126 else if (min_uV < 2500000)
127 *selector = 1;
128 else if (min_uV < 3000000)
129 *selector = 2;
130 else if (min_uV >= 3000000)
131 *selector = 3;
132
133 if (max1586_v6_calc_voltage(*selector) > max_uV)
134 return -EINVAL;
135
136 dev_dbg(&client->dev, "changing voltage v6 to %dmv\n", 86 dev_dbg(&client->dev, "changing voltage v6 to %dmv\n",
137 max1586_v6_calc_voltage(*selector) / 1000); 87 rdev->desc->volt_table[selector] / 1000);
138 88
139 v6_prog = I2C_V6_SELECT | (u8) *selector; 89 v6_prog = I2C_V6_SELECT | (u8) selector;
140 return i2c_smbus_write_byte(client, v6_prog); 90 return i2c_smbus_write_byte(client, v6_prog);
141} 91}
142 92
143static int max1586_v6_list(struct regulator_dev *rdev, unsigned selector)
144{
145 if (selector > MAX1586_V6_MAX_VSEL)
146 return -EINVAL;
147 return max1586_v6_calc_voltage(selector);
148}
149
150/* 93/*
151 * The Maxim 1586 controls V3 and V6 voltages, but offers no way of reading back 94 * The Maxim 1586 controls V3 and V6 voltages, but offers no way of reading back
152 * the set up value. 95 * the set up value.
153 */ 96 */
154static struct regulator_ops max1586_v3_ops = { 97static struct regulator_ops max1586_v3_ops = {
155 .set_voltage = max1586_v3_set, 98 .set_voltage_sel = max1586_v3_set_voltage_sel,
156 .list_voltage = max1586_v3_list, 99 .list_voltage = regulator_list_voltage_linear,
100 .map_voltage = regulator_map_voltage_linear,
157}; 101};
158 102
159static struct regulator_ops max1586_v6_ops = { 103static struct regulator_ops max1586_v6_ops = {
160 .set_voltage = max1586_v6_set, 104 .set_voltage_sel = max1586_v6_set_voltage_sel,
161 .list_voltage = max1586_v6_list, 105 .list_voltage = regulator_list_voltage_table,
162}; 106};
163 107
164static const struct regulator_desc max1586_reg[] = { 108static struct regulator_desc max1586_reg[] = {
165 { 109 {
166 .name = "Output_V3", 110 .name = "Output_V3",
167 .id = MAX1586_V3, 111 .id = MAX1586_V3,
@@ -176,6 +120,7 @@ static const struct regulator_desc max1586_reg[] = {
176 .ops = &max1586_v6_ops, 120 .ops = &max1586_v6_ops,
177 .type = REGULATOR_VOLTAGE, 121 .type = REGULATOR_VOLTAGE,
178 .n_voltages = MAX1586_V6_MAX_VSEL + 1, 122 .n_voltages = MAX1586_V6_MAX_VSEL + 1,
123 .volt_table = v6_voltages_uv,
179 .owner = THIS_MODULE, 124 .owner = THIS_MODULE,
180 }, 125 },
181}; 126};
@@ -213,6 +158,13 @@ static int __devinit max1586_pmic_probe(struct i2c_client *client,
213 goto err; 158 goto err;
214 } 159 }
215 160
161 if (id == MAX1586_V3) {
162 max1586_reg[id].min_uV = max1586->min_uV;
163 max1586_reg[id].uV_step =
164 (max1586->max_uV - max1586->min_uV) /
165 MAX1586_V3_MAX_VSEL;
166 }
167
216 config.dev = &client->dev; 168 config.dev = &client->dev;
217 config.init_data = pdata->subdevs[i].platform_data; 169 config.init_data = pdata->subdevs[i].platform_data;
218 config.driver_data = max1586; 170 config.driver_data = max1586;
diff --git a/drivers/regulator/max77686.c b/drivers/regulator/max77686.c
new file mode 100644
index 000000000000..c564af6f05a3
--- /dev/null
+++ b/drivers/regulator/max77686.c
@@ -0,0 +1,389 @@
1/*
2 * max77686.c - Regulator driver for the Maxim 77686
3 *
4 * Copyright (C) 2012 Samsung Electronics
5 * Chiwoong Byun <woong.byun@smasung.com>
6 * Jonghwa Lee <jonghwa3.lee@samsung.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 * This driver is based on max8997.c
23 */
24
25#include <linux/kernel.h>
26#include <linux/bug.h>
27#include <linux/delay.h>
28#include <linux/err.h>
29#include <linux/gpio.h>
30#include <linux/slab.h>
31#include <linux/platform_device.h>
32#include <linux/regulator/driver.h>
33#include <linux/regulator/machine.h>
34#include <linux/regulator/of_regulator.h>
35#include <linux/mfd/max77686.h>
36#include <linux/mfd/max77686-private.h>
37
38#define MAX77686_LDO_MINUV 800000
39#define MAX77686_LDO_UVSTEP 50000
40#define MAX77686_LDO_LOW_MINUV 800000
41#define MAX77686_LDO_LOW_UVSTEP 25000
42#define MAX77686_BUCK_MINUV 750000
43#define MAX77686_BUCK_UVSTEP 50000
44#define MAX77686_RAMP_DELAY 100000 /* uV/us */
45#define MAX77686_DVS_RAMP_DELAY 27500 /* uV/us */
46#define MAX77686_DVS_MINUV 600000
47#define MAX77686_DVS_UVSTEP 12500
48
49#define MAX77686_OPMODE_SHIFT 6
50#define MAX77686_OPMODE_BUCK234_SHIFT 4
51#define MAX77686_OPMODE_MASK 0x3
52
53#define MAX77686_VSEL_MASK 0x3F
54#define MAX77686_DVS_VSEL_MASK 0xFF
55
56#define MAX77686_RAMP_RATE_MASK 0xC0
57
58#define MAX77686_REGULATORS MAX77686_REG_MAX
59#define MAX77686_LDOS 26
60
61enum max77686_ramp_rate {
62 RAMP_RATE_13P75MV,
63 RAMP_RATE_27P5MV,
64 RAMP_RATE_55MV,
65 RAMP_RATE_NO_CTRL, /* 100mV/us */
66};
67
68struct max77686_data {
69 struct regulator_dev **rdev;
70};
71
72static int max77686_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
73{
74 unsigned int ramp_value = RAMP_RATE_NO_CTRL;
75
76 switch (ramp_delay) {
77 case 1 ... 13750:
78 ramp_value = RAMP_RATE_13P75MV;
79 break;
80 case 13751 ... 27500:
81 ramp_value = RAMP_RATE_27P5MV;
82 break;
83 case 27501 ... 55000:
84 ramp_value = RAMP_RATE_55MV;
85 break;
86 case 55001 ... 100000:
87 break;
88 default:
89 pr_warn("%s: ramp_delay: %d not supported, setting 100000\n",
90 rdev->desc->name, ramp_delay);
91 }
92
93 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
94 MAX77686_RAMP_RATE_MASK, ramp_value << 6);
95}
96
97static struct regulator_ops max77686_ops = {
98 .list_voltage = regulator_list_voltage_linear,
99 .map_voltage = regulator_map_voltage_linear,
100 .is_enabled = regulator_is_enabled_regmap,
101 .enable = regulator_enable_regmap,
102 .disable = regulator_disable_regmap,
103 .get_voltage_sel = regulator_get_voltage_sel_regmap,
104 .set_voltage_sel = regulator_set_voltage_sel_regmap,
105 .set_voltage_time_sel = regulator_set_voltage_time_sel,
106};
107
108static struct regulator_ops max77686_buck_dvs_ops = {
109 .list_voltage = regulator_list_voltage_linear,
110 .map_voltage = regulator_map_voltage_linear,
111 .is_enabled = regulator_is_enabled_regmap,
112 .enable = regulator_enable_regmap,
113 .disable = regulator_disable_regmap,
114 .get_voltage_sel = regulator_get_voltage_sel_regmap,
115 .set_voltage_sel = regulator_set_voltage_sel_regmap,
116 .set_voltage_time_sel = regulator_set_voltage_time_sel,
117 .set_ramp_delay = max77686_set_ramp_delay,
118};
119
120#define regulator_desc_ldo(num) { \
121 .name = "LDO"#num, \
122 .id = MAX77686_LDO##num, \
123 .ops = &max77686_ops, \
124 .type = REGULATOR_VOLTAGE, \
125 .owner = THIS_MODULE, \
126 .min_uV = MAX77686_LDO_MINUV, \
127 .uV_step = MAX77686_LDO_UVSTEP, \
128 .ramp_delay = MAX77686_RAMP_DELAY, \
129 .n_voltages = MAX77686_VSEL_MASK + 1, \
130 .vsel_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
131 .vsel_mask = MAX77686_VSEL_MASK, \
132 .enable_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
133 .enable_mask = MAX77686_OPMODE_MASK \
134 << MAX77686_OPMODE_SHIFT, \
135}
136#define regulator_desc_ldo_low(num) { \
137 .name = "LDO"#num, \
138 .id = MAX77686_LDO##num, \
139 .ops = &max77686_ops, \
140 .type = REGULATOR_VOLTAGE, \
141 .owner = THIS_MODULE, \
142 .min_uV = MAX77686_LDO_LOW_MINUV, \
143 .uV_step = MAX77686_LDO_LOW_UVSTEP, \
144 .ramp_delay = MAX77686_RAMP_DELAY, \
145 .n_voltages = MAX77686_VSEL_MASK + 1, \
146 .vsel_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
147 .vsel_mask = MAX77686_VSEL_MASK, \
148 .enable_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
149 .enable_mask = MAX77686_OPMODE_MASK \
150 << MAX77686_OPMODE_SHIFT, \
151}
152#define regulator_desc_buck(num) { \
153 .name = "BUCK"#num, \
154 .id = MAX77686_BUCK##num, \
155 .ops = &max77686_ops, \
156 .type = REGULATOR_VOLTAGE, \
157 .owner = THIS_MODULE, \
158 .min_uV = MAX77686_BUCK_MINUV, \
159 .uV_step = MAX77686_BUCK_UVSTEP, \
160 .ramp_delay = MAX77686_RAMP_DELAY, \
161 .n_voltages = MAX77686_VSEL_MASK + 1, \
162 .vsel_reg = MAX77686_REG_BUCK5OUT + (num - 5) * 2, \
163 .vsel_mask = MAX77686_VSEL_MASK, \
164 .enable_reg = MAX77686_REG_BUCK5CTRL + (num - 5) * 2, \
165 .enable_mask = MAX77686_OPMODE_MASK, \
166}
167#define regulator_desc_buck1(num) { \
168 .name = "BUCK"#num, \
169 .id = MAX77686_BUCK##num, \
170 .ops = &max77686_ops, \
171 .type = REGULATOR_VOLTAGE, \
172 .owner = THIS_MODULE, \
173 .min_uV = MAX77686_BUCK_MINUV, \
174 .uV_step = MAX77686_BUCK_UVSTEP, \
175 .ramp_delay = MAX77686_RAMP_DELAY, \
176 .n_voltages = MAX77686_VSEL_MASK + 1, \
177 .vsel_reg = MAX77686_REG_BUCK1OUT, \
178 .vsel_mask = MAX77686_VSEL_MASK, \
179 .enable_reg = MAX77686_REG_BUCK1CTRL, \
180 .enable_mask = MAX77686_OPMODE_MASK, \
181}
182#define regulator_desc_buck_dvs(num) { \
183 .name = "BUCK"#num, \
184 .id = MAX77686_BUCK##num, \
185 .ops = &max77686_buck_dvs_ops, \
186 .type = REGULATOR_VOLTAGE, \
187 .owner = THIS_MODULE, \
188 .min_uV = MAX77686_DVS_MINUV, \
189 .uV_step = MAX77686_DVS_UVSTEP, \
190 .ramp_delay = MAX77686_DVS_RAMP_DELAY, \
191 .n_voltages = MAX77686_DVS_VSEL_MASK + 1, \
192 .vsel_reg = MAX77686_REG_BUCK2DVS1 + (num - 2) * 10, \
193 .vsel_mask = MAX77686_DVS_VSEL_MASK, \
194 .enable_reg = MAX77686_REG_BUCK2CTRL1 + (num - 2) * 10, \
195 .enable_mask = MAX77686_OPMODE_MASK \
196 << MAX77686_OPMODE_BUCK234_SHIFT, \
197}
198
199static struct regulator_desc regulators[] = {
200 regulator_desc_ldo_low(1),
201 regulator_desc_ldo_low(2),
202 regulator_desc_ldo(3),
203 regulator_desc_ldo(4),
204 regulator_desc_ldo(5),
205 regulator_desc_ldo_low(6),
206 regulator_desc_ldo_low(7),
207 regulator_desc_ldo_low(8),
208 regulator_desc_ldo(9),
209 regulator_desc_ldo(10),
210 regulator_desc_ldo(11),
211 regulator_desc_ldo(12),
212 regulator_desc_ldo(13),
213 regulator_desc_ldo(14),
214 regulator_desc_ldo_low(15),
215 regulator_desc_ldo(16),
216 regulator_desc_ldo(17),
217 regulator_desc_ldo(18),
218 regulator_desc_ldo(19),
219 regulator_desc_ldo(20),
220 regulator_desc_ldo(21),
221 regulator_desc_ldo(22),
222 regulator_desc_ldo(23),
223 regulator_desc_ldo(24),
224 regulator_desc_ldo(25),
225 regulator_desc_ldo(26),
226 regulator_desc_buck1(1),
227 regulator_desc_buck_dvs(2),
228 regulator_desc_buck_dvs(3),
229 regulator_desc_buck_dvs(4),
230 regulator_desc_buck(5),
231 regulator_desc_buck(6),
232 regulator_desc_buck(7),
233 regulator_desc_buck(8),
234 regulator_desc_buck(9),
235};
236
237#ifdef CONFIG_OF
238static int max77686_pmic_dt_parse_pdata(struct max77686_dev *iodev,
239 struct max77686_platform_data *pdata)
240{
241 struct device_node *pmic_np, *regulators_np;
242 struct max77686_regulator_data *rdata;
243 struct of_regulator_match rmatch;
244 unsigned int i;
245
246 pmic_np = iodev->dev->of_node;
247 regulators_np = of_find_node_by_name(pmic_np, "voltage-regulators");
248 if (!regulators_np) {
249 dev_err(iodev->dev, "could not find regulators sub-node\n");
250 return -EINVAL;
251 }
252
253 pdata->num_regulators = ARRAY_SIZE(regulators);
254 rdata = devm_kzalloc(iodev->dev, sizeof(*rdata) *
255 pdata->num_regulators, GFP_KERNEL);
256 if (!rdata) {
257 dev_err(iodev->dev,
258 "could not allocate memory for regulator data\n");
259 return -ENOMEM;
260 }
261
262 for (i = 0; i < pdata->num_regulators; i++) {
263 rmatch.name = regulators[i].name;
264 rmatch.init_data = NULL;
265 rmatch.of_node = NULL;
266 of_regulator_match(iodev->dev, regulators_np, &rmatch, 1);
267 rdata[i].initdata = rmatch.init_data;
268 }
269
270 pdata->regulators = rdata;
271
272 return 0;
273}
274#else
275static int max77686_pmic_dt_parse_pdata(struct max77686_dev *iodev,
276 struct max77686_platform_data *pdata)
277{
278 return 0;
279}
280#endif /* CONFIG_OF */
281
282static __devinit int max77686_pmic_probe(struct platform_device *pdev)
283{
284 struct max77686_dev *iodev = dev_get_drvdata(pdev->dev.parent);
285 struct max77686_platform_data *pdata = dev_get_platdata(iodev->dev);
286 struct regulator_dev **rdev;
287 struct max77686_data *max77686;
288 int i, size;
289 int ret = 0;
290 struct regulator_config config = { };
291
292 dev_dbg(&pdev->dev, "%s\n", __func__);
293
294 if (!pdata) {
295 dev_err(&pdev->dev, "no platform data found for regulator\n");
296 return -ENODEV;
297 }
298
299 if (iodev->dev->of_node) {
300 ret = max77686_pmic_dt_parse_pdata(iodev, pdata);
301 if (ret)
302 return ret;
303 }
304
305 if (pdata->num_regulators != MAX77686_REGULATORS) {
306 dev_err(&pdev->dev,
307 "Invalid initial data for regulator's initialiation\n");
308 return -EINVAL;
309 }
310
311 max77686 = devm_kzalloc(&pdev->dev, sizeof(struct max77686_data),
312 GFP_KERNEL);
313 if (!max77686)
314 return -ENOMEM;
315
316 size = sizeof(struct regulator_dev *) * MAX77686_REGULATORS;
317 max77686->rdev = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
318 if (!max77686->rdev)
319 return -ENOMEM;
320
321 rdev = max77686->rdev;
322 config.dev = &pdev->dev;
323 config.regmap = iodev->regmap;
324 platform_set_drvdata(pdev, max77686);
325
326 for (i = 0; i < MAX77686_REGULATORS; i++) {
327 config.init_data = pdata->regulators[i].initdata;
328
329 rdev[i] = regulator_register(&regulators[i], &config);
330 if (IS_ERR(rdev[i])) {
331 ret = PTR_ERR(rdev[i]);
332 dev_err(&pdev->dev,
333 "regulator init failed for %d\n", i);
334 rdev[i] = NULL;
335 goto err;
336 }
337 }
338
339 return 0;
340err:
341 while (--i >= 0)
342 regulator_unregister(rdev[i]);
343 return ret;
344}
345
346static int __devexit max77686_pmic_remove(struct platform_device *pdev)
347{
348 struct max77686_data *max77686 = platform_get_drvdata(pdev);
349 struct regulator_dev **rdev = max77686->rdev;
350 int i;
351
352 for (i = 0; i < MAX77686_REGULATORS; i++)
353 if (rdev[i])
354 regulator_unregister(rdev[i]);
355
356 return 0;
357}
358
359static const struct platform_device_id max77686_pmic_id[] = {
360 {"max77686-pmic", 0},
361 { },
362};
363MODULE_DEVICE_TABLE(platform, max77686_pmic_id);
364
365static struct platform_driver max77686_pmic_driver = {
366 .driver = {
367 .name = "max77686-pmic",
368 .owner = THIS_MODULE,
369 },
370 .probe = max77686_pmic_probe,
371 .remove = __devexit_p(max77686_pmic_remove),
372 .id_table = max77686_pmic_id,
373};
374
375static int __init max77686_pmic_init(void)
376{
377 return platform_driver_register(&max77686_pmic_driver);
378}
379subsys_initcall(max77686_pmic_init);
380
381static void __exit max77686_pmic_cleanup(void)
382{
383 platform_driver_unregister(&max77686_pmic_driver);
384}
385module_exit(max77686_pmic_cleanup);
386
387MODULE_DESCRIPTION("MAXIM 77686 Regulator Driver");
388MODULE_AUTHOR("Chiwoong Byun <woong.byun@samsung.com>");
389MODULE_LICENSE("GPL");
diff --git a/drivers/regulator/max8952.c b/drivers/regulator/max8952.c
index 910c9b26d499..355ca7bad9d5 100644
--- a/drivers/regulator/max8952.c
+++ b/drivers/regulator/max8952.c
@@ -51,7 +51,6 @@ struct max8952_data {
51 51
52 bool vid0; 52 bool vid0;
53 bool vid1; 53 bool vid1;
54 bool en;
55}; 54};
56 55
57static int max8952_read_reg(struct max8952_data *max8952, u8 reg) 56static int max8952_read_reg(struct max8952_data *max8952, u8 reg)
@@ -80,38 +79,6 @@ static int max8952_list_voltage(struct regulator_dev *rdev,
80 return (max8952->pdata->dvs_mode[selector] * 10 + 770) * 1000; 79 return (max8952->pdata->dvs_mode[selector] * 10 + 770) * 1000;
81} 80}
82 81
83static int max8952_is_enabled(struct regulator_dev *rdev)
84{
85 struct max8952_data *max8952 = rdev_get_drvdata(rdev);
86 return max8952->en;
87}
88
89static int max8952_enable(struct regulator_dev *rdev)
90{
91 struct max8952_data *max8952 = rdev_get_drvdata(rdev);
92
93 /* If not valid, assume "ALWAYS_HIGH" */
94 if (gpio_is_valid(max8952->pdata->gpio_en))
95 gpio_set_value(max8952->pdata->gpio_en, 1);
96
97 max8952->en = true;
98 return 0;
99}
100
101static int max8952_disable(struct regulator_dev *rdev)
102{
103 struct max8952_data *max8952 = rdev_get_drvdata(rdev);
104
105 /* If not valid, assume "ALWAYS_HIGH" -> not permitted */
106 if (gpio_is_valid(max8952->pdata->gpio_en))
107 gpio_set_value(max8952->pdata->gpio_en, 0);
108 else
109 return -EPERM;
110
111 max8952->en = false;
112 return 0;
113}
114
115static int max8952_get_voltage_sel(struct regulator_dev *rdev) 82static int max8952_get_voltage_sel(struct regulator_dev *rdev)
116{ 83{
117 struct max8952_data *max8952 = rdev_get_drvdata(rdev); 84 struct max8952_data *max8952 = rdev_get_drvdata(rdev);
@@ -146,12 +113,8 @@ static int max8952_set_voltage_sel(struct regulator_dev *rdev,
146 113
147static struct regulator_ops max8952_ops = { 114static struct regulator_ops max8952_ops = {
148 .list_voltage = max8952_list_voltage, 115 .list_voltage = max8952_list_voltage,
149 .is_enabled = max8952_is_enabled,
150 .enable = max8952_enable,
151 .disable = max8952_disable,
152 .get_voltage_sel = max8952_get_voltage_sel, 116 .get_voltage_sel = max8952_get_voltage_sel,
153 .set_voltage_sel = max8952_set_voltage_sel, 117 .set_voltage_sel = max8952_set_voltage_sel,
154 .set_suspend_disable = max8952_disable,
155}; 118};
156 119
157static const struct regulator_desc regulator = { 120static const struct regulator_desc regulator = {
@@ -194,6 +157,10 @@ static int __devinit max8952_pmic_probe(struct i2c_client *client,
194 config.init_data = &pdata->reg_data; 157 config.init_data = &pdata->reg_data;
195 config.driver_data = max8952; 158 config.driver_data = max8952;
196 159
160 config.ena_gpio = pdata->gpio_en;
161 if (pdata->reg_data.constraints.boot_on)
162 config.ena_gpio_flags |= GPIOF_OUT_INIT_HIGH;
163
197 max8952->rdev = regulator_register(&regulator, &config); 164 max8952->rdev = regulator_register(&regulator, &config);
198 165
199 if (IS_ERR(max8952->rdev)) { 166 if (IS_ERR(max8952->rdev)) {
@@ -202,27 +169,9 @@ static int __devinit max8952_pmic_probe(struct i2c_client *client,
202 return ret; 169 return ret;
203 } 170 }
204 171
205 max8952->en = !!(pdata->reg_data.constraints.boot_on);
206 max8952->vid0 = pdata->default_mode & 0x1; 172 max8952->vid0 = pdata->default_mode & 0x1;
207 max8952->vid1 = (pdata->default_mode >> 1) & 0x1; 173 max8952->vid1 = (pdata->default_mode >> 1) & 0x1;
208 174
209 if (gpio_is_valid(pdata->gpio_en)) {
210 if (!gpio_request(pdata->gpio_en, "MAX8952 EN"))
211 gpio_direction_output(pdata->gpio_en, max8952->en);
212 else
213 err = 1;
214 } else
215 err = 2;
216
217 if (err) {
218 dev_info(max8952->dev, "EN gpio invalid: assume that EN"
219 "is always High\n");
220 max8952->en = 1;
221 pdata->gpio_en = -1; /* Mark invalid */
222 }
223
224 err = 0;
225
226 if (gpio_is_valid(pdata->gpio_vid0) && 175 if (gpio_is_valid(pdata->gpio_vid0) &&
227 gpio_is_valid(pdata->gpio_vid1)) { 176 gpio_is_valid(pdata->gpio_vid1)) {
228 if (!gpio_request(pdata->gpio_vid0, "MAX8952 VID0")) 177 if (!gpio_request(pdata->gpio_vid0, "MAX8952 VID0"))
@@ -308,7 +257,6 @@ static int __devexit max8952_pmic_remove(struct i2c_client *client)
308 257
309 gpio_free(pdata->gpio_vid0); 258 gpio_free(pdata->gpio_vid0);
310 gpio_free(pdata->gpio_vid1); 259 gpio_free(pdata->gpio_vid1);
311 gpio_free(pdata->gpio_en);
312 return 0; 260 return 0;
313} 261}
314 262
diff --git a/drivers/regulator/max8997.c b/drivers/regulator/max8997.c
index 704cd49ef375..e39a0c7260dc 100644
--- a/drivers/regulator/max8997.c
+++ b/drivers/regulator/max8997.c
@@ -1025,7 +1025,6 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev)
1025 */ 1025 */
1026 if (pdata->buck1_gpiodvs || pdata->buck2_gpiodvs || 1026 if (pdata->buck1_gpiodvs || pdata->buck2_gpiodvs ||
1027 pdata->buck5_gpiodvs) { 1027 pdata->buck5_gpiodvs) {
1028 bool gpio1set = false, gpio2set = false;
1029 1028
1030 if (!gpio_is_valid(pdata->buck125_gpios[0]) || 1029 if (!gpio_is_valid(pdata->buck125_gpios[0]) ||
1031 !gpio_is_valid(pdata->buck125_gpios[1]) || 1030 !gpio_is_valid(pdata->buck125_gpios[1]) ||
@@ -1035,40 +1034,20 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev)
1035 goto err_out; 1034 goto err_out;
1036 } 1035 }
1037 1036
1038 ret = gpio_request(pdata->buck125_gpios[0], 1037 ret = devm_gpio_request(&pdev->dev, pdata->buck125_gpios[0],
1039 "MAX8997 SET1"); 1038 "MAX8997 SET1");
1040 if (ret == -EBUSY) 1039 if (ret)
1041 dev_warn(&pdev->dev, "Duplicated gpio request"
1042 " on SET1\n");
1043 else if (ret)
1044 goto err_out; 1040 goto err_out;
1045 else 1041
1046 gpio1set = true; 1042 ret = devm_gpio_request(&pdev->dev, pdata->buck125_gpios[1],
1047 1043 "MAX8997 SET2");
1048 ret = gpio_request(pdata->buck125_gpios[1], 1044 if (ret)
1049 "MAX8997 SET2");
1050 if (ret == -EBUSY)
1051 dev_warn(&pdev->dev, "Duplicated gpio request"
1052 " on SET2\n");
1053 else if (ret) {
1054 if (gpio1set)
1055 gpio_free(pdata->buck125_gpios[0]);
1056 goto err_out; 1045 goto err_out;
1057 } else
1058 gpio2set = true;
1059 1046
1060 ret = gpio_request(pdata->buck125_gpios[2], 1047 ret = devm_gpio_request(&pdev->dev, pdata->buck125_gpios[2],
1061 "MAX8997 SET3"); 1048 "MAX8997 SET3");
1062 if (ret == -EBUSY) 1049 if (ret)
1063 dev_warn(&pdev->dev, "Duplicated gpio request"
1064 " on SET3\n");
1065 else if (ret) {
1066 if (gpio1set)
1067 gpio_free(pdata->buck125_gpios[0]);
1068 if (gpio2set)
1069 gpio_free(pdata->buck125_gpios[1]);
1070 goto err_out; 1050 goto err_out;
1071 }
1072 1051
1073 gpio_direction_output(pdata->buck125_gpios[0], 1052 gpio_direction_output(pdata->buck125_gpios[0],
1074 (max8997->buck125_gpioindex >> 2) 1053 (max8997->buck125_gpioindex >> 2)
@@ -1079,7 +1058,6 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev)
1079 gpio_direction_output(pdata->buck125_gpios[2], 1058 gpio_direction_output(pdata->buck125_gpios[2],
1080 (max8997->buck125_gpioindex >> 0) 1059 (max8997->buck125_gpioindex >> 0)
1081 & 0x1); /* SET3 */ 1060 & 0x1); /* SET3 */
1082 ret = 0;
1083 } 1061 }
1084 1062
1085 /* DVS-GPIO disabled */ 1063 /* DVS-GPIO disabled */
diff --git a/drivers/regulator/max8998.c b/drivers/regulator/max8998.c
index 18bb58b9b96e..5dfa920ff0c8 100644
--- a/drivers/regulator/max8998.c
+++ b/drivers/regulator/max8998.c
@@ -111,27 +111,6 @@ static const struct voltage_map_desc *ldo_voltage_map[] = {
111 &buck4_voltage_map_desc, /* BUCK4 */ 111 &buck4_voltage_map_desc, /* BUCK4 */
112}; 112};
113 113
114static int max8998_list_voltage(struct regulator_dev *rdev,
115 unsigned int selector)
116{
117 const struct voltage_map_desc *desc;
118 int ldo = rdev_get_id(rdev);
119 int val;
120
121 if (ldo >= ARRAY_SIZE(ldo_voltage_map))
122 return -EINVAL;
123
124 desc = ldo_voltage_map[ldo];
125 if (desc == NULL)
126 return -EINVAL;
127
128 val = desc->min + desc->step * selector;
129 if (val > desc->max)
130 return -EINVAL;
131
132 return val * 1000;
133}
134
135static int max8998_get_enable_register(struct regulator_dev *rdev, 114static int max8998_get_enable_register(struct regulator_dev *rdev,
136 int *reg, int *shift) 115 int *reg, int *shift)
137{ 116{
@@ -297,41 +276,18 @@ static int max8998_get_voltage_sel(struct regulator_dev *rdev)
297 return val; 276 return val;
298} 277}
299 278
300static int max8998_set_voltage_ldo(struct regulator_dev *rdev, 279static int max8998_set_voltage_ldo_sel(struct regulator_dev *rdev,
301 int min_uV, int max_uV, unsigned *selector) 280 unsigned selector)
302{ 281{
303 struct max8998_data *max8998 = rdev_get_drvdata(rdev); 282 struct max8998_data *max8998 = rdev_get_drvdata(rdev);
304 struct i2c_client *i2c = max8998->iodev->i2c; 283 struct i2c_client *i2c = max8998->iodev->i2c;
305 int min_vol = min_uV / 1000, max_vol = max_uV / 1000; 284 int reg, shift = 0, mask, ret;
306 const struct voltage_map_desc *desc;
307 int ldo = rdev_get_id(rdev);
308 int reg, shift = 0, mask, ret, i;
309
310 if (ldo >= ARRAY_SIZE(ldo_voltage_map))
311 return -EINVAL;
312
313 desc = ldo_voltage_map[ldo];
314 if (desc == NULL)
315 return -EINVAL;
316
317 if (max_vol < desc->min || min_vol > desc->max)
318 return -EINVAL;
319
320 if (min_vol < desc->min)
321 min_vol = desc->min;
322
323 i = DIV_ROUND_UP(min_vol - desc->min, desc->step);
324
325 if (desc->min + desc->step*i > max_vol)
326 return -EINVAL;
327
328 *selector = i;
329 285
330 ret = max8998_get_voltage_register(rdev, &reg, &shift, &mask); 286 ret = max8998_get_voltage_register(rdev, &reg, &shift, &mask);
331 if (ret) 287 if (ret)
332 return ret; 288 return ret;
333 289
334 ret = max8998_update_reg(i2c, reg, i<<shift, mask<<shift); 290 ret = max8998_update_reg(i2c, reg, selector<<shift, mask<<shift);
335 291
336 return ret; 292 return ret;
337} 293}
@@ -347,41 +303,18 @@ static inline void buck2_gpio_set(int gpio, int v)
347 gpio_set_value(gpio, v & 0x1); 303 gpio_set_value(gpio, v & 0x1);
348} 304}
349 305
350static int max8998_set_voltage_buck(struct regulator_dev *rdev, 306static int max8998_set_voltage_buck_sel(struct regulator_dev *rdev,
351 int min_uV, int max_uV, unsigned *selector) 307 unsigned selector)
352{ 308{
353 struct max8998_data *max8998 = rdev_get_drvdata(rdev); 309 struct max8998_data *max8998 = rdev_get_drvdata(rdev);
354 struct max8998_platform_data *pdata = 310 struct max8998_platform_data *pdata =
355 dev_get_platdata(max8998->iodev->dev); 311 dev_get_platdata(max8998->iodev->dev);
356 struct i2c_client *i2c = max8998->iodev->i2c; 312 struct i2c_client *i2c = max8998->iodev->i2c;
357 int min_vol = min_uV / 1000, max_vol = max_uV / 1000;
358 const struct voltage_map_desc *desc;
359 int buck = rdev_get_id(rdev); 313 int buck = rdev_get_id(rdev);
360 int reg, shift = 0, mask, ret; 314 int reg, shift = 0, mask, ret;
361 int i, j, previous_sel; 315 int j, previous_sel;
362 static u8 buck1_last_val; 316 static u8 buck1_last_val;
363 317
364 if (buck >= ARRAY_SIZE(ldo_voltage_map))
365 return -EINVAL;
366
367 desc = ldo_voltage_map[buck];
368
369 if (desc == NULL)
370 return -EINVAL;
371
372 if (max_vol < desc->min || min_vol > desc->max)
373 return -EINVAL;
374
375 if (min_vol < desc->min)
376 min_vol = desc->min;
377
378 i = DIV_ROUND_UP(min_vol - desc->min, desc->step);
379
380 if (desc->min + desc->step*i > max_vol)
381 return -EINVAL;
382
383 *selector = i;
384
385 ret = max8998_get_voltage_register(rdev, &reg, &shift, &mask); 318 ret = max8998_get_voltage_register(rdev, &reg, &shift, &mask);
386 if (ret) 319 if (ret)
387 return ret; 320 return ret;
@@ -390,19 +323,19 @@ static int max8998_set_voltage_buck(struct regulator_dev *rdev,
390 323
391 /* Check if voltage needs to be changed */ 324 /* Check if voltage needs to be changed */
392 /* if previous_voltage equal new voltage, return */ 325 /* if previous_voltage equal new voltage, return */
393 if (previous_sel == i) { 326 if (previous_sel == selector) {
394 dev_dbg(max8998->dev, "No voltage change, old:%d, new:%d\n", 327 dev_dbg(max8998->dev, "No voltage change, old:%d, new:%d\n",
395 max8998_list_voltage(rdev, previous_sel), 328 regulator_list_voltage_linear(rdev, previous_sel),
396 max8998_list_voltage(rdev, i)); 329 regulator_list_voltage_linear(rdev, selector));
397 return ret; 330 return ret;
398 } 331 }
399 332
400 switch (buck) { 333 switch (buck) {
401 case MAX8998_BUCK1: 334 case MAX8998_BUCK1:
402 dev_dbg(max8998->dev, 335 dev_dbg(max8998->dev,
403 "BUCK1, i:%d, buck1_vol1:%d, buck1_vol2:%d\n" 336 "BUCK1, selector:%d, buck1_vol1:%d, buck1_vol2:%d\n"
404 "buck1_vol3:%d, buck1_vol4:%d\n", 337 "buck1_vol3:%d, buck1_vol4:%d\n",
405 i, max8998->buck1_vol[0], max8998->buck1_vol[1], 338 selector, max8998->buck1_vol[0], max8998->buck1_vol[1],
406 max8998->buck1_vol[2], max8998->buck1_vol[3]); 339 max8998->buck1_vol[2], max8998->buck1_vol[3]);
407 340
408 if (gpio_is_valid(pdata->buck1_set1) && 341 if (gpio_is_valid(pdata->buck1_set1) &&
@@ -411,7 +344,7 @@ static int max8998_set_voltage_buck(struct regulator_dev *rdev,
411 /* check if requested voltage */ 344 /* check if requested voltage */
412 /* value is already defined */ 345 /* value is already defined */
413 for (j = 0; j < ARRAY_SIZE(max8998->buck1_vol); j++) { 346 for (j = 0; j < ARRAY_SIZE(max8998->buck1_vol); j++) {
414 if (max8998->buck1_vol[j] == i) { 347 if (max8998->buck1_vol[j] == selector) {
415 max8998->buck1_idx = j; 348 max8998->buck1_idx = j;
416 buck1_gpio_set(pdata->buck1_set1, 349 buck1_gpio_set(pdata->buck1_set1,
417 pdata->buck1_set2, j); 350 pdata->buck1_set2, j);
@@ -426,11 +359,11 @@ static int max8998_set_voltage_buck(struct regulator_dev *rdev,
426 max8998->buck1_idx = (buck1_last_val % 2) + 2; 359 max8998->buck1_idx = (buck1_last_val % 2) + 2;
427 dev_dbg(max8998->dev, "max8998->buck1_idx:%d\n", 360 dev_dbg(max8998->dev, "max8998->buck1_idx:%d\n",
428 max8998->buck1_idx); 361 max8998->buck1_idx);
429 max8998->buck1_vol[max8998->buck1_idx] = i; 362 max8998->buck1_vol[max8998->buck1_idx] = selector;
430 ret = max8998_get_voltage_register(rdev, &reg, 363 ret = max8998_get_voltage_register(rdev, &reg,
431 &shift, 364 &shift,
432 &mask); 365 &mask);
433 ret = max8998_write_reg(i2c, reg, i); 366 ret = max8998_write_reg(i2c, reg, selector);
434 buck1_gpio_set(pdata->buck1_set1, 367 buck1_gpio_set(pdata->buck1_set1,
435 pdata->buck1_set2, max8998->buck1_idx); 368 pdata->buck1_set2, max8998->buck1_idx);
436 buck1_last_val++; 369 buck1_last_val++;
@@ -440,20 +373,20 @@ buck1_exit:
440 gpio_get_value(pdata->buck1_set2)); 373 gpio_get_value(pdata->buck1_set2));
441 break; 374 break;
442 } else { 375 } else {
443 ret = max8998_write_reg(i2c, reg, i); 376 ret = max8998_write_reg(i2c, reg, selector);
444 } 377 }
445 break; 378 break;
446 379
447 case MAX8998_BUCK2: 380 case MAX8998_BUCK2:
448 dev_dbg(max8998->dev, 381 dev_dbg(max8998->dev,
449 "BUCK2, i:%d buck2_vol1:%d, buck2_vol2:%d\n" 382 "BUCK2, selector:%d buck2_vol1:%d, buck2_vol2:%d\n",
450 , i, max8998->buck2_vol[0], max8998->buck2_vol[1]); 383 selector, max8998->buck2_vol[0], max8998->buck2_vol[1]);
451 if (gpio_is_valid(pdata->buck2_set3)) { 384 if (gpio_is_valid(pdata->buck2_set3)) {
452 385
453 /* check if requested voltage */ 386 /* check if requested voltage */
454 /* value is already defined */ 387 /* value is already defined */
455 for (j = 0; j < ARRAY_SIZE(max8998->buck2_vol); j++) { 388 for (j = 0; j < ARRAY_SIZE(max8998->buck2_vol); j++) {
456 if (max8998->buck2_vol[j] == i) { 389 if (max8998->buck2_vol[j] == selector) {
457 max8998->buck2_idx = j; 390 max8998->buck2_idx = j;
458 buck2_gpio_set(pdata->buck2_set3, j); 391 buck2_gpio_set(pdata->buck2_set3, j);
459 goto buck2_exit; 392 goto buck2_exit;
@@ -465,20 +398,21 @@ buck1_exit:
465 398
466 max8998_get_voltage_register(rdev, 399 max8998_get_voltage_register(rdev,
467 &reg, &shift, &mask); 400 &reg, &shift, &mask);
468 ret = max8998_write_reg(i2c, reg, i); 401 ret = max8998_write_reg(i2c, reg, selector);
469 max8998->buck2_vol[max8998->buck2_idx] = i; 402 max8998->buck2_vol[max8998->buck2_idx] = selector;
470 buck2_gpio_set(pdata->buck2_set3, max8998->buck2_idx); 403 buck2_gpio_set(pdata->buck2_set3, max8998->buck2_idx);
471buck2_exit: 404buck2_exit:
472 dev_dbg(max8998->dev, "%s: SET3:%d\n", i2c->name, 405 dev_dbg(max8998->dev, "%s: SET3:%d\n", i2c->name,
473 gpio_get_value(pdata->buck2_set3)); 406 gpio_get_value(pdata->buck2_set3));
474 } else { 407 } else {
475 ret = max8998_write_reg(i2c, reg, i); 408 ret = max8998_write_reg(i2c, reg, selector);
476 } 409 }
477 break; 410 break;
478 411
479 case MAX8998_BUCK3: 412 case MAX8998_BUCK3:
480 case MAX8998_BUCK4: 413 case MAX8998_BUCK4:
481 ret = max8998_update_reg(i2c, reg, i<<shift, mask<<shift); 414 ret = max8998_update_reg(i2c, reg, selector<<shift,
415 mask<<shift);
482 break; 416 break;
483 } 417 }
484 418
@@ -519,34 +453,30 @@ static int max8998_set_voltage_buck_time_sel(struct regulator_dev *rdev,
519} 453}
520 454
521static struct regulator_ops max8998_ldo_ops = { 455static struct regulator_ops max8998_ldo_ops = {
522 .list_voltage = max8998_list_voltage, 456 .list_voltage = regulator_list_voltage_linear,
457 .map_voltage = regulator_map_voltage_linear,
523 .is_enabled = max8998_ldo_is_enabled, 458 .is_enabled = max8998_ldo_is_enabled,
524 .enable = max8998_ldo_enable, 459 .enable = max8998_ldo_enable,
525 .disable = max8998_ldo_disable, 460 .disable = max8998_ldo_disable,
526 .get_voltage_sel = max8998_get_voltage_sel, 461 .get_voltage_sel = max8998_get_voltage_sel,
527 .set_voltage = max8998_set_voltage_ldo, 462 .set_voltage_sel = max8998_set_voltage_ldo_sel,
528 .set_suspend_enable = max8998_ldo_enable,
529 .set_suspend_disable = max8998_ldo_disable,
530}; 463};
531 464
532static struct regulator_ops max8998_buck_ops = { 465static struct regulator_ops max8998_buck_ops = {
533 .list_voltage = max8998_list_voltage, 466 .list_voltage = regulator_list_voltage_linear,
467 .map_voltage = regulator_map_voltage_linear,
534 .is_enabled = max8998_ldo_is_enabled, 468 .is_enabled = max8998_ldo_is_enabled,
535 .enable = max8998_ldo_enable, 469 .enable = max8998_ldo_enable,
536 .disable = max8998_ldo_disable, 470 .disable = max8998_ldo_disable,
537 .get_voltage_sel = max8998_get_voltage_sel, 471 .get_voltage_sel = max8998_get_voltage_sel,
538 .set_voltage = max8998_set_voltage_buck, 472 .set_voltage_sel = max8998_set_voltage_buck_sel,
539 .set_voltage_time_sel = max8998_set_voltage_buck_time_sel, 473 .set_voltage_time_sel = max8998_set_voltage_buck_time_sel,
540 .set_suspend_enable = max8998_ldo_enable,
541 .set_suspend_disable = max8998_ldo_disable,
542}; 474};
543 475
544static struct regulator_ops max8998_others_ops = { 476static struct regulator_ops max8998_others_ops = {
545 .is_enabled = max8998_ldo_is_enabled, 477 .is_enabled = max8998_ldo_is_enabled,
546 .enable = max8998_ldo_enable, 478 .enable = max8998_ldo_enable,
547 .disable = max8998_ldo_disable, 479 .disable = max8998_ldo_disable,
548 .set_suspend_enable = max8998_ldo_enable,
549 .set_suspend_disable = max8998_ldo_disable,
550}; 480};
551 481
552static struct regulator_desc regulators[] = { 482static struct regulator_desc regulators[] = {
@@ -860,7 +790,10 @@ static __devinit int max8998_pmic_probe(struct platform_device *pdev)
860 desc = ldo_voltage_map[id]; 790 desc = ldo_voltage_map[id];
861 if (desc && regulators[index].ops != &max8998_others_ops) { 791 if (desc && regulators[index].ops != &max8998_others_ops) {
862 int count = (desc->max - desc->min) / desc->step + 1; 792 int count = (desc->max - desc->min) / desc->step + 1;
793
863 regulators[index].n_voltages = count; 794 regulators[index].n_voltages = count;
795 regulators[index].min_uV = desc->min * 1000;
796 regulators[index].uV_step = desc->step * 1000;
864 } 797 }
865 798
866 config.dev = max8998->dev; 799 config.dev = max8998->dev;
diff --git a/drivers/regulator/mc13783-regulator.c b/drivers/regulator/mc13783-regulator.c
index 7dcdfa283e93..4932e3449fe1 100644
--- a/drivers/regulator/mc13783-regulator.c
+++ b/drivers/regulator/mc13783-regulator.c
@@ -93,78 +93,78 @@
93 93
94 94
95/* Voltage Values */ 95/* Voltage Values */
96static const int mc13783_sw3_val[] = { 96static const unsigned int mc13783_sw3_val[] = {
97 5000000, 5000000, 5000000, 5500000, 97 5000000, 5000000, 5000000, 5500000,
98}; 98};
99 99
100static const int mc13783_vaudio_val[] = { 100static const unsigned int mc13783_vaudio_val[] = {
101 2775000, 101 2775000,
102}; 102};
103 103
104static const int mc13783_viohi_val[] = { 104static const unsigned int mc13783_viohi_val[] = {
105 2775000, 105 2775000,
106}; 106};
107 107
108static const int mc13783_violo_val[] = { 108static const unsigned int mc13783_violo_val[] = {
109 1200000, 1300000, 1500000, 1800000, 109 1200000, 1300000, 1500000, 1800000,
110}; 110};
111 111
112static const int mc13783_vdig_val[] = { 112static const unsigned int mc13783_vdig_val[] = {
113 1200000, 1300000, 1500000, 1800000, 113 1200000, 1300000, 1500000, 1800000,
114}; 114};
115 115
116static const int mc13783_vgen_val[] = { 116static const unsigned int mc13783_vgen_val[] = {
117 1200000, 1300000, 1500000, 1800000, 117 1200000, 1300000, 1500000, 1800000,
118 1100000, 2000000, 2775000, 2400000, 118 1100000, 2000000, 2775000, 2400000,
119}; 119};
120 120
121static const int mc13783_vrfdig_val[] = { 121static const unsigned int mc13783_vrfdig_val[] = {
122 1200000, 1500000, 1800000, 1875000, 122 1200000, 1500000, 1800000, 1875000,
123}; 123};
124 124
125static const int mc13783_vrfref_val[] = { 125static const unsigned int mc13783_vrfref_val[] = {
126 2475000, 2600000, 2700000, 2775000, 126 2475000, 2600000, 2700000, 2775000,
127}; 127};
128 128
129static const int mc13783_vrfcp_val[] = { 129static const unsigned int mc13783_vrfcp_val[] = {
130 2700000, 2775000, 130 2700000, 2775000,
131}; 131};
132 132
133static const int mc13783_vsim_val[] = { 133static const unsigned int mc13783_vsim_val[] = {
134 1800000, 2900000, 3000000, 134 1800000, 2900000, 3000000,
135}; 135};
136 136
137static const int mc13783_vesim_val[] = { 137static const unsigned int mc13783_vesim_val[] = {
138 1800000, 2900000, 138 1800000, 2900000,
139}; 139};
140 140
141static const int mc13783_vcam_val[] = { 141static const unsigned int mc13783_vcam_val[] = {
142 1500000, 1800000, 2500000, 2550000, 142 1500000, 1800000, 2500000, 2550000,
143 2600000, 2750000, 2800000, 3000000, 143 2600000, 2750000, 2800000, 3000000,
144}; 144};
145 145
146static const int mc13783_vrfbg_val[] = { 146static const unsigned int mc13783_vrfbg_val[] = {
147 1250000, 147 1250000,
148}; 148};
149 149
150static const int mc13783_vvib_val[] = { 150static const unsigned int mc13783_vvib_val[] = {
151 1300000, 1800000, 2000000, 3000000, 151 1300000, 1800000, 2000000, 3000000,
152}; 152};
153 153
154static const int mc13783_vmmc_val[] = { 154static const unsigned int mc13783_vmmc_val[] = {
155 1600000, 1800000, 2000000, 2600000, 155 1600000, 1800000, 2000000, 2600000,
156 2700000, 2800000, 2900000, 3000000, 156 2700000, 2800000, 2900000, 3000000,
157}; 157};
158 158
159static const int mc13783_vrf_val[] = { 159static const unsigned int mc13783_vrf_val[] = {
160 1500000, 1875000, 2700000, 2775000, 160 1500000, 1875000, 2700000, 2775000,
161}; 161};
162 162
163static const int mc13783_gpo_val[] = { 163static const unsigned int mc13783_gpo_val[] = {
164 3100000, 164 3100000,
165}; 165};
166 166
167static const int mc13783_pwgtdrv_val[] = { 167static const unsigned int mc13783_pwgtdrv_val[] = {
168 5500000, 168 5500000,
169}; 169};
170 170
@@ -328,7 +328,7 @@ static struct regulator_ops mc13783_gpo_regulator_ops = {
328 .enable = mc13783_gpo_regulator_enable, 328 .enable = mc13783_gpo_regulator_enable,
329 .disable = mc13783_gpo_regulator_disable, 329 .disable = mc13783_gpo_regulator_disable,
330 .is_enabled = mc13783_gpo_regulator_is_enabled, 330 .is_enabled = mc13783_gpo_regulator_is_enabled,
331 .list_voltage = mc13xxx_regulator_list_voltage, 331 .list_voltage = regulator_list_voltage_table,
332 .set_voltage = mc13xxx_fixed_regulator_set_voltage, 332 .set_voltage = mc13xxx_fixed_regulator_set_voltage,
333 .get_voltage = mc13xxx_fixed_regulator_get_voltage, 333 .get_voltage = mc13xxx_fixed_regulator_get_voltage,
334}; 334};
diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
index 970a233dbe46..b388b746452e 100644
--- a/drivers/regulator/mc13892-regulator.c
+++ b/drivers/regulator/mc13892-regulator.c
@@ -150,12 +150,12 @@
150#define MC13892_USB1 50 150#define MC13892_USB1 50
151#define MC13892_USB1_VUSBEN (1<<3) 151#define MC13892_USB1_VUSBEN (1<<3)
152 152
153static const int mc13892_vcoincell[] = { 153static const unsigned int mc13892_vcoincell[] = {
154 2500000, 2700000, 2800000, 2900000, 3000000, 3100000, 154 2500000, 2700000, 2800000, 2900000, 3000000, 3100000,
155 3200000, 3300000, 155 3200000, 3300000,
156}; 156};
157 157
158static const int mc13892_sw1[] = { 158static const unsigned int mc13892_sw1[] = {
159 600000, 625000, 650000, 675000, 700000, 725000, 159 600000, 625000, 650000, 675000, 700000, 725000,
160 750000, 775000, 800000, 825000, 850000, 875000, 160 750000, 775000, 800000, 825000, 850000, 875000,
161 900000, 925000, 950000, 975000, 1000000, 1025000, 161 900000, 925000, 950000, 975000, 1000000, 1025000,
@@ -164,7 +164,7 @@ static const int mc13892_sw1[] = {
164 1350000, 1375000 164 1350000, 1375000
165}; 165};
166 166
167static const int mc13892_sw[] = { 167static const unsigned int mc13892_sw[] = {
168 600000, 625000, 650000, 675000, 700000, 725000, 168 600000, 625000, 650000, 675000, 700000, 725000,
169 750000, 775000, 800000, 825000, 850000, 875000, 169 750000, 775000, 800000, 825000, 850000, 875000,
170 900000, 925000, 950000, 975000, 1000000, 1025000, 170 900000, 925000, 950000, 975000, 1000000, 1025000,
@@ -176,65 +176,65 @@ static const int mc13892_sw[] = {
176 1800000, 1825000, 1850000, 1875000 176 1800000, 1825000, 1850000, 1875000
177}; 177};
178 178
179static const int mc13892_swbst[] = { 179static const unsigned int mc13892_swbst[] = {
180 5000000, 180 5000000,
181}; 181};
182 182
183static const int mc13892_viohi[] = { 183static const unsigned int mc13892_viohi[] = {
184 2775000, 184 2775000,
185}; 185};
186 186
187static const int mc13892_vpll[] = { 187static const unsigned int mc13892_vpll[] = {
188 1050000, 1250000, 1650000, 1800000, 188 1050000, 1250000, 1650000, 1800000,
189}; 189};
190 190
191static const int mc13892_vdig[] = { 191static const unsigned int mc13892_vdig[] = {
192 1050000, 1250000, 1650000, 1800000, 192 1050000, 1250000, 1650000, 1800000,
193}; 193};
194 194
195static const int mc13892_vsd[] = { 195static const unsigned int mc13892_vsd[] = {
196 1800000, 2000000, 2600000, 2700000, 196 1800000, 2000000, 2600000, 2700000,
197 2800000, 2900000, 3000000, 3150000, 197 2800000, 2900000, 3000000, 3150000,
198}; 198};
199 199
200static const int mc13892_vusb2[] = { 200static const unsigned int mc13892_vusb2[] = {
201 2400000, 2600000, 2700000, 2775000, 201 2400000, 2600000, 2700000, 2775000,
202}; 202};
203 203
204static const int mc13892_vvideo[] = { 204static const unsigned int mc13892_vvideo[] = {
205 2700000, 2775000, 2500000, 2600000, 205 2700000, 2775000, 2500000, 2600000,
206}; 206};
207 207
208static const int mc13892_vaudio[] = { 208static const unsigned int mc13892_vaudio[] = {
209 2300000, 2500000, 2775000, 3000000, 209 2300000, 2500000, 2775000, 3000000,
210}; 210};
211 211
212static const int mc13892_vcam[] = { 212static const unsigned int mc13892_vcam[] = {
213 2500000, 2600000, 2750000, 3000000, 213 2500000, 2600000, 2750000, 3000000,
214}; 214};
215 215
216static const int mc13892_vgen1[] = { 216static const unsigned int mc13892_vgen1[] = {
217 1200000, 1500000, 2775000, 3150000, 217 1200000, 1500000, 2775000, 3150000,
218}; 218};
219 219
220static const int mc13892_vgen2[] = { 220static const unsigned int mc13892_vgen2[] = {
221 1200000, 1500000, 1600000, 1800000, 221 1200000, 1500000, 1600000, 1800000,
222 2700000, 2800000, 3000000, 3150000, 222 2700000, 2800000, 3000000, 3150000,
223}; 223};
224 224
225static const int mc13892_vgen3[] = { 225static const unsigned int mc13892_vgen3[] = {
226 1800000, 2900000, 226 1800000, 2900000,
227}; 227};
228 228
229static const int mc13892_vusb[] = { 229static const unsigned int mc13892_vusb[] = {
230 3300000, 230 3300000,
231}; 231};
232 232
233static const int mc13892_gpo[] = { 233static const unsigned int mc13892_gpo[] = {
234 2750000, 234 2750000,
235}; 235};
236 236
237static const int mc13892_pwgtdrv[] = { 237static const unsigned int mc13892_pwgtdrv[] = {
238 5000000, 238 5000000,
239}; 239};
240 240
@@ -394,7 +394,7 @@ static struct regulator_ops mc13892_gpo_regulator_ops = {
394 .enable = mc13892_gpo_regulator_enable, 394 .enable = mc13892_gpo_regulator_enable,
395 .disable = mc13892_gpo_regulator_disable, 395 .disable = mc13892_gpo_regulator_disable,
396 .is_enabled = mc13892_gpo_regulator_is_enabled, 396 .is_enabled = mc13892_gpo_regulator_is_enabled,
397 .list_voltage = mc13xxx_regulator_list_voltage, 397 .list_voltage = regulator_list_voltage_table,
398 .set_voltage = mc13xxx_fixed_regulator_set_voltage, 398 .set_voltage = mc13xxx_fixed_regulator_set_voltage,
399 .get_voltage = mc13xxx_fixed_regulator_get_voltage, 399 .get_voltage = mc13xxx_fixed_regulator_get_voltage,
400}; 400};
@@ -436,7 +436,7 @@ static int mc13892_sw_regulator_set_voltage_sel(struct regulator_dev *rdev,
436 u32 valread; 436 u32 valread;
437 int ret; 437 int ret;
438 438
439 value = mc13892_regulators[id].voltages[selector]; 439 value = rdev->desc->volt_table[selector];
440 440
441 mc13xxx_lock(priv->mc13xxx); 441 mc13xxx_lock(priv->mc13xxx);
442 ret = mc13xxx_reg_read(priv->mc13xxx, 442 ret = mc13xxx_reg_read(priv->mc13xxx,
@@ -469,8 +469,7 @@ err:
469} 469}
470 470
471static struct regulator_ops mc13892_sw_regulator_ops = { 471static struct regulator_ops mc13892_sw_regulator_ops = {
472 .is_enabled = mc13xxx_sw_regulator_is_enabled, 472 .list_voltage = regulator_list_voltage_table,
473 .list_voltage = mc13xxx_regulator_list_voltage,
474 .set_voltage_sel = mc13892_sw_regulator_set_voltage_sel, 473 .set_voltage_sel = mc13892_sw_regulator_set_voltage_sel,
475 .get_voltage = mc13892_sw_regulator_get_voltage, 474 .get_voltage = mc13892_sw_regulator_get_voltage,
476}; 475};
diff --git a/drivers/regulator/mc13xxx-regulator-core.c b/drivers/regulator/mc13xxx-regulator-core.c
index 4fa9704739bc..d6eda28ca5d0 100644
--- a/drivers/regulator/mc13xxx-regulator-core.c
+++ b/drivers/regulator/mc13xxx-regulator-core.c
@@ -80,20 +80,6 @@ static int mc13xxx_regulator_is_enabled(struct regulator_dev *rdev)
80 return (val & mc13xxx_regulators[id].enable_bit) != 0; 80 return (val & mc13xxx_regulators[id].enable_bit) != 0;
81} 81}
82 82
83int mc13xxx_regulator_list_voltage(struct regulator_dev *rdev,
84 unsigned selector)
85{
86 int id = rdev_get_id(rdev);
87 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
88 struct mc13xxx_regulator *mc13xxx_regulators = priv->mc13xxx_regulators;
89
90 if (selector >= mc13xxx_regulators[id].desc.n_voltages)
91 return -EINVAL;
92
93 return mc13xxx_regulators[id].voltages[selector];
94}
95EXPORT_SYMBOL_GPL(mc13xxx_regulator_list_voltage);
96
97static int mc13xxx_regulator_set_voltage_sel(struct regulator_dev *rdev, 83static int mc13xxx_regulator_set_voltage_sel(struct regulator_dev *rdev,
98 unsigned selector) 84 unsigned selector)
99{ 85{
@@ -135,14 +121,14 @@ static int mc13xxx_regulator_get_voltage(struct regulator_dev *rdev)
135 121
136 BUG_ON(val >= mc13xxx_regulators[id].desc.n_voltages); 122 BUG_ON(val >= mc13xxx_regulators[id].desc.n_voltages);
137 123
138 return mc13xxx_regulators[id].voltages[val]; 124 return rdev->desc->volt_table[val];
139} 125}
140 126
141struct regulator_ops mc13xxx_regulator_ops = { 127struct regulator_ops mc13xxx_regulator_ops = {
142 .enable = mc13xxx_regulator_enable, 128 .enable = mc13xxx_regulator_enable,
143 .disable = mc13xxx_regulator_disable, 129 .disable = mc13xxx_regulator_disable,
144 .is_enabled = mc13xxx_regulator_is_enabled, 130 .is_enabled = mc13xxx_regulator_is_enabled,
145 .list_voltage = mc13xxx_regulator_list_voltage, 131 .list_voltage = regulator_list_voltage_table,
146 .set_voltage_sel = mc13xxx_regulator_set_voltage_sel, 132 .set_voltage_sel = mc13xxx_regulator_set_voltage_sel,
147 .get_voltage = mc13xxx_regulator_get_voltage, 133 .get_voltage = mc13xxx_regulator_get_voltage,
148}; 134};
@@ -151,15 +137,13 @@ EXPORT_SYMBOL_GPL(mc13xxx_regulator_ops);
151int mc13xxx_fixed_regulator_set_voltage(struct regulator_dev *rdev, int min_uV, 137int mc13xxx_fixed_regulator_set_voltage(struct regulator_dev *rdev, int min_uV,
152 int max_uV, unsigned *selector) 138 int max_uV, unsigned *selector)
153{ 139{
154 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
155 struct mc13xxx_regulator *mc13xxx_regulators = priv->mc13xxx_regulators;
156 int id = rdev_get_id(rdev); 140 int id = rdev_get_id(rdev);
157 141
158 dev_dbg(rdev_get_dev(rdev), "%s id: %d min_uV: %d max_uV: %d\n", 142 dev_dbg(rdev_get_dev(rdev), "%s id: %d min_uV: %d max_uV: %d\n",
159 __func__, id, min_uV, max_uV); 143 __func__, id, min_uV, max_uV);
160 144
161 if (min_uV >= mc13xxx_regulators[id].voltages[0] && 145 if (min_uV <= rdev->desc->volt_table[0] &&
162 max_uV <= mc13xxx_regulators[id].voltages[0]) 146 rdev->desc->volt_table[0] <= max_uV)
163 return 0; 147 return 0;
164 else 148 else
165 return -EINVAL; 149 return -EINVAL;
@@ -168,13 +152,11 @@ EXPORT_SYMBOL_GPL(mc13xxx_fixed_regulator_set_voltage);
168 152
169int mc13xxx_fixed_regulator_get_voltage(struct regulator_dev *rdev) 153int mc13xxx_fixed_regulator_get_voltage(struct regulator_dev *rdev)
170{ 154{
171 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
172 struct mc13xxx_regulator *mc13xxx_regulators = priv->mc13xxx_regulators;
173 int id = rdev_get_id(rdev); 155 int id = rdev_get_id(rdev);
174 156
175 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id); 157 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id);
176 158
177 return mc13xxx_regulators[id].voltages[0]; 159 return rdev->desc->volt_table[0];
178} 160}
179EXPORT_SYMBOL_GPL(mc13xxx_fixed_regulator_get_voltage); 161EXPORT_SYMBOL_GPL(mc13xxx_fixed_regulator_get_voltage);
180 162
@@ -182,18 +164,12 @@ struct regulator_ops mc13xxx_fixed_regulator_ops = {
182 .enable = mc13xxx_regulator_enable, 164 .enable = mc13xxx_regulator_enable,
183 .disable = mc13xxx_regulator_disable, 165 .disable = mc13xxx_regulator_disable,
184 .is_enabled = mc13xxx_regulator_is_enabled, 166 .is_enabled = mc13xxx_regulator_is_enabled,
185 .list_voltage = mc13xxx_regulator_list_voltage, 167 .list_voltage = regulator_list_voltage_table,
186 .set_voltage = mc13xxx_fixed_regulator_set_voltage, 168 .set_voltage = mc13xxx_fixed_regulator_set_voltage,
187 .get_voltage = mc13xxx_fixed_regulator_get_voltage, 169 .get_voltage = mc13xxx_fixed_regulator_get_voltage,
188}; 170};
189EXPORT_SYMBOL_GPL(mc13xxx_fixed_regulator_ops); 171EXPORT_SYMBOL_GPL(mc13xxx_fixed_regulator_ops);
190 172
191int mc13xxx_sw_regulator_is_enabled(struct regulator_dev *rdev)
192{
193 return 1;
194}
195EXPORT_SYMBOL_GPL(mc13xxx_sw_regulator_is_enabled);
196
197#ifdef CONFIG_OF 173#ifdef CONFIG_OF
198int __devinit mc13xxx_get_num_regulators_dt(struct platform_device *pdev) 174int __devinit mc13xxx_get_num_regulators_dt(struct platform_device *pdev)
199{ 175{
diff --git a/drivers/regulator/mc13xxx.h b/drivers/regulator/mc13xxx.h
index 044aba4d28ec..eaff5510b6df 100644
--- a/drivers/regulator/mc13xxx.h
+++ b/drivers/regulator/mc13xxx.h
@@ -22,7 +22,6 @@ struct mc13xxx_regulator {
22 int vsel_shift; 22 int vsel_shift;
23 int vsel_mask; 23 int vsel_mask;
24 int hi_bit; 24 int hi_bit;
25 int const *voltages;
26}; 25};
27 26
28struct mc13xxx_regulator_priv { 27struct mc13xxx_regulator_priv {
@@ -33,10 +32,6 @@ struct mc13xxx_regulator_priv {
33 struct regulator_dev *regulators[]; 32 struct regulator_dev *regulators[];
34}; 33};
35 34
36extern int mc13xxx_sw_regulator(struct regulator_dev *rdev);
37extern int mc13xxx_sw_regulator_is_enabled(struct regulator_dev *rdev);
38extern int mc13xxx_regulator_list_voltage(struct regulator_dev *rdev,
39 unsigned selector);
40extern int mc13xxx_fixed_regulator_set_voltage(struct regulator_dev *rdev, 35extern int mc13xxx_fixed_regulator_set_voltage(struct regulator_dev *rdev,
41 int min_uV, int max_uV, unsigned *selector); 36 int min_uV, int max_uV, unsigned *selector);
42extern int mc13xxx_fixed_regulator_get_voltage(struct regulator_dev *rdev); 37extern int mc13xxx_fixed_regulator_get_voltage(struct regulator_dev *rdev);
@@ -68,6 +63,7 @@ extern struct regulator_ops mc13xxx_fixed_regulator_ops;
68 .desc = { \ 63 .desc = { \
69 .name = #_name, \ 64 .name = #_name, \
70 .n_voltages = ARRAY_SIZE(_voltages), \ 65 .n_voltages = ARRAY_SIZE(_voltages), \
66 .volt_table = _voltages, \
71 .ops = &_ops, \ 67 .ops = &_ops, \
72 .type = REGULATOR_VOLTAGE, \ 68 .type = REGULATOR_VOLTAGE, \
73 .id = prefix ## _name, \ 69 .id = prefix ## _name, \
@@ -78,7 +74,6 @@ extern struct regulator_ops mc13xxx_fixed_regulator_ops;
78 .vsel_reg = prefix ## _vsel_reg, \ 74 .vsel_reg = prefix ## _vsel_reg, \
79 .vsel_shift = prefix ## _vsel_reg ## _ ## _name ## VSEL,\ 75 .vsel_shift = prefix ## _vsel_reg ## _ ## _name ## VSEL,\
80 .vsel_mask = prefix ## _vsel_reg ## _ ## _name ## VSEL_M,\ 76 .vsel_mask = prefix ## _vsel_reg ## _ ## _name ## VSEL_M,\
81 .voltages = _voltages, \
82 } 77 }
83 78
84#define MC13xxx_FIXED_DEFINE(prefix, _name, _reg, _voltages, _ops) \ 79#define MC13xxx_FIXED_DEFINE(prefix, _name, _reg, _voltages, _ops) \
@@ -86,6 +81,7 @@ extern struct regulator_ops mc13xxx_fixed_regulator_ops;
86 .desc = { \ 81 .desc = { \
87 .name = #_name, \ 82 .name = #_name, \
88 .n_voltages = ARRAY_SIZE(_voltages), \ 83 .n_voltages = ARRAY_SIZE(_voltages), \
84 .volt_table = _voltages, \
89 .ops = &_ops, \ 85 .ops = &_ops, \
90 .type = REGULATOR_VOLTAGE, \ 86 .type = REGULATOR_VOLTAGE, \
91 .id = prefix ## _name, \ 87 .id = prefix ## _name, \
@@ -93,7 +89,6 @@ extern struct regulator_ops mc13xxx_fixed_regulator_ops;
93 }, \ 89 }, \
94 .reg = prefix ## _reg, \ 90 .reg = prefix ## _reg, \
95 .enable_bit = prefix ## _reg ## _ ## _name ## EN, \ 91 .enable_bit = prefix ## _reg ## _ ## _name ## EN, \
96 .voltages = _voltages, \
97 } 92 }
98 93
99#define MC13xxx_GPO_DEFINE(prefix, _name, _reg, _voltages, _ops) \ 94#define MC13xxx_GPO_DEFINE(prefix, _name, _reg, _voltages, _ops) \
@@ -101,6 +96,7 @@ extern struct regulator_ops mc13xxx_fixed_regulator_ops;
101 .desc = { \ 96 .desc = { \
102 .name = #_name, \ 97 .name = #_name, \
103 .n_voltages = ARRAY_SIZE(_voltages), \ 98 .n_voltages = ARRAY_SIZE(_voltages), \
99 .volt_table = _voltages, \
104 .ops = &_ops, \ 100 .ops = &_ops, \
105 .type = REGULATOR_VOLTAGE, \ 101 .type = REGULATOR_VOLTAGE, \
106 .id = prefix ## _name, \ 102 .id = prefix ## _name, \
@@ -108,7 +104,6 @@ extern struct regulator_ops mc13xxx_fixed_regulator_ops;
108 }, \ 104 }, \
109 .reg = prefix ## _reg, \ 105 .reg = prefix ## _reg, \
110 .enable_bit = prefix ## _reg ## _ ## _name ## EN, \ 106 .enable_bit = prefix ## _reg ## _ ## _name ## EN, \
111 .voltages = _voltages, \
112 } 107 }
113 108
114#define MC13xxx_DEFINE_SW(_name, _reg, _vsel_reg, _voltages, ops) \ 109#define MC13xxx_DEFINE_SW(_name, _reg, _vsel_reg, _voltages, ops) \
diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
index 56593b75168a..3e4106f2bda9 100644
--- a/drivers/regulator/of_regulator.c
+++ b/drivers/regulator/of_regulator.c
@@ -20,7 +20,7 @@ static void of_get_regulation_constraints(struct device_node *np,
20 struct regulator_init_data **init_data) 20 struct regulator_init_data **init_data)
21{ 21{
22 const __be32 *min_uV, *max_uV, *uV_offset; 22 const __be32 *min_uV, *max_uV, *uV_offset;
23 const __be32 *min_uA, *max_uA; 23 const __be32 *min_uA, *max_uA, *ramp_delay;
24 struct regulation_constraints *constraints = &(*init_data)->constraints; 24 struct regulation_constraints *constraints = &(*init_data)->constraints;
25 25
26 constraints->name = of_get_property(np, "regulator-name", NULL); 26 constraints->name = of_get_property(np, "regulator-name", NULL);
@@ -60,6 +60,10 @@ static void of_get_regulation_constraints(struct device_node *np,
60 constraints->always_on = true; 60 constraints->always_on = true;
61 else /* status change should be possible if not always on. */ 61 else /* status change should be possible if not always on. */
62 constraints->valid_ops_mask |= REGULATOR_CHANGE_STATUS; 62 constraints->valid_ops_mask |= REGULATOR_CHANGE_STATUS;
63
64 ramp_delay = of_get_property(np, "regulator-ramp-delay", NULL);
65 if (ramp_delay)
66 constraints->ramp_delay = be32_to_cpu(*ramp_delay);
63} 67}
64 68
65/** 69/**
@@ -88,15 +92,17 @@ struct regulator_init_data *of_get_regulator_init_data(struct device *dev,
88EXPORT_SYMBOL_GPL(of_get_regulator_init_data); 92EXPORT_SYMBOL_GPL(of_get_regulator_init_data);
89 93
90/** 94/**
91 * of_regulator_match - extract regulator init data 95 * of_regulator_match - extract regulator init data when node
96 * property "regulator-compatible" matches with the regulator name.
92 * @dev: device requesting the data 97 * @dev: device requesting the data
93 * @node: parent device node of the regulators 98 * @node: parent device node of the regulators
94 * @matches: match table for the regulators 99 * @matches: match table for the regulators
95 * @num_matches: number of entries in match table 100 * @num_matches: number of entries in match table
96 * 101 *
97 * This function uses a match table specified by the regulator driver and 102 * This function uses a match table specified by the regulator driver and
98 * looks up the corresponding init data in the device tree. Note that the 103 * looks up the corresponding init data in the device tree if
99 * match table is modified in place. 104 * regulator-compatible matches. Note that the match table is modified
105 * in place.
100 * 106 *
101 * Returns the number of matches found or a negative error code on failure. 107 * Returns the number of matches found or a negative error code on failure.
102 */ 108 */
@@ -106,27 +112,40 @@ int of_regulator_match(struct device *dev, struct device_node *node,
106{ 112{
107 unsigned int count = 0; 113 unsigned int count = 0;
108 unsigned int i; 114 unsigned int i;
115 const char *regulator_comp;
116 struct device_node *child;
109 117
110 if (!dev || !node) 118 if (!dev || !node)
111 return -EINVAL; 119 return -EINVAL;
112 120
113 for (i = 0; i < num_matches; i++) { 121 for_each_child_of_node(node, child) {
114 struct of_regulator_match *match = &matches[i]; 122 regulator_comp = of_get_property(child,
115 struct device_node *child; 123 "regulator-compatible", NULL);
116 124 if (!regulator_comp) {
117 child = of_find_node_by_name(node, match->name); 125 dev_err(dev, "regulator-compatible is missing for node %s\n",
118 if (!child)
119 continue;
120
121 match->init_data = of_get_regulator_init_data(dev, child);
122 if (!match->init_data) {
123 dev_err(dev, "failed to parse DT for regulator %s\n",
124 child->name); 126 child->name);
125 return -EINVAL; 127 continue;
128 }
129 for (i = 0; i < num_matches; i++) {
130 struct of_regulator_match *match = &matches[i];
131 if (match->of_node)
132 continue;
133
134 if (strcmp(match->name, regulator_comp))
135 continue;
136
137 match->init_data =
138 of_get_regulator_init_data(dev, child);
139 if (!match->init_data) {
140 dev_err(dev,
141 "failed to parse DT for regulator %s\n",
142 child->name);
143 return -EINVAL;
144 }
145 match->of_node = child;
146 count++;
147 break;
126 } 148 }
127
128 match->of_node = child;
129 count++;
130 } 149 }
131 150
132 return count; 151 return count;
diff --git a/drivers/regulator/palmas-regulator.c b/drivers/regulator/palmas-regulator.c
index 795f75a6ac33..17d19fbbc490 100644
--- a/drivers/regulator/palmas-regulator.c
+++ b/drivers/regulator/palmas-regulator.c
@@ -257,8 +257,7 @@ static int palmas_set_mode_smps(struct regulator_dev *dev, unsigned int mode)
257 unsigned int reg; 257 unsigned int reg;
258 258
259 palmas_smps_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, &reg); 259 palmas_smps_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, &reg);
260 reg &= ~PALMAS_SMPS12_CTRL_STATUS_MASK; 260 reg &= ~PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
261 reg >>= PALMAS_SMPS12_CTRL_STATUS_SHIFT;
262 261
263 switch (mode) { 262 switch (mode) {
264 case REGULATOR_MODE_NORMAL: 263 case REGULATOR_MODE_NORMAL:
@@ -374,11 +373,22 @@ static int palmas_set_voltage_smps_sel(struct regulator_dev *dev,
374static int palmas_map_voltage_smps(struct regulator_dev *rdev, 373static int palmas_map_voltage_smps(struct regulator_dev *rdev,
375 int min_uV, int max_uV) 374 int min_uV, int max_uV)
376{ 375{
376 struct palmas_pmic *pmic = rdev_get_drvdata(rdev);
377 int id = rdev_get_id(rdev);
377 int ret, voltage; 378 int ret, voltage;
378 379
379 ret = ((min_uV - 500000) / 10000) + 1; 380 if (min_uV == 0)
380 if (ret < 0) 381 return 0;
381 return ret; 382
383 if (pmic->range[id]) { /* RANGE is x2 */
384 if (min_uV < 1000000)
385 min_uV = 1000000;
386 ret = DIV_ROUND_UP(min_uV - 1000000, 20000) + 1;
387 } else { /* RANGE is x1 */
388 if (min_uV < 500000)
389 min_uV = 500000;
390 ret = DIV_ROUND_UP(min_uV - 500000, 10000) + 1;
391 }
382 392
383 /* Map back into a voltage to verify we're still in bounds */ 393 /* Map back into a voltage to verify we're still in bounds */
384 voltage = palmas_list_voltage_smps(rdev, ret); 394 voltage = palmas_list_voltage_smps(rdev, ret);
@@ -400,19 +410,14 @@ static struct regulator_ops palmas_ops_smps = {
400 .map_voltage = palmas_map_voltage_smps, 410 .map_voltage = palmas_map_voltage_smps,
401}; 411};
402 412
403static int palmas_list_voltage_smps10(struct regulator_dev *dev,
404 unsigned selector)
405{
406 return 3750000 + (selector * 1250000);
407}
408
409static struct regulator_ops palmas_ops_smps10 = { 413static struct regulator_ops palmas_ops_smps10 = {
410 .is_enabled = regulator_is_enabled_regmap, 414 .is_enabled = regulator_is_enabled_regmap,
411 .enable = regulator_enable_regmap, 415 .enable = regulator_enable_regmap,
412 .disable = regulator_disable_regmap, 416 .disable = regulator_disable_regmap,
413 .get_voltage_sel = regulator_get_voltage_sel_regmap, 417 .get_voltage_sel = regulator_get_voltage_sel_regmap,
414 .set_voltage_sel = regulator_set_voltage_sel_regmap, 418 .set_voltage_sel = regulator_set_voltage_sel_regmap,
415 .list_voltage = palmas_list_voltage_smps10, 419 .list_voltage = regulator_list_voltage_linear,
420 .map_voltage = regulator_map_voltage_linear,
416}; 421};
417 422
418static int palmas_is_enabled_ldo(struct regulator_dev *dev) 423static int palmas_is_enabled_ldo(struct regulator_dev *dev)
@@ -522,7 +527,15 @@ static int palmas_smps_init(struct palmas *palmas, int id,
522 if (ret) 527 if (ret)
523 return ret; 528 return ret;
524 529
525 if (id != PALMAS_REG_SMPS10) { 530 switch (id) {
531 case PALMAS_REG_SMPS10:
532 if (reg_init->mode_sleep) {
533 reg &= ~PALMAS_SMPS10_CTRL_MODE_SLEEP_MASK;
534 reg |= reg_init->mode_sleep <<
535 PALMAS_SMPS10_CTRL_MODE_SLEEP_SHIFT;
536 }
537 break;
538 default:
526 if (reg_init->warm_reset) 539 if (reg_init->warm_reset)
527 reg |= PALMAS_SMPS12_CTRL_WR_S; 540 reg |= PALMAS_SMPS12_CTRL_WR_S;
528 541
@@ -534,14 +547,8 @@ static int palmas_smps_init(struct palmas *palmas, int id,
534 reg |= reg_init->mode_sleep << 547 reg |= reg_init->mode_sleep <<
535 PALMAS_SMPS12_CTRL_MODE_SLEEP_SHIFT; 548 PALMAS_SMPS12_CTRL_MODE_SLEEP_SHIFT;
536 } 549 }
537 } else {
538 if (reg_init->mode_sleep) {
539 reg &= ~PALMAS_SMPS10_CTRL_MODE_SLEEP_MASK;
540 reg |= reg_init->mode_sleep <<
541 PALMAS_SMPS10_CTRL_MODE_SLEEP_SHIFT;
542 }
543
544 } 550 }
551
545 ret = palmas_smps_write(palmas, addr, reg); 552 ret = palmas_smps_write(palmas, addr, reg);
546 if (ret) 553 if (ret)
547 return ret; 554 return ret;
@@ -665,10 +672,8 @@ static __devinit int palmas_probe(struct platform_device *pdev)
665 pmic->desc[id].name = palmas_regs_info[id].name; 672 pmic->desc[id].name = palmas_regs_info[id].name;
666 pmic->desc[id].id = id; 673 pmic->desc[id].id = id;
667 674
668 if (id != PALMAS_REG_SMPS10) { 675 switch (id) {
669 pmic->desc[id].ops = &palmas_ops_smps; 676 case PALMAS_REG_SMPS10:
670 pmic->desc[id].n_voltages = PALMAS_SMPS_NUM_VOLTAGES;
671 } else {
672 pmic->desc[id].n_voltages = PALMAS_SMPS10_NUM_VOLTAGES; 677 pmic->desc[id].n_voltages = PALMAS_SMPS10_NUM_VOLTAGES;
673 pmic->desc[id].ops = &palmas_ops_smps10; 678 pmic->desc[id].ops = &palmas_ops_smps10;
674 pmic->desc[id].vsel_reg = PALMAS_SMPS10_CTRL; 679 pmic->desc[id].vsel_reg = PALMAS_SMPS10_CTRL;
@@ -677,6 +682,12 @@ static __devinit int palmas_probe(struct platform_device *pdev)
677 PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE, 682 PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE,
678 PALMAS_SMPS10_STATUS); 683 PALMAS_SMPS10_STATUS);
679 pmic->desc[id].enable_mask = SMPS10_BOOST_EN; 684 pmic->desc[id].enable_mask = SMPS10_BOOST_EN;
685 pmic->desc[id].min_uV = 3750000;
686 pmic->desc[id].uV_step = 1250000;
687 break;
688 default:
689 pmic->desc[id].ops = &palmas_ops_smps;
690 pmic->desc[id].n_voltages = PALMAS_SMPS_NUM_VOLTAGES;
680 } 691 }
681 692
682 pmic->desc[id].type = REGULATOR_VOLTAGE; 693 pmic->desc[id].type = REGULATOR_VOLTAGE;
diff --git a/drivers/regulator/pcap-regulator.c b/drivers/regulator/pcap-regulator.c
index 8211101121f0..68777acc099f 100644
--- a/drivers/regulator/pcap-regulator.c
+++ b/drivers/regulator/pcap-regulator.c
@@ -18,80 +18,80 @@
18#include <linux/regulator/machine.h> 18#include <linux/regulator/machine.h>
19#include <linux/mfd/ezx-pcap.h> 19#include <linux/mfd/ezx-pcap.h>
20 20
21static const u16 V1_table[] = { 21static const unsigned int V1_table[] = {
22 2775, 1275, 1600, 1725, 1825, 1925, 2075, 2275, 22 2775000, 1275000, 1600000, 1725000, 1825000, 1925000, 2075000, 2275000,
23}; 23};
24 24
25static const u16 V2_table[] = { 25static const unsigned int V2_table[] = {
26 2500, 2775, 26 2500000, 2775000,
27}; 27};
28 28
29static const u16 V3_table[] = { 29static const unsigned int V3_table[] = {
30 1075, 1275, 1550, 1725, 1876, 1950, 2075, 2275, 30 1075000, 1275000, 1550000, 1725000, 1876000, 1950000, 2075000, 2275000,
31}; 31};
32 32
33static const u16 V4_table[] = { 33static const unsigned int V4_table[] = {
34 1275, 1550, 1725, 1875, 1950, 2075, 2275, 2775, 34 1275000, 1550000, 1725000, 1875000, 1950000, 2075000, 2275000, 2775000,
35}; 35};
36 36
37static const u16 V5_table[] = { 37static const unsigned int V5_table[] = {
38 1875, 2275, 2475, 2775, 38 1875000, 2275000, 2475000, 2775000,
39}; 39};
40 40
41static const u16 V6_table[] = { 41static const unsigned int V6_table[] = {
42 2475, 2775, 42 2475000, 2775000,
43}; 43};
44 44
45static const u16 V7_table[] = { 45static const unsigned int V7_table[] = {
46 1875, 2775, 46 1875000, 2775000,
47}; 47};
48 48
49#define V8_table V4_table 49#define V8_table V4_table
50 50
51static const u16 V9_table[] = { 51static const unsigned int V9_table[] = {
52 1575, 1875, 2475, 2775, 52 1575000, 1875000, 2475000, 2775000,
53}; 53};
54 54
55static const u16 V10_table[] = { 55static const unsigned int V10_table[] = {
56 5000, 56 5000000,
57}; 57};
58 58
59static const u16 VAUX1_table[] = { 59static const unsigned int VAUX1_table[] = {
60 1875, 2475, 2775, 3000, 60 1875000, 2475000, 2775000, 3000000,
61}; 61};
62 62
63#define VAUX2_table VAUX1_table 63#define VAUX2_table VAUX1_table
64 64
65static const u16 VAUX3_table[] = { 65static const unsigned int VAUX3_table[] = {
66 1200, 1200, 1200, 1200, 1400, 1600, 1800, 2000, 66 1200000, 1200000, 1200000, 1200000, 1400000, 1600000, 1800000, 2000000,
67 2200, 2400, 2600, 2800, 3000, 3200, 3400, 3600, 67 2200000, 2400000, 2600000, 2800000, 3000000, 3200000, 3400000, 3600000,
68}; 68};
69 69
70static const u16 VAUX4_table[] = { 70static const unsigned int VAUX4_table[] = {
71 1800, 1800, 3000, 5000, 71 1800000, 1800000, 3000000, 5000000,
72}; 72};
73 73
74static const u16 VSIM_table[] = { 74static const unsigned int VSIM_table[] = {
75 1875, 3000, 75 1875000, 3000000,
76}; 76};
77 77
78static const u16 VSIM2_table[] = { 78static const unsigned int VSIM2_table[] = {
79 1875, 79 1875000,
80}; 80};
81 81
82static const u16 VVIB_table[] = { 82static const unsigned int VVIB_table[] = {
83 1300, 1800, 2000, 3000, 83 1300000, 1800000, 2000000, 3000000,
84}; 84};
85 85
86static const u16 SW1_table[] = { 86static const unsigned int SW1_table[] = {
87 900, 950, 1000, 1050, 1100, 1150, 1200, 1250, 87 900000, 950000, 1000000, 1050000, 1100000, 1150000, 1200000, 1250000,
88 1300, 1350, 1400, 1450, 1500, 1600, 1875, 2250, 88 1300000, 1350000, 1400000, 1450000, 1500000, 1600000, 1875000, 2250000,
89}; 89};
90 90
91#define SW2_table SW1_table 91#define SW2_table SW1_table
92 92
93static const u16 SW3_table[] = { 93static const unsigned int SW3_table[] = {
94 4000, 4500, 5000, 5500, 94 4000000, 4500000, 5000000, 5500000,
95}; 95};
96 96
97struct pcap_regulator { 97struct pcap_regulator {
@@ -100,8 +100,6 @@ struct pcap_regulator {
100 const u8 index; 100 const u8 index;
101 const u8 stby; 101 const u8 stby;
102 const u8 lowpwr; 102 const u8 lowpwr;
103 const u8 n_voltages;
104 const u16 *voltage_table;
105}; 103};
106 104
107#define NA 0xff 105#define NA 0xff
@@ -113,8 +111,6 @@ struct pcap_regulator {
113 .index = _index, \ 111 .index = _index, \
114 .stby = _stby, \ 112 .stby = _stby, \
115 .lowpwr = _lowpwr, \ 113 .lowpwr = _lowpwr, \
116 .n_voltages = ARRAY_SIZE(_vreg##_table), \
117 .voltage_table = _vreg##_table, \
118 } 114 }
119 115
120static struct pcap_regulator vreg_table[] = { 116static struct pcap_regulator vreg_table[] = {
@@ -157,11 +153,11 @@ static int pcap_regulator_set_voltage_sel(struct regulator_dev *rdev,
157 void *pcap = rdev_get_drvdata(rdev); 153 void *pcap = rdev_get_drvdata(rdev);
158 154
159 /* the regulator doesn't support voltage switching */ 155 /* the regulator doesn't support voltage switching */
160 if (vreg->n_voltages == 1) 156 if (rdev->desc->n_voltages == 1)
161 return -EINVAL; 157 return -EINVAL;
162 158
163 return ezx_pcap_set_bits(pcap, vreg->reg, 159 return ezx_pcap_set_bits(pcap, vreg->reg,
164 (vreg->n_voltages - 1) << vreg->index, 160 (rdev->desc->n_voltages - 1) << vreg->index,
165 selector << vreg->index); 161 selector << vreg->index);
166} 162}
167 163
@@ -171,11 +167,11 @@ static int pcap_regulator_get_voltage_sel(struct regulator_dev *rdev)
171 void *pcap = rdev_get_drvdata(rdev); 167 void *pcap = rdev_get_drvdata(rdev);
172 u32 tmp; 168 u32 tmp;
173 169
174 if (vreg->n_voltages == 1) 170 if (rdev->desc->n_voltages == 1)
175 return 0; 171 return 0;
176 172
177 ezx_pcap_read(pcap, vreg->reg, &tmp); 173 ezx_pcap_read(pcap, vreg->reg, &tmp);
178 tmp = ((tmp >> vreg->index) & (vreg->n_voltages - 1)); 174 tmp = ((tmp >> vreg->index) & (rdev->desc->n_voltages - 1));
179 return tmp; 175 return tmp;
180} 176}
181 177
@@ -214,16 +210,8 @@ static int pcap_regulator_is_enabled(struct regulator_dev *rdev)
214 return (tmp >> vreg->en) & 1; 210 return (tmp >> vreg->en) & 1;
215} 211}
216 212
217static int pcap_regulator_list_voltage(struct regulator_dev *rdev,
218 unsigned int index)
219{
220 struct pcap_regulator *vreg = &vreg_table[rdev_get_id(rdev)];
221
222 return vreg->voltage_table[index] * 1000;
223}
224
225static struct regulator_ops pcap_regulator_ops = { 213static struct regulator_ops pcap_regulator_ops = {
226 .list_voltage = pcap_regulator_list_voltage, 214 .list_voltage = regulator_list_voltage_table,
227 .set_voltage_sel = pcap_regulator_set_voltage_sel, 215 .set_voltage_sel = pcap_regulator_set_voltage_sel,
228 .get_voltage_sel = pcap_regulator_get_voltage_sel, 216 .get_voltage_sel = pcap_regulator_get_voltage_sel,
229 .enable = pcap_regulator_enable, 217 .enable = pcap_regulator_enable,
@@ -236,6 +224,7 @@ static struct regulator_ops pcap_regulator_ops = {
236 .name = #_vreg, \ 224 .name = #_vreg, \
237 .id = _vreg, \ 225 .id = _vreg, \
238 .n_voltages = ARRAY_SIZE(_vreg##_table), \ 226 .n_voltages = ARRAY_SIZE(_vreg##_table), \
227 .volt_table = _vreg##_table, \
239 .ops = &pcap_regulator_ops, \ 228 .ops = &pcap_regulator_ops, \
240 .type = REGULATOR_VOLTAGE, \ 229 .type = REGULATOR_VOLTAGE, \
241 .owner = THIS_MODULE, \ 230 .owner = THIS_MODULE, \
diff --git a/drivers/regulator/pcf50633-regulator.c b/drivers/regulator/pcf50633-regulator.c
index 3c9d14c0017b..092e5cb848a1 100644
--- a/drivers/regulator/pcf50633-regulator.c
+++ b/drivers/regulator/pcf50633-regulator.c
@@ -100,13 +100,12 @@ static unsigned int ldo_voltage_value(u8 bits)
100 return 900 + (bits * 100); 100 return 900 + (bits * 100);
101} 101}
102 102
103static int pcf50633_regulator_set_voltage(struct regulator_dev *rdev, 103static int pcf50633_regulator_map_voltage(struct regulator_dev *rdev,
104 int min_uV, int max_uV, 104 int min_uV, int max_uV)
105 unsigned *selector)
106{ 105{
107 struct pcf50633 *pcf; 106 struct pcf50633 *pcf;
108 int regulator_id, millivolts; 107 int regulator_id, millivolts;
109 u8 volt_bits, regnr; 108 u8 volt_bits;
110 109
111 pcf = rdev_get_drvdata(rdev); 110 pcf = rdev_get_drvdata(rdev);
112 111
@@ -116,15 +115,11 @@ static int pcf50633_regulator_set_voltage(struct regulator_dev *rdev,
116 115
117 millivolts = min_uV / 1000; 116 millivolts = min_uV / 1000;
118 117
119 regnr = rdev->desc->vsel_reg;
120
121 switch (regulator_id) { 118 switch (regulator_id) {
122 case PCF50633_REGULATOR_AUTO: 119 case PCF50633_REGULATOR_AUTO:
123 volt_bits = auto_voltage_bits(millivolts); 120 volt_bits = auto_voltage_bits(millivolts);
124 break; 121 break;
125 case PCF50633_REGULATOR_DOWN1: 122 case PCF50633_REGULATOR_DOWN1:
126 volt_bits = down_voltage_bits(millivolts);
127 break;
128 case PCF50633_REGULATOR_DOWN2: 123 case PCF50633_REGULATOR_DOWN2:
129 volt_bits = down_voltage_bits(millivolts); 124 volt_bits = down_voltage_bits(millivolts);
130 break; 125 break;
@@ -142,9 +137,7 @@ static int pcf50633_regulator_set_voltage(struct regulator_dev *rdev,
142 return -EINVAL; 137 return -EINVAL;
143 } 138 }
144 139
145 *selector = volt_bits; 140 return volt_bits;
146
147 return pcf50633_reg_write(pcf, regnr, volt_bits);
148} 141}
149 142
150static int pcf50633_regulator_list_voltage(struct regulator_dev *rdev, 143static int pcf50633_regulator_list_voltage(struct regulator_dev *rdev,
@@ -159,8 +152,6 @@ static int pcf50633_regulator_list_voltage(struct regulator_dev *rdev,
159 millivolts = auto_voltage_value(index); 152 millivolts = auto_voltage_value(index);
160 break; 153 break;
161 case PCF50633_REGULATOR_DOWN1: 154 case PCF50633_REGULATOR_DOWN1:
162 millivolts = down_voltage_value(index);
163 break;
164 case PCF50633_REGULATOR_DOWN2: 155 case PCF50633_REGULATOR_DOWN2:
165 millivolts = down_voltage_value(index); 156 millivolts = down_voltage_value(index);
166 break; 157 break;
@@ -182,9 +173,10 @@ static int pcf50633_regulator_list_voltage(struct regulator_dev *rdev,
182} 173}
183 174
184static struct regulator_ops pcf50633_regulator_ops = { 175static struct regulator_ops pcf50633_regulator_ops = {
185 .set_voltage = pcf50633_regulator_set_voltage, 176 .set_voltage_sel = regulator_set_voltage_sel_regmap,
186 .get_voltage_sel = regulator_get_voltage_sel_regmap, 177 .get_voltage_sel = regulator_get_voltage_sel_regmap,
187 .list_voltage = pcf50633_regulator_list_voltage, 178 .list_voltage = pcf50633_regulator_list_voltage,
179 .map_voltage = pcf50633_regulator_map_voltage,
188 .enable = regulator_enable_regmap, 180 .enable = regulator_enable_regmap,
189 .disable = regulator_disable_regmap, 181 .disable = regulator_disable_regmap,
190 .is_enabled = regulator_is_enabled_regmap, 182 .is_enabled = regulator_is_enabled_regmap,
diff --git a/drivers/regulator/rc5t583-regulator.c b/drivers/regulator/rc5t583-regulator.c
index 1d34e64a1307..8bf4e8c9de9a 100644
--- a/drivers/regulator/rc5t583-regulator.c
+++ b/drivers/regulator/rc5t583-regulator.c
@@ -42,7 +42,6 @@ struct rc5t583_regulator_info {
42 42
43 /* Regulator specific turn-on delay and voltage settling time*/ 43 /* Regulator specific turn-on delay and voltage settling time*/
44 int enable_uv_per_us; 44 int enable_uv_per_us;
45 int change_uv_per_us;
46 45
47 /* Used by regulator core */ 46 /* Used by regulator core */
48 struct regulator_desc desc; 47 struct regulator_desc desc;
@@ -66,25 +65,6 @@ static int rc5t583_regulator_enable_time(struct regulator_dev *rdev)
66 return DIV_ROUND_UP(curr_uV, reg->reg_info->enable_uv_per_us); 65 return DIV_ROUND_UP(curr_uV, reg->reg_info->enable_uv_per_us);
67} 66}
68 67
69static int rc5t583_set_voltage_time_sel(struct regulator_dev *rdev,
70 unsigned int old_selector, unsigned int new_selector)
71{
72 struct rc5t583_regulator *reg = rdev_get_drvdata(rdev);
73 int old_uV, new_uV;
74 old_uV = regulator_list_voltage_linear(rdev, old_selector);
75
76 if (old_uV < 0)
77 return old_uV;
78
79 new_uV = regulator_list_voltage_linear(rdev, new_selector);
80 if (new_uV < 0)
81 return new_uV;
82
83 return DIV_ROUND_UP(abs(old_uV - new_uV),
84 reg->reg_info->change_uv_per_us);
85}
86
87
88static struct regulator_ops rc5t583_ops = { 68static struct regulator_ops rc5t583_ops = {
89 .is_enabled = regulator_is_enabled_regmap, 69 .is_enabled = regulator_is_enabled_regmap,
90 .enable = regulator_enable_regmap, 70 .enable = regulator_enable_regmap,
@@ -94,7 +74,7 @@ static struct regulator_ops rc5t583_ops = {
94 .set_voltage_sel = regulator_set_voltage_sel_regmap, 74 .set_voltage_sel = regulator_set_voltage_sel_regmap,
95 .list_voltage = regulator_list_voltage_linear, 75 .list_voltage = regulator_list_voltage_linear,
96 .map_voltage = regulator_map_voltage_linear, 76 .map_voltage = regulator_map_voltage_linear,
97 .set_voltage_time_sel = rc5t583_set_voltage_time_sel, 77 .set_voltage_time_sel = regulator_set_voltage_time_sel,
98}; 78};
99 79
100#define RC5T583_REG(_id, _en_reg, _en_bit, _disc_reg, _disc_bit, \ 80#define RC5T583_REG(_id, _en_reg, _en_bit, _disc_reg, _disc_bit, \
@@ -104,7 +84,6 @@ static struct regulator_ops rc5t583_ops = {
104 .disc_bit = _disc_bit, \ 84 .disc_bit = _disc_bit, \
105 .deepsleep_reg = RC5T583_REG_##_id##DAC_DS, \ 85 .deepsleep_reg = RC5T583_REG_##_id##DAC_DS, \
106 .enable_uv_per_us = _enable_mv * 1000, \ 86 .enable_uv_per_us = _enable_mv * 1000, \
107 .change_uv_per_us = 40 * 1000, \
108 .deepsleep_id = RC5T583_DS_##_id, \ 87 .deepsleep_id = RC5T583_DS_##_id, \
109 .desc = { \ 88 .desc = { \
110 .name = "rc5t583-regulator-"#_id, \ 89 .name = "rc5t583-regulator-"#_id, \
@@ -119,6 +98,7 @@ static struct regulator_ops rc5t583_ops = {
119 .enable_mask = BIT(_en_bit), \ 98 .enable_mask = BIT(_en_bit), \
120 .min_uV = _min_mv * 1000, \ 99 .min_uV = _min_mv * 1000, \
121 .uV_step = _step_uV, \ 100 .uV_step = _step_uV, \
101 .ramp_delay = 40 * 1000, \
122 }, \ 102 }, \
123} 103}
124 104
diff --git a/drivers/regulator/s2mps11.c b/drivers/regulator/s2mps11.c
new file mode 100644
index 000000000000..4669dc9ac74a
--- /dev/null
+++ b/drivers/regulator/s2mps11.c
@@ -0,0 +1,363 @@
1/*
2 * s2mps11.c
3 *
4 * Copyright (c) 2012 Samsung Electronics Co., Ltd
5 * http://www.samsung.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
14#include <linux/bug.h>
15#include <linux/delay.h>
16#include <linux/err.h>
17#include <linux/gpio.h>
18#include <linux/slab.h>
19#include <linux/module.h>
20#include <linux/platform_device.h>
21#include <linux/regulator/driver.h>
22#include <linux/regulator/machine.h>
23#include <linux/mfd/samsung/core.h>
24#include <linux/mfd/samsung/s2mps11.h>
25
26struct s2mps11_info {
27 struct regulator_dev **rdev;
28
29 int ramp_delay2;
30 int ramp_delay34;
31 int ramp_delay5;
32 int ramp_delay16;
33 int ramp_delay7810;
34 int ramp_delay9;
35
36 bool buck6_ramp;
37 bool buck2_ramp;
38 bool buck3_ramp;
39 bool buck4_ramp;
40};
41
42static int get_ramp_delay(int ramp_delay)
43{
44 unsigned char cnt = 0;
45
46 ramp_delay /= 6;
47
48 while (true) {
49 ramp_delay = ramp_delay >> 1;
50 if (ramp_delay == 0)
51 break;
52 cnt++;
53 }
54 return cnt;
55}
56
57static struct regulator_ops s2mps11_ldo_ops = {
58 .list_voltage = regulator_list_voltage_linear,
59 .map_voltage = regulator_map_voltage_linear,
60 .is_enabled = regulator_is_enabled_regmap,
61 .enable = regulator_enable_regmap,
62 .disable = regulator_disable_regmap,
63 .get_voltage_sel = regulator_get_voltage_sel_regmap,
64 .set_voltage_sel = regulator_set_voltage_sel_regmap,
65 .set_voltage_time_sel = regulator_set_voltage_time_sel,
66};
67
68static struct regulator_ops s2mps11_buck_ops = {
69 .list_voltage = regulator_list_voltage_linear,
70 .map_voltage = regulator_map_voltage_linear,
71 .is_enabled = regulator_is_enabled_regmap,
72 .enable = regulator_enable_regmap,
73 .disable = regulator_disable_regmap,
74 .get_voltage_sel = regulator_get_voltage_sel_regmap,
75 .set_voltage_sel = regulator_set_voltage_sel_regmap,
76 .set_voltage_time_sel = regulator_set_voltage_time_sel,
77};
78
79#define regulator_desc_ldo1(num) { \
80 .name = "LDO"#num, \
81 .id = S2MPS11_LDO##num, \
82 .ops = &s2mps11_ldo_ops, \
83 .type = REGULATOR_VOLTAGE, \
84 .owner = THIS_MODULE, \
85 .min_uV = S2MPS11_LDO_MIN, \
86 .uV_step = S2MPS11_LDO_STEP1, \
87 .n_voltages = S2MPS11_LDO_N_VOLTAGES, \
88 .vsel_reg = S2MPS11_REG_L1CTRL + num - 1, \
89 .vsel_mask = S2MPS11_LDO_VSEL_MASK, \
90 .enable_reg = S2MPS11_REG_L1CTRL + num - 1, \
91 .enable_mask = S2MPS11_ENABLE_MASK \
92}
93#define regulator_desc_ldo2(num) { \
94 .name = "LDO"#num, \
95 .id = S2MPS11_LDO##num, \
96 .ops = &s2mps11_ldo_ops, \
97 .type = REGULATOR_VOLTAGE, \
98 .owner = THIS_MODULE, \
99 .min_uV = S2MPS11_LDO_MIN, \
100 .uV_step = S2MPS11_LDO_STEP2, \
101 .n_voltages = S2MPS11_LDO_N_VOLTAGES, \
102 .vsel_reg = S2MPS11_REG_L1CTRL + num - 1, \
103 .vsel_mask = S2MPS11_LDO_VSEL_MASK, \
104 .enable_reg = S2MPS11_REG_L1CTRL + num - 1, \
105 .enable_mask = S2MPS11_ENABLE_MASK \
106}
107
108#define regulator_desc_buck1_4(num) { \
109 .name = "BUCK"#num, \
110 .id = S2MPS11_BUCK##num, \
111 .ops = &s2mps11_buck_ops, \
112 .type = REGULATOR_VOLTAGE, \
113 .owner = THIS_MODULE, \
114 .min_uV = S2MPS11_BUCK_MIN1, \
115 .uV_step = S2MPS11_BUCK_STEP1, \
116 .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \
117 .vsel_reg = S2MPS11_REG_B1CTRL2 + (num - 1) * 2, \
118 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
119 .enable_reg = S2MPS11_REG_B1CTRL1 + (num - 1) * 2, \
120 .enable_mask = S2MPS11_ENABLE_MASK \
121}
122
123#define regulator_desc_buck5 { \
124 .name = "BUCK5", \
125 .id = S2MPS11_BUCK5, \
126 .ops = &s2mps11_buck_ops, \
127 .type = REGULATOR_VOLTAGE, \
128 .owner = THIS_MODULE, \
129 .min_uV = S2MPS11_BUCK_MIN1, \
130 .uV_step = S2MPS11_BUCK_STEP1, \
131 .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \
132 .vsel_reg = S2MPS11_REG_B5CTRL2, \
133 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
134 .enable_reg = S2MPS11_REG_B5CTRL1, \
135 .enable_mask = S2MPS11_ENABLE_MASK \
136}
137
138#define regulator_desc_buck6_8(num) { \
139 .name = "BUCK"#num, \
140 .id = S2MPS11_BUCK##num, \
141 .ops = &s2mps11_buck_ops, \
142 .type = REGULATOR_VOLTAGE, \
143 .owner = THIS_MODULE, \
144 .min_uV = S2MPS11_BUCK_MIN1, \
145 .uV_step = S2MPS11_BUCK_STEP1, \
146 .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \
147 .vsel_reg = S2MPS11_REG_B6CTRL2 + (num - 6) * 2, \
148 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
149 .enable_reg = S2MPS11_REG_B6CTRL1 + (num - 6) * 2, \
150 .enable_mask = S2MPS11_ENABLE_MASK \
151}
152
153#define regulator_desc_buck9 { \
154 .name = "BUCK9", \
155 .id = S2MPS11_BUCK9, \
156 .ops = &s2mps11_buck_ops, \
157 .type = REGULATOR_VOLTAGE, \
158 .owner = THIS_MODULE, \
159 .min_uV = S2MPS11_BUCK_MIN3, \
160 .uV_step = S2MPS11_BUCK_STEP3, \
161 .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \
162 .vsel_reg = S2MPS11_REG_B9CTRL2, \
163 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
164 .enable_reg = S2MPS11_REG_B9CTRL1, \
165 .enable_mask = S2MPS11_ENABLE_MASK \
166}
167
168#define regulator_desc_buck10 { \
169 .name = "BUCK10", \
170 .id = S2MPS11_BUCK10, \
171 .ops = &s2mps11_buck_ops, \
172 .type = REGULATOR_VOLTAGE, \
173 .owner = THIS_MODULE, \
174 .min_uV = S2MPS11_BUCK_MIN2, \
175 .uV_step = S2MPS11_BUCK_STEP2, \
176 .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \
177 .vsel_reg = S2MPS11_REG_B9CTRL2, \
178 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
179 .enable_reg = S2MPS11_REG_B9CTRL1, \
180 .enable_mask = S2MPS11_ENABLE_MASK \
181}
182
183static struct regulator_desc regulators[] = {
184 regulator_desc_ldo2(1),
185 regulator_desc_ldo1(2),
186 regulator_desc_ldo1(3),
187 regulator_desc_ldo1(4),
188 regulator_desc_ldo1(5),
189 regulator_desc_ldo2(6),
190 regulator_desc_ldo1(7),
191 regulator_desc_ldo1(8),
192 regulator_desc_ldo1(9),
193 regulator_desc_ldo1(10),
194 regulator_desc_ldo2(11),
195 regulator_desc_ldo1(12),
196 regulator_desc_ldo1(13),
197 regulator_desc_ldo1(14),
198 regulator_desc_ldo1(15),
199 regulator_desc_ldo1(16),
200 regulator_desc_ldo1(17),
201 regulator_desc_ldo1(18),
202 regulator_desc_ldo1(19),
203 regulator_desc_ldo1(20),
204 regulator_desc_ldo1(21),
205 regulator_desc_ldo2(22),
206 regulator_desc_ldo2(23),
207 regulator_desc_ldo1(24),
208 regulator_desc_ldo1(25),
209 regulator_desc_ldo1(26),
210 regulator_desc_ldo2(27),
211 regulator_desc_ldo1(28),
212 regulator_desc_ldo1(29),
213 regulator_desc_ldo1(30),
214 regulator_desc_ldo1(31),
215 regulator_desc_ldo1(32),
216 regulator_desc_ldo1(33),
217 regulator_desc_ldo1(34),
218 regulator_desc_ldo1(35),
219 regulator_desc_ldo1(36),
220 regulator_desc_ldo1(37),
221 regulator_desc_ldo1(38),
222 regulator_desc_buck1_4(1),
223 regulator_desc_buck1_4(2),
224 regulator_desc_buck1_4(3),
225 regulator_desc_buck1_4(4),
226 regulator_desc_buck5,
227 regulator_desc_buck6_8(6),
228 regulator_desc_buck6_8(7),
229 regulator_desc_buck6_8(8),
230 regulator_desc_buck9,
231 regulator_desc_buck10,
232};
233
234static __devinit int s2mps11_pmic_probe(struct platform_device *pdev)
235{
236 struct sec_pmic_dev *iodev = dev_get_drvdata(pdev->dev.parent);
237 struct sec_platform_data *pdata = dev_get_platdata(iodev->dev);
238 struct regulator_config config = { };
239 struct regulator_dev **rdev;
240 struct s2mps11_info *s2mps11;
241 int i, ret, size;
242 unsigned char ramp_enable, ramp_reg = 0;
243
244 if (!pdata) {
245 dev_err(pdev->dev.parent, "Platform data not supplied\n");
246 return -ENODEV;
247 }
248
249 s2mps11 = devm_kzalloc(&pdev->dev, sizeof(struct s2mps11_info),
250 GFP_KERNEL);
251 if (!s2mps11)
252 return -ENOMEM;
253
254 size = sizeof(struct regulator_dev *) * S2MPS11_REGULATOR_MAX;
255 s2mps11->rdev = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
256 if (!s2mps11->rdev) {
257 return -ENOMEM;
258 }
259
260 rdev = s2mps11->rdev;
261 platform_set_drvdata(pdev, s2mps11);
262
263 s2mps11->ramp_delay2 = pdata->buck2_ramp_delay;
264 s2mps11->ramp_delay34 = pdata->buck34_ramp_delay;
265 s2mps11->ramp_delay5 = pdata->buck5_ramp_delay;
266 s2mps11->ramp_delay16 = pdata->buck16_ramp_delay;
267 s2mps11->ramp_delay7810 = pdata->buck7810_ramp_delay;
268 s2mps11->ramp_delay9 = pdata->buck9_ramp_delay;
269
270 s2mps11->buck6_ramp = pdata->buck6_ramp_enable;
271 s2mps11->buck2_ramp = pdata->buck2_ramp_enable;
272 s2mps11->buck3_ramp = pdata->buck3_ramp_enable;
273 s2mps11->buck4_ramp = pdata->buck4_ramp_enable;
274
275 ramp_enable = (s2mps11->buck2_ramp << 3) | (s2mps11->buck3_ramp << 2) |
276 (s2mps11->buck4_ramp << 1) | s2mps11->buck6_ramp ;
277
278 if (ramp_enable) {
279 if (s2mps11->buck2_ramp)
280 ramp_reg |= get_ramp_delay(s2mps11->ramp_delay2) >> 6;
281 if (s2mps11->buck3_ramp || s2mps11->buck4_ramp)
282 ramp_reg |= get_ramp_delay(s2mps11->ramp_delay34) >> 4;
283 sec_reg_write(iodev, S2MPS11_REG_RAMP, ramp_reg | ramp_enable);
284 }
285
286 ramp_reg &= 0x00;
287 ramp_reg |= get_ramp_delay(s2mps11->ramp_delay5) >> 6;
288 ramp_reg |= get_ramp_delay(s2mps11->ramp_delay16) >> 4;
289 ramp_reg |= get_ramp_delay(s2mps11->ramp_delay7810) >> 2;
290 ramp_reg |= get_ramp_delay(s2mps11->ramp_delay9);
291 sec_reg_write(iodev, S2MPS11_REG_RAMP_BUCK, ramp_reg);
292
293 for (i = 0; i < S2MPS11_REGULATOR_MAX; i++) {
294
295 config.dev = &pdev->dev;
296 config.regmap = iodev->regmap;
297 config.init_data = pdata->regulators[i].initdata;
298 config.driver_data = s2mps11;
299
300 rdev[i] = regulator_register(&regulators[i], &config);
301 if (IS_ERR(rdev[i])) {
302 ret = PTR_ERR(rdev[i]);
303 dev_err(&pdev->dev, "regulator init failed for %d\n",
304 i);
305 rdev[i] = NULL;
306 goto err;
307 }
308 }
309
310 return 0;
311err:
312 for (i = 0; i < S2MPS11_REGULATOR_MAX; i++)
313 if (rdev[i])
314 regulator_unregister(rdev[i]);
315
316 return ret;
317}
318
319static int __devexit s2mps11_pmic_remove(struct platform_device *pdev)
320{
321 struct s2mps11_info *s2mps11 = platform_get_drvdata(pdev);
322 struct regulator_dev **rdev = s2mps11->rdev;
323 int i;
324
325 for (i = 0; i < S2MPS11_REGULATOR_MAX; i++)
326 if (rdev[i])
327 regulator_unregister(rdev[i]);
328
329 return 0;
330}
331
332static const struct platform_device_id s2mps11_pmic_id[] = {
333 { "s2mps11-pmic", 0},
334 { },
335};
336MODULE_DEVICE_TABLE(platform, s2mps11_pmic_id);
337
338static struct platform_driver s2mps11_pmic_driver = {
339 .driver = {
340 .name = "s2mps11-pmic",
341 .owner = THIS_MODULE,
342 },
343 .probe = s2mps11_pmic_probe,
344 .remove = __devexit_p(s2mps11_pmic_remove),
345 .id_table = s2mps11_pmic_id,
346};
347
348static int __init s2mps11_pmic_init(void)
349{
350 return platform_driver_register(&s2mps11_pmic_driver);
351}
352subsys_initcall(s2mps11_pmic_init);
353
354static void __exit s2mps11_pmic_exit(void)
355{
356 platform_driver_unregister(&s2mps11_pmic_driver);
357}
358module_exit(s2mps11_pmic_exit);
359
360/* Module information */
361MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>");
362MODULE_DESCRIPTION("SAMSUNG S2MPS11 Regulator Driver");
363MODULE_LICENSE("GPL");
diff --git a/drivers/regulator/s5m8767.c b/drivers/regulator/s5m8767.c
index 9caadb482178..102287fa7ecb 100644
--- a/drivers/regulator/s5m8767.c
+++ b/drivers/regulator/s5m8767.c
@@ -41,6 +41,7 @@ struct s5m8767_info {
41 u8 buck3_vol[8]; 41 u8 buck3_vol[8];
42 u8 buck4_vol[8]; 42 u8 buck4_vol[8];
43 int buck_gpios[3]; 43 int buck_gpios[3];
44 int buck_ds[3];
44 int buck_gpioindex; 45 int buck_gpioindex;
45}; 46};
46 47
@@ -120,27 +121,6 @@ static const struct s5m_voltage_desc *reg_voltage_map[] = {
120 [S5M8767_BUCK9] = &buck_voltage_val3, 121 [S5M8767_BUCK9] = &buck_voltage_val3,
121}; 122};
122 123
123static int s5m8767_list_voltage(struct regulator_dev *rdev,
124 unsigned int selector)
125{
126 const struct s5m_voltage_desc *desc;
127 int reg_id = rdev_get_id(rdev);
128 int val;
129
130 if (reg_id >= ARRAY_SIZE(reg_voltage_map) || reg_id < 0)
131 return -EINVAL;
132
133 desc = reg_voltage_map[reg_id];
134 if (desc == NULL)
135 return -EINVAL;
136
137 val = desc->min + desc->step * selector;
138 if (val > desc->max)
139 return -EINVAL;
140
141 return val;
142}
143
144static unsigned int s5m8767_opmode_reg[][4] = { 124static unsigned int s5m8767_opmode_reg[][4] = {
145 /* {OFF, ON, LOWPOWER, SUSPEND} */ 125 /* {OFF, ON, LOWPOWER, SUSPEND} */
146 /* LDO1 ... LDO28 */ 126 /* LDO1 ... LDO28 */
@@ -283,17 +263,17 @@ static int s5m8767_get_voltage_register(struct regulator_dev *rdev, int *_reg)
283 reg = S5M8767_REG_BUCK1CTRL2; 263 reg = S5M8767_REG_BUCK1CTRL2;
284 break; 264 break;
285 case S5M8767_BUCK2: 265 case S5M8767_BUCK2:
286 reg = S5M8767_REG_BUCK2DVS1; 266 reg = S5M8767_REG_BUCK2DVS2;
287 if (s5m8767->buck2_gpiodvs) 267 if (s5m8767->buck2_gpiodvs)
288 reg += s5m8767->buck_gpioindex; 268 reg += s5m8767->buck_gpioindex;
289 break; 269 break;
290 case S5M8767_BUCK3: 270 case S5M8767_BUCK3:
291 reg = S5M8767_REG_BUCK3DVS1; 271 reg = S5M8767_REG_BUCK3DVS2;
292 if (s5m8767->buck3_gpiodvs) 272 if (s5m8767->buck3_gpiodvs)
293 reg += s5m8767->buck_gpioindex; 273 reg += s5m8767->buck_gpioindex;
294 break; 274 break;
295 case S5M8767_BUCK4: 275 case S5M8767_BUCK4:
296 reg = S5M8767_REG_BUCK4DVS1; 276 reg = S5M8767_REG_BUCK4DVS2;
297 if (s5m8767->buck4_gpiodvs) 277 if (s5m8767->buck4_gpiodvs)
298 reg += s5m8767->buck_gpioindex; 278 reg += s5m8767->buck_gpioindex;
299 break; 279 break;
@@ -357,32 +337,34 @@ static int s5m8767_convert_voltage_to_sel(
357 return selector; 337 return selector;
358} 338}
359 339
360static inline void s5m8767_set_high(struct s5m8767_info *s5m8767) 340static inline int s5m8767_set_high(struct s5m8767_info *s5m8767)
361{ 341{
362 int temp_index = s5m8767->buck_gpioindex; 342 int temp_index = s5m8767->buck_gpioindex;
363 343
364 gpio_set_value(s5m8767->buck_gpios[0], (temp_index >> 2) & 0x1); 344 gpio_set_value(s5m8767->buck_gpios[0], (temp_index >> 2) & 0x1);
365 gpio_set_value(s5m8767->buck_gpios[1], (temp_index >> 1) & 0x1); 345 gpio_set_value(s5m8767->buck_gpios[1], (temp_index >> 1) & 0x1);
366 gpio_set_value(s5m8767->buck_gpios[2], temp_index & 0x1); 346 gpio_set_value(s5m8767->buck_gpios[2], temp_index & 0x1);
347
348 return 0;
367} 349}
368 350
369static inline void s5m8767_set_low(struct s5m8767_info *s5m8767) 351static inline int s5m8767_set_low(struct s5m8767_info *s5m8767)
370{ 352{
371 int temp_index = s5m8767->buck_gpioindex; 353 int temp_index = s5m8767->buck_gpioindex;
372 354
373 gpio_set_value(s5m8767->buck_gpios[2], temp_index & 0x1); 355 gpio_set_value(s5m8767->buck_gpios[2], temp_index & 0x1);
374 gpio_set_value(s5m8767->buck_gpios[1], (temp_index >> 1) & 0x1); 356 gpio_set_value(s5m8767->buck_gpios[1], (temp_index >> 1) & 0x1);
375 gpio_set_value(s5m8767->buck_gpios[0], (temp_index >> 2) & 0x1); 357 gpio_set_value(s5m8767->buck_gpios[0], (temp_index >> 2) & 0x1);
358
359 return 0;
376} 360}
377 361
378static int s5m8767_set_voltage(struct regulator_dev *rdev, 362static int s5m8767_set_voltage_sel(struct regulator_dev *rdev,
379 int min_uV, int max_uV, unsigned *selector) 363 unsigned selector)
380{ 364{
381 struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); 365 struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev);
382 const struct s5m_voltage_desc *desc;
383 int reg_id = rdev_get_id(rdev); 366 int reg_id = rdev_get_id(rdev);
384 int sel, reg, mask, ret = 0, old_index, index = 0; 367 int reg, mask, ret = 0, old_index, index = 0;
385 u8 val;
386 u8 *buck234_vol = NULL; 368 u8 *buck234_vol = NULL;
387 369
388 switch (reg_id) { 370 switch (reg_id) {
@@ -407,15 +389,9 @@ static int s5m8767_set_voltage(struct regulator_dev *rdev,
407 return -EINVAL; 389 return -EINVAL;
408 } 390 }
409 391
410 desc = reg_voltage_map[reg_id];
411
412 sel = s5m8767_convert_voltage_to_sel(desc, min_uV, max_uV);
413 if (sel < 0)
414 return sel;
415
416 /* buck234_vol != NULL means to control buck234 voltage via DVS GPIO */ 392 /* buck234_vol != NULL means to control buck234 voltage via DVS GPIO */
417 if (buck234_vol) { 393 if (buck234_vol) {
418 while (*buck234_vol != sel) { 394 while (*buck234_vol != selector) {
419 buck234_vol++; 395 buck234_vol++;
420 index++; 396 index++;
421 } 397 }
@@ -423,22 +399,16 @@ static int s5m8767_set_voltage(struct regulator_dev *rdev,
423 s5m8767->buck_gpioindex = index; 399 s5m8767->buck_gpioindex = index;
424 400
425 if (index > old_index) 401 if (index > old_index)
426 s5m8767_set_high(s5m8767); 402 return s5m8767_set_high(s5m8767);
427 else 403 else
428 s5m8767_set_low(s5m8767); 404 return s5m8767_set_low(s5m8767);
429 } else { 405 } else {
430 ret = s5m8767_get_voltage_register(rdev, &reg); 406 ret = s5m8767_get_voltage_register(rdev, &reg);
431 if (ret) 407 if (ret)
432 return ret; 408 return ret;
433 409
434 s5m_reg_read(s5m8767->iodev, reg, &val); 410 return s5m_reg_update(s5m8767->iodev, reg, selector, mask);
435 val = (val & ~mask) | sel;
436
437 ret = s5m_reg_write(s5m8767->iodev, reg, val);
438 } 411 }
439
440 *selector = sel;
441 return ret;
442} 412}
443 413
444static int s5m8767_set_voltage_time_sel(struct regulator_dev *rdev, 414static int s5m8767_set_voltage_time_sel(struct regulator_dev *rdev,
@@ -458,15 +428,21 @@ static int s5m8767_set_voltage_time_sel(struct regulator_dev *rdev,
458} 428}
459 429
460static struct regulator_ops s5m8767_ops = { 430static struct regulator_ops s5m8767_ops = {
461 .list_voltage = s5m8767_list_voltage, 431 .list_voltage = regulator_list_voltage_linear,
462 .is_enabled = s5m8767_reg_is_enabled, 432 .is_enabled = s5m8767_reg_is_enabled,
463 .enable = s5m8767_reg_enable, 433 .enable = s5m8767_reg_enable,
464 .disable = s5m8767_reg_disable, 434 .disable = s5m8767_reg_disable,
465 .get_voltage_sel = s5m8767_get_voltage_sel, 435 .get_voltage_sel = s5m8767_get_voltage_sel,
466 .set_voltage = s5m8767_set_voltage, 436 .set_voltage_sel = s5m8767_set_voltage_sel,
467 .set_voltage_time_sel = s5m8767_set_voltage_time_sel, 437 .set_voltage_time_sel = s5m8767_set_voltage_time_sel,
468}; 438};
469 439
440static struct regulator_ops s5m8767_buck78_ops = {
441 .is_enabled = s5m8767_reg_is_enabled,
442 .enable = s5m8767_reg_enable,
443 .disable = s5m8767_reg_disable,
444};
445
470#define s5m8767_regulator_desc(_name) { \ 446#define s5m8767_regulator_desc(_name) { \
471 .name = #_name, \ 447 .name = #_name, \
472 .id = S5M8767_##_name, \ 448 .id = S5M8767_##_name, \
@@ -475,6 +451,14 @@ static struct regulator_ops s5m8767_ops = {
475 .owner = THIS_MODULE, \ 451 .owner = THIS_MODULE, \
476} 452}
477 453
454#define s5m8767_regulator_buck78_desc(_name) { \
455 .name = #_name, \
456 .id = S5M8767_##_name, \
457 .ops = &s5m8767_buck78_ops, \
458 .type = REGULATOR_VOLTAGE, \
459 .owner = THIS_MODULE, \
460}
461
478static struct regulator_desc regulators[] = { 462static struct regulator_desc regulators[] = {
479 s5m8767_regulator_desc(LDO1), 463 s5m8767_regulator_desc(LDO1),
480 s5m8767_regulator_desc(LDO2), 464 s5m8767_regulator_desc(LDO2),
@@ -510,8 +494,8 @@ static struct regulator_desc regulators[] = {
510 s5m8767_regulator_desc(BUCK4), 494 s5m8767_regulator_desc(BUCK4),
511 s5m8767_regulator_desc(BUCK5), 495 s5m8767_regulator_desc(BUCK5),
512 s5m8767_regulator_desc(BUCK6), 496 s5m8767_regulator_desc(BUCK6),
513 s5m8767_regulator_desc(BUCK7), 497 s5m8767_regulator_buck78_desc(BUCK7),
514 s5m8767_regulator_desc(BUCK8), 498 s5m8767_regulator_buck78_desc(BUCK8),
515 s5m8767_regulator_desc(BUCK9), 499 s5m8767_regulator_desc(BUCK9),
516}; 500};
517 501
@@ -522,7 +506,7 @@ static __devinit int s5m8767_pmic_probe(struct platform_device *pdev)
522 struct regulator_config config = { }; 506 struct regulator_config config = { };
523 struct regulator_dev **rdev; 507 struct regulator_dev **rdev;
524 struct s5m8767_info *s5m8767; 508 struct s5m8767_info *s5m8767;
525 int i, ret, size; 509 int i, ret, size, buck_init;
526 510
527 if (!pdata) { 511 if (!pdata) {
528 dev_err(pdev->dev.parent, "Platform data not supplied\n"); 512 dev_err(pdev->dev.parent, "Platform data not supplied\n");
@@ -573,12 +557,37 @@ static __devinit int s5m8767_pmic_probe(struct platform_device *pdev)
573 s5m8767->buck_gpios[0] = pdata->buck_gpios[0]; 557 s5m8767->buck_gpios[0] = pdata->buck_gpios[0];
574 s5m8767->buck_gpios[1] = pdata->buck_gpios[1]; 558 s5m8767->buck_gpios[1] = pdata->buck_gpios[1];
575 s5m8767->buck_gpios[2] = pdata->buck_gpios[2]; 559 s5m8767->buck_gpios[2] = pdata->buck_gpios[2];
560 s5m8767->buck_ds[0] = pdata->buck_ds[0];
561 s5m8767->buck_ds[1] = pdata->buck_ds[1];
562 s5m8767->buck_ds[2] = pdata->buck_ds[2];
563
576 s5m8767->ramp_delay = pdata->buck_ramp_delay; 564 s5m8767->ramp_delay = pdata->buck_ramp_delay;
577 s5m8767->buck2_ramp = pdata->buck2_ramp_enable; 565 s5m8767->buck2_ramp = pdata->buck2_ramp_enable;
578 s5m8767->buck3_ramp = pdata->buck3_ramp_enable; 566 s5m8767->buck3_ramp = pdata->buck3_ramp_enable;
579 s5m8767->buck4_ramp = pdata->buck4_ramp_enable; 567 s5m8767->buck4_ramp = pdata->buck4_ramp_enable;
580 s5m8767->opmode = pdata->opmode; 568 s5m8767->opmode = pdata->opmode;
581 569
570 buck_init = s5m8767_convert_voltage_to_sel(&buck_voltage_val2,
571 pdata->buck2_init,
572 pdata->buck2_init +
573 buck_voltage_val2.step);
574
575 s5m_reg_write(s5m8767->iodev, S5M8767_REG_BUCK2DVS2, buck_init);
576
577 buck_init = s5m8767_convert_voltage_to_sel(&buck_voltage_val2,
578 pdata->buck3_init,
579 pdata->buck3_init +
580 buck_voltage_val2.step);
581
582 s5m_reg_write(s5m8767->iodev, S5M8767_REG_BUCK3DVS2, buck_init);
583
584 buck_init = s5m8767_convert_voltage_to_sel(&buck_voltage_val2,
585 pdata->buck4_init,
586 pdata->buck4_init +
587 buck_voltage_val2.step);
588
589 s5m_reg_write(s5m8767->iodev, S5M8767_REG_BUCK4DVS2, buck_init);
590
582 for (i = 0; i < 8; i++) { 591 for (i = 0; i < 8; i++) {
583 if (s5m8767->buck2_gpiodvs) { 592 if (s5m8767->buck2_gpiodvs) {
584 s5m8767->buck2_vol[i] = 593 s5m8767->buck2_vol[i] =
@@ -608,48 +617,70 @@ static __devinit int s5m8767_pmic_probe(struct platform_device *pdev)
608 } 617 }
609 } 618 }
610 619
611 if (pdata->buck2_gpiodvs || pdata->buck3_gpiodvs || 620 if (gpio_is_valid(pdata->buck_gpios[0]) &&
612 pdata->buck4_gpiodvs) { 621 gpio_is_valid(pdata->buck_gpios[1]) &&
613 if (gpio_is_valid(pdata->buck_gpios[0]) && 622 gpio_is_valid(pdata->buck_gpios[2])) {
614 gpio_is_valid(pdata->buck_gpios[1]) && 623 ret = devm_gpio_request(&pdev->dev, pdata->buck_gpios[0],
615 gpio_is_valid(pdata->buck_gpios[2])) { 624 "S5M8767 SET1");
616 ret = gpio_request(pdata->buck_gpios[0], 625 if (ret)
617 "S5M8767 SET1");
618 if (ret == -EBUSY)
619 dev_warn(&pdev->dev, "Duplicated gpio request for SET1\n");
620
621 ret = gpio_request(pdata->buck_gpios[1],
622 "S5M8767 SET2");
623 if (ret == -EBUSY)
624 dev_warn(&pdev->dev, "Duplicated gpio request for SET2\n");
625
626 ret = gpio_request(pdata->buck_gpios[2],
627 "S5M8767 SET3");
628 if (ret == -EBUSY)
629 dev_warn(&pdev->dev, "Duplicated gpio request for SET3\n");
630 /* SET1 GPIO */
631 gpio_direction_output(pdata->buck_gpios[0],
632 (s5m8767->buck_gpioindex >> 2) & 0x1);
633 /* SET2 GPIO */
634 gpio_direction_output(pdata->buck_gpios[1],
635 (s5m8767->buck_gpioindex >> 1) & 0x1);
636 /* SET3 GPIO */
637 gpio_direction_output(pdata->buck_gpios[2],
638 (s5m8767->buck_gpioindex >> 0) & 0x1);
639 ret = 0;
640 } else {
641 dev_err(&pdev->dev, "GPIO NOT VALID\n");
642 ret = -EINVAL;
643 return ret; 626 return ret;
644 } 627
628 ret = devm_gpio_request(&pdev->dev, pdata->buck_gpios[1],
629 "S5M8767 SET2");
630 if (ret)
631 return ret;
632
633 ret = devm_gpio_request(&pdev->dev, pdata->buck_gpios[2],
634 "S5M8767 SET3");
635 if (ret)
636 return ret;
637
638 /* SET1 GPIO */
639 gpio_direction_output(pdata->buck_gpios[0],
640 (s5m8767->buck_gpioindex >> 2) & 0x1);
641 /* SET2 GPIO */
642 gpio_direction_output(pdata->buck_gpios[1],
643 (s5m8767->buck_gpioindex >> 1) & 0x1);
644 /* SET3 GPIO */
645 gpio_direction_output(pdata->buck_gpios[2],
646 (s5m8767->buck_gpioindex >> 0) & 0x1);
647 } else {
648 dev_err(&pdev->dev, "GPIO NOT VALID\n");
649 ret = -EINVAL;
650 return ret;
645 } 651 }
646 652
647 s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK2CTRL, 653 ret = devm_gpio_request(&pdev->dev, pdata->buck_ds[0], "S5M8767 DS2");
648 (pdata->buck2_gpiodvs) ? (1 << 1) : (0 << 1), 1 << 1); 654 if (ret)
649 s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK3CTRL, 655 return ret;
650 (pdata->buck3_gpiodvs) ? (1 << 1) : (0 << 1), 1 << 1); 656
651 s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK4CTRL, 657 ret = devm_gpio_request(&pdev->dev, pdata->buck_ds[1], "S5M8767 DS3");
652 (pdata->buck4_gpiodvs) ? (1 << 1) : (0 << 1), 1 << 1); 658 if (ret)
659 return ret;
660
661 ret = devm_gpio_request(&pdev->dev, pdata->buck_ds[2], "S5M8767 DS4");
662 if (ret)
663 return ret;
664
665 /* DS2 GPIO */
666 gpio_direction_output(pdata->buck_ds[0], 0x0);
667 /* DS3 GPIO */
668 gpio_direction_output(pdata->buck_ds[1], 0x0);
669 /* DS4 GPIO */
670 gpio_direction_output(pdata->buck_ds[2], 0x0);
671
672 if (pdata->buck2_gpiodvs || pdata->buck3_gpiodvs ||
673 pdata->buck4_gpiodvs) {
674 s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK2CTRL,
675 (pdata->buck2_gpiodvs) ? (1 << 1) : (0 << 1),
676 1 << 1);
677 s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK3CTRL,
678 (pdata->buck3_gpiodvs) ? (1 << 1) : (0 << 1),
679 1 << 1);
680 s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK4CTRL,
681 (pdata->buck4_gpiodvs) ? (1 << 1) : (0 << 1),
682 1 << 1);
683 }
653 684
654 /* Initialize GPIO DVS registers */ 685 /* Initialize GPIO DVS registers */
655 for (i = 0; i < 8; i++) { 686 for (i = 0; i < 8; i++) {
@@ -668,9 +699,6 @@ static __devinit int s5m8767_pmic_probe(struct platform_device *pdev)
668 s5m8767->buck4_vol[i]); 699 s5m8767->buck4_vol[i]);
669 } 700 }
670 } 701 }
671 s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK2CTRL, 0x78, 0xff);
672 s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK3CTRL, 0x58, 0xff);
673 s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK4CTRL, 0x78, 0xff);
674 702
675 if (s5m8767->buck2_ramp) 703 if (s5m8767->buck2_ramp)
676 s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, 0x08, 0x08); 704 s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, 0x08, 0x08);
@@ -684,9 +712,13 @@ static __devinit int s5m8767_pmic_probe(struct platform_device *pdev)
684 if (s5m8767->buck2_ramp || s5m8767->buck3_ramp 712 if (s5m8767->buck2_ramp || s5m8767->buck3_ramp
685 || s5m8767->buck4_ramp) { 713 || s5m8767->buck4_ramp) {
686 switch (s5m8767->ramp_delay) { 714 switch (s5m8767->ramp_delay) {
687 case 15: 715 case 5:
688 s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, 716 s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP,
689 0xc0, 0xf0); 717 0x40, 0xf0);
718 break;
719 case 10:
720 s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP,
721 0x90, 0xf0);
690 break; 722 break;
691 case 25: 723 case 25:
692 s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, 724 s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP,
@@ -711,9 +743,12 @@ static __devinit int s5m8767_pmic_probe(struct platform_device *pdev)
711 int id = pdata->regulators[i].id; 743 int id = pdata->regulators[i].id;
712 744
713 desc = reg_voltage_map[id]; 745 desc = reg_voltage_map[id];
714 if (desc) 746 if (desc) {
715 regulators[id].n_voltages = 747 regulators[id].n_voltages =
716 (desc->max - desc->min) / desc->step + 1; 748 (desc->max - desc->min) / desc->step + 1;
749 regulators[id].min_uV = desc->min;
750 regulators[id].uV_step = desc->step;
751 }
717 752
718 config.dev = s5m8767->dev; 753 config.dev = s5m8767->dev;
719 config.init_data = pdata->regulators[i].initdata; 754 config.init_data = pdata->regulators[i].initdata;
diff --git a/drivers/regulator/tps6105x-regulator.c b/drivers/regulator/tps6105x-regulator.c
index d840d8440a91..1378409efaec 100644
--- a/drivers/regulator/tps6105x-regulator.c
+++ b/drivers/regulator/tps6105x-regulator.c
@@ -20,7 +20,7 @@
20#include <linux/mfd/core.h> 20#include <linux/mfd/core.h>
21#include <linux/mfd/tps6105x.h> 21#include <linux/mfd/tps6105x.h>
22 22
23static const int tps6105x_voltages[] = { 23static const unsigned int tps6105x_voltages[] = {
24 4500000, 24 4500000,
25 5000000, 25 5000000,
26 5250000, 26 5250000,
@@ -105,22 +105,13 @@ static int tps6105x_regulator_set_voltage_sel(struct regulator_dev *rdev,
105 return 0; 105 return 0;
106} 106}
107 107
108static int tps6105x_regulator_list_voltage(struct regulator_dev *rdev,
109 unsigned selector)
110{
111 if (selector >= ARRAY_SIZE(tps6105x_voltages))
112 return -EINVAL;
113
114 return tps6105x_voltages[selector];
115}
116
117static struct regulator_ops tps6105x_regulator_ops = { 108static struct regulator_ops tps6105x_regulator_ops = {
118 .enable = tps6105x_regulator_enable, 109 .enable = tps6105x_regulator_enable,
119 .disable = tps6105x_regulator_disable, 110 .disable = tps6105x_regulator_disable,
120 .is_enabled = tps6105x_regulator_is_enabled, 111 .is_enabled = tps6105x_regulator_is_enabled,
121 .get_voltage_sel = tps6105x_regulator_get_voltage_sel, 112 .get_voltage_sel = tps6105x_regulator_get_voltage_sel,
122 .set_voltage_sel = tps6105x_regulator_set_voltage_sel, 113 .set_voltage_sel = tps6105x_regulator_set_voltage_sel,
123 .list_voltage = tps6105x_regulator_list_voltage, 114 .list_voltage = regulator_list_voltage_table,
124}; 115};
125 116
126static const struct regulator_desc tps6105x_regulator_desc = { 117static const struct regulator_desc tps6105x_regulator_desc = {
@@ -130,6 +121,7 @@ static const struct regulator_desc tps6105x_regulator_desc = {
130 .id = 0, 121 .id = 0,
131 .owner = THIS_MODULE, 122 .owner = THIS_MODULE,
132 .n_voltages = ARRAY_SIZE(tps6105x_voltages), 123 .n_voltages = ARRAY_SIZE(tps6105x_voltages),
124 .volt_table = tps6105x_voltages,
133}; 125};
134 126
135/* 127/*
diff --git a/drivers/regulator/tps62360-regulator.c b/drivers/regulator/tps62360-regulator.c
index e534269ed44a..68729a7c8709 100644
--- a/drivers/regulator/tps62360-regulator.c
+++ b/drivers/regulator/tps62360-regulator.c
@@ -65,10 +65,8 @@ struct tps62360_chip {
65 struct regulator_desc desc; 65 struct regulator_desc desc;
66 struct regulator_dev *rdev; 66 struct regulator_dev *rdev;
67 struct regmap *regmap; 67 struct regmap *regmap;
68 int chip_id;
69 int vsel0_gpio; 68 int vsel0_gpio;
70 int vsel1_gpio; 69 int vsel1_gpio;
71 int voltage_base;
72 u8 voltage_reg_mask; 70 u8 voltage_reg_mask;
73 bool en_internal_pulldn; 71 bool en_internal_pulldn;
74 bool en_discharge; 72 bool en_discharge;
@@ -76,7 +74,6 @@ struct tps62360_chip {
76 int lru_index[4]; 74 int lru_index[4];
77 int curr_vset_vsel[4]; 75 int curr_vset_vsel[4];
78 int curr_vset_id; 76 int curr_vset_id;
79 int change_uv_per_us;
80}; 77};
81 78
82/* 79/*
@@ -175,23 +172,6 @@ static int tps62360_dcdc_set_voltage_sel(struct regulator_dev *dev,
175 return 0; 172 return 0;
176} 173}
177 174
178static int tps62360_set_voltage_time_sel(struct regulator_dev *rdev,
179 unsigned int old_selector, unsigned int new_selector)
180{
181 struct tps62360_chip *tps = rdev_get_drvdata(rdev);
182 int old_uV, new_uV;
183
184 old_uV = regulator_list_voltage_linear(rdev, old_selector);
185 if (old_uV < 0)
186 return old_uV;
187
188 new_uV = regulator_list_voltage_linear(rdev, new_selector);
189 if (new_uV < 0)
190 return new_uV;
191
192 return DIV_ROUND_UP(abs(old_uV - new_uV), tps->change_uv_per_us);
193}
194
195static int tps62360_set_mode(struct regulator_dev *rdev, unsigned int mode) 175static int tps62360_set_mode(struct regulator_dev *rdev, unsigned int mode)
196{ 176{
197 struct tps62360_chip *tps = rdev_get_drvdata(rdev); 177 struct tps62360_chip *tps = rdev_get_drvdata(rdev);
@@ -258,7 +238,7 @@ static struct regulator_ops tps62360_dcdc_ops = {
258 .set_voltage_sel = tps62360_dcdc_set_voltage_sel, 238 .set_voltage_sel = tps62360_dcdc_set_voltage_sel,
259 .list_voltage = regulator_list_voltage_linear, 239 .list_voltage = regulator_list_voltage_linear,
260 .map_voltage = regulator_map_voltage_linear, 240 .map_voltage = regulator_map_voltage_linear,
261 .set_voltage_time_sel = tps62360_set_voltage_time_sel, 241 .set_voltage_time_sel = regulator_set_voltage_time_sel,
262 .set_mode = tps62360_set_mode, 242 .set_mode = tps62360_set_mode,
263 .get_mode = tps62360_get_mode, 243 .get_mode = tps62360_get_mode,
264}; 244};
@@ -301,7 +281,7 @@ static int __devinit tps62360_init_dcdc(struct tps62360_chip *tps,
301 ramp_ctrl = (ramp_ctrl >> 4) & 0x7; 281 ramp_ctrl = (ramp_ctrl >> 4) & 0x7;
302 282
303 /* ramp mV/us = 32/(2^ramp_ctrl) */ 283 /* ramp mV/us = 32/(2^ramp_ctrl) */
304 tps->change_uv_per_us = DIV_ROUND_UP(32000, BIT(ramp_ctrl)); 284 tps->desc.ramp_delay = DIV_ROUND_UP(32000, BIT(ramp_ctrl));
305 return ret; 285 return ret;
306} 286}
307 287
@@ -408,13 +388,13 @@ static int __devinit tps62360_probe(struct i2c_client *client,
408 switch (chip_id) { 388 switch (chip_id) {
409 case TPS62360: 389 case TPS62360:
410 case TPS62362: 390 case TPS62362:
411 tps->voltage_base = TPS62360_BASE_VOLTAGE; 391 tps->desc.min_uV = TPS62360_BASE_VOLTAGE;
412 tps->voltage_reg_mask = 0x3F; 392 tps->voltage_reg_mask = 0x3F;
413 tps->desc.n_voltages = TPS62360_N_VOLTAGES; 393 tps->desc.n_voltages = TPS62360_N_VOLTAGES;
414 break; 394 break;
415 case TPS62361: 395 case TPS62361:
416 case TPS62363: 396 case TPS62363:
417 tps->voltage_base = TPS62361_BASE_VOLTAGE; 397 tps->desc.min_uV = TPS62361_BASE_VOLTAGE;
418 tps->voltage_reg_mask = 0x7F; 398 tps->voltage_reg_mask = 0x7F;
419 tps->desc.n_voltages = TPS62361_N_VOLTAGES; 399 tps->desc.n_voltages = TPS62361_N_VOLTAGES;
420 break; 400 break;
@@ -427,7 +407,6 @@ static int __devinit tps62360_probe(struct i2c_client *client,
427 tps->desc.ops = &tps62360_dcdc_ops; 407 tps->desc.ops = &tps62360_dcdc_ops;
428 tps->desc.type = REGULATOR_VOLTAGE; 408 tps->desc.type = REGULATOR_VOLTAGE;
429 tps->desc.owner = THIS_MODULE; 409 tps->desc.owner = THIS_MODULE;
430 tps->desc.min_uV = tps->voltage_base;
431 tps->desc.uV_step = 10000; 410 tps->desc.uV_step = 10000;
432 411
433 tps->regmap = devm_regmap_init_i2c(client, &tps62360_regmap_config); 412 tps->regmap = devm_regmap_init_i2c(client, &tps62360_regmap_config);
@@ -449,24 +428,24 @@ static int __devinit tps62360_probe(struct i2c_client *client,
449 int gpio_flags; 428 int gpio_flags;
450 gpio_flags = (pdata->vsel0_def_state) ? 429 gpio_flags = (pdata->vsel0_def_state) ?
451 GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW; 430 GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW;
452 ret = gpio_request_one(tps->vsel0_gpio, 431 ret = devm_gpio_request_one(&client->dev, tps->vsel0_gpio,
453 gpio_flags, "tps62360-vsel0"); 432 gpio_flags, "tps62360-vsel0");
454 if (ret) { 433 if (ret) {
455 dev_err(&client->dev, 434 dev_err(&client->dev,
456 "%s(): Could not obtain vsel0 GPIO %d: %d\n", 435 "%s(): Could not obtain vsel0 GPIO %d: %d\n",
457 __func__, tps->vsel0_gpio, ret); 436 __func__, tps->vsel0_gpio, ret);
458 goto err_gpio0; 437 return ret;
459 } 438 }
460 439
461 gpio_flags = (pdata->vsel1_def_state) ? 440 gpio_flags = (pdata->vsel1_def_state) ?
462 GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW; 441 GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW;
463 ret = gpio_request_one(tps->vsel1_gpio, 442 ret = devm_gpio_request_one(&client->dev, tps->vsel1_gpio,
464 gpio_flags, "tps62360-vsel1"); 443 gpio_flags, "tps62360-vsel1");
465 if (ret) { 444 if (ret) {
466 dev_err(&client->dev, 445 dev_err(&client->dev,
467 "%s(): Could not obtain vsel1 GPIO %d: %d\n", 446 "%s(): Could not obtain vsel1 GPIO %d: %d\n",
468 __func__, tps->vsel1_gpio, ret); 447 __func__, tps->vsel1_gpio, ret);
469 goto err_gpio1; 448 return ret;
470 } 449 }
471 tps->valid_gpios = true; 450 tps->valid_gpios = true;
472 451
@@ -484,7 +463,7 @@ static int __devinit tps62360_probe(struct i2c_client *client,
484 if (ret < 0) { 463 if (ret < 0) {
485 dev_err(tps->dev, "%s(): Init failed with err = %d\n", 464 dev_err(tps->dev, "%s(): Init failed with err = %d\n",
486 __func__, ret); 465 __func__, ret);
487 goto err_init; 466 return ret;
488 } 467 }
489 468
490 config.dev = &client->dev; 469 config.dev = &client->dev;
@@ -498,21 +477,11 @@ static int __devinit tps62360_probe(struct i2c_client *client,
498 dev_err(tps->dev, 477 dev_err(tps->dev,
499 "%s(): regulator register failed with err %s\n", 478 "%s(): regulator register failed with err %s\n",
500 __func__, id->name); 479 __func__, id->name);
501 ret = PTR_ERR(rdev); 480 return PTR_ERR(rdev);
502 goto err_init;
503 } 481 }
504 482
505 tps->rdev = rdev; 483 tps->rdev = rdev;
506 return 0; 484 return 0;
507
508err_init:
509 if (gpio_is_valid(tps->vsel1_gpio))
510 gpio_free(tps->vsel1_gpio);
511err_gpio1:
512 if (gpio_is_valid(tps->vsel0_gpio))
513 gpio_free(tps->vsel0_gpio);
514err_gpio0:
515 return ret;
516} 485}
517 486
518/** 487/**
@@ -525,12 +494,6 @@ static int __devexit tps62360_remove(struct i2c_client *client)
525{ 494{
526 struct tps62360_chip *tps = i2c_get_clientdata(client); 495 struct tps62360_chip *tps = i2c_get_clientdata(client);
527 496
528 if (gpio_is_valid(tps->vsel1_gpio))
529 gpio_free(tps->vsel1_gpio);
530
531 if (gpio_is_valid(tps->vsel0_gpio))
532 gpio_free(tps->vsel0_gpio);
533
534 regulator_unregister(tps->rdev); 497 regulator_unregister(tps->rdev);
535 return 0; 498 return 0;
536} 499}
diff --git a/drivers/regulator/tps65023-regulator.c b/drivers/regulator/tps65023-regulator.c
index 8f1be8586c72..6998d579d07b 100644
--- a/drivers/regulator/tps65023-regulator.c
+++ b/drivers/regulator/tps65023-regulator.c
@@ -69,10 +69,6 @@
69#define TPS65023_REG_CTRL2_DCDC1 BIT(1) 69#define TPS65023_REG_CTRL2_DCDC1 BIT(1)
70#define TPS65023_REG_CTRL2_DCDC3 BIT(0) 70#define TPS65023_REG_CTRL2_DCDC3 BIT(0)
71 71
72/* LDO_CTRL bitfields */
73#define TPS65023_LDO_CTRL_LDOx_SHIFT(ldo_id) ((ldo_id)*4)
74#define TPS65023_LDO_CTRL_LDOx_MASK(ldo_id) (0x07 << ((ldo_id)*4))
75
76/* Number of step-down converters available */ 72/* Number of step-down converters available */
77#define TPS65023_NUM_DCDC 3 73#define TPS65023_NUM_DCDC 3
78/* Number of LDO voltage regulators available */ 74/* Number of LDO voltage regulators available */
@@ -91,48 +87,53 @@
91#define TPS65023_MAX_REG_ID TPS65023_LDO_2 87#define TPS65023_MAX_REG_ID TPS65023_LDO_2
92 88
93/* Supported voltage values for regulators */ 89/* Supported voltage values for regulators */
94static const u16 VCORE_VSEL_table[] = { 90static const unsigned int VCORE_VSEL_table[] = {
95 800, 825, 850, 875, 91 800000, 825000, 850000, 875000,
96 900, 925, 950, 975, 92 900000, 925000, 950000, 975000,
97 1000, 1025, 1050, 1075, 93 1000000, 1025000, 1050000, 1075000,
98 1100, 1125, 1150, 1175, 94 1100000, 1125000, 1150000, 1175000,
99 1200, 1225, 1250, 1275, 95 1200000, 1225000, 1250000, 1275000,
100 1300, 1325, 1350, 1375, 96 1300000, 1325000, 1350000, 1375000,
101 1400, 1425, 1450, 1475, 97 1400000, 1425000, 1450000, 1475000,
102 1500, 1525, 1550, 1600, 98 1500000, 1525000, 1550000, 1600000,
99};
100
101static const unsigned int DCDC_FIXED_3300000_VSEL_table[] = {
102 3300000,
103};
104
105static const unsigned int DCDC_FIXED_1800000_VSEL_table[] = {
106 1800000,
103}; 107};
104 108
105/* Supported voltage values for LDO regulators for tps65020 */ 109/* Supported voltage values for LDO regulators for tps65020 */
106static const u16 TPS65020_LDO1_VSEL_table[] = { 110static const unsigned int TPS65020_LDO1_VSEL_table[] = {
107 1000, 1050, 1100, 1300, 111 1000000, 1050000, 1100000, 1300000,
108 1800, 2500, 3000, 3300, 112 1800000, 2500000, 3000000, 3300000,
109}; 113};
110 114
111static const u16 TPS65020_LDO2_VSEL_table[] = { 115static const unsigned int TPS65020_LDO2_VSEL_table[] = {
112 1000, 1050, 1100, 1300, 116 1000000, 1050000, 1100000, 1300000,
113 1800, 2500, 3000, 3300, 117 1800000, 2500000, 3000000, 3300000,
114}; 118};
115 119
116/* Supported voltage values for LDO regulators 120/* Supported voltage values for LDO regulators
117 * for tps65021 and tps65023 */ 121 * for tps65021 and tps65023 */
118static const u16 TPS65023_LDO1_VSEL_table[] = { 122static const unsigned int TPS65023_LDO1_VSEL_table[] = {
119 1000, 1100, 1300, 1800, 123 1000000, 1100000, 1300000, 1800000,
120 2200, 2600, 2800, 3150, 124 2200000, 2600000, 2800000, 3150000,
121}; 125};
122 126
123static const u16 TPS65023_LDO2_VSEL_table[] = { 127static const unsigned int TPS65023_LDO2_VSEL_table[] = {
124 1050, 1200, 1300, 1800, 128 1050000, 1200000, 1300000, 1800000,
125 2500, 2800, 3000, 3300, 129 2500000, 2800000, 3000000, 3300000,
126}; 130};
127 131
128/* Regulator specific details */ 132/* Regulator specific details */
129struct tps_info { 133struct tps_info {
130 const char *name; 134 const char *name;
131 unsigned min_uV;
132 unsigned max_uV;
133 bool fixed;
134 u8 table_len; 135 u8 table_len;
135 const u16 *table; 136 const unsigned int *table;
136}; 137};
137 138
138/* PMIC details */ 139/* PMIC details */
@@ -150,7 +151,7 @@ struct tps_driver_data {
150 u8 core_regulator; 151 u8 core_regulator;
151}; 152};
152 153
153static int tps65023_dcdc_get_voltage(struct regulator_dev *dev) 154static int tps65023_dcdc_get_voltage_sel(struct regulator_dev *dev)
154{ 155{
155 struct tps_pmic *tps = rdev_get_drvdata(dev); 156 struct tps_pmic *tps = rdev_get_drvdata(dev);
156 int ret; 157 int ret;
@@ -164,9 +165,9 @@ static int tps65023_dcdc_get_voltage(struct regulator_dev *dev)
164 if (ret != 0) 165 if (ret != 0)
165 return ret; 166 return ret;
166 data &= (tps->info[dcdc]->table_len - 1); 167 data &= (tps->info[dcdc]->table_len - 1);
167 return tps->info[dcdc]->table[data] * 1000; 168 return data;
168 } else 169 } else
169 return tps->info[dcdc]->min_uV; 170 return 0;
170} 171}
171 172
172static int tps65023_dcdc_set_voltage_sel(struct regulator_dev *dev, 173static int tps65023_dcdc_set_voltage_sel(struct regulator_dev *dev,
@@ -193,76 +194,14 @@ out:
193 return ret; 194 return ret;
194} 195}
195 196
196static int tps65023_ldo_get_voltage(struct regulator_dev *dev)
197{
198 struct tps_pmic *tps = rdev_get_drvdata(dev);
199 int data, ldo = rdev_get_id(dev);
200 int ret;
201
202 if (ldo < TPS65023_LDO_1 || ldo > TPS65023_LDO_2)
203 return -EINVAL;
204
205 ret = regmap_read(tps->regmap, TPS65023_REG_LDO_CTRL, &data);
206 if (ret != 0)
207 return ret;
208
209 data >>= (TPS65023_LDO_CTRL_LDOx_SHIFT(ldo - TPS65023_LDO_1));
210 data &= (tps->info[ldo]->table_len - 1);
211 return tps->info[ldo]->table[data] * 1000;
212}
213
214static int tps65023_ldo_set_voltage_sel(struct regulator_dev *dev,
215 unsigned selector)
216{
217 struct tps_pmic *tps = rdev_get_drvdata(dev);
218 int ldo_index = rdev_get_id(dev) - TPS65023_LDO_1;
219
220 return regmap_update_bits(tps->regmap, TPS65023_REG_LDO_CTRL,
221 TPS65023_LDO_CTRL_LDOx_MASK(ldo_index),
222 selector << TPS65023_LDO_CTRL_LDOx_SHIFT(ldo_index));
223}
224
225static int tps65023_dcdc_list_voltage(struct regulator_dev *dev,
226 unsigned selector)
227{
228 struct tps_pmic *tps = rdev_get_drvdata(dev);
229 int dcdc = rdev_get_id(dev);
230
231 if (dcdc < TPS65023_DCDC_1 || dcdc > TPS65023_DCDC_3)
232 return -EINVAL;
233
234 if (dcdc == tps->core_regulator) {
235 if (selector >= tps->info[dcdc]->table_len)
236 return -EINVAL;
237 else
238 return tps->info[dcdc]->table[selector] * 1000;
239 } else
240 return tps->info[dcdc]->min_uV;
241}
242
243static int tps65023_ldo_list_voltage(struct regulator_dev *dev,
244 unsigned selector)
245{
246 struct tps_pmic *tps = rdev_get_drvdata(dev);
247 int ldo = rdev_get_id(dev);
248
249 if (ldo < TPS65023_LDO_1 || ldo > TPS65023_LDO_2)
250 return -EINVAL;
251
252 if (selector >= tps->info[ldo]->table_len)
253 return -EINVAL;
254 else
255 return tps->info[ldo]->table[selector] * 1000;
256}
257
258/* Operations permitted on VDCDCx */ 197/* Operations permitted on VDCDCx */
259static struct regulator_ops tps65023_dcdc_ops = { 198static struct regulator_ops tps65023_dcdc_ops = {
260 .is_enabled = regulator_is_enabled_regmap, 199 .is_enabled = regulator_is_enabled_regmap,
261 .enable = regulator_enable_regmap, 200 .enable = regulator_enable_regmap,
262 .disable = regulator_disable_regmap, 201 .disable = regulator_disable_regmap,
263 .get_voltage = tps65023_dcdc_get_voltage, 202 .get_voltage_sel = tps65023_dcdc_get_voltage_sel,
264 .set_voltage_sel = tps65023_dcdc_set_voltage_sel, 203 .set_voltage_sel = tps65023_dcdc_set_voltage_sel,
265 .list_voltage = tps65023_dcdc_list_voltage, 204 .list_voltage = regulator_list_voltage_table,
266}; 205};
267 206
268/* Operations permitted on LDOx */ 207/* Operations permitted on LDOx */
@@ -270,9 +209,9 @@ static struct regulator_ops tps65023_ldo_ops = {
270 .is_enabled = regulator_is_enabled_regmap, 209 .is_enabled = regulator_is_enabled_regmap,
271 .enable = regulator_enable_regmap, 210 .enable = regulator_enable_regmap,
272 .disable = regulator_disable_regmap, 211 .disable = regulator_disable_regmap,
273 .get_voltage = tps65023_ldo_get_voltage, 212 .get_voltage_sel = regulator_get_voltage_sel_regmap,
274 .set_voltage_sel = tps65023_ldo_set_voltage_sel, 213 .set_voltage_sel = regulator_set_voltage_sel_regmap,
275 .list_voltage = tps65023_ldo_list_voltage, 214 .list_voltage = regulator_list_voltage_table,
276}; 215};
277 216
278static struct regmap_config tps65023_regmap_config = { 217static struct regmap_config tps65023_regmap_config = {
@@ -325,19 +264,28 @@ static int __devinit tps_65023_probe(struct i2c_client *client,
325 tps->desc[i].name = info->name; 264 tps->desc[i].name = info->name;
326 tps->desc[i].id = i; 265 tps->desc[i].id = i;
327 tps->desc[i].n_voltages = info->table_len; 266 tps->desc[i].n_voltages = info->table_len;
267 tps->desc[i].volt_table = info->table;
328 tps->desc[i].ops = (i > TPS65023_DCDC_3 ? 268 tps->desc[i].ops = (i > TPS65023_DCDC_3 ?
329 &tps65023_ldo_ops : &tps65023_dcdc_ops); 269 &tps65023_ldo_ops : &tps65023_dcdc_ops);
330 tps->desc[i].type = REGULATOR_VOLTAGE; 270 tps->desc[i].type = REGULATOR_VOLTAGE;
331 tps->desc[i].owner = THIS_MODULE; 271 tps->desc[i].owner = THIS_MODULE;
332 272
333 tps->desc[i].enable_reg = TPS65023_REG_REG_CTRL; 273 tps->desc[i].enable_reg = TPS65023_REG_REG_CTRL;
334 if (i == TPS65023_LDO_1) 274 switch (i) {
275 case TPS65023_LDO_1:
276 tps->desc[i].vsel_reg = TPS65023_REG_LDO_CTRL;
277 tps->desc[i].vsel_mask = 0x07;
335 tps->desc[i].enable_mask = 1 << 1; 278 tps->desc[i].enable_mask = 1 << 1;
336 else if (i == TPS65023_LDO_2) 279 break;
280 case TPS65023_LDO_2:
281 tps->desc[i].vsel_reg = TPS65023_REG_LDO_CTRL;
282 tps->desc[i].vsel_mask = 0x70;
337 tps->desc[i].enable_mask = 1 << 2; 283 tps->desc[i].enable_mask = 1 << 2;
338 else /* DCDCx */ 284 break;
285 default: /* DCDCx */
339 tps->desc[i].enable_mask = 286 tps->desc[i].enable_mask =
340 1 << (TPS65023_NUM_REGULATOR - i); 287 1 << (TPS65023_NUM_REGULATOR - i);
288 }
341 289
342 config.dev = &client->dev; 290 config.dev = &client->dev;
343 config.init_data = init_data; 291 config.init_data = init_data;
@@ -384,35 +332,26 @@ static int __devexit tps_65023_remove(struct i2c_client *client)
384static const struct tps_info tps65020_regs[] = { 332static const struct tps_info tps65020_regs[] = {
385 { 333 {
386 .name = "VDCDC1", 334 .name = "VDCDC1",
387 .min_uV = 3300000, 335 .table_len = ARRAY_SIZE(DCDC_FIXED_3300000_VSEL_table),
388 .max_uV = 3300000, 336 .table = DCDC_FIXED_3300000_VSEL_table,
389 .fixed = 1,
390 }, 337 },
391 { 338 {
392 .name = "VDCDC2", 339 .name = "VDCDC2",
393 .min_uV = 1800000, 340 .table_len = ARRAY_SIZE(DCDC_FIXED_1800000_VSEL_table),
394 .max_uV = 1800000, 341 .table = DCDC_FIXED_1800000_VSEL_table,
395 .fixed = 1,
396 }, 342 },
397 { 343 {
398 .name = "VDCDC3", 344 .name = "VDCDC3",
399 .min_uV = 800000,
400 .max_uV = 1600000,
401 .table_len = ARRAY_SIZE(VCORE_VSEL_table), 345 .table_len = ARRAY_SIZE(VCORE_VSEL_table),
402 .table = VCORE_VSEL_table, 346 .table = VCORE_VSEL_table,
403 }, 347 },
404
405 { 348 {
406 .name = "LDO1", 349 .name = "LDO1",
407 .min_uV = 1000000,
408 .max_uV = 3150000,
409 .table_len = ARRAY_SIZE(TPS65020_LDO1_VSEL_table), 350 .table_len = ARRAY_SIZE(TPS65020_LDO1_VSEL_table),
410 .table = TPS65020_LDO1_VSEL_table, 351 .table = TPS65020_LDO1_VSEL_table,
411 }, 352 },
412 { 353 {
413 .name = "LDO2", 354 .name = "LDO2",
414 .min_uV = 1050000,
415 .max_uV = 3300000,
416 .table_len = ARRAY_SIZE(TPS65020_LDO2_VSEL_table), 355 .table_len = ARRAY_SIZE(TPS65020_LDO2_VSEL_table),
417 .table = TPS65020_LDO2_VSEL_table, 356 .table = TPS65020_LDO2_VSEL_table,
418 }, 357 },
@@ -421,34 +360,26 @@ static const struct tps_info tps65020_regs[] = {
421static const struct tps_info tps65021_regs[] = { 360static const struct tps_info tps65021_regs[] = {
422 { 361 {
423 .name = "VDCDC1", 362 .name = "VDCDC1",
424 .min_uV = 3300000, 363 .table_len = ARRAY_SIZE(DCDC_FIXED_3300000_VSEL_table),
425 .max_uV = 3300000, 364 .table = DCDC_FIXED_3300000_VSEL_table,
426 .fixed = 1,
427 }, 365 },
428 { 366 {
429 .name = "VDCDC2", 367 .name = "VDCDC2",
430 .min_uV = 1800000, 368 .table_len = ARRAY_SIZE(DCDC_FIXED_1800000_VSEL_table),
431 .max_uV = 1800000, 369 .table = DCDC_FIXED_1800000_VSEL_table,
432 .fixed = 1,
433 }, 370 },
434 { 371 {
435 .name = "VDCDC3", 372 .name = "VDCDC3",
436 .min_uV = 800000,
437 .max_uV = 1600000,
438 .table_len = ARRAY_SIZE(VCORE_VSEL_table), 373 .table_len = ARRAY_SIZE(VCORE_VSEL_table),
439 .table = VCORE_VSEL_table, 374 .table = VCORE_VSEL_table,
440 }, 375 },
441 { 376 {
442 .name = "LDO1", 377 .name = "LDO1",
443 .min_uV = 1000000,
444 .max_uV = 3150000,
445 .table_len = ARRAY_SIZE(TPS65023_LDO1_VSEL_table), 378 .table_len = ARRAY_SIZE(TPS65023_LDO1_VSEL_table),
446 .table = TPS65023_LDO1_VSEL_table, 379 .table = TPS65023_LDO1_VSEL_table,
447 }, 380 },
448 { 381 {
449 .name = "LDO2", 382 .name = "LDO2",
450 .min_uV = 1050000,
451 .max_uV = 3300000,
452 .table_len = ARRAY_SIZE(TPS65023_LDO2_VSEL_table), 383 .table_len = ARRAY_SIZE(TPS65023_LDO2_VSEL_table),
453 .table = TPS65023_LDO2_VSEL_table, 384 .table = TPS65023_LDO2_VSEL_table,
454 }, 385 },
@@ -457,34 +388,26 @@ static const struct tps_info tps65021_regs[] = {
457static const struct tps_info tps65023_regs[] = { 388static const struct tps_info tps65023_regs[] = {
458 { 389 {
459 .name = "VDCDC1", 390 .name = "VDCDC1",
460 .min_uV = 800000,
461 .max_uV = 1600000,
462 .table_len = ARRAY_SIZE(VCORE_VSEL_table), 391 .table_len = ARRAY_SIZE(VCORE_VSEL_table),
463 .table = VCORE_VSEL_table, 392 .table = VCORE_VSEL_table,
464 }, 393 },
465 { 394 {
466 .name = "VDCDC2", 395 .name = "VDCDC2",
467 .min_uV = 3300000, 396 .table_len = ARRAY_SIZE(DCDC_FIXED_3300000_VSEL_table),
468 .max_uV = 3300000, 397 .table = DCDC_FIXED_3300000_VSEL_table,
469 .fixed = 1,
470 }, 398 },
471 { 399 {
472 .name = "VDCDC3", 400 .name = "VDCDC3",
473 .min_uV = 1800000, 401 .table_len = ARRAY_SIZE(DCDC_FIXED_1800000_VSEL_table),
474 .max_uV = 1800000, 402 .table = DCDC_FIXED_1800000_VSEL_table,
475 .fixed = 1,
476 }, 403 },
477 { 404 {
478 .name = "LDO1", 405 .name = "LDO1",
479 .min_uV = 1000000,
480 .max_uV = 3150000,
481 .table_len = ARRAY_SIZE(TPS65023_LDO1_VSEL_table), 406 .table_len = ARRAY_SIZE(TPS65023_LDO1_VSEL_table),
482 .table = TPS65023_LDO1_VSEL_table, 407 .table = TPS65023_LDO1_VSEL_table,
483 }, 408 },
484 { 409 {
485 .name = "LDO2", 410 .name = "LDO2",
486 .min_uV = 1050000,
487 .max_uV = 3300000,
488 .table_len = ARRAY_SIZE(TPS65023_LDO2_VSEL_table), 411 .table_len = ARRAY_SIZE(TPS65023_LDO2_VSEL_table),
489 .table = TPS65023_LDO2_VSEL_table, 412 .table = TPS65023_LDO2_VSEL_table,
490 }, 413 },
diff --git a/drivers/regulator/tps6507x-regulator.c b/drivers/regulator/tps6507x-regulator.c
index da38be1016aa..07d01ccdf308 100644
--- a/drivers/regulator/tps6507x-regulator.c
+++ b/drivers/regulator/tps6507x-regulator.c
@@ -43,58 +43,40 @@
43/* Number of total regulators available */ 43/* Number of total regulators available */
44#define TPS6507X_NUM_REGULATOR (TPS6507X_NUM_DCDC + TPS6507X_NUM_LDO) 44#define TPS6507X_NUM_REGULATOR (TPS6507X_NUM_DCDC + TPS6507X_NUM_LDO)
45 45
46/* Supported voltage values for regulators (in milliVolts) */ 46/* Supported voltage values for regulators (in microVolts) */
47static const u16 VDCDCx_VSEL_table[] = { 47static const unsigned int VDCDCx_VSEL_table[] = {
48 725, 750, 775, 800, 48 725000, 750000, 775000, 800000,
49 825, 850, 875, 900, 49 825000, 850000, 875000, 900000,
50 925, 950, 975, 1000, 50 925000, 950000, 975000, 1000000,
51 1025, 1050, 1075, 1100, 51 1025000, 1050000, 1075000, 1100000,
52 1125, 1150, 1175, 1200, 52 1125000, 1150000, 1175000, 1200000,
53 1225, 1250, 1275, 1300, 53 1225000, 1250000, 1275000, 1300000,
54 1325, 1350, 1375, 1400, 54 1325000, 1350000, 1375000, 1400000,
55 1425, 1450, 1475, 1500, 55 1425000, 1450000, 1475000, 1500000,
56 1550, 1600, 1650, 1700, 56 1550000, 1600000, 1650000, 1700000,
57 1750, 1800, 1850, 1900, 57 1750000, 1800000, 1850000, 1900000,
58 1950, 2000, 2050, 2100, 58 1950000, 2000000, 2050000, 2100000,
59 2150, 2200, 2250, 2300, 59 2150000, 2200000, 2250000, 2300000,
60 2350, 2400, 2450, 2500, 60 2350000, 2400000, 2450000, 2500000,
61 2550, 2600, 2650, 2700, 61 2550000, 2600000, 2650000, 2700000,
62 2750, 2800, 2850, 2900, 62 2750000, 2800000, 2850000, 2900000,
63 3000, 3100, 3200, 3300, 63 3000000, 3100000, 3200000, 3300000,
64}; 64};
65 65
66static const u16 LDO1_VSEL_table[] = { 66static const unsigned int LDO1_VSEL_table[] = {
67 1000, 1100, 1200, 1250, 67 1000000, 1100000, 1200000, 1250000,
68 1300, 1350, 1400, 1500, 68 1300000, 1350000, 1400000, 1500000,
69 1600, 1800, 2500, 2750, 69 1600000, 1800000, 2500000, 2750000,
70 2800, 3000, 3100, 3300, 70 2800000, 3000000, 3100000, 3300000,
71}; 71};
72 72
73static const u16 LDO2_VSEL_table[] = { 73/* The voltage mapping table for LDO2 is the same as VDCDCx */
74 725, 750, 775, 800, 74#define LDO2_VSEL_table VDCDCx_VSEL_table
75 825, 850, 875, 900,
76 925, 950, 975, 1000,
77 1025, 1050, 1075, 1100,
78 1125, 1150, 1175, 1200,
79 1225, 1250, 1275, 1300,
80 1325, 1350, 1375, 1400,
81 1425, 1450, 1475, 1500,
82 1550, 1600, 1650, 1700,
83 1750, 1800, 1850, 1900,
84 1950, 2000, 2050, 2100,
85 2150, 2200, 2250, 2300,
86 2350, 2400, 2450, 2500,
87 2550, 2600, 2650, 2700,
88 2750, 2800, 2850, 2900,
89 3000, 3100, 3200, 3300,
90};
91 75
92struct tps_info { 76struct tps_info {
93 const char *name; 77 const char *name;
94 unsigned min_uV;
95 unsigned max_uV;
96 u8 table_len; 78 u8 table_len;
97 const u16 *table; 79 const unsigned int *table;
98 80
99 /* Does DCDC high or the low register defines output voltage? */ 81 /* Does DCDC high or the low register defines output voltage? */
100 bool defdcdc_default; 82 bool defdcdc_default;
@@ -103,36 +85,26 @@ struct tps_info {
103static struct tps_info tps6507x_pmic_regs[] = { 85static struct tps_info tps6507x_pmic_regs[] = {
104 { 86 {
105 .name = "VDCDC1", 87 .name = "VDCDC1",
106 .min_uV = 725000,
107 .max_uV = 3300000,
108 .table_len = ARRAY_SIZE(VDCDCx_VSEL_table), 88 .table_len = ARRAY_SIZE(VDCDCx_VSEL_table),
109 .table = VDCDCx_VSEL_table, 89 .table = VDCDCx_VSEL_table,
110 }, 90 },
111 { 91 {
112 .name = "VDCDC2", 92 .name = "VDCDC2",
113 .min_uV = 725000,
114 .max_uV = 3300000,
115 .table_len = ARRAY_SIZE(VDCDCx_VSEL_table), 93 .table_len = ARRAY_SIZE(VDCDCx_VSEL_table),
116 .table = VDCDCx_VSEL_table, 94 .table = VDCDCx_VSEL_table,
117 }, 95 },
118 { 96 {
119 .name = "VDCDC3", 97 .name = "VDCDC3",
120 .min_uV = 725000,
121 .max_uV = 3300000,
122 .table_len = ARRAY_SIZE(VDCDCx_VSEL_table), 98 .table_len = ARRAY_SIZE(VDCDCx_VSEL_table),
123 .table = VDCDCx_VSEL_table, 99 .table = VDCDCx_VSEL_table,
124 }, 100 },
125 { 101 {
126 .name = "LDO1", 102 .name = "LDO1",
127 .min_uV = 1000000,
128 .max_uV = 3300000,
129 .table_len = ARRAY_SIZE(LDO1_VSEL_table), 103 .table_len = ARRAY_SIZE(LDO1_VSEL_table),
130 .table = LDO1_VSEL_table, 104 .table = LDO1_VSEL_table,
131 }, 105 },
132 { 106 {
133 .name = "LDO2", 107 .name = "LDO2",
134 .min_uV = 725000,
135 .max_uV = 3300000,
136 .table_len = ARRAY_SIZE(LDO2_VSEL_table), 108 .table_len = ARRAY_SIZE(LDO2_VSEL_table),
137 .table = LDO2_VSEL_table, 109 .table = LDO2_VSEL_table,
138 }, 110 },
@@ -375,28 +347,13 @@ static int tps6507x_pmic_set_voltage_sel(struct regulator_dev *dev,
375 return tps6507x_pmic_reg_write(tps, reg, data); 347 return tps6507x_pmic_reg_write(tps, reg, data);
376} 348}
377 349
378static int tps6507x_pmic_list_voltage(struct regulator_dev *dev,
379 unsigned selector)
380{
381 struct tps6507x_pmic *tps = rdev_get_drvdata(dev);
382 int rid = rdev_get_id(dev);
383
384 if (rid < TPS6507X_DCDC_1 || rid > TPS6507X_LDO_2)
385 return -EINVAL;
386
387 if (selector >= tps->info[rid]->table_len)
388 return -EINVAL;
389 else
390 return tps->info[rid]->table[selector] * 1000;
391}
392
393static struct regulator_ops tps6507x_pmic_ops = { 350static struct regulator_ops tps6507x_pmic_ops = {
394 .is_enabled = tps6507x_pmic_is_enabled, 351 .is_enabled = tps6507x_pmic_is_enabled,
395 .enable = tps6507x_pmic_enable, 352 .enable = tps6507x_pmic_enable,
396 .disable = tps6507x_pmic_disable, 353 .disable = tps6507x_pmic_disable,
397 .get_voltage_sel = tps6507x_pmic_get_voltage_sel, 354 .get_voltage_sel = tps6507x_pmic_get_voltage_sel,
398 .set_voltage_sel = tps6507x_pmic_set_voltage_sel, 355 .set_voltage_sel = tps6507x_pmic_set_voltage_sel,
399 .list_voltage = tps6507x_pmic_list_voltage, 356 .list_voltage = regulator_list_voltage_table,
400}; 357};
401 358
402static __devinit int tps6507x_pmic_probe(struct platform_device *pdev) 359static __devinit int tps6507x_pmic_probe(struct platform_device *pdev)
@@ -449,6 +406,7 @@ static __devinit int tps6507x_pmic_probe(struct platform_device *pdev)
449 tps->desc[i].name = info->name; 406 tps->desc[i].name = info->name;
450 tps->desc[i].id = i; 407 tps->desc[i].id = i;
451 tps->desc[i].n_voltages = info->table_len; 408 tps->desc[i].n_voltages = info->table_len;
409 tps->desc[i].volt_table = info->table;
452 tps->desc[i].ops = &tps6507x_pmic_ops; 410 tps->desc[i].ops = &tps6507x_pmic_ops;
453 tps->desc[i].type = REGULATOR_VOLTAGE; 411 tps->desc[i].type = REGULATOR_VOLTAGE;
454 tps->desc[i].owner = THIS_MODULE; 412 tps->desc[i].owner = THIS_MODULE;
diff --git a/drivers/regulator/tps65217-regulator.c b/drivers/regulator/tps65217-regulator.c
index 9d371d2cbcae..6caa222af77a 100644
--- a/drivers/regulator/tps65217-regulator.c
+++ b/drivers/regulator/tps65217-regulator.c
@@ -26,7 +26,7 @@
26#include <linux/regulator/machine.h> 26#include <linux/regulator/machine.h>
27#include <linux/mfd/tps65217.h> 27#include <linux/mfd/tps65217.h>
28 28
29#define TPS65217_REGULATOR(_name, _id, _ops, _n) \ 29#define TPS65217_REGULATOR(_name, _id, _ops, _n, _vr, _vm, _em, _t) \
30 { \ 30 { \
31 .name = _name, \ 31 .name = _name, \
32 .id = _id, \ 32 .id = _id, \
@@ -34,23 +34,23 @@
34 .n_voltages = _n, \ 34 .n_voltages = _n, \
35 .type = REGULATOR_VOLTAGE, \ 35 .type = REGULATOR_VOLTAGE, \
36 .owner = THIS_MODULE, \ 36 .owner = THIS_MODULE, \
37 .vsel_reg = _vr, \
38 .vsel_mask = _vm, \
39 .enable_reg = TPS65217_REG_ENABLE, \
40 .enable_mask = _em, \
41 .volt_table = _t, \
37 } \ 42 } \
38 43
39#define TPS65217_INFO(_nm, _min, _max, _f1, _f2, _t, _n, _em, _vr, _vm) \ 44#define TPS65217_INFO(_nm, _min, _max, _f1, _f2) \
40 { \ 45 { \
41 .name = _nm, \ 46 .name = _nm, \
42 .min_uV = _min, \ 47 .min_uV = _min, \
43 .max_uV = _max, \ 48 .max_uV = _max, \
44 .vsel_to_uv = _f1, \ 49 .vsel_to_uv = _f1, \
45 .uv_to_vsel = _f2, \ 50 .uv_to_vsel = _f2, \
46 .table = _t, \
47 .table_len = _n, \
48 .enable_mask = _em, \
49 .set_vout_reg = _vr, \
50 .set_vout_mask = _vm, \
51 } 51 }
52 52
53static const int LDO1_VSEL_table[] = { 53static const unsigned int LDO1_VSEL_table[] = {
54 1000000, 1100000, 1200000, 1250000, 54 1000000, 1100000, 1200000, 1250000,
55 1300000, 1350000, 1400000, 1500000, 55 1300000, 1350000, 1400000, 1500000,
56 1600000, 1800000, 2500000, 2750000, 56 1600000, 1800000, 2500000, 2750000,
@@ -78,7 +78,7 @@ static int tps65217_vsel_to_uv1(unsigned int vsel)
78 78
79static int tps65217_uv_to_vsel1(int uV, unsigned int *vsel) 79static int tps65217_uv_to_vsel1(int uV, unsigned int *vsel)
80{ 80{
81 if ((uV < 0) && (uV > 3300000)) 81 if (uV < 0 || uV > 3300000)
82 return -EINVAL; 82 return -EINVAL;
83 83
84 if (uV <= 1500000) 84 if (uV <= 1500000)
@@ -112,7 +112,7 @@ static int tps65217_vsel_to_uv2(unsigned int vsel)
112 112
113static int tps65217_uv_to_vsel2(int uV, unsigned int *vsel) 113static int tps65217_uv_to_vsel2(int uV, unsigned int *vsel)
114{ 114{
115 if ((uV < 0) && (uV > 3300000)) 115 if (uV < 0 || uV > 3300000)
116 return -EINVAL; 116 return -EINVAL;
117 117
118 if (uV <= 1900000) 118 if (uV <= 1900000)
@@ -127,46 +127,20 @@ static int tps65217_uv_to_vsel2(int uV, unsigned int *vsel)
127 127
128static struct tps_info tps65217_pmic_regs[] = { 128static struct tps_info tps65217_pmic_regs[] = {
129 TPS65217_INFO("DCDC1", 900000, 1800000, tps65217_vsel_to_uv1, 129 TPS65217_INFO("DCDC1", 900000, 1800000, tps65217_vsel_to_uv1,
130 tps65217_uv_to_vsel1, NULL, 64, TPS65217_ENABLE_DC1_EN, 130 tps65217_uv_to_vsel1),
131 TPS65217_REG_DEFDCDC1, TPS65217_DEFDCDCX_DCDC_MASK),
132 TPS65217_INFO("DCDC2", 900000, 3300000, tps65217_vsel_to_uv1, 131 TPS65217_INFO("DCDC2", 900000, 3300000, tps65217_vsel_to_uv1,
133 tps65217_uv_to_vsel1, NULL, 64, TPS65217_ENABLE_DC2_EN, 132 tps65217_uv_to_vsel1),
134 TPS65217_REG_DEFDCDC2, TPS65217_DEFDCDCX_DCDC_MASK),
135 TPS65217_INFO("DCDC3", 900000, 1500000, tps65217_vsel_to_uv1, 133 TPS65217_INFO("DCDC3", 900000, 1500000, tps65217_vsel_to_uv1,
136 tps65217_uv_to_vsel1, NULL, 64, TPS65217_ENABLE_DC3_EN, 134 tps65217_uv_to_vsel1),
137 TPS65217_REG_DEFDCDC3, TPS65217_DEFDCDCX_DCDC_MASK), 135 TPS65217_INFO("LDO1", 1000000, 3300000, NULL, NULL),
138 TPS65217_INFO("LDO1", 1000000, 3300000, NULL, NULL, LDO1_VSEL_table,
139 16, TPS65217_ENABLE_LDO1_EN, TPS65217_REG_DEFLDO1,
140 TPS65217_DEFLDO1_LDO1_MASK),
141 TPS65217_INFO("LDO2", 900000, 3300000, tps65217_vsel_to_uv1, 136 TPS65217_INFO("LDO2", 900000, 3300000, tps65217_vsel_to_uv1,
142 tps65217_uv_to_vsel1, NULL, 64, TPS65217_ENABLE_LDO2_EN, 137 tps65217_uv_to_vsel1),
143 TPS65217_REG_DEFLDO2, TPS65217_DEFLDO2_LDO2_MASK),
144 TPS65217_INFO("LDO3", 1800000, 3300000, tps65217_vsel_to_uv2, 138 TPS65217_INFO("LDO3", 1800000, 3300000, tps65217_vsel_to_uv2,
145 tps65217_uv_to_vsel2, NULL, 32, 139 tps65217_uv_to_vsel2),
146 TPS65217_ENABLE_LS1_EN | TPS65217_DEFLDO3_LDO3_EN,
147 TPS65217_REG_DEFLS1, TPS65217_DEFLDO3_LDO3_MASK),
148 TPS65217_INFO("LDO4", 1800000, 3300000, tps65217_vsel_to_uv2, 140 TPS65217_INFO("LDO4", 1800000, 3300000, tps65217_vsel_to_uv2,
149 tps65217_uv_to_vsel2, NULL, 32, 141 tps65217_uv_to_vsel2),
150 TPS65217_ENABLE_LS2_EN | TPS65217_DEFLDO4_LDO4_EN,
151 TPS65217_REG_DEFLS2, TPS65217_DEFLDO4_LDO4_MASK),
152}; 142};
153 143
154static int tps65217_pmic_is_enabled(struct regulator_dev *dev)
155{
156 int ret;
157 struct tps65217 *tps = rdev_get_drvdata(dev);
158 unsigned int data, rid = rdev_get_id(dev);
159
160 if (rid < TPS65217_DCDC_1 || rid > TPS65217_LDO_4)
161 return -EINVAL;
162
163 ret = tps65217_reg_read(tps, TPS65217_REG_ENABLE, &data);
164 if (ret)
165 return ret;
166
167 return (data & tps->info[rid]->enable_mask) ? 1 : 0;
168}
169
170static int tps65217_pmic_enable(struct regulator_dev *dev) 144static int tps65217_pmic_enable(struct regulator_dev *dev)
171{ 145{
172 struct tps65217 *tps = rdev_get_drvdata(dev); 146 struct tps65217 *tps = rdev_get_drvdata(dev);
@@ -177,9 +151,8 @@ static int tps65217_pmic_enable(struct regulator_dev *dev)
177 151
178 /* Enable the regulator and password protection is level 1 */ 152 /* Enable the regulator and password protection is level 1 */
179 return tps65217_set_bits(tps, TPS65217_REG_ENABLE, 153 return tps65217_set_bits(tps, TPS65217_REG_ENABLE,
180 tps->info[rid]->enable_mask, 154 dev->desc->enable_mask, dev->desc->enable_mask,
181 tps->info[rid]->enable_mask, 155 TPS65217_PROTECT_L1);
182 TPS65217_PROTECT_L1);
183} 156}
184 157
185static int tps65217_pmic_disable(struct regulator_dev *dev) 158static int tps65217_pmic_disable(struct regulator_dev *dev)
@@ -192,25 +165,7 @@ static int tps65217_pmic_disable(struct regulator_dev *dev)
192 165
193 /* Disable the regulator and password protection is level 1 */ 166 /* Disable the regulator and password protection is level 1 */
194 return tps65217_clear_bits(tps, TPS65217_REG_ENABLE, 167 return tps65217_clear_bits(tps, TPS65217_REG_ENABLE,
195 tps->info[rid]->enable_mask, TPS65217_PROTECT_L1); 168 dev->desc->enable_mask, TPS65217_PROTECT_L1);
196}
197
198static int tps65217_pmic_get_voltage_sel(struct regulator_dev *dev)
199{
200 int ret;
201 struct tps65217 *tps = rdev_get_drvdata(dev);
202 unsigned int selector, rid = rdev_get_id(dev);
203
204 if (rid < TPS65217_DCDC_1 || rid > TPS65217_LDO_4)
205 return -EINVAL;
206
207 ret = tps65217_reg_read(tps, tps->info[rid]->set_vout_reg, &selector);
208 if (ret)
209 return ret;
210
211 selector &= tps->info[rid]->set_vout_mask;
212
213 return selector;
214} 169}
215 170
216static int tps65217_pmic_set_voltage_sel(struct regulator_dev *dev, 171static int tps65217_pmic_set_voltage_sel(struct regulator_dev *dev,
@@ -221,8 +176,7 @@ static int tps65217_pmic_set_voltage_sel(struct regulator_dev *dev,
221 unsigned int rid = rdev_get_id(dev); 176 unsigned int rid = rdev_get_id(dev);
222 177
223 /* Set the voltage based on vsel value and write protect level is 2 */ 178 /* Set the voltage based on vsel value and write protect level is 2 */
224 ret = tps65217_set_bits(tps, tps->info[rid]->set_vout_reg, 179 ret = tps65217_set_bits(tps, dev->desc->vsel_reg, dev->desc->vsel_mask,
225 tps->info[rid]->set_vout_mask,
226 selector, TPS65217_PROTECT_L2); 180 selector, TPS65217_PROTECT_L2);
227 181
228 /* Set GO bit for DCDCx to initiate voltage transistion */ 182 /* Set GO bit for DCDCx to initiate voltage transistion */
@@ -252,10 +206,10 @@ static int tps65217_pmic_map_voltage(struct regulator_dev *dev,
252 if (rid < TPS65217_DCDC_1 || rid > TPS65217_LDO_4) 206 if (rid < TPS65217_DCDC_1 || rid > TPS65217_LDO_4)
253 return -EINVAL; 207 return -EINVAL;
254 208
255 if (min_uV < tps->info[rid]->min_uV || min_uV > tps->info[rid]->max_uV) 209 if (min_uV < tps->info[rid]->min_uV)
256 return -EINVAL; 210 min_uV = tps->info[rid]->min_uV;
257 211
258 if (max_uV < tps->info[rid]->min_uV || max_uV > tps->info[rid]->max_uV) 212 if (max_uV < tps->info[rid]->min_uV || min_uV > tps->info[rid]->max_uV)
259 return -EINVAL; 213 return -EINVAL;
260 214
261 ret = tps->info[rid]->uv_to_vsel(min_uV, &sel); 215 ret = tps->info[rid]->uv_to_vsel(min_uV, &sel);
@@ -274,21 +228,18 @@ static int tps65217_pmic_list_voltage(struct regulator_dev *dev,
274 if (rid < TPS65217_DCDC_1 || rid > TPS65217_LDO_4) 228 if (rid < TPS65217_DCDC_1 || rid > TPS65217_LDO_4)
275 return -EINVAL; 229 return -EINVAL;
276 230
277 if (selector >= tps->info[rid]->table_len) 231 if (selector >= dev->desc->n_voltages)
278 return -EINVAL; 232 return -EINVAL;
279 233
280 if (tps->info[rid]->table)
281 return tps->info[rid]->table[selector];
282
283 return tps->info[rid]->vsel_to_uv(selector); 234 return tps->info[rid]->vsel_to_uv(selector);
284} 235}
285 236
286/* Operations permitted on DCDCx, LDO2, LDO3 and LDO4 */ 237/* Operations permitted on DCDCx, LDO2, LDO3 and LDO4 */
287static struct regulator_ops tps65217_pmic_ops = { 238static struct regulator_ops tps65217_pmic_ops = {
288 .is_enabled = tps65217_pmic_is_enabled, 239 .is_enabled = regulator_is_enabled_regmap,
289 .enable = tps65217_pmic_enable, 240 .enable = tps65217_pmic_enable,
290 .disable = tps65217_pmic_disable, 241 .disable = tps65217_pmic_disable,
291 .get_voltage_sel = tps65217_pmic_get_voltage_sel, 242 .get_voltage_sel = regulator_get_voltage_sel_regmap,
292 .set_voltage_sel = tps65217_pmic_set_voltage_sel, 243 .set_voltage_sel = tps65217_pmic_set_voltage_sel,
293 .list_voltage = tps65217_pmic_list_voltage, 244 .list_voltage = tps65217_pmic_list_voltage,
294 .map_voltage = tps65217_pmic_map_voltage, 245 .map_voltage = tps65217_pmic_map_voltage,
@@ -296,22 +247,38 @@ static struct regulator_ops tps65217_pmic_ops = {
296 247
297/* Operations permitted on LDO1 */ 248/* Operations permitted on LDO1 */
298static struct regulator_ops tps65217_pmic_ldo1_ops = { 249static struct regulator_ops tps65217_pmic_ldo1_ops = {
299 .is_enabled = tps65217_pmic_is_enabled, 250 .is_enabled = regulator_is_enabled_regmap,
300 .enable = tps65217_pmic_enable, 251 .enable = tps65217_pmic_enable,
301 .disable = tps65217_pmic_disable, 252 .disable = tps65217_pmic_disable,
302 .get_voltage_sel = tps65217_pmic_get_voltage_sel, 253 .get_voltage_sel = regulator_get_voltage_sel_regmap,
303 .set_voltage_sel = tps65217_pmic_set_voltage_sel, 254 .set_voltage_sel = tps65217_pmic_set_voltage_sel,
304 .list_voltage = tps65217_pmic_list_voltage, 255 .list_voltage = regulator_list_voltage_table,
305}; 256};
306 257
307static const struct regulator_desc regulators[] = { 258static const struct regulator_desc regulators[] = {
308 TPS65217_REGULATOR("DCDC1", TPS65217_DCDC_1, tps65217_pmic_ops, 64), 259 TPS65217_REGULATOR("DCDC1", TPS65217_DCDC_1, tps65217_pmic_ops, 64,
309 TPS65217_REGULATOR("DCDC2", TPS65217_DCDC_2, tps65217_pmic_ops, 64), 260 TPS65217_REG_DEFDCDC1, TPS65217_DEFDCDCX_DCDC_MASK,
310 TPS65217_REGULATOR("DCDC3", TPS65217_DCDC_3, tps65217_pmic_ops, 64), 261 TPS65217_ENABLE_DC1_EN, NULL),
311 TPS65217_REGULATOR("LDO1", TPS65217_LDO_1, tps65217_pmic_ldo1_ops, 16), 262 TPS65217_REGULATOR("DCDC2", TPS65217_DCDC_2, tps65217_pmic_ops, 64,
312 TPS65217_REGULATOR("LDO2", TPS65217_LDO_2, tps65217_pmic_ops, 64), 263 TPS65217_REG_DEFDCDC2, TPS65217_DEFDCDCX_DCDC_MASK,
313 TPS65217_REGULATOR("LDO3", TPS65217_LDO_3, tps65217_pmic_ops, 32), 264 TPS65217_ENABLE_DC2_EN, NULL),
314 TPS65217_REGULATOR("LDO4", TPS65217_LDO_4, tps65217_pmic_ops, 32), 265 TPS65217_REGULATOR("DCDC3", TPS65217_DCDC_3, tps65217_pmic_ops, 64,
266 TPS65217_REG_DEFDCDC3, TPS65217_DEFDCDCX_DCDC_MASK,
267 TPS65217_ENABLE_DC3_EN, NULL),
268 TPS65217_REGULATOR("LDO1", TPS65217_LDO_1, tps65217_pmic_ldo1_ops, 16,
269 TPS65217_REG_DEFLDO1, TPS65217_DEFLDO1_LDO1_MASK,
270 TPS65217_ENABLE_LDO1_EN, LDO1_VSEL_table),
271 TPS65217_REGULATOR("LDO2", TPS65217_LDO_2, tps65217_pmic_ops, 64,
272 TPS65217_REG_DEFLDO2, TPS65217_DEFLDO2_LDO2_MASK,
273 TPS65217_ENABLE_LDO2_EN, NULL),
274 TPS65217_REGULATOR("LDO3", TPS65217_LDO_3, tps65217_pmic_ops, 32,
275 TPS65217_REG_DEFLS1, TPS65217_DEFLDO3_LDO3_MASK,
276 TPS65217_ENABLE_LS1_EN | TPS65217_DEFLDO3_LDO3_EN,
277 NULL),
278 TPS65217_REGULATOR("LDO4", TPS65217_LDO_4, tps65217_pmic_ops, 32,
279 TPS65217_REG_DEFLS2, TPS65217_DEFLDO4_LDO4_MASK,
280 TPS65217_ENABLE_LS2_EN | TPS65217_DEFLDO4_LDO4_EN,
281 NULL),
315}; 282};
316 283
317static int __devinit tps65217_regulator_probe(struct platform_device *pdev) 284static int __devinit tps65217_regulator_probe(struct platform_device *pdev)
@@ -326,6 +293,7 @@ static int __devinit tps65217_regulator_probe(struct platform_device *pdev)
326 tps->info[pdev->id] = info; 293 tps->info[pdev->id] = info;
327 294
328 config.dev = &pdev->dev; 295 config.dev = &pdev->dev;
296 config.of_node = pdev->dev.of_node;
329 config.init_data = pdev->dev.platform_data; 297 config.init_data = pdev->dev.platform_data;
330 config.driver_data = tps; 298 config.driver_data = tps;
331 299
diff --git a/drivers/regulator/tps6524x-regulator.c b/drivers/regulator/tps6524x-regulator.c
index 1b299aacf22f..947ece933d90 100644
--- a/drivers/regulator/tps6524x-regulator.c
+++ b/drivers/regulator/tps6524x-regulator.c
@@ -110,9 +110,6 @@
110#define N_SWITCH 2 110#define N_SWITCH 2
111#define N_REGULATORS (N_DCDC + N_LDO + N_SWITCH) 111#define N_REGULATORS (N_DCDC + N_LDO + N_SWITCH)
112 112
113#define FIXED_ILIMSEL BIT(0)
114#define FIXED_VOLTAGE BIT(1)
115
116#define CMD_READ(reg) ((reg) << 6) 113#define CMD_READ(reg) ((reg) << 6)
117#define CMD_WRITE(reg) (BIT(5) | (reg) << 6) 114#define CMD_WRITE(reg) (BIT(5) | (reg) << 6)
118#define STAT_CLK BIT(3) 115#define STAT_CLK BIT(3)
@@ -129,12 +126,9 @@ struct field {
129struct supply_info { 126struct supply_info {
130 const char *name; 127 const char *name;
131 int n_voltages; 128 int n_voltages;
132 const int *voltages; 129 const unsigned int *voltages;
133 int fixed_voltage;
134 int n_ilimsels; 130 int n_ilimsels;
135 const int *ilimsels; 131 const unsigned int *ilimsels;
136 int fixed_ilimsel;
137 int flags;
138 struct field enable, voltage, ilimsel; 132 struct field enable, voltage, ilimsel;
139}; 133};
140 134
@@ -307,7 +301,7 @@ static int write_field(struct tps6524x *hw, const struct field *field,
307 val << field->shift); 301 val << field->shift);
308} 302}
309 303
310static const int dcdc1_voltages[] = { 304static const unsigned int dcdc1_voltages[] = {
311 800000, 825000, 850000, 875000, 305 800000, 825000, 850000, 875000,
312 900000, 925000, 950000, 975000, 306 900000, 925000, 950000, 975000,
313 1000000, 1025000, 1050000, 1075000, 307 1000000, 1025000, 1050000, 1075000,
@@ -318,7 +312,7 @@ static const int dcdc1_voltages[] = {
318 1500000, 1525000, 1550000, 1575000, 312 1500000, 1525000, 1550000, 1575000,
319}; 313};
320 314
321static const int dcdc2_voltages[] = { 315static const unsigned int dcdc2_voltages[] = {
322 1400000, 1450000, 1500000, 1550000, 316 1400000, 1450000, 1500000, 1550000,
323 1600000, 1650000, 1700000, 1750000, 317 1600000, 1650000, 1700000, 1750000,
324 1800000, 1850000, 1900000, 1950000, 318 1800000, 1850000, 1900000, 1950000,
@@ -329,7 +323,7 @@ static const int dcdc2_voltages[] = {
329 2800000, 2850000, 2900000, 2950000, 323 2800000, 2850000, 2900000, 2950000,
330}; 324};
331 325
332static const int dcdc3_voltages[] = { 326static const unsigned int dcdc3_voltages[] = {
333 2400000, 2450000, 2500000, 2550000, 2600000, 327 2400000, 2450000, 2500000, 2550000, 2600000,
334 2650000, 2700000, 2750000, 2800000, 2850000, 328 2650000, 2700000, 2750000, 2800000, 2850000,
335 2900000, 2950000, 3000000, 3050000, 3100000, 329 2900000, 2950000, 3000000, 3050000, 3100000,
@@ -337,38 +331,54 @@ static const int dcdc3_voltages[] = {
337 3400000, 3450000, 3500000, 3550000, 3600000, 331 3400000, 3450000, 3500000, 3550000, 3600000,
338}; 332};
339 333
340static const int ldo1_voltages[] = { 334static const unsigned int ldo1_voltages[] = {
341 4300000, 4350000, 4400000, 4450000, 335 4300000, 4350000, 4400000, 4450000,
342 4500000, 4550000, 4600000, 4650000, 336 4500000, 4550000, 4600000, 4650000,
343 4700000, 4750000, 4800000, 4850000, 337 4700000, 4750000, 4800000, 4850000,
344 4900000, 4950000, 5000000, 5050000, 338 4900000, 4950000, 5000000, 5050000,
345}; 339};
346 340
347static const int ldo2_voltages[] = { 341static const unsigned int ldo2_voltages[] = {
348 1100000, 1150000, 1200000, 1250000, 342 1100000, 1150000, 1200000, 1250000,
349 1300000, 1700000, 1750000, 1800000, 343 1300000, 1700000, 1750000, 1800000,
350 1850000, 1900000, 3150000, 3200000, 344 1850000, 1900000, 3150000, 3200000,
351 3250000, 3300000, 3350000, 3400000, 345 3250000, 3300000, 3350000, 3400000,
352}; 346};
353 347
354static const int ldo_ilimsel[] = { 348static const unsigned int fixed_5000000_voltage[] = {
349 5000000
350};
351
352static const unsigned int ldo_ilimsel[] = {
355 400000, 1500000 353 400000, 1500000
356}; 354};
357 355
358static const int usb_ilimsel[] = { 356static const unsigned int usb_ilimsel[] = {
359 200000, 400000, 800000, 1000000 357 200000, 400000, 800000, 1000000
360}; 358};
361 359
360static const unsigned int fixed_2400000_ilimsel[] = {
361 2400000
362};
363
364static const unsigned int fixed_1200000_ilimsel[] = {
365 1200000
366};
367
368static const unsigned int fixed_400000_ilimsel[] = {
369 400000
370};
371
362#define __MK_FIELD(_reg, _mask, _shift) \ 372#define __MK_FIELD(_reg, _mask, _shift) \
363 { .reg = (_reg), .mask = (_mask), .shift = (_shift), } 373 { .reg = (_reg), .mask = (_mask), .shift = (_shift), }
364 374
365static const struct supply_info supply_info[N_REGULATORS] = { 375static const struct supply_info supply_info[N_REGULATORS] = {
366 { 376 {
367 .name = "DCDC1", 377 .name = "DCDC1",
368 .flags = FIXED_ILIMSEL,
369 .n_voltages = ARRAY_SIZE(dcdc1_voltages), 378 .n_voltages = ARRAY_SIZE(dcdc1_voltages),
370 .voltages = dcdc1_voltages, 379 .voltages = dcdc1_voltages,
371 .fixed_ilimsel = 2400000, 380 .n_ilimsels = ARRAY_SIZE(fixed_2400000_ilimsel),
381 .ilimsels = fixed_2400000_ilimsel,
372 .enable = __MK_FIELD(REG_DCDC_EN, DCDCDCDC_EN_MASK, 382 .enable = __MK_FIELD(REG_DCDC_EN, DCDCDCDC_EN_MASK,
373 DCDCDCDC1_EN_SHIFT), 383 DCDCDCDC1_EN_SHIFT),
374 .voltage = __MK_FIELD(REG_DCDC_SET, DCDC_VDCDC_MASK, 384 .voltage = __MK_FIELD(REG_DCDC_SET, DCDC_VDCDC_MASK,
@@ -376,10 +386,10 @@ static const struct supply_info supply_info[N_REGULATORS] = {
376 }, 386 },
377 { 387 {
378 .name = "DCDC2", 388 .name = "DCDC2",
379 .flags = FIXED_ILIMSEL,
380 .n_voltages = ARRAY_SIZE(dcdc2_voltages), 389 .n_voltages = ARRAY_SIZE(dcdc2_voltages),
381 .voltages = dcdc2_voltages, 390 .voltages = dcdc2_voltages,
382 .fixed_ilimsel = 1200000, 391 .n_ilimsels = ARRAY_SIZE(fixed_1200000_ilimsel),
392 .ilimsels = fixed_1200000_ilimsel,
383 .enable = __MK_FIELD(REG_DCDC_EN, DCDCDCDC_EN_MASK, 393 .enable = __MK_FIELD(REG_DCDC_EN, DCDCDCDC_EN_MASK,
384 DCDCDCDC2_EN_SHIFT), 394 DCDCDCDC2_EN_SHIFT),
385 .voltage = __MK_FIELD(REG_DCDC_SET, DCDC_VDCDC_MASK, 395 .voltage = __MK_FIELD(REG_DCDC_SET, DCDC_VDCDC_MASK,
@@ -387,10 +397,10 @@ static const struct supply_info supply_info[N_REGULATORS] = {
387 }, 397 },
388 { 398 {
389 .name = "DCDC3", 399 .name = "DCDC3",
390 .flags = FIXED_ILIMSEL,
391 .n_voltages = ARRAY_SIZE(dcdc3_voltages), 400 .n_voltages = ARRAY_SIZE(dcdc3_voltages),
392 .voltages = dcdc3_voltages, 401 .voltages = dcdc3_voltages,
393 .fixed_ilimsel = 1200000, 402 .n_ilimsels = ARRAY_SIZE(fixed_1200000_ilimsel),
403 .ilimsels = fixed_1200000_ilimsel,
394 .enable = __MK_FIELD(REG_DCDC_EN, DCDCDCDC_EN_MASK, 404 .enable = __MK_FIELD(REG_DCDC_EN, DCDCDCDC_EN_MASK,
395 DCDCDCDC3_EN_SHIFT), 405 DCDCDCDC3_EN_SHIFT),
396 .voltage = __MK_FIELD(REG_DCDC_SET, DCDC_VDCDC_MASK, 406 .voltage = __MK_FIELD(REG_DCDC_SET, DCDC_VDCDC_MASK,
@@ -424,8 +434,8 @@ static const struct supply_info supply_info[N_REGULATORS] = {
424 }, 434 },
425 { 435 {
426 .name = "USB", 436 .name = "USB",
427 .flags = FIXED_VOLTAGE, 437 .n_voltages = ARRAY_SIZE(fixed_5000000_voltage),
428 .fixed_voltage = 5000000, 438 .voltages = fixed_5000000_voltage,
429 .n_ilimsels = ARRAY_SIZE(usb_ilimsel), 439 .n_ilimsels = ARRAY_SIZE(usb_ilimsel),
430 .ilimsels = usb_ilimsel, 440 .ilimsels = usb_ilimsel,
431 .enable = __MK_FIELD(REG_BLOCK_EN, BLOCK_MASK, 441 .enable = __MK_FIELD(REG_BLOCK_EN, BLOCK_MASK,
@@ -435,29 +445,15 @@ static const struct supply_info supply_info[N_REGULATORS] = {
435 }, 445 },
436 { 446 {
437 .name = "LCD", 447 .name = "LCD",
438 .flags = FIXED_VOLTAGE | FIXED_ILIMSEL, 448 .n_voltages = ARRAY_SIZE(fixed_5000000_voltage),
439 .fixed_voltage = 5000000, 449 .voltages = fixed_5000000_voltage,
440 .fixed_ilimsel = 400000, 450 .n_ilimsels = ARRAY_SIZE(fixed_400000_ilimsel),
451 .ilimsels = fixed_400000_ilimsel,
441 .enable = __MK_FIELD(REG_BLOCK_EN, BLOCK_MASK, 452 .enable = __MK_FIELD(REG_BLOCK_EN, BLOCK_MASK,
442 BLOCK_LCD_SHIFT), 453 BLOCK_LCD_SHIFT),
443 }, 454 },
444}; 455};
445 456
446static int list_voltage(struct regulator_dev *rdev, unsigned selector)
447{
448 const struct supply_info *info;
449 struct tps6524x *hw;
450
451 hw = rdev_get_drvdata(rdev);
452 info = &supply_info[rdev_get_id(rdev)];
453
454 if (info->flags & FIXED_VOLTAGE)
455 return selector ? -EINVAL : info->fixed_voltage;
456
457 return ((selector < info->n_voltages) ?
458 info->voltages[selector] : -EINVAL);
459}
460
461static int set_voltage_sel(struct regulator_dev *rdev, unsigned selector) 457static int set_voltage_sel(struct regulator_dev *rdev, unsigned selector)
462{ 458{
463 const struct supply_info *info; 459 const struct supply_info *info;
@@ -466,7 +462,7 @@ static int set_voltage_sel(struct regulator_dev *rdev, unsigned selector)
466 hw = rdev_get_drvdata(rdev); 462 hw = rdev_get_drvdata(rdev);
467 info = &supply_info[rdev_get_id(rdev)]; 463 info = &supply_info[rdev_get_id(rdev)];
468 464
469 if (info->flags & FIXED_VOLTAGE) 465 if (rdev->desc->n_voltages == 1)
470 return -EINVAL; 466 return -EINVAL;
471 467
472 return write_field(hw, &info->voltage, selector); 468 return write_field(hw, &info->voltage, selector);
@@ -481,7 +477,7 @@ static int get_voltage_sel(struct regulator_dev *rdev)
481 hw = rdev_get_drvdata(rdev); 477 hw = rdev_get_drvdata(rdev);
482 info = &supply_info[rdev_get_id(rdev)]; 478 info = &supply_info[rdev_get_id(rdev)];
483 479
484 if (info->flags & FIXED_VOLTAGE) 480 if (rdev->desc->n_voltages == 1)
485 return 0; 481 return 0;
486 482
487 ret = read_field(hw, &info->voltage); 483 ret = read_field(hw, &info->voltage);
@@ -503,7 +499,7 @@ static int set_current_limit(struct regulator_dev *rdev, int min_uA,
503 hw = rdev_get_drvdata(rdev); 499 hw = rdev_get_drvdata(rdev);
504 info = &supply_info[rdev_get_id(rdev)]; 500 info = &supply_info[rdev_get_id(rdev)];
505 501
506 if (info->flags & FIXED_ILIMSEL) 502 if (info->n_ilimsels == 1)
507 return -EINVAL; 503 return -EINVAL;
508 504
509 for (i = 0; i < info->n_ilimsels; i++) 505 for (i = 0; i < info->n_ilimsels; i++)
@@ -526,8 +522,8 @@ static int get_current_limit(struct regulator_dev *rdev)
526 hw = rdev_get_drvdata(rdev); 522 hw = rdev_get_drvdata(rdev);
527 info = &supply_info[rdev_get_id(rdev)]; 523 info = &supply_info[rdev_get_id(rdev)];
528 524
529 if (info->flags & FIXED_ILIMSEL) 525 if (info->n_ilimsels == 1)
530 return info->fixed_ilimsel; 526 return info->ilimsels[0];
531 527
532 ret = read_field(hw, &info->ilimsel); 528 ret = read_field(hw, &info->ilimsel);
533 if (ret < 0) 529 if (ret < 0)
@@ -577,7 +573,7 @@ static struct regulator_ops regulator_ops = {
577 .disable = disable_supply, 573 .disable = disable_supply,
578 .get_voltage_sel = get_voltage_sel, 574 .get_voltage_sel = get_voltage_sel,
579 .set_voltage_sel = set_voltage_sel, 575 .set_voltage_sel = set_voltage_sel,
580 .list_voltage = list_voltage, 576 .list_voltage = regulator_list_voltage_table,
581 .set_current_limit = set_current_limit, 577 .set_current_limit = set_current_limit,
582 .get_current_limit = get_current_limit, 578 .get_current_limit = get_current_limit,
583}; 579};
@@ -629,13 +625,11 @@ static int __devinit pmic_probe(struct spi_device *spi)
629 hw->desc[i].name = info->name; 625 hw->desc[i].name = info->name;
630 hw->desc[i].id = i; 626 hw->desc[i].id = i;
631 hw->desc[i].n_voltages = info->n_voltages; 627 hw->desc[i].n_voltages = info->n_voltages;
628 hw->desc[i].volt_table = info->voltages;
632 hw->desc[i].ops = &regulator_ops; 629 hw->desc[i].ops = &regulator_ops;
633 hw->desc[i].type = REGULATOR_VOLTAGE; 630 hw->desc[i].type = REGULATOR_VOLTAGE;
634 hw->desc[i].owner = THIS_MODULE; 631 hw->desc[i].owner = THIS_MODULE;
635 632
636 if (info->flags & FIXED_VOLTAGE)
637 hw->desc[i].n_voltages = 1;
638
639 config.dev = dev; 633 config.dev = dev;
640 config.init_data = init_data; 634 config.init_data = init_data;
641 config.driver_data = hw; 635 config.driver_data = hw;
diff --git a/drivers/regulator/tps6586x-regulator.c b/drivers/regulator/tps6586x-regulator.c
index c0a214575380..e6da90ab5153 100644
--- a/drivers/regulator/tps6586x-regulator.c
+++ b/drivers/regulator/tps6586x-regulator.c
@@ -63,8 +63,6 @@ struct tps6586x_regulator {
63 int enable_bit[2]; 63 int enable_bit[2];
64 int enable_reg[2]; 64 int enable_reg[2];
65 65
66 int *voltages;
67
68 /* for DVM regulators */ 66 /* for DVM regulators */
69 int go_reg; 67 int go_reg;
70 int go_bit; 68 int go_bit;
@@ -72,22 +70,9 @@ struct tps6586x_regulator {
72 70
73static inline struct device *to_tps6586x_dev(struct regulator_dev *rdev) 71static inline struct device *to_tps6586x_dev(struct regulator_dev *rdev)
74{ 72{
75 return rdev_get_dev(rdev)->parent->parent; 73 return rdev_get_dev(rdev)->parent;
76} 74}
77 75
78static int tps6586x_list_voltage(struct regulator_dev *rdev, unsigned selector)
79{
80 struct tps6586x_regulator *info = rdev_get_drvdata(rdev);
81 int rid = rdev_get_id(rdev);
82
83 /* LDO0 has minimal voltage 1.2V rather than 1.25V */
84 if ((rid == TPS6586X_ID_LDO_0) && (selector == 0))
85 return (info->voltages[0] - 50) * 1000;
86
87 return info->voltages[selector] * 1000;
88}
89
90
91static int tps6586x_set_voltage_sel(struct regulator_dev *rdev, 76static int tps6586x_set_voltage_sel(struct regulator_dev *rdev,
92 unsigned selector) 77 unsigned selector)
93{ 78{
@@ -168,7 +153,7 @@ static int tps6586x_regulator_is_enabled(struct regulator_dev *rdev)
168} 153}
169 154
170static struct regulator_ops tps6586x_regulator_ops = { 155static struct regulator_ops tps6586x_regulator_ops = {
171 .list_voltage = tps6586x_list_voltage, 156 .list_voltage = regulator_list_voltage_table,
172 .get_voltage_sel = tps6586x_get_voltage_sel, 157 .get_voltage_sel = tps6586x_get_voltage_sel,
173 .set_voltage_sel = tps6586x_set_voltage_sel, 158 .set_voltage_sel = tps6586x_set_voltage_sel,
174 159
@@ -177,39 +162,45 @@ static struct regulator_ops tps6586x_regulator_ops = {
177 .disable = tps6586x_regulator_disable, 162 .disable = tps6586x_regulator_disable,
178}; 163};
179 164
180static int tps6586x_ldo_voltages[] = { 165static const unsigned int tps6586x_ldo0_voltages[] = {
181 1250, 1500, 1800, 2500, 2700, 2850, 3100, 3300, 166 1200000, 1500000, 1800000, 2500000, 2700000, 2850000, 3100000, 3300000,
167};
168
169static const unsigned int tps6586x_ldo4_voltages[] = {
170 1700000, 1725000, 1750000, 1775000, 1800000, 1825000, 1850000, 1875000,
171 1900000, 1925000, 1950000, 1975000, 2000000, 2025000, 2050000, 2075000,
172 2100000, 2125000, 2150000, 2175000, 2200000, 2225000, 2250000, 2275000,
173 2300000, 2325000, 2350000, 2375000, 2400000, 2425000, 2450000, 2475000,
182}; 174};
183 175
184static int tps6586x_ldo4_voltages[] = { 176static const unsigned int tps6586x_ldo_voltages[] = {
185 1700, 1725, 1750, 1775, 1800, 1825, 1850, 1875, 177 1250000, 1500000, 1800000, 2500000, 2700000, 2850000, 3100000, 3300000,
186 1900, 1925, 1950, 1975, 2000, 2025, 2050, 2075,
187 2100, 2125, 2150, 2175, 2200, 2225, 2250, 2275,
188 2300, 2325, 2350, 2375, 2400, 2425, 2450, 2475,
189}; 178};
190 179
191static int tps6586x_sm2_voltages[] = { 180static const unsigned int tps6586x_sm2_voltages[] = {
192 3000, 3050, 3100, 3150, 3200, 3250, 3300, 3350, 181 3000000, 3050000, 3100000, 3150000, 3200000, 3250000, 3300000, 3350000,
193 3400, 3450, 3500, 3550, 3600, 3650, 3700, 3750, 182 3400000, 3450000, 3500000, 3550000, 3600000, 3650000, 3700000, 3750000,
194 3800, 3850, 3900, 3950, 4000, 4050, 4100, 4150, 183 3800000, 3850000, 3900000, 3950000, 4000000, 4050000, 4100000, 4150000,
195 4200, 4250, 4300, 4350, 4400, 4450, 4500, 4550, 184 4200000, 4250000, 4300000, 4350000, 4400000, 4450000, 4500000, 4550000,
196}; 185};
197 186
198static int tps6586x_dvm_voltages[] = { 187static const unsigned int tps6586x_dvm_voltages[] = {
199 725, 750, 775, 800, 825, 850, 875, 900, 188 725000, 750000, 775000, 800000, 825000, 850000, 875000, 900000,
200 925, 950, 975, 1000, 1025, 1050, 1075, 1100, 189 925000, 950000, 975000, 1000000, 1025000, 1050000, 1075000, 1100000,
201 1125, 1150, 1175, 1200, 1225, 1250, 1275, 1300, 190 1125000, 1150000, 1175000, 1200000, 1225000, 1250000, 1275000, 1300000,
202 1325, 1350, 1375, 1400, 1425, 1450, 1475, 1500, 191 1325000, 1350000, 1375000, 1400000, 1425000, 1450000, 1475000, 1500000,
203}; 192};
204 193
205#define TPS6586X_REGULATOR(_id, vdata, vreg, shift, nbits, \ 194#define TPS6586X_REGULATOR(_id, _pin_name, vdata, vreg, shift, nbits, \
206 ereg0, ebit0, ereg1, ebit1) \ 195 ereg0, ebit0, ereg1, ebit1) \
207 .desc = { \ 196 .desc = { \
197 .supply_name = _pin_name, \
208 .name = "REG-" #_id, \ 198 .name = "REG-" #_id, \
209 .ops = &tps6586x_regulator_ops, \ 199 .ops = &tps6586x_regulator_ops, \
210 .type = REGULATOR_VOLTAGE, \ 200 .type = REGULATOR_VOLTAGE, \
211 .id = TPS6586X_ID_##_id, \ 201 .id = TPS6586X_ID_##_id, \
212 .n_voltages = ARRAY_SIZE(tps6586x_##vdata##_voltages), \ 202 .n_voltages = ARRAY_SIZE(tps6586x_##vdata##_voltages), \
203 .volt_table = tps6586x_##vdata##_voltages, \
213 .owner = THIS_MODULE, \ 204 .owner = THIS_MODULE, \
214 }, \ 205 }, \
215 .volt_reg = TPS6586X_##vreg, \ 206 .volt_reg = TPS6586X_##vreg, \
@@ -218,44 +209,45 @@ static int tps6586x_dvm_voltages[] = {
218 .enable_reg[0] = TPS6586X_SUPPLY##ereg0, \ 209 .enable_reg[0] = TPS6586X_SUPPLY##ereg0, \
219 .enable_bit[0] = (ebit0), \ 210 .enable_bit[0] = (ebit0), \
220 .enable_reg[1] = TPS6586X_SUPPLY##ereg1, \ 211 .enable_reg[1] = TPS6586X_SUPPLY##ereg1, \
221 .enable_bit[1] = (ebit1), \ 212 .enable_bit[1] = (ebit1),
222 .voltages = tps6586x_##vdata##_voltages,
223 213
224#define TPS6586X_REGULATOR_DVM_GOREG(goreg, gobit) \ 214#define TPS6586X_REGULATOR_DVM_GOREG(goreg, gobit) \
225 .go_reg = TPS6586X_##goreg, \ 215 .go_reg = TPS6586X_##goreg, \
226 .go_bit = (gobit), 216 .go_bit = (gobit),
227 217
228#define TPS6586X_LDO(_id, vdata, vreg, shift, nbits, \ 218#define TPS6586X_LDO(_id, _pname, vdata, vreg, shift, nbits, \
229 ereg0, ebit0, ereg1, ebit1) \ 219 ereg0, ebit0, ereg1, ebit1) \
230{ \ 220{ \
231 TPS6586X_REGULATOR(_id, vdata, vreg, shift, nbits, \ 221 TPS6586X_REGULATOR(_id, _pname, vdata, vreg, shift, nbits, \
232 ereg0, ebit0, ereg1, ebit1) \ 222 ereg0, ebit0, ereg1, ebit1) \
233} 223}
234 224
235#define TPS6586X_DVM(_id, vdata, vreg, shift, nbits, \ 225#define TPS6586X_DVM(_id, _pname, vdata, vreg, shift, nbits, \
236 ereg0, ebit0, ereg1, ebit1, goreg, gobit) \ 226 ereg0, ebit0, ereg1, ebit1, goreg, gobit) \
237{ \ 227{ \
238 TPS6586X_REGULATOR(_id, vdata, vreg, shift, nbits, \ 228 TPS6586X_REGULATOR(_id, _pname, vdata, vreg, shift, nbits, \
239 ereg0, ebit0, ereg1, ebit1) \ 229 ereg0, ebit0, ereg1, ebit1) \
240 TPS6586X_REGULATOR_DVM_GOREG(goreg, gobit) \ 230 TPS6586X_REGULATOR_DVM_GOREG(goreg, gobit) \
241} 231}
242 232
243static struct tps6586x_regulator tps6586x_regulator[] = { 233static struct tps6586x_regulator tps6586x_regulator[] = {
244 TPS6586X_LDO(LDO_0, ldo, SUPPLYV1, 5, 3, ENC, 0, END, 0), 234 TPS6586X_LDO(LDO_0, "vinldo01", ldo0, SUPPLYV1, 5, 3, ENC, 0, END, 0),
245 TPS6586X_LDO(LDO_3, ldo, SUPPLYV4, 0, 3, ENC, 2, END, 2), 235 TPS6586X_LDO(LDO_3, "vinldo23", ldo, SUPPLYV4, 0, 3, ENC, 2, END, 2),
246 TPS6586X_LDO(LDO_5, ldo, SUPPLYV6, 0, 3, ENE, 6, ENE, 6), 236 TPS6586X_LDO(LDO_5, NULL, ldo, SUPPLYV6, 0, 3, ENE, 6, ENE, 6),
247 TPS6586X_LDO(LDO_6, ldo, SUPPLYV3, 0, 3, ENC, 4, END, 4), 237 TPS6586X_LDO(LDO_6, "vinldo678", ldo, SUPPLYV3, 0, 3, ENC, 4, END, 4),
248 TPS6586X_LDO(LDO_7, ldo, SUPPLYV3, 3, 3, ENC, 5, END, 5), 238 TPS6586X_LDO(LDO_7, "vinldo678", ldo, SUPPLYV3, 3, 3, ENC, 5, END, 5),
249 TPS6586X_LDO(LDO_8, ldo, SUPPLYV2, 5, 3, ENC, 6, END, 6), 239 TPS6586X_LDO(LDO_8, "vinldo678", ldo, SUPPLYV2, 5, 3, ENC, 6, END, 6),
250 TPS6586X_LDO(LDO_9, ldo, SUPPLYV6, 3, 3, ENE, 7, ENE, 7), 240 TPS6586X_LDO(LDO_9, "vinldo9", ldo, SUPPLYV6, 3, 3, ENE, 7, ENE, 7),
251 TPS6586X_LDO(LDO_RTC, ldo, SUPPLYV4, 3, 3, V4, 7, V4, 7), 241 TPS6586X_LDO(LDO_RTC, NULL, ldo, SUPPLYV4, 3, 3, V4, 7, V4, 7),
252 TPS6586X_LDO(LDO_1, dvm, SUPPLYV1, 0, 5, ENC, 1, END, 1), 242 TPS6586X_LDO(LDO_1, "vinldo01", dvm, SUPPLYV1, 0, 5, ENC, 1, END, 1),
253 TPS6586X_LDO(SM_2, sm2, SUPPLYV2, 0, 5, ENC, 7, END, 7), 243 TPS6586X_LDO(SM_2, "sm2", sm2, SUPPLYV2, 0, 5, ENC, 7, END, 7),
254 244
255 TPS6586X_DVM(LDO_2, dvm, LDO2BV1, 0, 5, ENA, 3, ENB, 3, VCC2, 6), 245 TPS6586X_DVM(LDO_2, "vinldo23", dvm, LDO2BV1, 0, 5, ENA, 3,
256 TPS6586X_DVM(LDO_4, ldo4, LDO4V1, 0, 5, ENC, 3, END, 3, VCC1, 6), 246 ENB, 3, VCC2, 6),
257 TPS6586X_DVM(SM_0, dvm, SM0V1, 0, 5, ENA, 1, ENB, 1, VCC1, 2), 247 TPS6586X_DVM(LDO_4, "vinldo4", ldo4, LDO4V1, 0, 5, ENC, 3,
258 TPS6586X_DVM(SM_1, dvm, SM1V1, 0, 5, ENA, 0, ENB, 0, VCC1, 0), 248 END, 3, VCC1, 6),
249 TPS6586X_DVM(SM_0, "sm0", dvm, SM0V1, 0, 5, ENA, 1, ENB, 1, VCC1, 2),
250 TPS6586X_DVM(SM_1, "sm1", dvm, SM1V1, 0, 5, ENA, 0, ENB, 0, VCC1, 0),
259}; 251};
260 252
261/* 253/*
@@ -362,7 +354,7 @@ static int __devinit tps6586x_regulator_probe(struct platform_device *pdev)
362 if (err) 354 if (err)
363 return err; 355 return err;
364 356
365 config.dev = &pdev->dev; 357 config.dev = pdev->dev.parent;
366 config.of_node = pdev->dev.of_node; 358 config.of_node = pdev->dev.of_node;
367 config.init_data = pdev->dev.platform_data; 359 config.init_data = pdev->dev.platform_data;
368 config.driver_data = ri; 360 config.driver_data = ri;
diff --git a/drivers/regulator/tps65910-regulator.c b/drivers/regulator/tps65910-regulator.c
index 6bf864b4bdf6..793adda560c3 100644
--- a/drivers/regulator/tps65910-regulator.c
+++ b/drivers/regulator/tps65910-regulator.c
@@ -31,160 +31,147 @@
31 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3 | \ 31 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3 | \
32 TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP) 32 TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP)
33 33
34/* supported VIO voltages in millivolts */ 34/* supported VIO voltages in microvolts */
35static const u16 VIO_VSEL_table[] = { 35static const unsigned int VIO_VSEL_table[] = {
36 1500, 1800, 2500, 3300, 36 1500000, 1800000, 2500000, 3300000,
37}; 37};
38 38
39/* VSEL tables for TPS65910 specific LDOs and dcdc's */ 39/* VSEL tables for TPS65910 specific LDOs and dcdc's */
40 40
41/* supported VDD3 voltages in millivolts */ 41/* supported VDD3 voltages in microvolts */
42static const u16 VDD3_VSEL_table[] = { 42static const unsigned int VDD3_VSEL_table[] = {
43 5000, 43 5000000,
44}; 44};
45 45
46/* supported VDIG1 voltages in millivolts */ 46/* supported VDIG1 voltages in microvolts */
47static const u16 VDIG1_VSEL_table[] = { 47static const unsigned int VDIG1_VSEL_table[] = {
48 1200, 1500, 1800, 2700, 48 1200000, 1500000, 1800000, 2700000,
49}; 49};
50 50
51/* supported VDIG2 voltages in millivolts */ 51/* supported VDIG2 voltages in microvolts */
52static const u16 VDIG2_VSEL_table[] = { 52static const unsigned int VDIG2_VSEL_table[] = {
53 1000, 1100, 1200, 1800, 53 1000000, 1100000, 1200000, 1800000,
54}; 54};
55 55
56/* supported VPLL voltages in millivolts */ 56/* supported VPLL voltages in microvolts */
57static const u16 VPLL_VSEL_table[] = { 57static const unsigned int VPLL_VSEL_table[] = {
58 1000, 1100, 1800, 2500, 58 1000000, 1100000, 1800000, 2500000,
59}; 59};
60 60
61/* supported VDAC voltages in millivolts */ 61/* supported VDAC voltages in microvolts */
62static const u16 VDAC_VSEL_table[] = { 62static const unsigned int VDAC_VSEL_table[] = {
63 1800, 2600, 2800, 2850, 63 1800000, 2600000, 2800000, 2850000,
64}; 64};
65 65
66/* supported VAUX1 voltages in millivolts */ 66/* supported VAUX1 voltages in microvolts */
67static const u16 VAUX1_VSEL_table[] = { 67static const unsigned int VAUX1_VSEL_table[] = {
68 1800, 2500, 2800, 2850, 68 1800000, 2500000, 2800000, 2850000,
69}; 69};
70 70
71/* supported VAUX2 voltages in millivolts */ 71/* supported VAUX2 voltages in microvolts */
72static const u16 VAUX2_VSEL_table[] = { 72static const unsigned int VAUX2_VSEL_table[] = {
73 1800, 2800, 2900, 3300, 73 1800000, 2800000, 2900000, 3300000,
74}; 74};
75 75
76/* supported VAUX33 voltages in millivolts */ 76/* supported VAUX33 voltages in microvolts */
77static const u16 VAUX33_VSEL_table[] = { 77static const unsigned int VAUX33_VSEL_table[] = {
78 1800, 2000, 2800, 3300, 78 1800000, 2000000, 2800000, 3300000,
79}; 79};
80 80
81/* supported VMMC voltages in millivolts */ 81/* supported VMMC voltages in microvolts */
82static const u16 VMMC_VSEL_table[] = { 82static const unsigned int VMMC_VSEL_table[] = {
83 1800, 2800, 3000, 3300, 83 1800000, 2800000, 3000000, 3300000,
84}; 84};
85 85
86struct tps_info { 86struct tps_info {
87 const char *name; 87 const char *name;
88 unsigned min_uV; 88 const char *vin_name;
89 unsigned max_uV;
90 u8 n_voltages; 89 u8 n_voltages;
91 const u16 *voltage_table; 90 const unsigned int *voltage_table;
92 int enable_time_us; 91 int enable_time_us;
93}; 92};
94 93
95static struct tps_info tps65910_regs[] = { 94static struct tps_info tps65910_regs[] = {
96 { 95 {
97 .name = "vrtc", 96 .name = "vrtc",
97 .vin_name = "vcc7",
98 .enable_time_us = 2200, 98 .enable_time_us = 2200,
99 }, 99 },
100 { 100 {
101 .name = "vio", 101 .name = "vio",
102 .min_uV = 1500000, 102 .vin_name = "vccio",
103 .max_uV = 3300000,
104 .n_voltages = ARRAY_SIZE(VIO_VSEL_table), 103 .n_voltages = ARRAY_SIZE(VIO_VSEL_table),
105 .voltage_table = VIO_VSEL_table, 104 .voltage_table = VIO_VSEL_table,
106 .enable_time_us = 350, 105 .enable_time_us = 350,
107 }, 106 },
108 { 107 {
109 .name = "vdd1", 108 .name = "vdd1",
110 .min_uV = 600000, 109 .vin_name = "vcc1",
111 .max_uV = 4500000,
112 .enable_time_us = 350, 110 .enable_time_us = 350,
113 }, 111 },
114 { 112 {
115 .name = "vdd2", 113 .name = "vdd2",
116 .min_uV = 600000, 114 .vin_name = "vcc2",
117 .max_uV = 4500000,
118 .enable_time_us = 350, 115 .enable_time_us = 350,
119 }, 116 },
120 { 117 {
121 .name = "vdd3", 118 .name = "vdd3",
122 .min_uV = 5000000,
123 .max_uV = 5000000,
124 .n_voltages = ARRAY_SIZE(VDD3_VSEL_table), 119 .n_voltages = ARRAY_SIZE(VDD3_VSEL_table),
125 .voltage_table = VDD3_VSEL_table, 120 .voltage_table = VDD3_VSEL_table,
126 .enable_time_us = 200, 121 .enable_time_us = 200,
127 }, 122 },
128 { 123 {
129 .name = "vdig1", 124 .name = "vdig1",
130 .min_uV = 1200000, 125 .vin_name = "vcc6",
131 .max_uV = 2700000,
132 .n_voltages = ARRAY_SIZE(VDIG1_VSEL_table), 126 .n_voltages = ARRAY_SIZE(VDIG1_VSEL_table),
133 .voltage_table = VDIG1_VSEL_table, 127 .voltage_table = VDIG1_VSEL_table,
134 .enable_time_us = 100, 128 .enable_time_us = 100,
135 }, 129 },
136 { 130 {
137 .name = "vdig2", 131 .name = "vdig2",
138 .min_uV = 1000000, 132 .vin_name = "vcc6",
139 .max_uV = 1800000,
140 .n_voltages = ARRAY_SIZE(VDIG2_VSEL_table), 133 .n_voltages = ARRAY_SIZE(VDIG2_VSEL_table),
141 .voltage_table = VDIG2_VSEL_table, 134 .voltage_table = VDIG2_VSEL_table,
142 .enable_time_us = 100, 135 .enable_time_us = 100,
143 }, 136 },
144 { 137 {
145 .name = "vpll", 138 .name = "vpll",
146 .min_uV = 1000000, 139 .vin_name = "vcc5",
147 .max_uV = 2500000,
148 .n_voltages = ARRAY_SIZE(VPLL_VSEL_table), 140 .n_voltages = ARRAY_SIZE(VPLL_VSEL_table),
149 .voltage_table = VPLL_VSEL_table, 141 .voltage_table = VPLL_VSEL_table,
150 .enable_time_us = 100, 142 .enable_time_us = 100,
151 }, 143 },
152 { 144 {
153 .name = "vdac", 145 .name = "vdac",
154 .min_uV = 1800000, 146 .vin_name = "vcc5",
155 .max_uV = 2850000,
156 .n_voltages = ARRAY_SIZE(VDAC_VSEL_table), 147 .n_voltages = ARRAY_SIZE(VDAC_VSEL_table),
157 .voltage_table = VDAC_VSEL_table, 148 .voltage_table = VDAC_VSEL_table,
158 .enable_time_us = 100, 149 .enable_time_us = 100,
159 }, 150 },
160 { 151 {
161 .name = "vaux1", 152 .name = "vaux1",
162 .min_uV = 1800000, 153 .vin_name = "vcc4",
163 .max_uV = 2850000,
164 .n_voltages = ARRAY_SIZE(VAUX1_VSEL_table), 154 .n_voltages = ARRAY_SIZE(VAUX1_VSEL_table),
165 .voltage_table = VAUX1_VSEL_table, 155 .voltage_table = VAUX1_VSEL_table,
166 .enable_time_us = 100, 156 .enable_time_us = 100,
167 }, 157 },
168 { 158 {
169 .name = "vaux2", 159 .name = "vaux2",
170 .min_uV = 1800000, 160 .vin_name = "vcc4",
171 .max_uV = 3300000,
172 .n_voltages = ARRAY_SIZE(VAUX2_VSEL_table), 161 .n_voltages = ARRAY_SIZE(VAUX2_VSEL_table),
173 .voltage_table = VAUX2_VSEL_table, 162 .voltage_table = VAUX2_VSEL_table,
174 .enable_time_us = 100, 163 .enable_time_us = 100,
175 }, 164 },
176 { 165 {
177 .name = "vaux33", 166 .name = "vaux33",
178 .min_uV = 1800000, 167 .vin_name = "vcc3",
179 .max_uV = 3300000,
180 .n_voltages = ARRAY_SIZE(VAUX33_VSEL_table), 168 .n_voltages = ARRAY_SIZE(VAUX33_VSEL_table),
181 .voltage_table = VAUX33_VSEL_table, 169 .voltage_table = VAUX33_VSEL_table,
182 .enable_time_us = 100, 170 .enable_time_us = 100,
183 }, 171 },
184 { 172 {
185 .name = "vmmc", 173 .name = "vmmc",
186 .min_uV = 1800000, 174 .vin_name = "vcc3",
187 .max_uV = 3300000,
188 .n_voltages = ARRAY_SIZE(VMMC_VSEL_table), 175 .n_voltages = ARRAY_SIZE(VMMC_VSEL_table),
189 .voltage_table = VMMC_VSEL_table, 176 .voltage_table = VMMC_VSEL_table,
190 .enable_time_us = 100, 177 .enable_time_us = 100,
@@ -194,91 +181,79 @@ static struct tps_info tps65910_regs[] = {
194static struct tps_info tps65911_regs[] = { 181static struct tps_info tps65911_regs[] = {
195 { 182 {
196 .name = "vrtc", 183 .name = "vrtc",
184 .vin_name = "vcc7",
197 .enable_time_us = 2200, 185 .enable_time_us = 2200,
198 }, 186 },
199 { 187 {
200 .name = "vio", 188 .name = "vio",
201 .min_uV = 1500000, 189 .vin_name = "vccio",
202 .max_uV = 3300000,
203 .n_voltages = ARRAY_SIZE(VIO_VSEL_table), 190 .n_voltages = ARRAY_SIZE(VIO_VSEL_table),
204 .voltage_table = VIO_VSEL_table, 191 .voltage_table = VIO_VSEL_table,
205 .enable_time_us = 350, 192 .enable_time_us = 350,
206 }, 193 },
207 { 194 {
208 .name = "vdd1", 195 .name = "vdd1",
209 .min_uV = 600000, 196 .vin_name = "vcc1",
210 .max_uV = 4500000, 197 .n_voltages = 0x4C,
211 .n_voltages = 73,
212 .enable_time_us = 350, 198 .enable_time_us = 350,
213 }, 199 },
214 { 200 {
215 .name = "vdd2", 201 .name = "vdd2",
216 .min_uV = 600000, 202 .vin_name = "vcc2",
217 .max_uV = 4500000, 203 .n_voltages = 0x4C,
218 .n_voltages = 73,
219 .enable_time_us = 350, 204 .enable_time_us = 350,
220 }, 205 },
221 { 206 {
222 .name = "vddctrl", 207 .name = "vddctrl",
223 .min_uV = 600000, 208 .n_voltages = 0x44,
224 .max_uV = 1400000,
225 .n_voltages = 65,
226 .enable_time_us = 900, 209 .enable_time_us = 900,
227 }, 210 },
228 { 211 {
229 .name = "ldo1", 212 .name = "ldo1",
230 .min_uV = 1000000, 213 .vin_name = "vcc6",
231 .max_uV = 3300000, 214 .n_voltages = 0x33,
232 .n_voltages = 47,
233 .enable_time_us = 420, 215 .enable_time_us = 420,
234 }, 216 },
235 { 217 {
236 .name = "ldo2", 218 .name = "ldo2",
237 .min_uV = 1000000, 219 .vin_name = "vcc6",
238 .max_uV = 3300000, 220 .n_voltages = 0x33,
239 .n_voltages = 47,
240 .enable_time_us = 420, 221 .enable_time_us = 420,
241 }, 222 },
242 { 223 {
243 .name = "ldo3", 224 .name = "ldo3",
244 .min_uV = 1000000, 225 .vin_name = "vcc5",
245 .max_uV = 3300000, 226 .n_voltages = 0x1A,
246 .n_voltages = 24,
247 .enable_time_us = 230, 227 .enable_time_us = 230,
248 }, 228 },
249 { 229 {
250 .name = "ldo4", 230 .name = "ldo4",
251 .min_uV = 1000000, 231 .vin_name = "vcc5",
252 .max_uV = 3300000, 232 .n_voltages = 0x33,
253 .n_voltages = 47,
254 .enable_time_us = 230, 233 .enable_time_us = 230,
255 }, 234 },
256 { 235 {
257 .name = "ldo5", 236 .name = "ldo5",
258 .min_uV = 1000000, 237 .vin_name = "vcc4",
259 .max_uV = 3300000, 238 .n_voltages = 0x1A,
260 .n_voltages = 24,
261 .enable_time_us = 230, 239 .enable_time_us = 230,
262 }, 240 },
263 { 241 {
264 .name = "ldo6", 242 .name = "ldo6",
265 .min_uV = 1000000, 243 .vin_name = "vcc3",
266 .max_uV = 3300000, 244 .n_voltages = 0x1A,
267 .n_voltages = 24,
268 .enable_time_us = 230, 245 .enable_time_us = 230,
269 }, 246 },
270 { 247 {
271 .name = "ldo7", 248 .name = "ldo7",
272 .min_uV = 1000000, 249 .vin_name = "vcc3",
273 .max_uV = 3300000, 250 .n_voltages = 0x1A,
274 .n_voltages = 24,
275 .enable_time_us = 230, 251 .enable_time_us = 230,
276 }, 252 },
277 { 253 {
278 .name = "ldo8", 254 .name = "ldo8",
279 .min_uV = 1000000, 255 .vin_name = "vcc3",
280 .max_uV = 3300000, 256 .n_voltages = 0x1A,
281 .n_voltages = 24,
282 .enable_time_us = 230, 257 .enable_time_us = 230,
283 }, 258 },
284}; 259};
@@ -321,7 +296,6 @@ struct tps65910_reg {
321 struct tps65910 *mfd; 296 struct tps65910 *mfd;
322 struct regulator_dev **rdev; 297 struct regulator_dev **rdev;
323 struct tps_info **info; 298 struct tps_info **info;
324 struct mutex mutex;
325 int num_regulators; 299 int num_regulators;
326 int mode; 300 int mode;
327 int (*get_ctrl_reg)(int); 301 int (*get_ctrl_reg)(int);
@@ -329,71 +303,6 @@ struct tps65910_reg {
329 unsigned int board_ext_control[TPS65910_NUM_REGS]; 303 unsigned int board_ext_control[TPS65910_NUM_REGS];
330}; 304};
331 305
332static inline int tps65910_read(struct tps65910_reg *pmic, u8 reg)
333{
334 unsigned int val;
335 int err;
336
337 err = tps65910_reg_read(pmic->mfd, reg, &val);
338 if (err)
339 return err;
340
341 return val;
342}
343
344static int tps65910_modify_bits(struct tps65910_reg *pmic, u8 reg,
345 u8 set_mask, u8 clear_mask)
346{
347 int err, data;
348
349 mutex_lock(&pmic->mutex);
350
351 data = tps65910_read(pmic, reg);
352 if (data < 0) {
353 dev_err(pmic->mfd->dev, "Read from reg 0x%x failed\n", reg);
354 err = data;
355 goto out;
356 }
357
358 data &= ~clear_mask;
359 data |= set_mask;
360 err = tps65910_reg_write(pmic->mfd, reg, data);
361 if (err)
362 dev_err(pmic->mfd->dev, "Write for reg 0x%x failed\n", reg);
363
364out:
365 mutex_unlock(&pmic->mutex);
366 return err;
367}
368
369static int tps65910_reg_read_locked(struct tps65910_reg *pmic, u8 reg)
370{
371 int data;
372
373 mutex_lock(&pmic->mutex);
374
375 data = tps65910_read(pmic, reg);
376 if (data < 0)
377 dev_err(pmic->mfd->dev, "Read from reg 0x%x failed\n", reg);
378
379 mutex_unlock(&pmic->mutex);
380 return data;
381}
382
383static int tps65910_reg_write_locked(struct tps65910_reg *pmic, u8 reg, u8 val)
384{
385 int err;
386
387 mutex_lock(&pmic->mutex);
388
389 err = tps65910_reg_write(pmic->mfd, reg, val);
390 if (err < 0)
391 dev_err(pmic->mfd->dev, "Write for reg 0x%x failed\n", reg);
392
393 mutex_unlock(&pmic->mutex);
394 return err;
395}
396
397static int tps65910_get_ctrl_register(int id) 306static int tps65910_get_ctrl_register(int id)
398{ 307{
399 switch (id) { 308 switch (id) {
@@ -462,13 +371,6 @@ static int tps65911_get_ctrl_register(int id)
462 } 371 }
463} 372}
464 373
465static int tps65910_enable_time(struct regulator_dev *dev)
466{
467 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
468 int id = rdev_get_id(dev);
469 return pmic->info[id]->enable_time_us;
470}
471
472static int tps65910_set_mode(struct regulator_dev *dev, unsigned int mode) 374static int tps65910_set_mode(struct regulator_dev *dev, unsigned int mode)
473{ 375{
474 struct tps65910_reg *pmic = rdev_get_drvdata(dev); 376 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
@@ -481,8 +383,9 @@ static int tps65910_set_mode(struct regulator_dev *dev, unsigned int mode)
481 383
482 switch (mode) { 384 switch (mode) {
483 case REGULATOR_MODE_NORMAL: 385 case REGULATOR_MODE_NORMAL:
484 return tps65910_modify_bits(pmic, reg, LDO_ST_ON_BIT, 386 return tps65910_reg_update_bits(pmic->mfd, reg,
485 LDO_ST_MODE_BIT); 387 LDO_ST_MODE_BIT | LDO_ST_ON_BIT,
388 LDO_ST_ON_BIT);
486 case REGULATOR_MODE_IDLE: 389 case REGULATOR_MODE_IDLE:
487 value = LDO_ST_ON_BIT | LDO_ST_MODE_BIT; 390 value = LDO_ST_ON_BIT | LDO_ST_MODE_BIT;
488 return tps65910_reg_set_bits(mfd, reg, value); 391 return tps65910_reg_set_bits(mfd, reg, value);
@@ -496,15 +399,15 @@ static int tps65910_set_mode(struct regulator_dev *dev, unsigned int mode)
496static unsigned int tps65910_get_mode(struct regulator_dev *dev) 399static unsigned int tps65910_get_mode(struct regulator_dev *dev)
497{ 400{
498 struct tps65910_reg *pmic = rdev_get_drvdata(dev); 401 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
499 int reg, value, id = rdev_get_id(dev); 402 int ret, reg, value, id = rdev_get_id(dev);
500 403
501 reg = pmic->get_ctrl_reg(id); 404 reg = pmic->get_ctrl_reg(id);
502 if (reg < 0) 405 if (reg < 0)
503 return reg; 406 return reg;
504 407
505 value = tps65910_reg_read_locked(pmic, reg); 408 ret = tps65910_reg_read(pmic->mfd, reg, &value);
506 if (value < 0) 409 if (ret < 0)
507 return value; 410 return ret;
508 411
509 if (!(value & LDO_ST_ON_BIT)) 412 if (!(value & LDO_ST_ON_BIT))
510 return REGULATOR_MODE_STANDBY; 413 return REGULATOR_MODE_STANDBY;
@@ -517,33 +420,51 @@ static unsigned int tps65910_get_mode(struct regulator_dev *dev)
517static int tps65910_get_voltage_dcdc_sel(struct regulator_dev *dev) 420static int tps65910_get_voltage_dcdc_sel(struct regulator_dev *dev)
518{ 421{
519 struct tps65910_reg *pmic = rdev_get_drvdata(dev); 422 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
520 int id = rdev_get_id(dev); 423 int ret, id = rdev_get_id(dev);
521 int opvsel = 0, srvsel = 0, vselmax = 0, mult = 0, sr = 0; 424 int opvsel = 0, srvsel = 0, vselmax = 0, mult = 0, sr = 0;
522 425
523 switch (id) { 426 switch (id) {
524 case TPS65910_REG_VDD1: 427 case TPS65910_REG_VDD1:
525 opvsel = tps65910_reg_read_locked(pmic, TPS65910_VDD1_OP); 428 ret = tps65910_reg_read(pmic->mfd, TPS65910_VDD1_OP, &opvsel);
526 mult = tps65910_reg_read_locked(pmic, TPS65910_VDD1); 429 if (ret < 0)
430 return ret;
431 ret = tps65910_reg_read(pmic->mfd, TPS65910_VDD1, &mult);
432 if (ret < 0)
433 return ret;
527 mult = (mult & VDD1_VGAIN_SEL_MASK) >> VDD1_VGAIN_SEL_SHIFT; 434 mult = (mult & VDD1_VGAIN_SEL_MASK) >> VDD1_VGAIN_SEL_SHIFT;
528 srvsel = tps65910_reg_read_locked(pmic, TPS65910_VDD1_SR); 435 ret = tps65910_reg_read(pmic->mfd, TPS65910_VDD1_SR, &srvsel);
436 if (ret < 0)
437 return ret;
529 sr = opvsel & VDD1_OP_CMD_MASK; 438 sr = opvsel & VDD1_OP_CMD_MASK;
530 opvsel &= VDD1_OP_SEL_MASK; 439 opvsel &= VDD1_OP_SEL_MASK;
531 srvsel &= VDD1_SR_SEL_MASK; 440 srvsel &= VDD1_SR_SEL_MASK;
532 vselmax = 75; 441 vselmax = 75;
533 break; 442 break;
534 case TPS65910_REG_VDD2: 443 case TPS65910_REG_VDD2:
535 opvsel = tps65910_reg_read_locked(pmic, TPS65910_VDD2_OP); 444 ret = tps65910_reg_read(pmic->mfd, TPS65910_VDD2_OP, &opvsel);
536 mult = tps65910_reg_read_locked(pmic, TPS65910_VDD2); 445 if (ret < 0)
446 return ret;
447 ret = tps65910_reg_read(pmic->mfd, TPS65910_VDD2, &mult);
448 if (ret < 0)
449 return ret;
537 mult = (mult & VDD2_VGAIN_SEL_MASK) >> VDD2_VGAIN_SEL_SHIFT; 450 mult = (mult & VDD2_VGAIN_SEL_MASK) >> VDD2_VGAIN_SEL_SHIFT;
538 srvsel = tps65910_reg_read_locked(pmic, TPS65910_VDD2_SR); 451 ret = tps65910_reg_read(pmic->mfd, TPS65910_VDD2_SR, &srvsel);
452 if (ret < 0)
453 return ret;
539 sr = opvsel & VDD2_OP_CMD_MASK; 454 sr = opvsel & VDD2_OP_CMD_MASK;
540 opvsel &= VDD2_OP_SEL_MASK; 455 opvsel &= VDD2_OP_SEL_MASK;
541 srvsel &= VDD2_SR_SEL_MASK; 456 srvsel &= VDD2_SR_SEL_MASK;
542 vselmax = 75; 457 vselmax = 75;
543 break; 458 break;
544 case TPS65911_REG_VDDCTRL: 459 case TPS65911_REG_VDDCTRL:
545 opvsel = tps65910_reg_read_locked(pmic, TPS65911_VDDCTRL_OP); 460 ret = tps65910_reg_read(pmic->mfd, TPS65911_VDDCTRL_OP,
546 srvsel = tps65910_reg_read_locked(pmic, TPS65911_VDDCTRL_SR); 461 &opvsel);
462 if (ret < 0)
463 return ret;
464 ret = tps65910_reg_read(pmic->mfd, TPS65911_VDDCTRL_SR,
465 &srvsel);
466 if (ret < 0)
467 return ret;
547 sr = opvsel & VDDCTRL_OP_CMD_MASK; 468 sr = opvsel & VDDCTRL_OP_CMD_MASK;
548 opvsel &= VDDCTRL_OP_SEL_MASK; 469 opvsel &= VDDCTRL_OP_SEL_MASK;
549 srvsel &= VDDCTRL_SR_SEL_MASK; 470 srvsel &= VDDCTRL_SR_SEL_MASK;
@@ -577,15 +498,15 @@ static int tps65910_get_voltage_dcdc_sel(struct regulator_dev *dev)
577static int tps65910_get_voltage_sel(struct regulator_dev *dev) 498static int tps65910_get_voltage_sel(struct regulator_dev *dev)
578{ 499{
579 struct tps65910_reg *pmic = rdev_get_drvdata(dev); 500 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
580 int reg, value, id = rdev_get_id(dev); 501 int ret, reg, value, id = rdev_get_id(dev);
581 502
582 reg = pmic->get_ctrl_reg(id); 503 reg = pmic->get_ctrl_reg(id);
583 if (reg < 0) 504 if (reg < 0)
584 return reg; 505 return reg;
585 506
586 value = tps65910_reg_read_locked(pmic, reg); 507 ret = tps65910_reg_read(pmic->mfd, reg, &value);
587 if (value < 0) 508 if (ret < 0)
588 return value; 509 return ret;
589 510
590 switch (id) { 511 switch (id) {
591 case TPS65910_REG_VIO: 512 case TPS65910_REG_VIO:
@@ -609,18 +530,20 @@ static int tps65910_get_voltage_sel(struct regulator_dev *dev)
609 530
610static int tps65910_get_voltage_vdd3(struct regulator_dev *dev) 531static int tps65910_get_voltage_vdd3(struct regulator_dev *dev)
611{ 532{
612 return 5 * 1000 * 1000; 533 return dev->desc->volt_table[0];
613} 534}
614 535
615static int tps65911_get_voltage_sel(struct regulator_dev *dev) 536static int tps65911_get_voltage_sel(struct regulator_dev *dev)
616{ 537{
617 struct tps65910_reg *pmic = rdev_get_drvdata(dev); 538 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
618 int id = rdev_get_id(dev); 539 int ret, id = rdev_get_id(dev);
619 u8 value, reg; 540 unsigned int value, reg;
620 541
621 reg = pmic->get_ctrl_reg(id); 542 reg = pmic->get_ctrl_reg(id);
622 543
623 value = tps65910_reg_read_locked(pmic, reg); 544 ret = tps65910_reg_read(pmic->mfd, reg, &value);
545 if (ret < 0)
546 return ret;
624 547
625 switch (id) { 548 switch (id) {
626 case TPS65911_REG_LDO1: 549 case TPS65911_REG_LDO1:
@@ -662,10 +585,10 @@ static int tps65910_set_voltage_dcdc_sel(struct regulator_dev *dev,
662 dcdc_mult--; 585 dcdc_mult--;
663 vsel = (selector % VDD1_2_NUM_VOLT_FINE) + 3; 586 vsel = (selector % VDD1_2_NUM_VOLT_FINE) + 3;
664 587
665 tps65910_modify_bits(pmic, TPS65910_VDD1, 588 tps65910_reg_update_bits(pmic->mfd, TPS65910_VDD1,
666 (dcdc_mult << VDD1_VGAIN_SEL_SHIFT), 589 VDD1_VGAIN_SEL_MASK,
667 VDD1_VGAIN_SEL_MASK); 590 dcdc_mult << VDD1_VGAIN_SEL_SHIFT);
668 tps65910_reg_write_locked(pmic, TPS65910_VDD1_OP, vsel); 591 tps65910_reg_write(pmic->mfd, TPS65910_VDD1_OP, vsel);
669 break; 592 break;
670 case TPS65910_REG_VDD2: 593 case TPS65910_REG_VDD2:
671 dcdc_mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1; 594 dcdc_mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1;
@@ -673,14 +596,14 @@ static int tps65910_set_voltage_dcdc_sel(struct regulator_dev *dev,
673 dcdc_mult--; 596 dcdc_mult--;
674 vsel = (selector % VDD1_2_NUM_VOLT_FINE) + 3; 597 vsel = (selector % VDD1_2_NUM_VOLT_FINE) + 3;
675 598
676 tps65910_modify_bits(pmic, TPS65910_VDD2, 599 tps65910_reg_update_bits(pmic->mfd, TPS65910_VDD2,
677 (dcdc_mult << VDD2_VGAIN_SEL_SHIFT), 600 VDD1_VGAIN_SEL_MASK,
678 VDD1_VGAIN_SEL_MASK); 601 dcdc_mult << VDD2_VGAIN_SEL_SHIFT);
679 tps65910_reg_write_locked(pmic, TPS65910_VDD2_OP, vsel); 602 tps65910_reg_write(pmic->mfd, TPS65910_VDD2_OP, vsel);
680 break; 603 break;
681 case TPS65911_REG_VDDCTRL: 604 case TPS65911_REG_VDDCTRL:
682 vsel = selector + 3; 605 vsel = selector + 3;
683 tps65910_reg_write_locked(pmic, TPS65911_VDDCTRL_OP, vsel); 606 tps65910_reg_write(pmic->mfd, TPS65911_VDDCTRL_OP, vsel);
684 } 607 }
685 608
686 return 0; 609 return 0;
@@ -706,8 +629,8 @@ static int tps65910_set_voltage_sel(struct regulator_dev *dev,
706 case TPS65910_REG_VAUX2: 629 case TPS65910_REG_VAUX2:
707 case TPS65910_REG_VAUX33: 630 case TPS65910_REG_VAUX33:
708 case TPS65910_REG_VMMC: 631 case TPS65910_REG_VMMC:
709 return tps65910_modify_bits(pmic, reg, 632 return tps65910_reg_update_bits(pmic->mfd, reg, LDO_SEL_MASK,
710 (selector << LDO_SEL_SHIFT), LDO_SEL_MASK); 633 selector << LDO_SEL_SHIFT);
711 } 634 }
712 635
713 return -EINVAL; 636 return -EINVAL;
@@ -727,18 +650,18 @@ static int tps65911_set_voltage_sel(struct regulator_dev *dev,
727 case TPS65911_REG_LDO1: 650 case TPS65911_REG_LDO1:
728 case TPS65911_REG_LDO2: 651 case TPS65911_REG_LDO2:
729 case TPS65911_REG_LDO4: 652 case TPS65911_REG_LDO4:
730 return tps65910_modify_bits(pmic, reg, 653 return tps65910_reg_update_bits(pmic->mfd, reg, LDO1_SEL_MASK,
731 (selector << LDO_SEL_SHIFT), LDO1_SEL_MASK); 654 selector << LDO_SEL_SHIFT);
732 case TPS65911_REG_LDO3: 655 case TPS65911_REG_LDO3:
733 case TPS65911_REG_LDO5: 656 case TPS65911_REG_LDO5:
734 case TPS65911_REG_LDO6: 657 case TPS65911_REG_LDO6:
735 case TPS65911_REG_LDO7: 658 case TPS65911_REG_LDO7:
736 case TPS65911_REG_LDO8: 659 case TPS65911_REG_LDO8:
737 return tps65910_modify_bits(pmic, reg, 660 return tps65910_reg_update_bits(pmic->mfd, reg, LDO3_SEL_MASK,
738 (selector << LDO_SEL_SHIFT), LDO3_SEL_MASK); 661 selector << LDO_SEL_SHIFT);
739 case TPS65910_REG_VIO: 662 case TPS65910_REG_VIO:
740 return tps65910_modify_bits(pmic, reg, 663 return tps65910_reg_update_bits(pmic->mfd, reg, LDO_SEL_MASK,
741 (selector << LDO_SEL_SHIFT), LDO_SEL_MASK); 664 selector << LDO_SEL_SHIFT);
742 } 665 }
743 666
744 return -EINVAL; 667 return -EINVAL;
@@ -768,23 +691,6 @@ static int tps65910_list_voltage_dcdc(struct regulator_dev *dev,
768 return volt * 100 * mult; 691 return volt * 100 * mult;
769} 692}
770 693
771static int tps65910_list_voltage(struct regulator_dev *dev,
772 unsigned selector)
773{
774 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
775 int id = rdev_get_id(dev), voltage;
776
777 if (id < TPS65910_REG_VIO || id > TPS65910_REG_VMMC)
778 return -EINVAL;
779
780 if (selector >= pmic->info[id]->n_voltages)
781 return -EINVAL;
782 else
783 voltage = pmic->info[id]->voltage_table[selector] * 1000;
784
785 return voltage;
786}
787
788static int tps65911_list_voltage(struct regulator_dev *dev, unsigned selector) 694static int tps65911_list_voltage(struct regulator_dev *dev, unsigned selector)
789{ 695{
790 struct tps65910_reg *pmic = rdev_get_drvdata(dev); 696 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
@@ -816,7 +722,7 @@ static int tps65911_list_voltage(struct regulator_dev *dev, unsigned selector)
816 step_mv = 100; 722 step_mv = 100;
817 break; 723 break;
818 case TPS65910_REG_VIO: 724 case TPS65910_REG_VIO:
819 return pmic->info[id]->voltage_table[selector] * 1000; 725 return pmic->info[id]->voltage_table[selector];
820 default: 726 default:
821 return -EINVAL; 727 return -EINVAL;
822 } 728 }
@@ -824,42 +730,16 @@ static int tps65911_list_voltage(struct regulator_dev *dev, unsigned selector)
824 return (LDO_MIN_VOLT + selector * step_mv) * 1000; 730 return (LDO_MIN_VOLT + selector * step_mv) * 1000;
825} 731}
826 732
827static int tps65910_set_voltage_dcdc_time_sel(struct regulator_dev *dev,
828 unsigned int old_selector, unsigned int new_selector)
829{
830 int id = rdev_get_id(dev);
831 int old_volt, new_volt;
832
833 old_volt = tps65910_list_voltage_dcdc(dev, old_selector);
834 if (old_volt < 0)
835 return old_volt;
836
837 new_volt = tps65910_list_voltage_dcdc(dev, new_selector);
838 if (new_volt < 0)
839 return new_volt;
840
841 /* VDD1 and VDD2 are 12.5mV/us, VDDCTRL is 100mV/20us */
842 switch (id) {
843 case TPS65910_REG_VDD1:
844 case TPS65910_REG_VDD2:
845 return DIV_ROUND_UP(abs(old_volt - new_volt), 12500);
846 case TPS65911_REG_VDDCTRL:
847 return DIV_ROUND_UP(abs(old_volt - new_volt), 5000);
848 }
849 return -EINVAL;
850}
851
852/* Regulator ops (except VRTC) */ 733/* Regulator ops (except VRTC) */
853static struct regulator_ops tps65910_ops_dcdc = { 734static struct regulator_ops tps65910_ops_dcdc = {
854 .is_enabled = regulator_is_enabled_regmap, 735 .is_enabled = regulator_is_enabled_regmap,
855 .enable = regulator_enable_regmap, 736 .enable = regulator_enable_regmap,
856 .disable = regulator_disable_regmap, 737 .disable = regulator_disable_regmap,
857 .enable_time = tps65910_enable_time,
858 .set_mode = tps65910_set_mode, 738 .set_mode = tps65910_set_mode,
859 .get_mode = tps65910_get_mode, 739 .get_mode = tps65910_get_mode,
860 .get_voltage_sel = tps65910_get_voltage_dcdc_sel, 740 .get_voltage_sel = tps65910_get_voltage_dcdc_sel,
861 .set_voltage_sel = tps65910_set_voltage_dcdc_sel, 741 .set_voltage_sel = tps65910_set_voltage_dcdc_sel,
862 .set_voltage_time_sel = tps65910_set_voltage_dcdc_time_sel, 742 .set_voltage_time_sel = regulator_set_voltage_time_sel,
863 .list_voltage = tps65910_list_voltage_dcdc, 743 .list_voltage = tps65910_list_voltage_dcdc,
864}; 744};
865 745
@@ -867,30 +747,27 @@ static struct regulator_ops tps65910_ops_vdd3 = {
867 .is_enabled = regulator_is_enabled_regmap, 747 .is_enabled = regulator_is_enabled_regmap,
868 .enable = regulator_enable_regmap, 748 .enable = regulator_enable_regmap,
869 .disable = regulator_disable_regmap, 749 .disable = regulator_disable_regmap,
870 .enable_time = tps65910_enable_time,
871 .set_mode = tps65910_set_mode, 750 .set_mode = tps65910_set_mode,
872 .get_mode = tps65910_get_mode, 751 .get_mode = tps65910_get_mode,
873 .get_voltage = tps65910_get_voltage_vdd3, 752 .get_voltage = tps65910_get_voltage_vdd3,
874 .list_voltage = tps65910_list_voltage, 753 .list_voltage = regulator_list_voltage_table,
875}; 754};
876 755
877static struct regulator_ops tps65910_ops = { 756static struct regulator_ops tps65910_ops = {
878 .is_enabled = regulator_is_enabled_regmap, 757 .is_enabled = regulator_is_enabled_regmap,
879 .enable = regulator_enable_regmap, 758 .enable = regulator_enable_regmap,
880 .disable = regulator_disable_regmap, 759 .disable = regulator_disable_regmap,
881 .enable_time = tps65910_enable_time,
882 .set_mode = tps65910_set_mode, 760 .set_mode = tps65910_set_mode,
883 .get_mode = tps65910_get_mode, 761 .get_mode = tps65910_get_mode,
884 .get_voltage_sel = tps65910_get_voltage_sel, 762 .get_voltage_sel = tps65910_get_voltage_sel,
885 .set_voltage_sel = tps65910_set_voltage_sel, 763 .set_voltage_sel = tps65910_set_voltage_sel,
886 .list_voltage = tps65910_list_voltage, 764 .list_voltage = regulator_list_voltage_table,
887}; 765};
888 766
889static struct regulator_ops tps65911_ops = { 767static struct regulator_ops tps65911_ops = {
890 .is_enabled = regulator_is_enabled_regmap, 768 .is_enabled = regulator_is_enabled_regmap,
891 .enable = regulator_enable_regmap, 769 .enable = regulator_enable_regmap,
892 .disable = regulator_disable_regmap, 770 .disable = regulator_disable_regmap,
893 .enable_time = tps65910_enable_time,
894 .set_mode = tps65910_set_mode, 771 .set_mode = tps65910_set_mode,
895 .get_mode = tps65910_get_mode, 772 .get_mode = tps65910_get_mode,
896 .get_voltage_sel = tps65911_get_voltage_sel, 773 .get_voltage_sel = tps65911_get_voltage_sel,
@@ -996,19 +873,27 @@ static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic,
996 (tps65910_chip_id(mfd) == TPS65911))) { 873 (tps65910_chip_id(mfd) == TPS65911))) {
997 int op_reg_add = pmic->get_ctrl_reg(id) + 1; 874 int op_reg_add = pmic->get_ctrl_reg(id) + 1;
998 int sr_reg_add = pmic->get_ctrl_reg(id) + 2; 875 int sr_reg_add = pmic->get_ctrl_reg(id) + 2;
999 int opvsel = tps65910_reg_read_locked(pmic, op_reg_add); 876 int opvsel, srvsel;
1000 int srvsel = tps65910_reg_read_locked(pmic, sr_reg_add); 877
878 ret = tps65910_reg_read(pmic->mfd, op_reg_add, &opvsel);
879 if (ret < 0)
880 return ret;
881 ret = tps65910_reg_read(pmic->mfd, sr_reg_add, &srvsel);
882 if (ret < 0)
883 return ret;
884
1001 if (opvsel & VDD1_OP_CMD_MASK) { 885 if (opvsel & VDD1_OP_CMD_MASK) {
1002 u8 reg_val = srvsel & VDD1_OP_SEL_MASK; 886 u8 reg_val = srvsel & VDD1_OP_SEL_MASK;
1003 ret = tps65910_reg_write_locked(pmic, op_reg_add, 887
1004 reg_val); 888 ret = tps65910_reg_write(pmic->mfd, op_reg_add,
889 reg_val);
1005 if (ret < 0) { 890 if (ret < 0) {
1006 dev_err(mfd->dev, 891 dev_err(mfd->dev,
1007 "Error in configuring op register\n"); 892 "Error in configuring op register\n");
1008 return ret; 893 return ret;
1009 } 894 }
1010 } 895 }
1011 ret = tps65910_reg_write_locked(pmic, sr_reg_add, 0); 896 ret = tps65910_reg_write(pmic->mfd, sr_reg_add, 0);
1012 if (ret < 0) { 897 if (ret < 0) {
1013 dev_err(mfd->dev, "Error in settting sr register\n"); 898 dev_err(mfd->dev, "Error in settting sr register\n");
1014 return ret; 899 return ret;
@@ -1126,6 +1011,7 @@ static struct tps65910_board *tps65910_parse_dt_reg_data(
1126 "ti,regulator-ext-sleep-control", &prop); 1011 "ti,regulator-ext-sleep-control", &prop);
1127 if (!ret) 1012 if (!ret)
1128 pmic_plat_data->regulator_ext_sleep_control[idx] = prop; 1013 pmic_plat_data->regulator_ext_sleep_control[idx] = prop;
1014
1129 } 1015 }
1130 1016
1131 return pmic_plat_data; 1017 return pmic_plat_data;
@@ -1136,7 +1022,7 @@ static inline struct tps65910_board *tps65910_parse_dt_reg_data(
1136 struct of_regulator_match **tps65910_reg_matches) 1022 struct of_regulator_match **tps65910_reg_matches)
1137{ 1023{
1138 *tps65910_reg_matches = NULL; 1024 *tps65910_reg_matches = NULL;
1139 return 0; 1025 return NULL;
1140} 1026}
1141#endif 1027#endif
1142 1028
@@ -1168,7 +1054,6 @@ static __devinit int tps65910_probe(struct platform_device *pdev)
1168 return -ENOMEM; 1054 return -ENOMEM;
1169 } 1055 }
1170 1056
1171 mutex_init(&pmic->mutex);
1172 pmic->mfd = tps65910; 1057 pmic->mfd = tps65910;
1173 platform_set_drvdata(pdev, pmic); 1058 platform_set_drvdata(pdev, pmic);
1174 1059
@@ -1229,23 +1114,31 @@ static __devinit int tps65910_probe(struct platform_device *pdev)
1229 pmic->info[i] = info; 1114 pmic->info[i] = info;
1230 1115
1231 pmic->desc[i].name = info->name; 1116 pmic->desc[i].name = info->name;
1117 pmic->desc[i].supply_name = info->vin_name;
1232 pmic->desc[i].id = i; 1118 pmic->desc[i].id = i;
1233 pmic->desc[i].n_voltages = info->n_voltages; 1119 pmic->desc[i].n_voltages = info->n_voltages;
1120 pmic->desc[i].enable_time = info->enable_time_us;
1234 1121
1235 if (i == TPS65910_REG_VDD1 || i == TPS65910_REG_VDD2) { 1122 if (i == TPS65910_REG_VDD1 || i == TPS65910_REG_VDD2) {
1236 pmic->desc[i].ops = &tps65910_ops_dcdc; 1123 pmic->desc[i].ops = &tps65910_ops_dcdc;
1237 pmic->desc[i].n_voltages = VDD1_2_NUM_VOLT_FINE * 1124 pmic->desc[i].n_voltages = VDD1_2_NUM_VOLT_FINE *
1238 VDD1_2_NUM_VOLT_COARSE; 1125 VDD1_2_NUM_VOLT_COARSE;
1126 pmic->desc[i].ramp_delay = 12500;
1239 } else if (i == TPS65910_REG_VDD3) { 1127 } else if (i == TPS65910_REG_VDD3) {
1240 if (tps65910_chip_id(tps65910) == TPS65910) 1128 if (tps65910_chip_id(tps65910) == TPS65910) {
1241 pmic->desc[i].ops = &tps65910_ops_vdd3; 1129 pmic->desc[i].ops = &tps65910_ops_vdd3;
1242 else 1130 pmic->desc[i].volt_table = info->voltage_table;
1131 } else {
1243 pmic->desc[i].ops = &tps65910_ops_dcdc; 1132 pmic->desc[i].ops = &tps65910_ops_dcdc;
1133 pmic->desc[i].ramp_delay = 5000;
1134 }
1244 } else { 1135 } else {
1245 if (tps65910_chip_id(tps65910) == TPS65910) 1136 if (tps65910_chip_id(tps65910) == TPS65910) {
1246 pmic->desc[i].ops = &tps65910_ops; 1137 pmic->desc[i].ops = &tps65910_ops;
1247 else 1138 pmic->desc[i].volt_table = info->voltage_table;
1139 } else {
1248 pmic->desc[i].ops = &tps65911_ops; 1140 pmic->desc[i].ops = &tps65911_ops;
1141 }
1249 } 1142 }
1250 1143
1251 err = tps65910_set_ext_sleep_config(pmic, i, 1144 err = tps65910_set_ext_sleep_config(pmic, i,
diff --git a/drivers/regulator/twl-regulator.c b/drivers/regulator/twl-regulator.c
index c7390711d954..242fe90dc565 100644
--- a/drivers/regulator/twl-regulator.c
+++ b/drivers/regulator/twl-regulator.c
@@ -43,9 +43,6 @@ struct twlreg_info {
43 u8 table_len; 43 u8 table_len;
44 const u16 *table; 44 const u16 *table;
45 45
46 /* regulator specific turn-on delay */
47 u16 delay;
48
49 /* State REMAP default configuration */ 46 /* State REMAP default configuration */
50 u8 remap; 47 u8 remap;
51 48
@@ -223,20 +220,6 @@ static int twl6030reg_enable(struct regulator_dev *rdev)
223 return ret; 220 return ret;
224} 221}
225 222
226static int twl4030reg_enable_time(struct regulator_dev *rdev)
227{
228 struct twlreg_info *info = rdev_get_drvdata(rdev);
229
230 return info->delay;
231}
232
233static int twl6030reg_enable_time(struct regulator_dev *rdev)
234{
235 struct twlreg_info *info = rdev_get_drvdata(rdev);
236
237 return info->delay;
238}
239
240static int twl4030reg_disable(struct regulator_dev *rdev) 223static int twl4030reg_disable(struct regulator_dev *rdev)
241{ 224{
242 struct twlreg_info *info = rdev_get_drvdata(rdev); 225 struct twlreg_info *info = rdev_get_drvdata(rdev);
@@ -508,7 +491,6 @@ static struct regulator_ops twl4030ldo_ops = {
508 .enable = twl4030reg_enable, 491 .enable = twl4030reg_enable,
509 .disable = twl4030reg_disable, 492 .disable = twl4030reg_disable,
510 .is_enabled = twl4030reg_is_enabled, 493 .is_enabled = twl4030reg_is_enabled,
511 .enable_time = twl4030reg_enable_time,
512 494
513 .set_mode = twl4030reg_set_mode, 495 .set_mode = twl4030reg_set_mode,
514 496
@@ -577,59 +559,53 @@ static struct regulator_ops twl6030coresmps_ops = {
577 .get_voltage = twl6030coresmps_get_voltage, 559 .get_voltage = twl6030coresmps_get_voltage,
578}; 560};
579 561
580static int twl6030ldo_list_voltage(struct regulator_dev *rdev, unsigned index) 562static int twl6030ldo_list_voltage(struct regulator_dev *rdev, unsigned sel)
581{ 563{
582 struct twlreg_info *info = rdev_get_drvdata(rdev); 564 struct twlreg_info *info = rdev_get_drvdata(rdev);
583 565
584 return ((info->min_mV + (index * 100)) * 1000); 566 switch (sel) {
567 case 0:
568 return 0;
569 case 1 ... 24:
570 /* Linear mapping from 00000001 to 00011000:
571 * Absolute voltage value = 1.0 V + 0.1 V × (sel – 00000001)
572 */
573 return (info->min_mV + 100 * (sel - 1)) * 1000;
574 case 25 ... 30:
575 return -EINVAL;
576 case 31:
577 return 2750000;
578 default:
579 return -EINVAL;
580 }
585} 581}
586 582
587static int 583static int
588twl6030ldo_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV, 584twl6030ldo_set_voltage_sel(struct regulator_dev *rdev, unsigned selector)
589 unsigned *selector)
590{ 585{
591 struct twlreg_info *info = rdev_get_drvdata(rdev); 586 struct twlreg_info *info = rdev_get_drvdata(rdev);
592 int vsel;
593
594 if ((min_uV/1000 < info->min_mV) || (max_uV/1000 > info->max_mV))
595 return -EDOM;
596
597 /*
598 * Use the below formula to calculate vsel
599 * mV = 1000mv + 100mv * (vsel - 1)
600 */
601 vsel = (min_uV/1000 - 1000)/100 + 1;
602 *selector = vsel;
603 return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE, vsel);
604 587
588 return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE,
589 selector);
605} 590}
606 591
607static int twl6030ldo_get_voltage(struct regulator_dev *rdev) 592static int twl6030ldo_get_voltage_sel(struct regulator_dev *rdev)
608{ 593{
609 struct twlreg_info *info = rdev_get_drvdata(rdev); 594 struct twlreg_info *info = rdev_get_drvdata(rdev);
610 int vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER, 595 int vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE);
611 VREG_VOLTAGE);
612
613 if (vsel < 0)
614 return vsel;
615 596
616 /* 597 return vsel;
617 * Use the below formula to calculate vsel
618 * mV = 1000mv + 100mv * (vsel - 1)
619 */
620 return (1000 + (100 * (vsel - 1))) * 1000;
621} 598}
622 599
623static struct regulator_ops twl6030ldo_ops = { 600static struct regulator_ops twl6030ldo_ops = {
624 .list_voltage = twl6030ldo_list_voltage, 601 .list_voltage = twl6030ldo_list_voltage,
625 602
626 .set_voltage = twl6030ldo_set_voltage, 603 .set_voltage_sel = twl6030ldo_set_voltage_sel,
627 .get_voltage = twl6030ldo_get_voltage, 604 .get_voltage_sel = twl6030ldo_get_voltage_sel,
628 605
629 .enable = twl6030reg_enable, 606 .enable = twl6030reg_enable,
630 .disable = twl6030reg_disable, 607 .disable = twl6030reg_disable,
631 .is_enabled = twl6030reg_is_enabled, 608 .is_enabled = twl6030reg_is_enabled,
632 .enable_time = twl6030reg_enable_time,
633 609
634 .set_mode = twl6030reg_set_mode, 610 .set_mode = twl6030reg_set_mode,
635 611
@@ -663,7 +639,6 @@ static struct regulator_ops twl4030fixed_ops = {
663 .enable = twl4030reg_enable, 639 .enable = twl4030reg_enable,
664 .disable = twl4030reg_disable, 640 .disable = twl4030reg_disable,
665 .is_enabled = twl4030reg_is_enabled, 641 .is_enabled = twl4030reg_is_enabled,
666 .enable_time = twl4030reg_enable_time,
667 642
668 .set_mode = twl4030reg_set_mode, 643 .set_mode = twl4030reg_set_mode,
669 644
@@ -678,7 +653,6 @@ static struct regulator_ops twl6030fixed_ops = {
678 .enable = twl6030reg_enable, 653 .enable = twl6030reg_enable,
679 .disable = twl6030reg_disable, 654 .disable = twl6030reg_disable,
680 .is_enabled = twl6030reg_is_enabled, 655 .is_enabled = twl6030reg_is_enabled,
681 .enable_time = twl6030reg_enable_time,
682 656
683 .set_mode = twl6030reg_set_mode, 657 .set_mode = twl6030reg_set_mode,
684 658
@@ -689,7 +663,6 @@ static struct regulator_ops twl6030_fixed_resource = {
689 .enable = twl6030reg_enable, 663 .enable = twl6030reg_enable,
690 .disable = twl6030reg_disable, 664 .disable = twl6030reg_disable,
691 .is_enabled = twl6030reg_is_enabled, 665 .is_enabled = twl6030reg_is_enabled,
692 .enable_time = twl6030reg_enable_time,
693 .get_status = twl6030reg_get_status, 666 .get_status = twl6030reg_get_status,
694}; 667};
695 668
@@ -886,7 +859,6 @@ static struct regulator_ops twlsmps_ops = {
886 .enable = twl6030reg_enable, 859 .enable = twl6030reg_enable,
887 .disable = twl6030reg_disable, 860 .disable = twl6030reg_disable,
888 .is_enabled = twl6030reg_is_enabled, 861 .is_enabled = twl6030reg_is_enabled,
889 .enable_time = twl6030reg_enable_time,
890 862
891 .set_mode = twl6030reg_set_mode, 863 .set_mode = twl6030reg_set_mode,
892 864
@@ -909,7 +881,6 @@ static struct twlreg_info TWL4030_INFO_##label = { \
909 .id = num, \ 881 .id = num, \
910 .table_len = ARRAY_SIZE(label##_VSEL_table), \ 882 .table_len = ARRAY_SIZE(label##_VSEL_table), \
911 .table = label##_VSEL_table, \ 883 .table = label##_VSEL_table, \
912 .delay = turnon_delay, \
913 .remap = remap_conf, \ 884 .remap = remap_conf, \
914 .desc = { \ 885 .desc = { \
915 .name = #label, \ 886 .name = #label, \
@@ -918,6 +889,7 @@ static struct twlreg_info TWL4030_INFO_##label = { \
918 .ops = &twl4030ldo_ops, \ 889 .ops = &twl4030ldo_ops, \
919 .type = REGULATOR_VOLTAGE, \ 890 .type = REGULATOR_VOLTAGE, \
920 .owner = THIS_MODULE, \ 891 .owner = THIS_MODULE, \
892 .enable_time = turnon_delay, \
921 }, \ 893 }, \
922 } 894 }
923 895
@@ -925,7 +897,6 @@ static struct twlreg_info TWL4030_INFO_##label = { \
925static struct twlreg_info TWL4030_INFO_##label = { \ 897static struct twlreg_info TWL4030_INFO_##label = { \
926 .base = offset, \ 898 .base = offset, \
927 .id = num, \ 899 .id = num, \
928 .delay = turnon_delay, \
929 .remap = remap_conf, \ 900 .remap = remap_conf, \
930 .desc = { \ 901 .desc = { \
931 .name = #label, \ 902 .name = #label, \
@@ -933,6 +904,7 @@ static struct twlreg_info TWL4030_INFO_##label = { \
933 .ops = &twl4030smps_ops, \ 904 .ops = &twl4030smps_ops, \
934 .type = REGULATOR_VOLTAGE, \ 905 .type = REGULATOR_VOLTAGE, \
935 .owner = THIS_MODULE, \ 906 .owner = THIS_MODULE, \
907 .enable_time = turnon_delay, \
936 }, \ 908 }, \
937 } 909 }
938 910
@@ -955,7 +927,7 @@ static struct twlreg_info TWL6030_INFO_##label = { \
955 .desc = { \ 927 .desc = { \
956 .name = #label, \ 928 .name = #label, \
957 .id = TWL6030_REG_##label, \ 929 .id = TWL6030_REG_##label, \
958 .n_voltages = (max_mVolts - min_mVolts)/100 + 1, \ 930 .n_voltages = 32, \
959 .ops = &twl6030ldo_ops, \ 931 .ops = &twl6030ldo_ops, \
960 .type = REGULATOR_VOLTAGE, \ 932 .type = REGULATOR_VOLTAGE, \
961 .owner = THIS_MODULE, \ 933 .owner = THIS_MODULE, \
@@ -970,7 +942,7 @@ static struct twlreg_info TWL6025_INFO_##label = { \
970 .desc = { \ 942 .desc = { \
971 .name = #label, \ 943 .name = #label, \
972 .id = TWL6025_REG_##label, \ 944 .id = TWL6025_REG_##label, \
973 .n_voltages = ((max_mVolts - min_mVolts)/100) + 1, \ 945 .n_voltages = 32, \
974 .ops = &twl6030ldo_ops, \ 946 .ops = &twl6030ldo_ops, \
975 .type = REGULATOR_VOLTAGE, \ 947 .type = REGULATOR_VOLTAGE, \
976 .owner = THIS_MODULE, \ 948 .owner = THIS_MODULE, \
@@ -983,7 +955,6 @@ static struct twlreg_info TWLFIXED_INFO_##label = { \
983 .base = offset, \ 955 .base = offset, \
984 .id = num, \ 956 .id = num, \
985 .min_mV = mVolts, \ 957 .min_mV = mVolts, \
986 .delay = turnon_delay, \
987 .remap = remap_conf, \ 958 .remap = remap_conf, \
988 .desc = { \ 959 .desc = { \
989 .name = #label, \ 960 .name = #label, \
@@ -992,19 +963,20 @@ static struct twlreg_info TWLFIXED_INFO_##label = { \
992 .ops = &operations, \ 963 .ops = &operations, \
993 .type = REGULATOR_VOLTAGE, \ 964 .type = REGULATOR_VOLTAGE, \
994 .owner = THIS_MODULE, \ 965 .owner = THIS_MODULE, \
966 .enable_time = turnon_delay, \
995 }, \ 967 }, \
996 } 968 }
997 969
998#define TWL6030_FIXED_RESOURCE(label, offset, turnon_delay) \ 970#define TWL6030_FIXED_RESOURCE(label, offset, turnon_delay) \
999static struct twlreg_info TWLRES_INFO_##label = { \ 971static struct twlreg_info TWLRES_INFO_##label = { \
1000 .base = offset, \ 972 .base = offset, \
1001 .delay = turnon_delay, \
1002 .desc = { \ 973 .desc = { \
1003 .name = #label, \ 974 .name = #label, \
1004 .id = TWL6030_REG_##label, \ 975 .id = TWL6030_REG_##label, \
1005 .ops = &twl6030_fixed_resource, \ 976 .ops = &twl6030_fixed_resource, \
1006 .type = REGULATOR_VOLTAGE, \ 977 .type = REGULATOR_VOLTAGE, \
1007 .owner = THIS_MODULE, \ 978 .owner = THIS_MODULE, \
979 .enable_time = turnon_delay, \
1008 }, \ 980 }, \
1009 } 981 }
1010 982
@@ -1109,7 +1081,6 @@ static u8 twl_get_smps_mult(void)
1109#define TWL6030_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL6030, label) 1081#define TWL6030_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL6030, label)
1110#define TWL6025_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL6025, label) 1082#define TWL6025_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL6025, label)
1111#define TWLFIXED_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWLFIXED, label) 1083#define TWLFIXED_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWLFIXED, label)
1112#define TWLRES_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWLRES, label)
1113#define TWLSMPS_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWLSMPS, label) 1084#define TWLSMPS_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWLSMPS, label)
1114 1085
1115static const struct of_device_id twl_of_match[] __devinitconst = { 1086static const struct of_device_id twl_of_match[] __devinitconst = {
@@ -1157,7 +1128,6 @@ static const struct of_device_id twl_of_match[] __devinitconst = {
1157 TWLFIXED_OF_MATCH("ti,twl6030-vusb", VUSB), 1128 TWLFIXED_OF_MATCH("ti,twl6030-vusb", VUSB),
1158 TWLFIXED_OF_MATCH("ti,twl6030-v1v8", V1V8), 1129 TWLFIXED_OF_MATCH("ti,twl6030-v1v8", V1V8),
1159 TWLFIXED_OF_MATCH("ti,twl6030-v2v1", V2V1), 1130 TWLFIXED_OF_MATCH("ti,twl6030-v2v1", V2V1),
1160 TWLRES_OF_MATCH("ti,twl6030-clk32kg", CLK32KG),
1161 TWLSMPS_OF_MATCH("ti,twl6025-smps3", SMPS3), 1131 TWLSMPS_OF_MATCH("ti,twl6025-smps3", SMPS3),
1162 TWLSMPS_OF_MATCH("ti,twl6025-smps4", SMPS4), 1132 TWLSMPS_OF_MATCH("ti,twl6025-smps4", SMPS4),
1163 TWLSMPS_OF_MATCH("ti,twl6025-vio", VIO), 1133 TWLSMPS_OF_MATCH("ti,twl6025-vio", VIO),
diff --git a/drivers/regulator/wm831x-dcdc.c b/drivers/regulator/wm831x-dcdc.c
index 099da11e989f..7413885be01b 100644
--- a/drivers/regulator/wm831x-dcdc.c
+++ b/drivers/regulator/wm831x-dcdc.c
@@ -215,8 +215,8 @@ static int wm831x_buckv_list_voltage(struct regulator_dev *rdev,
215 return -EINVAL; 215 return -EINVAL;
216} 216}
217 217
218static int wm831x_buckv_select_min_voltage(struct regulator_dev *rdev, 218static int wm831x_buckv_map_voltage(struct regulator_dev *rdev,
219 int min_uV, int max_uV) 219 int min_uV, int max_uV)
220{ 220{
221 u16 vsel; 221 u16 vsel;
222 222
@@ -251,20 +251,14 @@ static int wm831x_buckv_set_dvs(struct regulator_dev *rdev, int state)
251 return 0; 251 return 0;
252} 252}
253 253
254static int wm831x_buckv_set_voltage(struct regulator_dev *rdev, 254static int wm831x_buckv_set_voltage_sel(struct regulator_dev *rdev,
255 int min_uV, int max_uV, unsigned *selector) 255 unsigned vsel)
256{ 256{
257 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev); 257 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
258 struct wm831x *wm831x = dcdc->wm831x; 258 struct wm831x *wm831x = dcdc->wm831x;
259 int on_reg = dcdc->base + WM831X_DCDC_ON_CONFIG; 259 int on_reg = dcdc->base + WM831X_DCDC_ON_CONFIG;
260 int dvs_reg = dcdc->base + WM831X_DCDC_DVS_CONTROL; 260 int dvs_reg = dcdc->base + WM831X_DCDC_DVS_CONTROL;
261 int vsel, ret; 261 int ret;
262
263 vsel = wm831x_buckv_select_min_voltage(rdev, min_uV, max_uV);
264 if (vsel < 0)
265 return vsel;
266
267 *selector = vsel;
268 262
269 /* If this value is already set then do a GPIO update if we can */ 263 /* If this value is already set then do a GPIO update if we can */
270 if (dcdc->dvs_gpio && dcdc->on_vsel == vsel) 264 if (dcdc->dvs_gpio && dcdc->on_vsel == vsel)
@@ -315,7 +309,7 @@ static int wm831x_buckv_set_suspend_voltage(struct regulator_dev *rdev,
315 u16 reg = dcdc->base + WM831X_DCDC_SLEEP_CONTROL; 309 u16 reg = dcdc->base + WM831X_DCDC_SLEEP_CONTROL;
316 int vsel; 310 int vsel;
317 311
318 vsel = wm831x_buckv_select_min_voltage(rdev, uV, uV); 312 vsel = wm831x_buckv_map_voltage(rdev, uV, uV);
319 if (vsel < 0) 313 if (vsel < 0)
320 return vsel; 314 return vsel;
321 315
@@ -373,9 +367,10 @@ static int wm831x_buckv_get_current_limit(struct regulator_dev *rdev)
373} 367}
374 368
375static struct regulator_ops wm831x_buckv_ops = { 369static struct regulator_ops wm831x_buckv_ops = {
376 .set_voltage = wm831x_buckv_set_voltage, 370 .set_voltage_sel = wm831x_buckv_set_voltage_sel,
377 .get_voltage_sel = wm831x_buckv_get_voltage_sel, 371 .get_voltage_sel = wm831x_buckv_get_voltage_sel,
378 .list_voltage = wm831x_buckv_list_voltage, 372 .list_voltage = wm831x_buckv_list_voltage,
373 .map_voltage = wm831x_buckv_map_voltage,
379 .set_suspend_voltage = wm831x_buckv_set_suspend_voltage, 374 .set_suspend_voltage = wm831x_buckv_set_suspend_voltage,
380 .set_current_limit = wm831x_buckv_set_current_limit, 375 .set_current_limit = wm831x_buckv_set_current_limit,
381 .get_current_limit = wm831x_buckv_get_current_limit, 376 .get_current_limit = wm831x_buckv_get_current_limit,
@@ -599,60 +594,25 @@ static struct platform_driver wm831x_buckv_driver = {
599 * BUCKP specifics 594 * BUCKP specifics
600 */ 595 */
601 596
602static int wm831x_buckp_list_voltage(struct regulator_dev *rdev, 597static int wm831x_buckp_set_suspend_voltage(struct regulator_dev *rdev, int uV)
603 unsigned selector)
604{
605 if (selector <= WM831X_BUCKP_MAX_SELECTOR)
606 return 850000 + (selector * 25000);
607 else
608 return -EINVAL;
609}
610
611static int wm831x_buckp_set_voltage_int(struct regulator_dev *rdev, int reg,
612 int min_uV, int max_uV, int *selector)
613{ 598{
614 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev); 599 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
615 struct wm831x *wm831x = dcdc->wm831x; 600 struct wm831x *wm831x = dcdc->wm831x;
616 u16 vsel;
617
618 if (min_uV <= 34000000)
619 vsel = (min_uV - 850000) / 25000;
620 else
621 return -EINVAL;
622
623 if (wm831x_buckp_list_voltage(rdev, vsel) > max_uV)
624 return -EINVAL;
625
626 *selector = vsel;
627
628 return wm831x_set_bits(wm831x, reg, WM831X_DC3_ON_VSEL_MASK, vsel);
629}
630
631static int wm831x_buckp_set_voltage(struct regulator_dev *rdev,
632 int min_uV, int max_uV,
633 unsigned *selector)
634{
635 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
636 u16 reg = dcdc->base + WM831X_DCDC_ON_CONFIG;
637
638 return wm831x_buckp_set_voltage_int(rdev, reg, min_uV, max_uV,
639 selector);
640}
641
642static int wm831x_buckp_set_suspend_voltage(struct regulator_dev *rdev,
643 int uV)
644{
645 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
646 u16 reg = dcdc->base + WM831X_DCDC_SLEEP_CONTROL; 601 u16 reg = dcdc->base + WM831X_DCDC_SLEEP_CONTROL;
647 unsigned selector; 602 int sel;
603
604 sel = regulator_map_voltage_linear(rdev, uV, uV);
605 if (sel < 0)
606 return sel;
648 607
649 return wm831x_buckp_set_voltage_int(rdev, reg, uV, uV, &selector); 608 return wm831x_set_bits(wm831x, reg, WM831X_DC3_ON_VSEL_MASK, sel);
650} 609}
651 610
652static struct regulator_ops wm831x_buckp_ops = { 611static struct regulator_ops wm831x_buckp_ops = {
653 .set_voltage = wm831x_buckp_set_voltage, 612 .set_voltage_sel = regulator_set_voltage_sel_regmap,
654 .get_voltage_sel = regulator_get_voltage_sel_regmap, 613 .get_voltage_sel = regulator_get_voltage_sel_regmap,
655 .list_voltage = wm831x_buckp_list_voltage, 614 .list_voltage = regulator_list_voltage_linear,
615 .map_voltage = regulator_map_voltage_linear,
656 .set_suspend_voltage = wm831x_buckp_set_suspend_voltage, 616 .set_suspend_voltage = wm831x_buckp_set_suspend_voltage,
657 617
658 .is_enabled = regulator_is_enabled_regmap, 618 .is_enabled = regulator_is_enabled_regmap,
@@ -715,6 +675,8 @@ static __devinit int wm831x_buckp_probe(struct platform_device *pdev)
715 dcdc->desc.vsel_mask = WM831X_DC3_ON_VSEL_MASK; 675 dcdc->desc.vsel_mask = WM831X_DC3_ON_VSEL_MASK;
716 dcdc->desc.enable_reg = WM831X_DCDC_ENABLE; 676 dcdc->desc.enable_reg = WM831X_DCDC_ENABLE;
717 dcdc->desc.enable_mask = 1 << id; 677 dcdc->desc.enable_mask = 1 << id;
678 dcdc->desc.min_uV = 850000;
679 dcdc->desc.uV_step = 25000;
718 680
719 config.dev = pdev->dev.parent; 681 config.dev = pdev->dev.parent;
720 if (pdata) 682 if (pdata)
diff --git a/drivers/regulator/wm831x-ldo.c b/drivers/regulator/wm831x-ldo.c
index a9a28d8ac185..5cb70ca1e98d 100644
--- a/drivers/regulator/wm831x-ldo.c
+++ b/drivers/regulator/wm831x-ldo.c
@@ -78,13 +78,10 @@ static int wm831x_gp_ldo_list_voltage(struct regulator_dev *rdev,
78 return -EINVAL; 78 return -EINVAL;
79} 79}
80 80
81static int wm831x_gp_ldo_set_voltage_int(struct regulator_dev *rdev, int reg, 81static int wm831x_gp_ldo_map_voltage(struct regulator_dev *rdev,
82 int min_uV, int max_uV, 82 int min_uV, int max_uV)
83 unsigned *selector)
84{ 83{
85 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); 84 int volt, vsel;
86 struct wm831x *wm831x = ldo->wm831x;
87 int vsel, ret;
88 85
89 if (min_uV < 900000) 86 if (min_uV < 900000)
90 vsel = 0; 87 vsel = 0;
@@ -94,36 +91,25 @@ static int wm831x_gp_ldo_set_voltage_int(struct regulator_dev *rdev, int reg,
94 vsel = ((min_uV - 1700000) / 100000) 91 vsel = ((min_uV - 1700000) / 100000)
95 + WM831X_GP_LDO_SELECTOR_LOW + 1; 92 + WM831X_GP_LDO_SELECTOR_LOW + 1;
96 93
97 ret = wm831x_gp_ldo_list_voltage(rdev, vsel); 94 volt = wm831x_gp_ldo_list_voltage(rdev, vsel);
98 if (ret < 0) 95 if (volt < min_uV || volt > max_uV)
99 return ret;
100 if (ret < min_uV || ret > max_uV)
101 return -EINVAL; 96 return -EINVAL;
102 97
103 *selector = vsel; 98 return vsel;
104
105 return wm831x_set_bits(wm831x, reg, WM831X_LDO1_ON_VSEL_MASK, vsel);
106}
107
108static int wm831x_gp_ldo_set_voltage(struct regulator_dev *rdev,
109 int min_uV, int max_uV,
110 unsigned *selector)
111{
112 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
113 int reg = ldo->base + WM831X_LDO_ON_CONTROL;
114
115 return wm831x_gp_ldo_set_voltage_int(rdev, reg, min_uV, max_uV,
116 selector);
117} 99}
118 100
119static int wm831x_gp_ldo_set_suspend_voltage(struct regulator_dev *rdev, 101static int wm831x_gp_ldo_set_suspend_voltage(struct regulator_dev *rdev,
120 int uV) 102 int uV)
121{ 103{
122 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); 104 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
123 int reg = ldo->base + WM831X_LDO_SLEEP_CONTROL; 105 struct wm831x *wm831x = ldo->wm831x;
124 unsigned int selector; 106 int sel, reg = ldo->base + WM831X_LDO_SLEEP_CONTROL;
125 107
126 return wm831x_gp_ldo_set_voltage_int(rdev, reg, uV, uV, &selector); 108 sel = wm831x_gp_ldo_map_voltage(rdev, uV, uV);
109 if (sel < 0)
110 return sel;
111
112 return wm831x_set_bits(wm831x, reg, WM831X_LDO1_ON_VSEL_MASK, sel);
127} 113}
128 114
129static unsigned int wm831x_gp_ldo_get_mode(struct regulator_dev *rdev) 115static unsigned int wm831x_gp_ldo_get_mode(struct regulator_dev *rdev)
@@ -243,8 +229,9 @@ static unsigned int wm831x_gp_ldo_get_optimum_mode(struct regulator_dev *rdev,
243 229
244static struct regulator_ops wm831x_gp_ldo_ops = { 230static struct regulator_ops wm831x_gp_ldo_ops = {
245 .list_voltage = wm831x_gp_ldo_list_voltage, 231 .list_voltage = wm831x_gp_ldo_list_voltage,
232 .map_voltage = wm831x_gp_ldo_map_voltage,
246 .get_voltage_sel = regulator_get_voltage_sel_regmap, 233 .get_voltage_sel = regulator_get_voltage_sel_regmap,
247 .set_voltage = wm831x_gp_ldo_set_voltage, 234 .set_voltage_sel = regulator_set_voltage_sel_regmap,
248 .set_suspend_voltage = wm831x_gp_ldo_set_suspend_voltage, 235 .set_suspend_voltage = wm831x_gp_ldo_set_suspend_voltage,
249 .get_mode = wm831x_gp_ldo_get_mode, 236 .get_mode = wm831x_gp_ldo_get_mode,
250 .set_mode = wm831x_gp_ldo_set_mode, 237 .set_mode = wm831x_gp_ldo_set_mode,
@@ -384,13 +371,10 @@ static int wm831x_aldo_list_voltage(struct regulator_dev *rdev,
384 return -EINVAL; 371 return -EINVAL;
385} 372}
386 373
387static int wm831x_aldo_set_voltage_int(struct regulator_dev *rdev, int reg, 374static int wm831x_aldo_map_voltage(struct regulator_dev *rdev,
388 int min_uV, int max_uV, 375 int min_uV, int max_uV)
389 unsigned *selector)
390{ 376{
391 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); 377 int volt, vsel;
392 struct wm831x *wm831x = ldo->wm831x;
393 int vsel, ret;
394 378
395 if (min_uV < 1000000) 379 if (min_uV < 1000000)
396 vsel = 0; 380 vsel = 0;
@@ -400,35 +384,26 @@ static int wm831x_aldo_set_voltage_int(struct regulator_dev *rdev, int reg,
400 vsel = ((min_uV - 1700000) / 100000) 384 vsel = ((min_uV - 1700000) / 100000)
401 + WM831X_ALDO_SELECTOR_LOW + 1; 385 + WM831X_ALDO_SELECTOR_LOW + 1;
402 386
403 ret = wm831x_aldo_list_voltage(rdev, vsel); 387 volt = wm831x_aldo_list_voltage(rdev, vsel);
404 if (ret < 0) 388 if (volt < min_uV || volt > max_uV)
405 return ret;
406 if (ret < min_uV || ret > max_uV)
407 return -EINVAL; 389 return -EINVAL;
408 390
409 *selector = vsel; 391 return vsel;
410
411 return wm831x_set_bits(wm831x, reg, WM831X_LDO7_ON_VSEL_MASK, vsel);
412}
413
414static int wm831x_aldo_set_voltage(struct regulator_dev *rdev,
415 int min_uV, int max_uV, unsigned *selector)
416{
417 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
418 int reg = ldo->base + WM831X_LDO_ON_CONTROL;
419 392
420 return wm831x_aldo_set_voltage_int(rdev, reg, min_uV, max_uV,
421 selector);
422} 393}
423 394
424static int wm831x_aldo_set_suspend_voltage(struct regulator_dev *rdev, 395static int wm831x_aldo_set_suspend_voltage(struct regulator_dev *rdev,
425 int uV) 396 int uV)
426{ 397{
427 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); 398 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
428 int reg = ldo->base + WM831X_LDO_SLEEP_CONTROL; 399 struct wm831x *wm831x = ldo->wm831x;
429 unsigned int selector; 400 int sel, reg = ldo->base + WM831X_LDO_SLEEP_CONTROL;
401
402 sel = wm831x_aldo_map_voltage(rdev, uV, uV);
403 if (sel < 0)
404 return sel;
430 405
431 return wm831x_aldo_set_voltage_int(rdev, reg, uV, uV, &selector); 406 return wm831x_set_bits(wm831x, reg, WM831X_LDO7_ON_VSEL_MASK, sel);
432} 407}
433 408
434static unsigned int wm831x_aldo_get_mode(struct regulator_dev *rdev) 409static unsigned int wm831x_aldo_get_mode(struct regulator_dev *rdev)
@@ -506,8 +481,9 @@ static int wm831x_aldo_get_status(struct regulator_dev *rdev)
506 481
507static struct regulator_ops wm831x_aldo_ops = { 482static struct regulator_ops wm831x_aldo_ops = {
508 .list_voltage = wm831x_aldo_list_voltage, 483 .list_voltage = wm831x_aldo_list_voltage,
484 .map_voltage = wm831x_aldo_map_voltage,
509 .get_voltage_sel = regulator_get_voltage_sel_regmap, 485 .get_voltage_sel = regulator_get_voltage_sel_regmap,
510 .set_voltage = wm831x_aldo_set_voltage, 486 .set_voltage_sel = regulator_set_voltage_sel_regmap,
511 .set_suspend_voltage = wm831x_aldo_set_suspend_voltage, 487 .set_suspend_voltage = wm831x_aldo_set_suspend_voltage,
512 .get_mode = wm831x_aldo_get_mode, 488 .get_mode = wm831x_aldo_get_mode,
513 .set_mode = wm831x_aldo_set_mode, 489 .set_mode = wm831x_aldo_set_mode,
@@ -628,47 +604,18 @@ static struct platform_driver wm831x_aldo_driver = {
628 604
629#define WM831X_ALIVE_LDO_MAX_SELECTOR 0xf 605#define WM831X_ALIVE_LDO_MAX_SELECTOR 0xf
630 606
631static int wm831x_alive_ldo_set_voltage_int(struct regulator_dev *rdev,
632 int reg,
633 int min_uV, int max_uV,
634 unsigned *selector)
635{
636 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
637 struct wm831x *wm831x = ldo->wm831x;
638 int vsel, ret;
639
640 vsel = (min_uV - 800000) / 50000;
641
642 ret = regulator_list_voltage_linear(rdev, vsel);
643 if (ret < 0)
644 return ret;
645 if (ret < min_uV || ret > max_uV)
646 return -EINVAL;
647
648 *selector = vsel;
649
650 return wm831x_set_bits(wm831x, reg, WM831X_LDO11_ON_VSEL_MASK, vsel);
651}
652
653static int wm831x_alive_ldo_set_voltage(struct regulator_dev *rdev,
654 int min_uV, int max_uV,
655 unsigned *selector)
656{
657 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
658 int reg = ldo->base + WM831X_ALIVE_LDO_ON_CONTROL;
659
660 return wm831x_alive_ldo_set_voltage_int(rdev, reg, min_uV, max_uV,
661 selector);
662}
663
664static int wm831x_alive_ldo_set_suspend_voltage(struct regulator_dev *rdev, 607static int wm831x_alive_ldo_set_suspend_voltage(struct regulator_dev *rdev,
665 int uV) 608 int uV)
666{ 609{
667 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); 610 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
668 int reg = ldo->base + WM831X_ALIVE_LDO_SLEEP_CONTROL; 611 struct wm831x *wm831x = ldo->wm831x;
669 unsigned selector; 612 int sel, reg = ldo->base + WM831X_ALIVE_LDO_SLEEP_CONTROL;
613
614 sel = regulator_map_voltage_linear(rdev, uV, uV);
615 if (sel < 0)
616 return sel;
670 617
671 return wm831x_alive_ldo_set_voltage_int(rdev, reg, uV, uV, &selector); 618 return wm831x_set_bits(wm831x, reg, WM831X_LDO11_ON_VSEL_MASK, sel);
672} 619}
673 620
674static int wm831x_alive_ldo_get_status(struct regulator_dev *rdev) 621static int wm831x_alive_ldo_get_status(struct regulator_dev *rdev)
@@ -690,8 +637,9 @@ static int wm831x_alive_ldo_get_status(struct regulator_dev *rdev)
690 637
691static struct regulator_ops wm831x_alive_ldo_ops = { 638static struct regulator_ops wm831x_alive_ldo_ops = {
692 .list_voltage = regulator_list_voltage_linear, 639 .list_voltage = regulator_list_voltage_linear,
640 .map_voltage = regulator_map_voltage_linear,
693 .get_voltage_sel = regulator_get_voltage_sel_regmap, 641 .get_voltage_sel = regulator_get_voltage_sel_regmap,
694 .set_voltage = wm831x_alive_ldo_set_voltage, 642 .set_voltage_sel = regulator_set_voltage_sel_regmap,
695 .set_suspend_voltage = wm831x_alive_ldo_set_suspend_voltage, 643 .set_suspend_voltage = wm831x_alive_ldo_set_suspend_voltage,
696 .get_status = wm831x_alive_ldo_get_status, 644 .get_status = wm831x_alive_ldo_get_status,
697 645
@@ -753,6 +701,7 @@ static __devinit int wm831x_alive_ldo_probe(struct platform_device *pdev)
753 ldo->desc.enable_mask = 1 << id; 701 ldo->desc.enable_mask = 1 << id;
754 ldo->desc.min_uV = 800000; 702 ldo->desc.min_uV = 800000;
755 ldo->desc.uV_step = 50000; 703 ldo->desc.uV_step = 50000;
704 ldo->desc.enable_time = 1000;
756 705
757 config.dev = pdev->dev.parent; 706 config.dev = pdev->dev.parent;
758 if (pdata) 707 if (pdata)
diff --git a/drivers/regulator/wm8350-regulator.c b/drivers/regulator/wm8350-regulator.c
index 94e550dc70b6..7f0fa22ef2aa 100644
--- a/drivers/regulator/wm8350-regulator.c
+++ b/drivers/regulator/wm8350-regulator.c
@@ -108,33 +108,6 @@ static int get_isink_val(int min_uA, int max_uA, u16 *setting)
108 return -EINVAL; 108 return -EINVAL;
109} 109}
110 110
111static inline int wm8350_ldo_val_to_mvolts(unsigned int val)
112{
113 if (val < 16)
114 return (val * 50) + 900;
115 else
116 return ((val - 16) * 100) + 1800;
117
118}
119
120static inline unsigned int wm8350_ldo_mvolts_to_val(int mV)
121{
122 if (mV < 1800)
123 return (mV - 900) / 50;
124 else
125 return ((mV - 1800) / 100) + 16;
126}
127
128static inline int wm8350_dcdc_val_to_mvolts(unsigned int val)
129{
130 return (val * 25) + 850;
131}
132
133static inline unsigned int wm8350_dcdc_mvolts_to_val(int mV)
134{
135 return (mV - 850) / 25;
136}
137
138static int wm8350_isink_set_current(struct regulator_dev *rdev, int min_uA, 111static int wm8350_isink_set_current(struct regulator_dev *rdev, int min_uA,
139 int max_uA) 112 int max_uA)
140{ 113{
@@ -359,104 +332,13 @@ int wm8350_isink_set_flash(struct wm8350 *wm8350, int isink, u16 mode,
359} 332}
360EXPORT_SYMBOL_GPL(wm8350_isink_set_flash); 333EXPORT_SYMBOL_GPL(wm8350_isink_set_flash);
361 334
362static int wm8350_dcdc_set_voltage(struct regulator_dev *rdev, int min_uV,
363 int max_uV, unsigned *selector)
364{
365 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
366 int volt_reg, dcdc = rdev_get_id(rdev), mV,
367 min_mV = min_uV / 1000, max_mV = max_uV / 1000;
368 u16 val;
369
370 if (min_mV < 850 || min_mV > 4025)
371 return -EINVAL;
372 if (max_mV < 850 || max_mV > 4025)
373 return -EINVAL;
374
375 /* step size is 25mV */
376 mV = (min_mV - 826) / 25;
377 if (wm8350_dcdc_val_to_mvolts(mV) > max_mV)
378 return -EINVAL;
379 BUG_ON(wm8350_dcdc_val_to_mvolts(mV) < min_mV);
380
381 switch (dcdc) {
382 case WM8350_DCDC_1:
383 volt_reg = WM8350_DCDC1_CONTROL;
384 break;
385 case WM8350_DCDC_3:
386 volt_reg = WM8350_DCDC3_CONTROL;
387 break;
388 case WM8350_DCDC_4:
389 volt_reg = WM8350_DCDC4_CONTROL;
390 break;
391 case WM8350_DCDC_6:
392 volt_reg = WM8350_DCDC6_CONTROL;
393 break;
394 case WM8350_DCDC_2:
395 case WM8350_DCDC_5:
396 default:
397 return -EINVAL;
398 }
399
400 *selector = mV;
401
402 /* all DCDCs have same mV bits */
403 val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_DC1_VSEL_MASK;
404 wm8350_reg_write(wm8350, volt_reg, val | mV);
405 return 0;
406}
407
408static int wm8350_dcdc_get_voltage_sel(struct regulator_dev *rdev)
409{
410 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
411 int volt_reg, dcdc = rdev_get_id(rdev);
412
413 switch (dcdc) {
414 case WM8350_DCDC_1:
415 volt_reg = WM8350_DCDC1_CONTROL;
416 break;
417 case WM8350_DCDC_3:
418 volt_reg = WM8350_DCDC3_CONTROL;
419 break;
420 case WM8350_DCDC_4:
421 volt_reg = WM8350_DCDC4_CONTROL;
422 break;
423 case WM8350_DCDC_6:
424 volt_reg = WM8350_DCDC6_CONTROL;
425 break;
426 case WM8350_DCDC_2:
427 case WM8350_DCDC_5:
428 default:
429 return -EINVAL;
430 }
431
432 /* all DCDCs have same mV bits */
433 return wm8350_reg_read(wm8350, volt_reg) & WM8350_DC1_VSEL_MASK;
434}
435
436static int wm8350_dcdc_list_voltage(struct regulator_dev *rdev,
437 unsigned selector)
438{
439 if (selector > WM8350_DCDC_MAX_VSEL)
440 return -EINVAL;
441 return wm8350_dcdc_val_to_mvolts(selector) * 1000;
442}
443
444static int wm8350_dcdc_set_suspend_voltage(struct regulator_dev *rdev, int uV) 335static int wm8350_dcdc_set_suspend_voltage(struct regulator_dev *rdev, int uV)
445{ 336{
446 struct wm8350 *wm8350 = rdev_get_drvdata(rdev); 337 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
447 int volt_reg, mV = uV / 1000, dcdc = rdev_get_id(rdev); 338 int sel, volt_reg, dcdc = rdev_get_id(rdev);
448 u16 val; 339 u16 val;
449 340
450 dev_dbg(wm8350->dev, "%s %d mV %d\n", __func__, dcdc, mV); 341 dev_dbg(wm8350->dev, "%s %d mV %d\n", __func__, dcdc, uV / 1000);
451
452 if (mV && (mV < 850 || mV > 4025)) {
453 dev_err(wm8350->dev,
454 "DCDC%d suspend voltage %d mV out of range\n",
455 dcdc, mV);
456 return -EINVAL;
457 }
458 if (mV == 0)
459 mV = 850;
460 342
461 switch (dcdc) { 343 switch (dcdc) {
462 case WM8350_DCDC_1: 344 case WM8350_DCDC_1:
@@ -477,10 +359,13 @@ static int wm8350_dcdc_set_suspend_voltage(struct regulator_dev *rdev, int uV)
477 return -EINVAL; 359 return -EINVAL;
478 } 360 }
479 361
362 sel = regulator_map_voltage_linear(rdev, uV, uV);
363 if (sel < 0)
364 return -EINVAL;
365
480 /* all DCDCs have same mV bits */ 366 /* all DCDCs have same mV bits */
481 val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_DC1_VSEL_MASK; 367 val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_DC1_VSEL_MASK;
482 wm8350_reg_write(wm8350, volt_reg, 368 wm8350_reg_write(wm8350, volt_reg, val | sel);
483 val | wm8350_dcdc_mvolts_to_val(mV));
484 return 0; 369 return 0;
485} 370}
486 371
@@ -657,19 +542,49 @@ static int wm8350_dcdc_set_suspend_mode(struct regulator_dev *rdev,
657 return 0; 542 return 0;
658} 543}
659 544
545static int wm8350_ldo_list_voltage(struct regulator_dev *rdev,
546 unsigned selector)
547{
548 if (selector > WM8350_LDO1_VSEL_MASK)
549 return -EINVAL;
550
551 if (selector < 16)
552 return (selector * 50000) + 900000;
553 else
554 return ((selector - 16) * 100000) + 1800000;
555}
556
557static int wm8350_ldo_map_voltage(struct regulator_dev *rdev, int min_uV,
558 int max_uV)
559{
560 int volt, sel;
561 int min_mV = min_uV / 1000;
562 int max_mV = max_uV / 1000;
563
564 if (min_mV < 900 || min_mV > 3300)
565 return -EINVAL;
566 if (max_mV < 900 || max_mV > 3300)
567 return -EINVAL;
568
569 if (min_mV < 1800) /* step size is 50mV < 1800mV */
570 sel = DIV_ROUND_UP(min_uV - 900, 50);
571 else /* step size is 100mV > 1800mV */
572 sel = DIV_ROUND_UP(min_uV - 1800, 100) + 16;
573
574 volt = wm8350_ldo_list_voltage(rdev, sel);
575 if (volt < min_uV || volt > max_uV)
576 return -EINVAL;
577
578 return sel;
579}
580
660static int wm8350_ldo_set_suspend_voltage(struct regulator_dev *rdev, int uV) 581static int wm8350_ldo_set_suspend_voltage(struct regulator_dev *rdev, int uV)
661{ 582{
662 struct wm8350 *wm8350 = rdev_get_drvdata(rdev); 583 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
663 int volt_reg, mV = uV / 1000, ldo = rdev_get_id(rdev); 584 int sel, volt_reg, ldo = rdev_get_id(rdev);
664 u16 val; 585 u16 val;
665 586
666 dev_dbg(wm8350->dev, "%s %d mV %d\n", __func__, ldo, mV); 587 dev_dbg(wm8350->dev, "%s %d mV %d\n", __func__, ldo, uV / 1000);
667
668 if (mV < 900 || mV > 3300) {
669 dev_err(wm8350->dev, "LDO%d voltage %d mV out of range\n",
670 ldo, mV);
671 return -EINVAL;
672 }
673 588
674 switch (ldo) { 589 switch (ldo) {
675 case WM8350_LDO_1: 590 case WM8350_LDO_1:
@@ -688,10 +603,13 @@ static int wm8350_ldo_set_suspend_voltage(struct regulator_dev *rdev, int uV)
688 return -EINVAL; 603 return -EINVAL;
689 } 604 }
690 605
606 sel = wm8350_ldo_map_voltage(rdev, uV, uV);
607 if (sel < 0)
608 return -EINVAL;
609
691 /* all LDOs have same mV bits */ 610 /* all LDOs have same mV bits */
692 val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_LDO1_VSEL_MASK; 611 val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_LDO1_VSEL_MASK;
693 wm8350_reg_write(wm8350, volt_reg, 612 wm8350_reg_write(wm8350, volt_reg, val | sel);
694 val | wm8350_ldo_mvolts_to_val(mV));
695 return 0; 613 return 0;
696} 614}
697 615
@@ -753,92 +671,6 @@ static int wm8350_ldo_set_suspend_disable(struct regulator_dev *rdev)
753 return 0; 671 return 0;
754} 672}
755 673
756static int wm8350_ldo_set_voltage(struct regulator_dev *rdev, int min_uV,
757 int max_uV, unsigned *selector)
758{
759 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
760 int volt_reg, ldo = rdev_get_id(rdev), mV, min_mV = min_uV / 1000,
761 max_mV = max_uV / 1000;
762 u16 val;
763
764 if (min_mV < 900 || min_mV > 3300)
765 return -EINVAL;
766 if (max_mV < 900 || max_mV > 3300)
767 return -EINVAL;
768
769 if (min_mV < 1800) {
770 /* step size is 50mV < 1800mV */
771 mV = (min_mV - 851) / 50;
772 if (wm8350_ldo_val_to_mvolts(mV) > max_mV)
773 return -EINVAL;
774 BUG_ON(wm8350_ldo_val_to_mvolts(mV) < min_mV);
775 } else {
776 /* step size is 100mV > 1800mV */
777 mV = ((min_mV - 1701) / 100) + 16;
778 if (wm8350_ldo_val_to_mvolts(mV) > max_mV)
779 return -EINVAL;
780 BUG_ON(wm8350_ldo_val_to_mvolts(mV) < min_mV);
781 }
782
783 switch (ldo) {
784 case WM8350_LDO_1:
785 volt_reg = WM8350_LDO1_CONTROL;
786 break;
787 case WM8350_LDO_2:
788 volt_reg = WM8350_LDO2_CONTROL;
789 break;
790 case WM8350_LDO_3:
791 volt_reg = WM8350_LDO3_CONTROL;
792 break;
793 case WM8350_LDO_4:
794 volt_reg = WM8350_LDO4_CONTROL;
795 break;
796 default:
797 return -EINVAL;
798 }
799
800 *selector = mV;
801
802 /* all LDOs have same mV bits */
803 val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_LDO1_VSEL_MASK;
804 wm8350_reg_write(wm8350, volt_reg, val | mV);
805 return 0;
806}
807
808static int wm8350_ldo_get_voltage_sel(struct regulator_dev *rdev)
809{
810 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
811 int volt_reg, ldo = rdev_get_id(rdev);
812
813 switch (ldo) {
814 case WM8350_LDO_1:
815 volt_reg = WM8350_LDO1_CONTROL;
816 break;
817 case WM8350_LDO_2:
818 volt_reg = WM8350_LDO2_CONTROL;
819 break;
820 case WM8350_LDO_3:
821 volt_reg = WM8350_LDO3_CONTROL;
822 break;
823 case WM8350_LDO_4:
824 volt_reg = WM8350_LDO4_CONTROL;
825 break;
826 default:
827 return -EINVAL;
828 }
829
830 /* all LDOs have same mV bits */
831 return wm8350_reg_read(wm8350, volt_reg) & WM8350_LDO1_VSEL_MASK;
832}
833
834static int wm8350_ldo_list_voltage(struct regulator_dev *rdev,
835 unsigned selector)
836{
837 if (selector > WM8350_LDO1_VSEL_MASK)
838 return -EINVAL;
839 return wm8350_ldo_val_to_mvolts(selector) * 1000;
840}
841
842int wm8350_dcdc_set_slot(struct wm8350 *wm8350, int dcdc, u16 start, 674int wm8350_dcdc_set_slot(struct wm8350 *wm8350, int dcdc, u16 start,
843 u16 stop, u16 fault) 675 u16 stop, u16 fault)
844{ 676{
@@ -959,63 +791,6 @@ int wm8350_dcdc25_set_mode(struct wm8350 *wm8350, int dcdc, u16 mode,
959} 791}
960EXPORT_SYMBOL_GPL(wm8350_dcdc25_set_mode); 792EXPORT_SYMBOL_GPL(wm8350_dcdc25_set_mode);
961 793
962static int wm8350_dcdc_enable(struct regulator_dev *rdev)
963{
964 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
965 int dcdc = rdev_get_id(rdev);
966 u16 shift;
967
968 if (dcdc < WM8350_DCDC_1 || dcdc > WM8350_DCDC_6)
969 return -EINVAL;
970
971 shift = dcdc - WM8350_DCDC_1;
972 wm8350_set_bits(wm8350, WM8350_DCDC_LDO_REQUESTED, 1 << shift);
973 return 0;
974}
975
976static int wm8350_dcdc_disable(struct regulator_dev *rdev)
977{
978 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
979 int dcdc = rdev_get_id(rdev);
980 u16 shift;
981
982 if (dcdc < WM8350_DCDC_1 || dcdc > WM8350_DCDC_6)
983 return -EINVAL;
984
985 shift = dcdc - WM8350_DCDC_1;
986 wm8350_clear_bits(wm8350, WM8350_DCDC_LDO_REQUESTED, 1 << shift);
987
988 return 0;
989}
990
991static int wm8350_ldo_enable(struct regulator_dev *rdev)
992{
993 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
994 int ldo = rdev_get_id(rdev);
995 u16 shift;
996
997 if (ldo < WM8350_LDO_1 || ldo > WM8350_LDO_4)
998 return -EINVAL;
999
1000 shift = (ldo - WM8350_LDO_1) + 8;
1001 wm8350_set_bits(wm8350, WM8350_DCDC_LDO_REQUESTED, 1 << shift);
1002 return 0;
1003}
1004
1005static int wm8350_ldo_disable(struct regulator_dev *rdev)
1006{
1007 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
1008 int ldo = rdev_get_id(rdev);
1009 u16 shift;
1010
1011 if (ldo < WM8350_LDO_1 || ldo > WM8350_LDO_4)
1012 return -EINVAL;
1013
1014 shift = (ldo - WM8350_LDO_1) + 8;
1015 wm8350_clear_bits(wm8350, WM8350_DCDC_LDO_REQUESTED, 1 << shift);
1016 return 0;
1017}
1018
1019static int force_continuous_enable(struct wm8350 *wm8350, int dcdc, int enable) 794static int force_continuous_enable(struct wm8350 *wm8350, int dcdc, int enable)
1020{ 795{
1021 int reg = 0, ret; 796 int reg = 0, ret;
@@ -1197,42 +972,17 @@ static unsigned int wm8350_dcdc_get_optimum_mode(struct regulator_dev *rdev,
1197 return mode; 972 return mode;
1198} 973}
1199 974
1200static int wm8350_dcdc_is_enabled(struct regulator_dev *rdev)
1201{
1202 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
1203 int dcdc = rdev_get_id(rdev), shift;
1204
1205 if (dcdc < WM8350_DCDC_1 || dcdc > WM8350_DCDC_6)
1206 return -EINVAL;
1207
1208 shift = dcdc - WM8350_DCDC_1;
1209 return wm8350_reg_read(wm8350, WM8350_DCDC_LDO_REQUESTED)
1210 & (1 << shift);
1211}
1212
1213static int wm8350_ldo_is_enabled(struct regulator_dev *rdev)
1214{
1215 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
1216 int ldo = rdev_get_id(rdev), shift;
1217
1218 if (ldo < WM8350_LDO_1 || ldo > WM8350_LDO_4)
1219 return -EINVAL;
1220
1221 shift = (ldo - WM8350_LDO_1) + 8;
1222 return wm8350_reg_read(wm8350, WM8350_DCDC_LDO_REQUESTED)
1223 & (1 << shift);
1224}
1225
1226static struct regulator_ops wm8350_dcdc_ops = { 975static struct regulator_ops wm8350_dcdc_ops = {
1227 .set_voltage = wm8350_dcdc_set_voltage, 976 .set_voltage_sel = regulator_set_voltage_sel_regmap,
1228 .get_voltage_sel = wm8350_dcdc_get_voltage_sel, 977 .get_voltage_sel = regulator_get_voltage_sel_regmap,
1229 .list_voltage = wm8350_dcdc_list_voltage, 978 .list_voltage = regulator_list_voltage_linear,
1230 .enable = wm8350_dcdc_enable, 979 .map_voltage = regulator_map_voltage_linear,
1231 .disable = wm8350_dcdc_disable, 980 .enable = regulator_enable_regmap,
981 .disable = regulator_disable_regmap,
982 .is_enabled = regulator_is_enabled_regmap,
1232 .get_mode = wm8350_dcdc_get_mode, 983 .get_mode = wm8350_dcdc_get_mode,
1233 .set_mode = wm8350_dcdc_set_mode, 984 .set_mode = wm8350_dcdc_set_mode,
1234 .get_optimum_mode = wm8350_dcdc_get_optimum_mode, 985 .get_optimum_mode = wm8350_dcdc_get_optimum_mode,
1235 .is_enabled = wm8350_dcdc_is_enabled,
1236 .set_suspend_voltage = wm8350_dcdc_set_suspend_voltage, 986 .set_suspend_voltage = wm8350_dcdc_set_suspend_voltage,
1237 .set_suspend_enable = wm8350_dcdc_set_suspend_enable, 987 .set_suspend_enable = wm8350_dcdc_set_suspend_enable,
1238 .set_suspend_disable = wm8350_dcdc_set_suspend_disable, 988 .set_suspend_disable = wm8350_dcdc_set_suspend_disable,
@@ -1240,20 +990,21 @@ static struct regulator_ops wm8350_dcdc_ops = {
1240}; 990};
1241 991
1242static struct regulator_ops wm8350_dcdc2_5_ops = { 992static struct regulator_ops wm8350_dcdc2_5_ops = {
1243 .enable = wm8350_dcdc_enable, 993 .enable = regulator_enable_regmap,
1244 .disable = wm8350_dcdc_disable, 994 .disable = regulator_disable_regmap,
1245 .is_enabled = wm8350_dcdc_is_enabled, 995 .is_enabled = regulator_is_enabled_regmap,
1246 .set_suspend_enable = wm8350_dcdc25_set_suspend_enable, 996 .set_suspend_enable = wm8350_dcdc25_set_suspend_enable,
1247 .set_suspend_disable = wm8350_dcdc25_set_suspend_disable, 997 .set_suspend_disable = wm8350_dcdc25_set_suspend_disable,
1248}; 998};
1249 999
1250static struct regulator_ops wm8350_ldo_ops = { 1000static struct regulator_ops wm8350_ldo_ops = {
1251 .set_voltage = wm8350_ldo_set_voltage, 1001 .map_voltage = wm8350_ldo_map_voltage,
1252 .get_voltage_sel = wm8350_ldo_get_voltage_sel, 1002 .set_voltage_sel = regulator_set_voltage_sel_regmap,
1003 .get_voltage_sel = regulator_get_voltage_sel_regmap,
1253 .list_voltage = wm8350_ldo_list_voltage, 1004 .list_voltage = wm8350_ldo_list_voltage,
1254 .enable = wm8350_ldo_enable, 1005 .enable = regulator_enable_regmap,
1255 .disable = wm8350_ldo_disable, 1006 .disable = regulator_disable_regmap,
1256 .is_enabled = wm8350_ldo_is_enabled, 1007 .is_enabled = regulator_is_enabled_regmap,
1257 .get_mode = wm8350_ldo_get_mode, 1008 .get_mode = wm8350_ldo_get_mode,
1258 .set_suspend_voltage = wm8350_ldo_set_suspend_voltage, 1009 .set_suspend_voltage = wm8350_ldo_set_suspend_voltage,
1259 .set_suspend_enable = wm8350_ldo_set_suspend_enable, 1010 .set_suspend_enable = wm8350_ldo_set_suspend_enable,
@@ -1277,6 +1028,12 @@ static const struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = {
1277 .irq = WM8350_IRQ_UV_DC1, 1028 .irq = WM8350_IRQ_UV_DC1,
1278 .type = REGULATOR_VOLTAGE, 1029 .type = REGULATOR_VOLTAGE,
1279 .n_voltages = WM8350_DCDC_MAX_VSEL + 1, 1030 .n_voltages = WM8350_DCDC_MAX_VSEL + 1,
1031 .min_uV = 850000,
1032 .uV_step = 25000,
1033 .vsel_reg = WM8350_DCDC1_CONTROL,
1034 .vsel_mask = WM8350_DC1_VSEL_MASK,
1035 .enable_reg = WM8350_DCDC_LDO_REQUESTED,
1036 .enable_mask = WM8350_DC1_ENA,
1280 .owner = THIS_MODULE, 1037 .owner = THIS_MODULE,
1281 }, 1038 },
1282 { 1039 {
@@ -1285,6 +1042,8 @@ static const struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = {
1285 .ops = &wm8350_dcdc2_5_ops, 1042 .ops = &wm8350_dcdc2_5_ops,
1286 .irq = WM8350_IRQ_UV_DC2, 1043 .irq = WM8350_IRQ_UV_DC2,
1287 .type = REGULATOR_VOLTAGE, 1044 .type = REGULATOR_VOLTAGE,
1045 .enable_reg = WM8350_DCDC_LDO_REQUESTED,
1046 .enable_mask = WM8350_DC2_ENA,
1288 .owner = THIS_MODULE, 1047 .owner = THIS_MODULE,
1289 }, 1048 },
1290 { 1049 {
@@ -1294,6 +1053,12 @@ static const struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = {
1294 .irq = WM8350_IRQ_UV_DC3, 1053 .irq = WM8350_IRQ_UV_DC3,
1295 .type = REGULATOR_VOLTAGE, 1054 .type = REGULATOR_VOLTAGE,
1296 .n_voltages = WM8350_DCDC_MAX_VSEL + 1, 1055 .n_voltages = WM8350_DCDC_MAX_VSEL + 1,
1056 .min_uV = 850000,
1057 .uV_step = 25000,
1058 .vsel_reg = WM8350_DCDC3_CONTROL,
1059 .vsel_mask = WM8350_DC3_VSEL_MASK,
1060 .enable_reg = WM8350_DCDC_LDO_REQUESTED,
1061 .enable_mask = WM8350_DC3_ENA,
1297 .owner = THIS_MODULE, 1062 .owner = THIS_MODULE,
1298 }, 1063 },
1299 { 1064 {
@@ -1303,6 +1068,12 @@ static const struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = {
1303 .irq = WM8350_IRQ_UV_DC4, 1068 .irq = WM8350_IRQ_UV_DC4,
1304 .type = REGULATOR_VOLTAGE, 1069 .type = REGULATOR_VOLTAGE,
1305 .n_voltages = WM8350_DCDC_MAX_VSEL + 1, 1070 .n_voltages = WM8350_DCDC_MAX_VSEL + 1,
1071 .min_uV = 850000,
1072 .uV_step = 25000,
1073 .vsel_reg = WM8350_DCDC4_CONTROL,
1074 .vsel_mask = WM8350_DC4_VSEL_MASK,
1075 .enable_reg = WM8350_DCDC_LDO_REQUESTED,
1076 .enable_mask = WM8350_DC4_ENA,
1306 .owner = THIS_MODULE, 1077 .owner = THIS_MODULE,
1307 }, 1078 },
1308 { 1079 {
@@ -1311,6 +1082,8 @@ static const struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = {
1311 .ops = &wm8350_dcdc2_5_ops, 1082 .ops = &wm8350_dcdc2_5_ops,
1312 .irq = WM8350_IRQ_UV_DC5, 1083 .irq = WM8350_IRQ_UV_DC5,
1313 .type = REGULATOR_VOLTAGE, 1084 .type = REGULATOR_VOLTAGE,
1085 .enable_reg = WM8350_DCDC_LDO_REQUESTED,
1086 .enable_mask = WM8350_DC5_ENA,
1314 .owner = THIS_MODULE, 1087 .owner = THIS_MODULE,
1315 }, 1088 },
1316 { 1089 {
@@ -1320,6 +1093,12 @@ static const struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = {
1320 .irq = WM8350_IRQ_UV_DC6, 1093 .irq = WM8350_IRQ_UV_DC6,
1321 .type = REGULATOR_VOLTAGE, 1094 .type = REGULATOR_VOLTAGE,
1322 .n_voltages = WM8350_DCDC_MAX_VSEL + 1, 1095 .n_voltages = WM8350_DCDC_MAX_VSEL + 1,
1096 .min_uV = 850000,
1097 .uV_step = 25000,
1098 .vsel_reg = WM8350_DCDC6_CONTROL,
1099 .vsel_mask = WM8350_DC6_VSEL_MASK,
1100 .enable_reg = WM8350_DCDC_LDO_REQUESTED,
1101 .enable_mask = WM8350_DC6_ENA,
1323 .owner = THIS_MODULE, 1102 .owner = THIS_MODULE,
1324 }, 1103 },
1325 { 1104 {
@@ -1329,6 +1108,10 @@ static const struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = {
1329 .irq = WM8350_IRQ_UV_LDO1, 1108 .irq = WM8350_IRQ_UV_LDO1,
1330 .type = REGULATOR_VOLTAGE, 1109 .type = REGULATOR_VOLTAGE,
1331 .n_voltages = WM8350_LDO1_VSEL_MASK + 1, 1110 .n_voltages = WM8350_LDO1_VSEL_MASK + 1,
1111 .vsel_reg = WM8350_LDO1_CONTROL,
1112 .vsel_mask = WM8350_LDO1_VSEL_MASK,
1113 .enable_reg = WM8350_DCDC_LDO_REQUESTED,
1114 .enable_mask = WM8350_LDO1_ENA,
1332 .owner = THIS_MODULE, 1115 .owner = THIS_MODULE,
1333 }, 1116 },
1334 { 1117 {
@@ -1338,6 +1121,10 @@ static const struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = {
1338 .irq = WM8350_IRQ_UV_LDO2, 1121 .irq = WM8350_IRQ_UV_LDO2,
1339 .type = REGULATOR_VOLTAGE, 1122 .type = REGULATOR_VOLTAGE,
1340 .n_voltages = WM8350_LDO2_VSEL_MASK + 1, 1123 .n_voltages = WM8350_LDO2_VSEL_MASK + 1,
1124 .vsel_reg = WM8350_LDO2_CONTROL,
1125 .vsel_mask = WM8350_LDO2_VSEL_MASK,
1126 .enable_reg = WM8350_DCDC_LDO_REQUESTED,
1127 .enable_mask = WM8350_LDO2_ENA,
1341 .owner = THIS_MODULE, 1128 .owner = THIS_MODULE,
1342 }, 1129 },
1343 { 1130 {
@@ -1347,6 +1134,10 @@ static const struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = {
1347 .irq = WM8350_IRQ_UV_LDO3, 1134 .irq = WM8350_IRQ_UV_LDO3,
1348 .type = REGULATOR_VOLTAGE, 1135 .type = REGULATOR_VOLTAGE,
1349 .n_voltages = WM8350_LDO3_VSEL_MASK + 1, 1136 .n_voltages = WM8350_LDO3_VSEL_MASK + 1,
1137 .vsel_reg = WM8350_LDO3_CONTROL,
1138 .vsel_mask = WM8350_LDO3_VSEL_MASK,
1139 .enable_reg = WM8350_DCDC_LDO_REQUESTED,
1140 .enable_mask = WM8350_LDO3_ENA,
1350 .owner = THIS_MODULE, 1141 .owner = THIS_MODULE,
1351 }, 1142 },
1352 { 1143 {
@@ -1356,6 +1147,10 @@ static const struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = {
1356 .irq = WM8350_IRQ_UV_LDO4, 1147 .irq = WM8350_IRQ_UV_LDO4,
1357 .type = REGULATOR_VOLTAGE, 1148 .type = REGULATOR_VOLTAGE,
1358 .n_voltages = WM8350_LDO4_VSEL_MASK + 1, 1149 .n_voltages = WM8350_LDO4_VSEL_MASK + 1,
1150 .vsel_reg = WM8350_LDO4_CONTROL,
1151 .vsel_mask = WM8350_LDO4_VSEL_MASK,
1152 .enable_reg = WM8350_DCDC_LDO_REQUESTED,
1153 .enable_mask = WM8350_LDO4_ENA,
1359 .owner = THIS_MODULE, 1154 .owner = THIS_MODULE,
1360 }, 1155 },
1361 { 1156 {
@@ -1429,6 +1224,7 @@ static int wm8350_regulator_probe(struct platform_device *pdev)
1429 config.dev = &pdev->dev; 1224 config.dev = &pdev->dev;
1430 config.init_data = pdev->dev.platform_data; 1225 config.init_data = pdev->dev.platform_data;
1431 config.driver_data = dev_get_drvdata(&pdev->dev); 1226 config.driver_data = dev_get_drvdata(&pdev->dev);
1227 config.regmap = wm8350->regmap;
1432 1228
1433 /* register regulator */ 1229 /* register regulator */
1434 rdev = regulator_register(&wm8350_reg[pdev->id], &config); 1230 rdev = regulator_register(&wm8350_reg[pdev->id], &config);
diff --git a/drivers/regulator/wm8400-regulator.c b/drivers/regulator/wm8400-regulator.c
index 69a2b7ce5e4a..9035dd053611 100644
--- a/drivers/regulator/wm8400-regulator.c
+++ b/drivers/regulator/wm8400-regulator.c
@@ -28,34 +28,26 @@ static int wm8400_ldo_list_voltage(struct regulator_dev *dev,
28 if (selector < 15) 28 if (selector < 15)
29 return 900000 + (selector * 50000); 29 return 900000 + (selector * 50000);
30 else 30 else
31 return 1600000 + ((selector - 14) * 100000); 31 return 1700000 + ((selector - 15) * 100000);
32} 32}
33 33
34static int wm8400_ldo_map_voltage(struct regulator_dev *dev, 34static int wm8400_ldo_map_voltage(struct regulator_dev *dev,
35 int min_uV, int max_uV) 35 int min_uV, int max_uV)
36{ 36{
37 u16 val; 37 u16 val;
38 int volt;
38 39
39 if (min_uV < 900000 || min_uV > 3300000) 40 if (min_uV < 900000 || min_uV > 3300000)
40 return -EINVAL; 41 return -EINVAL;
41 42
42 if (min_uV < 1700000) { 43 if (min_uV < 1700000) /* Steps of 50mV from 900mV; */
43 /* Steps of 50mV from 900mV; */
44 val = DIV_ROUND_UP(min_uV - 900000, 50000); 44 val = DIV_ROUND_UP(min_uV - 900000, 50000);
45 else /* Steps of 100mV from 1700mV */
46 val = DIV_ROUND_UP(min_uV - 1700000, 100000) + 15;
45 47
46 if ((val * 50000) + 900000 > max_uV) 48 volt = wm8400_ldo_list_voltage(dev, val);
47 return -EINVAL; 49 if (volt < min_uV || volt > max_uV)
48 BUG_ON((val * 50000) + 900000 < min_uV); 50 return -EINVAL;
49 } else {
50 /* Steps of 100mV from 1700mV */
51 val = DIV_ROUND_UP(min_uV - 1700000, 100000);
52
53 if ((val * 100000) + 1700000 > max_uV)
54 return -EINVAL;
55 BUG_ON((val * 100000) + 1700000 < min_uV);
56
57 val += 0xf;
58 }
59 51
60 return val; 52 return val;
61} 53}
@@ -152,6 +144,7 @@ static struct regulator_ops wm8400_dcdc_ops = {
152 .enable = regulator_enable_regmap, 144 .enable = regulator_enable_regmap,
153 .disable = regulator_disable_regmap, 145 .disable = regulator_disable_regmap,
154 .list_voltage = regulator_list_voltage_linear, 146 .list_voltage = regulator_list_voltage_linear,
147 .map_voltage = regulator_map_voltage_linear,
155 .get_voltage_sel = regulator_get_voltage_sel_regmap, 148 .get_voltage_sel = regulator_get_voltage_sel_regmap,
156 .set_voltage_sel = regulator_set_voltage_sel_regmap, 149 .set_voltage_sel = regulator_set_voltage_sel_regmap,
157 .get_mode = wm8400_dcdc_get_mode, 150 .get_mode = wm8400_dcdc_get_mode,
diff --git a/drivers/regulator/wm8994-regulator.c b/drivers/regulator/wm8994-regulator.c
index 9a994316e63c..86bb48db149e 100644
--- a/drivers/regulator/wm8994-regulator.c
+++ b/drivers/regulator/wm8994-regulator.c
@@ -26,8 +26,6 @@
26#include <linux/mfd/wm8994/pdata.h> 26#include <linux/mfd/wm8994/pdata.h>
27 27
28struct wm8994_ldo { 28struct wm8994_ldo {
29 int enable;
30 bool is_enabled;
31 struct regulator_dev *regulator; 29 struct regulator_dev *regulator;
32 struct wm8994 *wm8994; 30 struct wm8994 *wm8994;
33}; 31};
@@ -35,64 +33,9 @@ struct wm8994_ldo {
35#define WM8994_LDO1_MAX_SELECTOR 0x7 33#define WM8994_LDO1_MAX_SELECTOR 0x7
36#define WM8994_LDO2_MAX_SELECTOR 0x3 34#define WM8994_LDO2_MAX_SELECTOR 0x3
37 35
38static int wm8994_ldo_enable(struct regulator_dev *rdev)
39{
40 struct wm8994_ldo *ldo = rdev_get_drvdata(rdev);
41
42 /* If we have no soft control assume that the LDO is always enabled. */
43 if (!ldo->enable)
44 return 0;
45
46 gpio_set_value_cansleep(ldo->enable, 1);
47 ldo->is_enabled = true;
48
49 return 0;
50}
51
52static int wm8994_ldo_disable(struct regulator_dev *rdev)
53{
54 struct wm8994_ldo *ldo = rdev_get_drvdata(rdev);
55
56 /* If we have no soft control assume that the LDO is always enabled. */
57 if (!ldo->enable)
58 return -EINVAL;
59
60 gpio_set_value_cansleep(ldo->enable, 0);
61 ldo->is_enabled = false;
62
63 return 0;
64}
65
66static int wm8994_ldo_is_enabled(struct regulator_dev *rdev)
67{
68 struct wm8994_ldo *ldo = rdev_get_drvdata(rdev);
69
70 return ldo->is_enabled;
71}
72
73static int wm8994_ldo_enable_time(struct regulator_dev *rdev)
74{
75 /* 3ms is fairly conservative but this shouldn't be too performance
76 * critical; can be tweaked per-system if required. */
77 return 3000;
78}
79
80static int wm8994_ldo1_list_voltage(struct regulator_dev *rdev,
81 unsigned int selector)
82{
83 if (selector > WM8994_LDO1_MAX_SELECTOR)
84 return -EINVAL;
85
86 return (selector * 100000) + 2400000;
87}
88
89static struct regulator_ops wm8994_ldo1_ops = { 36static struct regulator_ops wm8994_ldo1_ops = {
90 .enable = wm8994_ldo_enable, 37 .list_voltage = regulator_list_voltage_linear,
91 .disable = wm8994_ldo_disable, 38 .map_voltage = regulator_map_voltage_linear,
92 .is_enabled = wm8994_ldo_is_enabled,
93 .enable_time = wm8994_ldo_enable_time,
94
95 .list_voltage = wm8994_ldo1_list_voltage,
96 .get_voltage_sel = regulator_get_voltage_sel_regmap, 39 .get_voltage_sel = regulator_get_voltage_sel_regmap,
97 .set_voltage_sel = regulator_set_voltage_sel_regmap, 40 .set_voltage_sel = regulator_set_voltage_sel_regmap,
98}; 41};
@@ -124,11 +67,6 @@ static int wm8994_ldo2_list_voltage(struct regulator_dev *rdev,
124} 67}
125 68
126static struct regulator_ops wm8994_ldo2_ops = { 69static struct regulator_ops wm8994_ldo2_ops = {
127 .enable = wm8994_ldo_enable,
128 .disable = wm8994_ldo_disable,
129 .is_enabled = wm8994_ldo_is_enabled,
130 .enable_time = wm8994_ldo_enable_time,
131
132 .list_voltage = wm8994_ldo2_list_voltage, 70 .list_voltage = wm8994_ldo2_list_voltage,
133 .get_voltage_sel = regulator_get_voltage_sel_regmap, 71 .get_voltage_sel = regulator_get_voltage_sel_regmap,
134 .set_voltage_sel = regulator_set_voltage_sel_regmap, 72 .set_voltage_sel = regulator_set_voltage_sel_regmap,
@@ -143,6 +81,9 @@ static const struct regulator_desc wm8994_ldo_desc[] = {
143 .vsel_reg = WM8994_LDO_1, 81 .vsel_reg = WM8994_LDO_1,
144 .vsel_mask = WM8994_LDO1_VSEL_MASK, 82 .vsel_mask = WM8994_LDO1_VSEL_MASK,
145 .ops = &wm8994_ldo1_ops, 83 .ops = &wm8994_ldo1_ops,
84 .min_uV = 2400000,
85 .uV_step = 100000,
86 .enable_time = 3000,
146 .owner = THIS_MODULE, 87 .owner = THIS_MODULE,
147 }, 88 },
148 { 89 {
@@ -153,6 +94,7 @@ static const struct regulator_desc wm8994_ldo_desc[] = {
153 .vsel_reg = WM8994_LDO_2, 94 .vsel_reg = WM8994_LDO_2,
154 .vsel_mask = WM8994_LDO2_VSEL_MASK, 95 .vsel_mask = WM8994_LDO2_VSEL_MASK,
155 .ops = &wm8994_ldo2_ops, 96 .ops = &wm8994_ldo2_ops,
97 .enable_time = 3000,
156 .owner = THIS_MODULE, 98 .owner = THIS_MODULE,
157 }, 99 },
158}; 100};
@@ -176,39 +118,26 @@ static __devinit int wm8994_ldo_probe(struct platform_device *pdev)
176 118
177 ldo->wm8994 = wm8994; 119 ldo->wm8994 = wm8994;
178 120
179 if (pdata->ldo[id].enable && gpio_is_valid(pdata->ldo[id].enable)) {
180 ldo->enable = pdata->ldo[id].enable;
181
182 ret = gpio_request_one(ldo->enable, 0, "WM8994 LDO enable");
183 if (ret < 0) {
184 dev_err(&pdev->dev, "Failed to get enable GPIO: %d\n",
185 ret);
186 goto err;
187 }
188 } else
189 ldo->is_enabled = true;
190
191 config.dev = wm8994->dev; 121 config.dev = wm8994->dev;
192 config.driver_data = ldo; 122 config.driver_data = ldo;
193 config.regmap = wm8994->regmap; 123 config.regmap = wm8994->regmap;
194 if (pdata) 124 if (pdata) {
195 config.init_data = pdata->ldo[id].init_data; 125 config.init_data = pdata->ldo[id].init_data;
126 config.ena_gpio = pdata->ldo[id].enable;
127 }
196 128
197 ldo->regulator = regulator_register(&wm8994_ldo_desc[id], &config); 129 ldo->regulator = regulator_register(&wm8994_ldo_desc[id], &config);
198 if (IS_ERR(ldo->regulator)) { 130 if (IS_ERR(ldo->regulator)) {
199 ret = PTR_ERR(ldo->regulator); 131 ret = PTR_ERR(ldo->regulator);
200 dev_err(wm8994->dev, "Failed to register LDO%d: %d\n", 132 dev_err(wm8994->dev, "Failed to register LDO%d: %d\n",
201 id + 1, ret); 133 id + 1, ret);
202 goto err_gpio; 134 goto err;
203 } 135 }
204 136
205 platform_set_drvdata(pdev, ldo); 137 platform_set_drvdata(pdev, ldo);
206 138
207 return 0; 139 return 0;
208 140
209err_gpio:
210 if (gpio_is_valid(ldo->enable))
211 gpio_free(ldo->enable);
212err: 141err:
213 return ret; 142 return ret;
214} 143}
@@ -220,8 +149,6 @@ static __devexit int wm8994_ldo_remove(struct platform_device *pdev)
220 platform_set_drvdata(pdev, NULL); 149 platform_set_drvdata(pdev, NULL);
221 150
222 regulator_unregister(ldo->regulator); 151 regulator_unregister(ldo->regulator);
223 if (gpio_is_valid(ldo->enable))
224 gpio_free(ldo->enable);
225 152
226 return 0; 153 return 0;
227} 154}
diff --git a/drivers/remoteproc/Kconfig b/drivers/remoteproc/Kconfig
index 24d880e78ec6..f8d818abf98c 100644
--- a/drivers/remoteproc/Kconfig
+++ b/drivers/remoteproc/Kconfig
@@ -4,9 +4,11 @@ menu "Remoteproc drivers (EXPERIMENTAL)"
4config REMOTEPROC 4config REMOTEPROC
5 tristate 5 tristate
6 depends on EXPERIMENTAL 6 depends on EXPERIMENTAL
7 select FW_CONFIG
7 8
8config OMAP_REMOTEPROC 9config OMAP_REMOTEPROC
9 tristate "OMAP remoteproc support" 10 tristate "OMAP remoteproc support"
11 depends on EXPERIMENTAL
10 depends on ARCH_OMAP4 12 depends on ARCH_OMAP4
11 depends on OMAP_IOMMU 13 depends on OMAP_IOMMU
12 select REMOTEPROC 14 select REMOTEPROC
diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c
index 75506ec2840e..39d3aa41adda 100644
--- a/drivers/rpmsg/virtio_rpmsg_bus.c
+++ b/drivers/rpmsg/virtio_rpmsg_bus.c
@@ -188,6 +188,26 @@ static int rpmsg_uevent(struct device *dev, struct kobj_uevent_env *env)
188 rpdev->id.name); 188 rpdev->id.name);
189} 189}
190 190
191/**
192 * __ept_release() - deallocate an rpmsg endpoint
193 * @kref: the ept's reference count
194 *
195 * This function deallocates an ept, and is invoked when its @kref refcount
196 * drops to zero.
197 *
198 * Never invoke this function directly!
199 */
200static void __ept_release(struct kref *kref)
201{
202 struct rpmsg_endpoint *ept = container_of(kref, struct rpmsg_endpoint,
203 refcount);
204 /*
205 * At this point no one holds a reference to ept anymore,
206 * so we can directly free it
207 */
208 kfree(ept);
209}
210
191/* for more info, see below documentation of rpmsg_create_ept() */ 211/* for more info, see below documentation of rpmsg_create_ept() */
192static struct rpmsg_endpoint *__rpmsg_create_ept(struct virtproc_info *vrp, 212static struct rpmsg_endpoint *__rpmsg_create_ept(struct virtproc_info *vrp,
193 struct rpmsg_channel *rpdev, rpmsg_rx_cb_t cb, 213 struct rpmsg_channel *rpdev, rpmsg_rx_cb_t cb,
@@ -206,6 +226,9 @@ static struct rpmsg_endpoint *__rpmsg_create_ept(struct virtproc_info *vrp,
206 return NULL; 226 return NULL;
207 } 227 }
208 228
229 kref_init(&ept->refcount);
230 mutex_init(&ept->cb_lock);
231
209 ept->rpdev = rpdev; 232 ept->rpdev = rpdev;
210 ept->cb = cb; 233 ept->cb = cb;
211 ept->priv = priv; 234 ept->priv = priv;
@@ -238,7 +261,7 @@ rem_idr:
238 idr_remove(&vrp->endpoints, request); 261 idr_remove(&vrp->endpoints, request);
239free_ept: 262free_ept:
240 mutex_unlock(&vrp->endpoints_lock); 263 mutex_unlock(&vrp->endpoints_lock);
241 kfree(ept); 264 kref_put(&ept->refcount, __ept_release);
242 return NULL; 265 return NULL;
243} 266}
244 267
@@ -302,11 +325,17 @@ EXPORT_SYMBOL(rpmsg_create_ept);
302static void 325static void
303__rpmsg_destroy_ept(struct virtproc_info *vrp, struct rpmsg_endpoint *ept) 326__rpmsg_destroy_ept(struct virtproc_info *vrp, struct rpmsg_endpoint *ept)
304{ 327{
328 /* make sure new inbound messages can't find this ept anymore */
305 mutex_lock(&vrp->endpoints_lock); 329 mutex_lock(&vrp->endpoints_lock);
306 idr_remove(&vrp->endpoints, ept->addr); 330 idr_remove(&vrp->endpoints, ept->addr);
307 mutex_unlock(&vrp->endpoints_lock); 331 mutex_unlock(&vrp->endpoints_lock);
308 332
309 kfree(ept); 333 /* make sure in-flight inbound messages won't invoke cb anymore */
334 mutex_lock(&ept->cb_lock);
335 ept->cb = NULL;
336 mutex_unlock(&ept->cb_lock);
337
338 kref_put(&ept->refcount, __ept_release);
310} 339}
311 340
312/** 341/**
@@ -790,12 +819,28 @@ static void rpmsg_recv_done(struct virtqueue *rvq)
790 819
791 /* use the dst addr to fetch the callback of the appropriate user */ 820 /* use the dst addr to fetch the callback of the appropriate user */
792 mutex_lock(&vrp->endpoints_lock); 821 mutex_lock(&vrp->endpoints_lock);
822
793 ept = idr_find(&vrp->endpoints, msg->dst); 823 ept = idr_find(&vrp->endpoints, msg->dst);
824
825 /* let's make sure no one deallocates ept while we use it */
826 if (ept)
827 kref_get(&ept->refcount);
828
794 mutex_unlock(&vrp->endpoints_lock); 829 mutex_unlock(&vrp->endpoints_lock);
795 830
796 if (ept && ept->cb) 831 if (ept) {
797 ept->cb(ept->rpdev, msg->data, msg->len, ept->priv, msg->src); 832 /* make sure ept->cb doesn't go away while we use it */
798 else 833 mutex_lock(&ept->cb_lock);
834
835 if (ept->cb)
836 ept->cb(ept->rpdev, msg->data, msg->len, ept->priv,
837 msg->src);
838
839 mutex_unlock(&ept->cb_lock);
840
841 /* farewell, ept, we don't need you anymore */
842 kref_put(&ept->refcount, __ept_release);
843 } else
799 dev_warn(dev, "msg received with no recepient\n"); 844 dev_warn(dev, "msg received with no recepient\n");
800 845
801 /* publish the real size of the buffer */ 846 /* publish the real size of the buffer */
diff --git a/drivers/rtc/rtc-ab8500.c b/drivers/rtc/rtc-ab8500.c
index 4bcf9ca2818a..370889d0489b 100644
--- a/drivers/rtc/rtc-ab8500.c
+++ b/drivers/rtc/rtc-ab8500.c
@@ -17,6 +17,7 @@
17#include <linux/mfd/abx500.h> 17#include <linux/mfd/abx500.h>
18#include <linux/mfd/abx500/ab8500.h> 18#include <linux/mfd/abx500/ab8500.h>
19#include <linux/delay.h> 19#include <linux/delay.h>
20#include <linux/of.h>
20 21
21#define AB8500_RTC_SOFF_STAT_REG 0x00 22#define AB8500_RTC_SOFF_STAT_REG 0x00
22#define AB8500_RTC_CC_CONF_REG 0x01 23#define AB8500_RTC_CC_CONF_REG 0x01
@@ -422,7 +423,7 @@ static int __devinit ab8500_rtc_probe(struct platform_device *pdev)
422 } 423 }
423 424
424 err = request_threaded_irq(irq, NULL, rtc_alarm_handler, 425 err = request_threaded_irq(irq, NULL, rtc_alarm_handler,
425 IRQF_NO_SUSPEND, "ab8500-rtc", rtc); 426 IRQF_NO_SUSPEND | IRQF_ONESHOT, "ab8500-rtc", rtc);
426 if (err < 0) { 427 if (err < 0) {
427 rtc_device_unregister(rtc); 428 rtc_device_unregister(rtc);
428 return err; 429 return err;
@@ -430,7 +431,6 @@ static int __devinit ab8500_rtc_probe(struct platform_device *pdev)
430 431
431 platform_set_drvdata(pdev, rtc); 432 platform_set_drvdata(pdev, rtc);
432 433
433
434 err = ab8500_sysfs_rtc_register(&pdev->dev); 434 err = ab8500_sysfs_rtc_register(&pdev->dev);
435 if (err) { 435 if (err) {
436 dev_err(&pdev->dev, "sysfs RTC failed to register\n"); 436 dev_err(&pdev->dev, "sysfs RTC failed to register\n");
@@ -454,10 +454,16 @@ static int __devexit ab8500_rtc_remove(struct platform_device *pdev)
454 return 0; 454 return 0;
455} 455}
456 456
457static const struct of_device_id ab8500_rtc_match[] = {
458 { .compatible = "stericsson,ab8500-rtc", },
459 {}
460};
461
457static struct platform_driver ab8500_rtc_driver = { 462static struct platform_driver ab8500_rtc_driver = {
458 .driver = { 463 .driver = {
459 .name = "ab8500-rtc", 464 .name = "ab8500-rtc",
460 .owner = THIS_MODULE, 465 .owner = THIS_MODULE,
466 .of_match_table = ab8500_rtc_match,
461 }, 467 },
462 .probe = ab8500_rtc_probe, 468 .probe = ab8500_rtc_probe,
463 .remove = __devexit_p(ab8500_rtc_remove), 469 .remove = __devexit_p(ab8500_rtc_remove),
diff --git a/drivers/rtc/rtc-mxc.c b/drivers/rtc/rtc-mxc.c
index 5e1d64ee5228..e3e50d69baf8 100644
--- a/drivers/rtc/rtc-mxc.c
+++ b/drivers/rtc/rtc-mxc.c
@@ -202,10 +202,11 @@ static irqreturn_t mxc_rtc_interrupt(int irq, void *dev_id)
202 struct platform_device *pdev = dev_id; 202 struct platform_device *pdev = dev_id;
203 struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 203 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
204 void __iomem *ioaddr = pdata->ioaddr; 204 void __iomem *ioaddr = pdata->ioaddr;
205 unsigned long flags;
205 u32 status; 206 u32 status;
206 u32 events = 0; 207 u32 events = 0;
207 208
208 spin_lock_irq(&pdata->rtc->irq_lock); 209 spin_lock_irqsave(&pdata->rtc->irq_lock, flags);
209 status = readw(ioaddr + RTC_RTCISR) & readw(ioaddr + RTC_RTCIENR); 210 status = readw(ioaddr + RTC_RTCISR) & readw(ioaddr + RTC_RTCIENR);
210 /* clear interrupt sources */ 211 /* clear interrupt sources */
211 writew(status, ioaddr + RTC_RTCISR); 212 writew(status, ioaddr + RTC_RTCISR);
@@ -224,7 +225,7 @@ static irqreturn_t mxc_rtc_interrupt(int irq, void *dev_id)
224 events |= (RTC_PF | RTC_IRQF); 225 events |= (RTC_PF | RTC_IRQF);
225 226
226 rtc_update_irq(pdata->rtc, 1, events); 227 rtc_update_irq(pdata->rtc, 1, events);
227 spin_unlock_irq(&pdata->rtc->irq_lock); 228 spin_unlock_irqrestore(&pdata->rtc->irq_lock, flags);
228 229
229 return IRQ_HANDLED; 230 return IRQ_HANDLED;
230} 231}
diff --git a/drivers/rtc/rtc-spear.c b/drivers/rtc/rtc-spear.c
index 1f76320e545b..e2785479113c 100644
--- a/drivers/rtc/rtc-spear.c
+++ b/drivers/rtc/rtc-spear.c
@@ -458,12 +458,12 @@ static int __devexit spear_rtc_remove(struct platform_device *pdev)
458 clk_disable(config->clk); 458 clk_disable(config->clk);
459 clk_put(config->clk); 459 clk_put(config->clk);
460 iounmap(config->ioaddr); 460 iounmap(config->ioaddr);
461 kfree(config);
462 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 461 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
463 if (res) 462 if (res)
464 release_mem_region(res->start, resource_size(res)); 463 release_mem_region(res->start, resource_size(res));
465 platform_set_drvdata(pdev, NULL); 464 platform_set_drvdata(pdev, NULL);
466 rtc_device_unregister(config->rtc); 465 rtc_device_unregister(config->rtc);
466 kfree(config);
467 467
468 return 0; 468 return 0;
469} 469}
diff --git a/drivers/rtc/rtc-twl.c b/drivers/rtc/rtc-twl.c
index 258abeabf624..c5d06fe83bba 100644
--- a/drivers/rtc/rtc-twl.c
+++ b/drivers/rtc/rtc-twl.c
@@ -510,7 +510,7 @@ static int __devinit twl_rtc_probe(struct platform_device *pdev)
510 } 510 }
511 511
512 ret = request_threaded_irq(irq, NULL, twl_rtc_interrupt, 512 ret = request_threaded_irq(irq, NULL, twl_rtc_interrupt,
513 IRQF_TRIGGER_RISING, 513 IRQF_TRIGGER_RISING | IRQF_ONESHOT,
514 dev_name(&rtc->dev), rtc); 514 dev_name(&rtc->dev), rtc);
515 if (ret < 0) { 515 if (ret < 0) {
516 dev_err(&pdev->dev, "IRQ is not free.\n"); 516 dev_err(&pdev->dev, "IRQ is not free.\n");
diff --git a/drivers/scsi/aic94xx/aic94xx_task.c b/drivers/scsi/aic94xx/aic94xx_task.c
index 532d212b6b2c..393e7ce8e95a 100644
--- a/drivers/scsi/aic94xx/aic94xx_task.c
+++ b/drivers/scsi/aic94xx/aic94xx_task.c
@@ -201,7 +201,7 @@ static void asd_get_response_tasklet(struct asd_ascb *ascb,
201 201
202 if (SAS_STATUS_BUF_SIZE >= sizeof(*resp)) { 202 if (SAS_STATUS_BUF_SIZE >= sizeof(*resp)) {
203 resp->frame_len = le16_to_cpu(*(__le16 *)(r+6)); 203 resp->frame_len = le16_to_cpu(*(__le16 *)(r+6));
204 memcpy(&resp->ending_fis[0], r+16, 24); 204 memcpy(&resp->ending_fis[0], r+16, ATA_RESP_FIS_SIZE);
205 ts->buf_valid_size = sizeof(*resp); 205 ts->buf_valid_size = sizeof(*resp);
206 } 206 }
207 } 207 }
diff --git a/drivers/scsi/bnx2i/bnx2i.h b/drivers/scsi/bnx2i/bnx2i.h
index 0c53c28dc3d3..7e77cf620291 100644
--- a/drivers/scsi/bnx2i/bnx2i.h
+++ b/drivers/scsi/bnx2i/bnx2i.h
@@ -350,6 +350,7 @@ struct bnx2i_hba {
350 struct pci_dev *pcidev; 350 struct pci_dev *pcidev;
351 struct net_device *netdev; 351 struct net_device *netdev;
352 void __iomem *regview; 352 void __iomem *regview;
353 resource_size_t reg_base;
353 354
354 u32 age; 355 u32 age;
355 unsigned long cnic_dev_type; 356 unsigned long cnic_dev_type;
diff --git a/drivers/scsi/bnx2i/bnx2i_hwi.c b/drivers/scsi/bnx2i/bnx2i_hwi.c
index ece47e502282..86a12b48e477 100644
--- a/drivers/scsi/bnx2i/bnx2i_hwi.c
+++ b/drivers/scsi/bnx2i/bnx2i_hwi.c
@@ -2724,7 +2724,6 @@ int bnx2i_map_ep_dbell_regs(struct bnx2i_endpoint *ep)
2724 goto arm_cq; 2724 goto arm_cq;
2725 } 2725 }
2726 2726
2727 reg_base = ep->hba->netdev->base_addr;
2728 if ((test_bit(BNX2I_NX2_DEV_5709, &ep->hba->cnic_dev_type)) && 2727 if ((test_bit(BNX2I_NX2_DEV_5709, &ep->hba->cnic_dev_type)) &&
2729 (ep->hba->mail_queue_access == BNX2I_MQ_BIN_MODE)) { 2728 (ep->hba->mail_queue_access == BNX2I_MQ_BIN_MODE)) {
2730 config2 = REG_RD(ep->hba, BNX2_MQ_CONFIG2); 2729 config2 = REG_RD(ep->hba, BNX2_MQ_CONFIG2);
@@ -2740,7 +2739,7 @@ int bnx2i_map_ep_dbell_regs(struct bnx2i_endpoint *ep)
2740 /* 5709 device in normal node and 5706/5708 devices */ 2739 /* 5709 device in normal node and 5706/5708 devices */
2741 reg_off = CTX_OFFSET + (MB_KERNEL_CTX_SIZE * cid_num); 2740 reg_off = CTX_OFFSET + (MB_KERNEL_CTX_SIZE * cid_num);
2742 2741
2743 ep->qp.ctx_base = ioremap_nocache(reg_base + reg_off, 2742 ep->qp.ctx_base = ioremap_nocache(ep->hba->reg_base + reg_off,
2744 MB_KERNEL_CTX_SIZE); 2743 MB_KERNEL_CTX_SIZE);
2745 if (!ep->qp.ctx_base) 2744 if (!ep->qp.ctx_base)
2746 return -ENOMEM; 2745 return -ENOMEM;
diff --git a/drivers/scsi/bnx2i/bnx2i_iscsi.c b/drivers/scsi/bnx2i/bnx2i_iscsi.c
index f8d516b53161..621538b8b544 100644
--- a/drivers/scsi/bnx2i/bnx2i_iscsi.c
+++ b/drivers/scsi/bnx2i/bnx2i_iscsi.c
@@ -811,13 +811,13 @@ struct bnx2i_hba *bnx2i_alloc_hba(struct cnic_dev *cnic)
811 bnx2i_identify_device(hba); 811 bnx2i_identify_device(hba);
812 bnx2i_setup_host_queue_size(hba, shost); 812 bnx2i_setup_host_queue_size(hba, shost);
813 813
814 hba->reg_base = pci_resource_start(hba->pcidev, 0);
814 if (test_bit(BNX2I_NX2_DEV_5709, &hba->cnic_dev_type)) { 815 if (test_bit(BNX2I_NX2_DEV_5709, &hba->cnic_dev_type)) {
815 hba->regview = ioremap_nocache(hba->netdev->base_addr, 816 hba->regview = pci_iomap(hba->pcidev, 0, BNX2_MQ_CONFIG2);
816 BNX2_MQ_CONFIG2);
817 if (!hba->regview) 817 if (!hba->regview)
818 goto ioreg_map_err; 818 goto ioreg_map_err;
819 } else if (test_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type)) { 819 } else if (test_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type)) {
820 hba->regview = ioremap_nocache(hba->netdev->base_addr, 4096); 820 hba->regview = pci_iomap(hba->pcidev, 0, 4096);
821 if (!hba->regview) 821 if (!hba->regview)
822 goto ioreg_map_err; 822 goto ioreg_map_err;
823 } 823 }
@@ -884,7 +884,7 @@ cid_que_err:
884 bnx2i_free_mp_bdt(hba); 884 bnx2i_free_mp_bdt(hba);
885mp_bdt_mem_err: 885mp_bdt_mem_err:
886 if (hba->regview) { 886 if (hba->regview) {
887 iounmap(hba->regview); 887 pci_iounmap(hba->pcidev, hba->regview);
888 hba->regview = NULL; 888 hba->regview = NULL;
889 } 889 }
890ioreg_map_err: 890ioreg_map_err:
@@ -910,7 +910,7 @@ void bnx2i_free_hba(struct bnx2i_hba *hba)
910 pci_dev_put(hba->pcidev); 910 pci_dev_put(hba->pcidev);
911 911
912 if (hba->regview) { 912 if (hba->regview) {
913 iounmap(hba->regview); 913 pci_iounmap(hba->pcidev, hba->regview);
914 hba->regview = NULL; 914 hba->regview = NULL;
915 } 915 }
916 bnx2i_free_mp_bdt(hba); 916 bnx2i_free_mp_bdt(hba);
diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
index 441d88ad99a7..d109cc3a17b6 100644
--- a/drivers/scsi/libsas/sas_ata.c
+++ b/drivers/scsi/libsas/sas_ata.c
@@ -139,12 +139,12 @@ static void sas_ata_task_done(struct sas_task *task)
139 if (stat->stat == SAS_PROTO_RESPONSE || stat->stat == SAM_STAT_GOOD || 139 if (stat->stat == SAS_PROTO_RESPONSE || stat->stat == SAM_STAT_GOOD ||
140 ((stat->stat == SAM_STAT_CHECK_CONDITION && 140 ((stat->stat == SAM_STAT_CHECK_CONDITION &&
141 dev->sata_dev.command_set == ATAPI_COMMAND_SET))) { 141 dev->sata_dev.command_set == ATAPI_COMMAND_SET))) {
142 ata_tf_from_fis(resp->ending_fis, &dev->sata_dev.tf); 142 memcpy(dev->sata_dev.fis, resp->ending_fis, ATA_RESP_FIS_SIZE);
143 143
144 if (!link->sactive) { 144 if (!link->sactive) {
145 qc->err_mask |= ac_err_mask(dev->sata_dev.tf.command); 145 qc->err_mask |= ac_err_mask(dev->sata_dev.fis[2]);
146 } else { 146 } else {
147 link->eh_info.err_mask |= ac_err_mask(dev->sata_dev.tf.command); 147 link->eh_info.err_mask |= ac_err_mask(dev->sata_dev.fis[2]);
148 if (unlikely(link->eh_info.err_mask)) 148 if (unlikely(link->eh_info.err_mask))
149 qc->flags |= ATA_QCFLAG_FAILED; 149 qc->flags |= ATA_QCFLAG_FAILED;
150 } 150 }
@@ -161,8 +161,8 @@ static void sas_ata_task_done(struct sas_task *task)
161 qc->flags |= ATA_QCFLAG_FAILED; 161 qc->flags |= ATA_QCFLAG_FAILED;
162 } 162 }
163 163
164 dev->sata_dev.tf.feature = 0x04; /* status err */ 164 dev->sata_dev.fis[3] = 0x04; /* status err */
165 dev->sata_dev.tf.command = ATA_ERR; 165 dev->sata_dev.fis[2] = ATA_ERR;
166 } 166 }
167 } 167 }
168 168
@@ -269,7 +269,7 @@ static bool sas_ata_qc_fill_rtf(struct ata_queued_cmd *qc)
269{ 269{
270 struct domain_device *dev = qc->ap->private_data; 270 struct domain_device *dev = qc->ap->private_data;
271 271
272 memcpy(&qc->result_tf, &dev->sata_dev.tf, sizeof(qc->result_tf)); 272 ata_tf_from_fis(dev->sata_dev.fis, &qc->result_tf);
273 return true; 273 return true;
274} 274}
275 275
diff --git a/drivers/scsi/qla2xxx/qla_target.c b/drivers/scsi/qla2xxx/qla_target.c
index 6986552b47e6..77759c78cc21 100644
--- a/drivers/scsi/qla2xxx/qla_target.c
+++ b/drivers/scsi/qla2xxx/qla_target.c
@@ -3960,7 +3960,7 @@ void qlt_async_event(uint16_t code, struct scsi_qla_host *vha,
3960{ 3960{
3961 struct qla_hw_data *ha = vha->hw; 3961 struct qla_hw_data *ha = vha->hw;
3962 struct qla_tgt *tgt = ha->tgt.qla_tgt; 3962 struct qla_tgt *tgt = ha->tgt.qla_tgt;
3963 int reason_code; 3963 int login_code;
3964 3964
3965 ql_dbg(ql_dbg_tgt, vha, 0xe039, 3965 ql_dbg(ql_dbg_tgt, vha, 0xe039,
3966 "scsi(%ld): ha state %d init_done %d oper_mode %d topo %d\n", 3966 "scsi(%ld): ha state %d init_done %d oper_mode %d topo %d\n",
@@ -4003,9 +4003,9 @@ void qlt_async_event(uint16_t code, struct scsi_qla_host *vha,
4003 { 4003 {
4004 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03b, 4004 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03b,
4005 "qla_target(%d): Async LOOP_UP occured " 4005 "qla_target(%d): Async LOOP_UP occured "
4006 "(m[1]=%x, m[2]=%x, m[3]=%x, m[4]=%x)", vha->vp_idx, 4006 "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha->vp_idx,
4007 le16_to_cpu(mailbox[1]), le16_to_cpu(mailbox[2]), 4007 le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]),
4008 le16_to_cpu(mailbox[3]), le16_to_cpu(mailbox[4])); 4008 le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3]));
4009 if (tgt->link_reinit_iocb_pending) { 4009 if (tgt->link_reinit_iocb_pending) {
4010 qlt_send_notify_ack(vha, (void *)&tgt->link_reinit_iocb, 4010 qlt_send_notify_ack(vha, (void *)&tgt->link_reinit_iocb,
4011 0, 0, 0, 0, 0, 0); 4011 0, 0, 0, 0, 0, 0);
@@ -4020,23 +4020,24 @@ void qlt_async_event(uint16_t code, struct scsi_qla_host *vha,
4020 case MBA_RSCN_UPDATE: 4020 case MBA_RSCN_UPDATE:
4021 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03c, 4021 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03c,
4022 "qla_target(%d): Async event %#x occured " 4022 "qla_target(%d): Async event %#x occured "
4023 "(m[1]=%x, m[2]=%x, m[3]=%x, m[4]=%x)", vha->vp_idx, code, 4023 "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha->vp_idx, code,
4024 le16_to_cpu(mailbox[1]), le16_to_cpu(mailbox[2]), 4024 le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]),
4025 le16_to_cpu(mailbox[3]), le16_to_cpu(mailbox[4])); 4025 le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3]));
4026 break; 4026 break;
4027 4027
4028 case MBA_PORT_UPDATE: 4028 case MBA_PORT_UPDATE:
4029 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03d, 4029 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03d,
4030 "qla_target(%d): Port update async event %#x " 4030 "qla_target(%d): Port update async event %#x "
4031 "occured: updating the ports database (m[1]=%x, m[2]=%x, " 4031 "occured: updating the ports database (m[0]=%x, m[1]=%x, "
4032 "m[3]=%x, m[4]=%x)", vha->vp_idx, code, 4032 "m[2]=%x, m[3]=%x)", vha->vp_idx, code,
4033 le16_to_cpu(mailbox[1]), le16_to_cpu(mailbox[2]), 4033 le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]),
4034 le16_to_cpu(mailbox[3]), le16_to_cpu(mailbox[4])); 4034 le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3]));
4035 reason_code = le16_to_cpu(mailbox[2]); 4035
4036 if (reason_code == 0x4) 4036 login_code = le16_to_cpu(mailbox[2]);
4037 if (login_code == 0x4)
4037 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03e, 4038 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03e,
4038 "Async MB 2: Got PLOGI Complete\n"); 4039 "Async MB 2: Got PLOGI Complete\n");
4039 else if (reason_code == 0x7) 4040 else if (login_code == 0x7)
4040 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03f, 4041 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03f,
4041 "Async MB 2: Port Logged Out\n"); 4042 "Async MB 2: Port Logged Out\n");
4042 break; 4043 break;
@@ -4044,9 +4045,9 @@ void qlt_async_event(uint16_t code, struct scsi_qla_host *vha,
4044 default: 4045 default:
4045 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf040, 4046 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf040,
4046 "qla_target(%d): Async event %#x occured: " 4047 "qla_target(%d): Async event %#x occured: "
4047 "ignore (m[1]=%x, m[2]=%x, m[3]=%x, m[4]=%x)", vha->vp_idx, 4048 "ignore (m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha->vp_idx,
4048 code, le16_to_cpu(mailbox[1]), le16_to_cpu(mailbox[2]), 4049 code, le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]),
4049 le16_to_cpu(mailbox[3]), le16_to_cpu(mailbox[4])); 4050 le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3]));
4050 break; 4051 break;
4051 } 4052 }
4052 4053
diff --git a/drivers/target/tcm_fc/tfc_sess.c b/drivers/target/tcm_fc/tfc_sess.c
index cb99da920068..87901fa74dd7 100644
--- a/drivers/target/tcm_fc/tfc_sess.c
+++ b/drivers/target/tcm_fc/tfc_sess.c
@@ -58,7 +58,8 @@ static struct ft_tport *ft_tport_create(struct fc_lport *lport)
58 struct ft_tport *tport; 58 struct ft_tport *tport;
59 int i; 59 int i;
60 60
61 tport = rcu_dereference(lport->prov[FC_TYPE_FCP]); 61 tport = rcu_dereference_protected(lport->prov[FC_TYPE_FCP],
62 lockdep_is_held(&ft_lport_lock));
62 if (tport && tport->tpg) 63 if (tport && tport->tpg)
63 return tport; 64 return tport;
64 65
diff --git a/drivers/tty/hvc/hvc_opal.c b/drivers/tty/hvc/hvc_opal.c
index ced26c8ccd57..0d2ea0c224c3 100644
--- a/drivers/tty/hvc/hvc_opal.c
+++ b/drivers/tty/hvc/hvc_opal.c
@@ -401,7 +401,7 @@ out:
401} 401}
402 402
403#ifdef CONFIG_PPC_EARLY_DEBUG_OPAL_RAW 403#ifdef CONFIG_PPC_EARLY_DEBUG_OPAL_RAW
404void __init udbg_init_debug_opal(void) 404void __init udbg_init_debug_opal_raw(void)
405{ 405{
406 u32 index = CONFIG_PPC_EARLY_DEBUG_OPAL_VTERMNO; 406 u32 index = CONFIG_PPC_EARLY_DEBUG_OPAL_VTERMNO;
407 hvc_opal_privs[index] = &hvc_opal_boot_priv; 407 hvc_opal_privs[index] = &hvc_opal_boot_priv;
diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c
index 8fd398dffced..ee469274a3fe 100644
--- a/drivers/usb/class/cdc-wdm.c
+++ b/drivers/usb/class/cdc-wdm.c
@@ -500,6 +500,8 @@ retry:
500 goto retry; 500 goto retry;
501 } 501 }
502 if (!desc->reslength) { /* zero length read */ 502 if (!desc->reslength) { /* zero length read */
503 dev_dbg(&desc->intf->dev, "%s: zero length - clearing WDM_READ\n", __func__);
504 clear_bit(WDM_READ, &desc->flags);
503 spin_unlock_irq(&desc->iuspin); 505 spin_unlock_irq(&desc->iuspin);
504 goto retry; 506 goto retry;
505 } 507 }
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 25a7422ee657..8fb484984c86 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -2324,12 +2324,16 @@ static unsigned hub_is_wusb(struct usb_hub *hub)
2324static int hub_port_reset(struct usb_hub *hub, int port1, 2324static int hub_port_reset(struct usb_hub *hub, int port1,
2325 struct usb_device *udev, unsigned int delay, bool warm); 2325 struct usb_device *udev, unsigned int delay, bool warm);
2326 2326
2327/* Is a USB 3.0 port in the Inactive state? */ 2327/* Is a USB 3.0 port in the Inactive or Complinance Mode state?
2328static bool hub_port_inactive(struct usb_hub *hub, u16 portstatus) 2328 * Port worm reset is required to recover
2329 */
2330static bool hub_port_warm_reset_required(struct usb_hub *hub, u16 portstatus)
2329{ 2331{
2330 return hub_is_superspeed(hub->hdev) && 2332 return hub_is_superspeed(hub->hdev) &&
2331 (portstatus & USB_PORT_STAT_LINK_STATE) == 2333 (((portstatus & USB_PORT_STAT_LINK_STATE) ==
2332 USB_SS_PORT_LS_SS_INACTIVE; 2334 USB_SS_PORT_LS_SS_INACTIVE) ||
2335 ((portstatus & USB_PORT_STAT_LINK_STATE) ==
2336 USB_SS_PORT_LS_COMP_MOD)) ;
2333} 2337}
2334 2338
2335static int hub_port_wait_reset(struct usb_hub *hub, int port1, 2339static int hub_port_wait_reset(struct usb_hub *hub, int port1,
@@ -2365,7 +2369,7 @@ static int hub_port_wait_reset(struct usb_hub *hub, int port1,
2365 * 2369 *
2366 * See https://bugzilla.kernel.org/show_bug.cgi?id=41752 2370 * See https://bugzilla.kernel.org/show_bug.cgi?id=41752
2367 */ 2371 */
2368 if (hub_port_inactive(hub, portstatus)) { 2372 if (hub_port_warm_reset_required(hub, portstatus)) {
2369 int ret; 2373 int ret;
2370 2374
2371 if ((portchange & USB_PORT_STAT_C_CONNECTION)) 2375 if ((portchange & USB_PORT_STAT_C_CONNECTION))
@@ -4408,9 +4412,7 @@ static void hub_events(void)
4408 /* Warm reset a USB3 protocol port if it's in 4412 /* Warm reset a USB3 protocol port if it's in
4409 * SS.Inactive state. 4413 * SS.Inactive state.
4410 */ 4414 */
4411 if (hub_is_superspeed(hub->hdev) && 4415 if (hub_port_warm_reset_required(hub, portstatus)) {
4412 (portstatus & USB_PORT_STAT_LINK_STATE)
4413 == USB_SS_PORT_LS_SS_INACTIVE) {
4414 dev_dbg(hub_dev, "warm reset port %d\n", i); 4416 dev_dbg(hub_dev, "warm reset port %d\n", i);
4415 hub_port_reset(hub, i, NULL, 4417 hub_port_reset(hub, i, NULL,
4416 HUB_BH_RESET_TIME, true); 4418 HUB_BH_RESET_TIME, true);
diff --git a/drivers/usb/host/ehci-omap.c b/drivers/usb/host/ehci-omap.c
index 17cfb8a1131c..c30435499a02 100644
--- a/drivers/usb/host/ehci-omap.c
+++ b/drivers/usb/host/ehci-omap.c
@@ -281,14 +281,13 @@ static int ehci_hcd_omap_probe(struct platform_device *pdev)
281 } 281 }
282 } 282 }
283 283
284 /* Hold PHYs in reset while initializing EHCI controller */
284 if (pdata->phy_reset) { 285 if (pdata->phy_reset) {
285 if (gpio_is_valid(pdata->reset_gpio_port[0])) 286 if (gpio_is_valid(pdata->reset_gpio_port[0]))
286 gpio_request_one(pdata->reset_gpio_port[0], 287 gpio_set_value_cansleep(pdata->reset_gpio_port[0], 0);
287 GPIOF_OUT_INIT_LOW, "USB1 PHY reset");
288 288
289 if (gpio_is_valid(pdata->reset_gpio_port[1])) 289 if (gpio_is_valid(pdata->reset_gpio_port[1]))
290 gpio_request_one(pdata->reset_gpio_port[1], 290 gpio_set_value_cansleep(pdata->reset_gpio_port[1], 0);
291 GPIOF_OUT_INIT_LOW, "USB2 PHY reset");
292 291
293 /* Hold the PHY in RESET for enough time till DIR is high */ 292 /* Hold the PHY in RESET for enough time till DIR is high */
294 udelay(10); 293 udelay(10);
@@ -330,6 +329,11 @@ static int ehci_hcd_omap_probe(struct platform_device *pdev)
330 omap_ehci->hcs_params = readl(&omap_ehci->caps->hcs_params); 329 omap_ehci->hcs_params = readl(&omap_ehci->caps->hcs_params);
331 330
332 ehci_reset(omap_ehci); 331 ehci_reset(omap_ehci);
332 ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
333 if (ret) {
334 dev_err(dev, "failed to add hcd with err %d\n", ret);
335 goto err_add_hcd;
336 }
333 337
334 if (pdata->phy_reset) { 338 if (pdata->phy_reset) {
335 /* Hold the PHY in RESET for enough time till 339 /* Hold the PHY in RESET for enough time till
@@ -344,12 +348,6 @@ static int ehci_hcd_omap_probe(struct platform_device *pdev)
344 gpio_set_value_cansleep(pdata->reset_gpio_port[1], 1); 348 gpio_set_value_cansleep(pdata->reset_gpio_port[1], 1);
345 } 349 }
346 350
347 ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
348 if (ret) {
349 dev_err(dev, "failed to add hcd with err %d\n", ret);
350 goto err_add_hcd;
351 }
352
353 /* root ports should always stay powered */ 351 /* root ports should always stay powered */
354 ehci_port_power(omap_ehci, 1); 352 ehci_port_power(omap_ehci, 1);
355 353
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 2732ef660c5c..7b01094d7993 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -462,6 +462,42 @@ void xhci_test_and_clear_bit(struct xhci_hcd *xhci, __le32 __iomem **port_array,
462 } 462 }
463} 463}
464 464
465/* Updates Link Status for super Speed port */
466static void xhci_hub_report_link_state(u32 *status, u32 status_reg)
467{
468 u32 pls = status_reg & PORT_PLS_MASK;
469
470 /* resume state is a xHCI internal state.
471 * Do not report it to usb core.
472 */
473 if (pls == XDEV_RESUME)
474 return;
475
476 /* When the CAS bit is set then warm reset
477 * should be performed on port
478 */
479 if (status_reg & PORT_CAS) {
480 /* The CAS bit can be set while the port is
481 * in any link state.
482 * Only roothubs have CAS bit, so we
483 * pretend to be in compliance mode
484 * unless we're already in compliance
485 * or the inactive state.
486 */
487 if (pls != USB_SS_PORT_LS_COMP_MOD &&
488 pls != USB_SS_PORT_LS_SS_INACTIVE) {
489 pls = USB_SS_PORT_LS_COMP_MOD;
490 }
491 /* Return also connection bit -
492 * hub state machine resets port
493 * when this bit is set.
494 */
495 pls |= USB_PORT_STAT_CONNECTION;
496 }
497 /* update status field */
498 *status |= pls;
499}
500
465int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, 501int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
466 u16 wIndex, char *buf, u16 wLength) 502 u16 wIndex, char *buf, u16 wLength)
467{ 503{
@@ -606,13 +642,9 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
606 else 642 else
607 status |= USB_PORT_STAT_POWER; 643 status |= USB_PORT_STAT_POWER;
608 } 644 }
609 /* Port Link State */ 645 /* Update Port Link State for super speed ports*/
610 if (hcd->speed == HCD_USB3) { 646 if (hcd->speed == HCD_USB3) {
611 /* resume state is a xHCI internal state. 647 xhci_hub_report_link_state(&status, temp);
612 * Do not report it to usb core.
613 */
614 if ((temp & PORT_PLS_MASK) != XDEV_RESUME)
615 status |= (temp & PORT_PLS_MASK);
616 } 648 }
617 if (bus_state->port_c_suspend & (1 << wIndex)) 649 if (bus_state->port_c_suspend & (1 << wIndex))
618 status |= 1 << USB_PORT_FEAT_C_SUSPEND; 650 status |= 1 << USB_PORT_FEAT_C_SUSPEND;
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 23b4aefd1036..8275645889da 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -885,6 +885,17 @@ static void update_ring_for_set_deq_completion(struct xhci_hcd *xhci,
885 num_trbs_free_temp = ep_ring->num_trbs_free; 885 num_trbs_free_temp = ep_ring->num_trbs_free;
886 dequeue_temp = ep_ring->dequeue; 886 dequeue_temp = ep_ring->dequeue;
887 887
888 /* If we get two back-to-back stalls, and the first stalled transfer
889 * ends just before a link TRB, the dequeue pointer will be left on
890 * the link TRB by the code in the while loop. So we have to update
891 * the dequeue pointer one segment further, or we'll jump off
892 * the segment into la-la-land.
893 */
894 if (last_trb(xhci, ep_ring, ep_ring->deq_seg, ep_ring->dequeue)) {
895 ep_ring->deq_seg = ep_ring->deq_seg->next;
896 ep_ring->dequeue = ep_ring->deq_seg->trbs;
897 }
898
888 while (ep_ring->dequeue != dev->eps[ep_index].queued_deq_ptr) { 899 while (ep_ring->dequeue != dev->eps[ep_index].queued_deq_ptr) {
889 /* We have more usable TRBs */ 900 /* We have more usable TRBs */
890 ep_ring->num_trbs_free++; 901 ep_ring->num_trbs_free++;
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index de3d6e3e57be..55c0785810c9 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -341,7 +341,11 @@ struct xhci_op_regs {
341#define PORT_PLC (1 << 22) 341#define PORT_PLC (1 << 22)
342/* port configure error change - port failed to configure its link partner */ 342/* port configure error change - port failed to configure its link partner */
343#define PORT_CEC (1 << 23) 343#define PORT_CEC (1 << 23)
344/* bit 24 reserved */ 344/* Cold Attach Status - xHC can set this bit to report device attached during
345 * Sx state. Warm port reset should be perfomed to clear this bit and move port
346 * to connected state.
347 */
348#define PORT_CAS (1 << 24)
345/* wake on connect (enable) */ 349/* wake on connect (enable) */
346#define PORT_WKCONN_E (1 << 25) 350#define PORT_WKCONN_E (1 << 25)
347/* wake on disconnect (enable) */ 351/* wake on disconnect (enable) */
diff --git a/drivers/usb/serial/metro-usb.c b/drivers/usb/serial/metro-usb.c
index 81423f7361db..d47eb06fe463 100644
--- a/drivers/usb/serial/metro-usb.c
+++ b/drivers/usb/serial/metro-usb.c
@@ -222,14 +222,6 @@ static int metrousb_open(struct tty_struct *tty, struct usb_serial_port *port)
222 metro_priv->throttled = 0; 222 metro_priv->throttled = 0;
223 spin_unlock_irqrestore(&metro_priv->lock, flags); 223 spin_unlock_irqrestore(&metro_priv->lock, flags);
224 224
225 /*
226 * Force low_latency on so that our tty_push actually forces the data
227 * through, otherwise it is scheduled, and with high data rates (like
228 * with OHCI) data can get lost.
229 */
230 if (tty)
231 tty->low_latency = 1;
232
233 /* Clear the urb pipe. */ 225 /* Clear the urb pipe. */
234 usb_clear_halt(serial->dev, port->interrupt_in_urb->pipe); 226 usb_clear_halt(serial->dev, port->interrupt_in_urb->pipe);
235 227
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index adf8ce72be50..417ab1b0aa30 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -497,6 +497,15 @@ static void option_instat_callback(struct urb *urb);
497 497
498/* MediaTek products */ 498/* MediaTek products */
499#define MEDIATEK_VENDOR_ID 0x0e8d 499#define MEDIATEK_VENDOR_ID 0x0e8d
500#define MEDIATEK_PRODUCT_DC_1COM 0x00a0
501#define MEDIATEK_PRODUCT_DC_4COM 0x00a5
502#define MEDIATEK_PRODUCT_DC_5COM 0x00a4
503#define MEDIATEK_PRODUCT_7208_1COM 0x7101
504#define MEDIATEK_PRODUCT_7208_2COM 0x7102
505#define MEDIATEK_PRODUCT_FP_1COM 0x0003
506#define MEDIATEK_PRODUCT_FP_2COM 0x0023
507#define MEDIATEK_PRODUCT_FPDC_1COM 0x0043
508#define MEDIATEK_PRODUCT_FPDC_2COM 0x0033
500 509
501/* Cellient products */ 510/* Cellient products */
502#define CELLIENT_VENDOR_ID 0x2692 511#define CELLIENT_VENDOR_ID 0x2692
@@ -554,6 +563,10 @@ static const struct option_blacklist_info net_intf1_blacklist = {
554 .reserved = BIT(1), 563 .reserved = BIT(1),
555}; 564};
556 565
566static const struct option_blacklist_info net_intf2_blacklist = {
567 .reserved = BIT(2),
568};
569
557static const struct option_blacklist_info net_intf3_blacklist = { 570static const struct option_blacklist_info net_intf3_blacklist = {
558 .reserved = BIT(3), 571 .reserved = BIT(3),
559}; 572};
@@ -1099,6 +1112,8 @@ static const struct usb_device_id option_ids[] = {
1099 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1298, 0xff, 0xff, 0xff) }, 1112 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1298, 0xff, 0xff, 0xff) },
1100 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1299, 0xff, 0xff, 0xff) }, 1113 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1299, 0xff, 0xff, 0xff) },
1101 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1300, 0xff, 0xff, 0xff) }, 1114 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1300, 0xff, 0xff, 0xff) },
1115 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1402, 0xff, 0xff, 0xff),
1116 .driver_info = (kernel_ulong_t)&net_intf2_blacklist },
1102 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x2002, 0xff, 1117 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x2002, 0xff,
1103 0xff, 0xff), .driver_info = (kernel_ulong_t)&zte_k3765_z_blacklist }, 1118 0xff, 0xff), .driver_info = (kernel_ulong_t)&zte_k3765_z_blacklist },
1104 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x2003, 0xff, 0xff, 0xff) }, 1119 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x2003, 0xff, 0xff, 0xff) },
@@ -1240,6 +1255,17 @@ static const struct usb_device_id option_ids[] = {
1240 { USB_DEVICE_AND_INTERFACE_INFO(MEDIATEK_VENDOR_ID, 0x00a1, 0xff, 0x02, 0x01) }, 1255 { USB_DEVICE_AND_INTERFACE_INFO(MEDIATEK_VENDOR_ID, 0x00a1, 0xff, 0x02, 0x01) },
1241 { USB_DEVICE_AND_INTERFACE_INFO(MEDIATEK_VENDOR_ID, 0x00a2, 0xff, 0x00, 0x00) }, 1256 { USB_DEVICE_AND_INTERFACE_INFO(MEDIATEK_VENDOR_ID, 0x00a2, 0xff, 0x00, 0x00) },
1242 { USB_DEVICE_AND_INTERFACE_INFO(MEDIATEK_VENDOR_ID, 0x00a2, 0xff, 0x02, 0x01) }, /* MediaTek MT6276M modem & app port */ 1257 { USB_DEVICE_AND_INTERFACE_INFO(MEDIATEK_VENDOR_ID, 0x00a2, 0xff, 0x02, 0x01) }, /* MediaTek MT6276M modem & app port */
1258 { USB_DEVICE_AND_INTERFACE_INFO(MEDIATEK_VENDOR_ID, MEDIATEK_PRODUCT_DC_1COM, 0x0a, 0x00, 0x00) },
1259 { USB_DEVICE_AND_INTERFACE_INFO(MEDIATEK_VENDOR_ID, MEDIATEK_PRODUCT_DC_5COM, 0xff, 0x02, 0x01) },
1260 { USB_DEVICE_AND_INTERFACE_INFO(MEDIATEK_VENDOR_ID, MEDIATEK_PRODUCT_DC_5COM, 0xff, 0x00, 0x00) },
1261 { USB_DEVICE_AND_INTERFACE_INFO(MEDIATEK_VENDOR_ID, MEDIATEK_PRODUCT_DC_4COM, 0xff, 0x02, 0x01) },
1262 { USB_DEVICE_AND_INTERFACE_INFO(MEDIATEK_VENDOR_ID, MEDIATEK_PRODUCT_DC_4COM, 0xff, 0x00, 0x00) },
1263 { USB_DEVICE_AND_INTERFACE_INFO(MEDIATEK_VENDOR_ID, MEDIATEK_PRODUCT_7208_1COM, 0x02, 0x00, 0x00) },
1264 { USB_DEVICE_AND_INTERFACE_INFO(MEDIATEK_VENDOR_ID, MEDIATEK_PRODUCT_7208_2COM, 0x02, 0x02, 0x01) },
1265 { USB_DEVICE_AND_INTERFACE_INFO(MEDIATEK_VENDOR_ID, MEDIATEK_PRODUCT_FP_1COM, 0x0a, 0x00, 0x00) },
1266 { USB_DEVICE_AND_INTERFACE_INFO(MEDIATEK_VENDOR_ID, MEDIATEK_PRODUCT_FP_2COM, 0x0a, 0x00, 0x00) },
1267 { USB_DEVICE_AND_INTERFACE_INFO(MEDIATEK_VENDOR_ID, MEDIATEK_PRODUCT_FPDC_1COM, 0x0a, 0x00, 0x00) },
1268 { USB_DEVICE_AND_INTERFACE_INFO(MEDIATEK_VENDOR_ID, MEDIATEK_PRODUCT_FPDC_2COM, 0x0a, 0x00, 0x00) },
1243 { USB_DEVICE(CELLIENT_VENDOR_ID, CELLIENT_PRODUCT_MEN200) }, 1269 { USB_DEVICE(CELLIENT_VENDOR_ID, CELLIENT_PRODUCT_MEN200) },
1244 { } /* Terminating entry */ 1270 { } /* Terminating entry */
1245}; 1271};
diff --git a/drivers/video/omap2/dss/core.c b/drivers/video/omap2/dss/core.c
index 5066eee10ccf..58bd9c27369d 100644
--- a/drivers/video/omap2/dss/core.c
+++ b/drivers/video/omap2/dss/core.c
@@ -32,6 +32,7 @@
32#include <linux/io.h> 32#include <linux/io.h>
33#include <linux/device.h> 33#include <linux/device.h>
34#include <linux/regulator/consumer.h> 34#include <linux/regulator/consumer.h>
35#include <linux/suspend.h>
35 36
36#include <video/omapdss.h> 37#include <video/omapdss.h>
37 38
@@ -201,6 +202,28 @@ int dss_debugfs_create_file(const char *name, void (*write)(struct seq_file *))
201#endif /* CONFIG_DEBUG_FS && CONFIG_OMAP2_DSS_DEBUG_SUPPORT */ 202#endif /* CONFIG_DEBUG_FS && CONFIG_OMAP2_DSS_DEBUG_SUPPORT */
202 203
203/* PLATFORM DEVICE */ 204/* PLATFORM DEVICE */
205static int omap_dss_pm_notif(struct notifier_block *b, unsigned long v, void *d)
206{
207 DSSDBG("pm notif %lu\n", v);
208
209 switch (v) {
210 case PM_SUSPEND_PREPARE:
211 DSSDBG("suspending displays\n");
212 return dss_suspend_all_devices();
213
214 case PM_POST_SUSPEND:
215 DSSDBG("resuming displays\n");
216 return dss_resume_all_devices();
217
218 default:
219 return 0;
220 }
221}
222
223static struct notifier_block omap_dss_pm_notif_block = {
224 .notifier_call = omap_dss_pm_notif,
225};
226
204static int __init omap_dss_probe(struct platform_device *pdev) 227static int __init omap_dss_probe(struct platform_device *pdev)
205{ 228{
206 struct omap_dss_board_info *pdata = pdev->dev.platform_data; 229 struct omap_dss_board_info *pdata = pdev->dev.platform_data;
@@ -224,6 +247,8 @@ static int __init omap_dss_probe(struct platform_device *pdev)
224 else if (pdata->default_device) 247 else if (pdata->default_device)
225 core.default_display_name = pdata->default_device->name; 248 core.default_display_name = pdata->default_device->name;
226 249
250 register_pm_notifier(&omap_dss_pm_notif_block);
251
227 return 0; 252 return 0;
228 253
229err_debugfs: 254err_debugfs:
@@ -233,6 +258,8 @@ err_debugfs:
233 258
234static int omap_dss_remove(struct platform_device *pdev) 259static int omap_dss_remove(struct platform_device *pdev)
235{ 260{
261 unregister_pm_notifier(&omap_dss_pm_notif_block);
262
236 dss_uninitialize_debugfs(); 263 dss_uninitialize_debugfs();
237 264
238 dss_uninit_overlays(pdev); 265 dss_uninit_overlays(pdev);
@@ -247,25 +274,9 @@ static void omap_dss_shutdown(struct platform_device *pdev)
247 dss_disable_all_devices(); 274 dss_disable_all_devices();
248} 275}
249 276
250static int omap_dss_suspend(struct platform_device *pdev, pm_message_t state)
251{
252 DSSDBG("suspend %d\n", state.event);
253
254 return dss_suspend_all_devices();
255}
256
257static int omap_dss_resume(struct platform_device *pdev)
258{
259 DSSDBG("resume\n");
260
261 return dss_resume_all_devices();
262}
263
264static struct platform_driver omap_dss_driver = { 277static struct platform_driver omap_dss_driver = {
265 .remove = omap_dss_remove, 278 .remove = omap_dss_remove,
266 .shutdown = omap_dss_shutdown, 279 .shutdown = omap_dss_shutdown,
267 .suspend = omap_dss_suspend,
268 .resume = omap_dss_resume,
269 .driver = { 280 .driver = {
270 .name = "omapdss", 281 .name = "omapdss",
271 .owner = THIS_MODULE, 282 .owner = THIS_MODULE,
diff --git a/drivers/video/omap2/dss/dispc.c b/drivers/video/omap2/dss/dispc.c
index 4749ac356469..397d4eee11bb 100644
--- a/drivers/video/omap2/dss/dispc.c
+++ b/drivers/video/omap2/dss/dispc.c
@@ -384,7 +384,7 @@ void dispc_runtime_put(void)
384 DSSDBG("dispc_runtime_put\n"); 384 DSSDBG("dispc_runtime_put\n");
385 385
386 r = pm_runtime_put_sync(&dispc.pdev->dev); 386 r = pm_runtime_put_sync(&dispc.pdev->dev);
387 WARN_ON(r < 0); 387 WARN_ON(r < 0 && r != -ENOSYS);
388} 388}
389 389
390static inline bool dispc_mgr_is_lcd(enum omap_channel channel) 390static inline bool dispc_mgr_is_lcd(enum omap_channel channel)
diff --git a/drivers/video/omap2/dss/dsi.c b/drivers/video/omap2/dss/dsi.c
index ca8382d346e9..14ce8cc079e3 100644
--- a/drivers/video/omap2/dss/dsi.c
+++ b/drivers/video/omap2/dss/dsi.c
@@ -1075,7 +1075,7 @@ void dsi_runtime_put(struct platform_device *dsidev)
1075 DSSDBG("dsi_runtime_put\n"); 1075 DSSDBG("dsi_runtime_put\n");
1076 1076
1077 r = pm_runtime_put_sync(&dsi->pdev->dev); 1077 r = pm_runtime_put_sync(&dsi->pdev->dev);
1078 WARN_ON(r < 0); 1078 WARN_ON(r < 0 && r != -ENOSYS);
1079} 1079}
1080 1080
1081/* source clock for DSI PLL. this could also be PCLKFREE */ 1081/* source clock for DSI PLL. this could also be PCLKFREE */
diff --git a/drivers/video/omap2/dss/dss.c b/drivers/video/omap2/dss/dss.c
index 770632359a17..d2b57197b292 100644
--- a/drivers/video/omap2/dss/dss.c
+++ b/drivers/video/omap2/dss/dss.c
@@ -731,7 +731,7 @@ static void dss_runtime_put(void)
731 DSSDBG("dss_runtime_put\n"); 731 DSSDBG("dss_runtime_put\n");
732 732
733 r = pm_runtime_put_sync(&dss.pdev->dev); 733 r = pm_runtime_put_sync(&dss.pdev->dev);
734 WARN_ON(r < 0 && r != -EBUSY); 734 WARN_ON(r < 0 && r != -ENOSYS && r != -EBUSY);
735} 735}
736 736
737/* DEBUGFS */ 737/* DEBUGFS */
diff --git a/drivers/video/omap2/dss/hdmi.c b/drivers/video/omap2/dss/hdmi.c
index 8195c7166d20..26a2430a7028 100644
--- a/drivers/video/omap2/dss/hdmi.c
+++ b/drivers/video/omap2/dss/hdmi.c
@@ -138,7 +138,7 @@ static void hdmi_runtime_put(void)
138 DSSDBG("hdmi_runtime_put\n"); 138 DSSDBG("hdmi_runtime_put\n");
139 139
140 r = pm_runtime_put_sync(&hdmi.pdev->dev); 140 r = pm_runtime_put_sync(&hdmi.pdev->dev);
141 WARN_ON(r < 0); 141 WARN_ON(r < 0 && r != -ENOSYS);
142} 142}
143 143
144static int __init hdmi_init_display(struct omap_dss_device *dssdev) 144static int __init hdmi_init_display(struct omap_dss_device *dssdev)
diff --git a/drivers/video/omap2/dss/rfbi.c b/drivers/video/omap2/dss/rfbi.c
index 3d8c206e90e5..7985fa12b9b4 100644
--- a/drivers/video/omap2/dss/rfbi.c
+++ b/drivers/video/omap2/dss/rfbi.c
@@ -141,7 +141,7 @@ static void rfbi_runtime_put(void)
141 DSSDBG("rfbi_runtime_put\n"); 141 DSSDBG("rfbi_runtime_put\n");
142 142
143 r = pm_runtime_put_sync(&rfbi.pdev->dev); 143 r = pm_runtime_put_sync(&rfbi.pdev->dev);
144 WARN_ON(r < 0); 144 WARN_ON(r < 0 && r != -ENOSYS);
145} 145}
146 146
147void rfbi_bus_lock(void) 147void rfbi_bus_lock(void)
diff --git a/drivers/video/omap2/dss/venc.c b/drivers/video/omap2/dss/venc.c
index 2b8973931ff4..3907c8b6ecbc 100644
--- a/drivers/video/omap2/dss/venc.c
+++ b/drivers/video/omap2/dss/venc.c
@@ -402,7 +402,7 @@ static void venc_runtime_put(void)
402 DSSDBG("venc_runtime_put\n"); 402 DSSDBG("venc_runtime_put\n");
403 403
404 r = pm_runtime_put_sync(&venc.pdev->dev); 404 r = pm_runtime_put_sync(&venc.pdev->dev);
405 WARN_ON(r < 0); 405 WARN_ON(r < 0 && r != -ENOSYS);
406} 406}
407 407
408static const struct venc_config *venc_timings_to_config( 408static const struct venc_config *venc_timings_to_config(
diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index bfbc15ca38dd..0908e6044333 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -47,7 +47,7 @@ struct virtio_balloon
47 struct task_struct *thread; 47 struct task_struct *thread;
48 48
49 /* Waiting for host to ack the pages we released. */ 49 /* Waiting for host to ack the pages we released. */
50 struct completion acked; 50 wait_queue_head_t acked;
51 51
52 /* Number of balloon pages we've told the Host we're not using. */ 52 /* Number of balloon pages we've told the Host we're not using. */
53 unsigned int num_pages; 53 unsigned int num_pages;
@@ -89,29 +89,25 @@ static struct page *balloon_pfn_to_page(u32 pfn)
89 89
90static void balloon_ack(struct virtqueue *vq) 90static void balloon_ack(struct virtqueue *vq)
91{ 91{
92 struct virtio_balloon *vb; 92 struct virtio_balloon *vb = vq->vdev->priv;
93 unsigned int len;
94 93
95 vb = virtqueue_get_buf(vq, &len); 94 wake_up(&vb->acked);
96 if (vb)
97 complete(&vb->acked);
98} 95}
99 96
100static void tell_host(struct virtio_balloon *vb, struct virtqueue *vq) 97static void tell_host(struct virtio_balloon *vb, struct virtqueue *vq)
101{ 98{
102 struct scatterlist sg; 99 struct scatterlist sg;
100 unsigned int len;
103 101
104 sg_init_one(&sg, vb->pfns, sizeof(vb->pfns[0]) * vb->num_pfns); 102 sg_init_one(&sg, vb->pfns, sizeof(vb->pfns[0]) * vb->num_pfns);
105 103
106 init_completion(&vb->acked);
107
108 /* We should always be able to add one buffer to an empty queue. */ 104 /* We should always be able to add one buffer to an empty queue. */
109 if (virtqueue_add_buf(vq, &sg, 1, 0, vb, GFP_KERNEL) < 0) 105 if (virtqueue_add_buf(vq, &sg, 1, 0, vb, GFP_KERNEL) < 0)
110 BUG(); 106 BUG();
111 virtqueue_kick(vq); 107 virtqueue_kick(vq);
112 108
113 /* When host has read buffer, this completes via balloon_ack */ 109 /* When host has read buffer, this completes via balloon_ack */
114 wait_for_completion(&vb->acked); 110 wait_event(vb->acked, virtqueue_get_buf(vq, &len));
115} 111}
116 112
117static void set_page_pfns(u32 pfns[], struct page *page) 113static void set_page_pfns(u32 pfns[], struct page *page)
@@ -231,12 +227,8 @@ static void update_balloon_stats(struct virtio_balloon *vb)
231 */ 227 */
232static void stats_request(struct virtqueue *vq) 228static void stats_request(struct virtqueue *vq)
233{ 229{
234 struct virtio_balloon *vb; 230 struct virtio_balloon *vb = vq->vdev->priv;
235 unsigned int len;
236 231
237 vb = virtqueue_get_buf(vq, &len);
238 if (!vb)
239 return;
240 vb->need_stats_update = 1; 232 vb->need_stats_update = 1;
241 wake_up(&vb->config_change); 233 wake_up(&vb->config_change);
242} 234}
@@ -245,11 +237,14 @@ static void stats_handle_request(struct virtio_balloon *vb)
245{ 237{
246 struct virtqueue *vq; 238 struct virtqueue *vq;
247 struct scatterlist sg; 239 struct scatterlist sg;
240 unsigned int len;
248 241
249 vb->need_stats_update = 0; 242 vb->need_stats_update = 0;
250 update_balloon_stats(vb); 243 update_balloon_stats(vb);
251 244
252 vq = vb->stats_vq; 245 vq = vb->stats_vq;
246 if (!virtqueue_get_buf(vq, &len))
247 return;
253 sg_init_one(&sg, vb->stats, sizeof(vb->stats)); 248 sg_init_one(&sg, vb->stats, sizeof(vb->stats));
254 if (virtqueue_add_buf(vq, &sg, 1, 0, vb, GFP_KERNEL) < 0) 249 if (virtqueue_add_buf(vq, &sg, 1, 0, vb, GFP_KERNEL) < 0)
255 BUG(); 250 BUG();
@@ -358,6 +353,7 @@ static int virtballoon_probe(struct virtio_device *vdev)
358 INIT_LIST_HEAD(&vb->pages); 353 INIT_LIST_HEAD(&vb->pages);
359 vb->num_pages = 0; 354 vb->num_pages = 0;
360 init_waitqueue_head(&vb->config_change); 355 init_waitqueue_head(&vb->config_change);
356 init_waitqueue_head(&vb->acked);
361 vb->vdev = vdev; 357 vb->vdev = vdev;
362 vb->need_stats_update = 0; 358 vb->need_stats_update = 0;
363 359
diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c
index 7301cdb4b2cb..a383c18e74e8 100644
--- a/fs/btrfs/backref.c
+++ b/fs/btrfs/backref.c
@@ -301,10 +301,14 @@ static int __resolve_indirect_ref(struct btrfs_fs_info *fs_info,
301 goto out; 301 goto out;
302 302
303 eb = path->nodes[level]; 303 eb = path->nodes[level];
304 if (!eb) { 304 while (!eb) {
305 WARN_ON(1); 305 if (!level) {
306 ret = 1; 306 WARN_ON(1);
307 goto out; 307 ret = 1;
308 goto out;
309 }
310 level--;
311 eb = path->nodes[level];
308 } 312 }
309 313
310 ret = add_all_parents(root, path, parents, level, &ref->key_for_search, 314 ret = add_all_parents(root, path, parents, level, &ref->key_for_search,
@@ -835,6 +839,7 @@ again:
835 } 839 }
836 ret = __add_delayed_refs(head, delayed_ref_seq, 840 ret = __add_delayed_refs(head, delayed_ref_seq,
837 &prefs_delayed); 841 &prefs_delayed);
842 mutex_unlock(&head->mutex);
838 if (ret) { 843 if (ret) {
839 spin_unlock(&delayed_refs->lock); 844 spin_unlock(&delayed_refs->lock);
840 goto out; 845 goto out;
@@ -928,8 +933,6 @@ again:
928 } 933 }
929 934
930out: 935out:
931 if (head)
932 mutex_unlock(&head->mutex);
933 btrfs_free_path(path); 936 btrfs_free_path(path);
934 while (!list_empty(&prefs)) { 937 while (!list_empty(&prefs)) {
935 ref = list_first_entry(&prefs, struct __prelim_ref, list); 938 ref = list_first_entry(&prefs, struct __prelim_ref, list);
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index 15cbc2bf4ff0..8206b3900587 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -1024,11 +1024,18 @@ __tree_mod_log_oldest_root(struct btrfs_fs_info *fs_info,
1024 if (!looped && !tm) 1024 if (!looped && !tm)
1025 return 0; 1025 return 0;
1026 /* 1026 /*
1027 * we must have key remove operations in the log before the 1027 * if there are no tree operation for the oldest root, we simply
1028 * replace operation. 1028 * return it. this should only happen if that (old) root is at
1029 * level 0.
1029 */ 1030 */
1030 BUG_ON(!tm); 1031 if (!tm)
1032 break;
1031 1033
1034 /*
1035 * if there's an operation that's not a root replacement, we
1036 * found the oldest version of our root. normally, we'll find a
1037 * MOD_LOG_KEY_REMOVE_WHILE_FREEING operation here.
1038 */
1032 if (tm->op != MOD_LOG_ROOT_REPLACE) 1039 if (tm->op != MOD_LOG_ROOT_REPLACE)
1033 break; 1040 break;
1034 1041
@@ -1087,11 +1094,7 @@ __tree_mod_log_rewind(struct extent_buffer *eb, u64 time_seq,
1087 tm->generation); 1094 tm->generation);
1088 break; 1095 break;
1089 case MOD_LOG_KEY_ADD: 1096 case MOD_LOG_KEY_ADD:
1090 if (tm->slot != n - 1) { 1097 /* if a move operation is needed it's in the log */
1091 o_dst = btrfs_node_key_ptr_offset(tm->slot);
1092 o_src = btrfs_node_key_ptr_offset(tm->slot + 1);
1093 memmove_extent_buffer(eb, o_dst, o_src, p_size);
1094 }
1095 n--; 1098 n--;
1096 break; 1099 break;
1097 case MOD_LOG_MOVE_KEYS: 1100 case MOD_LOG_MOVE_KEYS:
@@ -1192,16 +1195,8 @@ get_old_root(struct btrfs_root *root, u64 time_seq)
1192 } 1195 }
1193 1196
1194 tm = tree_mod_log_search(root->fs_info, logical, time_seq); 1197 tm = tree_mod_log_search(root->fs_info, logical, time_seq);
1195 /*
1196 * there was an item in the log when __tree_mod_log_oldest_root
1197 * returned. this one must not go away, because the time_seq passed to
1198 * us must be blocking its removal.
1199 */
1200 BUG_ON(!tm);
1201
1202 if (old_root) 1198 if (old_root)
1203 eb = alloc_dummy_extent_buffer(tm->index << PAGE_CACHE_SHIFT, 1199 eb = alloc_dummy_extent_buffer(logical, root->nodesize);
1204 root->nodesize);
1205 else 1200 else
1206 eb = btrfs_clone_extent_buffer(root->node); 1201 eb = btrfs_clone_extent_buffer(root->node);
1207 btrfs_tree_read_unlock(root->node); 1202 btrfs_tree_read_unlock(root->node);
@@ -1216,7 +1211,10 @@ get_old_root(struct btrfs_root *root, u64 time_seq)
1216 btrfs_set_header_level(eb, old_root->level); 1211 btrfs_set_header_level(eb, old_root->level);
1217 btrfs_set_header_generation(eb, old_generation); 1212 btrfs_set_header_generation(eb, old_generation);
1218 } 1213 }
1219 __tree_mod_log_rewind(eb, time_seq, tm); 1214 if (tm)
1215 __tree_mod_log_rewind(eb, time_seq, tm);
1216 else
1217 WARN_ON(btrfs_header_level(eb) != 0);
1220 extent_buffer_get(eb); 1218 extent_buffer_get(eb);
1221 1219
1222 return eb; 1220 return eb;
@@ -2995,7 +2993,7 @@ static noinline int insert_new_root(struct btrfs_trans_handle *trans,
2995static void insert_ptr(struct btrfs_trans_handle *trans, 2993static void insert_ptr(struct btrfs_trans_handle *trans,
2996 struct btrfs_root *root, struct btrfs_path *path, 2994 struct btrfs_root *root, struct btrfs_path *path,
2997 struct btrfs_disk_key *key, u64 bytenr, 2995 struct btrfs_disk_key *key, u64 bytenr,
2998 int slot, int level, int tree_mod_log) 2996 int slot, int level)
2999{ 2997{
3000 struct extent_buffer *lower; 2998 struct extent_buffer *lower;
3001 int nritems; 2999 int nritems;
@@ -3008,7 +3006,7 @@ static void insert_ptr(struct btrfs_trans_handle *trans,
3008 BUG_ON(slot > nritems); 3006 BUG_ON(slot > nritems);
3009 BUG_ON(nritems == BTRFS_NODEPTRS_PER_BLOCK(root)); 3007 BUG_ON(nritems == BTRFS_NODEPTRS_PER_BLOCK(root));
3010 if (slot != nritems) { 3008 if (slot != nritems) {
3011 if (tree_mod_log && level) 3009 if (level)
3012 tree_mod_log_eb_move(root->fs_info, lower, slot + 1, 3010 tree_mod_log_eb_move(root->fs_info, lower, slot + 1,
3013 slot, nritems - slot); 3011 slot, nritems - slot);
3014 memmove_extent_buffer(lower, 3012 memmove_extent_buffer(lower,
@@ -3016,7 +3014,7 @@ static void insert_ptr(struct btrfs_trans_handle *trans,
3016 btrfs_node_key_ptr_offset(slot), 3014 btrfs_node_key_ptr_offset(slot),
3017 (nritems - slot) * sizeof(struct btrfs_key_ptr)); 3015 (nritems - slot) * sizeof(struct btrfs_key_ptr));
3018 } 3016 }
3019 if (tree_mod_log && level) { 3017 if (level) {
3020 ret = tree_mod_log_insert_key(root->fs_info, lower, slot, 3018 ret = tree_mod_log_insert_key(root->fs_info, lower, slot,
3021 MOD_LOG_KEY_ADD); 3019 MOD_LOG_KEY_ADD);
3022 BUG_ON(ret < 0); 3020 BUG_ON(ret < 0);
@@ -3104,7 +3102,7 @@ static noinline int split_node(struct btrfs_trans_handle *trans,
3104 btrfs_mark_buffer_dirty(split); 3102 btrfs_mark_buffer_dirty(split);
3105 3103
3106 insert_ptr(trans, root, path, &disk_key, split->start, 3104 insert_ptr(trans, root, path, &disk_key, split->start,
3107 path->slots[level + 1] + 1, level + 1, 1); 3105 path->slots[level + 1] + 1, level + 1);
3108 3106
3109 if (path->slots[level] >= mid) { 3107 if (path->slots[level] >= mid) {
3110 path->slots[level] -= mid; 3108 path->slots[level] -= mid;
@@ -3641,7 +3639,7 @@ static noinline void copy_for_split(struct btrfs_trans_handle *trans,
3641 btrfs_set_header_nritems(l, mid); 3639 btrfs_set_header_nritems(l, mid);
3642 btrfs_item_key(right, &disk_key, 0); 3640 btrfs_item_key(right, &disk_key, 0);
3643 insert_ptr(trans, root, path, &disk_key, right->start, 3641 insert_ptr(trans, root, path, &disk_key, right->start,
3644 path->slots[1] + 1, 1, 0); 3642 path->slots[1] + 1, 1);
3645 3643
3646 btrfs_mark_buffer_dirty(right); 3644 btrfs_mark_buffer_dirty(right);
3647 btrfs_mark_buffer_dirty(l); 3645 btrfs_mark_buffer_dirty(l);
@@ -3848,7 +3846,7 @@ again:
3848 if (mid <= slot) { 3846 if (mid <= slot) {
3849 btrfs_set_header_nritems(right, 0); 3847 btrfs_set_header_nritems(right, 0);
3850 insert_ptr(trans, root, path, &disk_key, right->start, 3848 insert_ptr(trans, root, path, &disk_key, right->start,
3851 path->slots[1] + 1, 1, 0); 3849 path->slots[1] + 1, 1);
3852 btrfs_tree_unlock(path->nodes[0]); 3850 btrfs_tree_unlock(path->nodes[0]);
3853 free_extent_buffer(path->nodes[0]); 3851 free_extent_buffer(path->nodes[0]);
3854 path->nodes[0] = right; 3852 path->nodes[0] = right;
@@ -3857,7 +3855,7 @@ again:
3857 } else { 3855 } else {
3858 btrfs_set_header_nritems(right, 0); 3856 btrfs_set_header_nritems(right, 0);
3859 insert_ptr(trans, root, path, &disk_key, right->start, 3857 insert_ptr(trans, root, path, &disk_key, right->start,
3860 path->slots[1], 1, 0); 3858 path->slots[1], 1);
3861 btrfs_tree_unlock(path->nodes[0]); 3859 btrfs_tree_unlock(path->nodes[0]);
3862 free_extent_buffer(path->nodes[0]); 3860 free_extent_buffer(path->nodes[0]);
3863 path->nodes[0] = right; 3861 path->nodes[0] = right;
@@ -5121,6 +5119,18 @@ again:
5121 5119
5122 if (!path->skip_locking) { 5120 if (!path->skip_locking) {
5123 ret = btrfs_try_tree_read_lock(next); 5121 ret = btrfs_try_tree_read_lock(next);
5122 if (!ret && time_seq) {
5123 /*
5124 * If we don't get the lock, we may be racing
5125 * with push_leaf_left, holding that lock while
5126 * itself waiting for the leaf we've currently
5127 * locked. To solve this situation, we give up
5128 * on our lock and cycle.
5129 */
5130 btrfs_release_path(path);
5131 cond_resched();
5132 goto again;
5133 }
5124 if (!ret) { 5134 if (!ret) {
5125 btrfs_set_path_blocking(path); 5135 btrfs_set_path_blocking(path);
5126 btrfs_tree_read_lock(next); 5136 btrfs_tree_read_lock(next);
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 7b845ff4af99..2936ca49b3b4 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2354,12 +2354,17 @@ retry_root_backup:
2354 BTRFS_CSUM_TREE_OBJECTID, csum_root); 2354 BTRFS_CSUM_TREE_OBJECTID, csum_root);
2355 if (ret) 2355 if (ret)
2356 goto recovery_tree_root; 2356 goto recovery_tree_root;
2357
2358 csum_root->track_dirty = 1; 2357 csum_root->track_dirty = 1;
2359 2358
2360 fs_info->generation = generation; 2359 fs_info->generation = generation;
2361 fs_info->last_trans_committed = generation; 2360 fs_info->last_trans_committed = generation;
2362 2361
2362 ret = btrfs_recover_balance(fs_info);
2363 if (ret) {
2364 printk(KERN_WARNING "btrfs: failed to recover balance\n");
2365 goto fail_block_groups;
2366 }
2367
2363 ret = btrfs_init_dev_stats(fs_info); 2368 ret = btrfs_init_dev_stats(fs_info);
2364 if (ret) { 2369 if (ret) {
2365 printk(KERN_ERR "btrfs: failed to init dev_stats: %d\n", 2370 printk(KERN_ERR "btrfs: failed to init dev_stats: %d\n",
@@ -2485,20 +2490,23 @@ retry_root_backup:
2485 goto fail_trans_kthread; 2490 goto fail_trans_kthread;
2486 } 2491 }
2487 2492
2488 if (!(sb->s_flags & MS_RDONLY)) { 2493 if (sb->s_flags & MS_RDONLY)
2489 down_read(&fs_info->cleanup_work_sem); 2494 return 0;
2490 err = btrfs_orphan_cleanup(fs_info->fs_root);
2491 if (!err)
2492 err = btrfs_orphan_cleanup(fs_info->tree_root);
2493 up_read(&fs_info->cleanup_work_sem);
2494 2495
2495 if (!err) 2496 down_read(&fs_info->cleanup_work_sem);
2496 err = btrfs_recover_balance(fs_info->tree_root); 2497 if ((ret = btrfs_orphan_cleanup(fs_info->fs_root)) ||
2498 (ret = btrfs_orphan_cleanup(fs_info->tree_root))) {
2499 up_read(&fs_info->cleanup_work_sem);
2500 close_ctree(tree_root);
2501 return ret;
2502 }
2503 up_read(&fs_info->cleanup_work_sem);
2497 2504
2498 if (err) { 2505 ret = btrfs_resume_balance_async(fs_info);
2499 close_ctree(tree_root); 2506 if (ret) {
2500 return err; 2507 printk(KERN_WARNING "btrfs: failed to resume balance\n");
2501 } 2508 close_ctree(tree_root);
2509 return ret;
2502 } 2510 }
2503 2511
2504 return 0; 2512 return 0;
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 4b5a1e1bdefb..6e1d36702ff7 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -2347,12 +2347,10 @@ next:
2347 return count; 2347 return count;
2348} 2348}
2349 2349
2350
2351static void wait_for_more_refs(struct btrfs_delayed_ref_root *delayed_refs, 2350static void wait_for_more_refs(struct btrfs_delayed_ref_root *delayed_refs,
2352 unsigned long num_refs) 2351 unsigned long num_refs,
2352 struct list_head *first_seq)
2353{ 2353{
2354 struct list_head *first_seq = delayed_refs->seq_head.next;
2355
2356 spin_unlock(&delayed_refs->lock); 2354 spin_unlock(&delayed_refs->lock);
2357 pr_debug("waiting for more refs (num %ld, first %p)\n", 2355 pr_debug("waiting for more refs (num %ld, first %p)\n",
2358 num_refs, first_seq); 2356 num_refs, first_seq);
@@ -2381,6 +2379,7 @@ int btrfs_run_delayed_refs(struct btrfs_trans_handle *trans,
2381 struct btrfs_delayed_ref_root *delayed_refs; 2379 struct btrfs_delayed_ref_root *delayed_refs;
2382 struct btrfs_delayed_ref_node *ref; 2380 struct btrfs_delayed_ref_node *ref;
2383 struct list_head cluster; 2381 struct list_head cluster;
2382 struct list_head *first_seq = NULL;
2384 int ret; 2383 int ret;
2385 u64 delayed_start; 2384 u64 delayed_start;
2386 int run_all = count == (unsigned long)-1; 2385 int run_all = count == (unsigned long)-1;
@@ -2436,8 +2435,10 @@ again:
2436 */ 2435 */
2437 consider_waiting = 1; 2436 consider_waiting = 1;
2438 num_refs = delayed_refs->num_entries; 2437 num_refs = delayed_refs->num_entries;
2438 first_seq = root->fs_info->tree_mod_seq_list.next;
2439 } else { 2439 } else {
2440 wait_for_more_refs(delayed_refs, num_refs); 2440 wait_for_more_refs(delayed_refs,
2441 num_refs, first_seq);
2441 /* 2442 /*
2442 * after waiting, things have changed. we 2443 * after waiting, things have changed. we
2443 * dropped the lock and someone else might have 2444 * dropped the lock and someone else might have
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index aaa12c1eb348..01c21b6c6d43 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -3324,6 +3324,7 @@ static int extent_write_cache_pages(struct extent_io_tree *tree,
3324 writepage_t writepage, void *data, 3324 writepage_t writepage, void *data,
3325 void (*flush_fn)(void *)) 3325 void (*flush_fn)(void *))
3326{ 3326{
3327 struct inode *inode = mapping->host;
3327 int ret = 0; 3328 int ret = 0;
3328 int done = 0; 3329 int done = 0;
3329 int nr_to_write_done = 0; 3330 int nr_to_write_done = 0;
@@ -3334,6 +3335,18 @@ static int extent_write_cache_pages(struct extent_io_tree *tree,
3334 int scanned = 0; 3335 int scanned = 0;
3335 int tag; 3336 int tag;
3336 3337
3338 /*
3339 * We have to hold onto the inode so that ordered extents can do their
3340 * work when the IO finishes. The alternative to this is failing to add
3341 * an ordered extent if the igrab() fails there and that is a huge pain
3342 * to deal with, so instead just hold onto the inode throughout the
3343 * writepages operation. If it fails here we are freeing up the inode
3344 * anyway and we'd rather not waste our time writing out stuff that is
3345 * going to be truncated anyway.
3346 */
3347 if (!igrab(inode))
3348 return 0;
3349
3337 pagevec_init(&pvec, 0); 3350 pagevec_init(&pvec, 0);
3338 if (wbc->range_cyclic) { 3351 if (wbc->range_cyclic) {
3339 index = mapping->writeback_index; /* Start from prev offset */ 3352 index = mapping->writeback_index; /* Start from prev offset */
@@ -3428,6 +3441,7 @@ retry:
3428 index = 0; 3441 index = 0;
3429 goto retry; 3442 goto retry;
3430 } 3443 }
3444 btrfs_add_delayed_iput(inode);
3431 return ret; 3445 return ret;
3432} 3446}
3433 3447
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 70dc8ca73e25..9aa01ec2138d 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -1334,7 +1334,6 @@ static ssize_t __btrfs_direct_write(struct kiocb *iocb,
1334 loff_t *ppos, size_t count, size_t ocount) 1334 loff_t *ppos, size_t count, size_t ocount)
1335{ 1335{
1336 struct file *file = iocb->ki_filp; 1336 struct file *file = iocb->ki_filp;
1337 struct inode *inode = fdentry(file)->d_inode;
1338 struct iov_iter i; 1337 struct iov_iter i;
1339 ssize_t written; 1338 ssize_t written;
1340 ssize_t written_buffered; 1339 ssize_t written_buffered;
@@ -1344,18 +1343,6 @@ static ssize_t __btrfs_direct_write(struct kiocb *iocb,
1344 written = generic_file_direct_write(iocb, iov, &nr_segs, pos, ppos, 1343 written = generic_file_direct_write(iocb, iov, &nr_segs, pos, ppos,
1345 count, ocount); 1344 count, ocount);
1346 1345
1347 /*
1348 * the generic O_DIRECT will update in-memory i_size after the
1349 * DIOs are done. But our endio handlers that update the on
1350 * disk i_size never update past the in memory i_size. So we
1351 * need one more update here to catch any additions to the
1352 * file
1353 */
1354 if (inode->i_size != BTRFS_I(inode)->disk_i_size) {
1355 btrfs_ordered_update_i_size(inode, inode->i_size, NULL);
1356 mark_inode_dirty(inode);
1357 }
1358
1359 if (written < 0 || written == count) 1346 if (written < 0 || written == count)
1360 return written; 1347 return written;
1361 1348
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
index 81296c57405a..6c4e2baa9290 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
@@ -1543,29 +1543,26 @@ again:
1543 end = bitmap_info->offset + (u64)(BITS_PER_BITMAP * ctl->unit) - 1; 1543 end = bitmap_info->offset + (u64)(BITS_PER_BITMAP * ctl->unit) - 1;
1544 1544
1545 /* 1545 /*
1546 * XXX - this can go away after a few releases. 1546 * We need to search for bits in this bitmap. We could only cover some
1547 * 1547 * of the extent in this bitmap thanks to how we add space, so we need
1548 * since the only user of btrfs_remove_free_space is the tree logging 1548 * to search for as much as it as we can and clear that amount, and then
1549 * stuff, and the only way to test that is under crash conditions, we 1549 * go searching for the next bit.
1550 * want to have this debug stuff here just in case somethings not
1551 * working. Search the bitmap for the space we are trying to use to
1552 * make sure its actually there. If its not there then we need to stop
1553 * because something has gone wrong.
1554 */ 1550 */
1555 search_start = *offset; 1551 search_start = *offset;
1556 search_bytes = *bytes; 1552 search_bytes = ctl->unit;
1557 search_bytes = min(search_bytes, end - search_start + 1); 1553 search_bytes = min(search_bytes, end - search_start + 1);
1558 ret = search_bitmap(ctl, bitmap_info, &search_start, &search_bytes); 1554 ret = search_bitmap(ctl, bitmap_info, &search_start, &search_bytes);
1559 BUG_ON(ret < 0 || search_start != *offset); 1555 BUG_ON(ret < 0 || search_start != *offset);
1560 1556
1561 if (*offset > bitmap_info->offset && *offset + *bytes > end) { 1557 /* We may have found more bits than what we need */
1562 bitmap_clear_bits(ctl, bitmap_info, *offset, end - *offset + 1); 1558 search_bytes = min(search_bytes, *bytes);
1563 *bytes -= end - *offset + 1; 1559
1564 *offset = end + 1; 1560 /* Cannot clear past the end of the bitmap */
1565 } else if (*offset >= bitmap_info->offset && *offset + *bytes <= end) { 1561 search_bytes = min(search_bytes, end - search_start + 1);
1566 bitmap_clear_bits(ctl, bitmap_info, *offset, *bytes); 1562
1567 *bytes = 0; 1563 bitmap_clear_bits(ctl, bitmap_info, search_start, search_bytes);
1568 } 1564 *offset += search_bytes;
1565 *bytes -= search_bytes;
1569 1566
1570 if (*bytes) { 1567 if (*bytes) {
1571 struct rb_node *next = rb_next(&bitmap_info->offset_index); 1568 struct rb_node *next = rb_next(&bitmap_info->offset_index);
@@ -1596,7 +1593,7 @@ again:
1596 * everything over again. 1593 * everything over again.
1597 */ 1594 */
1598 search_start = *offset; 1595 search_start = *offset;
1599 search_bytes = *bytes; 1596 search_bytes = ctl->unit;
1600 ret = search_bitmap(ctl, bitmap_info, &search_start, 1597 ret = search_bitmap(ctl, bitmap_info, &search_start,
1601 &search_bytes); 1598 &search_bytes);
1602 if (ret < 0 || search_start != *offset) 1599 if (ret < 0 || search_start != *offset)
@@ -1879,12 +1876,14 @@ int btrfs_remove_free_space(struct btrfs_block_group_cache *block_group,
1879{ 1876{
1880 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; 1877 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
1881 struct btrfs_free_space *info; 1878 struct btrfs_free_space *info;
1882 struct btrfs_free_space *next_info = NULL;
1883 int ret = 0; 1879 int ret = 0;
1884 1880
1885 spin_lock(&ctl->tree_lock); 1881 spin_lock(&ctl->tree_lock);
1886 1882
1887again: 1883again:
1884 if (!bytes)
1885 goto out_lock;
1886
1888 info = tree_search_offset(ctl, offset, 0, 0); 1887 info = tree_search_offset(ctl, offset, 0, 0);
1889 if (!info) { 1888 if (!info) {
1890 /* 1889 /*
@@ -1905,88 +1904,48 @@ again:
1905 } 1904 }
1906 } 1905 }
1907 1906
1908 if (info->bytes < bytes && rb_next(&info->offset_index)) { 1907 if (!info->bitmap) {
1909 u64 end;
1910 next_info = rb_entry(rb_next(&info->offset_index),
1911 struct btrfs_free_space,
1912 offset_index);
1913
1914 if (next_info->bitmap)
1915 end = next_info->offset +
1916 BITS_PER_BITMAP * ctl->unit - 1;
1917 else
1918 end = next_info->offset + next_info->bytes;
1919
1920 if (next_info->bytes < bytes ||
1921 next_info->offset > offset || offset > end) {
1922 printk(KERN_CRIT "Found free space at %llu, size %llu,"
1923 " trying to use %llu\n",
1924 (unsigned long long)info->offset,
1925 (unsigned long long)info->bytes,
1926 (unsigned long long)bytes);
1927 WARN_ON(1);
1928 ret = -EINVAL;
1929 goto out_lock;
1930 }
1931
1932 info = next_info;
1933 }
1934
1935 if (info->bytes == bytes) {
1936 unlink_free_space(ctl, info); 1908 unlink_free_space(ctl, info);
1937 if (info->bitmap) { 1909 if (offset == info->offset) {
1938 kfree(info->bitmap); 1910 u64 to_free = min(bytes, info->bytes);
1939 ctl->total_bitmaps--; 1911
1940 } 1912 info->bytes -= to_free;
1941 kmem_cache_free(btrfs_free_space_cachep, info); 1913 info->offset += to_free;
1942 ret = 0; 1914 if (info->bytes) {
1943 goto out_lock; 1915 ret = link_free_space(ctl, info);
1944 } 1916 WARN_ON(ret);
1945 1917 } else {
1946 if (!info->bitmap && info->offset == offset) { 1918 kmem_cache_free(btrfs_free_space_cachep, info);
1947 unlink_free_space(ctl, info); 1919 }
1948 info->offset += bytes;
1949 info->bytes -= bytes;
1950 ret = link_free_space(ctl, info);
1951 WARN_ON(ret);
1952 goto out_lock;
1953 }
1954 1920
1955 if (!info->bitmap && info->offset <= offset && 1921 offset += to_free;
1956 info->offset + info->bytes >= offset + bytes) { 1922 bytes -= to_free;
1957 u64 old_start = info->offset; 1923 goto again;
1958 /* 1924 } else {
1959 * we're freeing space in the middle of the info, 1925 u64 old_end = info->bytes + info->offset;
1960 * this can happen during tree log replay
1961 *
1962 * first unlink the old info and then
1963 * insert it again after the hole we're creating
1964 */
1965 unlink_free_space(ctl, info);
1966 if (offset + bytes < info->offset + info->bytes) {
1967 u64 old_end = info->offset + info->bytes;
1968 1926
1969 info->offset = offset + bytes; 1927 info->bytes = offset - info->offset;
1970 info->bytes = old_end - info->offset;
1971 ret = link_free_space(ctl, info); 1928 ret = link_free_space(ctl, info);
1972 WARN_ON(ret); 1929 WARN_ON(ret);
1973 if (ret) 1930 if (ret)
1974 goto out_lock; 1931 goto out_lock;
1975 } else {
1976 /* the hole we're creating ends at the end
1977 * of the info struct, just free the info
1978 */
1979 kmem_cache_free(btrfs_free_space_cachep, info);
1980 }
1981 spin_unlock(&ctl->tree_lock);
1982 1932
1983 /* step two, insert a new info struct to cover 1933 /* Not enough bytes in this entry to satisfy us */
1984 * anything before the hole 1934 if (old_end < offset + bytes) {
1985 */ 1935 bytes -= old_end - offset;
1986 ret = btrfs_add_free_space(block_group, old_start, 1936 offset = old_end;
1987 offset - old_start); 1937 goto again;
1988 WARN_ON(ret); /* -ENOMEM */ 1938 } else if (old_end == offset + bytes) {
1989 goto out; 1939 /* all done */
1940 goto out_lock;
1941 }
1942 spin_unlock(&ctl->tree_lock);
1943
1944 ret = btrfs_add_free_space(block_group, offset + bytes,
1945 old_end - (offset + bytes));
1946 WARN_ON(ret);
1947 goto out;
1948 }
1990 } 1949 }
1991 1950
1992 ret = remove_from_bitmap(ctl, info, &offset, &bytes); 1951 ret = remove_from_bitmap(ctl, info, &offset, &bytes);
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index d8bb0dbc4941..a7d1921ac76b 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -3754,7 +3754,7 @@ void btrfs_evict_inode(struct inode *inode)
3754 btrfs_wait_ordered_range(inode, 0, (u64)-1); 3754 btrfs_wait_ordered_range(inode, 0, (u64)-1);
3755 3755
3756 if (root->fs_info->log_root_recovering) { 3756 if (root->fs_info->log_root_recovering) {
3757 BUG_ON(!test_bit(BTRFS_INODE_HAS_ORPHAN_ITEM, 3757 BUG_ON(test_bit(BTRFS_INODE_HAS_ORPHAN_ITEM,
3758 &BTRFS_I(inode)->runtime_flags)); 3758 &BTRFS_I(inode)->runtime_flags));
3759 goto no_delete; 3759 goto no_delete;
3760 } 3760 }
@@ -5876,8 +5876,17 @@ map:
5876 bh_result->b_size = len; 5876 bh_result->b_size = len;
5877 bh_result->b_bdev = em->bdev; 5877 bh_result->b_bdev = em->bdev;
5878 set_buffer_mapped(bh_result); 5878 set_buffer_mapped(bh_result);
5879 if (create && !test_bit(EXTENT_FLAG_PREALLOC, &em->flags)) 5879 if (create) {
5880 set_buffer_new(bh_result); 5880 if (!test_bit(EXTENT_FLAG_PREALLOC, &em->flags))
5881 set_buffer_new(bh_result);
5882
5883 /*
5884 * Need to update the i_size under the extent lock so buffered
5885 * readers will get the updated i_size when we unlock.
5886 */
5887 if (start + len > i_size_read(inode))
5888 i_size_write(inode, start + len);
5889 }
5881 5890
5882 free_extent_map(em); 5891 free_extent_map(em);
5883 5892
@@ -6360,12 +6369,48 @@ static ssize_t btrfs_direct_IO(int rw, struct kiocb *iocb,
6360 */ 6369 */
6361 ordered = btrfs_lookup_ordered_range(inode, lockstart, 6370 ordered = btrfs_lookup_ordered_range(inode, lockstart,
6362 lockend - lockstart + 1); 6371 lockend - lockstart + 1);
6363 if (!ordered) 6372
6373 /*
6374 * We need to make sure there are no buffered pages in this
6375 * range either, we could have raced between the invalidate in
6376 * generic_file_direct_write and locking the extent. The
6377 * invalidate needs to happen so that reads after a write do not
6378 * get stale data.
6379 */
6380 if (!ordered && (!writing ||
6381 !test_range_bit(&BTRFS_I(inode)->io_tree,
6382 lockstart, lockend, EXTENT_UPTODATE, 0,
6383 cached_state)))
6364 break; 6384 break;
6385
6365 unlock_extent_cached(&BTRFS_I(inode)->io_tree, lockstart, lockend, 6386 unlock_extent_cached(&BTRFS_I(inode)->io_tree, lockstart, lockend,
6366 &cached_state, GFP_NOFS); 6387 &cached_state, GFP_NOFS);
6367 btrfs_start_ordered_extent(inode, ordered, 1); 6388
6368 btrfs_put_ordered_extent(ordered); 6389 if (ordered) {
6390 btrfs_start_ordered_extent(inode, ordered, 1);
6391 btrfs_put_ordered_extent(ordered);
6392 } else {
6393 /* Screw you mmap */
6394 ret = filemap_write_and_wait_range(file->f_mapping,
6395 lockstart,
6396 lockend);
6397 if (ret)
6398 goto out;
6399
6400 /*
6401 * If we found a page that couldn't be invalidated just
6402 * fall back to buffered.
6403 */
6404 ret = invalidate_inode_pages2_range(file->f_mapping,
6405 lockstart >> PAGE_CACHE_SHIFT,
6406 lockend >> PAGE_CACHE_SHIFT);
6407 if (ret) {
6408 if (ret == -EBUSY)
6409 ret = 0;
6410 goto out;
6411 }
6412 }
6413
6369 cond_resched(); 6414 cond_resched();
6370 } 6415 }
6371 6416
diff --git a/fs/btrfs/ioctl.h b/fs/btrfs/ioctl.h
index 497c530724cf..e440aa653c30 100644
--- a/fs/btrfs/ioctl.h
+++ b/fs/btrfs/ioctl.h
@@ -339,7 +339,7 @@ struct btrfs_ioctl_get_dev_stats {
339#define BTRFS_IOC_WAIT_SYNC _IOW(BTRFS_IOCTL_MAGIC, 22, __u64) 339#define BTRFS_IOC_WAIT_SYNC _IOW(BTRFS_IOCTL_MAGIC, 22, __u64)
340#define BTRFS_IOC_SNAP_CREATE_V2 _IOW(BTRFS_IOCTL_MAGIC, 23, \ 340#define BTRFS_IOC_SNAP_CREATE_V2 _IOW(BTRFS_IOCTL_MAGIC, 23, \
341 struct btrfs_ioctl_vol_args_v2) 341 struct btrfs_ioctl_vol_args_v2)
342#define BTRFS_IOC_SUBVOL_GETFLAGS _IOW(BTRFS_IOCTL_MAGIC, 25, __u64) 342#define BTRFS_IOC_SUBVOL_GETFLAGS _IOR(BTRFS_IOCTL_MAGIC, 25, __u64)
343#define BTRFS_IOC_SUBVOL_SETFLAGS _IOW(BTRFS_IOCTL_MAGIC, 26, __u64) 343#define BTRFS_IOC_SUBVOL_SETFLAGS _IOW(BTRFS_IOCTL_MAGIC, 26, __u64)
344#define BTRFS_IOC_SCRUB _IOWR(BTRFS_IOCTL_MAGIC, 27, \ 344#define BTRFS_IOC_SCRUB _IOWR(BTRFS_IOCTL_MAGIC, 27, \
345 struct btrfs_ioctl_scrub_args) 345 struct btrfs_ioctl_scrub_args)
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 0eb9a4da069e..e23991574fdf 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -1187,6 +1187,10 @@ static int btrfs_remount(struct super_block *sb, int *flags, char *data)
1187 if (ret) 1187 if (ret)
1188 goto restore; 1188 goto restore;
1189 1189
1190 ret = btrfs_resume_balance_async(fs_info);
1191 if (ret)
1192 goto restore;
1193
1190 sb->s_flags &= ~MS_RDONLY; 1194 sb->s_flags &= ~MS_RDONLY;
1191 } 1195 }
1192 1196
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index 2017d0ff511c..8abeae4224f9 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -690,6 +690,8 @@ static noinline int drop_one_dir_item(struct btrfs_trans_handle *trans,
690 kfree(name); 690 kfree(name);
691 691
692 iput(inode); 692 iput(inode);
693
694 btrfs_run_delayed_items(trans, root);
693 return ret; 695 return ret;
694} 696}
695 697
@@ -895,6 +897,7 @@ again:
895 ret = btrfs_unlink_inode(trans, root, dir, 897 ret = btrfs_unlink_inode(trans, root, dir,
896 inode, victim_name, 898 inode, victim_name,
897 victim_name_len); 899 victim_name_len);
900 btrfs_run_delayed_items(trans, root);
898 } 901 }
899 kfree(victim_name); 902 kfree(victim_name);
900 ptr = (unsigned long)(victim_ref + 1) + victim_name_len; 903 ptr = (unsigned long)(victim_ref + 1) + victim_name_len;
@@ -1475,6 +1478,9 @@ again:
1475 ret = btrfs_unlink_inode(trans, root, dir, inode, 1478 ret = btrfs_unlink_inode(trans, root, dir, inode,
1476 name, name_len); 1479 name, name_len);
1477 BUG_ON(ret); 1480 BUG_ON(ret);
1481
1482 btrfs_run_delayed_items(trans, root);
1483
1478 kfree(name); 1484 kfree(name);
1479 iput(inode); 1485 iput(inode);
1480 1486
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 8a3d2594b807..ecaad40e7ef4 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2845,31 +2845,48 @@ out:
2845 2845
2846static int balance_kthread(void *data) 2846static int balance_kthread(void *data)
2847{ 2847{
2848 struct btrfs_balance_control *bctl = 2848 struct btrfs_fs_info *fs_info = data;
2849 (struct btrfs_balance_control *)data;
2850 struct btrfs_fs_info *fs_info = bctl->fs_info;
2851 int ret = 0; 2849 int ret = 0;
2852 2850
2853 mutex_lock(&fs_info->volume_mutex); 2851 mutex_lock(&fs_info->volume_mutex);
2854 mutex_lock(&fs_info->balance_mutex); 2852 mutex_lock(&fs_info->balance_mutex);
2855 2853
2856 set_balance_control(bctl); 2854 if (fs_info->balance_ctl) {
2857
2858 if (btrfs_test_opt(fs_info->tree_root, SKIP_BALANCE)) {
2859 printk(KERN_INFO "btrfs: force skipping balance\n");
2860 } else {
2861 printk(KERN_INFO "btrfs: continuing balance\n"); 2855 printk(KERN_INFO "btrfs: continuing balance\n");
2862 ret = btrfs_balance(bctl, NULL); 2856 ret = btrfs_balance(fs_info->balance_ctl, NULL);
2863 } 2857 }
2864 2858
2865 mutex_unlock(&fs_info->balance_mutex); 2859 mutex_unlock(&fs_info->balance_mutex);
2866 mutex_unlock(&fs_info->volume_mutex); 2860 mutex_unlock(&fs_info->volume_mutex);
2861
2867 return ret; 2862 return ret;
2868} 2863}
2869 2864
2870int btrfs_recover_balance(struct btrfs_root *tree_root) 2865int btrfs_resume_balance_async(struct btrfs_fs_info *fs_info)
2871{ 2866{
2872 struct task_struct *tsk; 2867 struct task_struct *tsk;
2868
2869 spin_lock(&fs_info->balance_lock);
2870 if (!fs_info->balance_ctl) {
2871 spin_unlock(&fs_info->balance_lock);
2872 return 0;
2873 }
2874 spin_unlock(&fs_info->balance_lock);
2875
2876 if (btrfs_test_opt(fs_info->tree_root, SKIP_BALANCE)) {
2877 printk(KERN_INFO "btrfs: force skipping balance\n");
2878 return 0;
2879 }
2880
2881 tsk = kthread_run(balance_kthread, fs_info, "btrfs-balance");
2882 if (IS_ERR(tsk))
2883 return PTR_ERR(tsk);
2884
2885 return 0;
2886}
2887
2888int btrfs_recover_balance(struct btrfs_fs_info *fs_info)
2889{
2873 struct btrfs_balance_control *bctl; 2890 struct btrfs_balance_control *bctl;
2874 struct btrfs_balance_item *item; 2891 struct btrfs_balance_item *item;
2875 struct btrfs_disk_balance_args disk_bargs; 2892 struct btrfs_disk_balance_args disk_bargs;
@@ -2882,29 +2899,30 @@ int btrfs_recover_balance(struct btrfs_root *tree_root)
2882 if (!path) 2899 if (!path)
2883 return -ENOMEM; 2900 return -ENOMEM;
2884 2901
2885 bctl = kzalloc(sizeof(*bctl), GFP_NOFS);
2886 if (!bctl) {
2887 ret = -ENOMEM;
2888 goto out;
2889 }
2890
2891 key.objectid = BTRFS_BALANCE_OBJECTID; 2902 key.objectid = BTRFS_BALANCE_OBJECTID;
2892 key.type = BTRFS_BALANCE_ITEM_KEY; 2903 key.type = BTRFS_BALANCE_ITEM_KEY;
2893 key.offset = 0; 2904 key.offset = 0;
2894 2905
2895 ret = btrfs_search_slot(NULL, tree_root, &key, path, 0, 0); 2906 ret = btrfs_search_slot(NULL, fs_info->tree_root, &key, path, 0, 0);
2896 if (ret < 0) 2907 if (ret < 0)
2897 goto out_bctl; 2908 goto out;
2898 if (ret > 0) { /* ret = -ENOENT; */ 2909 if (ret > 0) { /* ret = -ENOENT; */
2899 ret = 0; 2910 ret = 0;
2900 goto out_bctl; 2911 goto out;
2912 }
2913
2914 bctl = kzalloc(sizeof(*bctl), GFP_NOFS);
2915 if (!bctl) {
2916 ret = -ENOMEM;
2917 goto out;
2901 } 2918 }
2902 2919
2903 leaf = path->nodes[0]; 2920 leaf = path->nodes[0];
2904 item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_balance_item); 2921 item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_balance_item);
2905 2922
2906 bctl->fs_info = tree_root->fs_info; 2923 bctl->fs_info = fs_info;
2907 bctl->flags = btrfs_balance_flags(leaf, item) | BTRFS_BALANCE_RESUME; 2924 bctl->flags = btrfs_balance_flags(leaf, item);
2925 bctl->flags |= BTRFS_BALANCE_RESUME;
2908 2926
2909 btrfs_balance_data(leaf, item, &disk_bargs); 2927 btrfs_balance_data(leaf, item, &disk_bargs);
2910 btrfs_disk_balance_args_to_cpu(&bctl->data, &disk_bargs); 2928 btrfs_disk_balance_args_to_cpu(&bctl->data, &disk_bargs);
@@ -2913,14 +2931,13 @@ int btrfs_recover_balance(struct btrfs_root *tree_root)
2913 btrfs_balance_sys(leaf, item, &disk_bargs); 2931 btrfs_balance_sys(leaf, item, &disk_bargs);
2914 btrfs_disk_balance_args_to_cpu(&bctl->sys, &disk_bargs); 2932 btrfs_disk_balance_args_to_cpu(&bctl->sys, &disk_bargs);
2915 2933
2916 tsk = kthread_run(balance_kthread, bctl, "btrfs-balance"); 2934 mutex_lock(&fs_info->volume_mutex);
2917 if (IS_ERR(tsk)) 2935 mutex_lock(&fs_info->balance_mutex);
2918 ret = PTR_ERR(tsk);
2919 else
2920 goto out;
2921 2936
2922out_bctl: 2937 set_balance_control(bctl);
2923 kfree(bctl); 2938
2939 mutex_unlock(&fs_info->balance_mutex);
2940 mutex_unlock(&fs_info->volume_mutex);
2924out: 2941out:
2925 btrfs_free_path(path); 2942 btrfs_free_path(path);
2926 return ret; 2943 return ret;
@@ -4061,16 +4078,18 @@ static void btrfs_end_bio(struct bio *bio, int err)
4061 4078
4062 BUG_ON(stripe_index >= bbio->num_stripes); 4079 BUG_ON(stripe_index >= bbio->num_stripes);
4063 dev = bbio->stripes[stripe_index].dev; 4080 dev = bbio->stripes[stripe_index].dev;
4064 if (bio->bi_rw & WRITE) 4081 if (dev->bdev) {
4065 btrfs_dev_stat_inc(dev, 4082 if (bio->bi_rw & WRITE)
4066 BTRFS_DEV_STAT_WRITE_ERRS); 4083 btrfs_dev_stat_inc(dev,
4067 else 4084 BTRFS_DEV_STAT_WRITE_ERRS);
4068 btrfs_dev_stat_inc(dev, 4085 else
4069 BTRFS_DEV_STAT_READ_ERRS); 4086 btrfs_dev_stat_inc(dev,
4070 if ((bio->bi_rw & WRITE_FLUSH) == WRITE_FLUSH) 4087 BTRFS_DEV_STAT_READ_ERRS);
4071 btrfs_dev_stat_inc(dev, 4088 if ((bio->bi_rw & WRITE_FLUSH) == WRITE_FLUSH)
4072 BTRFS_DEV_STAT_FLUSH_ERRS); 4089 btrfs_dev_stat_inc(dev,
4073 btrfs_dev_stat_print_on_error(dev); 4090 BTRFS_DEV_STAT_FLUSH_ERRS);
4091 btrfs_dev_stat_print_on_error(dev);
4092 }
4074 } 4093 }
4075 } 4094 }
4076 4095
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index 74366f27a76b..95f6637614db 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -281,7 +281,8 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size);
281int btrfs_init_new_device(struct btrfs_root *root, char *path); 281int btrfs_init_new_device(struct btrfs_root *root, char *path);
282int btrfs_balance(struct btrfs_balance_control *bctl, 282int btrfs_balance(struct btrfs_balance_control *bctl,
283 struct btrfs_ioctl_balance_args *bargs); 283 struct btrfs_ioctl_balance_args *bargs);
284int btrfs_recover_balance(struct btrfs_root *tree_root); 284int btrfs_resume_balance_async(struct btrfs_fs_info *fs_info);
285int btrfs_recover_balance(struct btrfs_fs_info *fs_info);
285int btrfs_pause_balance(struct btrfs_fs_info *fs_info); 286int btrfs_pause_balance(struct btrfs_fs_info *fs_info);
286int btrfs_cancel_balance(struct btrfs_fs_info *fs_info); 287int btrfs_cancel_balance(struct btrfs_fs_info *fs_info);
287int btrfs_chunk_readonly(struct btrfs_root *root, u64 chunk_offset); 288int btrfs_chunk_readonly(struct btrfs_root *root, u64 chunk_offset);
diff --git a/fs/buffer.c b/fs/buffer.c
index 838a9cf246bd..c7062c896d7c 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -1036,6 +1036,9 @@ grow_buffers(struct block_device *bdev, sector_t block, int size)
1036static struct buffer_head * 1036static struct buffer_head *
1037__getblk_slow(struct block_device *bdev, sector_t block, int size) 1037__getblk_slow(struct block_device *bdev, sector_t block, int size)
1038{ 1038{
1039 int ret;
1040 struct buffer_head *bh;
1041
1039 /* Size must be multiple of hard sectorsize */ 1042 /* Size must be multiple of hard sectorsize */
1040 if (unlikely(size & (bdev_logical_block_size(bdev)-1) || 1043 if (unlikely(size & (bdev_logical_block_size(bdev)-1) ||
1041 (size < 512 || size > PAGE_SIZE))) { 1044 (size < 512 || size > PAGE_SIZE))) {
@@ -1048,20 +1051,21 @@ __getblk_slow(struct block_device *bdev, sector_t block, int size)
1048 return NULL; 1051 return NULL;
1049 } 1052 }
1050 1053
1051 for (;;) { 1054retry:
1052 struct buffer_head * bh; 1055 bh = __find_get_block(bdev, block, size);
1053 int ret; 1056 if (bh)
1057 return bh;
1054 1058
1059 ret = grow_buffers(bdev, block, size);
1060 if (ret == 0) {
1061 free_more_memory();
1062 goto retry;
1063 } else if (ret > 0) {
1055 bh = __find_get_block(bdev, block, size); 1064 bh = __find_get_block(bdev, block, size);
1056 if (bh) 1065 if (bh)
1057 return bh; 1066 return bh;
1058
1059 ret = grow_buffers(bdev, block, size);
1060 if (ret < 0)
1061 return NULL;
1062 if (ret == 0)
1063 free_more_memory();
1064 } 1067 }
1068 return NULL;
1065} 1069}
1066 1070
1067/* 1071/*
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index 78db68a5cf44..0ae86ddf2213 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -1653,24 +1653,26 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
1653 * If yes, we have encountered a double deliminator 1653 * If yes, we have encountered a double deliminator
1654 * reset the NULL character to the deliminator 1654 * reset the NULL character to the deliminator
1655 */ 1655 */
1656 if (tmp_end < end && tmp_end[1] == delim) 1656 if (tmp_end < end && tmp_end[1] == delim) {
1657 tmp_end[0] = delim; 1657 tmp_end[0] = delim;
1658 1658
1659 /* Keep iterating until we get to a single deliminator 1659 /* Keep iterating until we get to a single
1660 * OR the end 1660 * deliminator OR the end
1661 */ 1661 */
1662 while ((tmp_end = strchr(tmp_end, delim)) != NULL && 1662 while ((tmp_end = strchr(tmp_end, delim))
1663 (tmp_end[1] == delim)) { 1663 != NULL && (tmp_end[1] == delim)) {
1664 tmp_end = (char *) &tmp_end[2]; 1664 tmp_end = (char *) &tmp_end[2];
1665 } 1665 }
1666 1666
1667 /* Reset var options to point to next element */ 1667 /* Reset var options to point to next element */
1668 if (tmp_end) { 1668 if (tmp_end) {
1669 tmp_end[0] = '\0'; 1669 tmp_end[0] = '\0';
1670 options = (char *) &tmp_end[1]; 1670 options = (char *) &tmp_end[1];
1671 } else 1671 } else
1672 /* Reached the end of the mount option string */ 1672 /* Reached the end of the mount option
1673 options = end; 1673 * string */
1674 options = end;
1675 }
1674 1676
1675 /* Now build new password string */ 1677 /* Now build new password string */
1676 temp_len = strlen(value); 1678 temp_len = strlen(value);
@@ -3493,18 +3495,15 @@ cifs_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *pvolume_info)
3493 * MS-CIFS indicates that servers are only limited by the client's 3495 * MS-CIFS indicates that servers are only limited by the client's
3494 * bufsize for reads, testing against win98se shows that it throws 3496 * bufsize for reads, testing against win98se shows that it throws
3495 * INVALID_PARAMETER errors if you try to request too large a read. 3497 * INVALID_PARAMETER errors if you try to request too large a read.
3498 * OS/2 just sends back short reads.
3496 * 3499 *
3497 * If the server advertises a MaxBufferSize of less than one page, 3500 * If the server doesn't advertise CAP_LARGE_READ_X, then assume that
3498 * assume that it also can't satisfy reads larger than that either. 3501 * it can't handle a read request larger than its MaxBufferSize either.
3499 *
3500 * FIXME: Is there a better heuristic for this?
3501 */ 3502 */
3502 if (tcon->unix_ext && (unix_cap & CIFS_UNIX_LARGE_READ_CAP)) 3503 if (tcon->unix_ext && (unix_cap & CIFS_UNIX_LARGE_READ_CAP))
3503 defsize = CIFS_DEFAULT_IOSIZE; 3504 defsize = CIFS_DEFAULT_IOSIZE;
3504 else if (server->capabilities & CAP_LARGE_READ_X) 3505 else if (server->capabilities & CAP_LARGE_READ_X)
3505 defsize = CIFS_DEFAULT_NON_POSIX_RSIZE; 3506 defsize = CIFS_DEFAULT_NON_POSIX_RSIZE;
3506 else if (server->maxBuf >= PAGE_CACHE_SIZE)
3507 defsize = CIFSMaxBufSize;
3508 else 3507 else
3509 defsize = server->maxBuf - sizeof(READ_RSP); 3508 defsize = server->maxBuf - sizeof(READ_RSP);
3510 3509
diff --git a/fs/ecryptfs/kthread.c b/fs/ecryptfs/kthread.c
index 69f994a7d524..0dbe58a8b172 100644
--- a/fs/ecryptfs/kthread.c
+++ b/fs/ecryptfs/kthread.c
@@ -149,7 +149,7 @@ int ecryptfs_privileged_open(struct file **lower_file,
149 (*lower_file) = dentry_open(lower_dentry, lower_mnt, flags, cred); 149 (*lower_file) = dentry_open(lower_dentry, lower_mnt, flags, cred);
150 if (!IS_ERR(*lower_file)) 150 if (!IS_ERR(*lower_file))
151 goto out; 151 goto out;
152 if (flags & O_RDONLY) { 152 if ((flags & O_ACCMODE) == O_RDONLY) {
153 rc = PTR_ERR((*lower_file)); 153 rc = PTR_ERR((*lower_file));
154 goto out; 154 goto out;
155 } 155 }
diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
index 3a06f4043df4..c0038f6566d4 100644
--- a/fs/ecryptfs/miscdev.c
+++ b/fs/ecryptfs/miscdev.c
@@ -49,7 +49,10 @@ ecryptfs_miscdev_poll(struct file *file, poll_table *pt)
49 mutex_lock(&ecryptfs_daemon_hash_mux); 49 mutex_lock(&ecryptfs_daemon_hash_mux);
50 /* TODO: Just use file->private_data? */ 50 /* TODO: Just use file->private_data? */
51 rc = ecryptfs_find_daemon_by_euid(&daemon, euid, current_user_ns()); 51 rc = ecryptfs_find_daemon_by_euid(&daemon, euid, current_user_ns());
52 BUG_ON(rc || !daemon); 52 if (rc || !daemon) {
53 mutex_unlock(&ecryptfs_daemon_hash_mux);
54 return -EINVAL;
55 }
53 mutex_lock(&daemon->mux); 56 mutex_lock(&daemon->mux);
54 mutex_unlock(&ecryptfs_daemon_hash_mux); 57 mutex_unlock(&ecryptfs_daemon_hash_mux);
55 if (daemon->flags & ECRYPTFS_DAEMON_ZOMBIE) { 58 if (daemon->flags & ECRYPTFS_DAEMON_ZOMBIE) {
@@ -122,6 +125,7 @@ ecryptfs_miscdev_open(struct inode *inode, struct file *file)
122 goto out_unlock_daemon; 125 goto out_unlock_daemon;
123 } 126 }
124 daemon->flags |= ECRYPTFS_DAEMON_MISCDEV_OPEN; 127 daemon->flags |= ECRYPTFS_DAEMON_MISCDEV_OPEN;
128 file->private_data = daemon;
125 atomic_inc(&ecryptfs_num_miscdev_opens); 129 atomic_inc(&ecryptfs_num_miscdev_opens);
126out_unlock_daemon: 130out_unlock_daemon:
127 mutex_unlock(&daemon->mux); 131 mutex_unlock(&daemon->mux);
@@ -152,9 +156,9 @@ ecryptfs_miscdev_release(struct inode *inode, struct file *file)
152 156
153 mutex_lock(&ecryptfs_daemon_hash_mux); 157 mutex_lock(&ecryptfs_daemon_hash_mux);
154 rc = ecryptfs_find_daemon_by_euid(&daemon, euid, current_user_ns()); 158 rc = ecryptfs_find_daemon_by_euid(&daemon, euid, current_user_ns());
155 BUG_ON(rc || !daemon); 159 if (rc || !daemon)
160 daemon = file->private_data;
156 mutex_lock(&daemon->mux); 161 mutex_lock(&daemon->mux);
157 BUG_ON(daemon->pid != task_pid(current));
158 BUG_ON(!(daemon->flags & ECRYPTFS_DAEMON_MISCDEV_OPEN)); 162 BUG_ON(!(daemon->flags & ECRYPTFS_DAEMON_MISCDEV_OPEN));
159 daemon->flags &= ~ECRYPTFS_DAEMON_MISCDEV_OPEN; 163 daemon->flags &= ~ECRYPTFS_DAEMON_MISCDEV_OPEN;
160 atomic_dec(&ecryptfs_num_miscdev_opens); 164 atomic_dec(&ecryptfs_num_miscdev_opens);
@@ -191,31 +195,32 @@ int ecryptfs_send_miscdev(char *data, size_t data_size,
191 struct ecryptfs_msg_ctx *msg_ctx, u8 msg_type, 195 struct ecryptfs_msg_ctx *msg_ctx, u8 msg_type,
192 u16 msg_flags, struct ecryptfs_daemon *daemon) 196 u16 msg_flags, struct ecryptfs_daemon *daemon)
193{ 197{
194 int rc = 0; 198 struct ecryptfs_message *msg;
195 199
196 mutex_lock(&msg_ctx->mux); 200 msg = kmalloc((sizeof(*msg) + data_size), GFP_KERNEL);
197 msg_ctx->msg = kmalloc((sizeof(*msg_ctx->msg) + data_size), 201 if (!msg) {
198 GFP_KERNEL);
199 if (!msg_ctx->msg) {
200 rc = -ENOMEM;
201 printk(KERN_ERR "%s: Out of memory whilst attempting " 202 printk(KERN_ERR "%s: Out of memory whilst attempting "
202 "to kmalloc(%zd, GFP_KERNEL)\n", __func__, 203 "to kmalloc(%zd, GFP_KERNEL)\n", __func__,
203 (sizeof(*msg_ctx->msg) + data_size)); 204 (sizeof(*msg) + data_size));
204 goto out_unlock; 205 return -ENOMEM;
205 } 206 }
207
208 mutex_lock(&msg_ctx->mux);
209 msg_ctx->msg = msg;
206 msg_ctx->msg->index = msg_ctx->index; 210 msg_ctx->msg->index = msg_ctx->index;
207 msg_ctx->msg->data_len = data_size; 211 msg_ctx->msg->data_len = data_size;
208 msg_ctx->type = msg_type; 212 msg_ctx->type = msg_type;
209 memcpy(msg_ctx->msg->data, data, data_size); 213 memcpy(msg_ctx->msg->data, data, data_size);
210 msg_ctx->msg_size = (sizeof(*msg_ctx->msg) + data_size); 214 msg_ctx->msg_size = (sizeof(*msg_ctx->msg) + data_size);
211 mutex_lock(&daemon->mux);
212 list_add_tail(&msg_ctx->daemon_out_list, &daemon->msg_ctx_out_queue); 215 list_add_tail(&msg_ctx->daemon_out_list, &daemon->msg_ctx_out_queue);
216 mutex_unlock(&msg_ctx->mux);
217
218 mutex_lock(&daemon->mux);
213 daemon->num_queued_msg_ctx++; 219 daemon->num_queued_msg_ctx++;
214 wake_up_interruptible(&daemon->wait); 220 wake_up_interruptible(&daemon->wait);
215 mutex_unlock(&daemon->mux); 221 mutex_unlock(&daemon->mux);
216out_unlock: 222
217 mutex_unlock(&msg_ctx->mux); 223 return 0;
218 return rc;
219} 224}
220 225
221/* 226/*
@@ -269,8 +274,16 @@ ecryptfs_miscdev_read(struct file *file, char __user *buf, size_t count,
269 mutex_lock(&ecryptfs_daemon_hash_mux); 274 mutex_lock(&ecryptfs_daemon_hash_mux);
270 /* TODO: Just use file->private_data? */ 275 /* TODO: Just use file->private_data? */
271 rc = ecryptfs_find_daemon_by_euid(&daemon, euid, current_user_ns()); 276 rc = ecryptfs_find_daemon_by_euid(&daemon, euid, current_user_ns());
272 BUG_ON(rc || !daemon); 277 if (rc || !daemon) {
278 mutex_unlock(&ecryptfs_daemon_hash_mux);
279 return -EINVAL;
280 }
273 mutex_lock(&daemon->mux); 281 mutex_lock(&daemon->mux);
282 if (task_pid(current) != daemon->pid) {
283 mutex_unlock(&daemon->mux);
284 mutex_unlock(&ecryptfs_daemon_hash_mux);
285 return -EPERM;
286 }
274 if (daemon->flags & ECRYPTFS_DAEMON_ZOMBIE) { 287 if (daemon->flags & ECRYPTFS_DAEMON_ZOMBIE) {
275 rc = 0; 288 rc = 0;
276 mutex_unlock(&ecryptfs_daemon_hash_mux); 289 mutex_unlock(&ecryptfs_daemon_hash_mux);
@@ -307,9 +320,6 @@ check_list:
307 * message from the queue; try again */ 320 * message from the queue; try again */
308 goto check_list; 321 goto check_list;
309 } 322 }
310 BUG_ON(euid != daemon->euid);
311 BUG_ON(current_user_ns() != daemon->user_ns);
312 BUG_ON(task_pid(current) != daemon->pid);
313 msg_ctx = list_first_entry(&daemon->msg_ctx_out_queue, 323 msg_ctx = list_first_entry(&daemon->msg_ctx_out_queue,
314 struct ecryptfs_msg_ctx, daemon_out_list); 324 struct ecryptfs_msg_ctx, daemon_out_list);
315 BUG_ON(!msg_ctx); 325 BUG_ON(!msg_ctx);
diff --git a/fs/fat/inode.c b/fs/fat/inode.c
index a3d81ebf6d86..0038b32cb362 100644
--- a/fs/fat/inode.c
+++ b/fs/fat/inode.c
@@ -738,22 +738,21 @@ static int
738fat_encode_fh(struct inode *inode, __u32 *fh, int *lenp, struct inode *parent) 738fat_encode_fh(struct inode *inode, __u32 *fh, int *lenp, struct inode *parent)
739{ 739{
740 int len = *lenp; 740 int len = *lenp;
741 u32 ipos_h, ipos_m, ipos_l; 741 struct msdos_sb_info *sbi = MSDOS_SB(inode->i_sb);
742 loff_t i_pos;
742 743
743 if (len < 5) { 744 if (len < 5) {
744 *lenp = 5; 745 *lenp = 5;
745 return 255; /* no room */ 746 return 255; /* no room */
746 } 747 }
747 748
748 ipos_h = MSDOS_I(inode)->i_pos >> 8; 749 i_pos = fat_i_pos_read(sbi, inode);
749 ipos_m = (MSDOS_I(inode)->i_pos & 0xf0) << 24;
750 ipos_l = (MSDOS_I(inode)->i_pos & 0x0f) << 28;
751 *lenp = 5; 750 *lenp = 5;
752 fh[0] = inode->i_ino; 751 fh[0] = inode->i_ino;
753 fh[1] = inode->i_generation; 752 fh[1] = inode->i_generation;
754 fh[2] = ipos_h; 753 fh[2] = i_pos >> 8;
755 fh[3] = ipos_m | MSDOS_I(inode)->i_logstart; 754 fh[3] = ((i_pos & 0xf0) << 24) | MSDOS_I(inode)->i_logstart;
756 fh[4] = ipos_l; 755 fh[4] = (i_pos & 0x0f) << 28;
757 if (parent) 756 if (parent)
758 fh[4] |= MSDOS_I(parent)->i_logstart; 757 fh[4] |= MSDOS_I(parent)->i_logstart;
759 return 3; 758 return 3;
diff --git a/fs/locks.c b/fs/locks.c
index 814c51d0de47..fce6238d52c1 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -1465,7 +1465,7 @@ int generic_setlease(struct file *filp, long arg, struct file_lock **flp)
1465 case F_WRLCK: 1465 case F_WRLCK:
1466 return generic_add_lease(filp, arg, flp); 1466 return generic_add_lease(filp, arg, flp);
1467 default: 1467 default:
1468 BUG(); 1468 return -EINVAL;
1469 } 1469 }
1470} 1470}
1471EXPORT_SYMBOL(generic_setlease); 1471EXPORT_SYMBOL(generic_setlease);
diff --git a/fs/nfs/direct.c b/fs/nfs/direct.c
index 9a4cbfc85d81..48253372ab1d 100644
--- a/fs/nfs/direct.c
+++ b/fs/nfs/direct.c
@@ -484,6 +484,7 @@ static void nfs_direct_write_reschedule(struct nfs_direct_req *dreq)
484 484
485 list_for_each_entry_safe(req, tmp, &reqs, wb_list) { 485 list_for_each_entry_safe(req, tmp, &reqs, wb_list) {
486 if (!nfs_pageio_add_request(&desc, req)) { 486 if (!nfs_pageio_add_request(&desc, req)) {
487 nfs_list_remove_request(req);
487 nfs_list_add_request(req, &failed); 488 nfs_list_add_request(req, &failed);
488 spin_lock(cinfo.lock); 489 spin_lock(cinfo.lock);
489 dreq->flags = 0; 490 dreq->flags = 0;
@@ -494,8 +495,11 @@ static void nfs_direct_write_reschedule(struct nfs_direct_req *dreq)
494 } 495 }
495 nfs_pageio_complete(&desc); 496 nfs_pageio_complete(&desc);
496 497
497 while (!list_empty(&failed)) 498 while (!list_empty(&failed)) {
499 req = nfs_list_entry(failed.next);
500 nfs_list_remove_request(req);
498 nfs_unlock_and_release_request(req); 501 nfs_unlock_and_release_request(req);
502 }
499 503
500 if (put_dreq(dreq)) 504 if (put_dreq(dreq))
501 nfs_direct_write_complete(dreq, dreq->inode); 505 nfs_direct_write_complete(dreq, dreq->inode);
diff --git a/fs/nfs/super.c b/fs/nfs/super.c
index 906f09c7d842..06228192f64e 100644
--- a/fs/nfs/super.c
+++ b/fs/nfs/super.c
@@ -2860,6 +2860,8 @@ static struct dentry *nfs4_try_mount(int flags, const char *dev_name,
2860 2860
2861 dfprintk(MOUNT, "--> nfs4_try_mount()\n"); 2861 dfprintk(MOUNT, "--> nfs4_try_mount()\n");
2862 2862
2863 mount_info->fill_super = nfs4_fill_super;
2864
2863 export_path = data->nfs_server.export_path; 2865 export_path = data->nfs_server.export_path;
2864 data->nfs_server.export_path = "/"; 2866 data->nfs_server.export_path = "/";
2865 root_mnt = nfs_do_root_mount(&nfs4_remote_fs_type, flags, mount_info, 2867 root_mnt = nfs_do_root_mount(&nfs4_remote_fs_type, flags, mount_info,
diff --git a/fs/ocfs2/dlmglue.c b/fs/ocfs2/dlmglue.c
index 81a4cd22f80b..4f7795fb5fc0 100644
--- a/fs/ocfs2/dlmglue.c
+++ b/fs/ocfs2/dlmglue.c
@@ -456,7 +456,7 @@ static void ocfs2_update_lock_stats(struct ocfs2_lock_res *res, int level,
456 stats->ls_gets++; 456 stats->ls_gets++;
457 stats->ls_total += ktime_to_ns(kt); 457 stats->ls_total += ktime_to_ns(kt);
458 /* overflow */ 458 /* overflow */
459 if (unlikely(stats->ls_gets) == 0) { 459 if (unlikely(stats->ls_gets == 0)) {
460 stats->ls_gets++; 460 stats->ls_gets++;
461 stats->ls_total = ktime_to_ns(kt); 461 stats->ls_total = ktime_to_ns(kt);
462 } 462 }
@@ -3932,6 +3932,8 @@ unqueue:
3932static void ocfs2_schedule_blocked_lock(struct ocfs2_super *osb, 3932static void ocfs2_schedule_blocked_lock(struct ocfs2_super *osb,
3933 struct ocfs2_lock_res *lockres) 3933 struct ocfs2_lock_res *lockres)
3934{ 3934{
3935 unsigned long flags;
3936
3935 assert_spin_locked(&lockres->l_lock); 3937 assert_spin_locked(&lockres->l_lock);
3936 3938
3937 if (lockres->l_flags & OCFS2_LOCK_FREEING) { 3939 if (lockres->l_flags & OCFS2_LOCK_FREEING) {
@@ -3945,21 +3947,22 @@ static void ocfs2_schedule_blocked_lock(struct ocfs2_super *osb,
3945 3947
3946 lockres_or_flags(lockres, OCFS2_LOCK_QUEUED); 3948 lockres_or_flags(lockres, OCFS2_LOCK_QUEUED);
3947 3949
3948 spin_lock(&osb->dc_task_lock); 3950 spin_lock_irqsave(&osb->dc_task_lock, flags);
3949 if (list_empty(&lockres->l_blocked_list)) { 3951 if (list_empty(&lockres->l_blocked_list)) {
3950 list_add_tail(&lockres->l_blocked_list, 3952 list_add_tail(&lockres->l_blocked_list,
3951 &osb->blocked_lock_list); 3953 &osb->blocked_lock_list);
3952 osb->blocked_lock_count++; 3954 osb->blocked_lock_count++;
3953 } 3955 }
3954 spin_unlock(&osb->dc_task_lock); 3956 spin_unlock_irqrestore(&osb->dc_task_lock, flags);
3955} 3957}
3956 3958
3957static void ocfs2_downconvert_thread_do_work(struct ocfs2_super *osb) 3959static void ocfs2_downconvert_thread_do_work(struct ocfs2_super *osb)
3958{ 3960{
3959 unsigned long processed; 3961 unsigned long processed;
3962 unsigned long flags;
3960 struct ocfs2_lock_res *lockres; 3963 struct ocfs2_lock_res *lockres;
3961 3964
3962 spin_lock(&osb->dc_task_lock); 3965 spin_lock_irqsave(&osb->dc_task_lock, flags);
3963 /* grab this early so we know to try again if a state change and 3966 /* grab this early so we know to try again if a state change and
3964 * wake happens part-way through our work */ 3967 * wake happens part-way through our work */
3965 osb->dc_work_sequence = osb->dc_wake_sequence; 3968 osb->dc_work_sequence = osb->dc_wake_sequence;
@@ -3972,38 +3975,40 @@ static void ocfs2_downconvert_thread_do_work(struct ocfs2_super *osb)
3972 struct ocfs2_lock_res, l_blocked_list); 3975 struct ocfs2_lock_res, l_blocked_list);
3973 list_del_init(&lockres->l_blocked_list); 3976 list_del_init(&lockres->l_blocked_list);
3974 osb->blocked_lock_count--; 3977 osb->blocked_lock_count--;
3975 spin_unlock(&osb->dc_task_lock); 3978 spin_unlock_irqrestore(&osb->dc_task_lock, flags);
3976 3979
3977 BUG_ON(!processed); 3980 BUG_ON(!processed);
3978 processed--; 3981 processed--;
3979 3982
3980 ocfs2_process_blocked_lock(osb, lockres); 3983 ocfs2_process_blocked_lock(osb, lockres);
3981 3984
3982 spin_lock(&osb->dc_task_lock); 3985 spin_lock_irqsave(&osb->dc_task_lock, flags);
3983 } 3986 }
3984 spin_unlock(&osb->dc_task_lock); 3987 spin_unlock_irqrestore(&osb->dc_task_lock, flags);
3985} 3988}
3986 3989
3987static int ocfs2_downconvert_thread_lists_empty(struct ocfs2_super *osb) 3990static int ocfs2_downconvert_thread_lists_empty(struct ocfs2_super *osb)
3988{ 3991{
3989 int empty = 0; 3992 int empty = 0;
3993 unsigned long flags;
3990 3994
3991 spin_lock(&osb->dc_task_lock); 3995 spin_lock_irqsave(&osb->dc_task_lock, flags);
3992 if (list_empty(&osb->blocked_lock_list)) 3996 if (list_empty(&osb->blocked_lock_list))
3993 empty = 1; 3997 empty = 1;
3994 3998
3995 spin_unlock(&osb->dc_task_lock); 3999 spin_unlock_irqrestore(&osb->dc_task_lock, flags);
3996 return empty; 4000 return empty;
3997} 4001}
3998 4002
3999static int ocfs2_downconvert_thread_should_wake(struct ocfs2_super *osb) 4003static int ocfs2_downconvert_thread_should_wake(struct ocfs2_super *osb)
4000{ 4004{
4001 int should_wake = 0; 4005 int should_wake = 0;
4006 unsigned long flags;
4002 4007
4003 spin_lock(&osb->dc_task_lock); 4008 spin_lock_irqsave(&osb->dc_task_lock, flags);
4004 if (osb->dc_work_sequence != osb->dc_wake_sequence) 4009 if (osb->dc_work_sequence != osb->dc_wake_sequence)
4005 should_wake = 1; 4010 should_wake = 1;
4006 spin_unlock(&osb->dc_task_lock); 4011 spin_unlock_irqrestore(&osb->dc_task_lock, flags);
4007 4012
4008 return should_wake; 4013 return should_wake;
4009} 4014}
@@ -4033,10 +4038,12 @@ static int ocfs2_downconvert_thread(void *arg)
4033 4038
4034void ocfs2_wake_downconvert_thread(struct ocfs2_super *osb) 4039void ocfs2_wake_downconvert_thread(struct ocfs2_super *osb)
4035{ 4040{
4036 spin_lock(&osb->dc_task_lock); 4041 unsigned long flags;
4042
4043 spin_lock_irqsave(&osb->dc_task_lock, flags);
4037 /* make sure the voting thread gets a swipe at whatever changes 4044 /* make sure the voting thread gets a swipe at whatever changes
4038 * the caller may have made to the voting state */ 4045 * the caller may have made to the voting state */
4039 osb->dc_wake_sequence++; 4046 osb->dc_wake_sequence++;
4040 spin_unlock(&osb->dc_task_lock); 4047 spin_unlock_irqrestore(&osb->dc_task_lock, flags);
4041 wake_up(&osb->dc_event); 4048 wake_up(&osb->dc_event);
4042} 4049}
diff --git a/fs/ocfs2/extent_map.c b/fs/ocfs2/extent_map.c
index 2f5b92ef0e53..70b5863a2d64 100644
--- a/fs/ocfs2/extent_map.c
+++ b/fs/ocfs2/extent_map.c
@@ -923,8 +923,6 @@ out_unlock:
923 923
924 ocfs2_inode_unlock(inode, 0); 924 ocfs2_inode_unlock(inode, 0);
925out: 925out:
926 if (ret && ret != -ENXIO)
927 ret = -ENXIO;
928 return ret; 926 return ret;
929} 927}
930 928
diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c
index 061591a3ab08..7602783d7f41 100644
--- a/fs/ocfs2/file.c
+++ b/fs/ocfs2/file.c
@@ -1950,7 +1950,7 @@ static int __ocfs2_change_file_space(struct file *file, struct inode *inode,
1950 if (ret < 0) 1950 if (ret < 0)
1951 mlog_errno(ret); 1951 mlog_errno(ret);
1952 1952
1953 if (file->f_flags & O_SYNC) 1953 if (file && (file->f_flags & O_SYNC))
1954 handle->h_sync = 1; 1954 handle->h_sync = 1;
1955 1955
1956 ocfs2_commit_trans(osb, handle); 1956 ocfs2_commit_trans(osb, handle);
@@ -2422,8 +2422,10 @@ out_dio:
2422 unaligned_dio = 0; 2422 unaligned_dio = 0;
2423 } 2423 }
2424 2424
2425 if (unaligned_dio) 2425 if (unaligned_dio) {
2426 ocfs2_iocb_clear_unaligned_aio(iocb);
2426 atomic_dec(&OCFS2_I(inode)->ip_unaligned_aio); 2427 atomic_dec(&OCFS2_I(inode)->ip_unaligned_aio);
2428 }
2427 2429
2428out: 2430out:
2429 if (rw_level != -1) 2431 if (rw_level != -1)
diff --git a/fs/ocfs2/quota_global.c b/fs/ocfs2/quota_global.c
index 92fcd575775a..0a86e302655f 100644
--- a/fs/ocfs2/quota_global.c
+++ b/fs/ocfs2/quota_global.c
@@ -399,8 +399,6 @@ int ocfs2_global_read_info(struct super_block *sb, int type)
399 msecs_to_jiffies(oinfo->dqi_syncms)); 399 msecs_to_jiffies(oinfo->dqi_syncms));
400 400
401out_err: 401out_err:
402 if (status)
403 mlog_errno(status);
404 return status; 402 return status;
405out_unlock: 403out_unlock:
406 ocfs2_unlock_global_qf(oinfo, 0); 404 ocfs2_unlock_global_qf(oinfo, 0);
diff --git a/fs/open.c b/fs/open.c
index d6c79a0dffc7..1540632d8387 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -397,10 +397,10 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
397{ 397{
398 struct file *file; 398 struct file *file;
399 struct inode *inode; 399 struct inode *inode;
400 int error; 400 int error, fput_needed;
401 401
402 error = -EBADF; 402 error = -EBADF;
403 file = fget(fd); 403 file = fget_raw_light(fd, &fput_needed);
404 if (!file) 404 if (!file)
405 goto out; 405 goto out;
406 406
@@ -414,7 +414,7 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
414 if (!error) 414 if (!error)
415 set_fs_pwd(current->fs, &file->f_path); 415 set_fs_pwd(current->fs, &file->f_path);
416out_putf: 416out_putf:
417 fput(file); 417 fput_light(file, fput_needed);
418out: 418out:
419 return error; 419 return error;
420} 420}
diff --git a/fs/ramfs/file-nommu.c b/fs/ramfs/file-nommu.c
index fbb0b478a346..d5378d028589 100644
--- a/fs/ramfs/file-nommu.c
+++ b/fs/ramfs/file-nommu.c
@@ -110,6 +110,7 @@ int ramfs_nommu_expand_for_mapping(struct inode *inode, size_t newsize)
110 110
111 /* prevent the page from being discarded on memory pressure */ 111 /* prevent the page from being discarded on memory pressure */
112 SetPageDirty(page); 112 SetPageDirty(page);
113 SetPageUptodate(page);
113 114
114 unlock_page(page); 115 unlock_page(page);
115 put_page(page); 116 put_page(page);
diff --git a/fs/splice.c b/fs/splice.c
index c9f1318a3b82..7bf08fa22ec9 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -273,13 +273,16 @@ void spd_release_page(struct splice_pipe_desc *spd, unsigned int i)
273 * Check if we need to grow the arrays holding pages and partial page 273 * Check if we need to grow the arrays holding pages and partial page
274 * descriptions. 274 * descriptions.
275 */ 275 */
276int splice_grow_spd(struct pipe_inode_info *pipe, struct splice_pipe_desc *spd) 276int splice_grow_spd(const struct pipe_inode_info *pipe, struct splice_pipe_desc *spd)
277{ 277{
278 if (pipe->buffers <= PIPE_DEF_BUFFERS) 278 unsigned int buffers = ACCESS_ONCE(pipe->buffers);
279
280 spd->nr_pages_max = buffers;
281 if (buffers <= PIPE_DEF_BUFFERS)
279 return 0; 282 return 0;
280 283
281 spd->pages = kmalloc(pipe->buffers * sizeof(struct page *), GFP_KERNEL); 284 spd->pages = kmalloc(buffers * sizeof(struct page *), GFP_KERNEL);
282 spd->partial = kmalloc(pipe->buffers * sizeof(struct partial_page), GFP_KERNEL); 285 spd->partial = kmalloc(buffers * sizeof(struct partial_page), GFP_KERNEL);
283 286
284 if (spd->pages && spd->partial) 287 if (spd->pages && spd->partial)
285 return 0; 288 return 0;
@@ -289,10 +292,9 @@ int splice_grow_spd(struct pipe_inode_info *pipe, struct splice_pipe_desc *spd)
289 return -ENOMEM; 292 return -ENOMEM;
290} 293}
291 294
292void splice_shrink_spd(struct pipe_inode_info *pipe, 295void splice_shrink_spd(struct splice_pipe_desc *spd)
293 struct splice_pipe_desc *spd)
294{ 296{
295 if (pipe->buffers <= PIPE_DEF_BUFFERS) 297 if (spd->nr_pages_max <= PIPE_DEF_BUFFERS)
296 return; 298 return;
297 299
298 kfree(spd->pages); 300 kfree(spd->pages);
@@ -315,6 +317,7 @@ __generic_file_splice_read(struct file *in, loff_t *ppos,
315 struct splice_pipe_desc spd = { 317 struct splice_pipe_desc spd = {
316 .pages = pages, 318 .pages = pages,
317 .partial = partial, 319 .partial = partial,
320 .nr_pages_max = PIPE_DEF_BUFFERS,
318 .flags = flags, 321 .flags = flags,
319 .ops = &page_cache_pipe_buf_ops, 322 .ops = &page_cache_pipe_buf_ops,
320 .spd_release = spd_release_page, 323 .spd_release = spd_release_page,
@@ -326,7 +329,7 @@ __generic_file_splice_read(struct file *in, loff_t *ppos,
326 index = *ppos >> PAGE_CACHE_SHIFT; 329 index = *ppos >> PAGE_CACHE_SHIFT;
327 loff = *ppos & ~PAGE_CACHE_MASK; 330 loff = *ppos & ~PAGE_CACHE_MASK;
328 req_pages = (len + loff + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; 331 req_pages = (len + loff + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
329 nr_pages = min(req_pages, pipe->buffers); 332 nr_pages = min(req_pages, spd.nr_pages_max);
330 333
331 /* 334 /*
332 * Lookup the (hopefully) full range of pages we need. 335 * Lookup the (hopefully) full range of pages we need.
@@ -497,7 +500,7 @@ fill_it:
497 if (spd.nr_pages) 500 if (spd.nr_pages)
498 error = splice_to_pipe(pipe, &spd); 501 error = splice_to_pipe(pipe, &spd);
499 502
500 splice_shrink_spd(pipe, &spd); 503 splice_shrink_spd(&spd);
501 return error; 504 return error;
502} 505}
503 506
@@ -598,6 +601,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
598 struct splice_pipe_desc spd = { 601 struct splice_pipe_desc spd = {
599 .pages = pages, 602 .pages = pages,
600 .partial = partial, 603 .partial = partial,
604 .nr_pages_max = PIPE_DEF_BUFFERS,
601 .flags = flags, 605 .flags = flags,
602 .ops = &default_pipe_buf_ops, 606 .ops = &default_pipe_buf_ops,
603 .spd_release = spd_release_page, 607 .spd_release = spd_release_page,
@@ -608,8 +612,8 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
608 612
609 res = -ENOMEM; 613 res = -ENOMEM;
610 vec = __vec; 614 vec = __vec;
611 if (pipe->buffers > PIPE_DEF_BUFFERS) { 615 if (spd.nr_pages_max > PIPE_DEF_BUFFERS) {
612 vec = kmalloc(pipe->buffers * sizeof(struct iovec), GFP_KERNEL); 616 vec = kmalloc(spd.nr_pages_max * sizeof(struct iovec), GFP_KERNEL);
613 if (!vec) 617 if (!vec)
614 goto shrink_ret; 618 goto shrink_ret;
615 } 619 }
@@ -617,7 +621,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
617 offset = *ppos & ~PAGE_CACHE_MASK; 621 offset = *ppos & ~PAGE_CACHE_MASK;
618 nr_pages = (len + offset + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; 622 nr_pages = (len + offset + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
619 623
620 for (i = 0; i < nr_pages && i < pipe->buffers && len; i++) { 624 for (i = 0; i < nr_pages && i < spd.nr_pages_max && len; i++) {
621 struct page *page; 625 struct page *page;
622 626
623 page = alloc_page(GFP_USER); 627 page = alloc_page(GFP_USER);
@@ -665,7 +669,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
665shrink_ret: 669shrink_ret:
666 if (vec != __vec) 670 if (vec != __vec)
667 kfree(vec); 671 kfree(vec);
668 splice_shrink_spd(pipe, &spd); 672 splice_shrink_spd(&spd);
669 return res; 673 return res;
670 674
671err: 675err:
@@ -1614,6 +1618,7 @@ static long vmsplice_to_pipe(struct file *file, const struct iovec __user *iov,
1614 struct splice_pipe_desc spd = { 1618 struct splice_pipe_desc spd = {
1615 .pages = pages, 1619 .pages = pages,
1616 .partial = partial, 1620 .partial = partial,
1621 .nr_pages_max = PIPE_DEF_BUFFERS,
1617 .flags = flags, 1622 .flags = flags,
1618 .ops = &user_page_pipe_buf_ops, 1623 .ops = &user_page_pipe_buf_ops,
1619 .spd_release = spd_release_page, 1624 .spd_release = spd_release_page,
@@ -1629,13 +1634,13 @@ static long vmsplice_to_pipe(struct file *file, const struct iovec __user *iov,
1629 1634
1630 spd.nr_pages = get_iovec_page_array(iov, nr_segs, spd.pages, 1635 spd.nr_pages = get_iovec_page_array(iov, nr_segs, spd.pages,
1631 spd.partial, false, 1636 spd.partial, false,
1632 pipe->buffers); 1637 spd.nr_pages_max);
1633 if (spd.nr_pages <= 0) 1638 if (spd.nr_pages <= 0)
1634 ret = spd.nr_pages; 1639 ret = spd.nr_pages;
1635 else 1640 else
1636 ret = splice_to_pipe(pipe, &spd); 1641 ret = splice_to_pipe(pipe, &spd);
1637 1642
1638 splice_shrink_spd(pipe, &spd); 1643 splice_shrink_spd(&spd);
1639 return ret; 1644 return ret;
1640} 1645}
1641 1646
diff --git a/include/linux/aio.h b/include/linux/aio.h
index 2314ad8b3c9c..b1a520ec8b59 100644
--- a/include/linux/aio.h
+++ b/include/linux/aio.h
@@ -140,6 +140,7 @@ struct kiocb {
140 (x)->ki_dtor = NULL; \ 140 (x)->ki_dtor = NULL; \
141 (x)->ki_obj.tsk = tsk; \ 141 (x)->ki_obj.tsk = tsk; \
142 (x)->ki_user_data = 0; \ 142 (x)->ki_user_data = 0; \
143 (x)->private = NULL; \
143 } while (0) 144 } while (0)
144 145
145#define AIO_RING_MAGIC 0xa10a10a1 146#define AIO_RING_MAGIC 0xa10a10a1
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index ba43f408baa3..07954b05b86c 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -827,7 +827,6 @@ extern bool __blk_end_request_err(struct request *rq, int error);
827extern void blk_complete_request(struct request *); 827extern void blk_complete_request(struct request *);
828extern void __blk_complete_request(struct request *); 828extern void __blk_complete_request(struct request *);
829extern void blk_abort_request(struct request *); 829extern void blk_abort_request(struct request *);
830extern void blk_abort_queue(struct request_queue *);
831extern void blk_unprep_request(struct request *); 830extern void blk_unprep_request(struct request *);
832 831
833/* 832/*
diff --git a/include/linux/bootmem.h b/include/linux/bootmem.h
index 324fe08ea3b1..6d6795d46a75 100644
--- a/include/linux/bootmem.h
+++ b/include/linux/bootmem.h
@@ -91,6 +91,11 @@ extern void *__alloc_bootmem_node_nopanic(pg_data_t *pgdat,
91 unsigned long size, 91 unsigned long size,
92 unsigned long align, 92 unsigned long align,
93 unsigned long goal); 93 unsigned long goal);
94void *___alloc_bootmem_node_nopanic(pg_data_t *pgdat,
95 unsigned long size,
96 unsigned long align,
97 unsigned long goal,
98 unsigned long limit);
94extern void *__alloc_bootmem_low(unsigned long size, 99extern void *__alloc_bootmem_low(unsigned long size,
95 unsigned long align, 100 unsigned long align,
96 unsigned long goal); 101 unsigned long goal);
diff --git a/include/linux/gpio.h b/include/linux/gpio.h
index f07fc2d08159..2e31e8b3a190 100644
--- a/include/linux/gpio.h
+++ b/include/linux/gpio.h
@@ -22,8 +22,8 @@
22/* Gpio pin is open source */ 22/* Gpio pin is open source */
23#define GPIOF_OPEN_SOURCE (1 << 3) 23#define GPIOF_OPEN_SOURCE (1 << 3)
24 24
25#define GPIOF_EXPORT (1 << 2) 25#define GPIOF_EXPORT (1 << 4)
26#define GPIOF_EXPORT_CHANGEABLE (1 << 3) 26#define GPIOF_EXPORT_CHANGEABLE (1 << 5)
27#define GPIOF_EXPORT_DIR_FIXED (GPIOF_EXPORT) 27#define GPIOF_EXPORT_DIR_FIXED (GPIOF_EXPORT)
28#define GPIOF_EXPORT_DIR_CHANGEABLE (GPIOF_EXPORT | GPIOF_EXPORT_CHANGEABLE) 28#define GPIOF_EXPORT_DIR_CHANGEABLE (GPIOF_EXPORT | GPIOF_EXPORT_CHANGEABLE)
29 29
diff --git a/include/linux/hrtimer.h b/include/linux/hrtimer.h
index fd0dc30c9f15..cc07d2777bbe 100644
--- a/include/linux/hrtimer.h
+++ b/include/linux/hrtimer.h
@@ -165,6 +165,7 @@ enum hrtimer_base_type {
165 * @lock: lock protecting the base and associated clock bases 165 * @lock: lock protecting the base and associated clock bases
166 * and timers 166 * and timers
167 * @active_bases: Bitfield to mark bases with active timers 167 * @active_bases: Bitfield to mark bases with active timers
168 * @clock_was_set: Indicates that clock was set from irq context.
168 * @expires_next: absolute time of the next event which was scheduled 169 * @expires_next: absolute time of the next event which was scheduled
169 * via clock_set_next_event() 170 * via clock_set_next_event()
170 * @hres_active: State of high resolution mode 171 * @hres_active: State of high resolution mode
@@ -177,7 +178,8 @@ enum hrtimer_base_type {
177 */ 178 */
178struct hrtimer_cpu_base { 179struct hrtimer_cpu_base {
179 raw_spinlock_t lock; 180 raw_spinlock_t lock;
180 unsigned long active_bases; 181 unsigned int active_bases;
182 unsigned int clock_was_set;
181#ifdef CONFIG_HIGH_RES_TIMERS 183#ifdef CONFIG_HIGH_RES_TIMERS
182 ktime_t expires_next; 184 ktime_t expires_next;
183 int hres_active; 185 int hres_active;
@@ -286,6 +288,8 @@ extern void hrtimer_peek_ahead_timers(void);
286# define MONOTONIC_RES_NSEC HIGH_RES_NSEC 288# define MONOTONIC_RES_NSEC HIGH_RES_NSEC
287# define KTIME_MONOTONIC_RES KTIME_HIGH_RES 289# define KTIME_MONOTONIC_RES KTIME_HIGH_RES
288 290
291extern void clock_was_set_delayed(void);
292
289#else 293#else
290 294
291# define MONOTONIC_RES_NSEC LOW_RES_NSEC 295# define MONOTONIC_RES_NSEC LOW_RES_NSEC
@@ -306,6 +310,9 @@ static inline int hrtimer_is_hres_active(struct hrtimer *timer)
306{ 310{
307 return 0; 311 return 0;
308} 312}
313
314static inline void clock_was_set_delayed(void) { }
315
309#endif 316#endif
310 317
311extern void clock_was_set(void); 318extern void clock_was_set(void);
@@ -320,6 +327,7 @@ extern ktime_t ktime_get(void);
320extern ktime_t ktime_get_real(void); 327extern ktime_t ktime_get_real(void);
321extern ktime_t ktime_get_boottime(void); 328extern ktime_t ktime_get_boottime(void);
322extern ktime_t ktime_get_monotonic_offset(void); 329extern ktime_t ktime_get_monotonic_offset(void);
330extern ktime_t ktime_get_update_offsets(ktime_t *offs_real, ktime_t *offs_boot);
323 331
324DECLARE_PER_CPU(struct tick_device, tick_cpu_device); 332DECLARE_PER_CPU(struct tick_device, tick_cpu_device);
325 333
diff --git a/include/linux/input.h b/include/linux/input.h
index a81671453575..2740d080ec6b 100644
--- a/include/linux/input.h
+++ b/include/linux/input.h
@@ -116,6 +116,7 @@ struct input_keymap_entry {
116 116
117/** 117/**
118 * EVIOCGMTSLOTS(len) - get MT slot values 118 * EVIOCGMTSLOTS(len) - get MT slot values
119 * @len: size of the data buffer in bytes
119 * 120 *
120 * The ioctl buffer argument should be binary equivalent to 121 * The ioctl buffer argument should be binary equivalent to
121 * 122 *
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index c4464356b35b..96c158a37d3e 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -815,7 +815,7 @@ static inline void kvm_free_irq_routing(struct kvm *kvm) {}
815#ifdef CONFIG_HAVE_KVM_EVENTFD 815#ifdef CONFIG_HAVE_KVM_EVENTFD
816 816
817void kvm_eventfd_init(struct kvm *kvm); 817void kvm_eventfd_init(struct kvm *kvm);
818int kvm_irqfd(struct kvm *kvm, int fd, int gsi, int flags); 818int kvm_irqfd(struct kvm *kvm, struct kvm_irqfd *args);
819void kvm_irqfd_release(struct kvm *kvm); 819void kvm_irqfd_release(struct kvm *kvm);
820void kvm_irq_routing_update(struct kvm *, struct kvm_irq_routing_table *); 820void kvm_irq_routing_update(struct kvm *, struct kvm_irq_routing_table *);
821int kvm_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args); 821int kvm_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args);
@@ -824,7 +824,7 @@ int kvm_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args);
824 824
825static inline void kvm_eventfd_init(struct kvm *kvm) {} 825static inline void kvm_eventfd_init(struct kvm *kvm) {}
826 826
827static inline int kvm_irqfd(struct kvm *kvm, int fd, int gsi, int flags) 827static inline int kvm_irqfd(struct kvm *kvm, struct kvm_irqfd *args)
828{ 828{
829 return -EINVAL; 829 return -EINVAL;
830} 830}
diff --git a/include/linux/memblock.h b/include/linux/memblock.h
index a6bb10235148..19dc455b4f3d 100644
--- a/include/linux/memblock.h
+++ b/include/linux/memblock.h
@@ -50,9 +50,7 @@ phys_addr_t memblock_find_in_range_node(phys_addr_t start, phys_addr_t end,
50 phys_addr_t size, phys_addr_t align, int nid); 50 phys_addr_t size, phys_addr_t align, int nid);
51phys_addr_t memblock_find_in_range(phys_addr_t start, phys_addr_t end, 51phys_addr_t memblock_find_in_range(phys_addr_t start, phys_addr_t end,
52 phys_addr_t size, phys_addr_t align); 52 phys_addr_t size, phys_addr_t align);
53int memblock_free_reserved_regions(void); 53phys_addr_t get_allocated_memblock_reserved_regions_info(phys_addr_t *addr);
54int memblock_reserve_reserved_regions(void);
55
56void memblock_allow_resize(void); 54void memblock_allow_resize(void);
57int memblock_add_node(phys_addr_t base, phys_addr_t size, int nid); 55int memblock_add_node(phys_addr_t base, phys_addr_t size, int nid);
58int memblock_add(phys_addr_t base, phys_addr_t size); 56int memblock_add(phys_addr_t base, phys_addr_t size);
diff --git a/include/linux/mfd/s5m87xx/s5m-core.h b/include/linux/mfd/s5m87xx/s5m-core.h
index 21603b42f22f..0b2e0ed309f5 100644
--- a/include/linux/mfd/s5m87xx/s5m-core.h
+++ b/include/linux/mfd/s5m87xx/s5m-core.h
@@ -347,6 +347,7 @@ struct s5m_platform_data {
347 bool buck_voltage_lock; 347 bool buck_voltage_lock;
348 348
349 int buck_gpios[3]; 349 int buck_gpios[3];
350 int buck_ds[3];
350 int buck2_voltage[8]; 351 int buck2_voltage[8];
351 bool buck2_gpiodvs; 352 bool buck2_gpiodvs;
352 int buck3_voltage[8]; 353 int buck3_voltage[8];
@@ -369,6 +370,10 @@ struct s5m_platform_data {
369 bool buck2_ramp_enable; 370 bool buck2_ramp_enable;
370 bool buck3_ramp_enable; 371 bool buck3_ramp_enable;
371 bool buck4_ramp_enable; 372 bool buck4_ramp_enable;
373
374 int buck2_init;
375 int buck3_init;
376 int buck4_init;
372}; 377};
373 378
374#endif /* __LINUX_MFD_S5M_CORE_H */ 379#endif /* __LINUX_MFD_S5M_CORE_H */
diff --git a/include/linux/mfd/tps65217.h b/include/linux/mfd/tps65217.h
index e030ef9a64ee..12c06870829a 100644
--- a/include/linux/mfd/tps65217.h
+++ b/include/linux/mfd/tps65217.h
@@ -217,7 +217,8 @@ enum tps65217_regulator_id {
217 * Board data may be used to initialize regulator. 217 * Board data may be used to initialize regulator.
218 */ 218 */
219struct tps65217_board { 219struct tps65217_board {
220 struct regulator_init_data *tps65217_init_data; 220 struct regulator_init_data *tps65217_init_data[TPS65217_NUM_REGULATOR];
221 struct device_node *of_node[TPS65217_NUM_REGULATOR];
221}; 222};
222 223
223/** 224/**
@@ -227,11 +228,6 @@ struct tps65217_board {
227 * @max_uV: minimum micro volts 228 * @max_uV: minimum micro volts
228 * @vsel_to_uv: Function pointer to get voltage from selector 229 * @vsel_to_uv: Function pointer to get voltage from selector
229 * @uv_to_vsel: Function pointer to get selector from voltage 230 * @uv_to_vsel: Function pointer to get selector from voltage
230 * @table: Table for non-uniform voltage step-size
231 * @table_len: Length of the voltage table
232 * @enable_mask: Regulator enable mask bits
233 * @set_vout_reg: Regulator output voltage set register
234 * @set_vout_mask: Regulator output voltage set mask
235 * 231 *
236 * This data is used to check the regualtor voltage limits while setting. 232 * This data is used to check the regualtor voltage limits while setting.
237 */ 233 */
@@ -241,11 +237,6 @@ struct tps_info {
241 int max_uV; 237 int max_uV;
242 int (*vsel_to_uv)(unsigned int vsel); 238 int (*vsel_to_uv)(unsigned int vsel);
243 int (*uv_to_vsel)(int uV, unsigned int *vsel); 239 int (*uv_to_vsel)(int uV, unsigned int *vsel);
244 const int *table;
245 unsigned int table_len;
246 unsigned int enable_mask;
247 unsigned int set_vout_reg;
248 unsigned int set_vout_mask;
249}; 240};
250 241
251/** 242/**
diff --git a/include/linux/mfd/tps65910.h b/include/linux/mfd/tps65910.h
index dd8dc0a6c462..6c4c478e21a4 100644
--- a/include/linux/mfd/tps65910.h
+++ b/include/linux/mfd/tps65910.h
@@ -880,4 +880,10 @@ static inline int tps65910_reg_clear_bits(struct tps65910 *tps65910, u8 reg,
880 return regmap_update_bits(tps65910->regmap, reg, mask, 0); 880 return regmap_update_bits(tps65910->regmap, reg, mask, 0);
881} 881}
882 882
883static inline int tps65910_reg_update_bits(struct tps65910 *tps65910, u8 reg,
884 u8 mask, u8 val)
885{
886 return regmap_update_bits(tps65910->regmap, reg, mask, val);
887}
888
883#endif /* __LINUX_MFD_TPS65910_H */ 889#endif /* __LINUX_MFD_TPS65910_H */
diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index 2427706f78b4..68c569fcbb66 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -694,7 +694,7 @@ typedef struct pglist_data {
694 range, including holes */ 694 range, including holes */
695 int node_id; 695 int node_id;
696 wait_queue_head_t kswapd_wait; 696 wait_queue_head_t kswapd_wait;
697 struct task_struct *kswapd; 697 struct task_struct *kswapd; /* Protected by lock_memory_hotplug() */
698 int kswapd_max_order; 698 int kswapd_max_order;
699 enum zone_type classzone_idx; 699 enum zone_type classzone_idx;
700} pg_data_t; 700} pg_data_t;
diff --git a/include/linux/pci.h b/include/linux/pci.h
index fefb4e19bf6a..d8c379dba6ad 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -176,8 +176,6 @@ enum pci_dev_flags {
176 PCI_DEV_FLAGS_NO_D3 = (__force pci_dev_flags_t) 2, 176 PCI_DEV_FLAGS_NO_D3 = (__force pci_dev_flags_t) 2,
177 /* Provide indication device is assigned by a Virtual Machine Manager */ 177 /* Provide indication device is assigned by a Virtual Machine Manager */
178 PCI_DEV_FLAGS_ASSIGNED = (__force pci_dev_flags_t) 4, 178 PCI_DEV_FLAGS_ASSIGNED = (__force pci_dev_flags_t) 4,
179 /* Device causes system crash if in D3 during S3 sleep */
180 PCI_DEV_FLAGS_NO_D3_DURING_SLEEP = (__force pci_dev_flags_t) 8,
181}; 179};
182 180
183enum pci_irq_reroute_variant { 181enum pci_irq_reroute_variant {
diff --git a/include/linux/prctl.h b/include/linux/prctl.h
index 3988012255dc..289760f424aa 100644
--- a/include/linux/prctl.h
+++ b/include/linux/prctl.h
@@ -141,6 +141,8 @@
141 * Changing LSM security domain is considered a new privilege. So, for example, 141 * Changing LSM security domain is considered a new privilege. So, for example,
142 * asking selinux for a specific new context (e.g. with runcon) will result 142 * asking selinux for a specific new context (e.g. with runcon) will result
143 * in execve returning -EPERM. 143 * in execve returning -EPERM.
144 *
145 * See Documentation/prctl/no_new_privs.txt for more details.
144 */ 146 */
145#define PR_SET_NO_NEW_PRIVS 38 147#define PR_SET_NO_NEW_PRIVS 38
146#define PR_GET_NO_NEW_PRIVS 39 148#define PR_GET_NO_NEW_PRIVS 39
diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
index 26d1a47591f1..9cac722b169c 100644
--- a/include/linux/rcupdate.h
+++ b/include/linux/rcupdate.h
@@ -184,7 +184,6 @@ static inline int rcu_preempt_depth(void)
184/* Internal to kernel */ 184/* Internal to kernel */
185extern void rcu_sched_qs(int cpu); 185extern void rcu_sched_qs(int cpu);
186extern void rcu_bh_qs(int cpu); 186extern void rcu_bh_qs(int cpu);
187extern void rcu_preempt_note_context_switch(void);
188extern void rcu_check_callbacks(int cpu, int user); 187extern void rcu_check_callbacks(int cpu, int user);
189struct notifier_block; 188struct notifier_block;
190extern void rcu_idle_enter(void); 189extern void rcu_idle_enter(void);
diff --git a/include/linux/rcutiny.h b/include/linux/rcutiny.h
index 854dc4c5c271..4e56a9c69a35 100644
--- a/include/linux/rcutiny.h
+++ b/include/linux/rcutiny.h
@@ -87,6 +87,10 @@ static inline void kfree_call_rcu(struct rcu_head *head,
87 87
88#ifdef CONFIG_TINY_RCU 88#ifdef CONFIG_TINY_RCU
89 89
90static inline void rcu_preempt_note_context_switch(void)
91{
92}
93
90static inline int rcu_needs_cpu(int cpu, unsigned long *delta_jiffies) 94static inline int rcu_needs_cpu(int cpu, unsigned long *delta_jiffies)
91{ 95{
92 *delta_jiffies = ULONG_MAX; 96 *delta_jiffies = ULONG_MAX;
@@ -95,6 +99,7 @@ static inline int rcu_needs_cpu(int cpu, unsigned long *delta_jiffies)
95 99
96#else /* #ifdef CONFIG_TINY_RCU */ 100#else /* #ifdef CONFIG_TINY_RCU */
97 101
102void rcu_preempt_note_context_switch(void);
98int rcu_preempt_needs_cpu(void); 103int rcu_preempt_needs_cpu(void);
99 104
100static inline int rcu_needs_cpu(int cpu, unsigned long *delta_jiffies) 105static inline int rcu_needs_cpu(int cpu, unsigned long *delta_jiffies)
@@ -108,6 +113,7 @@ static inline int rcu_needs_cpu(int cpu, unsigned long *delta_jiffies)
108static inline void rcu_note_context_switch(int cpu) 113static inline void rcu_note_context_switch(int cpu)
109{ 114{
110 rcu_sched_qs(cpu); 115 rcu_sched_qs(cpu);
116 rcu_preempt_note_context_switch();
111} 117}
112 118
113/* 119/*
diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h
index 2513a54ca2e8..bac4c871f3bd 100644
--- a/include/linux/regulator/driver.h
+++ b/include/linux/regulator/driver.h
@@ -69,6 +69,8 @@ enum regulator_status {
69 * 69 *
70 * @enable_time: Time taken for the regulator voltage output voltage to 70 * @enable_time: Time taken for the regulator voltage output voltage to
71 * stabilise after being enabled, in microseconds. 71 * stabilise after being enabled, in microseconds.
72 * @set_ramp_delay: Set the ramp delay for the regulator. The driver should
73 * select ramp delay equal to or less than(closest) ramp_delay.
72 * @set_voltage_time_sel: Time taken for the regulator voltage output voltage 74 * @set_voltage_time_sel: Time taken for the regulator voltage output voltage
73 * to stabilise after being set to a new value, in microseconds. 75 * to stabilise after being set to a new value, in microseconds.
74 * The function provides the from and to voltage selector, the 76 * The function provides the from and to voltage selector, the
@@ -115,6 +117,7 @@ struct regulator_ops {
115 117
116 /* Time taken to enable or set voltage on the regulator */ 118 /* Time taken to enable or set voltage on the regulator */
117 int (*enable_time) (struct regulator_dev *); 119 int (*enable_time) (struct regulator_dev *);
120 int (*set_ramp_delay) (struct regulator_dev *, int ramp_delay);
118 int (*set_voltage_time_sel) (struct regulator_dev *, 121 int (*set_voltage_time_sel) (struct regulator_dev *,
119 unsigned int old_selector, 122 unsigned int old_selector,
120 unsigned int new_selector); 123 unsigned int new_selector);
@@ -172,12 +175,15 @@ enum regulator_type {
172 * 175 *
173 * @min_uV: Voltage given by the lowest selector (if linear mapping) 176 * @min_uV: Voltage given by the lowest selector (if linear mapping)
174 * @uV_step: Voltage increase with each selector (if linear mapping) 177 * @uV_step: Voltage increase with each selector (if linear mapping)
178 * @ramp_delay: Time to settle down after voltage change (unit: uV/us)
175 * @volt_table: Voltage mapping table (if table based mapping) 179 * @volt_table: Voltage mapping table (if table based mapping)
176 * 180 *
177 * @vsel_reg: Register for selector when using regulator_regmap_X_voltage_ 181 * @vsel_reg: Register for selector when using regulator_regmap_X_voltage_
178 * @vsel_mask: Mask for register bitfield used for selector 182 * @vsel_mask: Mask for register bitfield used for selector
179 * @enable_reg: Register for control when using regmap enable/disable ops 183 * @enable_reg: Register for control when using regmap enable/disable ops
180 * @enable_mask: Mask for control when using regmap enable/disable ops 184 * @enable_mask: Mask for control when using regmap enable/disable ops
185 *
186 * @enable_time: Time taken for initial enable of regulator (in uS).
181 */ 187 */
182struct regulator_desc { 188struct regulator_desc {
183 const char *name; 189 const char *name;
@@ -191,6 +197,7 @@ struct regulator_desc {
191 197
192 unsigned int min_uV; 198 unsigned int min_uV;
193 unsigned int uV_step; 199 unsigned int uV_step;
200 unsigned int ramp_delay;
194 201
195 const unsigned int *volt_table; 202 const unsigned int *volt_table;
196 203
@@ -198,6 +205,8 @@ struct regulator_desc {
198 unsigned int vsel_mask; 205 unsigned int vsel_mask;
199 unsigned int enable_reg; 206 unsigned int enable_reg;
200 unsigned int enable_mask; 207 unsigned int enable_mask;
208
209 unsigned int enable_time;
201}; 210};
202 211
203/** 212/**
@@ -213,6 +222,9 @@ struct regulator_desc {
213 * @of_node: OpenFirmware node to parse for device tree bindings (may be 222 * @of_node: OpenFirmware node to parse for device tree bindings (may be
214 * NULL). 223 * NULL).
215 * @regmap: regmap to use for core regmap helpers 224 * @regmap: regmap to use for core regmap helpers
225 * @ena_gpio: GPIO controlling regulator enable.
226 * @ena_gpio_invert: Sense for GPIO enable control.
227 * @ena_gpio_flags: Flags to use when calling gpio_request_one()
216 */ 228 */
217struct regulator_config { 229struct regulator_config {
218 struct device *dev; 230 struct device *dev;
@@ -220,6 +232,10 @@ struct regulator_config {
220 void *driver_data; 232 void *driver_data;
221 struct device_node *of_node; 233 struct device_node *of_node;
222 struct regmap *regmap; 234 struct regmap *regmap;
235
236 int ena_gpio;
237 unsigned int ena_gpio_invert:1;
238 unsigned int ena_gpio_flags;
223}; 239};
224 240
225/* 241/*
@@ -258,6 +274,10 @@ struct regulator_dev {
258 void *reg_data; /* regulator_dev data */ 274 void *reg_data; /* regulator_dev data */
259 275
260 struct dentry *debugfs; 276 struct dentry *debugfs;
277
278 int ena_gpio;
279 unsigned int ena_gpio_invert:1;
280 unsigned int ena_gpio_state:1;
261}; 281};
262 282
263struct regulator_dev * 283struct regulator_dev *
@@ -287,6 +307,9 @@ int regulator_set_voltage_sel_regmap(struct regulator_dev *rdev, unsigned sel);
287int regulator_is_enabled_regmap(struct regulator_dev *rdev); 307int regulator_is_enabled_regmap(struct regulator_dev *rdev);
288int regulator_enable_regmap(struct regulator_dev *rdev); 308int regulator_enable_regmap(struct regulator_dev *rdev);
289int regulator_disable_regmap(struct regulator_dev *rdev); 309int regulator_disable_regmap(struct regulator_dev *rdev);
310int regulator_set_voltage_time_sel(struct regulator_dev *rdev,
311 unsigned int old_selector,
312 unsigned int new_selector);
290 313
291void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data); 314void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data);
292 315
diff --git a/include/linux/regulator/fixed.h b/include/linux/regulator/fixed.h
index 680f24e08af2..48918be649d4 100644
--- a/include/linux/regulator/fixed.h
+++ b/include/linux/regulator/fixed.h
@@ -22,6 +22,7 @@ struct regulator_init_data;
22/** 22/**
23 * struct fixed_voltage_config - fixed_voltage_config structure 23 * struct fixed_voltage_config - fixed_voltage_config structure
24 * @supply_name: Name of the regulator supply 24 * @supply_name: Name of the regulator supply
25 * @input_supply: Name of the input regulator supply
25 * @microvolts: Output voltage of regulator 26 * @microvolts: Output voltage of regulator
26 * @gpio: GPIO to use for enable control 27 * @gpio: GPIO to use for enable control
27 * set to -EINVAL if not used 28 * set to -EINVAL if not used
@@ -46,6 +47,7 @@ struct regulator_init_data;
46 */ 47 */
47struct fixed_voltage_config { 48struct fixed_voltage_config {
48 const char *supply_name; 49 const char *supply_name;
50 const char *input_supply;
49 int microvolts; 51 int microvolts;
50 int gpio; 52 int gpio;
51 unsigned startup_delay; 53 unsigned startup_delay;
diff --git a/include/linux/regulator/lp872x.h b/include/linux/regulator/lp872x.h
new file mode 100644
index 000000000000..132e05c46661
--- /dev/null
+++ b/include/linux/regulator/lp872x.h
@@ -0,0 +1,90 @@
1/*
2 * Copyright 2012 Texas Instruments
3 *
4 * Author: Milo(Woogyom) Kim <milo.kim@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
12#ifndef __LP872X_REGULATOR_H__
13#define __LP872X_REGULATOR_H__
14
15#include <linux/regulator/machine.h>
16#include <linux/platform_device.h>
17#include <linux/gpio.h>
18
19#define LP872X_MAX_REGULATORS 9
20
21enum lp872x_regulator_id {
22 LP8720_ID_BASE,
23 LP8720_ID_LDO1 = LP8720_ID_BASE,
24 LP8720_ID_LDO2,
25 LP8720_ID_LDO3,
26 LP8720_ID_LDO4,
27 LP8720_ID_LDO5,
28 LP8720_ID_BUCK,
29
30 LP8725_ID_BASE,
31 LP8725_ID_LDO1 = LP8725_ID_BASE,
32 LP8725_ID_LDO2,
33 LP8725_ID_LDO3,
34 LP8725_ID_LDO4,
35 LP8725_ID_LDO5,
36 LP8725_ID_LILO1,
37 LP8725_ID_LILO2,
38 LP8725_ID_BUCK1,
39 LP8725_ID_BUCK2,
40
41 LP872X_ID_MAX,
42};
43
44enum lp872x_dvs_state {
45 DVS_LOW = GPIOF_OUT_INIT_LOW,
46 DVS_HIGH = GPIOF_OUT_INIT_HIGH,
47};
48
49enum lp872x_dvs_sel {
50 SEL_V1,
51 SEL_V2,
52};
53
54/**
55 * lp872x_dvs
56 * @gpio : gpio pin number for dvs control
57 * @vsel : dvs selector for buck v1 or buck v2 register
58 * @init_state : initial dvs pin state
59 */
60struct lp872x_dvs {
61 int gpio;
62 enum lp872x_dvs_sel vsel;
63 enum lp872x_dvs_state init_state;
64};
65
66/**
67 * lp872x_regdata
68 * @id : regulator id
69 * @init_data : init data for each regulator
70 */
71struct lp872x_regulator_data {
72 enum lp872x_regulator_id id;
73 struct regulator_init_data *init_data;
74};
75
76/**
77 * lp872x_platform_data
78 * @general_config : the value of LP872X_GENERAL_CFG register
79 * @update_config : if LP872X_GENERAL_CFG register is updated, set true
80 * @regulator_data : platform regulator id and init data
81 * @dvs : dvs data for buck voltage control
82 */
83struct lp872x_platform_data {
84 u8 general_config;
85 bool update_config;
86 struct lp872x_regulator_data regulator_data[LP872X_MAX_REGULATORS];
87 struct lp872x_dvs *dvs;
88};
89
90#endif
diff --git a/include/linux/regulator/machine.h b/include/linux/regulator/machine.h
index b02108446be7..40dd0a394cfa 100644
--- a/include/linux/regulator/machine.h
+++ b/include/linux/regulator/machine.h
@@ -92,6 +92,7 @@ struct regulator_state {
92 * mode. 92 * mode.
93 * @initial_state: Suspend state to set by default. 93 * @initial_state: Suspend state to set by default.
94 * @initial_mode: Mode to set at startup. 94 * @initial_mode: Mode to set at startup.
95 * @ramp_delay: Time to settle down after voltage change (unit: uV/us)
95 */ 96 */
96struct regulation_constraints { 97struct regulation_constraints {
97 98
@@ -125,6 +126,8 @@ struct regulation_constraints {
125 /* mode to set on startup */ 126 /* mode to set on startup */
126 unsigned int initial_mode; 127 unsigned int initial_mode;
127 128
129 unsigned int ramp_delay;
130
128 /* constraint flags */ 131 /* constraint flags */
129 unsigned always_on:1; /* regulator never off when system is on */ 132 unsigned always_on:1; /* regulator never off when system is on */
130 unsigned boot_on:1; /* bootloader/firmware enabled regulator */ 133 unsigned boot_on:1; /* bootloader/firmware enabled regulator */
diff --git a/include/linux/rpmsg.h b/include/linux/rpmsg.h
index a8e50e44203c..82a673905edb 100644
--- a/include/linux/rpmsg.h
+++ b/include/linux/rpmsg.h
@@ -38,6 +38,8 @@
38#include <linux/types.h> 38#include <linux/types.h>
39#include <linux/device.h> 39#include <linux/device.h>
40#include <linux/mod_devicetable.h> 40#include <linux/mod_devicetable.h>
41#include <linux/kref.h>
42#include <linux/mutex.h>
41 43
42/* The feature bitmap for virtio rpmsg */ 44/* The feature bitmap for virtio rpmsg */
43#define VIRTIO_RPMSG_F_NS 0 /* RP supports name service notifications */ 45#define VIRTIO_RPMSG_F_NS 0 /* RP supports name service notifications */
@@ -120,7 +122,9 @@ typedef void (*rpmsg_rx_cb_t)(struct rpmsg_channel *, void *, int, void *, u32);
120/** 122/**
121 * struct rpmsg_endpoint - binds a local rpmsg address to its user 123 * struct rpmsg_endpoint - binds a local rpmsg address to its user
122 * @rpdev: rpmsg channel device 124 * @rpdev: rpmsg channel device
125 * @refcount: when this drops to zero, the ept is deallocated
123 * @cb: rx callback handler 126 * @cb: rx callback handler
127 * @cb_lock: must be taken before accessing/changing @cb
124 * @addr: local rpmsg address 128 * @addr: local rpmsg address
125 * @priv: private data for the driver's use 129 * @priv: private data for the driver's use
126 * 130 *
@@ -140,7 +144,9 @@ typedef void (*rpmsg_rx_cb_t)(struct rpmsg_channel *, void *, int, void *, u32);
140 */ 144 */
141struct rpmsg_endpoint { 145struct rpmsg_endpoint {
142 struct rpmsg_channel *rpdev; 146 struct rpmsg_channel *rpdev;
147 struct kref refcount;
143 rpmsg_rx_cb_t cb; 148 rpmsg_rx_cb_t cb;
149 struct mutex cb_lock;
144 u32 addr; 150 u32 addr;
145 void *priv; 151 void *priv;
146}; 152};
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 4059c0f33f07..4a1f493e0fef 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1871,22 +1871,12 @@ static inline void rcu_copy_process(struct task_struct *p)
1871 INIT_LIST_HEAD(&p->rcu_node_entry); 1871 INIT_LIST_HEAD(&p->rcu_node_entry);
1872} 1872}
1873 1873
1874static inline void rcu_switch_from(struct task_struct *prev)
1875{
1876 if (prev->rcu_read_lock_nesting != 0)
1877 rcu_preempt_note_context_switch();
1878}
1879
1880#else 1874#else
1881 1875
1882static inline void rcu_copy_process(struct task_struct *p) 1876static inline void rcu_copy_process(struct task_struct *p)
1883{ 1877{
1884} 1878}
1885 1879
1886static inline void rcu_switch_from(struct task_struct *prev)
1887{
1888}
1889
1890#endif 1880#endif
1891 1881
1892#ifdef CONFIG_SMP 1882#ifdef CONFIG_SMP
@@ -1909,6 +1899,14 @@ static inline int set_cpus_allowed_ptr(struct task_struct *p,
1909} 1899}
1910#endif 1900#endif
1911 1901
1902#ifdef CONFIG_NO_HZ
1903void calc_load_enter_idle(void);
1904void calc_load_exit_idle(void);
1905#else
1906static inline void calc_load_enter_idle(void) { }
1907static inline void calc_load_exit_idle(void) { }
1908#endif /* CONFIG_NO_HZ */
1909
1912#ifndef CONFIG_CPUMASK_OFFSTACK 1910#ifndef CONFIG_CPUMASK_OFFSTACK
1913static inline int set_cpus_allowed(struct task_struct *p, cpumask_t new_mask) 1911static inline int set_cpus_allowed(struct task_struct *p, cpumask_t new_mask)
1914{ 1912{
diff --git a/include/linux/splice.h b/include/linux/splice.h
index 26e5b613deda..09a545a7dfa3 100644
--- a/include/linux/splice.h
+++ b/include/linux/splice.h
@@ -51,7 +51,8 @@ struct partial_page {
51struct splice_pipe_desc { 51struct splice_pipe_desc {
52 struct page **pages; /* page map */ 52 struct page **pages; /* page map */
53 struct partial_page *partial; /* pages[] may not be contig */ 53 struct partial_page *partial; /* pages[] may not be contig */
54 int nr_pages; /* number of pages in map */ 54 int nr_pages; /* number of populated pages in map */
55 unsigned int nr_pages_max; /* pages[] & partial[] arrays size */
55 unsigned int flags; /* splice flags */ 56 unsigned int flags; /* splice flags */
56 const struct pipe_buf_operations *ops;/* ops associated with output pipe */ 57 const struct pipe_buf_operations *ops;/* ops associated with output pipe */
57 void (*spd_release)(struct splice_pipe_desc *, unsigned int); 58 void (*spd_release)(struct splice_pipe_desc *, unsigned int);
@@ -85,9 +86,8 @@ extern ssize_t splice_direct_to_actor(struct file *, struct splice_desc *,
85/* 86/*
86 * for dynamic pipe sizing 87 * for dynamic pipe sizing
87 */ 88 */
88extern int splice_grow_spd(struct pipe_inode_info *, struct splice_pipe_desc *); 89extern int splice_grow_spd(const struct pipe_inode_info *, struct splice_pipe_desc *);
89extern void splice_shrink_spd(struct pipe_inode_info *, 90extern void splice_shrink_spd(struct splice_pipe_desc *);
90 struct splice_pipe_desc *);
91extern void spd_release_page(struct splice_pipe_desc *, unsigned int); 91extern void spd_release_page(struct splice_pipe_desc *, unsigned int);
92 92
93extern const struct pipe_buf_operations page_cache_pipe_buf_ops; 93extern const struct pipe_buf_operations page_cache_pipe_buf_ops;
diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
index e4652fe58958..fecdf31816f2 100644
--- a/include/net/sctp/structs.h
+++ b/include/net/sctp/structs.h
@@ -912,6 +912,9 @@ struct sctp_transport {
912 /* Is this structure kfree()able? */ 912 /* Is this structure kfree()able? */
913 malloced:1; 913 malloced:1;
914 914
915 /* Has this transport moved the ctsn since we last sacked */
916 __u32 sack_generation;
917
915 struct flowi fl; 918 struct flowi fl;
916 919
917 /* This is the peer's IP address and port. */ 920 /* This is the peer's IP address and port. */
@@ -1584,6 +1587,7 @@ struct sctp_association {
1584 */ 1587 */
1585 __u8 sack_needed; /* Do we need to sack the peer? */ 1588 __u8 sack_needed; /* Do we need to sack the peer? */
1586 __u32 sack_cnt; 1589 __u32 sack_cnt;
1590 __u32 sack_generation;
1587 1591
1588 /* These are capabilities which our peer advertised. */ 1592 /* These are capabilities which our peer advertised. */
1589 __u8 ecn_capable:1, /* Can peer do ECN? */ 1593 __u8 ecn_capable:1, /* Can peer do ECN? */
diff --git a/include/net/sctp/tsnmap.h b/include/net/sctp/tsnmap.h
index e7728bc14ccf..2c5d2b4d5d1e 100644
--- a/include/net/sctp/tsnmap.h
+++ b/include/net/sctp/tsnmap.h
@@ -117,7 +117,8 @@ void sctp_tsnmap_free(struct sctp_tsnmap *map);
117int sctp_tsnmap_check(const struct sctp_tsnmap *, __u32 tsn); 117int sctp_tsnmap_check(const struct sctp_tsnmap *, __u32 tsn);
118 118
119/* Mark this TSN as seen. */ 119/* Mark this TSN as seen. */
120int sctp_tsnmap_mark(struct sctp_tsnmap *, __u32 tsn); 120int sctp_tsnmap_mark(struct sctp_tsnmap *, __u32 tsn,
121 struct sctp_transport *trans);
121 122
122/* Mark this TSN and all lower as seen. */ 123/* Mark this TSN and all lower as seen. */
123void sctp_tsnmap_skip(struct sctp_tsnmap *map, __u32 tsn); 124void sctp_tsnmap_skip(struct sctp_tsnmap *map, __u32 tsn);
diff --git a/include/scsi/libsas.h b/include/scsi/libsas.h
index f4f1c96dca72..10ce74f589c5 100644
--- a/include/scsi/libsas.h
+++ b/include/scsi/libsas.h
@@ -163,6 +163,8 @@ enum ata_command_set {
163 ATAPI_COMMAND_SET = 1, 163 ATAPI_COMMAND_SET = 1,
164}; 164};
165 165
166#define ATA_RESP_FIS_SIZE 24
167
166struct sata_device { 168struct sata_device {
167 enum ata_command_set command_set; 169 enum ata_command_set command_set;
168 struct smp_resp rps_resp; /* report_phy_sata_resp */ 170 struct smp_resp rps_resp; /* report_phy_sata_resp */
@@ -171,7 +173,7 @@ struct sata_device {
171 173
172 struct ata_port *ap; 174 struct ata_port *ap;
173 struct ata_host ata_host; 175 struct ata_host ata_host;
174 struct ata_taskfile tf; 176 u8 fis[ATA_RESP_FIS_SIZE];
175}; 177};
176 178
177enum { 179enum {
@@ -537,7 +539,7 @@ enum exec_status {
537 */ 539 */
538struct ata_task_resp { 540struct ata_task_resp {
539 u16 frame_len; 541 u16 frame_len;
540 u8 ending_fis[24]; /* dev to host or data-in */ 542 u8 ending_fis[ATA_RESP_FIS_SIZE]; /* dev to host or data-in */
541}; 543};
542 544
543#define SAS_STATUS_BUF_SIZE 96 545#define SAS_STATUS_BUF_SIZE 96
diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h
index 1e1198546c72..ac06cc595890 100644
--- a/include/scsi/scsi_cmnd.h
+++ b/include/scsi/scsi_cmnd.h
@@ -134,10 +134,16 @@ 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 struct scsi_driver **sdp;
138
137 if (!cmd->request->rq_disk) 139 if (!cmd->request->rq_disk)
138 return NULL; 140 return NULL;
139 141
140 return *(struct scsi_driver **)cmd->request->rq_disk->private_data; 142 sdp = (struct scsi_driver **)cmd->request->rq_disk->private_data;
143 if (!sdp)
144 return NULL;
145
146 return *sdp;
141} 147}
142 148
143extern struct scsi_cmnd *scsi_get_command(struct scsi_device *, gfp_t); 149extern struct scsi_cmnd *scsi_get_command(struct scsi_device *, gfp_t);
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 2097684cf194..b303dfc7dce0 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -901,13 +901,10 @@ static void cgroup_diput(struct dentry *dentry, struct inode *inode)
901 mutex_unlock(&cgroup_mutex); 901 mutex_unlock(&cgroup_mutex);
902 902
903 /* 903 /*
904 * We want to drop the active superblock reference from the 904 * Drop the active superblock reference that we took when we
905 * cgroup creation after all the dentry refs are gone - 905 * created the cgroup
906 * kill_sb gets mighty unhappy otherwise. Mark
907 * dentry->d_fsdata with cgroup_diput() to tell
908 * cgroup_d_release() to call deactivate_super().
909 */ 906 */
910 dentry->d_fsdata = cgroup_diput; 907 deactivate_super(cgrp->root->sb);
911 908
912 /* 909 /*
913 * if we're getting rid of the cgroup, refcount should ensure 910 * if we're getting rid of the cgroup, refcount should ensure
@@ -933,13 +930,6 @@ static int cgroup_delete(const struct dentry *d)
933 return 1; 930 return 1;
934} 931}
935 932
936static void cgroup_d_release(struct dentry *dentry)
937{
938 /* did cgroup_diput() tell me to deactivate super? */
939 if (dentry->d_fsdata == cgroup_diput)
940 deactivate_super(dentry->d_sb);
941}
942
943static void remove_dir(struct dentry *d) 933static void remove_dir(struct dentry *d)
944{ 934{
945 struct dentry *parent = dget(d->d_parent); 935 struct dentry *parent = dget(d->d_parent);
@@ -1547,7 +1537,6 @@ static int cgroup_get_rootdir(struct super_block *sb)
1547 static const struct dentry_operations cgroup_dops = { 1537 static const struct dentry_operations cgroup_dops = {
1548 .d_iput = cgroup_diput, 1538 .d_iput = cgroup_diput,
1549 .d_delete = cgroup_delete, 1539 .d_delete = cgroup_delete,
1550 .d_release = cgroup_d_release,
1551 }; 1540 };
1552 1541
1553 struct inode *inode = 1542 struct inode *inode =
@@ -3894,8 +3883,12 @@ static void css_dput_fn(struct work_struct *work)
3894{ 3883{
3895 struct cgroup_subsys_state *css = 3884 struct cgroup_subsys_state *css =
3896 container_of(work, struct cgroup_subsys_state, dput_work); 3885 container_of(work, struct cgroup_subsys_state, dput_work);
3886 struct dentry *dentry = css->cgroup->dentry;
3887 struct super_block *sb = dentry->d_sb;
3897 3888
3898 dput(css->cgroup->dentry); 3889 atomic_inc(&sb->s_active);
3890 dput(dentry);
3891 deactivate_super(sb);
3899} 3892}
3900 3893
3901static void init_cgroup_css(struct cgroup_subsys_state *css, 3894static void init_cgroup_css(struct cgroup_subsys_state *css,
diff --git a/kernel/fork.c b/kernel/fork.c
index ab5211b9e622..f00e319d8376 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -304,12 +304,17 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
304 } 304 }
305 305
306 err = arch_dup_task_struct(tsk, orig); 306 err = arch_dup_task_struct(tsk, orig);
307 if (err)
308 goto out;
309 307
308 /*
309 * We defer looking at err, because we will need this setup
310 * for the clean up path to work correctly.
311 */
310 tsk->stack = ti; 312 tsk->stack = ti;
311
312 setup_thread_stack(tsk, orig); 313 setup_thread_stack(tsk, orig);
314
315 if (err)
316 goto out;
317
313 clear_user_return_notifier(tsk); 318 clear_user_return_notifier(tsk);
314 clear_tsk_need_resched(tsk); 319 clear_tsk_need_resched(tsk);
315 stackend = end_of_stack(tsk); 320 stackend = end_of_stack(tsk);
diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
index ae34bf51682b..6db7a5ed52b5 100644
--- a/kernel/hrtimer.c
+++ b/kernel/hrtimer.c
@@ -657,6 +657,14 @@ static inline int hrtimer_enqueue_reprogram(struct hrtimer *timer,
657 return 0; 657 return 0;
658} 658}
659 659
660static inline ktime_t hrtimer_update_base(struct hrtimer_cpu_base *base)
661{
662 ktime_t *offs_real = &base->clock_base[HRTIMER_BASE_REALTIME].offset;
663 ktime_t *offs_boot = &base->clock_base[HRTIMER_BASE_BOOTTIME].offset;
664
665 return ktime_get_update_offsets(offs_real, offs_boot);
666}
667
660/* 668/*
661 * Retrigger next event is called after clock was set 669 * Retrigger next event is called after clock was set
662 * 670 *
@@ -665,22 +673,12 @@ static inline int hrtimer_enqueue_reprogram(struct hrtimer *timer,
665static void retrigger_next_event(void *arg) 673static void retrigger_next_event(void *arg)
666{ 674{
667 struct hrtimer_cpu_base *base = &__get_cpu_var(hrtimer_bases); 675 struct hrtimer_cpu_base *base = &__get_cpu_var(hrtimer_bases);
668 struct timespec realtime_offset, xtim, wtm, sleep;
669 676
670 if (!hrtimer_hres_active()) 677 if (!hrtimer_hres_active())
671 return; 678 return;
672 679
673 /* Optimized out for !HIGH_RES */
674 get_xtime_and_monotonic_and_sleep_offset(&xtim, &wtm, &sleep);
675 set_normalized_timespec(&realtime_offset, -wtm.tv_sec, -wtm.tv_nsec);
676
677 /* Adjust CLOCK_REALTIME offset */
678 raw_spin_lock(&base->lock); 680 raw_spin_lock(&base->lock);
679 base->clock_base[HRTIMER_BASE_REALTIME].offset = 681 hrtimer_update_base(base);
680 timespec_to_ktime(realtime_offset);
681 base->clock_base[HRTIMER_BASE_BOOTTIME].offset =
682 timespec_to_ktime(sleep);
683
684 hrtimer_force_reprogram(base, 0); 682 hrtimer_force_reprogram(base, 0);
685 raw_spin_unlock(&base->lock); 683 raw_spin_unlock(&base->lock);
686} 684}
@@ -710,13 +708,25 @@ static int hrtimer_switch_to_hres(void)
710 base->clock_base[i].resolution = KTIME_HIGH_RES; 708 base->clock_base[i].resolution = KTIME_HIGH_RES;
711 709
712 tick_setup_sched_timer(); 710 tick_setup_sched_timer();
713
714 /* "Retrigger" the interrupt to get things going */ 711 /* "Retrigger" the interrupt to get things going */
715 retrigger_next_event(NULL); 712 retrigger_next_event(NULL);
716 local_irq_restore(flags); 713 local_irq_restore(flags);
717 return 1; 714 return 1;
718} 715}
719 716
717/*
718 * Called from timekeeping code to reprogramm the hrtimer interrupt
719 * device. If called from the timer interrupt context we defer it to
720 * softirq context.
721 */
722void clock_was_set_delayed(void)
723{
724 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
725
726 cpu_base->clock_was_set = 1;
727 __raise_softirq_irqoff(HRTIMER_SOFTIRQ);
728}
729
720#else 730#else
721 731
722static inline int hrtimer_hres_active(void) { return 0; } 732static inline int hrtimer_hres_active(void) { return 0; }
@@ -1250,11 +1260,10 @@ void hrtimer_interrupt(struct clock_event_device *dev)
1250 cpu_base->nr_events++; 1260 cpu_base->nr_events++;
1251 dev->next_event.tv64 = KTIME_MAX; 1261 dev->next_event.tv64 = KTIME_MAX;
1252 1262
1253 entry_time = now = ktime_get(); 1263 raw_spin_lock(&cpu_base->lock);
1264 entry_time = now = hrtimer_update_base(cpu_base);
1254retry: 1265retry:
1255 expires_next.tv64 = KTIME_MAX; 1266 expires_next.tv64 = KTIME_MAX;
1256
1257 raw_spin_lock(&cpu_base->lock);
1258 /* 1267 /*
1259 * We set expires_next to KTIME_MAX here with cpu_base->lock 1268 * We set expires_next to KTIME_MAX here with cpu_base->lock
1260 * held to prevent that a timer is enqueued in our queue via 1269 * held to prevent that a timer is enqueued in our queue via
@@ -1330,8 +1339,12 @@ retry:
1330 * We need to prevent that we loop forever in the hrtimer 1339 * We need to prevent that we loop forever in the hrtimer
1331 * interrupt routine. We give it 3 attempts to avoid 1340 * interrupt routine. We give it 3 attempts to avoid
1332 * overreacting on some spurious event. 1341 * overreacting on some spurious event.
1342 *
1343 * Acquire base lock for updating the offsets and retrieving
1344 * the current time.
1333 */ 1345 */
1334 now = ktime_get(); 1346 raw_spin_lock(&cpu_base->lock);
1347 now = hrtimer_update_base(cpu_base);
1335 cpu_base->nr_retries++; 1348 cpu_base->nr_retries++;
1336 if (++retries < 3) 1349 if (++retries < 3)
1337 goto retry; 1350 goto retry;
@@ -1343,6 +1356,7 @@ retry:
1343 */ 1356 */
1344 cpu_base->nr_hangs++; 1357 cpu_base->nr_hangs++;
1345 cpu_base->hang_detected = 1; 1358 cpu_base->hang_detected = 1;
1359 raw_spin_unlock(&cpu_base->lock);
1346 delta = ktime_sub(now, entry_time); 1360 delta = ktime_sub(now, entry_time);
1347 if (delta.tv64 > cpu_base->max_hang_time.tv64) 1361 if (delta.tv64 > cpu_base->max_hang_time.tv64)
1348 cpu_base->max_hang_time = delta; 1362 cpu_base->max_hang_time = delta;
@@ -1395,6 +1409,13 @@ void hrtimer_peek_ahead_timers(void)
1395 1409
1396static void run_hrtimer_softirq(struct softirq_action *h) 1410static void run_hrtimer_softirq(struct softirq_action *h)
1397{ 1411{
1412 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
1413
1414 if (cpu_base->clock_was_set) {
1415 cpu_base->clock_was_set = 0;
1416 clock_was_set();
1417 }
1418
1398 hrtimer_peek_ahead_timers(); 1419 hrtimer_peek_ahead_timers();
1399} 1420}
1400 1421
diff --git a/kernel/printk.c b/kernel/printk.c
index dba18211685e..177fa49357a5 100644
--- a/kernel/printk.c
+++ b/kernel/printk.c
@@ -194,8 +194,10 @@ static int console_may_schedule;
194 */ 194 */
195 195
196enum log_flags { 196enum log_flags {
197 LOG_DEFAULT = 0, 197 LOG_NOCONS = 1, /* already flushed, do not print to console */
198 LOG_NOCONS = 1, /* already flushed, do not print to console */ 198 LOG_NEWLINE = 2, /* text ended with a newline */
199 LOG_PREFIX = 4, /* text started with a prefix */
200 LOG_CONT = 8, /* text is a fragment of a continuation line */
199}; 201};
200 202
201struct log { 203struct log {
@@ -217,6 +219,8 @@ static DEFINE_RAW_SPINLOCK(logbuf_lock);
217/* the next printk record to read by syslog(READ) or /proc/kmsg */ 219/* the next printk record to read by syslog(READ) or /proc/kmsg */
218static u64 syslog_seq; 220static u64 syslog_seq;
219static u32 syslog_idx; 221static u32 syslog_idx;
222static enum log_flags syslog_prev;
223static size_t syslog_partial;
220 224
221/* index and sequence number of the first record stored in the buffer */ 225/* index and sequence number of the first record stored in the buffer */
222static u64 log_first_seq; 226static u64 log_first_seq;
@@ -430,20 +434,20 @@ static ssize_t devkmsg_read(struct file *file, char __user *buf,
430 ret = mutex_lock_interruptible(&user->lock); 434 ret = mutex_lock_interruptible(&user->lock);
431 if (ret) 435 if (ret)
432 return ret; 436 return ret;
433 raw_spin_lock(&logbuf_lock); 437 raw_spin_lock_irq(&logbuf_lock);
434 while (user->seq == log_next_seq) { 438 while (user->seq == log_next_seq) {
435 if (file->f_flags & O_NONBLOCK) { 439 if (file->f_flags & O_NONBLOCK) {
436 ret = -EAGAIN; 440 ret = -EAGAIN;
437 raw_spin_unlock(&logbuf_lock); 441 raw_spin_unlock_irq(&logbuf_lock);
438 goto out; 442 goto out;
439 } 443 }
440 444
441 raw_spin_unlock(&logbuf_lock); 445 raw_spin_unlock_irq(&logbuf_lock);
442 ret = wait_event_interruptible(log_wait, 446 ret = wait_event_interruptible(log_wait,
443 user->seq != log_next_seq); 447 user->seq != log_next_seq);
444 if (ret) 448 if (ret)
445 goto out; 449 goto out;
446 raw_spin_lock(&logbuf_lock); 450 raw_spin_lock_irq(&logbuf_lock);
447 } 451 }
448 452
449 if (user->seq < log_first_seq) { 453 if (user->seq < log_first_seq) {
@@ -451,7 +455,7 @@ static ssize_t devkmsg_read(struct file *file, char __user *buf,
451 user->idx = log_first_idx; 455 user->idx = log_first_idx;
452 user->seq = log_first_seq; 456 user->seq = log_first_seq;
453 ret = -EPIPE; 457 ret = -EPIPE;
454 raw_spin_unlock(&logbuf_lock); 458 raw_spin_unlock_irq(&logbuf_lock);
455 goto out; 459 goto out;
456 } 460 }
457 461
@@ -465,7 +469,7 @@ static ssize_t devkmsg_read(struct file *file, char __user *buf,
465 for (i = 0; i < msg->text_len; i++) { 469 for (i = 0; i < msg->text_len; i++) {
466 unsigned char c = log_text(msg)[i]; 470 unsigned char c = log_text(msg)[i];
467 471
468 if (c < ' ' || c >= 128) 472 if (c < ' ' || c >= 127 || c == '\\')
469 len += sprintf(user->buf + len, "\\x%02x", c); 473 len += sprintf(user->buf + len, "\\x%02x", c);
470 else 474 else
471 user->buf[len++] = c; 475 user->buf[len++] = c;
@@ -489,7 +493,7 @@ static ssize_t devkmsg_read(struct file *file, char __user *buf,
489 continue; 493 continue;
490 } 494 }
491 495
492 if (c < ' ' || c >= 128) { 496 if (c < ' ' || c >= 127 || c == '\\') {
493 len += sprintf(user->buf + len, "\\x%02x", c); 497 len += sprintf(user->buf + len, "\\x%02x", c);
494 continue; 498 continue;
495 } 499 }
@@ -501,7 +505,7 @@ static ssize_t devkmsg_read(struct file *file, char __user *buf,
501 505
502 user->idx = log_next(user->idx); 506 user->idx = log_next(user->idx);
503 user->seq++; 507 user->seq++;
504 raw_spin_unlock(&logbuf_lock); 508 raw_spin_unlock_irq(&logbuf_lock);
505 509
506 if (len > count) { 510 if (len > count) {
507 ret = -EINVAL; 511 ret = -EINVAL;
@@ -528,7 +532,7 @@ static loff_t devkmsg_llseek(struct file *file, loff_t offset, int whence)
528 if (offset) 532 if (offset)
529 return -ESPIPE; 533 return -ESPIPE;
530 534
531 raw_spin_lock(&logbuf_lock); 535 raw_spin_lock_irq(&logbuf_lock);
532 switch (whence) { 536 switch (whence) {
533 case SEEK_SET: 537 case SEEK_SET:
534 /* the first record */ 538 /* the first record */
@@ -552,7 +556,7 @@ static loff_t devkmsg_llseek(struct file *file, loff_t offset, int whence)
552 default: 556 default:
553 ret = -EINVAL; 557 ret = -EINVAL;
554 } 558 }
555 raw_spin_unlock(&logbuf_lock); 559 raw_spin_unlock_irq(&logbuf_lock);
556 return ret; 560 return ret;
557} 561}
558 562
@@ -566,14 +570,14 @@ static unsigned int devkmsg_poll(struct file *file, poll_table *wait)
566 570
567 poll_wait(file, &log_wait, wait); 571 poll_wait(file, &log_wait, wait);
568 572
569 raw_spin_lock(&logbuf_lock); 573 raw_spin_lock_irq(&logbuf_lock);
570 if (user->seq < log_next_seq) { 574 if (user->seq < log_next_seq) {
571 /* return error when data has vanished underneath us */ 575 /* return error when data has vanished underneath us */
572 if (user->seq < log_first_seq) 576 if (user->seq < log_first_seq)
573 ret = POLLIN|POLLRDNORM|POLLERR|POLLPRI; 577 ret = POLLIN|POLLRDNORM|POLLERR|POLLPRI;
574 ret = POLLIN|POLLRDNORM; 578 ret = POLLIN|POLLRDNORM;
575 } 579 }
576 raw_spin_unlock(&logbuf_lock); 580 raw_spin_unlock_irq(&logbuf_lock);
577 581
578 return ret; 582 return ret;
579} 583}
@@ -597,10 +601,10 @@ static int devkmsg_open(struct inode *inode, struct file *file)
597 601
598 mutex_init(&user->lock); 602 mutex_init(&user->lock);
599 603
600 raw_spin_lock(&logbuf_lock); 604 raw_spin_lock_irq(&logbuf_lock);
601 user->idx = log_first_idx; 605 user->idx = log_first_idx;
602 user->seq = log_first_seq; 606 user->seq = log_first_seq;
603 raw_spin_unlock(&logbuf_lock); 607 raw_spin_unlock_irq(&logbuf_lock);
604 608
605 file->private_data = user; 609 file->private_data = user;
606 return 0; 610 return 0;
@@ -818,15 +822,18 @@ static size_t print_time(u64 ts, char *buf)
818static size_t print_prefix(const struct log *msg, bool syslog, char *buf) 822static size_t print_prefix(const struct log *msg, bool syslog, char *buf)
819{ 823{
820 size_t len = 0; 824 size_t len = 0;
825 unsigned int prefix = (msg->facility << 3) | msg->level;
821 826
822 if (syslog) { 827 if (syslog) {
823 if (buf) { 828 if (buf) {
824 len += sprintf(buf, "<%u>", msg->level); 829 len += sprintf(buf, "<%u>", prefix);
825 } else { 830 } else {
826 len += 3; 831 len += 3;
827 if (msg->level > 9) 832 if (prefix > 999)
828 len++; 833 len += 3;
829 if (msg->level > 99) 834 else if (prefix > 99)
835 len += 2;
836 else if (prefix > 9)
830 len++; 837 len++;
831 } 838 }
832 } 839 }
@@ -835,13 +842,26 @@ static size_t print_prefix(const struct log *msg, bool syslog, char *buf)
835 return len; 842 return len;
836} 843}
837 844
838static size_t msg_print_text(const struct log *msg, bool syslog, 845static size_t msg_print_text(const struct log *msg, enum log_flags prev,
839 char *buf, size_t size) 846 bool syslog, char *buf, size_t size)
840{ 847{
841 const char *text = log_text(msg); 848 const char *text = log_text(msg);
842 size_t text_size = msg->text_len; 849 size_t text_size = msg->text_len;
850 bool prefix = true;
851 bool newline = true;
843 size_t len = 0; 852 size_t len = 0;
844 853
854 if ((prev & LOG_CONT) && !(msg->flags & LOG_PREFIX))
855 prefix = false;
856
857 if (msg->flags & LOG_CONT) {
858 if ((prev & LOG_CONT) && !(prev & LOG_NEWLINE))
859 prefix = false;
860
861 if (!(msg->flags & LOG_NEWLINE))
862 newline = false;
863 }
864
845 do { 865 do {
846 const char *next = memchr(text, '\n', text_size); 866 const char *next = memchr(text, '\n', text_size);
847 size_t text_len; 867 size_t text_len;
@@ -859,16 +879,22 @@ static size_t msg_print_text(const struct log *msg, bool syslog,
859 text_len + 1>= size - len) 879 text_len + 1>= size - len)
860 break; 880 break;
861 881
862 len += print_prefix(msg, syslog, buf + len); 882 if (prefix)
883 len += print_prefix(msg, syslog, buf + len);
863 memcpy(buf + len, text, text_len); 884 memcpy(buf + len, text, text_len);
864 len += text_len; 885 len += text_len;
865 buf[len++] = '\n'; 886 if (next || newline)
887 buf[len++] = '\n';
866 } else { 888 } else {
867 /* SYSLOG_ACTION_* buffer size only calculation */ 889 /* SYSLOG_ACTION_* buffer size only calculation */
868 len += print_prefix(msg, syslog, NULL); 890 if (prefix)
869 len += text_len + 1; 891 len += print_prefix(msg, syslog, NULL);
892 len += text_len;
893 if (next || newline)
894 len++;
870 } 895 }
871 896
897 prefix = true;
872 text = next; 898 text = next;
873 } while (text); 899 } while (text);
874 900
@@ -887,22 +913,35 @@ static int syslog_print(char __user *buf, int size)
887 913
888 while (size > 0) { 914 while (size > 0) {
889 size_t n; 915 size_t n;
916 size_t skip;
890 917
891 raw_spin_lock_irq(&logbuf_lock); 918 raw_spin_lock_irq(&logbuf_lock);
892 if (syslog_seq < log_first_seq) { 919 if (syslog_seq < log_first_seq) {
893 /* messages are gone, move to first one */ 920 /* messages are gone, move to first one */
894 syslog_seq = log_first_seq; 921 syslog_seq = log_first_seq;
895 syslog_idx = log_first_idx; 922 syslog_idx = log_first_idx;
923 syslog_prev = 0;
924 syslog_partial = 0;
896 } 925 }
897 if (syslog_seq == log_next_seq) { 926 if (syslog_seq == log_next_seq) {
898 raw_spin_unlock_irq(&logbuf_lock); 927 raw_spin_unlock_irq(&logbuf_lock);
899 break; 928 break;
900 } 929 }
930
931 skip = syslog_partial;
901 msg = log_from_idx(syslog_idx); 932 msg = log_from_idx(syslog_idx);
902 n = msg_print_text(msg, true, text, LOG_LINE_MAX); 933 n = msg_print_text(msg, syslog_prev, true, text, LOG_LINE_MAX);
903 if (n <= size) { 934 if (n - syslog_partial <= size) {
935 /* message fits into buffer, move forward */
904 syslog_idx = log_next(syslog_idx); 936 syslog_idx = log_next(syslog_idx);
905 syslog_seq++; 937 syslog_seq++;
938 syslog_prev = msg->flags;
939 n -= syslog_partial;
940 syslog_partial = 0;
941 } else if (!len){
942 /* partial read(), remember position */
943 n = size;
944 syslog_partial += n;
906 } else 945 } else
907 n = 0; 946 n = 0;
908 raw_spin_unlock_irq(&logbuf_lock); 947 raw_spin_unlock_irq(&logbuf_lock);
@@ -910,17 +949,15 @@ static int syslog_print(char __user *buf, int size)
910 if (!n) 949 if (!n)
911 break; 950 break;
912 951
913 len += n; 952 if (copy_to_user(buf, text + skip, n)) {
914 size -= n;
915 buf += n;
916 n = copy_to_user(buf - n, text, n);
917
918 if (n) {
919 len -= n;
920 if (!len) 953 if (!len)
921 len = -EFAULT; 954 len = -EFAULT;
922 break; 955 break;
923 } 956 }
957
958 len += n;
959 size -= n;
960 buf += n;
924 } 961 }
925 962
926 kfree(text); 963 kfree(text);
@@ -941,6 +978,7 @@ static int syslog_print_all(char __user *buf, int size, bool clear)
941 u64 next_seq; 978 u64 next_seq;
942 u64 seq; 979 u64 seq;
943 u32 idx; 980 u32 idx;
981 enum log_flags prev;
944 982
945 if (clear_seq < log_first_seq) { 983 if (clear_seq < log_first_seq) {
946 /* messages are gone, move to first available one */ 984 /* messages are gone, move to first available one */
@@ -954,10 +992,11 @@ static int syslog_print_all(char __user *buf, int size, bool clear)
954 */ 992 */
955 seq = clear_seq; 993 seq = clear_seq;
956 idx = clear_idx; 994 idx = clear_idx;
995 prev = 0;
957 while (seq < log_next_seq) { 996 while (seq < log_next_seq) {
958 struct log *msg = log_from_idx(idx); 997 struct log *msg = log_from_idx(idx);
959 998
960 len += msg_print_text(msg, true, NULL, 0); 999 len += msg_print_text(msg, prev, true, NULL, 0);
961 idx = log_next(idx); 1000 idx = log_next(idx);
962 seq++; 1001 seq++;
963 } 1002 }
@@ -965,10 +1004,11 @@ static int syslog_print_all(char __user *buf, int size, bool clear)
965 /* move first record forward until length fits into the buffer */ 1004 /* move first record forward until length fits into the buffer */
966 seq = clear_seq; 1005 seq = clear_seq;
967 idx = clear_idx; 1006 idx = clear_idx;
1007 prev = 0;
968 while (len > size && seq < log_next_seq) { 1008 while (len > size && seq < log_next_seq) {
969 struct log *msg = log_from_idx(idx); 1009 struct log *msg = log_from_idx(idx);
970 1010
971 len -= msg_print_text(msg, true, NULL, 0); 1011 len -= msg_print_text(msg, prev, true, NULL, 0);
972 idx = log_next(idx); 1012 idx = log_next(idx);
973 seq++; 1013 seq++;
974 } 1014 }
@@ -977,17 +1017,19 @@ static int syslog_print_all(char __user *buf, int size, bool clear)
977 next_seq = log_next_seq; 1017 next_seq = log_next_seq;
978 1018
979 len = 0; 1019 len = 0;
1020 prev = 0;
980 while (len >= 0 && seq < next_seq) { 1021 while (len >= 0 && seq < next_seq) {
981 struct log *msg = log_from_idx(idx); 1022 struct log *msg = log_from_idx(idx);
982 int textlen; 1023 int textlen;
983 1024
984 textlen = msg_print_text(msg, true, text, LOG_LINE_MAX); 1025 textlen = msg_print_text(msg, prev, true, text, LOG_LINE_MAX);
985 if (textlen < 0) { 1026 if (textlen < 0) {
986 len = textlen; 1027 len = textlen;
987 break; 1028 break;
988 } 1029 }
989 idx = log_next(idx); 1030 idx = log_next(idx);
990 seq++; 1031 seq++;
1032 prev = msg->flags;
991 1033
992 raw_spin_unlock_irq(&logbuf_lock); 1034 raw_spin_unlock_irq(&logbuf_lock);
993 if (copy_to_user(buf + len, text, textlen)) 1035 if (copy_to_user(buf + len, text, textlen))
@@ -1000,6 +1042,7 @@ static int syslog_print_all(char __user *buf, int size, bool clear)
1000 /* messages are gone, move to next one */ 1042 /* messages are gone, move to next one */
1001 seq = log_first_seq; 1043 seq = log_first_seq;
1002 idx = log_first_idx; 1044 idx = log_first_idx;
1045 prev = 0;
1003 } 1046 }
1004 } 1047 }
1005 } 1048 }
@@ -1018,7 +1061,6 @@ int do_syslog(int type, char __user *buf, int len, bool from_file)
1018{ 1061{
1019 bool clear = false; 1062 bool clear = false;
1020 static int saved_console_loglevel = -1; 1063 static int saved_console_loglevel = -1;
1021 static DEFINE_MUTEX(syslog_mutex);
1022 int error; 1064 int error;
1023 1065
1024 error = check_syslog_permissions(type, from_file); 1066 error = check_syslog_permissions(type, from_file);
@@ -1045,17 +1087,11 @@ int do_syslog(int type, char __user *buf, int len, bool from_file)
1045 error = -EFAULT; 1087 error = -EFAULT;
1046 goto out; 1088 goto out;
1047 } 1089 }
1048 error = mutex_lock_interruptible(&syslog_mutex);
1049 if (error)
1050 goto out;
1051 error = wait_event_interruptible(log_wait, 1090 error = wait_event_interruptible(log_wait,
1052 syslog_seq != log_next_seq); 1091 syslog_seq != log_next_seq);
1053 if (error) { 1092 if (error)
1054 mutex_unlock(&syslog_mutex);
1055 goto out; 1093 goto out;
1056 }
1057 error = syslog_print(buf, len); 1094 error = syslog_print(buf, len);
1058 mutex_unlock(&syslog_mutex);
1059 break; 1095 break;
1060 /* Read/clear last kernel messages */ 1096 /* Read/clear last kernel messages */
1061 case SYSLOG_ACTION_READ_CLEAR: 1097 case SYSLOG_ACTION_READ_CLEAR:
@@ -1111,6 +1147,8 @@ int do_syslog(int type, char __user *buf, int len, bool from_file)
1111 /* messages are gone, move to first one */ 1147 /* messages are gone, move to first one */
1112 syslog_seq = log_first_seq; 1148 syslog_seq = log_first_seq;
1113 syslog_idx = log_first_idx; 1149 syslog_idx = log_first_idx;
1150 syslog_prev = 0;
1151 syslog_partial = 0;
1114 } 1152 }
1115 if (from_file) { 1153 if (from_file) {
1116 /* 1154 /*
@@ -1120,19 +1158,20 @@ int do_syslog(int type, char __user *buf, int len, bool from_file)
1120 */ 1158 */
1121 error = log_next_idx - syslog_idx; 1159 error = log_next_idx - syslog_idx;
1122 } else { 1160 } else {
1123 u64 seq; 1161 u64 seq = syslog_seq;
1124 u32 idx; 1162 u32 idx = syslog_idx;
1163 enum log_flags prev = syslog_prev;
1125 1164
1126 error = 0; 1165 error = 0;
1127 seq = syslog_seq;
1128 idx = syslog_idx;
1129 while (seq < log_next_seq) { 1166 while (seq < log_next_seq) {
1130 struct log *msg = log_from_idx(idx); 1167 struct log *msg = log_from_idx(idx);
1131 1168
1132 error += msg_print_text(msg, true, NULL, 0); 1169 error += msg_print_text(msg, prev, true, NULL, 0);
1133 idx = log_next(idx); 1170 idx = log_next(idx);
1134 seq++; 1171 seq++;
1172 prev = msg->flags;
1135 } 1173 }
1174 error -= syslog_partial;
1136 } 1175 }
1137 raw_spin_unlock_irq(&logbuf_lock); 1176 raw_spin_unlock_irq(&logbuf_lock);
1138 break; 1177 break;
@@ -1400,10 +1439,9 @@ asmlinkage int vprintk_emit(int facility, int level,
1400 static char textbuf[LOG_LINE_MAX]; 1439 static char textbuf[LOG_LINE_MAX];
1401 char *text = textbuf; 1440 char *text = textbuf;
1402 size_t text_len; 1441 size_t text_len;
1442 enum log_flags lflags = 0;
1403 unsigned long flags; 1443 unsigned long flags;
1404 int this_cpu; 1444 int this_cpu;
1405 bool newline = false;
1406 bool prefix = false;
1407 int printed_len = 0; 1445 int printed_len = 0;
1408 1446
1409 boot_delay_msec(); 1447 boot_delay_msec();
@@ -1442,7 +1480,7 @@ asmlinkage int vprintk_emit(int facility, int level,
1442 recursion_bug = 0; 1480 recursion_bug = 0;
1443 printed_len += strlen(recursion_msg); 1481 printed_len += strlen(recursion_msg);
1444 /* emit KERN_CRIT message */ 1482 /* emit KERN_CRIT message */
1445 log_store(0, 2, LOG_DEFAULT, 0, 1483 log_store(0, 2, LOG_PREFIX|LOG_NEWLINE, 0,
1446 NULL, 0, recursion_msg, printed_len); 1484 NULL, 0, recursion_msg, printed_len);
1447 } 1485 }
1448 1486
@@ -1455,7 +1493,7 @@ asmlinkage int vprintk_emit(int facility, int level,
1455 /* mark and strip a trailing newline */ 1493 /* mark and strip a trailing newline */
1456 if (text_len && text[text_len-1] == '\n') { 1494 if (text_len && text[text_len-1] == '\n') {
1457 text_len--; 1495 text_len--;
1458 newline = true; 1496 lflags |= LOG_NEWLINE;
1459 } 1497 }
1460 1498
1461 /* strip syslog prefix and extract log level or control flags */ 1499 /* strip syslog prefix and extract log level or control flags */
@@ -1465,7 +1503,7 @@ asmlinkage int vprintk_emit(int facility, int level,
1465 if (level == -1) 1503 if (level == -1)
1466 level = text[1] - '0'; 1504 level = text[1] - '0';
1467 case 'd': /* KERN_DEFAULT */ 1505 case 'd': /* KERN_DEFAULT */
1468 prefix = true; 1506 lflags |= LOG_PREFIX;
1469 case 'c': /* KERN_CONT */ 1507 case 'c': /* KERN_CONT */
1470 text += 3; 1508 text += 3;
1471 text_len -= 3; 1509 text_len -= 3;
@@ -1475,22 +1513,20 @@ asmlinkage int vprintk_emit(int facility, int level,
1475 if (level == -1) 1513 if (level == -1)
1476 level = default_message_loglevel; 1514 level = default_message_loglevel;
1477 1515
1478 if (dict) { 1516 if (dict)
1479 prefix = true; 1517 lflags |= LOG_PREFIX|LOG_NEWLINE;
1480 newline = true;
1481 }
1482 1518
1483 if (!newline) { 1519 if (!(lflags & LOG_NEWLINE)) {
1484 /* 1520 /*
1485 * Flush the conflicting buffer. An earlier newline was missing, 1521 * Flush the conflicting buffer. An earlier newline was missing,
1486 * or another task also prints continuation lines. 1522 * or another task also prints continuation lines.
1487 */ 1523 */
1488 if (cont.len && (prefix || cont.owner != current)) 1524 if (cont.len && (lflags & LOG_PREFIX || cont.owner != current))
1489 cont_flush(); 1525 cont_flush();
1490 1526
1491 /* buffer line if possible, otherwise store it right away */ 1527 /* buffer line if possible, otherwise store it right away */
1492 if (!cont_add(facility, level, text, text_len)) 1528 if (!cont_add(facility, level, text, text_len))
1493 log_store(facility, level, LOG_DEFAULT, 0, 1529 log_store(facility, level, lflags | LOG_CONT, 0,
1494 dict, dictlen, text, text_len); 1530 dict, dictlen, text, text_len);
1495 } else { 1531 } else {
1496 bool stored = false; 1532 bool stored = false;
@@ -1502,13 +1538,13 @@ asmlinkage int vprintk_emit(int facility, int level,
1502 * flush it out and store this line separately. 1538 * flush it out and store this line separately.
1503 */ 1539 */
1504 if (cont.len && cont.owner == current) { 1540 if (cont.len && cont.owner == current) {
1505 if (!prefix) 1541 if (!(lflags & LOG_PREFIX))
1506 stored = cont_add(facility, level, text, text_len); 1542 stored = cont_add(facility, level, text, text_len);
1507 cont_flush(); 1543 cont_flush();
1508 } 1544 }
1509 1545
1510 if (!stored) 1546 if (!stored)
1511 log_store(facility, level, LOG_DEFAULT, 0, 1547 log_store(facility, level, lflags, 0,
1512 dict, dictlen, text, text_len); 1548 dict, dictlen, text, text_len);
1513 } 1549 }
1514 printed_len += text_len; 1550 printed_len += text_len;
@@ -1607,8 +1643,8 @@ static struct cont {
1607static struct log *log_from_idx(u32 idx) { return NULL; } 1643static struct log *log_from_idx(u32 idx) { return NULL; }
1608static u32 log_next(u32 idx) { return 0; } 1644static u32 log_next(u32 idx) { return 0; }
1609static void call_console_drivers(int level, const char *text, size_t len) {} 1645static void call_console_drivers(int level, const char *text, size_t len) {}
1610static size_t msg_print_text(const struct log *msg, bool syslog, 1646static size_t msg_print_text(const struct log *msg, enum log_flags prev,
1611 char *buf, size_t size) { return 0; } 1647 bool syslog, char *buf, size_t size) { return 0; }
1612static size_t cont_print_text(char *text, size_t size) { return 0; } 1648static size_t cont_print_text(char *text, size_t size) { return 0; }
1613 1649
1614#endif /* CONFIG_PRINTK */ 1650#endif /* CONFIG_PRINTK */
@@ -1884,6 +1920,7 @@ void wake_up_klogd(void)
1884/* the next printk record to write to the console */ 1920/* the next printk record to write to the console */
1885static u64 console_seq; 1921static u64 console_seq;
1886static u32 console_idx; 1922static u32 console_idx;
1923static enum log_flags console_prev;
1887 1924
1888/** 1925/**
1889 * console_unlock - unlock the console system 1926 * console_unlock - unlock the console system
@@ -1944,6 +1981,7 @@ again:
1944 /* messages are gone, move to first one */ 1981 /* messages are gone, move to first one */
1945 console_seq = log_first_seq; 1982 console_seq = log_first_seq;
1946 console_idx = log_first_idx; 1983 console_idx = log_first_idx;
1984 console_prev = 0;
1947 } 1985 }
1948skip: 1986skip:
1949 if (console_seq == log_next_seq) 1987 if (console_seq == log_next_seq)
@@ -1957,14 +1995,21 @@ skip:
1957 */ 1995 */
1958 console_idx = log_next(console_idx); 1996 console_idx = log_next(console_idx);
1959 console_seq++; 1997 console_seq++;
1998 /*
1999 * We will get here again when we register a new
2000 * CON_PRINTBUFFER console. Clear the flag so we
2001 * will properly dump everything later.
2002 */
2003 msg->flags &= ~LOG_NOCONS;
1960 goto skip; 2004 goto skip;
1961 } 2005 }
1962 2006
1963 level = msg->level; 2007 level = msg->level;
1964 len = msg_print_text(msg, false, text, sizeof(text)); 2008 len = msg_print_text(msg, console_prev, false,
1965 2009 text, sizeof(text));
1966 console_idx = log_next(console_idx); 2010 console_idx = log_next(console_idx);
1967 console_seq++; 2011 console_seq++;
2012 console_prev = msg->flags;
1968 raw_spin_unlock(&logbuf_lock); 2013 raw_spin_unlock(&logbuf_lock);
1969 2014
1970 stop_critical_timings(); /* don't trace print latency */ 2015 stop_critical_timings(); /* don't trace print latency */
@@ -2227,6 +2272,7 @@ void register_console(struct console *newcon)
2227 raw_spin_lock_irqsave(&logbuf_lock, flags); 2272 raw_spin_lock_irqsave(&logbuf_lock, flags);
2228 console_seq = syslog_seq; 2273 console_seq = syslog_seq;
2229 console_idx = syslog_idx; 2274 console_idx = syslog_idx;
2275 console_prev = syslog_prev;
2230 raw_spin_unlock_irqrestore(&logbuf_lock, flags); 2276 raw_spin_unlock_irqrestore(&logbuf_lock, flags);
2231 /* 2277 /*
2232 * We're about to replay the log buffer. Only do this to the 2278 * We're about to replay the log buffer. Only do this to the
@@ -2520,8 +2566,7 @@ bool kmsg_dump_get_line(struct kmsg_dumper *dumper, bool syslog,
2520 } 2566 }
2521 2567
2522 msg = log_from_idx(dumper->cur_idx); 2568 msg = log_from_idx(dumper->cur_idx);
2523 l = msg_print_text(msg, syslog, 2569 l = msg_print_text(msg, 0, syslog, line, size);
2524 line, size);
2525 2570
2526 dumper->cur_idx = log_next(dumper->cur_idx); 2571 dumper->cur_idx = log_next(dumper->cur_idx);
2527 dumper->cur_seq++; 2572 dumper->cur_seq++;
@@ -2561,6 +2606,7 @@ bool kmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog,
2561 u32 idx; 2606 u32 idx;
2562 u64 next_seq; 2607 u64 next_seq;
2563 u32 next_idx; 2608 u32 next_idx;
2609 enum log_flags prev;
2564 size_t l = 0; 2610 size_t l = 0;
2565 bool ret = false; 2611 bool ret = false;
2566 2612
@@ -2583,23 +2629,27 @@ bool kmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog,
2583 /* calculate length of entire buffer */ 2629 /* calculate length of entire buffer */
2584 seq = dumper->cur_seq; 2630 seq = dumper->cur_seq;
2585 idx = dumper->cur_idx; 2631 idx = dumper->cur_idx;
2632 prev = 0;
2586 while (seq < dumper->next_seq) { 2633 while (seq < dumper->next_seq) {
2587 struct log *msg = log_from_idx(idx); 2634 struct log *msg = log_from_idx(idx);
2588 2635
2589 l += msg_print_text(msg, true, NULL, 0); 2636 l += msg_print_text(msg, prev, true, NULL, 0);
2590 idx = log_next(idx); 2637 idx = log_next(idx);
2591 seq++; 2638 seq++;
2639 prev = msg->flags;
2592 } 2640 }
2593 2641
2594 /* move first record forward until length fits into the buffer */ 2642 /* move first record forward until length fits into the buffer */
2595 seq = dumper->cur_seq; 2643 seq = dumper->cur_seq;
2596 idx = dumper->cur_idx; 2644 idx = dumper->cur_idx;
2645 prev = 0;
2597 while (l > size && seq < dumper->next_seq) { 2646 while (l > size && seq < dumper->next_seq) {
2598 struct log *msg = log_from_idx(idx); 2647 struct log *msg = log_from_idx(idx);
2599 2648
2600 l -= msg_print_text(msg, true, NULL, 0); 2649 l -= msg_print_text(msg, prev, true, NULL, 0);
2601 idx = log_next(idx); 2650 idx = log_next(idx);
2602 seq++; 2651 seq++;
2652 prev = msg->flags;
2603 } 2653 }
2604 2654
2605 /* last message in next interation */ 2655 /* last message in next interation */
@@ -2607,14 +2657,14 @@ bool kmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog,
2607 next_idx = idx; 2657 next_idx = idx;
2608 2658
2609 l = 0; 2659 l = 0;
2660 prev = 0;
2610 while (seq < dumper->next_seq) { 2661 while (seq < dumper->next_seq) {
2611 struct log *msg = log_from_idx(idx); 2662 struct log *msg = log_from_idx(idx);
2612 2663
2613 l += msg_print_text(msg, syslog, 2664 l += msg_print_text(msg, prev, syslog, buf + l, size - l);
2614 buf + l, size - l);
2615
2616 idx = log_next(idx); 2665 idx = log_next(idx);
2617 seq++; 2666 seq++;
2667 prev = msg->flags;
2618 } 2668 }
2619 2669
2620 dumper->next_seq = next_seq; 2670 dumper->next_seq = next_seq;
diff --git a/kernel/rcutree.c b/kernel/rcutree.c
index 38ecdda3f55f..4b97bba7396e 100644
--- a/kernel/rcutree.c
+++ b/kernel/rcutree.c
@@ -201,6 +201,7 @@ void rcu_note_context_switch(int cpu)
201{ 201{
202 trace_rcu_utilization("Start context switch"); 202 trace_rcu_utilization("Start context switch");
203 rcu_sched_qs(cpu); 203 rcu_sched_qs(cpu);
204 rcu_preempt_note_context_switch(cpu);
204 trace_rcu_utilization("End context switch"); 205 trace_rcu_utilization("End context switch");
205} 206}
206EXPORT_SYMBOL_GPL(rcu_note_context_switch); 207EXPORT_SYMBOL_GPL(rcu_note_context_switch);
diff --git a/kernel/rcutree.h b/kernel/rcutree.h
index ea056495783e..19b61ac1079f 100644
--- a/kernel/rcutree.h
+++ b/kernel/rcutree.h
@@ -444,6 +444,7 @@ DECLARE_PER_CPU(char, rcu_cpu_has_work);
444/* Forward declarations for rcutree_plugin.h */ 444/* Forward declarations for rcutree_plugin.h */
445static void rcu_bootup_announce(void); 445static void rcu_bootup_announce(void);
446long rcu_batches_completed(void); 446long rcu_batches_completed(void);
447static void rcu_preempt_note_context_switch(int cpu);
447static int rcu_preempt_blocked_readers_cgp(struct rcu_node *rnp); 448static int rcu_preempt_blocked_readers_cgp(struct rcu_node *rnp);
448#ifdef CONFIG_HOTPLUG_CPU 449#ifdef CONFIG_HOTPLUG_CPU
449static void rcu_report_unblock_qs_rnp(struct rcu_node *rnp, 450static void rcu_report_unblock_qs_rnp(struct rcu_node *rnp,
diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
index 5271a020887e..3e4899459f3d 100644
--- a/kernel/rcutree_plugin.h
+++ b/kernel/rcutree_plugin.h
@@ -153,7 +153,7 @@ static void rcu_preempt_qs(int cpu)
153 * 153 *
154 * Caller must disable preemption. 154 * Caller must disable preemption.
155 */ 155 */
156void rcu_preempt_note_context_switch(void) 156static void rcu_preempt_note_context_switch(int cpu)
157{ 157{
158 struct task_struct *t = current; 158 struct task_struct *t = current;
159 unsigned long flags; 159 unsigned long flags;
@@ -164,7 +164,7 @@ void rcu_preempt_note_context_switch(void)
164 (t->rcu_read_unlock_special & RCU_READ_UNLOCK_BLOCKED) == 0) { 164 (t->rcu_read_unlock_special & RCU_READ_UNLOCK_BLOCKED) == 0) {
165 165
166 /* Possibly blocking in an RCU read-side critical section. */ 166 /* Possibly blocking in an RCU read-side critical section. */
167 rdp = __this_cpu_ptr(rcu_preempt_state.rda); 167 rdp = per_cpu_ptr(rcu_preempt_state.rda, cpu);
168 rnp = rdp->mynode; 168 rnp = rdp->mynode;
169 raw_spin_lock_irqsave(&rnp->lock, flags); 169 raw_spin_lock_irqsave(&rnp->lock, flags);
170 t->rcu_read_unlock_special |= RCU_READ_UNLOCK_BLOCKED; 170 t->rcu_read_unlock_special |= RCU_READ_UNLOCK_BLOCKED;
@@ -228,7 +228,7 @@ void rcu_preempt_note_context_switch(void)
228 * means that we continue to block the current grace period. 228 * means that we continue to block the current grace period.
229 */ 229 */
230 local_irq_save(flags); 230 local_irq_save(flags);
231 rcu_preempt_qs(smp_processor_id()); 231 rcu_preempt_qs(cpu);
232 local_irq_restore(flags); 232 local_irq_restore(flags);
233} 233}
234 234
@@ -1002,6 +1002,14 @@ void rcu_force_quiescent_state(void)
1002EXPORT_SYMBOL_GPL(rcu_force_quiescent_state); 1002EXPORT_SYMBOL_GPL(rcu_force_quiescent_state);
1003 1003
1004/* 1004/*
1005 * Because preemptible RCU does not exist, we never have to check for
1006 * CPUs being in quiescent states.
1007 */
1008static void rcu_preempt_note_context_switch(int cpu)
1009{
1010}
1011
1012/*
1005 * Because preemptible RCU does not exist, there are never any preempted 1013 * Because preemptible RCU does not exist, there are never any preempted
1006 * RCU readers. 1014 * RCU readers.
1007 */ 1015 */
diff --git a/kernel/relay.c b/kernel/relay.c
index ab56a1764d4d..e8cd2027abbd 100644
--- a/kernel/relay.c
+++ b/kernel/relay.c
@@ -1235,6 +1235,7 @@ static ssize_t subbuf_splice_actor(struct file *in,
1235 struct splice_pipe_desc spd = { 1235 struct splice_pipe_desc spd = {
1236 .pages = pages, 1236 .pages = pages,
1237 .nr_pages = 0, 1237 .nr_pages = 0,
1238 .nr_pages_max = PIPE_DEF_BUFFERS,
1238 .partial = partial, 1239 .partial = partial,
1239 .flags = flags, 1240 .flags = flags,
1240 .ops = &relay_pipe_buf_ops, 1241 .ops = &relay_pipe_buf_ops,
@@ -1302,8 +1303,8 @@ static ssize_t subbuf_splice_actor(struct file *in,
1302 ret += padding; 1303 ret += padding;
1303 1304
1304out: 1305out:
1305 splice_shrink_spd(pipe, &spd); 1306 splice_shrink_spd(&spd);
1306 return ret; 1307 return ret;
1307} 1308}
1308 1309
1309static ssize_t relay_file_splice_read(struct file *in, 1310static ssize_t relay_file_splice_read(struct file *in,
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index d5594a4268d4..468bdd44c1ba 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -2081,7 +2081,6 @@ context_switch(struct rq *rq, struct task_struct *prev,
2081#endif 2081#endif
2082 2082
2083 /* Here we just switch the register state and the stack. */ 2083 /* Here we just switch the register state and the stack. */
2084 rcu_switch_from(prev);
2085 switch_to(prev, next, prev); 2084 switch_to(prev, next, prev);
2086 2085
2087 barrier(); 2086 barrier();
@@ -2161,11 +2160,73 @@ unsigned long this_cpu_load(void)
2161} 2160}
2162 2161
2163 2162
2163/*
2164 * Global load-average calculations
2165 *
2166 * We take a distributed and async approach to calculating the global load-avg
2167 * in order to minimize overhead.
2168 *
2169 * The global load average is an exponentially decaying average of nr_running +
2170 * nr_uninterruptible.
2171 *
2172 * Once every LOAD_FREQ:
2173 *
2174 * nr_active = 0;
2175 * for_each_possible_cpu(cpu)
2176 * nr_active += cpu_of(cpu)->nr_running + cpu_of(cpu)->nr_uninterruptible;
2177 *
2178 * avenrun[n] = avenrun[0] * exp_n + nr_active * (1 - exp_n)
2179 *
2180 * Due to a number of reasons the above turns in the mess below:
2181 *
2182 * - for_each_possible_cpu() is prohibitively expensive on machines with
2183 * serious number of cpus, therefore we need to take a distributed approach
2184 * to calculating nr_active.
2185 *
2186 * \Sum_i x_i(t) = \Sum_i x_i(t) - x_i(t_0) | x_i(t_0) := 0
2187 * = \Sum_i { \Sum_j=1 x_i(t_j) - x_i(t_j-1) }
2188 *
2189 * So assuming nr_active := 0 when we start out -- true per definition, we
2190 * can simply take per-cpu deltas and fold those into a global accumulate
2191 * to obtain the same result. See calc_load_fold_active().
2192 *
2193 * Furthermore, in order to avoid synchronizing all per-cpu delta folding
2194 * across the machine, we assume 10 ticks is sufficient time for every
2195 * cpu to have completed this task.
2196 *
2197 * This places an upper-bound on the IRQ-off latency of the machine. Then
2198 * again, being late doesn't loose the delta, just wrecks the sample.
2199 *
2200 * - cpu_rq()->nr_uninterruptible isn't accurately tracked per-cpu because
2201 * this would add another cross-cpu cacheline miss and atomic operation
2202 * to the wakeup path. Instead we increment on whatever cpu the task ran
2203 * when it went into uninterruptible state and decrement on whatever cpu
2204 * did the wakeup. This means that only the sum of nr_uninterruptible over
2205 * all cpus yields the correct result.
2206 *
2207 * This covers the NO_HZ=n code, for extra head-aches, see the comment below.
2208 */
2209
2164/* Variables and functions for calc_load */ 2210/* Variables and functions for calc_load */
2165static atomic_long_t calc_load_tasks; 2211static atomic_long_t calc_load_tasks;
2166static unsigned long calc_load_update; 2212static unsigned long calc_load_update;
2167unsigned long avenrun[3]; 2213unsigned long avenrun[3];
2168EXPORT_SYMBOL(avenrun); 2214EXPORT_SYMBOL(avenrun); /* should be removed */
2215
2216/**
2217 * get_avenrun - get the load average array
2218 * @loads: pointer to dest load array
2219 * @offset: offset to add
2220 * @shift: shift count to shift the result left
2221 *
2222 * These values are estimates at best, so no need for locking.
2223 */
2224void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
2225{
2226 loads[0] = (avenrun[0] + offset) << shift;
2227 loads[1] = (avenrun[1] + offset) << shift;
2228 loads[2] = (avenrun[2] + offset) << shift;
2229}
2169 2230
2170static long calc_load_fold_active(struct rq *this_rq) 2231static long calc_load_fold_active(struct rq *this_rq)
2171{ 2232{
@@ -2182,6 +2243,9 @@ static long calc_load_fold_active(struct rq *this_rq)
2182 return delta; 2243 return delta;
2183} 2244}
2184 2245
2246/*
2247 * a1 = a0 * e + a * (1 - e)
2248 */
2185static unsigned long 2249static unsigned long
2186calc_load(unsigned long load, unsigned long exp, unsigned long active) 2250calc_load(unsigned long load, unsigned long exp, unsigned long active)
2187{ 2251{
@@ -2193,30 +2257,118 @@ calc_load(unsigned long load, unsigned long exp, unsigned long active)
2193 2257
2194#ifdef CONFIG_NO_HZ 2258#ifdef CONFIG_NO_HZ
2195/* 2259/*
2196 * For NO_HZ we delay the active fold to the next LOAD_FREQ update. 2260 * Handle NO_HZ for the global load-average.
2261 *
2262 * Since the above described distributed algorithm to compute the global
2263 * load-average relies on per-cpu sampling from the tick, it is affected by
2264 * NO_HZ.
2265 *
2266 * The basic idea is to fold the nr_active delta into a global idle-delta upon
2267 * entering NO_HZ state such that we can include this as an 'extra' cpu delta
2268 * when we read the global state.
2269 *
2270 * Obviously reality has to ruin such a delightfully simple scheme:
2271 *
2272 * - When we go NO_HZ idle during the window, we can negate our sample
2273 * contribution, causing under-accounting.
2274 *
2275 * We avoid this by keeping two idle-delta counters and flipping them
2276 * when the window starts, thus separating old and new NO_HZ load.
2277 *
2278 * The only trick is the slight shift in index flip for read vs write.
2279 *
2280 * 0s 5s 10s 15s
2281 * +10 +10 +10 +10
2282 * |-|-----------|-|-----------|-|-----------|-|
2283 * r:0 0 1 1 0 0 1 1 0
2284 * w:0 1 1 0 0 1 1 0 0
2285 *
2286 * This ensures we'll fold the old idle contribution in this window while
2287 * accumlating the new one.
2288 *
2289 * - When we wake up from NO_HZ idle during the window, we push up our
2290 * contribution, since we effectively move our sample point to a known
2291 * busy state.
2292 *
2293 * This is solved by pushing the window forward, and thus skipping the
2294 * sample, for this cpu (effectively using the idle-delta for this cpu which
2295 * was in effect at the time the window opened). This also solves the issue
2296 * of having to deal with a cpu having been in NOHZ idle for multiple
2297 * LOAD_FREQ intervals.
2197 * 2298 *
2198 * When making the ILB scale, we should try to pull this in as well. 2299 * When making the ILB scale, we should try to pull this in as well.
2199 */ 2300 */
2200static atomic_long_t calc_load_tasks_idle; 2301static atomic_long_t calc_load_idle[2];
2302static int calc_load_idx;
2201 2303
2202void calc_load_account_idle(struct rq *this_rq) 2304static inline int calc_load_write_idx(void)
2203{ 2305{
2306 int idx = calc_load_idx;
2307
2308 /*
2309 * See calc_global_nohz(), if we observe the new index, we also
2310 * need to observe the new update time.
2311 */
2312 smp_rmb();
2313
2314 /*
2315 * If the folding window started, make sure we start writing in the
2316 * next idle-delta.
2317 */
2318 if (!time_before(jiffies, calc_load_update))
2319 idx++;
2320
2321 return idx & 1;
2322}
2323
2324static inline int calc_load_read_idx(void)
2325{
2326 return calc_load_idx & 1;
2327}
2328
2329void calc_load_enter_idle(void)
2330{
2331 struct rq *this_rq = this_rq();
2204 long delta; 2332 long delta;
2205 2333
2334 /*
2335 * We're going into NOHZ mode, if there's any pending delta, fold it
2336 * into the pending idle delta.
2337 */
2206 delta = calc_load_fold_active(this_rq); 2338 delta = calc_load_fold_active(this_rq);
2207 if (delta) 2339 if (delta) {
2208 atomic_long_add(delta, &calc_load_tasks_idle); 2340 int idx = calc_load_write_idx();
2341 atomic_long_add(delta, &calc_load_idle[idx]);
2342 }
2209} 2343}
2210 2344
2211static long calc_load_fold_idle(void) 2345void calc_load_exit_idle(void)
2212{ 2346{
2213 long delta = 0; 2347 struct rq *this_rq = this_rq();
2348
2349 /*
2350 * If we're still before the sample window, we're done.
2351 */
2352 if (time_before(jiffies, this_rq->calc_load_update))
2353 return;
2214 2354
2215 /* 2355 /*
2216 * Its got a race, we don't care... 2356 * We woke inside or after the sample window, this means we're already
2357 * accounted through the nohz accounting, so skip the entire deal and
2358 * sync up for the next window.
2217 */ 2359 */
2218 if (atomic_long_read(&calc_load_tasks_idle)) 2360 this_rq->calc_load_update = calc_load_update;
2219 delta = atomic_long_xchg(&calc_load_tasks_idle, 0); 2361 if (time_before(jiffies, this_rq->calc_load_update + 10))
2362 this_rq->calc_load_update += LOAD_FREQ;
2363}
2364
2365static long calc_load_fold_idle(void)
2366{
2367 int idx = calc_load_read_idx();
2368 long delta = 0;
2369
2370 if (atomic_long_read(&calc_load_idle[idx]))
2371 delta = atomic_long_xchg(&calc_load_idle[idx], 0);
2220 2372
2221 return delta; 2373 return delta;
2222} 2374}
@@ -2302,66 +2454,39 @@ static void calc_global_nohz(void)
2302{ 2454{
2303 long delta, active, n; 2455 long delta, active, n;
2304 2456
2305 /* 2457 if (!time_before(jiffies, calc_load_update + 10)) {
2306 * If we crossed a calc_load_update boundary, make sure to fold 2458 /*
2307 * any pending idle changes, the respective CPUs might have 2459 * Catch-up, fold however many we are behind still
2308 * missed the tick driven calc_load_account_active() update 2460 */
2309 * due to NO_HZ. 2461 delta = jiffies - calc_load_update - 10;
2310 */ 2462 n = 1 + (delta / LOAD_FREQ);
2311 delta = calc_load_fold_idle();
2312 if (delta)
2313 atomic_long_add(delta, &calc_load_tasks);
2314
2315 /*
2316 * It could be the one fold was all it took, we done!
2317 */
2318 if (time_before(jiffies, calc_load_update + 10))
2319 return;
2320
2321 /*
2322 * Catch-up, fold however many we are behind still
2323 */
2324 delta = jiffies - calc_load_update - 10;
2325 n = 1 + (delta / LOAD_FREQ);
2326 2463
2327 active = atomic_long_read(&calc_load_tasks); 2464 active = atomic_long_read(&calc_load_tasks);
2328 active = active > 0 ? active * FIXED_1 : 0; 2465 active = active > 0 ? active * FIXED_1 : 0;
2329 2466
2330 avenrun[0] = calc_load_n(avenrun[0], EXP_1, active, n); 2467 avenrun[0] = calc_load_n(avenrun[0], EXP_1, active, n);
2331 avenrun[1] = calc_load_n(avenrun[1], EXP_5, active, n); 2468 avenrun[1] = calc_load_n(avenrun[1], EXP_5, active, n);
2332 avenrun[2] = calc_load_n(avenrun[2], EXP_15, active, n); 2469 avenrun[2] = calc_load_n(avenrun[2], EXP_15, active, n);
2333 2470
2334 calc_load_update += n * LOAD_FREQ; 2471 calc_load_update += n * LOAD_FREQ;
2335} 2472 }
2336#else
2337void calc_load_account_idle(struct rq *this_rq)
2338{
2339}
2340 2473
2341static inline long calc_load_fold_idle(void) 2474 /*
2342{ 2475 * Flip the idle index...
2343 return 0; 2476 *
2477 * Make sure we first write the new time then flip the index, so that
2478 * calc_load_write_idx() will see the new time when it reads the new
2479 * index, this avoids a double flip messing things up.
2480 */
2481 smp_wmb();
2482 calc_load_idx++;
2344} 2483}
2484#else /* !CONFIG_NO_HZ */
2345 2485
2346static void calc_global_nohz(void) 2486static inline long calc_load_fold_idle(void) { return 0; }
2347{ 2487static inline void calc_global_nohz(void) { }
2348}
2349#endif
2350 2488
2351/** 2489#endif /* CONFIG_NO_HZ */
2352 * get_avenrun - get the load average array
2353 * @loads: pointer to dest load array
2354 * @offset: offset to add
2355 * @shift: shift count to shift the result left
2356 *
2357 * These values are estimates at best, so no need for locking.
2358 */
2359void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
2360{
2361 loads[0] = (avenrun[0] + offset) << shift;
2362 loads[1] = (avenrun[1] + offset) << shift;
2363 loads[2] = (avenrun[2] + offset) << shift;
2364}
2365 2490
2366/* 2491/*
2367 * calc_load - update the avenrun load estimates 10 ticks after the 2492 * calc_load - update the avenrun load estimates 10 ticks after the
@@ -2369,11 +2494,18 @@ void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
2369 */ 2494 */
2370void calc_global_load(unsigned long ticks) 2495void calc_global_load(unsigned long ticks)
2371{ 2496{
2372 long active; 2497 long active, delta;
2373 2498
2374 if (time_before(jiffies, calc_load_update + 10)) 2499 if (time_before(jiffies, calc_load_update + 10))
2375 return; 2500 return;
2376 2501
2502 /*
2503 * Fold the 'old' idle-delta to include all NO_HZ cpus.
2504 */
2505 delta = calc_load_fold_idle();
2506 if (delta)
2507 atomic_long_add(delta, &calc_load_tasks);
2508
2377 active = atomic_long_read(&calc_load_tasks); 2509 active = atomic_long_read(&calc_load_tasks);
2378 active = active > 0 ? active * FIXED_1 : 0; 2510 active = active > 0 ? active * FIXED_1 : 0;
2379 2511
@@ -2384,12 +2516,7 @@ void calc_global_load(unsigned long ticks)
2384 calc_load_update += LOAD_FREQ; 2516 calc_load_update += LOAD_FREQ;
2385 2517
2386 /* 2518 /*
2387 * Account one period with whatever state we found before 2519 * In case we idled for multiple LOAD_FREQ intervals, catch up in bulk.
2388 * folding in the nohz state and ageing the entire idle period.
2389 *
2390 * This avoids loosing a sample when we go idle between
2391 * calc_load_account_active() (10 ticks ago) and now and thus
2392 * under-accounting.
2393 */ 2520 */
2394 calc_global_nohz(); 2521 calc_global_nohz();
2395} 2522}
@@ -2406,7 +2533,6 @@ static void calc_load_account_active(struct rq *this_rq)
2406 return; 2533 return;
2407 2534
2408 delta = calc_load_fold_active(this_rq); 2535 delta = calc_load_fold_active(this_rq);
2409 delta += calc_load_fold_idle();
2410 if (delta) 2536 if (delta)
2411 atomic_long_add(delta, &calc_load_tasks); 2537 atomic_long_add(delta, &calc_load_tasks);
2412 2538
@@ -2414,6 +2540,10 @@ static void calc_load_account_active(struct rq *this_rq)
2414} 2540}
2415 2541
2416/* 2542/*
2543 * End of global load-average stuff
2544 */
2545
2546/*
2417 * The exact cpuload at various idx values, calculated at every tick would be 2547 * The exact cpuload at various idx values, calculated at every tick would be
2418 * load = (2^idx - 1) / 2^idx * load + 1 / 2^idx * cur_load 2548 * load = (2^idx - 1) / 2^idx * load + 1 / 2^idx * cur_load
2419 * 2549 *
diff --git a/kernel/sched/idle_task.c b/kernel/sched/idle_task.c
index b44d604b35d1..b6baf370cae9 100644
--- a/kernel/sched/idle_task.c
+++ b/kernel/sched/idle_task.c
@@ -25,7 +25,6 @@ static void check_preempt_curr_idle(struct rq *rq, struct task_struct *p, int fl
25static struct task_struct *pick_next_task_idle(struct rq *rq) 25static struct task_struct *pick_next_task_idle(struct rq *rq)
26{ 26{
27 schedstat_inc(rq, sched_goidle); 27 schedstat_inc(rq, sched_goidle);
28 calc_load_account_idle(rq);
29 return rq->idle; 28 return rq->idle;
30} 29}
31 30
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 6d52cea7f33d..55844f24435a 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -942,8 +942,6 @@ static inline u64 sched_avg_period(void)
942 return (u64)sysctl_sched_time_avg * NSEC_PER_MSEC / 2; 942 return (u64)sysctl_sched_time_avg * NSEC_PER_MSEC / 2;
943} 943}
944 944
945void calc_load_account_idle(struct rq *this_rq);
946
947#ifdef CONFIG_SCHED_HRTICK 945#ifdef CONFIG_SCHED_HRTICK
948 946
949/* 947/*
diff --git a/kernel/sys.c b/kernel/sys.c
index e0c8ffc50d7f..2d39a84cd857 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -1788,7 +1788,6 @@ SYSCALL_DEFINE1(umask, int, mask)
1788#ifdef CONFIG_CHECKPOINT_RESTORE 1788#ifdef CONFIG_CHECKPOINT_RESTORE
1789static int prctl_set_mm_exe_file(struct mm_struct *mm, unsigned int fd) 1789static int prctl_set_mm_exe_file(struct mm_struct *mm, unsigned int fd)
1790{ 1790{
1791 struct vm_area_struct *vma;
1792 struct file *exe_file; 1791 struct file *exe_file;
1793 struct dentry *dentry; 1792 struct dentry *dentry;
1794 int err; 1793 int err;
@@ -1816,13 +1815,17 @@ static int prctl_set_mm_exe_file(struct mm_struct *mm, unsigned int fd)
1816 down_write(&mm->mmap_sem); 1815 down_write(&mm->mmap_sem);
1817 1816
1818 /* 1817 /*
1819 * Forbid mm->exe_file change if there are mapped other files. 1818 * Forbid mm->exe_file change if old file still mapped.
1820 */ 1819 */
1821 err = -EBUSY; 1820 err = -EBUSY;
1822 for (vma = mm->mmap; vma; vma = vma->vm_next) { 1821 if (mm->exe_file) {
1823 if (vma->vm_file && !path_equal(&vma->vm_file->f_path, 1822 struct vm_area_struct *vma;
1824 &exe_file->f_path)) 1823
1825 goto exit_unlock; 1824 for (vma = mm->mmap; vma; vma = vma->vm_next)
1825 if (vma->vm_file &&
1826 path_equal(&vma->vm_file->f_path,
1827 &mm->exe_file->f_path))
1828 goto exit_unlock;
1826 } 1829 }
1827 1830
1828 /* 1831 /*
@@ -1835,6 +1838,7 @@ static int prctl_set_mm_exe_file(struct mm_struct *mm, unsigned int fd)
1835 if (test_and_set_bit(MMF_EXE_FILE_CHANGED, &mm->flags)) 1838 if (test_and_set_bit(MMF_EXE_FILE_CHANGED, &mm->flags))
1836 goto exit_unlock; 1839 goto exit_unlock;
1837 1840
1841 err = 0;
1838 set_mm_exe_file(mm, exe_file); 1842 set_mm_exe_file(mm, exe_file);
1839exit_unlock: 1843exit_unlock:
1840 up_write(&mm->mmap_sem); 1844 up_write(&mm->mmap_sem);
diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c
index 869997833928..4a08472c3ca7 100644
--- a/kernel/time/tick-sched.c
+++ b/kernel/time/tick-sched.c
@@ -406,6 +406,7 @@ static void tick_nohz_stop_sched_tick(struct tick_sched *ts)
406 */ 406 */
407 if (!ts->tick_stopped) { 407 if (!ts->tick_stopped) {
408 select_nohz_load_balancer(1); 408 select_nohz_load_balancer(1);
409 calc_load_enter_idle();
409 410
410 ts->idle_tick = hrtimer_get_expires(&ts->sched_timer); 411 ts->idle_tick = hrtimer_get_expires(&ts->sched_timer);
411 ts->tick_stopped = 1; 412 ts->tick_stopped = 1;
@@ -597,6 +598,7 @@ void tick_nohz_idle_exit(void)
597 account_idle_ticks(ticks); 598 account_idle_ticks(ticks);
598#endif 599#endif
599 600
601 calc_load_exit_idle();
600 touch_softlockup_watchdog(); 602 touch_softlockup_watchdog();
601 /* 603 /*
602 * Cancel the scheduled timer and restore the tick 604 * Cancel the scheduled timer and restore the tick
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 6f46a00a1e8a..269b1fe5f2ae 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -70,6 +70,12 @@ struct timekeeper {
70 /* The raw monotonic time for the CLOCK_MONOTONIC_RAW posix clock. */ 70 /* The raw monotonic time for the CLOCK_MONOTONIC_RAW posix clock. */
71 struct timespec raw_time; 71 struct timespec raw_time;
72 72
73 /* Offset clock monotonic -> clock realtime */
74 ktime_t offs_real;
75
76 /* Offset clock monotonic -> clock boottime */
77 ktime_t offs_boot;
78
73 /* Seqlock for all timekeeper values */ 79 /* Seqlock for all timekeeper values */
74 seqlock_t lock; 80 seqlock_t lock;
75}; 81};
@@ -172,6 +178,14 @@ static inline s64 timekeeping_get_ns_raw(void)
172 return clocksource_cyc2ns(cycle_delta, clock->mult, clock->shift); 178 return clocksource_cyc2ns(cycle_delta, clock->mult, clock->shift);
173} 179}
174 180
181static void update_rt_offset(void)
182{
183 struct timespec tmp, *wtm = &timekeeper.wall_to_monotonic;
184
185 set_normalized_timespec(&tmp, -wtm->tv_sec, -wtm->tv_nsec);
186 timekeeper.offs_real = timespec_to_ktime(tmp);
187}
188
175/* must hold write on timekeeper.lock */ 189/* must hold write on timekeeper.lock */
176static void timekeeping_update(bool clearntp) 190static void timekeeping_update(bool clearntp)
177{ 191{
@@ -179,6 +193,7 @@ static void timekeeping_update(bool clearntp)
179 timekeeper.ntp_error = 0; 193 timekeeper.ntp_error = 0;
180 ntp_clear(); 194 ntp_clear();
181 } 195 }
196 update_rt_offset();
182 update_vsyscall(&timekeeper.xtime, &timekeeper.wall_to_monotonic, 197 update_vsyscall(&timekeeper.xtime, &timekeeper.wall_to_monotonic,
183 timekeeper.clock, timekeeper.mult); 198 timekeeper.clock, timekeeper.mult);
184} 199}
@@ -604,6 +619,7 @@ void __init timekeeping_init(void)
604 } 619 }
605 set_normalized_timespec(&timekeeper.wall_to_monotonic, 620 set_normalized_timespec(&timekeeper.wall_to_monotonic,
606 -boot.tv_sec, -boot.tv_nsec); 621 -boot.tv_sec, -boot.tv_nsec);
622 update_rt_offset();
607 timekeeper.total_sleep_time.tv_sec = 0; 623 timekeeper.total_sleep_time.tv_sec = 0;
608 timekeeper.total_sleep_time.tv_nsec = 0; 624 timekeeper.total_sleep_time.tv_nsec = 0;
609 write_sequnlock_irqrestore(&timekeeper.lock, flags); 625 write_sequnlock_irqrestore(&timekeeper.lock, flags);
@@ -612,6 +628,12 @@ void __init timekeeping_init(void)
612/* time in seconds when suspend began */ 628/* time in seconds when suspend began */
613static struct timespec timekeeping_suspend_time; 629static struct timespec timekeeping_suspend_time;
614 630
631static void update_sleep_time(struct timespec t)
632{
633 timekeeper.total_sleep_time = t;
634 timekeeper.offs_boot = timespec_to_ktime(t);
635}
636
615/** 637/**
616 * __timekeeping_inject_sleeptime - Internal function to add sleep interval 638 * __timekeeping_inject_sleeptime - Internal function to add sleep interval
617 * @delta: pointer to a timespec delta value 639 * @delta: pointer to a timespec delta value
@@ -630,8 +652,7 @@ static void __timekeeping_inject_sleeptime(struct timespec *delta)
630 timekeeper.xtime = timespec_add(timekeeper.xtime, *delta); 652 timekeeper.xtime = timespec_add(timekeeper.xtime, *delta);
631 timekeeper.wall_to_monotonic = 653 timekeeper.wall_to_monotonic =
632 timespec_sub(timekeeper.wall_to_monotonic, *delta); 654 timespec_sub(timekeeper.wall_to_monotonic, *delta);
633 timekeeper.total_sleep_time = timespec_add( 655 update_sleep_time(timespec_add(timekeeper.total_sleep_time, *delta));
634 timekeeper.total_sleep_time, *delta);
635} 656}
636 657
637 658
@@ -963,6 +984,8 @@ static cycle_t logarithmic_accumulation(cycle_t offset, int shift)
963 leap = second_overflow(timekeeper.xtime.tv_sec); 984 leap = second_overflow(timekeeper.xtime.tv_sec);
964 timekeeper.xtime.tv_sec += leap; 985 timekeeper.xtime.tv_sec += leap;
965 timekeeper.wall_to_monotonic.tv_sec -= leap; 986 timekeeper.wall_to_monotonic.tv_sec -= leap;
987 if (leap)
988 clock_was_set_delayed();
966 } 989 }
967 990
968 /* Accumulate raw time */ 991 /* Accumulate raw time */
@@ -1079,6 +1102,8 @@ static void update_wall_time(void)
1079 leap = second_overflow(timekeeper.xtime.tv_sec); 1102 leap = second_overflow(timekeeper.xtime.tv_sec);
1080 timekeeper.xtime.tv_sec += leap; 1103 timekeeper.xtime.tv_sec += leap;
1081 timekeeper.wall_to_monotonic.tv_sec -= leap; 1104 timekeeper.wall_to_monotonic.tv_sec -= leap;
1105 if (leap)
1106 clock_was_set_delayed();
1082 } 1107 }
1083 1108
1084 timekeeping_update(false); 1109 timekeeping_update(false);
@@ -1246,6 +1271,40 @@ void get_xtime_and_monotonic_and_sleep_offset(struct timespec *xtim,
1246 } while (read_seqretry(&timekeeper.lock, seq)); 1271 } while (read_seqretry(&timekeeper.lock, seq));
1247} 1272}
1248 1273
1274#ifdef CONFIG_HIGH_RES_TIMERS
1275/**
1276 * ktime_get_update_offsets - hrtimer helper
1277 * @offs_real: pointer to storage for monotonic -> realtime offset
1278 * @offs_boot: pointer to storage for monotonic -> boottime offset
1279 *
1280 * Returns current monotonic time and updates the offsets
1281 * Called from hrtimer_interupt() or retrigger_next_event()
1282 */
1283ktime_t ktime_get_update_offsets(ktime_t *offs_real, ktime_t *offs_boot)
1284{
1285 ktime_t now;
1286 unsigned int seq;
1287 u64 secs, nsecs;
1288
1289 do {
1290 seq = read_seqbegin(&timekeeper.lock);
1291
1292 secs = timekeeper.xtime.tv_sec;
1293 nsecs = timekeeper.xtime.tv_nsec;
1294 nsecs += timekeeping_get_ns();
1295 /* If arch requires, add in gettimeoffset() */
1296 nsecs += arch_gettimeoffset();
1297
1298 *offs_real = timekeeper.offs_real;
1299 *offs_boot = timekeeper.offs_boot;
1300 } while (read_seqretry(&timekeeper.lock, seq));
1301
1302 now = ktime_add_ns(ktime_set(secs, 0), nsecs);
1303 now = ktime_sub(now, *offs_real);
1304 return now;
1305}
1306#endif
1307
1249/** 1308/**
1250 * ktime_get_monotonic_offset() - get wall_to_monotonic in ktime_t format 1309 * ktime_get_monotonic_offset() - get wall_to_monotonic in ktime_t format
1251 */ 1310 */
diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
index 1d0f6a8a0e5e..f765465bffe4 100644
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -1075,6 +1075,7 @@ rb_allocate_cpu_buffer(struct ring_buffer *buffer, int nr_pages, int cpu)
1075 rb_init_page(bpage->page); 1075 rb_init_page(bpage->page);
1076 1076
1077 INIT_LIST_HEAD(&cpu_buffer->reader_page->list); 1077 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
1078 INIT_LIST_HEAD(&cpu_buffer->new_pages);
1078 1079
1079 ret = rb_allocate_pages(cpu_buffer, nr_pages); 1080 ret = rb_allocate_pages(cpu_buffer, nr_pages);
1080 if (ret < 0) 1081 if (ret < 0)
@@ -1346,10 +1347,9 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
1346 * If something was added to this page, it was full 1347 * If something was added to this page, it was full
1347 * since it is not the tail page. So we deduct the 1348 * since it is not the tail page. So we deduct the
1348 * bytes consumed in ring buffer from here. 1349 * bytes consumed in ring buffer from here.
1349 * No need to update overruns, since this page is 1350 * Increment overrun to account for the lost events.
1350 * deleted from ring buffer and its entries are
1351 * already accounted for.
1352 */ 1351 */
1352 local_add(page_entries, &cpu_buffer->overrun);
1353 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes); 1353 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
1354 } 1354 }
1355 1355
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 49249c28690d..a7fa0702be1c 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -3609,6 +3609,7 @@ static ssize_t tracing_splice_read_pipe(struct file *filp,
3609 .pages = pages_def, 3609 .pages = pages_def,
3610 .partial = partial_def, 3610 .partial = partial_def,
3611 .nr_pages = 0, /* This gets updated below. */ 3611 .nr_pages = 0, /* This gets updated below. */
3612 .nr_pages_max = PIPE_DEF_BUFFERS,
3612 .flags = flags, 3613 .flags = flags,
3613 .ops = &tracing_pipe_buf_ops, 3614 .ops = &tracing_pipe_buf_ops,
3614 .spd_release = tracing_spd_release_pipe, 3615 .spd_release = tracing_spd_release_pipe,
@@ -3680,7 +3681,7 @@ static ssize_t tracing_splice_read_pipe(struct file *filp,
3680 3681
3681 ret = splice_to_pipe(pipe, &spd); 3682 ret = splice_to_pipe(pipe, &spd);
3682out: 3683out:
3683 splice_shrink_spd(pipe, &spd); 3684 splice_shrink_spd(&spd);
3684 return ret; 3685 return ret;
3685 3686
3686out_err: 3687out_err:
@@ -4231,6 +4232,7 @@ tracing_buffers_splice_read(struct file *file, loff_t *ppos,
4231 struct splice_pipe_desc spd = { 4232 struct splice_pipe_desc spd = {
4232 .pages = pages_def, 4233 .pages = pages_def,
4233 .partial = partial_def, 4234 .partial = partial_def,
4235 .nr_pages_max = PIPE_DEF_BUFFERS,
4234 .flags = flags, 4236 .flags = flags,
4235 .ops = &buffer_pipe_buf_ops, 4237 .ops = &buffer_pipe_buf_ops,
4236 .spd_release = buffer_spd_release, 4238 .spd_release = buffer_spd_release,
@@ -4318,7 +4320,7 @@ tracing_buffers_splice_read(struct file *file, loff_t *ppos,
4318 } 4320 }
4319 4321
4320 ret = splice_to_pipe(pipe, &spd); 4322 ret = splice_to_pipe(pipe, &spd);
4321 splice_shrink_spd(pipe, &spd); 4323 splice_shrink_spd(&spd);
4322out: 4324out:
4323 return ret; 4325 return ret;
4324} 4326}
diff --git a/lib/dma-debug.c b/lib/dma-debug.c
index 518aea714d21..66ce41489133 100644
--- a/lib/dma-debug.c
+++ b/lib/dma-debug.c
@@ -78,7 +78,7 @@ static LIST_HEAD(free_entries);
78static DEFINE_SPINLOCK(free_entries_lock); 78static DEFINE_SPINLOCK(free_entries_lock);
79 79
80/* Global disable flag - will be set in case of an error */ 80/* Global disable flag - will be set in case of an error */
81static bool global_disable __read_mostly; 81static u32 global_disable __read_mostly;
82 82
83/* Global error count */ 83/* Global error count */
84static u32 error_count; 84static u32 error_count;
@@ -657,7 +657,7 @@ static int dma_debug_fs_init(void)
657 657
658 global_disable_dent = debugfs_create_bool("disabled", 0444, 658 global_disable_dent = debugfs_create_bool("disabled", 0444,
659 dma_debug_dent, 659 dma_debug_dent,
660 (u32 *)&global_disable); 660 &global_disable);
661 if (!global_disable_dent) 661 if (!global_disable_dent)
662 goto out_err; 662 goto out_err;
663 663
diff --git a/mm/bootmem.c b/mm/bootmem.c
index ec4fcb7a56c8..73096630cb35 100644
--- a/mm/bootmem.c
+++ b/mm/bootmem.c
@@ -698,7 +698,7 @@ void * __init __alloc_bootmem(unsigned long size, unsigned long align,
698 return ___alloc_bootmem(size, align, goal, limit); 698 return ___alloc_bootmem(size, align, goal, limit);
699} 699}
700 700
701static void * __init ___alloc_bootmem_node_nopanic(pg_data_t *pgdat, 701void * __init ___alloc_bootmem_node_nopanic(pg_data_t *pgdat,
702 unsigned long size, unsigned long align, 702 unsigned long size, unsigned long align,
703 unsigned long goal, unsigned long limit) 703 unsigned long goal, unsigned long limit)
704{ 704{
diff --git a/mm/compaction.c b/mm/compaction.c
index 7ea259d82a99..2f42d9528539 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -701,8 +701,11 @@ static int compact_zone(struct zone *zone, struct compact_control *cc)
701 if (err) { 701 if (err) {
702 putback_lru_pages(&cc->migratepages); 702 putback_lru_pages(&cc->migratepages);
703 cc->nr_migratepages = 0; 703 cc->nr_migratepages = 0;
704 if (err == -ENOMEM) {
705 ret = COMPACT_PARTIAL;
706 goto out;
707 }
704 } 708 }
705
706 } 709 }
707 710
708out: 711out:
diff --git a/mm/madvise.c b/mm/madvise.c
index deff1b64a08c..14d260fa0d17 100644
--- a/mm/madvise.c
+++ b/mm/madvise.c
@@ -15,6 +15,7 @@
15#include <linux/sched.h> 15#include <linux/sched.h>
16#include <linux/ksm.h> 16#include <linux/ksm.h>
17#include <linux/fs.h> 17#include <linux/fs.h>
18#include <linux/file.h>
18 19
19/* 20/*
20 * Any behaviour which results in changes to the vma->vm_flags needs to 21 * Any behaviour which results in changes to the vma->vm_flags needs to
@@ -204,14 +205,16 @@ static long madvise_remove(struct vm_area_struct *vma,
204{ 205{
205 loff_t offset; 206 loff_t offset;
206 int error; 207 int error;
208 struct file *f;
207 209
208 *prev = NULL; /* tell sys_madvise we drop mmap_sem */ 210 *prev = NULL; /* tell sys_madvise we drop mmap_sem */
209 211
210 if (vma->vm_flags & (VM_LOCKED|VM_NONLINEAR|VM_HUGETLB)) 212 if (vma->vm_flags & (VM_LOCKED|VM_NONLINEAR|VM_HUGETLB))
211 return -EINVAL; 213 return -EINVAL;
212 214
213 if (!vma->vm_file || !vma->vm_file->f_mapping 215 f = vma->vm_file;
214 || !vma->vm_file->f_mapping->host) { 216
217 if (!f || !f->f_mapping || !f->f_mapping->host) {
215 return -EINVAL; 218 return -EINVAL;
216 } 219 }
217 220
@@ -221,11 +224,18 @@ static long madvise_remove(struct vm_area_struct *vma,
221 offset = (loff_t)(start - vma->vm_start) 224 offset = (loff_t)(start - vma->vm_start)
222 + ((loff_t)vma->vm_pgoff << PAGE_SHIFT); 225 + ((loff_t)vma->vm_pgoff << PAGE_SHIFT);
223 226
224 /* filesystem's fallocate may need to take i_mutex */ 227 /*
228 * Filesystem's fallocate may need to take i_mutex. We need to
229 * explicitly grab a reference because the vma (and hence the
230 * vma's reference to the file) can go away as soon as we drop
231 * mmap_sem.
232 */
233 get_file(f);
225 up_read(&current->mm->mmap_sem); 234 up_read(&current->mm->mmap_sem);
226 error = do_fallocate(vma->vm_file, 235 error = do_fallocate(f,
227 FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, 236 FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
228 offset, end - start); 237 offset, end - start);
238 fput(f);
229 down_read(&current->mm->mmap_sem); 239 down_read(&current->mm->mmap_sem);
230 return error; 240 return error;
231} 241}
diff --git a/mm/memblock.c b/mm/memblock.c
index d4382095f8bd..5cc6731b00cc 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -143,30 +143,6 @@ phys_addr_t __init_memblock memblock_find_in_range(phys_addr_t start,
143 MAX_NUMNODES); 143 MAX_NUMNODES);
144} 144}
145 145
146/*
147 * Free memblock.reserved.regions
148 */
149int __init_memblock memblock_free_reserved_regions(void)
150{
151 if (memblock.reserved.regions == memblock_reserved_init_regions)
152 return 0;
153
154 return memblock_free(__pa(memblock.reserved.regions),
155 sizeof(struct memblock_region) * memblock.reserved.max);
156}
157
158/*
159 * Reserve memblock.reserved.regions
160 */
161int __init_memblock memblock_reserve_reserved_regions(void)
162{
163 if (memblock.reserved.regions == memblock_reserved_init_regions)
164 return 0;
165
166 return memblock_reserve(__pa(memblock.reserved.regions),
167 sizeof(struct memblock_region) * memblock.reserved.max);
168}
169
170static void __init_memblock memblock_remove_region(struct memblock_type *type, unsigned long r) 146static void __init_memblock memblock_remove_region(struct memblock_type *type, unsigned long r)
171{ 147{
172 type->total_size -= type->regions[r].size; 148 type->total_size -= type->regions[r].size;
@@ -184,6 +160,18 @@ static void __init_memblock memblock_remove_region(struct memblock_type *type, u
184 } 160 }
185} 161}
186 162
163phys_addr_t __init_memblock get_allocated_memblock_reserved_regions_info(
164 phys_addr_t *addr)
165{
166 if (memblock.reserved.regions == memblock_reserved_init_regions)
167 return 0;
168
169 *addr = __pa(memblock.reserved.regions);
170
171 return PAGE_ALIGN(sizeof(struct memblock_region) *
172 memblock.reserved.max);
173}
174
187/** 175/**
188 * memblock_double_array - double the size of the memblock regions array 176 * memblock_double_array - double the size of the memblock regions array
189 * @type: memblock type of the regions array being doubled 177 * @type: memblock type of the regions array being doubled
@@ -204,6 +192,7 @@ static int __init_memblock memblock_double_array(struct memblock_type *type,
204 phys_addr_t new_area_size) 192 phys_addr_t new_area_size)
205{ 193{
206 struct memblock_region *new_array, *old_array; 194 struct memblock_region *new_array, *old_array;
195 phys_addr_t old_alloc_size, new_alloc_size;
207 phys_addr_t old_size, new_size, addr; 196 phys_addr_t old_size, new_size, addr;
208 int use_slab = slab_is_available(); 197 int use_slab = slab_is_available();
209 int *in_slab; 198 int *in_slab;
@@ -217,6 +206,12 @@ static int __init_memblock memblock_double_array(struct memblock_type *type,
217 /* Calculate new doubled size */ 206 /* Calculate new doubled size */
218 old_size = type->max * sizeof(struct memblock_region); 207 old_size = type->max * sizeof(struct memblock_region);
219 new_size = old_size << 1; 208 new_size = old_size << 1;
209 /*
210 * We need to allocated new one align to PAGE_SIZE,
211 * so we can free them completely later.
212 */
213 old_alloc_size = PAGE_ALIGN(old_size);
214 new_alloc_size = PAGE_ALIGN(new_size);
220 215
221 /* Retrieve the slab flag */ 216 /* Retrieve the slab flag */
222 if (type == &memblock.memory) 217 if (type == &memblock.memory)
@@ -245,11 +240,11 @@ static int __init_memblock memblock_double_array(struct memblock_type *type,
245 240
246 addr = memblock_find_in_range(new_area_start + new_area_size, 241 addr = memblock_find_in_range(new_area_start + new_area_size,
247 memblock.current_limit, 242 memblock.current_limit,
248 new_size, sizeof(phys_addr_t)); 243 new_alloc_size, PAGE_SIZE);
249 if (!addr && new_area_size) 244 if (!addr && new_area_size)
250 addr = memblock_find_in_range(0, 245 addr = memblock_find_in_range(0,
251 min(new_area_start, memblock.current_limit), 246 min(new_area_start, memblock.current_limit),
252 new_size, sizeof(phys_addr_t)); 247 new_alloc_size, PAGE_SIZE);
253 248
254 new_array = addr ? __va(addr) : 0; 249 new_array = addr ? __va(addr) : 0;
255 } 250 }
@@ -279,13 +274,13 @@ static int __init_memblock memblock_double_array(struct memblock_type *type,
279 kfree(old_array); 274 kfree(old_array);
280 else if (old_array != memblock_memory_init_regions && 275 else if (old_array != memblock_memory_init_regions &&
281 old_array != memblock_reserved_init_regions) 276 old_array != memblock_reserved_init_regions)
282 memblock_free(__pa(old_array), old_size); 277 memblock_free(__pa(old_array), old_alloc_size);
283 278
284 /* Reserve the new array if that comes from the memblock. 279 /* Reserve the new array if that comes from the memblock.
285 * Otherwise, we needn't do it 280 * Otherwise, we needn't do it
286 */ 281 */
287 if (!use_slab) 282 if (!use_slab)
288 BUG_ON(memblock_reserve(addr, new_size)); 283 BUG_ON(memblock_reserve(addr, new_alloc_size));
289 284
290 /* Update slab flag */ 285 /* Update slab flag */
291 *in_slab = use_slab; 286 *in_slab = use_slab;
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index 0d7e3ec8e0f3..427bb291dd0f 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -618,7 +618,7 @@ int __ref add_memory(int nid, u64 start, u64 size)
618 pgdat = hotadd_new_pgdat(nid, start); 618 pgdat = hotadd_new_pgdat(nid, start);
619 ret = -ENOMEM; 619 ret = -ENOMEM;
620 if (!pgdat) 620 if (!pgdat)
621 goto out; 621 goto error;
622 new_pgdat = 1; 622 new_pgdat = 1;
623 } 623 }
624 624
diff --git a/mm/nobootmem.c b/mm/nobootmem.c
index d23415c001bc..405573010f99 100644
--- a/mm/nobootmem.c
+++ b/mm/nobootmem.c
@@ -105,27 +105,35 @@ static void __init __free_pages_memory(unsigned long start, unsigned long end)
105 __free_pages_bootmem(pfn_to_page(i), 0); 105 __free_pages_bootmem(pfn_to_page(i), 0);
106} 106}
107 107
108static unsigned long __init __free_memory_core(phys_addr_t start,
109 phys_addr_t end)
110{
111 unsigned long start_pfn = PFN_UP(start);
112 unsigned long end_pfn = min_t(unsigned long,
113 PFN_DOWN(end), max_low_pfn);
114
115 if (start_pfn > end_pfn)
116 return 0;
117
118 __free_pages_memory(start_pfn, end_pfn);
119
120 return end_pfn - start_pfn;
121}
122
108unsigned long __init free_low_memory_core_early(int nodeid) 123unsigned long __init free_low_memory_core_early(int nodeid)
109{ 124{
110 unsigned long count = 0; 125 unsigned long count = 0;
111 phys_addr_t start, end; 126 phys_addr_t start, end, size;
112 u64 i; 127 u64 i;
113 128
114 /* free reserved array temporarily so that it's treated as free area */ 129 for_each_free_mem_range(i, MAX_NUMNODES, &start, &end, NULL)
115 memblock_free_reserved_regions(); 130 count += __free_memory_core(start, end);
116 131
117 for_each_free_mem_range(i, MAX_NUMNODES, &start, &end, NULL) { 132 /* free range that is used for reserved array if we allocate it */
118 unsigned long start_pfn = PFN_UP(start); 133 size = get_allocated_memblock_reserved_regions_info(&start);
119 unsigned long end_pfn = min_t(unsigned long, 134 if (size)
120 PFN_DOWN(end), max_low_pfn); 135 count += __free_memory_core(start, start + size);
121 if (start_pfn < end_pfn) {
122 __free_pages_memory(start_pfn, end_pfn);
123 count += end_pfn - start_pfn;
124 }
125 }
126 136
127 /* put region array back? */
128 memblock_reserve_reserved_regions();
129 return count; 137 return count;
130} 138}
131 139
@@ -274,7 +282,7 @@ void * __init __alloc_bootmem(unsigned long size, unsigned long align,
274 return ___alloc_bootmem(size, align, goal, limit); 282 return ___alloc_bootmem(size, align, goal, limit);
275} 283}
276 284
277static void * __init ___alloc_bootmem_node_nopanic(pg_data_t *pgdat, 285void * __init ___alloc_bootmem_node_nopanic(pg_data_t *pgdat,
278 unsigned long size, 286 unsigned long size,
279 unsigned long align, 287 unsigned long align,
280 unsigned long goal, 288 unsigned long goal,
diff --git a/mm/shmem.c b/mm/shmem.c
index a15a466d0d1d..bd106361be4b 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -264,46 +264,55 @@ static int shmem_radix_tree_replace(struct address_space *mapping,
264} 264}
265 265
266/* 266/*
267 * Sometimes, before we decide whether to proceed or to fail, we must check
268 * that an entry was not already brought back from swap by a racing thread.
269 *
270 * Checking page is not enough: by the time a SwapCache page is locked, it
271 * might be reused, and again be SwapCache, using the same swap as before.
272 */
273static bool shmem_confirm_swap(struct address_space *mapping,
274 pgoff_t index, swp_entry_t swap)
275{
276 void *item;
277
278 rcu_read_lock();
279 item = radix_tree_lookup(&mapping->page_tree, index);
280 rcu_read_unlock();
281 return item == swp_to_radix_entry(swap);
282}
283
284/*
267 * Like add_to_page_cache_locked, but error if expected item has gone. 285 * Like add_to_page_cache_locked, but error if expected item has gone.
268 */ 286 */
269static int shmem_add_to_page_cache(struct page *page, 287static int shmem_add_to_page_cache(struct page *page,
270 struct address_space *mapping, 288 struct address_space *mapping,
271 pgoff_t index, gfp_t gfp, void *expected) 289 pgoff_t index, gfp_t gfp, void *expected)
272{ 290{
273 int error = 0; 291 int error;
274 292
275 VM_BUG_ON(!PageLocked(page)); 293 VM_BUG_ON(!PageLocked(page));
276 VM_BUG_ON(!PageSwapBacked(page)); 294 VM_BUG_ON(!PageSwapBacked(page));
277 295
296 page_cache_get(page);
297 page->mapping = mapping;
298 page->index = index;
299
300 spin_lock_irq(&mapping->tree_lock);
278 if (!expected) 301 if (!expected)
279 error = radix_tree_preload(gfp & GFP_RECLAIM_MASK); 302 error = radix_tree_insert(&mapping->page_tree, index, page);
303 else
304 error = shmem_radix_tree_replace(mapping, index, expected,
305 page);
280 if (!error) { 306 if (!error) {
281 page_cache_get(page); 307 mapping->nrpages++;
282 page->mapping = mapping; 308 __inc_zone_page_state(page, NR_FILE_PAGES);
283 page->index = index; 309 __inc_zone_page_state(page, NR_SHMEM);
284 310 spin_unlock_irq(&mapping->tree_lock);
285 spin_lock_irq(&mapping->tree_lock); 311 } else {
286 if (!expected) 312 page->mapping = NULL;
287 error = radix_tree_insert(&mapping->page_tree, 313 spin_unlock_irq(&mapping->tree_lock);
288 index, page); 314 page_cache_release(page);
289 else
290 error = shmem_radix_tree_replace(mapping, index,
291 expected, page);
292 if (!error) {
293 mapping->nrpages++;
294 __inc_zone_page_state(page, NR_FILE_PAGES);
295 __inc_zone_page_state(page, NR_SHMEM);
296 spin_unlock_irq(&mapping->tree_lock);
297 } else {
298 page->mapping = NULL;
299 spin_unlock_irq(&mapping->tree_lock);
300 page_cache_release(page);
301 }
302 if (!expected)
303 radix_tree_preload_end();
304 } 315 }
305 if (error)
306 mem_cgroup_uncharge_cache_page(page);
307 return error; 316 return error;
308} 317}
309 318
@@ -1124,9 +1133,9 @@ repeat:
1124 /* We have to do this with page locked to prevent races */ 1133 /* We have to do this with page locked to prevent races */
1125 lock_page(page); 1134 lock_page(page);
1126 if (!PageSwapCache(page) || page_private(page) != swap.val || 1135 if (!PageSwapCache(page) || page_private(page) != swap.val ||
1127 page->mapping) { 1136 !shmem_confirm_swap(mapping, index, swap)) {
1128 error = -EEXIST; /* try again */ 1137 error = -EEXIST; /* try again */
1129 goto failed; 1138 goto unlock;
1130 } 1139 }
1131 if (!PageUptodate(page)) { 1140 if (!PageUptodate(page)) {
1132 error = -EIO; 1141 error = -EIO;
@@ -1142,9 +1151,12 @@ repeat:
1142 1151
1143 error = mem_cgroup_cache_charge(page, current->mm, 1152 error = mem_cgroup_cache_charge(page, current->mm,
1144 gfp & GFP_RECLAIM_MASK); 1153 gfp & GFP_RECLAIM_MASK);
1145 if (!error) 1154 if (!error) {
1146 error = shmem_add_to_page_cache(page, mapping, index, 1155 error = shmem_add_to_page_cache(page, mapping, index,
1147 gfp, swp_to_radix_entry(swap)); 1156 gfp, swp_to_radix_entry(swap));
1157 /* We already confirmed swap, and make no allocation */
1158 VM_BUG_ON(error);
1159 }
1148 if (error) 1160 if (error)
1149 goto failed; 1161 goto failed;
1150 1162
@@ -1181,11 +1193,18 @@ repeat:
1181 __set_page_locked(page); 1193 __set_page_locked(page);
1182 error = mem_cgroup_cache_charge(page, current->mm, 1194 error = mem_cgroup_cache_charge(page, current->mm,
1183 gfp & GFP_RECLAIM_MASK); 1195 gfp & GFP_RECLAIM_MASK);
1184 if (!error)
1185 error = shmem_add_to_page_cache(page, mapping, index,
1186 gfp, NULL);
1187 if (error) 1196 if (error)
1188 goto decused; 1197 goto decused;
1198 error = radix_tree_preload(gfp & GFP_RECLAIM_MASK);
1199 if (!error) {
1200 error = shmem_add_to_page_cache(page, mapping, index,
1201 gfp, NULL);
1202 radix_tree_preload_end();
1203 }
1204 if (error) {
1205 mem_cgroup_uncharge_cache_page(page);
1206 goto decused;
1207 }
1189 lru_cache_add_anon(page); 1208 lru_cache_add_anon(page);
1190 1209
1191 spin_lock(&info->lock); 1210 spin_lock(&info->lock);
@@ -1245,14 +1264,10 @@ decused:
1245unacct: 1264unacct:
1246 shmem_unacct_blocks(info->flags, 1); 1265 shmem_unacct_blocks(info->flags, 1);
1247failed: 1266failed:
1248 if (swap.val && error != -EINVAL) { 1267 if (swap.val && error != -EINVAL &&
1249 struct page *test = find_get_page(mapping, index); 1268 !shmem_confirm_swap(mapping, index, swap))
1250 if (test && !radix_tree_exceptional_entry(test)) 1269 error = -EEXIST;
1251 page_cache_release(test); 1270unlock:
1252 /* Have another try if the entry has changed */
1253 if (test != swp_to_radix_entry(swap))
1254 error = -EEXIST;
1255 }
1256 if (page) { 1271 if (page) {
1257 unlock_page(page); 1272 unlock_page(page);
1258 page_cache_release(page); 1273 page_cache_release(page);
@@ -1264,7 +1279,7 @@ failed:
1264 spin_unlock(&info->lock); 1279 spin_unlock(&info->lock);
1265 goto repeat; 1280 goto repeat;
1266 } 1281 }
1267 if (error == -EEXIST) 1282 if (error == -EEXIST) /* from above or from radix_tree_insert */
1268 goto repeat; 1283 goto repeat;
1269 return error; 1284 return error;
1270} 1285}
@@ -1594,6 +1609,7 @@ static ssize_t shmem_file_splice_read(struct file *in, loff_t *ppos,
1594 struct splice_pipe_desc spd = { 1609 struct splice_pipe_desc spd = {
1595 .pages = pages, 1610 .pages = pages,
1596 .partial = partial, 1611 .partial = partial,
1612 .nr_pages_max = PIPE_DEF_BUFFERS,
1597 .flags = flags, 1613 .flags = flags,
1598 .ops = &page_cache_pipe_buf_ops, 1614 .ops = &page_cache_pipe_buf_ops,
1599 .spd_release = spd_release_page, 1615 .spd_release = spd_release_page,
@@ -1682,7 +1698,7 @@ static ssize_t shmem_file_splice_read(struct file *in, loff_t *ppos,
1682 if (spd.nr_pages) 1698 if (spd.nr_pages)
1683 error = splice_to_pipe(pipe, &spd); 1699 error = splice_to_pipe(pipe, &spd);
1684 1700
1685 splice_shrink_spd(pipe, &spd); 1701 splice_shrink_spd(&spd);
1686 1702
1687 if (error > 0) { 1703 if (error > 0) {
1688 *ppos += error; 1704 *ppos += error;
@@ -1691,98 +1707,6 @@ static ssize_t shmem_file_splice_read(struct file *in, loff_t *ppos,
1691 return error; 1707 return error;
1692} 1708}
1693 1709
1694/*
1695 * llseek SEEK_DATA or SEEK_HOLE through the radix_tree.
1696 */
1697static pgoff_t shmem_seek_hole_data(struct address_space *mapping,
1698 pgoff_t index, pgoff_t end, int origin)
1699{
1700 struct page *page;
1701 struct pagevec pvec;
1702 pgoff_t indices[PAGEVEC_SIZE];
1703 bool done = false;
1704 int i;
1705
1706 pagevec_init(&pvec, 0);
1707 pvec.nr = 1; /* start small: we may be there already */
1708 while (!done) {
1709 pvec.nr = shmem_find_get_pages_and_swap(mapping, index,
1710 pvec.nr, pvec.pages, indices);
1711 if (!pvec.nr) {
1712 if (origin == SEEK_DATA)
1713 index = end;
1714 break;
1715 }
1716 for (i = 0; i < pvec.nr; i++, index++) {
1717 if (index < indices[i]) {
1718 if (origin == SEEK_HOLE) {
1719 done = true;
1720 break;
1721 }
1722 index = indices[i];
1723 }
1724 page = pvec.pages[i];
1725 if (page && !radix_tree_exceptional_entry(page)) {
1726 if (!PageUptodate(page))
1727 page = NULL;
1728 }
1729 if (index >= end ||
1730 (page && origin == SEEK_DATA) ||
1731 (!page && origin == SEEK_HOLE)) {
1732 done = true;
1733 break;
1734 }
1735 }
1736 shmem_deswap_pagevec(&pvec);
1737 pagevec_release(&pvec);
1738 pvec.nr = PAGEVEC_SIZE;
1739 cond_resched();
1740 }
1741 return index;
1742}
1743
1744static loff_t shmem_file_llseek(struct file *file, loff_t offset, int origin)
1745{
1746 struct address_space *mapping;
1747 struct inode *inode;
1748 pgoff_t start, end;
1749 loff_t new_offset;
1750
1751 if (origin != SEEK_DATA && origin != SEEK_HOLE)
1752 return generic_file_llseek_size(file, offset, origin,
1753 MAX_LFS_FILESIZE);
1754 mapping = file->f_mapping;
1755 inode = mapping->host;
1756 mutex_lock(&inode->i_mutex);
1757 /* We're holding i_mutex so we can access i_size directly */
1758
1759 if (offset < 0)
1760 offset = -EINVAL;
1761 else if (offset >= inode->i_size)
1762 offset = -ENXIO;
1763 else {
1764 start = offset >> PAGE_CACHE_SHIFT;
1765 end = (inode->i_size + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
1766 new_offset = shmem_seek_hole_data(mapping, start, end, origin);
1767 new_offset <<= PAGE_CACHE_SHIFT;
1768 if (new_offset > offset) {
1769 if (new_offset < inode->i_size)
1770 offset = new_offset;
1771 else if (origin == SEEK_DATA)
1772 offset = -ENXIO;
1773 else
1774 offset = inode->i_size;
1775 }
1776 }
1777
1778 if (offset >= 0 && offset != file->f_pos) {
1779 file->f_pos = offset;
1780 file->f_version = 0;
1781 }
1782 mutex_unlock(&inode->i_mutex);
1783 return offset;
1784}
1785
1786static long shmem_fallocate(struct file *file, int mode, loff_t offset, 1710static long shmem_fallocate(struct file *file, int mode, loff_t offset,
1787 loff_t len) 1711 loff_t len)
1788{ 1712{
@@ -2786,7 +2710,7 @@ static const struct address_space_operations shmem_aops = {
2786static const struct file_operations shmem_file_operations = { 2710static const struct file_operations shmem_file_operations = {
2787 .mmap = shmem_mmap, 2711 .mmap = shmem_mmap,
2788#ifdef CONFIG_TMPFS 2712#ifdef CONFIG_TMPFS
2789 .llseek = shmem_file_llseek, 2713 .llseek = generic_file_llseek,
2790 .read = do_sync_read, 2714 .read = do_sync_read,
2791 .write = do_sync_write, 2715 .write = do_sync_write,
2792 .aio_read = shmem_file_aio_read, 2716 .aio_read = shmem_file_aio_read,
diff --git a/mm/sparse.c b/mm/sparse.c
index 6a4bf9160e85..c7bb952400c8 100644
--- a/mm/sparse.c
+++ b/mm/sparse.c
@@ -275,8 +275,9 @@ static unsigned long * __init
275sparse_early_usemaps_alloc_pgdat_section(struct pglist_data *pgdat, 275sparse_early_usemaps_alloc_pgdat_section(struct pglist_data *pgdat,
276 unsigned long size) 276 unsigned long size)
277{ 277{
278 pg_data_t *host_pgdat; 278 unsigned long goal, limit;
279 unsigned long goal; 279 unsigned long *p;
280 int nid;
280 /* 281 /*
281 * A page may contain usemaps for other sections preventing the 282 * A page may contain usemaps for other sections preventing the
282 * page being freed and making a section unremovable while 283 * page being freed and making a section unremovable while
@@ -287,10 +288,17 @@ sparse_early_usemaps_alloc_pgdat_section(struct pglist_data *pgdat,
287 * from the same section as the pgdat where possible to avoid 288 * from the same section as the pgdat where possible to avoid
288 * this problem. 289 * this problem.
289 */ 290 */
290 goal = __pa(pgdat) & PAGE_SECTION_MASK; 291 goal = __pa(pgdat) & (PAGE_SECTION_MASK << PAGE_SHIFT);
291 host_pgdat = NODE_DATA(early_pfn_to_nid(goal >> PAGE_SHIFT)); 292 limit = goal + (1UL << PA_SECTION_SHIFT);
292 return __alloc_bootmem_node_nopanic(host_pgdat, size, 293 nid = early_pfn_to_nid(goal >> PAGE_SHIFT);
293 SMP_CACHE_BYTES, goal); 294again:
295 p = ___alloc_bootmem_node_nopanic(NODE_DATA(nid), size,
296 SMP_CACHE_BYTES, goal, limit);
297 if (!p && limit) {
298 limit = 0;
299 goto again;
300 }
301 return p;
294} 302}
295 303
296static void __init check_usemap_section_nr(int nid, unsigned long *usemap) 304static void __init check_usemap_section_nr(int nid, unsigned long *usemap)
diff --git a/mm/vmscan.c b/mm/vmscan.c
index eeb3bc9d1d36..661576324c7f 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -2955,14 +2955,17 @@ int kswapd_run(int nid)
2955} 2955}
2956 2956
2957/* 2957/*
2958 * Called by memory hotplug when all memory in a node is offlined. 2958 * Called by memory hotplug when all memory in a node is offlined. Caller must
2959 * hold lock_memory_hotplug().
2959 */ 2960 */
2960void kswapd_stop(int nid) 2961void kswapd_stop(int nid)
2961{ 2962{
2962 struct task_struct *kswapd = NODE_DATA(nid)->kswapd; 2963 struct task_struct *kswapd = NODE_DATA(nid)->kswapd;
2963 2964
2964 if (kswapd) 2965 if (kswapd) {
2965 kthread_stop(kswapd); 2966 kthread_stop(kswapd);
2967 NODE_DATA(nid)->kswapd = NULL;
2968 }
2966} 2969}
2967 2970
2968static int __init kswapd_init(void) 2971static int __init kswapd_init(void)
diff --git a/net/core/dev.c b/net/core/dev.c
index 6df214041a5e..84f01ba81a34 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -1136,8 +1136,8 @@ void dev_load(struct net *net, const char *name)
1136 no_module = request_module("netdev-%s", name); 1136 no_module = request_module("netdev-%s", name);
1137 if (no_module && capable(CAP_SYS_MODULE)) { 1137 if (no_module && capable(CAP_SYS_MODULE)) {
1138 if (!request_module("%s", name)) 1138 if (!request_module("%s", name))
1139 pr_err("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n", 1139 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
1140 name); 1140 name);
1141 } 1141 }
1142} 1142}
1143EXPORT_SYMBOL(dev_load); 1143EXPORT_SYMBOL(dev_load);
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index d78671e9d545..46a3d23d259e 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -1755,6 +1755,7 @@ int skb_splice_bits(struct sk_buff *skb, unsigned int offset,
1755 struct splice_pipe_desc spd = { 1755 struct splice_pipe_desc spd = {
1756 .pages = pages, 1756 .pages = pages,
1757 .partial = partial, 1757 .partial = partial,
1758 .nr_pages_max = MAX_SKB_FRAGS,
1758 .flags = flags, 1759 .flags = flags,
1759 .ops = &sock_pipe_buf_ops, 1760 .ops = &sock_pipe_buf_ops,
1760 .spd_release = sock_spd_release, 1761 .spd_release = sock_spd_release,
diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
index 66e4fcdd1c6b..a4bb856de08f 100644
--- a/net/mac80211/mlme.c
+++ b/net/mac80211/mlme.c
@@ -1342,7 +1342,6 @@ static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
1342 struct ieee80211_local *local = sdata->local; 1342 struct ieee80211_local *local = sdata->local;
1343 struct sta_info *sta; 1343 struct sta_info *sta;
1344 u32 changed = 0; 1344 u32 changed = 0;
1345 u8 bssid[ETH_ALEN];
1346 1345
1347 ASSERT_MGD_MTX(ifmgd); 1346 ASSERT_MGD_MTX(ifmgd);
1348 1347
@@ -1354,10 +1353,7 @@ static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
1354 1353
1355 ieee80211_stop_poll(sdata); 1354 ieee80211_stop_poll(sdata);
1356 1355
1357 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
1358
1359 ifmgd->associated = NULL; 1356 ifmgd->associated = NULL;
1360 memset(ifmgd->bssid, 0, ETH_ALEN);
1361 1357
1362 /* 1358 /*
1363 * we need to commit the associated = NULL change because the 1359 * we need to commit the associated = NULL change because the
@@ -1377,7 +1373,7 @@ static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
1377 netif_carrier_off(sdata->dev); 1373 netif_carrier_off(sdata->dev);
1378 1374
1379 mutex_lock(&local->sta_mtx); 1375 mutex_lock(&local->sta_mtx);
1380 sta = sta_info_get(sdata, bssid); 1376 sta = sta_info_get(sdata, ifmgd->bssid);
1381 if (sta) { 1377 if (sta) {
1382 set_sta_flag(sta, WLAN_STA_BLOCK_BA); 1378 set_sta_flag(sta, WLAN_STA_BLOCK_BA);
1383 ieee80211_sta_tear_down_BA_sessions(sta, tx); 1379 ieee80211_sta_tear_down_BA_sessions(sta, tx);
@@ -1386,13 +1382,16 @@ static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
1386 1382
1387 /* deauthenticate/disassociate now */ 1383 /* deauthenticate/disassociate now */
1388 if (tx || frame_buf) 1384 if (tx || frame_buf)
1389 ieee80211_send_deauth_disassoc(sdata, bssid, stype, reason, 1385 ieee80211_send_deauth_disassoc(sdata, ifmgd->bssid, stype,
1390 tx, frame_buf); 1386 reason, tx, frame_buf);
1391 1387
1392 /* flush out frame */ 1388 /* flush out frame */
1393 if (tx) 1389 if (tx)
1394 drv_flush(local, false); 1390 drv_flush(local, false);
1395 1391
1392 /* clear bssid only after building the needed mgmt frames */
1393 memset(ifmgd->bssid, 0, ETH_ALEN);
1394
1396 /* remove AP and TDLS peers */ 1395 /* remove AP and TDLS peers */
1397 sta_info_flush(local, sdata); 1396 sta_info_flush(local, sdata);
1398 1397
diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
index 7bcecf73aafb..965e6ec0adb6 100644
--- a/net/mac80211/rx.c
+++ b/net/mac80211/rx.c
@@ -2455,7 +2455,7 @@ ieee80211_rx_h_action_return(struct ieee80211_rx_data *rx)
2455 * frames that we didn't handle, including returning unknown 2455 * frames that we didn't handle, including returning unknown
2456 * ones. For all other modes we will return them to the sender, 2456 * ones. For all other modes we will return them to the sender,
2457 * setting the 0x80 bit in the action category, as required by 2457 * setting the 0x80 bit in the action category, as required by
2458 * 802.11-2007 7.3.1.11. 2458 * 802.11-2012 9.24.4.
2459 * Newer versions of hostapd shall also use the management frame 2459 * Newer versions of hostapd shall also use the management frame
2460 * registration mechanisms, but older ones still use cooked 2460 * registration mechanisms, but older ones still use cooked
2461 * monitor interfaces so push all frames there. 2461 * monitor interfaces so push all frames there.
@@ -2465,6 +2465,9 @@ ieee80211_rx_h_action_return(struct ieee80211_rx_data *rx)
2465 sdata->vif.type == NL80211_IFTYPE_AP_VLAN)) 2465 sdata->vif.type == NL80211_IFTYPE_AP_VLAN))
2466 return RX_DROP_MONITOR; 2466 return RX_DROP_MONITOR;
2467 2467
2468 if (is_multicast_ether_addr(mgmt->da))
2469 return RX_DROP_MONITOR;
2470
2468 /* do not return rejected action frames */ 2471 /* do not return rejected action frames */
2469 if (mgmt->u.action.category & 0x80) 2472 if (mgmt->u.action.category & 0x80)
2470 return RX_DROP_UNUSABLE; 2473 return RX_DROP_UNUSABLE;
diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
index 819c342f5b30..9730882697aa 100644
--- a/net/netfilter/ipset/ip_set_core.c
+++ b/net/netfilter/ipset/ip_set_core.c
@@ -640,6 +640,14 @@ find_free_id(const char *name, ip_set_id_t *index, struct ip_set **set)
640} 640}
641 641
642static int 642static int
643ip_set_none(struct sock *ctnl, struct sk_buff *skb,
644 const struct nlmsghdr *nlh,
645 const struct nlattr * const attr[])
646{
647 return -EOPNOTSUPP;
648}
649
650static int
643ip_set_create(struct sock *ctnl, struct sk_buff *skb, 651ip_set_create(struct sock *ctnl, struct sk_buff *skb,
644 const struct nlmsghdr *nlh, 652 const struct nlmsghdr *nlh,
645 const struct nlattr * const attr[]) 653 const struct nlattr * const attr[])
@@ -1539,6 +1547,10 @@ nlmsg_failure:
1539} 1547}
1540 1548
1541static const struct nfnl_callback ip_set_netlink_subsys_cb[IPSET_MSG_MAX] = { 1549static const struct nfnl_callback ip_set_netlink_subsys_cb[IPSET_MSG_MAX] = {
1550 [IPSET_CMD_NONE] = {
1551 .call = ip_set_none,
1552 .attr_count = IPSET_ATTR_CMD_MAX,
1553 },
1542 [IPSET_CMD_CREATE] = { 1554 [IPSET_CMD_CREATE] = {
1543 .call = ip_set_create, 1555 .call = ip_set_create,
1544 .attr_count = IPSET_ATTR_CMD_MAX, 1556 .attr_count = IPSET_ATTR_CMD_MAX,
diff --git a/net/netfilter/ipset/ip_set_hash_netiface.c b/net/netfilter/ipset/ip_set_hash_netiface.c
index ee863943c826..d5d3607ae7bc 100644
--- a/net/netfilter/ipset/ip_set_hash_netiface.c
+++ b/net/netfilter/ipset/ip_set_hash_netiface.c
@@ -38,30 +38,6 @@ struct iface_node {
38 38
39#define iface_data(n) (rb_entry(n, struct iface_node, node)->iface) 39#define iface_data(n) (rb_entry(n, struct iface_node, node)->iface)
40 40
41static inline long
42ifname_compare(const char *_a, const char *_b)
43{
44 const long *a = (const long *)_a;
45 const long *b = (const long *)_b;
46
47 BUILD_BUG_ON(IFNAMSIZ > 4 * sizeof(unsigned long));
48 if (a[0] != b[0])
49 return a[0] - b[0];
50 if (IFNAMSIZ > sizeof(long)) {
51 if (a[1] != b[1])
52 return a[1] - b[1];
53 }
54 if (IFNAMSIZ > 2 * sizeof(long)) {
55 if (a[2] != b[2])
56 return a[2] - b[2];
57 }
58 if (IFNAMSIZ > 3 * sizeof(long)) {
59 if (a[3] != b[3])
60 return a[3] - b[3];
61 }
62 return 0;
63}
64
65static void 41static void
66rbtree_destroy(struct rb_root *root) 42rbtree_destroy(struct rb_root *root)
67{ 43{
@@ -99,7 +75,7 @@ iface_test(struct rb_root *root, const char **iface)
99 75
100 while (n) { 76 while (n) {
101 const char *d = iface_data(n); 77 const char *d = iface_data(n);
102 long res = ifname_compare(*iface, d); 78 int res = strcmp(*iface, d);
103 79
104 if (res < 0) 80 if (res < 0)
105 n = n->rb_left; 81 n = n->rb_left;
@@ -121,7 +97,7 @@ iface_add(struct rb_root *root, const char **iface)
121 97
122 while (*n) { 98 while (*n) {
123 char *ifname = iface_data(*n); 99 char *ifname = iface_data(*n);
124 long res = ifname_compare(*iface, ifname); 100 int res = strcmp(*iface, ifname);
125 101
126 p = *n; 102 p = *n;
127 if (res < 0) 103 if (res < 0)
@@ -366,7 +342,7 @@ hash_netiface4_uadt(struct ip_set *set, struct nlattr *tb[],
366 struct hash_netiface4_elem data = { .cidr = HOST_MASK }; 342 struct hash_netiface4_elem data = { .cidr = HOST_MASK };
367 u32 ip = 0, ip_to, last; 343 u32 ip = 0, ip_to, last;
368 u32 timeout = h->timeout; 344 u32 timeout = h->timeout;
369 char iface[IFNAMSIZ] = {}; 345 char iface[IFNAMSIZ];
370 int ret; 346 int ret;
371 347
372 if (unlikely(!tb[IPSET_ATTR_IP] || 348 if (unlikely(!tb[IPSET_ATTR_IP] ||
@@ -663,7 +639,7 @@ hash_netiface6_uadt(struct ip_set *set, struct nlattr *tb[],
663 ipset_adtfn adtfn = set->variant->adt[adt]; 639 ipset_adtfn adtfn = set->variant->adt[adt];
664 struct hash_netiface6_elem data = { .cidr = HOST_MASK }; 640 struct hash_netiface6_elem data = { .cidr = HOST_MASK };
665 u32 timeout = h->timeout; 641 u32 timeout = h->timeout;
666 char iface[IFNAMSIZ] = {}; 642 char iface[IFNAMSIZ];
667 int ret; 643 int ret;
668 644
669 if (unlikely(!tb[IPSET_ATTR_IP] || 645 if (unlikely(!tb[IPSET_ATTR_IP] ||
diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
index dd811b8dd97c..d43e3c122f7b 100644
--- a/net/netfilter/ipvs/ip_vs_ctl.c
+++ b/net/netfilter/ipvs/ip_vs_ctl.c
@@ -76,19 +76,19 @@ static void __ip_vs_del_service(struct ip_vs_service *svc);
76 76
77#ifdef CONFIG_IP_VS_IPV6 77#ifdef CONFIG_IP_VS_IPV6
78/* Taken from rt6_fill_node() in net/ipv6/route.c, is there a better way? */ 78/* Taken from rt6_fill_node() in net/ipv6/route.c, is there a better way? */
79static int __ip_vs_addr_is_local_v6(struct net *net, 79static bool __ip_vs_addr_is_local_v6(struct net *net,
80 const struct in6_addr *addr) 80 const struct in6_addr *addr)
81{ 81{
82 struct rt6_info *rt;
83 struct flowi6 fl6 = { 82 struct flowi6 fl6 = {
84 .daddr = *addr, 83 .daddr = *addr,
85 }; 84 };
85 struct dst_entry *dst = ip6_route_output(net, NULL, &fl6);
86 bool is_local;
86 87
87 rt = (struct rt6_info *)ip6_route_output(net, NULL, &fl6); 88 is_local = !dst->error && dst->dev && (dst->dev->flags & IFF_LOOPBACK);
88 if (rt && rt->dst.dev && (rt->dst.dev->flags & IFF_LOOPBACK))
89 return 1;
90 89
91 return 0; 90 dst_release(dst);
91 return is_local;
92} 92}
93#endif 93#endif
94 94
diff --git a/net/netfilter/nfnetlink.c b/net/netfilter/nfnetlink.c
index 3e797d1fcb94..791d56bbd74a 100644
--- a/net/netfilter/nfnetlink.c
+++ b/net/netfilter/nfnetlink.c
@@ -169,8 +169,10 @@ replay:
169 169
170 err = nla_parse(cda, ss->cb[cb_id].attr_count, 170 err = nla_parse(cda, ss->cb[cb_id].attr_count,
171 attr, attrlen, ss->cb[cb_id].policy); 171 attr, attrlen, ss->cb[cb_id].policy);
172 if (err < 0) 172 if (err < 0) {
173 rcu_read_unlock();
173 return err; 174 return err;
175 }
174 176
175 if (nc->call_rcu) { 177 if (nc->call_rcu) {
176 err = nc->call_rcu(net->nfnl, skb, nlh, 178 err = nc->call_rcu(net->nfnl, skb, nlh,
diff --git a/net/nfc/nci/ntf.c b/net/nfc/nci/ntf.c
index cb2646179e5f..2ab196a9f228 100644
--- a/net/nfc/nci/ntf.c
+++ b/net/nfc/nci/ntf.c
@@ -106,7 +106,7 @@ static __u8 *nci_extract_rf_params_nfca_passive_poll(struct nci_dev *ndev,
106 nfca_poll->sens_res = __le16_to_cpu(*((__u16 *)data)); 106 nfca_poll->sens_res = __le16_to_cpu(*((__u16 *)data));
107 data += 2; 107 data += 2;
108 108
109 nfca_poll->nfcid1_len = *data++; 109 nfca_poll->nfcid1_len = min_t(__u8, *data++, NFC_NFCID1_MAXSIZE);
110 110
111 pr_debug("sens_res 0x%x, nfcid1_len %d\n", 111 pr_debug("sens_res 0x%x, nfcid1_len %d\n",
112 nfca_poll->sens_res, nfca_poll->nfcid1_len); 112 nfca_poll->sens_res, nfca_poll->nfcid1_len);
@@ -130,7 +130,7 @@ static __u8 *nci_extract_rf_params_nfcb_passive_poll(struct nci_dev *ndev,
130 struct rf_tech_specific_params_nfcb_poll *nfcb_poll, 130 struct rf_tech_specific_params_nfcb_poll *nfcb_poll,
131 __u8 *data) 131 __u8 *data)
132{ 132{
133 nfcb_poll->sensb_res_len = *data++; 133 nfcb_poll->sensb_res_len = min_t(__u8, *data++, NFC_SENSB_RES_MAXSIZE);
134 134
135 pr_debug("sensb_res_len %d\n", nfcb_poll->sensb_res_len); 135 pr_debug("sensb_res_len %d\n", nfcb_poll->sensb_res_len);
136 136
@@ -145,7 +145,7 @@ static __u8 *nci_extract_rf_params_nfcf_passive_poll(struct nci_dev *ndev,
145 __u8 *data) 145 __u8 *data)
146{ 146{
147 nfcf_poll->bit_rate = *data++; 147 nfcf_poll->bit_rate = *data++;
148 nfcf_poll->sensf_res_len = *data++; 148 nfcf_poll->sensf_res_len = min_t(__u8, *data++, NFC_SENSF_RES_MAXSIZE);
149 149
150 pr_debug("bit_rate %d, sensf_res_len %d\n", 150 pr_debug("bit_rate %d, sensf_res_len %d\n",
151 nfcf_poll->bit_rate, nfcf_poll->sensf_res_len); 151 nfcf_poll->bit_rate, nfcf_poll->sensf_res_len);
@@ -331,7 +331,7 @@ static int nci_extract_activation_params_iso_dep(struct nci_dev *ndev,
331 switch (ntf->activation_rf_tech_and_mode) { 331 switch (ntf->activation_rf_tech_and_mode) {
332 case NCI_NFC_A_PASSIVE_POLL_MODE: 332 case NCI_NFC_A_PASSIVE_POLL_MODE:
333 nfca_poll = &ntf->activation_params.nfca_poll_iso_dep; 333 nfca_poll = &ntf->activation_params.nfca_poll_iso_dep;
334 nfca_poll->rats_res_len = *data++; 334 nfca_poll->rats_res_len = min_t(__u8, *data++, 20);
335 pr_debug("rats_res_len %d\n", nfca_poll->rats_res_len); 335 pr_debug("rats_res_len %d\n", nfca_poll->rats_res_len);
336 if (nfca_poll->rats_res_len > 0) { 336 if (nfca_poll->rats_res_len > 0) {
337 memcpy(nfca_poll->rats_res, 337 memcpy(nfca_poll->rats_res,
@@ -341,7 +341,7 @@ static int nci_extract_activation_params_iso_dep(struct nci_dev *ndev,
341 341
342 case NCI_NFC_B_PASSIVE_POLL_MODE: 342 case NCI_NFC_B_PASSIVE_POLL_MODE:
343 nfcb_poll = &ntf->activation_params.nfcb_poll_iso_dep; 343 nfcb_poll = &ntf->activation_params.nfcb_poll_iso_dep;
344 nfcb_poll->attrib_res_len = *data++; 344 nfcb_poll->attrib_res_len = min_t(__u8, *data++, 50);
345 pr_debug("attrib_res_len %d\n", nfcb_poll->attrib_res_len); 345 pr_debug("attrib_res_len %d\n", nfcb_poll->attrib_res_len);
346 if (nfcb_poll->attrib_res_len > 0) { 346 if (nfcb_poll->attrib_res_len > 0) {
347 memcpy(nfcb_poll->attrib_res, 347 memcpy(nfcb_poll->attrib_res,
diff --git a/net/nfc/rawsock.c b/net/nfc/rawsock.c
index ec1134c9e07f..8b8a6a2b2bad 100644
--- a/net/nfc/rawsock.c
+++ b/net/nfc/rawsock.c
@@ -54,7 +54,10 @@ static int rawsock_release(struct socket *sock)
54{ 54{
55 struct sock *sk = sock->sk; 55 struct sock *sk = sock->sk;
56 56
57 pr_debug("sock=%p\n", sock); 57 pr_debug("sock=%p sk=%p\n", sock, sk);
58
59 if (!sk)
60 return 0;
58 61
59 sock_orphan(sk); 62 sock_orphan(sk);
60 sock_put(sk); 63 sock_put(sk);
diff --git a/net/sctp/associola.c b/net/sctp/associola.c
index 5bc9ab161b37..b16517ee1aaf 100644
--- a/net/sctp/associola.c
+++ b/net/sctp/associola.c
@@ -271,6 +271,7 @@ static struct sctp_association *sctp_association_init(struct sctp_association *a
271 */ 271 */
272 asoc->peer.sack_needed = 1; 272 asoc->peer.sack_needed = 1;
273 asoc->peer.sack_cnt = 0; 273 asoc->peer.sack_cnt = 0;
274 asoc->peer.sack_generation = 1;
274 275
275 /* Assume that the peer will tell us if he recognizes ASCONF 276 /* Assume that the peer will tell us if he recognizes ASCONF
276 * as part of INIT exchange. 277 * as part of INIT exchange.
diff --git a/net/sctp/output.c b/net/sctp/output.c
index f1b7d4bb591e..6ae47acaaec6 100644
--- a/net/sctp/output.c
+++ b/net/sctp/output.c
@@ -248,6 +248,11 @@ static sctp_xmit_t sctp_packet_bundle_sack(struct sctp_packet *pkt,
248 /* If the SACK timer is running, we have a pending SACK */ 248 /* If the SACK timer is running, we have a pending SACK */
249 if (timer_pending(timer)) { 249 if (timer_pending(timer)) {
250 struct sctp_chunk *sack; 250 struct sctp_chunk *sack;
251
252 if (pkt->transport->sack_generation !=
253 pkt->transport->asoc->peer.sack_generation)
254 return retval;
255
251 asoc->a_rwnd = asoc->rwnd; 256 asoc->a_rwnd = asoc->rwnd;
252 sack = sctp_make_sack(asoc); 257 sack = sctp_make_sack(asoc);
253 if (sack) { 258 if (sack) {
diff --git a/net/sctp/sm_make_chunk.c b/net/sctp/sm_make_chunk.c
index a85eeeb55dd0..b6de71efb140 100644
--- a/net/sctp/sm_make_chunk.c
+++ b/net/sctp/sm_make_chunk.c
@@ -734,8 +734,10 @@ struct sctp_chunk *sctp_make_sack(const struct sctp_association *asoc)
734 int len; 734 int len;
735 __u32 ctsn; 735 __u32 ctsn;
736 __u16 num_gabs, num_dup_tsns; 736 __u16 num_gabs, num_dup_tsns;
737 struct sctp_association *aptr = (struct sctp_association *)asoc;
737 struct sctp_tsnmap *map = (struct sctp_tsnmap *)&asoc->peer.tsn_map; 738 struct sctp_tsnmap *map = (struct sctp_tsnmap *)&asoc->peer.tsn_map;
738 struct sctp_gap_ack_block gabs[SCTP_MAX_GABS]; 739 struct sctp_gap_ack_block gabs[SCTP_MAX_GABS];
740 struct sctp_transport *trans;
739 741
740 memset(gabs, 0, sizeof(gabs)); 742 memset(gabs, 0, sizeof(gabs));
741 ctsn = sctp_tsnmap_get_ctsn(map); 743 ctsn = sctp_tsnmap_get_ctsn(map);
@@ -805,6 +807,20 @@ struct sctp_chunk *sctp_make_sack(const struct sctp_association *asoc)
805 sctp_addto_chunk(retval, sizeof(__u32) * num_dup_tsns, 807 sctp_addto_chunk(retval, sizeof(__u32) * num_dup_tsns,
806 sctp_tsnmap_get_dups(map)); 808 sctp_tsnmap_get_dups(map));
807 809
810 /* Once we have a sack generated, check to see what our sack
811 * generation is, if its 0, reset the transports to 0, and reset
812 * the association generation to 1
813 *
814 * The idea is that zero is never used as a valid generation for the
815 * association so no transport will match after a wrap event like this,
816 * Until the next sack
817 */
818 if (++aptr->peer.sack_generation == 0) {
819 list_for_each_entry(trans, &asoc->peer.transport_addr_list,
820 transports)
821 trans->sack_generation = 0;
822 aptr->peer.sack_generation = 1;
823 }
808nodata: 824nodata:
809 return retval; 825 return retval;
810} 826}
diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
index c96d1a81cf42..8716da1a8592 100644
--- a/net/sctp/sm_sideeffect.c
+++ b/net/sctp/sm_sideeffect.c
@@ -1268,7 +1268,7 @@ static int sctp_cmd_interpreter(sctp_event_t event_type,
1268 case SCTP_CMD_REPORT_TSN: 1268 case SCTP_CMD_REPORT_TSN:
1269 /* Record the arrival of a TSN. */ 1269 /* Record the arrival of a TSN. */
1270 error = sctp_tsnmap_mark(&asoc->peer.tsn_map, 1270 error = sctp_tsnmap_mark(&asoc->peer.tsn_map,
1271 cmd->obj.u32); 1271 cmd->obj.u32, NULL);
1272 break; 1272 break;
1273 1273
1274 case SCTP_CMD_REPORT_FWDTSN: 1274 case SCTP_CMD_REPORT_FWDTSN:
diff --git a/net/sctp/transport.c b/net/sctp/transport.c
index b026ba0c6992..1dcceb6e0ce6 100644
--- a/net/sctp/transport.c
+++ b/net/sctp/transport.c
@@ -68,6 +68,8 @@ static struct sctp_transport *sctp_transport_init(struct sctp_transport *peer,
68 peer->af_specific = sctp_get_af_specific(addr->sa.sa_family); 68 peer->af_specific = sctp_get_af_specific(addr->sa.sa_family);
69 memset(&peer->saddr, 0, sizeof(union sctp_addr)); 69 memset(&peer->saddr, 0, sizeof(union sctp_addr));
70 70
71 peer->sack_generation = 0;
72
71 /* From 6.3.1 RTO Calculation: 73 /* From 6.3.1 RTO Calculation:
72 * 74 *
73 * C1) Until an RTT measurement has been made for a packet sent to the 75 * C1) Until an RTT measurement has been made for a packet sent to the
diff --git a/net/sctp/tsnmap.c b/net/sctp/tsnmap.c
index f1e40cebc981..b5fb7c409023 100644
--- a/net/sctp/tsnmap.c
+++ b/net/sctp/tsnmap.c
@@ -114,7 +114,8 @@ int sctp_tsnmap_check(const struct sctp_tsnmap *map, __u32 tsn)
114 114
115 115
116/* Mark this TSN as seen. */ 116/* Mark this TSN as seen. */
117int sctp_tsnmap_mark(struct sctp_tsnmap *map, __u32 tsn) 117int sctp_tsnmap_mark(struct sctp_tsnmap *map, __u32 tsn,
118 struct sctp_transport *trans)
118{ 119{
119 u16 gap; 120 u16 gap;
120 121
@@ -133,6 +134,9 @@ int sctp_tsnmap_mark(struct sctp_tsnmap *map, __u32 tsn)
133 */ 134 */
134 map->max_tsn_seen++; 135 map->max_tsn_seen++;
135 map->cumulative_tsn_ack_point++; 136 map->cumulative_tsn_ack_point++;
137 if (trans)
138 trans->sack_generation =
139 trans->asoc->peer.sack_generation;
136 map->base_tsn++; 140 map->base_tsn++;
137 } else { 141 } else {
138 /* Either we already have a gap, or about to record a gap, so 142 /* Either we already have a gap, or about to record a gap, so
diff --git a/net/sctp/ulpevent.c b/net/sctp/ulpevent.c
index 8a84017834c2..33d894776192 100644
--- a/net/sctp/ulpevent.c
+++ b/net/sctp/ulpevent.c
@@ -715,7 +715,8 @@ struct sctp_ulpevent *sctp_ulpevent_make_rcvmsg(struct sctp_association *asoc,
715 * can mark it as received so the tsn_map is updated correctly. 715 * can mark it as received so the tsn_map is updated correctly.
716 */ 716 */
717 if (sctp_tsnmap_mark(&asoc->peer.tsn_map, 717 if (sctp_tsnmap_mark(&asoc->peer.tsn_map,
718 ntohl(chunk->subh.data_hdr->tsn))) 718 ntohl(chunk->subh.data_hdr->tsn),
719 chunk->transport))
719 goto fail_mark; 720 goto fail_mark;
720 721
721 /* First calculate the padding, so we don't inadvertently 722 /* First calculate the padding, so we don't inadvertently
diff --git a/net/sctp/ulpqueue.c b/net/sctp/ulpqueue.c
index f2d1de7f2ffb..f5a6a4f4faf7 100644
--- a/net/sctp/ulpqueue.c
+++ b/net/sctp/ulpqueue.c
@@ -1051,7 +1051,7 @@ void sctp_ulpq_renege(struct sctp_ulpq *ulpq, struct sctp_chunk *chunk,
1051 if (chunk && (freed >= needed)) { 1051 if (chunk && (freed >= needed)) {
1052 __u32 tsn; 1052 __u32 tsn;
1053 tsn = ntohl(chunk->subh.data_hdr->tsn); 1053 tsn = ntohl(chunk->subh.data_hdr->tsn);
1054 sctp_tsnmap_mark(&asoc->peer.tsn_map, tsn); 1054 sctp_tsnmap_mark(&asoc->peer.tsn_map, tsn, chunk->transport);
1055 sctp_ulpq_tail_data(ulpq, chunk, gfp); 1055 sctp_ulpq_tail_data(ulpq, chunk, gfp);
1056 1056
1057 sctp_ulpq_partial_delivery(ulpq, chunk, gfp); 1057 sctp_ulpq_partial_delivery(ulpq, chunk, gfp);
diff --git a/security/security.c b/security/security.c
index 3efc9b12aef4..860aeb349cb3 100644
--- a/security/security.c
+++ b/security/security.c
@@ -23,6 +23,7 @@
23#include <linux/mman.h> 23#include <linux/mman.h>
24#include <linux/mount.h> 24#include <linux/mount.h>
25#include <linux/personality.h> 25#include <linux/personality.h>
26#include <linux/backing-dev.h>
26#include <net/flow.h> 27#include <net/flow.h>
27 28
28#define MAX_LSM_EVM_XATTR 2 29#define MAX_LSM_EVM_XATTR 2
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index 5ccf10a4d593..aa4c25e0f327 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -6688,6 +6688,31 @@ static const struct alc_model_fixup alc662_fixup_models[] = {
6688 {} 6688 {}
6689}; 6689};
6690 6690
6691static void alc662_fill_coef(struct hda_codec *codec)
6692{
6693 int val, coef;
6694
6695 coef = alc_get_coef0(codec);
6696
6697 switch (codec->vendor_id) {
6698 case 0x10ec0662:
6699 if ((coef & 0x00f0) == 0x0030) {
6700 val = alc_read_coef_idx(codec, 0x4); /* EAPD Ctrl */
6701 alc_write_coef_idx(codec, 0x4, val & ~(1<<10));
6702 }
6703 break;
6704 case 0x10ec0272:
6705 case 0x10ec0273:
6706 case 0x10ec0663:
6707 case 0x10ec0665:
6708 case 0x10ec0670:
6709 case 0x10ec0671:
6710 case 0x10ec0672:
6711 val = alc_read_coef_idx(codec, 0xd); /* EAPD Ctrl */
6712 alc_write_coef_idx(codec, 0xd, val | (1<<14));
6713 break;
6714 }
6715}
6691 6716
6692/* 6717/*
6693 */ 6718 */
@@ -6707,6 +6732,9 @@ static int patch_alc662(struct hda_codec *codec)
6707 6732
6708 alc_fix_pll_init(codec, 0x20, 0x04, 15); 6733 alc_fix_pll_init(codec, 0x20, 0x04, 15);
6709 6734
6735 spec->init_hook = alc662_fill_coef;
6736 alc662_fill_coef(codec);
6737
6710 alc_pick_fixup(codec, alc662_fixup_models, 6738 alc_pick_fixup(codec, alc662_fixup_models,
6711 alc662_fixup_tbl, alc662_fixups); 6739 alc662_fixup_tbl, alc662_fixups);
6712 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); 6740 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
diff --git a/sound/soc/codecs/tlv320aic3x.c b/sound/soc/codecs/tlv320aic3x.c
index 64d2a4fa34b2..e9b62b5ea637 100644
--- a/sound/soc/codecs/tlv320aic3x.c
+++ b/sound/soc/codecs/tlv320aic3x.c
@@ -935,9 +935,7 @@ static int aic3x_hw_params(struct snd_pcm_substream *substream,
935 } 935 }
936 936
937found: 937found:
938 data = snd_soc_read(codec, AIC3X_PLL_PROGA_REG); 938 snd_soc_update_bits(codec, AIC3X_PLL_PROGA_REG, PLLP_MASK, pll_p);
939 snd_soc_write(codec, AIC3X_PLL_PROGA_REG,
940 data | (pll_p << PLLP_SHIFT));
941 snd_soc_write(codec, AIC3X_OVRF_STATUS_AND_PLLR_REG, 939 snd_soc_write(codec, AIC3X_OVRF_STATUS_AND_PLLR_REG,
942 pll_r << PLLR_SHIFT); 940 pll_r << PLLR_SHIFT);
943 snd_soc_write(codec, AIC3X_PLL_PROGB_REG, pll_j << PLLJ_SHIFT); 941 snd_soc_write(codec, AIC3X_PLL_PROGB_REG, pll_j << PLLJ_SHIFT);
diff --git a/sound/soc/codecs/tlv320aic3x.h b/sound/soc/codecs/tlv320aic3x.h
index 6f097fb60683..08c7f6685ff0 100644
--- a/sound/soc/codecs/tlv320aic3x.h
+++ b/sound/soc/codecs/tlv320aic3x.h
@@ -166,6 +166,7 @@
166 166
167/* PLL registers bitfields */ 167/* PLL registers bitfields */
168#define PLLP_SHIFT 0 168#define PLLP_SHIFT 0
169#define PLLP_MASK 7
169#define PLLQ_SHIFT 3 170#define PLLQ_SHIFT 3
170#define PLLR_SHIFT 0 171#define PLLR_SHIFT 0
171#define PLLJ_SHIFT 2 172#define PLLJ_SHIFT 2
diff --git a/sound/soc/codecs/wm2200.c b/sound/soc/codecs/wm2200.c
index acbdc5fde923..32682c1b7cde 100644
--- a/sound/soc/codecs/wm2200.c
+++ b/sound/soc/codecs/wm2200.c
@@ -1491,6 +1491,7 @@ static int wm2200_bclk_rates_dat[WM2200_NUM_BCLK_RATES] = {
1491 1491
1492static int wm2200_bclk_rates_cd[WM2200_NUM_BCLK_RATES] = { 1492static int wm2200_bclk_rates_cd[WM2200_NUM_BCLK_RATES] = {
1493 5644800, 1493 5644800,
1494 3763200,
1494 2882400, 1495 2882400,
1495 1881600, 1496 1881600,
1496 1411200, 1497 1411200,
diff --git a/sound/usb/endpoint.c b/sound/usb/endpoint.c
index e6906901debb..0f647d22cb4a 100644
--- a/sound/usb/endpoint.c
+++ b/sound/usb/endpoint.c
@@ -414,7 +414,7 @@ struct snd_usb_endpoint *snd_usb_add_endpoint(struct snd_usb_audio *chip,
414{ 414{
415 struct list_head *p; 415 struct list_head *p;
416 struct snd_usb_endpoint *ep; 416 struct snd_usb_endpoint *ep;
417 int ret, is_playback = direction == SNDRV_PCM_STREAM_PLAYBACK; 417 int is_playback = direction == SNDRV_PCM_STREAM_PLAYBACK;
418 418
419 mutex_lock(&chip->mutex); 419 mutex_lock(&chip->mutex);
420 420
@@ -434,16 +434,6 @@ struct snd_usb_endpoint *snd_usb_add_endpoint(struct snd_usb_audio *chip,
434 type == SND_USB_ENDPOINT_TYPE_DATA ? "data" : "sync", 434 type == SND_USB_ENDPOINT_TYPE_DATA ? "data" : "sync",
435 ep_num); 435 ep_num);
436 436
437 /* select the alt setting once so the endpoints become valid */
438 ret = usb_set_interface(chip->dev, alts->desc.bInterfaceNumber,
439 alts->desc.bAlternateSetting);
440 if (ret < 0) {
441 snd_printk(KERN_ERR "%s(): usb_set_interface() failed, ret = %d\n",
442 __func__, ret);
443 ep = NULL;
444 goto __exit_unlock;
445 }
446
447 ep = kzalloc(sizeof(*ep), GFP_KERNEL); 437 ep = kzalloc(sizeof(*ep), GFP_KERNEL);
448 if (!ep) 438 if (!ep)
449 goto __exit_unlock; 439 goto __exit_unlock;
@@ -831,9 +821,6 @@ int snd_usb_endpoint_start(struct snd_usb_endpoint *ep)
831 if (++ep->use_count != 1) 821 if (++ep->use_count != 1)
832 return 0; 822 return 0;
833 823
834 if (snd_BUG_ON(!test_bit(EP_FLAG_ACTIVATED, &ep->flags)))
835 return -EINVAL;
836
837 /* just to be sure */ 824 /* just to be sure */
838 deactivate_urbs(ep, 0, 1); 825 deactivate_urbs(ep, 0, 1);
839 wait_clear_urbs(ep); 826 wait_clear_urbs(ep);
@@ -911,9 +898,6 @@ void snd_usb_endpoint_stop(struct snd_usb_endpoint *ep,
911 if (snd_BUG_ON(ep->use_count == 0)) 898 if (snd_BUG_ON(ep->use_count == 0))
912 return; 899 return;
913 900
914 if (snd_BUG_ON(!test_bit(EP_FLAG_ACTIVATED, &ep->flags)))
915 return;
916
917 if (--ep->use_count == 0) { 901 if (--ep->use_count == 0) {
918 deactivate_urbs(ep, force, can_sleep); 902 deactivate_urbs(ep, force, can_sleep);
919 ep->data_subs = NULL; 903 ep->data_subs = NULL;
@@ -927,42 +911,6 @@ void snd_usb_endpoint_stop(struct snd_usb_endpoint *ep,
927} 911}
928 912
929/** 913/**
930 * snd_usb_endpoint_activate: activate an snd_usb_endpoint
931 *
932 * @ep: the endpoint to activate
933 *
934 * If the endpoint is not currently in use, this functions will select the
935 * correct alternate interface setting for the interface of this endpoint.
936 *
937 * In case of any active users, this functions does nothing.
938 *
939 * Returns an error if usb_set_interface() failed, 0 in all other
940 * cases.
941 */
942int snd_usb_endpoint_activate(struct snd_usb_endpoint *ep)
943{
944 if (ep->use_count != 0)
945 return 0;
946
947 if (!ep->chip->shutdown &&
948 !test_and_set_bit(EP_FLAG_ACTIVATED, &ep->flags)) {
949 int ret;
950
951 ret = usb_set_interface(ep->chip->dev, ep->iface, ep->alt_idx);
952 if (ret < 0) {
953 snd_printk(KERN_ERR "%s() usb_set_interface() failed, ret = %d\n",
954 __func__, ret);
955 clear_bit(EP_FLAG_ACTIVATED, &ep->flags);
956 return ret;
957 }
958
959 return 0;
960 }
961
962 return -EBUSY;
963}
964
965/**
966 * snd_usb_endpoint_deactivate: deactivate an snd_usb_endpoint 914 * snd_usb_endpoint_deactivate: deactivate an snd_usb_endpoint
967 * 915 *
968 * @ep: the endpoint to deactivate 916 * @ep: the endpoint to deactivate
@@ -980,24 +928,15 @@ int snd_usb_endpoint_deactivate(struct snd_usb_endpoint *ep)
980 if (!ep) 928 if (!ep)
981 return -EINVAL; 929 return -EINVAL;
982 930
931 deactivate_urbs(ep, 1, 1);
932 wait_clear_urbs(ep);
933
983 if (ep->use_count != 0) 934 if (ep->use_count != 0)
984 return 0; 935 return 0;
985 936
986 if (!ep->chip->shutdown && 937 clear_bit(EP_FLAG_ACTIVATED, &ep->flags);
987 test_and_clear_bit(EP_FLAG_ACTIVATED, &ep->flags)) {
988 int ret;
989
990 ret = usb_set_interface(ep->chip->dev, ep->iface, 0);
991 if (ret < 0) {
992 snd_printk(KERN_ERR "%s(): usb_set_interface() failed, ret = %d\n",
993 __func__, ret);
994 return ret;
995 }
996 938
997 return 0; 939 return 0;
998 }
999
1000 return -EBUSY;
1001} 940}
1002 941
1003/** 942/**
diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c
index 54607f8c4f66..a1298f379428 100644
--- a/sound/usb/pcm.c
+++ b/sound/usb/pcm.c
@@ -261,19 +261,6 @@ static void stop_endpoints(struct snd_usb_substream *subs,
261 force, can_sleep, wait); 261 force, can_sleep, wait);
262} 262}
263 263
264static int activate_endpoints(struct snd_usb_substream *subs)
265{
266 if (subs->sync_endpoint) {
267 int ret;
268
269 ret = snd_usb_endpoint_activate(subs->sync_endpoint);
270 if (ret < 0)
271 return ret;
272 }
273
274 return snd_usb_endpoint_activate(subs->data_endpoint);
275}
276
277static int deactivate_endpoints(struct snd_usb_substream *subs) 264static int deactivate_endpoints(struct snd_usb_substream *subs)
278{ 265{
279 int reta, retb; 266 int reta, retb;
@@ -314,6 +301,33 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt)
314 if (fmt == subs->cur_audiofmt) 301 if (fmt == subs->cur_audiofmt)
315 return 0; 302 return 0;
316 303
304 /* close the old interface */
305 if (subs->interface >= 0 && subs->interface != fmt->iface) {
306 err = usb_set_interface(subs->dev, subs->interface, 0);
307 if (err < 0) {
308 snd_printk(KERN_ERR "%d:%d:%d: return to setting 0 failed (%d)\n",
309 dev->devnum, fmt->iface, fmt->altsetting, err);
310 return -EIO;
311 }
312 subs->interface = -1;
313 subs->altset_idx = 0;
314 }
315
316 /* set interface */
317 if (subs->interface != fmt->iface ||
318 subs->altset_idx != fmt->altset_idx) {
319 err = usb_set_interface(dev, fmt->iface, fmt->altsetting);
320 if (err < 0) {
321 snd_printk(KERN_ERR "%d:%d:%d: usb_set_interface failed (%d)\n",
322 dev->devnum, fmt->iface, fmt->altsetting, err);
323 return -EIO;
324 }
325 snd_printdd(KERN_INFO "setting usb interface %d:%d\n",
326 fmt->iface, fmt->altsetting);
327 subs->interface = fmt->iface;
328 subs->altset_idx = fmt->altset_idx;
329 }
330
317 subs->data_endpoint = snd_usb_add_endpoint(subs->stream->chip, 331 subs->data_endpoint = snd_usb_add_endpoint(subs->stream->chip,
318 alts, fmt->endpoint, subs->direction, 332 alts, fmt->endpoint, subs->direction,
319 SND_USB_ENDPOINT_TYPE_DATA); 333 SND_USB_ENDPOINT_TYPE_DATA);
@@ -387,7 +401,7 @@ add_sync_ep:
387 subs->data_endpoint->sync_master = subs->sync_endpoint; 401 subs->data_endpoint->sync_master = subs->sync_endpoint;
388 } 402 }
389 403
390 if ((err = snd_usb_init_pitch(subs->stream->chip, subs->interface, alts, fmt)) < 0) 404 if ((err = snd_usb_init_pitch(subs->stream->chip, fmt->iface, alts, fmt)) < 0)
391 return err; 405 return err;
392 406
393 subs->cur_audiofmt = fmt; 407 subs->cur_audiofmt = fmt;
@@ -450,7 +464,7 @@ static int snd_usb_hw_params(struct snd_pcm_substream *substream,
450 struct usb_interface *iface; 464 struct usb_interface *iface;
451 iface = usb_ifnum_to_if(subs->dev, fmt->iface); 465 iface = usb_ifnum_to_if(subs->dev, fmt->iface);
452 alts = &iface->altsetting[fmt->altset_idx]; 466 alts = &iface->altsetting[fmt->altset_idx];
453 ret = snd_usb_init_sample_rate(subs->stream->chip, subs->interface, alts, fmt, rate); 467 ret = snd_usb_init_sample_rate(subs->stream->chip, fmt->iface, alts, fmt, rate);
454 if (ret < 0) 468 if (ret < 0)
455 return ret; 469 return ret;
456 subs->cur_rate = rate; 470 subs->cur_rate = rate;
@@ -460,12 +474,6 @@ static int snd_usb_hw_params(struct snd_pcm_substream *substream,
460 mutex_lock(&subs->stream->chip->shutdown_mutex); 474 mutex_lock(&subs->stream->chip->shutdown_mutex);
461 /* format changed */ 475 /* format changed */
462 stop_endpoints(subs, 0, 0, 0); 476 stop_endpoints(subs, 0, 0, 0);
463 deactivate_endpoints(subs);
464
465 ret = activate_endpoints(subs);
466 if (ret < 0)
467 goto unlock;
468
469 ret = snd_usb_endpoint_set_params(subs->data_endpoint, hw_params, fmt, 477 ret = snd_usb_endpoint_set_params(subs->data_endpoint, hw_params, fmt,
470 subs->sync_endpoint); 478 subs->sync_endpoint);
471 if (ret < 0) 479 if (ret < 0)
@@ -500,6 +508,7 @@ static int snd_usb_hw_free(struct snd_pcm_substream *substream)
500 subs->period_bytes = 0; 508 subs->period_bytes = 0;
501 mutex_lock(&subs->stream->chip->shutdown_mutex); 509 mutex_lock(&subs->stream->chip->shutdown_mutex);
502 stop_endpoints(subs, 0, 1, 1); 510 stop_endpoints(subs, 0, 1, 1);
511 deactivate_endpoints(subs);
503 mutex_unlock(&subs->stream->chip->shutdown_mutex); 512 mutex_unlock(&subs->stream->chip->shutdown_mutex);
504 return snd_pcm_lib_free_vmalloc_buffer(substream); 513 return snd_pcm_lib_free_vmalloc_buffer(substream);
505} 514}
@@ -938,16 +947,20 @@ static int snd_usb_pcm_open(struct snd_pcm_substream *substream, int direction)
938 947
939static int snd_usb_pcm_close(struct snd_pcm_substream *substream, int direction) 948static int snd_usb_pcm_close(struct snd_pcm_substream *substream, int direction)
940{ 949{
941 int ret;
942 struct snd_usb_stream *as = snd_pcm_substream_chip(substream); 950 struct snd_usb_stream *as = snd_pcm_substream_chip(substream);
943 struct snd_usb_substream *subs = &as->substream[direction]; 951 struct snd_usb_substream *subs = &as->substream[direction];
944 952
945 stop_endpoints(subs, 0, 0, 0); 953 stop_endpoints(subs, 0, 0, 0);
946 ret = deactivate_endpoints(subs); 954
955 if (!as->chip->shutdown && subs->interface >= 0) {
956 usb_set_interface(subs->dev, subs->interface, 0);
957 subs->interface = -1;
958 }
959
947 subs->pcm_substream = NULL; 960 subs->pcm_substream = NULL;
948 snd_usb_autosuspend(subs->stream->chip); 961 snd_usb_autosuspend(subs->stream->chip);
949 962
950 return ret; 963 return 0;
951} 964}
952 965
953/* Since a URB can handle only a single linear buffer, we must use double 966/* Since a URB can handle only a single linear buffer, we must use double
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index 35ae56864e4f..a1f4e3669142 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -669,25 +669,26 @@ struct machine *machines__find(struct rb_root *self, pid_t pid)
669struct machine *machines__findnew(struct rb_root *self, pid_t pid) 669struct machine *machines__findnew(struct rb_root *self, pid_t pid)
670{ 670{
671 char path[PATH_MAX]; 671 char path[PATH_MAX];
672 const char *root_dir; 672 const char *root_dir = "";
673 struct machine *machine = machines__find(self, pid); 673 struct machine *machine = machines__find(self, pid);
674 674
675 if (!machine || machine->pid != pid) { 675 if (machine && (machine->pid == pid))
676 if (pid == HOST_KERNEL_ID || pid == DEFAULT_GUEST_KERNEL_ID) 676 goto out;
677 root_dir = ""; 677
678 else { 678 if ((pid != HOST_KERNEL_ID) &&
679 if (!symbol_conf.guestmount) 679 (pid != DEFAULT_GUEST_KERNEL_ID) &&
680 goto out; 680 (symbol_conf.guestmount)) {
681 sprintf(path, "%s/%d", symbol_conf.guestmount, pid); 681 sprintf(path, "%s/%d", symbol_conf.guestmount, pid);
682 if (access(path, R_OK)) { 682 if (access(path, R_OK)) {
683 pr_err("Can't access file %s\n", path); 683 pr_err("Can't access file %s\n", path);
684 goto out; 684 machine = NULL;
685 } 685 goto out;
686 root_dir = path;
687 } 686 }
688 machine = machines__add(self, pid, root_dir); 687 root_dir = path;
689 } 688 }
690 689
690 machine = machines__add(self, pid, root_dir);
691
691out: 692out:
692 return machine; 693 return machine;
693} 694}
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index c3e399bcf18d..56142d0fb8d7 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -926,7 +926,7 @@ static struct machine *
926 else 926 else
927 pid = event->ip.pid; 927 pid = event->ip.pid;
928 928
929 return perf_session__find_machine(session, pid); 929 return perf_session__findnew_machine(session, pid);
930 } 930 }
931 931
932 return perf_session__find_host_machine(session); 932 return perf_session__find_host_machine(session);
diff --git a/tools/perf/util/trace-event-parse.c b/tools/perf/util/trace-event-parse.c
index df2fddbf0cd2..5dd3b5ec8411 100644
--- a/tools/perf/util/trace-event-parse.c
+++ b/tools/perf/util/trace-event-parse.c
@@ -198,9 +198,8 @@ void print_trace_event(int cpu, void *data, int size)
198 record.data = data; 198 record.data = data;
199 199
200 trace_seq_init(&s); 200 trace_seq_init(&s);
201 pevent_print_event(pevent, &s, &record); 201 pevent_event_info(&s, event, &record);
202 trace_seq_do_printf(&s); 202 trace_seq_do_printf(&s);
203 printf("\n");
204} 203}
205 204
206void print_event(int cpu, void *data, int size, unsigned long long nsecs, 205void print_event(int cpu, void *data, int size, unsigned long long nsecs,
diff --git a/virt/kvm/assigned-dev.c b/virt/kvm/assigned-dev.c
index b1e091ae2f37..23a41a9f8db9 100644
--- a/virt/kvm/assigned-dev.c
+++ b/virt/kvm/assigned-dev.c
@@ -334,6 +334,11 @@ static int assigned_device_enable_host_intx(struct kvm *kvm,
334} 334}
335 335
336#ifdef __KVM_HAVE_MSI 336#ifdef __KVM_HAVE_MSI
337static irqreturn_t kvm_assigned_dev_msi(int irq, void *dev_id)
338{
339 return IRQ_WAKE_THREAD;
340}
341
337static int assigned_device_enable_host_msi(struct kvm *kvm, 342static int assigned_device_enable_host_msi(struct kvm *kvm,
338 struct kvm_assigned_dev_kernel *dev) 343 struct kvm_assigned_dev_kernel *dev)
339{ 344{
@@ -346,7 +351,7 @@ static int assigned_device_enable_host_msi(struct kvm *kvm,
346 } 351 }
347 352
348 dev->host_irq = dev->dev->irq; 353 dev->host_irq = dev->dev->irq;
349 if (request_threaded_irq(dev->host_irq, NULL, 354 if (request_threaded_irq(dev->host_irq, kvm_assigned_dev_msi,
350 kvm_assigned_dev_thread_msi, 0, 355 kvm_assigned_dev_thread_msi, 0,
351 dev->irq_name, dev)) { 356 dev->irq_name, dev)) {
352 pci_disable_msi(dev->dev); 357 pci_disable_msi(dev->dev);
@@ -358,6 +363,11 @@ static int assigned_device_enable_host_msi(struct kvm *kvm,
358#endif 363#endif
359 364
360#ifdef __KVM_HAVE_MSIX 365#ifdef __KVM_HAVE_MSIX
366static irqreturn_t kvm_assigned_dev_msix(int irq, void *dev_id)
367{
368 return IRQ_WAKE_THREAD;
369}
370
361static int assigned_device_enable_host_msix(struct kvm *kvm, 371static int assigned_device_enable_host_msix(struct kvm *kvm,
362 struct kvm_assigned_dev_kernel *dev) 372 struct kvm_assigned_dev_kernel *dev)
363{ 373{
@@ -374,7 +384,8 @@ static int assigned_device_enable_host_msix(struct kvm *kvm,
374 384
375 for (i = 0; i < dev->entries_nr; i++) { 385 for (i = 0; i < dev->entries_nr; i++) {
376 r = request_threaded_irq(dev->host_msix_entries[i].vector, 386 r = request_threaded_irq(dev->host_msix_entries[i].vector,
377 NULL, kvm_assigned_dev_thread_msix, 387 kvm_assigned_dev_msix,
388 kvm_assigned_dev_thread_msix,
378 0, dev->irq_name, dev); 389 0, dev->irq_name, dev);
379 if (r) 390 if (r)
380 goto err; 391 goto err;
diff --git a/virt/kvm/eventfd.c b/virt/kvm/eventfd.c
index f59c1e8de7a2..7d7e2aaffece 100644
--- a/virt/kvm/eventfd.c
+++ b/virt/kvm/eventfd.c
@@ -198,7 +198,7 @@ static void irqfd_update(struct kvm *kvm, struct _irqfd *irqfd,
198} 198}
199 199
200static int 200static int
201kvm_irqfd_assign(struct kvm *kvm, int fd, int gsi) 201kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *args)
202{ 202{
203 struct kvm_irq_routing_table *irq_rt; 203 struct kvm_irq_routing_table *irq_rt;
204 struct _irqfd *irqfd, *tmp; 204 struct _irqfd *irqfd, *tmp;
@@ -212,12 +212,12 @@ kvm_irqfd_assign(struct kvm *kvm, int fd, int gsi)
212 return -ENOMEM; 212 return -ENOMEM;
213 213
214 irqfd->kvm = kvm; 214 irqfd->kvm = kvm;
215 irqfd->gsi = gsi; 215 irqfd->gsi = args->gsi;
216 INIT_LIST_HEAD(&irqfd->list); 216 INIT_LIST_HEAD(&irqfd->list);
217 INIT_WORK(&irqfd->inject, irqfd_inject); 217 INIT_WORK(&irqfd->inject, irqfd_inject);
218 INIT_WORK(&irqfd->shutdown, irqfd_shutdown); 218 INIT_WORK(&irqfd->shutdown, irqfd_shutdown);
219 219
220 file = eventfd_fget(fd); 220 file = eventfd_fget(args->fd);
221 if (IS_ERR(file)) { 221 if (IS_ERR(file)) {
222 ret = PTR_ERR(file); 222 ret = PTR_ERR(file);
223 goto fail; 223 goto fail;
@@ -298,19 +298,19 @@ kvm_eventfd_init(struct kvm *kvm)
298 * shutdown any irqfd's that match fd+gsi 298 * shutdown any irqfd's that match fd+gsi
299 */ 299 */
300static int 300static int
301kvm_irqfd_deassign(struct kvm *kvm, int fd, int gsi) 301kvm_irqfd_deassign(struct kvm *kvm, struct kvm_irqfd *args)
302{ 302{
303 struct _irqfd *irqfd, *tmp; 303 struct _irqfd *irqfd, *tmp;
304 struct eventfd_ctx *eventfd; 304 struct eventfd_ctx *eventfd;
305 305
306 eventfd = eventfd_ctx_fdget(fd); 306 eventfd = eventfd_ctx_fdget(args->fd);
307 if (IS_ERR(eventfd)) 307 if (IS_ERR(eventfd))
308 return PTR_ERR(eventfd); 308 return PTR_ERR(eventfd);
309 309
310 spin_lock_irq(&kvm->irqfds.lock); 310 spin_lock_irq(&kvm->irqfds.lock);
311 311
312 list_for_each_entry_safe(irqfd, tmp, &kvm->irqfds.items, list) { 312 list_for_each_entry_safe(irqfd, tmp, &kvm->irqfds.items, list) {
313 if (irqfd->eventfd == eventfd && irqfd->gsi == gsi) { 313 if (irqfd->eventfd == eventfd && irqfd->gsi == args->gsi) {
314 /* 314 /*
315 * This rcu_assign_pointer is needed for when 315 * This rcu_assign_pointer is needed for when
316 * another thread calls kvm_irq_routing_update before 316 * another thread calls kvm_irq_routing_update before
@@ -338,12 +338,15 @@ kvm_irqfd_deassign(struct kvm *kvm, int fd, int gsi)
338} 338}
339 339
340int 340int
341kvm_irqfd(struct kvm *kvm, int fd, int gsi, int flags) 341kvm_irqfd(struct kvm *kvm, struct kvm_irqfd *args)
342{ 342{
343 if (flags & KVM_IRQFD_FLAG_DEASSIGN) 343 if (args->flags & ~KVM_IRQFD_FLAG_DEASSIGN)
344 return kvm_irqfd_deassign(kvm, fd, gsi); 344 return -EINVAL;
345
346 if (args->flags & KVM_IRQFD_FLAG_DEASSIGN)
347 return kvm_irqfd_deassign(kvm, args);
345 348
346 return kvm_irqfd_assign(kvm, fd, gsi); 349 return kvm_irqfd_assign(kvm, args);
347} 350}
348 351
349/* 352/*
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 7e140683ff14..44ee7124b16d 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -2047,7 +2047,7 @@ static long kvm_vm_ioctl(struct file *filp,
2047 r = -EFAULT; 2047 r = -EFAULT;
2048 if (copy_from_user(&data, argp, sizeof data)) 2048 if (copy_from_user(&data, argp, sizeof data))
2049 goto out; 2049 goto out;
2050 r = kvm_irqfd(kvm, data.fd, data.gsi, data.flags); 2050 r = kvm_irqfd(kvm, &data);
2051 break; 2051 break;
2052 } 2052 }
2053 case KVM_IOEVENTFD: { 2053 case KVM_IOEVENTFD: {
@@ -2845,6 +2845,7 @@ void kvm_exit(void)
2845 kvm_arch_hardware_unsetup(); 2845 kvm_arch_hardware_unsetup();
2846 kvm_arch_exit(); 2846 kvm_arch_exit();
2847 free_cpumask_var(cpus_hardware_enabled); 2847 free_cpumask_var(cpus_hardware_enabled);
2848 __free_page(fault_page);
2848 __free_page(hwpoison_page); 2849 __free_page(hwpoison_page);
2849 __free_page(bad_page); 2850 __free_page(bad_page);
2850} 2851}